pump.cpp

Go to the documentation of this file.
00001 // $Id: pump.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 /*
00099 // */ 
00100 
00101 #include "camtypes.h"
00102 //#include "pump.h"  - in camtypes.h [AUTOMATICALLY REMOVED]
00103 //#include "ensure.h"    - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "listitem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "msg.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "comattrmsg.h"
00112 #include "optsmsgs.h"
00113 #include "colmsg.h"
00114 #include "brushmsg.h"
00115 #include "ctrllist.h"
00116 
00117 DECLARE_SOURCE("$Revision: 1282 $");
00118 CC_IMPLEMENT_DYNCREATE(MessageHandler, ListItem)
00119 
00120 // All message implement macros here
00121 CC_IMPLEMENT_DYNAMIC(Msg, CCObject) 
00122 CC_IMPLEMENT_DYNAMIC(DialogMsg, Msg) 
00123 CC_IMPLEMENT_DYNAMIC(DeathMsg, Msg) 
00124 CC_IMPLEMENT_DYNAMIC(OpMsg, Msg) 
00125 CC_IMPLEMENT_MEMDUMP(MessageHandlerList, ListItem)
00126 CC_IMPLEMENT_DYNAMIC(BrushMsg, Msg);
00127 CC_IMPLEMENT_DYNAMIC(ScreenChangeMsg, Msg);
00128 CC_IMPLEMENT_DYNAMIC(BrushDefMsg, Msg);
00129 CC_IMPLEMENT_DYNAMIC(NewBrushMsg, Msg);
00130 CC_IMPLEMENT_DYNAMIC(StrokeMsg, Msg);
00131 
00132 // Declare smart memory handling in Debug builds
00133 #define new CAM_DEBUG_NEW                                                                    
00134 
00135 List MessageHandler::MessageHandlerClassList; // A list of MessageHandlerClassItems 
00136 Msg* MessageHandler::pTmpMsg; 
00137 BOOL MessageHandler::PostDeath = FALSE;
00138 
00139 
00140 /********************************************************************************************
00141 
00142 >   MessageHandler::MessageHandler(CCRuntimeClass* Class, BOOL  SendMessages = TRUE)
00143 
00144     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00145     Created:    18/03/94
00146 
00147     Inputs:     Class:        Specifies the MessageHandler list this MessageHandler should
00148                               be added to. This class must be derived from Class.  
00149                               (See Purpose for a description of how to use this)  
00150     
00151                 SendMessages: This flag specifies if the MessageHandler should be added 
00152                               to a message list or not. For example certain operations may
00153                               not be interested in any messages. Setting SendMessages to
00154                               FALSE in this situation will make message dispatching 
00155                               more efficient. 
00156     Outputs:    -
00157     Returns:    -
00158     Purpose:    If the SendMessage flag is TRUE then this function adds the MessageHandler 
00159                 to a list of MessageHandlers constructed with the same Class parameter.
00160                 The Class specified should have been registered using RegisterClassGroup
00161                 during startup. 
00162 
00163                 Note: The reason for specifying a class parameter is that it allows you 
00164                       to send messages to selected groups of MessageHandlers. For example 
00165                       if a dialog message is being sent then it is more efficient to 
00166                       broadcast this message only to Operations derived from DialogOperation. 
00167                       So all DialogOpS should specify a DialogOp class in their MessageHandler 
00168                       constructor. 
00169 
00170                       It is important not to create too many groups of MessageHandlers as 
00171                       this can lead to inefficient message dispatching. Only create a 
00172                       new group if you see a situation where a message should be sent 
00173                       only to MessageHandlers in that group. 
00174 
00175     Errors:     In the retail version: If a MessageHandler list for the class specified does 
00176                 not exist then one is created (because the constructor cannot fail). 
00177                 In the debug version an ENSURE failure will occur. 
00178 
00179     SeeAlso:    MessageHandler::Broadcast
00180     SeeAlso:    MessageHandler::RegisterClassGroup
00181 
00182 ********************************************************************************************/
00183 
00184 MessageHandler::MessageHandler(CCRuntimeClass* Class, BOOL SendMessages)
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 }
00222 
00223 /********************************************************************************************
00224 
00225 >   static BOOL MessageHandler::RegisterClassGroup(CCRuntimeClass* Class)
00226 
00227     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00228     Created:    21/3/94
00229     Inputs:     Class: The class group to create. 
00230     Outputs:    -
00231     Returns:    TRUE if successful, FALSE if memory could not be allocated
00232 
00233     Purpose:    This function should be called to register a Class group at startup eg. 
00234                 Application::Init. See the Message Handler constructor for more information. 
00235 
00236     Errors:     ERROR is called if we are out of memory, and FALSE is returned
00237     SeeAlso:    -
00238 
00239 ********************************************************************************************/
00240 
00241 BOOL MessageHandler::RegisterClassGroup(CCRuntimeClass* Class)
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 }
00264 
00265 /********************************************************************************************
00266 
00267 >   List* GetClassList(CCRuntimeClass* Class)
00268 
00269     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00270     Created:    22/3/94
00271     Inputs:     Class:  The class group
00272     Outputs:    -
00273     Returns:    The list of MessageHandlers in the Class group, NULL if the class group
00274                 could not be found
00275     Purpose:    For obtaining a pointer to a list of MessageHandlers in the specified class
00276                 group. 
00277     Errors:     An ENSURE will occur if the class group could not be found
00278     SeeAlso:    -
00279 
00280 ********************************************************************************************/
00281 
00282 List* MessageHandler::GetClassList(CCRuntimeClass* Class)
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 }
00296 
00297 /********************************************************************************************
00298 
00299 >   static BOOL MessageHandler::MessageHandlerExists(CCRuntimeClass* Class) 
00300 
00301     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00302     Created:    26/08/94
00303     Inputs:     Class: The message handler's runtime class
00304                 
00305     Outputs:    -
00306     Returns:    TRUE if a MessageHandler exists with runtime class 'Class'
00307     Purpose:    Searches for a message handler with runtime class (Class). 
00308 
00309                 eg. to determine if there is a 'live' BlobbyDlg operation
00310                 if (MessageHandler::MessageHandlerExists(CC_RUNTIME_CLASS(DialogOp,BlobbyDlg)))
00311                 {
00312                     // ...
00313                 }
00314     Errors:     -
00315     SeeAlso:    -
00316 
00317 ********************************************************************************************/
00318 
00319 BOOL MessageHandler::MessageHandlerExists(CCRuntimeClass* Class)
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 } 
00358 
00359 
00360 /********************************************************************************************
00361 
00362 >   MessageHandler::~MessageHandler()
00363 
00364     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00365     Created:    15/2/94
00366     Inputs:     -
00367     Outputs:    -
00368     Returns:    -
00369     Purpose:    MessageHandler destructor, removes the MessageHandler from a MessageHandler
00370                 list, if it's on one.  
00371     Errors:     -
00372     SeeAlso:    -
00373 
00374 ********************************************************************************************/
00375 
00376 MessageHandler::~MessageHandler()
00377 {
00378 
00379     SendNoMoreMessages(this); // Removes the Message Handler from any Message list 
00380                                // it may have been on. 
00381 
00382 }
00383 
00384 /********************************************************************************************
00385 >   static MsgResult MessageHandler::Broadcast(Msg* Msg, 
00386                                           CCRuntimeClass* Class = NULL)
00387 
00388     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00389     Created:    18/2/94
00390     Inputs:     Msg         - The message to send
00391                               this will be deleted after the message has been sent
00392                 
00393                 Class       - Class specifies which MessageHandlers you wish to 
00394                               send the message to.If Class = NULL (which is the default) then 
00395                               the message is sent to all MessageHandlers, otherwise the 
00396                               message is sent only to those MessageHandlers with a runtime 
00397                               class Class, or a class derived from Class. 
00398 
00399             
00400     Outputs:    -
00401 
00402     Returns:    A value of OK or EAT_MSG indicates that the message was successfully sent to the 
00403                 MessageHandler objects. i.e. the MessageHandlers Message functions
00404                 all returned either OK, or EAT_MSG. 
00405 
00406                 OK means that message got sent to all specified MessageHandlers and all of them
00407                 return OK. This does not imply than anyone acted on the message of course.
00408 
00409                 EAT_MSG means that a handler processed the message and didn't want it to be
00410                 passed on. 
00411 
00412                 A FAIL value indicates that one or more Message handlers returned a FAIL value 
00413                 from their Message functions. In this situation the broadcast function will call 
00414                 InformError describing the first error which occured.  
00415 
00416     Purpose:    Sends a message to the specified MessageHandlers. Note that you should not use
00417                 this function directly. Instead use one of the BROADCAST macros
00418         
00419 
00420     SeeAlso:    MessageHandler::Message
00421     SeeAlso:    MessageHandler::RegisterClassGroup
00422     SeeAlso:    BROADCAST_TO_ALL
00423     SeeAlso:    BROADCAST_TO_CLASS
00424 
00425 ********************************************************************************************/
00426 
00427 
00428 MsgResult MessageHandler::Broadcast(Msg* Message, CCRuntimeClass* Class)
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 }
00579 
00580 
00581 /********************************************************************************************
00582 >   virtual MsgResult MessageHandler::Message(Msg* Message)
00583 
00584     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00585     Created:    18/2/94
00586     Inputs:     Message: The message 
00587 
00588     
00589     Returns:    OK            Message handled ok (return this even if you don't need to 
00590                               respond to the message). 
00591 
00592                 FAIL          Something terrible happened whilst processing the message
00593                               eg. we ran out of memory. You must set ERROR if you
00594                               are returning this value. The message will continue to
00595                               be sent to other MessageHandlers. 
00596 
00597                 EAT_MSG       The Message was handled ok but don't send it to any
00598                               more MessageHandlers. 
00599 
00600     Purpose:    The default message handler receives global messages, extracts information
00601                 from them and then calls virtual On<Message> handlers. 
00602      
00603     Errors:     You must set ERROR if you are returning FAIL. 
00604 
00605     SeeAlso:    Operation::Broadcast
00606 ********************************************************************************************/
00607 
00608 
00609 MsgResult MessageHandler::Message(Msg* Message)
00610 {
00611     // Find out the type of the message
00612     CCRuntimeClass* MsgType = Message->GetRuntimeClass();
00613 
00614     if (MsgType==CC_RUNTIME_CLASS(DeathMsg))
00615     {
00616         return(OnDeathMsg() ? OK : FAIL);   
00617     }
00618     else if (MsgType==CC_RUNTIME_CLASS(SelChangingMsg))
00619     {
00620         return(OnSelChangingMsg( ((SelChangingMsg*)Message)->State ) ? OK: FAIL);
00621     }
00622     else if (MsgType==CC_RUNTIME_CLASS(ColourChangingMsg))
00623     {
00624         return(OnColourChangingMsg((ColourChangingMsg*)Message) ? OK: FAIL);
00625     }
00626     else if (MsgType==CC_RUNTIME_CLASS(DocViewMsg))
00627     {
00628         DocViewMsg* DVMsg = (DocViewMsg*)Message; 
00629         return(OnDocViewMsg(DVMsg->pNewDocView, DVMsg->State) ? OK: FAIL);
00630     }
00631 #if !defined(EXCLUDE_FROM_RALPH)
00632     else if (MsgType==CC_RUNTIME_CLASS(BarMsg))
00633     {
00634         return(OnBarMsg((BarMsg*)Message) ? OK: FAIL);  
00635     }
00636 #endif
00637     else  if (MsgType==CC_RUNTIME_CLASS(DocChangingMsg))
00638     {
00639         DocChangingMsg* DCMsg = (DocChangingMsg*)Message;
00640         return(OnDocChangingMsg(DCMsg->pChangingDoc, DCMsg->State) ? OK: FAIL); 
00641     } 
00642 #if !defined(EXCLUDE_FROM_RALPH)
00643     else if (MsgType==CC_RUNTIME_CLASS(OptionsChangingMsg))
00644     {
00645         return(OnOptionsChangingMsg((OptionsChangingMsg*)Message) ? OK: FAIL);
00646     }
00647 #endif
00648     else if (MsgType==CC_RUNTIME_CLASS(CommonAttrsChangedMsg))
00649     {
00650         return(OnCommonAttrsChangedMsg() ? OK: FAIL);
00651     }
00652     else return OK; 
00653 }
00654 
00655 
00656 /********************************************************************************************
00657 
00658 >   static void MessageHandler::SendNoMoreMessages(MessageHandler* MessageHandlerToRemove); 
00659 
00660     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00661     Created:    18/3/94
00662     Inputs:     -
00663     Outputs:    -
00664     Returns:    -
00665     Purpose:    Call this function when you want Messages to stop being sent to the 
00666                 MessageHandler. The MessageHandler is simply removed from its 
00667                 message handler list. 
00668 
00669                 It is quite safe to call this function even if the MessageHandler does
00670                 not receive messages. The Operation's End method exploits this. 
00671 
00672     Errors:     -
00673     Scope:      protected. 
00674     SeeAlso:    -
00675 
00676 ********************************************************************************************/
00677 
00678 void MessageHandler::SendNoMoreMessages(MessageHandler* MessageHandlerToRemove)
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 }
00698 
00699 /********************************************************************************************
00700 
00701 >   static void Destroy()
00702 
00703     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00704     Created:    21/3/94
00705     Inputs:     -
00706     Outputs:    -
00707     Returns:    -
00708     Purpose:    This static function should be Called before we quit Camelot. It deletes all 
00709                 message handler class lists. 
00710 
00711     SeeAlso:    -
00712 
00713 ********************************************************************************************/
00714 
00715 
00716 void MessageHandler::Destroy()
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 }
00729 
00730 // ------------------------------------------------------------------------------------------
00731 // OnMessage handlers
00732 
00733 // If you are going to add new On<msg> handlers then you should do so here
00734 // these functions should either return a BOOL or a MsgResult value. 
00735 // If they return a BOOL then TRUE will be equivelent to a OK MsgResult value, and FALSE
00736 // should be equivelent to a FAIL MsgResult value. 
00737 
00738 /********************************************************************************************
00739 
00740 >   inline virtual BOOL OnDeathMsg(void) { return TRUE }; 
00741 
00742     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00743     Created:    15/6/94
00744     Inputs:     -
00745     Outputs:    -
00746     Returns:    A FALSE  value is equivalent to the Message functions FAIL return value, 
00747                 A TRUE  value is equivalent to the Message functions OK return value.
00748                 refer to MessageHandler::Message
00749                 
00750     Purpose:    Called by the Message fn when a death message is received
00751                 See DeathMsg for a description
00752 
00753     Errors:     -
00754     SeeAlso:    DeathMsg
00755     SeeAlso:    MessageHandler::Message
00756 
00757 ********************************************************************************************/
00758 
00759 /********************************************************************************************
00760 
00761 >   virtual BOOL OnSelChanging(SelectionState State) {return TRUE}; 
00762 
00763     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00764     Created:    15/6/94
00765     Inputs:     -
00766     Outputs:    -
00767     Returns:    A FALSE  value is equivalent to the Message functions FAIL return value, 
00768                 A TRUE  value is equivalent to the Message functions OK return value.
00769                 refer to MessageHandler::Message
00770                 
00771     Purpose:    Called by the Message fn when a SelChangingMsg message is received
00772 
00773     Errors:     -
00774     SeeAlso:    SelChangingMsg
00775 
00776 
00777 ********************************************************************************************/
00778 
00779 /********************************************************************************************
00780     
00781     virtual BOOL OnColourChangingMsg(ColourChangingMsg* Msg) { return TRUE; };
00782 
00783 
00784     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00785     Created:    15/6/94
00786     Inputs:     -
00787     Outputs:    -
00788     Returns:    A FALSE  value is equivalent to the Message functions FAIL return value, 
00789                 A TRUE  value is equivalent to the Message functions OK return value.
00790                 refer to MessageHandler::Message
00791                 
00792     Purpose:    Called by the Message fn when a ColourChangingMsg message is received
00793 
00794     Errors:     -
00795     SeeAlso:    ColourChangingMsg
00796 
00797 
00798 ********************************************************************************************/
00799 
00800 
00801 /********************************************************************************************
00802 
00803 >   virtual BOOL OnDocViewMsg(DocView* pDocView, DocViewState State) {return TRUE};
00804 
00805     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00806     Created:    15/6/94
00807     Inputs:     -
00808     Outputs:    -
00809     Returns:    A FALSE  value is equivalent to the Message functions FAIL return value, 
00810                 A TRUE  value is equivalent to the Message functions OK return value.
00811                 refer to MessageHandler::Message
00812                 
00813     Purpose:    Called by the Message fn when a DocViewMsg message is received
00814 
00815     Errors:     -
00816     SeeAlso:    DocViewMsg
00817 
00818 
00819 ********************************************************************************************/
00820 
00821 /********************************************************************************************
00822 
00823 >   virtual BOOL OnBarMsg(BarMsg* Msg) {return OK};
00824 
00825     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00826     Created:    15/6/94
00827     Inputs:     -
00828     Outputs:    -
00829     Returns:    A FALSE  value is equivalent to the Message functions FAIL return value, 
00830                 A TRUE  value is equivalent to the Message functions OK return value.
00831                 refer to MessageHandler::Message
00832                 
00833     Purpose:    Called by the Message fn when a BarMsg  is received
00834 
00835     Errors:     -
00836     SeeAlso:    BarMsg
00837 
00838 
00839 ********************************************************************************************/
00840 
00841 /********************************************************************************************
00842 
00843 >   virtual BOOL OnDocChangingMsg(Document* pChangingDoc, DocState State) {return OK};
00844 
00845     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00846     Created:    15/6/94
00847     Inputs:     -
00848     Outputs:    -
00849     Returns:    A FALSE  value is equivalent to the Message functions FAIL return value, 
00850                 A TRUE  value is equivalent to the Message functions OK return value.
00851                 refer to MessageHandler::Message
00852                 
00853     Purpose:    Called by the Message fn when a  DocChangingMsg is received
00854 
00855     Errors:     -
00856     SeeAlso:    DocChangingMsg
00857 
00858 
00859 ********************************************************************************************/
00860 
00861 
00862 /********************************************************************************************
00863 
00864 >   MessageHandlerList::MessageHandlerList(CCRuntimeClass* Class)
00865 
00866     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00867     Created:    22/3/94
00868     Inputs:     Class:  Class group
00869     Outputs:    -
00870     Returns:    -
00871     Purpose:    MessageHandlerList constructor 
00872     Errors:     -
00873     SeeAlso:    MessageHandler
00874 
00875 ********************************************************************************************/
00876 
00877 MessageHandlerList::MessageHandlerList(CCRuntimeClass* Class)
00878 {
00879     MessageHandlerClass = Class; 
00880 } 
00881 

Generated on Sat Nov 10 03:46:39 2007 for Camelot by  doxygen 1.4.4