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:
		@@ -1184,12 +1184,12 @@ private:
 | 
			
		||||
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; }
 | 
			
		||||
@@ -1197,10 +1197,14 @@ public:
 | 
			
		||||
    // 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;
 | 
			
		||||
    wxMenu* m_menu;
 | 
			
		||||
 | 
			
		||||
    DECLARE_DYNAMIC_CLASS(wxMenuEvent)
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -146,8 +146,9 @@ public:
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
@@ -102,6 +102,12 @@ public:
 | 
			
		||||
    // 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();
 | 
			
		||||
@@ -128,8 +134,8 @@ protected:
 | 
			
		||||
    // 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; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -332,8 +332,7 @@
 | 
			
		||||
 * 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
 | 
			
		||||
 
 | 
			
		||||
@@ -256,10 +256,10 @@ void wxFrameBase::OnInternalIdle()
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event))
 | 
			
		||||
void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
 | 
			
		||||
{
 | 
			
		||||
#if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
 | 
			
		||||
    DoMenuUpdates();
 | 
			
		||||
    DoMenuUpdates(event.GetMenu());
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -421,13 +421,15 @@ wxToolBar* wxFrameBase::OnCreateToolBar(long style,
 | 
			
		||||
#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);
 | 
			
		||||
 
 | 
			
		||||
@@ -169,7 +169,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu )
 | 
			
		||||
{
 | 
			
		||||
    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();
 | 
			
		||||
 
 | 
			
		||||
@@ -169,7 +169,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu )
 | 
			
		||||
{
 | 
			
		||||
    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();
 | 
			
		||||
 
 | 
			
		||||
@@ -141,11 +141,7 @@ wxFrame::~wxFrame()
 | 
			
		||||
    m_isBeingDeleted = TRUE;
 | 
			
		||||
    DeleteAllBars();
 | 
			
		||||
#ifdef __WXWINCE__
 | 
			
		||||
    if (m_commandBar)
 | 
			
		||||
    {
 | 
			
		||||
        ::DestroyWindow((HWND) m_commandBar);
 | 
			
		||||
        m_commandBar = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    RemoveCommandBar();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -300,16 +296,9 @@ void wxFrame::InternalSetMenuBar()
 | 
			
		||||
#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,
 | 
			
		||||
@@ -802,6 +791,10 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
 | 
			
		||||
            processed = HandlePaint();
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case WM_INITMENUPOPUP:
 | 
			
		||||
            processed = HandleInitMenuPopup((WXHMENU) wParam);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
 | 
			
		||||
        case WM_MENUSELECT:
 | 
			
		||||
            {
 | 
			
		||||
@@ -813,10 +806,6 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case WM_INITMENU:
 | 
			
		||||
            processed = HandleInitMenu();
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case WM_EXITMENULOOP:
 | 
			
		||||
            processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
 | 
			
		||||
            break;
 | 
			
		||||
@@ -839,13 +828,52 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user