#define wxDECLARE_EVENT( name, type ) \
wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type );
- // Try to cast the given event handler to the correct handler type:
-
- #define wxEVENT_HANDLER_CAST( functype, func ) \
- ( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
#else
// Define/Declare a templatized event type with the corresponding event as
// a nested typedef:
#define wxDECLARE_EVENT( name, type ) \
wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type );
- // Don't cast the given event handler so that wxEvtHandler::Connect() sees
- // the actual type:
-
- #define wxEVENT_HANDLER_CAST( functype, func ) \
- ( &func )
#endif
+// Try to cast the given event handler to the correct handler type:
+
+#define wxEVENT_HANDLER_CAST( functype, func ) \
+ ( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
+
// Template which associates the correct event object with the event type
#if !wxEVENTS_COMPATIBILITY_2_8
m_method = method;
}
- virtual void operator()(wxEvtHandler *handler, wxEvent& event)
- {
- wxEvtHandler * const realHandler = m_handler ? m_handler : handler;
-
- (realHandler->*m_method)(event);
- }
+ virtual void operator()(wxEvtHandler *handler, wxEvent& event);
virtual bool Matches(const wxEventFunctor& func) const
{
<
Class,
EventArg,
- wxConvertibleTo<Class, wxEvtHandler>::value
+ wxConvertibleTo<Class, wxEvtHandler>::value != 0
>
{
private:
// used in wxEventLoopBase::YieldFor to specify all event categories should be processed:
wxEVT_CATEGORY_ALL =
wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT|wxEVT_CATEGORY_SOCKET| \
- wxEVT_CATEGORY_TIMER|wxEVT_CATEGORY_THREAD
+ wxEVT_CATEGORY_TIMER|wxEVT_CATEGORY_THREAD|wxEVT_CATEGORY_UNKNOWN| \
+ wxEVT_CATEGORY_CLIPBOARD
};
/*
: wxCommandEvent(eventType, id)
{ }
+ wxThreadEvent(const wxThreadEvent& event)
+ : wxCommandEvent(event)
+ {
+ // make sure our string member (which uses COW, aka refcounting) is not
+ // shared by other wxString instances:
+ SetString(GetString().c_str());
+ }
+
virtual wxEvent *Clone() const
{
wxThreadEvent* ev = new wxThreadEvent(*this);
virtual wxEvent *Clone() const { return new wxNavigationKeyEvent(*this); }
- enum
+ enum wxNavigationKeyEventFlags
{
IsBackward = 0x0000,
IsForward = 0x0001,
// Event queuing and processing
// ----------------------------
-
// Process an event right now: this can only be called from the main
// thread, use QueueEvent() for scheduling the events for
// processing from other threads.
void ProcessPendingEvents();
// NOTE: uses ProcessEvent()
+ void DeletePendingEvents();
+
#if wxUSE_THREADS
bool ProcessThreadEvent(const wxEvent& event);
- // NOTE: uses AddPendingEvent()
+ // NOTE: uses AddPendingEvent(); call only from secondary threads
#endif
{ return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
#if !wxEVENTS_COMPATIBILITY_2_8
- // Event handling in functions (including generalized functors):
-
- template <typename EventTag, typename Functor>
- void Connect(int winid,
- int lastId,
- const EventTag& eventType,
- Functor func)
- {
- DoConnect(winid, lastId, eventType,
- wxNewEventFunctor(eventType, func));
- }
-
- template <typename EventTag, typename Functor>
- void Connect(int winid, const EventTag& eventType, Functor func)
- { Connect(winid, wxID_ANY, eventType, func); }
-
- template <typename EventTag, typename Functor>
- void Connect(const EventTag& eventType, Functor func)
- { Connect(wxID_ANY, eventType, func); }
-
-
- template <typename EventTag, typename Functor>
- bool Disconnect(int winid,
- int lastId,
- const EventTag& eventType,
- Functor func)
- {
- return DoDisconnect(winid, lastId, eventType,
- wxMakeEventFunctor(eventType, func));
- }
-
- template <typename EventTag, typename Functor>
- bool Disconnect(int winid, const EventTag& eventType, Functor func)
- { return Disconnect(winid, wxID_ANY, eventType, func); }
-
+ // Bind arbitrary functor (including just a function) to an event:
template <typename EventTag, typename Functor>
- bool Disconnect(const EventTag& eventType, Functor func)
- { return Disconnect(wxID_ANY, eventType, func); }
-
-
-
- // Event handling in class methods: the object handling the event (i.e.
- // this object itself by default or eventSink if specified) must be
- // convertible to this class.
- //
- // Notice that we need to have separate overloads for the versions with and
- // without eventSink because in the latter case we must check that this
- // object itself derives from Class while in the former this is not
- // necessarily true
-
- // Methods connecting/disconnecting event to this object itself
-
- template <typename EventTag, typename Class, typename EventArg>
- void Connect(int winid,
- int lastId,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL)
+ void Bind(const EventTag& eventType,
+ Functor func,
+ int winid = wxID_ANY,
+ int lastId = wxID_ANY,
+ wxObject *userData = NULL)
{
DoConnect(winid, lastId, eventType,
- wxNewEventFunctor(eventType, func, static_cast<Class *>(this)),
+ wxNewEventFunctor(eventType, func),
userData);
}
- template <typename EventTag, typename Class, typename EventArg>
- void Connect(int winid,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL)
- { Connect(winid, wxID_ANY, eventType, func, userData); }
-
- template <typename EventTag, typename Class, typename EventArg>
- void Connect(const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL)
- { Connect(wxID_ANY, eventType, func, userData); }
-
- template <typename EventTag, typename Class, typename EventArg>
- bool Disconnect(int winid,
- int lastId,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL)
+ template <typename EventTag, typename Functor>
+ bool Unbind(const EventTag& eventType,
+ Functor func,
+ int winid = wxID_ANY,
+ int lastId = wxID_ANY,
+ wxObject *userData = NULL)
{
return DoDisconnect(winid, lastId, eventType,
- wxMakeEventFunctor(eventType, func,
- static_cast<Class *>(this)),
+ wxMakeEventFunctor(eventType, func),
userData);
}
- template <typename EventTag, typename Class, typename EventArg>
- bool Disconnect(int winid,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL)
- { return Disconnect(winid, wxID_ANY, eventType, func, userData); }
- template <typename EventTag, typename Class, typename EventArg>
- bool Disconnect(const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL)
- { return Disconnect(wxID_ANY, eventType, func, userData); }
-
-
- // Methods connecting/disconnecting event to another object
+ // Bind a method of a class (called on the specified eventSink which must
+ // be convertible to this class) object to an event:
template
<typename EventTag, typename Class, typename EventArg, typename ObjClass>
- void Connect(int winid,
- int lastId,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData,
- ObjClass *eventSink)
+ void Bind(const EventTag &eventType,
+ void (Class::*func)(EventArg &),
+ ObjClass *eventSink,
+ int winid = wxID_ANY,
+ int lastId = wxID_ANY,
+ wxObject *userData = NULL)
{
DoConnect(winid, lastId, eventType,
wxNewEventFunctor(eventType, func, eventSink),
template
<typename EventTag, typename Class, typename EventArg, typename ObjClass>
- void Connect(int winid,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData,
- ObjClass *eventSink)
- { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
-
- template
- <typename EventTag, typename Class, typename EventArg, typename ObjClass>
- void Connect(const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData,
- ObjClass *eventSink)
- { Connect(wxID_ANY, eventType, func, userData, eventSink); }
-
-
- template
- <typename EventTag, typename Class, typename EventArg, typename ObjClass>
- bool Disconnect(int winid,
- int lastId,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData,
- ObjClass *eventSink)
+ bool Unbind(const EventTag &eventType,
+ void (Class::*func)(EventArg&),
+ ObjClass *eventSink,
+ int winid = wxID_ANY,
+ int lastId = wxID_ANY,
+ wxObject *userData = NULL )
{
return DoDisconnect(winid, lastId, eventType,
wxMakeEventFunctor(eventType, func, eventSink),
userData);
}
-
- template
- <typename EventTag, typename Class, typename EventArg, typename ObjClass>
- bool Disconnect(int winid,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData,
- ObjClass *eventSink)
- { return Disconnect(winid, wxID_ANY, eventType, func,
- userData, eventSink); }
-
- template
- <typename EventTag, typename Class, typename EventArg, typename ObjClass>
- bool Disconnect(const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData,
- ObjClass *eventSink)
- { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
-
-
-
- // Static version of Connect() which allows to specify the event source and
- // event handler in a more symmetric way
- template <typename ObjSource, typename EventTag,
- typename Class, typename EventArg, typename ObjClass>
- static void Connect(ObjSource *eventSrc,
- int winid,
- int lastId,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL,
- ObjClass *eventSink = NULL)
- {
- eventSrc->Connect(winid, lastId, eventType, func, userData, eventSink);
- }
-
- template <typename ObjSource, typename EventTag,
- typename Class, typename EventArg, typename ObjClass>
- static void Connect(ObjSource *eventSrc,
- int winid,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL,
- ObjClass *eventSink = NULL)
- {
- Connect(eventSrc, winid, wxID_ANY, eventType, func, userData, eventSink);
- }
-
- template <typename ObjSource, typename EventTag,
- typename Class, typename EventArg, typename ObjClass>
- static void Connect(ObjSource *eventSrc,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL,
- ObjClass *eventSink = NULL)
- {
- Connect(eventSrc, wxID_ANY, eventType, func, userData, eventSink);
- }
-
-
- template <typename ObjSource, typename EventTag,
- typename Class, typename EventArg, typename ObjClass>
- static bool Disconnect(ObjSource *eventSrc,
- int winid,
- int lastId,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL,
- ObjClass *eventSink = NULL)
- {
- return eventSrc->Disconnect(winid, lastId, eventType, func,
- userData, eventSink);
- }
-
- template <typename ObjSource, typename EventTag,
- typename Class, typename EventArg, typename ObjClass>
- static bool Disconnect(ObjSource *eventSrc,
- int winid,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL,
- ObjClass *eventSink = NULL)
- {
- return Disconnect(eventSrc, winid, wxID_ANY, eventType, func,
- userData, eventSink);
- }
-
- template <typename ObjSource, typename EventTag,
- typename Class, typename EventArg, typename ObjClass>
- static bool Disconnect(ObjSource *eventSrc,
- const EventTag& eventType,
- void (Class::*func)(EventArg&),
- wxObject *userData = NULL,
- ObjClass *eventSink = NULL)
- {
- return Disconnect(eventSrc, wxID_ANY, eventType, func,
- userData, eventSink);
- }
#endif // !wxEVENTS_COMPATIBILITY_2_8
-
wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
// User data can be associated with each wxEvtHandler
//
// It is meant to be called from ProcessEvent() only and is not virtual,
// additional event handlers can be hooked into the normal event processing
- // logic using TryValidator() hook.
+ // logic using TryBefore() and TryAfter() hooks.
bool ProcessEventHere(wxEvent& event);
// hooks for wxWindow used by ProcessEvent()
// -----------------------------------------
- // This one is called before trying our own event table to allow plugging
- // in the validators.
- //
- // NB: This method is intentionally *not* inside wxUSE_VALIDATORS!
- // It is part of wxBase which doesn't use validators and the code
- // is compiled out when building wxBase w/o GUI classes, which affects
- // binary compatibility and wxBase library can't be used by GUI
- // ports.
- virtual bool TryValidator(wxEvent& WXUNUSED(event)) { return false; }
+ // this one is called before trying our own event table to allow plugging
+ // in the event handlers overriding the default logic, this is used by e.g.
+ // validators.
+ virtual bool TryBefore(wxEvent& event);
// this one is called after failing to find the event handle in our own
// table to give a chance to the other windows to process it
//
// base class implementation passes the event to wxTheApp
- virtual bool TryParent(wxEvent& event);
+ virtual bool TryAfter(wxEvent& event);
+
+#ifdef WXWIN_COMPATIBILITY_2_8
+ // deprecated method: override TryBefore() instead of this one
+ wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
+ virtual bool TryValidator(wxEvent& WXUNUSED(event)), return false; )
+
+ wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
+ virtual bool TryParent(wxEvent& event), return DoTryApp(event); )
+#endif // WXWIN_COMPATIBILITY_2_8
static const wxEventTable sm_eventTable;
wxEventConnectionRef *FindRefInTrackerList(wxEvtHandler *eventSink);
private:
+ // pass the event to wxTheApp instance, called from TryAfter()
+ bool DoTryApp(wxEvent& event);
+
DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler)
};
-WX_DEFINE_EXPORTED_ARRAY_PTR(wxEvtHandler*, wxEvtHandlerArray);
+WX_DEFINE_ARRAY_WITH_DECL_PTR(wxEvtHandler *, wxEvtHandlerArray, class WXDLLIMPEXP_BASE);
// ----------------------------------------------------------------------------
// wxEventConnectionRef represents all connections between two event handlers
wxDECLARE_NO_ASSIGN_CLASS(wxEventConnectionRef);
};
+inline void wxObjectEventFunctor::operator()(wxEvtHandler *handler, wxEvent& event)
+{
+ wxEvtHandler * const realHandler = m_handler ? m_handler : handler;
+
+ (realHandler->*m_method)(event);
+}
+
// Post a message to the given event handler which will be processed during the
// next event loop iteration.
//
// Helper functions
// ----------------------------------------------------------------------------
+// This is an ugly hack to allow the use of Bind() instead of Connect() inside
+// the library code if the library was built with support for it, here is how
+// it is used:
+//
+// class SomeEventHandlingClass : wxBIND_OR_CONNECT_HACK_BASE_CLASS
+// public SomeBaseClass
+// {
+// public:
+// SomeEventHandlingClass(wxWindow *win)
+// {
+// // connect to the event for the given window
+// wxBIND_OR_CONNECT_HACK(win, wxEVT_SOMETHING, wxSomeEventHandler,
+// SomeEventHandlingClass::OnSomeEvent, this);
+// }
+//
+// private:
+// void OnSomeEvent(wxSomeEvent&) { ... }
+// };
+//
+// This is *not* meant to be used by library users, it is only defined here
+// (and not in a private header) because the base class must be visible from
+// other public headers, please do NOT use this in your code, it will be
+// removed from future wx versions without warning.
+#if wxEVENTS_COMPATIBILITY_2_8
+ #define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler,
+ #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler
+ #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
+ win->Connect(evt, handler(func), NULL, obj)
+#else // wxEVENTS_COMPATIBILITY_2_8
+ #define wxBIND_OR_CONNECT_HACK_BASE_CLASS
+ #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
+ #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
+ win->Bind(evt, &func, obj)
+#endif // wxEVENTS_COMPATIBILITY_2_8/!wxEVENTS_COMPATIBILITY_2_8
+
#if wxUSE_GUI
// Find a window with the focus, that is also a descendant of the given window.