Use WM_INITMENUPOPUP

Added wxMenu member to wxMenuEvent


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2003-07-12 23:09:04 +00:00
parent 1b80d34a52
commit 92f1a59c28
8 changed files with 79 additions and 39 deletions

View File

@@ -1184,12 +1184,12 @@ private:
class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent
{ {
public: public:
wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0) wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL)
: wxEvent(winid, type) : wxEvent(winid, type)
{ m_menuId = winid; } { m_menuId = winid; m_menu = NULL; }
wxMenuEvent(const wxMenuEvent & event) wxMenuEvent(const wxMenuEvent & event)
: wxEvent(event) : wxEvent(event)
{ m_menuId = event.m_menuId; } { m_menuId = event.m_menuId; m_menu = event.m_menu; }
// only for wxEVT_MENU_HIGHLIGHT // only for wxEVT_MENU_HIGHLIGHT
int GetMenuId() const { return m_menuId; } int GetMenuId() const { return m_menuId; }
@@ -1197,10 +1197,14 @@ public:
// only for wxEVT_MENU_OPEN/CLOSE // only for wxEVT_MENU_OPEN/CLOSE
bool IsPopup() const { return m_menuId == -1; } 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); } virtual wxEvent *Clone() const { return new wxMenuEvent(*this); }
private: private:
int m_menuId; int m_menuId;
wxMenu* m_menu;
DECLARE_DYNAMIC_CLASS(wxMenuEvent) DECLARE_DYNAMIC_CLASS(wxMenuEvent)
}; };

View File

@@ -146,8 +146,9 @@ public:
void OnMenuHighlight(wxMenuEvent& event); void OnMenuHighlight(wxMenuEvent& event);
#if wxUSE_MENUS #if wxUSE_MENUS
// send wxUpdateUIEvents for all menu items (called from OnIdle()) // send wxUpdateUIEvents for all menu items in the menubar,
void DoMenuUpdates(); // or just for menu if non-NULL
void DoMenuUpdates(wxMenu* menu = NULL);
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
// do the UI update processing for this window // do the UI update processing for this window

View File

@@ -102,6 +102,12 @@ public:
// current size - this has an effect of refreshing the window layout // current size - this has an effect of refreshing the window layout
virtual void SendSizeEvent(); virtual void SendSizeEvent();
#ifdef __WXWINCE__
WXHWND GetCommandBar() { return m_commandBar; }
WXHWND CreateCommandBar() ;
void RemoveCommandBar() ;
#endif
protected: protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
@@ -128,8 +134,8 @@ protected:
// window proc for the frames // window proc for the frames
long MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); long MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
// handle WM_INITMENU message // handle WM_INITMENUPOPUP message
bool HandleInitMenu(); bool HandleInitMenuPopup(WXHMENU hMenu);
virtual bool IsMDIChild() const { return FALSE; } virtual bool IsMDIChild() const { return FALSE; }

View File

@@ -332,8 +332,7 @@
* Presently, only Windows and GTK+ support wxEVT_MENU_OPEN. * Presently, only Windows and GTK+ support wxEVT_MENU_OPEN.
*/ */
#ifndef wxUSE_IDLEMENUUPDATES #ifndef wxUSE_IDLEMENUUPDATES
#if (defined(__WXMSW__) && !defined(__WXWINCE)) ||\ #if defined(__WXMSW__) || defined(__WXGTK__)
defined(__WXGTK__)
#define wxUSE_IDLEMENUUPDATES 0 #define wxUSE_IDLEMENUUPDATES 0
#else #else
#define wxUSE_IDLEMENUUPDATES 1 #define wxUSE_IDLEMENUUPDATES 1

View File

@@ -256,10 +256,10 @@ void wxFrameBase::OnInternalIdle()
#endif #endif
} }
void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event)) void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
{ {
#if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
DoMenuUpdates(); DoMenuUpdates(event.GetMenu());
#endif #endif
} }
@@ -421,13 +421,15 @@ wxToolBar* wxFrameBase::OnCreateToolBar(long style,
#if wxUSE_MENUS #if wxUSE_MENUS
// update all menus // update all menus
void wxFrameBase::DoMenuUpdates() void wxFrameBase::DoMenuUpdates(wxMenu* menu)
{
wxMenuBar* bar = GetMenuBar();
if ( bar != NULL )
{ {
wxEvtHandler* source = GetEventHandler(); wxEvtHandler* source = GetEventHandler();
wxMenuBar* bar = GetMenuBar();
if (menu)
menu->UpdateUI(source);
else if ( bar != NULL )
{
int nCount = bar->GetMenuCount(); int nCount = bar->GetMenuCount();
for (int n = 0; n < nCount; n++) for (int n = 0; n < nCount; n++)
bar->GetMenu(n)->UpdateUI(source); bar->GetMenu(n)->UpdateUI(source);

View File

@@ -169,7 +169,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu )
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle) wxapp_install_idle_handler();
wxMenuEvent event( wxEVT_MENU_OPEN, -1 ); wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu );
event.SetEventObject( menu ); event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler(); wxEvtHandler* handler = menu->GetEventHandler();

View File

@@ -169,7 +169,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu )
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle) wxapp_install_idle_handler();
wxMenuEvent event( wxEVT_MENU_OPEN, -1 ); wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu );
event.SetEventObject( menu ); event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler(); wxEvtHandler* handler = menu->GetEventHandler();

View File

@@ -141,11 +141,7 @@ wxFrame::~wxFrame()
m_isBeingDeleted = TRUE; m_isBeingDeleted = TRUE;
DeleteAllBars(); DeleteAllBars();
#ifdef __WXWINCE__ #ifdef __WXWINCE__
if (m_commandBar) RemoveCommandBar();
{
::DestroyWindow((HWND) m_commandBar);
m_commandBar = NULL;
}
#endif #endif
} }
@@ -300,16 +296,9 @@ void wxFrame::InternalSetMenuBar()
#ifdef __WXMICROWIN__ #ifdef __WXMICROWIN__
// Nothing // Nothing
#elif defined(__WXWINCE__) #elif defined(__WXWINCE__)
if (!m_commandBar)
{ CreateCommandBar() ;
// 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;
}
}
if (m_commandBar) if (m_commandBar)
{ {
if (!CommandBar_InsertMenubarEx((HWND) m_commandBar, NULL, if (!CommandBar_InsertMenubarEx((HWND) m_commandBar, NULL,
@@ -802,6 +791,10 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
processed = HandlePaint(); processed = HandlePaint();
break; break;
case WM_INITMENUPOPUP:
processed = HandleInitMenuPopup((WXHMENU) wParam);
break;
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
case WM_MENUSELECT: case WM_MENUSELECT:
{ {
@@ -813,10 +806,6 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
} }
break; break;
case WM_INITMENU:
processed = HandleInitMenu();
break;
case WM_EXITMENULOOP: case WM_EXITMENULOOP:
processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam); processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
break; break;
@@ -839,13 +828,52 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
return rc; return rc;
} }
// handle WM_INITMENU message // handle WM_INITMENUPOPUP message
bool wxFrame::HandleInitMenu() 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); event.SetEventObject(this);
return GetEventHandler()->ProcessEvent(event); 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