+ wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x, name: %s"), GetHandle(), GetName().c_str() );
+
+ // If the panel gets the focus *by way of getting clicked on*
+ // we move the focus to either the last window that had the
+ // focus or the first one that can get it.
+ (void)SetFocusToChild();
+
+ event.Skip();
+}
+
+bool wxPanel::SetFocusToChild()
+{
+ return wxSetFocusToChild(this, &m_winLastFocused);
+}
+
+// ----------------------------------------------------------------------------
+// SetFocusToChild(): this function is used by wxPanel but also by wxFrame in
+// wxMSW, this is why it is outside of wxPanel class
+// ----------------------------------------------------------------------------
+
+bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused)
+{
+ wxCHECK_MSG( win, FALSE, _T("wxSetFocusToChild(): invalid window") );
+
+ if ( *childLastFocused )
+ {
+ // It might happen that the window got reparented or no longer accepts
+ // the focus.
+ if ( (*childLastFocused)->GetParent() == win &&
+ (*childLastFocused)->AcceptsFocus() )
+ {
+ wxLogTrace(_T("focus"),
+ _T("SetFocusToChild() => last child (0x%08x)."),
+ (*childLastFocused)->GetHandle());
+
+ (*childLastFocused)->SetFocus();
+ return TRUE;
+ }
+ else
+ {
+ // it doesn't count as such any more
+ *childLastFocused = (wxWindow *)NULL;
+ }
+ }
+
+ // set the focus to the first child who wants it
+ wxWindowList::Node *node = win->GetChildren().GetFirst();
+ while ( node )