]> git.saurik.com Git - wxWidgets.git/blob - src/generic/panelg.cpp
809cb7c569b8a92ab59fba655d0e58b79539b393
[wxWidgets.git] / src / generic / panelg.cpp
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
30 IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
31
32 BEGIN_EVENT_TABLE(wxPanel, wxWindow)
33 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
34 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey)
35 END_EVENT_TABLE()
36
37 #endif
38
39 wxPanel::wxPanel()
40 {
41 }
42
43 bool wxPanel::Create(wxWindow *parent, wxWindowID id,
44 const wxPoint& pos,
45 const wxSize& size,
46 long style,
47 const wxString& name)
48 {
49 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
50
51 if ( ret ) {
52 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
53 SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
54 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
55 }
56
57 return ret;
58 }
59
60 void wxPanel::InitDialog(void)
61 {
62 wxInitDialogEvent event(GetId());
63 event.SetEventObject(this);
64 GetEventHandler()->ProcessEvent(event);
65 }
66
67 void wxPanel::SetFocus()
68 {
69 SetFocusToNextChild();
70 }
71
72 // Responds to colour changes, and passes event on to children.
73 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
74 {
75 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
76 SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
77 Refresh();
78
79 // Propagate the event to the non-top-level children
80 wxWindow::OnSysColourChanged(event);
81 }
82
83 void 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
92 wxNode *node = GetChildren()->First();
93 wxWindow *winFocus = event.GetCurrentFocus();
94 if ( winFocus == NULL )
95 winFocus = wxWindow::FindFocus();
96 while ( node != NULL ) {
97 if ( node->Data() == winFocus )
98 break;
99
100 node = node->Next();
101 }
102
103 if ( !SetFocusToNextChild(node, event.GetDirection()) )
104 event.Skip();
105 }
106
107 // set focus to the next child which accepts it (or first/last if node == NULL)
108 bool wxPanel::SetFocusToNextChild(wxNode *node, bool bForward)
109 {
110 // @@ using typed list would be better...
111 #define WIN(node) ((wxWindow *)(node->Data()))
112
113 bool bFound = FALSE; // have we found a window we will set focus to?
114
115 wxList *children = GetChildren();
116 if ( node == NULL ) {
117 // we've never had focus before
118 node = bForward ? children->First() : children->Last();
119 if ( node == NULL ) {
120 // no children
121 return FALSE;
122 }
123
124 bFound = WIN(node)->AcceptsFocus();
125 }
126 else {
127 // just to be sure it's the right one
128 wxASSERT( WIN(node)->AcceptsFocus() );
129 }
130
131 // find the next child which accepts focus
132 while ( !bFound ) {
133 node = bForward ? node->Next() : node->Previous();
134 if ( node == NULL ) {
135 // ask parent if he doesn't want to advance focus to the next panel
136 if ( GetParent() != NULL ) {
137 wxNavigationKeyEvent event;
138 event.SetDirection(bForward);
139 event.SetWindowChange(FALSE);
140 event.SetCurrentFocus(this);
141
142 if ( GetParent()->ProcessEvent(event) )
143 return TRUE;
144 }
145
146 // wrap around
147 node = bForward ? children->First() : children->Last();
148 }
149
150 bFound = WIN(node)->AcceptsFocus();
151 }
152
153 WIN(node)->SetFocus();
154
155 #undef WIN
156
157 return TRUE;
158 }