From 1c6bb3f5b83b28ce645f5224ae2e60c8882e9caa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2014 22:17:38 +0000 Subject: [PATCH] Add a popup menu to the MDI sample. This is just to test how wxEVT_MENU_HIGHLIGHT events from popup menu items are handled under the different platforms. Also log menu events to the canvas window too as it now gets some. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/mdi/mdi.cpp | 23 +++++++++++++++++++++-- samples/mdi/mdi.h | 46 +++++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index 706b129a1c..2ff38c2209 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -105,7 +105,13 @@ wxBEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) wxEND_EVENT_TABLE() wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) + EVT_CONTEXT_MENU(MyCanvas::OnMenu) EVT_MOUSE_EVENTS(MyCanvas::OnEvent) + + EVT_MENU_OPEN(MyCanvas::OnMenuOpen) + EVT_MENU_HIGHLIGHT(wxID_ABOUT, MyCanvas::OnMenuHighlight) + EVT_MENU_HIGHLIGHT(MDI_REFRESH, MyCanvas::OnMenuHighlight) + EVT_MENU_CLOSE(MyCanvas::OnMenuClose) wxEND_EVENT_TABLE() wxBEGIN_EVENT_TABLE(MyChild::EventHandler, wxEvtHandler) @@ -351,11 +357,13 @@ void MyFrame::InitToolBar(wxToolBar* toolBar) // --------------------------------------------------------------------------- // Define a constructor for my canvas -MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size) +MyCanvas::MyCanvas(wxFrame *parent, const wxPoint& pos, const wxSize& size) : wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER | wxNO_FULL_REPAINT_ON_RESIZE | - wxVSCROLL | wxHSCROLL) + wxVSCROLL | wxHSCROLL), + MenuEventLogger("canvas", parent) + { SetBackgroundColour(*wxWHITE); SetCursor(wxCursor(wxCURSOR_PENCIL)); @@ -415,11 +423,22 @@ void MyCanvas::OnEvent(wxMouseEvent& event) m_dirty = true; } + else + { + event.Skip(); + } xpos = pt.x; ypos = pt.y; } +void MyCanvas::OnMenu(wxContextMenuEvent& event) +{ + wxMenu menu; + menu.Append(MDI_REFRESH, "&Refresh picture"); + PopupMenu(&menu, ScreenToClient(event.GetPosition())); +} + // --------------------------------------------------------------------------- // MyChild // --------------------------------------------------------------------------- diff --git a/samples/mdi/mdi.h b/samples/mdi/mdi.h index 181a31c9a7..6c86e2bdf7 100644 --- a/samples/mdi/mdi.h +++ b/samples/mdi/mdi.h @@ -17,26 +17,6 @@ public: virtual bool OnInit() wxOVERRIDE; }; -class MyCanvas : public wxScrolledWindow -{ -public: - MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size); - virtual void OnDraw(wxDC& dc) wxOVERRIDE; - - bool IsDirty() const { return m_dirty; } - - void SetText(const wxString& text) { m_text = text; Refresh(); } - -private: - void OnEvent(wxMouseEvent& event); - - wxString m_text; - - bool m_dirty; - - wxDECLARE_EVENT_TABLE(); -}; - // Helper class logging menu open/close events. class MenuEventLogger { @@ -77,6 +57,32 @@ protected: wxDECLARE_NO_COPY_CLASS(MenuEventLogger); }; +class MyCanvas : public wxScrolledWindow, + private MenuEventLogger +{ +public: + MyCanvas(wxFrame *parent, const wxPoint& pos, const wxSize& size); + virtual void OnDraw(wxDC& dc) wxOVERRIDE; + + bool IsDirty() const { return m_dirty; } + + void SetText(const wxString& text) { m_text = text; Refresh(); } + +private: + void OnMenuOpen(wxMenuEvent& event) { LogMenuOpenClose(event, "opened"); } + void OnMenuHighlight(wxMenuEvent& event) { LogMenuHighlight(event); } + void OnMenuClose(wxMenuEvent& event) { LogMenuOpenClose(event, "closed"); } + + void OnMenu(wxContextMenuEvent& event); + void OnEvent(wxMouseEvent& event); + + wxString m_text; + + bool m_dirty; + + wxDECLARE_EVENT_TABLE(); +}; + // Define a new frame class MyFrame : public wxMDIParentFrame, private MenuEventLogger