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