]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/panelg.cpp
3ff8c2dbc0d02d347cf24aec669fd37c863683e5
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "panelg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/object.h"
26 #include "wx/colour.h"
27 #include "wx/settings.h"
30 #include "wx/generic/panelg.h"
32 IMPLEMENT_DYNAMIC_CLASS(wxPanel
, wxWindow
)
34 BEGIN_EVENT_TABLE(wxPanel
, wxWindow
)
35 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged
)
36 EVT_SET_FOCUS(wxPanel::OnFocus
)
37 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey
)
38 EVT_SIZE(wxPanel::OnSize
)
44 m_winLastFocused
= (wxWindow
*)NULL
;
45 m_btnDefault
= (wxButton
*)NULL
;
48 bool wxPanel::Create(wxWindow
*parent
, wxWindowID id
,
54 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
58 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
59 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
65 void wxPanel::InitDialog(void)
67 wxInitDialogEvent
event(GetId());
68 event
.SetEventObject(this);
69 GetEventHandler()->ProcessEvent(event
);
72 // Responds to colour changes, and passes event on to children.
73 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
75 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
78 // Propagate the event to the non-top-level children
79 wxWindow::OnSysColourChanged(event
);
82 void wxPanel::OnNavigationKey( wxNavigationKeyEvent
& event
)
84 // there is not much to do if we have only one child (or not at all)
85 if (GetChildren().GetCount() < 2)
91 // don't process these ones here
92 if (event
.IsWindowChange())
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();
103 // Do we know where the focus was ourselves, then?
105 winFocus
= m_winLastFocused
;
108 winFocus
= wxWindow::FindFocus();
116 wxWindowList::Node
*start_node
= GetChildren().Find( winFocus
);
118 start_node
= GetChildren().Find( m_winLastFocused
);
120 start_node
= GetChildren().GetFirst();
122 wxWindowList::Node
*node
= event
.GetDirection() ? start_node
->GetNext()
123 : start_node
->GetPrevious();
125 while ( node
!= start_node
)
127 // Have we come to the last or first item on the panel?
130 // Check if our (may be grand) parent is another panel: if this is
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
134 // item after this panel in the parent panel).
135 wxWindow
*focussed_child_of_parent
= this;
136 for ( wxWindow
*parent
= GetParent(); parent
; parent
= parent
->GetParent() )
138 // we don't want to tab into a different dialog or frame
139 if ( focussed_child_of_parent
->IsTopLevel() )
142 // is the parent a panel?
143 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
146 event
.SetCurrentFocus( focussed_child_of_parent
);
147 if (parent
->GetEventHandler()->ProcessEvent( event
))
151 focussed_child_of_parent
= parent
;
154 // no, we are not inside another panel so process this ourself
155 node
= event
.GetDirection() ? GetChildren().GetFirst()
156 : GetChildren().GetLast();
161 wxWindow
*child
= node
->GetData();
163 if ( child
->AcceptsFocus() )
165 m_winLastFocused
= child
; // should be redundant, but it is not
170 node
= event
.GetDirection() ? node
->GetNext() : node
->GetPrevious();
173 // we cycled through all of our children and none of them wanted to accept
179 void wxPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
181 #if wxUSE_CONSTRAINTS
187 void wxPanel::SetFocus()
189 wxLogTrace(_T("focus"), _T("SetFocus on wxPanel 0x%08x."), GetHandle());
191 // If the panel gets the focus *by way of getting it set directly*
192 // we move the focus to the first window that can get it.
194 // VZ: no, we set the focus to the last window too. I don't understand why
195 // should we make this distinction: if an app wants to set focus to
196 // some precise control, it may always do it directly, but if we don't
197 // use m_winLastFocused here, the focus won't be set correctly after a
198 // notebook page change nor after frame activation under MSW (it calls
201 // If you still want to have old behaviour for wxGTK, edit the
203 #if 0 // def __WXGTK__
204 m_winLastFocused
= (wxWindow
*)NULL
;
207 if ( !SetFocusToChild() )
209 wxWindow::SetFocus();
213 void wxPanel::OnFocus(wxFocusEvent
& event
)
215 wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x."), GetHandle());
217 // If the panel gets the focus *by way of getting clicked on*
218 // we move the focus to either the last window that had the
219 // focus or the first one that can get it.
220 (void)SetFocusToChild();
225 bool wxPanel::SetFocusToChild()
227 if ( m_winLastFocused
)
229 // It might happen that the window got reparented or no longer accepts
231 if ( (m_winLastFocused
->GetParent() == this) &&
232 m_winLastFocused
->AcceptsFocus() )
234 wxLogTrace(_T("focus"),
235 _T("SetFocusToChild() => last child (0x%08x)."),
236 m_winLastFocused
->GetHandle());
238 m_winLastFocused
->SetFocus();
243 // it doesn't count as such any more
244 m_winLastFocused
= (wxWindow
*)NULL
;
248 // set the focus to the first child who wants it
249 wxWindowList::Node
*node
= GetChildren().GetFirst();
252 wxWindow
*child
= node
->GetData();
253 if ( child
->AcceptsFocus() )
255 wxLogTrace(_T("focus"),
256 _T("SetFocusToChild() => first child (0x%08x)."),
259 m_winLastFocused
= child
; // should be redundant, but it is not
264 node
= node
->GetNext();