[Libreoffice-commits] .: Branch 'libreoffice-3-6' - 2 commits - sc/source

Noel Power noelp at kemper.freedesktop.org
Tue Jun 26 10:21:18 PDT 2012


 sc/source/ui/inc/prevwsh.hxx  |    3 -
 sc/source/ui/view/preview.cxx |    5 --
 sc/source/ui/view/prevwsh.cxx |   96 +++++++++++++++++++++++++-----------------
 3 files changed, 61 insertions(+), 43 deletions(-)

New commits:
commit 4a5e8fc26e2bbd37779505c40f470b3b3be9a5db
Author: Noel Power <noel.power at novell.com>
Date:   Tue Jun 26 18:19:21 2012 +0100

    fix for fdo#51040 preview crash
    
    Change-Id: I13d3cfa99294bdce8c9f5133f49e91114feb4baa

diff --git a/sc/source/ui/inc/prevwsh.hxx b/sc/source/ui/inc/prevwsh.hxx
index 0f89fc7..020c211 100644
--- a/sc/source/ui/inc/prevwsh.hxx
+++ b/sc/source/ui/inc/prevwsh.hxx
@@ -50,7 +50,6 @@ class CommandEvent;
 
 class ScPreviewShell: public SfxViewShell
 {
-friend class ScPreview; // allow access to AdjustPosSizePixel
     ScDocShell*     pDocShell;
 
     SystemWindow*   mpFrameWindow;
@@ -66,7 +65,6 @@ friend class ScPreview; // allow access to AdjustPosSizePixel
 
     SfxBroadcaster* pAccessibilityBroadcaster;
     bool            GetPageSize( Size& aPageSize );
-    void            UpdateNeededScrollBars();
 private:
     void            Construct( Window* pParent );
     DECL_LINK(ScrollHandler, ScrollBar* );
@@ -106,6 +104,7 @@ public:
     void            InitStartTable(SCTAB nTab);
 
     void            UpdateScrollBars();
+    void            UpdateNeededScrollBars(bool bFromZoom = false);
     sal_Bool            ScrollCommand( const CommandEvent& rCEvt );
 
     void            Execute( SfxRequest& rReq );
diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx
index da05322..c45135b 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -705,10 +705,7 @@ void ScPreview::SetZoom(sal_uInt16 nNewZoom)
         SetMapMode( aMMMode );
 
         bInSetZoom = true;              // don't scroll during SetYOffset in UpdateScrollBars
-        if ( Window* pWin = ( pViewShell->GetViewFrame() ? &pViewShell->GetViewFrame()->GetWindow() : NULL ) )
-            pViewShell->AdjustPosSizePixel( pWin->GetPosPixel(), pWin->GetSizePixel() );
-        else
-            pViewShell->UpdateScrollBars();
+        pViewShell->UpdateNeededScrollBars(true);
         bInSetZoom = false;
 
         bStateValid = false;
diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index a69cb79..02bf4e1 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -302,16 +302,9 @@ bool ScPreviewShell::GetPageSize( Size& aPageSize )
     return true;
 }
 
