00001 // $Id: msg.h 751 2006-03-31 15:43: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 // This file contains a hierarchy of messages and broadcast macros 00102 00103 #ifndef INC_MSG 00104 #define INC_MSG 00105 00106 #include "dlgtypes.h" 00107 #include "errors.h" 00108 00109 class Operation; 00110 00111 // Place the CC_IMPLEMENT_DYNAMIC macros in pump.cpp if you like 00112 00113 /******************************************************************************************** 00114 00115 > class Msg: public CCObject 00116 00117 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00118 Created: 23/3/94 00119 Purpose: The base Msg class from which all messages must be derived 00120 SeeAlso: - 00121 00122 ********************************************************************************************/ 00123 00124 class Msg: public CCObject 00125 { 00126 CC_DECLARE_DYNAMIC(Msg); 00127 Msg() { } 00128 Msg(const Msg & msg) { } 00129 }; 00130 00131 /******************************************************************************************** 00132 00133 > class OpMsg: public Msg 00134 00135 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00136 Created: 23/3/94 00137 Purpose: This message is sent whenever something happens to an operation 00138 SeeAlso: - 00139 00140 ********************************************************************************************/ 00141 00142 class OpMsg: public Msg 00143 { 00144 CC_DECLARE_DYNAMIC(OpMsg); 00145 public: 00146 00147 enum OpMsgType 00148 { 00149 BEGIN, // An operation is about to be performed 00150 END, // An operation has successfully ended 00151 BEFORE_UNDO, // Sent prior to the operation being undone 00152 AFTER_UNDO, // Sent after the operation has been undone 00153 BEFORE_REDO, // Sent prior to the operation being redone 00154 AFTER_REDO // Sent after the operation has been redone 00155 }; 00156 00157 OpMsgType MsgType; // The message type 00158 Operation* pOp; // A pointer to the operation, can be NULL 00159 00160 OpMsg(Operation* pOperation, OpMsgType TypeMsg) 00161 : MsgType(TypeMsg), pOp(pOperation) 00162 { /* empty */ } 00163 }; 00164 00165 00166 /******************************************************************************************** 00167 00168 > class DialogMsg: public Msg 00169 00170 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00171 Created: 23/3/94 00172 Purpose: A DialogMsg is sent whenever the user interacts with the gadgets in 00173 a dialog box, It is only sensible to send this message to DialogOp objects. 00174 00175 ** Important ** 00176 00177 When processing the DialogMessage you should always use the IS_OUR_DIALOG_MSG 00178 macro. In normal circumstances this will return TRUE if the DlgWndID of 00179 the message is the same as the DialogOps window ID. However sometimes it 00180 is neccessary to send a DialogMsg to all DialogOps. For example when Camelot is 00181 dying we need to send a DIM_CANCEL to all open dialogs. The IS_DIALOG_MSG macro 00182 provides clever handling to ensure that all open DialogOps receive this message. 00183 in this situation the DlgWndID will be NULL. So when handling the DIM_CANCEL 00184 message you should not assume that DlgWndID is a valid window identifier. 00185 00186 after processing the dialog message you should always 00187 00188 return(DLG_EAT_IF_HUNGRY(DlgMsg)); 00189 00190 The DLG_EAT_IF_HUNGRY macro will return EAT_MSG if the message should not be 00191 sent on to other dialogOps and OK if it should. 00192 00193 00194 Syntax of constructor is: 00195 DialogMsg(CWindowID DlgID, CDlgMessage Msg, CGadgetID Gadget, INT32 LongParam=0) 00196 00197 00198 00199 SeeAlso: IS_OUR_DIALOG_MSG 00200 SeeAlso: EAT_IF_HUNGRY 00201 00202 ********************************************************************************************/ 00203 00204 class DialogMsg: public Msg 00205 { 00206 CC_DECLARE_DYNAMIC(DialogMsg); 00207 public: 00208 CWindowID DlgWndID; 00209 CDlgMessage DlgMsg; 00210 CGadgetID GadgetID; 00211 UINT_PTR DlgMsgParam; // Message specific data will be placed in here 00212 // Note: if more complex data needs to be stored in the 00213 // future this field ought to become a pointer 00214 // to a struct which holds the data (rather than 00215 // adding huge structs into this class). 00216 CDlgResID PageID; // Only relevent for tabbed dialogs. Specifies which page 00217 // (in the tabbed dialog) generated the message. If the dialog 00218 // itself sent the message then this will be 0. 00219 00220 DialogMsg(CWindowID DlgID, CDlgMessage Msg, CGadgetID Gadget, UINT_PTR LongParam=0, CDlgResID Pageid=0): 00221 DlgWndID(DlgID), DlgMsg(Msg), GadgetID(Gadget), DlgMsgParam(LongParam), PageID(Pageid) 00222 { 00223 } 00224 DialogMsg(const DialogMsg & msg) : 00225 DlgWndID(msg.DlgWndID), DlgMsg(msg.DlgMsg), GadgetID(msg.GadgetID), DlgMsgParam(msg.DlgMsgParam), PageID(msg.PageID) { } // copy constructor 00226 00227 }; 00228 00229 00230 00231 /******************************************************************************************** 00232 00233 > class DeathMsg: public Msg 00234 00235 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00236 Created: 29/3/94 00237 Purpose: This message is sent just before camelot's death. 00238 When a long-life operation receives this message it should tidy-up then call 00239 End(). 00240 SeeAlso: - 00241 00242 ********************************************************************************************/ 00243 00244 class DeathMsg: public Msg 00245 { 00246 CC_DECLARE_DYNAMIC(DeathMsg); 00247 DeathMsg() { } 00248 }; 00249 00250 /******************************************************************************************** 00251 00252 > MsgResult BROADCAST_TO_ALL(Msg) 00253 00254 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00255 Created: 23/3/94 00256 Inputs: - 00257 Outputs: - 00258 00259 00260 Returns: A value of OK or EAT_MSG indicates that the message was successfully sent to the 00261 MessageHandler objects. i.e. the MessageHandlers Message functions 00262 all returned either OK, or EAT_MSG. 00263 00264 OK means that message got sent to all specified MessageHandlers and all of them 00265 return OK. This does not imply than anyone acted on the message of course. 00266 00267 EAT_MSG means that a handler processed the message and didn't want it to be 00268 passed on. 00269 00270 A FAIL value indicates that one or more Message handlers returned a FAIL value 00271 from their Message functions. In this situation the broadcast function will call 00272 InformError describing the first error which occured. 00273 00274 Purpose: The BROADCAST_TO_ALL macro is used to send a message to all MessageHandler objects 00275 in the system. If any MessageHandler returns a FAIL value then InformError is 00276 called. 00277 00278 Usage: 00279 00280 BROADCAST_TO_ALL(AMsg(p1,p2,p3)) 00281 00282 SeeAlso: BROADCAST_TO_CLASS 00283 SeeAlso: MessageHandler::Broadcast 00284 00285 ********************************************************************************************/ 00286 #define BROADCAST_TO_ALL(Message) \ 00287 MessageHandler::pTmpMsg = new Message, \ 00288 (MessageHandler::pTmpMsg == NULL) ? (FAIL) : \ 00289 MessageHandler::Broadcast(MessageHandler::pTmpMsg) \ 00290 00291 00292 /******************************************************************************************** 00293 00294 > MsgResult BROADCAST_TO_CLASS(Msg,Class) 00295 00296 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00297 Created: 23/3/94 00298 Inputs: - 00299 Outputs: - 00300 Returns: A value of OK or EAT_MSG indicates that the message was successfully sent to the 00301 MessageHandler objects. i.e. the MessageHandlers Message functions 00302 all returned either OK, or EAT_MSG. 00303 00304 OK means that message got sent to all specified MessageHandlers and all of them 00305 return OK. This does not imply than anyone acted on the message of course. 00306 00307 EAT_MSG means that a handler processed the message and didn't want it to be 00308 passed on. 00309 00310 A FAIL value indicates that one or more Message handlers returned a FAIL value 00311 from their Message functions. In this situation the broadcast function will call 00312 InformError describing the first error which occured. 00313 00314 Purpose: The BROADCAST_TO_ALL macro is used to send a message to all MessageHandler objects 00315 with a class derived from or equal to Class. 00316 00317 00318 To send a message to all DialogOp objects 00319 00320 BROADCAST_TO_CLASS(DialogMsg(p1,p2,p3), DialogOp) 00321 00322 To send a message to all Operation objects, including DialogOp objects. 00323 00324 BROADCAST_TO_CLASS(AMsg(p1,p2,p3), Operation) 00325 00326 Errors: - 00327 SeeAlso: BROADCAST_TO_ALL 00328 SeeAlso: MessageHandler::Broadcast 00329 00330 ********************************************************************************************/ 00331 00332 #define BROADCAST_TO_CLASS(Message, Class) \ 00333 MessageHandler::pTmpMsg = new Message, \ 00334 (MessageHandler::pTmpMsg == NULL) ? (FAIL) : \ 00335 MessageHandler::Broadcast(MessageHandler::pTmpMsg, CC_RUNTIME_CLASS(Class)) \ 00336 00337 // The following are useful little macros for use in a MessageHandler's message function 00338 00339 /******************************************************************************************** 00340 00341 > IS_OUR_DIALOG_MSG(Message) 00342 00343 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00344 Created: 23/3/94 00345 Inputs: Message: Msg* 00346 Outputs: - 00347 Returns: - 00348 Purpose: This macro for use in DialogOp classes evaluates to TRUE if the Message is 00349 a DialogMsg for the DialogOp. See DialogMsg for a full description of its 00350 usage. 00351 Errors: - 00352 SeeAlso: DialogMsg 00353 SeeAlso: DLG_EAT_IF_HUNGRY 00354 00355 ********************************************************************************************/ 00356 // Returns TRUE if 00357 // The DialogOps WindowID != NULL and // The DialogOp is visible (may not be the case if it's a bar) 00358 // (The message is a DialogMsg and 00359 // ((The DialogOps WindowID == The message's Window ID) or 00360 // (The message's Window ID is NULL)) // A message for all DialogOps 00361 // ) 00362 // ** We need all this nonsense so that we can send CANCEL messages sensibly 00363 00364 #define IS_OUR_DIALOG_MSG(Message) \ 00365 ( \ 00366 (WindowID != NULL) && \ 00367 ( \ 00368 ((Message)->IsKindOf(CC_RUNTIME_CLASS(DialogMsg))) && \ 00369 ( \ 00370 (WindowID == ((DialogMsg*)(Message))->DlgWndID) || \ 00371 ( ((DialogMsg*)(Message))->DlgWndID == NULL) \ 00372 ) \ 00373 ) \ 00374 ) 00375 #endif 00376 00377 /******************************************************************************************** 00378 00379 > DLG_EAT_IF_HUNGRY(DialogMsg) 00380 00381 00382 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00383 Created: 18/4/94 00384 Inputs: DialogMsg: The dialog message (DialogMsg) 00385 Outputs: - 00386 Returns: - 00387 Purpose: You should use this macro to return from a DialogOp's Message function after 00388 a DialogMsg has been processed. See DialogMsg for a full description of its use 00389 00390 return(DLG_EAT_IF_HUNGRY(Msg)); 00391 00392 Errors: - 00393 SeeAlso: IS_OUR_DIALOG_MSG 00394 00395 ********************************************************************************************/ 00396 00397 // If the DlgWndID is NULL then the message should be broadcast to all DialogOps so return OK 00398 // otherwise return EAT_MSG 00399 00400 #define DLG_EAT_IF_HUNGRY(DialogMsg) \ 00401 ((DialogMsg)->DlgWndID) == NULL ? OK : EAT_MSG 00402 00403 /******************************************************************************************** 00404 00405 > MESSAGE_IS_A(Message, MsgClass) 00406 00407 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00408 Created: 23/3/94 00409 Inputs: Message: Msg* 00410 MsgClass: A class eg. DialogMsg 00411 Outputs: - 00412 Returns: 00413 Purpose: This macro determines if Message is a kind of MsgClass 00414 Errors: - 00415 SeeAlso: - 00416 00417 ********************************************************************************************/ 00418 00419 00420 #define MESSAGE_IS_A(Message,MsgClass) \ 00421 (Message->IsKindOf(CC_RUNTIME_CLASS(MsgClass)))