]> git.saurik.com Git - wxWidgets.git/blame - src/generic/panelg.cpp
Tweaks needed to be able to build wxPython with wxGTK.
[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
9// Licence: wxWindows license
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
24#include "wx/settings.h"
25#endif
26
27#include "wx/generic/panelg.h"
28
29#if !USE_SHARED_LIBRARY
30IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
31
32BEGIN_EVENT_TABLE(wxPanel, wxWindow)
33 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
90c3bdac 34 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey)
c801d85f
KB
35END_EVENT_TABLE()
36
37#endif
38
90c3bdac 39wxPanel::wxPanel()
c801d85f 40{
c801d85f
KB
41}
42
debe6624 43bool wxPanel::Create(wxWindow *parent, wxWindowID id,
90c3bdac
VZ
44 const wxPoint& pos,
45 const wxSize& size,
46 long style,
47 const wxString& name)
c801d85f
KB
48{
49 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
50
90c3bdac 51 if ( ret ) {
f96aa4d9 52#ifndef __WXGTK__
90c3bdac 53 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
90c3bdac 54 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
f96aa4d9 55#endif
90c3bdac 56 }
c801d85f 57
90c3bdac 58 return ret;
c801d85f
KB
59}
60
61void wxPanel::InitDialog(void)
62{
63 wxInitDialogEvent event(GetId());
64 event.SetEventObject(this);
65 GetEventHandler()->ProcessEvent(event);
66}
67
90c3bdac
VZ
68void wxPanel::SetFocus()
69{
70 SetFocusToNextChild();
71}
72
c801d85f
KB
73// Responds to colour changes, and passes event on to children.
74void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
75{
76 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
c801d85f
KB
77 Refresh();
78
79 // Propagate the event to the non-top-level children
80 wxWindow::OnSysColourChanged(event);
81}
82
90c3bdac
VZ
83void wxPanel::OnNavigationKey(wxNavigationKeyEvent& event)
84{
85 // don't process these ones here
86 if ( event.IsWindowChange() ) {
87 event.Skip();
88 return;
89 }
90
91 // first of all, find the window which currently has the focus
c0ed460c 92 wxNode *node = GetChildren().First();
90c3bdac 93 wxWindow *winFocus = event.GetCurrentFocus();
6e4739a0
VZ
94
95 // @@@ no FindFocus() in wxGTK
2049ba38 96 #ifndef __WXGTK__
6e4739a0
VZ
97 if ( winFocus == NULL )
98 winFocus = wxWindow::FindFocus();
99 #endif
100
90c3bdac
VZ
101 while ( node != NULL ) {
102 if ( node->Data() == winFocus )
103 break;
104
105 node = node->Next();
106 }
107
108 if ( !SetFocusToNextChild(node, event.GetDirection()) )
109 event.Skip();
110}
111
112// set focus to the next child which accepts it (or first/last if node == NULL)
113bool wxPanel::SetFocusToNextChild(wxNode *node, bool bForward)
114{
115 // @@ using typed list would be better...
116 #define WIN(node) ((wxWindow *)(node->Data()))
117
118 bool bFound = FALSE; // have we found a window we will set focus to?
119
c0ed460c 120 wxList *children = & GetChildren();
90c3bdac
VZ
121 if ( node == NULL ) {
122 // we've never had focus before
123 node = bForward ? children->First() : children->Last();
124 if ( node == NULL ) {
125 // no children
126 return FALSE;
127 }
128
129 bFound = WIN(node)->AcceptsFocus();
130 }
86bb7d48 131#if 0 // to restore when it will really work (now it's triggered all the time)
90c3bdac
VZ
132 else {
133 // just to be sure it's the right one
134 wxASSERT( WIN(node)->AcceptsFocus() );
135 }
86bb7d48 136#endif // 0
90c3bdac
VZ
137
138 // find the next child which accepts focus
86bb7d48 139 bool bParentWantsIt = TRUE;
90c3bdac
VZ
140 while ( !bFound ) {
141 node = bForward ? node->Next() : node->Previous();
142 if ( node == NULL ) {
86bb7d48
VZ
143 if ( !bParentWantsIt ) {
144 // we've already been here which means that we've done a whole
145 // cycle without success - get out from the infinite loop
146 return FALSE;
147 }
148
90c3bdac
VZ
149 // ask parent if he doesn't want to advance focus to the next panel
150 if ( GetParent() != NULL ) {
151 wxNavigationKeyEvent event;
152 event.SetDirection(bForward);
153 event.SetWindowChange(FALSE);
154 event.SetCurrentFocus(this);
155
156 if ( GetParent()->ProcessEvent(event) )
157 return TRUE;
158 }
159
86bb7d48
VZ
160 // a sentinel to avoid infinite loops
161 bParentWantsIt = FALSE;
162
90c3bdac
VZ
163 // wrap around
164 node = bForward ? children->First() : children->Last();
165 }
166
167 bFound = WIN(node)->AcceptsFocus();
168 }
169
170 WIN(node)->SetFocus();
171
172 #undef WIN
173
174 return TRUE;
6e4739a0 175}
58614078 176