2001-01-31 11:00:00 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: event.cpp
|
2004-05-25 07:20:37 -04:00
|
|
|
// Purpose: wxWidgets sample demonstrating different event usage
|
2001-01-31 11:00:00 -05:00
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 31.01.01
|
|
|
|
// RCS-ID: $Id$
|
2009-04-16 12:34:35 -04:00
|
|
|
// Copyright: (c) 2001-2009 Vadim Zeitlin
|
2001-01-31 11:00:00 -05:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
2004-05-25 07:20:37 -04:00
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
2001-01-31 11:00:00 -05:00
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2009-02-07 20:01:00 -05:00
|
|
|
#ifndef __WXMSW__
|
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2001-12-14 18:38:33 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-02-02 07:38:17 -05:00
|
|
|
// define a custom event type (we don't need a separate declaration here but
|
2009-02-07 10:29:29 -05:00
|
|
|
// usually you would use a matching wxDECLARE_EVENT in a header)
|
2009-02-07 16:04:47 -05:00
|
|
|
wxDEFINE_EVENT(wxEVT_MY_CUSTOM_COMMAND, wxCommandEvent);
|
2001-12-14 18:38:33 -05:00
|
|
|
|
|
|
|
// it may also be convenient to define an event table macro for this event type
|
|
|
|
#define EVT_MY_CUSTOM_COMMAND(id, fn) \
|
|
|
|
DECLARE_EVENT_TABLE_ENTRY( \
|
2004-05-28 06:43:39 -04:00
|
|
|
wxEVT_MY_CUSTOM_COMMAND, id, wxID_ANY, \
|
2009-02-02 15:46:33 -05:00
|
|
|
wxCommandEventHandler(fn), \
|
2001-12-14 18:38:33 -05:00
|
|
|
(wxObject *) NULL \
|
|
|
|
),
|
|
|
|
|
2001-01-31 11:00:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// override base class virtuals
|
|
|
|
// ----------------------------
|
|
|
|
|
|
|
|
// this one is called on application startup and is a good place for the app
|
|
|
|
// initialization (doing it here and not in the ctor allows to have an error
|
|
|
|
// return: if OnInit() returns false, the application terminates)
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type: this is going to be our main frame
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor(s)
|
|
|
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
|
|
|
virtual ~MyFrame();
|
|
|
|
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
2009-04-16 12:34:35 -04:00
|
|
|
#if !wxEVENTS_COMPATIBILITY_2_8
|
|
|
|
void OnBind(wxCommandEvent& event);
|
|
|
|
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
2001-01-31 11:00:00 -05:00
|
|
|
void OnConnect(wxCommandEvent& event);
|
|
|
|
void OnDynamic(wxCommandEvent& event);
|
|
|
|
void OnPushEventHandler(wxCommandEvent& event);
|
|
|
|
void OnPopEventHandler(wxCommandEvent& event);
|
|
|
|
void OnTest(wxCommandEvent& event);
|
|
|
|
|
2001-12-14 18:38:33 -05:00
|
|
|
void OnFireCustom(wxCommandEvent& event);
|
|
|
|
void OnProcessCustom(wxCommandEvent& event);
|
|
|
|
|
2001-01-31 11:00:00 -05:00
|
|
|
void OnUpdateUIPop(wxUpdateUIEvent& event);
|
|
|
|
|
2009-04-16 12:34:35 -04:00
|
|
|
private:
|
|
|
|
// symbolic names for the status bar fields
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Status_Main = 0,
|
|
|
|
Status_Dynamic,
|
|
|
|
Status_Push
|
|
|
|
};
|
|
|
|
|
|
|
|
void UpdateDynamicStatus(bool on)
|
|
|
|
{
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
if ( on )
|
|
|
|
{
|
|
|
|
SetStatusText("You can now use \"Dynamic\" item in the menu");
|
|
|
|
SetStatusText("Dynamic: on", Status_Dynamic);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetStatusText("You can no more use \"Dynamic\" item in the menu");
|
|
|
|
SetStatusText("Dynamic: off", Status_Dynamic);
|
|
|
|
}
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
}
|
|
|
|
|
2001-01-31 11:00:00 -05:00
|
|
|
// number of pushed event handlers
|
2006-10-02 01:36:31 -04:00
|
|
|
unsigned m_nPush;
|
2001-01-31 11:00:00 -05:00
|
|
|
|
2009-04-16 12:34:35 -04:00
|
|
|
// the button to whose event we connect dynamically
|
|
|
|
wxButton *m_btnDynamic;
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2001-01-31 11:00:00 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define a custom event handler
|
|
|
|
class MyEvtHandler : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyEvtHandler(size_t level) { m_level = level; }
|
|
|
|
|
|
|
|
void OnTest(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxLogMessage(_T("This is the pushed test event handler #%u"), m_level);
|
|
|
|
|
|
|
|
// if we don't skip the event, the other event handlers won't get it:
|
|
|
|
// try commenting out this line and see what changes
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2006-10-02 01:36:31 -04:00
|
|
|
unsigned m_level;
|
2001-01-31 11:00:00 -05:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// menu items
|
|
|
|
Event_Quit = 1,
|
|
|
|
Event_About,
|
2009-04-16 12:34:35 -04:00
|
|
|
Event_Bind,
|
2001-01-31 11:00:00 -05:00
|
|
|
Event_Connect,
|
|
|
|
Event_Dynamic,
|
|
|
|
Event_Push,
|
|
|
|
Event_Pop,
|
2001-12-14 18:38:33 -05:00
|
|
|
Event_Custom,
|
2001-01-31 11:00:00 -05:00
|
|
|
Event_Test
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// event tables and other macros for wxWidgets
|
2001-01-31 11:00:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// the event tables connect the wxWidgets events with the functions (event
|
2001-01-31 11:00:00 -05:00
|
|
|
// handlers) which process them. It can be also done at run-time, but for the
|
|
|
|
// simple menu events like this the static method is much simpler.
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(Event_Quit, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(Event_About, MyFrame::OnAbout)
|
|
|
|
|
2009-04-16 12:34:35 -04:00
|
|
|
#if !wxEVENTS_COMPATIBILITY_2_8
|
|
|
|
EVT_MENU(Event_Bind, MyFrame::OnBind)
|
|
|
|
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
2001-01-31 11:00:00 -05:00
|
|
|
EVT_MENU(Event_Connect, MyFrame::OnConnect)
|
|
|
|
|
2001-12-14 18:38:33 -05:00
|
|
|
EVT_MENU(Event_Custom, MyFrame::OnFireCustom)
|
2001-01-31 11:00:00 -05:00
|
|
|
EVT_MENU(Event_Test, MyFrame::OnTest)
|
|
|
|
EVT_MENU(Event_Push, MyFrame::OnPushEventHandler)
|
|
|
|
EVT_MENU(Event_Pop, MyFrame::OnPopEventHandler)
|
|
|
|
|
|
|
|
EVT_UPDATE_UI(Event_Pop, MyFrame::OnUpdateUIPop)
|
2001-12-14 18:38:33 -05:00
|
|
|
|
2004-05-28 06:43:39 -04:00
|
|
|
EVT_MY_CUSTOM_COMMAND(wxID_ANY, MyFrame::OnProcessCustom)
|
2001-12-14 18:45:17 -05:00
|
|
|
|
2004-06-22 19:25:46 -04:00
|
|
|
// the line below would also work if OnProcessCustom() were defined as
|
|
|
|
// taking a wxEvent (as required by EVT_CUSTOM) and not wxCommandEvent
|
2004-05-28 06:43:39 -04:00
|
|
|
//EVT_CUSTOM(wxEVT_MY_CUSTOM_COMMAND, wxID_ANY, MyFrame::OnProcessCustom)
|
2001-01-31 11:00:00 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
|
|
|
|
EVT_MENU(Event_Test, MyEvtHandler::OnTest)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// Create a new application object: this macro will allow wxWidgets to create
|
2001-01-31 11:00:00 -05:00
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also declares the accessor function
|
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
|
|
|
// not wxApp)
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2001-01-31 11:00:00 -05:00
|
|
|
// create the main application window
|
2004-05-25 07:20:37 -04:00
|
|
|
MyFrame *frame = new MyFrame(_T("Event wxWidgets Sample"),
|
2001-12-14 18:38:33 -05:00
|
|
|
wxPoint(50, 50), wxSize(600, 340));
|
2001-01-31 11:00:00 -05:00
|
|
|
|
|
|
|
// and show it (the frames, unlike simple controls, are not shown when
|
|
|
|
// created initially)
|
2004-05-28 06:43:39 -04:00
|
|
|
frame->Show(true);
|
2001-01-31 11:00:00 -05:00
|
|
|
|
|
|
|
// success: wxApp::OnRun() will be called which will enter the main message
|
2004-05-28 06:43:39 -04:00
|
|
|
// loop and the application will run. If we returned false here, the
|
2001-01-31 11:00:00 -05:00
|
|
|
// application would exit immediately.
|
2004-05-28 06:43:39 -04:00
|
|
|
return true;
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// frame constructor
|
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
2009-04-16 12:34:35 -04:00
|
|
|
: wxFrame(NULL, wxID_ANY, title, pos, size)
|
2001-01-31 11:00:00 -05:00
|
|
|
{
|
2009-02-07 20:01:00 -05:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
2001-05-27 09:21:16 -04:00
|
|
|
// init members
|
|
|
|
m_nPush = 0;
|
2009-04-16 12:34:35 -04:00
|
|
|
m_btnDynamic = NULL;
|
2001-05-27 09:21:16 -04:00
|
|
|
|
2001-01-31 11:00:00 -05:00
|
|
|
// create a menu bar
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
|
2001-12-14 18:38:33 -05:00
|
|
|
menuFile->Append(Event_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
2001-01-31 11:00:00 -05:00
|
|
|
menuFile->AppendSeparator();
|
2001-12-14 18:38:33 -05:00
|
|
|
menuFile->Append(Event_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
2001-01-31 11:00:00 -05:00
|
|
|
|
|
|
|
wxMenu *menuEvent = new wxMenu;
|
2009-04-16 12:34:35 -04:00
|
|
|
#if !wxEVENTS_COMPATIBILITY_2_8
|
|
|
|
menuEvent->AppendCheckItem(Event_Bind, "&Bind\tCtrl-B",
|
|
|
|
"Bind or unbind a dynamic event handler");
|
|
|
|
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
|
|
|
menuEvent->AppendCheckItem(Event_Connect, _T("&Connect\tCtrl-C"),
|
|
|
|
_T("Connect or disconnect the dynamic event handler"));
|
2001-12-14 18:38:33 -05:00
|
|
|
menuEvent->Append(Event_Dynamic, _T("&Dynamic event\tCtrl-D"),
|
|
|
|
_T("Dynamic event sample - only works after Connect"));
|
|
|
|
menuEvent->AppendSeparator();
|
|
|
|
menuEvent->Append(Event_Push, _T("&Push event handler\tCtrl-P"),
|
|
|
|
_T("Push event handler for test event"));
|
|
|
|
menuEvent->Append(Event_Pop, _T("P&op event handler\tCtrl-O"),
|
|
|
|
_T("Pop event handler for test event"));
|
|
|
|
menuEvent->Append(Event_Test, _T("Test event\tCtrl-T"),
|
|
|
|
_T("Test event processed by pushed event handler"));
|
2001-01-31 11:00:00 -05:00
|
|
|
menuEvent->AppendSeparator();
|
2001-12-14 18:38:33 -05:00
|
|
|
menuEvent->Append(Event_Custom, _T("Fire c&ustom event\tCtrl-U"),
|
|
|
|
_T("Generate a custom event"));
|
2001-01-31 11:00:00 -05:00
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
2001-12-14 18:38:33 -05:00
|
|
|
menuBar->Append(menuFile, _T("&File"));
|
|
|
|
menuBar->Append(menuEvent, _T("&Event"));
|
2001-01-31 11:00:00 -05:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
CreateStatusBar(3);
|
2004-05-25 07:20:37 -04:00
|
|
|
SetStatusText(_T("Welcome to wxWidgets event sample"));
|
2001-01-31 11:00:00 -05:00
|
|
|
SetStatusText(_T("Dynamic: off"), Status_Dynamic);
|
|
|
|
SetStatusText(_T("Push count: 0"), Status_Push);
|
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-04-16 12:34:35 -04:00
|
|
|
|
|
|
|
wxPanel * const panel = new wxPanel(this);
|
|
|
|
wxSizer * const sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
const wxSizerFlags centreY(wxSizerFlags().Centre().Border());
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY,
|
|
|
|
"This button will only work if its handler is dynamically connected"),
|
|
|
|
centreY);
|
|
|
|
m_btnDynamic = new wxButton(panel, Event_Dynamic, "&Dynamic button");
|
|
|
|
sizer->Add(m_btnDynamic, centreY);
|
|
|
|
panel->SetSizer(sizer);
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
// we must pop any remaining event handlers to avoid memory leaks and
|
|
|
|
// crashes!
|
|
|
|
while ( m_nPush-- != 0 )
|
|
|
|
{
|
2004-05-28 06:43:39 -04:00
|
|
|
PopEventHandler(true /* delete handler */);
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// standard event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-05-28 06:43:39 -04:00
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2009-04-16 12:34:35 -04:00
|
|
|
wxMessageBox("Event sample shows different ways of using events\n"
|
|
|
|
"(c) 2001-2009 Vadim Zeitlin",
|
|
|
|
"About wxWidgets Event Sample",
|
|
|
|
wxOK | wxICON_INFORMATION, this);
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// dynamic event handling stuff
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-04-16 12:34:35 -04:00
|
|
|
void MyFrame::OnDynamic(wxCommandEvent& event)
|
2001-01-31 11:00:00 -05:00
|
|
|
{
|
2009-04-16 12:34:35 -04:00
|
|
|
wxString origin;
|
|
|
|
if ( event.GetEventObject() == this )
|
|
|
|
origin = "menu item";
|
|
|
|
else if ( event.GetEventObject() == m_btnDynamic )
|
|
|
|
origin = "button";
|
|
|
|
else
|
|
|
|
origin = "unknown event source";
|
|
|
|
|
2002-03-27 13:45:20 -05:00
|
|
|
wxMessageBox
|
|
|
|
(
|
2009-04-16 12:34:35 -04:00
|
|
|
"This message box is shown from the dynamically connected "
|
|
|
|
"event handler in response to event generated by " + origin,
|
|
|
|
"wxWidgets Event Sample", wxOK | wxICON_INFORMATION, this
|
2002-03-27 13:45:20 -05:00
|
|
|
);
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
2009-04-16 12:34:35 -04:00
|
|
|
#if !wxEVENTS_COMPATIBILITY_2_8
|
|
|
|
|
|
|
|
void MyFrame::OnBind(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.IsChecked() )
|
|
|
|
{
|
|
|
|
// as we bind directly to the button, there is no need to use an id
|
|
|
|
// here: the button will only ever get its own events
|
|
|
|
m_btnDynamic->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MyFrame::OnDynamic,
|
|
|
|
this);
|
|
|
|
|
|
|
|
// but we do need the id for the menu command as the frame gets all of
|
|
|
|
// them
|
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, &MyFrame::OnDynamic, this,
|
|
|
|
Event_Dynamic);
|
|
|
|
}
|
|
|
|
else // disconnect
|
|
|
|
{
|
|
|
|
m_btnDynamic->Unbind(wxEVT_COMMAND_BUTTON_CLICKED,
|
|
|
|
&MyFrame::OnDynamic, this);
|
|
|
|
Unbind(wxEVT_COMMAND_MENU_SELECTED, &MyFrame::OnDynamic, this,
|
|
|
|
Event_Dynamic);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateDynamicStatus(event.IsChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
|
|
|
|
2001-01-31 11:00:00 -05:00
|
|
|
void MyFrame::OnConnect(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.IsChecked() )
|
|
|
|
{
|
2009-04-16 12:34:35 -04:00
|
|
|
m_btnDynamic->Connect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,
|
|
|
|
wxCommandEventHandler(MyFrame::OnDynamic),
|
|
|
|
NULL, this);
|
2009-02-02 07:38:17 -05:00
|
|
|
Connect(Event_Dynamic, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(MyFrame::OnDynamic));
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
2009-02-02 07:38:17 -05:00
|
|
|
else // disconnect
|
2001-01-31 11:00:00 -05:00
|
|
|
{
|
2009-04-16 12:34:35 -04:00
|
|
|
m_btnDynamic->Disconnect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,
|
|
|
|
wxCommandEventHandler(MyFrame::OnDynamic),
|
|
|
|
NULL, this);
|
2009-02-02 07:38:17 -05:00
|
|
|
Disconnect(Event_Dynamic, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(MyFrame::OnDynamic));
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
2009-04-16 12:34:35 -04:00
|
|
|
|
|
|
|
UpdateDynamicStatus(event.IsChecked());
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// push/pop event handlers support
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MyFrame::OnPushEventHandler(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
PushEventHandler(new MyEvtHandler(++m_nPush));
|
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2001-01-31 11:00:00 -05:00
|
|
|
SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnPopEventHandler(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxCHECK_RET( m_nPush, _T("this command should be disabled!") );
|
|
|
|
|
2004-05-28 06:43:39 -04:00
|
|
|
PopEventHandler(true /* delete handler */);
|
2001-01-31 11:00:00 -05:00
|
|
|
m_nPush--;
|
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2001-01-31 11:00:00 -05:00
|
|
|
SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2001-01-31 11:00:00 -05:00
|
|
|
}
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event))
|
2001-01-31 11:00:00 -05:00
|
|
|
{
|
|
|
|
wxLogMessage(_T("This is the test event handler in the main frame"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateUIPop(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable( m_nPush > 0 );
|
|
|
|
}
|
|
|
|
|
2001-12-14 18:38:33 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// custom event methods
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::OnFireCustom(wxCommandEvent& WXUNUSED(event))
|
2001-12-14 18:38:33 -05:00
|
|
|
{
|
|
|
|
wxCommandEvent eventCustom(wxEVT_MY_CUSTOM_COMMAND);
|
|
|
|
|
|
|
|
wxPostEvent(this, eventCustom);
|
|
|
|
}
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::OnProcessCustom(wxCommandEvent& WXUNUSED(event))
|
2001-12-14 18:38:33 -05:00
|
|
|
{
|
|
|
|
wxLogMessage(_T("Got a custom event!"));
|
|
|
|
}
|
|
|
|
|