1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/inpcons.h
3 // Purpose: wxInputConsumer: mix-in class for input handling
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_INPCONS_H_
13 #define _WX_UNIV_INPCONS_H_
16 #pragma interface "inpcons.h"
19 class WXDLLEXPORT wxInputHandler
;
20 class WXDLLEXPORT wxWindow
;
22 #include "wx/object.h"
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 // ----------------------------------------------------------------------------
30 typedef wxString wxControlAction
;
32 // the list of actions which apply to all controls (other actions are defined
33 // in the controls headers)
35 #define wxACTION_NONE _T("") // no action to perform
37 // ----------------------------------------------------------------------------
38 // wxInputConsumer: mix-in class for handling wxControlActions (used by
39 // wxControl and wxTopLevelWindow).
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxInputConsumer
45 wxInputConsumer() { m_inputHandler
= NULL
; }
47 // get the input handler
48 wxInputHandler
*GetInputHandler() const { return m_inputHandler
; }
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
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
,
61 const wxString
& strArg
= wxEmptyString
);
63 // get the window to work with (usually the class wxInputConsumer was mixed into)
64 virtual wxWindow
*GetInputWindow() const = 0;
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
);
74 // create input handler by name
75 void CreateInputHandler(const wxString
& inphandler
);
77 // input processor (never deleted, the theme deletes it itself)
78 wxInputHandler
*m_inputHandler
;
82 // ----------------------------------------------------------------------------
83 // macros which must be used by the classes derived from wxInputConsumer mix-in
84 // ----------------------------------------------------------------------------
86 // declare the methods to be forwarded
87 #define WX_DECLARE_INPUT_CONSUMER() \
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);
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)
104 // Forward event handlers to wxInputConsumer
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) \
120 wxInputConsumer::OnMouse(event); \
122 void classname::OnKeyDown(wxKeyEvent& event) \
124 wxInputConsumer::OnKeyDown(event); \
126 void classname::OnKeyUp(wxKeyEvent& event) \
128 wxInputConsumer::OnKeyUp(event); \
130 void classname::OnFocus(wxFocusEvent& event) \
132 wxInputConsumer::OnFocus(event); \
134 void classname::OnActivate(wxActivateEvent& event) \
136 wxInputConsumer::OnActivate(event); \
140 #endif // _WX_UNIV_INPCONS_H_