Always make wxWindow::SetFocus() focus the window, overriding SetCanFocus, some more focus related docs

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48747 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-09-17 10:17:12 +00:00
parent 16a6b53ddc
commit 00ff24c81c
5 changed files with 85 additions and 59 deletions

View File

@@ -1,13 +1,19 @@
\section{\class{wxPanel}}\label{wxpanel}
A panel is a window on which controls are placed. It is usually placed within a frame.
It contains minimal extra functionality over and above its parent class wxWindow; its main
purpose is to be similar in appearance and functionality to a dialog, but with the flexibility of
having any window as a parent.
A panel is a window on which controls are placed. It is usually placed within
a frame. Its main feature over its parent class wxWindow is code for handling
child windows and TAB traversal. Since wxWidgets 2.9, there is support both
for TAB traversal implemented by wxWidgets itself as well as native TAB
traversal (such as for GTK 2.0).
{\it Note:} if not all characters are being intercepted by your OnKeyDown or OnChar handler,
it may be because you are using the wxTAB\_TRAVERSAL style, which grabs some keypresses for use
by child controls.
{\it Note:} Tab traversal is implemented through an otherwise undocumented
intermediate wxControlContainer class from which any class can derive
in addition to the normal wxWindow base class. Please see <wx/containr.h>
and <wx/panel.h> to find out how this is achieved.
{\it Note:} if not all characters are being intercepted by your OnKeyDown or
OnChar handler, it may be because you are using the wxTAB\_TRAVERSAL style,
which grabs some keypresses for use by child controls.
\wxheading{Derived from}
@@ -88,6 +94,17 @@ Destructor. Deletes any child windows before deleting the physical window.
Used for two-step panel construction. See \helpref{wxPanel::wxPanel}{wxpanelctor}\rtfsp
for details.
\membersection{wxPanel::AcceptsFocus}\label{wxpanelacceptsfocus}
\constfunc{bool}{AcceptsFocus}{\void}
This method is overridden from \helpref{wxWindow::AcceptsFocus}{wxwindowacceptsfocus}
and returns true only if there is no child window in the panel which
can accept the focus. This is reevaluated each time a child
window is added or removed from the panel.
\membersection{wxPanel::InitDialog}\label{wxpanelinitdialog}
\func{void}{InitDialog}{\void}

View File

@@ -2780,26 +2780,23 @@ background, such as a tiled bitmap. Currently the style has no effect on other p
\helpref{wxWindow::GetBackgroundStyle}{wxwindowgetbackgroundstyle}
\membersection{wxWindow::SetInitialSize}\label{wxwindowsetinitialsize}
\func{void}{SetInitialSize}{\param{const wxSize\& }{size = wxDefaultSize}}
\membersection{wxWindow::SetCanFocus}\label{wxwindowsetcanfocus}
A {\it smart} SetSize that will fill in default size components with the
window's {\it best} size values. Also sets the window's minsize to
the value passed in for use with sizers. This means that if a full or
partial size is passed to this function then the sizers will use that
size instead of the results of GetBestSize to determine the minimum
needs of the window for layout.
Most controls will use this to set their initial size, and their min
size to the passed in value (if any.)
\func{virtual void}{SetCanFocus}{\param{bool}{ canFocus}}
This method is only implemented by ports which have support for
native TAB traversal (such as GTK+ 2.0). It is called by wxWidgets'
container control code to give the native system a hint when
doing TAB traversal. A call to this does not disable or change
the effect of programmatically calling
\helpref{wxWindow::SetFocus}{wxwindowsetfocus}.
\wxheading{See also}
\helpref{wxWindow::SetSize}{wxwindowsetsize},\rtfsp
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp
\helpref{wxWindow::GetEffectiveMinSize}{wxwindowgeteffectiveminsize}
\helpref{wxFocusEvent}{wxfocusevent}
\helpref{wxPanel::SetFocus}{wxpanelsetfocus}
\helpref{wxPanel::SetFocusIgnoringChildren}{wxpanelsetfocusignoringchildren}
\membersection{wxWindow::SetCaret}\label{wxwindowsetcaret}
@@ -2903,13 +2900,6 @@ If the window already has a drop target, it is deleted.
\membersection{wxWindow::SetInitialBestSize}\label{wxwindowsetinitialbestsize}
\func{virtual void}{SetInitialBestSize}{\param{const wxSize\& }{size}}
Sets the initial window size if none is given (i.e. at least one of the
components of the size passed to ctor/Create() is wxDefaultCoord).
\membersection{wxWindow::SetEventHandler}\label{wxwindowseteventhandler}
\func{void}{SetEventHandler}{\param{wxEvtHandler* }{handler}}
@@ -2928,9 +2918,9 @@ an application may wish to substitute another, for example to allow
central implementation of event-handling for a variety of different
window classes.
It is usually better to use \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler} since
this sets up a chain of event handlers, where an event not handled by one event handler is
handed to the next one in the chain.
It is usually better to use \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler}
since this sets up a chain of event handlers, where an event not handled by
one event handler is handed to the next one in the chain.
\wxheading{See also}
@@ -3098,6 +3088,36 @@ on creation and should not be modified subsequently.
\membersection{wxWindow::SetInitialBestSize}\label{wxwindowsetinitialbestsize}
\func{virtual void}{SetInitialBestSize}{\param{const wxSize\& }{size}}
Sets the initial window size if none is given (i.e. at least one of the
components of the size passed to ctor/Create() is wxDefaultCoord).
\membersection{wxWindow::SetInitialSize}\label{wxwindowsetinitialsize}
\func{void}{SetInitialSize}{\param{const wxSize\& }{size = wxDefaultSize}}
A {\it smart} SetSize that will fill in default size components with the
window's {\it best} size values. Also sets the window's minsize to
the value passed in for use with sizers. This means that if a full or
partial size is passed to this function then the sizers will use that
size instead of the results of GetBestSize to determine the minimum
needs of the window for layout.
Most controls will use this to set their initial size, and their min
size to the passed in value (if any.)
\wxheading{See also}
\helpref{wxWindow::SetSize}{wxwindowsetsize},\rtfsp
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp
\helpref{wxWindow::GetEffectiveMinSize}{wxwindowgeteffectiveminsize}
\membersection{wxWindow::SetLabel}\label{wxwindowsetlabel}
\func{virtual void}{SetLabel}{\param{const wxString\& }{label}}

