menuitem.cpp

Go to the documentation of this file.
00001 // $Id: menuitem.cpp 1464 2006-07-18 12:32:26Z gerry $
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     menuitem.cpp - This class models menu items. It has a similar purpose to the MFC CMenu
00102     class, but instead of modelling the whole menu it models individual menu items and 
00103     further more is platform independent.
00104 
00105 ********************************************************************************************/
00106 
00107 
00108 #include "camtypes.h"
00109 #include "menuitem.h"
00110 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "mario.h"
00112 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "oilmenus.h"
00114 #include "hotkeys.h"
00115 
00116 DECLARE_SOURCE("$Revision: 1464 $");  
00117 
00118 
00119 const OpState MenuItem::DefaultMenuState( FALSE, TRUE );        // not ticked, but greyed
00120 
00121 CC_IMPLEMENT_MEMDUMP(MenuItem, CmdControl)
00122 CC_IMPLEMENT_DYNAMIC(OpMenuParam, OpParam)
00123 
00124 // This will get Camelot to display the filename and linenumber of any memory allocations
00125 // that are not released at program exit
00126 #define new CAM_DEBUG_NEW
00127 
00128 /********************************************************************************************
00129 
00130 >   MenuItem::MenuItem( UINT32 parentMenuID,
00131                         OpDescriptor *Owner,
00132                         BOOL separator
00133                       )
00134 
00135     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00136     Created:    12/7/93
00137     Inputs:     Parent Menu Identifier
00138                 Pointer to owner OpDescriptor
00139                 Separator flag (defaults to FALSE)
00140     Outputs:    None
00141     Returns:    None
00142     Purpose:    Constructor for the MenuItem Class. Creates a new menu items and connects
00143                 to an OpDescriptor. The ID of the menu is determined algorithmically.
00144     Errors:     None
00145 
00146 ********************************************************************************************/
00147 
00148 MenuItem::MenuItem( UINT32 parentMenuID, OpDescriptor* pOwner, BOOL separator )
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 }
00166     
00167 /********************************************************************************************
00168 
00169 >   MenuItem::MenuItem( const String_256& description, UINT32 parentMenuID,  BOOL separator)
00170 
00171     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00172     Created:    12/7/93
00173     Inputs:     Parent Menu Identifier
00174                 Constanst String Reference for description of Menu.
00175                 Boolean - Followed By Separator Flag
00176     Outputs:    None
00177     Returns:    None
00178     Purpose:    Constructor for the MenuItem Class. Used for creating new group menu items. 
00179     Errors:     None
00180 
00181 ********************************************************************************************/
00182 
00183 MenuItem::MenuItem(const String_256& description, UINT32 parentMenuID, BOOL separator)
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 }
00195     
00196 /********************************************************************************************
00197 
00198 >   MenuItem::~MenuItem()
00199 
00200     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00201     Created:    7/9/93
00202     Purpose:    Default destructor.
00203     Errors:     None
00204 
00205 ********************************************************************************************/
00206 
00207 MenuItem::~MenuItem()
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 }
00221 
00222 /********************************************************************************************
00223 
00224 >   BOOL MenuItem::IsFollowedBySeparator()
00225 
00226     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00227     Created:    28/6/93
00228     Inputs:     None
00229     Outputs:    None
00230     Returns:    True if MenuItem is followed by a separator in the menu.
00231                 False if MenuItem is not followed by a separator
00232     Purpose:    
00233         Identifies if the current MenuItem has a separator following it in the menu to which  
00234         it belongs.
00235     Errors:     None
00236 
00237 ********************************************************************************************/
00238 
00239 BOOL MenuItem::IsFollowedBySeparator()
00240 {
00241      return FollowedBySeparator;
00242 }
00243 
00244 /********************************************************************************************
00245 
00246 >   BOOL MenuItem::SetIsFollowedBySeparator(BOOL NewValue)
00247 
00248     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00249     Created:    5/3/97
00250     Inputs:     NewValue to be applied as the IsFollowedBySeparator flag
00251     Outputs:    None
00252     Returns:    the old state of the IsFollowedBySeparator flag.
00253     Purpose:    Sets a new state for the IsFollowedBySeparator flag. This Identifies if the
00254                 current MenuItem has a separator following it in the menu to which it belongs.
00255     Errors:     None
00256 
00257 ********************************************************************************************/
00258 
00259 BOOL MenuItem::SetIsFollowedBySeparator(BOOL NewValue)
00260 {
00261      BOOL OldValue = FollowedBySeparator;
00262      FollowedBySeparator = NewValue;
00263      return OldValue;
00264 }
00265 
00266 /********************************************************************************************
00267 
00268 >   BOOL MenuItem::IsMenuItemGroup()
00269 
00270     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00271     Created:    28/6/93
00272     Inputs:     None
00273     Outputs:    None
00274     Returns:    True if there are any SubMenuItems in current MenuItem 
00275                 False if MenuItem is singular
00276     Purpose:    Identifies if the current MenuItem is a group.
00277     Errors:     None
00278 
00279 ********************************************************************************************/
00280 
00281 BOOL MenuItem::IsMenuItemGroup()
00282 {
00283     return (SubMenuItems == NULL)? FALSE : TRUE;
00284 }
00285 
00286 /********************************************************************************************
00287 
00288 >   BOOL MenuItem::IsCheckable()
00289 
00290     Author:     Luke_Hart (Xara Group Ltd) <lukeh@xara.com>
00291     Created:    10/03/06
00292     Inputs:     None
00293     Outputs:    None
00294     Returns:    True if the item should have a check box else it shouldn't
00295     Errors:     None
00296 
00297 ********************************************************************************************/
00298 
00299 BOOL MenuItem::IsCheckable()
00300 {
00301     return OwnerOperation->GetOpFlags().fCheckable;
00302 }
00303 
00304 /********************************************************************************************
00305 
00306 >   virtual void MenuItem::PerformAction()
00307 
00308     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00309     Created:    12/10/93
00310     Inputs:     None
00311     Outputs:    None
00312     Returns:    None
00313     Purpose:    Performs the action assoicated with a CmdControl. 
00314     Errors:     None
00315 
00316 ********************************************************************************************/
00317 
00318 void MenuItem::PerformAction()
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 }
00335 
00336 
00337 /********************************************************************************************
00338 
00339 >   BOOL MenuItem::UpdateControlState(BOOL AppendHotKeyName = TRUE)
00340 
00341     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00342     Created:    17/6/93
00343     Inputs:     None
00344     Outputs:    None
00345     Returns:    TRUE if state is updated 
00346                 FALSE otherwise
00347     Purpose:    Obtains the state of a MenuItem. 
00348     Errors:     None
00349 
00350 ********************************************************************************************/
00351 
00352 BOOL MenuItem::UpdateControlState(BOOL AppendHotKeyName)
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 }
00417 
00418     
00419 /********************************************************************************************
00420 
00421 >   void MenuItem::PopulateMenuParam()
00422 
00423     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00424     Created:    13/10/2004
00425     Inputs:     -
00426     Outputs:    -
00427     Returns:    -
00428     Purpose:    Fills in the OpMenuParam supplied by the menu builder with details of this
00429                 specific menu item
00430     Errors:     None
00431 
00432 ********************************************************************************************/
00433 
00434 void MenuItem::PopulateMenuParam()
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 }
00454 
00455 
00456 /********************************************************************************************
00457 
00458 >   BOOL MenuItem::UpdateMenuState(BOOL AppendHotKeyNames = TRUE)
00459 
00460     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00461     Created:    17/6/93
00462     Inputs:     None
00463     Outputs:    None
00464     Returns:    True if all Menu Enabled
00465                 False Otherwize
00466     Purpose:    Obtains the state of all MenuItems in MenuItem. 
00467     Errors:     None
00468 
00469 ********************************************************************************************/
00470 
00471 BOOL MenuItem::UpdateMenuState(BOOL AppendHotKeyNames)
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 }
00498 
00499 /********************************************************************************************
00500 
00501 >   UINT32 MenuItem::GetMenuId()
00502 
00503     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00504     Created:    28/6/93
00505     Inputs:     None
00506     Outputs:    None
00507     Returns:    Menu Id of current MenuItem
00508     Purpose:    Gets the menu Id of the current MenuItem.
00509     Errors:     None
00510 
00511 ********************************************************************************************/
00512 
00513 UINT32 MenuItem::GetMenuId()
00514 {
00515     return ControlId;
00516 }
00517 
00518 /********************************************************************************************
00519 
00520 >   UINT32 MenuItem::GetHelpId()
00521 
00522     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00523     Created:    25/1/94
00524     Inputs:     None
00525     Outputs:    None
00526     Returns:    Help Id of current MenuItem
00527     Purpose:    Gets the Help Id of the current MenuItem.
00528     Errors:     None
00529 
00530 ********************************************************************************************/
00531 
00532 UINT32 MenuItem::GetHelpId()
00533 {
00534     return OwnerOperation->GetHelpId();
00535 }
00536 
00537 /********************************************************************************************
00538 
00539 >   UINT32 MenuItem::GetMenuItemParentId()
00540 
00541     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00542     Created:    28/6/93
00543     Inputs:     None
00544     Outputs:    None
00545     Returns:    Menu Id of parent of current MenuItem
00546     Purpose:    Gets the menu Id of the parent of the current MenuItem.
00547     Errors:     None
00548 
00549 ********************************************************************************************/
00550 
00551 UINT32 MenuItem::GetMenuItemParentId()
00552 {
00553     return ParentMenuId;
00554 }
00555 
00556 /********************************************************************************************
00557 
00558 >   String_256 MenuItem::GetMenuText()
00559 
00560     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00561     Created:    28/6/93
00562     Inputs:     None
00563     Outputs:    None
00564     Returns:    String representing a description of the MenuItem
00565     Purpose:    Gets MenuItem Text Description.
00566     Errors:     None
00567 
00568 ********************************************************************************************/
00569 
00570 String_256 MenuItem::GetMenuText()
00571 {
00572     return Description;
00573 }
00574 
00575 
00576 
00577 /********************************************************************************************
00578 >   UINT32 MenuItem::GetMenuSelectedBitmapID()
00579 
00580     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00581     Created:    21/5/00
00582     Returns:    Resource identifier of the small bitmap associated with this menu item,
00583                 or 0 if there isn't one available.
00584     Purpose:    Looks up and caches the bitmap resource for this MenuItem.
00585 ********************************************************************************************/
00586 
00587 UINT32 MenuItem::GetMenuSelectedBitmapID()
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 }
00598 
00599 
00600 
00601 /********************************************************************************************
00602 >   UINT32 MenuItem::GetMenuUnselectedBitmapID()
00603 
00604     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00605     Created:    21/5/00
00606     Returns:    Resource identifier of the small bitmap associated with this menu item,
00607                 or 0 if there isn't one available.
00608     Purpose:    Looks up and caches the bitmap resource for this MenuItem.
00609 ********************************************************************************************/
00610 
00611 UINT32 MenuItem::GetMenuUnselectedBitmapID()
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 }
00622 
00623 
00624 
00625 /********************************************************************************************
00626 
00627 >   String_256 *MenuItem::GetMenuDesc()
00628 
00629     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00630     Created:    28/6/93
00631     Inputs:     None
00632     Outputs:    None
00633     Returns:    If Succesfull returns a string representing a description of the MenuItem
00634                 otherwise NULL
00635     Purpose:    Gets MenuItem Text Description.
00636     Errors:     None
00637 
00638 ********************************************************************************************/
00639 
00640 String_256 *MenuItem::GetMenuDesc()
00641 {
00642     static String_256 MenuDesc = "";                 
00643     
00644     if (OwnerOperation->GetText(&MenuDesc, OP_DESC_TEXT))
00645         return &MenuDesc;
00646     else
00647         return NULL;
00648 }
00649 
00650 /********************************************************************************************
00651 
00652 >   String_32 *MenuItem::GetOpToken()
00653 
00654     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00655     Created:    17/1/97
00656     Inputs:     None
00657     Outputs:    None
00658     Returns:    If Succesfull returns a string representing the OpToken of the MenuItem
00659                 otherwise returns a NULL
00660     Purpose:    Gets the OpToken for the menu item.
00661     Errors:     None
00662 
00663 ********************************************************************************************/
00664 
00665 String_32 * MenuItem::GetOpToken()
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 }
00677 
00678 
00679 /********************************************************************************************
00680 
00681 >   MenuItem *MenuItem::GetFirstMenuItem()
00682 
00683     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00684     Created:    25/6/93
00685     Inputs:     None
00686     Outputs:    None
00687     Returns:    First MenuItem in Group
00688     Purpose:    Obtains the first MenuItem in MenuItem. 
00689     Errors:     None
00690 
00691 ********************************************************************************************/
00692 
00693 MenuItem *MenuItem::GetFirstMenuItem() 
00694 {                                         
00695     if (SubMenuItems == NULL)
00696         return NULL;
00697     else
00698         return (MenuItem*)(SubMenuItems->GetHead());
00699 }
00700 
00701 /********************************************************************************************
00702 
00703 >   MenuItem *MenuItem::GetNextMenuItem(MenuItem* CurrItem)
00704 
00705     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00706     Created:    25/6/93
00707     Inputs:     None
00708     Outputs:    None
00709     Returns:    First MenuItem in Group
00710     Purpose:    Obtains the next MenuItem in MenuItem. 
00711     Errors:     None
00712 
00713 ********************************************************************************************/
00714 
00715 MenuItem *MenuItem::GetNextMenuItem(MenuItem* CurrItem) 
00716 {
00717     if (SubMenuItems == NULL)
00718         return NULL;
00719     else
00720         return (MenuItem*)(SubMenuItems->GetNext(CurrItem));
00721 }
00722 
00723 /********************************************************************************************
00724 
00725 >   BOOL MenuItem::AddMenuItem(MenuItem newItem)
00726 
00727     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00728     Created:    17/6/93
00729     Inputs:     New MenuItem
00730     Outputs:    None
00731     Returns:    True if MenuItem is added successfully
00732                 False if MenuItem isn't added 
00733     Purpose:    Adds a MenuItem to a MenuItem. 
00734     Errors:     None
00735 
00736 ********************************************************************************************/
00737 
00738 BOOL MenuItem::AddMenuItem(MenuItem *newItem)
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 }
00754 
00755 /********************************************************************************************
00756 
00757 >   MenuItem *MenuItem::RemoveMenuItem(MenuItem* Item)
00758 
00759     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00760     Created:    25/6/93
00761     Inputs:     None
00762     Outputs:    None
00763     Returns:    MenuItem removed from SubMenuItems List
00764     Purpose:    Removes MenuItem from SubMenuItems List. 
00765     Errors:     None
00766 
00767 ********************************************************************************************/
00768 
00769 MenuItem *MenuItem::RemoveMenuItem(MenuItem* Item)
00770 {
00771     if (SubMenuItems == NULL)
00772         return NULL;
00773     else    
00774         return (MenuItem*)(SubMenuItems->RemoveItem(Item));
00775 }
00776 
00777 
00778 // this is used to automatically create unique menu IDs. It ranges from two (OIL specific)
00779 // values, AUTO_MENU_ID_MIN and AUTO_MENU_ID_MAX inclusive (defined in oilmenus.h)
00780 
00781 UINT32 MenuItem::AutomaticMenuID = AUTO_MENU_ID_MIN;
00782 
00783 
00784 /********************************************************************************************
00785 
00786 >   static UINT32 GetNextAutomaticMenuID()
00787 
00788     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00789     Created:    12/7/93
00790     Inputs:     None
00791     Outputs:    None
00792     Returns:    The next automatic menu ID value
00793     Purpose:    Creates a unique ID for each menu, based on a monotonic increasing value
00794                 (whose range is determined by the OIL layer). When the range fills, a search
00795                 is done to find individual unused IDs.
00796     Friend:     MenuItem
00797     Errors:     Will ENSURE when range is filled.
00798     Scope:      Private
00799 
00800 ********************************************************************************************/
00801 
00802 UINT32 MenuItem::GetNextAutomaticMenuID()
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 }
00816 
00817 
00818 
00819 
00820 /********************************************************************************************
00821 
00822 >   static UINT32 MenuItem::GetAutomaticIDState()
00823 
00824     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00825     Created:    17/03/95
00826     Inputs:     None
00827     Outputs:    None
00828     Returns:    The next automatic menu ID value without incrementing the internal counter.
00829     Purpose:    Finds the current state of the menu ID generator so that it can be preserved.
00830     Scope:      Public
00831 
00832 ********************************************************************************************/
00833 
00834 UINT32 MenuItem::GetAutomaticIDState()
00835 {
00836     return AutomaticMenuID;                         // return current value
00837 }
00838 
00839 
00840 
00841 
00842 /********************************************************************************************
00843 
00844 >   static BOOL MenuItem::SetAutomaticIDState(UINT32 newvalue)
00845 
00846     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00847     Created:    17/03/95
00848     Inputs:     The new value for the internal menu ID generator.
00849     Outputs:    None
00850     Returns:    -
00851     Purpose:    Allows the state of the menu ID generator to be restored after it been 
00852                 preserved.
00853     Scope:      Public
00854 
00855 ********************************************************************************************/
00856 
00857 BOOL MenuItem::SetAutomaticIDState(UINT32 newvalue)
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 }
00865 
00866 
00867 
00868 

Generated on Sat Nov 10 03:45:41 2007 for Camelot by  doxygen 1.4.4