plugop.cpp

Go to the documentation of this file.
00001 // $Id: plugop.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 "plugop.h"         // useful plug-in realted items
00104 //#include "plugres.h"      // _R(IDS_PLUGIN_FAMILY)
00105 
00106 #include "plugmngr.h"       // main plug-in manager
00107 //#include "app.h"          // GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED]
00108 
00109 #include "pshpop.h"         // PhotoShopContextMenu
00110 #include "bfxop.h"          // BfxContextMenu
00111 
00112 // Place any IMPLEMENT type statements here
00113 CC_IMPLEMENT_DYNAMIC(PlugInOpDescriptor, OpDescriptor);
00114 CC_IMPLEMENT_DYNCREATE(PlugInOp, Operation);
00115 CC_IMPLEMENT_MEMDUMP(PlugInsContextMenu, ContextMenu)
00116 
00117 // We want better memory tracking
00118 #define new CAM_DEBUG_NEW
00119 
00120 /********************************************************************************************
00121 
00122 >   PlugInOpDescriptor::PlugInOpDescriptor(const TCHAR* pcszToken, const String_64& NewMenuText,
00123                                            CCRuntimeClass* pClass = CC_RUNTIME_CLASS(PlugInOp),
00124                                            pfnGetState gs = PlugInOp::GetState)
00125 
00126     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00127     Created:    11/12/96
00128     Inputs:     pcszToken       the "OpToken" (OLE verb?) of the associated Operation
00129                 NewMenuText     string resource of menu text
00130                 pClass      the runtime class to use, defaults to PlugInOp.
00131                 gs          the GetState function to use
00132     Outputs:    -
00133     Returns:    -
00134     Purpose:    Constructs the new PlugInOpDescriptor
00135     Errors:     -
00136     SeeAlso:    -
00137 
00138 ********************************************************************************************/
00139 
00140 PlugInOpDescriptor::PlugInOpDescriptor(const TCHAR* pcszToken, const String_64& NewMenuText,
00141                                        CCRuntimeClass* pClass, pfnGetState gs)
00142   : OpDescriptor(   0,                          // tool ID
00143                     _R(IDS_PHOTOSHOP_PLUGIN),       // String resource ID (use same for all)
00144                     pClass, //CC_RUNTIME_CLASS(PlugInOp),   // Runtime class
00145                     (TCHAR*) pcszToken,         // OpToken
00146                     gs,                         // GetState function
00147                     NULL,                       // help ID
00148                     NULL,                       // bubble help
00149                     NULL,                       // resource ID
00150                     NULL,                       // control ID
00151                     TRUE,                       // Recieve system messages
00152                     FALSE,                      // Smart duplicate operation
00153                     TRUE,                       // Clean operation
00154                     NULL,                       // String for one copy only error
00155                     (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00156                 )
00157 {
00158     m_MenuText = NewMenuText;
00159 }
00160 
00161 /********************************************************************************************
00162 
00163 >   static OpState PlugInOpDescriptor::GetState(String_256* pDesc, OpDescriptor* pOpDesc)
00164 
00165     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00166     Created:    11/12/96
00167     Inputs:     pDesc       --- A pointer to a String. GetState fills this with the
00168                                 appropriate details for the conditions arising eg. why
00169                                 "Previous Zoom" is greyed out.
00170                 pOpDesc     --- A pointer to the OpDescriptor whose state is being
00171                                 queried.
00172     Returns:    An OpState containing the flags that show what is valid.
00173     Purpose:    Returns the state that this operation should appear in the menus 
00174                 or as a buttom, for example - greyed out, or ticked.
00175 
00176 ********************************************************************************************/
00177 
00178 OpState PlugInOpDescriptor::GetState(String_256*, OpDescriptor* pOpDesc)
00179 {
00180     // At present, this item is always available.
00181     OpState OpSt;
00182     return OpSt;
00183 }
00184 
00185 /********************************************************************************************
00186 
00187 >   virtual void PlugInOpDescriptor::GetText(String_256* Description, OpTextFlags WhichText)
00188 
00189     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00190     Created:    11/12/96
00191     Inputs:     TextFlag - Identifies which text string to retrieve from the string resource
00192     Outputs:    Description - Operation description string if it is found or
00193                 NULL otherwise.
00194     Returns:    TRUE if successfully retrieves the string and FALSE othersise.
00195     Purpose:    This function will use the TextID and ModuleID values to obtain a String
00196                 resource describing an operation. String resources may have one or more 
00197                 text descriptions in them, therefore, a TextFlag can be used to identify the
00198                 the appropriate text required.
00199     SeeAlso:    OpDescriptor::GetText
00200     SeeAlso:    GetDescription
00201 
00202     Note:       Made virtual by Neville 11/12/96
00203                 We do this so that we do not have to store a string with every OpDesciptor.
00204                 This would be ok if we had dynamic strings but of course we don't. The overhead
00205                 would be unacceptable. So we use this overriding class instead.
00206 
00207 ********************************************************************************************/
00208 
00209 BOOL PlugInOpDescriptor::GetText(String_256* Description, OpTextFlags WhichText)
00210 {
00211     String_256 ResourceText = m_MenuText; // ( TextID, ModuleID );
00212     // This string should contain various elements for each part of the apply, undo, redo text
00213     // each separated by a semi colon. So we will fake this up in the string using the
00214     // text that we will have set, which is the plug-in name on the menu, for the apply name. 
00215     ResourceText += ";";            // DO NOT internationlise this!
00216     ResourceText += m_MenuText;     // add undo text
00217     ResourceText += ";";            // DO NOT internationlise this!
00218     ResourceText += m_MenuText;     // add redo text
00219 
00220     TCHAR* ok = NULL;
00221 
00222     // The rest is the same as the main OpDescriptor...
00223 
00224     // Explicitly cast return value from GetDescription from a TCHAR* to a String_256
00225     ok = GetDescription((TCHAR*) ResourceText, WhichText);
00226     
00227     // if description is found then return true else return false
00228     if (ok)        
00229     {
00230         *Description = String_256(ok);
00231         return TRUE;
00232     }
00233     else
00234         return FALSE;
00235 } 
00236 
00237 /********************************************************************************************
00239 ********************************************************************************************/
00240 
00241 /********************************************************************************************
00242 
00243 >   PlugInOp::PlugInOp()
00244 
00245     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00246     Created:    11/12/96
00247     Inputs:
00248     Outputs:
00249     Returns:
00250     Purpose:    Constructor for PlugInOp operation. It is not undoable.
00251     Errors:     None
00252 
00253 ********************************************************************************************/
00254 
00255 PlugInOp::PlugInOp()
00256 {
00257 }
00258 
00259 /********************************************************************************************
00260 
00261 >   static BOOL PlugInOp::Init()
00262 
00263     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00264     Created:    11/12/96
00265     Returns:    TRUE if the Op was started ok
00266     Purpose:    Creates all the opDescriptors that call this operation.
00267 
00268 ********************************************************************************************/
00269 
00270 BOOL PlugInOp::Init()
00271 {
00272     BOOL ok = TRUE;
00273     // Set up some standard operations
00274     ok = ok && RegisterOpToken(OPTOKEN_PLUGINS, _R(IDS_PLUGINS));
00275 //  ok = ok && RegisterOpToken(OPTOKEN_PHOTOSHOP_PLUGINS, _R(IDS_PHOTOSHOP_PLUGINS));
00276 //  ok = ok && RegisterOpToken(OPTOKEN_PHOTOSHOP_APPLYLAST, _R(IDS_PHOTOSHOP_APPLYLAST));
00277 
00278 //  ok = ok && RegisterOpToken(OPTOKEN_PLUGINONE, _R(IDS_PLUGIN_ONE));
00279 //  ok = ok && RegisterOpToken(OPTOKEN_PLUGINTWO, _R(IDS_PLUGIN_TWO));
00280 //  ok = ok && RegisterOpToken(OPTOKEN_PLUGINTHREE, _R(IDS_PLUGIN_THREE));
00281     return ok;
00282 }
00283 
00284 /********************************************************************************************
00285 
00286 >   static BOOL PlugInOp::RegisterOpToken(TCHAR *OpToken, const String_64& NewMenuText,
00287                                           CCRuntimeClass* pClass = CC_RUNTIME_CLASS(PlugInOp))
00288 
00289     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00290     Created:    11/12/96
00291     Inputs:     OpToken     the OpToken for the operation
00292                 NewMenuText the text for the menu item for this operation
00293                 pClass      the runtime class to use, defaults to PlugInOp.
00294                 gs          the GetState function to use
00295     Returns:    TRUE if the Op was registered ok
00296     Purpose:    Allows OpDescriptors to be defined to the operation system.
00297 
00298 ********************************************************************************************/
00299 
00300 BOOL PlugInOp::RegisterOpToken(TCHAR *OpToken, const String_64& NewMenuText,
00301                                CCRuntimeClass* pClass, pfnGetState gs)
00302 {
00303     // Try to create the OpDescriptor
00304     PlugInOpDescriptor* pOpDesc = new PlugInOpDescriptor(OpToken, NewMenuText, pClass, gs);
00305     if (pOpDesc == NULL)
00306         return FALSE;
00307 
00308     return TRUE;
00309 }
00310 
00311 /********************************************************************************************
00312 
00313 >   static BOOL PlugInOp::RegisterOpToken(TCHAR *OpToken, UINT32 MenuTextID,
00314                                           CCRuntimeClass* pClass = CC_RUNTIME_CLASS(PlugInOp),
00315                                           pfnGetState gs = PlugInOp::GetState)
00316 
00317     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00318     Created:    11/12/96
00319     Inputs:     OpToken     the OpToken for the operation
00320                 MenuTextId  the text for the menu item for this operation
00321                 pClass      the runtime class to use, defaults to PlugInOp.
00322                 gs          the GetState function to use
00323     Returns:    TRUE if the Op was registered ok
00324     Purpose:    Allows OpDescriptors to be defined to the operation system.
00325 
00326 ********************************************************************************************/
00327 
00328 BOOL PlugInOp::RegisterOpToken(TCHAR *OpToken, UINT32 MenuTextID, CCRuntimeClass* pClass,
00329                                pfnGetState gs)
00330 {
00331     // register some option descriptors
00332     if (!Operation::RegisterOpDescriptor(
00333                         0,                          // Tool ID
00334                         MenuTextID,                 // String resource ID
00335                         pClass, //CC_RUNTIME_CLASS(PlugInOp),   // Runtime class
00336                         OpToken,                    // Token string
00337                         gs,                         // GetState function
00338                         NULL,                       // help ID
00339                         NULL,                       // bubble help
00340                         NULL,                       // resource ID
00341                         NULL,                       // control ID
00342                         SYSTEMBAR_ILLEGAL,          // Bar ID
00343                         TRUE,                       // Recieve system messages
00344                         FALSE,                      // Smart duplicate operation
00345                         TRUE,                       // Clean operation
00346                         NULL,                       // No vertical counterpart
00347                         NULL,                       // String for one copy only error
00348                         (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00349                         ))
00350         return FALSE;
00351 
00352     return TRUE;
00353 }
00354 
00355 /********************************************************************************************
00356 
00357 >   static OpState PlugInOp::GetState(String_256*, OpDescriptor*)
00358 
00359     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00360     Created:    11/12/96
00361     Inputs:     
00362     Outputs:    String - if MenuItem is enabled Then return the name of the operation to 
00363                             be undone Else return the reason why it is disabled
00364     Returns:    OpState the state of the operation
00365     Purpose:    To provide greying and ticking functionality for the
00366                 operation.
00367     Errors:     None
00368 
00369 ********************************************************************************************/
00370 
00371 OpState PlugInOp::GetState(String_256*, OpDescriptor* OpDesc)
00372 {
00373     // At present, this item is always available.
00374     OpState OpSt;
00375     return OpSt;
00376 }
00377 
00378 /********************************************************************************************
00379 
00380 >   virtual void PlugInOp::Do(OpDescriptor*)
00381 
00382     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00383     Created:    11/12/96
00384     Inputs:     pOpDesc     the OpDescriptor of the item to invoke
00385     Outputs:    None
00386     Returns:    None
00387     Purpose:    Invokes the plug-in specified by the OpDescriptor.
00388     Errors:     if no OpDescriptor is supplied
00389 
00390 ********************************************************************************************/
00391 
00392 void PlugInOp::Do(OpDescriptor* pOpDesc)
00393 {
00394     if (pOpDesc == NULL)
00395     {
00396         ERROR3IF(pOpDesc == NULL,"PlugInOp::Do null OpDescriptor");
00397         return;
00398     }
00399     //ERROR3("PlugInOp - do");
00400 
00401     // Search the plug-ins list for the specified plug-in and invoke it
00402     PlugInManager* pManager = GetApplication()->GetPlugInManager();
00403     if (pManager == NULL)
00404         return;
00405 
00406     PlugInItem * pPlugIn = pManager->GetFirstPlugIn();
00407     String_32 OpToken;
00408     while (pPlugIn)
00409     {
00410         OpToken = pPlugIn->GetUniqueID();
00411         OpToken += pPlugIn->GetPlugInName();
00412         if (pOpDesc->Token == OpToken)
00413             pPlugIn->About();
00414 
00415         pPlugIn = pManager->GetNextPlugIn(pPlugIn);
00416     }
00417 
00418     // and finish
00419     End();
00420 }
00421 
00422 
00423 /********************************************************************************************
00425 ********************************************************************************************/
00426 
00427 
00428 /********************************************************************************************
00429 
00430 >   PlugInsContextMenu::PlugInsContextMenu()
00431 
00432     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00433     Created:    11/12/96
00434 
00435     Inputs:     -
00436     Outputs:    -
00437     Purpose:    To construct ;-)
00438 
00439 ********************************************************************************************/
00440 
00441 PlugInsContextMenu::PlugInsContextMenu()
00442 {
00443     // As we are just about to invoke UI, check that the plug-in manager has its list
00444     // of available plug-ins otherwise, go and get it now as we are just about to need it.
00445     /* PlugInManager* pManager = GetApplication()->GetPlugInManager();
00446     if (pManager)
00447         pManager->CheckHaveDetailsOnPlugIns(); */
00448 }
00449 
00450 /********************************************************************************************
00451 
00452 >   PlugInsContextMenu::PlugInsContextMenu()
00453 
00454     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00455     Created:    5/3/97
00456     Inputs:     pBitmap     the bitmap to apply the effect to
00457                 pDocument   the document the bitmap is stored in
00458     Outputs:    -
00459     Purpose:    Default constructer.
00460 
00461 ********************************************************************************************/
00462 
00463 PlugInsContextMenu::PlugInsContextMenu(KernelBitmap* pBitmap, Document * pDocument)
00464 {
00465     // remember them for later use
00466     m_pBitmap = pBitmap;
00467     m_pDocument = pDocument;
00468 
00469     // As we are just about to invoke UI, check that the plug-in manager has its list
00470     // of available plug-ins otherwise, go and get it now as we are just about to need it.
00471     /* PlugInManager* pManager = GetApplication()->GetPlugInManager();
00472     if (pManager)
00473         pManager->CheckHaveDetailsOnPlugIns(); */
00474 }
00475 
00476 /********************************************************************************************
00477 
00478 >   virtual BOOL PlugInsContextMenu::Build(void)
00479 
00480     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00481     Created:    11/12/96
00482     Returns:    TRUE if menu built OK
00483                 FALSE (and sets error) otherwise
00484     Purpose:    To build the Plug-ins pop-up menu.
00485 
00486 ********************************************************************************************/
00487 
00488 BOOL PlugInsContextMenu::Build()
00489 {
00490     return PlugInsContextMenu::BuildMenu(m_pBitmap, m_pDocument, this);
00491 }
00492 
00493 /********************************************************************************************
00494 
00495 >   static BOOL PlugInsContextMenu::BuildMenu(KernelBitmap * pBitmap, Document * pDocument,
00496                                               ContextMenu * pContextMenu, MenuItem * pMainRoot = NULL,
00497                                               BOOL AddSeparator = FALSE, BOOL UseUndoable = FALSE)
00498 
00499     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00500     Created:    4/3/97
00501     Inputs:     pBitmap         bitmap the effect is to be applied to
00502                 pDocument       the document the bitmap is in
00503                 pContextMenu    the menu we want to add to
00504                 pMainRoot       the root menu to add this menu to, defaults to no parent
00505                 AddSeparator    True if want a separator added to the last item on the menu
00506                 UseUndoable     True if want the undoable operations instead of the non-undoable
00507                                 Defaults to False
00508     Returns:    TRUE if menu built OK
00509                 FALSE (and sets error) otherwise
00510     Purpose:    To build the a plug-ins pop-up menu either directly or tacked on
00511                 as a sub-menu item to the specified pMainRoot. At present, this is the pop-ups
00512                 that appear over the bitmap gallery and so are very bitmap related.
00513 
00514 ********************************************************************************************/
00515 
00516 BOOL PlugInsContextMenu::BuildMenu(KernelBitmap * pBitmap, Document * pDocument,
00517                                    ContextMenu * pContextMenu, MenuItem * pMainRoot,
00518                                    BOOL AddSeparator, BOOL UseUndoable)
00519 {
00520     ERROR2IF(pContextMenu == NULL,FALSE,"PlugInsContextMenu::BuildMenu null ContextMenu to add to");
00521 
00522     BOOL ok = TRUE;
00523 
00524     // As we are just about to invoke UI, check that the plug-in manager has its list
00525     // of available plug-ins otherwise, go and get it now as we are just about to need it.
00526 //  PlugInManager* pManager = GetApplication()->GetPlugInManager();
00527 //  if (pManager)
00528 //      pManager->CheckHaveDetailsOnPlugIns();
00529 
00530 //#ifndef WEBSTER
00531 //#ifndef EXCLUDE_BFX
00532 //  ok = ok && BfxPlugInContextMenu::BuildMenu(pBitmap, pDocument, pContextMenu, pMainRoot, TRUE, UseUndoable);
00533 //#endif
00534 //#endif // WEBSTER
00535 //  ok = ok && PhotoShopContextMenu::BuildMenu(pBitmap, pDocument, pContextMenu, pMainRoot, FALSE, UseUndoable);
00536 
00537     ok = ok && BfxPlugInContextMenu::BuildMenu(pBitmap, pDocument, pContextMenu, pMainRoot, TRUE, UseUndoable);
00538     
00539     return ok;
00540 }
00541 
00542 /********************************************************************************************
00543 ********************************************************************************************/

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