LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - preview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 360 868 41.5 %
Date: 2013-07-09 Functions: 30 39 76.9 %
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 "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : 
      23             : 
      24             : #include <svtools/colorcfg.hxx>
      25             : #include <svx/fmview.hxx>
      26             : #include <editeng/sizeitem.hxx>
      27             : #include <svx/svdpagv.hxx>
      28             : #include <sfx2/bindings.hxx>
      29             : #include <sfx2/viewfrm.hxx>
      30             : #include <sfx2/dispatch.hxx>
      31             : #include <svtools/accessibilityoptions.hxx>
      32             : #include <svl/itemset.hxx>
      33             : #include <tools/multisel.hxx>
      34             : #include <vcl/waitobj.hxx>
      35             : 
      36             : #include "preview.hxx"
      37             : #include "prevwsh.hxx"
      38             : #include "prevloc.hxx"
      39             : #include "docsh.hxx"
      40             : #include "docfunc.hxx"
      41             : #include "printfun.hxx"
      42             : #include "printopt.hxx"
      43             : #include "stlpool.hxx"
      44             : #include "undostyl.hxx"
      45             : #include "drwlayer.hxx"
      46             : #include "scmod.hxx"
      47             : #include "markdata.hxx"
      48             : #include "globstr.hrc"
      49             : #include "sc.hrc"           // for ShellInvalidate
      50             : #include "AccessibleDocumentPagePreview.hxx"
      51             : #include <vcl/lineinfo.hxx>
      52             : #include <svx/algitem.hxx>
      53             : #include <editeng/lrspitem.hxx>
      54             : #include <editeng/ulspitem.hxx>
      55             : #include "attrib.hxx"
      56             : #include "pagepar.hxx"
      57             : #include <com/sun/star/accessibility/XAccessible.hpp>
      58             : #include "AccessibilityHints.hxx"
      59             : #include <vcl/svapp.hxx>
      60             : #include "viewutil.hxx"
      61             : 
      62             : // STATIC DATA -----------------------------------------------------------
      63             : 
      64             : //==================================================================
      65             : 
      66             : #define SC_PREVIEW_SHADOWSIZE   2
      67             : 
      68          36 : static long lcl_GetDisplayStart( SCTAB nTab, ScDocument* pDoc, std::vector<long>& nPages )
      69             : {
      70          36 :     long nDisplayStart = 0;
      71          36 :     for (SCTAB i=0; i<nTab; i++)
      72             :     {
      73           0 :         if ( pDoc->NeedPageResetAfterTab(i) )
      74           0 :             nDisplayStart = 0;
      75             :         else
      76           0 :             nDisplayStart += nPages[i];
      77             :     }
      78          36 :     return nDisplayStart;
      79             : }
      80             : 
      81             : 
      82           8 : ScPreview::ScPreview( Window* pParent, ScDocShell* pDocSh, ScPreviewShell* pViewSh ) :
      83             :     Window( pParent ),
      84             :     nPageNo( 0 ),
      85             :     nZoom( 100 ),
      86             :     nTabsTested( 0 ),
      87             :     nPages(),
      88             :     nFirstAttr(),
      89             :     nTab( 0 ),
      90             :     nTabStart( 0 ),
      91             :     nDisplayStart( 0 ),
      92             :     aDate( Date::SYSTEM ),
      93             :     aTime( Time::SYSTEM ),
      94             :     nTotalPages( 0 ),
      95             :     pLocationData( NULL ),
      96             :     pDrawView( NULL ),
      97             :     pDocShell( pDocSh ),
      98             :     pViewShell( pViewSh ),
      99             :     bInGetState( false ),
     100             :     bValid( false ),
     101             :     bStateValid( false ),
     102             :     bLocationValid( false ),
     103             :     bInPaint( false ),
     104             :     bInSetZoom( false ),
     105             :     bLeftRulerMove( false ),
     106             :     bRightRulerMove( false ),
     107             :     bTopRulerMove( false ),
     108             :     bBottomRulerMove( false ),
     109             :     bHeaderRulerMove( false ),
     110             :     bFooterRulerMove( false ),
     111             :     bLeftRulerChange( false ),
     112             :     bRightRulerChange( false ),
     113             :     bTopRulerChange( false ),
     114             :     bBottomRulerChange( false ),
     115             :     bHeaderRulerChange( false ),
     116             :     bFooterRulerChange( false ),
     117             :     bPageMargin ( false ),
     118             :     bColRulerMove( false ),
     119             :     mnScale( 0 ),
     120             :     nColNumberButttonDown( 0 ),
     121             :     nHeaderHeight ( 0 ),
     122           8 :     nFooterHeight ( 0 )
     123             : {
     124           8 :     SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW ); //#106611#
     125           8 :     SetBackground();
     126             : 
     127           8 :     SetHelpId( HID_SC_WIN_PREVIEW );
     128           8 :     SetUniqueId( HID_SC_WIN_PREVIEW );
     129             : 
     130           8 :     SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
     131             : 
     132        8200 :     for (SCCOL i=0; i<=MAXCOL; i++)
     133        8192 :         nRight[i] = 0;                  // initialized with actual positions when markers are drawn
     134           8 : }
     135             : 
     136             : 
     137          24 : ScPreview::~ScPreview()
     138             : {
     139           8 :     delete pDrawView;
     140           8 :     delete pLocationData;
     141          16 : }
     142             : 
     143          18 : void ScPreview::UpdateDrawView()        // nTab must be right
     144             : {
     145          18 :     ScDocument* pDoc = pDocShell->GetDocument();
     146          18 :     ScDrawLayer* pModel = pDoc->GetDrawLayer();     // is not 0
     147             : 
     148             :     // #114135#
     149          18 :     if ( pModel )
     150             :     {
     151          18 :         SdrPage* pPage = pModel->GetPage(nTab);
     152          18 :         if ( pDrawView && ( !pDrawView->GetSdrPageView() || pDrawView->GetSdrPageView()->GetPage() != pPage ) )
     153             :         {
     154             :             //  die angezeigte Page der DrawView umzustellen (s.u.) funktioniert nicht ?!?
     155           0 :             delete pDrawView;
     156           0 :             pDrawView = NULL;
     157             :         }
     158             : 
     159          18 :         if ( !pDrawView )                                   // New Drawing?
     160             :         {
     161           8 :             pDrawView = new FmFormView( pModel, this );
     162             : 
     163             :             // The DrawView takes over the Design-Mode from the Model
     164             :             // (Settings "In opening Draftmode"), therefore to restore here
     165           8 :             pDrawView->SetDesignMode( true );
     166           8 :             pDrawView->SetPrintPreview( true );
     167           8 :             pDrawView->ShowSdrPage(pPage);
     168             :         }
     169             :     }
     170           0 :     else if ( pDrawView )
     171             :     {
     172           0 :         delete pDrawView;           // for this Chart is not needed
     173           0 :         pDrawView = NULL;
     174             :     }
     175          18 : }
     176             : 
     177             : 
     178          36 : void ScPreview::TestLastPage()
     179             : {
     180          36 :     if (nPageNo >= nTotalPages)
     181             :     {
     182           0 :         if (nTotalPages)
     183             :         {
     184           0 :             nPageNo = nTotalPages - 1;
     185           0 :             nTab = static_cast<SCTAB>(nPages.size()) -1;
     186           0 :             while (nTab > 0 && !nPages[nTab])       // not the last empty Table
     187           0 :                 --nTab;
     188             :             OSL_ENSURE(0 < static_cast<SCTAB>(nPages.size()),"are all tables empty?");
     189           0 :             nTabPage = nPages[nTab] - 1;
     190           0 :             nTabStart = 0;
     191           0 :             for (sal_uInt16 i=0; i<nTab; i++)
     192           0 :                 nTabStart += nPages[i];
     193             : 
     194           0 :             ScDocument* pDoc = pDocShell->GetDocument();
     195           0 :             nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
     196             :         }
     197             :         else        // empty Document
     198             :         {
     199           0 :             nTab = 0;
     200           0 :             nPageNo = nTabPage = nTabStart = nDisplayStart = 0;
     201           0 :             aState.nPrintTab = 0;
     202           0 :                         aState.nStartCol = aState.nEndCol = 0;
     203           0 :                         aState.nStartRow = aState.nEndRow = 0;
     204           0 :                         aState.nZoom = 0;
     205           0 :             aState.nPagesX = aState.nPagesY = 0;
     206             :             aState.nTabPages = aState.nTotalPages =
     207           0 :             aState.nPageStart = aState.nDocPages = 0;
     208             :         }
     209             :     }
     210          36 : }
     211             : 
     212             : 
     213          18 : void ScPreview::CalcPages()
     214             : {
     215          18 :     WaitObject aWait( this );
     216             : 
     217          18 :     ScDocument* pDoc = pDocShell->GetDocument();
     218          18 :     nTabCount = pDoc->GetTableCount();
     219             : 
     220          18 :     SCTAB nStart = nTabsTested;
     221          18 :     if (!bValid)
     222             :     {
     223          18 :         nStart = 0;
     224          18 :         nTotalPages = 0;
     225          18 :         nTabsTested = 0;
     226             :     }
     227             : 
     228             :     // update all pending row heights with a single progress bar,
     229             :     // instead of a separate progress for each sheet from ScPrintFunc
     230          18 :     pDocShell->UpdatePendingRowHeights( nTabCount-1, true );
     231             : 
     232             :     //  PrintOptions is passed to PrintFunc for SkipEmpty flag,
     233             :     //  but always all sheets are used (there is no selected sheet)
     234          36 :     ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
     235             : 
     236          36 :     while (nStart > static_cast<SCTAB>(nPages.size()))
     237           0 :         nPages.push_back(0);
     238          36 :     while (nStart > static_cast<SCTAB>(nFirstAttr.size()))
     239           0 :         nFirstAttr.push_back(0);
     240             : 
     241          36 :     for (SCTAB i=nStart; i<nTabCount; i++)
     242             :     {
     243          18 :         if ( i == static_cast<SCTAB>(nPages.size()))
     244           8 :             nPages.push_back(0);
     245          18 :         if ( i == static_cast<SCTAB>(nFirstAttr.size()))
     246           8 :             nFirstAttr.push_back(0);
     247          18 :         if (!aOptions.GetAllSheets() && maSelectedTabs.count(i) == 0)
     248             :         {
     249           0 :             nPages[i] = 0;
     250           0 :             nFirstAttr[i] = 0;
     251           0 :             continue;
     252             :         }
     253             : 
     254          18 :         long nAttrPage = i > 0 ? nFirstAttr[i-1] : 1;
     255             : 
     256          18 :         long nThisStart = nTotalPages;
     257          18 :         ScPrintFunc aPrintFunc( this, pDocShell, i, nAttrPage, 0, NULL, &aOptions );
     258          18 :         long nThisTab = aPrintFunc.GetTotalPages();
     259          18 :         nPages[i] = nThisTab;
     260          18 :         nTotalPages += nThisTab;
     261          18 :         nFirstAttr[i] = aPrintFunc.GetFirstPageNo();    // to keep or from template
     262             : 
     263          18 :         if (nPageNo>=nThisStart && nPageNo<nTotalPages)
     264             :         {
     265          18 :             nTab = i;
     266          18 :             nTabPage = nPageNo - nThisStart;
     267          18 :             nTabStart = nThisStart;
     268             : 
     269          18 :             aPrintFunc.GetPrintState( aState );
     270          18 :             aPageSize = aPrintFunc.GetPageSize();
     271             :         }
     272          18 :     }
     273             : 
     274          18 :     nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
     275             : 
     276          18 :     if (nTabCount > nTabsTested)
     277          18 :         nTabsTested = nTabCount;
     278             : 
     279          18 :     TestLastPage();
     280             : 
     281          18 :     aState.nDocPages = nTotalPages;
     282             : 
     283          18 :     bValid = true;
     284          18 :     bStateValid = true;
     285          36 :     DoInvalidate();
     286          18 : }
     287             : 
     288             : 
     289          26 : void ScPreview::RecalcPages()                   // only nPageNo is changed
     290             : {
     291          26 :     if (!bValid)
     292          34 :         return;                         // then CalcPages is called
     293             : 
     294          18 :     SCTAB nOldTab = nTab;
     295             : 
     296          18 :     bool bDone = false;
     297          36 :     while (nPageNo >= nTotalPages && nTabsTested < nTabCount)
     298             :     {
     299           0 :         CalcPages();
     300           0 :         bDone = true;
     301             :     }
     302             : 
     303          18 :     if (!bDone)
     304             :     {
     305          18 :         long nPartPages = 0;
     306          36 :         for (SCTAB i=0; i<nTabsTested && nTab < static_cast<SCTAB>(nPages.size()); i++)
     307             :         {
     308          18 :             long nThisStart = nPartPages;
     309          18 :             nPartPages += nPages[i];
     310             : 
     311          18 :             if (nPageNo>=nThisStart && nPageNo<nPartPages)
     312             :             {
     313          18 :                 nTab = i;
     314          18 :                 nTabPage = nPageNo - nThisStart;
     315          18 :                 nTabStart = nThisStart;
     316             :             }
     317             :         }
     318             : 
     319          18 :         ScDocument* pDoc = pDocShell->GetDocument();
     320          18 :         nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
     321             :     }
     322             : 
     323          18 :     TestLastPage();         // to test, if after last page
     324             : 
     325          18 :     if ( nTab != nOldTab )
     326           0 :         bStateValid = false;
     327             : 
     328          18 :     DoInvalidate();
     329             : }
     330             : 
     331             : 
     332          56 : void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
     333             : {
     334          56 :     if (!bValid)
     335             :     {
     336          10 :         CalcPages();
     337          10 :         RecalcPages();
     338          10 :         UpdateDrawView();       // Spreedsheet eventually changes
     339             :     }
     340             : 
     341          56 :     Fraction aPreviewZoom( nZoom, 100 );
     342          56 :     Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
     343          56 :     MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
     344             : 
     345          56 :     bool bDoPrint = ( pFillLocation == NULL );
     346          56 :     bool bValidPage = ( nPageNo < nTotalPages );
     347             : 
     348          56 :     ScModule* pScMod = SC_MOD();
     349          56 :     const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
     350          56 :     Color aBackColor( rColorCfg.GetColorValue(svtools::APPBACKGROUND).nColor );
     351             : 
     352          56 :     if ( bDoPrint && ( aOffset.X() < 0 || aOffset.Y() < 0 ) && bValidPage )
     353             :     {
     354          33 :         SetMapMode( aMMMode );
     355          33 :         SetLineColor();
     356          33 :         SetFillColor(aBackColor);
     357             : 
     358          33 :         Size aWinSize = GetOutputSize();
     359          33 :         if ( aOffset.X() < 0 )
     360          33 :             DrawRect(Rectangle( 0, 0, -aOffset.X(), aWinSize.Height() ));
     361          33 :         if ( aOffset.Y() < 0 )
     362          21 :             DrawRect(Rectangle( 0, 0, aWinSize.Width(), -aOffset.Y() ));
     363             :     }
     364             : 
     365          56 :     long   nLeftMargin = 0;
     366          56 :     long   nRightMargin = 0;
     367          56 :     long   nTopMargin = 0;
     368          56 :     long   nBottomMargin = 0;
     369          56 :     bool   bHeaderOn = false;
     370          56 :     bool   bFooterOn = false;
     371             : 
     372          56 :     ScDocument* pDoc = pDocShell->GetDocument();
     373          56 :     bool   bLayoutRTL = pDoc->IsLayoutRTL( nTab );
     374             : 
     375          56 :     Size aLocalPageSize;
     376          56 :     if ( bValidPage )
     377             :     {
     378          56 :         ScPrintOptions aOptions = pScMod->GetPrintOptions();
     379             : 
     380             :         ScPrintFunc* pPrintFunc;
     381          56 :         if (bStateValid)
     382          46 :             pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
     383             :         else
     384          10 :             pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
     385             : 
     386          56 :         pPrintFunc->SetOffset(aOffset);
     387          56 :         pPrintFunc->SetManualZoom(nZoom);
     388          56 :         pPrintFunc->SetDateTime(aDate,aTime);
     389          56 :         pPrintFunc->SetClearFlag(true);
     390          56 :         pPrintFunc->SetUseStyleColor( pScMod->GetAccessOptions().GetIsForPagePreviews() );
     391             : 
     392          56 :         pPrintFunc->SetDrawView( pDrawView );
     393             : 
     394             :         // MultiSelection for the one Page must produce something inconvenient
     395          56 :         Range aPageRange( nPageNo+1, nPageNo+1 );
     396         112 :         MultiSelection aPage( aPageRange );
     397          56 :         aPage.SetTotalRange( Range(0,RANGE_MAX) );
     398          56 :         aPage.Select( aPageRange );
     399             : 
     400          56 :         long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, bDoPrint, pFillLocation );
     401             :         OSL_ENSURE(nPrinted<=1, "was'n nu los?");
     402             : 
     403          56 :         SetMapMode(aMMMode);
     404             : 
     405             :         //init nLeftMargin ... in the ScPrintFunc::InitParam!!!
     406          56 :         nLeftMargin = pPrintFunc->GetLeftMargin();
     407          56 :         nRightMargin = pPrintFunc->GetRightMargin();
     408          56 :         nTopMargin = pPrintFunc->GetTopMargin();
     409          56 :         nBottomMargin = pPrintFunc->GetBottomMargin();
     410          56 :         nHeaderHeight = pPrintFunc->GetHeader().nHeight;
     411          56 :         nFooterHeight = pPrintFunc->GetFooter().nHeight;
     412          56 :         bHeaderOn = pPrintFunc->GetHeader().bEnable;
     413          56 :         bFooterOn = pPrintFunc->GetFooter().bEnable;
     414          56 :         mnScale = pPrintFunc->GetZoom();
     415             : 
     416          56 :         if ( bDoPrint && bPageMargin && pLocationData )     // don't make use of pLocationData while filling it
     417             :         {
     418           0 :             Rectangle aPixRect;
     419           0 :             Rectangle aRectCellPosition;
     420           0 :             Rectangle aRectPosition;
     421           0 :             pLocationData->GetMainCellRange( aPageArea, aPixRect );
     422           0 :             if( !bLayoutRTL )
     423             :             {
     424           0 :                 pLocationData->GetCellPosition( aPageArea.aStart, aRectPosition );
     425           0 :                 nLeftPosition = aRectPosition.Left();
     426           0 :                 for( SCCOL i = aPageArea.aStart.Col(); i <= aPageArea.aEnd.Col(); i++ )
     427             :                 {
     428           0 :                     pLocationData->GetCellPosition( ScAddress( i,aPageArea.aStart.Row(),aPageArea.aStart.Tab()),aRectCellPosition );
     429           0 :                     nRight[i] = aRectCellPosition.Right();
     430             :                 }
     431             :             }
     432             :             else
     433             :             {
     434           0 :                 pLocationData->GetCellPosition( aPageArea.aEnd, aRectPosition );
     435           0 :                 nLeftPosition = aRectPosition.Right()+1;
     436             : 
     437           0 :                 pLocationData->GetCellPosition( aPageArea.aStart,aRectCellPosition );
     438           0 :                 nRight[ aPageArea.aEnd.Col() ] = aRectCellPosition.Left();
     439           0 :                 for( SCCOL i = aPageArea.aEnd.Col(); i > aPageArea.aStart.Col(); i-- )
     440             :                 {
     441           0 :                     pLocationData->GetCellPosition( ScAddress( i,aPageArea.aEnd.Row(),aPageArea.aEnd.Tab()),aRectCellPosition );
     442           0 :                     nRight[ i-1 ] = nRight[ i ] + aRectCellPosition.Right() - aRectCellPosition.Left() + 1;
     443             :                 }
     444             :             }
     445             :         }
     446             : 
     447          56 :         if (nPrinted)   // if not, draw everything grey
     448             :         {
     449          56 :             aLocalPageSize = pPrintFunc->GetPageSize();
     450          56 :             aLocalPageSize.Width()  = (long) (aLocalPageSize.Width()  * HMM_PER_TWIPS );
     451          56 :             aLocalPageSize.Height() = (long) (aLocalPageSize.Height() * HMM_PER_TWIPS );
     452             : 
     453          56 :             nLeftMargin = (long) ( nLeftMargin * HMM_PER_TWIPS );
     454          56 :             nRightMargin = (long) ( nRightMargin * HMM_PER_TWIPS );
     455          56 :             nTopMargin = (long) ( nTopMargin * HMM_PER_TWIPS );
     456          56 :             nBottomMargin = (long) ( nBottomMargin * HMM_PER_TWIPS );
     457          56 :             nHeaderHeight = (long) ( nHeaderHeight * HMM_PER_TWIPS * mnScale / 100 + nTopMargin );
     458          56 :             nFooterHeight = (long) ( nFooterHeight * HMM_PER_TWIPS * mnScale / 100 + nBottomMargin );
     459             :         }
     460             : 
     461          56 :         if (!bStateValid)
     462             :         {
     463          10 :             pPrintFunc->GetPrintState( aState );
     464          10 :             aState.nDocPages = nTotalPages;
     465          10 :             bStateValid = true;
     466             :         }
     467         112 :         delete pPrintFunc;
     468             :     }
     469             : 
     470          56 :     if ( bDoPrint )
     471             :     {
     472          33 :         long nPageEndX = aLocalPageSize.Width()  - aOffset.X();
     473          33 :         long nPageEndY = aLocalPageSize.Height() - aOffset.Y();
     474          33 :         if ( !bValidPage )
     475           0 :             nPageEndX = nPageEndY = 0;
     476             : 
     477          33 :         Size aWinSize = GetOutputSize();
     478          33 :         Point aWinEnd( aWinSize.Width(), aWinSize.Height() );
     479          33 :         bool bRight  = nPageEndX <= aWinEnd.X();
     480          33 :         bool bBottom = nPageEndY <= aWinEnd.Y();
     481             : 
     482          33 :         if( bPageMargin && bValidPage )
     483             :         {
     484           0 :             SetMapMode(aMMMode);
     485           0 :             SetLineColor( COL_BLACK );
     486           0 :             DrawInvert( (long)( nTopMargin - aOffset.Y() ), POINTER_VSIZEBAR );
     487           0 :             DrawInvert( (long)(nPageEndY - nBottomMargin ), POINTER_VSIZEBAR );
     488           0 :             DrawInvert( (long)( nLeftMargin - aOffset.X() ), POINTER_HSIZEBAR );
     489           0 :             DrawInvert( (long)( nPageEndX - nRightMargin ) , POINTER_HSIZEBAR );
     490           0 :             if( bHeaderOn )
     491             :             {
     492           0 :                 DrawInvert( nHeaderHeight - aOffset.Y(), POINTER_VSIZEBAR );
     493             :             }
     494           0 :             if( bFooterOn )
     495             :             {
     496           0 :                 DrawInvert( nPageEndY - nFooterHeight, POINTER_VSIZEBAR );
     497             :             }
     498             : 
     499           0 :             SetMapMode( MapMode( MAP_PIXEL ) );
     500           0 :             for( int i= aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
     501             :             {
     502           0 :                 Point aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
     503           0 :                 SetLineColor( COL_BLACK );
     504           0 :                 SetFillColor( COL_BLACK );
     505           0 :                 DrawRect( Rectangle( Point( nRight[i] - 2, aColumnTop.Y() ),Point( nRight[i] + 2 , 4 + aColumnTop.Y()) ));
     506           0 :                 DrawLine( Point( nRight[i], aColumnTop.Y() ), Point( nRight[i],  10 + aColumnTop.Y()) );
     507             :             }
     508           0 :             SetMapMode( aMMMode );
     509             :         }
     510             : 
     511          33 :         if (bRight || bBottom)
     512             :         {
     513          33 :             SetMapMode(aMMMode);
     514          33 :             SetLineColor();
     515          33 :             SetFillColor(aBackColor);
     516          33 :             if (bRight)
     517          33 :                 DrawRect(Rectangle(nPageEndX,0, aWinEnd.X(),aWinEnd.Y()));
     518          33 :             if (bBottom)
     519             :             {
     520          28 :                 if (bRight)
     521          28 :                     DrawRect(Rectangle(0,nPageEndY, nPageEndX,aWinEnd.Y()));    // Corner not duplicated
     522             :                 else
     523           0 :                     DrawRect(Rectangle(0,nPageEndY, aWinEnd.X(),aWinEnd.Y()));
     524             :             }
     525             :         }
     526             : 
     527          33 :         if ( bValidPage )
     528             :         {
     529          33 :             Color aBorderColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
     530             : 
     531             :             //  draw border
     532             : 
     533          33 :             if ( aOffset.X() <= 0 || aOffset.Y() <= 0 || bRight || bBottom )
     534             :             {
     535          33 :                 SetLineColor( aBorderColor );
     536          33 :                 SetFillColor();
     537             : 
     538          33 :                 Rectangle aPixel( LogicToPixel( Rectangle( -aOffset.X(), -aOffset.Y(), nPageEndX, nPageEndY ) ) );
     539          33 :                 --aPixel.Right();
     540          33 :                 --aPixel.Bottom();
     541          33 :                 DrawRect( PixelToLogic( aPixel ) );
     542             :             }
     543             : 
     544             :             //  draw shadow
     545             : 
     546          33 :             SetLineColor();
     547          33 :             SetFillColor( aBorderColor );
     548             : 
     549          33 :             Rectangle aPixel;
     550             : 
     551          33 :             aPixel = LogicToPixel( Rectangle( nPageEndX, -aOffset.Y(), nPageEndX, nPageEndY ) );
     552          33 :             aPixel.Top() += SC_PREVIEW_SHADOWSIZE;
     553          33 :             aPixel.Right() += SC_PREVIEW_SHADOWSIZE - 1;
     554          33 :             aPixel.Bottom() += SC_PREVIEW_SHADOWSIZE - 1;
     555          33 :             DrawRect( PixelToLogic( aPixel ) );
     556             : 
     557          33 :             aPixel = LogicToPixel( Rectangle( -aOffset.X(), nPageEndY, nPageEndX, nPageEndY ) );
     558          33 :             aPixel.Left() += SC_PREVIEW_SHADOWSIZE;
     559          33 :             aPixel.Right() += SC_PREVIEW_SHADOWSIZE - 1;
     560          33 :             aPixel.Bottom() += SC_PREVIEW_SHADOWSIZE - 1;
     561          33 :             DrawRect( PixelToLogic( aPixel ) );
     562             :         }
     563          56 :     }
     564          56 : }
     565             : 
     566          33 : void ScPreview::Paint( const Rectangle& /* rRect */ )
     567             : {
     568          33 :     bool bWasInPaint = bInPaint;        // nested calls shouldn't be necessary, but allow for now
     569          33 :     bInPaint = true;
     570             : 
     571          33 :     if (bPageMargin)
     572           0 :         GetLocationData();              // fill location data for column positions
     573          33 :     DoPrint( NULL );
     574          33 :     pViewShell->UpdateScrollBars();
     575             : 
     576          33 :     bInPaint = bWasInPaint;
     577          33 : }
     578             : 
     579           0 : void ScPreview::Command( const CommandEvent& rCEvt )
     580             : {
     581           0 :     sal_uInt16 nCmd = rCEvt.GetCommand();
     582           0 :     if ( nCmd == COMMAND_WHEEL || nCmd == COMMAND_STARTAUTOSCROLL || nCmd == COMMAND_AUTOSCROLL )
     583             :     {
     584           0 :         bool bDone = pViewShell->ScrollCommand( rCEvt );
     585           0 :         if (!bDone)
     586           0 :             Window::Command(rCEvt);
     587             :     }
     588           0 :     else if ( nCmd == COMMAND_CONTEXTMENU )
     589           0 :         SfxDispatcher::ExecutePopup();
     590             :     else
     591           0 :         Window::Command( rCEvt );
     592           0 : }
     593             : 
     594             : 
     595           0 : void ScPreview::KeyInput( const KeyEvent& rKEvt )
     596             : {
     597             :     //  The + and - keys can't be configured as accelerator entries, so they must be handled directly
     598             :     //  (in ScPreview, not ScPreviewShell -> only if the preview window has the focus)
     599             : 
     600           0 :     const KeyCode& rKeyCode = rKEvt.GetKeyCode();
     601           0 :     sal_uInt16 nKey = rKeyCode.GetCode();
     602           0 :     bool bHandled = false;
     603           0 :     if(!rKeyCode.GetModifier())
     604             :     {
     605           0 :         sal_uInt16 nSlot = 0;
     606           0 :         switch(nKey)
     607             :         {
     608           0 :             case KEY_ADD:      nSlot = SID_PREVIEW_ZOOMIN;  break;
     609           0 :             case KEY_ESCAPE:   nSlot = ScViewUtil::IsFullScreen( *pViewShell ) ? SID_CANCEL : SID_PREVIEW_CLOSE; break;
     610           0 :             case KEY_SUBTRACT: nSlot = SID_PREVIEW_ZOOMOUT; break;
     611             :         }
     612           0 :         if(nSlot)
     613             :         {
     614           0 :             bHandled = true;
     615           0 :             pViewShell->GetViewFrame()->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_ASYNCHRON );
     616             :         }
     617             :     }
     618             : 
     619           0 :     if ( !bHandled && !pViewShell->KeyInput(rKEvt) )
     620           0 :         Window::KeyInput(rKEvt);
     621           0 : }
     622             : 
     623             : 
     624         928 : const ScPreviewLocationData& ScPreview::GetLocationData()
     625             : {
     626         928 :     if ( !pLocationData )
     627             :     {
     628           8 :         pLocationData = new ScPreviewLocationData( pDocShell->GetDocument(), this );
     629           8 :         bLocationValid = false;
     630             :     }
     631         928 :     if ( !bLocationValid )
     632             :     {
     633          23 :         pLocationData->Clear();
     634          23 :         DoPrint( pLocationData );
     635          23 :         bLocationValid = true;
     636             :     }
     637         928 :     return *pLocationData;
     638             : }
     639             : 
     640             : 
     641          10 : void ScPreview::DataChanged(bool bNewTime)
     642             : {
     643          10 :     if (bNewTime)
     644             :     {
     645          10 :         aDate = Date( Date::SYSTEM );
     646          10 :         aTime = Time( Time::SYSTEM );
     647             :     }
     648             : 
     649          10 :     bValid = false;
     650          10 :     InvalidateLocationData( SC_HINT_DATACHANGED );
     651          10 :     Invalidate();
     652          10 : }
     653             : 
     654             : 
     655          18 : String ScPreview::GetPosString()
     656             : {
     657          18 :     if (!bValid)
     658             :     {
     659           0 :         CalcPages();
     660           0 :         UpdateDrawView();       // The table eventually changes
     661             :     }
     662             : 
     663          36 :     OUString aString = ScGlobal::GetRscString( STR_PAGE ) +
     664          54 :                        " " + OUString::number(nPageNo+1);
     665             : 
     666          18 :     if (nTabsTested >= nTabCount)
     667          18 :         aString += " / " + OUString::number(nTotalPages);
     668             : 
     669          18 :     return aString;
     670             : }
     671             : 
     672             : 
     673          18 : void ScPreview::SetZoom(sal_uInt16 nNewZoom)
     674             : {
     675          18 :     if (nNewZoom < 20)
     676           0 :         nNewZoom = 20;
     677          18 :     if (nNewZoom > 400)
     678           0 :         nNewZoom = 400;
     679          18 :     if (nNewZoom != nZoom)
     680             :     {
     681          10 :         nZoom = nNewZoom;
     682             : 
     683             :         //  apply new MapMode and call UpdateScrollBars to update aOffset
     684             : 
     685          10 :         Fraction aPreviewZoom( nZoom, 100 );
     686          10 :         Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
     687          10 :         MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
     688          10 :         SetMapMode( aMMMode );
     689             : 
     690          10 :         bInSetZoom = true;              // don't scroll during SetYOffset in UpdateScrollBars
     691          10 :         pViewShell->UpdateNeededScrollBars(true);
     692          10 :         bInSetZoom = false;
     693             : 
     694          10 :         bStateValid = false;
     695          10 :         InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
     696          10 :         DoInvalidate();
     697          10 :         Invalidate();
     698             :     }
     699          18 : }
     700             : 
     701             : 
     702           8 : void ScPreview::SetPageNo( long nPage )
     703             : {
     704           8 :     nPageNo = nPage;
     705           8 :     RecalcPages();
     706           8 :     UpdateDrawView();       // The table eventually changes
     707           8 :     InvalidateLocationData( SC_HINT_DATACHANGED );
     708           8 :     Invalidate();
     709           8 : }
     710             : 
     711             : 
     712           8 : long ScPreview::GetFirstPage(SCTAB nTabP)
     713             : {
     714           8 :     SCTAB nDocTabCount = pDocShell->GetDocument()->GetTableCount();
     715           8 :     if (nTabP >= nDocTabCount)
     716           0 :         nTabP = nDocTabCount-1;
     717             : 
     718           8 :     long nPage = 0;
     719           8 :     if (nTabP>0)
     720             :     {
     721           0 :         CalcPages();
     722           0 :         if (nTabP >= static_cast<SCTAB>(nPages.size()) )
     723             :             OSL_FAIL("nPages out ouf bounds, FIX IT");
     724           0 :         UpdateDrawView();       // The table eventually changes
     725             : 
     726           0 :         for (SCTAB i=0; i<nTabP; i++)
     727           0 :             nPage += nPages[i];
     728             : 
     729             :         // An empty Table on the previous Page
     730             : 
     731           0 :         if ( nPages[nTabP]==0 && nPage > 0 )
     732           0 :             --nPage;
     733             :     }
     734             : 
     735           8 :     return nPage;
     736             : }
     737             : 
     738             : 
     739           8 : static Size lcl_GetDocPageSize( ScDocument* pDoc, SCTAB nTab )
     740             : {
     741           8 :     String aName = pDoc->GetPageStyle( nTab );
     742           8 :     ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
     743           8 :     SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aName, SFX_STYLE_FAMILY_PAGE );
     744           8 :     if ( pStyleSheet )
     745             :     {
     746           8 :         SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
     747           8 :         return ((const SvxSizeItem&) rStyleSet.Get(ATTR_PAGE_SIZE)).GetSize();
     748             :     }
     749             :     else
     750             :     {
     751             :         OSL_FAIL( "PageStyle not found" );
     752           0 :         return Size();
     753           8 :     }
     754             : }
     755             : 
     756             : 
     757           8 : sal_uInt16 ScPreview::GetOptimalZoom(bool bWidthOnly)
     758             : {
     759           8 :     double nWinScaleX = ScGlobal::nScreenPPTX / pDocShell->GetOutputFactor();
     760           8 :     double nWinScaleY = ScGlobal::nScreenPPTY;
     761           8 :     Size aWinSize = GetOutputSizePixel();
     762             : 
     763             :     //  desired margin is 0.25cm in default MapMode (like Writer),
     764             :     //  but some additional margin is introduced by integer scale values
     765             :     //  -> add only 0.10cm, so there is some margin in all cases.
     766           8 :     Size aMarginSize( LogicToPixel( Size( 100, 100 ), MAP_100TH_MM ) );
     767           8 :     aWinSize.Width()  -= 2 * aMarginSize.Width();
     768           8 :     aWinSize.Height() -= 2 * aMarginSize.Height();
     769             : 
     770           8 :     Size aLocalPageSize = lcl_GetDocPageSize( pDocShell->GetDocument(), nTab );
     771           8 :     if ( aLocalPageSize.Width() && aLocalPageSize.Height() )
     772             :     {
     773           8 :         long nZoomX = (long) ( aWinSize.Width() * 100  / ( aLocalPageSize.Width() * nWinScaleX ));
     774           8 :         long nZoomY = (long) ( aWinSize.Height() * 100 / ( aLocalPageSize.Height() * nWinScaleY ));
     775             : 
     776           8 :         long nOptimal = nZoomX;
     777           8 :         if (!bWidthOnly && nZoomY<nOptimal)
     778           8 :             nOptimal = nZoomY;
     779             : 
     780           8 :         if (nOptimal<20)
     781           0 :             nOptimal = 20;
     782           8 :         if (nOptimal>400)
     783           0 :             nOptimal = 400;
     784             : 
     785           8 :         return (sal_uInt16) nOptimal;
     786             :     }
     787             :     else
     788           0 :         return nZoom;
     789             : }
     790             : 
     791             : 
     792          51 : void ScPreview::SetXOffset( long nX )
     793             : {
     794          51 :     if ( aOffset.X() == nX )
     795          92 :         return;
     796             : 
     797          10 :     if (bValid)
     798             :     {
     799          10 :         long nDif = LogicToPixel(aOffset).X() - LogicToPixel(Point(nX,0)).X();
     800          10 :         aOffset.X() = nX;
     801          10 :         if (nDif && !bInSetZoom)
     802             :         {
     803           0 :             MapMode aOldMode = GetMapMode(); SetMapMode(MAP_PIXEL);
     804           0 :             Scroll( nDif, 0 );
     805           0 :             SetMapMode(aOldMode);
     806             :         }
     807             :     }
     808             :     else
     809             :     {
     810           0 :         aOffset.X() = nX;
     811           0 :         if (!bInSetZoom)
     812           0 :             Invalidate();
     813             :     }
     814          10 :     InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
     815          10 :     Paint(Rectangle());
     816             : }
     817             : 
     818             : 
     819          46 : void ScPreview::SetYOffset( long nY )
     820             : {
     821          46 :     if ( aOffset.Y() == nY )
     822          83 :         return;
     823             : 
     824           9 :     if (bValid)
     825             :     {
     826           9 :         long nDif = LogicToPixel(aOffset).Y() - LogicToPixel(Point(0,nY)).Y();
     827           9 :         aOffset.Y() = nY;
     828           9 :         if (nDif && !bInSetZoom)
     829             :         {
     830           0 :             MapMode aOldMode = GetMapMode(); SetMapMode(MAP_PIXEL);
     831           0 :             Scroll( 0, nDif );
     832           0 :             SetMapMode(aOldMode);
     833             :         }
     834             :     }
     835             :     else
     836             :     {
     837           0 :         aOffset.Y() = nY;
     838           0 :         if (!bInSetZoom)
     839           0 :             Invalidate();
     840             :     }
     841           9 :     InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
     842           9 :     Paint(Rectangle());
     843             : }
     844             : 
     845             : 
     846          46 : void ScPreview::DoInvalidate()
     847             : {
     848             :     //  If the whole GetState of the shell is called
     849             :     //  The Invalidate must come behind asynchronously
     850             : 
     851          46 :    if (bInGetState)
     852          16 :         Application::PostUserEvent( STATIC_LINK( this, ScPreview, InvalidateHdl ) );
     853             :     else
     854          30 :         StaticInvalidate();     // Immediately
     855          46 : }
     856             : 
     857          46 : void ScPreview::StaticInvalidate()
     858             : {
     859             :     //  static method, because it's called asynchronously
     860             :     //  -> must use current viewframe
     861             : 
     862          46 :     SfxViewFrame* pViewFrm = SfxViewFrame::Current();
     863          46 :     if (!pViewFrm)
     864          46 :         return;
     865             : 
     866          46 :     SfxBindings& rBindings = pViewFrm->GetBindings();
     867          46 :     rBindings.Invalidate(SID_STATUS_DOCPOS);
     868          46 :     rBindings.Invalidate(SID_STATUS_PAGESTYLE);
     869          46 :     rBindings.Invalidate(SID_PREVIEW_PREVIOUS);
     870          46 :     rBindings.Invalidate(SID_PREVIEW_NEXT);
     871          46 :     rBindings.Invalidate(SID_PREVIEW_FIRST);
     872          46 :     rBindings.Invalidate(SID_PREVIEW_LAST);
     873          46 :     rBindings.Invalidate(SID_ATTR_ZOOM);
     874          46 :     rBindings.Invalidate(SID_PREVIEW_ZOOMIN);
     875          46 :     rBindings.Invalidate(SID_PREVIEW_ZOOMOUT);
     876          46 :     rBindings.Invalidate(SID_PREVIEW_SCALINGFACTOR);
     877          46 :     rBindings.Invalidate(SID_ATTR_ZOOMSLIDER);
     878             : }
     879             : 
     880          16 : IMPL_STATIC_LINK( ScPreview, InvalidateHdl, void*, EMPTYARG )
     881             : {
     882             :     (void)pThis;    // avoid warning
     883             : 
     884          16 :     StaticInvalidate();
     885          16 :     return 0;
     886             : }
     887             : 
     888           0 : void ScPreview::DataChanged( const DataChangedEvent& rDCEvt )
     889             : {
     890           0 :     Window::DataChanged(rDCEvt);
     891             : 
     892           0 :     if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
     893           0 :          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
     894           0 :          (rDCEvt.GetType() == DATACHANGED_FONTS) ||
     895           0 :          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
     896           0 :          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     897           0 :           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
     898             :     {
     899           0 :         if ( rDCEvt.GetType() == DATACHANGED_FONTS )
     900           0 :             pDocShell->UpdateFontList();
     901             : 
     902             :         // #i114518# Paint of form controls may modify the window's settings.
     903             :         // Ignore the event if it is called from within Paint.
     904           0 :         if ( !bInPaint )
     905             :         {
     906           0 :             if ( rDCEvt.GetType() == DATACHANGED_SETTINGS &&
     907           0 :                   (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     908             :             {
     909             :                 //  scroll bar size may have changed
     910           0 :                 pViewShell->InvalidateBorder();     // calls OuterResizePixel
     911             :             }
     912           0 :             Invalidate();
     913           0 :             InvalidateLocationData( SC_HINT_DATACHANGED );
     914             :         }
     915             :     }
     916           0 : }
     917             : 
     918           0 : void ScPreview::MouseButtonDown( const MouseEvent& rMEvt )
     919             : {
     920           0 :     Fraction  aPreviewZoom( nZoom, 100 );
     921           0 :     Fraction  aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
     922           0 :     MapMode   aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
     923             : 
     924           0 :     aButtonDownChangePoint = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
     925           0 :     aButtonDownPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
     926             : 
     927           0 :     CaptureMouse();
     928             : 
     929           0 :     if( rMEvt.IsLeft() && GetPointer() == POINTER_HSIZEBAR )
     930             :     {
     931           0 :         SetMapMode( aMMMode );
     932           0 :         if( bLeftRulerChange )
     933             :         {
     934           0 :            DrawInvert( aButtonDownChangePoint.X(), POINTER_HSIZEBAR );
     935           0 :            bLeftRulerMove = true;
     936           0 :            bRightRulerMove = false;
     937             :         }
     938           0 :         else if( bRightRulerChange )
     939             :         {
     940           0 :            DrawInvert( aButtonDownChangePoint.X(), POINTER_HSIZEBAR );
     941           0 :            bLeftRulerMove = false;
     942           0 :            bRightRulerMove = true;
     943             :         }
     944             :     }
     945             : 
     946           0 :     if( rMEvt.IsLeft() && GetPointer() == POINTER_VSIZEBAR )
     947             :     {
     948           0 :         SetMapMode( aMMMode );
     949           0 :         if( bTopRulerChange )
     950             :         {
     951           0 :             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
     952           0 :             bTopRulerMove = true;
     953           0 :             bBottomRulerMove = false;
     954             :         }
     955           0 :         else if( bBottomRulerChange )
     956             :         {
     957           0 :             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
     958           0 :             bTopRulerMove = false;
     959           0 :             bBottomRulerMove = true;
     960             :         }
     961           0 :         else if( bHeaderRulerChange )
     962             :         {
     963           0 :             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
     964           0 :             bHeaderRulerMove = true;
     965           0 :             bFooterRulerMove = false;
     966             :         }
     967           0 :         else if( bFooterRulerChange )
     968             :         {
     969           0 :             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
     970           0 :             bHeaderRulerMove = false;
     971           0 :             bFooterRulerMove = true;
     972             :         }
     973             :     }
     974             : 
     975           0 :     if( rMEvt.IsLeft() && GetPointer() == POINTER_HSPLIT )
     976             :     {
     977           0 :         Point  aNowPt = rMEvt.GetPosPixel();
     978           0 :         SCCOL i = 0;
     979           0 :         for( i = aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
     980             :         {
     981           0 :             if( aNowPt.X() < nRight[i] + 2 && aNowPt.X() > nRight[i] - 2 )
     982             :             {
     983           0 :                 nColNumberButttonDown = i;
     984           0 :                 break;
     985             :             }
     986             :         }
     987           0 :         if( i == aPageArea.aEnd.Col()+1 )
     988           0 :             return;
     989             : 
     990           0 :         SetMapMode( aMMMode );
     991           0 :         if( nColNumberButttonDown == aPageArea.aStart.Col() )
     992           0 :             DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,POINTER_HSPLIT );
     993             :         else
     994           0 :             DrawInvert( PixelToLogic( Point( nRight[ nColNumberButttonDown-1 ], 0 ),aMMMode ).X() ,POINTER_HSPLIT );
     995             : 
     996           0 :         DrawInvert( aButtonDownChangePoint.X(), POINTER_HSPLIT );
     997           0 :         bColRulerMove = true;
     998           0 :     }
     999             : }
    1000             : 
    1001           0 : void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
    1002             : {
    1003           0 :         Fraction  aPreviewZoom( nZoom, 100 );
    1004           0 :         Fraction  aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    1005           0 :         MapMode   aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
    1006             : 
    1007           0 :         aButtonUpPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
    1008             : 
    1009           0 :         long  nWidth = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Width();
    1010           0 :         long  nHeight = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Height();
    1011             : 
    1012           0 :         if( rMEvt.IsLeft() && GetPointer() == POINTER_HSIZEBAR )
    1013             :         {
    1014           0 :             SetPointer( Pointer( POINTER_ARROW ) );
    1015             : 
    1016             : 
    1017           0 :             ScDocument * pDoc = pDocShell->GetDocument();
    1018           0 :             String   aOldName = pDoc->GetPageStyle( nTab );
    1019           0 :             bool bUndo = pDoc->IsUndoEnabled();
    1020           0 :             ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
    1021           0 :             SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
    1022             : 
    1023           0 :             if ( pStyleSheet )
    1024             :             {
    1025           0 :                 bool bMoveRulerAction= true;
    1026           0 :                 ScStyleSaveData aOldData;
    1027           0 :                 if( bUndo )
    1028           0 :                     aOldData.InitFromStyle( pStyleSheet );
    1029             : 
    1030           0 :                 SfxItemSet&  rStyleSet = pStyleSheet->GetItemSet();
    1031             : 
    1032           0 :                 SvxLRSpaceItem aLRItem = ( const SvxLRSpaceItem& ) rStyleSet.Get( ATTR_LRSPACE );
    1033             : 
    1034           0 :                 if(( bLeftRulerChange || bRightRulerChange ) && ( aButtonUpPt.X() <= ( 0 - aOffset.X() ) || aButtonUpPt.X() > nWidth * HMM_PER_TWIPS - aOffset.X() ) )
    1035             :                 {
    1036           0 :                     bMoveRulerAction = false;
    1037           0 :                     Paint(Rectangle(0,0,10000,10000));
    1038             :                 }
    1039           0 :                 else if( bLeftRulerChange && ( aButtonUpPt.X() / HMM_PER_TWIPS > nWidth - aLRItem.GetRight() - aOffset.X() / HMM_PER_TWIPS ) )
    1040             :                 {
    1041           0 :                     bMoveRulerAction = false;
    1042           0 :                     Paint(Rectangle(0,0,10000,10000));
    1043             :                 }
    1044           0 :                 else if( bRightRulerChange && ( aButtonUpPt.X() / HMM_PER_TWIPS < aLRItem.GetLeft() - aOffset.X() / HMM_PER_TWIPS ) )
    1045             :                 {
    1046           0 :                     bMoveRulerAction = false;
    1047           0 :                     Paint(Rectangle(0,0,10000,10000));
    1048             :                 }
    1049           0 :                 else if( aButtonDownPt.X() == aButtonUpPt.X() )
    1050             :                 {
    1051           0 :                     bMoveRulerAction = false;
    1052           0 :                     DrawInvert( aButtonUpPt.X(), POINTER_HSIZEBAR );
    1053             :                 }
    1054           0 :                 if( bMoveRulerAction )
    1055             :                 {
    1056           0 :                     ScDocShellModificator aModificator( *pDocShell );
    1057           0 :                     if( bLeftRulerChange && bLeftRulerMove )
    1058             :                     {
    1059           0 :                        aLRItem.SetLeft( (long)( aButtonUpPt.X() / HMM_PER_TWIPS + aOffset.X() / HMM_PER_TWIPS ));
    1060           0 :                        rStyleSet.Put( aLRItem );
    1061           0 :                        pDocShell->SetModified(true);
    1062             :                     }
    1063           0 :                     else if( bRightRulerChange && bRightRulerMove )
    1064             :                     {
    1065           0 :                         aLRItem.SetRight( (long)( nWidth - aButtonUpPt.X() / HMM_PER_TWIPS - aOffset.X() / HMM_PER_TWIPS ));
    1066           0 :                         rStyleSet.Put( aLRItem );
    1067           0 :                         pDocShell->SetModified(true);
    1068             :                     }
    1069             : 
    1070           0 :                     ScStyleSaveData aNewData;
    1071           0 :                     aNewData.InitFromStyle( pStyleSheet );
    1072           0 :                     if( bUndo )
    1073             :                     {
    1074           0 :                         pDocShell->GetUndoManager()->AddUndoAction(
    1075             :                             new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
    1076           0 :                             aOldData, aNewData ) );
    1077             :                     }
    1078             : 
    1079           0 :                     if ( ValidTab( nTab ) )
    1080             :                     {
    1081           0 :                         ScPrintFunc aPrintFunc( this, pDocShell, nTab );
    1082           0 :                         aPrintFunc.UpdatePages();
    1083             :                     }
    1084             : 
    1085           0 :                     Rectangle aRect(0,0,10000,10000);
    1086           0 :                     Paint( aRect );
    1087           0 :                     aModificator.SetDocumentModified();
    1088           0 :                     bLeftRulerChange = false;
    1089           0 :                     bRightRulerChange = false;
    1090           0 :                 }
    1091             :             }
    1092           0 :             bLeftRulerMove = false;
    1093           0 :             bRightRulerMove = false;
    1094             :         }
    1095             : 
    1096           0 :         if( rMEvt.IsLeft() && GetPointer() == POINTER_VSIZEBAR )
    1097             :         {
    1098           0 :             SetPointer( POINTER_ARROW );
    1099             : 
    1100           0 :             bool bMoveRulerAction = true;
    1101           0 :             if( ( bTopRulerChange || bBottomRulerChange || bHeaderRulerChange || bFooterRulerChange ) && ( aButtonUpPt.Y() <= ( 0 - aOffset.Y() ) || aButtonUpPt.Y() > nHeight * HMM_PER_TWIPS -aOffset.Y() ) )
    1102             :             {
    1103           0 :                 bMoveRulerAction = false;
    1104           0 :                 Paint( Rectangle(0,0,10000,10000) );
    1105             :             }
    1106           0 :             else if( aButtonDownPt.Y() == aButtonUpPt.Y() )
    1107             :             {
    1108           0 :                 bMoveRulerAction = false;
    1109           0 :                 DrawInvert( aButtonUpPt.Y(), POINTER_VSIZEBAR );
    1110             :             }
    1111           0 :             if( bMoveRulerAction )
    1112             :             {
    1113           0 :                 ScDocument * pDoc = pDocShell->GetDocument();
    1114           0 :                 bool bUndo = pDoc->IsUndoEnabled();
    1115           0 :                 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
    1116           0 :                 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE );
    1117             :                 OSL_ENSURE( pStyleSheet, "PageStyle not found" );
    1118           0 :                 if ( pStyleSheet )
    1119             :                 {
    1120           0 :                     ScDocShellModificator aModificator( *pDocShell );
    1121           0 :                     ScStyleSaveData aOldData;
    1122           0 :                     if( bUndo )
    1123           0 :                         aOldData.InitFromStyle( pStyleSheet );
    1124             : 
    1125           0 :                     SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
    1126             : 
    1127           0 :                     SvxULSpaceItem aULItem = ( const SvxULSpaceItem&)rStyleSet.Get( ATTR_ULSPACE );
    1128             : 
    1129           0 :                     if( bTopRulerMove && bTopRulerChange )
    1130             :                     {
    1131           0 :                         aULItem.SetUpperValue( (sal_uInt16)( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS ) );
    1132           0 :                         rStyleSet.Put( aULItem );
    1133           0 :                         pDocShell->SetModified(true);
    1134             :                     }
    1135           0 :                     else if( bBottomRulerMove && bBottomRulerChange )
    1136             :                     {
    1137           0 :                         aULItem.SetLowerValue( (sal_uInt16)( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS ) );
    1138           0 :                         rStyleSet.Put( aULItem );
    1139           0 :                         pDocShell->SetModified(true);
    1140             :                     }
    1141           0 :                     else if( bHeaderRulerMove && bHeaderRulerChange )
    1142             :                     {
    1143           0 :                         const SfxPoolItem* pItem = NULL;
    1144           0 :                         if ( rStyleSet.GetItemState( ATTR_PAGE_HEADERSET, false, &pItem ) == SFX_ITEM_SET )
    1145             :                         {
    1146           0 :                             SfxItemSet& pHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
    1147           0 :                             Size  aHeaderSize = ((const SvxSizeItem&)pHeaderSet.Get(ATTR_PAGE_SIZE)).GetSize();
    1148           0 :                             aHeaderSize.Height() = (long)( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS - aULItem.GetUpper());
    1149           0 :                             aHeaderSize.Height() = aHeaderSize.Height() * 100 / mnScale;
    1150           0 :                             SvxSetItem  aNewHeader( (const SvxSetItem&)rStyleSet.Get(ATTR_PAGE_HEADERSET) );
    1151           0 :                             aNewHeader.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aHeaderSize ) );
    1152           0 :                             rStyleSet.Put( aNewHeader );
    1153           0 :                             pDocShell->SetModified(true);
    1154           0 :                         }
    1155             :                     }
    1156           0 :                     else if( bFooterRulerMove && bFooterRulerChange )
    1157             :                     {
    1158           0 :                         const SfxPoolItem* pItem = NULL;
    1159           0 :                         if( rStyleSet.GetItemState( ATTR_PAGE_FOOTERSET, false, &pItem ) == SFX_ITEM_SET )
    1160             :                         {
    1161           0 :                             SfxItemSet& pFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
    1162           0 :                             Size aFooterSize = ((const SvxSizeItem&)pFooterSet.Get(ATTR_PAGE_SIZE)).GetSize();
    1163           0 :                             aFooterSize.Height() = (long)( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS - aULItem.GetLower() );
    1164           0 :                             aFooterSize.Height() = aFooterSize.Height() * 100 / mnScale;
    1165           0 :                             SvxSetItem  aNewFooter( (const SvxSetItem&)rStyleSet.Get(ATTR_PAGE_FOOTERSET) );
    1166           0 :                             aNewFooter.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aFooterSize ) );
    1167           0 :                             rStyleSet.Put( aNewFooter );
    1168           0 :                             pDocShell->SetModified(true);
    1169             :                         }
    1170             :                     }
    1171             : 
    1172           0 :                     ScStyleSaveData aNewData;
    1173           0 :                     aNewData.InitFromStyle( pStyleSheet );
    1174           0 :                     if( bUndo )
    1175             :                     {
    1176           0 :                         pDocShell->GetUndoManager()->AddUndoAction(
    1177             :                             new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
    1178           0 :                             aOldData, aNewData ) );
    1179             :                     }
    1180             : 
    1181           0 :                     if ( ValidTab( nTab ) )
    1182             :                     {
    1183           0 :                         ScPrintFunc aPrintFunc( this, pDocShell, nTab );
    1184           0 :                         aPrintFunc.UpdatePages();
    1185             :                     }
    1186             : 
    1187           0 :                     Rectangle  aRect(0,0,10000,10000);
    1188           0 :                     Paint( aRect );
    1189           0 :                     aModificator.SetDocumentModified();
    1190           0 :                     bTopRulerChange = false;
    1191           0 :                     bBottomRulerChange = false;
    1192           0 :                     bHeaderRulerChange = false;
    1193           0 :                     bFooterRulerChange = false;
    1194             :                  }
    1195             :               }
    1196           0 :               bTopRulerMove = false;
    1197           0 :               bBottomRulerMove = false;
    1198           0 :               bHeaderRulerMove = false;
    1199           0 :               bFooterRulerMove = false;
    1200             :         }
    1201           0 :         if( rMEvt.IsLeft() && GetPointer() == POINTER_HSPLIT )
    1202             :         {
    1203           0 :             SetPointer(POINTER_ARROW);
    1204           0 :             ScDocument* pDoc = pDocShell->GetDocument();
    1205           0 :             bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
    1206           0 :             bool bMoveRulerAction = true;
    1207           0 :             if( aButtonDownPt.X() == aButtonUpPt.X() )
    1208             :             {
    1209           0 :                 bMoveRulerAction = false;
    1210           0 :                 if( nColNumberButttonDown == aPageArea.aStart.Col() )
    1211           0 :                     DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,POINTER_HSPLIT );
    1212             :                 else
    1213           0 :                     DrawInvert( PixelToLogic( Point( nRight[ nColNumberButttonDown-1 ], 0 ),aMMMode ).X() ,POINTER_HSPLIT );
    1214           0 :                 DrawInvert( aButtonUpPt.X(), POINTER_HSPLIT );
    1215             :             }
    1216           0 :             if( bMoveRulerAction )
    1217             :             {
    1218           0 :                 long  nNewColWidth = 0;
    1219           0 :                 SCCOLROW nCols[2] = { nColNumberButttonDown, nColNumberButttonDown };
    1220             : 
    1221           0 :                 if( !bLayoutRTL )
    1222             :                 {
    1223           0 :                     nNewColWidth = (long) ( PixelToLogic( Point( rMEvt.GetPosPixel().X() - nRight[ nColNumberButttonDown ], 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
    1224           0 :                     nNewColWidth += pDocShell->GetDocument()->GetColWidth( nColNumberButttonDown, nTab );
    1225             :                 }
    1226             :                 else
    1227             :                 {
    1228             : 
    1229           0 :                     nNewColWidth = (long) ( PixelToLogic( Point( nRight[ nColNumberButttonDown ] - rMEvt.GetPosPixel().X(), 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
    1230           0 :                     nNewColWidth += pDocShell->GetDocument()->GetColWidth( nColNumberButttonDown, nTab );
    1231             :                 }
    1232             : 
    1233           0 :                 if( nNewColWidth >= 0 )
    1234             :                 {
    1235           0 :                     pDocShell->GetDocFunc().SetWidthOrHeight(
    1236             :                                                 true, 1,nCols, nTab, SC_SIZE_DIRECT,
    1237           0 :                                                 (sal_uInt16)nNewColWidth, true, true);
    1238           0 :                     pDocShell->SetModified(true);
    1239             :                 }
    1240           0 :                 if ( ValidTab( nTab ) )
    1241             :                 {
    1242           0 :                     ScPrintFunc aPrintFunc( this, pDocShell, nTab );
    1243           0 :                     aPrintFunc.UpdatePages();
    1244             :                 }
    1245           0 :                 Rectangle  nRect(0,0,10000,10000);
    1246           0 :                 Paint( nRect );
    1247             :             }
    1248           0 :             bColRulerMove = false;
    1249             :         }
    1250           0 :         ReleaseMouse();
    1251           0 : }
    1252             : 
    1253           0 : void ScPreview::MouseMove( const MouseEvent& rMEvt )
    1254             : {
    1255           0 :     Fraction aPreviewZoom( nZoom, 100 );
    1256           0 :     Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    1257           0 :     MapMode  aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
    1258           0 :     Point    aMouseMovePoint = PixelToLogic( rMEvt.GetPosPixel(), aMMMode );
    1259             : 
    1260           0 :     long    nLeftMargin = 0;
    1261           0 :     long    nRightMargin = 0;
    1262           0 :     long    nTopMargin = 0;
    1263           0 :     long    nBottomMargin = 0;
    1264             : 
    1265           0 :     long    nWidth = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Width();
    1266           0 :     long    nHeight = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Height();
    1267             : 
    1268           0 :     if ( nPageNo < nTotalPages )
    1269             :     {
    1270           0 :         ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
    1271             : 
    1272             :         ScPrintFunc* pPrintFunc;
    1273             : 
    1274           0 :         if (bStateValid)
    1275           0 :             pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
    1276             :         else
    1277           0 :             pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
    1278             : 
    1279           0 :         nLeftMargin = (long)( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
    1280           0 :         nRightMargin = (long)( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
    1281           0 :         nRightMargin = (long)( nWidth * HMM_PER_TWIPS - nRightMargin - aOffset.X() );
    1282           0 :         nTopMargin = (long)( pPrintFunc->GetTopMargin() * HMM_PER_TWIPS - aOffset.Y() );
    1283           0 :         nBottomMargin = (long)( pPrintFunc->GetBottomMargin() * HMM_PER_TWIPS );
    1284           0 :         nBottomMargin = (long)( nHeight * HMM_PER_TWIPS - nBottomMargin - aOffset.Y() );
    1285           0 :         if( mnScale > 0 )
    1286             :         {
    1287           0 :             nHeaderHeight = (long)( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS * mnScale / 100 );
    1288           0 :             nFooterHeight = (long)( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS * mnScale / 100 );
    1289             :         }
    1290             :         else
    1291             :         {
    1292           0 :             nHeaderHeight = (long)( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
    1293           0 :             nFooterHeight = (long)( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
    1294             :         }
    1295           0 :         delete pPrintFunc;
    1296             :     }
    1297             : 
    1298           0 :     Point   aPixPt( rMEvt.GetPosPixel() );
    1299           0 :     Point   aLeftTop = LogicToPixel( Point( nLeftMargin, -aOffset.Y() ) , aMMMode );
    1300           0 :     Point   aLeftBottom = LogicToPixel( Point( nLeftMargin ,(long)(nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
    1301           0 :     Point   aRightTop = LogicToPixel( Point( nRightMargin, -aOffset.Y() ), aMMMode );
    1302           0 :     Point   aTopLeft = LogicToPixel( Point( -aOffset.X(), nTopMargin ), aMMMode );
    1303           0 :     Point   aTopRight = LogicToPixel( Point( (long)(nWidth * HMM_PER_TWIPS - aOffset.X()), nTopMargin ), aMMMode );
    1304           0 :     Point   aBottomLeft = LogicToPixel( Point( -aOffset.X(), nBottomMargin ), aMMMode );
    1305           0 :     Point   aHeaderLeft = LogicToPixel( Point(  -aOffset.X(), nHeaderHeight ), aMMMode );
    1306           0 :     Point   aFooderLeft = LogicToPixel( Point( -aOffset.X(), nFooterHeight ), aMMMode );
    1307             : 
    1308           0 :     bool bOnColRulerChange = false;
    1309             : 
    1310           0 :     for( SCCOL i=aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
    1311             :     {
    1312           0 :         Point   aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
    1313           0 :         Point   aColumnBottom = LogicToPixel( Point( 0, (long)( nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
    1314           0 :         if( aPixPt.X() < ( nRight[i] + 2 ) && ( aPixPt.X() > ( nRight[i] - 2 ) ) && ( aPixPt.X() < aRightTop.X() ) && ( aPixPt.X() > aLeftTop.X() )
    1315           0 :             && ( aPixPt.Y() > aColumnTop.Y() ) && ( aPixPt.Y() < aColumnBottom.Y() ) && !bLeftRulerMove && !bRightRulerMove
    1316           0 :             && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
    1317             :         {
    1318           0 :             bOnColRulerChange = true;
    1319           0 :             if( !rMEvt.GetButtons() && GetPointer() == POINTER_HSPLIT )
    1320           0 :                 nColNumberButttonDown = i;
    1321           0 :             break;
    1322             :         }
    1323             :     }
    1324             : 
    1325           0 :     if( aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 ) && !bRightRulerMove )
    1326             :     {
    1327           0 :         bLeftRulerChange = true;
    1328           0 :         bRightRulerChange = false;
    1329             :     }
    1330           0 :     else if( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) && !bLeftRulerMove )
    1331             :     {
    1332           0 :         bLeftRulerChange = false;
    1333           0 :         bRightRulerChange = true;
    1334             :     }
    1335           0 :     else if( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
    1336             :     {
    1337           0 :         bTopRulerChange = true;
    1338           0 :         bBottomRulerChange = false;
    1339           0 :         bHeaderRulerChange = false;
    1340           0 :         bFooterRulerChange = false;
    1341             :     }
    1342           0 :     else if( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) && !bTopRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
    1343             :     {
    1344           0 :         bTopRulerChange = false;
    1345           0 :         bBottomRulerChange = true;
    1346           0 :         bHeaderRulerChange = false;
    1347           0 :         bFooterRulerChange = false;
    1348             :     }
    1349           0 :     else if( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bFooterRulerMove )
    1350             :     {
    1351           0 :         bTopRulerChange = false;
    1352           0 :         bBottomRulerChange = false;
    1353           0 :         bHeaderRulerChange = true;
    1354           0 :         bFooterRulerChange = false;
    1355             :     }
    1356           0 :     else if( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove )
    1357             :     {
    1358           0 :         bTopRulerChange = false;
    1359           0 :         bBottomRulerChange = false;
    1360           0 :         bHeaderRulerChange = false;
    1361           0 :         bFooterRulerChange = true;
    1362             :     }
    1363             : 
    1364           0 :     if( bPageMargin )
    1365             :     {
    1366           0 :         if(( (aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 )) || bLeftRulerMove ||
    1367           0 :             ( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) ) || bRightRulerMove || bOnColRulerChange || bColRulerMove )
    1368           0 :             && aPixPt.Y() > aLeftTop.Y() && aPixPt.Y() < aLeftBottom.Y() )
    1369             :         {
    1370           0 :             if( bOnColRulerChange || bColRulerMove )
    1371             :             {
    1372           0 :                 SetPointer( Pointer( POINTER_HSPLIT ) );
    1373           0 :                 if( bColRulerMove )
    1374             :                 {
    1375           0 :                     if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
    1376           0 :                        DragMove( aMouseMovePoint.X(), POINTER_HSPLIT );
    1377             :                 }
    1378             :             }
    1379             :             else
    1380             :             {
    1381           0 :                 if( bLeftRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
    1382             :                 {
    1383           0 :                     SetPointer( Pointer( POINTER_HSIZEBAR ) );
    1384           0 :                     if( bLeftRulerMove )
    1385             :                     {
    1386           0 :                        if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
    1387           0 :                            DragMove( aMouseMovePoint.X(), POINTER_HSIZEBAR );
    1388             :                     }
    1389             :                 }
    1390           0 :                 else if( bRightRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
    1391             :                 {
    1392           0 :                     SetPointer( Pointer( POINTER_HSIZEBAR ) );
    1393           0 :                     if( bRightRulerMove )
    1394             :                     {
    1395           0 :                        if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
    1396           0 :                            DragMove( aMouseMovePoint.X(), POINTER_HSIZEBAR );
    1397             :                     }
    1398             :                 }
    1399             :             }
    1400             :         }
    1401             :         else
    1402             :         {
    1403           0 :             if( ( ( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) ) || bTopRulerMove ||
    1404           0 :                 ( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) ) || bBottomRulerMove ||
    1405           0 :                 ( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) ) || bHeaderRulerMove ||
    1406           0 :                 ( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) ) || bFooterRulerMove )
    1407           0 :                 && aPixPt.X() > aTopLeft.X() && aPixPt.X() < aTopRight.X() )
    1408             :             {
    1409           0 :                 if( bTopRulerChange )
    1410             :                 {
    1411           0 :                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
    1412           0 :                     if( bTopRulerMove )
    1413             :                     {
    1414           0 :                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
    1415           0 :                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
    1416             :                     }
    1417             :                 }
    1418           0 :                 else if( bBottomRulerChange )
    1419             :                 {
    1420           0 :                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
    1421           0 :                     if( bBottomRulerMove )
    1422             :                     {
    1423           0 :                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
    1424           0 :                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
    1425             :                     }
    1426             :                 }
    1427           0 :                 else if( bHeaderRulerChange )
    1428             :                 {
    1429           0 :                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
    1430           0 :                     if( bHeaderRulerMove )
    1431             :                     {
    1432           0 :                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
    1433           0 :                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
    1434             :                     }
    1435             :                 }
    1436           0 :                 else if( bFooterRulerChange )
    1437             :                 {
    1438           0 :                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
    1439           0 :                     if( bFooterRulerMove )
    1440             :                     {
    1441           0 :                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
    1442           0 :                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
    1443             :                     }
    1444             :                 }
    1445             :             }
    1446             :             else
    1447           0 :                 SetPointer( Pointer( POINTER_ARROW ) );
    1448             :         }
    1449           0 :     }
    1450           0 : }
    1451             : 
    1452          47 : void ScPreview::InvalidateLocationData(sal_uLong nId)
    1453             : {
    1454          47 :     bLocationValid = false;
    1455          47 :     if (pViewShell->HasAccessibilityObjects())
    1456          15 :         pViewShell->BroadcastAccessibility( SfxSimpleHint( nId ) );
    1457          47 : }
    1458             : 
    1459           8 : void ScPreview::GetFocus()
    1460             : {
    1461           8 :     if (pViewShell->HasAccessibilityObjects())
    1462           0 :         pViewShell->BroadcastAccessibility( ScAccWinFocusGotHint(GetAccessible()) );
    1463           8 : }
    1464             : 
    1465           8 : void ScPreview::LoseFocus()
    1466             : {
    1467           8 :     if (pViewShell->HasAccessibilityObjects())
    1468           8 :         pViewShell->BroadcastAccessibility( ScAccWinFocusLostHint(GetAccessible()) );
    1469           8 : }
    1470             : 
    1471           8 : com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessible> ScPreview::CreateAccessible()
    1472             : {
    1473             :     ScAccessibleDocumentPagePreview* pAccessible =
    1474           8 :         new ScAccessibleDocumentPagePreview( GetAccessibleParentWindow()->GetAccessible(), pViewShell );
    1475           8 :     com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xAccessible = pAccessible;
    1476           8 :     pAccessible->Init();
    1477           8 :     return xAccessible;
    1478             : }
    1479             : 
    1480           0 : void ScPreview::DragMove( long nDragMovePos, sal_uInt16 nFlags )
    1481             : {
    1482           0 :     Fraction aPreviewZoom( nZoom, 100 );
    1483           0 :     Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    1484           0 :     MapMode  aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
    1485           0 :     SetMapMode( aMMMode );
    1486           0 :     long  nPos = nDragMovePos;
    1487           0 :     if( nFlags == POINTER_HSIZEBAR || nFlags == POINTER_HSPLIT )
    1488             :     {
    1489           0 :         if( nDragMovePos != aButtonDownChangePoint.X() )
    1490             :         {
    1491           0 :             DrawInvert( aButtonDownChangePoint.X(), nFlags );
    1492           0 :             aButtonDownChangePoint.X() = nPos;
    1493           0 :             DrawInvert( aButtonDownChangePoint.X(), nFlags );
    1494             :         }
    1495             :     }
    1496           0 :     else if( nFlags == POINTER_VSIZEBAR )
    1497             :     {
    1498           0 :         if( nDragMovePos != aButtonDownChangePoint.Y() )
    1499             :         {
    1500           0 :             DrawInvert( aButtonDownChangePoint.Y(), nFlags );
    1501           0 :             aButtonDownChangePoint.Y() = nPos;
    1502           0 :             DrawInvert( aButtonDownChangePoint.Y(), nFlags );
    1503             :         }
    1504           0 :     }
    1505           0 : }
    1506             : 
    1507           0 : void ScPreview::DrawInvert( long nDragPos, sal_uInt16 nFlags )
    1508             : {
    1509           0 :     long  nHeight = (long) lcl_GetDocPageSize( pDocShell->GetDocument(), nTab ).Height();
    1510           0 :     long  nWidth = (long) lcl_GetDocPageSize( pDocShell->GetDocument(), nTab ).Width();
    1511           0 :     if( nFlags == POINTER_HSIZEBAR || nFlags == POINTER_HSPLIT )
    1512             :     {
    1513           0 :         Rectangle aRect( nDragPos, -aOffset.Y(), nDragPos + 1,(long)( ( nHeight * HMM_PER_TWIPS ) - aOffset.Y()));
    1514           0 :         Invert( aRect,INVERT_50 );
    1515             :     }
    1516           0 :     else if( nFlags == POINTER_VSIZEBAR )
    1517             :     {
    1518           0 :         Rectangle aRect( -aOffset.X(), nDragPos,(long)( ( nWidth * HMM_PER_TWIPS ) - aOffset.X() ), nDragPos + 1 );
    1519           0 :         Invert( aRect,INVERT_50 );
    1520             :     }
    1521           0 : }
    1522             : 
    1523           8 : void ScPreview::SetSelectedTabs(const ScMarkData& rMark)
    1524             : {
    1525           8 :     maSelectedTabs = rMark.GetSelectedTabs();
    1526           8 : }
    1527             : 
    1528           0 : const ScMarkData::MarkedTabsType& ScPreview::GetSelectedTabs() const
    1529             : {
    1530           0 :     return maSelectedTabs;
    1531          93 : }
    1532             : 
    1533             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10