1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControlContainer class declration: a "mix-in" class which
4 // implements the TAB navigation between the controls
5 // Author: Vadim Zeitlin
9 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_CONTAINR_H_
14 #define _WX_CONTAINR_H_
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "containr.h"
20 class WXDLLEXPORT wxFocusEvent
;
21 class WXDLLEXPORT wxNavigationKeyEvent
;
22 class WXDLLEXPORT wxWindow
;
23 class WXDLLEXPORT wxWindowBase
;
26 Implementation note: wxControlContainer is not a real mix-in but rather
27 a class meant to be agregated with (and not inherited from). Although
28 logically it should be a mix-in, doing it like this has no advantage from
29 the point of view of the existing code but does have some problems (we'd
30 need to play tricks with event handlers which may be difficult to do
31 safely). The price we pay for this simplicity is the ugly macros below.
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxControlContainer
42 wxControlContainer(wxWindow
*winParent
= NULL
);
43 void SetContainerWindow(wxWindow
*winParent
) { m_winParent
= winParent
; }
45 // default item access: we have a permanent default item which is the one
46 // set by the user code but we may also have a temporary default item which
47 // would be chosen if the user pressed "Enter" now but the default action
48 // reverts to the "permanent" default as soon as this temporary default
51 // get the default item, temporary or permanent
52 wxWindow
*GetDefaultItem() const
53 { return m_winTmpDefault
? m_winTmpDefault
: m_winDefault
; }
55 // set the permanent default item, return its old value
56 wxWindow
*SetDefaultItem(wxWindow
*win
)
57 { wxWindow
*winOld
= m_winDefault
; m_winDefault
= win
; return winOld
; }
59 // set a temporary default item, SetTmpDefaultItem(NULL) should be called
60 // soon after a call to SetTmpDefaultItem(window)
61 void SetTmpDefaultItem(wxWindow
*win
) { m_winTmpDefault
= win
; }
63 // the methods to be called from the window event handlers
64 void HandleOnNavigationKey(wxNavigationKeyEvent
& event
);
65 void HandleOnFocus(wxFocusEvent
& event
);
66 void HandleOnWindowDestroy(wxWindowBase
*child
);
68 // should be called from SetFocus(), returns FALSE if we did nothing with
69 // the focus and the default processing should take place
72 // can our child get the focus?
73 bool AcceptsFocus() const;
75 // called from OnChildFocus() handler, i.e. when one of our (grand)
76 // children gets the focus
77 void SetLastFocus(wxWindow
*win
);
80 // set the focus to the child which had it the last time
81 bool SetFocusToChild();
83 // the parent window we manage the children for
84 wxWindow
*m_winParent
;
86 // the child which had the focus last time this panel was activated
87 wxWindow
*m_winLastFocused
;
89 // a default window (usually a button) or NULL
90 wxWindow
*m_winDefault
;
92 // a temporary override of m_winDefault, use the latter if NULL
93 wxWindow
*m_winTmpDefault
;
95 // a guard against infinite recursion
98 DECLARE_NO_COPY_CLASS(wxControlContainer
)
101 // this function is for wxWindows internal use only
102 extern bool wxSetFocusToChild(wxWindow
*win
, wxWindow
**child
);
104 // ----------------------------------------------------------------------------
105 // macros which may be used by the classes wishing to implement TAB navigation
106 // among their children
107 // ----------------------------------------------------------------------------
109 // declare the methods to be forwarded
110 #define WX_DECLARE_CONTROL_CONTAINER() \
112 void OnNavigationKey(wxNavigationKeyEvent& event); \
113 void OnFocus(wxFocusEvent& event); \
114 virtual void OnChildFocus(wxChildFocusEvent& event); \
115 virtual void SetFocus(); \
116 virtual void RemoveChild(wxWindowBase *child); \
117 virtual wxWindow *GetDefaultItem() const; \
118 virtual wxWindow *SetDefaultItem(wxWindow *child); \
119 virtual void SetTmpDefaultItem(wxWindow *win); \
120 virtual bool AcceptsFocus() const; \
123 wxControlContainer m_container
125 // implement the event table entries for wxControlContainer
126 #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
127 EVT_SET_FOCUS(classname::OnFocus) \
128 EVT_CHILD_FOCUS(classname::OnChildFocus) \
129 EVT_NAVIGATION_KEY(classname::OnNavigationKey)
131 // implement the methods forwarding to the wxControlContainer
132 #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname) \
133 wxWindow *classname::SetDefaultItem(wxWindow *child) \
135 return m_container.SetDefaultItem(child); \
138 void classname::SetTmpDefaultItem(wxWindow *child) \
140 m_container.SetTmpDefaultItem(child); \
143 wxWindow *classname::GetDefaultItem() const \
145 return m_container.GetDefaultItem(); \
148 void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
150 m_container.HandleOnNavigationKey(event); \
153 void classname::RemoveChild(wxWindowBase *child) \
155 m_container.HandleOnWindowDestroy(child); \
157 wxWindow::RemoveChild(child); \
160 void classname::SetFocus() \
162 if ( !m_container.DoSetFocus() ) \
163 wxWindow::SetFocus(); \
166 void classname::OnChildFocus(wxChildFocusEvent& event) \
168 m_container.SetLastFocus(event.GetWindow()); \
171 void classname::OnFocus(wxFocusEvent& event) \
173 m_container.HandleOnFocus(event); \
175 bool classname::AcceptsFocus() const \
177 return m_container.AcceptsFocus(); \
181 #endif // _WX_CONTAINR_H_