]>
Commit | Line | Data |
---|---|---|
23645bfa VS |
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 | |
23645bfa | 7 | // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 8 | // Licence: wxWindows licence |
23645bfa VS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_UNIV_INPCONS_H_ | |
12 | #define _WX_UNIV_INPCONS_H_ | |
13 | ||
b5dbe15d VS |
14 | class WXDLLIMPEXP_FWD_CORE wxInputHandler; |
15 | class WXDLLIMPEXP_FWD_CORE wxWindow; | |
23645bfa VS |
16 | |
17 | #include "wx/object.h" | |
18 | #include "wx/event.h" | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // wxControlAction: the action is currently just a string which identifies it, | |
22 | // later it might become an atom (i.e. an opaque handler to string). | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | typedef wxString wxControlAction; | |
26 | ||
27 | // the list of actions which apply to all controls (other actions are defined | |
28 | // in the controls headers) | |
29 | ||
9a83f860 | 30 | #define wxACTION_NONE wxT("") // no action to perform |
23645bfa VS |
31 | |
32 | // ---------------------------------------------------------------------------- | |
23ff76d5 | 33 | // wxInputConsumer: mix-in class for handling wxControlActions (used by |
23645bfa VS |
34 | // wxControl and wxTopLevelWindow). |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
53a2db12 | 37 | class WXDLLIMPEXP_CORE wxInputConsumer |
23645bfa VS |
38 | { |
39 | public: | |
6463b9f5 | 40 | wxInputConsumer() { m_inputHandler = NULL; } |
9467bdb7 | 41 | virtual ~wxInputConsumer() { } |
23645bfa VS |
42 | |
43 | // get the input handler | |
44 | wxInputHandler *GetInputHandler() const { return m_inputHandler; } | |
45 | ||
46 | // perform a control-dependent action: an action may have an optional | |
47 | // numeric and another (also optional) string argument whose interpretation | |
48 | // depends on the action | |
49 | // | |
50 | // NB: we might use ellipsis in PerformAction() declaration but this | |
51 | // wouldn't be more efficient than always passing 2 unused parameters | |
52 | // but would be more difficult. Another solution would be to have | |
53 | // several overloaded versions but this will expose the problem of | |
54 | // virtual function hiding we don't have here. | |
55 | virtual bool PerformAction(const wxControlAction& action, | |
56 | long numArg = -1l, | |
57 | const wxString& strArg = wxEmptyString); | |
58 | ||
59 | // get the window to work with (usually the class wxInputConsumer was mixed into) | |
60 | virtual wxWindow *GetInputWindow() const = 0; | |
61 | ||
9467bdb7 VZ |
62 | // this function must be implemented in any classes process input (i.e. not |
63 | // static controls) to create the standard input handler for the concrete | |
64 | // class deriving from this mix-in | |
65 | // | |
66 | // the parameter is the default input handler which should receive all | |
67 | // unprocessed input (i.e. typically handlerDef is passed to | |
68 | // wxStdInputHandler ctor) or it may be NULL | |
69 | // | |
70 | // the returned pointer will not be deleted by caller so it must either | |
71 | // point to a static object or be deleted on program termination | |
72 | virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef); | |
73 | ||
74 | ||
23645bfa VS |
75 | protected: |
76 | // event handlers | |
77 | void OnMouse(wxMouseEvent& event); | |
78 | void OnKeyDown(wxKeyEvent& event); | |
79 | void OnKeyUp(wxKeyEvent& event); | |
80 | void OnFocus(wxFocusEvent& event); | |
81 | void OnActivate(wxActivateEvent& event); | |
82 | ||
9467bdb7 VZ |
83 | // create input handler by name, fall back to GetStdInputHandler() if |
84 | // the current theme doesn't define any specific handler of this type | |
23645bfa VS |
85 | void CreateInputHandler(const wxString& inphandler); |
86 | ||
9467bdb7 VZ |
87 | private: |
88 | // the input processor (we never delete it) | |
23645bfa VS |
89 | wxInputHandler *m_inputHandler; |
90 | }; | |
91 | ||
92 | ||
93 | // ---------------------------------------------------------------------------- | |
94 | // macros which must be used by the classes derived from wxInputConsumer mix-in | |
95 | // ---------------------------------------------------------------------------- | |
96 | ||
97 | // declare the methods to be forwarded | |
98 | #define WX_DECLARE_INPUT_CONSUMER() \ | |
99 | private: \ | |
100 | void OnMouse(wxMouseEvent& event); \ | |
101 | void OnKeyDown(wxKeyEvent& event); \ | |
102 | void OnKeyUp(wxKeyEvent& event); \ | |
103 | void OnFocus(wxFocusEvent& event); \ | |
813edf09 VS |
104 | public: /* because of docview :-( */ \ |
105 | void OnActivate(wxActivateEvent& event); \ | |
106 | private: | |
23645bfa VS |
107 | |
108 | // implement the event table entries for wxControlContainer | |
109 | #define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \ | |
110 | EVT_KEY_DOWN(classname::OnKeyDown) \ | |
111 | EVT_KEY_UP(classname::OnKeyUp) \ | |
112 | EVT_MOUSE_EVENTS(classname::OnMouse) \ | |
113 | EVT_SET_FOCUS(classname::OnFocus) \ | |
114 | EVT_KILL_FOCUS(classname::OnFocus) \ | |
115 | EVT_ACTIVATE(classname::OnActivate) | |
23ff76d5 | 116 | |
23645bfa VS |
117 | // Forward event handlers to wxInputConsumer |
118 | // | |
23ff76d5 WS |
119 | // (We can't use them directly, because wxIC has virtual methods, which forces |
120 | // the compiler to include (at least) two vtables into wxControl, one for the | |
121 | // wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in. | |
122 | // Consequently, the "this" pointer has different value when in wxControl's | |
123 | // and wxIC's method, even though the instance stays same. This doesn't matter | |
124 | // so far as member pointers aren't used, but that's not wxControl's case. | |
125 | // When we add an event table entry (= use a member pointer) pointing to | |
126 | // wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the | |
127 | // version of "this" that belongs to wxControl, not wxIC! In our particular | |
23645bfa VS |
128 | // case, the effect is that m_handler is NULL (probably same memory |
129 | // area as the_other_vtable's_this->m_refObj) and input handling doesn't work.) | |
130 | #define WX_FORWARD_TO_INPUT_CONSUMER(classname) \ | |
131 | void classname::OnMouse(wxMouseEvent& event) \ | |
132 | { \ | |
133 | wxInputConsumer::OnMouse(event); \ | |
134 | } \ | |
135 | void classname::OnKeyDown(wxKeyEvent& event) \ | |
136 | { \ | |
137 | wxInputConsumer::OnKeyDown(event); \ | |
138 | } \ | |
139 | void classname::OnKeyUp(wxKeyEvent& event) \ | |
140 | { \ | |
141 | wxInputConsumer::OnKeyUp(event); \ | |
142 | } \ | |
143 | void classname::OnFocus(wxFocusEvent& event) \ | |
144 | { \ | |
145 | wxInputConsumer::OnFocus(event); \ | |
146 | } \ | |
147 | void classname::OnActivate(wxActivateEvent& event) \ | |
148 | { \ | |
149 | wxInputConsumer::OnActivate(event); \ | |
9c3cc136 | 150 | } |
23645bfa VS |
151 | |
152 | #endif // _WX_UNIV_INPCONS_H_ |