]> git.saurik.com Git - wxWidgets.git/blame - src/generic/panelg.cpp
Several changes and 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
fb99aca7 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
32#if !USE_SHARED_LIBRARY
33IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
34
35BEGIN_EVENT_TABLE(wxPanel, wxWindow)
36 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
341c92a8 37 EVT_SET_FOCUS(wxPanel::OnFocus)
90c3bdac 38 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey)
c801d85f
KB
39END_EVENT_TABLE()
40
41#endif
42
edccf428 43void wxPanel::Init()
c801d85f 44{
319fefa9 45 m_winLastFocused = (wxWindow *)NULL;
edccf428 46 m_btnDefault = (wxButton *)NULL;
c801d85f
KB
47}
48
debe6624 49bool wxPanel::Create(wxWindow *parent, wxWindowID id,
90c3bdac
VZ
50 const wxPoint& pos,
51 const wxSize& size,
52 long style,
53 const wxString& name)
c801d85f 54{
b292e2f5 55 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
c801d85f 56
fb99aca7 57 if ( ret )
b292e2f5 58 {
f96aa4d9 59#ifndef __WXGTK__
b292e2f5
RR
60 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
61 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
f96aa4d9 62#endif
b292e2f5 63 }
c801d85f 64
b292e2f5 65 return ret;
c801d85f
KB
66}
67
68void wxPanel::InitDialog(void)
69{
b292e2f5
RR
70 wxInitDialogEvent event(GetId());
71 event.SetEventObject(this);
72 GetEventHandler()->ProcessEvent(event);
90c3bdac
VZ
73}
74
c801d85f
KB
75// Responds to colour changes, and passes event on to children.
76void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
77{
78 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
c801d85f
KB
79 Refresh();
80
81 // Propagate the event to the non-top-level children
82 wxWindow::OnSysColourChanged(event);
83}
84
b292e2f5 85void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
90c3bdac 86{
fb99aca7 87 // there is not much to do if we have only one child (or not at all)
399aa5e3 88 if (GetChildren().GetCount() < 2)
b292e2f5
RR
89 {
90 event.Skip();
91 return;
90c3bdac
VZ
92 }
93
b292e2f5 94 // don't process these ones here
fb99aca7 95 if (event.IsWindowChange())
b292e2f5
RR
96 {
97 event.Skip();
98 return;
90c3bdac
VZ
99 }
100
b292e2f5 101 wxWindow *winFocus = event.GetCurrentFocus();
fb99aca7
VZ
102 if (!winFocus)
103 winFocus = wxWindow::FindFocus();
ed58dbea 104
b292e2f5
RR
105 if (!winFocus)
106 {
107 event.Skip();
108 return;
109 }
fb99aca7 110
f03fc89f 111 wxWindowList::Node *start_node = GetChildren().Find( winFocus );
a1665b22
VZ
112 if ( !start_node )
113 start_node = GetChildren().Find( m_winLastFocused );
114 if ( !start_node )
f03fc89f 115 start_node = GetChildren().GetFirst();
fb99aca7 116
f03fc89f
VZ
117 wxWindowList::Node *node = event.GetDirection() ? start_node->GetNext()
118 : start_node->GetPrevious();
fb99aca7 119
a1665b22 120 while ( node != start_node )
b292e2f5 121 {
a1665b22 122 if ( !node )
fb99aca7 123 {
a1665b22
VZ
124 // check if our (may be grand) parent is another panel: if this is
125 // the case, they will know what to do with this navigation key and
126 // so give them the chance to process it instead of looping inside
127 // this panel (normally, the focus will go to the next/previous
128 // item after this panel in the parent panel)
ed58dbea 129 wxWindow *focussed_child_of_p = this;
a1665b22
VZ
130 for ( wxWindow *p = GetParent(); p; p = p->GetParent() )
131 {
132 if ( wxDynamicCast(p, wxPanel) )
133 {
ed58dbea
RR
134 event.SetCurrentFocus( focussed_child_of_p );
135 if (p->GetEventHandler()->ProcessEvent( event ))
136 return;
a1665b22 137 }
ed58dbea 138 focussed_child_of_p = p;
a1665b22
VZ
139 }
140
141 // no, we are not inside another panel so process this ourself
f03fc89f
VZ
142 node = event.GetDirection() ? GetChildren().GetFirst()
143 : GetChildren().GetLast();
341c92a8 144
e4ffaca4 145 continue;
fb99aca7
VZ
146 }
147
f03fc89f 148 wxWindow *child = node->GetData();
fb99aca7 149
a1665b22 150 if ( child->AcceptsFocus() )
fb99aca7
VZ
151 {
152 // ok, event processed
153 child->SetFocus();
154 return;
155 }
156
f03fc89f 157 node = event.GetDirection() ? node->GetNext() : node->GetPrevious();
b292e2f5 158 }
fb99aca7
VZ
159
160 // we cycled through all of our children and none of them wanted to accept
161 // focus
b292e2f5 162 event.Skip();
6e4739a0 163}
58614078 164
341c92a8
VZ
165void wxPanel::OnFocus(wxFocusEvent& event)
166{
319fefa9 167 if ( m_winLastFocused )
0492c5a0 168 {
319fefa9
VZ
169 // it might happen that the window got reparented...
170 if ( m_winLastFocused->GetParent() != this )
171 m_winLastFocused = (wxWindow *)NULL;
172 else
173 m_winLastFocused->SetFocus();
0492c5a0 174 }
341c92a8
VZ
175 else
176 event.Skip();
177}