]> git.saurik.com Git - wxWidgets.git/blame - include/wx/containr.h
Patch #826420, and also adapted to new SWIG
[wxWidgets.git] / include / wx / containr.h
CommitLineData
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>
10// Licence: wxWindows licence
11///////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_CONTAINR_H_
14#define _WX_CONTAINR_H_
15
12028905 16#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
dad5f99a 17 #pragma interface "containr.h"
456bc6d9
VZ
18#endif
19
20class WXDLLEXPORT wxFocusEvent;
21class WXDLLEXPORT wxNavigationKeyEvent;
22class WXDLLEXPORT wxWindow;
6285be72 23class WXDLLEXPORT wxWindowBase;
456bc6d9
VZ
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
38class WXDLLEXPORT wxControlContainer
39{
40public:
41 // ctors and such
9948d31f
VZ
42 wxControlContainer(wxWindow *winParent = NULL);
43 void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
456bc6d9 44
036da5e3
VZ
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
49 // item lsoes focus
50
51 // get the default item, temporary or permanent
52 wxWindow *GetDefaultItem() const
53 { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
54
55 // set the permanent default item, return its old value
456bc6d9
VZ
56 wxWindow *SetDefaultItem(wxWindow *win)
57 { wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
58
036da5e3
VZ
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; }
62
456bc6d9
VZ
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);
67
24a7a198
VZ
68 // should be called from SetFocus(), returns FALSE if we did nothing with
69 // the focus and the default processing should take place
70 bool DoSetFocus();
456bc6d9 71
3251b834
VZ
72 // can our child get the focus?
73 bool AcceptsFocus() const;
74
9948d31f
VZ
75 // called from OnChildFocus() handler, i.e. when one of our (grand)
76 // children gets the focus
77 void SetLastFocus(wxWindow *win);
78
456bc6d9
VZ
79protected:
80 // set the focus to the child which had it the last time
81 bool SetFocusToChild();
82
83 // the parent window we manage the children for
84 wxWindow *m_winParent;
85
86 // the child which had the focus last time this panel was activated
87 wxWindow *m_winLastFocused;
88
036da5e3 89 // a default window (usually a button) or NULL
456bc6d9 90 wxWindow *m_winDefault;
036da5e3
VZ
91
92 // a temporary override of m_winDefault, use the latter if NULL
93 wxWindow *m_winTmpDefault;
94
95 DECLARE_NO_COPY_CLASS(wxControlContainer)
456bc6d9
VZ
96};
97
98// this function is for wxWindows internal use only
99extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
100
101// ----------------------------------------------------------------------------
102// macros which may be used by the classes wishing to implement TAB navigation
103// among their children
104// ----------------------------------------------------------------------------
105
106// declare the methods to be forwarded
107#define WX_DECLARE_CONTROL_CONTAINER() \
6b55490a 108public: \
456bc6d9
VZ
109 void OnNavigationKey(wxNavigationKeyEvent& event); \
110 void OnFocus(wxFocusEvent& event); \
111 virtual void OnChildFocus(wxChildFocusEvent& event); \
112 virtual void SetFocus(); \
113 virtual void RemoveChild(wxWindowBase *child); \
114 virtual wxWindow *GetDefaultItem() const; \
6b55490a 115 virtual wxWindow *SetDefaultItem(wxWindow *child); \
036da5e3 116 virtual void SetTmpDefaultItem(wxWindow *win); \
3251b834 117 virtual bool AcceptsFocus() const; \
6b55490a
VZ
118\
119protected: \
120 wxControlContainer m_container
456bc6d9
VZ
121
122// implement the event table entries for wxControlContainer
123#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
124 EVT_SET_FOCUS(classname::OnFocus) \
125 EVT_CHILD_FOCUS(classname::OnChildFocus) \
126 EVT_NAVIGATION_KEY(classname::OnNavigationKey)
127
128// implement the methods forwarding to the wxControlContainer
6b55490a 129#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname) \
456bc6d9
VZ
130wxWindow *classname::SetDefaultItem(wxWindow *child) \
131{ \
6b55490a 132 return m_container.SetDefaultItem(child); \
456bc6d9
VZ
133} \
134 \
036da5e3
VZ
135void classname::SetTmpDefaultItem(wxWindow *child) \
136{ \
137 m_container.SetTmpDefaultItem(child); \
138} \
139 \
456bc6d9
VZ
140wxWindow *classname::GetDefaultItem() const \
141{ \
6b55490a 142 return m_container.GetDefaultItem(); \
456bc6d9
VZ
143} \
144 \
145void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
146{ \
6b55490a 147 m_container.HandleOnNavigationKey(event); \
456bc6d9
VZ
148} \
149 \
150void classname::RemoveChild(wxWindowBase *child) \
151{ \
6b55490a 152 m_container.HandleOnWindowDestroy(child); \
456bc6d9
VZ
153 \
154 wxWindow::RemoveChild(child); \
155} \
156 \
157void classname::SetFocus() \
158{ \
6b55490a 159 if ( !m_container.DoSetFocus() ) \
24a7a198 160 wxWindow::SetFocus(); \
456bc6d9
VZ
161} \
162 \
163void classname::OnChildFocus(wxChildFocusEvent& event) \
164{ \
6b55490a 165 m_container.SetLastFocus(event.GetWindow()); \
456bc6d9
VZ
166} \
167 \
168void classname::OnFocus(wxFocusEvent& event) \
169{ \
6b55490a 170 m_container.HandleOnFocus(event); \
3251b834
VZ
171} \
172bool classname::AcceptsFocus() const \
173{ \
174 return m_container.AcceptsFocus(); \
456bc6d9
VZ
175}
176
177
178#endif // _WX_CONTAINR_H_