ContextMenu Class Reference

Encapsulate the concept of pop-up, context-sensitive menus at the kernel level. More...

#include <contmenu.h>

Inheritance diagram for ContextMenu:

ColEditContextMenu GalleryContextMenu OriginContextMenu PaletteContextMenu PlugInsContextMenu PreviewContextMenu RulerContextMenu ViewContextMenu List of all members.

Public Member Functions

 ContextMenu ()
virtual ~ContextMenu ()
BOOL Show ()
BOOL ShowOverView (Spread *pSpread, DocCoord ClickPos, ClickModifiers ClickMods)
 This function does the same job as ShowMenu but unfortunately needs some parameters to pass on to the menu builders. Not very neat, I know...
BOOL Hide ()
 Close and delete any context menu that may be open.
virtual BOOL Build ()
 Base class implementation of menu builder. This function builds a menu statically by creating the appropriate objects. It does NOT call teh menu script interpreter because I am unhappy about the reliability of repeatedly calling that code.
virtual BOOL BuildOverView (Spread *pSpread, DocCoord ClickPos, ClickModifiers ClickMods)
 Base class function which, when overridden in derived classes, will build a pop-up menu according to a given position in a view.
BOOL BuildTransferCommands (BOOL NodeCommands)
 Append the standard "transfer command" menu items to the input root menu This function adds: Cut Copy Paste (Paste link When we implement OLE...) And if NodeCommands is TRUE: ----- Delete Duplicate Clone -----.
BOOL BuildEffectCommands ()
 Append the "effect" menu items to the input root menu.
BOOL BuildCommand (TCHAR *pOpToken, BOOL Separator=FALSE, MenuItem *pRootMenu=NULL, const String &strNewText=String(_T("")), OpMenuParam *pParam=NULL)
 Append a new menu item to this menu. Passing pRootMenu as NULL (leaving it defaulted) causes the new item to be added to the first level of the pop-up menu. Passing pRootMenu non-NULL allows you to build a submenu.
MenuItemGetLastItem ()
 Get pointer to item last previously created.

Static Public Member Functions

static BOOL HideCurrent ()
 Close and delete the current context menu if it's open.

Protected Attributes

MenuItempRootItem
MenuItempLastItem
UINT32 AutoIDStash

Static Protected Attributes

static ContextMenupCurrentMenu = NULL

Private Member Functions

 CC_DECLARE_MEMDUMP (ContextMenu)

Detailed Description

Encapsulate the concept of pop-up, context-sensitive menus at the kernel level.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
To create and use a new context-sensitive menu: Derive a new subclass from ContextMenu, e.g. ViewContextMenu. Create the operations that you want to use from the menu or use existing operations. Implement a new Build function in your subclass to build your menu using the helper functions provided (see func headers for more details). That's all there is to it - the menu system handles everything else!

Note: There are guidelines about how to construct a pop-up menu and when to open it. The menu should be formed something like this: Clicked object's primary commands Clicked object's transfer commands (e.g. cut, copy, etc...) "Properties..." command The menu should be opened in response to a BUTTON UP event!!!

Definition at line 139 of file contmenu.h.


Constructor & Destructor Documentation

ContextMenu::ContextMenu  ) 
 

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE FALSE

Errors: -

Definition at line 145 of file contmenu.cpp.

00146 {
00147     pRootItem = NULL;
00148     pLastItem = NULL;
00149     AutoIDStash = 0;
00150 }

ContextMenu::~ContextMenu  )  [virtual]
 

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE FALSE

Errors: -

Definition at line 170 of file contmenu.cpp.

00171 {
00172 }


Member Function Documentation

BOOL ContextMenu::Build void   )  [virtual]
 

Base class implementation of menu builder. This function builds a menu statically by creating the appropriate objects. It does NOT call teh menu script interpreter because I am unhappy about the reliability of repeatedly calling that code.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
pRootMenu Pointer to root menu item to add new items to. [INPUTS]
- [OUTPUTS]
Returns:
TRUE if menu built OK FALSE (and sets error) otherwise
An overloaded version of this function could be written which takes in a reference to a "file" to be opened and interpreted.

Note also that by building the menu programmatically it can change depending on the context within which it is opened...

The standard layout for pop-up menus is: Clicked object's primary commands Transfer commands Other commands supported by the clicked object The "What's this?" command The Properties... command These are only guidelines and you can omit any sections you don't need.

To implement an overriden version of this function you simply need to make it add new menu items to the root menu. There are helper functions to make this easier: BuildTransferCommands will add Cut,Copy,Paste,etc. BuildCommand will take any OPTOKEN you give it and build an item linked to that OPTOKEN.

