[Libreoffice-commits] .: 2 commits - sc/source sw/source

Noel Power noelp at kemper.freedesktop.org
Tue Apr 3 09:23:33 PDT 2012


 sc/source/ui/inc/prevwsh.hxx  |    5 +-
 sc/source/ui/view/preview.cxx |    5 +-
 sc/source/ui/view/prevwsh.cxx |  104 +++++++++++++++++++++++++++++++++---------
 sw/source/ui/uiview/pview.cxx |   84 +++++++++++++++++++++------------
 4 files changed, 143 insertions(+), 55 deletions(-)

New commits:
commit f194d18dfeceff104f9c5e500ea4dd94fa1b5b06
Author: Noel Power <noel.power at novell.com>
Date:   Tue Apr 3 17:07:54 2012 +0100

    Hori/Vert scrollbars in calc preview should be shown only when necessary

diff --git a/sc/source/ui/inc/prevwsh.hxx b/sc/source/ui/inc/prevwsh.hxx
index 271a352..1ac668a 100644
--- a/sc/source/ui/inc/prevwsh.hxx
+++ b/sc/source/ui/inc/prevwsh.hxx
@@ -50,6 +50,7 @@ class CommandEvent;
 
 class ScPreviewShell: public SfxViewShell
 {
+friend class ScPreview; // allow access to AdjustPosSizePixel
     ScDocShell*     pDocShell;
 
     ScPreview*      pPreview;               // Ausgabe-Fenster
@@ -63,7 +64,8 @@ class ScPreviewShell: public SfxViewShell
     long            nMaxVertPos;
 
     SfxBroadcaster* pAccessibilityBroadcaster;
-
+    bool            GetPageSize( Size& aPageSize );
+    void            UpdateNeededScrollBars();
 private:
     void            Construct( Window* pParent );
     DECL_LINK(ScrollHandler, ScrollBar* );
@@ -72,7 +74,6 @@ private:
 protected:
     virtual void    Activate(sal_Bool bMDI);
     virtual void    Deactivate(sal_Bool bMDI);
-
     virtual void    AdjustPosSizePixel( const Point &rPos, const Size &rSize );
 
     virtual void    InnerResizePixel( const Point &rOfs, const Size &rSize );
diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx
index bbb7c72..e83224d 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -705,7 +705,10 @@ void ScPreview::SetZoom(sal_uInt16 nNewZoom)
         SetMapMode( aMMMode );
 
         bInSetZoom = true;              // don't scroll during SetYOffset in UpdateScrollBars
-        pViewShell->UpdateScrollBars();
+        if ( Window* pWin = pViewShell->GetWindow() )
+            pViewShell->AdjustPosSizePixel( pWin->GetPosPixel(), pWin->GetSizePixel() );
+        else
+            pViewShell->UpdateScrollBars();
         bInSetZoom = false;
 
         bStateValid = false;
diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index dfc6268..8b65824 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -134,8 +134,8 @@ void ScPreviewShell::Construct( Window* pParent )
     if (pDrawBC)
         StartListening(*pDrawBC);
 
-    pHorScroll->Show();
-    pVerScroll->Show();
+    pHorScroll->Show( false );
+    pVerScroll->Show( false );
     pCorner->Show();
     SetHelpId( HID_SCSHELL_PREVWSH );
     SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Preview")));
@@ -244,24 +244,15 @@ Size ScPreviewShell::GetOptimalSizePixel() const
 
 void ScPreviewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
 {
-    long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
-    long nBarH = nBarW;
-
-    Size aOutSize( rSize.Width()-nBarW, rSize.Height()-nBarH );
+    Size aOutSize( rSize );
     pPreview->SetPosSizePixel( rPos, aOutSize );
-    pHorScroll->SetPosSizePixel( Point( rPos.X(), rPos.Y() + aOutSize.Height() ),
-                                 Size( aOutSize.Width(), nBarH ) );
-    pVerScroll->SetPosSizePixel( Point( rPos.X() + aOutSize.Width(), rPos.Y() ),
-                                 Size( nBarW, aOutSize.Height() ) );
-    pCorner->SetPosSizePixel( Point( rPos.X() + aOutSize.Width(), rPos.Y() + aOutSize.Height() ),
-                              Size( nBarW, nBarH ) );
 
     if ( SVX_ZOOM_WHOLEPAGE == eZoom )
         pPreview->SetZoom( pPreview->GetOptimalZoom(false) );
     else if ( SVX_ZOOM_PAGEWIDTH == eZoom )
-        pPreview->SetZoom( pPreview->GetOptimalZoom(sal_True) );
+        pPreview->SetZoom( pPreview->GetOptimalZoom(true) );
 
-    UpdateScrollBars();
+    UpdateNeededScrollBars();
 }
 
 void ScPreviewShell::InnerResizePixel( const Point &rOfs, const Size &rSize )
@@ -274,7 +265,7 @@ void ScPreviewShell::OuterResizePixel( const Point &rOfs, const Size &rSize )
     AdjustPosSizePixel( rOfs,rSize );
 }
 
