X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad81651f00edc6f489d9b6a0839d316a964fd521..5c3beb8ee5dca82b1a20e45d694df9a01a1be96a:/src/generic/panelg.cpp?ds=sidebyside diff --git a/src/generic/panelg.cpp b/src/generic/panelg.cpp index 9ac21f6245..0218693d28 100644 --- a/src/generic/panelg.cpp +++ b/src/generic/panelg.cpp @@ -25,6 +25,7 @@ #include "wx/font.h" #include "wx/colour.h" #include "wx/settings.h" +#include "wx/log.h" #endif #include "wx/generic/panelg.h" @@ -55,10 +56,8 @@ bool wxPanel::Create(wxWindow *parent, wxWindowID id, if ( ret ) { -#ifndef __WXGTK__ SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); -#endif } return ret; @@ -181,65 +180,90 @@ void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event ) void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event)) { #if wxUSE_CONSTRAINTS - if (GetAutoLayout()) Layout(); + if (GetAutoLayout()) + Layout(); #endif } void wxPanel::SetFocus() { + wxLogTrace(_T("focus"), _T("SetFocus on wxPanel 0x%08x."), GetHandle()); + // If the panel gets the focus *by way of getting it set directly* // we move the focus to the first window that can get it. - wxNode *node = GetChildren().First(); - while (node) + // VZ: no, we set the focus to the last window too. I don't understand why + // should we make this distinction: if an app wants to set focus to + // some precise control, it may always do it directly, but if we don't + // use m_winLastFocused here, the focus won't be set correctly after a + // notebook page change nor after frame activation under MSW (it calls + // SetFocus too) + // + // If you still want to have old behaviour for wxGTK, edit the + // following line +#if 0 // def __WXGTK__ + m_winLastFocused = (wxWindow *)NULL; +#endif // 0 + + if ( !SetFocusToChild() ) { - wxWindow *child = (wxWindow*) node->Data(); - if (child->AcceptsFocus()) - { - m_winLastFocused = child; // should be redundant, but it is not - child->SetFocus(); - return; - } - node = node->Next(); + wxWindow::SetFocus(); } - - m_winLastFocused = (wxWindow*) NULL; - - wxWindow::SetFocus(); } void wxPanel::OnFocus(wxFocusEvent& event) { + wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x."), GetHandle()); + // 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(); +} - if (m_winLastFocused) +bool wxPanel::SetFocusToChild() +{ + 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())) + // It might happen that the window got reparented or no longer accepts + // the focus. + if ( (m_winLastFocused->GetParent() == this) && + m_winLastFocused->AcceptsFocus() ) { + wxLogTrace(_T("focus"), + _T("SetFocusToChild() => last child (0x%08x)."), + m_winLastFocused->GetHandle()); + m_winLastFocused->SetFocus(); - return; + return TRUE; + } + else + { + // it doesn't count as such any more + m_winLastFocused = (wxWindow *)NULL; } } - wxNode *node = GetChildren().First(); - while (node) + // set the focus to the first child who wants it + wxWindowList::Node *node = GetChildren().GetFirst(); + while ( node ) { - wxWindow *child = (wxWindow*) node->Data(); - if (child->AcceptsFocus()) + wxWindow *child = node->GetData(); + if ( child->AcceptsFocus() ) { + wxLogTrace(_T("focus"), + _T("SetFocusToChild() => first child (0x%08x)."), + child->GetHandle()); + m_winLastFocused = child; // should be redundant, but it is not child->SetFocus(); - return; + return TRUE; } - node = node->Next(); - } - m_winLastFocused = (wxWindow*) NULL; + node = node->GetNext(); + } - event.Skip(); + return FALSE; }