home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MenuBar.cpp
-
- Contains: Implementation of ODMenuBar
-
- Owned by: Richard Rodseth
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <27> 10/23/95 RR # 1291688 Synch with menu manager when
- adding & removing menus, if this menu bar
- is the current menu bar
- <26> 10/8/95 TJ Fixes Recomended by Refball
- <25> 9/12/95 eeh 1283557: use SetErrorCode
- <24> 8/21/95 RR #1271358 GetMenuAndItem throws
- kODErrInvalidCommandID. EnableCommand etc.
- suppress this error and fail silently
- <23> 8/16/95 NP 1274946: ErrorDef.idl problems. Add include
- file.
- <22> 8/15/95 RR #1276683 remove extra new ODPrivMenuInfo.
- <21> 8/3/95 RR #1257260: Collapse B classes. Remove
- somInit methods. Don't call IsInitialized
- or SubclassResponsibility
- <20> 7/25/95 VL 1270320: Delete foundMenu in RemoveMenu.
- Delete elements in _fOtherMenus before
- deleting it.
- <19> 7/25/95 eeh 1259218: remove assert in SetItemString
- <18> 6/8/95 RR #1257260 Collapse base classes. #1214898
- StdTypes.r -> ODTypes.r
- <17> 5/26/95 RR #1251403: Multithreading naming support
- <16> 5/17/95 RR #1250135/1250137/1250143 Getters increment
- refcount
- <15> 4/28/95 RR 1211085 Remove 5$ comments
- <14> 4/13/95 RR # 1216618 Added ODVolatile, #1220325
- Removed private error code
- <13> 4/7/95 RR #1216618 Added SOM_TRY etc.
- <12> 4/6/95 RR #1211085 Remove 5$ comments
- <11> 4/4/95 RR # 1197749 Get/Set ItemString deal with
- script code
- <10> 3/22/95 RR #1197749, 1194296 Set script code in
- SetItemString
- <9> 1/23/95 RR # 1212896 Added EnableAll and DisableAll
- <8> 1/12/95 jpa Don't use obsolete Toolbox names [1211211]
- <7> 9/29/94 RA 1189812: Mods for 68K build.
- <6> 8/25/94 RR Implemented IsValid. Added private
- SetGeneration/GetGeneration
- <5> 8/15/94 JBS 1181023: return kODTrue in IsValid
- <4> 8/15/94 CG #1181023: Added new IsValid API. It is
- not implemented yet.
- <3> 7/19/94 eeh fix to ODMenuBarCopy
- <2> 7/6/94 RR Implemented SetItemString and GetItemString
- <1> 6/23/94 RR first checked in
-
- To Do:
- */
-
-
- #define ODMenuBar_Class_Source
- #define VARIABLE_MACROS
- #include <MenuBar.xih>
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _CMDTABLE_
- #include "CmdTable.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h" // Adkins -- added
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
- #pragma segment ODMenuBar
-
- #include "MenuBarB.cpp" // Platform-independent methods, if any
-
- //=====================================================================================
- // Constants
- //=====================================================================================
- #define kSyntheticMask 0x0F000000
- #define kMenuIDMask 0x00FFFF00
- #define kMenuIDShift 8
- #define kMenuItemMask 0x000000FF
-
-
- class ODPrivMenuInfo
- {
- public:
- ODPrivMenuInfo(ODMenuID menuID, ODPlatformMenu menu,
- ODPart* part, ODSShort position);
- ~ODPrivMenuInfo();
-
- ODMenuID fMenuID;
- ODPlatformMenu fMenu;
- ODPart* fPart;
- ODSShort fPosition;
- };
-
- ODPrivMenuInfo::ODPrivMenuInfo( ODMenuID menuID, ODPlatformMenu menu,
- ODPart* part, ODSShort position)
- {
- fMenuID = menuID;
- fMenu = menu;
- fPart = part;
- fPosition = position;
- }
-
- ODPrivMenuInfo::~ODPrivMenuInfo()
- {
- }
-
- //=====================================================================================
- // Class ODMenuBar
- //=====================================================================================
-
-
- SOM_Scope void SOMLINK ODMenuBarInitMenuBar(ODMenuBar *somSelf, Environment *ev,
- ODSession* session,
- ODPlatformMenuBar menuBar)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarInitMenuBar");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fSession = kODNULL;
- _fSystemMenus = kODNULL;
- _fCommandTable = kODNULL;
- _fOtherMenus = kODNULL;
- _fGeneration = 0;
- */
-
- somSelf->InitRefCntObject(ev);
-
- _fSession = session;
- _fSystemMenus = menuBar;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarAddSubMenu(ODMenuBar *somSelf, Environment *ev,
- ODMenuID menuID,
- ODPlatformMenu menu,
- ODPart* part)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarAddSubMenu");
-
- OrderedCollection* otherMenus = kODNULL; ODVolatile(otherMenus);
- ODPrivMenuInfo* info = kODNULL; ODVolatile(info);
-
- SOM_TRY
-
- if (_fOtherMenus == kODNULL)
- {
- otherMenus = new OrderedCollection;
- _fOtherMenus = otherMenus;
- }
- info = new ODPrivMenuInfo(menuID, menu,part, hierMenu);
- _fOtherMenus->AddLast((ElementType) info);
-
- // if this is the current menu bar, we should also tell the Menu Manager
- TempODMenuBar currentMenuBar = _fSession->GetWindowState(ev)->AcquireCurrentMenuBar(ev);
- if (ODObjectsAreEqual(ev, currentMenuBar, somSelf))
- {
- ::InsertMenu(menu, hierMenu);
- ::InvalMenuBar();
- }
-
- SOM_CATCH_ALL
-
- ODDeleteObject(otherMenus);
- ODDeleteObject(info);
-
- SOM_ENDTRY
-
- }
-
- SOM_Scope void SOMLINK ODMenuBarRegisterCommand(ODMenuBar *somSelf, Environment *ev,
- ODCommandID command,
- ODMenuID menu,
- ODMenuItemID menuItem)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarRegisterCommand");
-
- CommandTable* table = kODNULL; ODVolatile(table);
-
- SOM_TRY
-
- if (_fCommandTable == kODNULL)
- {
- table = new CommandTable;
- _fCommandTable = table;
- }
- _fCommandTable->RegisterCommand(command, menu, menuItem);
-
- SOM_CATCH_ALL
-
- ODDeleteObject(table);
-
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarUnregisterCommand(ODMenuBar *somSelf, Environment *ev,
- ODCommandID command)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarUnregisterCommand");
-
- SOM_TRY
-
- if (_fCommandTable)
- _fCommandTable->UnregisterCommand(command);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarUnregisterAll(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarUnregisterAll");
-
- SOM_TRY
-
- if (_fCommandTable)
- _fCommandTable->UnregisterAll();
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- SOM_Scope ODBoolean SOMLINK ODMenuBarIsCommandRegistered(ODMenuBar *somSelf, Environment *ev,
- ODCommandID command)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarIsCommandRegistered");
-
- ODBoolean isRegistered = kODFalse;
-
- SOM_TRY
-
- if (_fCommandTable)
- isRegistered = _fCommandTable->IsCommandRegistered(command);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return isRegistered;
- }
-
- SOM_Scope ODBoolean SOMLINK ODMenuBarIsCommandSynthetic(ODMenuBar *somSelf, Environment *ev,
- ODCommandID command)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarIsCommandSynthetic");
-
- return (command&kSyntheticMask) == kSyntheticMask;
- }
-
- SOM_Scope ODCommandID SOMLINK ODMenuBarGetCommand(ODMenuBar *somSelf, Environment *ev,
- ODMenuID menu,
- ODMenuItemID menuItem)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarGetCommand");
-
- ODCommandID command = kNoCommand;
-
- SOM_TRY
-
- if (_fCommandTable)
- command = _fCommandTable->GetCommand(menu, menuItem);
-
- if (command == kNoCommand)
- // No command in table, so synthesize one:
- command = kSyntheticMask | ((long)menu<<kMenuIDShift) | (menuItem & kMenuItemMask);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return command;
- }
-
- SOM_Scope void SOMLINK ODMenuBarGetMenuAndItem(ODMenuBar *somSelf, Environment *ev,
- ODCommandID command,
- ODMenuID* menu,
- ODMenuItemID* menuItem)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarGetMenuAndItem");
-
- ODBoolean found = kODFalse;
-
- SOM_TRY
-
- if (somSelf->IsCommandSynthetic(ev, command))
- {
- *menu = (ODMenuID) ((command & kMenuIDMask) >>kMenuIDShift);
- *menuItem = (ODMenuItemID) (command & kMenuItemMask);
- found = kODTrue;
- }
- else if (_fCommandTable)
- {
- found = _fCommandTable->GetMenuAndItem(command, *menu, *menuItem);
- }
- if (!found)
- THROW(kODErrInvalidCommandID);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarEnableCommand(ODMenuBar *somSelf, Environment *ev,
- ODCommandID cmdNumber,
- ODBoolean enable)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarEnableCommand");
-
- SOM_TRY
-
- ODMenuID menuID;
- ODMenuItemID item;
- somSelf->GetMenuAndItem( ev, cmdNumber, &menuID, &item ) ; // THROWS
- ODPlatformMenu macMenu = somSelf->GetMenu( ev, menuID ) ;
- if (macMenu)
- {
- if (enable)
- EnableItem(macMenu, item) ;
- else
- DisableItem(macMenu, item) ;
- }
-
- SOM_CATCH_ALL
-
- SetErrorCode(kODNoError);
-
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarCheckCommand(ODMenuBar *somSelf, Environment *ev,
- ODCommandID cmdNumber,
- ODBoolean check)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarCheckCommand");
-
- SOM_TRY
-
- ODMenuID menuID;
- ODMenuItemID item;
- somSelf->GetMenuAndItem( ev, cmdNumber, &menuID, &item ) ;
- ODPlatformMenu macMenu = somSelf->GetMenu( ev, menuID ) ;
- if (macMenu)
- CheckItem(macMenu, item, check);
-
- SOM_CATCH_ALL
-
- SetErrorCode(kODNoError);
-
- SOM_ENDTRY
-
- }
-
- SOM_Scope void SOMLINK ODMenuBarEnableAndCheckCommand(ODMenuBar *somSelf, Environment *ev,
- ODCommandID cmdNumber,
- ODBoolean enable,
- ODBoolean check)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarEnableAndCheckCommand");
-
- SOM_TRY
-
- ODMenuID menuID;
- ODMenuItemID item;
- somSelf->GetMenuAndItem( ev, cmdNumber, &menuID, &item ) ;
- ODPlatformMenu macMenu = somSelf->GetMenu( ev, menuID ) ;
- if (macMenu)
- {
- if ( enable )
- EnableItem(macMenu, item) ;
- else
- DisableItem(macMenu, item) ;
- CheckItem(macMenu, item, check);
- }
-
- SOM_CATCH_ALL
-
- SetErrorCode(kODNoError);
-
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarSetItemString(ODMenuBar *somSelf, Environment *ev,
- ODCommandID cmdNumber,
- ODIText* itemString)
- {
- const ODSShort kUseSpecificScript = 0x1c;
-
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarSetItemString");
-
- SOM_TRY
-
- ODMenuID menuID;
- ODMenuItemID item;
- somSelf->GetMenuAndItem( ev, cmdNumber, &menuID, &item ) ;
- ODPlatformMenu macMenu = somSelf->GetMenu( ev, menuID ) ;
- if( macMenu != kODNULL )
- {
- StringPtr s = GetPStringFromIText(itemString);
- SetMenuItemText(macMenu, item, s);
- ODDisposePtr(s);
-
- short scriptID = GetITextScriptCode(itemString);
- ODSLong savedSMFontForceFlag = GetScriptManagerVariable(smFontForce);
- SetScriptManagerVariable(smFontForce, false);
-
- if (scriptID != FontToScript(GetAppFont()))
- {
- SetItemCmd(macMenu, item, kUseSpecificScript);
- SetItemIcon(macMenu, item, scriptID);
- }
-
- SetScriptManagerVariable(smFontForce, savedSMFontForceFlag);
- }
-
- SOM_CATCH_ALL
-
- SetErrorCode(kODNoError);
-
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarGetItemString(ODMenuBar *somSelf, Environment *ev,
- ODCommandID cmdNumber,
- ODIText* itemString)
- {
- const ODSShort kUseSpecificScript = 0x1c;
-
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarGetItemString");
-
- SOM_TRY
-
- ODMenuID menuID;
- ODMenuItemID item;
- somSelf->GetMenuAndItem( ev, cmdNumber, &menuID, &item ) ;
- ODPlatformMenu macMenu = somSelf->GetMenu( ev, menuID ) ;
- if (macMenu)
- {
- if (itemString)
- {
- itemString->format = kODTraditionalMacText;
- itemString->text._buffer = kODNULL;
- }
-
- Str255 s;
- GetMenuItemText(macMenu, item, s);
- SetITextString(itemString, s);
-
- // Is this correct?
- short cmd;
- short scriptID = smSystemScript;
- ODSLong savedSMFontForceFlag = GetScriptManagerVariable(smFontForce);
- SetScriptManagerVariable(smFontForce, false);
- GetItemCmd (macMenu, item, &cmd);
- if (cmd == kUseSpecificScript)
- {
- GetItemIcon (macMenu, item, &scriptID);
- }
- SetITextScriptCode(itemString, scriptID);
- SetITextLangCode(itemString, langEnglish);
- SetScriptManagerVariable(smFontForce, savedSMFontForceFlag);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarSetCommandTable(ODMenuBar *somSelf, Environment *ev,
- CommandTable* table)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarSetCommandTable");
-
- _fCommandTable = table;
- }
-
- SOM_Scope void SOMLINK ODMenuBarDisableAll(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarDisableAll");
-
- SOM_TRY
-
- if (_fOtherMenus)
- {
- ODPlatformMenu platformMenu = kODNULL;
- OrderedCollectionIterator iter(_fOtherMenus);
- for (ODPrivMenuInfo* menuInfo = (ODPrivMenuInfo*) iter.First();
- iter.IsNotComplete();
- menuInfo = (ODPrivMenuInfo*) iter.Next())
- {
- platformMenu = menuInfo->fMenu;
- DisableItem(platformMenu,0);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarEnableAll(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarEnableAll");
-
- SOM_TRY
-
- if (_fOtherMenus)
- {
- ODPlatformMenu platformMenu = kODNULL;
- OrderedCollectionIterator iter(_fOtherMenus);
- for (ODPrivMenuInfo* menuInfo = (ODPrivMenuInfo*) iter.First();
- iter.IsNotComplete();
- menuInfo = (ODPrivMenuInfo*) iter.Next())
- {
- platformMenu = menuInfo->fMenu;
- EnableItem(platformMenu,0);
- }
- }
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarsomUninit(ODMenuBar *somSelf)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarsomUninit");
-
- ODDeleteObject(_fCommandTable);
-
- if (_fOtherMenus)
- {
- TRY
- OrderedCollectionIterator* iter = _fOtherMenus->CreateIterator();
- for (ElementType t = iter->First(); iter->IsNotComplete(); t = iter->Next())
- {
- ODDeleteObject(t);
- }
- ODDeleteObject(iter);
- ODDeleteObject(_fOtherMenus);
- CATCH_ALL
- // Ignore any exceptions
- ENDTRY
- }
- }
-
- SOM_Scope ODSize SOMLINK ODMenuBarPurge(ODMenuBar *somSelf, Environment *ev,
- ODSize size)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarPurge");
-
- ODSize purgeSize = 0;
-
- SOM_TRY
-
- purgeSize = parent_Purge(somSelf, ev, size);
-
- SOM_CATCH_ALL
- WARN("Error %ld trying to purge in ODMenuBarPurge",ErrorCode());
- SetErrorCode(kODNoError); // dh - Eat the exception; Purge should not
- // propagate it because clients function
- // fine whether memory was purged or not.
- SOM_ENDTRY
-
- return purgeSize;
- }
-
- SOM_Scope void SOMLINK ODMenuBarRelease(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarRelease");
-
- SOM_TRY
-
- parent_Release(somSelf,ev);
- if (somSelf->GetRefCount(ev) == 0)
- somSelf->somFree();
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarDisplay(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarDisplay");
-
- SOM_TRY
-
- if (_fSystemMenus)
- {
- ClearMenuBar();
- SetMenuBar(_fSystemMenus);
- }
- if (_fOtherMenus)
- {
- OrderedCollectionIterator iter(_fOtherMenus);
- for (ODPrivMenuInfo* menu = (ODPrivMenuInfo*) iter.First();
- iter.IsNotComplete();
- menu = (ODPrivMenuInfo*) iter.Next())
- {
- InsertMenu(menu->fMenu,menu->fPosition);
- }
- }
- InvalMenuBar();
-
- _fSession->GetWindowState(ev)->SetCurrentMenuBar(ev,somSelf);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarAddMenuLast(ODMenuBar *somSelf, Environment *ev,
- ODMenuID menuID,
- ODPlatformMenu menu,
- ODPart* part)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarAddMenuLast");
-
- OrderedCollection* otherMenus = kODNULL; ODVolatile(otherMenus);
- ODPrivMenuInfo* info = kODNULL; ODVolatile(info);
-
- SOM_TRY
-
- if (_fOtherMenus == kODNULL)
- {
- otherMenus = new OrderedCollection;
- _fOtherMenus = otherMenus;
- }
- info = new ODPrivMenuInfo(menuID, menu,part, 0);
- _fOtherMenus->AddLast((ElementType) info);
-
- // if this is the current menu bar, we should also tell the Menu Manager
- TempODMenuBar currentMenuBar = _fSession->GetWindowState(ev)->AcquireCurrentMenuBar(ev);
- if (ODObjectsAreEqual(ev, currentMenuBar, somSelf))
- {
- ::InsertMenu(menu, 0);
- ::InvalMenuBar();
- }
-
- SOM_CATCH_ALL
-
- ODDeleteObject(otherMenus);
- ODDeleteObject(info);
-
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarAddMenuBefore(ODMenuBar *somSelf, Environment *ev,
- ODMenuID menuID,
- ODPlatformMenu menu,
- ODPart* part,
- ODMenuID beforeID)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarAddMenuBefore");
-
- OrderedCollection* otherMenus = kODNULL; ODVolatile(otherMenus);
- ODPrivMenuInfo* info = kODNULL; ODVolatile(info);
-
- SOM_TRY
-
- if (_fOtherMenus == kODNULL)
- {
- otherMenus = new OrderedCollection;
- _fOtherMenus = otherMenus;
- }
- info = new ODPrivMenuInfo(menuID, menu,part, beforeID);
- _fOtherMenus->AddLast((ElementType) info);
-
- // if this is the current menu bar, we should also tell the Menu Manager
- TempODMenuBar currentMenuBar = _fSession->GetWindowState(ev)->AcquireCurrentMenuBar(ev);
- if (ODObjectsAreEqual(ev, currentMenuBar, somSelf))
- {
- ::InsertMenu(menu, beforeID);
- ::InvalMenuBar();
- }
-
- SOM_CATCH_ALL
-
- ODDeleteObject(otherMenus);
- ODDeleteObject(info);
-
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODMenuBarRemoveMenu(ODMenuBar *somSelf, Environment *ev,
- ODMenuID menu)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarRemoveMenu");
-
- ODPrivMenuInfo* foundMenu = kODNULL;
-
- SOM_TRY
-
- if (_fOtherMenus)
- {
- OrderedCollectionIterator iter(_fOtherMenus);
- for (ODPrivMenuInfo* menuInfo = (ODPrivMenuInfo*) iter.First();
- iter.IsNotComplete();
- menuInfo = (ODPrivMenuInfo*) iter.Next())
- {
- if (menuInfo->fMenuID == menu)
- {
- foundMenu = menuInfo;
- break;
- }
- }
- if (foundMenu)
- {
- _fOtherMenus->Remove((ElementType) foundMenu);
-
- // if this is the current menu bar, we should also tell the Menu Manager
- TempODMenuBar currentMenuBar = _fSession->GetWindowState(ev)->AcquireCurrentMenuBar(ev);
- if (ODObjectsAreEqual(ev, currentMenuBar, somSelf))
- {
- ::DeleteMenu(menu);
- ::InvalMenuBar();
- }
- }
- ODDeleteObject(foundMenu);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope ODPlatformMenu SOMLINK ODMenuBarGetMenu(ODMenuBar *somSelf, Environment *ev,
- ODMenuID menu)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarGetMenu");
-
- ODPlatformMenu platformMenu = kODNULL;
-
- SOM_TRY
-
- if (_fOtherMenus)
- {
- OrderedCollectionIterator iter(_fOtherMenus);
- for (ODPrivMenuInfo* menuInfo = (ODPrivMenuInfo*) iter.First();
- iter.IsNotComplete();
- menuInfo = (ODPrivMenuInfo*) iter.Next())
- {
- if (menuInfo->fMenuID == menu)
- {
- platformMenu = menuInfo->fMenu;
- break;
- }
- }
- }
- // In case it's in the system menus:
- if (platformMenu == kODNULL)
- platformMenu = GetMenuHandle(menu);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return platformMenu;
- }
-
- SOM_Scope ODBoolean SOMLINK ODMenuBarIsValid(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarIsValid");
-
- ODBoolean isValid = kODFalse;
-
- SOM_TRY
-
- ODMenuBar* baseMenuBar = _fSession->GetWindowState(ev)->AcquireBaseMenuBar(ev);
- if (baseMenuBar)
- isValid = _fGeneration == baseMenuBar->GetGeneration(ev);
- baseMenuBar->Release(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return isValid;
- }
-
-
- SOM_Scope void SOMLINK ODMenuBarSetGeneration(ODMenuBar *somSelf, Environment *ev,
- ODULong generation)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarSetGeneration");
-
- _fGeneration = generation;
- }
-
-
- SOM_Scope ODULong SOMLINK ODMenuBarGetGeneration(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarGetGeneration");
-
- return _fGeneration;
- }
-
- SOM_Scope ODMenuBar* SOMLINK ODMenuBarCopy(ODMenuBar *somSelf, Environment *ev)
- {
- ODMenuBarData *somThis = ODMenuBarGetData(somSelf);
- ODMenuBarMethodDebug("ODMenuBar","ODMenuBarCopy");
-
- // Needs work, obviously!
-
- ODMenuBar* copy = kODNULL; ODVolatile(copy);
-
- SOM_TRY
-
- copy = new ODMenuBar();
- THROW_IF_NULL(copy); // "new" does not THROW for SOM objects
- copy->InitMenuBar(ev, _fSession,_fSystemMenus);
-
- if (_fOtherMenus)
- {
- OrderedCollectionIterator iter(_fOtherMenus);
- for (ODPrivMenuInfo* menu = (ODPrivMenuInfo*) iter.First();
- iter.IsNotComplete();
- menu = (ODPrivMenuInfo*) iter.Next())
- {
- if (menu->fPosition == 0)
- copy->AddMenuLast(ev, menu->fMenuID, menu->fMenu, menu->fPart);
- else if (menu->fPosition == hierMenu)
- copy->AddSubMenu(ev, menu->fMenuID, menu->fMenu, menu->fPart);
- else
- copy->AddMenuBefore(ev, menu->fMenuID, menu->fMenu,
- menu->fPart, menu->fPosition);
- }
- if (_fCommandTable) //!!! eeewh!!!
- // copy->fCommandTable = _fCommandTable->Copy();
- copy->SetCommandTable(ev, _fCommandTable->Copy() ); // <eeh> was somSelf->SetCommandTable
- }
- copy->SetGeneration(ev, _fGeneration);
-
- SOM_CATCH_ALL
-
- ODDeleteObject(copy);
-
- SOM_ENDTRY
-
- return copy;
- }
-