pragma fix for gcc
[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
24 /*
25 Implementation note: wxControlContainer is not a real mix-in but rather
26 a class meant to be agregated with (and not inherited from). Although
27 logically it should be a mix-in, doing it like this has no advantage from
28 the point of view of the existing code but does have some problems (we'd
29 need to play tricks with event handlers which may be difficult to do
30 safely). The price we pay for this simplicity is the ugly macros below.
31 */
32
33 // ----------------------------------------------------------------------------
34 // wxControlContainer
35 // ----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxControlContainer
38 {
39 public:
40 // ctors and such
41 wxControlContainer(wxWindow *winParent);
42
43 wxWindow *GetDefaultItem() const { return m_winDefault; }
44 wxWindow *SetDefaultItem(wxWindow *win)
45 { wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
46
47 void SetLastFocus(wxWindow *win);
48
49 // the methods to be called from the window event handlers
50 void HandleOnNavigationKey(wxNavigationKeyEvent& event);
51 void HandleOnFocus(wxFocusEvent& event);
52 void HandleOnWindowDestroy(wxWindowBase *child);
53
54 // should be called from SetFocus()
55 void DoSetFocus();
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 default window (e.g. a button) or NULL
68 wxWindow *m_winDefault;
69 };
70
71 // this function is for wxWindows internal use only
72 extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
73
74 // ----------------------------------------------------------------------------
75 // macros which may be used by the classes wishing to implement TAB navigation
76 // among their children
77 // ----------------------------------------------------------------------------
78
79 // declare the methods to be forwarded
80 #define WX_DECLARE_CONTROL_CONTAINER() \
81 void OnNavigationKey(wxNavigationKeyEvent& event); \
82 void OnFocus(wxFocusEvent& event); \
83 virtual void OnChildFocus(wxChildFocusEvent& event); \
84 virtual void SetFocus(); \
85 virtual void RemoveChild(wxWindowBase *child); \
86 virtual wxWindow *GetDefaultItem() const; \
87 virtual wxWindow *SetDefaultItem(wxWindow *child) \
88
89 // implement the event table entries for wxControlContainer
90 #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
91 EVT_SET_FOCUS(classname::OnFocus) \
92 EVT_CHILD_FOCUS(classname::OnChildFocus) \
93 EVT_NAVIGATION_KEY(classname::OnNavigationKey)
94
95 // implement the methods forwarding to the wxControlContainer
96 #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, container) \
97 wxWindow *classname::SetDefaultItem(wxWindow *child) \
98 { \
99 return container->SetDefaultItem(child); \
100 } \
101 \
102 wxWindow *classname::GetDefaultItem() const \
103 { \
104 return container->GetDefaultItem(); \
105 } \
106 \
107 void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
108 { \
109 container->HandleOnNavigationKey(event); \
110 } \
111 \
112 void classname::RemoveChild(wxWindowBase *child) \
113 { \
114 container->HandleOnWindowDestroy(child); \
115 \
116 wxWindow::RemoveChild(child); \
117 } \
118 \
119 void classname::SetFocus() \
120 { \
121 container->DoSetFocus(); \
122 } \
123 \
124 void classname::OnChildFocus(wxChildFocusEvent& event) \
125 { \
126 container->SetLastFocus(event.GetWindow()); \
127 } \
128 \
129 void classname::OnFocus(wxFocusEvent& event) \
130 { \
131 container->HandleOnFocus(event); \
132 }
133
134
135 #endif // _WX_CONTAINR_H_