#include <pump.h>
Inheritance diagram for MessageHandler:
Public Member Functions | |
MessageHandler (CCRuntimeClass *Class=CC_RUNTIME_CLASS(MessageHandler), BOOL SendMessages=TRUE) | |
If the SendMessage flag is TRUE then this function adds the MessageHandler to a list of MessageHandlers constructed with the same Class parameter. The Class specified should have been registered using RegisterClassGroup during startup. | |
virtual | ~MessageHandler () |
MessageHandler destructor, removes the MessageHandler from a MessageHandler list, if it's on one. | |
Static Public Member Functions | |
static MsgResult | Broadcast (Msg *Message, CCRuntimeClass *Class=NULL) |
Sends a message to the specified MessageHandlers. Note that you should not use this function directly. Instead use one of the BROADCAST macros. | |
static BOOL | RegisterClassGroup (CCRuntimeClass *Class) |
This function should be called to register a Class group at startup eg. Application::Init. See the Message Handler constructor for more information. | |
static List * | GetClassList (CCRuntimeClass *Class) |
For obtaining a pointer to a list of MessageHandlers in the specified class group. | |
static void | Destroy () |
This static function should be Called before we quit Camelot. It deletes all message handler class lists. | |
static BOOL | MessageHandlerExists (CCRuntimeClass *Class) |
Searches for a message handler with runtime class (Class). | |
Static Public Attributes | |
static Msg * | pTmpMsg |
Protected Member Functions | |
virtual MsgResult | Message (Msg *Msg) |
The default message handler receives global messages, extracts information from them and then calls virtual On<Message> handlers. | |
virtual BOOL | OnDeathMsg (void) |
virtual BOOL | OnSelChangingMsg (SelChangingMsg::SelectionState State) |
virtual BOOL | OnColourChangingMsg (ColourChangingMsg *Msg) |
virtual BOOL | OnDocViewMsg (DocView *pDocView, DocViewMsg::DocViewState State) |
virtual BOOL | OnBarMsg (BarMsg *Msg) |
virtual BOOL | OnDocChangingMsg (Document *pChangingDoc, DocChangingMsg::DocState State) |
virtual BOOL | OnOptionsChangingMsg (OptionsChangingMsg *Msg) |
virtual BOOL | OnCommonAttrsChangedMsg (void) |
Static Protected Member Functions | |
static void | SendNoMoreMessages (MessageHandler *MessageHandlerToRemove) |
Call this function when you want Messages to stop being sent to the MessageHandler. The MessageHandler is simply removed from its message handler list. | |
Static Protected Attributes | |
static List | MessageHandlerClassList |
static BOOL | PostDeath = FALSE |
Definition at line 149 of file pump.h.
|
If the SendMessage flag is TRUE then this function adds the MessageHandler to a list of MessageHandlers constructed with the same Class parameter. The Class specified should have been registered using RegisterClassGroup during startup.
It is important not to create too many groups of MessageHandlers as this can lead to inefficient message dispatching. Only create a new group if you see a situation where a message should be sent only to MessageHandlers in that group.
Definition at line 184 of file pump.cpp. 00185 { 00186 if (SendMessages) 00187 { 00188 // The MessageHandler is to receive messages so it needs to be added to a list grouping 00189 // all MessageHandlers with the same Class. 00190 00191 ListItem* AddMessageHandlerList = NULL; // The list the message handler should be added to. 00192 00193 // Firstly determine if there is already a MessageHandlerList to place the MessageHandler on 00194 ListItem* CurrentMessageHandlerList = MessageHandlerClassList.GetHead(); 00195 while (CurrentMessageHandlerList != NULL) 00196 { 00197 if (((MessageHandlerList*)CurrentMessageHandlerList)->MessageHandlerClass == Class) 00198 { 00199 AddMessageHandlerList = CurrentMessageHandlerList; 00200 break; 00201 } 00202 CurrentMessageHandlerList = 00203 MessageHandlerClassList.GetNext(CurrentMessageHandlerList); 00204 } 00205 00206 if (AddMessageHandlerList == NULL) // There is no suitable MessageHandlerList so we 00207 // must create one. 00208 { 00209 // this test can go off when someone forgot to register a class. It can also 00210 // go off in DLL builds if a default parameter of CC_RUNTIME_CLASS is used 00211 // as the compiler screws up the function call 00212 ERROR3_PF( ("Class %s not registered for MessageHandler", Class->GetClassName() ) ); 00213 00214 AddMessageHandlerList = new MessageHandlerList(Class); 00215 MessageHandlerClassList.AddHead(AddMessageHandlerList); 00216 } 00217 00218 // Add the MessageHandler to the MessageHandler list 00219 ((MessageHandlerList*)AddMessageHandlerList)->m_List.AddHead(this); 00220 } 00221 }
|
|
MessageHandler destructor, removes the MessageHandler from a MessageHandler list, if it's on one.
Definition at line 376 of file pump.cpp. 00377 { 00378 00379 SendNoMoreMessages(this); // Removes the Message Handler from any Message list 00380 // it may have been on. 00381 00382 }
|
|
Sends a message to the specified MessageHandlers. Note that you should not use this function directly. Instead use one of the BROADCAST macros.
EAT_MSG means that a handler processed the message and didn't want it to be passed on. A FAIL value indicates that one or more Message handlers returned a FAIL value from their Message functions. In this situation the broadcast function will call InformError describing the first error which occured.
Definition at line 428 of file pump.cpp. 00429 { 00430 // If the DeathMsg has been sent to all MessageHandlers then we won't allow any more 00431 // broadcasts... 00432 if (PostDeath) 00433 { 00434 delete Message; 00435 return (OK); 00436 } 00437 00438 // Indicate we may need to refresh button states on exit 00439 // ControlList::Get()->Changed(); 00440 00441 /* Document* pOldCurDoc = Document::GetCurrent(); 00442 View* pOldCurView = View::GetCurrent(); 00443 */ 00444 if (Class == NULL) 00445 { 00446 // Send the message to all Message Handlers 00447 Class = CC_RUNTIME_CLASS(MessageHandler); 00448 }; 00449 00450 MessageHandlerList* CurrentMessageHandlerList = 00451 (MessageHandlerList*)(MessageHandlerClassList.GetHead()); 00452 ListItem* CurrentMessageHandler; 00453 ListItem* NextMessageHandler; 00454 BOOL Result; 00455 00456 #ifdef _DEBUG 00457 BOOL FoundClassGrp = FALSE; 00458 #endif 00459 00460 BOOL Failed = FALSE; // Set to TRUE if a Message fn returns FAIL 00461 String_256 FirstErrStr; // Used to save the first error description set 00462 UINT32 FirstErrMod=0; 00463 00464 while (CurrentMessageHandlerList != NULL) 00465 { 00466 // Determine if we should send messages to the objects in the 00467 // list 00468 const CCRuntimeClass* GroupClass = CurrentMessageHandlerList-> MessageHandlerClass; 00469 while (GroupClass != NULL) 00470 { 00471 if (GroupClass == Class) 00472 { 00473 #ifdef _DEBUG 00474 FoundClassGrp = TRUE; 00475 #endif 00476 // GroupClass is equal to or derived from Class 00477 // Send the message to every MessageHandler in the list 00478 CurrentMessageHandler = CurrentMessageHandlerList->m_List.GetHead(); 00479 while (CurrentMessageHandler != NULL) 00480 { 00481 // Get the next message handler now cos there is no guarantee that 00482 // CurrentMessageHandler will survive. 00483 NextMessageHandler = (MessageHandlerList*) 00484 (CurrentMessageHandlerList->m_List.GetNext(CurrentMessageHandler)); 00485 00486 Result = ((MessageHandler*)CurrentMessageHandler)-> 00487 Message(Message); // Send the message 00488 00489 if (Result == EAT_MSG) 00490 { 00491 delete Message; 00492 /* 00493 // We need to restore the old current doc and view's, 00494 // but they may have been deleted, so we must first 00495 // check that they are still in the doc list. 00496 Document *pDoc = (Document *) Camelot.Documents.GetHead(); 00497 while (pDoc != NULL) 00498 { 00499 if (pDoc == pOldCurDoc) 00500 { 00501 // Restore the old current values 00502 if (pOldCurView) 00503 pOldCurView->SetCurrent(); 00504 else 00505 View::SetNoCurrent(); 00506 if (pOldCurDoc) 00507 pOldCurDoc->SetCurrent(); 00508 else 00509 Document::SetNoCurrent(); 00510 00511 break; 00512 } 00513 00514 pDoc = (Document *) Camelot.Documents.GetNext(pDoc); 00515 } 00516 */ 00517 return EAT_MSG; // The message has been eaten 00518 } 00519 if (Result == FAIL) 00520 { 00521 // If we have failed previously then we need not do anything special 00522 if (!Failed) 00523 { 00524 // Record the error which was set, we will restore this value prior 00525 // to returning from the function. 00526 FirstErrStr = Error::GetErrorString(); 00527 FirstErrMod = Error::GetErrorModule(); 00528 Failed = TRUE; // So we don't record the error again 00529 } 00530 // Continue to send the message on to other MessageHandlers 00531 } 00532 // Get the next Message Handler 00533 CurrentMessageHandler = NextMessageHandler; 00534 } 00535 break; 00536 00537 } 00538 GroupClass = GroupClass->GetBaseClass1(); 00539 } 00540 00541 CurrentMessageHandlerList = (MessageHandlerList*) 00542 (MessageHandlerClassList.GetNext(CurrentMessageHandlerList)); 00543 } 00544 00545 // If we have just sent the DeathMsg then flag that we will allow no more! 00546 CCRuntimeClass* MsgType = Message->GetRuntimeClass(); 00547 if (MsgType==CC_RUNTIME_CLASS(DeathMsg)) 00548 { 00549 PostDeath = TRUE; 00550 } 00551 00552 delete Message; 00553 #ifdef _DEBUG 00554 ENSURE(FoundClassGrp, "Message cannot be sent"); 00555 #endif 00556 00557 /* // Restore the old current values 00558 if (pOldCurView) 00559 pOldCurView->SetCurrent(); 00560 else 00561 View::SetNoCurrent(); 00562 if (pOldCurDoc) 00563 pOldCurDoc->SetCurrent(); 00564 else 00565 Document::SetNoCurrent(); 00566 */ 00567 if (Failed) 00568 { 00569 // Restore the error 00570 Error::SetError(0, FirstErrStr, FirstErrMod); 00571 InformError(); 00572 return FAIL; 00573 } 00574 else 00575 { 00576 return OK; 00577 } 00578 }
|
|
This static function should be Called before we quit Camelot. It deletes all message handler class lists.
Definition at line 716 of file pump.cpp. 00717 { 00718 ListItem* CurrentMessageHandlerList = MessageHandlerClassList.GetHead(); 00719 00720 while (CurrentMessageHandlerList != NULL) 00721 { 00722 ListItem* NextItem = MessageHandlerClassList.GetNext(CurrentMessageHandlerList); 00723 00724 delete( MessageHandlerClassList.RemoveItem(CurrentMessageHandlerList) ); 00725 00726 CurrentMessageHandlerList = NextItem; 00727 } 00728 }
|
|
For obtaining a pointer to a list of MessageHandlers in the specified class group.
Definition at line 282 of file pump.cpp. 00283 { 00284 ListItem* CurrentMessageHandlerList = MessageHandlerClassList.GetHead(); 00285 while (CurrentMessageHandlerList != NULL) 00286 { 00287 if (((MessageHandlerList*)CurrentMessageHandlerList)->MessageHandlerClass == Class) 00288 { 00289 return (&(((MessageHandlerList*)CurrentMessageHandlerList)->m_List)); 00290 } 00291 CurrentMessageHandlerList = MessageHandlerClassList.GetNext(CurrentMessageHandlerList); 00292 } 00293 ENSURE(FALSE, "Could not find class list"); 00294 return NULL; 00295 }
|
|
|
Searches for a message handler with runtime class (Class).
Definition at line 319 of file pump.cpp. 00320 { 00321 const CCRuntimeClass* BaseClass; 00322 00323 // Search for the class list 00324 MessageHandlerList* CurrentMessageHandlerList = 00325 (MessageHandlerList*)(MessageHandlerClassList.GetHead()); 00326 while (CurrentMessageHandlerList != NULL) 00327 { 00328 BaseClass = Class; 00329 // An instance of the Class message handler could be on any Class group list 00330 // which it is derived from 00331 while (BaseClass != NULL) 00332 { 00333 if (BaseClass == CurrentMessageHandlerList->MessageHandlerClass) 00334 { 00335 // Could be on this list ! 00336 // Search for a message handler with class 'Class' 00337 MessageHandler* MHandler = (MessageHandler*) 00338 (CurrentMessageHandlerList->m_List.GetHead()); 00339 while (MHandler != NULL) 00340 { 00341 if (MHandler->GetRuntimeClass() == Class) 00342 { 00343 return TRUE; 00344 } 00345 MHandler = (MessageHandler*) 00346 (CurrentMessageHandlerList->m_List.GetNext(MHandler)); 00347 00348 } 00349 break; 00350 } 00351 BaseClass = BaseClass->GetBaseClass1(); 00352 } 00353 CurrentMessageHandlerList = 00354 (MessageHandlerList*)MessageHandlerClassList.GetNext(CurrentMessageHandlerList); 00355 } 00356 return FALSE; 00357 }
|
|
Definition at line 206 of file pump.h. 00206 {return TRUE;};
|
|
Definition at line 202 of file pump.h. 00202 { return TRUE; };
|
|
Reimplemented in OpChangeLineAttribOpDesc, OpChangeLineWidthOpDesc, ChangeFeatherSizeSliderOpDesc, and LineGallery. Definition at line 212 of file pump.h. 00212 {return TRUE;};
|
|
Reimplemented in DownloadOp, OpAddWebFolders, and OpAddWebLibrary. Definition at line 198 of file pump.h. 00198 {return TRUE;};
|
|
Reimplemented in OpMenuImport, OpAsynchBitmapImport, OpAsynchClipartImport, OpChangeLineAttribOpDesc, OpChangeLineWidthOpDesc, OpGenericDownload, HelpDownloadOp, and OpBitmapDownload. Definition at line 208 of file pump.h. 00208 {return TRUE;};
|
|
Reimplemented in QualitySliderDescriptor. Definition at line 204 of file pump.h. 00204 {return TRUE;};
|
|
Reimplemented in ChangeFeatherSizeSliderOpDesc. Definition at line 210 of file pump.h. 00210 {return TRUE;};
|
|
Reimplemented in OpChangeLineWidthOpDesc, ChangeFeatherSizeSliderOpDesc, and OpChangeFeatherProfile. Definition at line 200 of file pump.h. 00200 {return TRUE;};
|
|
This function should be called to register a Class group at startup eg. Application::Init. See the Message Handler constructor for more information.
Definition at line 241 of file pump.cpp. 00242 { 00243 #if _DEBUG 00244 // Lets make sure that this class has not already been registered 00245 ListItem* CurrentMessageHandlerList = MessageHandlerClassList.GetHead(); 00246 while (CurrentMessageHandlerList != NULL) 00247 { 00248 if (((MessageHandlerList*)CurrentMessageHandlerList)->MessageHandlerClass == Class) 00249 { 00250 ENSURE(FALSE, 00251 "Trying to register a class group which has already been registered"); 00252 } 00253 CurrentMessageHandlerList = MessageHandlerClassList.GetNext(CurrentMessageHandlerList); 00254 } 00255 #endif 00256 00257 // Create a new Message handler list 00258 ListItem* NewMessageHandlerList = new MessageHandlerList(Class); 00259 if (NewMessageHandlerList == NULL) 00260 return FALSE; 00261 MessageHandlerClassList.AddTail(NewMessageHandlerList); 00262 return TRUE; 00263 }
|
|
Call this function when you want Messages to stop being sent to the MessageHandler. The MessageHandler is simply removed from its message handler list.
Definition at line 678 of file pump.cpp. 00679 { 00680 00681 MessageHandlerList* CurrentMessageHandlerList 00682 = (MessageHandlerList*)MessageHandlerClassList.GetHead(); 00683 00684 while (CurrentMessageHandlerList != NULL) 00685 { 00686 // The MessageHandler could be on this list 00687 if ((CurrentMessageHandlerList->m_List.FindPosition(MessageHandlerToRemove)) >= 0) // yuk 00688 { 00689 // The message handler is on the list 00690 CurrentMessageHandlerList->m_List.RemoveItem(MessageHandlerToRemove); 00691 break; 00692 00693 } 00694 CurrentMessageHandlerList = (MessageHandlerList*) 00695 (MessageHandlerClassList.GetNext(CurrentMessageHandlerList)); 00696 } 00697 }
|
|
|
|
|
|
|