This commit was manufactured by cvs2svn to create tag 'WX_2_2_9'.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/WX_2_2_9@13364 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -47,7 +47,9 @@ class MyFrame: public wxFrame
|
||||
public:
|
||||
MyFrame();
|
||||
|
||||
virtual ~MyFrame() { delete m_menu; }
|
||||
virtual ~MyFrame();
|
||||
|
||||
void LogMenuEvent(const wxCommandEvent& event);
|
||||
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
@@ -75,6 +77,7 @@ public:
|
||||
void OnRightDown(wxMouseEvent& event);
|
||||
|
||||
void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event);
|
||||
void OnUpdatePopup(wxUpdateUIEvent& event) { event.Enable(FALSE); }
|
||||
|
||||
private:
|
||||
wxMenu *CreateDummyMenu(wxString *title);
|
||||
@@ -88,6 +91,36 @@ private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
// A small helper class which intercepts all menu events and logs them
|
||||
class MyEvtHandler : public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
MyEvtHandler(MyFrame *frame) { m_frame = frame; }
|
||||
|
||||
void OnMenuEvent(wxCommandEvent& event)
|
||||
{
|
||||
m_frame->LogMenuEvent(event);
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
private:
|
||||
MyFrame *m_frame;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyPopupMenu : public wxMenu
|
||||
{
|
||||
public:
|
||||
MyPopupMenu(const wxString& title) : wxMenu(title) { }
|
||||
|
||||
void OnUpdateUI(wxUpdateUIEvent& event) { event.Enable(FALSE); }
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -124,6 +157,8 @@ enum
|
||||
|
||||
Menu_Popup_ToBeDeleted = 2000,
|
||||
Menu_Popup_ToBeGreyed,
|
||||
Menu_Popup_ToBeGreyed2,
|
||||
Menu_Popup_ToBeGreyed3,
|
||||
Menu_Popup_ToBeChecked,
|
||||
Menu_Popup_Submenu,
|
||||
|
||||
@@ -161,9 +196,19 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
|
||||
EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
|
||||
|
||||
EVT_UPDATE_UI(Menu_Popup_ToBeGreyed3, MyFrame::OnUpdatePopup)
|
||||
|
||||
EVT_RIGHT_DOWN(MyFrame::OnRightDown)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
|
||||
EVT_MENU(-1, MyEvtHandler::OnMenuEvent)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(MyPopupMenu, wxMenu)
|
||||
EVT_UPDATE_UI(Menu_Popup_ToBeGreyed2, MyPopupMenu::OnUpdateUI)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
@@ -202,7 +247,7 @@ MyFrame::MyFrame()
|
||||
m_menu = NULL;
|
||||
m_countDummy = 0;
|
||||
|
||||
CreateStatusBar();
|
||||
CreateStatusBar(2);
|
||||
|
||||
// create the menubar
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
@@ -267,6 +312,17 @@ MyFrame::MyFrame()
|
||||
|
||||
// associate the menu bar with the frame
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
// intercept all menu events and log them in this custom event handler
|
||||
PushEventHandler(new MyEvtHandler(this));
|
||||
}
|
||||
|
||||
MyFrame::~MyFrame()
|
||||
{
|
||||
delete m_menu;
|
||||
|
||||
// delete the event handler installed in ctor
|
||||
PopEventHandler(TRUE);
|
||||
}
|
||||
|
||||
wxMenu *MyFrame::CreateDummyMenu(wxString *title)
|
||||
@@ -302,6 +358,25 @@ wxMenuItem *MyFrame::GetLastMenuItem() const
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::LogMenuEvent(const wxCommandEvent& event)
|
||||
{
|
||||
int id = event.GetId();
|
||||
if (!GetMenuBar()->FindItem(id))
|
||||
return;
|
||||
wxString msg = wxString::Format("Menu command %d", id);
|
||||
if ( GetMenuBar()->FindItem(id)->IsCheckable() )
|
||||
{
|
||||
msg += wxString::Format(" (the item is currently %schecked)",
|
||||
event.IsChecked() ? "" : "not ");
|
||||
}
|
||||
|
||||
SetStatusText(msg, 1);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// menu callbacks
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Close(TRUE);
|
||||
@@ -408,11 +483,11 @@ void MyFrame::OnAppendMenuItem(wxCommandEvent& WXUNUSED(event))
|
||||
void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxMenuBar *menubar = GetMenuBar();
|
||||
|
||||
|
||||
wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
|
||||
|
||||
menu->Append(Menu_Dummy_Last, "Dummy sub menu\tCtrl-F2",
|
||||
CreateDummyMenu(NULL));
|
||||
|
||||
menu->Append(Menu_Dummy_Last, "Dummy sub menu",
|
||||
CreateDummyMenu(NULL), "Dummy sub menu help");
|
||||
}
|
||||
|
||||
void MyFrame::OnDeleteMenuItem(wxCommandEvent& WXUNUSED(event))
|
||||
@@ -498,7 +573,7 @@ void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event))
|
||||
msg << "The item is " << (item->IsEnabled() ? "enabled"
|
||||
: "disabled")
|
||||
<< '\n';
|
||||
|
||||
|
||||
if ( item->IsCheckable() )
|
||||
{
|
||||
msg << "It is checkable and " << (item->IsChecked() ? "" : "un")
|
||||
@@ -565,7 +640,7 @@ void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
void MyFrame::OnRightDown(wxMouseEvent &event )
|
||||
{
|
||||
wxMenu menu("Test popup");
|
||||
MyPopupMenu menu("Test popup");
|
||||
|
||||
menu.Append(Menu_Help_About, "&About");
|
||||
menu.Append(Menu_Popup_Submenu, "Submenu", CreateDummyMenu(NULL));
|
||||
@@ -573,11 +648,22 @@ void MyFrame::OnRightDown(wxMouseEvent &event )
|
||||
menu.Append(Menu_Popup_ToBeChecked, "To be checked", "", TRUE);
|
||||
menu.Append(Menu_Popup_ToBeGreyed, "To be greyed");
|
||||
menu.AppendSeparator();
|
||||
// VZ: don't search for the word autogreyed in the dictionary...
|
||||
menu.Append(Menu_Popup_ToBeGreyed2, "To be autogreyed");
|
||||
menu.Append(Menu_Popup_ToBeGreyed3, "This one too");
|
||||
menu.AppendSeparator();
|
||||
menu.Append(Menu_File_Quit, "E&xit");
|
||||
|
||||
//menu.Delete(Menu_Popup_ToBeDeleted);
|
||||
menu.Delete(Menu_Popup_ToBeDeleted);
|
||||
menu.Check(Menu_Popup_ToBeChecked, TRUE);
|
||||
menu.Enable(Menu_Popup_ToBeGreyed, FALSE);
|
||||
|
||||
PopupMenu( &menu, event.GetX(), event.GetY() );
|
||||
|
||||
// test for destroying items in popup menus
|
||||
#if 0
|
||||
menu.Destroy(Menu_Popup_Submenu);
|
||||
|
||||
PopupMenu( &menu, event.GetX(), event.GetY() );
|
||||
#endif // 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user