+ // 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.
+
+ if (m_winLastFocused)
+ {
+ // It might happen that the window got reparented or no longer
+ // accepts the focus.
+ if ((m_winLastFocused->GetParent() == this) &&
+ (m_winLastFocused->AcceptsFocus()))
+ {
+ m_winLastFocused->SetFocus();
+ return;
+ }
+ }
+
+ wxNode *node = GetChildren().First();
+ while (node)
+ {
+ wxWindow *child = (wxWindow*) node->Data();
+ if (child->AcceptsFocus())
+ {
+ m_winLastFocused = child; // should be redundant, but it is not
+ child->SetFocus();
+ return;
+ }
+ node = node->Next();
+ }
+
+ m_winLastFocused = (wxWindow*) NULL;
+
+ event.Skip();