1999-11-01 20:25:43 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: samples/menu.cpp
|
|
|
|
// Purpose: wxMenu/wxMenuBar sample
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 01.11.99
|
|
|
|
// Copyright: (c) 1999 Vadim Zeitlin
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
2001-10-30 08:33:34 -05:00
|
|
|
#include "wx/wxprec.h"
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2001-11-20 16:31:04 -05:00
|
|
|
#include "wx/app.h"
|
2014-06-23 16:05:30 -04:00
|
|
|
#include "wx/bitmap.h"
|
2001-11-20 16:31:04 -05:00
|
|
|
#include "wx/frame.h"
|
2014-06-23 16:05:30 -04:00
|
|
|
#include "wx/image.h"
|
2001-11-20 16:31:04 -05:00
|
|
|
#include "wx/menu.h"
|
|
|
|
#include "wx/msgdlg.h"
|
|
|
|
#include "wx/log.h"
|
|
|
|
#include "wx/textctrl.h"
|
2002-02-20 11:41:35 -05:00
|
|
|
#include "wx/textdlg.h"
|
1999-11-01 20:25:43 -05:00
|
|
|
#endif
|
|
|
|
|
2001-05-21 19:58:58 -04:00
|
|
|
#if !wxUSE_MENUS
|
|
|
|
// nice try...
|
|
|
|
#error "menu sample requires wxUSE_MENUS=1"
|
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
2004-04-08 15:15:46 -04:00
|
|
|
// not all ports have support for EVT_CONTEXT_MENU yet, don't define
|
|
|
|
// USE_CONTEXT_MENU for those which don't
|
2014-05-15 19:56:58 -04:00
|
|
|
#if defined(__WXMOTIF__) || defined(__WXX11__)
|
2004-04-13 06:46:17 -04:00
|
|
|
#define USE_CONTEXT_MENU 0
|
|
|
|
#else
|
|
|
|
#define USE_CONTEXT_MENU 1
|
2004-04-08 15:15:46 -04:00
|
|
|
#endif
|
|
|
|
|
2011-04-03 16:31:32 -04:00
|
|
|
// this sample is useful when a new port is developed
|
|
|
|
// and usually a new port has majority of flags turned off
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_LOG && wxUSE_TEXTCTRL
|
|
|
|
#define USE_LOG_WINDOW 1
|
|
|
|
#else
|
|
|
|
#define USE_LOG_WINDOW 0
|
|
|
|
#endif
|
|
|
|
|
2000-09-12 04:17:23 -04:00
|
|
|
#include "copy.xpm"
|
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-07 20:01:00 -05:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2014-03-29 20:02:23 -04:00
|
|
|
bool OnInit() wxOVERRIDE;
|
1999-11-01 20:25:43 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame
|
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame();
|
|
|
|
|
2000-08-08 02:11:51 -04:00
|
|
|
virtual ~MyFrame();
|
|
|
|
|
|
|
|
void LogMenuEvent(const wxCommandEvent& event);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
protected:
|
1999-11-01 20:25:43 -05:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
void OnClearLog(wxCommandEvent& event);
|
2007-01-14 15:45:30 -05:00
|
|
|
void OnClearLogUpdateUI(wxUpdateUIEvent& event);
|
|
|
|
#endif // USE_LOG_WINDOW
|
2013-02-24 08:48:13 -05:00
|
|
|
void OnShowDialog(wxCommandEvent& event);
|
2001-06-26 20:27:24 -04:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnDummy(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnAppendMenuItem(wxCommandEvent& event);
|
|
|
|
void OnAppendSubMenu(wxCommandEvent& event);
|
|
|
|
void OnDeleteMenuItem(wxCommandEvent& event);
|
2010-11-09 19:36:50 -05:00
|
|
|
void OnDeleteSubMenu(wxCommandEvent& event);
|
1999-11-01 20:25:43 -05:00
|
|
|
void OnInsertMenuItem(wxCommandEvent& event);
|
|
|
|
void OnCheckMenuItem(wxCommandEvent& event);
|
|
|
|
void OnEnableMenuItem(wxCommandEvent& event);
|
|
|
|
void OnGetLabelMenuItem(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
void OnSetLabelMenuItem(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-02 11:17:16 -05:00
|
|
|
void OnGetMenuItemInfo(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2002-12-14 16:12:47 -05:00
|
|
|
void OnFindMenuItem(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
void OnAppendMenu(wxCommandEvent& event);
|
1999-12-04 08:43:59 -05:00
|
|
|
void OnInsertMenu(wxCommandEvent& event);
|
1999-11-01 20:25:43 -05:00
|
|
|
void OnDeleteMenu(wxCommandEvent& event);
|
|
|
|
void OnToggleMenu(wxCommandEvent& event);
|
|
|
|
void OnEnableMenu(wxCommandEvent& event);
|
|
|
|
void OnGetLabelMenu(wxCommandEvent& event);
|
|
|
|
void OnSetLabelMenu(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2002-12-14 16:12:47 -05:00
|
|
|
void OnFindMenu(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
void OnTestNormal(wxCommandEvent& event);
|
|
|
|
void OnTestCheck(wxCommandEvent& event);
|
|
|
|
void OnTestRadio(wxCommandEvent& event);
|
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
void OnUpdateSubMenuNormal(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateSubMenuCheck(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateSubMenuRadio(wxUpdateUIEvent& event);
|
|
|
|
|
2004-04-08 15:15:46 -04:00
|
|
|
#if USE_CONTEXT_MENU
|
2005-01-16 10:27:15 -05:00
|
|
|
void OnContextMenu(wxContextMenuEvent& event);
|
2002-02-23 18:16:32 -05:00
|
|
|
#else
|
|
|
|
void OnRightUp(wxMouseEvent& event)
|
|
|
|
{ ShowContextMenu(event.GetPosition()); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void OnMenuOpen(wxMenuEvent& event)
|
2004-05-18 07:52:25 -04:00
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
2013-02-24 08:48:13 -05:00
|
|
|
LogMenuOpenCloseOrHighlight(event, wxT("opened")); event.Skip();
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
|
|
|
}
|
2002-02-23 18:16:32 -05:00
|
|
|
void OnMenuClose(wxMenuEvent& event)
|
2004-05-18 07:52:25 -04:00
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
2013-02-24 08:48:13 -05:00
|
|
|
LogMenuOpenCloseOrHighlight(event, wxT("closed")); event.Skip();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void OnMenuHighlight(wxMenuEvent& event)
|
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
LogMenuOpenCloseOrHighlight(event, wxT("highlighted")); event.Skip();
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
|
|
|
}
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event);
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
private:
|
2013-02-24 08:48:13 -05:00
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
void LogMenuOpenCloseOrHighlight(const wxMenuEvent& event, const wxChar *what);
|
|
|
|
#endif
|
2002-02-23 18:16:32 -05:00
|
|
|
void ShowContextMenu(const wxPoint& pos);
|
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
wxMenu *CreateDummyMenu(wxString *title);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
wxMenuItem *GetLastMenuItem() const;
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
// the menu previously detached from the menubar (may be NULL)
|
|
|
|
wxMenu *m_menu;
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
// the count of dummy menus already created
|
1999-12-04 08:43:59 -05:00
|
|
|
size_t m_countDummy;
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
// the control used for logging
|
|
|
|
wxTextCtrl *m_textctrl;
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
|
|
// the previous log target
|
|
|
|
wxLog *m_logOld;
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
1999-11-01 20:25:43 -05:00
|
|
|
};
|
|
|
|
|
2013-02-24 08:48:13 -05:00
|
|
|
class MyDialog : public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyDialog(wxWindow* parent);
|
|
|
|
|
|
|
|
#if USE_CONTEXT_MENU
|
|
|
|
void OnContextMenu(wxContextMenuEvent& event);
|
|
|
|
#else
|
|
|
|
void OnRightUp(wxMouseEvent& event)
|
|
|
|
{ ShowContextMenu(event.GetPosition()); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void OnMenuOpen(wxMenuEvent& event)
|
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
LogMenuOpenCloseOrHighlight(event, wxT("opened")); event.Skip();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void OnMenuClose(wxMenuEvent& event)
|
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
LogMenuOpenCloseOrHighlight(event, wxT("closed")); event.Skip();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void OnMenuHighlight(wxMenuEvent& event)
|
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
LogMenuOpenCloseOrHighlight(event, wxT("highlighted")); event.Skip();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
void LogMenuOpenCloseOrHighlight(const wxMenuEvent& event, const wxChar *what);
|
|
|
|
#endif
|
|
|
|
void ShowContextMenu(const wxPoint& pos);
|
|
|
|
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
// the control used for logging
|
|
|
|
wxTextCtrl *m_textctrl;
|
|
|
|
#endif
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2013-02-24 08:48:13 -05:00
|
|
|
};
|
|
|
|
|
2000-08-08 02:11:51 -04:00
|
|
|
// 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;
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2000-08-08 02:11:51 -04:00
|
|
|
};
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2004-05-18 07:52:25 -04:00
|
|
|
Menu_File_Quit = wxID_EXIT,
|
|
|
|
#if USE_LOG_WINDOW
|
2007-01-14 15:45:30 -05:00
|
|
|
Menu_File_ClearLog = 100,
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2013-02-24 08:48:13 -05:00
|
|
|
Menu_File_ShowDialog,
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
Menu_MenuBar_Toggle = 200,
|
|
|
|
Menu_MenuBar_Append,
|
1999-12-04 08:43:59 -05:00
|
|
|
Menu_MenuBar_Insert,
|
1999-11-01 20:25:43 -05:00
|
|
|
Menu_MenuBar_Delete,
|
|
|
|
Menu_MenuBar_Enable,
|
|
|
|
Menu_MenuBar_GetLabel,
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
Menu_MenuBar_SetLabel,
|
2002-12-14 16:12:47 -05:00
|
|
|
Menu_MenuBar_FindMenu,
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
Menu_Menu_Append = 300,
|
|
|
|
Menu_Menu_AppendSub,
|
|
|
|
Menu_Menu_Insert,
|
|
|
|
Menu_Menu_Delete,
|
2010-11-09 19:36:50 -05:00
|
|
|
Menu_Menu_DeleteSub,
|
1999-11-01 20:25:43 -05:00
|
|
|
Menu_Menu_Enable,
|
|
|
|
Menu_Menu_Check,
|
|
|
|
Menu_Menu_GetLabel,
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
Menu_Menu_SetLabel,
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-02 11:17:16 -05:00
|
|
|
Menu_Menu_GetInfo,
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2002-12-14 16:12:47 -05:00
|
|
|
Menu_Menu_FindItem,
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
Menu_Test_Normal = 400,
|
|
|
|
Menu_Test_Check,
|
|
|
|
Menu_Test_Radio1,
|
|
|
|
Menu_Test_Radio2,
|
|
|
|
Menu_Test_Radio3,
|
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
Menu_SubMenu = 450,
|
|
|
|
Menu_SubMenu_Normal,
|
|
|
|
Menu_SubMenu_Check,
|
|
|
|
Menu_SubMenu_Radio1,
|
|
|
|
Menu_SubMenu_Radio2,
|
|
|
|
Menu_SubMenu_Radio3,
|
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
Menu_Dummy_First = 500,
|
1999-11-01 20:25:43 -05:00
|
|
|
Menu_Dummy_Second,
|
|
|
|
Menu_Dummy_Third,
|
|
|
|
Menu_Dummy_Fourth,
|
|
|
|
Menu_Dummy_Last,
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
Menu_Help_About = wxID_ABOUT,
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
Menu_Popup_ToBeDeleted = 2000,
|
|
|
|
Menu_Popup_ToBeGreyed,
|
|
|
|
Menu_Popup_ToBeChecked,
|
|
|
|
Menu_Popup_Submenu,
|
|
|
|
|
2007-09-23 19:42:31 -04:00
|
|
|
Menu_PopupChoice,
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
Menu_Max
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2001-06-26 20:27:24 -04:00
|
|
|
EVT_MENU(Menu_File_Quit, MyFrame::OnQuit)
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
EVT_MENU(Menu_File_ClearLog, MyFrame::OnClearLog)
|
2007-01-14 15:45:30 -05:00
|
|
|
EVT_UPDATE_UI(Menu_File_ClearLog, MyFrame::OnClearLogUpdateUI)
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2013-02-24 08:48:13 -05:00
|
|
|
EVT_MENU(Menu_File_ShowDialog, MyFrame::OnShowDialog)
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
EVT_MENU(Menu_Help_About, MyFrame::OnAbout)
|
|
|
|
|
|
|
|
EVT_MENU(Menu_MenuBar_Toggle, MyFrame::OnToggleMenu)
|
|
|
|
EVT_MENU(Menu_MenuBar_Append, MyFrame::OnAppendMenu)
|
1999-12-04 08:43:59 -05:00
|
|
|
EVT_MENU(Menu_MenuBar_Insert, MyFrame::OnInsertMenu)
|
1999-11-01 20:25:43 -05:00
|
|
|
EVT_MENU(Menu_MenuBar_Delete, MyFrame::OnDeleteMenu)
|
|
|
|
EVT_MENU(Menu_MenuBar_Enable, MyFrame::OnEnableMenu)
|
|
|
|
EVT_MENU(Menu_MenuBar_GetLabel, MyFrame::OnGetLabelMenu)
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu)
|
2002-12-14 16:12:47 -05:00
|
|
|
EVT_MENU(Menu_MenuBar_FindMenu, MyFrame::OnFindMenu)
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
EVT_MENU(Menu_Menu_Append, MyFrame::OnAppendMenuItem)
|
|
|
|
EVT_MENU(Menu_Menu_AppendSub, MyFrame::OnAppendSubMenu)
|
|
|
|
EVT_MENU(Menu_Menu_Insert, MyFrame::OnInsertMenuItem)
|
|
|
|
EVT_MENU(Menu_Menu_Delete, MyFrame::OnDeleteMenuItem)
|
2010-11-09 19:36:50 -05:00
|
|
|
EVT_MENU(Menu_Menu_DeleteSub, MyFrame::OnDeleteSubMenu)
|
1999-11-01 20:25:43 -05:00
|
|
|
EVT_MENU(Menu_Menu_Enable, MyFrame::OnEnableMenuItem)
|
1999-11-02 11:17:16 -05:00
|
|
|
EVT_MENU(Menu_Menu_Check, MyFrame::OnCheckMenuItem)
|
1999-11-01 20:25:43 -05:00
|
|
|
EVT_MENU(Menu_Menu_GetLabel, MyFrame::OnGetLabelMenuItem)
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem)
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-02 11:17:16 -05:00
|
|
|
EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo)
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2002-12-14 16:12:47 -05:00
|
|
|
EVT_MENU(Menu_Menu_FindItem, MyFrame::OnFindMenuItem)
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
EVT_MENU(Menu_Test_Normal, MyFrame::OnTestNormal)
|
|
|
|
EVT_MENU(Menu_Test_Check, MyFrame::OnTestCheck)
|
|
|
|
EVT_MENU(Menu_Test_Radio1, MyFrame::OnTestRadio)
|
|
|
|
EVT_MENU(Menu_Test_Radio2, MyFrame::OnTestRadio)
|
|
|
|
EVT_MENU(Menu_Test_Radio3, MyFrame::OnTestRadio)
|
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
EVT_UPDATE_UI(Menu_SubMenu_Normal, MyFrame::OnUpdateSubMenuNormal)
|
|
|
|
EVT_UPDATE_UI(Menu_SubMenu_Check, MyFrame::OnUpdateSubMenuCheck)
|
|
|
|
EVT_UPDATE_UI(Menu_SubMenu_Radio1, MyFrame::OnUpdateSubMenuRadio)
|
|
|
|
EVT_UPDATE_UI(Menu_SubMenu_Radio2, MyFrame::OnUpdateSubMenuRadio)
|
|
|
|
EVT_UPDATE_UI(Menu_SubMenu_Radio3, MyFrame::OnUpdateSubMenuRadio)
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy)
|
|
|
|
|
|
|
|
EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
|
|
|
|
|
2004-04-08 15:15:46 -04:00
|
|
|
#if USE_CONTEXT_MENU
|
2002-02-23 18:16:32 -05:00
|
|
|
EVT_CONTEXT_MENU(MyFrame::OnContextMenu)
|
|
|
|
#else
|
2001-06-26 20:27:24 -04:00
|
|
|
EVT_RIGHT_UP(MyFrame::OnRightUp)
|
2002-02-23 18:16:32 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
EVT_MENU_OPEN(MyFrame::OnMenuOpen)
|
|
|
|
EVT_MENU_CLOSE(MyFrame::OnMenuClose)
|
2013-02-24 08:48:13 -05:00
|
|
|
EVT_MENU_HIGHLIGHT_ALL(MyFrame::OnMenuHighlight)
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
|
|
EVT_SIZE(MyFrame::OnSize)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyDialog, wxDialog)
|
2013-02-24 08:48:13 -05:00
|
|
|
#if USE_CONTEXT_MENU
|
|
|
|
EVT_CONTEXT_MENU(MyDialog::OnContextMenu)
|
|
|
|
#else
|
|
|
|
EVT_RIGHT_UP(MyDialog::OnRightUp)
|
|
|
|
#endif
|
|
|
|
EVT_MENU_OPEN(MyDialog::OnMenuOpen)
|
|
|
|
EVT_MENU_CLOSE(MyDialog::OnMenuClose)
|
|
|
|
EVT_MENU_HIGHLIGHT_ALL(MyDialog::OnMenuHighlight)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2013-02-24 08:48:13 -05:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
|
2004-05-18 07:52:25 -04:00
|
|
|
EVT_MENU(wxID_ANY, MyEvtHandler::OnMenuEvent)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2000-08-08 02:11:51 -04:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// The `main program' equivalent, creating the windows and returning the
|
|
|
|
// main frame
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// Create the main frame window
|
|
|
|
MyFrame* frame = new MyFrame;
|
|
|
|
|
2004-01-08 06:36:38 -05:00
|
|
|
frame->Show(true);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2001-05-21 19:58:58 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2009-07-23 16:30:22 -04:00
|
|
|
frame->SetStatusText(wxT("Welcome to wxWidgets menu sample"));
|
2001-05-21 19:58:58 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2004-01-08 06:36:38 -05:00
|
|
|
return true;
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame()
|
2009-07-23 16:30:22 -04:00
|
|
|
: wxFrame((wxFrame *)NULL, wxID_ANY, wxT("wxWidgets menu sample"))
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
2009-02-07 20:01:00 -05:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-10-09 20:11:23 -04:00
|
|
|
m_textctrl = NULL;
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
m_menu = NULL;
|
1999-12-04 08:43:59 -05:00
|
|
|
m_countDummy = 0;
|
2001-06-26 20:27:24 -04:00
|
|
|
m_logOld = NULL;
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2001-05-21 19:58:58 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2001-06-26 20:27:24 -04:00
|
|
|
CreateStatusBar();
|
2001-05-21 19:58:58 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
// create the menubar
|
|
|
|
wxMenu *fileMenu = new wxMenu;
|
2001-05-21 19:58:58 -04:00
|
|
|
|
2006-08-20 18:24:57 -04:00
|
|
|
wxMenu *stockSubMenu = new wxMenu;
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_ADD);
|
|
|
|
stockSubMenu->Append(wxID_APPLY);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_BACKWARD);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_BOLD);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_BOTTOM);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_CANCEL);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_CDROM);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_CLEAR);
|
|
|
|
stockSubMenu->Append(wxID_CLOSE);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_CONVERT);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_COPY);
|
|
|
|
stockSubMenu->Append(wxID_CUT);
|
|
|
|
stockSubMenu->Append(wxID_DELETE);
|
|
|
|
stockSubMenu->Append(wxID_DOWN);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_EXECUTE);
|
|
|
|
stockSubMenu->Append(wxID_EXIT);
|
|
|
|
stockSubMenu->Append(wxID_FIND);
|
|
|
|
stockSubMenu->Append(wxID_FIRST);
|
|
|
|
stockSubMenu->Append(wxID_FLOPPY);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_FORWARD);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_HARDDISK);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_HELP);
|
|
|
|
stockSubMenu->Append(wxID_HOME);
|
|
|
|
stockSubMenu->Append(wxID_INDENT);
|
|
|
|
stockSubMenu->Append(wxID_INDEX);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_INFO);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_ITALIC);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_JUMP_TO);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_JUSTIFY_CENTER);
|
|
|
|
stockSubMenu->Append(wxID_JUSTIFY_FILL);
|
|
|
|
stockSubMenu->Append(wxID_JUSTIFY_LEFT);
|
|
|
|
stockSubMenu->Append(wxID_JUSTIFY_RIGHT);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_LAST);
|
|
|
|
stockSubMenu->Append(wxID_NETWORK);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_NEW);
|
|
|
|
stockSubMenu->Append(wxID_NO);
|
|
|
|
stockSubMenu->Append(wxID_OK);
|
|
|
|
stockSubMenu->Append(wxID_OPEN);
|
|
|
|
stockSubMenu->Append(wxID_PASTE);
|
|
|
|
stockSubMenu->Append(wxID_PREFERENCES);
|
|
|
|
stockSubMenu->Append(wxID_PREVIEW);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_PRINT);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_PROPERTIES);
|
|
|
|
stockSubMenu->Append(wxID_REDO);
|
|
|
|
stockSubMenu->Append(wxID_REFRESH);
|
|
|
|
stockSubMenu->Append(wxID_REMOVE);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_REPLACE);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_REVERT_TO_SAVED);
|
|
|
|
stockSubMenu->Append(wxID_SAVE);
|
|
|
|
stockSubMenu->Append(wxID_SAVEAS);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_SELECT_COLOR);
|
|
|
|
stockSubMenu->Append(wxID_SELECT_FONT);
|
|
|
|
stockSubMenu->Append(wxID_SORT_ASCENDING);
|
|
|
|
stockSubMenu->Append(wxID_SORT_DESCENDING);
|
|
|
|
stockSubMenu->Append(wxID_SPELL_CHECK);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_STOP);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_STRIKETHROUGH);
|
|
|
|
stockSubMenu->Append(wxID_TOP);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_UNDELETE);
|
|
|
|
stockSubMenu->Append(wxID_UNDERLINE);
|
|
|
|
stockSubMenu->Append(wxID_UNDO);
|
|
|
|
stockSubMenu->Append(wxID_UNINDENT);
|
2008-08-01 10:38:02 -04:00
|
|
|
stockSubMenu->Append(wxID_UP);
|
2006-09-03 08:23:04 -04:00
|
|
|
stockSubMenu->Append(wxID_YES);
|
|
|
|
stockSubMenu->Append(wxID_ZOOM_100);
|
|
|
|
stockSubMenu->Append(wxID_ZOOM_FIT);
|
|
|
|
stockSubMenu->Append(wxID_ZOOM_IN);
|
|
|
|
stockSubMenu->Append(wxID_ZOOM_OUT);
|
2009-07-23 16:30:22 -04:00
|
|
|
fileMenu->AppendSubMenu(stockSubMenu, wxT("&Standard items demo"));
|
2006-08-20 18:24:57 -04:00
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog,
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Clear &log\tCtrl-L"));
|
2001-06-26 20:27:24 -04:00
|
|
|
item->SetBitmap(copy_xpm);
|
|
|
|
fileMenu->Append(item);
|
|
|
|
fileMenu->AppendSeparator();
|
2006-08-20 18:24:57 -04:00
|
|
|
#endif // USE_LOG_WINDOW
|
|
|
|
|
2013-02-24 08:48:13 -05:00
|
|
|
fileMenu->Append(Menu_File_ShowDialog, wxT("Show &Dialog\tCtrl-D"),
|
|
|
|
wxT("Show a dialog"));
|
|
|
|
fileMenu->AppendSeparator();
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
fileMenu->Append(Menu_File_Quit, wxT("E&xit\tAlt-X"), wxT("Quit menu sample"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
wxMenu *menubarMenu = new wxMenu;
|
2009-07-23 16:30:22 -04:00
|
|
|
menubarMenu->Append(Menu_MenuBar_Append, wxT("&Append menu\tCtrl-A"),
|
|
|
|
wxT("Append a menu to the menubar"));
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Insert, wxT("&Insert menu\tCtrl-I"),
|
|
|
|
wxT("Insert a menu into the menubar"));
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Delete, wxT("&Delete menu\tCtrl-D"),
|
|
|
|
wxT("Delete the last menu from the menubar"));
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Toggle, wxT("&Toggle menu\tCtrl-T"),
|
|
|
|
wxT("Toggle the first menu in the menubar"), true);
|
1999-11-01 20:25:43 -05:00
|
|
|
menubarMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menubarMenu->Append(Menu_MenuBar_Enable, wxT("&Enable menu\tCtrl-E"),
|
|
|
|
wxT("Enable or disable the last menu"), true);
|
1999-11-01 20:25:43 -05:00
|
|
|
menubarMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menubarMenu->Append(Menu_MenuBar_GetLabel, wxT("&Get menu label\tCtrl-G"),
|
|
|
|
wxT("Get the label of the last menu"));
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2009-07-23 16:30:22 -04:00
|
|
|
menubarMenu->Append(Menu_MenuBar_SetLabel, wxT("&Set menu label\tCtrl-S"),
|
|
|
|
wxT("Change the label of the last menu"));
|
2002-12-14 16:12:47 -05:00
|
|
|
menubarMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menubarMenu->Append(Menu_MenuBar_FindMenu, wxT("&Find menu from label\tCtrl-F"),
|
|
|
|
wxT("Find a menu by searching for its label"));
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
wxMenu* subMenu = new wxMenu;
|
2009-07-23 16:30:22 -04:00
|
|
|
subMenu->Append(Menu_SubMenu_Normal, wxT("&Normal submenu item"), wxT("Disabled submenu item"));
|
|
|
|
subMenu->AppendCheckItem(Menu_SubMenu_Check, wxT("&Check submenu item"), wxT("Check submenu item"));
|
|
|
|
subMenu->AppendRadioItem(Menu_SubMenu_Radio1, wxT("Radio item &1"), wxT("Radio item"));
|
|
|
|
subMenu->AppendRadioItem(Menu_SubMenu_Radio2, wxT("Radio item &2"), wxT("Radio item"));
|
|
|
|
subMenu->AppendRadioItem(Menu_SubMenu_Radio3, wxT("Radio item &3"), wxT("Radio item"));
|
2003-06-01 16:35:12 -04:00
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
menubarMenu->Append(Menu_SubMenu, wxT("Submenu"), subMenu);
|
2003-06-01 16:35:12 -04:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
wxMenu *menuMenu = new wxMenu;
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_Append, wxT("&Append menu item\tAlt-A"),
|
2010-11-13 10:02:50 -05:00
|
|
|
wxT("Append a menu item to the 'Test' menu"));
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_AppendSub, wxT("&Append sub menu\tAlt-S"),
|
2010-11-13 10:02:50 -05:00
|
|
|
wxT("Append a sub menu to the 'Test' menu"));
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_Insert, wxT("&Insert menu item\tAlt-I"),
|
2010-11-13 10:02:50 -05:00
|
|
|
wxT("Insert a menu item in head of the 'Test' menu"));
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_Delete, wxT("&Delete menu item\tAlt-D"),
|
2010-11-13 10:02:50 -05:00
|
|
|
wxT("Delete the last menu item from the 'Test' menu"));
|
2010-11-09 19:36:50 -05:00
|
|
|
menuMenu->Append(Menu_Menu_DeleteSub, wxT("Delete last &submenu\tAlt-K"),
|
2010-11-13 10:02:50 -05:00
|
|
|
wxT("Delete the last submenu from the 'Test' menu"));
|
1999-11-01 20:25:43 -05:00
|
|
|
menuMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_Enable, wxT("&Enable menu item\tAlt-E"),
|
|
|
|
wxT("Enable or disable the last menu item"), true);
|
|
|
|
menuMenu->Append(Menu_Menu_Check, wxT("&Check menu item\tAlt-C"),
|
|
|
|
wxT("Check or uncheck the last menu item"), true);
|
1999-11-01 20:25:43 -05:00
|
|
|
menuMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_GetInfo, wxT("Get menu item in&fo\tAlt-F"),
|
|
|
|
wxT("Show the state of the last menu item"));
|
2005-06-10 13:53:19 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_SetLabel, wxT("Set menu item label\tAlt-L"),
|
|
|
|
wxT("Set the label of a menu item"));
|
2005-06-10 13:53:19 -04:00
|
|
|
#endif
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-02 11:17:16 -05:00
|
|
|
menuMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menuMenu->Append(Menu_Menu_FindItem, wxT("Find menu item from label"),
|
|
|
|
wxT("Find a menu item by searching for its label"));
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
wxMenu *testMenu = new wxMenu;
|
2009-07-23 16:30:22 -04:00
|
|
|
testMenu->Append(Menu_Test_Normal, wxT("&Normal item"));
|
2002-03-18 14:41:35 -05:00
|
|
|
testMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
testMenu->AppendCheckItem(Menu_Test_Check, wxT("&Check item"));
|
2014-06-23 16:05:30 -04:00
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
#if wxUSE_IMAGE
|
|
|
|
wxBitmap bmpUnchecked(8, 8);
|
|
|
|
|
|
|
|
wxImage imageChecked(8, 8);
|
|
|
|
imageChecked.Clear(0xff);
|
|
|
|
wxBitmap bmpChecked(imageChecked);
|
|
|
|
|
|
|
|
wxMenuItem *checkedBitmapItem = new wxMenuItem(testMenu, wxID_ANY,
|
|
|
|
"Check item with bitmaps", "", wxITEM_CHECK);
|
|
|
|
checkedBitmapItem->SetBitmaps(bmpChecked, bmpUnchecked);
|
|
|
|
testMenu->Append(checkedBitmapItem);
|
|
|
|
|
|
|
|
checkedBitmapItem = new wxMenuItem(testMenu, wxID_ANY,
|
|
|
|
"Check item with bitmaps set afterwards", "", wxITEM_CHECK);
|
|
|
|
testMenu->Append(checkedBitmapItem);
|
|
|
|
checkedBitmapItem->SetBitmaps(bmpChecked, bmpUnchecked);
|
|
|
|
|
|
|
|
checkedBitmapItem = new wxMenuItem(testMenu, wxID_ANY,
|
|
|
|
"Check item with bitmaps set afterwards (initially checked)", "", wxITEM_CHECK);
|
|
|
|
testMenu->Append(checkedBitmapItem);
|
|
|
|
checkedBitmapItem->Check();
|
|
|
|
checkedBitmapItem->SetBitmaps(bmpChecked, bmpUnchecked);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
testMenu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
testMenu->AppendRadioItem(Menu_Test_Radio1, wxT("Radio item &1"));
|
|
|
|
testMenu->AppendRadioItem(Menu_Test_Radio2, wxT("Radio item &2"));
|
|
|
|
testMenu->AppendRadioItem(Menu_Test_Radio3, wxT("Radio item &3"));
|
2002-03-18 14:41:35 -05:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
wxMenu *helpMenu = new wxMenu;
|
2009-07-23 16:30:22 -04:00
|
|
|
helpMenu->Append(Menu_Help_About, wxT("&About\tF1"), wxT("About menu sample"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
menuBar->Append(fileMenu, wxT("&File"));
|
|
|
|
menuBar->Append(menubarMenu, wxT("Menu&bar"));
|
|
|
|
menuBar->Append(menuMenu, wxT("&Menu"));
|
|
|
|
menuBar->Append(testMenu, wxT("&Test"));
|
|
|
|
menuBar->Append(helpMenu, wxT("&Help"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
// these items should be initially checked
|
2004-01-08 06:36:38 -05:00
|
|
|
menuBar->Check(Menu_MenuBar_Toggle, true);
|
|
|
|
menuBar->Check(Menu_MenuBar_Enable, true);
|
|
|
|
menuBar->Check(Menu_Menu_Enable, true);
|
|
|
|
menuBar->Check(Menu_Menu_Check, false);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
// associate the menu bar with the frame
|
|
|
|
SetMenuBar(menuBar);
|
2000-08-08 02:11:51 -04:00
|
|
|
|
|
|
|
// intercept all menu events and log them in this custom event handler
|
|
|
|
PushEventHandler(new MyEvtHandler(this));
|
2001-06-26 20:27:24 -04:00
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
// create the log text window
|
2005-06-10 13:53:19 -04:00
|
|
|
m_textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
|
2001-06-26 20:27:24 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE);
|
2004-01-08 06:36:38 -05:00
|
|
|
m_textctrl->SetEditable(false);
|
2002-02-20 11:41:35 -05:00
|
|
|
|
2007-06-27 15:25:58 -04:00
|
|
|
wxLog::DisableTimestamp();
|
2001-06-26 20:27:24 -04:00
|
|
|
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl));
|
|
|
|
|
2010-11-09 19:36:50 -05:00
|
|
|
wxLogMessage(wxT("Brief explanations: the commands in the \"Menu\" menu ")
|
2010-11-13 10:02:50 -05:00
|
|
|
wxT("append/insert/delete items to/from the \"Test\" menu.\n")
|
2010-11-09 19:36:50 -05:00
|
|
|
wxT("The commands in the \"Menubar\" menu work with the ")
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("menubar itself.\n\n")
|
|
|
|
wxT("Right click the band below to test popup menus.\n"));
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2006-02-28 09:18:45 -05:00
|
|
|
#ifdef __POCKETPC__
|
|
|
|
EnableContextMenu();
|
|
|
|
#endif
|
2000-08-08 02:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
delete m_menu;
|
|
|
|
|
|
|
|
// delete the event handler installed in ctor
|
2004-01-08 06:36:38 -05:00
|
|
|
PopEventHandler(true);
|
2001-06-26 20:27:24 -04:00
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
// restore old logger
|
|
|
|
delete wxLog::SetActiveTarget(m_logOld);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
wxMenu *MyFrame::CreateDummyMenu(wxString *title)
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
2009-07-23 16:30:22 -04:00
|
|
|
menu->Append(Menu_Dummy_First, wxT("&First item\tCtrl-F1"));
|
1999-11-01 20:25:43 -05:00
|
|
|
menu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menu->AppendCheckItem(Menu_Dummy_Second, wxT("&Second item\tCtrl-F2"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
if ( title )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
title->Printf(wxT("Dummy menu &%u"), (unsigned)++m_countDummy);
|
1999-12-04 08:43:59 -05:00
|
|
|
}
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenuItem *MyFrame::GetLastMenuItem() const
|
|
|
|
{
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2010-11-13 10:02:50 -05:00
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->FindMenu("Test"));
|
|
|
|
wxCHECK_MSG( menu, NULL, wxT("no 'Test' menu?") );
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2003-07-10 17:12:25 -04:00
|
|
|
wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetLast();
|
1999-11-01 20:25:43 -05:00
|
|
|
if ( !node )
|
|
|
|
{
|
2010-11-13 10:02:50 -05:00
|
|
|
wxLogWarning(wxT("No last item in the 'Test' menu!"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return node->GetData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-08 02:11:51 -04:00
|
|
|
void MyFrame::LogMenuEvent(const wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int id = event.GetId();
|
2001-06-26 20:27:24 -04:00
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxString msg = wxString::Format(wxT("Menu command %d"), id);
|
2005-08-28 09:17:29 -04:00
|
|
|
|
|
|
|
// catch all checkable menubar items and also the check item from the popup
|
|
|
|
// menu
|
|
|
|
wxMenuItem *item = GetMenuBar()->FindItem(id);
|
|
|
|
if ( (item && item->IsCheckable()) || id == Menu_Popup_ToBeChecked )
|
2000-08-08 02:11:51 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
msg += wxString::Format(wxT(" (the item is currently %schecked)"),
|
|
|
|
event.IsChecked() ? wxT("") : wxT("not "));
|
2000-08-08 02:11:51 -04:00
|
|
|
}
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
wxLogMessage(msg);
|
2000-08-08 02:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// menu callbacks
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
Close(true);
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2007-01-14 15:45:30 -05:00
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_textctrl->Clear();
|
|
|
|
}
|
2007-01-14 15:45:30 -05:00
|
|
|
|
|
|
|
void MyFrame::OnClearLogUpdateUI(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
// if we only enable this item when the log window is empty, we never see
|
|
|
|
// it in the disable state as a message is logged whenever the menu is
|
|
|
|
// opened, so we disable it if there is not "much" text in the window
|
|
|
|
event.Enable( m_textctrl->GetNumberOfLines() > 5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
|
2013-02-24 08:48:13 -05:00
|
|
|
void MyFrame::OnShowDialog(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
MyDialog dlg(this);
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
(void)wxMessageBox(wxT("wxWidgets menu sample\n(c) 1999-2001 Vadim Zeitlin"),
|
|
|
|
wxT("About wxWidgets menu sample"),
|
2009-03-25 12:29:23 -04:00
|
|
|
wxOK | wxICON_INFORMATION);
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
|
|
|
|
size_t count = mbar->GetMenuCount();
|
2010-11-13 10:02:50 -05:00
|
|
|
if ( count == 4 )
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
2010-11-13 10:02:50 -05:00
|
|
|
// don't let delete the first 4 menus
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogError(wxT("Can't delete any more menus"));
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete mbar->Remove(count - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
void MyFrame::OnInsertMenu(wxCommandEvent& WXUNUSED(event))
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
|
|
|
wxString title;
|
1999-12-04 08:43:59 -05:00
|
|
|
wxMenu *menu = CreateDummyMenu(&title);
|
2010-11-13 10:02:50 -05:00
|
|
|
// Insert before the 'Help' menu
|
2011-03-22 10:17:38 -04:00
|
|
|
// Otherwise repeated Deletes will remove the 'Test' menu
|
2010-11-13 10:02:50 -05:00
|
|
|
GetMenuBar()->Insert(4, menu, title);
|
1999-12-04 08:43:59 -05:00
|
|
|
}
|
1999-11-01 20:25:43 -05:00
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString title;
|
|
|
|
wxMenu *menu = CreateDummyMenu(&title);
|
|
|
|
GetMenuBar()->Append(menu, title);
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnToggleMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
if ( !m_menu )
|
|
|
|
{
|
|
|
|
// hide the menu
|
|
|
|
m_menu = mbar->Remove(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// restore it
|
2009-07-23 16:30:22 -04:00
|
|
|
mbar->Insert(0, m_menu, wxT("&File"));
|
1999-11-01 20:25:43 -05:00
|
|
|
m_menu = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
void MyFrame::OnEnableMenu(wxCommandEvent& event)
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
mbar->EnableTop(count - 1, event.IsChecked());
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnGetLabelMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxCHECK_RET( count, wxT("no last menu?") );
|
2002-02-20 11:41:35 -05:00
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("The label of the last menu item is '%s'"),
|
2007-08-11 13:54:59 -04:00
|
|
|
mbar->GetMenuLabel(count - 1).c_str());
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxCHECK_RET( count, wxT("no last menu?") );
|
2002-02-20 11:41:35 -05:00
|
|
|
|
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
(
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Enter new label: "),
|
|
|
|
wxT("Change last menu text"),
|
2007-08-11 13:54:59 -04:00
|
|
|
mbar->GetMenuLabel(count - 1),
|
2002-02-20 11:41:35 -05:00
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
{
|
2007-08-11 13:54:59 -04:00
|
|
|
mbar->SetMenuLabel(count - 1, label);
|
2002-02-20 11:41:35 -05:00
|
|
|
}
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
2002-12-14 16:12:47 -05:00
|
|
|
void MyFrame::OnFindMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxCHECK_RET( count, wxT("no last menu?") );
|
2002-12-14 16:12:47 -05:00
|
|
|
|
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
(
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Enter label to search for: "),
|
|
|
|
wxT("Find menu"),
|
2005-06-10 13:53:19 -04:00
|
|
|
wxEmptyString,
|
2002-12-14 16:12:47 -05:00
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
{
|
|
|
|
int index = mbar->FindMenu(label);
|
|
|
|
|
|
|
|
if (index == wxNOT_FOUND)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogWarning(wxT("No menu with label '%s'"), label.c_str());
|
2002-12-14 16:12:47 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Menu %d has label '%s'"), index, label.c_str());
|
2002-12-14 16:12:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2002-12-14 16:12:47 -05:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnDummy(wxCommandEvent& event)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Dummy item #%d"), event.GetId() - Menu_Dummy_First + 1);
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAppendMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2010-11-13 10:02:50 -05:00
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->FindMenu("Test"));
|
|
|
|
wxCHECK_RET( menu, wxT("no 'Test' menu?") );
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
menu->AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menu->Append(Menu_Dummy_Third, wxT("&Third dummy item\tCtrl-F3"),
|
|
|
|
wxT("Checkable item"), true);
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2010-11-13 10:02:50 -05:00
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->FindMenu("Test"));
|
|
|
|
wxCHECK_RET( menu, wxT("no 'Test' menu?") );
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
menu->Append(Menu_Dummy_Last, wxT("&Dummy sub menu"),
|
|
|
|
CreateDummyMenu(NULL), wxT("Dummy sub menu help"));
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDeleteMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2010-11-13 10:02:50 -05:00
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->FindMenu("Test"));
|
|
|
|
wxCHECK_RET( menu, wxT("no 'Test' menu?") );
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
size_t count = menu->GetMenuItemCount();
|
|
|
|
if ( !count )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogWarning(wxT("No items to delete!"));
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menu->Destroy(menu->GetMenuItems().Item(count - 1)->GetData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 19:36:50 -05:00
|
|
|
void MyFrame::OnDeleteSubMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2010-11-13 10:02:50 -05:00
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->FindMenu("Test"));
|
|
|
|
wxCHECK_RET( menu, wxT("no 'Test' menu?") );
|
2010-11-09 19:36:50 -05:00
|
|
|
|
|
|
|
for ( int n = menu->GetMenuItemCount() - 1; n >=0 ; --n )
|
|
|
|
{
|
|
|
|
wxMenuItem* item = menu->FindItemByPosition(n);
|
|
|
|
if (item->IsSubMenu())
|
|
|
|
{
|
|
|
|
menu->Destroy(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogWarning(wxT("No submenu to delete!"));
|
|
|
|
}
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnInsertMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2010-11-13 10:02:50 -05:00
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->FindMenu("Test"));
|
|
|
|
wxCHECK_RET( menu, wxT("no 'Test' menu?") );
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
menu->Insert(0, wxMenuItem::New(menu, Menu_Dummy_Fourth,
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Fourth dummy item\tCtrl-F4")));
|
2005-06-10 13:53:19 -04:00
|
|
|
menu->Insert(1, wxMenuItem::New(menu, wxID_SEPARATOR));
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnEnableMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuItem *item = GetLastMenuItem();
|
|
|
|
|
|
|
|
if ( item )
|
|
|
|
{
|
|
|
|
item->Enable(!item->IsEnabled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnCheckMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuItem *item = GetLastMenuItem();
|
|
|
|
|
2010-11-13 10:02:50 -05:00
|
|
|
if (item && item->IsCheckable())
|
|
|
|
{
|
1999-11-01 20:25:43 -05:00
|
|
|
item->Toggle();
|
|
|
|
}
|
2010-11-13 10:02:50 -05:00
|
|
|
}
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
void MyFrame::OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event)
|
|
|
|
{
|
1999-12-04 09:10:31 -05:00
|
|
|
wxLogNull nolog;
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
wxMenuItem *item = GetLastMenuItem();
|
|
|
|
|
|
|
|
event.Enable(item && item->IsCheckable());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnGetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuItem *item = GetLastMenuItem();
|
|
|
|
|
|
|
|
if ( item )
|
|
|
|
{
|
2007-08-11 14:39:49 -04:00
|
|
|
wxString label = item->GetItemLabel();
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("The label of the last menu item is '%s'"),
|
2007-08-11 14:39:49 -04:00
|
|
|
label.c_str());
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnSetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuItem *item = GetLastMenuItem();
|
|
|
|
|
|
|
|
if ( item )
|
|
|
|
{
|
2002-02-20 11:41:35 -05:00
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
(
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Enter new label: "),
|
|
|
|
wxT("Change last menu item text"),
|
2007-08-11 13:54:59 -04:00
|
|
|
item->GetItemLabel(),
|
2002-02-20 11:41:35 -05:00
|
|
|
this
|
|
|
|
);
|
2009-07-23 16:30:22 -04:00
|
|
|
label.Replace( wxT("\\t"), wxT("\t") );
|
2002-02-20 11:41:35 -05:00
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
{
|
2007-08-11 13:54:59 -04:00
|
|
|
item->SetItemLabel(label);
|
2002-02-20 11:41:35 -05:00
|
|
|
}
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
|
|
|
}
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
1999-11-01 20:25:43 -05:00
|
|
|
|
1999-11-02 11:17:16 -05:00
|
|
|
void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuItem *item = GetLastMenuItem();
|
|
|
|
|
|
|
|
if ( item )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("The item is ") << (item->IsEnabled() ? wxT("enabled")
|
|
|
|
: wxT("disabled"))
|
|
|
|
<< wxT('\n');
|
2000-07-15 15:51:35 -04:00
|
|
|
|
1999-11-02 11:17:16 -05:00
|
|
|
if ( item->IsCheckable() )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("It is checkable and ") << (item->IsChecked() ? wxT("") : wxT("un"))
|
|
|
|
<< wxT("checked\n");
|
1999-11-02 11:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
wxAcceleratorEntry *accel = item->GetAccel();
|
|
|
|
if ( accel )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("Its accelerator is ");
|
1999-11-02 11:17:16 -05:00
|
|
|
|
|
|
|
int flags = accel->GetFlags();
|
|
|
|
if ( flags & wxACCEL_ALT )
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("Alt-");
|
1999-11-02 11:17:16 -05:00
|
|
|
if ( flags & wxACCEL_CTRL )
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("Ctrl-");
|
1999-11-02 11:17:16 -05:00
|
|
|
if ( flags & wxACCEL_SHIFT )
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("Shift-");
|
1999-11-02 11:17:16 -05:00
|
|
|
|
|
|
|
int code = accel->GetKeyCode();
|
|
|
|
switch ( code )
|
|
|
|
{
|
|
|
|
case WXK_F1:
|
|
|
|
case WXK_F2:
|
|
|
|
case WXK_F3:
|
|
|
|
case WXK_F4:
|
|
|
|
case WXK_F5:
|
|
|
|
case WXK_F6:
|
|
|
|
case WXK_F7:
|
|
|
|
case WXK_F8:
|
|
|
|
case WXK_F9:
|
|
|
|
case WXK_F10:
|
|
|
|
case WXK_F11:
|
|
|
|
case WXK_F12:
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT('F') << code - WXK_F1 + 1;
|
1999-11-02 11:17:16 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
// if there are any other keys wxGetAccelFromString() may return,
|
|
|
|
// we should process them here
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ( wxIsalnum(code) )
|
|
|
|
{
|
|
|
|
msg << (wxChar)code;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxFAIL_MSG( wxT("unknown keyboard accel") );
|
1999-11-02 11:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
delete accel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("It doesn't have an accelerator");
|
1999-11-02 11:17:16 -05:00
|
|
|
}
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
wxLogMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2002-12-14 16:12:47 -05:00
|
|
|
void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxCHECK_RET( count, wxT("no last menu?") );
|
2002-12-14 16:12:47 -05:00
|
|
|
|
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
(
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Enter label to search for: "),
|
|
|
|
wxT("Find menu item"),
|
2005-06-10 13:53:19 -04:00
|
|
|
wxEmptyString,
|
2002-12-14 16:12:47 -05:00
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
size_t menuindex;
|
2002-12-14 16:12:47 -05:00
|
|
|
int index = wxNOT_FOUND;
|
2004-04-08 15:15:46 -04:00
|
|
|
|
2002-12-14 16:12:47 -05:00
|
|
|
for (menuindex = 0; (menuindex < count) && (index == wxNOT_FOUND); ++menuindex)
|
|
|
|
{
|
|
|
|
index = mbar->FindMenuItem(mbar->GetMenu(menuindex)->GetTitle(), label);
|
|
|
|
}
|
|
|
|
if (index == wxNOT_FOUND)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogWarning(wxT("No menu item with label '%s'"), label.c_str());
|
2002-12-14 16:12:47 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Menu item %d in menu %lu has label '%s'"),
|
2003-04-08 07:28:57 -04:00
|
|
|
index, (unsigned long)menuindex, label.c_str());
|
2002-12-14 16:12:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2002-12-14 16:12:47 -05:00
|
|
|
|
2002-02-23 18:16:32 -05:00
|
|
|
void MyFrame::ShowContextMenu(const wxPoint& pos)
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
2006-02-28 08:26:55 -05:00
|
|
|
wxMenu menu;
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2007-09-23 19:42:31 -04:00
|
|
|
if ( wxGetKeyState(WXK_SHIFT) )
|
|
|
|
{
|
|
|
|
// when Shift is pressed, demonstrate the use of a simple function
|
|
|
|
// returning the id of the item selected in the popup menu
|
|
|
|
menu.SetTitle("Choose one of:");
|
|
|
|
static const char *choices[] = { "Apple", "Banana", "Cherry" };
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(choices); n++ )
|
|
|
|
menu.Append(Menu_PopupChoice + n, choices[n]);
|
|
|
|
|
|
|
|
const int rc = GetPopupMenuSelectionFromUser(menu, pos);
|
|
|
|
if ( rc == wxID_NONE )
|
|
|
|
{
|
|
|
|
wxLogMessage("No selection");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogMessage("You have selected \"%s\"",
|
|
|
|
choices[rc - Menu_PopupChoice]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // normal case, shift not pressed
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
menu.Append(Menu_Help_About, wxT("&About"));
|
|
|
|
menu.Append(Menu_Popup_Submenu, wxT("&Submenu"), CreateDummyMenu(NULL));
|
|
|
|
menu.Append(Menu_Popup_ToBeDeleted, wxT("To be &deleted"));
|
|
|
|
menu.AppendCheckItem(Menu_Popup_ToBeChecked, wxT("To be &checked"));
|
|
|
|
menu.Append(Menu_Popup_ToBeGreyed, wxT("To be &greyed"),
|
|
|
|
wxT("This menu item should be initially greyed out"));
|
2007-09-23 19:42:31 -04:00
|
|
|
menu.AppendSeparator();
|
2009-07-23 16:30:22 -04:00
|
|
|
menu.Append(Menu_File_Quit, wxT("E&xit"));
|
2007-09-23 19:42:31 -04:00
|
|
|
|
|
|
|
menu.Delete(Menu_Popup_ToBeDeleted);
|
|
|
|
menu.Check(Menu_Popup_ToBeChecked, true);
|
|
|
|
menu.Enable(Menu_Popup_ToBeGreyed, false);
|
|
|
|
|
|
|
|
PopupMenu(&menu, pos);
|
|
|
|
|
|
|
|
// test for destroying items in popup menus
|
2001-06-26 20:27:24 -04:00
|
|
|
#if 0 // doesn't work in wxGTK!
|
2007-09-23 19:42:31 -04:00
|
|
|
menu.Destroy(Menu_Popup_Submenu);
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2007-09-23 19:42:31 -04:00
|
|
|
PopupMenu( &menu, event.GetX(), event.GetY() );
|
2000-07-15 15:51:35 -04:00
|
|
|
#endif // 0
|
2007-09-23 19:42:31 -04:00
|
|
|
}
|
1999-11-01 20:25:43 -05:00
|
|
|
}
|
2001-06-26 20:27:24 -04:00
|
|
|
|
2003-09-11 08:52:20 -04:00
|
|
|
void MyFrame::OnTestNormal(wxCommandEvent& WXUNUSED(event))
|
2002-03-18 14:41:35 -05:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Normal item selected"));
|
2002-03-18 14:41:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnTestCheck(wxCommandEvent& event)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Check item %schecked"),
|
|
|
|
event.IsChecked() ? wxT("") : wxT("un"));
|
2002-03-18 14:41:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnTestRadio(wxCommandEvent& event)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Radio item %d selected"),
|
2002-03-18 14:41:35 -05:00
|
|
|
event.GetId() - Menu_Test_Radio1 + 1);
|
|
|
|
}
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2013-02-24 08:48:13 -05:00
|
|
|
void MyFrame::LogMenuOpenCloseOrHighlight(const wxMenuEvent& event, const wxChar *what)
|
2002-02-23 18:16:32 -05:00
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxString msg;
|
2009-07-23 16:30:22 -04:00
|
|
|
msg << wxT("A ")
|
|
|
|
<< ( event.IsPopup() ? wxT("popup ") : wxT("") )
|
|
|
|
<< wxT("menu has been ")
|
2013-02-24 08:48:13 -05:00
|
|
|
<< what;
|
|
|
|
|
|
|
|
if ( event.GetEventType() == wxEVT_MENU_HIGHLIGHT )
|
|
|
|
{
|
|
|
|
msg << wxT(" (id=") << event.GetId() << wxT(")");
|
|
|
|
}
|
2014-11-10 20:02:27 -05:00
|
|
|
else // wxEVT_MENU_{OPEN,CLOSE}
|
|
|
|
{
|
|
|
|
wxMenu* const menu = event.GetMenu();
|
|
|
|
if ( menu )
|
|
|
|
{
|
|
|
|
msg << " (menu with title \"" << menu->GetTitle() << "\")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg << " (no menu)";
|
|
|
|
}
|
|
|
|
}
|
2013-02-24 08:48:13 -05:00
|
|
|
|
|
|
|
msg << wxT(".");
|
2004-04-08 15:15:46 -04:00
|
|
|
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogStatus(this, msg.c_str());
|
2002-02-23 18:16:32 -05:00
|
|
|
}
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2002-02-23 18:16:32 -05:00
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
void MyFrame::OnUpdateSubMenuNormal(wxUpdateUIEvent& event)
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
event.Enable(false);
|
2003-06-01 16:35:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateSubMenuCheck(wxUpdateUIEvent& event)
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
event.Enable(true);
|
2003-06-01 16:35:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateSubMenuRadio(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
int which = (event.GetId() - Menu_SubMenu_Radio1 + 1);
|
|
|
|
if (which == 2)
|
2004-01-08 06:36:38 -05:00
|
|
|
event.Check(true);
|
2003-06-01 16:35:12 -04:00
|
|
|
else
|
2004-01-08 06:36:38 -05:00
|
|
|
event.Check(false);
|
2003-06-01 16:35:12 -04:00
|
|
|
}
|
|
|
|
|
2005-01-16 10:27:15 -05:00
|
|
|
#if USE_CONTEXT_MENU
|
|
|
|
void MyFrame::OnContextMenu(wxContextMenuEvent& event)
|
|
|
|
{
|
|
|
|
wxPoint point = event.GetPosition();
|
|
|
|
// If from keyboard
|
|
|
|
if (point.x == -1 && point.y == -1) {
|
|
|
|
wxSize size = GetSize();
|
|
|
|
point.x = size.x / 2;
|
|
|
|
point.y = size.y / 2;
|
|
|
|
} else {
|
|
|
|
point = ScreenToClient(point);
|
|
|
|
}
|
|
|
|
ShowContextMenu(point);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-09-11 08:52:20 -04:00
|
|
|
void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event))
|
2001-06-26 20:27:24 -04:00
|
|
|
{
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-10-09 20:11:23 -04:00
|
|
|
if ( !m_textctrl )
|
|
|
|
return;
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
// leave a band below for popup menu testing
|
|
|
|
wxSize size = GetClientSize();
|
|
|
|
m_textctrl->SetSize(0, 0, size.x, (3*size.y)/4);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
|
|
// this is really ugly but we have to do it as we can't just call
|
|
|
|
// event.Skip() because wxFrameBase would make the text control fill the
|
|
|
|
// entire frame then
|
|
|
|
#ifdef __WXUNIVERSAL__
|
|
|
|
PositionMenuBar();
|
|
|
|
#endif // __WXUNIVERSAL__
|
|
|
|
}
|
|
|
|
|
2013-02-24 08:48:13 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyDialog
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MyDialog::MyDialog(wxWindow* parent)
|
|
|
|
: wxDialog(parent, wxID_ANY, "Test Dialog")
|
|
|
|
{
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
// create the log text window
|
|
|
|
m_textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
m_textctrl->SetEditable(false);
|
|
|
|
|
|
|
|
m_textctrl->AppendText(wxT("Dialogs do not have menus, but popup menus should function the same\n\n")
|
|
|
|
wxT("Right click this text ctrl to test popup menus.\n"));
|
|
|
|
#endif
|
|
|
|
#ifdef __POCKETPC__
|
|
|
|
EnableContextMenu();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_LOG_WINDOW
|
|
|
|
void MyDialog::LogMenuOpenCloseOrHighlight(const wxMenuEvent& event, const wxChar *what)
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg << wxT("A ")
|
|
|
|
<< ( event.IsPopup() ? wxT("popup ") : wxT("") )
|
|
|
|
<< wxT("menu has been ")
|
|
|
|
<< what;
|
|
|
|
if ( event.GetEventType() == wxEVT_MENU_HIGHLIGHT )
|
|
|
|
{
|
|
|
|
msg << wxT(" (id=") << event.GetId() << wxT(")");
|
|
|
|
}
|
|
|
|
msg << wxT(".\n");
|
|
|
|
|
|
|
|
m_textctrl->AppendText(msg);
|
|
|
|
}
|
|
|
|
#endif // USE_LOG_WINDOW
|
|
|
|
#if USE_CONTEXT_MENU
|
|
|
|
void MyDialog::OnContextMenu(wxContextMenuEvent& event)
|
|
|
|
{
|
|
|
|
wxPoint point = event.GetPosition();
|
|
|
|
// If from keyboard
|
|
|
|
if (point.x == -1 && point.y == -1) {
|
|
|
|
wxSize size = GetSize();
|
|
|
|
point.x = size.x / 2;
|
|
|
|
point.y = size.y / 2;
|
|
|
|
} else {
|
|
|
|
point = ScreenToClient(point);
|
|
|
|
}
|
|
|
|
ShowContextMenu(point);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void MyDialog::ShowContextMenu(const wxPoint& pos)
|
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
|
|
|
|
menu.Append(Menu_Help_About, wxT("&About"));
|
|
|
|
menu.Append(Menu_Popup_ToBeDeleted, wxT("To be &deleted"));
|
|
|
|
menu.AppendCheckItem(Menu_Popup_ToBeChecked, wxT("To be &checked"));
|
|
|
|
menu.Append(Menu_Popup_ToBeGreyed, wxT("To be &greyed"),
|
|
|
|
wxT("This menu item should be initially greyed out"));
|
|
|
|
menu.AppendSeparator();
|
|
|
|
menu.Append(Menu_File_Quit, wxT("E&xit"));
|
|
|
|
|
|
|
|
menu.Delete(Menu_Popup_ToBeDeleted);
|
|
|
|
menu.Check(Menu_Popup_ToBeChecked, true);
|
|
|
|
menu.Enable(Menu_Popup_ToBeGreyed, false);
|
|
|
|
|
|
|
|
PopupMenu(&menu, pos);
|
|
|
|
}
|