]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/panelg.cpp
ae4d58ad5b706c94b6eca32e30134d5720538cd9
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"
31 #include "wx/generic/panelg.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxPanel
, wxWindow
)
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 EVT_SIZE(wxPanel::OnSize
)
45 m_winLastFocused
= (wxWindow
*)NULL
;
46 m_btnDefault
= (wxButton
*)NULL
;
49 bool wxPanel::Create(wxWindow
*parent
, wxWindowID id
,
55 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
59 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
60 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
66 void wxPanel::InitDialog(void)
68 wxInitDialogEvent
event(GetId());
69 event
.SetEventObject(this);
70 GetEventHandler()->ProcessEvent(event
);
73 // Responds to colour changes, and passes event on to children.
74 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
76 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
79 // Propagate the event to the non-top-level children
80 wxWindow::OnSysColourChanged(event
);
83 void wxPanel::OnNavigationKey( wxNavigationKeyEvent
& event
)
85 // there is not much to do if we have only one child (or not at all)
86 if (GetChildren().GetCount() < 2)
92 // don't process these ones here
93 if (event
.IsWindowChange())
99 // Did the event emitter tell us where the last focus was?
100 // wxGTK does this in wxWindow, but wxMSW does not. It is
101 // also done in wxPanel if the event is propagated up.
102 wxWindow
*winFocus
= event
.GetCurrentFocus();
104 // Do we know where the focus was ourselves, then?
106 winFocus
= m_winLastFocused
;
109 winFocus
= wxWindow::FindFocus();
117 wxWindowList::Node
*start_node
= GetChildren().Find( winFocus
);
119 start_node
= GetChildren().Find( m_winLastFocused
);
121 start_node
= GetChildren().GetFirst();
123 wxWindowList::Node
*node
= event
.GetDirection() ? start_node
->GetNext()
124 : start_node
->GetPrevious();
126 while ( node
!= start_node
)
128 // Have we come to the last or first item on the panel?
131 // Check if our (may be grand) parent is another panel: if this is
132 // the case, they will know what to do with this navigation key and
133 // so give them the chance to process it instead of looping inside
134 // this panel (normally, the focus will go to the next/previous
135 // item after this panel in the parent panel).
136 wxWindow
*focussed_child_of_parent
= this;
137 for ( wxWindow
*parent
= GetParent(); parent
; parent
= parent
->GetParent() )
139 // we don't want to tab into a different dialog or frame
140 if ( focussed_child_of_parent
->IsTopLevel() )
143 // is the parent a panel?
144 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
147 event
.SetCurrentFocus( focussed_child_of_parent
);
148 if (parent
->GetEventHandler()->ProcessEvent( event
))
152 focussed_child_of_parent
= parent
;
155 // no, we are not inside another panel so process this ourself
156 node
= event
.GetDirection() ? GetChildren().GetFirst()
157 : GetChildren().GetLast();
162 wxWindow
*child
= node
->GetData();
164 if ( child
->AcceptsFocus() )
166 m_winLastFocused
= child
; // should be redundant, but it is not
171 node
= event
.GetDirection() ? node
->GetNext() : node
->GetPrevious();
174 // we cycled through all of our children and none of them wanted to accept
180 void wxPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
182 #if wxUSE_CONSTRAINTS
188 void wxPanel::SetFocus()
190 wxLogTrace(_T("focus"), _T("SetFocus on wxPanel 0x%08x."), GetHandle());
192 // If the panel gets the focus *by way of getting it set directly*
193 // we move the focus to the first window that can get it.
195 // VZ: no, we set the focus to the last window too. I don't understand why
196 // should we make this distinction: if an app wants to set focus to
197 // some precise control, it may always do it directly, but if we don't
198 // use m_winLastFocused here, the focus won't be set correctly after a
199 // notebook page change nor after frame activation under MSW (it calls
202 // RR: yes, when I the tab key to navigate in a panel with some controls and
203 // a notebook and the focus jumps to the notebook (typically coming from
204 // a button at the top) the notebook should focus the first child in the
205 // current notebook page, not the last one which would otherwise get the
206 // focus if you used the tab key to navigate from the current notebook
207 // page to button at the bottom. See every page in the controls sample.
210 m_winLastFocused
= (wxWindow
*)NULL
;
213 if ( !SetFocusToChild() )
215 wxWindow::SetFocus();
219 void wxPanel::OnFocus(wxFocusEvent
& event
)
221 wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x."), GetHandle());
223 // If the panel gets the focus *by way of getting clicked on*
224 // we move the focus to either the last window that had the
225 // focus or the first one that can get it.
226 (void)SetFocusToChild();
231 bool wxPanel::SetFocusToChild()
233 if ( m_winLastFocused
)
235 // It might happen that the window got reparented or no longer accepts
237 if ( (m_winLastFocused
->GetParent() == this) &&
238 m_winLastFocused
->AcceptsFocus() )
240 wxLogTrace(_T("focus"),
241 _T("SetFocusToChild() => last child (0x%08x)."),
242 m_winLastFocused
->GetHandle());
244 m_winLastFocused
->SetFocus();
249 // it doesn't count as such any more
250 m_winLastFocused
= (wxWindow
*)NULL
;
254 // set the focus to the first child who wants it
255 wxWindowList::Node
*node
= GetChildren().GetFirst();
258 wxWindow
*child
= node
->GetData();
259 if ( child
->AcceptsFocus() )
261 wxLogTrace(_T("focus"),
262 _T("SetFocusToChild() => first child (0x%08x)."),
265 m_winLastFocused
= child
; // should be redundant, but it is not
270 node
= node
->GetNext();