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 public: /* because of docview :-( */ \
94 void OnActivate(wxActivateEvent& event); \
97 // implement the event table entries for wxControlContainer
98 #define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \
99 EVT_KEY_DOWN(classname::OnKeyDown) \
100 EVT_KEY_UP(classname::OnKeyUp) \
101 EVT_MOUSE_EVENTS(classname::OnMouse) \
102 EVT_SET_FOCUS(classname::OnFocus) \
103 EVT_KILL_FOCUS(classname::OnFocus) \
104 EVT_ACTIVATE(classname::OnActivate)
106 // Forward event handlers to wxInputConsumer
108 // (We can't use them directly, because wxIC has virtual methods, which forces
109 // the compiler to include (at least) two vtables into wxControl, one for the
110 // wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in.
111 // Consequently, the "this" pointer has different value when in wxControl's
112 // and wxIC's method, even though the instance stays same. This doesn't matter
113 // so far as member pointers aren't used, but that's not wxControl's case.
114 // When we add an event table entry (= use a member pointer) pointing to
115 // wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the
116 // version of "this" that belongs to wxControl, not wxIC! In our particular
117 // case, the effect is that m_handler is NULL (probably same memory
118 // area as the_other_vtable's_this->m_refObj) and input handling doesn't work.)
119 #define WX_FORWARD_TO_INPUT_CONSUMER(classname) \
120 void classname::OnMouse(wxMouseEvent& event) \
122 wxInputConsumer::OnMouse(event); \
124 void classname::OnKeyDown(wxKeyEvent& event) \
126 wxInputConsumer::OnKeyDown(event); \
128 void classname::OnKeyUp(wxKeyEvent& event) \
130 wxInputConsumer::OnKeyUp(event); \
132 void classname::OnFocus(wxFocusEvent& event) \
134 wxInputConsumer::OnFocus(event); \
136 void classname::OnActivate(wxActivateEvent& event) \
138 wxInputConsumer::OnActivate(event); \
141 #endif // _WX_UNIV_INPCONS_H_