]> git.saurik.com Git - wxWidgets.git/blob - src/generic/panelg.cpp
latest CW additions
[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/object.h"
25 #include "wx/font.h"
26 #include "wx/colour.h"
27 #include "wx/settings.h"
28 #endif
29
30 #include "wx/generic/panelg.h"
31
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
34
35 BEGIN_EVENT_TABLE(wxPanel, wxWindow)
36 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
37 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey)
38 END_EVENT_TABLE()
39
40 #endif
41
42 wxPanel::wxPanel()
43 {
44 }
45
46 bool wxPanel::Create(wxWindow *parent, wxWindowID id,
47 const wxPoint& pos,
48 const wxSize& size,
49 long style,
50 const wxString& name)
51 {
52 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
53
54 if ( ret )
55 {
56 #ifndef __WXGTK__
57 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
58 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
59 #endif
60 }
61
62 return ret;
63 }
64
65 void wxPanel::InitDialog(void)
66 {
67 wxInitDialogEvent event(GetId());
68 event.SetEventObject(this);
69 GetEventHandler()->ProcessEvent(event);
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 Refresh();
77
78 // Propagate the event to the non-top-level children
79 wxWindow::OnSysColourChanged(event);
80 }
81
82 void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
83 {
84 // there is not much to do if we have only one child (or not at all)
85 if (GetChildren().GetCount() < 2)
86 {
87 event.Skip();
88 return;
89 }
90
91 // don't process these ones here
92 if (event.IsWindowChange())
93 {
94 event.Skip();
95 return;
96 }
97
98 wxWindow *winFocus = event.GetCurrentFocus();
99 if (!winFocus)
100 winFocus = wxWindow::FindFocus();
101
102 if (!winFocus)
103 {
104 event.Skip();
105 return;
106 }
107
108 wxNode *start_node = GetChildren().Find( winFocus );
109 if (!start_node)
110 start_node = GetChildren().First();
111
112 wxNode *node = event.GetDirection() ? start_node->Next()
113 : start_node->Previous();
114
115 while (node != start_node)
116 {
117 if (!node)
118 {
119 #if 0
120 if (GetParent() != NULL)
121 {
122 wxNavigationKeyEvent new_event;
123 new_event.SetDirection( event.GetDirection() );
124 new_event.SetWindowChange(FALSE);
125 new_event.SetCurrentFocus( this );
126
127 if (GetParent()->GetEventHandler()->ProcessEvent(new_event))
128 {
129 return;
130 }
131 }
132 #endif // 0
133
134 node = event.GetDirection() ? GetChildren().First()
135 : GetChildren().Last();
136 }
137
138 wxWindow *child = (wxWindow *)node->Data();
139
140 if (child->AcceptsFocus())
141 {
142 // ok, event processed
143 child->SetFocus();
144 return;
145 }
146
147 node = event.GetDirection() ? node->Next() : node->Previous();
148 }
149
150 // we cycled through all of our children and none of them wanted to accept
151 // focus
152 event.Skip();
153 }
154