don't check whether the window is shown and enabled in AcceptsFocus() itself
as it makes overriding it in derived classes problematic; provide a separate non virtual CanAcceptFocus() method checking whether the window accepts focus and if it can accept it now and use it instead of AcceptsFocus(); documented AcceptsFocus() and AcceptsFocusFromKeyboard() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45055 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4542739ccb
commit
ad02525dad
@ -171,6 +171,29 @@ can delete a window only when it is safe to do so, in idle time.
|
||||
\helpref{wxCloseEvent}{wxcloseevent}
|
||||
|
||||
|
||||
\membersection{wxWindow::AcceptsFocus}\label{wxwindowacceptsfocus}
|
||||
|
||||
\constfunc{bool}{AcceptsFocus}{\void}
|
||||
|
||||
This method may be overridden in the derived classes to return \false to
|
||||
indicate that this control doesn't accept input at all (i.e. behaves like e.g.
|
||||
\helpref{wxStaticText}{wxstatictext}) and so doesn't need focus.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{AcceptsFocusFromKeyboard}{wxwindowacceptsfocusfromkeyboard}
|
||||
|
||||
|
||||
\membersection{wxWindow::AcceptsFocusFromKeyboard}\label{wxwindowacceptsfocusfromkeyboard}
|
||||
|
||||
\constfunc{bool}{AcceptsFocusFromKeyboard}{\void}
|
||||
|
||||
This method may be overridden in the derived classes to return \false to
|
||||
indicate that while this control can, in principle, have focus if the user
|
||||
clicks it with the mouse, it shouldn't be included in the TAB traversal chain
|
||||
when using the keyboard.
|
||||
|
||||
|
||||
\membersection{wxWindow::AddChild}\label{wxwindowaddchild}
|
||||
|
||||
\func{virtual void}{AddChild}{\param{wxWindow* }{child}}
|
||||
|
@ -571,14 +571,27 @@ public:
|
||||
|
||||
static wxWindow *DoFindFocus() /* = 0: implement in derived classes */;
|
||||
|
||||
// can this window have focus?
|
||||
virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
|
||||
// can this window have focus in principle?
|
||||
//
|
||||
// the difference between AcceptsFocus[FromKeyboard]() and CanAcceptFocus
|
||||
// [FromKeyboard]() is that the former functions are meant to be
|
||||
// overridden in the derived classes to simply return false if the
|
||||
// control can't have focus, while the latter are meant to be used by
|
||||
// this class clients and take into account the current window state
|
||||
virtual bool AcceptsFocus() const { return true; }
|
||||
|
||||
// can this window have focus right now?
|
||||
bool CanAcceptFocus() const { return AcceptsFocus() && IsShown() && IsEnabled(); }
|
||||
|
||||
// can this window be given focus by keyboard navigation? if not, the
|
||||
// only way to give it focus (provided it accepts it at all) is to
|
||||
// click it
|
||||
virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
|
||||
|
||||
// can this window be assigned focus from keyboard right now?
|
||||
bool CanAcceptFocusFromKeyboard() const
|
||||
{ return AcceptsFocusFromKeyboard() && CanAcceptFocus(); }
|
||||
|
||||
// navigates in the specified direction by sending a wxNavigationKeyEvent
|
||||
virtual bool Navigate(int flags = wxNavigationKeyEvent::IsForward);
|
||||
|
||||
|
@ -249,7 +249,7 @@ bool wxNonOwnedWindow::Show(bool show)
|
||||
{
|
||||
SetDfbFocus();
|
||||
}
|
||||
else if ( AcceptsFocus() )
|
||||
else if ( CanAcceptFocus() )
|
||||
{
|
||||
// FIXME: we should probably always call SetDfbFocus instead
|
||||
// and call SetFocus() from wxActivateEvent/DWET_GOTFOCUS
|
||||
|
@ -1469,7 +1469,7 @@ gtk_window_button_press_callback( GtkWidget *widget,
|
||||
|
||||
g_lastButtonNumber = gdk_event->button;
|
||||
|
||||
if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
|
||||
if (win->m_wxwindow && (g_focusWindow != win) && win->CanAcceptFocus())
|
||||
{
|
||||
gtk_widget_grab_focus( win->m_wxwindow );
|
||||
}
|
||||
|
@ -1475,7 +1475,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget,
|
||||
|
||||
g_lastButtonNumber = gdk_event->button;
|
||||
|
||||
if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
|
||||
if (win->m_wxwindow && (g_focusWindow != win) && win->CanAcceptFocus())
|
||||
{
|
||||
gtk_widget_grab_focus( win->m_wxwindow );
|
||||
/*
|
||||
|
@ -591,7 +591,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev
|
||||
if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
|
||||
{
|
||||
// ... that is set focus to this window
|
||||
if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow)
|
||||
if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow)
|
||||
currentMouseWindow->SetFocus();
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ bool wxTopLevelWindowMGL::Show(bool show)
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
if ( ret && show && AcceptsFocus() )
|
||||
if ( ret && show && CanAcceptFocus() )
|
||||
SetFocus();
|
||||
// FIXME_MGL -- don't do this for popup windows?
|
||||
return ret;
|
||||
|
@ -184,7 +184,7 @@ static ibool MGLAPI wxWindowMouseHandler(window_t *wnd, event_t *e)
|
||||
{
|
||||
case EVT_MOUSEDOWN:
|
||||
// Change focus if the user clicks outside focused window:
|
||||
if ( win->AcceptsFocus() && wxWindow::FindFocus() != win )
|
||||
if ( win->CanAcceptFocus() && wxWindow::FindFocus() != win )
|
||||
win->SetFocus();
|
||||
|
||||
if ( e->message & EVT_DBLCLICK )
|
||||
|
@ -237,7 +237,7 @@ WXDWORD wxControl::MSWGetStyle(long style, WXDWORD *exstyle) const
|
||||
{
|
||||
long msStyle = wxWindow::MSWGetStyle(style, exstyle);
|
||||
|
||||
if ( AcceptsFocus() )
|
||||
if ( AcceptsFocusFromKeyboard() )
|
||||
{
|
||||
msStyle |= WS_TABSTOP;
|
||||
}
|
||||
|
@ -2331,7 +2331,7 @@ bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* msg)
|
||||
node = node->GetNext() )
|
||||
{
|
||||
wxWindow * const win = node->GetData();
|
||||
if ( win->AcceptsFocus() &&
|
||||
if ( win->CanAcceptFocus() &&
|
||||
!(::GetWindowLong(GetHwndOf(win), GWL_EXSTYLE) &
|
||||
WS_EX_CONTROLPARENT) )
|
||||
{
|
||||
@ -2741,7 +2741,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
|
||||
// problems, so don't do it for them (unnecessary anyhow)
|
||||
if ( !win->IsOfStandardClass() )
|
||||
{
|
||||
if ( message == WM_LBUTTONDOWN && win->AcceptsFocus() )
|
||||
if ( message == WM_LBUTTONDOWN && win->CanAcceptFocus() )
|
||||
win->SetFocus();
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ WXDWORD wxControl::OS2GetStyle( long lStyle, WXDWORD* pdwExstyle ) const
|
||||
{
|
||||
long dwStyle = wxWindow::OS2GetStyle( lStyle, pdwExstyle );
|
||||
|
||||
if (AcceptsFocus())
|
||||
if (AcceptsFocusFromKeyboard())
|
||||
{
|
||||
dwStyle |= WS_TABSTOP;
|
||||
}
|
||||
|
@ -2358,7 +2358,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg,
|
||||
);
|
||||
if (!pWin->IsOfStandardClass())
|
||||
{
|
||||
if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() )
|
||||
if (uMsg == WM_BUTTON1DOWN && pWin->CanAcceptFocus() )
|
||||
pWin->SetFocus();
|
||||
}
|
||||
bProcessed = pWin->HandleMouseEvent( uMsg
|
||||
|
@ -3196,10 +3196,9 @@ bool wxWin32InputHandler::HandleMouse(wxInputConsumer *control,
|
||||
// clicking on the control gives it focus
|
||||
if ( event.ButtonDown() )
|
||||
{
|
||||
wxWindow *win = control->GetInputWindow();
|
||||
wxWindow * const win = control->GetInputWindow();
|
||||
|
||||
if ( (wxWindow::FindFocus() != control->GetInputWindow()) &&
|
||||
win->AcceptsFocus() )
|
||||
if ( win->CanAcceptFocus() && wxWindow::FindFocus() != win )
|
||||
{
|
||||
win->SetFocus();
|
||||
|
||||
|
@ -544,7 +544,7 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
|
||||
|
||||
if (event->type == ButtonPress)
|
||||
{
|
||||
if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
|
||||
if ((win != wxWindow::FindFocus()) && win->CanAcceptFocus())
|
||||
{
|
||||
// This might actually be done in wxWindow::SetFocus()
|
||||
// and not here. TODO.
|
||||
|
Loading…
Reference in New Issue
Block a user