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