Home | History | Annotate | Download | only in app
      1 //
      2 // Copyright 2005 The Android Open Source Project
      3 //
      4 // A "user event" for wxWidgets.
      5 //
      6 #ifndef _SIM_USER_EVENT_H
      7 #define _SIM_USER_EVENT_H
      8 
      9 /*
     10  * Event declaration.  The book says to use DECLARE_EVENT_TYPE, but that
     11  * causes a compiler warning and a link failure with gcc under MinGW.
     12  *
     13  * It looks like the "magic number", in this case 12345, is just picked
     14  * by hand.  There may be a better mechanism in this version of
     15  * wxWidgets, but the documentation and sample code doesn't reflect it.
     16  */
     17 BEGIN_DECLARE_EVENT_TYPES()
     18     DECLARE_LOCAL_EVENT_TYPE(wxEVT_USER_EVENT, 12345)
     19 END_DECLARE_EVENT_TYPES()
     20 
     21 /*
     22  * A "user event" class.  This can be used like any other wxWidgets
     23  * event, but we get to stuff anything we want to in it.
     24  */
     25 class UserEvent : public wxEvent {
     26 public:
     27     UserEvent(int id = 0, void* data = (void*) 0)
     28         : wxEvent(id, wxEVT_USER_EVENT), mData(data)
     29         {}
     30     UserEvent(const UserEvent& event)
     31         : wxEvent(event), mData(event.mData)
     32         {}
     33 
     34     virtual wxEvent* Clone() const {
     35         return new UserEvent(*this);
     36     }
     37 
     38     void* GetData(void) const { return mData; }
     39 
     40     DECLARE_DYNAMIC_CLASS(UserEvent);
     41 
     42 private:
     43     UserEvent& operator=(const UserEvent&);     // not implemented
     44     void*   mData;
     45 };
     46 
     47 typedef void (wxEvtHandler::*UserEventFunction)(UserEvent&);
     48 
     49 #define EVT_USER_EVENT(fn) \
     50         DECLARE_EVENT_TABLE_ENTRY(wxEVT_USER_EVENT, wxID_ANY, wxID_ANY, \
     51             (wxObjectEventFunction)(wxEventFunction)(UserEventFunction)&fn, \
     52             (wxObject*) NULL ),
     53 
     54 #endif // _SIM_USER_EVENT_H
     55