]> git.saurik.com Git - wxWidgets.git/blob - include/wx/containr.h
fix messages for OpenGL headers detection
[wxWidgets.git] / include / wx / containr.h
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>
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_CONTAINR_H_
14 #define _WX_CONTAINR_H_
15
16 class WXDLLEXPORT wxFocusEvent;
17 class WXDLLEXPORT wxNavigationKeyEvent;
18 class WXDLLEXPORT wxWindow;
19 class WXDLLEXPORT wxWindowBase;
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
34 class WXDLLEXPORT wxControlContainer
35 {
36 public:
37 // ctors and such
38 wxControlContainer(wxWindow *winParent = NULL);
39 void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
40
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
46 // should be called from SetFocus(), returns false if we did nothing with
47 // the focus and the default processing should take place
48 bool DoSetFocus();
49
50 // can our child get the focus?
51 bool AcceptsFocus() const;
52
53 // called from OnChildFocus() handler, i.e. when one of our (grand)
54 // children gets the focus
55 void SetLastFocus(wxWindow *win);
56
57 protected:
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
67 // a guard against infinite recursion
68 bool m_inSetFocus;
69
70 DECLARE_NO_COPY_CLASS(wxControlContainer)
71 };
72
73 // this function is for wxWidgets internal use only
74 extern 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() \
83 public: \
84 void OnNavigationKey(wxNavigationKeyEvent& event); \
85 void OnFocus(wxFocusEvent& event); \
86 virtual void OnChildFocus(wxChildFocusEvent& event); \
87 virtual void SetFocus(); \
88 virtual void SetFocusIgnoringChildren(); \
89 virtual void RemoveChild(wxWindowBase *child); \
90 virtual bool AcceptsFocus() const; \
91 \
92 protected: \
93 wxControlContainer m_container
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
102 #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) \
103 void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
104 { \
105 m_container.HandleOnNavigationKey(event); \
106 } \
107 \
108 void classname::RemoveChild(wxWindowBase *child) \
109 { \
110 m_container.HandleOnWindowDestroy(child); \
111 \
112 basename::RemoveChild(child); \
113 } \
114 \
115 void classname::SetFocus() \
116 { \
117 if ( !m_container.DoSetFocus() ) \
118 basename::SetFocus(); \
119 } \
120 \
121 void classname::SetFocusIgnoringChildren() \
122 { \
123 basename::SetFocus(); \
124 } \
125 \
126 void classname::OnChildFocus(wxChildFocusEvent& event) \
127 { \
128 m_container.SetLastFocus(event.GetWindow()); \
129 } \
130 \
131 void classname::OnFocus(wxFocusEvent& event) \
132 { \
133 m_container.HandleOnFocus(event); \
134 } \
135 bool classname::AcceptsFocus() const \
136 { \
137 return m_container.AcceptsFocus(); \
138 }
139
140
141 #endif // _WX_CONTAINR_H_