]> git.saurik.com Git - wxWidgets.git/blob - include/wx/evtloopsrc.h
Add wxWebView backend wxUSE_ macros
[wxWidgets.git] / include / wx / evtloopsrc.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/evtloopsrc.h
3 // Purpose: declaration of wxEventLoopSource class
4 // Author: Vadim Zeitlin
5 // Created: 2009-10-21
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_EVTLOOPSRC_H_
12 #define _WX_EVTLOOPSRC_H_
13
14 // ----------------------------------------------------------------------------
15 // wxEventLoopSource: a source of events which may be added to wxEventLoop
16 // ----------------------------------------------------------------------------
17
18 // TODO: refactor wxSocket under Unix to reuse wxEventLoopSource instead of
19 // duplicating much of its logic
20 //
21 // TODO: freeze the API and document it
22
23 #if wxUSE_EVENTLOOP_SOURCE
24
25 #define wxTRACE_EVT_SOURCE "EventSource"
26
27 // handler used to process events on event loop sources
28 class wxEventLoopSourceHandler
29 {
30 public:
31 // called when descriptor is available for non-blocking read
32 virtual void OnReadWaiting() = 0;
33
34 // called when descriptor is available for non-blocking write
35 virtual void OnWriteWaiting() = 0;
36
37 // called when there is exception on descriptor
38 virtual void OnExceptionWaiting() = 0;
39
40 // virtual dtor for the base class
41 virtual ~wxEventLoopSourceHandler() { }
42 };
43
44 // flags describing which kind of IO events we're interested in
45 enum
46 {
47 wxEVENT_SOURCE_INPUT = 0x01,
48 wxEVENT_SOURCE_OUTPUT = 0x02,
49 wxEVENT_SOURCE_EXCEPTION = 0x04,
50 wxEVENT_SOURCE_ALL = wxEVENT_SOURCE_INPUT |
51 wxEVENT_SOURCE_OUTPUT |
52 wxEVENT_SOURCE_EXCEPTION,
53 };
54
55 // wxEventLoopSource itself is an ABC and can't be created directly, currently
56 // the only way to create it is by using wxEventLoop::AddSourceForFD().
57 class wxEventLoopSource
58 {
59 public:
60 // dtor is pure virtual because it must be overridden to remove the source
61 // from the event loop monitoring it
62 virtual ~wxEventLoopSource() = 0;
63
64 void SetHandler(wxEventLoopSourceHandler* handler) { m_handler = handler; }
65 wxEventLoopSourceHandler* GetHandler() const { return m_handler; }
66
67 void SetFlags(int flags) { m_flags = flags; }
68 int GetFlags() const { return m_flags; }
69
70 protected:
71 // ctor is only used by the derived classes
72 wxEventLoopSource(wxEventLoopSourceHandler *handler, int flags)
73 : m_handler(handler),
74 m_flags(flags)
75 {
76 }
77
78 wxEventLoopSourceHandler* m_handler;
79 int m_flags;
80
81 wxDECLARE_NO_COPY_CLASS(wxEventLoopSource);
82 };
83
84 inline wxEventLoopSource::~wxEventLoopSource() { }
85
86 #if defined(__UNIX__)
87 #include "wx/unix/evtloopsrc.h"
88 #endif // __UNIX__
89
90 #if defined(__WXGTK20__)
91 #include "wx/gtk/evtloopsrc.h"
92 #elif defined(__WXOSX__)
93 #include "wx/osx/evtloopsrc.h"
94 #endif // platform
95
96 #endif // wxUSE_EVENTLOOP_SOURCE
97
98 #endif // _WX_EVTLOOPSRC_H_
99