]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/event/event.cpp
fix handling of long lines in wxGridCellAutoWrapStringRenderer
[wxWidgets.git] / samples / event / event.cpp
index ee1b87c5e77dd35c64d9d2b9439a4294046d3e70..4b07cd06e4da523cb766085d00ba99a2455dd494 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(__APPLE__)
-    // 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"
 
     #include "wx/wx.h"
 #endif
 
+#ifndef __WXMSW__
+    #include "../sample.xpm"
+#endif
+
 // ----------------------------------------------------------------------------
 // event constants
 // ----------------------------------------------------------------------------
 
-// declare a custom event type
-//
-// note that in wxWin 2.3+ these macros expand simply into the following code:
-//
-//  extern const wxEventType wxEVT_MY_CUSTOM_COMMAND;
-//
-//  const wxEventType wxEVT_MY_CUSTOM_COMMAND = wxNewEventType();
-//
-// and you may use this code directly if you don't care about 2.2 compatibility
-BEGIN_DECLARE_EVENT_TYPES()
-    DECLARE_EVENT_TYPE(wxEVT_MY_CUSTOM_COMMAND, 7777)
-END_DECLARE_EVENT_TYPES()
-
-DEFINE_EVENT_TYPE(wxEVT_MY_CUSTOM_COMMAND)
+// define a custom event type (we don't need a separate declaration here but
+// usually you would use a matching wxDECLARE_EVENT in a header)
+wxDEFINE_EVENT(wxEVT_MY_CUSTOM_COMMAND, wxCommandEvent);
 
 // 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, wxID_ANY, \
-        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
+        wxCommandEventHandler(fn), \
         (wxObject *) NULL \
     ),
 
@@ -104,7 +90,7 @@ public:
 
 protected:
     // number of pushed event handlers
-    size_t m_nPush;
+    unsigned m_nPush;
 
 private:
     // any class wishing to process wxWidgets events must use this macro
@@ -127,7 +113,7 @@ public:
     }
 
 private:
-    size_t m_level;
+    unsigned m_level;
 
     DECLARE_EVENT_TABLE()
 };
@@ -180,7 +166,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 
     EVT_MY_CUSTOM_COMMAND(wxID_ANY, MyFrame::OnProcessCustom)
 
-    // this would also work:
+    // 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()
 
@@ -206,6 +193,9 @@ IMPLEMENT_APP(MyApp)
 // 'Main program' equivalent: the program execution "starts" here
 bool MyApp::OnInit()
 {
+    if ( !wxApp::OnInit() )
+        return false;
+
     // create the main application window
     MyFrame *frame = new MyFrame(_T("Event wxWidgets Sample"),
                                  wxPoint(50, 50), wxSize(600, 340));
@@ -228,6 +218,8 @@ bool MyApp::OnInit()
 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
        : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
 {
+    SetIcon(wxICON(sample));
+
     // init members
     m_nPush = 0;
 
@@ -294,7 +286,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
     wxMessageBox( wxT("Event sample shows different ways of using events\n")
-                  wxT("© 2001 Vadim Zeitlin"),
+                  wxT("(c) 2001 Vadim Zeitlin"),
                   wxT("About Event Sample"), wxOK | wxICON_INFORMATION, this );
 }
 
@@ -316,21 +308,23 @@ void MyFrame::OnConnect(wxCommandEvent& event)
 {
     if ( event.IsChecked() )
     {
-        // disconnect
-        Connect(Event_Dynamic, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
-                (wxObjectEventFunction)
-                (wxEventFunction)
-                (wxCommandEventFunction)&MyFrame::OnDynamic);
+        Connect(Event_Dynamic, wxEVT_COMMAND_MENU_SELECTED,
+                wxCommandEventHandler(MyFrame::OnDynamic));
 
+#if wxUSE_STATUSBAR
         SetStatusText(_T("You can now use \"Dynamic\" item in the menu"));
         SetStatusText(_T("Dynamic: on"), Status_Dynamic);
+#endif // wxUSE_STATUSBAR
     }
-    else // connect
+    else // disconnect
     {
-        Disconnect(Event_Dynamic, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED);
+        Disconnect(Event_Dynamic, wxEVT_COMMAND_MENU_SELECTED,
+                   wxCommandEventHandler(MyFrame::OnDynamic));
 
+#if wxUSE_STATUSBAR
         SetStatusText(_T("You can no more use \"Dynamic\" item in the menu"));
         SetStatusText(_T("Dynamic: off"), Status_Dynamic);
+#endif // wxUSE_STATUSBAR
     }
 }
 
@@ -342,7 +336,9 @@ void MyFrame::OnPushEventHandler(wxCommandEvent& WXUNUSED(event))
 {
     PushEventHandler(new MyEvtHandler(++m_nPush));
 
+#if wxUSE_STATUSBAR
     SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
+#endif // wxUSE_STATUSBAR
 }
 
 void MyFrame::OnPopEventHandler(wxCommandEvent& WXUNUSED(event))
@@ -352,7 +348,9 @@ void MyFrame::OnPopEventHandler(wxCommandEvent& WXUNUSED(event))
     PopEventHandler(true /* delete handler */);
     m_nPush--;
 
+#if wxUSE_STATUSBAR
     SetStatusText(wxString::Format(_T("Push count: %u"), m_nPush), Status_Push);
+#endif // wxUSE_STATUSBAR
 }
 
 void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event))