|
@@ -215,8 +215,8 @@ DefineEngineMethod(GuiMenuBar, addMenu, void, (const char* menuText, S32 menuId)
|
|
|
object->addMenu(menuText, menuId);
|
|
|
}
|
|
|
|
|
|
-DefineEngineMethod(GuiMenuBar, addMenuItem, void, (const char* targetMenu, const char* menuItemText, S32 menuItemId, const char* accelerator, int checkGroup),
|
|
|
- ("","",0,"",-1),
|
|
|
+DefineEngineMethod(GuiMenuBar, addMenuItem, void, (const char* targetMenu, const char* menuItemText, S32 menuItemId, const char* accelerator, int checkGroup, const char *cmd),
|
|
|
+ ("","",0,NULL,-1,""),
|
|
|
"@brief Adds a menu item to the specified menu. The menu argument can be either the text of a menu or its id.\n\n"
|
|
|
"@param menu Menu name or menu Id to add the new item to.\n"
|
|
|
"@param menuItemText Text for the new menu item.\n"
|
|
@@ -250,7 +250,7 @@ DefineEngineMethod(GuiMenuBar, addMenuItem, void, (const char* targetMenu, const
|
|
|
Con::errorf("Cannot find menu %s for addMenuItem.", targetMenu);
|
|
|
return;
|
|
|
}
|
|
|
- object->addMenuItem(menu, menuItemText, menuItemId, accelerator != NULL ? accelerator : "", checkGroup == -1 ? -1 : checkGroup);
|
|
|
+ object->addMenuItem(menu, menuItemText, menuItemId, accelerator != NULL ? accelerator : "", checkGroup == -1 ? -1 : checkGroup, cmd);
|
|
|
}
|
|
|
|
|
|
DefineEngineMethod(GuiMenuBar, setMenuItemEnable, void, (const char* menuTarget, const char* menuItemTarget, bool enabled),,
|
|
@@ -767,7 +767,7 @@ DefineEngineMethod(GuiMenuBar, setSubmenuItemChecked, void, (const char* menuTar
|
|
|
if(checked && submenuItem->checkGroup != -1)
|
|
|
{
|
|
|
// first, uncheck everything in the group:
|
|
|
- for(GuiMenuBar::MenuItem *itemWalk = menuItem->firstSubmenuItem; itemWalk; itemWalk = itemWalk->nextMenuItem)
|
|
|
+ for(GuiMenuBar::MenuItem *itemWalk = menuItem->submenu->firstMenuItem; itemWalk; itemWalk = itemWalk->nextMenuItem)
|
|
|
if(itemWalk->checkGroup == submenuItem->checkGroup && itemWalk->bitmapIndex == object->mCheckmarkBitmapIndex)
|
|
|
itemWalk->bitmapIndex = -1;
|
|
|
}
|
|
@@ -777,8 +777,7 @@ DefineEngineMethod(GuiMenuBar, setSubmenuItemChecked, void, (const char* menuTar
|
|
|
//------------------------------------------------------------------------------
|
|
|
// menu management methods
|
|
|
//------------------------------------------------------------------------------
|
|
|
-
|
|
|
-void GuiMenuBar::addMenu(const char *menuText, U32 menuId)
|
|
|
+GuiMenuBar::Menu* GuiMenuBar::sCreateMenu(const char *menuText, U32 menuId)
|
|
|
{
|
|
|
// allocate the menu
|
|
|
Menu *newMenu = new Menu;
|
|
@@ -792,7 +791,12 @@ void GuiMenuBar::addMenu(const char *menuText, U32 menuId)
|
|
|
newMenu->bitmapIndex = -1;
|
|
|
newMenu->drawBitmapOnly = false;
|
|
|
newMenu->drawBorder = true;
|
|
|
-
|
|
|
+
|
|
|
+ return newMenu;
|
|
|
+}
|
|
|
+
|
|
|
+void GuiMenuBar::addMenu(GuiMenuBar::Menu *newMenu)
|
|
|
+{
|
|
|
// add it to the menu list
|
|
|
menuBarDirty = true;
|
|
|
Menu **walk;
|
|
@@ -801,6 +805,13 @@ void GuiMenuBar::addMenu(const char *menuText, U32 menuId)
|
|
|
*walk = newMenu;
|
|
|
}
|
|
|
|
|
|
+void GuiMenuBar::addMenu(const char *menuText, U32 menuId)
|
|
|
+{
|
|
|
+ Menu *newMenu = sCreateMenu(menuText, menuId);
|
|
|
+
|
|
|
+ addMenu(newMenu);
|
|
|
+}
|
|
|
+
|
|
|
GuiMenuBar::Menu *GuiMenuBar::findMenu(const char *menu)
|
|
|
{
|
|
|
if(dIsdigit(menu[0]))
|
|
@@ -877,7 +888,7 @@ void GuiMenuBar::removeMenuItem(Menu *menu, MenuItem *menuItem)
|
|
|
delete menuItem;
|
|
|
}
|
|
|
|
|
|
-void GuiMenuBar::addMenuItem(Menu *menu, const char *text, U32 id, const char *accelerator, S32 checkGroup)
|
|
|
+GuiMenuBar::MenuItem* GuiMenuBar::addMenuItem(Menu *menu, const char *text, U32 id, const char *accelerator, S32 checkGroup, const char *cmd )
|
|
|
{
|
|
|
// allocate the new menu item
|
|
|
MenuItem *newMenuItem = new MenuItem;
|
|
@@ -886,6 +897,7 @@ void GuiMenuBar::addMenuItem(Menu *menu, const char *text, U32 id, const char *a
|
|
|
newMenuItem->accelerator = dStrdup(accelerator);
|
|
|
else
|
|
|
newMenuItem->accelerator = NULL;
|
|
|
+ newMenuItem->cmd = cmd;
|
|
|
newMenuItem->id = id;
|
|
|
newMenuItem->checkGroup = checkGroup;
|
|
|
newMenuItem->nextMenuItem = NULL;
|
|
@@ -896,15 +908,33 @@ void GuiMenuBar::addMenuItem(Menu *menu, const char *text, U32 id, const char *a
|
|
|
|
|
|
// Default to not having a submenu
|
|
|
newMenuItem->isSubmenu = false;
|
|
|
- newMenuItem->firstSubmenuItem = NULL;
|
|
|
+ newMenuItem->submenu = NULL;
|
|
|
newMenuItem->submenuParentMenu = NULL;
|
|
|
|
|
|
// link it into the menu's menu item list
|
|
|
- MenuItem **walk = &menu->firstMenuItem;
|
|
|
- while(*walk)
|
|
|
- walk = &(*walk)->nextMenuItem;
|
|
|
- *walk = newMenuItem;
|
|
|
+ if(menu)
|
|
|
+ {
|
|
|
+ MenuItem **walk = &menu->firstMenuItem;
|
|
|
+ while(*walk)
|
|
|
+ walk = &(*walk)->nextMenuItem;
|
|
|
+ *walk = newMenuItem;
|
|
|
+ }
|
|
|
|
|
|
+ return newMenuItem;
|
|
|
+}
|
|
|
+
|
|
|
+GuiMenuBar::MenuItem* GuiMenuBar::addMenuItem(Menu *menu, MenuItem* newMenuItem)
|
|
|
+{
|
|
|
+ // link it into the menu's menu item list
|
|
|
+ if(menu)
|
|
|
+ {
|
|
|
+ MenuItem **walk = &menu->firstMenuItem;
|
|
|
+ while(*walk)
|
|
|
+ walk = &(*walk)->nextMenuItem;
|
|
|
+ *walk = newMenuItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ return newMenuItem;
|
|
|
}
|
|
|
|
|
|
void GuiMenuBar::clearMenuItems(Menu *menu)
|
|
@@ -935,16 +965,9 @@ GuiMenuBar::MenuItem *GuiMenuBar::findSubmenuItem(Menu *menu, const char *menuIt
|
|
|
for(MenuItem *walk = menu->firstMenuItem; walk; walk = walk->nextMenuItem)
|
|
|
if(id == walk->id)
|
|
|
{
|
|
|
- if(walk->isSubmenu)
|
|
|
+ if(walk->isSubmenu && walk->submenu)
|
|
|
{
|
|
|
- U32 subid = dAtoi(submenuItem);
|
|
|
- for(MenuItem *subwalk = walk->firstSubmenuItem; subwalk; subwalk = subwalk->nextMenuItem)
|
|
|
- {
|
|
|
- if(subid == walk->id)
|
|
|
- {
|
|
|
- return subwalk;
|
|
|
- }
|
|
|
- }
|
|
|
+ return GuiMenuBar::findMenuItem(walk->submenu, submenuItem);
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
@@ -956,13 +979,9 @@ GuiMenuBar::MenuItem *GuiMenuBar::findSubmenuItem(Menu *menu, const char *menuIt
|
|
|
for(MenuItem *walk = menu->firstMenuItem; walk; walk = walk->nextMenuItem)
|
|
|
if(!dStricmp(menuItem, walk->text))
|
|
|
{
|
|
|
- if(walk->isSubmenu)
|
|
|
+ if(walk->isSubmenu && walk->submenu)
|
|
|
{
|
|
|
- for(MenuItem *subwalk = walk->firstSubmenuItem; subwalk; subwalk = subwalk->nextMenuItem)
|
|
|
- {
|
|
|
- if(!dStricmp(submenuItem, subwalk->text))
|
|
|
- return subwalk;
|
|
|
- }
|
|
|
+ return GuiMenuBar::findMenuItem(walk->submenu, submenuItem);
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
@@ -970,6 +989,14 @@ GuiMenuBar::MenuItem *GuiMenuBar::findSubmenuItem(Menu *menu, const char *menuIt
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+GuiMenuBar::MenuItem* GuiMenuBar::findSubmenuItem(MenuItem *menuItem, const char *submenuItem)
|
|
|
+{
|
|
|
+ if( !menuItem->isSubmenu )
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ return GuiMenuBar::findMenuItem( menuItem->submenu, submenuItem );
|
|
|
+}
|
|
|
+
|
|
|
// Add a menuitem to the given submenu
|
|
|
void GuiMenuBar::addSubmenuItem(Menu *menu, MenuItem *submenu, const char *text, U32 id, const char *accelerator, S32 checkGroup)
|
|
|
{
|
|
@@ -997,17 +1024,30 @@ void GuiMenuBar::addSubmenuItem(Menu *menu, MenuItem *submenu, const char *text,
|
|
|
|
|
|
// Default to not having a submenu
|
|
|
newMenuItem->isSubmenu = false;
|
|
|
- newMenuItem->firstSubmenuItem = NULL;
|
|
|
+ newMenuItem->submenu = NULL;
|
|
|
|
|
|
// Point back to the submenu's menu
|
|
|
newMenuItem->submenuParentMenu = menu;
|
|
|
|
|
|
// link it into the menu's menu item list
|
|
|
- MenuItem **walk = &submenu->firstSubmenuItem;
|
|
|
+ MenuItem **walk = &submenu->submenu->firstMenuItem;
|
|
|
while(*walk)
|
|
|
walk = &(*walk)->nextMenuItem;
|
|
|
*walk = newMenuItem;
|
|
|
+}
|
|
|
+
|
|
|
+void GuiMenuBar::addSubmenuItem(Menu *menu, MenuItem *submenu, MenuItem *newMenuItem )
|
|
|
+{
|
|
|
+ AssertFatal( submenu && newMenuItem, "");
|
|
|
+
|
|
|
+ // Point back to the submenu's menu
|
|
|
+ newMenuItem->submenuParentMenu = menu;
|
|
|
|
|
|
+ // link it into the menu's menu item list
|
|
|
+ MenuItem **walk = &submenu->submenu->firstMenuItem;
|
|
|
+ while(*walk)
|
|
|
+ walk = &(*walk)->nextMenuItem;
|
|
|
+ *walk = newMenuItem;
|
|
|
}
|
|
|
|
|
|
// Remove a submenu item
|
|
@@ -1020,17 +1060,7 @@ void GuiMenuBar::removeSubmenuItem(MenuItem *menuItem, MenuItem *submenuItem)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- for(MenuItem **subwalk = &menuItem->firstSubmenuItem; *subwalk; subwalk = &(*subwalk)->nextMenuItem)
|
|
|
- {
|
|
|
- if(*subwalk == submenuItem)
|
|
|
- {
|
|
|
- *subwalk = submenuItem->nextMenuItem;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- dFree(submenuItem->text);
|
|
|
- dFree(submenuItem->accelerator);
|
|
|
- delete submenuItem;
|
|
|
+ GuiMenuBar::removeMenuItem(menuItem->submenu, submenuItem);
|
|
|
}
|
|
|
|
|
|
// Clear all menuitems from a submenu
|
|
@@ -1043,8 +1073,8 @@ void GuiMenuBar::clearSubmenuItems(MenuItem *menuitem)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- while(menuitem->firstSubmenuItem)
|
|
|
- removeSubmenuItem(menuitem, menuitem->firstSubmenuItem);
|
|
|
+ while(menuitem->submenu->firstMenuItem)
|
|
|
+ removeSubmenuItem(menuitem, menuitem->submenu->firstMenuItem);
|
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
@@ -1317,9 +1347,8 @@ void GuiMenuBar::onRender(Point2I offset, const RectI &updateRect)
|
|
|
renderChildControls( offset, updateRect );
|
|
|
}
|
|
|
|
|
|
-void GuiMenuBar::buildAcceleratorMap()
|
|
|
+void GuiMenuBar::buildWindowAcceleratorMap( WindowInputGenerator &inputGenerator )
|
|
|
{
|
|
|
- Parent::buildAcceleratorMap();
|
|
|
// ok, accelerator map is cleared...
|
|
|
// add all our keys:
|
|
|
mCurAcceleratorIndex = 1;
|
|
@@ -1334,18 +1363,22 @@ void GuiMenuBar::buildAcceleratorMap()
|
|
|
continue;
|
|
|
}
|
|
|
EventDescriptor accelEvent;
|
|
|
- ActionMap::createEventDescriptor(item->accelerator, &accelEvent);
|
|
|
+ ActionMap::createEventDescriptor(item->accelerator, &accelEvent);
|
|
|
|
|
|
//now we have a modifier, and a key, add them to the canvas
|
|
|
- GuiCanvas *root = getRoot();
|
|
|
- if (root)
|
|
|
- root->addAcceleratorKey(this, mCurAcceleratorIndex, accelEvent.eventCode, accelEvent.flags);
|
|
|
+ inputGenerator.addAcceleratorKey( this, item->cmd, accelEvent.eventCode, accelEvent.flags);
|
|
|
+
|
|
|
item->acceleratorIndex = mCurAcceleratorIndex;
|
|
|
mCurAcceleratorIndex++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void GuiMenuBar::removeWindowAcceleratorMap( WindowInputGenerator &inputGenerator )
|
|
|
+{
|
|
|
+ inputGenerator.removeAcceleratorKeys( this );
|
|
|
+}
|
|
|
+
|
|
|
void GuiMenuBar::acceleratorKeyPress(U32 index)
|
|
|
{
|
|
|
// loop through all the menus
|
|
@@ -1617,7 +1650,7 @@ void GuiMenuBar::highlightedMenuItem(S32 selectionIndex, RectI bounds, Point2I c
|
|
|
if(list->isSubmenu)
|
|
|
{
|
|
|
// If there are submenu items, then open the submenu
|
|
|
- if(list->firstSubmenuItem)
|
|
|
+ if(list->submenu->firstMenuItem)
|
|
|
{
|
|
|
mouseOverSubmenu = list;
|
|
|
onSubmenuAction(selstore, bounds, cellSize);
|
|
@@ -1752,7 +1785,7 @@ void GuiMenuBar::onSubmenuAction(S32 selectionIndex, RectI bounds, Point2I cellS
|
|
|
// first, call the script callback for menu selection:
|
|
|
onSubmenuSelect_callback(Con::getIntArg(mouseOverSubmenu->id), mouseOverSubmenu->text);
|
|
|
|
|
|
- MenuItem *visWalk = mouseOverSubmenu->firstSubmenuItem;
|
|
|
+ MenuItem *visWalk = mouseOverSubmenu->submenu->firstMenuItem;
|
|
|
while(visWalk)
|
|
|
{
|
|
|
if(visWalk->visible)
|
|
@@ -1780,7 +1813,7 @@ void GuiMenuBar::onSubmenuAction(S32 selectionIndex, RectI bounds, Point2I cellS
|
|
|
|
|
|
GFont *font = mProfile->mFont;
|
|
|
|
|
|
- for(MenuItem *walk = mouseOverSubmenu->firstSubmenuItem; walk; walk = walk->nextMenuItem)
|
|
|
+ for(MenuItem *walk = mouseOverSubmenu->submenu->firstMenuItem; walk; walk = walk->nextMenuItem)
|
|
|
{
|
|
|
if(!walk->visible)
|
|
|
continue;
|
|
@@ -1803,7 +1836,7 @@ void GuiMenuBar::onSubmenuAction(S32 selectionIndex, RectI bounds, Point2I cellS
|
|
|
|
|
|
U32 entryCount = 0;
|
|
|
|
|
|
- for(MenuItem *walk = mouseOverSubmenu->firstSubmenuItem; walk; walk = walk->nextMenuItem)
|
|
|
+ for(MenuItem *walk = mouseOverSubmenu->submenu->firstMenuItem; walk; walk = walk->nextMenuItem)
|
|
|
{
|
|
|
if(!walk->visible)
|
|
|
continue;
|
|
@@ -1885,7 +1918,7 @@ void GuiMenuBar::closeSubmenu()
|
|
|
MenuItem *list = NULL;
|
|
|
if(mouseOverSubmenu)
|
|
|
{
|
|
|
- list = mouseOverSubmenu->firstSubmenuItem;
|
|
|
+ list = mouseOverSubmenu->submenu->firstMenuItem;
|
|
|
|
|
|
while(selectionIndex && list)
|
|
|
{
|