00001 // $Id: bfxmngr.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 // bfxpmngr.cpp : implementation file 00003 // 00004 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00005 ================================XARAHEADERSTART=========================== 00006 00007 Xara LX, a vector drawing and manipulation program. 00008 Copyright (C) 1993-2006 Xara Group Ltd. 00009 Copyright on certain contributions may be held in joint with their 00010 respective authors. See AUTHORS file for details. 00011 00012 LICENSE TO USE AND MODIFY SOFTWARE 00013 ---------------------------------- 00014 00015 This file is part of Xara LX. 00016 00017 Xara LX is free software; you can redistribute it and/or modify it 00018 under the terms of the GNU General Public License version 2 as published 00019 by the Free Software Foundation. 00020 00021 Xara LX and its component source files are distributed in the hope 00022 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00023 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00024 See the GNU General Public License for more details. 00025 00026 You should have received a copy of the GNU General Public License along 00027 with Xara LX (see the file GPL in the root directory of the 00028 distribution); if not, write to the Free Software Foundation, Inc., 51 00029 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00030 00031 00032 ADDITIONAL RIGHTS 00033 ----------------- 00034 00035 Conditional upon your continuing compliance with the GNU General Public 00036 License described above, Xara Group Ltd grants to you certain additional 00037 rights. 00038 00039 The additional rights are to use, modify, and distribute the software 00040 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00041 library and any other such library that any version of Xara LX relased 00042 by Xara Group Ltd requires in order to compile and execute, including 00043 the static linking of that library to XaraLX. In the case of the 00044 "CDraw" library, you may satisfy obligation under the GNU General Public 00045 License to provide source code by providing a binary copy of the library 00046 concerned and a copy of the license accompanying it. 00047 00048 Nothing in this section restricts any of the rights you have under 00049 the GNU General Public License. 00050 00051 00052 SCOPE OF LICENSE 00053 ---------------- 00054 00055 This license applies to this program (XaraLX) and its constituent source 00056 files only, and does not necessarily apply to other Xara products which may 00057 in part share the same code base, and are subject to their own licensing 00058 terms. 00059 00060 This license does not apply to files in the wxXtra directory, which 00061 are built into a separate library, and are subject to the wxWindows 00062 license contained within that directory in the file "WXXTRA-LICENSE". 00063 00064 This license does not apply to the binary libraries (if any) within 00065 the "libs" directory, which are subject to a separate license contained 00066 within that directory in the file "LIBS-LICENSE". 00067 00068 00069 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00070 ---------------------------------------------- 00071 00072 Subject to the terms of the GNU Public License (see above), you are 00073 free to do whatever you like with your modifications. However, you may 00074 (at your option) wish contribute them to Xara's source tree. You can 00075 find details of how to do this at: 00076 http://www.xaraxtreme.org/developers/ 00077 00078 Prior to contributing your modifications, you will need to complete our 00079 contributor agreement. This can be found at: 00080 http://www.xaraxtreme.org/developers/contribute/ 00081 00082 Please note that Xara will not accept modifications which modify any of 00083 the text between the start and end of this header (marked 00084 XARAHEADERSTART and XARAHEADEREND). 00085 00086 00087 MARKS 00088 ----- 00089 00090 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00091 designs are registered or unregistered trademarks, design-marks, and/or 00092 service marks of Xara Group Ltd. All rights in these marks are reserved. 00093 00094 00095 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00096 http://www.xara.com/ 00097 00098 =================================XARAHEADEREND============================ 00099 */ 00100 00101 // This file contains specific BFX plug-in manager related items 00102 // At present this includes:- 00103 00104 // BfxHandler 00105 // Defines the characteristics of a BFX plug-in and provides a function 00106 // for parsing them. These type of plug-ins are at present built in 00107 // and so are not parsed but added using the AddFixedPlugIns virtual function. 00108 00109 #include "camtypes.h" 00110 00111 #include "plugmngr.h" // main header file 00112 #include "bfxmngr.h" // BfxHandler 00113 #include "bfxitem.h" // BfxPlugIn 00114 #include "bfxop.h" // BfxPlugInOp BfxContextMenu 00115 #include "bfxopun.h" // BfxPlugInUndoOp 00116 #include "bfxdlg2.h" // BfxPlugInDlg 00117 00118 //#include "app.h" // GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED] 00119 #include "menuitem.h" // MenuItem 00120 #include "menupref.h" // CreateMenuItem 00121 00122 #include "appprefs.h" // OPTOKEN_PLUGSDLG 00123 00124 00125 // Place any IMPLEMENT type statements here 00126 CC_IMPLEMENT_DYNAMIC(BfxHandler, PlugInHandler) 00127 00128 // We want better memory tracking 00129 #define new CAM_DEBUG_NEW 00130 00131 /************************************************************************************** 00132 **************************************************************************************/ 00133 00134 /************************************************************************************** 00135 00136 > BfxHandler::BfxHandler() 00137 00138 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00139 Created: 4/3/97 00140 Purpose: Main constructor for the Bfx plug-in handler in Camelot. 00141 00142 **************************************************************************************/ 00143 00144 BfxHandler::BfxHandler() 00145 { 00146 } 00147 00148 /************************************************************************************** 00149 00150 > BfxHandler::~BfxHandler() 00151 00152 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00153 Created: 4/3/97 00154 Purpose: Main destructor for the Bfx plug-in handler in Camelot. 00155 00156 **************************************************************************************/ 00157 00158 BfxHandler::~BfxHandler() 00159 { 00160 } 00161 00162 /************************************************************************************** 00163 00164 > virtual BOOL BfxHandler::Init() 00165 00166 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00167 Created: 4/3/97 00168 Returns: True if initialised ok, False otherwise. 00169 Purpose: Main initialisation code for the Bfx plug-in handler in Camelot. 00170 00171 **************************************************************************************/ 00172 00173 BOOL BfxHandler::Init() 00174 { 00175 // Initialise the operations we are going to need 00176 if (!BfxPlugInOp::Init()) 00177 return FALSE; 00178 //#if NEW_NATIVE_FILTER 00179 if (!BfxPlugInUndoOp::Init()) 00180 return FALSE; 00181 //#endif 00182 if (!BfxPlugInDlg::Init()) 00183 return FALSE; 00184 00185 return TRUE; 00186 } 00187 00188 /************************************************************************************** 00189 00190 > virtual String_32 BfxHandler::GetUniqueID() const 00191 00192 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00193 Created: 4/3/97 00194 Returns: A string containing a filetype. 00195 Purpose: A string which defines the unique identifier for the plug-ins that this 00196 handler is interested in. 00197 In this case being Bfx it is 'Bfx:'. 00198 00199 **************************************************************************************/ 00200 00201 String_32 BfxHandler::GetUniqueID() const 00202 { 00203 return TEXT("BFX:"); 00204 } 00205 00206 /************************************************************************************** 00207 00208 > virtual TypeOfPlugIn BfxHandler::GetTypeOfPlugIn() const 00209 00210 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00211 Created: 4/3/97 00212 Returns: Type of the plug-in. 00213 Purpose: A unique type for the plug-ins that this handler is interested in. 00214 In this case being Bfx it is PLUGIN_BFX. 00215 00216 **************************************************************************************/ 00217 00218 TypeOfPlugIn BfxHandler::GetTypeOfPlugIn() const 00219 { 00220 return PLUGIN_BFX; 00221 } 00222 00223 /************************************************************************************** 00224 00225 > virtual String_32 BfxHandler::GetFileTypes() const 00226 00227 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00228 Created: 4/3/97 00229 Returns: A string containing a filetype. 00230 Purpose: A string which defines the filetype or a list of filetypes that this 00231 type of plug-in is interested in. 00232 In this case being Bfx they are built in and have no filetype. 00233 Always supplied in lowercase. 00234 00235 **************************************************************************************/ 00236 00237 String_32 BfxHandler::GetFileTypes() const 00238 { 00239 return TEXT(""); 00240 } 00241 00242 /************************************************************************************** 00243 00244 > virtual BOOL BfxHandler::AddFixedPlugIns() 00245 00246 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00247 Created: 4/3/97 00248 Inputs: - 00249 Returns: True if worked, False otherwise 00250 Purpose: Add any fixed plug-ins to the list in the plug-in manager and register the op 00251 descriptor to the system. By fixed, I mean those which are not file 00252 related and hence will be loaded when the specified paths are parsed 00253 for plug-ins. 00254 This is the main way that BFX type plug-ins are added to the system. 00255 00256 **************************************************************************************/ 00257 00258 BOOL BfxHandler::AddFixedPlugIns() 00259 { 00260 // Add our fixed plug-ins to the system 00261 // BfxBrightnessContrast * pBrightnessContrast = new BfxBrightnessContrast; 00262 // if (pBrightnessContrast) 00263 // AddPlugIn(pBrightnessContrast, CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00264 00265 BfxSpecialEffects * pSpecialEffects = new BfxSpecialEffects; 00266 if (pSpecialEffects) 00267 AddPlugIn(pSpecialEffects, CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00268 00269 // BfxResize * pBfxResize = new BfxResize; 00270 // if (pBfxResize) 00271 // AddPlugIn(pBfxResize, CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00272 00273 // BfxFlipAndRotate * pBfxFlipAndRotate = new BfxFlipAndRotate; 00274 // if (pBfxFlipAndRotate) 00275 // AddPlugIn(pBfxFlipAndRotate, CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00276 00277 // BfxColourDepth * pBfxColourDepth = new BfxColourDepth; 00278 // if (pBfxColourDepth) 00279 // AddPlugIn(pBfxColourDepth, CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00280 00281 return TRUE; 00282 } 00283 00284 /************************************************************************************** 00285 00286 > virtual BOOL BfxHandler::ParsePlugIn(const PathName& Path, const INT32 PathID) 00287 00288 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00289 Created: 4/3/97 00290 Inputs: Path the pathname of the file to parse 00291 PathID the id assigned to this pathname 00292 Returns: True if parsed ok and False otherwise. 00293 Purpose: Parses the specified plug-in and sees whether it is a Bfx plug-in. 00294 If so, then adds it to the list of available plug-ins, noting any useful 00295 details which will be required later. 00296 The PathID should be added to the plug-in record so that it can be 00297 translated back to the pathname at the appropriate time. 00298 00299 **************************************************************************************/ 00300 00301 BOOL BfxHandler::ParsePlugIn(const PathName& Path, const INT32 PathID) 00302 { 00303 // TRACEUSER( "Neville", _T("ParsePlugIn = %s\n"), (TCHAR*)Path.GetPath()); 00304 // They are built in and so do not need parsing 00305 00306 return TRUE; 00307 } 00308 00309 /************************************************************************************** 00310 00311 > virtual BOOL BfxHandler::AddPlugIn(PlugInItem * pPlugIn, CCRuntimeClass* pClass = CC_RUNTIME_CLASS(PlugInOp), 00312 pfnGetState gs = PlugInOp::GetState) 00313 00314 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00315 Created: 4/3/97 00316 Inputs: pPlugIn the new PlugInItem to add to the list 00317 pClass the operation handling class to use 00318 gs the GetState function to use 00319 Returns: True if worked, False otherwise 00320 Purpose: Add a plug-in to the list in the plug-in manager and register the op 00321 descriptor to the system. 00322 We override the baseclass version as we need to register an undoable 00323 operation and a normal version for each plug-in. The undoable version 00324 is used in the document. The normal version is used in the bitmap 00325 gallery. 00326 00327 **************************************************************************************/ 00328 00329 BOOL BfxHandler::AddPlugIn(PlugInItem * pPlugIn, CCRuntimeClass* pClass, pfnGetState gs) 00330 { 00331 PlugInManager* pManager = GetApplication()->GetPlugInManager(); 00332 if (pManager == NULL) 00333 return FALSE; 00334 00335 if (!pManager->AddPlugIn(pPlugIn)) 00336 ERROR2(FALSE,"Failed to register a plug-in with plug-in manager"); 00337 00338 // Make up a unique name for the plug in 00339 String_32 OpToken = GetUniqueID(); 00340 OpToken += pPlugIn->GetPlugInName(); 00341 // Register this name as an OpDescriptor to the system so that we can use it 00342 // on menus etc. 00343 if (!PlugInOp::RegisterOpToken(OpToken, pPlugIn->GetPlugInName(), pClass, gs)) 00344 ERROR2(FALSE,"Failed to register OpToken for a plug-in"); 00345 00346 //#if NEW_NATIVE_FILTER 00347 // Now do the same to register the undoable operation to the system 00348 // Make up a unique name for the plug in 00349 OpToken = GetUniqueID(); 00350 // Add the unique undo signature 00351 String_32 UndoSig(TEXT(PLUGIN_UNDO_SIG)); 00352 OpToken += UndoSig; 00353 OpToken += pPlugIn->GetPlugInName(); 00354 // Register this name as an OpDescriptor to the system so that we can use it 00355 // on menus etc. 00356 if (!PlugInUndoOp::RegisterOpToken(OpToken, pPlugIn->GetPlugInName(), CC_RUNTIME_CLASS(BfxPlugInUndoOp), BfxPlugInUndoOp::GetState)) 00357 ERROR2(FALSE,"Failed to register undo OpToken for a plug-in"); 00358 //#endif 00359 00360 // Now see if the family name is registered, if not then register it 00361 OpToken = GetUniqueID(); 00362 OpToken += pPlugIn->GetFamilyName(); 00363 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OpToken); 00364 if (pOpDesc == NULL) 00365 { 00366 // Register this name as an OpDescriptor to the system so that we can use it 00367 // on menus etc. 00368 // Use the default OpDescriptor as this will have enough functionality for tick 00369 // greying i.e. none! 00370 if (!PlugInOp::RegisterOpToken(OpToken, pPlugIn->GetFamilyName())) //, pClass, gs)) 00371 ERROR2(FALSE,"Failed to register OpToken for a plug-in family name"); 00372 } 00373 00374 // Now see if the undo version of the family name is registered, if not then register it 00375 OpToken = GetUniqueID(); 00376 OpToken += UndoSig; 00377 OpToken += pPlugIn->GetFamilyName(); 00378 pOpDesc = OpDescriptor::FindOpDescriptor(OpToken); 00379 if (pOpDesc == NULL) 00380 { 00381 // Register this name as an OpDescriptor to the system so that we can use it 00382 // on menus etc. 00383 // Use the default OpDescriptor as this will have enough functionality for tick 00384 // greying i.e. none! 00385 if (!PlugInUndoOp::RegisterOpToken(OpToken, pPlugIn->GetFamilyName(), CC_RUNTIME_CLASS(BfxPlugInUndoOp), BfxPlugInUndoOp::GetState)) 00386 ERROR2(FALSE,"Failed to register OpToken for a plug-in family name"); 00387 } 00388 00389 return TRUE; 00390 } 00391 00392 /******************************************************************************************** 00393 00394 > BOOL BfxHandler::CreateMainMenuItems(PlugInManager * pManager, MenuItem * pRootMenu, 00395 BOOL AddSeparator = FALSE) 00396 00397 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00398 Created: 4/3/97 00399 Inputs: pManager the plug-in manager to get at useful things like the plug-in list 00400 pRootMenu The root of the main menu to add the items to 00401 AddSeparator True if want a separator added to the last item on the menu 00402 Outputs: - 00403 Returns: True if the operation completed successfully 00404 False if it failed in some way. 00405 Purpose: After the plug in list has been sorted alphabetically we must add each item 00406 in the list to the main plug-in menu. This is a handler's chance to insert 00407 menu options into this menu. 00408 00409 ********************************************************************************************/ 00410 00411 BOOL BfxHandler::CreateMainMenuItems(PlugInManager * pManager, MenuItem * pRootMenu, 00412 BOOL AddSeparator) 00413 { 00414 ERROR2IF(pManager == NULL || pRootMenu == NULL,FALSE,"CreateMainMenuItems bad parameters!"); 00415 00416 //#if NEW_NATIVE_FILTER 00417 // Create a menu item for the apply last item 00418 //MenuItem * pApplyLastItem = CreateMenuItem(OPTOKEN_PLUGINS_PARSING, pRootMenu->GetMenuId(), FALSE); 00419 // If created ok then add this to the main plug-in's menu 00420 //if (pApplyLastItem) 00421 // pRootMenu->AddMenuItem(pApplyLastItem); 00422 00423 // Create the plug-ins manager menu item... 00424 MenuItem * pPlugDlgMngr = CreateMenuItem(OPTOKEN_PLUGSDLG, pRootMenu->GetMenuId(), TRUE); 00425 // If created ok then add this to the main plug-in's menu 00426 if (pPlugDlgMngr) 00427 pRootMenu->AddMenuItem(pPlugDlgMngr); 00428 00429 // Did we find the plug-in main menu item? 00430 // If we did then we need to add the plug-ins to the item 00431 String_32 OpToken; 00432 String_32 FamilyOpToken; 00433 String_32 LastFamilyOpToken; 00434 // MenuItem* pFamilyRoot = NULL; 00435 MenuItem* pFamilyRoot = pRootMenu; 00436 String_32 UndoSig(TEXT(PLUGIN_UNDO_SIG)); 00437 // Go through the list of plug-ins registered to the system and make up a 00438 // menu structure from the OpTokens that they have registered. 00439 // Assumes the plug-ins are sorted correctly on family names and then 00440 // plug-in names. 00441 PlugInItem * pPlugIn = pManager->GetFirstPlugIn(); 00442 BOOL ok = TRUE; 00443 while (pPlugIn != NULL) 00444 { 00445 // Only allow Bfx plug-ins on this menu. We are very plug-inist! 00446 if (pPlugIn->GetTypeOfPlugIn() == PLUGIN_BFX) 00447 { 00448 OpToken = pPlugIn->GetUniqueID(); 00449 FamilyOpToken = OpToken; 00450 // Add the unique undo signature 00451 OpToken += UndoSig; 00452 FamilyOpToken += UndoSig; 00453 // Now add the menu names themselves 00454 OpToken += pPlugIn->GetPlugInName(); 00455 FamilyOpToken += pPlugIn->GetFamilyName(); 00456 // check if we already have 00457 // if (FamilyOpToken != LastFamilyOpToken) 00458 // { 00459 // MenuItem * pNewFamilyItem = CreateMenuItem(FamilyOpToken, pRootMenu->GetMenuId(), FALSE); 00460 // if (pNewFamilyItem) 00461 // { 00462 // // Created ok so add this to the main plug-in's menu 00463 // ok = ok && pRootMenu->AddMenuItem(pNewFamilyItem); 00464 // // This becomes the new family root 00465 // pFamilyRoot = pNewFamilyItem; 00466 // } 00467 // } 00468 // 00469 if (pFamilyRoot) 00470 { 00471 // Create a menu item for the plug-in itself 00472 MenuItem * pNewItem = CreateMenuItem(OpToken, pFamilyRoot->GetMenuId(), FALSE); 00473 // If created ok then add this to the main plug-in's menu 00474 if (pNewItem) 00475 ok = ok && pFamilyRoot->AddMenuItem(pNewItem); 00476 } 00477 00478 LastFamilyOpToken = FamilyOpToken; 00479 } 00480 00481 pPlugIn = pManager->GetNextPlugIn(pPlugIn); 00482 } 00483 00484 00485 // Tell the last item that it should have a separator 00486 // if (pFamilyRoot != NULL && AddSeparator) 00487 // pFamilyRoot->SetIsFollowedBySeparator(TRUE); 00488 00489 //#endif 00490 return TRUE; 00491 }