00001 // $Id: bfxop.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 00103 #include "bfxop.h" // useful BFX plug-in related operations 00104 //#include "plugres.h" // _R(IDS_PLUGIN_FAMILY) 00105 00106 #include "plugmngr.h" // main plug-in manager 00107 #include "bfxitem.h" // useful Bfx plug-in related items 00108 //#include "app.h" // GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED] 00109 00110 //#include "bitmap.h" // KernelBitmap - in camtypes.h [AUTOMATICALLY REMOVED] 00111 #include "menuitem.h" // MenuItem 00112 00113 // Place any IMPLEMENT type statements here 00114 CC_IMPLEMENT_DYNCREATE(BfxPlugInOp, PlugInOp); 00115 CC_IMPLEMENT_MEMDUMP(BfxPlugInContextMenu, PlugInsContextMenu) 00116 00117 // We want better memory tracking 00118 #define new CAM_DEBUG_NEW 00119 00120 // Set up our statics 00121 KernelBitmap* BfxPlugInOp::m_pBitmap = NULL; 00122 Document* BfxPlugInOp::m_pDocument = NULL; 00123 00124 /******************************************************************************************** 00125 00126 > BfxPlugInOp::BfxPlugInOp() 00127 00128 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00129 Created: 4/3/97 00130 Inputs: 00131 Outputs: 00132 Returns: 00133 Purpose: Constructor for BfxPlugInOp operation. It is not undoable. 00134 Errors: None 00135 00136 ********************************************************************************************/ 00137 00138 BfxPlugInOp::BfxPlugInOp() 00139 { 00140 } 00141 00142 /******************************************************************************************** 00143 00144 > static BOOL BfxPlugInOp::Init() 00145 00146 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00147 Created: 4/3/97 00148 Returns: TRUE if the Op was started ok 00149 Purpose: Creates all the opDescriptors that call this operation. 00150 00151 ********************************************************************************************/ 00152 00153 BOOL BfxPlugInOp::Init() 00154 { 00155 BOOL ok = TRUE; 00156 // Set up some standard operations 00157 /* ok = ok && RegisterOpToken(OPTOKEN_Bfx_PLUGINS, _R(IDS_Bfx_PLUGINS), 00158 CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00159 ok = ok && RegisterOpToken(OPTOKEN_Bfx_APPLYLAST, _R(IDS_Bfx_APPLYLAST), 00160 CC_RUNTIME_CLASS(BfxPlugInOp), BfxPlugInOp::GetState); 00161 */ 00162 return ok; 00163 } 00164 00165 /******************************************************************************************** 00166 00167 > static BOOL BfxPlugInOp::CheckBitmapWithPlugIn(const String_256& OpName, 00168 BOOL IncludeUniqueName = TRUE, 00169 BOOL IncludeUndoAbleSig = FALSE) 00170 00171 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00172 Created: 4/3/97 00173 Inputs: OpName - the name of the OpToken being requested. 00174 IncludeUniqueName - Set to True (Default) if want the 00175 unique name of the plug-in added to the OpToken 00176 IncludeUndoAbleSig - Set to True is want the unique undoable 00177 sig added to the OpToken. (Default = FALSE.) 00178 Returns: True if the item is ok with the plug-in, False otherwise 00179 Purpose: To ask the plug-in which matches the OpName whether the 00180 bitmap is ok. 00181 Assumes only working on Bfx plug-ins. Not that this should 00182 make much difference at present. 00183 Errors: None 00184 00185 ********************************************************************************************/ 00186 00187 BOOL BfxPlugInOp::CheckBitmapWithPlugIn(const String_256& OpName, BOOL IncludeUniqueName, 00188 BOOL IncludeUndoAbleSig) 00189 { 00190 // If no bitmap then always return False 00191 if (m_pBitmap == NULL) 00192 return FALSE; 00193 00194 // Search the plug-ins list for the specified plug-in and check 00195 // that this colour depth is ok with it 00196 INT32 ColourDepth = m_pBitmap->GetBPP(); 00197 BOOL GreyScale = m_pBitmap->IsGreyscale(); 00198 PlugInManager* pManager = GetApplication()->GetPlugInManager(); 00199 if (pManager) 00200 { 00201 PlugInItem * pPlugIn = pManager->GetFirstPlugIn(); 00202 String_32 OpToken; 00203 // Add the unique undo signature 00204 String_32 UndoSig(TEXT(PLUGIN_UNDO_SIG)); 00205 while (pPlugIn) 00206 { 00207 // If we are to include the unique name in the test then do so 00208 if (IncludeUniqueName) 00209 OpToken = pPlugIn->GetUniqueID(); 00210 else 00211 OpToken.Empty(); 00212 if (IncludeUndoAbleSig) 00213 OpToken += UndoSig; 00214 OpToken += pPlugIn->GetPlugInName(); 00215 if (OpName == OpToken) 00216 { 00217 // Ask the plug-in item whether it likes this colour depth 00218 // Returns True if likes it, False otherwise, so we must negate this to 00219 // set the greyed state. 00220 return pPlugIn->IsBitmapModeOk(ColourDepth, GreyScale); 00221 } 00222 00223 pPlugIn = pManager->GetNextPlugIn(pPlugIn); 00224 } 00225 } 00226 00227 // Cannot find plug-in so return False 00228 return FALSE; 00229 } 00230 00231 /******************************************************************************************** 00232 00233 > static OpState BfxPlugInOp::GetState(String_256* pDesc, OpDescriptor* pOpDesc) 00234 00235 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00236 Created: 4/3/97 00237 Inputs: pOpDesc - the OpDescriptor being used. 00238 Outputs: pDesc - if MenuItem is enabled Then return the name of the operation to 00239 be undone Else return the reason why it is disabled 00240 Returns: OpState the state of the operation 00241 Purpose: To provide greying and ticking functionality for the 00242 operation. 00243 Assumes only working on Bfx plug-ins. Not that this should 00244 make much difference at present. 00245 Errors: None 00246 00247 ********************************************************************************************/ 00248 00249 OpState BfxPlugInOp::GetState(String_256* pDesc, OpDescriptor* pOpDesc) 00250 { 00251 // At present, this item is always available unless there is 00252 // no bitmap and document to apply it to. 00253 OpState OpSt; 00254 if (m_pBitmap == NULL || m_pDocument == NULL) 00255 OpSt.Greyed = TRUE; 00256 00257 if (m_pBitmap) 00258 { 00259 // If there is a bitmap then we are always available 00260 OpSt.Greyed = FALSE; 00261 00262 /* // If we have a valid bitmap then checks that it is of the correct type 00263 INT32 ColourDepth = m_pBitmap->GetBPP(); 00264 00265 // Only allow bitmaps of 24bpp or of 8bpp greyscale 00266 if (ColourDepth == 24 || (ColourDepth == 8 && m_pBitmap->IsGreyscale())) 00267 { 00268 // Check the bitmap depth with the plug-in itself 00269 // Returns True if likes it, False otherwise, so we must negate this to 00270 // set the greyed state. 00271 OpSt.Greyed = !CheckBitmapWithPlugIn(pOpDesc->Token); 00272 } 00273 else 00274 OpSt.Greyed = TRUE; 00275 */ 00276 } 00277 00278 return OpSt; 00279 } 00280 00281 /******************************************************************************************** 00282 00283 > void BfxPlugInOp::Do(OpDescriptor*) 00284 00285 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00286 Created: 4/3/97 00287 Inputs: pOpDesc the OpDescriptor of the item to invoke 00288 Outputs: None 00289 Returns: None 00290 Purpose: Invokes the plug-in specified by the OpDescriptor. 00291 Errors: if no OpDescriptor is supplied 00292 00293 ********************************************************************************************/ 00294 00295 void BfxPlugInOp::Do(OpDescriptor* pOpDesc) 00296 { 00297 if (pOpDesc == NULL || m_pBitmap == NULL || m_pDocument == NULL) 00298 { 00299 ERROR3("BfxPlugInOp::Do null OpDescriptor/bitmap/document"); 00300 FailAndExecute(); 00301 End(); 00302 return; 00303 } 00304 //ERROR3("PlugInOp - do"); 00305 00306 // Search the plug-ins list for the specified plug-in and invoke it 00307 PlugInManager* pManager = GetApplication()->GetPlugInManager(); 00308 if (pManager == NULL) 00309 return; 00310 00311 PlugInItem * pPlugIn = pManager->GetFirstPlugIn(); 00312 00313 String_32 OpToken; 00314 while (pPlugIn) 00315 { 00316 OpToken = pPlugIn->GetUniqueID(); 00317 OpToken += pPlugIn->GetPlugInName(); 00318 if (pOpDesc->Token == OpToken) 00319 { 00320 BOOL ok = pPlugIn->Apply(m_pBitmap, m_pDocument); 00321 if (!ok) 00322 { 00323 FailAndExecute(); 00324 } 00325 00326 // and finish as we have done our work 00327 End(); 00328 return; 00329 } 00330 00331 pPlugIn = pManager->GetNextPlugIn(pPlugIn); 00332 } 00333 00334 // We must have failed to find the plug-in operation so fail and finish 00335 ERROR3("BfxPlugInOp::Do Failed to find plug-in operation"); 00336 FailAndExecute(); 00337 End(); 00338 } 00339 00340 /******************************************************************************************** 00341 00342 > static BOOL BfxPlugInOp::SetBitmapAndDocument(KernelBitmap* pBitmap, Document * pDocument) 00343 00344 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00345 Created: 4/3/97 00346 Inputs: pBitmap the bitmap to apply the effect to 00347 pDocument the document the bitmap is stored in 00348 Purpose: Provides the parameters that the operation will apply to. 00349 00350 ********************************************************************************************/ 00351 00352 BOOL BfxPlugInOp::SetBitmapAndDocument(KernelBitmap* pBitmap, Document * pDocument) 00353 { 00354 m_pBitmap = pBitmap; 00355 m_pDocument = pDocument; 00356 return TRUE; 00357 } 00358 00359 /******************************************************************************************** 00360 // BfxPlugInContextMenu 00361 ********************************************************************************************/ 00362 00363 /******************************************************************************************** 00364 00365 > BfxPlugInContextMenu::BfxPlugInContextMenu() 00366 00367 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00368 Created: 4/3/97 00369 Inputs: pBitmap the bitmap to apply the effect to 00370 pDocument the document the bitmap is stored in 00371 Outputs: - 00372 Purpose: Default constructer. 00373 00374 ********************************************************************************************/ 00375 00376 BfxPlugInContextMenu::BfxPlugInContextMenu(KernelBitmap* pBitmap, Document * pDocument) 00377 { 00378 BfxPlugInOp::SetBitmapAndDocument(pBitmap, pDocument); 00379 00380 // remember them for later use 00381 m_pBitmap = pBitmap; 00382 m_pDocument = pDocument; 00383 00384 } 00385 00386 /******************************************************************************************** 00387 00388 > virtual BOOL BfxPlugInContextMenu::Build(void) 00389 00390 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00391 Created: 4/3/97 00392 Returns: TRUE if menu built OK 00393 FALSE (and sets error) otherwise 00394 Purpose: To build the Bfx plug-ins pop-up menu. 00395 00396 ********************************************************************************************/ 00397 00398 BOOL BfxPlugInContextMenu::Build() 00399 { 00400 return BfxPlugInContextMenu::BuildMenu(m_pBitmap, m_pDocument, this); 00401 } 00402 00403 /******************************************************************************************** 00404 00405 > static BOOL BfxPlugInContextMenu::BuildMenu(KernelBitmap * pBitmap, Document * pDocument, 00406 ContextMenu * pContextMenu, MenuItem * pMainRoot = NULL, 00407 BOOL AddSeparator = FALSE, BOOL UseUndoable = FALSE) 00408 00409 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00410 Created: 4/3/97 00411 Inputs: pBitmap bitmap the effect is to be applied to 00412 pDocument the document the bitmap is in 00413 pContextMenu the menu we want to add to 00414 pMainRoot the root menu to add this menu to, defaults to no parent 00415 AddSeparator True if want a separator added to the last item on the menu 00416 UseUndoable True if want the undoable operations instead of the non-undoable 00417 Defaults to False 00418 Returns: TRUE if menu built OK 00419 FALSE (and sets error) otherwise 00420 Purpose: To build the a Bfx plug-ins pop-up menu either directly or tacked on 00421 as a sub-menu item to the specified pMainRoot. 00422 00423 ********************************************************************************************/ 00424 00425 BOOL BfxPlugInContextMenu::BuildMenu(KernelBitmap * pBitmap, Document * pDocument, 00426 ContextMenu * pContextMenu, MenuItem * pMainRoot, 00427 BOOL AddSeparator, BOOL UseUndoable) 00428 { 00429 ERROR2IF(pContextMenu == NULL,FALSE,"BfxPlugInContextMenu::BuildMenu null ContextMenu to add to"); 00430 00431 // Inform the Bfx operation what bitmap and document it will be working on 00432 BfxPlugInOp::SetBitmapAndDocument(pBitmap, pDocument); 00433 00434 BOOL ok = TRUE; 00435 // In the non-undoable case we require the bitmap and document pointers. 00436 // In the undoable case these will be null. 00437 if ((pBitmap != NULL && pDocument != NULL) || UseUndoable) 00438 { 00439 //ok = ok && pContextMenu->BuildCommand(OPTOKEN_Bfx_APPLYLAST, TRUE, pMainRoot); 00440 00441 PlugInManager* pManager = GetApplication()->GetPlugInManager(); 00442 if (pManager != NULL) 00443 { 00444 String_32 OpToken; 00445 String_32 FamilyOpToken; 00446 String_32 LastFamilyOpToken; 00447 MenuItem* pFamilyRoot = NULL; 00448 // Add the unique undo signature 00449 String_32 UndoSig(TEXT(PLUGIN_UNDO_SIG)); 00450 // Go through the list of plug-ins registered to the system and make up a 00451 // menu structure from the OpTokens that they have registered. 00452 // Assumes the plug-ins are sorted correctly on family names and then 00453 // plug-in names. 00454 PlugInItem * pPlugIn = pManager->GetFirstPlugIn(); 00455 while (pPlugIn) 00456 { 00457 // Only allow Bfx plug-ins on this menu. We are very plug-inist! 00458 if (pPlugIn->GetTypeOfPlugIn() == PLUGIN_BFX) 00459 { 00460 OpToken = pPlugIn->GetUniqueID(); 00461 if (UseUndoable) 00462 OpToken += UndoSig; 00463 FamilyOpToken = OpToken; 00464 OpToken += pPlugIn->GetPlugInName(); 00465 FamilyOpToken += pPlugIn->GetFamilyName(); 00466 // check if we already have 00467 // if (FamilyOpToken != LastFamilyOpToken) 00468 // { 00469 // ok = ok && pContextMenu->BuildCommand(FamilyOpToken, FALSE, pMainRoot); 00470 // pFamilyRoot = pContextMenu->GetLastItem(); 00471 // } 00472 // ok = ok && pContextMenu->BuildCommand(OpToken, FALSE, pFamilyRoot); 00473 ok = ok && pContextMenu->BuildCommand(OpToken, FALSE, pMainRoot); 00474 00475 LastFamilyOpToken = FamilyOpToken; 00476 } 00477 00478 // Go to the next plug-in in the list 00479 pPlugIn = pManager->GetNextPlugIn(pPlugIn); 00480 } 00481 00482 // Tell the last item that it should have a separator 00483 if (pFamilyRoot != NULL && AddSeparator) 00484 pFamilyRoot->SetIsFollowedBySeparator(TRUE); 00485 } 00486 } 00487 00488 return ok; 00489 }