From ababa106ae015f05e14cd2487100954ef50ca694 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 11 Dec 2004 12:51:05 +0000 Subject: [PATCH] Add SetFocusIgnoringChildren() to wxControlContainer. This makes corresponding hacks in wxListCtrl and wxTreeCtrl obsolete. With docs. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30927 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/panel.tex | 31 +++++++++++++++++++++++++++++++ docs/latex/wx/window.tex | 2 ++ include/wx/containr.h | 6 ++++++ src/generic/listctrl.cpp | 24 +----------------------- src/generic/treectlg.cpp | 2 +- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/docs/latex/wx/panel.tex b/docs/latex/wx/panel.tex index 0f437695c0..355cc31ca4 100644 --- a/docs/latex/wx/panel.tex +++ b/docs/latex/wx/panel.tex @@ -128,6 +128,7 @@ propagate the notification to child windows and controls. \helpref{wxSysColourChangedEvent}{wxsyscolourchangedevent} + \membersection{wxPanel::SetDefaultItem}\label{wxpanelsetdefaultitem} \func{void}{SetDefaultItem}{\param{wxButton }{*btn}} @@ -138,3 +139,33 @@ Changes the default button for the panel. \helpref{GetDefaultItem}{wxpanelgetdefaultitem} + +\membersection{wxPanel::SetFocus}\label{wxpanelsetfocus} + +\func{virtual void}{SetFocus}{\void} + +Overrides \helpref{wxWindow::SetFocus}{wxwindowsetfocus}. This method +uses the (undocumented) mix-in class wxControlContainer which manages +the focus and TAB logic for controls which usually have child controls. +In practice, if you call this method and the control has at least +one child window, the focus will be given to the child window. + +\wxheading{See also} + +\helpref{wxFocusEvent}{wxfocusevent} +\helpref{wxWindow::SetFocus}{wxwindowsetfocus} + + +\membersection{wxPanel::SetFocusIgnoringChildren}\label{wxpanelsetfocusignoringchildren} + +\func{virtual void}{SetFocusIgnoringChildren}{\void} + +In contrast to \helpref{wxPanel::SetFocus}{wxpanelsetfocus} (see above) +this will set the focus to the panel even of there are child windows +in the panel. This is only rarely needed. + +\wxheading{See also} + +\helpref{wxFocusEvent}{wxfocusevent} +\helpref{wxPanel::SetFocus}{wxpanelsetfocus} + diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 437cd23a79..00790633f9 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -2762,6 +2762,8 @@ This sets the window to receive keyboard input. \wxheading{See also} \helpref{wxFocusEvent}{wxfocusevent} +\helpref{wxPanel::SetFocus}{wxpanelsetfocus} +\helpref{wxPanel::SetFocusIgnoringChildren}{wxpanelsetfocusignoringchildren} \membersection{wxWindow::SetFocusFromKbd}\label{wxwindowsetfocusfromkbd} diff --git a/include/wx/containr.h b/include/wx/containr.h index a70b4eadef..00edc5861e 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -113,6 +113,7 @@ public: \ void OnFocus(wxFocusEvent& event); \ virtual void OnChildFocus(wxChildFocusEvent& event); \ virtual void SetFocus(); \ + virtual void SetFocusIgnoringChildren(); \ virtual void RemoveChild(wxWindowBase *child); \ virtual wxWindow *GetDefaultItem() const; \ virtual wxWindow *SetDefaultItem(wxWindow *child); \ @@ -163,6 +164,11 @@ void classname::SetFocus() \ wxWindow::SetFocus(); \ } \ \ +void classname::SetFocusIgnoringChildren() \ +{ \ + wxWindow::SetFocus(); \ +} \ + \ void classname::OnChildFocus(wxChildFocusEvent& event) \ { \ m_container.SetLastFocus(event.GetWindow()); \ diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index dece7fb5eb..164f094cf0 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -606,8 +606,6 @@ public: void Freeze(); void Thaw(); - void SetFocus(); - void OnRenameTimer(); bool OnRenameAccept(size_t itemEdit, const wxString& value); void OnRenameCancelled(size_t itemEdit); @@ -2047,7 +2045,7 @@ void wxListTextCtrl::Finish() m_finished = true; - m_owner->SetFocus(); + m_owner->SetFocusIgnoringChildren(); } } @@ -3299,26 +3297,6 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) // focus handling // ---------------------------------------------------------------------------- -void wxListMainWindow::SetFocus() -{ - // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel - // overrides SetFocus in such way that it does never change focus from - // panel's child to the panel itself. Unfortunately, we must be able to change - // focus to the panel from wxListTextCtrl because the text control should - // disappear when the user clicks outside it. - - wxWindow *oldFocus = DoFindFocus(); - - if ( oldFocus && oldFocus->GetParent() == this ) - { - wxWindow::SetFocus(); - } - else - { - wxScrolledWindow::SetFocus(); - } -} - void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) { if ( GetParent() ) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 0018af55bd..8155541026 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -415,7 +415,7 @@ void wxTreeTextCtrl::Finish() m_finished = true; - m_owner->SetFocus(); // This doesn't work. TODO. + m_owner->SetFocusIgnoringChildren(); } }