MenuItem Class Reference

MenuItems are the things that appear in menus, but in camelot they are also the menus themselves. The idea is that the menu system is a dynamically growing, living-thing where all the elements are connected in a tree like structure. The elements of the menu system or the nodes in the tree are MenuItems. MenuItems can therefore be simple or composite i.e. a menu option or a sub menu. In windows there is a third type of MenuItem: the separator, in our new improved menuing system separators will not be modelled as MenuItems. Instead a MenuItem may be specified as having a menu separator following it. More...

#include <menuitem.h>

Inheritance diagram for MenuItem:

CmdControl ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

virtual void PerformAction ()
 Performs the action assoicated with a CmdControl.
 MenuItem ()
 MenuItem (UINT32 parentMenuID, OpDescriptor *Owner, BOOL separator=FALSE)
 Constructor for the MenuItem Class. Creates a new menu items and connects to an OpDescriptor. The ID of the menu is determined algorithmically.
 MenuItem (const String_256 &description, UINT32 parentMenuID=0, BOOL separator=FALSE)
 Constructor for the MenuItem Class. Used for creating new group menu items.
 ~MenuItem ()
 Default destructor.
BOOL IsMenuItemGroup ()
 Identifies if the current MenuItem is a group.
BOOL IsFollowedBySeparator ()
 Identifies if the current MenuItem has a separator following it in the menu to which it belongs.
BOOL IsCheckable ()
BOOL SetIsFollowedBySeparator (BOOL NewValue)
 Sets a new state for the IsFollowedBySeparator flag. This Identifies if the current MenuItem has a separator following it in the menu to which it belongs.
BOOL UpdateControlState (BOOL AppendHotKeyName=TRUE)
 Obtains the state of a MenuItem.
BOOL UpdateMenuState (BOOL AppendHotKeyNames=TRUE)
 Obtains the state of all MenuItems in MenuItem.
UINT32 GetMenuId ()
 Gets the menu Id of the current MenuItem.
UINT32 GetMenuItemParentId ()
 Gets the menu Id of the parent of the current MenuItem.
UINT32 GetHelpId ()
 Gets the Help Id of the current MenuItem.
String_256 GetMenuText ()
 Gets MenuItem Text Description.
String_256GetMenuDesc ()
 Gets MenuItem Text Description.
String_32GetOpToken ()
 Gets the OpToken for the menu item.
void SetMenuText (const String_256 &strNewText)
void SetMenuParam (OpMenuParam *pNewParam)
UINT32 GetMenuSelectedBitmapID ()
 Looks up and caches the bitmap resource for this MenuItem.
UINT32 GetMenuUnselectedBitmapID ()
 Looks up and caches the bitmap resource for this MenuItem.
MenuItemGetFirstMenuItem ()
 Obtains the first MenuItem in MenuItem.
MenuItemGetNextMenuItem (MenuItem *curItem)
 Obtains the next MenuItem in MenuItem.
BOOL AddMenuItem (MenuItem *newItem)
 Adds a MenuItem to a MenuItem.
MenuItemRemoveMenuItem (MenuItem *Item)
 Removes MenuItem from SubMenuItems List.

Static Public Member Functions

static UINT32 GetNextAutomaticMenuID ()
 Creates a unique ID for each menu, based on a monotonic increasing value (whose range is determined by the OIL layer). When the range fills, a search is done to find individual unused IDs. Friend: MenuItem.
static UINT32 GetAutomaticIDState ()
 Finds the current state of the menu ID generator so that it can be preserved. Scope: Public.
static BOOL SetAutomaticIDState (UINT32 newvalue)
 Allows the state of the menu ID generator to be restored after it been preserved. Scope: Public.

Static Public Attributes

static UINT32 AutomaticMenuID = AUTO_MENU_ID_MIN
static const OpState DefaultMenuState

Private Member Functions

 CC_DECLARE_MEMDUMP (MenuItem)
void PopulateMenuParam ()
 Fills in the OpMenuParam supplied by the menu builder with details of this specific menu item.

Private Attributes

UINT32 ParentMenuId
ListSubMenuItems
String_256 Description
BOOL FollowedBySeparator
UINT32 m_nSelectedBitmapID
UINT32 m_nUnselectedBitmapID
OpMenuParampMenuParam

