Engine directory for ticket #1

This commit is contained in:
DavidWyand-GG 2012-09-19 11:15:01 -04:00
parent 352279af7a
commit 7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBClasses</key>
<array>
<dict>
<key>ACTIONS</key>
<dict>
<key>toggleAutomaticLinkDetection</key>
<string>id</string>
<key>toggleAutomaticQuoteSubstitution</key>
<string>id</string>
<key>toggleGrammarChecking</key>
<string>id</string>
<key>toggleSmartInsertDelete</key>
<string>id</string>
</dict>
<key>CLASS</key>
<string>FirstResponder</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
</array>
<key>IBVersion</key>
<string>1</string>
</dict>
</plist>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBFramework Version</key>
<string>629</string>
<key>IBLastKnownRelativeProjectPath</key>
<string>../../../../../GameExamples/T3D/buildFiles/Xcode/T3D.xcodeproj</string>
<key>IBOldestOS</key>
<integer>5</integer>
<key>IBOpenObjects</key>
<array>
<integer>29</integer>
</array>
<key>IBSystem Version</key>
<string>9F33</string>
<key>targetFramework</key>
<string>IBCocoaFramework</string>
</dict>
</plist>

Binary file not shown.

View file

@ -0,0 +1,303 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platformMac/platformMacCarb.h"
#include "platform/menus/menuBar.h"
#include "platform/menus/popupMenu.h"
#include "gui/core/guiCanvas.h"
#include "windowManager/platformWindowMgr.h"
#include "windowManager/platformWindow.h"
class PlatformMenuBarData
{
public:
PlatformMenuBarData() :
mMenuEventHandlerRef(NULL),
mCommandEventHandlerRef(NULL),
mMenuOpenCount( 0 ),
mLastCloseTime( 0 )
{}
EventHandlerRef mMenuEventHandlerRef;
EventHandlerRef mCommandEventHandlerRef;
/// More evil hacking for OSX. There seems to be no way to disable menu shortcuts and
/// they are automatically routed within that Cocoa thing outside of our control. Also,
/// there's no way of telling what triggered a command event and thus no way of knowing
/// whether it was a keyboard shortcut. Sigh.
///
/// So what we do here is monitor the sequence of events leading to a command event. We
/// capture the time the last open menu was closed and then, when we receive a command
/// event (which are dished out after the menus are closed) and keyboard accelerators are
/// disabled, we check whether we are a certain very short time away in the event stream
/// from the menu close event. If so, we figure the event came from clicking in a menu.
///
/// Utterly evil and dirty but seems to do the trick.
U32 mMenuOpenCount;
EventTime mLastCloseTime;
};
//-----------------------------------------------------------------------------
#pragma mark -
#pragma mark ---- menu event handler ----
static OSStatus _OnMenuEvent(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData)
{
PlatformMenuBarData* mbData = ( PlatformMenuBarData* ) userData;
MenuRef menu;
GetEventParameter(theEvent, kEventParamDirectObject, typeMenuRef, NULL, sizeof(MenuRef), NULL, &menu);
// Count open/close for the sake of hotkey disabling.
UInt32 kind = GetEventKind( theEvent );
if( kind == kEventMenuOpening )
mbData->mMenuOpenCount ++;
else
{
AssertWarn( mbData->mMenuOpenCount > 0, "Unbalanced menu open/close events in _OnMenuEvent" );
if( mbData->mMenuOpenCount )
mbData->mMenuOpenCount --;
// Initial menu closed. Capture time.
if( !mbData->mMenuOpenCount )
mbData->mLastCloseTime = GetEventTime( theEvent );
}
OSStatus err = eventNotHandledErr;
PopupMenu *torqueMenu;
if( CountMenuItems( menu ) > 0 )
{
// I don't know of a way to get the Torque PopupMenu object from a Carbon MenuRef
// other than going through its first menu item
err = GetMenuItemProperty(menu, 1, 'GG2d', 'ownr', sizeof(PopupMenu*), NULL, &torqueMenu);
if( err == noErr && torqueMenu != NULL )
{
torqueMenu->onMenuSelect();
}
}
return err;
}
//-----------------------------------------------------------------------------
#pragma mark -
#pragma mark ---- menu command event handler ----
static bool MacCarbHandleMenuCommand( void* hiCommand, PlatformMenuBarData* mbData )
{
HICommand *cmd = (HICommand*)hiCommand;
if(cmd->commandID != kHICommandTorque)
return false;
MenuRef menu = cmd->menu.menuRef;
MenuItemIndex item = cmd->menu.menuItemIndex;
// Run the command handler.
PopupMenu* torqueMenu;
OSStatus err = GetMenuItemProperty(menu, item, 'GG2d', 'ownr', sizeof(PopupMenu*), NULL, &torqueMenu);
AssertFatal(err == noErr, "Could not resolve the PopupMenu stored on a native menu item");
UInt32 command;
err = GetMenuItemRefCon(menu, item, &command);
AssertFatal(err == noErr, "Could not find the tag of a native menu item");
if(!torqueMenu->canHandleID(command))
Con::errorf("menu claims it cannot handle that id. how odd.");
// un-highlight currently selected menu
HiliteMenu( 0 );
return torqueMenu->handleSelect(command,NULL);
}
//-----------------------------------------------------------------------------
#pragma mark -
#pragma mark ---- Command Events ----
static OSStatus _OnCommandEvent(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData)
{
PlatformMenuBarData* mbData = ( PlatformMenuBarData* ) userData;
HICommand commandStruct;
OSStatus result = eventNotHandledErr;
GetEventParameter(theEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &commandStruct);
// pass menu command events to a more specific handler.
if(commandStruct.attributes & kHICommandFromMenu)
{
bool handleEvent = true;
// Do menu-close check hack.
PlatformWindow* window = PlatformWindowManager::get()->getFocusedWindow();
if( !window || !window->getAcceleratorsEnabled() )
{
F32 deltaTime = mFabs( GetEventTime( theEvent ) - mbData->mLastCloseTime );
if( deltaTime > 0.1f )
handleEvent = false;
}
if( handleEvent && MacCarbHandleMenuCommand(&commandStruct, mbData) )
result = noErr;
}
return result;
}
//-----------------------------------------------------------------------------
// MenuBar Methods
//-----------------------------------------------------------------------------
void MenuBar::createPlatformPopupMenuData()
{
mData = new PlatformMenuBarData;
}
void MenuBar::deletePlatformPopupMenuData()
{
SAFE_DELETE(mData);
}
//-----------------------------------------------------------------------------
void MenuBar::attachToCanvas(GuiCanvas *owner, S32 pos)
{
if(owner == NULL || isAttachedToCanvas())
return;
mCanvas = owner;
// Add the items
for(S32 i = 0;i < size();++i)
{
PopupMenu *mnu = dynamic_cast<PopupMenu *>(at(i));
if(mnu == NULL)
{
Con::warnf("MenuBar::attachToMenuBar - Non-PopupMenu object in set");
continue;
}
if(mnu->isAttachedToMenuBar())
mnu->removeFromMenuBar();
mnu->attachToMenuBar(owner, pos + i, mnu->getBarTitle());
}
// register as listener for menu opening events
static EventTypeSpec menuEventTypes[ 2 ];
menuEventTypes[ 0 ].eventClass = kEventClassMenu;
menuEventTypes[ 0 ].eventKind = kEventMenuOpening;
menuEventTypes[ 1 ].eventClass = kEventClassMenu;
menuEventTypes[ 1 ].eventKind = kEventMenuClosed;
EventHandlerUPP menuEventHandlerUPP;
menuEventHandlerUPP = NewEventHandlerUPP(_OnMenuEvent);
InstallEventHandler(GetApplicationEventTarget(), menuEventHandlerUPP, 2, menuEventTypes, mData, &mData->mMenuEventHandlerRef);
// register as listener for process command events
static EventTypeSpec comEventTypes[1];
comEventTypes[0].eventClass = kEventClassCommand;
comEventTypes[0].eventKind = kEventCommandProcess;
EventHandlerUPP commandEventHandlerUPP;
commandEventHandlerUPP = NewEventHandlerUPP(_OnCommandEvent);
InstallEventHandler(GetApplicationEventTarget(), commandEventHandlerUPP, 1, comEventTypes, mData, &mData->mCommandEventHandlerRef);
}
//-----------------------------------------------------------------------------
void MenuBar::removeFromCanvas()
{
if(mCanvas == NULL || ! isAttachedToCanvas())
return;
if(mData->mCommandEventHandlerRef != NULL)
RemoveEventHandler( mData->mCommandEventHandlerRef );
mData->mCommandEventHandlerRef = NULL;
if(mData->mMenuEventHandlerRef != NULL)
RemoveEventHandler( mData->mMenuEventHandlerRef );
mData->mMenuEventHandlerRef = NULL;
// Add the items
for(S32 i = 0;i < size();++i)
{
PopupMenu *mnu = dynamic_cast<PopupMenu *>(at(i));
if(mnu == NULL)
{
Con::warnf("MenuBar::removeFromMenuBar - Non-PopupMenu object in set");
continue;
}
mnu->removeFromMenuBar();
}
mCanvas = NULL;
}
//-----------------------------------------------------------------------------
void MenuBar::updateMenuBar(PopupMenu* menu)
{
if(! isAttachedToCanvas())
return;
menu->removeFromMenuBar();
SimSet::iterator itr = find(begin(), end(), menu);
if(itr == end())
return;
// Get the item currently at the position we want to add to
S32 pos = itr - begin();
S16 posID = 0;
PopupMenu *nextMenu = NULL;
for(S32 i = pos + 1; i < size(); i++)
{
PopupMenu *testMenu = dynamic_cast<PopupMenu *>(at(i));
if (testMenu && testMenu->isAttachedToMenuBar())
{
nextMenu = testMenu;
break;
}
}
if(nextMenu)
posID = GetMenuID(nextMenu->mData->mMenu);
menu->attachToMenuBar(mCanvas, posID, menu->mBarTitle);
}

