]> git.saurik.com Git - wxWidgets.git/blame - include/wx/containr.h
implemented wxDC::DoGetSize() correctly for metafile DC classes
[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>
65571936 10// Licence: wxWindows licence
456bc6d9
VZ
11///////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_CONTAINR_H_
14#define _WX_CONTAINR_H_
15
456bc6d9
VZ
16class WXDLLEXPORT wxFocusEvent;
17class WXDLLEXPORT wxNavigationKeyEvent;
18class WXDLLEXPORT wxWindow;
6285be72 19class WXDLLEXPORT wxWindowBase;
456bc6d9
VZ
20
21/*
22 Implementation note: wxControlContainer is not a real mix-in but rather
23 a class meant to be agregated with (and not inherited from). Although
24 logically it should be a mix-in, doing it like this has no advantage from
25 the point of view of the existing code but does have some problems (we'd
26 need to play tricks with event handlers which may be difficult to do
27 safely). The price we pay for this simplicity is the ugly macros below.
28 */
29
30// ----------------------------------------------------------------------------
31// wxControlContainer
32// ----------------------------------------------------------------------------
33
34class WXDLLEXPORT wxControlContainer
35{
36public:
37 // ctors and such
9948d31f
VZ
38 wxControlContainer(wxWindow *winParent = NULL);
39 void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
456bc6d9 40
036da5e3
VZ
41 // default item access: we have a permanent default item which is the one
42 // set by the user code but we may also have a temporary default item which
43 // would be chosen if the user pressed "Enter" now but the default action
44 // reverts to the "permanent" default as soon as this temporary default
45 // item lsoes focus
46
47 // get the default item, temporary or permanent
48 wxWindow *GetDefaultItem() const
49 { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
50
51 // set the permanent default item, return its old value
456bc6d9
VZ
52 wxWindow *SetDefaultItem(wxWindow *win)
53 { wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
54
036da5e3
VZ
55 // set a temporary default item, SetTmpDefaultItem(NULL) should be called
56 // soon after a call to SetTmpDefaultItem(window)
57 void SetTmpDefaultItem(wxWindow *win) { m_winTmpDefault = win; }
58
456bc6d9
VZ
59 // the methods to be called from the window event handlers
60 void HandleOnNavigationKey(wxNavigationKeyEvent& event);
61 void HandleOnFocus(wxFocusEvent& event);
62 void HandleOnWindowDestroy(wxWindowBase *child);
63
68379eaf 64 // should be called from SetFocus(), returns false if we did nothing with
24a7a198
VZ
65 // the focus and the default processing should take place
66 bool DoSetFocus();
456bc6d9 67
3251b834
VZ
68 // can our child get the focus?
69 bool AcceptsFocus() const;
70
9948d31f
VZ
71 // called from OnChildFocus() handler, i.e. when one of our (grand)
72 // children gets the focus
73 void SetLastFocus(wxWindow *win);
74
456bc6d9
VZ
75protected:
76 // set the focus to the child which had it the last time
77 bool SetFocusToChild();
78
79 // the parent window we manage the children for
80 wxWindow *m_winParent;
81
82 // the child which had the focus last time this panel was activated
83 wxWindow *m_winLastFocused;
84
036da5e3 85 // a default window (usually a button) or NULL
456bc6d9 86 wxWindow *m_winDefault;
036da5e3
VZ
87
88 // a temporary override of m_winDefault, use the latter if NULL
89 wxWindow *m_winTmpDefault;
90
b33f7651
JS
91 // a guard against infinite recursion
92 bool m_inSetFocus;
93
036da5e3 94 DECLARE_NO_COPY_CLASS(wxControlContainer)
456bc6d9
VZ
95};
96
77ffb593 97// this function is for wxWidgets internal use only
456bc6d9
VZ
98extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
99
100// ----------------------------------------------------------------------------
101// macros which may be used by the classes wishing to implement TAB navigation
102// among their children
103// ----------------------------------------------------------------------------
104
105// declare the methods to be forwarded
106#define WX_DECLARE_CONTROL_CONTAINER() \
6b55490a 107public: \
456bc6d9
VZ
108 void OnNavigationKey(wxNavigationKeyEvent& event); \
109 void OnFocus(wxFocusEvent& event); \
110 virtual void OnChildFocus(wxChildFocusEvent& event); \
111 virtual void SetFocus(); \
ababa106 112 virtual void SetFocusIgnoringChildren(); \
456bc6d9
VZ
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 \
ababa106
RR
163void classname::SetFocusIgnoringChildren() \
164{ \
165 wxWindow::SetFocus(); \
166} \
167 \
456bc6d9
VZ
168void classname::OnChildFocus(wxChildFocusEvent& event) \
169{ \
6b55490a 170 m_container.SetLastFocus(event.GetWindow()); \
456bc6d9
VZ
171} \
172 \
173void classname::OnFocus(wxFocusEvent& event) \
174{ \
6b55490a 175 m_container.HandleOnFocus(event); \
3251b834
VZ
176} \
177bool classname::AcceptsFocus() const \
178{ \
179 return m_container.AcceptsFocus(); \
456bc6d9
VZ
180}
181
182
183#endif // _WX_CONTAINR_H_