Friends

void UpdateWinMenu (CNativeMenu *pMenu, MenuItem *kernelMenu)
 To update windows menu system. It is also a Friend of the MenuItem Class.

Detailed Description

MenuItems are the things that appear in menus, but in camelot they are also the menus themselves. The idea is that the menu system is a dynamically growing, living-thing where all the elements are connected in a tree like structure. The elements of the menu system or the nodes in the tree are MenuItems. MenuItems can therefore be simple or composite i.e. a menu option or a sub menu. In windows there is a third type of MenuItem: the separator, in our new improved menuing system separators will not be modelled as MenuItems. Instead a MenuItem may be specified as having a menu separator following it.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/6/93
Returns:
Errors: None yet.
See also:
Control

Definition at line 164 of file menuitem.h.


Constructor & Destructor Documentation

MenuItem::MenuItem  )  [inline]
 

Definition at line 186 of file menuitem.h.

MenuItem::MenuItem UINT32  parentMenuID,
OpDescriptor pOwner,
BOOL  separator = FALSE
 

Constructor for the MenuItem Class. Creates a new menu items and connects to an OpDescriptor. The ID of the menu is determined algorithmically.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/7/93
Parameters:
Parent Menu Identifier [INPUTS] Pointer to owner OpDescriptor Separator flag (defaults to FALSE)
None [OUTPUTS]
Returns:
None

Errors: None

Definition at line 148 of file menuitem.cpp.

00149   : CmdControl(pOwner),
00150     ParentMenuId(parentMenuID),
00151     SubMenuItems(0),
00152     FollowedBySeparator(separator),
00153     m_nSelectedBitmapID(0),
00154     m_nUnselectedBitmapID(0)
00155 {
00156 
00157     ENSURE( pOwner, "No owner for MenuItem" );
00158 
00159     pOwner->GetText(&Description, OP_MENU_TEXT);                    
00160     ControlState        = DefaultMenuState;
00161     OwnerOperation      = pOwner;                               // the connection between the
00162                                                                 // menu and an operation
00163     ControlId           = GetNextAutomaticMenuID();             // wrong, but temp hack
00164     pMenuParam          = NULL;
00165 }

MenuItem::MenuItem const String_256 description,
UINT32  parentMenuID = 0,
BOOL  separator = FALSE
 

Constructor for the MenuItem Class. Used for creating new group menu items.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/7/93
Parameters:
Parent Menu Identifier [INPUTS] Constanst String Reference for description of Menu. Boolean - Followed By Separator Flag
None [OUTPUTS]
Returns:
None

Errors: None

Definition at line 183 of file menuitem.cpp.

00184   : ParentMenuId(parentMenuID),
00185     SubMenuItems(0),
00186     Description(description),
00187     FollowedBySeparator(separator),
00188     m_nSelectedBitmapID(0),
00189     m_nUnselectedBitmapID(0)
00190 {
00191     ControlState        = DefaultMenuState;
00192     ControlId           = GetNextAutomaticMenuID();
00193     pMenuParam          = NULL;
00194 }

MenuItem::~MenuItem  ) 
 

Default destructor.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/9/93
Returns:
Errors: None

Definition at line 207 of file menuitem.cpp.

00208 {
00209     if (SubMenuItems != NULL)
00210     {
00211         SubMenuItems->DeleteAll();
00212         delete SubMenuItems;
00213     }
00214 
00215     if (pMenuParam)
00216     {
00217         delete pMenuParam;
00218         pMenuParam = NULL;
00219     }
00220 }


Member Function Documentation

BOOL MenuItem::AddMenuItem MenuItem newItem  ) 
 

Adds a MenuItem to a MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/6/93
Parameters:
New MenuItem [INPUTS]
None [OUTPUTS]
Returns:
True if MenuItem is added successfully False if MenuItem isn't added

Errors: None

Definition at line 738 of file menuitem.cpp.

00739 {
00740     if (SubMenuItems == NULL)     
00741     {
00742         SubMenuItems = new List();
00743         ERRORIF(!SubMenuItems, _R(IDE_NOMORE_MEMORY), FALSE);
00744     }
00745 
00746     if (SubMenuItems->FindPosition(newItem) <= NOT_IN_LIST)
00747     {
00748         SubMenuItems->AddTail(newItem);
00749         return TRUE;
00750     }
00751     else
00752         return FALSE;
00753 }

