]> git.saurik.com Git - wxWidgets.git/blame - src/generic/panelg.cpp
added #include <fcntl.h> to allow compilation under Linux
[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
90c3bdac 43wxPanel::wxPanel()
c801d85f 44{
341c92a8 45 m_lastFocus = 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{
341c92a8
VZ
54 m_lastFocus = NULL;
55
b292e2f5 56 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
c801d85f 57
fb99aca7 58 if ( ret )
b292e2f5 59 {
f96aa4d9 60#ifndef __WXGTK__
b292e2f5
RR
61 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
62 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
f96aa4d9 63#endif
b292e2f5 64 }
c801d85f 65
b292e2f5 66 return ret;
c801d85f
KB
67}
68
69void wxPanel::InitDialog(void)
70{
b292e2f5
RR
71 wxInitDialogEvent event(GetId());
72 event.SetEventObject(this);
73 GetEventHandler()->ProcessEvent(event);
90c3bdac
VZ
74}
75
c801d85f
KB
76// Responds to colour changes, and passes event on to children.
77void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
78{
79 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
c801d85f
KB
80 Refresh();
81
82 // Propagate the event to the non-top-level children
83 wxWindow::OnSysColourChanged(event);
84}
85
b292e2f5 86void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
90c3bdac 87{
fb99aca7 88 // there is not much to do if we have only one child (or not at all)
399aa5e3 89 if (GetChildren().GetCount() < 2)
b292e2f5
RR
90 {
91 event.Skip();
92 return;
90c3bdac
VZ
93 }
94
b292e2f5 95 // don't process these ones here
fb99aca7 96 if (event.IsWindowChange())
b292e2f5
RR
97 {
98 event.Skip();
99 return;
90c3bdac
VZ
100 }
101
b292e2f5 102 wxWindow *winFocus = event.GetCurrentFocus();
fb99aca7
VZ
103 if (!winFocus)
104 winFocus = wxWindow::FindFocus();
105
b292e2f5
RR
106 if (!winFocus)
107 {
108 event.Skip();
109 return;
110 }
fb99aca7 111
399aa5e3 112 wxNode *start_node = GetChildren().Find( winFocus );
fb99aca7
VZ
113 if (!start_node)
114 start_node = GetChildren().First();
115
116 wxNode *node = event.GetDirection() ? start_node->Next()
117 : start_node->Previous();
118
b292e2f5
RR
119 while (node != start_node)
120 {
fb99aca7
VZ
121 if (!node)
122 {
341c92a8
VZ
123//#if 0 // FIXME seems to enter in an infinite loop - how is this possible?
124 // we arrived at the last/first of our children - but may be this
125 // panel is inside another panel, so make focus go to the next/prev
126 // control in the parent (if we have one)
fb99aca7
VZ
127 if (GetParent() != NULL)
128 {
b292e2f5
RR
129 wxNavigationKeyEvent new_event;
130 new_event.SetDirection( event.GetDirection() );
131 new_event.SetWindowChange(FALSE);
132 new_event.SetCurrentFocus( this );
133
134 if (GetParent()->GetEventHandler()->ProcessEvent(new_event))
fb99aca7
VZ
135 {
136 return;
137 }
b292e2f5 138 }
341c92a8 139//#endif // 0
fb99aca7
VZ
140
141 node = event.GetDirection() ? GetChildren().First()
142 : GetChildren().Last();
341c92a8
VZ
143
144 continue;
fb99aca7
VZ
145 }
146
147 wxWindow *child = (wxWindow *)node->Data();
148
149 if (child->AcceptsFocus())
150 {
151 // ok, event processed
152 child->SetFocus();
153 return;
154 }
155
156 node = event.GetDirection() ? node->Next() : node->Previous();
b292e2f5 157 }
fb99aca7
VZ
158
159 // we cycled through all of our children and none of them wanted to accept
160 // focus
b292e2f5 161 event.Skip();
6e4739a0 162}
58614078 163
341c92a8
VZ
164void wxPanel::OnFocus(wxFocusEvent& event)
165{
166 if ( m_lastFocus )
167 m_lastFocus->SetFocus();
168 else
169 event.Skip();
170}