// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-
-// ============================================================================
-// declarations
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// headers
-// ----------------------------------------------------------------------------
-
-// wxWindows headers
-// -----------------
-
#ifdef __GNUG__
- #pragma implementation "menu.h"
- #pragma implementation "menuitem.h"
+#pragma implementation "menu.h"
#endif
// For compilers that support precompilation, includes "wx.h".
m_hMenu = (WXHMENU) CreatePopupMenu();
m_savehMenu = 0 ;
m_topLevelMenu = this;
+ m_clientData = (void*) NULL;
+
if (m_title != "")
{
Append(idMenuTitle, m_title) ;
void wxMenu::Delete(int id)
{
wxNode *node;
- wxMenuItem *item;
int pos;
HMENU menu;
+ wxMenuItem *item = NULL;
for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) {
item = (wxMenuItem *)node->Data();
if (item->GetId() == id)
{
if ( !label.IsEmpty() )
{
- if ( !InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING,
- idMenuTitle, m_title) ||
- !InsertMenu(hMenu, 1, MF_BYPOSITION, -1, NULL) )
+ if ( !InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
+ (unsigned)idMenuTitle, m_title) ||
+ !InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
{
wxLogLastError("InsertMenu");
}
else
{
// modify the title
- if ( !ModifyMenu(hMenu, 0,
+ if ( !ModifyMenu(hMenu, 0u,
MF_BYPOSITION | MF_STRING,
- idMenuTitle, m_title) )
+ (unsigned)idMenuTitle, m_title) )
{
wxLogLastError("ModifyMenu");
}
}
}
- // TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face
+#ifndef __WIN16__
+ // put the title string in bold face
+ if ( !m_title.IsEmpty() )
+ {
+ MENUITEMINFO mii;
+ mii.cbSize = sizeof(mii);
+ mii.fMask = MIIM_STATE;
+ mii.fState = MFS_DEFAULT;
+
+ if ( !SetMenuItemInfo(hMenu, (unsigned)idMenuTitle, FALSE, &mii) )
+ {
+ wxLogLastError("SetMenuItemInfo");
+ }
+ }
+#endif
}
const wxString wxMenu::GetTitle() const
bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id)
{
- wxCommandEvent event(wxEVENT_TYPE_MENU_COMMAND);
- event.SetEventObject( this );
- event.SetId( id );
- event.SetInt( id );
- ProcessCommand(event);
- return TRUE;
+ // ignore commands from the menu title
+
+ // NB: VC++ generates wrong assembler for `if ( id != idMenuTitle )'!!
+ if ( id != (WXWORD)idMenuTitle )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
+ event.SetEventObject( this );
+ event.SetId( id );
+ event.SetInt( id );
+ ProcessCommand(event);
+ }
+
+ return TRUE;
}
// Finds the item id matching the given string, -1 if not found.
wxString wxMenu::GetHelpString (int itemId) const
{
wxMenuItem *item = FindItemForId (itemId);
- wxString str("");
- return (item == NULL) ? str : item->GetHelp();
+ if (item)
+ return item->GetHelp();
+ else
+ return wxEmptyString;
}
void wxMenu::ProcessCommand(wxCommandEvent & event)
// Try the window the menu was popped up from (and up
// through the hierarchy)
if ( !processed && GetInvokingWindow())
- processed = GetInvokingWindow()->ProcessEvent(event);
+ processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event);
}
extern wxMenu *wxCurrentPopupMenu;
bool wxWindow::PopupMenu(wxMenu *menu, int x, int y)
{
menu->SetInvokingWindow(this);
+ menu->UpdateUI();
HWND hWnd = (HWND) GetHWND();
HMENU hMenu = (HMENU)menu->m_hMenu;
wxMenuBar::wxMenuBar()
{
m_eventHandler = this;
+ m_menuCount = 0;
+ m_menus = NULL;
+ m_titles = NULL;
+ m_menuBarFrame = NULL;
+ m_hMenu = 0;
+}
+wxMenuBar::wxMenuBar( long WXUNUSED(style) )
+{
+ m_eventHandler = this;
m_menuCount = 0;
m_menus = NULL;
m_titles = NULL;
if (!item)
return FALSE;
- int Flag ;
+ int Flag = 0;
if (itemMenu->m_hMenu)
Flag=GetMenuState((HMENU)itemMenu->m_hMenu, Id, MF_BYCOMMAND) ;
wxMenuItem *item = NULL;
int i;
for (i = 0; i < m_menuCount; i++)
- if ((item = m_menus[i]->FindItemForId (Id, itemMenu)))
+ {
+ item = m_menus[i]->FindItemForId (Id, itemMenu);
+ if (item)
return item;
+ }
return NULL;
}
return 0;
}
+// Update a menu and all submenus recursively.
+// source is the object that has the update event handlers
+// defined for it. If NULL, the menu or associated window
+// will be used.
+void wxMenu::UpdateUI(wxEvtHandler* source)
+{
+ if (!source && GetInvokingWindow())
+ source = GetInvokingWindow()->GetEventHandler();
+ if (!source)
+ source = GetEventHandler();
+ if (!source)
+ source = this;
+
+ wxNode* node = GetItems().First();
+ while (node)
+ {
+ wxMenuItem* item = (wxMenuItem*) node->Data();
+ if ( !item->IsSeparator() )
+ {
+ wxWindowID id = item->GetId();
+ wxUpdateUIEvent event(id);
+ event.SetEventObject( source );
+
+ if (source->ProcessEvent(event))
+ {
+ if (event.GetSetText())
+ SetLabel(id, event.GetText());
+ if (event.GetSetChecked())
+ Check(id, event.GetChecked());
+ if (event.GetSetEnabled())
+ Enable(id, event.GetEnabled());
+ }
+
+ if (item->GetSubMenu())
+ item->GetSubMenu()->UpdateUI(source);
+ }
+ node = node->Next();
+ }
+}