MenuItem::CC_DECLARE_MEMDUMP MenuItem   )  [private]
 

UINT32 MenuItem::GetAutomaticIDState  )  [static]
 

Finds the current state of the menu ID generator so that it can be preserved. Scope: Public.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/95
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
The next automatic menu ID value without incrementing the internal counter.

Definition at line 834 of file menuitem.cpp.

00835 {
00836     return AutomaticMenuID;                         // return current value
00837 }

MenuItem * MenuItem::GetFirstMenuItem  ) 
 

Obtains the first MenuItem in MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
First MenuItem in Group

Errors: None

Definition at line 693 of file menuitem.cpp.

00694 {                                         
00695     if (SubMenuItems == NULL)
00696         return NULL;
00697     else
00698         return (MenuItem*)(SubMenuItems->GetHead());
00699 }

UINT32 MenuItem::GetHelpId  ) 
 

Gets the Help Id of the current MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/1/94
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
Help Id of current MenuItem

Errors: None

Definition at line 532 of file menuitem.cpp.

00533 {
00534     return OwnerOperation->GetHelpId();
00535 }

String_256 * MenuItem::GetMenuDesc  ) 
 

Gets MenuItem Text Description.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
If Succesfull returns a string representing a description of the MenuItem otherwise NULL

Errors: None

Definition at line 640 of file menuitem.cpp.

00641 {
00642     static String_256 MenuDesc = "";                 
00643     
00644     if (OwnerOperation->GetText(&MenuDesc, OP_DESC_TEXT))
00645         return &MenuDesc;
00646     else
00647         return NULL;
00648 }

UINT32 MenuItem::GetMenuId  ) 
 

Gets the menu Id of the current MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
Menu Id of current MenuItem

Errors: None

Definition at line 513 of file menuitem.cpp.

00514 {
00515     return ControlId;
00516 }

UINT32 MenuItem::GetMenuItemParentId  ) 
 

Gets the menu Id of the parent of the current MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
Menu Id of parent of current MenuItem

Errors: None

Definition at line 551 of file menuitem.cpp.

00552 {
00553     return ParentMenuId;
00554 }

UINT32 MenuItem::GetMenuSelectedBitmapID  ) 
 

Looks up and caches the bitmap resource for this MenuItem.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/5/00
Returns:
Resource identifier of the small bitmap associated with this menu item, or 0 if there isn't one available.

Definition at line 587 of file menuitem.cpp.

00588 {
00589     if (m_nSelectedBitmapID == 0)
00590     {
00591         // We have to look up the small button bitmap that may be associated with the
00592         // operation this menu item refers to.
00593 
00594     }
00595 
00596     return m_nSelectedBitmapID;
00597 }

String_256 MenuItem::GetMenuText  ) 
 

Gets MenuItem Text Description.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
String representing a description of the MenuItem

Errors: None

Definition at line 570 of file menuitem.cpp.

00571 {
00572     return Description;
00573 }

UINT32 MenuItem::GetMenuUnselectedBitmapID  ) 
 

Looks up and caches the bitmap resource for this MenuItem.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/5/00
Returns:
Resource identifier of the small bitmap associated with this menu item, or 0 if there isn't one available.

Definition at line 611 of file menuitem.cpp.

00612 {
00613     if (m_nUnselectedBitmapID == 0)
00614     {
00615         // We have to look up the small button bitmap that may be associated with the
00616         // operation this menu item refers to.
00617 
00618     }
00619 
00620     return m_nUnselectedBitmapID;
00621 }

UINT32 MenuItem::GetNextAutomaticMenuID  )  [static]
 

Creates a unique ID for each menu, based on a monotonic increasing value (whose range is determined by the OIL layer). When the range fills, a search is done to find individual unused IDs. Friend: MenuItem.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/7/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
The next automatic menu ID value

Errors: Will ENSURE when range is filled. Scope: Private

Definition at line 802 of file menuitem.cpp.

