]> git.saurik.com Git - wxWidgets.git/blame - src/generic/panelg.cpp
Some doc updates.
[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 {
f96aa4d9 58#ifndef __WXGTK__
b292e2f5
RR
59 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
60 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
f96aa4d9 61#endif
b292e2f5 62 }
c801d85f 63
b292e2f5 64 return ret;
c801d85f
KB
65}
66
67void wxPanel::InitDialog(void)
68{
b292e2f5
RR
69 wxInitDialogEvent event(GetId());
70 event.SetEventObject(this);
71 GetEventHandler()->ProcessEvent(event);
90c3bdac
VZ
72}
73
c801d85f
KB
74// Responds to colour changes, and passes event on to children.
75void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
76{
77 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
c801d85f
KB
78 Refresh();
79
80 // Propagate the event to the non-top-level children
81 wxWindow::OnSysColourChanged(event);
82}
83
b292e2f5 84void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
90c3bdac 85{
fb99aca7 86 // there is not much to do if we have only one child (or not at all)
399aa5e3 87 if (GetChildren().GetCount() < 2)
b292e2f5
RR
88 {
89 event.Skip();
90 return;
90c3bdac
VZ
91 }
92
b292e2f5 93 // don't process these ones here
fb99aca7 94 if (event.IsWindowChange())
b292e2f5
RR
95 {
96 event.Skip();
97 return;
90c3bdac
VZ
98 }
99
3da17724
RR
100 // Did the event emitter tell us where the last focus was?
101 // wxGTK does this in wxWindow, but wxMSW does not. It is
102 // also done in wxPanel if the event is propagated up.
103 wxWindow *winFocus = event.GetCurrentFocus();
87a1e308 104
3da17724
RR
105 // Do we know where the focus was ourselves, then?
106 if (!winFocus)
107 winFocus = m_winLastFocused;
87a1e308 108
fb99aca7
VZ
109 if (!winFocus)
110 winFocus = wxWindow::FindFocus();
27dc7e21 111
b292e2f5
RR
112 if (!winFocus)
113 {
114 event.Skip();
115 return;
116 }
fb99aca7 117
f03fc89f 118 wxWindowList::Node *start_node = GetChildren().Find( winFocus );
a1665b22
VZ
119 if ( !start_node )
120 start_node = GetChildren().Find( m_winLastFocused );
121 if ( !start_node )
f03fc89f 122 start_node = GetChildren().GetFirst();
fb99aca7 123
f03fc89f
VZ
124 wxWindowList::Node *node = event.GetDirection() ? start_node->GetNext()
125 : start_node->GetPrevious();
fb99aca7 126
a1665b22 127 while ( node != start_node )
b292e2f5 128 {
3da17724 129 // Have we come to the last or first item on the panel?
a1665b22 130 if ( !node )
fb99aca7 131 {
3da17724 132 // Check if our (may be grand) parent is another panel: if this is
a1665b22
VZ
133 // the case, they will know what to do with this navigation key and
134 // so give them the chance to process it instead of looping inside
135 // this panel (normally, the focus will go to the next/previous
3da17724 136 // item after this panel in the parent panel).
87a1e308 137 wxWindow *focussed_child_of_parent = this;
3da17724 138 for ( wxWindow *parent = GetParent(); parent; parent = parent->GetParent() )
a1665b22 139 {
87a1e308
VZ
140 // we don't want to tab into a different dialog or frame
141 if ( focussed_child_of_parent->IsTopLevel() )
142 break;
143
144 // is the parent a panel?
145 wxPanel *panel = wxDynamicCast(parent, wxPanel);
3da17724 146 if (panel)
a1665b22 147 {
87a1e308
VZ
148 event.SetCurrentFocus( focussed_child_of_parent );
149 if (parent->GetEventHandler()->ProcessEvent( event ))
ed58dbea 150 return;
a1665b22 151 }
87a1e308
VZ
152
153 focussed_child_of_parent = parent;
a1665b22
VZ
154 }
155
156 // no, we are not inside another panel so process this ourself
f03fc89f
VZ
157 node = event.GetDirection() ? GetChildren().GetFirst()
158 : GetChildren().GetLast();
341c92a8 159
e4ffaca4 160 continue;
fb99aca7
VZ
161 }
162
f03fc89f 163 wxWindow *child = node->GetData();
fb99aca7 164
a1665b22 165 if ( child->AcceptsFocus() )
fb99aca7 166 {
87a1e308 167 m_winLastFocused = child; // should be redundant, but it is not
fb99aca7
VZ
168 child->SetFocus();
169 return;
170 }
171
f03fc89f 172 node = event.GetDirection() ? node->GetNext() : node->GetPrevious();
b292e2f5 173 }
fb99aca7
VZ
174
175 // we cycled through all of our children and none of them wanted to accept
176 // focus
b292e2f5 177 event.Skip();
6e4739a0 178}
58614078 179
27dc7e21
RD
180
181void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event))
182{
183#if wxUSE_CONSTRAINTS
184 if (GetAutoLayout()) Layout();
185#endif
186}
187
3da17724
RR
188void wxPanel::SetFocus()
189{
190 // If the panel gets the focus *by way of getting it set directly*
69ffe1d2 191 // we move the focus to the first window that can get it.
3da17724
RR
192
193 wxNode *node = GetChildren().First();
194 while (node)
195 {
87a1e308
VZ
196 wxWindow *child = (wxWindow*) node->Data();
197 if (child->AcceptsFocus())
198 {
199 m_winLastFocused = child; // should be redundant, but it is not
200 child->SetFocus();
201 return;
202 }
3da17724
RR
203 node = node->Next();
204 }
87a1e308 205
3da17724 206 m_winLastFocused = (wxWindow*) NULL;
87a1e308 207
3da17724
RR
208 wxWindow::SetFocus();
209}
210
341c92a8
VZ
211void wxPanel::OnFocus(wxFocusEvent& event)
212{
3da17724 213 // If the panel gets the focus *by way of getting clicked on*
69ffe1d2
RR
214 // we move the focus to either the last window that had the
215 // focus or the first one that can get it.
3da17724
RR
216
217 if (m_winLastFocused)
0492c5a0 218 {
69ffe1d2
RR
219 // It might happen that the window got reparented or no longer
220 // accepts the focus.
221 if ((m_winLastFocused->GetParent() == this) &&
222 (m_winLastFocused->AcceptsFocus()))
87a1e308 223 {
319fefa9 224 m_winLastFocused->SetFocus();
87a1e308
VZ
225 return;
226 }
0492c5a0 227 }
87a1e308 228
3da17724
RR
229 wxNode *node = GetChildren().First();
230 while (node)
231 {
87a1e308
VZ
232 wxWindow *child = (wxWindow*) node->Data();
233 if (child->AcceptsFocus())
234 {
235 m_winLastFocused = child; // should be redundant, but it is not
236 child->SetFocus();
237 return;
238 }
3da17724
RR
239 node = node->Next();
240 }
87a1e308 241
3da17724 242 m_winLastFocused = (wxWindow*) NULL;
87a1e308 243
3da17724 244 event.Skip();
341c92a8 245}