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
|
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
|
// 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"
|
|
|
|
|
#include "wx/frame.h"
|
|
|
|
|
#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
|
|
|
|
|
|
2000-09-12 04:17:23 -04:00
|
|
|
|
#include "copy.xpm"
|
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// classes
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// Define a new application
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
bool OnInit();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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);
|
2001-06-26 20:27:24 -04:00
|
|
|
|
void OnClearLog(wxCommandEvent& event);
|
|
|
|
|
|
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);
|
|
|
|
|
void OnInsertMenuItem(wxCommandEvent& event);
|
|
|
|
|
void OnCheckMenuItem(wxCommandEvent& event);
|
|
|
|
|
void OnEnableMenuItem(wxCommandEvent& event);
|
|
|
|
|
void OnGetLabelMenuItem(wxCommandEvent& event);
|
|
|
|
|
void OnSetLabelMenuItem(wxCommandEvent& event);
|
1999-11-02 11:17:16 -05:00
|
|
|
|
void OnGetMenuItemInfo(wxCommandEvent& event);
|
2002-12-14 16:12:47 -05:00
|
|
|
|
void OnFindMenuItem(wxCommandEvent& event);
|
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);
|
2002-12-14 16:12:47 -05:00
|
|
|
|
void OnFindMenu(wxCommandEvent& event);
|
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);
|
|
|
|
|
|
2003-03-06 11:56:06 -05:00
|
|
|
|
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
|
2002-02-23 18:16:32 -05:00
|
|
|
|
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")); }
|
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:
|
2002-02-23 18:16:32 -05:00
|
|
|
|
void LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what);
|
|
|
|
|
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;
|
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
|
// the control used for logging
|
|
|
|
|
wxTextCtrl *m_textctrl;
|
|
|
|
|
|
|
|
|
|
// the previous log target
|
|
|
|
|
wxLog *m_logOld;
|
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
};
|
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// constants
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
Menu_File_Quit = 100,
|
2001-06-26 20:27:24 -04:00
|
|
|
|
Menu_File_ClearLog,
|
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,
|
|
|
|
|
Menu_MenuBar_SetLabel,
|
2002-12-14 16:12:47 -05:00
|
|
|
|
Menu_MenuBar_FindMenu,
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
|
|
Menu_Menu_Append = 300,
|
|
|
|
|
Menu_Menu_AppendSub,
|
|
|
|
|
Menu_Menu_Insert,
|
|
|
|
|
Menu_Menu_Delete,
|
|
|
|
|
Menu_Menu_Enable,
|
|
|
|
|
Menu_Menu_Check,
|
|
|
|
|
Menu_Menu_GetLabel,
|
|
|
|
|
Menu_Menu_SetLabel,
|
1999-11-02 11:17:16 -05:00
|
|
|
|
Menu_Menu_GetInfo,
|
2002-12-14 16:12:47 -05:00
|
|
|
|
Menu_Menu_FindItem,
|
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,
|
|
|
|
|
|
|
|
|
|
Menu_Help_About = 1000,
|
|
|
|
|
|
|
|
|
|
Menu_Popup_ToBeDeleted = 2000,
|
|
|
|
|
Menu_Popup_ToBeGreyed,
|
|
|
|
|
Menu_Popup_ToBeChecked,
|
|
|
|
|
Menu_Popup_Submenu,
|
|
|
|
|
|
|
|
|
|
Menu_Max
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// event tables
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2001-06-26 20:27:24 -04:00
|
|
|
|
EVT_MENU(Menu_File_Quit, MyFrame::OnQuit)
|
|
|
|
|
EVT_MENU(Menu_File_ClearLog, MyFrame::OnClearLog)
|
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)
|
|
|
|
|
EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu)
|
2002-12-14 16:12:47 -05:00
|
|
|
|
EVT_MENU(Menu_MenuBar_FindMenu, MyFrame::OnFindMenu)
|
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)
|
|
|
|
|
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)
|
|
|
|
|
EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem)
|
1999-11-02 11:17:16 -05:00
|
|
|
|
EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo)
|
2002-12-14 16:12:47 -05:00
|
|
|
|
EVT_MENU(Menu_Menu_FindItem, MyFrame::OnFindMenuItem)
|
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)
|
|
|
|
|
|
2003-03-06 11:56:06 -05:00
|
|
|
|
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
|
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)
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
|
|
|
|
EVT_SIZE(MyFrame::OnSize)
|
1999-11-01 20:25:43 -05:00
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
2000-08-08 02:11:51 -04:00
|
|
|
|
BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
|
|
|
|
|
EVT_MENU(-1, MyEvtHandler::OnMenuEvent)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
// Create the main frame window
|
|
|
|
|
MyFrame* frame = new MyFrame;
|
|
|
|
|
|
|
|
|
|
frame->Show(TRUE);
|
|
|
|
|
|
2001-05-21 19:58:58 -04:00
|
|
|
|
#if wxUSE_STATUSBAR
|
2002-12-15 05:23:11 -05:00
|
|
|
|
frame->SetStatusText(_T("Welcome to wxWindows menu sample"));
|
2001-05-21 19:58:58 -04:00
|
|
|
|
#endif // wxUSE_STATUSBAR
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// MyFrame
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
|
MyFrame::MyFrame()
|
2002-12-15 05:23:11 -05:00
|
|
|
|
: wxFrame((wxFrame *)NULL, -1, _T("wxWindows menu sample"),
|
2002-02-20 11:41:35 -05:00
|
|
|
|
wxDefaultPosition, wxSize(400, 250))
|
1999-11-01 20:25:43 -05:00
|
|
|
|
{
|
2001-10-09 20:11:23 -04:00
|
|
|
|
m_textctrl = NULL;
|
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
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
|
wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog,
|
2002-12-15 05:23:11 -05:00
|
|
|
|
_T("Clear &log\tCtrl-L"));
|
2001-06-26 20:27:24 -04:00
|
|
|
|
item->SetBitmap(copy_xpm);
|
|
|
|
|
fileMenu->Append(item);
|
|
|
|
|
fileMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
fileMenu->Append(Menu_File_Quit, _T("E&xit\tAlt-X"), _T("Quit menu sample"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
|
|
wxMenu *menubarMenu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Append, _T("&Append menu\tCtrl-A"),
|
|
|
|
|
_T("Append a menu to the menubar"));
|
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Insert, _T("&Insert menu\tCtrl-I"),
|
|
|
|
|
_T("Insert a menu into the menubar"));
|
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Delete, _T("&Delete menu\tCtrl-D"),
|
|
|
|
|
_T("Delete the last menu from the menubar"));
|
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Toggle, _T("&Toggle menu\tCtrl-T"),
|
|
|
|
|
_T("Toggle the first menu in the menubar"), TRUE);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menubarMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menubarMenu->Append(Menu_MenuBar_Enable, _T("&Enable menu\tCtrl-E"),
|
|
|
|
|
_T("Enable or disable the last menu"), TRUE);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menubarMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menubarMenu->Append(Menu_MenuBar_GetLabel, _T("&Get menu label\tCtrl-G"),
|
|
|
|
|
_T("Get the label of the last menu"));
|
|
|
|
|
menubarMenu->Append(Menu_MenuBar_SetLabel, _T("&Set menu label\tCtrl-S"),
|
|
|
|
|
_T("Change the label of the last menu"));
|
2002-12-14 16:12:47 -05:00
|
|
|
|
menubarMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menubarMenu->Append(Menu_MenuBar_FindMenu, _T("&Find menu from label\tCtrl-F"),
|
|
|
|
|
_T("Find a menu by searching for its label"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
|
wxMenu* subMenu = new wxMenu;
|
|
|
|
|
subMenu->Append(Menu_SubMenu_Normal, _T("&Normal submenu item"), _T("Disabled submenu item"));
|
|
|
|
|
subMenu->AppendCheckItem(Menu_SubMenu_Check, _T("&Unchecked submenu item"), _T("Unchecked submenu item"));
|
|
|
|
|
subMenu->AppendRadioItem(Menu_SubMenu_Radio1, _T("&Radio item 1"), _T("Radio item"));
|
|
|
|
|
subMenu->AppendRadioItem(Menu_SubMenu_Radio2, _T("&Radio item 2"), _T("Radio item"));
|
|
|
|
|
subMenu->AppendRadioItem(Menu_SubMenu_Radio3, _T("&Radio item 3"), _T("Radio item"));
|
|
|
|
|
|
|
|
|
|
menubarMenu->Append(Menu_SubMenu, _T("Submenu"), subMenu);
|
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
wxMenu *menuMenu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menuMenu->Append(Menu_Menu_Append, _T("&Append menu item\tAlt-A"),
|
|
|
|
|
_T("Append a menu item to the last menu"));
|
|
|
|
|
menuMenu->Append(Menu_Menu_AppendSub, _T("&Append sub menu\tAlt-S"),
|
|
|
|
|
_T("Append a sub menu to the last menu"));
|
|
|
|
|
menuMenu->Append(Menu_Menu_Insert, _T("&Insert menu item\tAlt-I"),
|
|
|
|
|
_T("Insert a menu item in head of the last menu"));
|
|
|
|
|
menuMenu->Append(Menu_Menu_Delete, _T("&Delete menu item\tAlt-D"),
|
|
|
|
|
_T("Delete the last menu item from the last menu"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menuMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menuMenu->Append(Menu_Menu_Enable, _T("&Enable menu item\tAlt-E"),
|
|
|
|
|
_T("Enable or disable the last menu item"), TRUE);
|
|
|
|
|
menuMenu->Append(Menu_Menu_Check, _T("&Check menu item\tAlt-C"),
|
|
|
|
|
_T("Check or uncheck the last menu item"), TRUE);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menuMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menuMenu->Append(Menu_Menu_GetInfo, _T("Get menu item in&fo\tAlt-F"),
|
|
|
|
|
_T("Show the state of the last menu item"));
|
1999-11-02 11:17:16 -05:00
|
|
|
|
menuMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menuMenu->Append(Menu_Menu_FindItem, _T("Find menu item from label"),
|
|
|
|
|
_T("Find a menu item by searching for its label"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
|
wxMenu *testMenu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
|
testMenu->Append(Menu_Test_Normal, _T("&Normal item"));
|
2002-03-18 14:41:35 -05:00
|
|
|
|
testMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
testMenu->AppendCheckItem(Menu_Test_Check, _T("&Check item"));
|
2002-03-18 14:41:35 -05:00
|
|
|
|
testMenu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
testMenu->AppendRadioItem(Menu_Test_Radio1, _T("Radio item &1"));
|
|
|
|
|
testMenu->AppendRadioItem(Menu_Test_Radio2, _T("Radio item &2"));
|
|
|
|
|
testMenu->AppendRadioItem(Menu_Test_Radio3, _T("Radio item &3"));
|
2002-03-18 14:41:35 -05:00
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
|
helpMenu->Append(Menu_Help_About, _T("&About\tF1"), _T("About menu sample"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
|
|
wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
|
|
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menuBar->Append(fileMenu, _T("&File"));
|
|
|
|
|
menuBar->Append(menubarMenu, _T("Menu&bar"));
|
|
|
|
|
menuBar->Append(menuMenu, _T("&Menu"));
|
|
|
|
|
menuBar->Append(testMenu, _T("&Test"));
|
|
|
|
|
menuBar->Append(helpMenu, _T("&Help"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
|
|
// these items should be initially checked
|
|
|
|
|
menuBar->Check(Menu_MenuBar_Toggle, TRUE);
|
|
|
|
|
menuBar->Check(Menu_MenuBar_Enable, TRUE);
|
|
|
|
|
menuBar->Check(Menu_Menu_Enable, TRUE);
|
|
|
|
|
menuBar->Check(Menu_Menu_Check, FALSE);
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
// create the log text window
|
|
|
|
|
m_textctrl = new wxTextCtrl(this, -1, _T(""),
|
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
|
m_textctrl->SetEditable(FALSE);
|
2002-02-20 11:41:35 -05:00
|
|
|
|
|
|
|
|
|
wxLog::SetTimestamp(NULL);
|
2001-06-26 20:27:24 -04:00
|
|
|
|
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl));
|
|
|
|
|
|
2002-02-20 11:41:35 -05:00
|
|
|
|
wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ")
|
2001-06-26 20:27:24 -04:00
|
|
|
|
_T("append/insert/delete items to/from the last menu.\n")
|
2002-02-20 11:41:35 -05:00
|
|
|
|
_T("The commands from \"Menubar\" menu work with the ")
|
|
|
|
|
_T("menubar itself.\n\n")
|
2001-06-26 20:27:24 -04:00
|
|
|
|
_T("Right click the band below to test popup menus.\n"));
|
2000-08-08 02:11:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
|
{
|
|
|
|
|
delete m_menu;
|
|
|
|
|
|
|
|
|
|
// delete the event handler installed in ctor
|
|
|
|
|
PopEventHandler(TRUE);
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
|
|
|
|
// restore old logger
|
|
|
|
|
delete wxLog::SetActiveTarget(m_logOld);
|
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;
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menu->Append(Menu_Dummy_First, _T("&First item\tCtrl-F1"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menu->Append(Menu_Dummy_Second, _T("&Second item\tCtrl-F2"), _T(""), TRUE);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
|
if ( title )
|
|
|
|
|
{
|
2002-09-14 14:38:31 -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();
|
|
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
|
|
|
|
|
|
|
|
|
|
wxMenuItemList::Node *node = menu->GetMenuItems().GetLast();
|
|
|
|
|
if ( !node )
|
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
|
wxLogWarning(wxT("No last item in the last 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
|
|
|
|
if ( !GetMenuBar()->FindItem(id) )
|
2001-03-02 07:49:26 -05:00
|
|
|
|
return;
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
2001-09-21 16:21:44 -04:00
|
|
|
|
wxString msg = wxString::Format(wxT("Menu command %d"), id);
|
2000-08-08 02:11:51 -04:00
|
|
|
|
if ( GetMenuBar()->FindItem(id)->IsCheckable() )
|
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
|
msg += wxString::Format(wxT(" (the item is currently %schecked)"),
|
2000-08-08 02:11:51 -04:00
|
|
|
|
event.IsChecked() ? "" : "not ");
|
|
|
|
|
}
|
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
Close(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
|
void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
m_textctrl->Clear();
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
|
(void)wxMessageBox(_T("wxWindows menu sample\n<EFBFBD> 1999-2001 Vadim Zeitlin"),
|
|
|
|
|
_T("About wxWindows menu sample"),
|
1999-11-01 20:25:43 -05:00
|
|
|
|
wxICON_INFORMATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
|
|
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
if ( count == 2 )
|
|
|
|
|
{
|
|
|
|
|
// don't let delete the first 2 menus
|
2001-09-21 16:21:44 -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);
|
|
|
|
|
GetMenuBar()->Insert(0, menu, title);
|
|
|
|
|
}
|
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
|
2002-12-15 05:23:11 -05:00
|
|
|
|
mbar->Insert(0, m_menu, _T("&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();
|
|
|
|
|
|
2002-02-20 11:41:35 -05:00
|
|
|
|
wxCHECK_RET( count, _T("no last menu?") );
|
|
|
|
|
|
2001-09-21 16:21:44 -04:00
|
|
|
|
wxLogMessage(wxT("The label of the last menu item is '%s'"),
|
1999-11-02 10:21:40 -05:00
|
|
|
|
mbar->GetLabelTop(count - 1).c_str());
|
1999-11-01 20:25:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
|
2002-02-20 11:41:35 -05:00
|
|
|
|
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);
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
|
|
wxCHECK_RET( count, _T("no last menu?") );
|
|
|
|
|
|
|
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
|
(
|
|
|
|
|
_T("Enter label to search for: "),
|
|
|
|
|
_T("Find menu"),
|
2002-12-22 15:14:18 -05:00
|
|
|
|
_T(""),
|
2002-12-14 16:12:47 -05:00
|
|
|
|
this
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
|
{
|
|
|
|
|
int index = mbar->FindMenu(label);
|
|
|
|
|
|
|
|
|
|
if (index == wxNOT_FOUND)
|
|
|
|
|
{
|
|
|
|
|
wxLogWarning(wxT("No menu with label '%s'"), label.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wxLogMessage(wxT("Menu %d has label '%s'"), index, label.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
|
void MyFrame::OnDummy(wxCommandEvent& event)
|
|
|
|
|
{
|
2001-09-21 16:21:44 -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();
|
|
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
|
|
|
|
|
|
|
|
|
|
menu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menu->Append(Menu_Dummy_Third, _T("&Third dummy item\tCtrl-F3"),
|
|
|
|
|
_T("Checkable item"), TRUE);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
2003-03-06 11:56:06 -05:00
|
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 2);
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menu->Append(Menu_Dummy_Last, _T("&Dummy sub menu"),
|
|
|
|
|
CreateDummyMenu(NULL), _T("Dummy sub menu help"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnDeleteMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
|
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
|
|
|
|
|
|
|
|
|
|
size_t count = menu->GetMenuItemCount();
|
|
|
|
|
if ( !count )
|
|
|
|
|
{
|
2001-09-21 16:21:44 -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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnInsertMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxMenuBar *menubar = GetMenuBar();
|
|
|
|
|
wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
|
|
|
|
|
|
|
|
|
|
menu->Insert(0, wxMenuItem::New(menu, Menu_Dummy_Fourth,
|
2002-12-15 05:23:11 -05:00
|
|
|
|
_T("Fourth dummy item\tCtrl-F4")));
|
|
|
|
|
menu->Insert(1, wxMenuItem::New(menu, wxID_SEPARATOR, _T("")));
|
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();
|
|
|
|
|
|
|
|
|
|
item->Toggle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
|
wxLogMessage(wxT("The label of the last menu item is '%s'"),
|
1999-11-02 10:21:40 -05:00
|
|
|
|
item->GetLabel().c_str());
|
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
|
|
|
|
|
(
|
|
|
|
|
_T("Enter new label: "),
|
|
|
|
|
_T("Change last menu item text"),
|
|
|
|
|
item->GetLabel(),
|
|
|
|
|
this
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
|
{
|
|
|
|
|
item->SetText(label);
|
|
|
|
|
}
|
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;
|
2002-12-15 05:23:11 -05:00
|
|
|
|
msg << _T("The item is ") << (item->IsEnabled() ? _T("enabled")
|
|
|
|
|
: _T("disabled"))
|
1999-11-02 11:17:16 -05:00
|
|
|
|
<< '\n';
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
1999-11-02 11:17:16 -05:00
|
|
|
|
if ( item->IsCheckable() )
|
|
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
|
msg << _T("It is checkable and ") << (item->IsChecked() ? _T("") : _T("un"))
|
|
|
|
|
<< _T("checked\n");
|
1999-11-02 11:17:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
|
wxAcceleratorEntry *accel = item->GetAccel();
|
|
|
|
|
if ( accel )
|
|
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
|
msg << _T("Its accelerator is ");
|
1999-11-02 11:17:16 -05:00
|
|
|
|
|
|
|
|
|
int flags = accel->GetFlags();
|
|
|
|
|
if ( flags & wxACCEL_ALT )
|
|
|
|
|
msg << wxT("Alt-");
|
|
|
|
|
if ( flags & wxACCEL_CTRL )
|
|
|
|
|
msg << wxT("Ctrl-");
|
|
|
|
|
if ( flags & wxACCEL_SHIFT )
|
|
|
|
|
msg << wxT("Shift-");
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
msg << wxT('F') << code - WXK_F1 + 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// if there are any other keys wxGetAccelFromString() may return,
|
|
|
|
|
// we should process them here
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if ( wxIsalnum(code) )
|
|
|
|
|
{
|
|
|
|
|
msg << (wxChar)code;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxFAIL_MSG( wxT("unknown keyboard accel") );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete accel;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
|
msg << _T("It doesn't have an accelerator");
|
1999-11-02 11:17:16 -05:00
|
|
|
|
}
|
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
|
|
wxLogMessage(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-14 16:12:47 -05:00
|
|
|
|
void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxMenuBar *mbar = GetMenuBar();
|
|
|
|
|
size_t count = mbar->GetMenuCount();
|
|
|
|
|
|
|
|
|
|
wxCHECK_RET( count, _T("no last menu?") );
|
|
|
|
|
|
|
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
|
(
|
|
|
|
|
_T("Enter label to search for: "),
|
|
|
|
|
_T("Find menu item"),
|
2002-12-22 15:14:18 -05:00
|
|
|
|
_T(""),
|
2002-12-14 16:12:47 -05:00
|
|
|
|
this
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
|
{
|
|
|
|
|
size_t menuindex = 0;
|
|
|
|
|
int index = wxNOT_FOUND;
|
|
|
|
|
|
|
|
|
|
for (menuindex = 0; (menuindex < count) && (index == wxNOT_FOUND); ++menuindex)
|
|
|
|
|
{
|
|
|
|
|
index = mbar->FindMenuItem(mbar->GetMenu(menuindex)->GetTitle(), label);
|
|
|
|
|
}
|
|
|
|
|
if (index == wxNOT_FOUND)
|
|
|
|
|
{
|
|
|
|
|
wxLogWarning(wxT("No menu item with label '%s'"), label.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-04-08 07:28:57 -04:00
|
|
|
|
wxLogMessage(wxT("Menu item %d in menu %lu has label '%s'"),
|
|
|
|
|
index, (unsigned long)menuindex, label.c_str());
|
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
|
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
|
wxMenu menu(_T("Test popup"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menu.Append(Menu_Help_About, _T("&About"));
|
|
|
|
|
menu.Append(Menu_Popup_Submenu, _T("&Submenu"), CreateDummyMenu(NULL));
|
|
|
|
|
menu.Append(Menu_Popup_ToBeDeleted, _T("To be &deleted"));
|
|
|
|
|
menu.Append(Menu_Popup_ToBeChecked, _T("To be &checked"), _T(""), TRUE);
|
2003-06-02 18:59:37 -04:00
|
|
|
|
menu.Append(Menu_Popup_ToBeGreyed, _T("To be &greyed"),
|
|
|
|
|
_T("This menu item should be initially greyed out"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menu.AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
|
menu.Append(Menu_File_Quit, _T("E&xit"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
|
menu.Delete(Menu_Popup_ToBeDeleted);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
menu.Check(Menu_Popup_ToBeChecked, TRUE);
|
|
|
|
|
menu.Enable(Menu_Popup_ToBeGreyed, FALSE);
|
|
|
|
|
|
2002-02-23 18:16:32 -05:00
|
|
|
|
PopupMenu(&menu, pos.x, pos.y);
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
|
|
// test for destroying items in popup menus
|
2001-06-26 20:27:24 -04:00
|
|
|
|
#if 0 // doesn't work in wxGTK!
|
2000-07-15 15:51:35 -04:00
|
|
|
|
menu.Destroy(Menu_Popup_Submenu);
|
|
|
|
|
|
|
|
|
|
PopupMenu( &menu, event.GetX(), event.GetY() );
|
|
|
|
|
#endif // 0
|
1999-11-01 20:25:43 -05:00
|
|
|
|
}
|
2001-06-26 20:27:24 -04:00
|
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
|
void MyFrame::OnTestNormal(wxCommandEvent& event)
|
|
|
|
|
{
|
|
|
|
|
wxLogMessage(_T("Normal item selected"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnTestCheck(wxCommandEvent& event)
|
|
|
|
|
{
|
|
|
|
|
wxLogMessage(_T("Check item %schecked"),
|
|
|
|
|
event.IsChecked() ? _T("") : _T("un"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnTestRadio(wxCommandEvent& event)
|
|
|
|
|
{
|
|
|
|
|
wxLogMessage(_T("Radio item %d selected"),
|
|
|
|
|
event.GetId() - Menu_Test_Radio1 + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-23 18:16:32 -05:00
|
|
|
|
void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what)
|
|
|
|
|
{
|
|
|
|
|
wxLogStatus(this, _T("A %smenu has been %s."),
|
|
|
|
|
event.IsPopup() ? _T("popup ") : _T(""), what);
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-01 16:35:12 -04:00
|
|
|
|
void MyFrame::OnUpdateSubMenuNormal(wxUpdateUIEvent& event)
|
|
|
|
|
{
|
|
|
|
|
event.Enable(FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateSubMenuCheck(wxUpdateUIEvent& event)
|
|
|
|
|
{
|
|
|
|
|
event.Enable(TRUE);
|
|
|
|
|
event.Check(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateSubMenuRadio(wxUpdateUIEvent& event)
|
|
|
|
|
{
|
|
|
|
|
int which = (event.GetId() - Menu_SubMenu_Radio1 + 1);
|
|
|
|
|
if (which == 2)
|
|
|
|
|
event.Check(TRUE);
|
|
|
|
|
else
|
|
|
|
|
event.Check(FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-26 20:27:24 -04:00
|
|
|
|
void MyFrame::OnSize(wxSizeEvent& event)
|
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
|
|
// 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__
|
|
|
|
|
}
|
|
|
|
|
|