projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[ 1578466 ] Support for custom floating panes
[wxWidgets.git]
/
samples
/
event
/
event.cpp
diff --git
a/samples/event/event.cpp
b/samples/event/event.cpp
index 1f63f7efd164bbc0f43f7c2433765199cfa85e55..a0647391aee01dcde7ac622b26e1d96d9618a635 100644
(file)
--- a/
samples/event/event.cpp
+++ b/
samples/event/event.cpp
@@
-1,6
+1,6
@@
/////////////////////////////////////////////////////////////////////////////
// Name: event.cpp
/////////////////////////////////////////////////////////////////////////////
// Name: event.cpp
-// Purpose: wxWi
ndow
s sample demonstrating different event usage
+// Purpose: wxWi
dget
s sample demonstrating different event usage
// Author: Vadim Zeitlin
// Modified by:
// Created: 31.01.01
// Author: Vadim Zeitlin
// Modified by:
// Created: 31.01.01
@@
-17,13
+17,6
@@
// headers
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
- // DO NOT use event.cpp here, it breaks statics initialization in
- // src/common/event.cpp and nothing works at all then!
- #pragma implementation "eventsample.cpp"
- #pragma interface "eventsample.cpp"
-#endif
-
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
@@
-32,7
+25,7
@@
#endif
// for all others, include the necessary headers (this file is usually all you
#endif
// for all others, include the necessary headers (this file is usually all you
-// need because it includes almost all "standard" wxWi
ndow
s headers)
+// need because it includes almost all "standard" wxWi
dget
s headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
@@
-59,8
+52,8
@@
DEFINE_EVENT_TYPE(wxEVT_MY_CUSTOM_COMMAND)
// 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( \
// 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( \
- wxEVT_MY_CUSTOM_COMMAND, id,
-1
, \
- (wxObjectEventFunction)(wxEventFunction)
(wxCommandEventFunction)&fn
, \
+ wxEVT_MY_CUSTOM_COMMAND, id,
wxID_ANY
, \
+ (wxObjectEventFunction)(wxEventFunction)
wxStaticCastEvent( wxCommandEventFunction, &fn )
, \
(wxObject *) NULL \
),
(wxObject *) NULL \
),
@@
-104,10
+97,10
@@
public:
protected:
// number of pushed event handlers
protected:
// number of pushed event handlers
-
size_t
m_nPush;
+
unsigned
m_nPush;
private:
private:
- // any class wishing to process wxWi
ndow
s events must use this macro
+ // any class wishing to process wxWi
dget
s events must use this macro
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TABLE()
};
@@
-127,7
+120,7
@@
public:
}
private:
}
private:
-
size_t
m_level;
+
unsigned
m_level;
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TABLE()
};
@@
-159,10
+152,10
@@
enum
};
// ----------------------------------------------------------------------------
};
// ----------------------------------------------------------------------------
-// event tables and other macros for wxWi
ndow
s
+// event tables and other macros for wxWi
dget
s
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
-// the event tables connect the wxWi
ndow
s events with the functions (event
+// the event tables connect the wxWi
dget
s events with the functions (event
// 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)
// 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)
@@
-178,17
+171,18
@@
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_UPDATE_UI(Event_Pop, MyFrame::OnUpdateUIPop)
EVT_UPDATE_UI(Event_Pop, MyFrame::OnUpdateUIPop)
- EVT_MY_CUSTOM_COMMAND(
-1
, MyFrame::OnProcessCustom)
+ EVT_MY_CUSTOM_COMMAND(
wxID_ANY
, MyFrame::OnProcessCustom)
- // this would also work:
- //EVT_CUSTOM(wxEVT_MY_CUSTOM_COMMAND, -1, MyFrame::OnProcessCustom)
+ // the line below would also work if OnProcessCustom() were defined as
+ // taking a wxEvent (as required by EVT_CUSTOM) and not wxCommandEvent
+ //EVT_CUSTOM(wxEVT_MY_CUSTOM_COMMAND, wxID_ANY, MyFrame::OnProcessCustom)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
EVT_MENU(Event_Test, MyEvtHandler::OnTest)
END_EVENT_TABLE()
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
EVT_MENU(Event_Test, MyEvtHandler::OnTest)
END_EVENT_TABLE()
-// Create a new application object: this macro will allow wxWi
ndow
s to create
+// Create a new application object: this macro will allow wxWi
dget
s to create
// 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
// 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
@@
-207,17
+201,17
@@
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
// create the main application window
bool MyApp::OnInit()
{
// create the main application window
- MyFrame *frame = new MyFrame(_T("Event wxWi
ndow
s Sample"),
+ MyFrame *frame = new MyFrame(_T("Event wxWi
dget
s Sample"),
wxPoint(50, 50), wxSize(600, 340));
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
wxPoint(50, 50), wxSize(600, 340));
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
- frame->Show(
TRUE
);
+ frame->Show(
true
);
// success: wxApp::OnRun() will be called which will enter the main message
// success: wxApp::OnRun() will be called which will enter the main message
- // loop and the application will run. If we returned
FALSE
here, the
+ // loop and the application will run. If we returned
false
here, the
// application would exit immediately.
// application would exit immediately.
- return
TRUE
;
+ return
true
;
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
@@
-226,7
+220,7
@@
bool MyApp::OnInit()
// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
- : wxFrame((wxFrame *)NULL,
-1
, title, pos, size)
+ : wxFrame((wxFrame *)NULL,
wxID_ANY
, title, pos, size)
{
// init members
m_nPush = 0;
{
// init members
m_nPush = 0;
@@
-241,7
+235,7
@@
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
wxMenu *menuEvent = new wxMenu;
menuEvent->Append(Event_Connect, _T("&Connect\tCtrl-C"),
_T("Connect or disconnect the dynamic event handler"),
wxMenu *menuEvent = new wxMenu;
menuEvent->Append(Event_Connect, _T("&Connect\tCtrl-C"),
_T("Connect or disconnect the dynamic event handler"),
-
TRUE
/* checkable */);
+
true
/* checkable */);
menuEvent->Append(Event_Dynamic, _T("&Dynamic event\tCtrl-D"),
_T("Dynamic event sample - only works after Connect"));
menuEvent->AppendSeparator();
menuEvent->Append(Event_Dynamic, _T("&Dynamic event\tCtrl-D"),
_T("Dynamic event sample - only works after Connect"));
menuEvent->AppendSeparator();
@@
-265,7
+259,7
@@
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
#if wxUSE_STATUSBAR
CreateStatusBar(3);
#if wxUSE_STATUSBAR
CreateStatusBar(3);
- SetStatusText(_T("Welcome to wxWi
ndow
s event sample"));
+ SetStatusText(_T("Welcome to wxWi
dget
s event sample"));
SetStatusText(_T("Dynamic: off"), Status_Dynamic);
SetStatusText(_T("Push count: 0"), Status_Push);
#endif // wxUSE_STATUSBAR
SetStatusText(_T("Dynamic: off"), Status_Dynamic);
SetStatusText(_T("Push count: 0"), Status_Push);
#endif // wxUSE_STATUSBAR
@@
-277,7
+271,7
@@
MyFrame::~MyFrame()
// crashes!
while ( m_nPush-- != 0 )
{
// crashes!
while ( m_nPush-- != 0 )
{
- PopEventHandler(
TRUE
/* delete handler */);
+ PopEventHandler(
true
/* delete handler */);
}
}
}
}
@@
-287,15
+281,15
@@
MyFrame::~MyFrame()
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
- //
TRUE
is to force the frame to close
- Close(
TRUE
);
+ //
true
is to force the frame to close
+ Close(
true
);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
- wxMessageBox(
_T("Event sample shows different ways of using events\n"
-
"©
2001 Vadim Zeitlin"),
-
_T("About Event Sample"), wxOK | wxICON_INFORMATION, this
);
+ wxMessageBox(
wxT("Event sample shows different ways of using events\n")
+
wxT("(c)
2001 Vadim Zeitlin"),
+
wxT("About Event Sample"), wxOK | wxICON_INFORMATION, this
);
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
@@
-304,9
+298,12
@@
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnDynamic(wxCommandEvent& WXUNUSED(event))
{
void MyFrame::OnDynamic(wxCommandEvent& WXUNUSED(event))
{
- wxMessageBox(_T("This is a dynamic event handler which can be connected "
- "and disconnected during run-time."),
- _T("Dynamic Event Handler"), wxOK | wxICON_INFORMATION, this);
+ wxMessageBox
+ (
+ wxT("This is a dynamic event handler which can be connected ")
+ wxT("and disconnected at run-time."),
+ wxT("Dynamic Event Handler"), wxOK | wxICON_INFORMATION, this
+ );
}
void MyFrame::OnConnect(wxCommandEvent& event)
}
void MyFrame::OnConnect(wxCommandEvent& event)
@@
-314,20
+311,24
@@
void MyFrame::OnConnect(wxCommandEvent& event)
if ( event.IsChecked() )
{
// disconnect
if ( event.IsChecked() )
{
// disconnect
- Connect(Event_Dynamic,
-1
, wxEVT_COMMAND_MENU_SELECTED,
+ Connect(Event_Dynamic,
wxID_ANY
, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction)
(wxEventFunction)
(wxCommandEventFunction)&MyFrame::OnDynamic);
(wxObjectEventFunction)
(wxEventFunction)
(wxCommandEventFunction)&MyFrame::OnDynamic);
+#if wxUSE_STATUSBAR
SetStatusText(_T("You can now use \"Dynamic\" item in the menu"));
SetStatusText(_T("Dynamic: on"), Status_Dynamic);
SetStatusText(_T("You can now use \"Dynamic\" item in the menu"));
SetStatusText(_T("Dynamic: on"), Status_Dynamic);
+#endif // wxUSE_STATUSBAR
}
else // connect
{
}
else // connect
{
- Disconnect(Event_Dynamic,
-1
, wxEVT_COMMAND_MENU_SELECTED);
+ Disconnect(Event_Dynamic,
wxID_ANY
, wxEVT_COMMAND_MENU_SELECTED);
+#if wxUSE_STATUSBAR
SetStatusText(_T("You can no more use \"Dynamic\" item in the menu"));
SetStatusText(_T("Dynamic: off"), Status_Dynamic);
SetStatusText(_T("You can no more use \"Dynamic\" item in the menu"));
SetStatusText(_T("Dynamic: off"), Status_Dynamic);
+#endif // wxUSE_STATUSBAR
}
}
}
}
@@
-339,20
+340,24
@@
void MyFrame::OnPushEventHandler(wxCommandEvent& WXUNUSED(event))
{
PushEventHandler(new MyEvtHandler(++m_nPush));
{
PushEventHandler(new MyEvtHandler(++m_nPush));
+#if wxUSE_STATUSBAR
SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
+#endif // wxUSE_STATUSBAR
}
void MyFrame::OnPopEventHandler(wxCommandEvent& WXUNUSED(event))
{
wxCHECK_RET( m_nPush, _T("this command should be disabled!") );
}
void MyFrame::OnPopEventHandler(wxCommandEvent& WXUNUSED(event))
{
wxCHECK_RET( m_nPush, _T("this command should be disabled!") );
- PopEventHandler(
TRUE
/* delete handler */);
+ PopEventHandler(
true
/* delete handler */);
m_nPush--;
m_nPush--;
+#if wxUSE_STATUSBAR
SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
+#endif // wxUSE_STATUSBAR
}
}
-void MyFrame::OnTest(wxCommandEvent&
event
)
+void MyFrame::OnTest(wxCommandEvent&
WXUNUSED(event)
)
{
wxLogMessage(_T("This is the test event handler in the main frame"));
}
{
wxLogMessage(_T("This is the test event handler in the main frame"));
}
@@
-366,14
+371,14
@@
void MyFrame::OnUpdateUIPop(wxUpdateUIEvent& event)
// custom event methods
// ----------------------------------------------------------------------------
// custom event methods
// ----------------------------------------------------------------------------
-void MyFrame::OnFireCustom(wxCommandEvent&
event
)
+void MyFrame::OnFireCustom(wxCommandEvent&
WXUNUSED(event)
)
{
wxCommandEvent eventCustom(wxEVT_MY_CUSTOM_COMMAND);
wxPostEvent(this, eventCustom);
}
{
wxCommandEvent eventCustom(wxEVT_MY_CUSTOM_COMMAND);
wxPostEvent(this, eventCustom);
}
-void MyFrame::OnProcessCustom(wxCommandEvent&
event
)
+void MyFrame::OnProcessCustom(wxCommandEvent&
WXUNUSED(event)
)
{
wxLogMessage(_T("Got a custom event!"));
}
{
wxLogMessage(_T("Got a custom event!"));
}