LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uiview - viewport.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 673 0.0 %
Date: 2014-04-14 Functions: 0 36 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      22             : #include "hintids.hxx"
      23             : 
      24             : #include <vcl/help.hxx>
      25             : #include <vcl/settings.hxx>
      26             : 
      27             : #include <svx/ruler.hxx>
      28             : #include <editeng/paperinf.hxx>
      29             : #include <editeng/lrspitem.hxx>
      30             : #include <sfx2/bindings.hxx>
      31             : #include <view.hxx>
      32             : #include <wrtsh.hxx>
      33             : #include <swmodule.hxx>
      34             : #include <viewopt.hxx>
      35             : #include <frmatr.hxx>
      36             : #include <docsh.hxx>
      37             : #include <cmdid.h>
      38             : #include <edtwin.hxx>
      39             : #include <scroll.hxx>
      40             : #include <wview.hxx>
      41             : #include <usrpref.hxx>
      42             : #include <pagedesc.hxx>
      43             : #include <workctrl.hxx>
      44             : #include <crsskip.hxx>
      45             : #include <touch/touch.h>
      46             : 
      47             : #include <PostItMgr.hxx>
      48             : 
      49             : #include <IDocumentSettingAccess.hxx>
      50             : 
      51             : #include <basegfx/tools/zoomtools.hxx>
      52             : 
      53             : // The SetVisArea of the DocShell must not be called from InnerResizePixel.
      54             : // But our adjustments must take place.
      55             : #ifndef WB_RIGHT_ALIGNED
      56             : #define WB_RIGHT_ALIGNED    ((WinBits)0x00008000)
      57             : #endif
      58             : 
      59             : static bool bProtectDocShellVisArea = false;
      60             : 
      61             : static sal_uInt16 nPgNum = 0;
      62             : 
      63           0 : bool SwView::IsDocumentBorder()
      64             : {
      65           0 :     if (GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
      66           0 :         return true;
      67             : 
      68           0 :     if (!m_pWrtShell)
      69           0 :         return false;
      70             : 
      71           0 :     return m_pWrtShell->GetViewOptions()->getBrowseMode() ||
      72           0 :            SVX_ZOOM_PAGEWIDTH_NOBORDER == (SvxZoomType)m_pWrtShell->GetViewOptions()->GetZoomType();
      73             : }
      74             : 
      75           0 : inline long GetLeftMargin( SwView &rView )
      76             : {
      77           0 :     SvxZoomType eType = (SvxZoomType)rView.GetWrtShell().GetViewOptions()->GetZoomType();
      78           0 :     long lRet = rView.GetWrtShell().GetAnyCurRect(RECT_PAGE_PRT).Left();
      79             :     return eType == SVX_ZOOM_PERCENT   ? lRet + DOCUMENTBORDER :
      80           0 :            eType == SVX_ZOOM_PAGEWIDTH || eType == SVX_ZOOM_PAGEWIDTH_NOBORDER ? 0 :
      81           0 :                                          lRet + DOCUMENTBORDER + nLeftOfst;
      82             : }
      83             : 
      84           0 : static void lcl_GetPos(SwView* pView,
      85             :                 Point& rPos,
      86             :                 SwScrollbar* pScrollbar,
      87             :                 bool bBorder)
      88             : {
      89           0 :     SwWrtShell &rSh = pView->GetWrtShell();
      90           0 :     const Size m_aDocSz( rSh.GetDocSize() );
      91             : 
      92           0 :     const long lBorder = bBorder ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
      93           0 :     const bool bHori = pScrollbar->IsHoriScroll();
      94             : 
      95           0 :     const long lPos = pScrollbar->GetThumbPos() + (bBorder ? DOCUMENTBORDER : 0);
      96             : 
      97           0 :     long lDelta = lPos - (bHori ? rSh.VisArea().Pos().X() : rSh.VisArea().Pos().Y());
      98             : 
      99           0 :     const long lSize = (bHori ? m_aDocSz.A() : m_aDocSz.B()) + lBorder;
     100             :     // Should right or below are too much space,
     101             :     // then they must be subtracted out of the VisArea!
     102           0 :     long nTmp = pView->GetVisArea().Right()+lDelta;
     103           0 :     if ( bHori && nTmp > lSize )
     104           0 :         lDelta -= nTmp - lSize;
     105           0 :     nTmp = pView->GetVisArea().Bottom()+lDelta;
     106           0 :     if ( !bHori && nTmp > lSize )
     107           0 :         lDelta -= nTmp - lSize;
     108             : 
     109             :     // use a reference to access/moodify the correct coordinate
     110             :     // returned by accessors to non-const object
     111           0 :     long & rCoord = bHori ? rPos.X() : rPos.Y();
     112           0 :     rCoord += lDelta;
     113           0 :     if ( bBorder && rCoord < DOCUMENTBORDER )
     114           0 :         rCoord = DOCUMENTBORDER;
     115           0 : }
     116             : 
     117             : // Set zero ruler
     118             : 
     119           0 : void SwView::InvalidateRulerPos()
     120             : {
     121             :     static sal_uInt16 aInval[] =
     122             :     {
     123             :         SID_ATTR_PARA_LRSPACE, SID_RULER_BORDERS, SID_RULER_PAGE_POS,
     124             :         SID_RULER_LR_MIN_MAX, SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
     125             :         SID_RULER_BORDER_DISTANCE,
     126             :         SID_ATTR_PARA_LRSPACE_VERTICAL, SID_RULER_BORDERS_VERTICAL,
     127             :         SID_RULER_TEXT_RIGHT_TO_LEFT,
     128             :         SID_RULER_ROWS, SID_RULER_ROWS_VERTICAL, FN_STAT_PAGE,
     129             :         0
     130             :     };
     131             : 
     132           0 :     GetViewFrame()->GetBindings().Invalidate(aInval);
     133             : 
     134             :     OSL_ENSURE(m_pHRuler, "Why is the ruler not there?");
     135           0 :     m_pHRuler->ForceUpdate();
     136           0 :     m_pVRuler->ForceUpdate();
     137           0 : }
     138             : 
     139             : // Limits the scrolling so far that only a quarter of the
     140             : // screen can be scrolled up before the end of the document.
     141             : 
     142           0 : long SwView::SetHScrollMax( long lMax )
     143             : {
     144           0 :     const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
     145           0 :     const long lSize = GetDocSz().Width() + lBorder - m_aVisArea.GetWidth();
     146             : 
     147             :     // At negative values the document is completely visible.
     148             :     // In this case, no scrolling.
     149           0 :     return std::max( std::min( lMax, lSize ), 0L );
     150             : }
     151             : 
     152           0 : long SwView::SetVScrollMax( long lMax )
     153             : {
     154           0 :     const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
     155           0 :     long lSize = GetDocSz().Height() + lBorder - m_aVisArea.GetHeight();
     156           0 :     return std::max( std::min( lMax, lSize), 0L );        // see horizontal
     157             : }
     158             : 
     159           0 : Point SwView::AlignToPixel(const Point &rPt) const
     160             : {
     161           0 :     return GetEditWin().PixelToLogic( GetEditWin().LogicToPixel( rPt ) );
     162             : }
     163             : 
     164             : // Document size has changed.
     165             : 
     166           0 : void SwView::DocSzChgd(const Size &rSz)
     167             : {
     168             : 
     169             : extern int bDocSzUpdated;
     170             : 
     171           0 : m_aDocSz = rSz;
     172             : 
     173           0 :     if( !m_pWrtShell || m_aVisArea.IsEmpty() )      // no shell -> no change
     174             :     {
     175           0 :         bDocSzUpdated = sal_False;
     176           0 :         return;
     177             :     }
     178             : 
     179             :     //If text has been deleted, it may be that the VisArea points behind the visible range.
     180           0 :     Rectangle aNewVisArea( m_aVisArea );
     181           0 :     bool bModified = false;
     182           0 :     SwTwips lGreenOffset = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
     183           0 :     SwTwips lTmp = m_aDocSz.Width() + lGreenOffset;
     184             : 
     185           0 :     if ( aNewVisArea.Right() >= lTmp  )
     186             :     {
     187           0 :         lTmp = aNewVisArea.Right() - lTmp;
     188           0 :         aNewVisArea.Right() -= lTmp;
     189           0 :         aNewVisArea.Left() -= lTmp;
     190           0 :         bModified = true;
     191             :     }
     192             : 
     193           0 :     lTmp = m_aDocSz.Height() + lGreenOffset;
     194           0 :     if ( aNewVisArea.Bottom() >= lTmp )
     195             :     {
     196           0 :         lTmp = aNewVisArea.Bottom() - lTmp;
     197           0 :         aNewVisArea.Bottom() -= lTmp;
     198           0 :         aNewVisArea.Top() -= lTmp;
     199           0 :         bModified = true;
     200             :     }
     201             : 
     202           0 :     if ( bModified )
     203           0 :         SetVisArea( aNewVisArea, sal_False );
     204             : 
     205           0 :     if ( UpdateScrollbars() && !m_bInOuterResizePixel && !m_bInInnerResizePixel &&
     206           0 :             !GetViewFrame()->GetFrame().IsInPlace())
     207             :         OuterResizePixel( Point(),
     208           0 :                           GetViewFrame()->GetWindow().GetOutputSizePixel() );
     209             : }
     210             : 
     211             : // Set VisArea newly
     212             : 
     213           0 : void SwView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar )
     214             : {
     215           0 :     const Size aOldSz( m_aVisArea.GetSize() );
     216             : 
     217           0 :     const Point aTopLeft(     AlignToPixel( rRect.TopLeft() ));
     218           0 :     const Point aBottomRight( AlignToPixel( rRect.BottomRight() ));
     219           0 :     Rectangle aLR( aTopLeft, aBottomRight );
     220             : 
     221           0 :     if( aLR == m_aVisArea )
     222           0 :         return;
     223             : 
     224           0 :     const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
     225             : 
     226             :     // No negative position, no negative size
     227           0 :     if( aLR.Top() < lMin )
     228             :     {
     229           0 :         aLR.Bottom() += lMin - aLR.Top();
     230           0 :         aLR.Top() = lMin;
     231             :     }
     232           0 :     if( aLR.Left() < lMin )
     233             :     {
     234           0 :         aLR.Right() += lMin - aLR.Left();
     235           0 :         aLR.Left() = lMin;
     236             :     }
     237           0 :     if( aLR.Right() < 0 )
     238           0 :         aLR.Right() = 0;
     239           0 :     if( aLR.Bottom() < 0 )
     240           0 :         aLR.Bottom() = 0;
     241             : 
     242           0 :     if( aLR == m_aVisArea )
     243           0 :         return;
     244             : 
     245           0 :     const Size aSize( aLR.GetSize() );
     246           0 :     if( aSize.Width() < 0 || aSize.Height() < 0 )
     247           0 :         return;
     248             : 
     249             :     // Before the data can be changed, call an update if necessary. This
     250             :     // ensures that adjacent Paints in document coordinates are converted
     251             :     // correctly.
     252             :     // As a precaution, we do this only when an action is running in the
     253             :     // shell, because then it is not really drawn but the rectangles will
     254             :     // be only marked (in document coordinates).
     255           0 :     if ( m_pWrtShell && m_pWrtShell->ActionPend() )
     256           0 :         m_pWrtShell->GetWin()->Update();
     257             : 
     258           0 :     m_aVisArea = aLR;
     259             : 
     260           0 :     const sal_Bool bOuterResize = bUpdateScrollbar && UpdateScrollbars();
     261             : 
     262           0 :     if ( m_pWrtShell )
     263             :     {
     264           0 :         m_pWrtShell->VisPortChgd( m_aVisArea );
     265           0 :         if ( aOldSz != m_pWrtShell->VisArea().SSize() &&
     266           0 :              ( std::abs(aOldSz.Width() - m_pWrtShell->VisArea().Width()) > 2 ||
     267           0 :                 std::abs(aOldSz.Height() - m_pWrtShell->VisArea().Height()) > 2 ) )
     268           0 :             m_pWrtShell->CheckBrowseView( sal_False );
     269             :     }
     270             : 
     271           0 :     if ( !bProtectDocShellVisArea )
     272             :     {
     273             :         // If the size of VisArea is unchanged, we extend the size of the VisArea
     274             :         // InternalObject on. By that the transport of errors shall be avoided.
     275           0 :         Rectangle aVis( m_aVisArea );
     276           0 :         if ( aVis.GetSize() == aOldSz )
     277           0 :             aVis.SetSize( GetDocShell()->SfxObjectShell::GetVisArea(ASPECT_CONTENT).GetSize() );
     278             :                     // TODO/LATER: why casting?!
     279             :                     //GetDocShell()->SfxInPlaceObject::GetVisArea().GetSize() );
     280             : 
     281             :         // With embedded always with modify...
     282             :         // TODO/LATER: why casting?!
     283           0 :         GetDocShell()->SfxObjectShell::SetVisArea( aVis );
     284             :         /*
     285             :         if ( GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
     286             :             GetDocShell()->SfxInPlaceObject::SetVisArea( aVis );
     287             :         else
     288             :             GetDocShell()->SvEmbeddedObject::SetVisArea( aVis );*/
     289             :     }
     290             : 
     291           0 :     SfxViewShell::VisAreaChanged( m_aVisArea );
     292             : 
     293           0 :     InvalidateRulerPos();
     294             : 
     295           0 :     if ( bOuterResize && !m_bInOuterResizePixel && !m_bInInnerResizePixel)
     296             :             OuterResizePixel( Point(),
     297           0 :                 GetViewFrame()->GetWindow().GetOutputSizePixel() );
     298             : }
     299             : 
     300             : // Set Pos VisArea
     301             : 
     302           0 : void SwView::SetVisArea( const Point &rPt, sal_Bool bUpdateScrollbar )
     303             : {
     304             :     // Align once, so brushes will be inserted correctly.
     305             :     // This goes wrong in the BrowseView, because the entire document may
     306             :     // not be visible. Since the content in frames is fitting exactly,
     307             :     // align is not possible (better idea?!?!)
     308             :     // (fix: Bild.de, 200%) It does not work completly without alignment
     309             :     // Let's see how far we get with half BrushSize.
     310           0 :     Point aPt( rPt );
     311           0 :     aPt = GetEditWin().LogicToPixel( aPt );
     312             : #if HAVE_FEATURE_DESKTOP
     313           0 :     const long nTmp = GetWrtShell().IsFrameView() ? 4 : 8;
     314           0 :     aPt.X() -= aPt.X() % nTmp;
     315           0 :     aPt.Y() -= aPt.Y() % nTmp;
     316             : #endif
     317           0 :     aPt = GetEditWin().PixelToLogic( aPt );
     318             : 
     319           0 :     if ( aPt == m_aVisArea.TopLeft() )
     320           0 :         return;
     321             : 
     322           0 :     const long lXDiff = m_aVisArea.Left() - aPt.X();
     323           0 :     const long lYDiff = m_aVisArea.Top()  - aPt.Y();
     324             :     SetVisArea( Rectangle( aPt,
     325           0 :             Point( m_aVisArea.Right() - lXDiff, m_aVisArea.Bottom() - lYDiff ) ),
     326           0 :             bUpdateScrollbar);
     327             : }
     328             : 
     329           0 : void SwView::CheckVisArea()
     330             : {
     331           0 :     m_pHScrollbar->SetAuto( m_pWrtShell->GetViewOptions()->getBrowseMode() &&
     332           0 :                               !GetViewFrame()->GetFrame().IsInPlace() );
     333           0 :     if ( IsDocumentBorder() )
     334             :     {
     335           0 :         if ( m_aVisArea.Left() != DOCUMENTBORDER ||
     336           0 :              m_aVisArea.Top()  != DOCUMENTBORDER )
     337             :         {
     338           0 :             Rectangle aNewVisArea( m_aVisArea );
     339           0 :             aNewVisArea.Move( DOCUMENTBORDER - m_aVisArea.Left(),
     340           0 :                               DOCUMENTBORDER - m_aVisArea.Top() );
     341           0 :             SetVisArea( aNewVisArea, sal_True );
     342             :         }
     343             :     }
     344           0 : }
     345             : 
     346             : /// Calculate the visible range.
     347             : 
     348             : //  OUT Point *pPt:             new position of the visible area
     349             : 
     350             : //  IN  Rectangle &rRect:       Rectangle, which should be located
     351             : //                              within the new visible area.
     352             : //  sal_uInt16 nRange           optional accurate indication of the
     353             : //                              range by which to scroll if necessary.
     354             : 
     355           0 : void SwView::CalcPt( Point *pPt, const Rectangle &rRect,
     356             :                      sal_uInt16 nRangeX, sal_uInt16 nRangeY)
     357             : {
     358             : 
     359           0 :     const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
     360             : 
     361           0 :     long nYScroll = GetYScroll();
     362           0 :     long nDesHeight = rRect.GetHeight();
     363           0 :     long nCurHeight = m_aVisArea.GetHeight();
     364           0 :     nYScroll = std::min(nYScroll, nCurHeight - nDesHeight); // If it is scarce, then scroll not too much.
     365           0 :     if(nDesHeight > nCurHeight) // the height is not sufficient, then nYScroll is no longer of interest
     366             :     {
     367           0 :         pPt->Y() = rRect.Top();
     368           0 :         pPt->Y() = std::max( lMin, pPt->Y() );
     369             :     }
     370           0 :     else if ( rRect.Top() < m_aVisArea.Top() )                // Upward shift
     371             :     {
     372           0 :         pPt->Y() = rRect.Top() - (nRangeY != USHRT_MAX ? nRangeY : nYScroll);
     373           0 :         pPt->Y() = std::max( lMin, pPt->Y() );
     374             :     }
     375           0 :     else if( rRect.Bottom() > m_aVisArea.Bottom() )   // Downward shift
     376             :     {
     377           0 :         pPt->Y() = rRect.Bottom() -
     378           0 :                     (m_aVisArea.GetHeight()) + ( nRangeY != USHRT_MAX ?
     379           0 :             nRangeY : nYScroll );
     380           0 :         pPt->Y() = SetVScrollMax( pPt->Y() );
     381             :     }
     382           0 :     long nXScroll = GetXScroll();
     383           0 :     if ( rRect.Right() > m_aVisArea.Right() )         // Shift right
     384             :     {
     385           0 :         pPt->X() = rRect.Right()  -
     386           0 :                     (m_aVisArea.GetWidth()) +
     387           0 :                     (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
     388           0 :         pPt->X() = SetHScrollMax( pPt->X() );
     389             :     }
     390           0 :     else if ( rRect.Left() < m_aVisArea.Left() )      // Shift left
     391             :     {
     392           0 :         pPt->X() = rRect.Left() - (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
     393           0 :         pPt->X() = std::max( ::GetLeftMargin( *this ) + nLeftOfst, pPt->X() );
     394           0 :         pPt->X() = std::min( rRect.Left() - nScrollX, pPt->X() );
     395           0 :         pPt->X() = std::max( 0L, pPt->X() );
     396             :     }
     397           0 : }
     398             : 
     399             : // Scrolling
     400             : 
     401           0 : sal_Bool SwView::IsScroll( const Rectangle &rRect ) const
     402             : {
     403           0 :     return m_bCenterCrsr || m_bTopCrsr || !m_aVisArea.IsInside(rRect);
     404             : }
     405             : 
     406           0 : void SwView::Scroll( const Rectangle &rRect, sal_uInt16 nRangeX, sal_uInt16 nRangeY )
     407             : {
     408           0 :     if ( m_aVisArea.IsEmpty() )
     409           0 :         return;
     410             : 
     411           0 :     Rectangle aOldVisArea( m_aVisArea );
     412           0 :     long nDiffY = 0;
     413             : 
     414           0 :     Window* pCareWn = SwViewShell::GetCareWin(GetWrtShell());
     415           0 :     if ( pCareWn )
     416             :     {
     417           0 :         Rectangle aDlgRect( GetEditWin().PixelToLogic(
     418           0 :                 pCareWn->GetWindowExtentsRelative( &GetEditWin() ) ) );
     419             :         // Only if the dialogue is not the VisArea right or left:
     420           0 :         if ( aDlgRect.Left() < m_aVisArea.Right() &&
     421           0 :              aDlgRect.Right() > m_aVisArea.Left() )
     422             :         {
     423             :             // If we are not supposed to be centered, lying in the VisArea
     424             :             // and are not covered by the dialogue ...
     425           0 :             if ( !m_bCenterCrsr && aOldVisArea.IsInside( rRect )
     426           0 :                  && ( rRect.Left() > aDlgRect.Right()
     427           0 :                       || rRect.Right() < aDlgRect.Left()
     428           0 :                       || rRect.Top() > aDlgRect.Bottom()
     429           0 :                       || rRect.Bottom() < aDlgRect.Top() ) )
     430           0 :                 return;
     431             : 
     432             :             // Is above or below the dialogue more space?
     433           0 :             long nTopDiff = aDlgRect.Top() - m_aVisArea.Top();
     434           0 :             long nBottomDiff = m_aVisArea.Bottom() - aDlgRect.Bottom();
     435           0 :             if ( nTopDiff < nBottomDiff )
     436             :             {
     437           0 :                 if ( nBottomDiff > 0 ) // Is there room below at all?
     438             :                 {   // then we move the upper edge and we remember this
     439           0 :                     nDiffY = aDlgRect.Bottom() - m_aVisArea.Top();
     440           0 :                     m_aVisArea.Top() += nDiffY;
     441             :                 }
     442             :             }
     443             :             else
     444             :             {
     445           0 :                 if ( nTopDiff > 0 ) // Is there room below at all?
     446           0 :                     m_aVisArea.Bottom() = aDlgRect.Top(); // Modify the lower edge
     447             :             }
     448             :         }
     449             :     }
     450             : 
     451             :     //s.o. !IsScroll()
     452           0 :     if( !(m_bCenterCrsr || m_bTopCrsr) && m_aVisArea.IsInside( rRect ) )
     453             :     {
     454           0 :         m_aVisArea = aOldVisArea;
     455           0 :         return;
     456             :     }
     457             :     // If the rectangle is larger than the visible area -->
     458             :     // upper left corner
     459           0 :     Size aSize( rRect.GetSize() );
     460           0 :     const Size aVisSize( m_aVisArea.GetSize() );
     461           0 :     if( !m_aVisArea.IsEmpty() && (
     462           0 :         aSize.Width() + GetXScroll() > aVisSize.Width() ||
     463           0 :         aSize.Height()+ GetYScroll() > aVisSize.Height() ))
     464             :     {
     465           0 :         Point aPt( m_aVisArea.TopLeft() );
     466           0 :         aSize.Width() = std::min( aSize.Width(), aVisSize.Width() );
     467           0 :         aSize.Height()= std::min( aSize.Height(),aVisSize.Height());
     468             : 
     469             :         CalcPt( &aPt, Rectangle( rRect.TopLeft(), aSize ),
     470           0 :                 static_cast< sal_uInt16 >((aVisSize.Width() - aSize.Width()) / 2),
     471           0 :                 static_cast< sal_uInt16 >((aVisSize.Height()- aSize.Height())/ 2) );
     472             : 
     473           0 :         if( m_bTopCrsr )
     474             :         {
     475           0 :             const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
     476           0 :             aPt.Y() = std::min( std::max( nBorder, rRect.Top() ),
     477           0 :                                 m_aDocSz.Height() + nBorder -
     478           0 :                                     m_aVisArea.GetHeight() );
     479             :         }
     480           0 :         aPt.Y() -= nDiffY;
     481           0 :         m_aVisArea = aOldVisArea;
     482           0 :         SetVisArea( aPt );
     483           0 :         return;
     484             :     }
     485           0 :     if( !m_bCenterCrsr )
     486             :     {
     487           0 :         Point aPt( m_aVisArea.TopLeft() );
     488           0 :         CalcPt( &aPt, rRect, nRangeX, nRangeY );
     489             : 
     490           0 :         if( m_bTopCrsr )
     491             :         {
     492           0 :             const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
     493           0 :             aPt.Y() = std::min( std::max( nBorder, rRect.Top() ),
     494           0 :                                 m_aDocSz.Height() + nBorder -
     495           0 :                                     m_aVisArea.GetHeight() );
     496             :         }
     497             : 
     498           0 :         aPt.Y() -= nDiffY;
     499           0 :         m_aVisArea = aOldVisArea;
     500           0 :         SetVisArea( aPt );
     501           0 :         return;
     502             :     }
     503             : 
     504             :     //Center cursor
     505           0 :     Point aPnt( m_aVisArea.TopLeft() );
     506             :     // ... in Y-direction in any case
     507           0 :     aPnt.Y() += ( rRect.Top() + rRect.Bottom()
     508           0 :                   - m_aVisArea.Top() - m_aVisArea.Bottom() ) / 2 - nDiffY;
     509             :     // ... in X-direction, only if the rectangle protrudes over the right or left of the VisArea.
     510           0 :     if ( rRect.Right() > m_aVisArea.Right() || rRect.Left() < m_aVisArea.Left() )
     511             :     {
     512           0 :         aPnt.X() += ( rRect.Left() + rRect.Right()
     513           0 :                   - m_aVisArea.Left() - m_aVisArea.Right() ) / 2;
     514           0 :         aPnt.X() = SetHScrollMax( aPnt.X() );
     515           0 :         const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
     516           0 :         aPnt.X() = std::max( (GetLeftMargin( *this ) - lMin) + nLeftOfst, aPnt.X() );
     517             :     }
     518           0 :     m_aVisArea = aOldVisArea;
     519           0 :     if( pCareWn )
     520             :     {   // If we want to avoid only a dialogue, we do
     521             :         // not want to go beyond the end of the document.
     522           0 :         aPnt.Y() = SetVScrollMax( aPnt.Y() );
     523             :     }
     524           0 :     SetVisArea( aPnt );
     525             : }
     526             : 
     527             : /// Scroll page by page
     528             : //  Returns the value by which to be scrolled with PageUp / Down
     529             : 
     530           0 : sal_Bool SwView::GetPageScrollUpOffset( SwTwips &rOff ) const
     531             : {
     532           0 :     if ( !m_aVisArea.Top() || !m_aVisArea.GetHeight() )
     533           0 :         return sal_False;
     534           0 :     long nYScrl = GetYScroll() / 2;
     535           0 :     rOff = -(m_aVisArea.GetHeight() - nYScrl);
     536             :     // Do not scroll before the beginning of the document.
     537           0 :     if( m_aVisArea.Top() - rOff < 0 )
     538           0 :         rOff = rOff - m_aVisArea.Top();
     539           0 :     else if( GetWrtShell().GetCharRect().Top() < (m_aVisArea.Top() + nYScrl))
     540           0 :         rOff += nYScrl;
     541           0 :     return sal_True;
     542             : }
     543             : 
     544           0 : sal_Bool SwView::GetPageScrollDownOffset( SwTwips &rOff ) const
     545             : {
     546           0 :     if ( !m_aVisArea.GetHeight() ||
     547           0 :          (m_aVisArea.GetHeight() > m_aDocSz.Height()) )
     548           0 :         return sal_False;
     549           0 :     long nYScrl = GetYScroll() / 2;
     550           0 :     rOff = m_aVisArea.GetHeight() - nYScrl;
     551             :     // Do not scroll past the end of the document.
     552           0 :     if ( m_aVisArea.Top() + rOff > m_aDocSz.Height() )
     553           0 :         rOff = m_aDocSz.Height() - m_aVisArea.Bottom();
     554           0 :     else if( GetWrtShell().GetCharRect().Bottom() >
     555           0 :                                             ( m_aVisArea.Bottom() - nYScrl ))
     556           0 :         rOff -= nYScrl;
     557           0 :     return rOff > 0;
     558             : }
     559             : 
     560             : // Scroll page by page
     561           0 : long SwView::PageUp()
     562             : {
     563           0 :     if (!m_aVisArea.GetHeight())
     564           0 :         return 0;
     565             : 
     566           0 :     Point aPos(m_aVisArea.TopLeft());
     567           0 :     aPos.Y() -= m_aVisArea.GetHeight() - (GetYScroll() / 2);
     568           0 :     aPos.Y() = std::max(0L, aPos.Y());
     569           0 :     SetVisArea( aPos );
     570           0 :     return 1;
     571             : }
     572             : 
     573           0 : long SwView::PageDown()
     574             : {
     575           0 :     if ( !m_aVisArea.GetHeight() )
     576           0 :         return 0;
     577           0 :     Point aPos( m_aVisArea.TopLeft() );
     578           0 :     aPos.Y() += m_aVisArea.GetHeight() - (GetYScroll() / 2);
     579           0 :     aPos.Y() = SetVScrollMax( aPos.Y() );
     580           0 :     SetVisArea( aPos );
     581           0 :     return 1;
     582             : }
     583             : 
     584           0 : long SwView::PhyPageUp()
     585             : {
     586             :     // Check for the currently visible page, do not format
     587           0 :     sal_uInt16 nActPage = m_pWrtShell->GetNextPrevPageNum( sal_False );
     588             : 
     589           0 :     if( USHRT_MAX != nActPage )
     590             :     {
     591           0 :         const Point aPt( m_aVisArea.Left(),
     592           0 :                          m_pWrtShell->GetPagePos( nActPage ).Y() );
     593           0 :         Point aAlPt( AlignToPixel( aPt ) );
     594             :         // If there is a difference, has been truncated --> then add one pixel,
     595             :         // so that no residue of the previous page is visible.
     596           0 :         if( aPt.Y() != aAlPt.Y() )
     597           0 :             aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
     598           0 :         SetVisArea( aAlPt );
     599             :     }
     600           0 :     return 1;
     601             : }
     602             : 
     603           0 : long SwView::PhyPageDown()
     604             : {
     605             :     // Check for the currently visible page, do not format
     606           0 :     sal_uInt16 nActPage = m_pWrtShell->GetNextPrevPageNum( sal_True );
     607             :     // If the last page of the document is visible, do nothing.
     608           0 :     if( USHRT_MAX != nActPage )
     609             :     {
     610           0 :         const Point aPt( m_aVisArea.Left(),
     611           0 :                          m_pWrtShell->GetPagePos( nActPage ).Y() );
     612           0 :         Point aAlPt( AlignToPixel( aPt ) );
     613             :         // If there is a difference, has been truncated --> then add one pixel,
     614             :         // so that no residue of the previous page is visible.
     615           0 :         if( aPt.Y() != aAlPt.Y() )
     616           0 :             aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
     617           0 :         SetVisArea( aAlPt );
     618             :     }
     619           0 :     return 1;
     620             : }
     621             : 
     622           0 : long SwView::PageUpCrsr( sal_Bool bSelect )
     623             : {
     624           0 :     if ( !bSelect )
     625             :     {
     626           0 :         const sal_uInt16 eType = m_pWrtShell->GetFrmType(0,sal_True);
     627           0 :         if ( eType & FRMTYPE_FOOTNOTE )
     628             :         {
     629           0 :             m_pWrtShell->MoveCrsr();
     630           0 :             m_pWrtShell->GotoFtnAnchor();
     631           0 :             m_pWrtShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
     632           0 :             return 1;
     633             :         }
     634             :     }
     635             : 
     636           0 :     SwTwips lOff = 0;
     637           0 :     if ( GetPageScrollUpOffset( lOff ) &&
     638           0 :          (m_pWrtShell->IsCrsrReadonly() ||
     639           0 :           !m_pWrtShell->PageCrsr( lOff, bSelect )) &&
     640           0 :          PageUp() )
     641             :     {
     642           0 :         m_pWrtShell->ResetCursorStack();
     643           0 :         return sal_True;
     644             :     }
     645           0 :     return sal_False;
     646             : }
     647             : 
     648           0 : long SwView::PageDownCrsr(sal_Bool bSelect)
     649             : {
     650           0 :     SwTwips lOff = 0;
     651           0 :     if ( GetPageScrollDownOffset( lOff ) &&
     652           0 :          (m_pWrtShell->IsCrsrReadonly() ||
     653           0 :           !m_pWrtShell->PageCrsr( lOff, bSelect )) &&
     654           0 :          PageDown() )
     655             :     {
     656           0 :         m_pWrtShell->ResetCursorStack();
     657           0 :         return sal_True;
     658             :     }
     659           0 :     return sal_False;
     660             : }
     661             : 
     662             : // Handler of the scrollbars
     663             : 
     664           0 : IMPL_LINK( SwView, ScrollHdl, SwScrollbar *, pScrollbar )
     665             : {
     666           0 :     if ( GetWrtShell().ActionPend() )
     667           0 :         return 0;
     668             : 
     669           0 :     if ( pScrollbar->GetType() == SCROLL_DRAG )
     670           0 :         m_pWrtShell->EnableSmooth( sal_False );
     671             : 
     672           0 :     if(!m_pWrtShell->GetViewOptions()->getBrowseMode() &&
     673           0 :         pScrollbar->GetType() == SCROLL_DRAG)
     674             :     {
     675             :         // Here comment out again if it is not desired to scroll together:
     676             :         // The end scrollhandler invalidate the FN_STAT_PAGE,
     677             :         // so we don't must do it again.
     678           0 :         EndScrollHdl(pScrollbar);
     679             : 
     680           0 :         if ( !m_bWheelScrollInProgress && Help::IsQuickHelpEnabled() &&
     681           0 :              m_pWrtShell->GetViewOptions()->IsShowScrollBarTips())
     682             :         {
     683             : 
     684           0 :             Point aPos( m_aVisArea.TopLeft() );
     685           0 :             lcl_GetPos(this, aPos, pScrollbar, IsDocumentBorder());
     686             : 
     687           0 :             sal_uInt16 nPhNum = 1;
     688           0 :             sal_uInt16 nVirtNum = 1;
     689             : 
     690           0 :             OUString sDisplay;
     691           0 :             if(m_pWrtShell->GetPageNumber( aPos.Y(), sal_False, nPhNum, nVirtNum, sDisplay ))
     692             :             {
     693             :                 // The end scrollhandler invalidate the FN_STAT_PAGE,
     694             :                 // so we don't must do it again.
     695             :         //      if(!GetViewFrame()->GetFrame().IsInPlace())
     696             :         //            S F X_BINDINGS().Update(FN_STAT_PAGE);
     697             : 
     698             :                 //QuickHelp:
     699           0 :                 if( m_pWrtShell->GetPageCnt() > 1 )
     700             :                 {
     701           0 :                     Rectangle aRect;
     702           0 :                     aRect.Left() = pScrollbar->GetParent()->OutputToScreenPixel(
     703           0 :                                         pScrollbar->GetPosPixel() ).X() -8;
     704           0 :                     aRect.Top() = pScrollbar->OutputToScreenPixel(
     705           0 :                                     pScrollbar->GetPointerPosPixel() ).Y();
     706           0 :                     aRect.Right()   = aRect.Left();
     707           0 :                     aRect.Bottom()  = aRect.Top();
     708             : 
     709           0 :                     OUString sPageStr( GetPageStr( nPhNum, nVirtNum, sDisplay ));
     710           0 :                     SwContentAtPos aCnt( SwContentAtPos::SW_OUTLINE );
     711           0 :                     m_pWrtShell->GetContentAtPos( aPos, aCnt );
     712           0 :                     if( !aCnt.sStr.isEmpty() )
     713             :                     {
     714           0 :                         sPageStr += "  - ";
     715           0 :                         sal_Int32 nChunkLen = std::min<sal_Int32>(aCnt.sStr.getLength(), 80);
     716           0 :                         OUString sChunk = aCnt.sStr.copy(0, nChunkLen);
     717           0 :                         sPageStr = sChunk + sPageStr;
     718           0 :                         sPageStr = sPageStr.replace('\t', ' ');
     719           0 :                         sPageStr = sPageStr.replace(0x0a, ' ');
     720             :                     }
     721           0 :                     nPgNum = nPhNum;
     722             :                 }
     723           0 :             }
     724             :         }
     725             :     }
     726             :     else
     727           0 :         EndScrollHdl(pScrollbar);
     728             : 
     729           0 :     if ( pScrollbar->GetType() == SCROLL_DRAG )
     730           0 :         m_pWrtShell->EnableSmooth( sal_True );
     731             : 
     732           0 :     return 0;
     733             : }
     734             : 
     735             : // Handler of the scrollbars
     736             : 
     737           0 : IMPL_LINK( SwView, EndScrollHdl, SwScrollbar *, pScrollbar )
     738             : {
     739           0 :     if ( !GetWrtShell().ActionPend() )
     740             :     {
     741           0 :         if(nPgNum)
     742             :         {
     743           0 :             nPgNum = 0;
     744           0 :             Help::ShowQuickHelp(pScrollbar, Rectangle(), OUString(), 0);
     745             :         }
     746           0 :         Point aPos( m_aVisArea.TopLeft() );
     747           0 :         bool bBorder = IsDocumentBorder();
     748           0 :         lcl_GetPos(this, aPos, pScrollbar, bBorder);
     749           0 :         if ( bBorder && aPos == m_aVisArea.TopLeft() )
     750           0 :             UpdateScrollbars();
     751             :         else
     752           0 :             SetVisArea( aPos, sal_False );
     753             : 
     754           0 :         GetViewFrame()->GetBindings().Update(FN_STAT_PAGE);
     755             :     }
     756           0 :     return 0;
     757             : }
     758             : 
     759             : // Calculates the size of the m_aVisArea in dependency of the size of
     760             : // EditWin on the screen.
     761             : 
     762           0 : void SwView::CalcVisArea( const Size &rOutPixel )
     763             : {
     764           0 :     Point aTopLeft;
     765           0 :     Rectangle aRect( aTopLeft, rOutPixel );
     766           0 :     aTopLeft = GetEditWin().PixelToLogic( aTopLeft );
     767           0 :     Point aBottomRight( GetEditWin().PixelToLogic( aRect.BottomRight() ) );
     768             : 
     769           0 :     aRect.Left() = aTopLeft.X();
     770           0 :     aRect.Top() = aTopLeft.Y();
     771           0 :     aRect.Right() = aBottomRight.X();
     772           0 :     aRect.Bottom() = aBottomRight.Y();
     773             : 
     774             :     // The shifts to the right and/or below can now be incorrect
     775             :     // (e.g. change zoom level, change view size).
     776           0 :     const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
     777           0 :     if ( aRect.Left() )
     778             :     {
     779           0 :         const long lWidth = GetWrtShell().GetDocSize().Width() + lBorder;
     780           0 :         if ( aRect.Right() > lWidth )
     781             :         {
     782           0 :             long lDelta    = aRect.Right() - lWidth;
     783           0 :             aRect.Left()  -= lDelta;
     784           0 :             aRect.Right() -= lDelta;
     785             :         }
     786             :     }
     787           0 :     if ( aRect.Top() )
     788             :     {
     789           0 :         const long lHeight = GetWrtShell().GetDocSize().Height() + lBorder;
     790           0 :         if ( aRect.Bottom() > lHeight )
     791             :         {
     792           0 :             long lDelta     = aRect.Bottom() - lHeight;
     793           0 :             aRect.Top()    -= lDelta;
     794           0 :             aRect.Bottom() -= lDelta;
     795             :         }
     796             :     }
     797           0 :     SetVisArea( aRect );
     798           0 :     GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
     799           0 :     GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER ); // for snapping points
     800           0 : }
     801             : 
     802             : // Rearrange control elements
     803             : 
     804           0 : void SwView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*/ )
     805             : {
     806           0 :     sal_Bool bRightVRuler = m_pWrtShell->GetViewOptions()->IsVRulerRight();
     807           0 :     if ( m_pVRuler->IsVisible() )
     808             :     {
     809           0 :         long nWidth = m_pVRuler->GetSizePixel().Width();
     810           0 :         if(bRightVRuler)
     811           0 :             rToFill.Right() = nWidth;
     812             :         else
     813           0 :             rToFill.Left() = nWidth;
     814             :     }
     815             : 
     816             :     OSL_ENSURE(m_pHRuler, "Why is the ruler not present?");
     817           0 :     if ( m_pHRuler->IsVisible() )
     818           0 :         rToFill.Top() = m_pHRuler->GetSizePixel().Height();
     819             : 
     820           0 :     const StyleSettings &rSet = GetEditWin().GetSettings().GetStyleSettings();
     821           0 :     const long nTmp = rSet.GetScrollBarSize();
     822           0 :     if( m_pVScrollbar->IsVisible(sal_True) )
     823             :     {
     824           0 :         if(bRightVRuler)
     825           0 :             rToFill.Left() = nTmp;
     826             :         else
     827           0 :             rToFill.Right()  = nTmp;
     828             :     }
     829           0 :     if ( m_pHScrollbar->IsVisible(sal_True) )
     830           0 :         rToFill.Bottom() = nTmp;
     831             : 
     832           0 :     SetBorderPixel( rToFill );
     833           0 : }
     834             : 
     835           0 : void ViewResizePixel( const Window &rRef,
     836             :                     const Point &rOfst,
     837             :                     const Size &rSize,
     838             :                     const Size &rEditSz,
     839             :                     SwScrollbar& rVScrollbar,
     840             :                     SwScrollbar& rHScrollbar,
     841             :                     Window& rScrollBarBox,
     842             :                     SvxRuler* pVRuler,
     843             :                     SvxRuler* pHRuler,
     844             :                     sal_Bool bVRulerRight )
     845             : {
     846             : // ViewResizePixel is also used by Preview!!!
     847             : 
     848           0 :     const sal_Bool bHRuler = pHRuler && pHRuler->IsVisible();
     849             :     const long nHLinSzHeight = bHRuler ?
     850           0 :                         pHRuler->GetSizePixel().Height() : 0;
     851           0 :     const sal_Bool bVRuler = pVRuler && pVRuler->IsVisible();
     852             :     const long nVLinSzWidth = bVRuler ?
     853           0 :                         pVRuler->GetSizePixel().Width() : 0;
     854             : 
     855           0 :     long nScrollBarSize = rRef.GetSettings().GetStyleSettings().GetScrollBarSize();
     856           0 :     long nHBSzHeight = rHScrollbar.IsVisible(true) ? nScrollBarSize : 0;
     857           0 :     long nVBSzWidth = rVScrollbar.IsVisible(true) ? nScrollBarSize : 0;
     858             : 
     859           0 :     if(pVRuler)
     860             :     {
     861           0 :         WinBits nStyle = pVRuler->GetStyle()&~WB_RIGHT_ALIGNED;
     862           0 :         Point aPos( rOfst.X(), rOfst.Y()+nHLinSzHeight );
     863           0 :         if(bVRulerRight)
     864             :         {
     865           0 :             aPos.X() += rSize.Width() - nVLinSzWidth;
     866           0 :             nStyle |= WB_RIGHT_ALIGNED;
     867             :         }
     868           0 :         Size  aSize( nVLinSzWidth, rEditSz.Height() );
     869           0 :         if(!aSize.Width())
     870           0 :             aSize.Width() = pVRuler->GetSizePixel().Width();
     871           0 :         pVRuler->SetStyle(nStyle);
     872           0 :         pVRuler->SetPosSizePixel( aPos, aSize );
     873           0 :         if(!pVRuler->IsVisible())
     874           0 :             pVRuler->Resize();
     875             :     }
     876             :     // Ruler needs a resize, otherwise it will not work in the invisible condition
     877           0 :     if(pHRuler)
     878             :     {
     879           0 :         Size aSize( rSize.Width(), nHLinSzHeight );
     880           0 :         if ( nVBSzWidth && !bVRulerRight)
     881           0 :             aSize.Width() -= nVBSzWidth;
     882           0 :         if(!aSize.Height())
     883           0 :             aSize.Height() = pHRuler->GetSizePixel().Height();
     884           0 :         pHRuler->SetPosSizePixel( rOfst, aSize );
     885             :         // VCL calls no resize on invisible windows
     886             :         // but that is not a good idea for the ruler
     887           0 :         if(!pHRuler->IsVisible())
     888           0 :             pHRuler->Resize();
     889             :     }
     890             : 
     891             :     // Arrange scrollbars and SizeBox
     892           0 :     Point aScrollFillPos;
     893             :     {
     894             :         Point aPos( rOfst.X(),
     895           0 :                     rOfst.Y()+rSize.Height()-nHBSzHeight );
     896           0 :         if(bVRulerRight)
     897             :         {
     898           0 :             aPos.X() += nVBSzWidth;
     899             :         }
     900             : 
     901           0 :         Size  aSize( rSize.Width(), nHBSzHeight );
     902           0 :         if ( nVBSzWidth )
     903           0 :             aSize.Width() -= nVBSzWidth;
     904           0 :         rHScrollbar.SetPosSizePixel( aPos, aSize );
     905           0 :         aScrollFillPos.Y() = aPos.Y();
     906             :     }
     907             :     {
     908           0 :         Point aPos( rOfst.X()+rSize.Width()-nVBSzWidth,
     909           0 :                     rOfst.Y() );
     910           0 :         Size  aSize( nVBSzWidth, rSize.Height() );
     911           0 :         if(bVRulerRight)
     912             :         {
     913           0 :             aPos.X() = rOfst.X();
     914           0 :             if(bHRuler)
     915             :             {
     916           0 :                 aPos.Y() += nHLinSzHeight;
     917           0 :                 aSize.Height() -= nHLinSzHeight;
     918             :             }
     919             :         }
     920             : 
     921           0 :         if ( nHBSzHeight )
     922           0 :             aSize.Height() -= nHBSzHeight;
     923           0 :         rVScrollbar.SetPosSizePixel( aPos, aSize );
     924             : 
     925           0 :         aPos.Y() += aSize.Height();
     926             : 
     927           0 :         aScrollFillPos.X() = aPos.X();
     928             :     }
     929             : 
     930           0 :     rScrollBarBox.SetPosSizePixel( aScrollFillPos, Size( nHBSzHeight, nVBSzWidth) );
     931           0 : }
     932             : 
     933           0 : void SwView::ShowAtResize()
     934             : {
     935           0 :     m_bShowAtResize = sal_False;
     936           0 :     if ( m_pWrtShell->GetViewOptions()->IsViewHRuler() )
     937           0 :         m_pHRuler->Show();
     938           0 : }
     939             : 
     940           0 : void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize )
     941             : {
     942           0 :     Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
     943           0 :     if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
     944             :     {
     945           0 :         SvBorder aBorder( GetBorderPixel() );
     946           0 :         Size aSize( rSize );
     947           0 :         aSize.Width() -= (aBorder.Left() + aBorder.Right());
     948           0 :         aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
     949           0 :         Size aObjSizePixel = GetWindow()->LogicToPixel( aObjSize, MAP_TWIP );
     950           0 :         SfxViewShell::SetZoomFactor( Fraction( aSize.Width(), aObjSizePixel.Width() ),
     951           0 :                         Fraction( aSize.Height(), aObjSizePixel.Height() ) );
     952             :     }
     953             : 
     954           0 :     m_bInInnerResizePixel = sal_True;
     955           0 :     const sal_Bool bHScrollVisible = m_pHScrollbar->IsVisible(sal_True);
     956           0 :     const sal_Bool bVScrollVisible = m_pVScrollbar->IsVisible(sal_True);
     957           0 :     sal_Bool bRepeat = sal_False;
     958           0 :     do
     959             :     {
     960           0 :         Size aSz( rSize );
     961           0 :         SvBorder aBorder;
     962           0 :         CalcAndSetBorderPixel( aBorder, sal_True );
     963           0 :         if ( GetViewFrame()->GetFrame().IsInPlace() )
     964             :         {
     965           0 :             Size aViewSize( aSz );
     966           0 :             Point aViewPos( rOfst );
     967           0 :             aViewSize.Height() -= (aBorder.Top() + aBorder.Bottom());
     968           0 :             aViewSize.Width()  -= (aBorder.Left() + aBorder.Right());
     969           0 :             aViewPos.X() += aBorder.Left();
     970           0 :             aViewPos.Y() += aBorder.Top();
     971           0 :             GetEditWin().SetPosSizePixel( aViewPos, aViewSize );
     972             :         }
     973             :         else
     974             :         {
     975           0 :             aSz.Height() += aBorder.Top()  + aBorder.Bottom();
     976           0 :             aSz.Width()  += aBorder.Left() + aBorder.Right();
     977             :         }
     978             : 
     979           0 :         Size aEditSz( GetEditWin().GetOutputSizePixel() );
     980           0 :         ViewResizePixel( GetEditWin(), rOfst, aSz, aEditSz, *m_pVScrollbar,
     981             :                             *m_pHScrollbar, *m_pScrollFill, m_pVRuler, m_pHRuler,
     982           0 :                             m_pWrtShell->GetViewOptions()->IsVRulerRight());
     983           0 :         if ( m_bShowAtResize )
     984           0 :             ShowAtResize();
     985             : 
     986           0 :         if( m_pHRuler->IsVisible() || m_pVRuler->IsVisible() )
     987             :         {
     988           0 :             const Fraction& rFrac = GetEditWin().GetMapMode().GetScaleX();
     989           0 :             sal_uInt16 nZoom = 100;
     990           0 :             if (0 != rFrac.GetDenominator())
     991           0 :                 nZoom = sal_uInt16(rFrac.GetNumerator() * 100L / rFrac.GetDenominator());
     992             : 
     993           0 :             const Fraction aFrac( nZoom, 100 );
     994           0 :             m_pVRuler->SetZoom( aFrac );
     995           0 :             m_pHRuler->SetZoom( aFrac );
     996           0 :             InvalidateRulerPos();   // Invalidate content.
     997             :         }
     998             :         // Reset the cursor stack because the cursor positions for PageUp/Down
     999             :         // no longer fit the currently visible area.
    1000           0 :         m_pWrtShell->ResetCursorStack();
    1001             : 
    1002             :         // EditWin never set!
    1003             : 
    1004             :         // Set VisArea, but do not call the SetVisArea of the Docshell there!
    1005           0 :         bProtectDocShellVisArea = true;
    1006           0 :         CalcVisArea( aEditSz );
    1007             :         // Visibility changes of the automatic horizontal scrollbar
    1008             :         // require to repeat the ViewResizePixel() call - but only once!
    1009           0 :         if(bRepeat)
    1010           0 :             bRepeat = sal_False;
    1011           0 :         else if(bHScrollVisible != m_pHScrollbar->IsVisible(sal_True) ||
    1012           0 :                 bVScrollVisible != m_pVScrollbar->IsVisible(sal_True))
    1013           0 :             bRepeat = sal_True;
    1014             :     }while( bRepeat );
    1015           0 :     bProtectDocShellVisArea = false;
    1016           0 :     m_bInInnerResizePixel = sal_False;
    1017           0 : }
    1018             : 
    1019           0 : void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
    1020             : {
    1021             :     // #i16909# return, if no size (caused by minimize window).
    1022           0 :     if ( m_bInOuterResizePixel || ( !rSize.Width() && !rSize.Height() ) )
    1023           0 :         return;
    1024           0 :     m_bInOuterResizePixel = sal_True;
    1025             : 
    1026             :     // Determine whether scroll bars may be displayed.
    1027           0 :     sal_Bool bShowH = sal_True,
    1028           0 :          bShowV = sal_True,
    1029           0 :          bAuto  = sal_True,
    1030           0 :          bHAuto = sal_True;
    1031             : 
    1032           0 :     const SwViewOption *pVOpt = m_pWrtShell->GetViewOptions();
    1033           0 :     if ( !pVOpt->IsReadonly() || pVOpt->IsStarOneSetting() )
    1034             :     {
    1035           0 :         bShowH = pVOpt->IsViewHScrollBar();
    1036           0 :         bShowV = pVOpt->IsViewVScrollBar();
    1037             :     }
    1038             : 
    1039           0 :     if (!m_bHScrollbarEnabled)
    1040             :     {
    1041           0 :         bHAuto = bShowH = false;
    1042             :     }
    1043           0 :     if (!m_bVScrollbarEnabled)
    1044             :     {
    1045           0 :         bAuto = bShowV = false;
    1046             :     }
    1047             : 
    1048           0 :     SwDocShell* pDocSh = GetDocShell();
    1049           0 :     sal_Bool bIsPreview = pDocSh->IsPreview();
    1050           0 :     if( bIsPreview )
    1051             :     {
    1052           0 :         bShowH = bShowV = bHAuto = bAuto = sal_False;
    1053             :     }
    1054           0 :     if(m_pHScrollbar->IsVisible(sal_False) != bShowH && !bHAuto)
    1055           0 :         ShowHScrollbar(bShowH);
    1056           0 :     m_pHScrollbar->SetAuto( bHAuto );
    1057           0 :     if(m_pVScrollbar->IsVisible(sal_False) != bShowV && !bAuto)
    1058           0 :         ShowVScrollbar(bShowV);
    1059           0 :     m_pVScrollbar->SetAuto(bAuto);
    1060             : 
    1061           0 :     SET_CURR_SHELL( m_pWrtShell );
    1062           0 :     sal_Bool bRepeat = sal_False;
    1063           0 :     long nCnt = 0;
    1064             : 
    1065           0 :     sal_Bool bUnLockView = !m_pWrtShell->IsViewLocked();
    1066           0 :     m_pWrtShell->LockView( sal_True );
    1067           0 :     m_pWrtShell->LockPaint();
    1068             : 
    1069           0 :     do {
    1070           0 :         ++nCnt;
    1071           0 :         const sal_Bool bScroll1 = m_pVScrollbar->IsVisible(sal_True);
    1072           0 :         const sal_Bool bScroll2 = m_pHScrollbar->IsVisible(sal_True);
    1073           0 :         SvBorder aBorder;
    1074           0 :         CalcAndSetBorderPixel( aBorder, sal_False );
    1075           0 :         const Size aEditSz( GetEditWin().GetOutputSizePixel() );
    1076           0 :         ViewResizePixel( GetEditWin(), rOfst, rSize, aEditSz, *m_pVScrollbar,
    1077             :                                 *m_pHScrollbar, *m_pScrollFill, m_pVRuler, m_pHRuler,
    1078           0 :                                 m_pWrtShell->GetViewOptions()->IsVRulerRight() );
    1079           0 :         if ( m_bShowAtResize )
    1080           0 :             ShowAtResize();
    1081             : 
    1082           0 :         if( m_pHRuler->IsVisible() || m_pVRuler->IsVisible() )
    1083           0 :             InvalidateRulerPos();   // Invalidate content.
    1084             : 
    1085             :         // Reset the cursor stack because the cursor positions for PageUp/Down
    1086             :         // no longer fit the currently visible area.
    1087           0 :         m_pWrtShell->ResetCursorStack();
    1088             : 
    1089             :         OSL_ENSURE( !GetEditWin().IsVisible() ||
    1090             :                     (( aEditSz.Width() > 0 && aEditSz.Height() > 0 )
    1091             :                         || !m_aVisArea.IsEmpty()), "Small world, isn't it?" );
    1092             : 
    1093             :         // Never set EditWin!
    1094             : 
    1095             :         // Of course the VisArea must also be set.
    1096             :         // Now is the right time to re-calculate the zoom if it is not a simple factor.
    1097           0 :         m_pWrtShell->StartAction();
    1098           0 :         CalcVisArea( aEditSz );
    1099             : 
    1100             :         //Thus also in the outplace editing the page width will be adjusted immediately.
    1101             :         //TODO/LATER: is that still necessary?!
    1102             :         /*
    1103             :         if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
    1104             :             pDocSh->SetVisArea(
    1105             :                             pDocSh->SfxInPlaceObject::GetVisArea() );*/
    1106           0 :         if ( m_pWrtShell->GetViewOptions()->GetZoomType() != SVX_ZOOM_PERCENT &&
    1107           0 :              !m_pWrtShell->GetViewOptions()->getBrowseMode() )
    1108           0 :             _SetZoom( aEditSz, (SvxZoomType)m_pWrtShell->GetViewOptions()->GetZoomType(), 100, sal_True );
    1109           0 :         m_pWrtShell->EndAction();
    1110             : 
    1111           0 :         bRepeat = bScroll1 != m_pVScrollbar->IsVisible(sal_True);
    1112           0 :         if ( !bRepeat )
    1113           0 :             bRepeat = bScroll2 != m_pHScrollbar->IsVisible(sal_True);
    1114             : 
    1115             :         // Do no infinite loops.
    1116             :         // If possible stop when the (auto-) scroll bars are visible.
    1117           0 :         if ( bRepeat &&
    1118           0 :              ( nCnt > 10 || ( nCnt > 3 && bHAuto && bAuto ) )
    1119             :            )
    1120             :         {
    1121           0 :             bRepeat = sal_False;
    1122             :         }
    1123             : 
    1124             :     } while ( bRepeat );
    1125             : 
    1126           0 :     m_pWrtShell->UnlockPaint();
    1127           0 :     if( bUnLockView )
    1128           0 :         m_pWrtShell->LockView( sal_False );
    1129             : 
    1130           0 :     m_bInOuterResizePixel = sal_False;
    1131             : 
    1132           0 :     if ( m_pPostItMgr )
    1133             :     {
    1134           0 :         m_pPostItMgr->CalcRects();
    1135           0 :         m_pPostItMgr->LayoutPostIts();
    1136           0 :     }
    1137             : }
    1138             : 
    1139           0 : void SwView::SetZoomFactor( const Fraction &rX, const Fraction &rY )
    1140             : {
    1141           0 :     const Fraction &rFrac = rX < rY ? rX : rY;
    1142           0 :     SetZoom( SVX_ZOOM_PERCENT, (short) long(rFrac * Fraction( 100, 1 )) );
    1143             : 
    1144             :     // To minimize rounding errors we also adjust the odd values
    1145             :     // of the base class if necessary.
    1146           0 :     SfxViewShell::SetZoomFactor( rX, rY );
    1147           0 : }
    1148             : 
    1149           0 : sal_Bool SwView::UpdateScrollbars()
    1150             : {
    1151           0 :     sal_Bool bRet = sal_False;
    1152           0 :     if ( !m_aVisArea.IsEmpty() )
    1153             :     {
    1154           0 :         const bool bBorder = IsDocumentBorder();
    1155           0 :         Rectangle aTmpRect( m_aVisArea );
    1156           0 :         if ( bBorder )
    1157             :         {
    1158           0 :             Point aPt( DOCUMENTBORDER, DOCUMENTBORDER );
    1159           0 :             aPt = AlignToPixel( aPt );
    1160           0 :             aTmpRect.Move( -aPt.X(), -aPt.Y() );
    1161             :         }
    1162             : 
    1163           0 :         Size aTmpSz( m_aDocSz );
    1164           0 :         const long lOfst = bBorder ? 0 : DOCUMENTBORDER * 2L;
    1165           0 :         aTmpSz.Width() += lOfst; aTmpSz.Height() += lOfst;
    1166             : 
    1167             :         {
    1168           0 :             const sal_Bool bVScrollVisible = m_pVScrollbar->IsVisible(sal_True);
    1169           0 :             m_pVScrollbar->DocSzChgd( aTmpSz );
    1170           0 :             m_pVScrollbar->ViewPortChgd( aTmpRect );
    1171           0 :             if ( bVScrollVisible != m_pVScrollbar->IsVisible(sal_True) )
    1172           0 :                 bRet = sal_True;
    1173             :         }
    1174             :         {
    1175           0 :             const sal_Bool bHScrollVisible = m_pHScrollbar->IsVisible(sal_True);
    1176           0 :             m_pHScrollbar->DocSzChgd( aTmpSz );
    1177           0 :             m_pHScrollbar->ViewPortChgd( aTmpRect );
    1178           0 :             if ( bHScrollVisible != m_pHScrollbar->IsVisible(sal_True) )
    1179           0 :                 bRet = sal_True;
    1180           0 :             m_pScrollFill->Show(m_pHScrollbar->IsVisible(sal_True) && m_pVScrollbar->IsVisible(sal_True) );
    1181             :         }
    1182             :     }
    1183           0 :     return bRet;
    1184             : }
    1185             : 
    1186           0 : void SwView::Move()
    1187             : {
    1188           0 :     if ( GetWrtShell().IsInSelect() )
    1189           0 :         GetWrtShell().EndSelect();
    1190           0 :     SfxViewShell::Move();
    1191           0 : }
    1192             : 
    1193           0 : sal_Bool SwView::HandleWheelCommands( const CommandEvent& rCEvt )
    1194             : {
    1195           0 :     sal_Bool bOk = sal_False;
    1196           0 :     const CommandWheelData* pWData = rCEvt.GetWheelData();
    1197           0 :     if (pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode())
    1198             :     {
    1199           0 :         long nFact = m_pWrtShell->GetViewOptions()->GetZoom();
    1200           0 :         if( 0L > pWData->GetDelta() )
    1201           0 :             nFact = std::max( (long) 20, basegfx::zoomtools::zoomOut( nFact ));
    1202             :         else
    1203           0 :             nFact = std::min( (long) 600, basegfx::zoomtools::zoomIn( nFact ));
    1204             : 
    1205           0 :         SetZoom( SVX_ZOOM_PERCENT, nFact );
    1206           0 :         bOk = sal_True;
    1207             :     }
    1208           0 :     else if (pWData && COMMAND_WHEEL_ZOOM_SCALE == pWData->GetMode())
    1209             :     {
    1210             :         // mobile touch zoom (pinch) section
    1211             :         // remember the center location to reach in logic
    1212             : 
    1213           0 :         Size winSize = GetViewFrame()->GetWindow().GetOutputSizePixel();
    1214           0 :         Point centerInPixels(winSize.getWidth() / 2, winSize.getHeight() / 2);
    1215           0 :         const Point & preZoomTargetCenterInLogic = GetEditWin().PixelToLogic(centerInPixels);
    1216             : 
    1217           0 :         double scale = double(pWData->GetDelta()) / double(MOBILE_ZOOM_SCALE_MULTIPLIER);
    1218             : 
    1219           0 :         int preZoomByVCL = m_pWrtShell->GetViewOptions()->GetZoom();
    1220             : 
    1221             :         // each zooming event is scaling the initial zoom
    1222           0 :         int zoomTarget = int(preZoomByVCL * scale);
    1223             : 
    1224             :         // thresholding the zoom
    1225           0 :         zoomTarget = std::max( MOBILE_MAX_ZOOM_OUT, std::min( MOBILE_MAX_ZOOM_IN, zoomTarget ) );
    1226             : 
    1227             :         // no point zooming if the target zoom is the same as the current zoom
    1228           0 :         if(zoomTarget!=preZoomByVCL)
    1229             :         {
    1230             : 
    1231           0 :             SetZoom( SVX_ZOOM_PERCENT, zoomTarget );
    1232             :         }
    1233             :         // we move to the center, and add additional tilt from center
    1234           0 :         const Point & postZoomTargetCenterInPixels = GetEditWin().LogicToPixel(preZoomTargetCenterInLogic);
    1235           0 :         long deltaX = rCEvt.GetMousePosPixel().X() + centerInPixels.X() - postZoomTargetCenterInPixels.X();
    1236           0 :         long deltaY = rCEvt.GetMousePosPixel().Y() + centerInPixels.Y() - postZoomTargetCenterInPixels.Y();
    1237             : 
    1238           0 :         if((deltaX!=0) || (deltaY!=0))
    1239             :         {
    1240             : 
    1241             :             // scrolling the deltaX deltaY
    1242           0 :             Point deltaPoint( deltaX, deltaY );
    1243           0 :             CommandWheelData cmd( 0, 0, 0, COMMAND_WHEEL_SCROLL, 0, false, true);
    1244           0 :             CommandEvent event(deltaPoint , COMMAND_WHEEL, true, &cmd );
    1245           0 :             m_pEditWin->HandleScrollCommand(event, m_pHScrollbar, m_pVScrollbar);
    1246             :         }
    1247             : 
    1248           0 :         bOk = sal_True;
    1249             :     }
    1250             :     else
    1251             :     {
    1252           0 :         if (pWData && pWData->GetMode()==COMMAND_WHEEL_SCROLL)
    1253             :         {
    1254             :             // This influences whether quick help is shown
    1255           0 :             m_bWheelScrollInProgress=true;
    1256             :         }
    1257             : 
    1258           0 :         if (pWData && (COMMAND_WHEEL_SCROLL==pWData->GetMode()) &&
    1259           0 :                 (COMMAND_WHEEL_PAGESCROLL == pWData->GetScrollLines()))
    1260             :         {
    1261           0 :             if (pWData->GetDelta()<0)
    1262           0 :                 PhyPageDown();
    1263             :             else
    1264           0 :                 PhyPageUp();
    1265           0 :             bOk = sal_True;
    1266             :         }
    1267             :         else
    1268           0 :             bOk = m_pEditWin->HandleScrollCommand(rCEvt, m_pHScrollbar, m_pVScrollbar);
    1269             : 
    1270             :         // Restore default state for case when scroll command comes from dragging scrollbar handle
    1271           0 :         m_bWheelScrollInProgress=false;
    1272             :     }
    1273           0 :     return bOk;
    1274             : }
    1275             : 
    1276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10