]>
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 | |
87a1e308 | 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 | |
33 | IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow) | |
34 | ||
35 | BEGIN_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) |
27dc7e21 | 39 | EVT_SIZE(wxPanel::OnSize) |
c801d85f KB |
40 | END_EVENT_TABLE() |
41 | ||
42 | #endif | |
43 | ||
edccf428 | 44 | void wxPanel::Init() |
c801d85f | 45 | { |
319fefa9 | 46 | m_winLastFocused = (wxWindow *)NULL; |
edccf428 | 47 | m_btnDefault = (wxButton *)NULL; |
c801d85f KB |
48 | } |
49 | ||
debe6624 | 50 | bool wxPanel::Create(wxWindow *parent, wxWindowID id, |
90c3bdac VZ |
51 | const wxPoint& pos, |
52 | const wxSize& size, | |
53 | long style, | |
54 | const wxString& name) | |
c801d85f | 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 | ||
69 | void 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. |
77 | void 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 | 86 | void 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 | ||
3da17724 RR |
102 | // Did the event emitter tell us where the last focus was? |
103 | // wxGTK does this in wxWindow, but wxMSW does not. It is | |
104 | // also done in wxPanel if the event is propagated up. | |
105 | wxWindow *winFocus = event.GetCurrentFocus(); | |
87a1e308 | 106 | |
3da17724 RR |
107 | // Do we know where the focus was ourselves, then? |
108 | if (!winFocus) | |
109 | winFocus = m_winLastFocused; | |
87a1e308 | 110 | |
fb99aca7 VZ |
111 | if (!winFocus) |
112 | winFocus = wxWindow::FindFocus(); | |
27dc7e21 | 113 | |
b292e2f5 RR |
114 | if (!winFocus) |
115 | { | |
116 | event.Skip(); | |
117 | return; | |
118 | } | |
fb99aca7 | 119 | |
f03fc89f | 120 | wxWindowList::Node *start_node = GetChildren().Find( winFocus ); |
a1665b22 VZ |
121 | if ( !start_node ) |
122 | start_node = GetChildren().Find( m_winLastFocused ); | |
123 | if ( !start_node ) | |
f03fc89f | 124 | start_node = GetChildren().GetFirst(); |
fb99aca7 | 125 | |
f03fc89f VZ |
126 | wxWindowList::Node *node = event.GetDirection() ? start_node->GetNext() |
127 | : start_node->GetPrevious(); | |
fb99aca7 | 128 | |
a1665b22 | 129 | while ( node != start_node ) |
b292e2f5 | 130 | { |
3da17724 | 131 | // Have we come to the last or first item on the panel? |
a1665b22 | 132 | if ( !node ) |
fb99aca7 | 133 | { |
3da17724 | 134 | // Check if our (may be grand) parent is another panel: if this is |
a1665b22 VZ |
135 | // the case, they will know what to do with this navigation key and |
136 | // so give them the chance to process it instead of looping inside | |
137 | // this panel (normally, the focus will go to the next/previous | |
3da17724 | 138 | // item after this panel in the parent panel). |
87a1e308 | 139 | wxWindow *focussed_child_of_parent = this; |
3da17724 | 140 | for ( wxWindow *parent = GetParent(); parent; parent = parent->GetParent() ) |
a1665b22 | 141 | { |
87a1e308 VZ |
142 | // we don't want to tab into a different dialog or frame |
143 | if ( focussed_child_of_parent->IsTopLevel() ) | |
144 | break; | |
145 | ||
146 | // is the parent a panel? | |
147 | wxPanel *panel = wxDynamicCast(parent, wxPanel); | |
3da17724 | 148 | if (panel) |
a1665b22 | 149 | { |
87a1e308 VZ |
150 | event.SetCurrentFocus( focussed_child_of_parent ); |
151 | if (parent->GetEventHandler()->ProcessEvent( event )) | |
ed58dbea | 152 | return; |
a1665b22 | 153 | } |
87a1e308 VZ |
154 | |
155 | focussed_child_of_parent = parent; | |
a1665b22 VZ |
156 | } |
157 | ||
158 | // no, we are not inside another panel so process this ourself | |
f03fc89f VZ |
159 | node = event.GetDirection() ? GetChildren().GetFirst() |
160 | : GetChildren().GetLast(); | |
341c92a8 | 161 | |
e4ffaca4 | 162 | continue; |
fb99aca7 VZ |
163 | } |
164 | ||
f03fc89f | 165 | wxWindow *child = node->GetData(); |
fb99aca7 | 166 | |
a1665b22 | 167 | if ( child->AcceptsFocus() ) |
fb99aca7 | 168 | { |
87a1e308 | 169 | m_winLastFocused = child; // should be redundant, but it is not |
fb99aca7 VZ |
170 | child->SetFocus(); |
171 | return; | |
172 | } | |
173 | ||
f03fc89f | 174 | node = event.GetDirection() ? node->GetNext() : node->GetPrevious(); |
b292e2f5 | 175 | } |
fb99aca7 VZ |
176 | |
177 | // we cycled through all of our children and none of them wanted to accept | |
178 | // focus | |
b292e2f5 | 179 | event.Skip(); |
6e4739a0 | 180 | } |
58614078 | 181 | |
27dc7e21 RD |
182 | |
183 | void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event)) | |
184 | { | |
185 | #if wxUSE_CONSTRAINTS | |
186 | if (GetAutoLayout()) Layout(); | |
187 | #endif | |
188 | } | |
189 | ||
3da17724 RR |
190 | void wxPanel::SetFocus() |
191 | { | |
192 | // If the panel gets the focus *by way of getting it set directly* | |
69ffe1d2 | 193 | // we move the focus to the first window that can get it. |
3da17724 RR |
194 | |
195 | wxNode *node = GetChildren().First(); | |
196 | while (node) | |
197 | { | |
87a1e308 VZ |
198 | wxWindow *child = (wxWindow*) node->Data(); |
199 | if (child->AcceptsFocus()) | |
200 | { | |
201 | m_winLastFocused = child; // should be redundant, but it is not | |
202 | child->SetFocus(); | |
203 | return; | |
204 | } | |
3da17724 RR |
205 | node = node->Next(); |
206 | } | |
87a1e308 | 207 | |
3da17724 | 208 | m_winLastFocused = (wxWindow*) NULL; |
87a1e308 | 209 | |
3da17724 RR |
210 | wxWindow::SetFocus(); |
211 | } | |
212 | ||
341c92a8 VZ |
213 | void wxPanel::OnFocus(wxFocusEvent& event) |
214 | { | |
3da17724 | 215 | // If the panel gets the focus *by way of getting clicked on* |
69ffe1d2 RR |
216 | // we move the focus to either the last window that had the |
217 | // focus or the first one that can get it. | |
3da17724 RR |
218 | |
219 | if (m_winLastFocused) | |
0492c5a0 | 220 | { |
69ffe1d2 RR |
221 | // It might happen that the window got reparented or no longer |
222 | // accepts the focus. | |
223 | if ((m_winLastFocused->GetParent() == this) && | |
224 | (m_winLastFocused->AcceptsFocus())) | |
87a1e308 | 225 | { |
319fefa9 | 226 | m_winLastFocused->SetFocus(); |
87a1e308 VZ |
227 | return; |
228 | } | |
0492c5a0 | 229 | } |
87a1e308 | 230 | |
3da17724 RR |
231 | wxNode *node = GetChildren().First(); |
232 | while (node) | |
233 | { | |
87a1e308 VZ |
234 | wxWindow *child = (wxWindow*) node->Data(); |
235 | if (child->AcceptsFocus()) | |
236 | { | |
237 | m_winLastFocused = child; // should be redundant, but it is not | |
238 | child->SetFocus(); | |
239 | return; | |
240 | } | |
3da17724 RR |
241 | node = node->Next(); |
242 | } | |
87a1e308 | 243 | |
3da17724 | 244 | m_winLastFocused = (wxWindow*) NULL; |
87a1e308 | 245 | |
3da17724 | 246 | event.Skip(); |
341c92a8 | 247 | } |