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