[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - include/vcl vcl/source

Caolán McNamara caolanm at redhat.com
Thu Oct 6 14:27:55 UTC 2016


 include/vcl/window.hxx                   |    2 -
 vcl/source/window/floatwin.cxx           |    2 -
 vcl/source/window/menu.cxx               |   15 -------
 vcl/source/window/menubarwindow.cxx      |    7 +--
 vcl/source/window/menufloatingwindow.cxx |   60 +++++++++++++++++++------------
 vcl/source/window/menufloatingwindow.hxx |    6 ++-
 vcl/source/window/window2.cxx            |   16 +-------
 7 files changed, 50 insertions(+), 58 deletions(-)

New commits:
commit 06761518b63cc420ee11cff3e54e1059a5985b01
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Sep 27 15:14:46 2016 +0100

    Resolves: tdf#102177 focus not restored from context menus
    
    this is a bunch of squashed together commits, much easier to
    read commit by commit
    
    the problem being that the attempt to restore the focus in the document in the
    floatingwindow tear down is blocked because the menus have set that window as
    modal so the focus isn't set.
    
    The attempt to set the focus in the floatingwindow teardown causes the
    SavedFocus in the menufloatingwindow to be dropped, so the extra layer of code
    to restore focus after modality is removed doesn't do anything
    
    this is fallout from...
    
    commit dd46727b99d4bb5135451aa7e5e1bdb197373843
    Author: Caolán McNamara <caolanm at redhat.com>
    Date:   Tue Apr 5 15:27:38 2016 +0100
    
        Resolves: tdf#87120 no keyboard navigation inside floating windows
    
    which allows the focus to "truly" enter the menus, triggering the
    floatingwindow attempt, which fails but blocks the menufloatingwindow attempt
    
    easiest thing seems to make the restoring modality, and then restore focus,
    something that MenuFloatingWindow does before it finishes
    
    (cherry picked from commit 4da7971812b0a53ba80f7d9c29851c527488067d)
    
    the only place the default xFocusId arg isn't used...
    
    the argument is (effectively) equal to the default
    
    (cherry picked from commit 95a6d24ed7a231c42ccd608fb93cbed989a62e3a)
    
    EndSaveFocus return value is unused
    
    (cherry picked from commit 98da362f1691734437cb37f902fb1cdab613ac0a)
    
    EndSaveFocus does nothing on the !bRestore case
    
    (cherry picked from commit 9b7dfb10641ba7978ffcbd1db0507163411ae027)
    
    detangle code that now looks silly since...
    
    commit 9b7dfb10641ba7978ffcbd1db0507163411ae027
    Author: Caolán McNamara <caolanm at redhat.com>
    Date:   Thu Jun 9 16:52:21 2016 +0100
    
        EndSaveFocus does nothing on the !bRestore case
    
    removed the code that made it look like it made sense
    
    (cherry picked from commit 0d56cc15803965a1be6991a3630076f7ccf67817)
    
    Change-Id: I97a4ac71419dcb04709e4667586d8343e89ddbeb
    26fcd43d2bc8e37e6887c244f728e3231328e34e
    746e47b118a8b8c687c435371e2bdf2dc22cbf88
    8e199535803faf364469f9b9df46f339febe25c6
    2e7280fd6643e86d65cba04c8302be099d6f3d0e
    Reviewed-on: https://gerrit.libreoffice.org/29326
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index dea60a9..577416d 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -1132,7 +1132,7 @@ public:
     bool                                IsCompoundControl() const;
 
     static VclPtr<vcl::Window>          SaveFocus();
-    static bool                         EndSaveFocus( const VclPtr<vcl::Window>& xFocusWin, bool bRestore = true );
+    static void                         EndSaveFocus(const VclPtr<vcl::Window>& xFocusWin);
 
     void                                CaptureMouse();
     void                                ReleaseMouse();
diff --git a/vcl/source/window/floatwin.cxx b/vcl/source/window/floatwin.cxx
index 2f41522..c24706b 100644
--- a/vcl/source/window/floatwin.cxx
+++ b/vcl/source/window/floatwin.cxx
@@ -804,8 +804,6 @@ void FloatingWindow::ImplEndPopupMode( FloatWinPopupEndFlags nFlags, const VclPt
     else
     {
         mbPopupModeTearOff = true;
-        if ( xFocusId != nullptr )
-            Window::EndSaveFocus( xFocusId, false );
     }
 
     mbPopupModeCanceled = bool(nFlags & FloatWinPopupEndFlags::Cancel);
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 6454936..30cfed8 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -3027,12 +3027,6 @@ sal_uInt16 PopupMenu::ImplExecute( const VclPtr<vcl::Window>& pW, const Rectangl
 
     pWin->SetFocusId( xFocusId );
     pWin->SetOutputSizePixel( aSz );
-    // #102158# menus must never grab the focus, otherwise
-    // they will be closed immediately
-    // from now on focus grabbing is only prohibited automatically if
-    // FloatWinPopupFlags::GrabFocus was set (which is done below), because some
-    // floaters (like floating toolboxes) may grab the focus
-    // pWin->GrabFocus();
     if ( GetItemCount() )
     {
         SalMenu* pMenu = ImplGetSalMenu();
@@ -3082,15 +3076,8 @@ sal_uInt16 PopupMenu::ImplExecute( const VclPtr<vcl::Window>& pW, const Rectangl
     }
     if ( bRealExecute )
     {
-        pW->ImplIncModalCount();
-
         pWin->Execute();
-
-        DBG_ASSERT( ! pW->IsDisposed(), "window for popup died, modal count incorrect !" );
-        if( ! pW->IsDisposed() )
-            pW->ImplDecModalCount();
-
-        if ( pWin->IsDisposed() )
+        if (pWin->IsDisposed())
             return 0;
 
         // Restore focus (could already have been
diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx
index 16d3af5..bf8b76c 100644
--- a/vcl/source/window/menubarwindow.cxx
+++ b/vcl/source/window/menubarwindow.cxx
@@ -466,8 +466,6 @@ void MenuBarWindow::ChangeHighlightItem( sal_uInt16 n, bool bSelectEntry, bool b
             {
                 if( !ImplGetSVData()->maWinData.mbNoSaveFocus )
                 {
-                    // we didn't clean up last time
-                    Window::EndSaveFocus( xSaveFocusId, false );    // clean up
                     xSaveFocusId = nullptr;
                     if( !bNoSaveFocus )
                         xSaveFocusId = Window::SaveFocus(); // only save focus when initially activated
@@ -499,9 +497,10 @@ void MenuBarWindow::ChangeHighlightItem( sal_uInt16 n, bool bSelectEntry, bool b
         {
             VclPtr<vcl::Window> xTempFocusId = xSaveFocusId;
             xSaveFocusId = nullptr;
-            Window::EndSaveFocus( xTempFocusId, bAllowRestoreFocus );
+            if (bAllowRestoreFocus)
+                Window::EndSaveFocus(xTempFocusId);
             // #105406# restore focus to document if we could not save focus before
-            if( bDefaultToDocument && xTempFocusId == nullptr && bAllowRestoreFocus )
+            if (bDefaultToDocument && xTempFocusId == nullptr && bAllowRestoreFocus)
                 GrabFocusToDocument();
         }
     }
diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx
index 20cb2e5..3e0c28f 100644
--- a/vcl/source/window/menufloatingwindow.cxx
+++ b/vcl/source/window/menufloatingwindow.cxx
@@ -270,13 +270,13 @@ IMPL_LINK_NOARG_TYPED(MenuFloatingWindow, PopupEnd, FloatingWindow*, void)
     Menu* pM = pMenu;
     if ( bInExecute )
     {
+        End();
         if ( pActivePopup )
         {
             //DBG_ASSERT( !pActivePopup->ImplGetWindow(), "PopupEnd, obwohl pActivePopup MIT Window!" );
             KillActivePopup(); // should be ok to just remove it
             //pActivePopup->bCanceled = true;
         }
-        bInExecute = false;
         pMenu->bInCallback = true;
         pMenu->Deactivate();
         pMenu->bInCallback = false;
@@ -386,40 +386,57 @@ void MenuFloatingWindow::EnableScrollMenu( bool b )
     InitMenuClipRegion(*this);
 }
 
+void MenuFloatingWindow::Start()
+{
+    if (bInExecute)
+        return;
+    bInExecute = true;
+    if (GetParent())
+        GetParent()->ImplIncModalCount();
+}
+
+void MenuFloatingWindow::End()
+{
+    if (!bInExecute)
+        return;
+
+    if (GetParent() && !GetParent()->IsDisposed())
+        GetParent()->ImplDecModalCount();
+
+    // restore focus
+    VclPtr<vcl::Window> xFocusId(xSaveFocusId);
+    if (xFocusId != nullptr)
+    {
+        xSaveFocusId = nullptr;
+        ImplGetSVData()->maWinData.mbNoDeactivate = false;
+        Window::EndSaveFocus(xFocusId);
+    }
+
+    bInExecute = false;
+}
+
 void MenuFloatingWindow::Execute()
 {
     ImplSVData* pSVData = ImplGetSVData();
 
     pSVData->maAppData.mpActivePopupMenu = static_cast<PopupMenu*>(pMenu);
 
-    bInExecute = true;
-//  bCallingSelect = false;
+    Start();
 
-    while ( bInExecute )
+    while (bInExecute)
         Application::Yield();
 
     pSVData->maAppData.mpActivePopupMenu = nullptr;
 }
 
-void MenuFloatingWindow::StopExecute( VclPtr<vcl::Window> xFocusId )
+void MenuFloatingWindow::StopExecute()
 {
-    // restore focus
-    // (could have been restored in Select)
-    if ( xSaveFocusId != nullptr )
-    {
-        Window::EndSaveFocus( xFocusId, false );
-        xFocusId = xSaveFocusId;
-        if ( xFocusId != nullptr )
-        {
-            xSaveFocusId = nullptr;
-            ImplGetSVData()->maWinData.mbNoDeactivate = false;
-        }
-    }
-    ImplEndPopupMode( FloatWinPopupEndFlags::NONE, xFocusId );
+    End();
+
+    ImplEndPopupMode(FloatWinPopupEndFlags::NONE, xSaveFocusId);
 
     aHighlightChangedTimer.Stop();
-    bInExecute = false;
-    if ( pActivePopup )
+    if (pActivePopup)
     {
         KillActivePopup();
     }
@@ -460,7 +477,6 @@ void MenuFloatingWindow::KillActivePopup( PopupMenu* pThisOnly )
 void MenuFloatingWindow::EndExecute()
 {
     Menu* pStart = pMenu ? pMenu->ImplGetStartMenu() : nullptr;
-    VclPtr<vcl::Window> xFocusId;
 
     // if started elsewhere, cleanup there as well
     MenuFloatingWindow* pCleanUpFrom = this;
@@ -477,7 +493,7 @@ void MenuFloatingWindow::EndExecute()
     Menu* pM = pMenu;
     sal_uInt16 nItem = nHighlightedItem;
 
-    pCleanUpFrom->StopExecute( xFocusId );
+    pCleanUpFrom->StopExecute();
 
     if ( nItem != ITEMPOS_INVALID && pM )
     {
diff --git a/vcl/source/window/menufloatingwindow.hxx b/vcl/source/window/menufloatingwindow.hxx
index 8791293..1aec4f7 100644
--- a/vcl/source/window/menufloatingwindow.hxx
+++ b/vcl/source/window/menufloatingwindow.hxx
@@ -50,7 +50,6 @@ private:
     sal_uInt16 nPosInParent;
 
     bool bInExecute : 1;
-
     bool bScrollMenu : 1;
     bool bScrollUp : 1;
     bool bScrollDown : 1;
@@ -68,6 +67,9 @@ private:
 
     void InitMenuClipRegion(vcl::RenderContext& rRenderContext);
 
+    void Start();
+    void End();
+
 protected:
     vcl::Region ImplCalcClipRegion( bool bIncludeLogo = true ) const;
     void ImplDrawScroller(vcl::RenderContext& rRenderContext, bool bUp);
@@ -108,7 +110,7 @@ public:
     sal_uInt16 GetScrollerHeight() const   { return nScrollerHeight; }
 
     void Execute();
-    void StopExecute( VclPtr<vcl::Window> xFocusId = nullptr );
+    void StopExecute();
     void EndExecute();
     void EndExecute( sal_uInt16 nSelectId );
 
diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx
index 3cd36e24..79ae5c5 100644
--- a/vcl/source/window/window2.cxx
+++ b/vcl/source/window/window2.cxx
@@ -421,21 +421,11 @@ VclPtr<vcl::Window> Window::SaveFocus()
         return nullptr;
 }
 
-bool Window::EndSaveFocus( const VclPtr<vcl::Window>& xFocusWin, bool bRestore )
+void Window::EndSaveFocus(const VclPtr<vcl::Window>& xFocusWin)
 {
-    if ( xFocusWin == nullptr )
-        return false;
-    else
+    if (xFocusWin && !xFocusWin->IsDisposed())
     {
-        bool                bOK = true;
-        if ( !xFocusWin->IsDisposed() )
-        {
-            if ( bRestore )
-                xFocusWin->GrabFocus();
-        }
-        else
-            bOK = !bRestore;
-        return bOK;
+        xFocusWin->GrabFocus();
     }
 }
 


More information about the Libreoffice-commits mailing list