]> git.saurik.com Git - wxWidgets.git/blame - include/wx/containr.h
test whether pointer is non-NULL before using it, not after, in wxAnimation::Load...
[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
617fb24f
VZ
16#include "wx/defs.h"
17
de160b06
VZ
18#ifdef wxHAS_NATIVE_TAB_TRAVERSAL
19
20#define WX_DECLARE_CONTROL_CONTAINER() \
21 virtual bool AcceptsFocus() const { return false; } \
22 void SetFocusIgnoringChildren() { SetFocus(); }
23
24#define WX_INIT_CONTROL_CONTAINER()
25#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname)
26#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename)
27
28#else // !wxHAS_NATIVE_TAB_TRAVERSAL
29
456bc6d9
VZ
30class WXDLLEXPORT wxFocusEvent;
31class WXDLLEXPORT wxNavigationKeyEvent;
32class WXDLLEXPORT wxWindow;
6285be72 33class WXDLLEXPORT wxWindowBase;
456bc6d9
VZ
34
35/*
36 Implementation note: wxControlContainer is not a real mix-in but rather
de160b06 37 a class meant to be aggregated with (and not inherited from). Although
456bc6d9
VZ
38 logically it should be a mix-in, doing it like this has no advantage from
39 the point of view of the existing code but does have some problems (we'd
40 need to play tricks with event handlers which may be difficult to do
41 safely). The price we pay for this simplicity is the ugly macros below.
42 */
43
44// ----------------------------------------------------------------------------
45// wxControlContainer
46// ----------------------------------------------------------------------------
47
48class WXDLLEXPORT wxControlContainer
49{
50public:
51 // ctors and such
9948d31f
VZ
52 wxControlContainer(wxWindow *winParent = NULL);
53 void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
456bc6d9 54
456bc6d9
VZ
55 // the methods to be called from the window event handlers
56 void HandleOnNavigationKey(wxNavigationKeyEvent& event);
57 void HandleOnFocus(wxFocusEvent& event);
58 void HandleOnWindowDestroy(wxWindowBase *child);
59
68379eaf 60 // should be called from SetFocus(), returns false if we did nothing with
24a7a198
VZ
61 // the focus and the default processing should take place
62 bool DoSetFocus();
456bc6d9 63
3251b834
VZ
64 // can our child get the focus?
65 bool AcceptsFocus() const;
66
9948d31f
VZ
67 // called from OnChildFocus() handler, i.e. when one of our (grand)
68 // children gets the focus
69 void SetLastFocus(wxWindow *win);
70
456bc6d9
VZ
71protected:
72 // set the focus to the child which had it the last time
73 bool SetFocusToChild();
74
75 // the parent window we manage the children for
76 wxWindow *m_winParent;
77
78 // the child which had the focus last time this panel was activated
79 wxWindow *m_winLastFocused;
80
b33f7651
JS
81 // a guard against infinite recursion
82 bool m_inSetFocus;
83
036da5e3 84 DECLARE_NO_COPY_CLASS(wxControlContainer)
456bc6d9
VZ
85};
86
77ffb593 87// this function is for wxWidgets internal use only
456bc6d9
VZ
88extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
89
90// ----------------------------------------------------------------------------
91// macros which may be used by the classes wishing to implement TAB navigation
92// among their children
93// ----------------------------------------------------------------------------
94
95// declare the methods to be forwarded
96#define WX_DECLARE_CONTROL_CONTAINER() \
6b55490a 97public: \
456bc6d9
VZ
98 void OnNavigationKey(wxNavigationKeyEvent& event); \
99 void OnFocus(wxFocusEvent& event); \
100 virtual void OnChildFocus(wxChildFocusEvent& event); \
101 virtual void SetFocus(); \
ababa106 102 virtual void SetFocusIgnoringChildren(); \
456bc6d9 103 virtual void RemoveChild(wxWindowBase *child); \
3251b834 104 virtual bool AcceptsFocus() const; \
6b55490a
VZ
105\
106protected: \
107 wxControlContainer m_container
456bc6d9 108
de160b06
VZ
109// this macro must be used in the derived class ctor
110#define WX_INIT_CONTROL_CONTAINER() \
111 m_container.SetContainerWindow(this)
112
456bc6d9
VZ
113// implement the event table entries for wxControlContainer
114#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
115 EVT_SET_FOCUS(classname::OnFocus) \
116 EVT_CHILD_FOCUS(classname::OnChildFocus) \
117 EVT_NAVIGATION_KEY(classname::OnNavigationKey)
118
119// implement the methods forwarding to the wxControlContainer
6c20e8f8 120#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) \
456bc6d9
VZ
121void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
122{ \
6b55490a 123 m_container.HandleOnNavigationKey(event); \
456bc6d9
VZ
124} \
125 \
126void classname::RemoveChild(wxWindowBase *child) \
127{ \
6b55490a 128 m_container.HandleOnWindowDestroy(child); \
456bc6d9 129 \
6c20e8f8 130 basename::RemoveChild(child); \
456bc6d9
VZ
131} \
132 \
133void classname::SetFocus() \
134{ \
6b55490a 135 if ( !m_container.DoSetFocus() ) \
6c20e8f8 136 basename::SetFocus(); \
456bc6d9
VZ
137} \
138 \
ababa106
RR
139void classname::SetFocusIgnoringChildren() \
140{ \
6c20e8f8 141 basename::SetFocus(); \
ababa106
RR
142} \
143 \
456bc6d9
VZ
144void classname::OnChildFocus(wxChildFocusEvent& event) \
145{ \
6b55490a 146 m_container.SetLastFocus(event.GetWindow()); \
456bc6d9
VZ
147} \
148 \
149void classname::OnFocus(wxFocusEvent& event) \
150{ \
6b55490a 151 m_container.HandleOnFocus(event); \
3251b834
VZ
152} \
153bool classname::AcceptsFocus() const \
154{ \
155 return m_container.AcceptsFocus(); \
456bc6d9
VZ
156}
157
de160b06 158#endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
456bc6d9
VZ
159
160#endif // _WX_CONTAINR_H_