-void ScPreviewShell::UpdateScrollBars()
+bool ScPreviewShell::GetPageSize( Size& aPageSize )
 {
     ScDocument* pDoc = pDocShell->GetDocument();
     SCTAB nTab = pPreview->GetTab();
@@ -282,13 +273,87 @@ void ScPreviewShell::UpdateScrollBars()
     ScStyleSheetPool*   pStylePool  = pDoc->GetStyleSheetPool();
     SfxStyleSheetBase*  pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ),
                                                         SFX_STYLE_FAMILY_PAGE );
-    OSL_ENSURE(pStyleSheet,"StyleSheet nicht gefunden");
-    if (!pStyleSheet) return;
+    OSL_ENSURE(pStyleSheet,"No style sheet");
+    if (!pStyleSheet) return false;
     const SfxItemSet* pParamSet = &pStyleSheet->GetItemSet();
 
-    Size aPageSize = ((const SvxSizeItem&) pParamSet->Get(ATTR_PAGE_SIZE)).GetSize();
+    aPageSize = ((const SvxSizeItem&) pParamSet->Get(ATTR_PAGE_SIZE)).GetSize();
     aPageSize.Width()  = (long) (aPageSize.Width()  * HMM_PER_TWIPS );
     aPageSize.Height() = (long) (aPageSize.Height() * HMM_PER_TWIPS );
+    return true;
+}
+
+void ScPreviewShell::UpdateNeededScrollBars()
+{
+    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();
+    long nBarH = nBarW;
+
+    long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0;
+    long aWidthOffSet = aHeightOffSet;
+
+    Point aOfs = pPreview->GetOffset();
+
+    if( pHorScroll )
+    {
+        long nMaxPos = aPageSize.Width() - aWindowSize.Width() + aWidthOffSet;
+        if ( nMaxPos<0 )
+            bHori = false;
+        else
+            bHori = true;
+        pHorScroll->Show( bHori );
+    }
+
+    if( pVerScroll )
+    {
+        nMaxVertPos = aPageSize.Height() - aWindowSize.Height() + aHeightOffSet;
+
+        if ( nMaxVertPos < 0 )
+            bVert = false;
+        else
+            bVert = true;
+        pVerScroll->Show( bVert );
+    }
+
+    Size aOutSize = pPreview->GetSizePixel();
+    Size aNewSize = aOutSize;
+    Point aPos = pPreview->GetPosPixel();
+
+    if ( bHori )
+        aNewSize.Height() -= nBarH;
+    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() ),
+                              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();
+}
+
+void ScPreviewShell::UpdateScrollBars()
+{
+    Size aPageSize;
+    if ( !GetPageSize( aPageSize ) )
+        return;
 
     //  for centering, page size without the shadow is used
 
commit d7b06ba7ec2c988e80c8ef14e2d9bfc2c29e2d24
Author: Noel Power <noel.power at novell.com>
Date:   Tue Apr 3 16:33:41 2012 +0100

    Revert "Hori scroll fix in Writer and Calc Print Preview" & add new patch
    
    This reverts commit eeeb4d9a1c772b12aab515c8d5089fb6b5e003c7.
    
    Fix Scrollbar in Writer Print preview

diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index 6d876b3..dfc6268 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -308,21 +308,18 @@ void ScPreviewShell::UpdateScrollBars()
             //  page smaller than window -> center (but put scrollbar to 0)
             aOfs.X() = 0;
             pPreview->SetXOffset( nMaxPos / 2 );
-            pHorScroll->Show( sal_False );
         }
         else if (aOfs.X() < 0)
         {
             //  page larger than window -> never use negative offset
             aOfs.X() = 0;
             pPreview->SetXOffset( 0 );
-            pHorScroll->Show( sal_True );
         }
         else if (aOfs.X() > nMaxPos)
         {
             //  limit offset to align with right edge of window
             aOfs.X() = nMaxPos;
             pPreview->SetXOffset(nMaxPos);
-            pHorScroll->Show( sal_True );
         }
         pHorScroll->SetThumbPos( aOfs.X() );
     }
diff --git a/sw/source/ui/uiview/pview.cxx b/sw/source/ui/uiview/pview.cxx
index b37baea..2f1fea6 100644
--- a/sw/source/ui/uiview/pview.cxx
+++ b/sw/source/ui/uiview/pview.cxx
@@ -1365,9 +1365,9 @@ void SwPagePreView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*
 {
     const StyleSettings &rSet = aViewWin.GetSettings().GetStyleSettings();
     const long nTmp = rSet.GetScrollBarSize();
-    if ( pVScrollbar->IsVisible( sal_False ))
+    if ( pVScrollbar->IsVisible( true ) )
         rToFill.Right()  = nTmp;
-    if ( pHScrollbar->IsVisible( sal_False ) )
+    if ( pHScrollbar->IsVisible( false ) )
         rToFill.Bottom() = nTmp;
     SetBorderPixel( rToFill );
 }
@@ -1388,7 +1388,7 @@ void  SwPagePreView::InnerResizePixel( const Point &rOfst, const Size &rSize )
     //VisArea niemals einstellen!
 }
 
