class WXDLLIMPEXP_FWD_CORE wxWindowBase;
#endif // wxUSE_GUI
-class WXDLLIMPEXP_FWD_BASE wxEvtHandler;
+// We operate with pointer to members of wxEvtHandler (such functions are used
+// as event handlers in the event tables or as arguments to Connect()) but by
+// default MSVC uses a restricted (but more efficient) representation of
+// pointers to members which can't deal with multiple base classes. To avoid
+// mysterious (as the compiler is not good enough to detect this and give a
+// sensible error message) errors in the user code as soon as it defines
+// classes inheriting from both wxEvtHandler (possibly indirectly, e.g. via
+// wxWindow) and something else (including our own wxTrackable but not limited
+// to it), we use the special MSVC keyword telling the compiler to use a more
+// general pointer to member representation for the classes inheriting from
+// wxEvtHandler.
+#ifdef __VISUALC__
+ #define wxMSVC_FWD_MULTIPLE_BASES __multiple_inheritance
+#else
+ #define wxMSVC_FWD_MULTIPLE_BASES
+#endif
+
+class WXDLLIMPEXP_FWD_BASE wxMSVC_FWD_MULTIPLE_BASES wxEvtHandler;
class wxEventConnectionRef;
// ----------------------------------------------------------------------------
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED;
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOL_ENTER;
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SPINCTRL_UPDATED;
+extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED;
// Sockets and timers send events, too
extern WXDLLIMPEXP_BASE const wxEventType wxEVT_SOCKET;
// event handler and related classes
// ============================================================================
-// for backwards compatibility and to prevent eVC 4 for ARM from crashing with
-// internal compiler error when compiling wx, we define wxObjectEventFunction
-// as a wxObject method even though it can only be a wxEvtHandler one
-typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
+typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
+
+// We had some trouble (specifically with eVC for ARM WinCE build) with using
+// wxEventFunction in the past so we had introduced wxObjectEventFunction which
+// used to be a typedef for a member of wxObject and not wxEvtHandler to work
+// around this but as eVC is not really supported any longer we now only keep
+// this for backwards compatibility and, despite its name, this is a typedef
+// for wxEvtHandler member now -- but if we have the same problem with another
+// compiler we can restore its old definition for it.
+typedef wxEventFunction wxObjectEventFunction;
// struct containing the members common to static and dynamic event tables
// entries
// wxEvtHandler: the base class for all objects handling wxWidgets events
// ----------------------------------------------------------------------------
-class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject, public wxTrackable
+class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject
+ , public wxTrackable
{
public:
wxEvtHandler();
void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
bool GetEvtHandlerEnabled() const { return m_enabled; }
- // process an event right now
+ // 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.
virtual bool ProcessEvent(wxEvent& event);
// Process an event by calling ProcessEvent and handling any exceptions
// wouldn't correctly propagate to wxEventLoop.
bool SafelyProcessEvent(wxEvent& event);
- // add an event to be processed later
- virtual void AddPendingEvent(const wxEvent& event);
+ // Schedule the given event to be processed later. It takes ownership of
+ // the event pointer, i.e. it will be deleted later. This is safe to call
+ // from multiple threads although you still need to ensure that wxString
+ // fields of the event object are deep copies and not use the same string
+ // buffer as other wxString objects in this thread.
+ virtual void QueueEvent(wxEvent *event);
+
+ // Add an event to be processed later: notice that this function is not
+ // safe to call from threads other than main, use QueueEvent()
+ virtual void AddPendingEvent(const wxEvent& event)
+ {
+ // notice that the thread-safety problem comes from the fact that
+ // Clone() doesn't make deep copies of wxString fields of wxEvent
+ // object and so the same wxString could be used from both threads when
+ // the event object is destroyed in this one -- QueueEvent() avoids
+ // this problem as the event pointer is not used any more in this
+ // thread at all after it is called.
+ QueueEvent(event.Clone());
+ }
void ProcessPendingEvents();
DECLARE_NO_ASSIGN_CLASS(wxEventConnectionRef)
};
-// Post a message to the given eventhandler which will be processed during the
-// next event loop iteration
+// Post a message to the given event handler which will be processed during the
+// next event loop iteration.
+//
+// Notice that this one is not thread-safe, use wxQueueEvent()
inline void wxPostEvent(wxEvtHandler *dest, const wxEvent& event)
{
- wxCHECK_RET( dest, wxT("need an object to post event to in wxPostEvent") );
+ wxCHECK_RET( dest, "need an object to post event to" );
dest->AddPendingEvent(event);
}
+// Wrapper around wxEvtHandler::QueueEvent(): adds an event for later
+// processing, unlike wxPostEvent it is safe to use from different thread even
+// for events with wxString members
+inline void wxQueueEvent(wxEvtHandler *dest, wxEvent *event)
+{
+ wxCHECK_RET( dest, "need an object to queue event for" );
+
+ dest->QueueEvent(event);
+}
+
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
+typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&);
#define wxEventHandler(func) \
(wxObjectEventFunction)wxStaticCastEvent(wxEventFunction, &func)
+#define wxIdleEventHandler(func) \
+ (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxIdleEventFunction, &func)
#if wxUSE_GUI
typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&);
typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&);
typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&);
-typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&);
typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&);
typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&);
typedef void (wxEvtHandler::*wxIconizeEventFunction)(wxIconizeEvent&);
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDisplayChangedEventFunction, &func)
#define wxUpdateUIEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxUpdateUIEventFunction, &func)
-#define wxIdleEventHandler(func) \
- (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxIdleEventFunction, &func)
#define wxCloseEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCloseEventFunction, &func)
#define wxShowEventHandler(func) \