00803 {
00804     if (AutomaticMenuID > AUTO_MENU_ID_MAX)
00805     {
00806         // we have run out of IDs, so search for gaps in the allocation
00807         // UNFINISHED CODE!!
00808         ERROR2(0,"Run out of menu IDs" );
00809     }
00810     else
00811     {
00812         return AutomaticMenuID++;                       // return old value, inc for next time
00813     }
00814     
00815 }

MenuItem * MenuItem::GetNextMenuItem MenuItem CurrItem  ) 
 

Obtains the next MenuItem in MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
First MenuItem in Group

Errors: None

Definition at line 715 of file menuitem.cpp.

00716 {
00717     if (SubMenuItems == NULL)
00718         return NULL;
00719     else
00720         return (MenuItem*)(SubMenuItems->GetNext(CurrItem));
00721 }

String_32 * MenuItem::GetOpToken  ) 
 

Gets the OpToken for the menu item.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/1/97
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
If Succesfull returns a string representing the OpToken of the MenuItem otherwise returns a NULL

Errors: None

Definition at line 665 of file menuitem.cpp.

00666 {
00667     static String_32 OpToken = _T("");                 
00668 
00669     if (OwnerOperation)
00670     {
00671         OpToken = OwnerOperation->Token;
00672         return &OpToken;
00673     }
00674 
00675     return NULL;
00676 }

BOOL MenuItem::IsCheckable  ) 
 

Author:
Luke_Hart (Xara Group Ltd) <lukeh@xara.com>
Date:
10/03/06
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
True if the item should have a check box else it shouldn't

Errors: None

Definition at line 299 of file menuitem.cpp.

00300 {
00301     return OwnerOperation->GetOpFlags().fCheckable;
00302 }

BOOL MenuItem::IsFollowedBySeparator  ) 
 

Identifies if the current MenuItem has a separator following it in the menu to which it belongs.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
True if MenuItem is followed by a separator in the menu. False if MenuItem is not followed by a separator

Errors: None

Definition at line 239 of file menuitem.cpp.

00240 {
00241      return FollowedBySeparator;
00242 }

BOOL MenuItem::IsMenuItemGroup  ) 
 

Identifies if the current MenuItem is a group.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
True if there are any SubMenuItems in current MenuItem False if MenuItem is singular

Errors: None

Definition at line 281 of file menuitem.cpp.

00282 {
00283     return (SubMenuItems == NULL)? FALSE : TRUE;
00284 }

void MenuItem::PerformAction  )  [virtual]
 

Performs the action assoicated with a CmdControl.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/10/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
None

Errors: None

Reimplemented from CmdControl.

Definition at line 318 of file menuitem.cpp.

00319 {
00320     ENSURE(OwnerOperation, "Cannot Perform Menu Action with NULL Owner");
00321 
00322     if (pMenuParam==NULL)
00323     {
00324         OwnerOperation->Invoke();
00325     }
00326     else
00327     {
00328         // The OpDescriptor wants more info about which menu item
00329         // has been invoked...
00330         // So make a special param for DoWithParam
00331         PopulateMenuParam();
00332         OwnerOperation->Invoke(pMenuParam);
00333     }
00334 }

void MenuItem::PopulateMenuParam  )  [private]
 

Fills in the OpMenuParam supplied by the menu builder with details of this specific menu item.

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

Errors: None

Definition at line 434 of file menuitem.cpp.

00435 {
00436     if (pMenuParam)
00437     {
00438         MenuItem* pItem = GetMenuItem(ParentMenuId);
00439         String_256 strFullPath = Description;
00440         while (pItem && !pItem->GetMenuText().IsEmpty())
00441         {
00442             String_256 strParentText = pItem->GetMenuText();
00443             strParentText += String( _T("/") );
00444             strParentText += strFullPath;
00445             strFullPath = strParentText;
00446 //          strFullPath = pItem->GetMenuText() + String("/") + strFullPath;
00447 
00448             pItem = GetMenuItem(pItem->GetMenuItemParentId());
00449         }
00450         pMenuParam->strMenuText = Description;          // Give common ops access to individual menu identity
00451         pMenuParam->strMenuPath = strFullPath;
00452     }
00453 }

MenuItem * MenuItem::RemoveMenuItem MenuItem Item  ) 
 

Removes MenuItem from SubMenuItems List.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
MenuItem removed from SubMenuItems List

Errors: None

