home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 28.0 KB | 871 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPullDM.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPULLDM_H
- #include "FWPullDM.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- #ifndef FWBNDSTR_H
- #include "FWBndStr.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwmenu
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CPullDownMenu)
-
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LPullDownMenu, FW_CPullDownMenu, FW_CPullDownMenu::Read, FW_CPullDownMenu::Write)
-
- //========================================================================================
- // class FW_CPullDownMenu
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev) :
- fMenuID(-1)
- {
- FW_CString32 menuTitle(" ");
- this->PrivInitialize(ev, menuTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev, const FW_CString& menuTitle) :
- fMenuID(-1)
- {
- this->PrivInitialize(ev, menuTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long stringId) :
- fMenuID(-1)
- {
- FW_CString32 menuTitle;
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, stringId, menuTitle);
- this->PrivInitialize(ev, menuTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev, FW_CReadableStream& archive)
- {
- FW_Char str[256];
-
- archive >> fMenuID;
- archive >> str;
-
- FW_CString32 menuTitle(str);
- this->PrivInitialize(ev, menuTitle);
-
- // ----- Read every items -----
- unsigned long count;
- archive >> count;
- for (unsigned long i = 0; i < count; i++)
- {
- FW_CMenuItem* menuItem;
- FW_READ_DYNAMIC_OBJECT(archive, &menuItem, FW_CMenuItem);
- AdoptMenuItemLast(ev, menuItem);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivInitialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivInitialize(Environment* ev, const FW_CString& menuTitle)
- {
- fMenuBar = NULL;
- fParentMenuItem = NULL;
-
- fItems = new FW_CPrivOrderedCollection;
-
- #ifdef FW_BUILD_MAC
- Str255 str;
- menuTitle.ExportPascal(str);
- fPlatformMenu = ::NewMenu(fMenuID, str);
- #endif
-
- #ifdef FW_BUILD_WIN
- fPlatformMenu.menu = ::CreatePopupMenu();
- menuTitle.Export(fPlatformMenu.strMenu);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::~FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::~FW_CPullDownMenu()
- {
- if (fItems)
- {
- FW_CMenuItem* item;
- while ((item = (FW_CMenuItem*)fItems->First()) != NULL)
- {
- fItems->Remove(item);
- delete item;
- }
-
- delete fItems;
- fItems = NULL;
- }
-
- #ifdef FW_BUILD_MAC
- if (fPlatformMenu)
- {
- ::DisposeMenu(fPlatformMenu);
- fPlatformMenu = NULL;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- if (fPlatformMenu.menu)
- {
- ::DestroyMenu(fPlatformMenu.menu);
- fPlatformMenu.menu = NULL;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendTextItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendTextItem(Environment* ev,
- const FW_CString& text,
- ODCommandID commandID,
- FW_MenuKey menuKey)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = new FW_CTextItem(ev, this, index, text, commandID, menuKey);
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendTextItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendTextItem(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long id,
- ODCommandID commandID,
- FW_MenuKey menuKey)
- {
- FW_CString255 string;
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, id, string);
- this->AppendTextItem(ev, string, commandID, menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertTextItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertTextItem(Environment* ev,
- const FW_CString& text,
- ODCommandID commandID,
- short afterItem,
- FW_MenuKey menuKey)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = new FW_CTextItem(ev, this, index, text, commandID, menuKey);
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertTextItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertTextItem(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long id,
- ODCommandID commandID,
- short afterItem,
- FW_MenuKey menuKey)
- {
- FW_CString255 string;
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, id, string);
- this->InsertTextItem(ev, string, commandID, afterItem, menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertTextItemAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertTextItemAfterCommand(Environment* ev,
- const FW_CString& text,
- ODCommandID commandID,
- ODCommandID afterCommand,
- FW_MenuKey menuKey)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertTextItem(ev, text, commandID, item->GetIndex(ev), menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertTextItemAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertTextItemAfterCommand(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long id,
- ODCommandID commandID,
- ODCommandID afterCommand,
- FW_MenuKey menuKey)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertTextItem(ev, resFile, resourceId, id, commandID, item->GetIndex(ev), menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendToggleItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendToggleItem(Environment* ev,
- const FW_CString& trueText,
- const FW_CString& falseText,
- ODCommandID commandID,
- FW_MenuKey menuKey)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = new FW_CToggleItem(ev, this, index, trueText, falseText, commandID, menuKey);
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendToggleItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendToggleItem(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long trueId,
- unsigned long falseId,
- ODCommandID commandID,
- FW_MenuKey menuKey)
- {
- FW_CString255 trueString;
- FW_CString255 falseString;
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, trueId, trueString);
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, falseId, falseString);
- this->AppendToggleItem(ev, trueString, falseString, commandID, menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertToggleItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertToggleItem(Environment* ev,
- const FW_CString& trueText,
- const FW_CString& falseText,
- ODCommandID commandID,
- short afterItem,
- FW_MenuKey menuKey)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = new FW_CToggleItem(ev, this, index, trueText, falseText, commandID, menuKey);
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertToggleItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertToggleItem(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long trueId,
- unsigned long falseId,
- ODCommandID commandID,
- short afterItem,
- FW_MenuKey menuKey)
- {
- FW_CString255 trueString;
- FW_CString255 falseString;
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, trueId, trueString);
- ::FW_LoadStringByID(resFile, resourceId, MULTISTRINGRES, falseId, falseString);
- this->InsertToggleItem(ev, trueString, falseString, commandID, afterItem, menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertToggleItemAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertToggleItemAfterCommand(Environment* ev,
- const FW_CString& trueText,
- const FW_CString& falseText,
- ODCommandID commandID,
- ODCommandID afterCommand,
- FW_MenuKey menuKey)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertToggleItem(ev, trueText, falseText, commandID, item->GetIndex(ev), menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertToggleItemAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertToggleItemAfterCommand(Environment* ev,
- FW_CResourceFile &resFile,
- FW_ResourceId resourceId,
- unsigned long trueId,
- unsigned long falseId,
- ODCommandID commandID,
- ODCommandID afterCommand,
- FW_MenuKey menuKey)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertToggleItem(ev, resFile, resourceId, trueId, falseId, commandID, item->GetIndex(ev), menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendSubMenu
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendSubMenu(Environment* ev,
- FW_CPullDownMenu* adoptSubMenu)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = new FW_CSubMenuItem(ev, this, index, adoptSubMenu);
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSubMenu
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSubMenu(Environment* ev,
- FW_CPullDownMenu* adoptSubMenu,
- short afterItem)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = new FW_CSubMenuItem(ev, this, index, adoptSubMenu);
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSubMenuAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSubMenuAfterCommand(Environment* ev,
- FW_CPullDownMenu* adoptSubMenu,
- ODCommandID afterCommand)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertSubMenu(ev, adoptSubMenu, item->GetIndex(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendSeparator
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendSeparator(Environment* ev)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = new FW_CSeparatorItem(ev, this, index);
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSeparator
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSeparator(Environment* ev,
- short afterItem)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = new FW_CSeparatorItem(ev, this, index);
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSeparatorAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSeparatorAfterCommand(Environment* ev,
- ODCommandID afterCommand)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertSeparator(ev, item->GetIndex(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::RemoveItem
- //
- // If an index greater than the number of items in the menu is specified,
- // the last item is deleted.
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::RemoveItem(Environment* ev, short position)
- {
- FW_ASSERT(position > 0);
-
- if (position > CountItems(ev))
- position = CountItems(ev);
-
- FW_COrderedCollectionIterator ite(fItems);
- FW_CMenuItem* itemToRemove = NULL;
-
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- short index = item->GetIndex(ev);
-
- if (index == position)
- itemToRemove = item;
- else if (index > position)
- // if the current item is beneath the new item in the menu...
- {
- item->PrivSetIndex(ev, index - 1);
-
- #ifdef FW_BUILD_MAC
- if (fMenuBar != NULL) // need to unregister and re-register the item
- {
- fMenuBar->PrivMacUnregisterCommand(ev, item->GetCommandID(ev));
- fMenuBar->PrivMacRegisterCommand(ev, item->GetCommandID(ev), fMenuID, index - 1);
- }
- #endif
- }
- }
-
- FW_ASSERT(itemToRemove);
- fItems->Remove(itemToRemove);
-
- if (fMenuBar != NULL)
- itemToRemove->PrivDetach(ev, fMenuBar);
-
- // now, actually delete the item
-
- #ifdef FW_BUILD_MAC
- DeleteMenuItem(fPlatformMenu, position);
- #endif
-
- #ifdef FW_BUILD_WIN
- DeleteMenu(fPlatformMenu.menu, position - 1, MF_BYPOSITION);
- #endif
-
- delete itemToRemove;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AdoptMenuItemLast
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AdoptMenuItemLast(Environment* ev, FW_CMenuItem* menuItem)
- {
- fItems->AddLast(menuItem);
-
- if (fMenuBar != NULL)
- menuItem->PrivAttach(ev, fMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AdoptMenuItemAfter
- //----------------------------------------------------------------------------------------
- // If afterItem is greater than the number of items in the menu, the item is added to
- // then bottom of the menu; if it's zero, the item is added to the top.
-
- void FW_CPullDownMenu::AdoptMenuItemAfter(Environment* ev, FW_CMenuItem* menuItem, short afterItem)
- {
- FW_ASSERT(afterItem >= 0 && afterItem <= CountItems(ev));
-
- FW_COrderedCollectionIterator ite(fItems);
- FW_CMenuItem* prevItem = NULL;
-
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- short index = item->GetIndex(ev);
-
- if (index == afterItem)
- prevItem = item;
- else if (index > afterItem)
- // if the current item is beneath the new item in the menu...
- {
- item->PrivSetIndex(ev, index + 1); // adjust item numbers
-
- #ifdef FW_BUILD_MAC
- if (fMenuBar != NULL) // need to unregister and re-register the item
- {
- fMenuBar->PrivMacUnregisterCommand(ev, item->GetCommandID(ev));
- fMenuBar->PrivMacRegisterCommand(ev, item->GetCommandID(ev), fMenuID, index + 1);
- }
- #endif
- }
- }
-
- if (afterItem == 0) // add the item to the menu
- fItems->AddFirst(menuItem);
- else
- {
- FW_ASSERT(prevItem);
- fItems->AddAfter(prevItem, menuItem);
- }
-
- if (fMenuBar != NULL)
- menuItem->PrivAttach(ev, fMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::GetCommandID
- //----------------------------------------------------------------------------------------
- // returns FW_kNoCommand if not found or submenu, FW_kSeparatorCommand if separator
-
- ODCommandID FW_CPullDownMenu::GetCommandID(Environment* ev, short position) const
- {
- #ifdef FW_BUILD_MAC
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- if (item->GetIndex(ev) == position)
- return item->GetCommandID(ev);
- }
-
- return FW_kNoCommand;
- #endif
-
- #ifdef FW_BUILD_WIN
- return ::GetMenuItemID(fPlatformMenu.menu, position-1); // zero-based on windows
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivGetMenuItem
- //----------------------------------------------------------------------------------------
-
- FW_CMenuItem* FW_CPullDownMenu::PrivGetMenuItem(Environment* ev, ODCommandID commandID) const
- {
- FW_ASSERT(commandID != FW_kNoCommand);
- FW_ASSERT(commandID != FW_kSeparatorCommand);
-
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- if (item->GetCommandID(ev) == commandID)
- return item;
- else
- {
- FW_CMenuItem* subItem = item->PrivGetMenuItem(ev, commandID);
- if (subItem != NULL)
- return subItem;
- }
-
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivFindMenuWithID
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu* FW_CPullDownMenu::PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const
- {
- FW_ASSERT(IsAttachedToMenuBar(ev)); // Otherwise it doesn't make sense because menuID
- // are only assigned when the menu is attached
-
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- FW_CPullDownMenu* subMenu = item->PrivFindMenuWithID(ev, menuID);
- if (subMenu != NULL)
- return subMenu;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::DisableAll
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::DisableAll(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- // ----- On the Mac disable all the items at once
- (*fPlatformMenu)->enableFlags &= 0x00000001;
- #endif
-
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- item->PrivDisableAll(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::EnableAll
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::EnableAll(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- // ----- On the Mac enale all the items at once
- (*fPlatformMenu)->enableFlags &= 0xFFFFFFFF;
- #endif
-
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- item->PrivEnableAll(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivAcquireMenuID
- //----------------------------------------------------------------------------------------
-
- short FW_CPullDownMenu::PrivAcquireMenuID(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuID == -1);
- fMenuID = menuBar->PrivGetNewMenuID(ev);
- #ifdef FW_BUILD_MAC
- (*fPlatformMenu)->menuID = fMenuID;
- #endif
- return fMenuID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivRelinquishMenuID
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivRelinquishMenuID(Environment* ev)
- {
- FW_ASSERT(fMenuID != -1);
- fMenuID = -1;
- #ifdef FW_BUILD_MAC
- (*fPlatformMenu)->menuID = -1;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivAttach
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuBar == NULL);
- fMenuBar = menuBar;
-
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- item->PrivAttach(ev, menuBar);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivDetach
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuBar == menuBar);
- fMenuBar = NULL;
-
- FW_COrderedCollectionIterator ite(fItems);
- for (FW_CMenuItem* item = (FW_CMenuItem*)ite.First(); ite.IsNotComplete(); item = (FW_CMenuItem*)ite.Next())
- {
- item->PrivDetach(ev, menuBar);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivAttachedToMenuBar
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivAttachedToMenuBar(Environment* ev, FW_CMenuBar* menuBar, ODMenuID beforeID)
- {
- FW_ASSERT(menuBar != NULL);
- FW_ASSERT(fMenuBar == NULL);
- FW_ASSERT(fMenuID == -1);
-
- PrivAcquireMenuID(ev, menuBar);
-
- FW_CAcquiredODMenuBar aqODMenuBar = menuBar->AcquireODMenuBar(ev);
- ODPart* odPart = menuBar->GetODPart(ev);
-
- if (beforeID == -1)
- {
- #ifdef FW_BUILD_WIN
- // [WIN_PORT]: AddMenuLast takes an ODPlatformMenu* in OD/Win -- different from OD/Mac
- aqODMenuBar->AddMenuLast(ev, fMenuID, &fPlatformMenu, odPart);
- #else
- aqODMenuBar->AddMenuLast(ev, fMenuID, fPlatformMenu, odPart);
- #endif
- }
- else
- {
- #ifdef FW_BUILD_WIN
- // [WIN_PORT]: AddMenuBefore takes an ODPlatformMenu* in OD/Win -- different from OD/Mac
- aqODMenuBar->AddMenuBefore(ev, fMenuID, &fPlatformMenu, odPart, beforeID);
- #else
- aqODMenuBar->AddMenuBefore(ev, fMenuID, fPlatformMenu, odPart, beforeID);
- #endif
- }
-
- PrivAttach(ev, menuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivDetachedFromMenuBar
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivDetachedFromMenuBar(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuBar != NULL);
- FW_ASSERT(fMenuBar == menuBar);
-
- fMenuBar->PrivRemoveMenu(ev, fMenuID);
-
- PrivDetach(ev, fMenuBar);
-
- PrivRelinquishMenuID(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CPullDownMenu::Read(FW_CReadableStream& archive)
- {
- return new FW_CPullDownMenu(somGetGlobalEnvironment(), archive);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::Write(FW_CWritableStream& archive, const void* thePullDownMenu)
- {
- ((FW_CPullDownMenu*) thePullDownMenu)->Flatten(somGetGlobalEnvironment(), archive);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::Flatten(Environment* ev, FW_CWritableStream& archive) const
- {
- //----- Save menu data -----
- FW_CString255 menuTitle;
- unsigned long count = fItems->Count();
-
- #ifdef FW_BUILD_MAC
- menuTitle.ReplaceAll((*fPlatformMenu)->menuData);
- FW_ASSERT(count == ::CountMItems(fPlatformMenu));
- #endif
- #ifdef FW_BUILD_WIN
- menuTitle = fPlatformMenu.strMenu;
- FW_ASSERT(count == ::GetMenuItemCount(fPlatformMenu.menu));
- #endif
-
- archive << this->GetMenuID(ev);
- archive << menuTitle;
- archive << count;
-
- //----- Save menu items -----
- FW_COrderedCollectionIterator itemIter(fItems);
- for (FW_CMenuItem* menuItem = (FW_CMenuItem*)itemIter.First(); itemIter.IsNotComplete(); menuItem = (FW_CMenuItem*)itemIter.Next())
- {
- FW_WRITE_DYNAMIC_OBJECT(archive, menuItem, FW_CMenuItem);
- }
- }
-
- //========================================================================================
- // Global operators << and >>
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // operator>>
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CReadableStream& operator>>(FW_CReadableStream& archive, FW_CPullDownMenu*& object)
- {
- void* voidPtr = NULL;
- FW_CDynamicArchiver::InputObject(archive, voidPtr);
- object = (FW_CPullDownMenu*) voidPtr;
-
- return archive;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CWritableStream& operator<<(FW_CWritableStream& archive, const FW_CPullDownMenu* object)
- {
- FW_ASSERT(object != NULL);
- FW_CDynamicArchiver::OutputObject(archive, object, FW_CLASSNAME_FROM_POINTER(object));
- return archive;
- }
-