]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/inpcons.h
we are always compositing on the supported OS versions, add transparency for individu...
[wxWidgets.git] / include / wx / univ / inpcons.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/inpcons.h
3 // Purpose: wxInputConsumer: mix-in class for input handling
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 14.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_INPCONS_H_
13 #define _WX_UNIV_INPCONS_H_
14
15 class WXDLLEXPORT wxInputHandler;
16 class WXDLLEXPORT wxWindow;
17
18 #include "wx/object.h"
19 #include "wx/event.h"
20
21 // ----------------------------------------------------------------------------
22 // wxControlAction: the action is currently just a string which identifies it,
23 // later it might become an atom (i.e. an opaque handler to string).
24 // ----------------------------------------------------------------------------
25
26 typedef wxString wxControlAction;
27
28 // the list of actions which apply to all controls (other actions are defined
29 // in the controls headers)
30
31 #define wxACTION_NONE _T("") // no action to perform
32
33 // ----------------------------------------------------------------------------
34 // wxInputConsumer: mix-in class for handling wxControlActions (used by
35 // wxControl and wxTopLevelWindow).
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxInputConsumer
39 {
40 public:
41 wxInputConsumer() { m_inputHandler = NULL; }
42 virtual ~wxInputConsumer() {}
43
44 // get the input handler
45 wxInputHandler *GetInputHandler() const { return m_inputHandler; }
46
47 // perform a control-dependent action: an action may have an optional
48 // numeric and another (also optional) string argument whose interpretation
49 // depends on the action
50 //
51 // NB: we might use ellipsis in PerformAction() declaration but this
52 // wouldn't be more efficient than always passing 2 unused parameters
53 // but would be more difficult. Another solution would be to have
54 // several overloaded versions but this will expose the problem of
55 // virtual function hiding we don't have here.
56 virtual bool PerformAction(const wxControlAction& action,
57 long numArg = -1l,
58 const wxString& strArg = wxEmptyString);
59
60 // get the window to work with (usually the class wxInputConsumer was mixed into)
61 virtual wxWindow *GetInputWindow() const = 0;
62
63 protected:
64 // event handlers
65 void OnMouse(wxMouseEvent& event);
66 void OnKeyDown(wxKeyEvent& event);
67 void OnKeyUp(wxKeyEvent& event);
68 void OnFocus(wxFocusEvent& event);
69 void OnActivate(wxActivateEvent& event);
70
71 // create input handler by name
72 void CreateInputHandler(const wxString& inphandler);
73
74 // input processor (never deleted, the theme deletes it itself)
75 wxInputHandler *m_inputHandler;
76 };
77
78
79 // ----------------------------------------------------------------------------
80 // macros which must be used by the classes derived from wxInputConsumer mix-in
81 // ----------------------------------------------------------------------------
82
83 // declare the methods to be forwarded
84 #define WX_DECLARE_INPUT_CONSUMER() \
85 private: \
86 void OnMouse(wxMouseEvent& event); \
87 void OnKeyDown(wxKeyEvent& event); \
88 void OnKeyUp(wxKeyEvent& event); \
89 void OnFocus(wxFocusEvent& event); \
90 public: /* because of docview :-( */ \
91 void OnActivate(wxActivateEvent& event); \
92 private:
93
94 // implement the event table entries for wxControlContainer
95 #define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \
96 EVT_KEY_DOWN(classname::OnKeyDown) \
97 EVT_KEY_UP(classname::OnKeyUp) \
98 EVT_MOUSE_EVENTS(classname::OnMouse) \
99 EVT_SET_FOCUS(classname::OnFocus) \
100 EVT_KILL_FOCUS(classname::OnFocus) \
101 EVT_ACTIVATE(classname::OnActivate)
102
103 // Forward event handlers to wxInputConsumer
104 //
105 // (We can't use them directly, because wxIC has virtual methods, which forces
106 // the compiler to include (at least) two vtables into wxControl, one for the
107 // wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in.
108 // Consequently, the "this" pointer has different value when in wxControl's
109 // and wxIC's method, even though the instance stays same. This doesn't matter
110 // so far as member pointers aren't used, but that's not wxControl's case.
111 // When we add an event table entry (= use a member pointer) pointing to
112 // wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the
113 // version of "this" that belongs to wxControl, not wxIC! In our particular
114 // case, the effect is that m_handler is NULL (probably same memory
115 // area as the_other_vtable's_this->m_refObj) and input handling doesn't work.)
116 #define WX_FORWARD_TO_INPUT_CONSUMER(classname) \
117 void classname::OnMouse(wxMouseEvent& event) \
118 { \
119 wxInputConsumer::OnMouse(event); \
120 } \
121 void classname::OnKeyDown(wxKeyEvent& event) \
122 { \
123 wxInputConsumer::OnKeyDown(event); \
124 } \
125 void classname::OnKeyUp(wxKeyEvent& event) \
126 { \
127 wxInputConsumer::OnKeyUp(event); \
128 } \
129 void classname::OnFocus(wxFocusEvent& event) \
130 { \
131 wxInputConsumer::OnFocus(event); \
132 } \
133 void classname::OnActivate(wxActivateEvent& event) \
134 { \
135 wxInputConsumer::OnActivate(event); \
136 }
137
138 #endif // _WX_UNIV_INPCONS_H_