Definition at line 769 of file menuitem.cpp.

00770 {
00771     if (SubMenuItems == NULL)
00772         return NULL;
00773     else    
00774         return (MenuItem*)(SubMenuItems->RemoveItem(Item));
00775 }

BOOL MenuItem::SetAutomaticIDState UINT32  newvalue  )  [static]
 

Allows the state of the menu ID generator to be restored after it been preserved. Scope: Public.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/95
Parameters:
The new value for the internal menu ID generator. [INPUTS]
None [OUTPUTS]
Returns:
-

Definition at line 857 of file menuitem.cpp.

00858 {
00859     ERROR2IF(newvalue<AUTO_MENU_ID_MIN,FALSE,"Attempt to set menu ID generator below valid range.");
00860     ERROR2IF(newvalue>AUTO_MENU_ID_MAX,FALSE,"Attempt to set menu ID generator above valid range.");
00861 
00862     AutomaticMenuID = newvalue;                     // return current value
00863     return TRUE;
00864 }

BOOL MenuItem::SetIsFollowedBySeparator BOOL  NewValue  ) 
 

Sets a new state for the IsFollowedBySeparator flag. This Identifies if the current MenuItem has a separator following it in the menu to which it belongs.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/3/97
Parameters:
NewValue to be applied as the IsFollowedBySeparator flag [INPUTS]
None [OUTPUTS]
Returns:
the old state of the IsFollowedBySeparator flag.

Errors: None

Definition at line 259 of file menuitem.cpp.

00260 {
00261      BOOL OldValue = FollowedBySeparator;
00262      FollowedBySeparator = NewValue;
00263      return OldValue;
00264 }

void MenuItem::SetMenuParam OpMenuParam pNewParam  )  [inline]
 

Definition at line 221 of file menuitem.h.

00221 {pMenuParam=pNewParam;}

void MenuItem::SetMenuText const String_256 strNewText  )  [inline]
 

Definition at line 220 of file menuitem.h.

00220 {Description=strNewText;}

BOOL MenuItem::UpdateControlState BOOL  AppendHotKeyName = TRUE  ) 
 

Obtains the state of a MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
TRUE if state is updated FALSE otherwise

Errors: None

Definition at line 352 of file menuitem.cpp.

00353 {                      
00354     ENSURE(OwnerOperation, "Cannot update the state of a NULL operation");
00355 
00356     // Reset the Menu text to the Default Menu Description
00357     OwnerOperation->GetText(&Description, OP_MENU_TEXT);
00358 
00359     // Pass Default Menu Description to GetState
00360     String_256  MenuDesc = Description;
00361     
00362     // get new menu state
00363     PopulateMenuParam();
00364     OpState newState = OwnerOperation->GetOpsState(&MenuDesc, pMenuParam);
00365 
00366     // if a description has been returned
00367     if (!MenuDesc.IsEmpty())
00368     {   
00369         if (newState.Greyed)
00370         {
00371             // Check to see that Disabled Message is being returned!
00372             if (MenuDesc != Description)
00373             {
00374                 // Set up reason why item is disabled
00375                 String_256 disabledStub(_R(IDS_DISABLED_BECAUSE));
00376                 String_256 menuOption;
00377                 
00378                 OwnerOperation->GetText(&menuOption, OP_MENU_NAME);
00379             
00380                 WhyDisabled = disabledStub;
00381                 WhyDisabled += MenuDesc;
00382             }
00383         }
00384         else                 
00385             // Set Description to be 
00386             Description = MenuDesc;
00387     }
00388 
00389     if (AppendHotKeyName)
00390     {
00391         // Is there a hot key assigned to this menuitem
00392         HotKey *pHotKey = HotKey::FindHotKey(OwnerOperation);
00393 
00394         // if there is then get menu text description of hot key and attach to
00395         // end of menu item description.
00396         if (pHotKey)
00397         {
00398             String_256 Str;
00399             pHotKey->GetTextDesc(&Str);
00400             Description += String( _T("\t") );
00401             Description += Str;
00402 
00403         //  Description += *(pHotKey->GetMenuTextDesc());
00404         }
00405     }
00406 
00407     // if the state has changed
00408     if ((newState.Greyed != ControlState.Greyed) ||             // if changed then
00409         (newState.Ticked != ControlState.Ticked) ||
00410         (newState.RemoveFromMenu != ControlState.RemoveFromMenu))
00411     {
00412         ControlState = newState;                                // record new state
00413         return TRUE;  
00414     }
00415     return FALSE;
00416 }

