#endif
#ifndef WX_PRECOMP
- #include <wx/app.h>
- #include <wx/frame.h>
- #include <wx/menu.h>
- #include <wx/msgdlg.h>
- #include <wx/log.h>
- #include <wx/textctrl.h>
+ #include "wx/app.h"
+ #include "wx/frame.h"
+ #include "wx/menu.h"
+ #include "wx/msgdlg.h"
+ #include "wx/log.h"
+ #include "wx/textctrl.h"
+ #include "wx/textdlg.h"
#endif
#if !wxUSE_MENUS
void OnGetLabelMenu(wxCommandEvent& event);
void OnSetLabelMenu(wxCommandEvent& event);
- void OnRightUp(wxMouseEvent& event);
+#ifdef __WXMSW__
+ void OnContextMenu(wxContextMenuEvent& event)
+ { ShowContextMenu(ScreenToClient(event.GetPosition())); }
+#else
+ void OnRightUp(wxMouseEvent& event)
+ { ShowContextMenu(event.GetPosition()); }
+#endif
+
+ void OnMenuOpen(wxMenuEvent& event)
+ { LogMenuOpenOrClose(event, _T("opened")); }
+ void OnMenuClose(wxMenuEvent& event)
+ { LogMenuOpenOrClose(event, _T("closed")); }
void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event);
void OnSize(wxSizeEvent& event);
private:
+ void LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what);
+ void ShowContextMenu(const wxPoint& pos);
+
wxMenu *CreateDummyMenu(wxString *title);
wxMenuItem *GetLastMenuItem() const;
EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
+#ifdef __WXMSW__
+ EVT_CONTEXT_MENU(MyFrame::OnContextMenu)
+#else
EVT_RIGHT_UP(MyFrame::OnRightUp)
+#endif
+
+ EVT_MENU_OPEN(MyFrame::OnMenuOpen)
+ EVT_MENU_CLOSE(MyFrame::OnMenuClose)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()
// Define my frame constructor
MyFrame::MyFrame()
: wxFrame((wxFrame *)NULL, -1, "wxWindows menu sample",
- wxDefaultPosition, wxSize(300, 200))
+ wxDefaultPosition, wxSize(400, 250))
{
m_textctrl = NULL;
m_menu = NULL;
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE);
m_textctrl->SetEditable(FALSE);
+
+ wxLog::SetTimestamp(NULL);
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl));
- wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu\n")
+ wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ")
_T("append/insert/delete items to/from the last menu.\n")
- _T("The commands from \"Menubar\" menu work with the\n")
- _T("menubar itself.\n")
+ _T("The commands from \"Menubar\" menu work with the ")
+ _T("menubar itself.\n\n")
_T("Right click the band below to test popup menus.\n"));
}
wxMenuBar *mbar = GetMenuBar();
size_t count = mbar->GetMenuCount();
+ wxCHECK_RET( count, _T("no last menu?") );
+
wxLogMessage(wxT("The label of the last menu item is '%s'"),
mbar->GetLabelTop(count - 1).c_str());
}
wxMenuBar *mbar = GetMenuBar();
size_t count = mbar->GetMenuCount();
- mbar->SetLabelTop(count - 1, "Dummy label &0");
+ wxCHECK_RET( count, _T("no last menu?") );
+
+ wxString label = wxGetTextFromUser
+ (
+ _T("Enter new label: "),
+ _T("Change last menu text"),
+ mbar->GetLabelTop(count - 1),
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ mbar->SetLabelTop(count - 1, label);
+ }
}
void MyFrame::OnDummy(wxCommandEvent& event)
if ( item )
{
- item->SetText("Dummy menu item text");
+ wxString label = wxGetTextFromUser
+ (
+ _T("Enter new label: "),
+ _T("Change last menu item text"),
+ item->GetLabel(),
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ item->SetText(label);
+ }
}
}
}
}
-void MyFrame::OnRightUp(wxMouseEvent &event)
+void MyFrame::ShowContextMenu(const wxPoint& pos)
{
wxMenu menu("Test popup");
menu.Check(Menu_Popup_ToBeChecked, TRUE);
menu.Enable(Menu_Popup_ToBeGreyed, FALSE);
- PopupMenu(&menu, event.GetX(), event.GetY());
+ PopupMenu(&menu, pos.x, pos.y);
// test for destroying items in popup menus
#if 0 // doesn't work in wxGTK!
#endif // 0
}
+void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what)
+{
+ wxLogStatus(this, _T("A %smenu has been %s."),
+ event.IsPopup() ? _T("popup ") : _T(""), what);
+}
+
void MyFrame::OnSize(wxSizeEvent& event)
{
if ( !m_textctrl )