View File

@@ -70,10 +70,9 @@ public:
// wxListCtrl) and so should get focus for ourselves
bool AcceptsFocusRecursively() const { return true; }
// call this when the number of children of the window changes
//
// note that we have any children, this panel (used just as container for
// them) shouldn't get focus for itself
// Call this when the number of children of the window changes.
// If we have any children, this panel (used just as container for
// them) shouldn't get focus for itself.
void UpdateCanFocus() { SetCanFocus(!HasAnyFocusableChildren()); }
protected:
@@ -177,7 +176,7 @@ protected:
\
void classname::SetFocusIgnoringChildren() \
{ \
basename::SetFocusIgnoringChildren(); \
basename::SetFocus(); \
}
#else // !wxHAS_NATIVE_TAB_TRAVERSAL

View File

@@ -60,7 +60,8 @@ public:
virtual bool IsRetained() const;
virtual void SetFocus();
virtual void SetFocusIgnoringChildren();
// hint from wx to native GTK+ tab traversal code
virtual void SetCanFocus(bool canFocus);
virtual bool Reparent( wxWindowBase *newParent );

View File

@@ -25,7 +25,6 @@
#include "wx/settings.h"
#include "wx/msgdlg.h"
#include "wx/textctrl.h"
#include "wx/radiobut.h"
#include "wx/toolbar.h"
#include "wx/combobox.h"
#include "wx/layout.h"
@@ -3172,24 +3171,6 @@ bool wxWindowGTK::GTKSetDelayedFocusIfNeeded()
return false;
}
void wxWindowGTK::SetFocusIgnoringChildren()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
if ( m_hasFocus )
{
// don't do anything if we already have focus
return;
}
if (m_wxwindow)
{
if (!GTK_WIDGET_CAN_FOCUS(m_wxwindow))
GTK_WIDGET_SET_FLAGS(m_wxwindow, GTK_CAN_FOCUS);
}
wxWindowGTK::SetFocus();
}
void wxWindowGTK::SetFocus()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
@@ -3201,6 +3182,11 @@ void wxWindowGTK::SetFocus()
if (m_wxwindow)
{
// wxWindow::SetFocus() should really set the focus to
// this control, whatever the flags are
if (!GTK_WIDGET_CAN_FOCUS(m_wxwindow))
GTK_WIDGET_SET_FLAGS(m_wxwindow, GTK_CAN_FOCUS);
if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow))
{
gtk_widget_grab_focus (m_wxwindow);
@@ -3208,15 +3194,18 @@ void wxWindowGTK::SetFocus()
}
else if (m_widget)
{
// wxWindow::SetFocus() should really set the focus to
// this control, whatever the flags are
if (!GTK_WIDGET_CAN_FOCUS(m_widget))
GTK_WIDGET_SET_FLAGS(m_widget, GTK_CAN_FOCUS);
if (GTK_IS_CONTAINER(m_widget))
{
#if wxUSE_RADIOBTN
if (IsKindOf(CLASSINFO(wxRadioButton)))
if (GTK_IS_RADIO_BUTTON(m_widget))
{
gtk_widget_grab_focus (m_widget);
return;
}
#endif // wxUSE_RADIOBTN
gtk_widget_child_focus( m_widget, GTK_DIR_TAB_FORWARD );
}