00001 // $Id: sgmenu.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 // Context sensitive menu for SuperGalleries 00100 00101 /* 00102 */ 00103 00104 #include "camtypes.h" 00105 00106 #include "sgmenu.h" 00107 //#include "sgallery.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 00109 DECLARE_SOURCE("$Revision: 1282 $"); 00110 00111 CC_IMPLEMENT_MEMDUMP(GalleryContextMenu, ContextMenu) 00112 CC_IMPLEMENT_DYNCREATE(OpGalleryCommand, Operation); 00113 00114 #define new CAM_DEBUG_NEW 00115 00116 /******************************************************************************************** 00117 00118 > GalleryContextMenu::GalleryContextMenu(SGMenuID TheMenuType, SuperGallery *ParentGallery) 00119 00120 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00121 Created: 14/9/95 00122 00123 Inputs: TheMenuType - Determines whether this will be a gallery-options dropdown menu 00124 or a gallery-item/group pop-up menu. 00125 00126 ParentGallery - The gallery whose options are to be shown 00127 00128 Purpose: To construct ;-) 00129 00130 Notes: The default constructor will ERROR3 - always use this variant 00131 00132 ********************************************************************************************/ 00133 00134 GalleryContextMenu::GalleryContextMenu() 00135 { 00136 ERROR3("GalleryContextMenu - DON'T call the default constructor!"); 00137 MenuType = SGMENU_OPTIONS; 00138 ParentGallery = NULL; 00139 } 00140 00141 GalleryContextMenu::GalleryContextMenu(SGMenuID TheMenuType, SuperGallery *ParentGal) 00142 { 00143 MenuType = TheMenuType; 00144 ParentGallery = ParentGal; 00145 } 00146 00147 00148 00149 /******************************************************************************************** 00150 00151 > virtual BOOL GalleryContextMenu::Build(void) 00152 00153 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00154 Created: 15/9/95 00155 00156 Returns: TRUE if menu built OK 00157 FALSE (and sets error) otherwise 00158 00159 Purpose: To build the SuperGallery pop-up menu. (Called whn the list is adjust-clicked) 00160 The exact type (options or item-pop-up) of menu depends on the value passed\ 00161 into the constructor. 00162 00163 ********************************************************************************************/ 00164 00165 BOOL GalleryContextMenu::Build(void) 00166 { 00167 if (ParentGallery == NULL) 00168 { 00169 ERROR3("GalleryContextMenu incorrectly constructed"); 00170 return(FALSE); 00171 } 00172 00173 // It's all up to the gallery to fill us in appropriately 00174 return(ParentGallery->BuildCommandMenu(this, MenuType)); 00175 } 00176 00177 00178 00179 00180 00181 00182 //------------------------------------------------------------------------------------------- 00183 //- Polymorphic gallery menu-item Ops 00184 00185 00186 /******************************************************************************************** 00187 00188 > static BOOL OpGalleryCommand::InitPolymorphicCommand(StringBase *OpToken, UINT32 MenuTextID) 00189 00190 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00191 Created: 15/9/95 00192 00193 Inputs: OpToken - The OpToken for the new Op 00194 This must be of the form "Gallery name:Gallery command" 00195 Each portion must be no more than 31 characters long 00196 00197 MenuTextID - A String Resource ID for the menu item text 00198 00199 Returns: TRUE if it succeeded, FALSE if not enough memory to register the OpDescriptor 00200 00201 Purpose: Given a Gallery command OpToken of the form "Gallery name:Command name" 00202 this creates a new OpDescriptor for the OpGalleryCommand Op. This in turn 00203 will provide an Upcall to the named Gallery containing the given command 00204 string, whenever the Op is invoked. 00205 00206 ********************************************************************************************/ 00207 00208 BOOL OpGalleryCommand::InitPolymorphicCommand(StringBase *OpToken, UINT32 MenuTextID) 00209 { 00210 return(RegisterOpDescriptor(0, // Tool ID 00211 MenuTextID, // String resource ID 00212 CC_RUNTIME_CLASS(OpGalleryCommand), // Runtime class 00213 (TCHAR *) (*OpToken), // Token string 00214 OpGalleryCommand::GetCommandState, // GetState function 00215 0, // help ID 00216 0, // bubble help 00217 0, // resource ID 00218 0, // control ID 00219 SYSTEMBAR_ILLEGAL, // Bar ID 00220 FALSE, // Recieve system messages 00221 FALSE, // Smart duplicate operation 00222 TRUE, // Clean operation 00223 0, // No vertical counterpart 00224 0, // String for one copy only error 00225 DONT_GREY_WHEN_SELECT_INSIDE // Auto state flags 00226 )); 00227 } 00228 00229 00230 00231 /******************************************************************************************** 00232 00233 > static SuperGallery *OpGalleryCommand::GetGalleryAndCommand(OpDescriptor *pOpDesc, 00234 String_32 *Command) 00235 00236 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00237 Created: 14/9/95 00238 Inputs: pOpDesc - The Op Descriptor for the Op 00239 00240 Outputs: Command - returned as "" or as the command string from the OpToken 00241 00242 Returns: NULL if the gallery wasn't found, or a pointer to the SuperGallery which 00243 should process the command 00244 00245 Purpose: Given a Gallery command OpDescriptor of the form "Gallery name:Command name" 00246 this returns a pointer to the gallery to use and the string "Command name" 00247 which is the command that gallery should apply. 00248 00249 ********************************************************************************************/ 00250 00251 SuperGallery *OpGalleryCommand::GetGalleryAndCommand(OpDescriptor *pOpDesc, String_32 *Command) 00252 { 00253 String_256 Temp = pOpDesc->Token; 00254 TCHAR *Str = (TCHAR *)Temp; 00255 00256 *Command = TEXT(""); 00257 00258 while (*Str != '\0' && *Str != ':') 00259 Str++; 00260 00261 if (*Str == '\0') 00262 return(NULL); 00263 00264 // Copy the right end of the string into Command for return 00265 *Command = (TCHAR *) (Str+1); 00266 00267 // Find the gallery referenced by the left end of the string 00268 *Str = '\0'; // NULL Terminate the left end of the string 00269 00270 String_32 Bob; 00271 Temp.Left(&Bob, 31); 00272 SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(Bob , GalleryBarNameLimitSize); 00273 00274 if (pSuperGallery != NULL && pSuperGallery->IsKindOf(CC_RUNTIME_CLASS(SuperGallery))) 00275 return((SuperGallery *) pSuperGallery); 00276 00277 // Not found, or isn't a gallery?! (eep!) 00278 return(NULL); 00279 } 00280 00281 00282 00283 /******************************************************************************************** 00284 00285 > static BOOL OpGalleryCommand::Init(void) 00286 00287 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00288 Created: 14/9/95 00289 00290 Returns: TRUE if the operation could be successfully initialised 00291 FALSE if no more memory could be allocated 00292 00293 Purpose: OpGalleryCommand initialiser method. 00294 00295 Notes: This Init does nothing - The Op does not have its own OpDescriptor. 00296 Instead, each gallery will add an OpDescriptor for each command they 00297 wish to add to their menu, all of which will reference this Op. 00298 00299 SeeAlso: SuperGallery::InitMenuCommand 00300 00301 ********************************************************************************************/ 00302 00303 //BOOL OpGalleryCommand::Init(void) 00304 //{ 00305 // return (TRUE); 00306 //} 00307 00308 00309 00310 /******************************************************************************************** 00311 00312 > static OpState OpGalleryCommand::GetCommandState(String_256 *UIDescription, 00313 OpDescriptor *pOpDesc) 00314 00315 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00316 Created: 14/9/95 00317 00318 Inputs: UIDescriptoin - ptr to a string to place a description of what went wrong (if it did!) 00319 OpDesc - The OpDescriptor for which we need the state 00320 00321 Outputs: UIDescription is updated appropriately 00322 00323 Returns: The state of the OpGalleryCommand operation for the given OpDescriptor 00324 Purpose: For finding OpGalleryCommand's state. 00325 00326 ********************************************************************************************/ 00327 00328 OpState OpGalleryCommand::GetCommandState(String_256 *UIDescription, OpDescriptor *pOpDesc) 00329 { 00330 String_32 Command; 00331 SuperGallery *ParentGallery = GetGalleryAndCommand(pOpDesc, &Command); 00332 00333 if (ParentGallery != NULL) 00334 return(ParentGallery->GetCommandState(&Command, UIDescription)); 00335 00336 ERROR3("Attempt to get state for non-existent Gallery command"); 00337 00338 // Return a "safe" shaded state 00339 OpState OpSt; 00340 OpSt.Greyed = TRUE; 00341 *UIDescription = ""; 00342 return (OpSt); 00343 } 00344 00345 00346 00347 /******************************************************************************************** 00348 00349 > void OpGalleryCommand::Do(OpDescriptor* pOpDesc) 00350 00351 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00352 Created: 14/9/95 00353 Inputs: pOpDesc = ptr to the op descriptor 00354 Outputs: - 00355 Returns: - 00356 Purpose: The nudge op's Do() function. 00357 Errors: - 00358 SeeAlso: - 00359 00360 ********************************************************************************************/ 00361 00362 void OpGalleryCommand::Do(OpDescriptor* pOpDesc) 00363 { 00364 String_32 Command; 00365 SuperGallery *ParentGallery = GetGalleryAndCommand(pOpDesc, &Command); 00366 00367 if (ParentGallery != NULL) 00368 ParentGallery->DoCommand(&Command); 00369 00370 End(); 00371 } 00372