-void ScPreviewShell::UpdateNeededScrollBars()
+void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom )
 {
-    bool bVert = pVerScroll ? pVerScroll->IsVisible() : false;
-    bool bHori = pHorScroll ? pHorScroll->IsVisible() : false;
-
     Size aPageSize;
-    if ( !GetPageSize( aPageSize ) )
-        return;
-
-    Size aWindowSize = pPreview->GetOutputSize();
     OutputDevice* pDevice = Application::GetDefaultDevice();
 
     long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
@@ -320,49 +313,74 @@ void ScPreviewShell::UpdateNeededScrollBars()
     long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0;
     long aWidthOffSet = aHeightOffSet;
 
-    if( pHorScroll )
+
+    if (!GetPageSize( aPageSize ))
+        return;
+
+    //  for centering, page size without the shadow is used
+    bool bVert = pVerScroll ? pVerScroll->IsVisible() : false;
+    bool bHori = pHorScroll ? pHorScroll->IsVisible() : false;
+    Size aWindowSize = pPreview->GetOutputSize();
+    Point aPos = pPreview->GetPosPixel();
+    Size aWindowPixelSize = pPreview->GetOutputSizePixel();
+
+    // if we are called from Zoom then we need to compensate for whatever
+    // scrollbars were displayed before the zoom was called
+    if ( bFromZoom )
     {
-        long nMaxPos = aPageSize.Width() - aWindowSize.Width() + aWidthOffSet;
-        if ( nMaxPos<0 )
-            bHori = false;
-        else
-            bHori = true;
-        pHorScroll->Show( bHori );
+        if ( bVert )
+        {
+            aWindowPixelSize.Width() += nBarH;
+            aWindowSize.Width() += aHeightOffSet;
+        }
+        if ( bHori )
+        {
+            aWindowPixelSize.Height() += nBarW;
+            aWindowSize.Height() += aWidthOffSet;
+        }
     }
+    // recalculate any needed scrollbars
+    bHori = false;
+    bVert = false;
 
-    if( pVerScroll )
-    {
-        nMaxVertPos = aPageSize.Height() - aWindowSize.Height() + aHeightOffSet;
+    long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width();
+    if ( nMaxWidthPos<0 )
+        bHori = false;
+    else
+        bHori = true;
 
-        if ( nMaxVertPos < 0 )
-            bVert = false;
-        else
+    long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height();
+
+    if ( nMaxHeightPos < 0 )
+        bVert = false;
+    else
+        bVert = true;
+
+    // see if having a scroll bar requires the other
+    if ( bVert != bHori && ( bVert || bHori ) )
+    {
+        if ( bVert && ( (nMaxWidthPos + aWidthOffSet  ) > 0 ) )
+            bHori = true;
+        else if ( (nMaxHeightPos + aHeightOffSet ) > 0 )
             bVert = true;
-        pVerScroll->Show( bVert );
     }
+    pHorScroll->Show( bHori );
+    pVerScroll->Show( bVert );
 
-    Size aOutSize = pPreview->GetSizePixel();
-    Size aNewSize = aOutSize;
-    Point aPos = pPreview->GetPosPixel();
-
+    // make room for needed scrollbars ( and reduce the size
+    // of the preview appropriately )
     if ( bHori )
-        aNewSize.Height() -= nBarH;
+        aWindowPixelSize.Height() -= nBarW;
     if ( bVert )
-        aNewSize.Width() -= nBarW;
-
-    pPreview->SetPosSizePixel( aPos, aNewSize );
-
-    pHorScroll->SetPosSizePixel( Point( aPos.X(), aPos.Y() + aNewSize.Height() ),
-                                 Size( aNewSize.Width(), nBarH ) );
-    pVerScroll->SetPosSizePixel( Point( aPos.X() + aNewSize.Width(), aPos.Y() ),
-                                 Size( nBarW, aNewSize.Height() ) );
-    pCorner->SetPosSizePixel( Point( aPos.X() + aNewSize.Width(), aPos.Y() + aNewSize.Height() ),
+        aWindowPixelSize.Width() -= nBarH;
+
+    pPreview->SetSizePixel( aWindowPixelSize );
+    pHorScroll->SetPosSizePixel( Point( aPos.X(), aPos.Y() + aWindowPixelSize.Height() ),
+                                 Size( aWindowPixelSize.Width(), nBarH ) );
+    pVerScroll->SetPosSizePixel( Point( aPos.X() + aWindowPixelSize.Width(), aPos.Y() ),
+                                 Size( nBarW, aWindowPixelSize.Height() ) );
+    pCorner->SetPosSizePixel( Point( aPos.X() + aWindowPixelSize.Width(), aPos.Y() + aWindowPixelSize.Height() ),
                               Size( nBarW, nBarH ) );
-
-    if ( SVX_ZOOM_WHOLEPAGE == eZoom )
-        pPreview->SetZoom( pPreview->GetOptimalZoom( sal_False ) );
-    else if ( SVX_ZOOM_PAGEWIDTH == eZoom )
-        pPreview->SetZoom( pPreview->GetOptimalZoom( sal_True ) );
     UpdateScrollBars();
 }
 
commit be92126c633f13589628068d523939c60f905894
Author: Noel Power <noel.power at novell.com>
Date:   Tue Jun 26 16:19:46 2012 +0100

    Revert "set the zoom only once, prevents infinite loop, fdo#51040"
    
    This reverts commit a266f82d2199974dee0429ddc263d2ca2cecea1c.

diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index c4816bb..a69cb79 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -359,6 +359,10 @@ void ScPreviewShell::UpdateNeededScrollBars()
     pCorner->SetPosSizePixel( Point( aPos.X() + aNewSize.Width(), aPos.Y() + aNewSize.Height() ),
                               Size( nBarW, nBarH ) );
 
+    if ( SVX_ZOOM_WHOLEPAGE == eZoom )
+        pPreview->SetZoom( pPreview->GetOptimalZoom( sal_False ) );
+    else if ( SVX_ZOOM_PAGEWIDTH == eZoom )
+        pPreview->SetZoom( pPreview->GetOptimalZoom( sal_True ) );
     UpdateScrollBars();
 }
 


More information about the Libreoffice-commits mailing list