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