Globally replace _T() with wxT().
[wxWidgets.git] / include / wx / univ / inpcons.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/inpcons.h
3 // Purpose: wxInputConsumer: mix-in class for input handling
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 14.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_INPCONS_H_
13 #define _WX_UNIV_INPCONS_H_
14
15 class WXDLLIMPEXP_FWD_CORE wxInputHandler;
16 class WXDLLIMPEXP_FWD_CORE wxWindow;
17
18 #include "wx/object.h"
19 #include "wx/event.h"
20
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 // ----------------------------------------------------------------------------
25
26 typedef wxString wxControlAction;
27
28 // the list of actions which apply to all controls (other actions are defined
29 // in the controls headers)
30
31 #define wxACTION_NONE wxT("") // no action to perform
32
33 // ----------------------------------------------------------------------------
34 // wxInputConsumer: mix-in class for handling wxControlActions (used by
35 // wxControl and wxTopLevelWindow).
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxInputConsumer
39 {
40 public:
41 wxInputConsumer() { m_inputHandler = NULL; }
42 virtual ~wxInputConsumer() { }
43
44 // get the input handler
45 wxInputHandler *GetInputHandler() const { return m_inputHandler; }
46
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
50 //
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,
57 long numArg = -1l,
58 const wxString& strArg = wxEmptyString);
59
60 // get the window to work with (usually the class wxInputConsumer was mixed into)
61 virtual wxWindow *GetInputWindow() const = 0;
62
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
66 //
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
70 //
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);
74
75
76 protected:
77 // event handlers
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);
83
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);
87
88 private:
89 // the input processor (we never delete it)
90 wxInputHandler *m_inputHandler;
91 };
92
93
94 // ----------------------------------------------------------------------------
95 // macros which must be used by the classes derived from wxInputConsumer mix-in
96 // ----------------------------------------------------------------------------
97
98 // declare the methods to be forwarded
99 #define WX_DECLARE_INPUT_CONSUMER() \
100 private: \
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); \
107 private:
108
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)
117
118 // Forward event handlers to wxInputConsumer
119 //
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) \
133 { \
134 wxInputConsumer::OnMouse(event); \
135 } \
136 void classname::OnKeyDown(wxKeyEvent& event) \
137 { \
138 wxInputConsumer::OnKeyDown(event); \
139 } \
140 void classname::OnKeyUp(wxKeyEvent& event) \
141 { \
142 wxInputConsumer::OnKeyUp(event); \
143 } \
144 void classname::OnFocus(wxFocusEvent& event) \
145 { \
146 wxInputConsumer::OnFocus(event); \
147 } \
148 void classname::OnActivate(wxActivateEvent& event) \
149 { \
150 wxInputConsumer::OnActivate(event); \
151 }
152
153 #endif // _WX_UNIV_INPCONS_H_