Returns:
Errors: -

Reimplemented in BfxPlugInContextMenu, ColEditContextMenu, PaletteContextMenu, PlugInsContextMenu, PreviewContextMenu, RulerContextMenu, OriginContextMenu, and GalleryContextMenu.

Definition at line 373 of file contmenu.cpp.

00374 {
00375     ERROR2(FALSE,"ContextMenu::Build called in base class - should be overridden!");
00376 }

BOOL ContextMenu::BuildCommand TCHAR pOpToken,
BOOL  Separator = FALSE,
MenuItem pRootMenu = NULL,
const String strNewText = String( _T("") ),
OpMenuParam pParam = NULL
 

Append a new menu item to this menu. Passing pRootMenu as NULL (leaving it defaulted) causes the new item to be added to the first level of the pop-up menu. Passing pRootMenu non-NULL allows you to build a submenu.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/95
Parameters:
pOpToken Pointer to optoken for this item [INPUTS] Separator Flag that separator is required after this item pRootMenu Pointer to root menu to add this to or NULL for main root
- [OUTPUTS]
Returns:
Pointer to first MenuItem in the kernel menu definition

Errors: -

Definition at line 504 of file contmenu.cpp.

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 }

BOOL ContextMenu::BuildEffectCommands  ) 
 

Append the "effect" menu items to the input root menu.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Pointer to first MenuItem in the kernel menu definition

Errors: -

Definition at line 467 of file contmenu.cpp.

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 }

BOOL ContextMenu::BuildOverView Spread pSpread,
DocCoord  ClickPos,
ClickModifiers  ClickMods
[virtual]
 

Base class function which, when overridden in derived classes, will build a pop-up menu according to a given position in a view.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
pRootMenu Pointer to root menu item to add new items to. [INPUTS]
- [OUTPUTS]
Returns:
TRUE if menu built OK FALSE (and sets error) otherwise

Errors: -

Reimplemented in ViewContextMenu.

Definition at line 397 of file contmenu.cpp.

00398 {
00399     ERROR2(FALSE,"ContextMenu::BuildOverView called in base class - should be overridden!");
00400 }

BOOL ContextMenu::BuildTransferCommands BOOL  NodeCommands  ) 
 

Append the standard "transfer command" menu items to the input root menu This function adds: Cut Copy Paste (Paste link When we implement OLE...) And if NodeCommands is TRUE: ----- Delete Duplicate Clone -----.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Pointer to first MenuItem in the kernel menu definition

Errors: -

Definition at line 431 of file contmenu.cpp.

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 }

ContextMenu::CC_DECLARE_MEMDUMP ContextMenu   )  [private]
 

MenuItem * ContextMenu::GetLastItem  ) 
 

Get pointer to item last previously created.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Pointer to last MenuItem defined

Errors: -

Definition at line 551 of file contmenu.cpp.

00552 {
00553     return  pLastItem;
00554 }

BOOL ContextMenu::Hide  ) 
 

Close and delete any context menu that may be open.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE FALSE

Errors: -

Definition at line 291 of file contmenu.cpp.

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 }

BOOL ContextMenu::HideCurrent  )  [static]
 

Close and delete the current context menu if it's open.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/10/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE FALSE

Errors: -

Definition at line 324 of file contmenu.cpp.

00325 {
00326     if (pCurrentMenu)
00327         pCurrentMenu->Hide();
00328     return TRUE;
00329 }

BOOL ContextMenu::Show  ) 
 

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE FALSE

Errors: -

Definition at line 192 of file contmenu.cpp.

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 }

BOOL ContextMenu::ShowOverView Spread pSpread,
DocCoord  ClickPos,
ClickModifiers  ClickMods
 

This function does the same job as ShowMenu but unfortunately needs some parameters to pass on to the menu builders. Not very neat, I know...

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/03/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE FALSE

Errors: -

Definition at line 242 of file contmenu.cpp.

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 }


Member Data Documentation

UINT32 ContextMenu::AutoIDStash [protected]
 

Definition at line 175 of file contmenu.h.

ContextMenu * ContextMenu::pCurrentMenu = NULL [static, protected]
 

Definition at line 177 of file contmenu.h.

MenuItem* ContextMenu::pLastItem [protected]
 

Definition at line 174 of file contmenu.h.

MenuItem* ContextMenu::pRootItem [protected]
 

Definition at line 173 of file contmenu.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:05 2007 for Camelot by  doxygen 1.4.4