View file

@ -0,0 +1,439 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platformMac/platformMacCarb.h"
#include "platform/menus/popupmenu.h"
#include "core/util/safeDelete.h"
#include "gui/core/guiCanvas.h"
void PopupMenu::createPlatformPopupMenuData()
{
mData = new PlatformPopupMenuData;
}
void PopupMenu::deletePlatformPopupMenuData()
{
SAFE_DELETE(mData);
}
void PopupMenu::createPlatformMenu()
{
OSStatus err = CreateNewMenu( mData->tag, kMenuAttrAutoDisable,&(mData->mMenu));
CFRetain(mData->mMenu);
AssertFatal(err == noErr, "Could not create Carbon MenuRef");
}
static int _getModifierMask(const char* accel)
{
int ret = 0;
if(dStrstr(accel, "ctrl"))
ret |= kMenuControlModifier;
if(dStrstr(accel, "shift"))
ret |= kMenuShiftModifier;
if(dStrstr(accel, "alt"))
ret |= kMenuOptionModifier;
if(!(dStrstr(accel, "cmd") || dStrstr(accel, "command")))
ret |= kMenuNoCommandModifier;
return ret;
}
static void _assignCommandKeys(const char* accel, MenuRef menu, MenuItemIndex item)
{
if(!(accel && *accel))
return;
// get the modifier keys
String _accel = String::ToLower( accel );
int mods = _getModifierMask(_accel);
// accel is space or dash delimted.
// the modifier key is either the last token in accel, or the first char in accel.
const char* key = dStrrchr(_accel, ' ');
if(!key)
key = dStrrchr(_accel, '-');
if(!key)
key = _accel;
else
key++;
if(dStrlen(key) <= 1)
{
char k = dToupper( key[0] );
SetMenuItemCommandKey( menu, item, false, k );
}
else
{
SInt16 glyph = kMenuNullGlyph;
//*** A lot of these mappings came from a listing at http://developer.apple.com/releasenotes/Carbon/HIToolboxOlderNotes.html
if(!dStricmp(key, "DELETE"))
glyph = kMenuDeleteRightGlyph;
else if(!dStricmp(key, "HOME"))
glyph = kMenuNorthwestArrowGlyph;
else if(!dStricmp(key, "END"))
glyph = kMenuSoutheastArrowGlyph;
else if(!dStricmp(key, "BACKSPACE"))
glyph = kMenuDeleteLeftGlyph;
else if(!dStricmp(key, "TAB"))
glyph = kMenuTabRightGlyph;
else if(!dStricmp(key, "RETURN"))
glyph = kMenuReturnGlyph;
else if(!dStricmp(key, "ENTER"))
glyph = kMenuEnterGlyph;
else if(!dStricmp(key, "PG UP"))
glyph = kMenuPageUpGlyph;
else if(!dStricmp(key, "PG DOWN"))
glyph = kMenuPageDownGlyph;
else if(!dStricmp(key, "ESC"))
glyph = kMenuEscapeGlyph;
else if(!dStricmp(key, "LEFT"))
glyph = kMenuLeftArrowGlyph;
else if(!dStricmp(key, "RIGHT"))
glyph = kMenuRightArrowGlyph;
else if(!dStricmp(key, "UP"))
glyph = kMenuUpArrowGlyph;
else if(!dStricmp(key, "DOWN"))
glyph = kMenuDownArrowGlyph;
else if(!dStricmp(key, "SPACE"))
glyph = kMenuSpaceGlyph;
else if(!dStricmp(key, "F1"))
glyph = kMenuF1Glyph;
else if(!dStricmp(key, "F2"))
glyph = kMenuF2Glyph;
else if(!dStricmp(key, "F3"))
glyph = kMenuF3Glyph;
else if(!dStricmp(key, "F4"))
glyph = kMenuF4Glyph;
else if(!dStricmp(key, "F5"))
glyph = kMenuF5Glyph;
else if(!dStricmp(key, "F6"))
glyph = kMenuF6Glyph;
else if(!dStricmp(key, "F7"))
glyph = kMenuF7Glyph;
else if(!dStricmp(key, "F8"))
glyph = kMenuF8Glyph;
else if(!dStricmp(key, "F9"))
glyph = kMenuF9Glyph;
else if(!dStricmp(key, "F10"))
glyph = kMenuF10Glyph;
else if(!dStricmp(key, "F11"))
glyph = kMenuF11Glyph;
else if(!dStricmp(key, "F12"))
glyph = kMenuF12Glyph;
else if(!dStricmp(key, "F13"))
glyph = kMenuF13Glyph;
else if(!dStricmp(key, "F14"))
glyph = kMenuF14Glyph;
else if(!dStricmp(key, "F15"))
glyph = kMenuF15Glyph;
SetMenuItemKeyGlyph(menu, item, glyph);
}
SetMenuItemModifiers(menu, item, mods);
}
S32 PopupMenu::insertItem(S32 pos, const char *title, const char* accel)
{
MenuItemIndex item;
CFStringRef cftitle;
MenuItemAttributes attr = 0;
bool needRelease = false;
if(title && *title)
{
cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8);
needRelease = true;
}
else
{
cftitle = CFSTR("-");
attr = kMenuItemAttrSeparator;
}
InsertMenuItemTextWithCFString(mData->mMenu, cftitle, pos, attr, kHICommandTorque + 1);
if( needRelease )
CFRelease( cftitle );
// ensure that we have the correct index for the new menu item
MenuRef outref;
GetIndMenuItemWithCommandID(mData->mMenu, kHICommandTorque+1, 1, &outref, &item);
SetMenuItemCommandID(mData->mMenu, item, kHICommandTorque);
// save a ref to the PopupMenu that owns this item.
PopupMenu* thisMenu = this;
SetMenuItemProperty(mData->mMenu, item, 'GG2d', 'ownr', sizeof(PopupMenu*), &thisMenu);
// construct the accelerator keys
_assignCommandKeys(accel, mData->mMenu, item);
S32 tag = PlatformPopupMenuData::getTag();
SetMenuItemRefCon(mData->mMenu, item, tag);
return tag;
}
S32 PopupMenu::insertSubMenu(S32 pos, const char *title, PopupMenu *submenu)
{
for(S32 i = 0;i < mSubmenus->size();i++)
{
if(submenu == (*mSubmenus)[i])
{
Con::errorf("PopupMenu::insertSubMenu - Attempting to add submenu twice");
return -1;
}
}
CFStringRef cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8);
InsertMenuItemTextWithCFString(mData->mMenu, cftitle, pos, 0, kHICommandTorque + 1);
CFRelease( cftitle );
// ensure that we have the correct index for the new menu item
MenuRef outref;
MenuItemIndex item;
GetIndMenuItemWithCommandID(mData->mMenu, kHICommandTorque+1, 1, &outref, &item);
SetMenuItemCommandID(mData->mMenu, item, 0);
S32 tag = PlatformPopupMenuData::getTag();
SetMenuItemRefCon( mData->mMenu, item, tag);
// store a pointer to the PopupMenu this item represents. See PopupMenu::removeItem()
SetMenuItemProperty(mData->mMenu, item, 'GG2d', 'subm', sizeof(PopupMenu*), submenu);
SetMenuItemHierarchicalMenu( mData->mMenu, item, submenu->mData->mMenu);
mSubmenus->addObject(submenu);
return tag;
}
void PopupMenu::removeItem(S32 itemPos)
{
PopupMenu* submenu;
itemPos++; // adjust torque -> mac menu index
OSStatus err = GetMenuItemProperty(mData->mMenu, itemPos, 'GG2d', 'subm', sizeof(PopupMenu*),NULL,&submenu);
if(err == noErr)
mSubmenus->removeObject(submenu);
// deleting the item decrements the ref count on the mac submenu.
DeleteMenuItem(mData->mMenu, itemPos);
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::enableItem(S32 pos, bool enable)
{
pos++; // adjust torque -> mac menu index.
if(enable)
EnableMenuItem(mData->mMenu, pos);
else
DisableMenuItem(mData->mMenu, pos);
}
void PopupMenu::checkItem(S32 pos, bool checked)
{
pos++;
CheckMenuItem(mData->mMenu, pos, checked);
}
void PopupMenu::checkRadioItem(S32 firstPos, S32 lastPos, S32 checkPos)
{
// uncheck items
for(int i = firstPos; i <= lastPos; i++)
checkItem( i, false);
// check the selected item
checkItem( checkPos, true);
}
bool PopupMenu::isItemChecked(S32 pos)
{
CharParameter mark;
GetItemMark(mData->mMenu, pos, &mark);
return (mark == checkMark);
}
//////////////////////////////////////////////////////////////////////////
// this method really isn't necessary for the mac implementation
bool PopupMenu::canHandleID(U32 iD)
{
for(S32 i = 0;i < mSubmenus->size();i++)
{
PopupMenu *subM = dynamic_cast<PopupMenu *>((*mSubmenus)[i]);
if(subM == NULL)
continue;
if(subM->canHandleID(iD))
return true;
}
UInt32 refcon;
U32 nItems = CountMenuItems(mData->mMenu);
for(int i = 1; i <= nItems; i++)
{
GetMenuItemRefCon(mData->mMenu, i, &refcon);
if(refcon == iD)
return true;
}
return false;
}
bool PopupMenu::handleSelect(U32 command, const char *text /* = NULL */)
{
// [tom, 8/20/2006] Pass off to a sub menu if it's for them
for(S32 i = 0;i < mSubmenus->size();i++)
{
PopupMenu *subM = dynamic_cast<PopupMenu *>((*mSubmenus)[i]);
if(subM == NULL)
continue;
if(subM->canHandleID(command))
{
return subM->handleSelect(command, text);
}
}
// ensure that this menu actually has an item with the specificed command / refcon.
// this is not strictly necessary, we're just doing it here to keep the behavior
// in line with the windows implementation.
UInt32 refcon;
U32 nItems = CountMenuItems(mData->mMenu);
S32 pos = -1;
for(int i = 1; i <= nItems; i++)
{
GetMenuItemRefCon(mData->mMenu, i, &refcon);
if(refcon == command)
pos = i;
}
if(pos == -1)
{
Con::errorf("PopupMenu::handleSelect - Could not find menu item position for ID %d ... this shouldn't happen!", command);
return false;
}
char textbuf[1024];
if(!text)
{
CFStringRef cfstr;
CopyMenuItemTextAsCFString(mData->mMenu, pos, &cfstr);
CFStringGetCString(cfstr,textbuf,sizeof(textbuf) - 1,kCFStringEncodingUTF8);
CFRelease( cfstr );
text = textbuf;
}
// [tom, 8/20/2006] Wasn't handled by a submenu, pass off to script
return dAtob(Con::executef(this, "onSelectItem", Con::getIntArg(pos - 1), text ? text : ""));
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::showPopup(GuiCanvas* canvas, S32 x /* = -1 */, S32 y /* = -1 */)
{
if(x < 0 || y < 0)
{
Point2I p = canvas->getCursorPos();
x = p.x;
y = p.y;
}
PopUpMenuSelect(mData->mMenu, y, x, 0);
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::attachToMenuBar(GuiCanvas* canvas, S32 pos, const char *title)
{
CFStringRef cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8);
SetMenuTitleWithCFString(mData->mMenu, cftitle);
CFRelease( cftitle );
InsertMenu(mData->mMenu, pos);
onAttachToMenuBar(canvas, pos, title);
}
void PopupMenu::removeFromMenuBar()
{
DeleteMenu(mData->tag);
onRemoveFromMenuBar(mCanvas);
}
U32 PopupMenu::getItemCount()
{
return CountMenuItems( mData->mMenu );
}
bool PopupMenu::setItem(S32 pos, const char *title, const char *accelerator)
{
//TODO: update accelerator?
pos += 1; // Torque to mac index
CFStringRef cftitle = CFStringCreateWithCString( NULL, title, kCFStringEncodingUTF8 );
SetMenuItemTextWithCFString( mData->mMenu, pos, cftitle );
CFRelease( cftitle );
return true;
}
S32 PopupMenu::getPosOnMenuBar()
{
return -1;
}
void PopupMenu::attachToMenuBar(GuiCanvas *owner, S32 pos)
{
}