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
|
|
|
|
|
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
|
2005-05-18 16:39:34 -04:00
|
|
|
#if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__) || defined(__WXMGL__)
|
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
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
// this sample is usefull when new port is developed
|
|
|
|
// and usually new port has majority of flags turned off
|
|
|
|
#if wxUSE_LOG && wxUSE_TEXTCTRL
|
|
|
|
#define USE_LOG_WINDOW 1
|
|
|
|
#else
|
|
|
|
#define USE_LOG_WINDOW 0
|
|
|
|
#endif
|
|
|
|
|
2005-11-15 17:40:32 -05:00
|
|
|
#if wxUSE_OWNER_DRAWN || defined(__WXGTK__)
|
2000-09-12 04:17:23 -04:00
|
|
|
#include "copy.xpm"
|
2004-06-05 16:49:42 -04:00
|
|
|
#endif
|
2000-09-12 04:17:23 -04:00
|
|
|
|
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);
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
void OnClearLog(wxCommandEvent& event);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
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);
|
|
|
|
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
|
|
|
|
LogMenuOpenOrClose(event, _T("opened")); event.Skip();
|
|
|
|
#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
|
|
|
|
LogMenuOpenOrClose(event, _T("closed")); event.Skip();
|
|
|
|
#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:
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
{
|
2004-05-18 07:52:25 -04:00
|
|
|
Menu_File_Quit = wxID_EXIT,
|
|
|
|
#if USE_LOG_WINDOW
|
2001-06-26 20:27:24 -04:00
|
|
|
Menu_File_ClearLog,
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
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,
|
|
|
|
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,
|
|
|
|
|
|
|
|
Menu_Max
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_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)
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
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)
|
|
|
|
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)
|
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)
|
2004-05-18 07:52:25 -04:00
|
|
|
EVT_MENU(wxID_ANY, MyEvtHandler::OnMenuEvent)
|
2000-08-08 02:11:51 -04:00
|
|
|
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;
|
|
|
|
|
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
|
2004-05-25 07:20:37 -04:00
|
|
|
frame->SetStatusText(_T("Welcome to wxWidgets menu sample"));
|
2001-05-21 19:58:58 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
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()
|
2004-05-25 07:20:37 -04:00
|
|
|
: wxFrame((wxFrame *)NULL, wxID_ANY, _T("wxWidgets menu sample"))
|
1999-11-01 20:25:43 -05:00
|
|
|
{
|
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
|
|
|
|
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,
|
2002-12-15 05:23:11 -05:00
|
|
|
_T("Clear &log\tCtrl-L"));
|
2005-11-15 17:40:32 -05:00
|
|
|
#if wxUSE_OWNER_DRAWN || defined(__WXGTK__)
|
2001-06-26 20:27:24 -04:00
|
|
|
item->SetBitmap(copy_xpm);
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2001-06-26 20:27:24 -04:00
|
|
|
fileMenu->Append(item);
|
|
|
|
fileMenu->AppendSeparator();
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
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"),
|
2004-01-08 06:36:38 -05:00
|
|
|
_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"),
|
2004-01-08 06:36:38 -05:00
|
|
|
_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"));
|
2004-05-18 07:52:25 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2002-12-15 05:23:11 -05:00
|
|
|
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"));
|
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;
|
|
|
|
subMenu->Append(Menu_SubMenu_Normal, _T("&Normal submenu item"), _T("Disabled submenu item"));
|
2006-02-02 13:19:04 -05:00
|
|
|
subMenu->AppendCheckItem(Menu_SubMenu_Check, _T("&Check submenu item"), _T("Check submenu item"));
|
2004-11-19 17:35:22 -05:00
|
|
|
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"));
|
2003-06-01 16:35:12 -04:00
|
|
|
|
|
|
|
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"),
|
2004-01-08 06:36:38 -05:00
|
|
|
_T("Enable or disable the last menu item"), true);
|
2002-12-15 05:23:11 -05:00
|
|
|
menuMenu->Append(Menu_Menu_Check, _T("&Check menu item\tAlt-C"),
|
2004-01-08 06:36:38 -05:00
|
|
|
_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"));
|
2005-06-10 13:53:19 -04:00
|
|
|
#if wxUSE_TEXTDLG
|
2005-04-16 12:53:55 -04:00
|
|
|
menuMenu->Append(Menu_Menu_SetLabel, _T("Set menu item label\tAlt-L"),
|
|
|
|
_T("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();
|
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"));
|
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;
|
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
|
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
|
|
|
|
|
|
|
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"));
|
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;
|
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();
|
2004-06-12 20:02:35 -04:00
|
|
|
menu->AppendCheckItem(Menu_Dummy_Second, _T("&Second item\tCtrl-F2"));
|
1999-11-01 20:25:43 -05:00
|
|
|
|
1999-12-04 08:43:59 -05:00
|
|
|
if ( title )
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
title->Printf(_T("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);
|
|
|
|
|
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 )
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogWarning(_T("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
|
|
|
|
2004-01-08 06:36:38 -05:00
|
|
|
wxString msg = wxString::Format(_T("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
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
msg += wxString::Format(_T(" (the item is currently %schecked)"),
|
|
|
|
event.IsChecked() ? _T("") : _T("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
|
2001-06-26 20:27:24 -04:00
|
|
|
void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_textctrl->Clear();
|
|
|
|
}
|
2004-05-18 07:52:25 -04:00
|
|
|
#endif
|
2001-06-26 20:27:24 -04:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-09-25 14:56:33 -04:00
|
|
|
(void)wxMessageBox(_T("wxWidgets menu sample\n(c) 1999-2001 Vadim Zeitlin"),
|
2004-05-25 07:20:37 -04:00
|
|
|
_T("About wxWidgets 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
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogError(_T("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?") );
|
|
|
|
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogMessage(_T("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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
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"),
|
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)
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogWarning(_T("No menu with label '%s'"), label.c_str());
|
2002-12-14 16:12:47 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogMessage(_T("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)
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogMessage(_T("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"),
|
2004-01-08 06:36:38 -05:00
|
|
|
_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 )
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogWarning(_T("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")));
|
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();
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogMessage(_T("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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
(
|
|
|
|
_T("Enter new label: "),
|
|
|
|
_T("Change last menu item text"),
|
|
|
|
item->GetLabel(),
|
|
|
|
this
|
|
|
|
);
|
2005-04-16 12:53:55 -04:00
|
|
|
label.Replace( _T("\\t"), _T("\t") );
|
2002-02-20 11:41:35 -05:00
|
|
|
|
|
|
|
if ( !label.empty() )
|
|
|
|
{
|
|
|
|
item->SetText(label);
|
|
|
|
}
|
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;
|
2002-12-15 05:23:11 -05:00
|
|
|
msg << _T("The item is ") << (item->IsEnabled() ? _T("enabled")
|
|
|
|
: _T("disabled"))
|
2004-01-08 06:36:38 -05:00
|
|
|
<< _T('\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 )
|
2004-01-08 06:36:38 -05:00
|
|
|
msg << _T("Alt-");
|
1999-11-02 11:17:16 -05:00
|
|
|
if ( flags & wxACCEL_CTRL )
|
2004-01-08 06:36:38 -05:00
|
|
|
msg << _T("Ctrl-");
|
1999-11-02 11:17:16 -05:00
|
|
|
if ( flags & wxACCEL_SHIFT )
|
2004-01-08 06:36:38 -05:00
|
|
|
msg << _T("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:
|
2004-01-08 06:36:38 -05:00
|
|
|
msg << _T('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;
|
|
|
|
}
|
|
|
|
|
2004-01-08 06:36:38 -05:00
|
|
|
wxFAIL_MSG( _T("unknown keyboard accel") );
|
1999-11-02 11:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
wxCHECK_RET( count, _T("no last menu?") );
|
|
|
|
|
|
|
|
wxString label = wxGetTextFromUser
|
|
|
|
(
|
|
|
|
_T("Enter label to search for: "),
|
|
|
|
_T("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)
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogWarning(_T("No menu item with label '%s'"), label.c_str());
|
2002-12-14 16:12:47 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxLogMessage(_T("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
|
|
|
|
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"));
|
2004-06-12 20:02:35 -04:00
|
|
|
menu.AppendCheckItem(Menu_Popup_ToBeChecked, _T("To be &checked"));
|
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);
|
2004-01-08 06:36:38 -05:00
|
|
|
menu.Check(Menu_Popup_ToBeChecked, true);
|
|
|
|
menu.Enable(Menu_Popup_ToBeGreyed, false);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
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
|
|
|
|
2003-09-11 08:52:20 -04:00
|
|
|
void MyFrame::OnTestNormal(wxCommandEvent& WXUNUSED(event))
|
2002-03-18 14:41:35 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-05-18 07:52:25 -04:00
|
|
|
#if USE_LOG_WINDOW
|
2002-02-23 18:16:32 -05:00
|
|
|
void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what)
|
|
|
|
{
|
2004-01-08 06:36:38 -05:00
|
|
|
wxString msg;
|
|
|
|
msg << _T("A ")
|
|
|
|
<< ( event.IsPopup() ? _T("popup ") : _T("") )
|
|
|
|
<< _T("menu has been ")
|
|
|
|
<< what
|
|
|
|
<< _T(".");
|
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__
|
|
|
|
}
|
|
|
|
|