BOOL MenuItem::UpdateMenuState BOOL  AppendHotKeyNames = TRUE  ) 
 

Obtains the state of all MenuItems in MenuItem.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/6/93
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
True if all Menu Enabled False Otherwize

Errors: None

Definition at line 471 of file menuitem.cpp.

00472 {
00473     MenuItem *pMItem = NULL;
00474     BOOL updateMenu = FALSE;
00475     
00476     if (SubMenuItems != NULL)
00477         pMItem = (MenuItem *) SubMenuItems->GetHead();      //Get first MenuItem in List
00478                                                             
00479     //Loop while not end of list
00480     while (pMItem != NULL) // && (SubMenuItems != NULL))                            
00481     {                                     
00482         if (pMItem->IsMenuItemGroup()) 
00483         {
00484             if (pMItem->UpdateMenuState(AppendHotKeyNames)) //Set Update Menu Flag if 
00485                 updateMenu = TRUE;                          //menu state has changed
00486         }
00487         else        
00488         {
00489             if (pMItem->UpdateControlState(AppendHotKeyNames))//Set Update Menu Flag if 
00490                 updateMenu = TRUE;                          //menu state has changed
00491         }
00492                 
00493         pMItem = (MenuItem *) SubMenuItems->GetNext(pMItem);    //Get next MenuItem in List 
00494     }
00495     
00496     return updateMenu;
00497 }


Friends And Related Function Documentation

void UpdateWinMenu CNativeMenu pMenu,
MenuItem kernelMenu
[friend]
 

To update windows menu system. It is also a Friend of the MenuItem Class.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/7/93
Parameters:
A pointer to a wxMenu and a kernel menu object [INPUTS]
None. [OUTPUTS]
Returns:
None.

Errors: None.

See also:
CMainFrame

wxMenu

MenuItem

Definition at line 1038 of file oilmenus.cpp.