-void  SwPagePreView::OuterResizePixel( const Point &rOfst, const Size &rSize )
+void SwPagePreView::OuterResizePixel( const Point &rOfst, const Size &rSize )
 {
     SvBorder aBorder;
     CalcAndSetBorderPixel( aBorder, sal_False );
@@ -1404,11 +1404,13 @@ void  SwPagePreView::OuterResizePixel( const Point &rOfst, const Size &rSize )
 
     //Aufruf der DocSzChgd-Methode der Scrollbars ist noetig, da vom maximalen
     //Scrollrange immer die halbe Hoehe der VisArea abgezogen wird.
-    if ( pVScrollbar &&
-             aTmpSize.Width() > 0 && aTmpSize.Height() > 0 )
-        {
-            ScrollDocSzChg();
-        }
+    if ( pVScrollbar && aTmpSize.Width() > 0 && aTmpSize.Height() > 0 )
+    {
+        ScrollDocSzChg();
+    }
+
+    SvBorder aBorderNew;
+    CalcAndSetBorderPixel( aBorderNew, sal_False );
 }
 
 void SwPagePreView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar )
@@ -1620,30 +1622,48 @@ void SwPagePreView::ScrollViewSzChg()
             //vertical scrolling by row
             // adjust to new preview functionality
             sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
-            pVScrollbar->SetVisibleSize( nVisPages );
-            // set selected page as scroll bar position,
-            // if it is visible.
-            SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
-            if ( pPagePrevwLay->IsPageVisible( aViewWin.SelectedPage() ) )
+
+            if( nVisPages < mnPageCount )
             {
-                pVScrollbar->SetThumbPos( aViewWin.SelectedPage() );
+                ShowVScrollbar( sal_True );
+                pPageUpBtn->Show( sal_True );
+                pPageDownBtn->Show( sal_True );
+
+                pVScrollbar->SetVisibleSize( nVisPages );
+                // set selected page as scroll bar position,
+                // if it is visible.
+                SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
+                if ( pPagePrevwLay->IsPageVisible( aViewWin.SelectedPage() ) )
+                {
+                    pVScrollbar->SetThumbPos( aViewWin.SelectedPage() );
+                }
+                else
+                {
+                    pVScrollbar->SetThumbPos( aViewWin.GetSttPage() );
+                }
+                pVScrollbar->SetLineSize( aViewWin.GetCol() );
+                pVScrollbar->SetPageSize( nVisPages );
+                // calculate and set scrollbar range
+                Range aScrollbarRange( 1, mnPageCount );
+                // increase range by one, because left-top-corner is left blank.
+                ++aScrollbarRange.Max();
+                // increase range in order to access all pages
+                aScrollbarRange.Max() += ( nVisPages - 1 );
+                pVScrollbar->SetRange( aScrollbarRange );
             }
             else
             {
-                pVScrollbar->SetThumbPos( aViewWin.GetSttPage() );
+                ShowVScrollbar( sal_False );
+                pPageUpBtn->Show( sal_False );
+                pPageDownBtn->Show( sal_False );
             }
-            pVScrollbar->SetLineSize( aViewWin.GetCol() );
-            pVScrollbar->SetPageSize( nVisPages );
-            // calculate and set scrollbar range
-            Range aScrollbarRange( 1, mnPageCount );
-            // increase range by one, because left-top-corner is left blank.
-            ++aScrollbarRange.Max();
-            // increase range in order to access all pages
-            aScrollbarRange.Max() += ( nVisPages - 1 );
-            pVScrollbar->SetRange( aScrollbarRange );
         }
         else //vertical scrolling by pixel
         {
+            ShowVScrollbar( sal_True );
+            pPageUpBtn->Show( sal_True );
+            pPageDownBtn->Show( sal_True );
+
             const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect();
             const Size& rPreviewSize =
                     GetViewShell()->PagePreviewLayout()->GetPrevwDocSize();
@@ -1666,18 +1686,20 @@ void SwPagePreView::ScrollViewSzChg()
 
         if(rDocRect.GetWidth() < rPreviewSize.Width())
         {
-            pHScrollbar->Show( sal_True );
+            ShowHScrollbar( sal_True );
+
             nVisWidth = rDocRect.GetWidth();
             nThumb = rDocRect.Left();
             aRange = Range(0, rPreviewSize.Width());
+
+            pHScrollbar->SetRange( aRange );
+            pHScrollbar->SetVisibleSize( nVisWidth );
+            pHScrollbar->SetThumbPos( nThumb );
+            pHScrollbar->SetLineSize( nVisWidth / 10 );
+            pHScrollbar->SetPageSize( nVisWidth / 2 );
         }
         else
-            pHScrollbar->Show( sal_False );
-        pHScrollbar->SetRange( aRange );
-        pHScrollbar->SetVisibleSize( nVisWidth );
-        pHScrollbar->SetThumbPos( nThumb );
-        pHScrollbar->SetLineSize( nVisWidth / 10 );
-        pHScrollbar->SetPageSize( nVisWidth / 2 );
+            ShowHScrollbar( sal_False );
     }
 }
 


More information about the Libreoffice-commits mailing list