contmenu.cpp

Go to the documentation of this file.
00001 // $Id: contmenu.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 // Class that represents pop-up menus in the kernel
00100 //
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 #include "contmenu.h"
00106 #include "menuitem.h"
00107 #include "oilmenus.h"
00108 #include "menupref.h"
00109 #include "cutop.h"
00110 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "effects_stack.h"
00112 #include "opliveeffects.h"
00113 
00114 // This is not compulsory, but you may as well put it in so that the correct version
00115 // of your file can be registered in the .exe
00116 DECLARE_SOURCE("$Revision: 1282 $");
00117 
00118 // An implement to match the Declare in the .h file.
00119 // If you have many classes, it is recommended to place them all together, here at the start of the file
00120 CC_IMPLEMENT_MEMDUMP(ContextMenu, CC_CLASS_MEMDUMP)
00121 
00122 // This will get Camelot to display the filename and linenumber of any memory allocations
00123 // that are not released at program exit
00124 #define new CAM_DEBUG_NEW
00125 
00126 
00127 
00128 ContextMenu* ContextMenu::pCurrentMenu = NULL;
00129 
00130 /********************************************************************************************
00131 
00132 >   ContextMenu::ContextMenu()
00133 
00134     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00135     Created:    13/03/95
00136     Inputs:     -
00137     Outputs:    -
00138     Returns:    TRUE
00139                 FALSE
00140     Purpose:    
00141     Errors:     -
00142 
00143 ********************************************************************************************/
00144 
00145 ContextMenu::ContextMenu()
00146 {
00147     pRootItem = NULL;
00148     pLastItem = NULL;
00149     AutoIDStash = 0;
00150 }
00151 
00152 
00153 
00154 
00155 /********************************************************************************************
00156 
00157 >   ContextMenu::~ContextMenu()
00158 
00159     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00160     Created:    13/03/95
00161     Inputs:     -
00162     Outputs:    -
00163     Returns:    TRUE
00164                 FALSE
00165     Purpose:    
00166     Errors:     -
00167 
00168 ********************************************************************************************/
00169 
00170 ContextMenu::~ContextMenu()
00171 {
00172 }
00173 
00174 
00175 
00176 
00177 /********************************************************************************************
00178 
00179 >   BOOL ContextMenu::Show()
00180 
00181     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00182     Created:    13/03/95
00183     Inputs:     -
00184     Outputs:    -
00185     Returns:    TRUE
00186                 FALSE
00187     Purpose:    
00188     Errors:     -
00189 
00190 ********************************************************************************************/
00191 
00192 BOOL ContextMenu::Show()
00193 {
00194     // If there's a menu still around for some reason, get rid of it.
00195     if (pCurrentMenu)
00196     {
00197         pCurrentMenu->Hide();
00198     }
00199 
00200     // Preserve current ID generator state
00201     AutoIDStash = MenuItem::GetAutomaticIDState();
00202 
00203     // Make a new root item
00204     pRootItem = new MenuItem("CONTEXT");
00205     if (pRootItem)
00206     {
00207         // OK, make this menu current and try to build it's contents
00208         pCurrentMenu=this;
00209         if (Build())
00210         {
00211             // Kernel menu built OK so create the OILy part of it...
00212             CreateContextMenu(pRootItem);
00213             return TRUE;
00214         }
00215     }
00216 
00217     // Failed to completely build Kernel menu structure so delete anything
00218     // that might have been built...
00219     Hide();
00220     return FALSE;
00221 }
00222 
00223 
00224 
00225 
00226 /********************************************************************************************
00227 
00228 >   BOOL ContextMenu::ShowOverView(Spread* pSpread, DocCoord ClickPos, ClickModifiers ClickMods)
00229 
00230     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00231     Created:    13/03/95
00232     Inputs:     -
00233     Outputs:    -
00234     Returns:    TRUE
00235                 FALSE
00236     Purpose:    This function does the same job as ShowMenu but unfortunately needs some
00237                 parameters to pass on to the menu builders. Not very neat, I know...
00238     Errors:     -
00239 
00240 ********************************************************************************************/
00241 
00242 BOOL ContextMenu::ShowOverView(Spread* pSpread, DocCoord ClickPos, ClickModifiers ClickMods)
00243 {
00244     // If there's a menu still around for some reason, get rid of it.
00245     if (pCurrentMenu)
00246     {
00247         pCurrentMenu->Hide();
00248     }
00249 
00250     // Preserve current ID generator state
00251     AutoIDStash = MenuItem::GetAutomaticIDState();
00252 
00253     // Make a new root item
00254     pRootItem = new MenuItem("CONTEXT");
00255     if (pRootItem)
00256     {
00257         // OK, make this menu current and try to build it's contents
00258         pCurrentMenu=this;
00259         if (BuildOverView(pSpread, ClickPos, ClickMods))
00260         {
00261             // Kernel menu built OK so create the OILy part of it...
00262             CreateContextMenu(pRootItem);
00263             return TRUE;
00264         }
00265     }
00266 
00267     // Failed to completely build Kernel menu structure so delete anything
00268     // that might have been built...
00269     Hide();
00270     return FALSE;
00271 }
00272 
00273 
00274 
00275 
00276 /********************************************************************************************
00277 
00278 >   BOOL ContextMenu::Hide()
00279 
00280     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00281     Created:    13/03/95
00282     Inputs:     -
00283     Outputs:    -
00284     Returns:    TRUE
00285                 FALSE
00286     Purpose:    Close and delete any context menu that may be open.
00287     Errors:     -
00288 
00289 ********************************************************************************************/
00290 
00291 BOOL ContextMenu::Hide()
00292 {
00293     DestroyContextMenu();
00294 
00295     // Restore ID generator state
00296     MenuItem::SetAutomaticIDState(AutoIDStash);
00297     AutoIDStash = 0;
00298 
00299     if (pCurrentMenu==this)
00300         pCurrentMenu = NULL;
00301 
00302     delete this;
00303     return TRUE;
00304 }
00305 
00306 
00307 
00308 
00309 /********************************************************************************************
00310 
00311 >   static BOOL ContextMenu::HideCurrent()
00312 
00313     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00314     Created:    28/10/95
00315     Inputs:     -
00316     Outputs:    -
00317     Returns:    TRUE
00318                 FALSE
00319     Purpose:    Close and delete the current context menu if it's open.
00320     Errors:     -
00321 
00322 ********************************************************************************************/
00323 
00324 BOOL ContextMenu::HideCurrent()
00325 {
00326     if (pCurrentMenu)
00327         pCurrentMenu->Hide();
00328     return TRUE;
00329 }
00330 
00331 
00332 
00333 
00334 /********************************************************************************************
00335 
00336 >   BOOL ContextMenu::Build()
00337 
00338     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00339     Created:    13/03/95
00340     Inputs:     pRootMenu   Pointer to root menu item to add new items to.
00341     Outputs:    -
00342     Returns:    TRUE if menu built OK
00343                 FALSE (and sets error) otherwise
00344     Purpose:    Base class implementation of menu builder.
00345                 This function builds a menu statically by creating the appropriate objects.
00346                 It does NOT call teh menu script interpreter because I am unhappy about the
00347                 reliability of repeatedly calling that code.
00348 
00349                 An overloaded version of this function could be written which takes in a
00350                 reference to a "file" to be opened and interpreted.
00351 
00352                 Note also that by building the menu programmatically it can change depending
00353                 on the context within which it is opened...
00354 
00355                 The standard layout for pop-up menus is:
00356                     Clicked object's primary commands
00357                     Transfer commands
00358                     Other commands supported by the clicked object
00359                     The "What's this?" command
00360                     The Properties... command
00361                 These are only guidelines and you can omit any sections you don't need.
00362 
00363                 To implement an overriden version of this function you simply need to make it
00364                 add new menu items to the root menu. There are helper functions to make this
00365                 easier:
00366                     BuildTransferCommands will add Cut,Copy,Paste,etc.
00367                     BuildCommand will take any OPTOKEN you give it and build an item linked
00368                         to that OPTOKEN.
00369     Errors:     -
00370 
00371 ********************************************************************************************/
00372 
00373 BOOL ContextMenu::Build()
00374 {
00375     ERROR2(FALSE,"ContextMenu::Build called in base class - should be overridden!");
00376 }
00377 
00378 
00379 
00380 
00381 /********************************************************************************************
00382 
00383 >   BOOL ContextMenu::BuildOverView(Spread* pSpread, DocCoord ClickPos, ClickModifiers ClickMods)
00384 
00385     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00386     Created:    13/03/95
00387     Inputs:     pRootMenu   Pointer to root menu item to add new items to.
00388     Outputs:    -
00389     Returns:    TRUE if menu built OK
00390                 FALSE (and sets error) otherwise
00391     Purpose:    Base class function which, when overridden in derived classes, will build
00392                 a pop-up menu according to a given position in a view.
00393     Errors:     -
00394 
00395 ********************************************************************************************/
00396 
00397 BOOL ContextMenu::BuildOverView(Spread* pSpread, DocCoord ClickPos, ClickModifiers ClickMods)
00398 {
00399     ERROR2(FALSE,"ContextMenu::BuildOverView called in base class - should be overridden!");
00400 }
00401 
00402 
00403 
00404 
00405 /********************************************************************************************
00406 
00407 >   BOOL ContextMenu::BuildTransferCommands(BOOL NodeCommands)
00408 
00409     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00410     Created:    13/03/95
00411     Inputs:     -
00412     Outputs:    -
00413     Returns:    Pointer to first MenuItem in the kernel menu definition
00414     Purpose:    Append the standard "transfer command" menu items to the input root menu
00415                 This function adds:
00416                     Cut
00417                     Copy
00418                     Paste
00419                     (Paste link When we implement OLE...)
00420                 And if NodeCommands is TRUE:
00421                     -----
00422                     Delete
00423                     Duplicate
00424                     Clone
00425                     -----
00426                     
00427     Errors:     -
00428 
00429 ********************************************************************************************/
00430 
00431 BOOL ContextMenu::BuildTransferCommands(BOOL NodeCommands)
00432 {
00433     // Build the standard transfer command menu items...
00434     BuildCommand(OPTOKEN_CUT);
00435     BuildCommand(OPTOKEN_COPY);
00436     BuildCommand(OPTOKEN_PASTE, TRUE);
00437 //  BuildCommand(OPTOKEN_PASTELINK);
00438 
00439     // If caller wants transfer commands for Nodes in the document build them...
00440     if (NodeCommands)
00441     {
00442         BuildCommand(OPTOKEN_DELETE);
00443         BuildCommand(OPTOKEN_DUPLICATE);
00444         BuildCommand(OPTOKEN_CLONE, TRUE);
00445     }
00446 
00447     return TRUE;
00448 }
00449 
00450 
00451 
00452 
00453 /********************************************************************************************
00454 
00455 >   BOOL ContextMenu::BuildEffectCommands()
00456 
00457     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00458     Created:    13/03/95
00459     Inputs:     -
00460     Outputs:    -
00461     Returns:    Pointer to first MenuItem in the kernel menu definition
00462     Purpose:    Append the "effect" menu items to the input root menu
00463     Errors:     -
00464 
00465 ********************************************************************************************/
00466 
00467 BOOL ContextMenu::BuildEffectCommands()
00468 {
00469     EffectsStack* pStack = GetApplication()->FindSelection()->GetEffectsStack();    // Cached copy
00470     if (pStack->IsEmpty() || !pStack->bConsistent)
00471         return TRUE;
00472 
00473     BuildCommand( TOOL_OPTOKEN_LIVEEFFECT );        // Go to Effects tool
00474 
00475     pStack->BuildEffectMenu(this);                      // <List of effects>
00476 
00477     BuildCommand(OPTOKEN_DELETEALL_LIVEEFFECT, TRUE);   // Remove all Effects
00478 
00479     return TRUE;
00480 }
00481 
00482 
00483 
00484 
00485 /********************************************************************************************
00486 
00487 >   BOOL ContextMenu::BuildCommand(TCHAR* pOpToken, BOOL Separator = FALSE, MenuItem* pRootMenu = NULL, const String& strNewText = "", OpMenuParam* pParam = NULL)
00488 
00489     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00490     Created:    17/03/95
00491     Inputs:     pOpToken    Pointer to optoken for this item
00492                 Separator   Flag that separator is required after this item
00493                 pRootMenu   Pointer to root menu to add this to or NULL for main root
00494     Outputs:    -
00495     Returns:    Pointer to first MenuItem in the kernel menu definition
00496     Purpose:    Append a new menu item to this menu.
00497                 Passing pRootMenu as NULL (leaving it defaulted) causes the new item to be
00498                 added to the first level of the pop-up menu.
00499                 Passing pRootMenu non-NULL allows you to build a submenu.
00500     Errors:     -
00501 
00502 ********************************************************************************************/
00503 
00504 BOOL ContextMenu::BuildCommand(TCHAR* pOpToken, BOOL Separator, MenuItem* pRootMenu, const String& strNewText, OpMenuParam* pParam)
00505 {
00506     MenuItem* pNewItem;
00507 
00508     // If caller hasn't specified a root menu use the root of the whole thing...
00509     if (pRootMenu == NULL)
00510         pRootMenu = pRootItem;
00511 
00512     // Create a new kernel menu item...
00513     pNewItem = CreateMenuItem(pOpToken, pRootMenu->GetMenuId(), Separator);
00514 
00515     // If that worked, add it to the root menu. Else flag failure.
00516     if (pNewItem)
00517     {
00518         pLastItem = pNewItem;
00519 
00520         if (!strNewText.IsEmpty())
00521             pNewItem->SetMenuText(strNewText);
00522 
00523         if (pParam)
00524             pNewItem->SetMenuParam(pParam);
00525 
00526         pRootMenu->AddMenuItem(pNewItem);
00527 
00528         return TRUE;
00529     }
00530     else
00531         return FALSE;
00532 }
00533 
00534 
00535 
00536 
00537 /********************************************************************************************
00538 
00539 >   MenuItem* ContextMenu::GetLastItem()
00540 
00541     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00542     Created:    17/03/95
00543     Inputs:     -
00544     Outputs:    -
00545     Returns:    Pointer to last MenuItem defined
00546     Purpose:    Get pointer to item last previously created
00547     Errors:     -
00548 
00549 ********************************************************************************************/
00550 
00551 MenuItem* ContextMenu::GetLastItem()
00552 {
00553     return  pLastItem;
00554 }
00555 
00556 
00557 
00558 

Generated on Sat Nov 10 03:44:54 2007 for Camelot by  doxygen 1.4.4