]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/univ/inpcons.h
removed redundant code
[wxWidgets.git] / include / wx / univ / inpcons.h
... / ...
CommitLineData
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 license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UNIV_INPCONS_H_
13#define _WX_UNIV_INPCONS_H_
14
15#ifdef __GNUG__
16 #pragma interface "inpcons.h"
17#endif
18
19class WXDLLEXPORT wxInputHandler;
20class WXDLLEXPORT wxWindow;
21
22#include "wx/object.h"
23#include "wx/event.h"
24
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// ----------------------------------------------------------------------------
29
30typedef wxString wxControlAction;
31
32// the list of actions which apply to all controls (other actions are defined
33// in the controls headers)
34
35#define wxACTION_NONE _T("") // no action to perform
36
37// ----------------------------------------------------------------------------
38// wxInputConsumer: mix-in class for handling wxControlActions (used by
39// wxControl and wxTopLevelWindow).
40// ----------------------------------------------------------------------------
41
42class WXDLLEXPORT wxInputConsumer
43{
44public:
45 wxInputConsumer() { m_inputHandler = NULL; }
46
47 // get the input handler
48 wxInputHandler *GetInputHandler() const { return m_inputHandler; }
49
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
53 //
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,
60 long numArg = -1l,
61 const wxString& strArg = wxEmptyString);
62
63 // get the window to work with (usually the class wxInputConsumer was mixed into)
64 virtual wxWindow *GetInputWindow() const = 0;
65
66protected:
67 // event handlers
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);
73
74 // create input handler by name
75 void CreateInputHandler(const wxString& inphandler);
76
77 // input processor (never deleted, the theme deletes it itself)
78 wxInputHandler *m_inputHandler;
79};
80
81
82// ----------------------------------------------------------------------------
83// macros which must be used by the classes derived from wxInputConsumer mix-in
84// ----------------------------------------------------------------------------
85
86// declare the methods to be forwarded
87#define WX_DECLARE_INPUT_CONSUMER() \
88private: \
89 void OnMouse(wxMouseEvent& event); \
90 void OnKeyDown(wxKeyEvent& event); \
91 void OnKeyUp(wxKeyEvent& event); \
92 void OnFocus(wxFocusEvent& event); \
93public: /* because of docview :-( */ \
94 void OnActivate(wxActivateEvent& event); \
95private:
96
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)
105
106// Forward event handlers to wxInputConsumer
107//
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) \
121 { \
122 wxInputConsumer::OnMouse(event); \
123 } \
124 void classname::OnKeyDown(wxKeyEvent& event) \
125 { \
126 wxInputConsumer::OnKeyDown(event); \
127 } \
128 void classname::OnKeyUp(wxKeyEvent& event) \
129 { \
130 wxInputConsumer::OnKeyUp(event); \
131 } \
132 void classname::OnFocus(wxFocusEvent& event) \
133 { \
134 wxInputConsumer::OnFocus(event); \
135 } \
136 void classname::OnActivate(wxActivateEvent& event) \
137 { \
138 wxInputConsumer::OnActivate(event); \
139 }
140
141#endif // _WX_UNIV_INPCONS_H_