LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - prevwsh.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 301 639 47.1 %
Date: 2013-07-09 Functions: 35 52 67.3 %
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 <comphelper/string.hxx>
      22             : #include <editeng/eeitem.hxx>
      23             : 
      24             : #include <sfx2/app.hxx>
      25             : #include <editeng/sizeitem.hxx>
      26             : #include <svl/srchitem.hxx>
      27             : #include <svx/zoomslideritem.hxx>
      28             : #include <svx/svdview.hxx>
      29             : #include <sfx2/dispatch.hxx>
      30             : #include <sfx2/objface.hxx>
      31             : #include <sfx2/request.hxx>
      32             : #include <svl/stritem.hxx>
      33             : #include <svl/whiter.hxx>
      34             : #include <vcl/msgbox.hxx>
      35             : #include <vcl/help.hxx>
      36             : #include <tools/urlobj.hxx>
      37             : #include <sfx2/docfile.hxx>
      38             : #include <sfx2/printer.hxx>
      39             : 
      40             : #include "prevwsh.hxx"
      41             : #include "preview.hxx"
      42             : #include "printfun.hxx"
      43             : #include "attrib.hxx"
      44             : #include "scmod.hxx"
      45             : #include "inputhdl.hxx"
      46             : #include "docsh.hxx"
      47             : #include "tabvwsh.hxx"
      48             : #include "stlpool.hxx"
      49             : #include "editutil.hxx"
      50             : #include "scresid.hxx"
      51             : #include "globstr.hrc"
      52             : #include "sc.hrc"
      53             : #include "ViewSettingsSequenceDefines.hxx"
      54             : #include "tpprint.hxx"
      55             : #include "printopt.hxx"
      56             : #include "viewuno.hxx"
      57             : #include <sax/tools/converter.hxx>
      58             : #include <rtl/ustrbuf.hxx>
      59             : 
      60             : #include <svx/svxdlg.hxx>
      61             : #include <svx/dialogs.hrc>
      62             : 
      63             : #include <basegfx/tools/zoomtools.hxx>
      64             : #include <svx/zoom_def.hxx>
      65             : #include <com/sun/star/document/XDocumentProperties.hpp>
      66             : 
      67             : #include "scabstdlg.hxx"
      68             : //  for mouse wheel
      69             : #define MINZOOM_SLIDER 10
      70             : #define MAXZOOM_SLIDER 400
      71             : 
      72             : #define SC_USERDATA_SEP ';'
      73             : 
      74             : using namespace com::sun::star;
      75             : 
      76             : // -----------------------------------------------------------------------
      77             : 
      78             : #define ScPreviewShell
      79             : #include "scslots.hxx"
      80             : 
      81         408 : TYPEINIT1( ScPreviewShell, SfxViewShell );
      82             : 
      83        3099 : SFX_IMPL_INTERFACE( ScPreviewShell, SfxViewShell, ScResId(SCSTR_PREVIEWSHELL) )
      84             : {
      85          62 :     SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|
      86             :                                 SFX_VISIBILITY_SERVER|SFX_VISIBILITY_READONLYDOC,
      87          31 :                                 ScResId(RID_OBJECTBAR_PREVIEW));
      88          31 :     SFX_POPUPMENU_REGISTRATION(ScResId(RID_POPUP_PREVIEW));
      89          31 : }
      90             : 
      91          70 : SFX_IMPL_NAMED_VIEWFACTORY( ScPreviewShell, "PrintPreview" )
      92             : {
      93          31 :     SFX_VIEW_REGISTRATION(ScDocShell);
      94          31 : }
      95             : 
      96             : //------------------------------------------------------------------
      97             : 
      98           8 : void ScPreviewShell::Construct( Window* pParent )
      99             : {
     100             :     // Find the top-most window, and set the close window handler to intercept
     101             :     // the window close event.
     102           8 :     Window* pWin = pParent;
     103          32 :     while (!pWin->IsSystemWindow())
     104             :     {
     105          16 :         if (pWin->GetParent())
     106          16 :             pWin = pWin->GetParent();
     107             :         else
     108           0 :             break;
     109             :     }
     110             : 
     111           8 :     mpFrameWindow = dynamic_cast<SystemWindow*>(pWin);
     112           8 :     if (mpFrameWindow)
     113           8 :         mpFrameWindow->SetCloseHdl(LINK(this, ScPreviewShell, CloseHdl));
     114             : 
     115           8 :     eZoom = SVX_ZOOM_WHOLEPAGE;
     116             : 
     117           8 :     pCorner = new ScrollBarBox( pParent, WB_SIZEABLE );
     118             : 
     119           8 :     pHorScroll = new ScrollBar(pParent, WB_HSCROLL );
     120           8 :     pVerScroll = new ScrollBar(pParent, WB_VSCROLL);
     121             : 
     122             :     // SSA: --- RTL --- no mirroring for horizontal scrollbars
     123           8 :     pHorScroll->EnableRTL( false );
     124             : 
     125           8 :     pHorScroll->SetEndScrollHdl( LINK( this, ScPreviewShell, ScrollHandler ) );
     126           8 :     pVerScroll->SetEndScrollHdl( LINK( this, ScPreviewShell, ScrollHandler ) );
     127             : 
     128           8 :     pPreview = new ScPreview( pParent, pDocShell, this );
     129             : 
     130           8 :     SetPool( &SC_MOD()->GetPool() );
     131           8 :     SetWindow( pPreview );
     132           8 :     StartListening(*pDocShell,sal_True);
     133           8 :     StartListening(*SFX_APP(),sal_True);        // #i62045# #i62046# application is needed for Calc's own hints
     134           8 :     SfxBroadcaster* pDrawBC = pDocShell->GetDocument()->GetDrawBroadcaster();
     135           8 :     if (pDrawBC)
     136           8 :         StartListening(*pDrawBC);
     137             : 
     138           8 :     pHorScroll->Show( false );
     139           8 :     pVerScroll->Show( false );
     140           8 :     pCorner->Show();
     141           8 :     SetHelpId( HID_SCSHELL_PREVWSH );
     142           8 :     SetName(OUString("Preview"));
     143           8 : }
     144             : 
     145           8 : ScPreviewShell::ScPreviewShell( SfxViewFrame* pViewFrame,
     146             :                                 SfxViewShell* pOldSh ) :
     147             :     SfxViewShell( pViewFrame, SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ),
     148           8 :     pDocShell( (ScDocShell*)pViewFrame->GetObjectShell() ),
     149             :     mpFrameWindow(NULL),
     150             :     nSourceDesignMode( SC_FORCEMODE_NONE ),
     151          16 :     pAccessibilityBroadcaster( NULL )
     152             : {
     153           8 :     Construct( &pViewFrame->GetWindow() );
     154             : 
     155           8 :     if ( pOldSh && pOldSh->ISA( ScTabViewShell ) )
     156             :     {
     157             :         //  store view settings, show table from TabView
     158             :         //! store live ScViewData instead, and update on ScTablesHint?
     159             :         //! or completely forget aSourceData on ScTablesHint?
     160             : 
     161           8 :         ScTabViewShell* pTabViewShell = ((ScTabViewShell*)pOldSh);
     162           8 :         const ScViewData* pData = pTabViewShell->GetViewData();
     163           8 :         pData->WriteUserDataSequence( aSourceData );
     164           8 :         pPreview->SetSelectedTabs(pData->GetMarkData());
     165           8 :         InitStartTable( pData->GetTabNo() );
     166             : 
     167             :         //  also have to store the TabView's DesignMode state
     168             :         //  (only if draw view exists)
     169           8 :         SdrView* pDrawView = pTabViewShell->GetSdrView();
     170           8 :         if ( pDrawView )
     171           8 :             nSourceDesignMode = pDrawView->IsDesignMode();
     172             :     }
     173             : 
     174           8 :     new ScPreviewObj(this);
     175           8 : }
     176             : 
     177          24 : ScPreviewShell::~ScPreviewShell()
     178             : {
     179           8 :     if (mpFrameWindow)
     180           8 :         mpFrameWindow->SetCloseHdl(Link()); // Remove close handler.
     181             : 
     182             :     // #108333#; notify Accessibility that Shell is dying and before destroy all
     183           8 :     BroadcastAccessibility( SfxSimpleHint( SFX_HINT_DYING ) );
     184           8 :     DELETEZ(pAccessibilityBroadcaster);
     185             : 
     186           8 :     SfxBroadcaster* pDrawBC = pDocShell->GetDocument()->GetDrawBroadcaster();
     187           8 :     if (pDrawBC)
     188           8 :         EndListening(*pDrawBC);
     189           8 :     EndListening(*SFX_APP());
     190           8 :     EndListening(*pDocShell);
     191             : 
     192           8 :     SetWindow(0);
     193           8 :     delete pPreview;
     194           8 :     delete pHorScroll;
     195           8 :     delete pVerScroll;
     196           8 :     delete pCorner;
     197             : 
     198             :     //  normal mode of operation is switching back to default view in the same frame,
     199             :     //  so there's no need to activate any other window here anymore
     200          16 : }
     201             : 
     202           8 : void ScPreviewShell::InitStartTable(SCTAB nTab)
     203             : {
     204           8 :     pPreview->SetPageNo( pPreview->GetFirstPage(nTab) );
     205           8 : }
     206             : 
     207             : //------------------------------------------------------------------
     208             : 
     209           0 : String ScPreviewShell::GetDescription() const
     210             : {
     211           0 :     return OUString(" ** Test ** ");
     212             : }
     213             : 
     214           8 : void ScPreviewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
     215             : {
     216           8 :     Size aOutSize( rSize );
     217           8 :     pPreview->SetPosSizePixel( rPos, aOutSize );
     218             : 
     219           8 :     if ( SVX_ZOOM_WHOLEPAGE == eZoom )
     220           8 :         pPreview->SetZoom( pPreview->GetOptimalZoom(false) );
     221           0 :     else if ( SVX_ZOOM_PAGEWIDTH == eZoom )
     222           0 :         pPreview->SetZoom( pPreview->GetOptimalZoom(true) );
     223             : 
     224           8 :     UpdateNeededScrollBars();
     225           8 : }
     226             : 
     227           0 : void ScPreviewShell::InnerResizePixel( const Point &rOfs, const Size &rSize )
     228             : {
     229           0 :     AdjustPosSizePixel( rOfs,rSize );
     230           0 : }
     231             : 
     232           8 : void ScPreviewShell::OuterResizePixel( const Point &rOfs, const Size &rSize )
     233             : {
     234           8 :     AdjustPosSizePixel( rOfs,rSize );
     235           8 : }
     236             : 
     237          69 : bool ScPreviewShell::GetPageSize( Size& aPageSize )
     238             : {
     239          69 :     ScDocument* pDoc = pDocShell->GetDocument();
     240          69 :     SCTAB nTab = pPreview->GetTab();
     241             : 
     242          69 :     ScStyleSheetPool*   pStylePool  = pDoc->GetStyleSheetPool();
     243             :     SfxStyleSheetBase*  pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ),
     244          69 :                                                         SFX_STYLE_FAMILY_PAGE );
     245             :     OSL_ENSURE(pStyleSheet,"No style sheet");
     246          69 :     if (!pStyleSheet) return false;
     247          69 :     const SfxItemSet* pParamSet = &pStyleSheet->GetItemSet();
     248             : 
     249          69 :     aPageSize = ((const SvxSizeItem&) pParamSet->Get(ATTR_PAGE_SIZE)).GetSize();
     250          69 :     aPageSize.Width()  = (long) (aPageSize.Width()  * HMM_PER_TWIPS );
     251          69 :     aPageSize.Height() = (long) (aPageSize.Height() * HMM_PER_TWIPS );
     252          69 :     return true;
     253             : }
     254             : 
     255          18 : void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom )
     256             : {
     257          18 :     Size aPageSize;
     258          18 :     OutputDevice* pDevice = Application::GetDefaultDevice();
     259             : 
     260          18 :     long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
     261          18 :     long nBarH = nBarW;
     262             : 
     263          18 :     long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0;
     264          18 :     long aWidthOffSet = aHeightOffSet;
     265             : 
     266             : 
     267          18 :     if (!GetPageSize( aPageSize ))
     268          18 :         return;
     269             : 
     270             :     //  for centering, page size without the shadow is used
     271          18 :     bool bVert = pVerScroll ? pVerScroll->IsVisible() : false;
     272          18 :     bool bHori = pHorScroll ? pHorScroll->IsVisible() : false;
     273          18 :     Size aWindowSize = pPreview->GetOutputSize();
     274          18 :     Point aPos = pPreview->GetPosPixel();
     275          18 :     Size aWindowPixelSize = pPreview->GetOutputSizePixel();
     276             : 
     277             :     // if we are called from Zoom then we need to compensate for whatever
     278             :     // scrollbars were displayed before the zoom was called
     279          18 :     if ( bFromZoom )
     280             :     {
     281          10 :         if ( bVert )
     282             :         {
     283           1 :             aWindowPixelSize.Width() += nBarH;
     284           1 :             aWindowSize.Width() += aHeightOffSet;
     285             :         }
     286          10 :         if ( bHori )
     287             :         {
     288           0 :             aWindowPixelSize.Height() += nBarW;
     289           0 :             aWindowSize.Height() += aWidthOffSet;
     290             :         }
     291             :     }
     292             :     // recalculate any needed scrollbars
     293          18 :     bHori = false;
     294          18 :     bVert = false;
     295             : 
     296          18 :     long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width();
     297          18 :     if ( nMaxWidthPos<0 )
     298          18 :         bHori = false;
     299             :     else
     300           0 :         bHori = true;
     301             : 
     302          18 :     long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height();
     303             : 
     304          18 :     if ( nMaxHeightPos < 0 )
     305          16 :         bVert = false;
     306             :     else
     307           2 :         bVert = true;
     308             : 
     309             :     // see if having a scroll bar requires the other
     310          18 :     if ( bVert != bHori && ( bVert || bHori ) )
     311             :     {
     312           2 :         if ( bVert && ( (nMaxWidthPos + aWidthOffSet  ) > 0 ) )
     313           0 :             bHori = true;
     314           2 :         else if ( (nMaxHeightPos + aHeightOffSet ) > 0 )
     315           2 :             bVert = true;
     316             :     }
     317          18 :     pHorScroll->Show( bHori );
     318          18 :     pVerScroll->Show( bVert );
     319             : 
     320             :     // make room for needed scrollbars ( and reduce the size
     321             :     // of the preview appropriately )
     322          18 :     if ( bHori )
     323           0 :         aWindowPixelSize.Height() -= nBarW;
     324          18 :     if ( bVert )
     325           2 :         aWindowPixelSize.Width() -= nBarH;
     326             : 
     327          18 :     pPreview->SetSizePixel( aWindowPixelSize );
     328          54 :     pHorScroll->SetPosSizePixel( Point( aPos.X(), aPos.Y() + aWindowPixelSize.Height() ),
     329          72 :                                  Size( aWindowPixelSize.Width(), nBarH ) );
     330          54 :     pVerScroll->SetPosSizePixel( Point( aPos.X() + aWindowPixelSize.Width(), aPos.Y() ),
     331          72 :                                  Size( nBarW, aWindowPixelSize.Height() ) );
     332          72 :     pCorner->SetPosSizePixel( Point( aPos.X() + aWindowPixelSize.Width(), aPos.Y() + aWindowPixelSize.Height() ),
     333          90 :                               Size( nBarW, nBarH ) );
     334          18 :     UpdateScrollBars();
     335             : }
     336             : 
     337          51 : void ScPreviewShell::UpdateScrollBars()
     338             : {
     339          51 :     Size aPageSize;
     340          51 :     if ( !GetPageSize( aPageSize ) )
     341          51 :         return;
     342             : 
     343             :     //  for centering, page size without the shadow is used
     344             : 
     345          51 :     Size aWindowSize = pPreview->GetOutputSize();
     346             : 
     347          51 :     Point aOfs = pPreview->GetOffset();
     348             : 
     349          51 :     if( pHorScroll )
     350             :     {
     351          51 :         pHorScroll->SetRange( Range( 0, aPageSize.Width() ) );
     352          51 :         pHorScroll->SetLineSize( aWindowSize.Width() / 16 );
     353          51 :         pHorScroll->SetPageSize( aWindowSize.Width() );
     354          51 :         pHorScroll->SetVisibleSize( aWindowSize.Width() );
     355          51 :         long nMaxPos = aPageSize.Width() - aWindowSize.Width();
     356          51 :         if ( nMaxPos<0 )
     357             :         {
     358             :             //  page smaller than window -> center (but put scrollbar to 0)
     359          51 :             aOfs.X() = 0;
     360          51 :             pPreview->SetXOffset( nMaxPos / 2 );
     361             :         }
     362           0 :         else if (aOfs.X() < 0)
     363             :         {
     364             :             //  page larger than window -> never use negative offset
     365           0 :             aOfs.X() = 0;
     366           0 :             pPreview->SetXOffset( 0 );
     367             :         }
     368           0 :         else if (aOfs.X() > nMaxPos)
     369             :         {
     370             :             //  limit offset to align with right edge of window
     371           0 :             aOfs.X() = nMaxPos;
     372           0 :             pPreview->SetXOffset(nMaxPos);
     373             :         }
     374          51 :         pHorScroll->SetThumbPos( aOfs.X() );
     375             :     }
     376             : 
     377          51 :     if( pVerScroll )
     378             :     {
     379          51 :         long nPageNo     = pPreview->GetPageNo();
     380          51 :         long nTotalPages = pPreview->GetTotalPages();
     381             : 
     382          51 :         nMaxVertPos = aPageSize.Height() - aWindowSize.Height();
     383          51 :         pVerScroll->SetLineSize( aWindowSize.Height() / 16  );
     384          51 :         pVerScroll->SetPageSize( aWindowSize.Height() );
     385          51 :         pVerScroll->SetVisibleSize( aWindowSize.Height() );
     386          51 :         if ( nMaxVertPos < 0 )
     387             :         {
     388             :             //  page smaller than window -> center (but put scrollbar to 0)
     389          44 :             aOfs.Y() = 0;
     390          44 :             pPreview->SetYOffset( nMaxVertPos / 2 );
     391          44 :             pVerScroll->SetThumbPos( nPageNo * aWindowSize.Height() );
     392          44 :             pVerScroll->SetRange( Range( 0, aWindowSize.Height() * nTotalPages ));
     393             :         }
     394           7 :         else if (aOfs.Y() < 0)
     395             :         {
     396             :             //  page larger than window -> never use negative offset
     397           2 :             pVerScroll->SetRange( Range( 0, aPageSize.Height() ) );
     398           2 :             aOfs.Y() = 0;
     399           2 :             pPreview->SetYOffset( 0 );
     400           2 :             pVerScroll->SetThumbPos( aOfs.Y() );
     401             :         }
     402           5 :         else if (aOfs.Y() > nMaxVertPos )
     403             :         {
     404             :             //  limit offset to align with window bottom
     405           0 :             pVerScroll->SetRange( Range( 0, aPageSize.Height() ) );
     406           0 :             aOfs.Y() = nMaxVertPos;
     407           0 :             pPreview->SetYOffset( nMaxVertPos );
     408           0 :             pVerScroll->SetThumbPos( aOfs.Y() );
     409             :         }
     410             :     }
     411             : }
     412             : 
     413           0 : IMPL_LINK (ScPreviewShell,ScrollHandler, ScrollBar* ,pScroll )
     414             : {
     415           0 :     long nPos           = pScroll->GetThumbPos();
     416           0 :     long nDelta         = pScroll->GetDelta();
     417           0 :     long nMaxRange      = pScroll->GetRangeMax();
     418           0 :     long nTotalPages    = pPreview->GetTotalPages();
     419           0 :     long nPageNo        = 0;
     420           0 :     long nPerPageLength = 0;
     421           0 :     sal_Bool bIsDivide      = sal_True;
     422             : 
     423           0 :     if( nTotalPages )
     424           0 :         nPerPageLength = nMaxRange / nTotalPages;
     425             : 
     426           0 :     if( nPerPageLength )
     427             :     {
     428           0 :         nPageNo = nPos / nPerPageLength;
     429           0 :         if( nPos % nPerPageLength )
     430             :         {
     431           0 :             bIsDivide = false;
     432           0 :             nPageNo ++;
     433             :         }
     434             :     }
     435             : 
     436           0 :     sal_Bool bHoriz = ( pScroll == pHorScroll );
     437             : 
     438           0 :     if( bHoriz )
     439           0 :         pPreview->SetXOffset( nPos );
     440             :     else
     441             :     {
     442           0 :         if( nMaxVertPos > 0 )
     443           0 :             pPreview->SetYOffset( nPos );
     444             :         else
     445             :         {
     446           0 :             Point  aMousePos = pScroll->OutputToNormalizedScreenPixel( pScroll->GetPointerPosPixel() );
     447           0 :             Point  aPos      = pScroll->GetParent()->OutputToNormalizedScreenPixel( pScroll->GetPosPixel() );
     448           0 :             OUString aHelpStr;
     449           0 :             Rectangle aRect;
     450             :             sal_uInt16   nAlign;
     451             : 
     452           0 :             if( nDelta < 0 )
     453             :             {
     454           0 :                 if ( nTotalPages && nPageNo > 0 && !bIsDivide )
     455           0 :                     pPreview->SetPageNo( nPageNo-1 );
     456           0 :                 if( bIsDivide )
     457           0 :                     pPreview->SetPageNo( nPageNo );
     458             : 
     459           0 :                 aHelpStr = ScGlobal::GetRscString( STR_PAGE ) +
     460           0 :                            " " + OUString::number( nPageNo ) +
     461           0 :                            " / "  + OUString::number( nTotalPages );
     462             :             }
     463           0 :             else if( nDelta > 0 )
     464             :             {
     465           0 :                 sal_Bool bAllTested = pPreview->AllTested();
     466           0 :                 if ( nTotalPages && ( nPageNo < nTotalPages || !bAllTested ) )
     467           0 :                     pPreview->SetPageNo( nPageNo );
     468             : 
     469           0 :                 aHelpStr = ScGlobal::GetRscString( STR_PAGE ) +
     470           0 :                            " " + OUString::number( nPageNo+1 ) +
     471           0 :                            " / "  + OUString::number( nTotalPages );
     472             :             }
     473             : 
     474           0 :             aRect.Left()    = aPos.X() - 8;
     475           0 :             aRect.Top()     = aMousePos.Y();
     476           0 :             aRect.Right()   = aRect.Left();
     477           0 :             aRect.Top()     = aRect.Top();
     478           0 :             nAlign          = QUICKHELP_BOTTOM|QUICKHELP_CENTER;
     479           0 :             Help::ShowQuickHelp( pScroll->GetParent(), aRect, aHelpStr, nAlign );
     480             :         }
     481             :     }
     482             : 
     483           0 :     return 0;
     484             : }
     485             : 
     486           0 : IMPL_LINK (ScPreviewShell, CloseHdl, SystemWindow*, EMPTYARG)
     487             : {
     488           0 :     ExitPreview();
     489           0 :     return 0;
     490             : }
     491             : 
     492           0 : sal_Bool ScPreviewShell::ScrollCommand( const CommandEvent& rCEvt )
     493             : {
     494           0 :     sal_Bool bDone = false;
     495           0 :     const CommandWheelData* pData = rCEvt.GetWheelData();
     496           0 :     if ( pData && pData->GetMode() == COMMAND_WHEEL_ZOOM )
     497             :     {
     498           0 :         long nOld = pPreview->GetZoom();
     499           0 :         long nNew = nOld;
     500           0 :         if ( pData->GetDelta() < 0 )
     501           0 :             nNew = std::max( (long) MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
     502             :         else
     503           0 :             nNew = std::min( (long) MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
     504             : 
     505           0 :         if ( nNew != nOld )
     506             :         {
     507           0 :             eZoom = SVX_ZOOM_PERCENT;
     508           0 :             pPreview->SetZoom( (sal_uInt16)nNew );
     509             :         }
     510             : 
     511           0 :         bDone = sal_True;
     512             :     }
     513             :     else
     514             :     {
     515           0 :         bDone = pPreview->HandleScrollCommand( rCEvt, pHorScroll, pVerScroll );
     516             :     }
     517             : 
     518           0 :     return bDone;
     519             : }
     520             : 
     521          30 : SfxPrinter* ScPreviewShell::GetPrinter( sal_Bool bCreate )
     522             : {
     523          30 :     return pDocShell->GetPrinter(bCreate);
     524             : }
     525             : 
     526           0 : sal_uInt16 ScPreviewShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
     527             : {
     528           0 :     return pDocShell->SetPrinter( pNewPrinter, nDiffFlags );
     529             : }
     530             : 
     531           0 : bool ScPreviewShell::HasPrintOptionsPage() const
     532             : {
     533           0 :     return true;
     534             : }
     535             : 
     536           0 : SfxTabPage* ScPreviewShell::CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions )
     537             : {
     538           0 :     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     539             :     OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
     540           0 :     ::CreateTabPage ScTpPrintOptionsCreate =    pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
     541           0 :     if ( ScTpPrintOptionsCreate )
     542           0 :         return  (*ScTpPrintOptionsCreate)( pParent, rOptions);
     543           0 :     return 0;
     544             : }
     545             : 
     546           8 : void ScPreviewShell::Activate(sal_Bool bMDI)
     547             : {
     548           8 :     SfxViewShell::Activate(bMDI);
     549             : 
     550             :     //! Basic etc. -> auslagern in eigene Datei (s. tabvwsh4)
     551             : 
     552           8 :     if (bMDI)
     553             :     {
     554             :         // InputHdl ist jetzt meistens Null, keine Assertion mehr!
     555           8 :         ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
     556           8 :         if ( pInputHdl )
     557           0 :             pInputHdl->NotifyChange( NULL );
     558             :     }
     559           8 : }
     560             : 
     561           8 : void ScPreviewShell::Deactivate(sal_Bool bMDI)
     562             : {
     563           8 :     SfxViewShell::Deactivate(bMDI);
     564             : 
     565             :     if (bMDI)
     566             :     {
     567             :     }
     568           8 : }
     569             : 
     570             : //------------------------------------------------------------------------
     571             : 
     572           2 : void ScPreviewShell::Execute( SfxRequest& rReq )
     573             : {
     574           2 :     sal_uInt16 nSlot = rReq.GetSlot();
     575           2 :     const SfxItemSet* pReqArgs = rReq.GetArgs();
     576             : 
     577           2 :     switch ( nSlot )
     578             :     {
     579             :         case SID_FORMATPAGE:
     580             :         case SID_STATUS_PAGESTYLE:
     581             :         case SID_HFEDIT:
     582           0 :             pDocShell->ExecutePageStyle( *this, rReq, pPreview->GetTab() );
     583           0 :             break;
     584             :         case SID_REPAINT:
     585           0 :             pPreview->Invalidate();
     586           0 :             rReq.Done();
     587           0 :             break;
     588             :         case SID_PREV_TABLE: // Accelerator
     589             :         case SID_PREVIEW_PREVIOUS:
     590             :             {
     591           0 :                 long nPage = pPreview->GetPageNo();
     592           0 :                 long nTotal = pPreview->GetTotalPages();
     593           0 :                 if (nTotal && nPage > 0)
     594           0 :                     pPreview->SetPageNo( nPage-1 );
     595             :             }
     596           0 :             break;
     597             :         case SID_NEXT_TABLE: // Accelerator
     598             :         case SID_PREVIEW_NEXT:
     599             :             {
     600           0 :                 sal_Bool bAllTested = pPreview->AllTested();
     601           0 :                 long nPage = pPreview->GetPageNo();
     602           0 :                 long nTotal = pPreview->GetTotalPages();
     603           0 :                 if (nTotal && (nPage+1 < nTotal || !bAllTested))
     604           0 :                     pPreview->SetPageNo( nPage+1 );
     605             :             }
     606           0 :             break;
     607             :         case SID_CURSORTOPOFFILE: // Accelerator
     608             :         case SID_PREVIEW_FIRST:
     609             :             {
     610           0 :                 long nPage = pPreview->GetPageNo();
     611           0 :                 long nTotal = pPreview->GetTotalPages();
     612           0 :                 if (nTotal && nPage != 0)
     613           0 :                     pPreview->SetPageNo( 0 );
     614             :             }
     615           0 :             break;
     616             :         case SID_CURSORENDOFFILE: // Accelerator
     617             :         case SID_PREVIEW_LAST:
     618             :             {
     619           0 :                 if (!pPreview->AllTested())
     620           0 :                     pPreview->CalcAll();
     621             : 
     622           0 :                 long nPage = pPreview->GetPageNo();
     623           0 :                 long nTotal = pPreview->GetTotalPages();
     624           0 :                 if (nTotal && nPage+1 != nTotal)
     625           0 :                     pPreview->SetPageNo( nTotal-1 );
     626             :             }
     627           0 :             break;
     628             :         case SID_ATTR_ZOOM:
     629             :         case FID_SCALE:
     630             :             {
     631           0 :                 sal_uInt16      nZoom       = 100;
     632           0 :                 sal_Bool        bCancel     = false;
     633             : 
     634           0 :                 eZoom = SVX_ZOOM_PERCENT;
     635             : 
     636           0 :                 if ( pReqArgs )
     637             :                 {
     638             : 
     639             :                     const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
     640           0 :                                                    pReqArgs->Get(SID_ATTR_ZOOM);
     641             : 
     642           0 :                     eZoom = rZoomItem.GetType();
     643           0 :                     nZoom = rZoomItem.GetValue();
     644             :                 }
     645             :                 else
     646             :                 {
     647           0 :                     SfxItemSet      aSet     ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
     648           0 :                     SvxZoomItem     aZoomItem( SVX_ZOOM_PERCENT, pPreview->GetZoom(), SID_ATTR_ZOOM );
     649             : 
     650           0 :                     aSet.Put( aZoomItem );
     651           0 :                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     652           0 :                     if(pFact)
     653             :                     {
     654           0 :                         AbstractSvxZoomDialog* pDlg = pFact->CreateSvxZoomDialog(NULL, aSet);
     655             :                         OSL_ENSURE(pDlg, "Dialogdiet fail!");
     656           0 :                         pDlg->SetLimits( 20, 400 );
     657           0 :                         pDlg->HideButton( ZOOMBTN_OPTIMAL );
     658           0 :                         bCancel = ( RET_CANCEL == pDlg->Execute() );
     659             : 
     660           0 :                         if ( !bCancel )
     661             :                         {
     662             :                             const SvxZoomItem&  rZoomItem = (const SvxZoomItem&)
     663           0 :                                                     pDlg->GetOutputItemSet()->
     664           0 :                                                         Get( SID_ATTR_ZOOM );
     665             : 
     666           0 :                             eZoom = rZoomItem.GetType();
     667           0 :                             nZoom = rZoomItem.GetValue();
     668             :                         }
     669             : 
     670           0 :                         delete pDlg;
     671           0 :                     }
     672             :                 }
     673             : 
     674           0 :                 if ( !bCancel )
     675             :                 {
     676           0 :                     switch ( eZoom )
     677             :                     {
     678             :                         case SVX_ZOOM_OPTIMAL:
     679             :                         case SVX_ZOOM_WHOLEPAGE:
     680           0 :                             nZoom = pPreview->GetOptimalZoom(false);
     681           0 :                             break;
     682             :                         case SVX_ZOOM_PAGEWIDTH:
     683           0 :                             nZoom = pPreview->GetOptimalZoom(sal_True);
     684           0 :                             break;
     685             :                         default:
     686             :                         {
     687             :                             // added to avoid warnings
     688             :                         }
     689             :                     }
     690             : 
     691           0 :                     pPreview->SetZoom( nZoom );
     692           0 :                     rReq.Done();
     693             :                 }
     694             :             }
     695           0 :             break;
     696             :         case SID_PREVIEW_ZOOMIN:
     697             :             {
     698           2 :                 sal_uInt16 nNew = pPreview->GetZoom() + 20 ;
     699           2 :                 nNew -= nNew % 20;
     700           2 :                 pPreview->SetZoom( nNew );
     701           2 :                 eZoom = SVX_ZOOM_PERCENT;
     702           2 :                 rReq.Done();
     703             :             }
     704           2 :             break;
     705             :         case SID_PREVIEW_ZOOMOUT:
     706             :             {
     707           0 :                 sal_uInt16 nNew = pPreview->GetZoom() - 1;
     708           0 :                 nNew -= nNew % 20;
     709           0 :                 pPreview->SetZoom( nNew );
     710           0 :                 eZoom = SVX_ZOOM_PERCENT;
     711           0 :                 rReq.Done();
     712             :             }
     713           0 :             break;
     714             :         case SID_PREVIEW_MARGIN:
     715             :             {
     716           0 :                 sal_Bool bMargin = pPreview->GetPageMargins();
     717           0 :                 pPreview->SetPageMargins( !bMargin );
     718           0 :                 pPreview->Invalidate();
     719           0 :                 rReq.Done();
     720             :             }
     721           0 :             break;
     722             :         case SID_ATTR_ZOOMSLIDER:
     723             :             {
     724             :                 const SfxPoolItem* pItem;
     725           0 :                 eZoom = SVX_ZOOM_PERCENT;
     726           0 :                 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_ZOOMSLIDER, sal_True, &pItem ) )
     727             :                 {
     728           0 :                     const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem*)pItem)->GetValue();
     729           0 :                     if( nCurrentZoom )
     730             :                     {
     731           0 :                         pPreview->SetZoom( nCurrentZoom );
     732           0 :                         rReq.Done();
     733             :                     }
     734             :                 }
     735             :             }
     736           0 :             break;
     737             :         case SID_PREVIEW_SCALINGFACTOR:
     738             :             {
     739             :                 const SfxPoolItem* pItem;
     740           0 :                 SCTAB nTab                      = pPreview->GetTab();
     741           0 :                 String aOldName                 = pDocShell->GetDocument()->GetPageStyle( pPreview->GetTab() );
     742           0 :                 ScStyleSheetPool* pStylePool    = pDocShell->GetDocument()->GetStyleSheetPool();
     743           0 :                 SfxStyleSheetBase* pStyleSheet  = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
     744             :                 OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
     745             : 
     746           0 :                 if ( pReqArgs && pStyleSheet && SFX_ITEM_SET == pReqArgs->GetItemState( SID_PREVIEW_SCALINGFACTOR, sal_True, &pItem ) )
     747             :                 {
     748           0 :                     const sal_uInt16 nCurrentZoom   = ((const SvxZoomSliderItem *)pItem)->GetValue();
     749           0 :                     SfxItemSet& rSet            = pStyleSheet->GetItemSet();
     750           0 :                     rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nCurrentZoom ) );
     751           0 :                     ScPrintFunc aPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab );
     752           0 :                     aPrintFunc.UpdatePages();
     753           0 :                     rReq.Done();
     754             :                 }
     755           0 :                 GetViewFrame()->GetBindings().Invalidate( nSlot );
     756             :             }
     757           0 :             break;
     758             :         case SID_PRINTPREVIEW:
     759             :         case SID_PREVIEW_CLOSE:
     760             :             //  print preview is now always in the same frame as the tab view
     761             :             //  -> always switch this frame back to normal view
     762             :             //  (ScTabViewShell ctor reads stored view data)
     763             : 
     764           0 :             ExitPreview();
     765           0 :             break;
     766             :         case SID_CURSORPAGEUP:
     767             :         case SID_CURSORPAGEDOWN:
     768             :         case SID_CURSORHOME:
     769             :         case SID_CURSOREND:
     770             :         case SID_CURSORUP:
     771             :         case SID_CURSORDOWN:
     772             :         case SID_CURSORLEFT:
     773             :         case SID_CURSORRIGHT:
     774           0 :             DoScroll( nSlot );
     775           0 :             break;
     776             :         case SID_CANCEL:
     777           0 :             if( ScViewUtil::IsFullScreen( *this ) )
     778           0 :                 ScViewUtil::SetFullScreen( *this, false );
     779           0 :             break;
     780             : 
     781             :         default:
     782           0 :             break;
     783             :     }
     784           2 : }
     785             : 
     786         196 : void ScPreviewShell::GetState( SfxItemSet& rSet )
     787             : {
     788         196 :     pPreview->SetInGetState(sal_True);
     789             : 
     790         196 :     SCTAB nTab      = pPreview->GetTab();
     791         196 :     long nPage      = pPreview->GetPageNo();
     792         196 :     long nTotal     = pPreview->GetTotalPages();
     793         196 :     sal_uInt16 nZoom    = pPreview->GetZoom();
     794         196 :     sal_Bool bAllTested = pPreview->AllTested();
     795             : 
     796         196 :     SfxWhichIter aIter(rSet);
     797         196 :     sal_uInt16 nWhich = aIter.FirstWhich();
     798         754 :     while ( nWhich )
     799             :     {
     800         362 :         switch (nWhich)
     801             :         {
     802             :             case SID_STATUS_PAGESTYLE:
     803             :             case SID_HFEDIT:
     804          32 :                 pDocShell->GetStatePageStyle( *this, rSet, nTab );
     805          32 :                 break;
     806             :             case SID_UNDO:
     807             :             case SID_REDO:
     808             :             case SID_REPEAT:
     809             :             case SID_SAVEDOC:
     810             :             case SID_SAVEASDOC:
     811             :             case SID_MAIL_SENDDOC:
     812             :             case SID_VIEW_DATA_SOURCE_BROWSER:
     813             :             case SID_QUITAPP:
     814          84 :                 rSet.DisableItem(nWhich);
     815          84 :                 break;
     816             :             case SID_PREVIEW_PREVIOUS:
     817             :             case SID_PREVIEW_FIRST:
     818          36 :                 if (!nTotal || nPage==0)
     819          36 :                     rSet.DisableItem(nWhich);
     820          36 :                 break;
     821             :             case SID_PREVIEW_NEXT:
     822             :             case SID_PREVIEW_LAST:
     823          36 :                 if (bAllTested)
     824          36 :                     if (!nTotal || nPage==nTotal-1)
     825          36 :                         rSet.DisableItem(nWhich);
     826          36 :                 break;
     827             :             case SID_PREVIEW_ZOOMIN:
     828          20 :                 if (nZoom >= 400)
     829           0 :                     rSet.DisableItem(nWhich);
     830          20 :                 break;
     831             :             case SID_PREVIEW_ZOOMOUT:
     832          18 :                 if (nZoom <= 20)
     833           0 :                     rSet.DisableItem(nWhich);
     834          18 :                 break;
     835             :             case SID_ATTR_ZOOM:
     836             :                 {
     837          26 :                     SvxZoomItem aZoom( eZoom, nZoom, nWhich );
     838          26 :                     aZoom.SetValueSet( SVX_ZOOM_ENABLE_ALL & ~SVX_ZOOM_ENABLE_OPTIMAL );
     839          26 :                     rSet.Put( aZoom );
     840             :                 }
     841          26 :                 break;
     842             :             case SID_ATTR_ZOOMSLIDER:
     843             :                 {
     844          18 :                     SvxZoomSliderItem aZoomSliderItem( nZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
     845          18 :                     aZoomSliderItem.AddSnappingPoint( 100 );
     846          18 :                     rSet.Put( aZoomSliderItem );
     847             :                 }
     848          18 :                 break;
     849             :             case SID_PREVIEW_SCALINGFACTOR:
     850             :                 {
     851          18 :                     if( pDocShell->IsReadOnly() )
     852           0 :                         rSet.DisableItem( nWhich );
     853             :                     else
     854             :                     {
     855          18 :                         String aOldName                 = pDocShell->GetDocument()->GetPageStyle( pPreview->GetTab() );
     856          18 :                         ScStyleSheetPool* pStylePool    = pDocShell->GetDocument()->GetStyleSheetPool();
     857          18 :                         SfxStyleSheetBase* pStyleSheet  = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
     858             :                         OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
     859             : 
     860          18 :                         if ( pStyleSheet )
     861             :                         {
     862          18 :                             SfxItemSet& rStyleSet   = pStyleSheet->GetItemSet();
     863          18 :                             sal_uInt16 nCurrentZoom     = ((const SfxUInt16Item&)rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
     864          18 :                             if( nCurrentZoom )
     865             :                             {
     866          18 :                                 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM_SLIDER, MAXZOOM_SLIDER, SID_PREVIEW_SCALINGFACTOR );
     867          18 :                                 aZoomSliderItem.AddSnappingPoint( 100 );
     868          18 :                                 rSet.Put( aZoomSliderItem );
     869             :                             }
     870             :                             else
     871           0 :                                 rSet.DisableItem( nWhich );
     872          18 :                         }
     873             :                     }
     874             :                 }
     875          18 :                 break;
     876             :             case SID_STATUS_DOCPOS:
     877          18 :                 rSet.Put( SfxStringItem( nWhich, pPreview->GetPosString() ) );
     878          18 :                 break;
     879             :             case SID_PRINTPREVIEW:
     880          14 :                 rSet.Put( SfxBoolItem( nWhich, sal_True ) );
     881          14 :                 break;
     882             :             case SID_FORMATPAGE:
     883             :             case SID_PREVIEW_MARGIN:
     884          28 :                 if( pDocShell->IsReadOnly() )
     885           0 :                     rSet.DisableItem( nWhich );
     886          28 :                 break;
     887             :         }
     888             : 
     889         362 :         nWhich = aIter.NextWhich();
     890             :     }
     891             : 
     892         196 :     pPreview->SetInGetState(false);
     893         196 : }
     894             : 
     895          10 : void ScPreviewShell::FillFieldData( ScHeaderFieldData& rData )
     896             : {
     897          10 :     ScDocument* pDoc = pDocShell->GetDocument();
     898          10 :     SCTAB nTab = pPreview->GetTab();
     899          10 :     OUString aTmp;
     900          10 :     pDoc->GetName(nTab, aTmp);
     901          10 :     rData.aTabName = aTmp;
     902             : 
     903          10 :     if( pDocShell->getDocProperties()->getTitle().getLength() != 0 )
     904           0 :         rData.aTitle = pDocShell->getDocProperties()->getTitle();
     905             :     else
     906          10 :         rData.aTitle = pDocShell->GetTitle();
     907             : 
     908          10 :     const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
     909          10 :     rData.aLongDocName  = rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
     910          10 :     if ( rData.aLongDocName.Len() )
     911           0 :         rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS );
     912             :     else
     913          10 :         rData.aShortDocName = rData.aLongDocName = rData.aTitle;
     914          10 :     rData.nPageNo       = pPreview->GetPageNo() + 1;
     915             : 
     916          10 :     sal_Bool bAllTested = pPreview->AllTested();
     917          10 :     if (bAllTested)
     918          10 :         rData.nTotalPages = pPreview->GetTotalPages();
     919             :     else
     920           0 :         rData.nTotalPages = 99;
     921             : 
     922             :     //  the dialog knows eNumType
     923          10 : }
     924             : 
     925           0 : void ScPreviewShell::WriteUserData(String& rData, sal_Bool /* bBrowse */)
     926             : {
     927             :     //  nZoom
     928             :     //  nPageNo
     929             : 
     930           0 :     rData =  OUString::number(pPreview->GetZoom());
     931           0 :     rData += (sal_Unicode) SC_USERDATA_SEP;
     932           0 :     rData += OUString::number(pPreview->GetPageNo());
     933           0 : }
     934             : 
     935           0 : void ScPreviewShell::ReadUserData(const String& rData, sal_Bool /* bBrowse */)
     936             : {
     937           0 :     xub_StrLen nCount = comphelper::string::getTokenCount(rData, ';');
     938           0 :     if (nCount)
     939             :     {
     940           0 :         sal_Int32 nIndex = 0;
     941           0 :         pPreview->SetZoom((sal_uInt16)rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32());
     942           0 :         pPreview->SetPageNo(rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32());
     943           0 :         eZoom = SVX_ZOOM_PERCENT;
     944             :     }
     945           0 : }
     946             : 
     947           0 : void ScPreviewShell::WriteUserDataSequence(uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */)
     948             : {
     949           0 :     rSeq.realloc(3);
     950           0 :     beans::PropertyValue* pSeq = rSeq.getArray();
     951           0 :     if(pSeq)
     952             :     {
     953           0 :         sal_uInt16 nViewID(GetViewFrame()->GetCurViewId());
     954           0 :         pSeq[0].Name = OUString(SC_VIEWID);
     955           0 :         OUStringBuffer sBuffer(OUString(SC_VIEW));
     956             :         ::sax::Converter::convertNumber(sBuffer,
     957           0 :                 static_cast<sal_Int32>(nViewID));
     958           0 :         pSeq[0].Value <<= sBuffer.makeStringAndClear();
     959           0 :         pSeq[1].Name = OUString(SC_ZOOMVALUE);
     960           0 :         pSeq[1].Value <<= sal_Int32 (pPreview->GetZoom());
     961           0 :         pSeq[2].Name = OUString("PageNumber");
     962           0 :         pSeq[2].Value <<= pPreview->GetPageNo();
     963             :     }
     964           0 : }
     965             : 
     966           8 : void ScPreviewShell::ReadUserDataSequence(const uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */)
     967             : {
     968           8 :     sal_Int32 nCount(rSeq.getLength());
     969           8 :     if (nCount)
     970             :     {
     971           8 :         const beans::PropertyValue* pSeq = rSeq.getConstArray();
     972           8 :         if(pSeq)
     973             :         {
     974         192 :             for(sal_Int32 i = 0; i < nCount; i++, pSeq++)
     975             :             {
     976         184 :                 OUString sName(pSeq->Name);
     977         184 :                 if(sName.compareToAscii(SC_ZOOMVALUE) == 0)
     978             :                 {
     979           8 :                     sal_Int32 nTemp = 0;
     980           8 :                     if (pSeq->Value >>= nTemp)
     981           8 :                         pPreview->SetZoom(sal_uInt16(nTemp));
     982             :                 }
     983         176 :                 else if (sName.compareToAscii("PageNumber") == 0)
     984             :                 {
     985           0 :                     sal_Int32 nTemp = 0;
     986           0 :                     if (pSeq->Value >>= nTemp)
     987           0 :                         pPreview->SetPageNo(nTemp);
     988             :                 }
     989         184 :             }
     990             :         }
     991             :     }
     992           8 : }
     993             : 
     994           0 : void ScPreviewShell::DoScroll( sal_uInt16 nMode )
     995             : {
     996           0 :     Point   aCurPos, aPrevPos;
     997             : 
     998           0 :     long nHRange    = pHorScroll->GetRange().Max();
     999           0 :     long nHLine     = pHorScroll->GetLineSize();
    1000           0 :     long nHPage     = pHorScroll->GetPageSize();
    1001           0 :     long nVRange    = pVerScroll->GetRange().Max();
    1002           0 :     long nVLine     = pVerScroll->GetLineSize();
    1003           0 :     long nVPage     = pVerScroll->GetPageSize();
    1004             : 
    1005           0 :     aCurPos.X() = pHorScroll->GetThumbPos();
    1006           0 :     aCurPos.Y() = pVerScroll->GetThumbPos();
    1007           0 :     aPrevPos = aCurPos;
    1008             : 
    1009           0 :     long nThumbPos  = pVerScroll->GetThumbPos();
    1010           0 :     long nRangeMax  = pVerScroll->GetRangeMax();
    1011             : 
    1012           0 :     switch( nMode )
    1013             :     {
    1014             :         case SID_CURSORUP:
    1015           0 :             if( nMaxVertPos<0 )
    1016             :             {
    1017           0 :                 long nPage = pPreview->GetPageNo();
    1018             : 
    1019           0 :                 if( nPage>0 )
    1020             :                 {
    1021           0 :                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
    1022           0 :                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
    1023           0 :                     Execute( aSfxRequest );
    1024             :                 }
    1025             :             }
    1026             :             else
    1027           0 :                 aCurPos.Y() -= nVLine;
    1028           0 :             break;
    1029             :         case SID_CURSORDOWN:
    1030           0 :             if( nMaxVertPos<0 )
    1031             :             {
    1032           0 :                 long nPage = pPreview->GetPageNo();
    1033           0 :                 long nTotal = pPreview->GetTotalPages();
    1034             : 
    1035             :                 // before testing for last page, make sure all page counts are calculated
    1036           0 :                 if ( nPage+1 == nTotal && !pPreview->AllTested() )
    1037             :                 {
    1038           0 :                     pPreview->CalcAll();
    1039           0 :                     nTotal = pPreview->GetTotalPages();
    1040             :                 }
    1041             : 
    1042           0 :                 if( nPage<nTotal-1 )
    1043             :                 {
    1044           0 :                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
    1045           0 :                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT );
    1046           0 :                     Execute( aSfxRequest );
    1047             :                 }
    1048             :             }
    1049             :             else
    1050           0 :                 aCurPos.Y() += nVLine;
    1051           0 :             break;
    1052             :         case SID_CURSORLEFT:
    1053           0 :             aCurPos.X() -= nHLine;
    1054           0 :             break;
    1055             :         case SID_CURSORRIGHT:
    1056           0 :             aCurPos.X() += nHLine;
    1057           0 :             break;
    1058             :         case SID_CURSORPAGEUP:
    1059           0 :             if( nThumbPos==0 || nMaxVertPos<0 )
    1060             :             {
    1061           0 :                 long nPage = pPreview->GetPageNo();
    1062             : 
    1063           0 :                 if( nPage>0 )
    1064             :                 {
    1065           0 :                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
    1066           0 :                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
    1067           0 :                     Execute( aSfxRequest );
    1068           0 :                     aCurPos.Y() = nVRange;
    1069           0 :                 }
    1070             :             }
    1071             :             else
    1072           0 :                 aCurPos.Y() -= nVPage;
    1073           0 :             break;
    1074             :         case SID_CURSORPAGEDOWN:
    1075           0 :             if( (abs(nVPage+nThumbPos-nRangeMax)<10) || nMaxVertPos<0 )
    1076             :             {
    1077           0 :                 long nPage = pPreview->GetPageNo();
    1078           0 :                 long nTotal = pPreview->GetTotalPages();
    1079             : 
    1080             :                 // before testing for last page, make sure all page counts are calculated
    1081           0 :                 if ( nPage+1 == nTotal && !pPreview->AllTested() )
    1082             :                 {
    1083           0 :                     pPreview->CalcAll();
    1084           0 :                     nTotal = pPreview->GetTotalPages();
    1085             :                 }
    1086           0 :                 if( nPage<nTotal-1 )
    1087             :                 {
    1088           0 :                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
    1089           0 :                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT );
    1090           0 :                     Execute( aSfxRequest );
    1091           0 :                     aCurPos.Y() = 0;
    1092           0 :                 }
    1093             :             }
    1094             :             else
    1095           0 :                 aCurPos.Y() += nVPage;
    1096           0 :             break;
    1097             :         case SID_CURSORHOME:
    1098           0 :             if( nMaxVertPos<0 )
    1099             :             {
    1100           0 :                 long nPage  = pPreview->GetPageNo();
    1101           0 :                 long nTotal = pPreview->GetTotalPages();
    1102           0 :                 if( nTotal && nPage != 0 )
    1103             :                 {
    1104           0 :                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
    1105           0 :                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_FIRST );
    1106           0 :                     Execute( aSfxRequest );
    1107             :                 }
    1108             :             }
    1109             :             else
    1110             :             {
    1111           0 :                 aCurPos.Y() = 0;
    1112           0 :                 aCurPos.X() = 0;
    1113             :             }
    1114           0 :             break;
    1115             :         case SID_CURSOREND:
    1116           0 :             if( nMaxVertPos<0 )
    1117             :             {
    1118           0 :                 if( !pPreview->AllTested() )
    1119           0 :                     pPreview->CalcAll();
    1120           0 :                 long nPage  = pPreview->GetPageNo();
    1121           0 :                 long nTotal = pPreview->GetTotalPages();
    1122           0 :                 if( nTotal && nPage+1 != nTotal )
    1123             :                 {
    1124           0 :                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
    1125           0 :                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_LAST );
    1126           0 :                     Execute( aSfxRequest );
    1127             :                 }
    1128             :             }
    1129             :             else
    1130             :             {
    1131           0 :                 aCurPos.Y() = nVRange;
    1132           0 :                 aCurPos.X() = nHRange;
    1133             :             }
    1134           0 :             break;
    1135             :     }
    1136             : 
    1137             :         // nHRange-nHPage might be negative, that's why we check for < 0 afterwards
    1138             : 
    1139           0 :     if( aCurPos.Y() > (nVRange-nVPage) )
    1140           0 :         aCurPos.Y() = (nVRange-nVPage);
    1141           0 :     if( aCurPos.Y() < 0 )
    1142           0 :         aCurPos.Y() = 0;
    1143           0 :     if( aCurPos.X() > (nHRange-nHPage) )
    1144           0 :         aCurPos.X() = (nHRange-nHPage);
    1145           0 :     if( aCurPos.X() < 0 )
    1146           0 :         aCurPos.X() = 0;
    1147             : 
    1148           0 :     if( nMaxVertPos>=0 )
    1149             :     {
    1150           0 :         if( aCurPos.Y() != aPrevPos.Y() )
    1151             :         {
    1152           0 :             pVerScroll->SetThumbPos( aCurPos.Y() );
    1153           0 :             pPreview->SetYOffset( aCurPos.Y() );
    1154             :         }
    1155             :     }
    1156             : 
    1157           0 :     if( aCurPos.X() != aPrevPos.X() )
    1158             :     {
    1159           0 :         pHorScroll->SetThumbPos( aCurPos.X() );
    1160           0 :         pPreview->SetXOffset( aCurPos.X() );
    1161             :     }
    1162             : 
    1163           0 : }
    1164             : 
    1165           0 : void ScPreviewShell::ExitPreview()
    1166             : {
    1167           0 :     GetViewFrame()->GetDispatcher()->Execute(SID_VIEWSHELL0, SFX_CALLMODE_ASYNCHRON);
    1168           0 : }
    1169             : 
    1170          71 : void ScPreviewShell::AddAccessibilityObject( SfxListener& rObject )
    1171             : {
    1172          71 :     if (!pAccessibilityBroadcaster)
    1173           8 :         pAccessibilityBroadcaster = new SfxBroadcaster;
    1174             : 
    1175          71 :     rObject.StartListening( *pAccessibilityBroadcaster );
    1176          71 : }
    1177             : 
    1178          71 : void ScPreviewShell::RemoveAccessibilityObject( SfxListener& rObject )
    1179             : {
    1180          71 :     if (pAccessibilityBroadcaster)
    1181          71 :         rObject.EndListening( *pAccessibilityBroadcaster );
    1182             :     else
    1183             :     {
    1184             :         OSL_FAIL("kein Accessibility-Broadcaster?");
    1185             :     }
    1186          71 : }
    1187             : 
    1188          31 : void ScPreviewShell::BroadcastAccessibility( const SfxHint &rHint )
    1189             : {
    1190          31 :     if (pAccessibilityBroadcaster)
    1191          31 :         pAccessibilityBroadcaster->Broadcast( rHint );
    1192          31 : }
    1193             : 
    1194          63 : sal_Bool ScPreviewShell::HasAccessibilityObjects()
    1195             : {
    1196          63 :     return pAccessibilityBroadcaster && pAccessibilityBroadcaster->HasListeners();
    1197             : }
    1198             : 
    1199         928 : const ScPreviewLocationData& ScPreviewShell::GetLocationData()
    1200             : {
    1201         928 :     return pPreview->GetLocationData();
    1202             : }
    1203             : 
    1204         202 : ScDocument* ScPreviewShell::GetDocument()
    1205             : {
    1206         202 :     return pDocShell->GetDocument();
    1207          93 : }
    1208             : 
    1209             : 
    1210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10