]> git.saurik.com Git - wxWidgets.git/blame - include/wx/containr.h
Compilation fix for old GCC versions.
[wxWidgets.git] / include / wx / containr.h
CommitLineData
456bc6d9
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/containr.h
3// Purpose: wxControlContainer class declration: a "mix-in" class which
4// implements the TAB navigation between the controls
5// Author: Vadim Zeitlin
6// Modified by:
7// Created: 06.08.01
8// RCS-ID: $Id$
9// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 10// Licence: wxWindows licence
456bc6d9
VZ
11///////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_CONTAINR_H_
14#define _WX_CONTAINR_H_
15
456bc6d9
VZ
16class WXDLLEXPORT wxFocusEvent;
17class WXDLLEXPORT wxNavigationKeyEvent;
18class WXDLLEXPORT wxWindow;
6285be72 19class WXDLLEXPORT wxWindowBase;
456bc6d9
VZ
20
21/*
22 Implementation note: wxControlContainer is not a real mix-in but rather
23 a class meant to be agregated with (and not inherited from). Although
24 logically it should be a mix-in, doing it like this has no advantage from
25 the point of view of the existing code but does have some problems (we'd
26 need to play tricks with event handlers which may be difficult to do
27 safely). The price we pay for this simplicity is the ugly macros below.
28 */
29
30// ----------------------------------------------------------------------------
31// wxControlContainer
32// ----------------------------------------------------------------------------
33
34class WXDLLEXPORT wxControlContainer
35{
36public:
37 // ctors and such
9948d31f
VZ
38 wxControlContainer(wxWindow *winParent = NULL);
39 void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
456bc6d9 40
456bc6d9
VZ
41 // the methods to be called from the window event handlers
42 void HandleOnNavigationKey(wxNavigationKeyEvent& event);
43 void HandleOnFocus(wxFocusEvent& event);
44 void HandleOnWindowDestroy(wxWindowBase *child);
45
68379eaf 46 // should be called from SetFocus(), returns false if we did nothing with
24a7a198
VZ
47 // the focus and the default processing should take place
48 bool DoSetFocus();
456bc6d9 49
3251b834
VZ
50 // can our child get the focus?
51 bool AcceptsFocus() const;
52
9948d31f
VZ
53 // called from OnChildFocus() handler, i.e. when one of our (grand)
54 // children gets the focus
55 void SetLastFocus(wxWindow *win);
56
456bc6d9
VZ
57protected:
58 // set the focus to the child which had it the last time
59 bool SetFocusToChild();
60
61 // the parent window we manage the children for
62 wxWindow *m_winParent;
63
64 // the child which had the focus last time this panel was activated
65 wxWindow *m_winLastFocused;
66
b33f7651
JS
67 // a guard against infinite recursion
68 bool m_inSetFocus;
69
036da5e3 70 DECLARE_NO_COPY_CLASS(wxControlContainer)
456bc6d9
VZ
71};
72
77ffb593 73// this function is for wxWidgets internal use only
456bc6d9
VZ
74extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
75
76// ----------------------------------------------------------------------------
77// macros which may be used by the classes wishing to implement TAB navigation
78// among their children
79// ----------------------------------------------------------------------------
80
81// declare the methods to be forwarded
82#define WX_DECLARE_CONTROL_CONTAINER() \
6b55490a 83public: \
456bc6d9
VZ
84 void OnNavigationKey(wxNavigationKeyEvent& event); \
85 void OnFocus(wxFocusEvent& event); \
86 virtual void OnChildFocus(wxChildFocusEvent& event); \
87 virtual void SetFocus(); \
ababa106 88 virtual void SetFocusIgnoringChildren(); \
456bc6d9 89 virtual void RemoveChild(wxWindowBase *child); \
3251b834 90 virtual bool AcceptsFocus() const; \
6b55490a
VZ
91\
92protected: \
93 wxControlContainer m_container
456bc6d9
VZ
94
95// implement the event table entries for wxControlContainer
96#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
97 EVT_SET_FOCUS(classname::OnFocus) \
98 EVT_CHILD_FOCUS(classname::OnChildFocus) \
99 EVT_NAVIGATION_KEY(classname::OnNavigationKey)
100
101// implement the methods forwarding to the wxControlContainer
6c20e8f8 102#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) \
456bc6d9
VZ
103void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
104{ \
6b55490a 105 m_container.HandleOnNavigationKey(event); \
456bc6d9
VZ
106} \
107 \
108void classname::RemoveChild(wxWindowBase *child) \
109{ \
6b55490a 110 m_container.HandleOnWindowDestroy(child); \
456bc6d9 111 \
6c20e8f8 112 basename::RemoveChild(child); \
456bc6d9
VZ
113} \
114 \
115void classname::SetFocus() \
116{ \
6b55490a 117 if ( !m_container.DoSetFocus() ) \
6c20e8f8 118 basename::SetFocus(); \
456bc6d9
VZ
119} \
120 \
ababa106
RR
121void classname::SetFocusIgnoringChildren() \
122{ \
6c20e8f8 123 basename::SetFocus(); \
ababa106
RR
124} \
125 \
456bc6d9
VZ
126void classname::OnChildFocus(wxChildFocusEvent& event) \
127{ \
6b55490a 128 m_container.SetLastFocus(event.GetWindow()); \
456bc6d9
VZ
129} \
130 \
131void classname::OnFocus(wxFocusEvent& event) \
132{ \
6b55490a 133 m_container.HandleOnFocus(event); \
3251b834
VZ
134} \
135bool classname::AcceptsFocus() const \
136{ \
137 return m_container.AcceptsFocus(); \
456bc6d9
VZ
138}
139
140
141#endif // _WX_CONTAINR_H_