01039 {
01040     if (kernelMenu == NULL) return;
01041 
01042     MenuItem* subMenu = (kernelMenu->GetFirstMenuItem());
01043     
01044     //Read through list of Kernel MenuItems updating their state
01045     while (subMenu != NULL)
01046     {
01047         if (!subMenu->IsMenuItemGroup())
01048         {
01049             wxItemKind  ItemKind = wxITEM_NORMAL;
01050             if( subMenu->IsCheckable() )
01051                 ItemKind = wxITEM_CHECK;
01052             
01053             // Make sure the wxMenu has this menu item in it...
01054             wxMenuItem  *pItem = pMenu->FindItem( subMenu->GetMenuId() );
01055             if( NULL == pItem )
01056             {
01057                 // This menu item is missing, probably deleted by the bit of code below
01058                 // We have to put it back in again to be on the safe side
01059                 // Find out the position of the next visible menu item, so we can insert just before it
01060                 MenuItem* NextMenu = subMenu;
01061                 while( NULL != NextMenu && 
01062                     NULL == pMenu->FindItem( NextMenu->GetMenuId() ) )
01063                 {
01064                     NextMenu = (kernelMenu->GetNextMenuItem(NextMenu));
01065                 }
01066                 
01067                 // If there was a next item, insert before it, else append to the end of the menu
01068                 if (NextMenu!=NULL)
01069                 {
01070                     BOOL    MenuAdded = FALSE;
01071                     BOOL    PrevWasSeparator = FALSE;
01072                     size_t  NumMenuItems = pMenu->GetMenuItemCount();
01073                     for( size_t i=0; (!MenuAdded) && (i<NumMenuItems); i++ )
01074                     {
01075                         // loop through all the menu items to try and find our ID
01076                         wxMenuItem* pMenuItem = pMenu->FindItemByPosition( i );
01077                         UINT32 MenuID = pMenuItem->GetId();
01078                         if (MenuID == NextMenu->GetMenuId())
01079                         {
01080                             // We will be wanting to insert just before this one
01081                             size_t InsertPos = i;
01082 
01083                             // but was the previous item was a separator
01084                             if (PrevWasSeparator)
01085                                 InsertPos--;
01086                             
01087                             // Insert the menu and set the flag to say it was inserted
01088                             pMenu->Insert( InsertPos, subMenu->GetMenuId(), subMenu->GetMenuText(), 
01089                                 _T(""), ItemKind );
01090                             MenuAdded = TRUE;
01091                         }
01092 
01093                         // Unset the Prev Separator flag
01094                         PrevWasSeparator = FALSE;
01095 
01096                         // if this was a separator, then remember for the next loop
01097                         if( pMenuItem->IsSeparator() )
01098                             PrevWasSeparator = TRUE;
01099                     }
01100                 }
01101                 else
01102                     pMenu->Append( subMenu->GetMenuId(), subMenu->GetMenuText(), _T(""),
01103                         ItemKind );
01104             }
01105 
01106 PORTNOTE( "menu", "Remove Unimplemented menuitems from menu, under Release" )
01107 #if !defined(_DEBUG)
01108             if( subMenu->Description == _T("Unimplemented") )
01109                 subMenu->ControlState.RemoveFromMenu = true;
01110 #endif
01111 
01112             if( !subMenu->ControlState.RemoveFromMenu )
01113             {
01114                 //Update the Menu Text
01115                 pMenu->FindItem( subMenu->GetMenuId() )->SetText( wxString( (TCHAR *)subMenu->GetMenuText() ) );
01116 
01117                 if (subMenu->ControlState.Greyed)
01118                     //Disable and Grey Menu Item 
01119                     pMenu->Enable( subMenu->GetMenuId(), false );
01120                 else
01121                 {
01122                     //Enable Menu Item and UnGrey
01123                     pMenu->Enable( subMenu->GetMenuId(), true );
01124 
01125                     if (subMenu->ControlState.Ticked)
01126                     {
01127                         TRACE( _T("Check %s\n"), (PCTSTR)subMenu->GetMenuText() );
01128                         
01129                         //Tick Menu Item
01130                         if (pMenu->FindItem(subMenu->GetMenuId())->IsCheckable())
01131                             pMenu->Check( subMenu->GetMenuId(), true );
01132                     }
01133                     else
01134                         //UnTick Menu Item
01135                         if (pMenu->FindItem(subMenu->GetMenuId())->IsCheckable())
01136                             pMenu->Check( subMenu->GetMenuId(), false );
01137                 }
01138             }
01139             else
01140             // See if this menu item want itself removed from the menu
01141             {
01142                 // take it out of the menu
01143                 pMenu->Delete( subMenu->GetMenuId() );
01144             }
01145         }
01146         else
01147         {
01148             // It's a menu item group, so we need to recurse down
01149             wxMenuItem  *pItem = pMenu->FindItem( subMenu->GetMenuId() );
01150             if (pItem)
01151             {
01152                 wxMenu * pwxSubMenu = pItem->GetSubMenu();
01153                 if (pwxSubMenu)
01154                 {
01155                     UpdateWinMenu(pwxSubMenu,subMenu);
01156                 }
01157             }
01158         }   
01159         subMenu = (kernelMenu->GetNextMenuItem(subMenu));
01160     }
01161 }


Member Data Documentation

UINT32 MenuItem::AutomaticMenuID = AUTO_MENU_ID_MIN [static]
 

Definition at line 232 of file menuitem.h.

const OpState MenuItem::DefaultMenuState [static]
 

Definition at line 237 of file menuitem.h.

String_256 MenuItem::Description [private]
 

Definition at line 178 of file menuitem.h.

BOOL MenuItem::FollowedBySeparator [private]
 

Definition at line 179 of file menuitem.h.

UINT32 MenuItem::m_nSelectedBitmapID [private]
 

Definition at line 180 of file menuitem.h.

UINT32 MenuItem::m_nUnselectedBitmapID [private]
 

Definition at line 181 of file menuitem.h.

UINT32 MenuItem::ParentMenuId [private]
 

Definition at line 176 of file menuitem.h.

OpMenuParam* MenuItem::pMenuParam [private]
 

Definition at line 182 of file menuitem.h.

List* MenuItem::SubMenuItems [private]
 

Definition at line 177 of file menuitem.h.


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