]> git.saurik.com Git - wxWidgets.git/blame - src/generic/panelg.cpp
1. added some test code (currently disabled) to controls
[wxWidgets.git] / src / generic / panelg.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: panelg.cpp
3// Purpose: wxPanel
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
87a1e308 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "panelg.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
2432b92d
JS
24#include "wx/object.h"
25#include "wx/font.h"
26#include "wx/colour.h"
c801d85f
KB
27#include "wx/settings.h"
28#endif
29
30#include "wx/generic/panelg.h"
31
c801d85f
KB
32IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
33
34BEGIN_EVENT_TABLE(wxPanel, wxWindow)
35 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
341c92a8 36 EVT_SET_FOCUS(wxPanel::OnFocus)
90c3bdac 37 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey)
27dc7e21 38 EVT_SIZE(wxPanel::OnSize)
c801d85f
KB
39END_EVENT_TABLE()
40
c801d85f 41
edccf428 42void wxPanel::Init()
c801d85f 43{
319fefa9 44 m_winLastFocused = (wxWindow *)NULL;
edccf428 45 m_btnDefault = (wxButton *)NULL;
c801d85f
KB
46}
47
debe6624 48bool wxPanel::Create(wxWindow *parent, wxWindowID id,
90c3bdac
VZ
49 const wxPoint& pos,
50 const wxSize& size,
51 long style,
52 const wxString& name)
c801d85f 53{
b292e2f5 54 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
c801d85f 55
fb99aca7 56 if ( ret )
b292e2f5 57 {
b292e2f5
RR
58 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
59 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
b292e2f5 60 }
c801d85f 61
b292e2f5 62 return ret;
c801d85f
KB
63}
64
65void wxPanel::InitDialog(void)
66{
b292e2f5
RR
67 wxInitDialogEvent event(GetId());
68 event.SetEventObject(this);
69 GetEventHandler()->ProcessEvent(event);
90c3bdac
VZ
70}
71
c801d85f
KB
72// Responds to colour changes, and passes event on to children.
73void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
74{
75 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
c801d85f
KB
76 Refresh();
77
78 // Propagate the event to the non-top-level children
79 wxWindow::OnSysColourChanged(event);
80}
81
b292e2f5 82void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
90c3bdac 83{
fb99aca7 84 // there is not much to do if we have only one child (or not at all)
399aa5e3 85 if (GetChildren().GetCount() < 2)
b292e2f5
RR
86 {
87 event.Skip();
88 return;
90c3bdac
VZ
89 }
90
b292e2f5 91 // don't process these ones here
fb99aca7 92 if (event.IsWindowChange())
b292e2f5
RR
93 {
94 event.Skip();
95 return;
90c3bdac
VZ
96 }
97
3da17724
RR
98 // Did the event emitter tell us where the last focus was?
99 // wxGTK does this in wxWindow, but wxMSW does not. It is
100 // also done in wxPanel if the event is propagated up.
101 wxWindow *winFocus = event.GetCurrentFocus();
87a1e308 102
3da17724
RR
103 // Do we know where the focus was ourselves, then?
104 if (!winFocus)
105 winFocus = m_winLastFocused;
87a1e308 106
fb99aca7
VZ
107 if (!winFocus)
108 winFocus = wxWindow::FindFocus();
27dc7e21 109
b292e2f5
RR
110 if (!winFocus)
111 {
112 event.Skip();
113 return;
114 }
fb99aca7 115
f03fc89f 116 wxWindowList::Node *start_node = GetChildren().Find( winFocus );
a1665b22
VZ
117 if ( !start_node )
118 start_node = GetChildren().Find( m_winLastFocused );
119 if ( !start_node )
f03fc89f 120 start_node = GetChildren().GetFirst();
fb99aca7 121
f03fc89f
VZ
122 wxWindowList::Node *node = event.GetDirection() ? start_node->GetNext()
123 : start_node->GetPrevious();
fb99aca7 124
a1665b22 125 while ( node != start_node )
b292e2f5 126 {
3da17724 127 // Have we come to the last or first item on the panel?
a1665b22 128 if ( !node )
fb99aca7 129 {
3da17724 130 // Check if our (may be grand) parent is another panel: if this is
a1665b22
VZ
131 // the case, they will know what to do with this navigation key and
132 // so give them the chance to process it instead of looping inside
133 // this panel (normally, the focus will go to the next/previous
3da17724 134 // item after this panel in the parent panel).
87a1e308 135 wxWindow *focussed_child_of_parent = this;
3da17724 136 for ( wxWindow *parent = GetParent(); parent; parent = parent->GetParent() )
a1665b22 137 {
87a1e308
VZ
138 // we don't want to tab into a different dialog or frame
139 if ( focussed_child_of_parent->IsTopLevel() )
140 break;
141
142 // is the parent a panel?
143 wxPanel *panel = wxDynamicCast(parent, wxPanel);
3da17724 144 if (panel)
a1665b22 145 {
87a1e308
VZ
146 event.SetCurrentFocus( focussed_child_of_parent );
147 if (parent->GetEventHandler()->ProcessEvent( event ))
ed58dbea 148 return;
a1665b22 149 }
87a1e308
VZ
150
151 focussed_child_of_parent = parent;
a1665b22
VZ
152 }
153
154 // no, we are not inside another panel so process this ourself
f03fc89f
VZ
155 node = event.GetDirection() ? GetChildren().GetFirst()
156 : GetChildren().GetLast();
341c92a8 157
e4ffaca4 158 continue;
fb99aca7
VZ
159 }
160
f03fc89f 161 wxWindow *child = node->GetData();
fb99aca7 162
a1665b22 163 if ( child->AcceptsFocus() )
fb99aca7 164 {
87a1e308 165 m_winLastFocused = child; // should be redundant, but it is not
fb99aca7
VZ
166 child->SetFocus();
167 return;
168 }
169
f03fc89f 170 node = event.GetDirection() ? node->GetNext() : node->GetPrevious();
b292e2f5 171 }
fb99aca7
VZ
172
173 // we cycled through all of our children and none of them wanted to accept
174 // focus
b292e2f5 175 event.Skip();
6e4739a0 176}
58614078 177
27dc7e21
RD
178
179void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event))
180{
181#if wxUSE_CONSTRAINTS
d9317fd4
VZ
182 if (GetAutoLayout())
183 Layout();
27dc7e21
RD
184#endif
185}
186
3da17724
RR
187void wxPanel::SetFocus()
188{
00c4e897
VZ
189 wxLogTrace(_T("focus"), _T("SetFocus on wxPanel 0x%08x."), GetHandle());
190
3da17724 191 // If the panel gets the focus *by way of getting it set directly*
69ffe1d2 192 // we move the focus to the first window that can get it.
3da17724 193
00c4e897
VZ
194 // VZ: no, we set the focus to the last window too. I don't understand why
195 // should we make this distinction: if an app wants to set focus to
196 // some precise control, it may always do it directly, but if we don't
197 // use m_winLastFocused here, the focus won't be set correctly after a
198 // notebook page change nor after frame activation under MSW (it calls
199 // SetFocus too)
200 //
201 // If you still want to have old behaviour for wxGTK, edit the
202 // following line
203#if 0 // def __WXGTK__
204 m_winLastFocused = (wxWindow *)NULL;
205#endif // 0
206
207 if ( !SetFocusToChild() )
3da17724 208 {
00c4e897 209 wxWindow::SetFocus();
3da17724 210 }
3da17724
RR
211}
212
341c92a8
VZ
213void wxPanel::OnFocus(wxFocusEvent& event)
214{
00c4e897
VZ
215 wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x."), GetHandle());
216
3da17724 217 // If the panel gets the focus *by way of getting clicked on*
69ffe1d2
RR
218 // we move the focus to either the last window that had the
219 // focus or the first one that can get it.
00c4e897
VZ
220 (void)SetFocusToChild();
221
222 event.Skip();
223}
3da17724 224
00c4e897
VZ
225bool wxPanel::SetFocusToChild()
226{
227 if ( m_winLastFocused )
0492c5a0 228 {
00c4e897
VZ
229 // It might happen that the window got reparented or no longer accepts
230 // the focus.
231 if ( (m_winLastFocused->GetParent() == this) &&
232 m_winLastFocused->AcceptsFocus() )
87a1e308 233 {
00c4e897
VZ
234 wxLogTrace(_T("focus"),
235 _T("SetFocusToChild() => last child (0x%08x)."),
236 m_winLastFocused->GetHandle());
237
319fefa9 238 m_winLastFocused->SetFocus();
00c4e897
VZ
239 return TRUE;
240 }
241 else
242 {
243 // it doesn't count as such any more
244 m_winLastFocused = (wxWindow *)NULL;
87a1e308 245 }
0492c5a0 246 }
87a1e308 247
00c4e897
VZ
248 // set the focus to the first child who wants it
249 wxWindowList::Node *node = GetChildren().GetFirst();
250 while ( node )
3da17724 251 {
00c4e897
VZ
252 wxWindow *child = node->GetData();
253 if ( child->AcceptsFocus() )
87a1e308 254 {
00c4e897
VZ
255 wxLogTrace(_T("focus"),
256 _T("SetFocusToChild() => first child (0x%08x)."),
257 child->GetHandle());
258
87a1e308
VZ
259 m_winLastFocused = child; // should be redundant, but it is not
260 child->SetFocus();
00c4e897 261 return TRUE;
87a1e308 262 }
87a1e308 263
00c4e897
VZ
264 node = node->GetNext();
265 }
87a1e308 266
00c4e897 267 return FALSE;
341c92a8 268}