// ---------------------------------------------------------------------------
// Construct a menu with optional title (then use append)
-void wxMenu::Init()
+void wxMenu::InitNoCreate()
{
m_radioData = NULL;
m_doBreak = false;
m_maxBitmapWidth = 0;
m_maxAccelWidth = -1;
#endif // wxUSE_OWNER_DRAWN
+}
+
+void wxMenu::Init()
+{
+ InitNoCreate();
// create the menu
m_hMenu = (WXHMENU)CreatePopupMenu();
}
}
+wxMenu::wxMenu(WXHMENU hMenu)
+{
+ InitNoCreate();
+
+ m_hMenu = hMenu;
+
+ // Ensure that our internal idea of how many items we have corresponds to
+ // the real number of items in the menu.
+ //
+ // We could also retrieve the real labels of the items here but it doesn't
+ // seem to be worth the trouble.
+ const int numExistingItems = ::GetMenuItemCount(m_hMenu);
+ for ( int n = 0; n < numExistingItems; n++ )
+ {
+ wxMenuBase::DoAppend(wxMenuItem::New(this, wxID_SEPARATOR));
+ }
+}
+
// The wxWindow destructor will take care of deleting the submenus.
wxMenu::~wxMenu()
{
// ignore commands from the menu title
if ( id != idMenuTitle )
{
+ // Default value for uncheckable items.
+ int checked = -1;
+
// update the check item when it's clicked
wxMenuItem * const item = FindItem(id);
if ( item && item->IsCheckable() )
+ {
item->Toggle();
- // get the status of the menu item: note that it has been just changed
- // by Toggle() above so here we already get the new state of the item
- UINT menuState = ::GetMenuState(GetHmenu(), id, MF_BYCOMMAND);
- SendEvent(id, menuState & MF_CHECKED);
+ // Get the status of the menu item: note that it has been just changed
+ // by Toggle() above so here we already get the new state of the item.
+ //
+ // Also notice that we must pass unsigned id_ and not sign-extended id
+ // to ::GetMenuState() as this is what it expects.
+ UINT menuState = ::GetMenuState(GetHmenu(), id_, MF_BYCOMMAND);
+ checked = (menuState & MF_CHECKED) != 0;
+ }
+
+ SendEvent(id, checked);
}
return true;