- // In fact, don't want menu to be destroyed before MDI
- // shuffling has taken place. Let it be destroyed
- // automatically when the window is destroyed.
-
-// DestroyMenu(menu);
-// m_hMenu = NULL;
-
- int i;
-/*
- // See remarks in ::~wxMenu() method
- // BEWARE - this may interfere with MDI fixes, so
- // may need to remove
- int N = 0 ;
-
- if (m_menuBarFrame && ((m_menuBarFrame->GetWindowStyleFlag() & wxSDI) == wxSDI))
- {
- if (menu)
- N = GetMenuItemCount(menu) ;
- for (i = N-1; i >= 0; i--)
- RemoveMenu(menu, i, MF_BYPOSITION);
- }
-*/
- for (i = 0; i < m_menuCount; i++)
- {
- delete m_menus[i];
- }
- delete[] m_menus;
- delete[] m_titles;
-
-/* Don't destroy menu here, in case we're MDI and
- need to do some shuffling with VALID menu handles.
- if (menu)
- DestroyMenu(menu);
- m_hMenu = 0;
-*/
-}
-
-// 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 Flag)
-{
- int ms_flag;
- if (Flag)
- ms_flag = MF_ENABLED;
- else
- ms_flag = MF_GRAYED;
-
- wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
- if (!item)
- return;
-
- if (itemMenu->m_hMenu)
- EnableMenuItem((HMENU)itemMenu->m_hMenu, Id, MF_BYCOMMAND | ms_flag);
- else if (itemMenu->m_savehMenu)
- EnableMenuItem((HMENU)itemMenu->m_savehMenu, Id, MF_BYCOMMAND | ms_flag);
-
-}
-
-void wxMenuBar::EnableTop(int pos, bool flag)
-{
- int ms_flag;
- if (flag)
- ms_flag = MF_ENABLED;
- else
- ms_flag = MF_GRAYED;
-
- EnableMenuItem((HMENU)m_hMenu, pos, MF_BYPOSITION | ms_flag);
- DrawMenuBar((HWND) m_menuBarFrame->GetHWND()) ;
-}
-
-// Must only be used AFTER menu has been attached to frame,
-// otherwise use individual menus
-void wxMenuBar::Check(int Id, bool Flag)
-{
- wxMenu *itemMenu = NULL;
- wxMenuItem *item = FindItemForId(Id, &itemMenu) ;
- if (!item)
- return;
-
- if (!item->IsCheckable())
- return ;
- int ms_flag;
- if (Flag)
- ms_flag = MF_CHECKED;
- else
- ms_flag = MF_UNCHECKED;
+ // In Windows CE (not .NET), the menubar is always associated
+ // with a toolbar, which destroys the menu implicitly.
+#if defined(WINCE_WITHOUT_COMMANDBAR)
+ if (GetToolBar())
+ GetToolBar()->SetMenuBar(NULL);
+#else
+ // we should free Windows resources only if Windows doesn't do it for us
+ // which happens if we're attached to a frame
+ if (m_hMenu && !IsAttached())
+ {
+#if defined(WINCE_WITH_COMMANDBAR)
+ ::DestroyWindow((HWND) m_commandBar);
+ m_commandBar = (WXHWND) NULL;
+#else
+ ::DestroyMenu((HMENU)m_hMenu);
+#endif
+ m_hMenu = (WXHMENU)NULL;
+ }
+#endif
+}
+
+// ---------------------------------------------------------------------------
+// wxMenuBar helpers
+// ---------------------------------------------------------------------------