From de160b06478f7b007a28bd84f60fc59c0683ee09 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Mar 2007 22:41:11 +0000 Subject: [PATCH] don't use wxControlContainer if wxHAS_NATIVE_TAB_TRAVERSAL is defined (currently it never is) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45056 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/containr.h | 24 +++++++++++++- include/wx/pickerbase.h | 2 +- src/common/containr.cpp | 65 +++++++++++++++++++------------------ src/common/dlgcmn.cpp | 2 +- src/generic/panelg.cpp | 2 +- src/generic/splitter.cpp | 2 +- src/mac/carbon/combobox.cpp | 2 +- src/mac/carbon/spinctrl.cpp | 2 +- 8 files changed, 63 insertions(+), 38 deletions(-) diff --git a/include/wx/containr.h b/include/wx/containr.h index 1bf91cfef5..e6750713bc 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -13,6 +13,23 @@ #ifndef _WX_CONTAINR_H_ #define _WX_CONTAINR_H_ +// use native tab traversal logic under GTK+ 2 (doesn't work yet) +#if 0 // def __WXGTK20__ + #define wxHAS_NATIVE_TAB_TRAVERSAL +#endif + +#ifdef wxHAS_NATIVE_TAB_TRAVERSAL + +#define WX_DECLARE_CONTROL_CONTAINER() \ + virtual bool AcceptsFocus() const { return false; } \ + void SetFocusIgnoringChildren() { SetFocus(); } + +#define WX_INIT_CONTROL_CONTAINER() +#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) +#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) + +#else // !wxHAS_NATIVE_TAB_TRAVERSAL + class WXDLLEXPORT wxFocusEvent; class WXDLLEXPORT wxNavigationKeyEvent; class WXDLLEXPORT wxWindow; @@ -20,7 +37,7 @@ class WXDLLEXPORT wxWindowBase; /* Implementation note: wxControlContainer is not a real mix-in but rather - a class meant to be agregated with (and not inherited from). Although + a class meant to be aggregated with (and not inherited from). Although logically it should be a mix-in, doing it like this has no advantage from the point of view of the existing code but does have some problems (we'd need to play tricks with event handlers which may be difficult to do @@ -92,6 +109,10 @@ public: \ protected: \ wxControlContainer m_container +// this macro must be used in the derived class ctor +#define WX_INIT_CONTROL_CONTAINER() \ + m_container.SetContainerWindow(this) + // implement the event table entries for wxControlContainer #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \ EVT_SET_FOCUS(classname::OnFocus) \ @@ -137,5 +158,6 @@ bool classname::AcceptsFocus() const \ return m_container.AcceptsFocus(); \ } +#endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL #endif // _WX_CONTAINR_H_ diff --git a/include/wx/pickerbase.h b/include/wx/pickerbase.h index c1b8bb9b49..8fc0846b2a 100644 --- a/include/wx/pickerbase.h +++ b/include/wx/pickerbase.h @@ -37,7 +37,7 @@ class WXDLLIMPEXP_CORE wxPickerBase : public wxControl public: // ctor: text is the associated text control wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL) - { m_container.SetContainerWindow(this); } + { WX_INIT_CONTROL_CONTAINER(); } virtual ~wxPickerBase() {} diff --git a/src/common/containr.cpp b/src/common/containr.cpp index 3333232ec5..84be03d146 100644 --- a/src/common/containr.cpp +++ b/src/common/containr.cpp @@ -24,13 +24,18 @@ #pragma hdrstop #endif +#ifndef WX_PRECOMP + #include "wx/containr.h" +#endif + +#ifndef wxHAS_NATIVE_TAB_TRAVERSAL + #ifndef WX_PRECOMP #include "wx/log.h" #include "wx/event.h" #include "wx/window.h" #include "wx/scrolbar.h" #include "wx/radiobut.h" - #include "wx/containr.h" #endif //WX_PRECOMP // trace mask for focus messages @@ -49,43 +54,39 @@ wxControlContainer::wxControlContainer(wxWindow *winParent) bool wxControlContainer::AcceptsFocus() const { - // if we're not shown or disabled, we can't accept focus - if ( m_winParent->IsShown() && m_winParent->IsEnabled() ) + // we can accept focus either if we have no children at all (in this case + // we're probably not used as a container) or only when at least one child + // accepts focus + wxWindowList::compatibility_iterator node = m_winParent->GetChildren().GetFirst(); + if ( !node ) + return true; + +#ifdef __WXMAC__ + // wxMac has eventually the two scrollbars as children, they don't count + // as real children in the algorithm mentioned above + bool hasRealChildren = false ; +#endif + + while ( node ) { - // otherwise we can accept focus either if we have no children at all - // (in this case we're probably not used as a container) or only when - // at least one child will accept focus - wxWindowList::compatibility_iterator node = m_winParent->GetChildren().GetFirst(); - if ( !node ) - return true; + wxWindow *child = node->GetData(); + node = node->GetNext(); #ifdef __WXMAC__ - // wxMac has eventually the two scrollbars as children, they don't count - // as real children in the algorithm mentioned above - bool hasRealChildren = false ; + if ( m_winParent->MacIsWindowScrollbar( child ) ) + continue; + hasRealChildren = true ; #endif - - while ( node ) + if ( child->CanAcceptFocus() ) { - wxWindow *child = node->GetData(); - node = node->GetNext(); - -#ifdef __WXMAC__ - if ( m_winParent->MacIsWindowScrollbar( child ) ) - continue; - hasRealChildren = true ; -#endif - if ( child->AcceptsFocus() ) - { - return true; - } + return true; } + } #ifdef __WXMAC__ - if ( !hasRealChildren ) - return true ; + if ( !hasRealChildren ) + return true ; #endif - } return false; } @@ -504,7 +505,7 @@ void wxControlContainer::HandleOnNavigationKey( wxNavigationKeyEvent& event ) } #endif // __WXMSW__ - if ( child->AcceptsFocusFromKeyboard() ) + if ( child->CanAcceptFocusFromKeyboard() ) { // if we're setting the focus to a child panel we should prevent it // from giving it to the child which had the focus the last time @@ -650,7 +651,7 @@ bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused) continue; #endif - if ( child->AcceptsFocusFromKeyboard() && !child->IsTopLevel() ) + if ( child->CanAcceptFocusFromKeyboard() && !child->IsTopLevel() ) { #ifdef __WXMSW__ // If a radiobutton is the first focusable child, search for the @@ -676,3 +677,5 @@ bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused) return false; } + +#endif // !wxHAS_NATIVE_TAB_TRAVERSAL diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index 74af36254e..cf4557e883 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -121,7 +121,7 @@ void wxDialogBase::Init() // undesirable and can lead to unexpected and hard to find bugs SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS); - m_container.SetContainerWindow(this); + WX_INIT_CONTROL_CONTAINER(); } #if wxUSE_STATTEXT diff --git a/src/generic/panelg.cpp b/src/generic/panelg.cpp index 34c59bb52d..d714bce3c0 100644 --- a/src/generic/panelg.cpp +++ b/src/generic/panelg.cpp @@ -105,7 +105,7 @@ WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, wxWindow) void wxPanel::Init() { - m_container.SetContainerWindow(this); + WX_INIT_CONTROL_CONTAINER(); } bool wxPanel::Create(wxWindow *parent, wxWindowID id, diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index a8747b4652..958de8cc0b 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -107,7 +107,7 @@ bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id, void wxSplitterWindow::Init() { - m_container.SetContainerWindow(this); + WX_INIT_CONTROL_CONTAINER(); m_splitMode = wxSPLIT_VERTICAL; m_permitUnsplitAlways = true; diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp index 6a155d9636..734e631e28 100644 --- a/src/mac/carbon/combobox.cpp +++ b/src/mac/carbon/combobox.cpp @@ -334,7 +334,7 @@ void wxComboBox::DelegateChoice( const wxString& value ) void wxComboBox::Init() { - m_container.SetContainerWindow(this); + WX_INIT_CONTROL_CONTAINER(); } bool wxComboBox::Create(wxWindow *parent, diff --git a/src/mac/carbon/spinctrl.cpp b/src/mac/carbon/spinctrl.cpp index 63b1a7c41c..e0e3bcb597 100644 --- a/src/mac/carbon/spinctrl.cpp +++ b/src/mac/carbon/spinctrl.cpp @@ -202,7 +202,7 @@ void wxSpinCtrl::Init() { m_text = NULL; m_btn = NULL; - m_container.SetContainerWindow(this); + WX_INIT_CONTROL_CONTAINER(); } bool wxSpinCtrl::Create(wxWindow *parent,