]>
Commit | Line | Data |
---|---|---|
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 | ||
de160b06 VZ |
16 | #ifdef wxHAS_NATIVE_TAB_TRAVERSAL |
17 | ||
18 | #define WX_DECLARE_CONTROL_CONTAINER() \ | |
19 | virtual bool AcceptsFocus() const { return false; } \ | |
20 | void SetFocusIgnoringChildren() { SetFocus(); } | |
21 | ||
22 | #define WX_INIT_CONTROL_CONTAINER() | |
23 | #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) | |
24 | #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) | |
25 | ||
26 | #else // !wxHAS_NATIVE_TAB_TRAVERSAL | |
27 | ||
456bc6d9 VZ |
28 | class WXDLLEXPORT wxFocusEvent; |
29 | class WXDLLEXPORT wxNavigationKeyEvent; | |
30 | class WXDLLEXPORT wxWindow; | |
6285be72 | 31 | class WXDLLEXPORT wxWindowBase; |
456bc6d9 VZ |
32 | |
33 | /* | |
34 | Implementation note: wxControlContainer is not a real mix-in but rather | |
de160b06 | 35 | a class meant to be aggregated with (and not inherited from). Although |
456bc6d9 VZ |
36 | logically it should be a mix-in, doing it like this has no advantage from |
37 | the point of view of the existing code but does have some problems (we'd | |
38 | need to play tricks with event handlers which may be difficult to do | |
39 | safely). The price we pay for this simplicity is the ugly macros below. | |
40 | */ | |
41 | ||
42 | // ---------------------------------------------------------------------------- | |
43 | // wxControlContainer | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | class WXDLLEXPORT wxControlContainer | |
47 | { | |
48 | public: | |
49 | // ctors and such | |
9948d31f VZ |
50 | wxControlContainer(wxWindow *winParent = NULL); |
51 | void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; } | |
456bc6d9 | 52 | |
456bc6d9 VZ |
53 | // the methods to be called from the window event handlers |
54 | void HandleOnNavigationKey(wxNavigationKeyEvent& event); | |
55 | void HandleOnFocus(wxFocusEvent& event); | |
56 | void HandleOnWindowDestroy(wxWindowBase *child); | |
57 | ||
68379eaf | 58 | // should be called from SetFocus(), returns false if we did nothing with |
24a7a198 VZ |
59 | // the focus and the default processing should take place |
60 | bool DoSetFocus(); | |
456bc6d9 | 61 | |
3251b834 VZ |
62 | // can our child get the focus? |
63 | bool AcceptsFocus() const; | |
64 | ||
9948d31f VZ |
65 | // called from OnChildFocus() handler, i.e. when one of our (grand) |
66 | // children gets the focus | |
67 | void SetLastFocus(wxWindow *win); | |
68 | ||
456bc6d9 VZ |
69 | protected: |
70 | // set the focus to the child which had it the last time | |
71 | bool SetFocusToChild(); | |
72 | ||
73 | // the parent window we manage the children for | |
74 | wxWindow *m_winParent; | |
75 | ||
76 | // the child which had the focus last time this panel was activated | |
77 | wxWindow *m_winLastFocused; | |
78 | ||
b33f7651 JS |
79 | // a guard against infinite recursion |
80 | bool m_inSetFocus; | |
81 | ||
036da5e3 | 82 | DECLARE_NO_COPY_CLASS(wxControlContainer) |
456bc6d9 VZ |
83 | }; |
84 | ||
77ffb593 | 85 | // this function is for wxWidgets internal use only |
456bc6d9 VZ |
86 | extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child); |
87 | ||
88 | // ---------------------------------------------------------------------------- | |
89 | // macros which may be used by the classes wishing to implement TAB navigation | |
90 | // among their children | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | // declare the methods to be forwarded | |
94 | #define WX_DECLARE_CONTROL_CONTAINER() \ | |
6b55490a | 95 | public: \ |
456bc6d9 VZ |
96 | void OnNavigationKey(wxNavigationKeyEvent& event); \ |
97 | void OnFocus(wxFocusEvent& event); \ | |
98 | virtual void OnChildFocus(wxChildFocusEvent& event); \ | |
99 | virtual void SetFocus(); \ | |
ababa106 | 100 | virtual void SetFocusIgnoringChildren(); \ |
456bc6d9 | 101 | virtual void RemoveChild(wxWindowBase *child); \ |
3251b834 | 102 | virtual bool AcceptsFocus() const; \ |
6b55490a VZ |
103 | \ |
104 | protected: \ | |
105 | wxControlContainer m_container | |
456bc6d9 | 106 | |
de160b06 VZ |
107 | // this macro must be used in the derived class ctor |
108 | #define WX_INIT_CONTROL_CONTAINER() \ | |
109 | m_container.SetContainerWindow(this) | |
110 | ||
456bc6d9 VZ |
111 | // implement the event table entries for wxControlContainer |
112 | #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \ | |
113 | EVT_SET_FOCUS(classname::OnFocus) \ | |
114 | EVT_CHILD_FOCUS(classname::OnChildFocus) \ | |
115 | EVT_NAVIGATION_KEY(classname::OnNavigationKey) | |
116 | ||
117 | // implement the methods forwarding to the wxControlContainer | |
6c20e8f8 | 118 | #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) \ |
456bc6d9 VZ |
119 | void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \ |
120 | { \ | |
6b55490a | 121 | m_container.HandleOnNavigationKey(event); \ |
456bc6d9 VZ |
122 | } \ |
123 | \ | |
124 | void classname::RemoveChild(wxWindowBase *child) \ | |
125 | { \ | |
6b55490a | 126 | m_container.HandleOnWindowDestroy(child); \ |
456bc6d9 | 127 | \ |
6c20e8f8 | 128 | basename::RemoveChild(child); \ |
456bc6d9 VZ |
129 | } \ |
130 | \ | |
131 | void classname::SetFocus() \ | |
132 | { \ | |
6b55490a | 133 | if ( !m_container.DoSetFocus() ) \ |
6c20e8f8 | 134 | basename::SetFocus(); \ |
456bc6d9 VZ |
135 | } \ |
136 | \ | |
ababa106 RR |
137 | void classname::SetFocusIgnoringChildren() \ |
138 | { \ | |
6c20e8f8 | 139 | basename::SetFocus(); \ |
ababa106 RR |
140 | } \ |
141 | \ | |
456bc6d9 VZ |
142 | void classname::OnChildFocus(wxChildFocusEvent& event) \ |
143 | { \ | |
6b55490a | 144 | m_container.SetLastFocus(event.GetWindow()); \ |
456bc6d9 VZ |
145 | } \ |
146 | \ | |
147 | void classname::OnFocus(wxFocusEvent& event) \ | |
148 | { \ | |
6b55490a | 149 | m_container.HandleOnFocus(event); \ |
3251b834 VZ |
150 | } \ |
151 | bool classname::AcceptsFocus() const \ | |
152 | { \ | |
153 | return m_container.AcceptsFocus(); \ | |
456bc6d9 VZ |
154 | } |
155 | ||
de160b06 | 156 | #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL |
456bc6d9 VZ |
157 | |
158 | #endif // _WX_CONTAINR_H_ |