class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent
{
public:
- wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0)
+ wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL)
: wxEvent(winid, type)
- { m_menuId = winid; }
+ { m_menuId = winid; m_menu = NULL; }
wxMenuEvent(const wxMenuEvent & event)
: wxEvent(event)
- { m_menuId = event.m_menuId; }
+ { m_menuId = event.m_menuId; m_menu = event.m_menu; }
// only for wxEVT_MENU_HIGHLIGHT
int GetMenuId() const { return m_menuId; }
// only for wxEVT_MENU_OPEN/CLOSE
bool IsPopup() const { return m_menuId == -1; }
+ // only for wxEVT_MENU_OPEN/CLOSE
+ wxMenu* GetMenu() const { return m_menu; }
+
virtual wxEvent *Clone() const { return new wxMenuEvent(*this); }
private:
- int m_menuId;
+ int m_menuId;
+ wxMenu* m_menu;
DECLARE_DYNAMIC_CLASS(wxMenuEvent)
};
void OnMenuHighlight(wxMenuEvent& event);
#if wxUSE_MENUS
- // send wxUpdateUIEvents for all menu items (called from OnIdle())
- void DoMenuUpdates();
+ // send wxUpdateUIEvents for all menu items in the menubar,
+ // or just for menu if non-NULL
+ void DoMenuUpdates(wxMenu* menu = NULL);
#endif // wxUSE_MENUS
// do the UI update processing for this window
// current size - this has an effect of refreshing the window layout
virtual void SendSizeEvent();
+#ifdef __WXWINCE__
+ WXHWND GetCommandBar() { return m_commandBar; }
+ WXHWND CreateCommandBar() ;
+ void RemoveCommandBar() ;
+#endif
+
protected:
// common part of all ctors
void Init();
// window proc for the frames
long MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
- // handle WM_INITMENU message
- bool HandleInitMenu();
+ // handle WM_INITMENUPOPUP message
+ bool HandleInitMenuPopup(WXHMENU hMenu);
virtual bool IsMDIChild() const { return FALSE; }
* Presently, only Windows and GTK+ support wxEVT_MENU_OPEN.
*/
#ifndef wxUSE_IDLEMENUUPDATES
- #if (defined(__WXMSW__) && !defined(__WXWINCE)) ||\
- defined(__WXGTK__)
+ #if defined(__WXMSW__) || defined(__WXGTK__)
#define wxUSE_IDLEMENUUPDATES 0
#else
#define wxUSE_IDLEMENUUPDATES 1
#endif
}
-void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event))
+void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
{
#if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
- DoMenuUpdates();
+ DoMenuUpdates(event.GetMenu());
#endif
}
#if wxUSE_MENUS
// update all menus
-void wxFrameBase::DoMenuUpdates()
+void wxFrameBase::DoMenuUpdates(wxMenu* menu)
{
+ wxEvtHandler* source = GetEventHandler();
wxMenuBar* bar = GetMenuBar();
- if ( bar != NULL )
+ if (menu)
+ menu->UpdateUI(source);
+ else if ( bar != NULL )
{
- wxEvtHandler* source = GetEventHandler();
int nCount = bar->GetMenuCount();
for (int n = 0; n < nCount; n++)
bar->GetMenu(n)->UpdateUI(source);
{
if (g_isIdle) wxapp_install_idle_handler();
- wxMenuEvent event( wxEVT_MENU_OPEN, -1 );
+ wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu );
event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler();
{
if (g_isIdle) wxapp_install_idle_handler();
- wxMenuEvent event( wxEVT_MENU_OPEN, -1 );
+ wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu );
event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler();
m_isBeingDeleted = TRUE;
DeleteAllBars();
#ifdef __WXWINCE__
- if (m_commandBar)
- {
- ::DestroyWindow((HWND) m_commandBar);
- m_commandBar = NULL;
- }
+ RemoveCommandBar();
#endif
}
#ifdef __WXMICROWIN__
// Nothing
#elif defined(__WXWINCE__)
- if (!m_commandBar)
- {
- // TODO: eventually have a wxCommandBar class
- m_commandBar = (WXHWND) CommandBar_Create(wxGetInstance(), GetHwnd(), NewControlId());
- if (!m_commandBar)
- {
- wxFAIL_MSG( _T("failed to create commandbar") );
- return;
- }
- }
+
+ CreateCommandBar() ;
+
if (m_commandBar)
{
if (!CommandBar_InsertMenubarEx((HWND) m_commandBar, NULL,
processed = HandlePaint();
break;
+ case WM_INITMENUPOPUP:
+ processed = HandleInitMenuPopup((WXHMENU) wParam);
+ break;
+
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
case WM_MENUSELECT:
{
}
break;
- case WM_INITMENU:
- processed = HandleInitMenu();
- break;
-
case WM_EXITMENULOOP:
processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
break;
return rc;
}
-// handle WM_INITMENU message
-bool wxFrame::HandleInitMenu()
+// handle WM_INITMENUPOPUP message
+bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
{
- wxMenuEvent event(wxEVT_MENU_OPEN, 0);
+ wxMenu* menu = NULL;
+ if (GetMenuBar())
+ {
+ int nCount = GetMenuBar()->GetMenuCount();
+ for (int n = 0; n < nCount; n++)
+ {
+ if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
+ {
+ menu = GetMenuBar()->GetMenu(n);
+ break;
+ }
+ }
+ }
+
+ wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
event.SetEventObject(this);
return GetEventHandler()->ProcessEvent(event);
}
+#ifdef __WXWINCE__
+WXHWND wxFrame::CreateCommandBar()
+{
+ if (m_commandBar)
+ return m_commandBar;
+
+ m_commandBar = (WXHWND) CommandBar_Create(wxGetInstance(), GetHwnd(), NewControlId());
+ if (!m_commandBar)
+ {
+ wxFAIL_MSG( _T("failed to create commandbar") );
+ return 0;
+ }
+ return m_commandBar;
+}
+
+void wxFrame::RemoveCommandBar()
+{
+ if (m_commandBar)
+ {
+ ::DestroyWindow((HWND) m_commandBar);
+ m_commandBar = NULL;
+ }
+}
+#endif
+