]> git.saurik.com Git - wxWidgets.git/blame - src/generic/panelg.cpp
wxLongLongWx::Assign(double) works - thanks Guillermo
[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
182 if (GetAutoLayout()) Layout();
183#endif
184}
185
3da17724
RR
186void wxPanel::SetFocus()
187{
188 // If the panel gets the focus *by way of getting it set directly*
69ffe1d2 189 // we move the focus to the first window that can get it.
3da17724
RR
190
191 wxNode *node = GetChildren().First();
192 while (node)
193 {
87a1e308
VZ
194 wxWindow *child = (wxWindow*) node->Data();
195 if (child->AcceptsFocus())
196 {
197 m_winLastFocused = child; // should be redundant, but it is not
198 child->SetFocus();
199 return;
200 }
3da17724
RR
201 node = node->Next();
202 }
87a1e308 203
3da17724 204 m_winLastFocused = (wxWindow*) NULL;
87a1e308 205
3da17724
RR
206 wxWindow::SetFocus();
207}
208
341c92a8
VZ
209void wxPanel::OnFocus(wxFocusEvent& event)
210{
3da17724 211 // If the panel gets the focus *by way of getting clicked on*
69ffe1d2
RR
212 // we move the focus to either the last window that had the
213 // focus or the first one that can get it.
3da17724
RR
214
215 if (m_winLastFocused)
0492c5a0 216 {
69ffe1d2
RR
217 // It might happen that the window got reparented or no longer
218 // accepts the focus.
219 if ((m_winLastFocused->GetParent() == this) &&
220 (m_winLastFocused->AcceptsFocus()))
87a1e308 221 {
319fefa9 222 m_winLastFocused->SetFocus();
87a1e308
VZ
223 return;
224 }
0492c5a0 225 }
87a1e308 226
3da17724
RR
227 wxNode *node = GetChildren().First();
228 while (node)
229 {
87a1e308
VZ
230 wxWindow *child = (wxWindow*) node->Data();
231 if (child->AcceptsFocus())
232 {
233 m_winLastFocused = child; // should be redundant, but it is not
234 child->SetFocus();
235 return;
236 }
3da17724
RR
237 node = node->Next();
238 }
87a1e308 239
3da17724 240 m_winLastFocused = (wxWindow*) NULL;
87a1e308 241
3da17724 242 event.Skip();
341c92a8 243}