]>
Commit | Line | Data |
---|---|---|
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_SET_FOCUS(wxPanel::OnFocus) | |
38 | EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey) | |
39 | END_EVENT_TABLE() | |
40 | ||
41 | #endif | |
42 | ||
43 | void wxPanel::Init() | |
44 | { | |
45 | m_winLastFocused = (wxWindow *)NULL; | |
46 | m_btnDefault = (wxButton *)NULL; | |
47 | } | |
48 | ||
49 | bool wxPanel::Create(wxWindow *parent, wxWindowID id, | |
50 | const wxPoint& pos, | |
51 | const wxSize& size, | |
52 | long style, | |
53 | const wxString& name) | |
54 | { | |
55 | bool ret = wxWindow::Create(parent, id, pos, size, style, name); | |
56 | ||
57 | if ( ret ) | |
58 | { | |
59 | #ifndef __WXGTK__ | |
60 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
61 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
62 | #endif | |
63 | } | |
64 | ||
65 | return ret; | |
66 | } | |
67 | ||
68 | void wxPanel::InitDialog(void) | |
69 | { | |
70 | wxInitDialogEvent event(GetId()); | |
71 | event.SetEventObject(this); | |
72 | GetEventHandler()->ProcessEvent(event); | |
73 | } | |
74 | ||
75 | // Responds to colour changes, and passes event on to children. | |
76 | void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event) | |
77 | { | |
78 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
79 | Refresh(); | |
80 | ||
81 | // Propagate the event to the non-top-level children | |
82 | wxWindow::OnSysColourChanged(event); | |
83 | } | |
84 | ||
85 | void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event ) | |
86 | { | |
87 | // there is not much to do if we have only one child (or not at all) | |
88 | if (GetChildren().GetCount() < 2) | |
89 | { | |
90 | event.Skip(); | |
91 | return; | |
92 | } | |
93 | ||
94 | // don't process these ones here | |
95 | if (event.IsWindowChange()) | |
96 | { | |
97 | event.Skip(); | |
98 | return; | |
99 | } | |
100 | ||
101 | wxWindow *winFocus = event.GetCurrentFocus(); | |
102 | if (!winFocus) | |
103 | winFocus = wxWindow::FindFocus(); | |
104 | ||
105 | if (!winFocus) | |
106 | { | |
107 | event.Skip(); | |
108 | return; | |
109 | } | |
110 | ||
111 | wxWindowList::Node *start_node = GetChildren().Find( winFocus ); | |
112 | if ( !start_node ) | |
113 | start_node = GetChildren().Find( m_winLastFocused ); | |
114 | if ( !start_node ) | |
115 | start_node = GetChildren().GetFirst(); | |
116 | ||
117 | wxWindowList::Node *node = event.GetDirection() ? start_node->GetNext() | |
118 | : start_node->GetPrevious(); | |
119 | ||
120 | while ( node != start_node ) | |
121 | { | |
122 | if ( !node ) | |
123 | { | |
124 | // check if our (may be grand) parent is another panel: if this is | |
125 | // the case, they will know what to do with this navigation key and | |
126 | // so give them the chance to process it instead of looping inside | |
127 | // this panel (normally, the focus will go to the next/previous | |
128 | // item after this panel in the parent panel) | |
129 | wxWindow *focussed_child_of_p = this; | |
130 | for ( wxWindow *p = GetParent(); p; p = p->GetParent() ) | |
131 | { | |
132 | // we don't want to tab into a different dialog or frame | |
133 | if ( focussed_child_of_p->IsTopLevel() ) | |
134 | break; | |
135 | ||
136 | if ( wxDynamicCast(p, wxPanel) ) | |
137 | { | |
138 | event.SetCurrentFocus( focussed_child_of_p ); | |
139 | if (p->GetEventHandler()->ProcessEvent( event )) | |
140 | return; | |
141 | } | |
142 | focussed_child_of_p = p; | |
143 | } | |
144 | ||
145 | // no, we are not inside another panel so process this ourself | |
146 | node = event.GetDirection() ? GetChildren().GetFirst() | |
147 | : GetChildren().GetLast(); | |
148 | ||
149 | continue; | |
150 | } | |
151 | ||
152 | wxWindow *child = node->GetData(); | |
153 | ||
154 | if ( child->AcceptsFocus() ) | |
155 | { | |
156 | // ok, event processed | |
157 | child->SetFocus(); | |
158 | return; | |
159 | } | |
160 | ||
161 | node = event.GetDirection() ? node->GetNext() : node->GetPrevious(); | |
162 | } | |
163 | ||
164 | // we cycled through all of our children and none of them wanted to accept | |
165 | // focus | |
166 | event.Skip(); | |
167 | } | |
168 | ||
169 | void wxPanel::OnFocus(wxFocusEvent& event) | |
170 | { | |
171 | if ( m_winLastFocused ) | |
172 | { | |
173 | // it might happen that the window got reparented... | |
174 | if ( m_winLastFocused->GetParent() != this ) | |
175 | m_winLastFocused = (wxWindow *)NULL; | |
176 | else | |
177 | m_winLastFocused->SetFocus(); | |
178 | } | |
179 | else | |
180 | event.Skip(); | |
181 | } |