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
This commit is contained in:
@@ -105,7 +105,13 @@ wxBEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
|||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||||
|
EVT_CONTEXT_MENU(MyCanvas::OnMenu)
|
||||||
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
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()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(MyChild::EventHandler, wxEvtHandler)
|
wxBEGIN_EVENT_TABLE(MyChild::EventHandler, wxEvtHandler)
|
||||||
@@ -351,11 +357,13 @@ void MyFrame::InitToolBar(wxToolBar* toolBar)
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Define a constructor for my canvas
|
// 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,
|
: wxScrolledWindow(parent, wxID_ANY, pos, size,
|
||||||
wxSUNKEN_BORDER |
|
wxSUNKEN_BORDER |
|
||||||
wxNO_FULL_REPAINT_ON_RESIZE |
|
wxNO_FULL_REPAINT_ON_RESIZE |
|
||||||
wxVSCROLL | wxHSCROLL)
|
wxVSCROLL | wxHSCROLL),
|
||||||
|
MenuEventLogger("canvas", parent)
|
||||||
|
|
||||||
{
|
{
|
||||||
SetBackgroundColour(*wxWHITE);
|
SetBackgroundColour(*wxWHITE);
|
||||||
SetCursor(wxCursor(wxCURSOR_PENCIL));
|
SetCursor(wxCursor(wxCURSOR_PENCIL));
|
||||||
@@ -415,11 +423,22 @@ void MyCanvas::OnEvent(wxMouseEvent& event)
|
|||||||
|
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
xpos = pt.x;
|
xpos = pt.x;
|
||||||
ypos = pt.y;
|
ypos = pt.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyCanvas::OnMenu(wxContextMenuEvent& event)
|
||||||
|
{
|
||||||
|
wxMenu menu;
|
||||||
|
menu.Append(MDI_REFRESH, "&Refresh picture");
|
||||||
|
PopupMenu(&menu, ScreenToClient(event.GetPosition()));
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// MyChild
|
// MyChild
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -17,26 +17,6 @@ public:
|
|||||||
virtual bool OnInit() wxOVERRIDE;
|
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.
|
// Helper class logging menu open/close events.
|
||||||
class MenuEventLogger
|
class MenuEventLogger
|
||||||
{
|
{
|
||||||
@@ -77,6 +57,32 @@ protected:
|
|||||||
wxDECLARE_NO_COPY_CLASS(MenuEventLogger);
|
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
|
// Define a new frame
|
||||||
class MyFrame : public wxMDIParentFrame,
|
class MyFrame : public wxMDIParentFrame,
|
||||||
private MenuEventLogger
|
private MenuEventLogger
|
||||||
|
Reference in New Issue
Block a user