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;
65 void OnMouse(wxMouseEvent
& event
);
66 void OnKeyDown(wxKeyEvent
& event
);
67 void OnKeyUp(wxKeyEvent
& event
);
68 void OnFocus(wxFocusEvent
& event
);
69 void OnActivate(wxActivateEvent
& event
);
71 // create input handler by name
72 void CreateInputHandler(const wxString
& inphandler
);
74 // input processor (never deleted, the theme deletes it itself)
75 wxInputHandler
*m_inputHandler
;
79 // ----------------------------------------------------------------------------
80 // macros which must be used by the classes derived from wxInputConsumer mix-in
81 // ----------------------------------------------------------------------------
83 // declare the methods to be forwarded
84 #define WX_DECLARE_INPUT_CONSUMER() \
86 void OnMouse(wxMouseEvent& event); \
87 void OnKeyDown(wxKeyEvent& event); \
88 void OnKeyUp(wxKeyEvent& event); \
89 void OnFocus(wxFocusEvent& event); \
90 public: /* because of docview :-( */ \
91 void OnActivate(wxActivateEvent& event); \
94 // implement the event table entries for wxControlContainer
95 #define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \
96 EVT_KEY_DOWN(classname::OnKeyDown) \
97 EVT_KEY_UP(classname::OnKeyUp) \
98 EVT_MOUSE_EVENTS(classname::OnMouse) \
99 EVT_SET_FOCUS(classname::OnFocus) \
100 EVT_KILL_FOCUS(classname::OnFocus) \
101 EVT_ACTIVATE(classname::OnActivate)
103 // Forward event handlers to wxInputConsumer
105 // (We can't use them directly, because wxIC has virtual methods, which forces
106 // the compiler to include (at least) two vtables into wxControl, one for the
107 // wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in.
108 // Consequently, the "this" pointer has different value when in wxControl's
109 // and wxIC's method, even though the instance stays same. This doesn't matter
110 // so far as member pointers aren't used, but that's not wxControl's case.
111 // When we add an event table entry (= use a member pointer) pointing to
112 // wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the
113 // version of "this" that belongs to wxControl, not wxIC! In our particular
114 // case, the effect is that m_handler is NULL (probably same memory
115 // area as the_other_vtable's_this->m_refObj) and input handling doesn't work.)
116 #define WX_FORWARD_TO_INPUT_CONSUMER(classname) \
117 void classname::OnMouse(wxMouseEvent& event) \
119 wxInputConsumer::OnMouse(event); \
121 void classname::OnKeyDown(wxKeyEvent& event) \
123 wxInputConsumer::OnKeyDown(event); \
125 void classname::OnKeyUp(wxKeyEvent& event) \
127 wxInputConsumer::OnKeyUp(event); \
129 void classname::OnFocus(wxFocusEvent& event) \
131 wxInputConsumer::OnFocus(event); \
133 void classname::OnActivate(wxActivateEvent& event) \
135 wxInputConsumer::OnActivate(event); \
138 #endif // _WX_UNIV_INPCONS_H_