1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/inpcons.h
3 // Purpose: wxInputConsumer: mix-in class for input handling
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIV_INPCONS_H_
12 #define _WX_UNIV_INPCONS_H_
14 class WXDLLIMPEXP_FWD_CORE wxInputHandler
;
15 class WXDLLIMPEXP_FWD_CORE wxWindow
;
17 #include "wx/object.h"
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 // ----------------------------------------------------------------------------
25 typedef wxString wxControlAction
;
27 // the list of actions which apply to all controls (other actions are defined
28 // in the controls headers)
30 #define wxACTION_NONE wxT("") // no action to perform
32 // ----------------------------------------------------------------------------
33 // wxInputConsumer: mix-in class for handling wxControlActions (used by
34 // wxControl and wxTopLevelWindow).
35 // ----------------------------------------------------------------------------
37 class WXDLLIMPEXP_CORE wxInputConsumer
40 wxInputConsumer() { m_inputHandler
= NULL
; }
41 virtual ~wxInputConsumer() { }
43 // get the input handler
44 wxInputHandler
*GetInputHandler() const { return m_inputHandler
; }
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
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
,
57 const wxString
& strArg
= wxEmptyString
);
59 // get the window to work with (usually the class wxInputConsumer was mixed into)
60 virtual wxWindow
*GetInputWindow() const = 0;
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
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
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
);
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
);
83 // create input handler by name, fall back to GetStdInputHandler() if
84 // the current theme doesn't define any specific handler of this type
85 void CreateInputHandler(const wxString
& inphandler
);
88 // the input processor (we never delete it)
89 wxInputHandler
*m_inputHandler
;
93 // ----------------------------------------------------------------------------
94 // macros which must be used by the classes derived from wxInputConsumer mix-in
95 // ----------------------------------------------------------------------------
97 // declare the methods to be forwarded
98 #define WX_DECLARE_INPUT_CONSUMER() \
100 void OnMouse(wxMouseEvent& event); \
101 void OnKeyDown(wxKeyEvent& event); \
102 void OnKeyUp(wxKeyEvent& event); \
103 void OnFocus(wxFocusEvent& event); \
104 public: /* because of docview :-( */ \
105 void OnActivate(wxActivateEvent& event); \
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)
117 // Forward event handlers to wxInputConsumer
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
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) \
133 wxInputConsumer::OnMouse(event); \
135 void classname::OnKeyDown(wxKeyEvent& event) \
137 wxInputConsumer::OnKeyDown(event); \
139 void classname::OnKeyUp(wxKeyEvent& event) \
141 wxInputConsumer::OnKeyUp(event); \
143 void classname::OnFocus(wxFocusEvent& event) \
145 wxInputConsumer::OnFocus(event); \
147 void classname::OnActivate(wxActivateEvent& event) \
149 wxInputConsumer::OnActivate(event); \
152 #endif // _WX_UNIV_INPCONS_H_