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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_INPCONS_H_
13 #define _WX_UNIV_INPCONS_H_
15 class WXDLLEXPORT wxInputHandler
;
16 class WXDLLEXPORT wxWindow
;
18 #include "wx/object.h"
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 // ----------------------------------------------------------------------------
26 typedef wxString wxControlAction
;
28 // the list of actions which apply to all controls (other actions are defined
29 // in the controls headers)
31 #define wxACTION_NONE _T("") // no action to perform
33 // ----------------------------------------------------------------------------
34 // wxInputConsumer: mix-in class for handling wxControlActions (used by
35 // wxControl and wxTopLevelWindow).
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxInputConsumer
41 wxInputConsumer() { m_inputHandler
= NULL
; }
42 virtual ~wxInputConsumer() { }
44 // get the input handler
45 wxInputHandler
*GetInputHandler() const { return m_inputHandler
; }
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
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
,
58 const wxString
& strArg
= wxEmptyString
);
60 // get the window to work with (usually the class wxInputConsumer was mixed into)
61 virtual wxWindow
*GetInputWindow() const = 0;
63 // this function must be implemented in any classes process input (i.e. not
64 // static controls) to create the standard input handler for the concrete
65 // class deriving from this mix-in
67 // the parameter is the default input handler which should receive all
68 // unprocessed input (i.e. typically handlerDef is passed to
69 // wxStdInputHandler ctor) or it may be NULL
71 // the returned pointer will not be deleted by caller so it must either
72 // point to a static object or be deleted on program termination
73 virtual wxInputHandler
*DoGetStdInputHandler(wxInputHandler
*handlerDef
);
78 void OnMouse(wxMouseEvent
& event
);
79 void OnKeyDown(wxKeyEvent
& event
);
80 void OnKeyUp(wxKeyEvent
& event
);
81 void OnFocus(wxFocusEvent
& event
);
82 void OnActivate(wxActivateEvent
& event
);
84 // create input handler by name, fall back to GetStdInputHandler() if
85 // the current theme doesn't define any specific handler of this type
86 void CreateInputHandler(const wxString
& inphandler
);
89 // the input processor (we never delete it)
90 wxInputHandler
*m_inputHandler
;
94 // ----------------------------------------------------------------------------
95 // macros which must be used by the classes derived from wxInputConsumer mix-in
96 // ----------------------------------------------------------------------------
98 // declare the methods to be forwarded
99 #define WX_DECLARE_INPUT_CONSUMER() \
101 void OnMouse(wxMouseEvent& event); \
102 void OnKeyDown(wxKeyEvent& event); \
103 void OnKeyUp(wxKeyEvent& event); \
104 void OnFocus(wxFocusEvent& event); \
105 public: /* because of docview :-( */ \
106 void OnActivate(wxActivateEvent& event); \
109 // implement the event table entries for wxControlContainer
110 #define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \
111 EVT_KEY_DOWN(classname::OnKeyDown) \
112 EVT_KEY_UP(classname::OnKeyUp) \
113 EVT_MOUSE_EVENTS(classname::OnMouse) \
114 EVT_SET_FOCUS(classname::OnFocus) \
115 EVT_KILL_FOCUS(classname::OnFocus) \
116 EVT_ACTIVATE(classname::OnActivate)
118 // Forward event handlers to wxInputConsumer
120 // (We can't use them directly, because wxIC has virtual methods, which forces
121 // the compiler to include (at least) two vtables into wxControl, one for the
122 // wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in.
123 // Consequently, the "this" pointer has different value when in wxControl's
124 // and wxIC's method, even though the instance stays same. This doesn't matter
125 // so far as member pointers aren't used, but that's not wxControl's case.
126 // When we add an event table entry (= use a member pointer) pointing to
127 // wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the
128 // version of "this" that belongs to wxControl, not wxIC! In our particular
129 // case, the effect is that m_handler is NULL (probably same memory
130 // area as the_other_vtable's_this->m_refObj) and input handling doesn't work.)
131 #define WX_FORWARD_TO_INPUT_CONSUMER(classname) \
132 void classname::OnMouse(wxMouseEvent& event) \
134 wxInputConsumer::OnMouse(event); \
136 void classname::OnKeyDown(wxKeyEvent& event) \
138 wxInputConsumer::OnKeyDown(event); \
140 void classname::OnKeyUp(wxKeyEvent& event) \
142 wxInputConsumer::OnKeyUp(event); \
144 void classname::OnFocus(wxFocusEvent& event) \
146 wxInputConsumer::OnFocus(event); \
148 void classname::OnActivate(wxActivateEvent& event) \
150 wxInputConsumer::OnActivate(event); \
153 #endif // _WX_UNIV_INPCONS_H_