]> git.saurik.com Git - wxWidgets.git/blob - include/wx/containr.h
layout improvement on mac
[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 #ifdef __GNUG__
17 #pragma interface "containr.h"
18 #endif
19
20 class WXDLLEXPORT wxFocusEvent;
21 class WXDLLEXPORT wxNavigationKeyEvent;
22 class WXDLLEXPORT wxWindow;
23 class WXDLLEXPORT wxWindowBase;
24
25 /*
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.
32 */
33
34 // ----------------------------------------------------------------------------
35 // wxControlContainer
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxControlContainer
39 {
40 DECLARE_NO_COPY_CLASS(wxControlContainer)
41
42 public:
43 // ctors and such
44 wxControlContainer(wxWindow *winParent = NULL);
45 void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
46
47 // default item access
48 wxWindow *GetDefaultItem() const { return m_winDefault; }
49 wxWindow *SetDefaultItem(wxWindow *win)
50 { wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
51
52 // the methods to be called from the window event handlers
53 void HandleOnNavigationKey(wxNavigationKeyEvent& event);
54 void HandleOnFocus(wxFocusEvent& event);
55 void HandleOnWindowDestroy(wxWindowBase *child);
56
57 // should be called from SetFocus(), returns FALSE if we did nothing with
58 // the focus and the default processing should take place
59 bool DoSetFocus();
60
61 // called from OnChildFocus() handler, i.e. when one of our (grand)
62 // children gets the focus
63 void SetLastFocus(wxWindow *win);
64
65 protected:
66 // set the focus to the child which had it the last time
67 bool SetFocusToChild();
68
69 // the parent window we manage the children for
70 wxWindow *m_winParent;
71
72 // the child which had the focus last time this panel was activated
73 wxWindow *m_winLastFocused;
74
75 // a default window (e.g. a button) or NULL
76 wxWindow *m_winDefault;
77 };
78
79 // this function is for wxWindows internal use only
80 extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
81
82 // ----------------------------------------------------------------------------
83 // macros which may be used by the classes wishing to implement TAB navigation
84 // among their children
85 // ----------------------------------------------------------------------------
86
87 // declare the methods to be forwarded
88 #define WX_DECLARE_CONTROL_CONTAINER() \
89 public: \
90 void OnNavigationKey(wxNavigationKeyEvent& event); \
91 void OnFocus(wxFocusEvent& event); \
92 virtual void OnChildFocus(wxChildFocusEvent& event); \
93 virtual void SetFocus(); \
94 virtual void RemoveChild(wxWindowBase *child); \
95 virtual wxWindow *GetDefaultItem() const; \
96 virtual wxWindow *SetDefaultItem(wxWindow *child); \
97 \
98 protected: \
99 wxControlContainer m_container
100
101 // implement the event table entries for wxControlContainer
102 #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
103 EVT_SET_FOCUS(classname::OnFocus) \
104 EVT_CHILD_FOCUS(classname::OnChildFocus) \
105 EVT_NAVIGATION_KEY(classname::OnNavigationKey)
106
107 // implement the methods forwarding to the wxControlContainer
108 #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname) \
109 wxWindow *classname::SetDefaultItem(wxWindow *child) \
110 { \
111 return m_container.SetDefaultItem(child); \
112 } \
113 \
114 wxWindow *classname::GetDefaultItem() const \
115 { \
116 return m_container.GetDefaultItem(); \
117 } \
118 \
119 void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
120 { \
121 m_container.HandleOnNavigationKey(event); \
122 } \
123 \
124 void classname::RemoveChild(wxWindowBase *child) \
125 { \
126 m_container.HandleOnWindowDestroy(child); \
127 \
128 wxWindow::RemoveChild(child); \
129 } \
130 \
131 void classname::SetFocus() \
132 { \
133 if ( !m_container.DoSetFocus() ) \
134 wxWindow::SetFocus(); \
135 } \
136 \
137 void classname::OnChildFocus(wxChildFocusEvent& event) \
138 { \
139 m_container.SetLastFocus(event.GetWindow()); \
140 } \
141 \
142 void classname::OnFocus(wxFocusEvent& event) \
143 { \
144 m_container.HandleOnFocus(event); \
145 }
146
147
148 #endif // _WX_CONTAINR_H_