git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1968
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#endif
// convenience macro
#endif
// convenience macro
-#define GetHMENU() ((HMENU)GetHMenu())
+#define GetHMENU() ((HMENU)GetHMenu())
+#define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
// ============================================================================
// implementation
// ============================================================================
// implementation
-void wxMenu::Append(int Id, const wxString& label,
+void wxMenu::Append(int id, const wxString& label,
wxMenu *SubMenu, const wxString& helpString)
{
wxMenu *SubMenu, const wxString& helpString)
{
- Append(new wxMenuItem(this, Id, label, helpString, FALSE, SubMenu));
+ Append(new wxMenuItem(this, id, label, helpString, FALSE, SubMenu));
-void wxMenu::Append(int Id, const wxString& label,
+void wxMenu::Append(int id, const wxString& label,
const wxString& helpString, bool checkable)
{
// 'checkable' parameter is useless for Windows.
const wxString& helpString, bool checkable)
{
// 'checkable' parameter is useless for Windows.
- Append(new wxMenuItem(this, Id, label, helpString, checkable));
+ Append(new wxMenuItem(this, id, label, helpString, checkable));
}
void wxMenu::Delete(int id)
}
void wxMenu::Delete(int id)
-void wxMenu::Enable(int Id, bool Flag)
+void wxMenu::Enable(int id, bool Flag)
- wxMenuItem *item = FindItemForId(Id);
+ wxMenuItem *item = FindItemForId(id);
wxCHECK_RET( item != NULL, "can't enable non-existing menu item" );
item->Enable(Flag);
}
wxCHECK_RET( item != NULL, "can't enable non-existing menu item" );
item->Enable(Flag);
}
-bool wxMenu::IsEnabled(int Id) const
+bool wxMenu::IsEnabled(int id) const
- wxMenuItem *item = FindItemForId(Id);
- wxCHECK( item != NULL, FALSE, "invalid item id" );
+ wxMenuItem *item = FindItemForId(id);
+ wxCHECK_MSG( item != NULL, FALSE, "invalid item id" );
return item->IsEnabled();
}
return item->IsEnabled();
}
-void wxMenu::Check(int Id, bool Flag)
+void wxMenu::Check(int id, bool Flag)
- wxMenuItem *item = FindItemForId(Id);
+ wxMenuItem *item = FindItemForId(id);
wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" );
item->Check(Flag);
}
wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" );
item->Check(Flag);
}
-bool wxMenu::IsChecked(int Id) const
+bool wxMenu::IsChecked(int id) const
- wxMenuItem *item = FindItemForId(Id);
- wxCHECK( item != NULL, FALSE, "invalid item id" );
+ wxMenuItem *item = FindItemForId(id);
+ wxCHECK_MSG( item != NULL, FALSE, "invalid item id" );
return item->IsChecked();
}
return item->IsChecked();
}
-void wxMenu::SetLabel(int Id, const wxString& label)
+void wxMenu::SetLabel(int id, const wxString& label)
- wxMenuItem *item = FindItemForId(Id) ;
+ wxMenuItem *item = FindItemForId(id) ;
{
HMENU hMenu = GetHMENU();
{
HMENU hMenu = GetHMENU();
- UINT was_flag = GetMenuState(hMenu, Id, MF_BYCOMMAND);
- ModifyMenu(hMenu, Id, MF_BYCOMMAND | MF_STRING | was_flag, Id, label);
+ UINT was_flag = GetMenuState(hMenu, id, MF_BYCOMMAND);
+ ModifyMenu(hMenu, id, MF_BYCOMMAND | MF_STRING | was_flag, id, label);
// Must only be used AFTER menu has been attached to frame,
// otherwise use individual menus to enable/disable items
// Must only be used AFTER menu has been attached to frame,
// otherwise use individual menus to enable/disable items
-void wxMenuBar::Enable(int Id, bool enable)
+void wxMenuBar::Enable(int id, bool enable)
{
int flag = enable ? MF_ENABLED : MF_GRAYED;
wxMenu *itemMenu = NULL;
{
int flag = enable ? MF_ENABLED : MF_GRAYED;
wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
+ wxMenuItem *item = FindItemForId(id, &itemMenu) ;
wxCHECK_RET( item, "attempt to enable an item which doesn't exist" );
wxCHECK_RET( item, "attempt to enable an item which doesn't exist" );
- EnableMenuItem(GetHMENU(), Id, MF_BYCOMMAND | flag);
+ EnableMenuItem(GetHMenuOf(itemMenu), id, MF_BYCOMMAND | flag);
}
void wxMenuBar::EnableTop(int pos, bool enable)
}
void wxMenuBar::EnableTop(int pos, bool enable)
int flag = enable ? MF_ENABLED : MF_GRAYED;;
EnableMenuItem((HMENU)m_hMenu, pos, MF_BYPOSITION | flag);
int flag = enable ? MF_ENABLED : MF_GRAYED;;
EnableMenuItem((HMENU)m_hMenu, pos, MF_BYPOSITION | flag);
- DrawMenuBar((HWND) m_menuBarFrame->GetHWND()) ;
+ DrawMenuBar((HWND)m_menuBarFrame->GetHWND()) ;
}
// Must only be used AFTER menu has been attached to frame,
// otherwise use individual menus
}
// Must only be used AFTER menu has been attached to frame,
// otherwise use individual menus
-void wxMenuBar::Check(int Id, bool check)
+void wxMenuBar::Check(int id, bool check)
{
wxMenu *itemMenu = NULL;
{
wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
+ wxMenuItem *item = FindItemForId(id, &itemMenu) ;
wxCHECK_RET( item, "attempt to check an item which doesn't exist" );
wxCHECK_RET( item->IsCheckable(), "attempt to check an uncheckable item" );
int flag = check ? MF_CHECKED : MF_UNCHECKED;
wxCHECK_RET( item, "attempt to check an item which doesn't exist" );
wxCHECK_RET( item->IsCheckable(), "attempt to check an uncheckable item" );
int flag = check ? MF_CHECKED : MF_UNCHECKED;
- CheckMenuItem(GetHMENU(), Id, MF_BYCOMMAND | flag);
+ CheckMenuItem(GetHMenuOf(itemMenu), id, MF_BYCOMMAND | flag);
-bool wxMenuBar::IsChecked(int Id) const
+bool wxMenuBar::IsChecked(int id) const
{
wxMenu *itemMenu = NULL;
{
wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
+ wxMenuItem *item = FindItemForId(id, &itemMenu) ;
wxCHECK_MSG( item, FALSE, "wxMenuItem::IsChecked(): no such item" );
wxCHECK_MSG( item, FALSE, "wxMenuItem::IsChecked(): no such item" );
- int flag = ::GetMenuState(GetHMENU(), Id, MF_BYCOMMAND);
+ int flag = ::GetMenuState(GetHMenuOf(itemMenu), id, MF_BYCOMMAND);
return (flag & MF_CHECKED) != 0;
}
return (flag & MF_CHECKED) != 0;
}
-bool wxMenuBar::IsEnabled(int Id) const
+bool wxMenuBar::IsEnabled(int id) const
{
wxMenu *itemMenu = NULL;
{
wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
+ wxMenuItem *item = FindItemForId(id, &itemMenu) ;
wxCHECK_MSG( item, FALSE, "wxMenuItem::IsEnabled(): no such item" );
wxCHECK_MSG( item, FALSE, "wxMenuItem::IsEnabled(): no such item" );
- int flag = ::GetMenuState(GetHMENU(), Id, MF_BYCOMMAND) ;
+ int flag = ::GetMenuState(GetHMenuOf(itemMenu), id, MF_BYCOMMAND) ;
return (flag & MF_ENABLED) != 0;
}
return (flag & MF_ENABLED) != 0;
}
-void wxMenuBar::SetLabel(int Id, const wxString& label)
+void wxMenuBar::SetLabel(int id, const wxString& label)
{
wxMenu *itemMenu = NULL;
{
wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
+ wxMenuItem *item = FindItemForId(id, &itemMenu) ;
- HMENU hMenu = GetHMENU();
- UINT was_flag = ::GetMenuState(hMenu, Id, MF_BYCOMMAND);
- ::ModifyMenu(hMenu, Id, MF_BYCOMMAND | MF_STRING | was_flag, Id, label);
+ HMENU hMenu = GetHMenuOf(itemMenu);
+ UINT was_flag = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
+ ::ModifyMenu(hMenu, id, MF_BYCOMMAND | MF_STRING | was_flag, id, label);
-wxString wxMenuBar::GetLabel(int Id) const
+wxString wxMenuBar::GetLabel(int id) const
{
wxMenu *itemMenu = NULL;
{
wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
+ wxMenuItem *item = FindItemForId(id, &itemMenu) ;
wxCHECK_MSG( item, "", "wxMenuItem::GetLabel(): no such item" );
wxCHECK_MSG( item, "", "wxMenuItem::GetLabel(): no such item" );
- char tmp[128];
- int len = GetMenuString(GetHMENU(), Id, tmp, WXSIZEOF(tmp), MF_BYCOMMAND);
- tmp[len] = '\0' ;
+ HMENU hMenu = GetHMenuOf(itemMenu);
+ int len = ::GetMenuString(hMenu, id, NULL, 0, MF_BYCOMMAND);
+
+ len++; // for the NUL character
+ wxString label;
+ ::GetMenuString(hMenu, id, label.GetWriteBuf(len), len, MF_BYCOMMAND);
+ label.UngetWriteBuf();
}
void wxMenuBar::SetLabelTop(int pos, const wxString& label)
{
}
void wxMenuBar::SetLabelTop(int pos, const wxString& label)
{
- UINT was_flag = GetMenuState((HMENU)m_hMenu,pos,MF_BYPOSITION) ;
- if (was_flag&MF_POPUP)
+ UINT id;
+ UINT was_flag = ::GetMenuState((HMENU)m_hMenu, pos, MF_BYPOSITION);
+ if (was_flag & MF_POPUP)
- HMENU popup = GetSubMenu((HMENU)m_hMenu,pos) ;
- ModifyMenu((HMENU)m_hMenu,pos,MF_BYPOSITION|MF_STRING|was_flag,(UINT)popup,(const char *)label) ;
+ id = (UINT)::GetSubMenu((HMENU)m_hMenu, pos) ;
- ModifyMenu((HMENU)m_hMenu,pos,MF_BYPOSITION|MF_STRING|was_flag,pos,(const char *)label) ;
+ {
+ id = pos;
+ }
+
+ ::ModifyMenu((HMENU)m_hMenu, pos, MF_BYPOSITION | MF_STRING | was_flag,
+ id, label) ;
}
wxString wxMenuBar::GetLabelTop(int pos) const
{
}
wxString wxMenuBar::GetLabelTop(int pos) const
{
- static char tmp[128] ;
- int len = GetMenuString((HMENU)m_hMenu,pos,tmp,127,MF_BYPOSITION) ;
- tmp[len] = '\0' ;
- return wxString(tmp);
+ int len = ::GetMenuString((HMENU)m_hMenu, pos, NULL, 0, MF_BYCOMMAND);
+
+ len++; // for the NUL character
+ wxString label;
+ ::GetMenuString((HMENU)m_hMenu, pos, label.GetWriteBuf(len), len, MF_BYCOMMAND);
+ label.UngetWriteBuf();
+
+ return label;
}
bool wxMenuBar::OnDelete(wxMenu *a_menu, int pos)
}
bool wxMenuBar::OnDelete(wxMenu *a_menu, int pos)
-wxMenuItem *wxMenuBar::FindItemForId (int Id, wxMenu ** itemMenu) const
+wxMenuItem *wxMenuBar::FindItemForId (int id, wxMenu ** itemMenu) const
{
if (itemMenu)
*itemMenu = NULL;
{
if (itemMenu)
*itemMenu = NULL;
int i;
for (i = 0; i < m_menuCount; i++)
{
int i;
for (i = 0; i < m_menuCount; i++)
{
- item = m_menus[i]->FindItemForId (Id, itemMenu);
+ item = m_menus[i]->FindItemForId (id, itemMenu);
if (item)
return item;
}
return NULL;
}
if (item)
return item;
}
return NULL;
}
-void wxMenuBar::SetHelpString (int Id, const wxString& helpString)
+void wxMenuBar::SetHelpString (int id, const wxString& helpString)
{
int i;
for (i = 0; i < m_menuCount; i++)
{
{
int i;
for (i = 0; i < m_menuCount; i++)
{
- if (m_menus[i]->FindItemForId (Id))
+ if (m_menus[i]->FindItemForId (id))
- m_menus[i]->SetHelpString (Id, helpString);
+ m_menus[i]->SetHelpString (id, helpString);
-wxString wxMenuBar::GetHelpString (int Id) const
+wxString wxMenuBar::GetHelpString (int id) const
{
wxString helpString;
for (int i = 0; i < m_menuCount; i++)
{
{
wxString helpString;
for (int i = 0; i < m_menuCount; i++)
{
- wxMenuItem *item = m_menus[i]->FindItemForId(Id);
+ wxMenuItem *item = m_menus[i]->FindItemForId(id);
if ( item )
{
helpString = item->GetHelp();
if ( item )
{
helpString = item->GetHelp();