]> git.saurik.com Git - wxWidgets.git/blame - include/wx/univ/inpcons.h
more extra semicolons removed (patch 1303724)
[wxWidgets.git] / include / wx / univ / inpcons.h
CommitLineData
23645bfa
VS
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)
65571936 9// Licence: wxWindows licence
23645bfa
VS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UNIV_INPCONS_H_
13#define _WX_UNIV_INPCONS_H_
14
23645bfa
VS
15class WXDLLEXPORT wxInputHandler;
16class WXDLLEXPORT 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
26typedef 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 _T("") // no action to perform
32
33// ----------------------------------------------------------------------------
34// wxInputConsumer: mix-in class for handling wxControlActions (used by
35// wxControl and wxTopLevelWindow).
36// ----------------------------------------------------------------------------
37
38class WXDLLEXPORT wxInputConsumer
39{
40public:
6463b9f5 41 wxInputConsumer() { m_inputHandler = NULL; }
23645bfa
VS
42
43 // get the input handler
44 wxInputHandler *GetInputHandler() const { return m_inputHandler; }
45
46 // perform a control-dependent action: an action may have an optional
47 // numeric and another (also optional) string argument whose interpretation
48 // depends on the action
49 //
50 // NB: we might use ellipsis in PerformAction() declaration but this
51 // wouldn't be more efficient than always passing 2 unused parameters
52 // but would be more difficult. Another solution would be to have
53 // several overloaded versions but this will expose the problem of
54 // virtual function hiding we don't have here.
55 virtual bool PerformAction(const wxControlAction& action,
56 long numArg = -1l,
57 const wxString& strArg = wxEmptyString);
58
59 // get the window to work with (usually the class wxInputConsumer was mixed into)
60 virtual wxWindow *GetInputWindow() const = 0;
61
62protected:
63 // event handlers
64 void OnMouse(wxMouseEvent& event);
65 void OnKeyDown(wxKeyEvent& event);
66 void OnKeyUp(wxKeyEvent& event);
67 void OnFocus(wxFocusEvent& event);
68 void OnActivate(wxActivateEvent& event);
69
70 // create input handler by name
71 void CreateInputHandler(const wxString& inphandler);
72
73 // input processor (never deleted, the theme deletes it itself)
74 wxInputHandler *m_inputHandler;
75};
76
77
78// ----------------------------------------------------------------------------
79// macros which must be used by the classes derived from wxInputConsumer mix-in
80// ----------------------------------------------------------------------------
81
82// declare the methods to be forwarded
83#define WX_DECLARE_INPUT_CONSUMER() \
84private: \
85 void OnMouse(wxMouseEvent& event); \
86 void OnKeyDown(wxKeyEvent& event); \
87 void OnKeyUp(wxKeyEvent& event); \
88 void OnFocus(wxFocusEvent& event); \
813edf09
VS
89public: /* because of docview :-( */ \
90 void OnActivate(wxActivateEvent& event); \
91private:
23645bfa
VS
92
93// implement the event table entries for wxControlContainer
94#define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \
95 EVT_KEY_DOWN(classname::OnKeyDown) \
96 EVT_KEY_UP(classname::OnKeyUp) \
97 EVT_MOUSE_EVENTS(classname::OnMouse) \
98 EVT_SET_FOCUS(classname::OnFocus) \
99 EVT_KILL_FOCUS(classname::OnFocus) \
100 EVT_ACTIVATE(classname::OnActivate)
101
102// Forward event handlers to wxInputConsumer
103//
104// (We can't use them directly, because wxIC has virtual methods, which forces
105// the compiler to include (at least) two vtables into wxControl, one for the
106// wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in.
107// Consequently, the "this" pointer has different value when in wxControl's
108// and wxIC's method, even though the instance stays same. This doesn't matter
109// so far as member pointers aren't used, but that's not wxControl's case.
110// When we add an event table entry (= use a member pointer) pointing to
111// wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the
112// version of "this" that belongs to wxControl, not wxIC! In our particular
113// case, the effect is that m_handler is NULL (probably same memory
114// area as the_other_vtable's_this->m_refObj) and input handling doesn't work.)
115#define WX_FORWARD_TO_INPUT_CONSUMER(classname) \
116 void classname::OnMouse(wxMouseEvent& event) \
117 { \
118 wxInputConsumer::OnMouse(event); \
119 } \
120 void classname::OnKeyDown(wxKeyEvent& event) \
121 { \
122 wxInputConsumer::OnKeyDown(event); \
123 } \
124 void classname::OnKeyUp(wxKeyEvent& event) \
125 { \
126 wxInputConsumer::OnKeyUp(event); \
127 } \
128 void classname::OnFocus(wxFocusEvent& event) \
129 { \
130 wxInputConsumer::OnFocus(event); \
131 } \
132 void classname::OnActivate(wxActivateEvent& event) \
133 { \
134 wxInputConsumer::OnActivate(event); \
9c3cc136 135 }
23645bfa
VS
136
137#endif // _WX_UNIV_INPCONS_H_