]> git.saurik.com Git - wxWidgets.git/commitdiff
don't check whether the window is shown and enabled in AcceptsFocus() itself
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 25 Mar 2007 22:36:24 +0000 (22:36 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 25 Mar 2007 22:36:24 +0000 (22:36 +0000)
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

14 files changed:
docs/latex/wx/window.tex
include/wx/window.h
src/dfb/nonownedwnd.cpp
src/gtk/window.cpp
src/gtk1/window.cpp
src/mac/carbon/toplevel.cpp
src/mgl/toplevel.cpp
src/mgl/window.cpp
src/msw/control.cpp
src/msw/window.cpp
src/os2/control.cpp
src/os2/window.cpp
src/univ/themes/win32.cpp
src/x11/app.cpp

index 4d266a0112dea822a61032b6d06ba39ffa50834a..874de4a13a6eca671da115ed6783b597884e1747 100644 (file)
@@ -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}}
index 9e732457529e6ef6407d62b7aa24adb47660ebf4..c48e7b8579aef478255188f8be49c97d7488985f 100644 (file)
@@ -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);
 
index 4fe1ac999d6229480c06b994928c7f4a3094eba2..886f918b0c336ab20851b5507fe893703e46df06 100644 (file)
@@ -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
index 1dbf515853a1231aa00d84ab88b7f98b633af1a5..3d372237edaa63913dcb0c785395901f2e443c88 100644 (file)
@@ -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 );
     }
index 9e328dbcdef0592e005afc0c339b58ea02310f5e..f9934ba15e3c0ac8e02cc2c0b10418f43c10b7b7 100644 (file)
@@ -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 );
 /*
index 27d297fac2c8c63c7061a49708bba8aa9839eab4..d29746a500e26513e56857e0124aa9628bb044d3 100644 (file)
@@ -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();
             }
 
index a4f10c308cf355f18ea62c531e7277c9f0cc9378..ebb4bacd10802d58d6bfb6c2a681587014551521 100644 (file)
@@ -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;
index 70a9ffaf6431198e81ef573bff178f34d7e1e866..85f2abeee3d5417af7718dcfcae3321ec0e0cf1b 100644 (file)
@@ -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 )
index 8e72df223da4ae9f06f7e3547923be9222d29a58..bd6c3cff174509be5fe04c95f2b83534ad8340c6 100644 (file)
@@ -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;
     }
index b66358af13dd1d667df7279493a63075c7389e13..a7ea67d2bb89c7e837df73f071df07296b858cee 100644 (file)
@@ -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();
                     }
                 }
index 51eff786ee8367ce25756322c243caef4fbba3bb..09bf756b6f4e842414dd245a795b3488e1075e38 100644 (file)
@@ -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;
     }
index 3a80c6337d5a721fa14a2bc474b865a7d71e4b4d..43c6a8f13ab6ba3dc73a638292f443bdb0ad3859 100644 (file)
@@ -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
index 12b176ac044dbfefd0f3f632dc9e5534293fed76..3603333f2bca8e8fa47654eace0559eeefe868bc 100644 (file)
@@ -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();
 
index a7165cf5ec4bf93fb828bf008bf770b959a20dfc..afcc29cb00f76d75223715857ae60e83647a565b 100644 (file)
@@ -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.