1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
24 #include "scitems.hxx"
25 #include <comphelper/string.hxx>
26 #include <editeng/eeitem.hxx>
28 #include <sfx2/app.hxx>
29 #include <editeng/sizeitem.hxx>
30 #include <svl/srchitem.hxx>
31 #include <svx/zoomslideritem.hxx>
32 #include <svx/svdview.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/objface.hxx>
35 #include <sfx2/request.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/whiter.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <vcl/help.hxx>
40 #include <vcl/settings.hxx>
41 #include <tools/urlobj.hxx>
42 #include <sfx2/docfile.hxx>
43 #include <sfx2/printer.hxx>
45 #include "prevwsh.hxx"
46 #include "preview.hxx"
47 #include "printfun.hxx"
50 #include "inputhdl.hxx"
52 #include "tabvwsh.hxx"
53 #include "stlpool.hxx"
54 #include "editutil.hxx"
55 #include "scresid.hxx"
56 #include "globstr.hrc"
58 #include "ViewSettingsSequenceDefines.hxx"
59 #include "tpprint.hxx"
60 #include "printopt.hxx"
61 #include "viewuno.hxx"
62 #include <sax/tools/converter.hxx>
63 #include <rtl/ustrbuf.hxx>
65 #include <svx/svxdlg.hxx>
66 #include <svx/dialogs.hrc>
68 #include <basegfx/tools/zoomtools.hxx>
69 #include <svx/zoom_def.hxx>
70 #include <com/sun/star/document/XDocumentProperties.hpp>
72 #include "scabstdlg.hxx"
74 #define MINZOOM_SLIDER 10
75 #define MAXZOOM_SLIDER 400
77 #define SC_USERDATA_SEP ';'
79 using namespace com::sun::star
;
81 #define ScPreviewShell
82 #include "scslots.hxx"
84 #include <boost/scoped_ptr.hpp>
86 TYPEINIT1( ScPreviewShell
, SfxViewShell
);
88 SFX_IMPL_INTERFACE(ScPreviewShell
, SfxViewShell
)
90 void ScPreviewShell::InitInterface_Impl()
92 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
|SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
|SFX_VISIBILITY_READONLYDOC
,
93 RID_OBJECTBAR_PREVIEW
);
95 GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_PREVIEW
));
98 SFX_IMPL_NAMED_VIEWFACTORY( ScPreviewShell
, "PrintPreview" )
100 SFX_VIEW_REGISTRATION(ScDocShell
);
103 void ScPreviewShell::Construct( vcl::Window
* pParent
)
105 // Find the top-most window, and set the close window handler to intercept
106 // the window close event.
107 vcl::Window
* pWin
= pParent
;
108 while (!pWin
->IsSystemWindow())
110 if (pWin
->GetParent())
111 pWin
= pWin
->GetParent();
116 mpFrameWindow
= dynamic_cast<SystemWindow
*>(pWin
);
118 mpFrameWindow
->SetCloseHdl(LINK(this, ScPreviewShell
, CloseHdl
));
120 eZoom
= SvxZoomType::WHOLEPAGE
;
122 pCorner
= VclPtr
<ScrollBarBox
>::Create( pParent
, WB_SIZEABLE
);
124 pHorScroll
= VclPtr
<ScrollBar
>::Create(pParent
, WB_HSCROLL
);
125 pVerScroll
= VclPtr
<ScrollBar
>::Create(pParent
, WB_VSCROLL
);
127 // SSA: --- RTL --- no mirroring for horizontal scrollbars
128 pHorScroll
->EnableRTL( false );
130 pHorScroll
->SetEndScrollHdl( LINK( this, ScPreviewShell
, ScrollHandler
) );
131 pVerScroll
->SetEndScrollHdl( LINK( this, ScPreviewShell
, ScrollHandler
) );
133 pPreview
= VclPtr
<ScPreview
>::Create( pParent
, pDocShell
, this );
135 SetPool( &SC_MOD()->GetPool() );
136 SetWindow( pPreview
);
137 StartListening(*pDocShell
,true);
138 StartListening(*SfxGetpApp(),true); // #i62045# #i62046# application is needed for Calc's own hints
139 SfxBroadcaster
* pDrawBC
= pDocShell
->GetDocument().GetDrawBroadcaster();
141 StartListening(*pDrawBC
);
143 pHorScroll
->Show( false );
144 pVerScroll
->Show( false );
146 SetHelpId( HID_SCSHELL_PREVWSH
);
147 SetName(OUString("Preview"));
150 ScPreviewShell::ScPreviewShell( SfxViewFrame
* pViewFrame
,
151 SfxViewShell
* pOldSh
) :
152 SfxViewShell( pViewFrame
, SfxViewShellFlags::CAN_PRINT
| SfxViewShellFlags::HAS_PRINTOPTIONS
),
153 pDocShell( static_cast<ScDocShell
*>(pViewFrame
->GetObjectShell()) ),
155 nSourceDesignMode( TRISTATE_INDET
),
157 pAccessibilityBroadcaster( NULL
)
159 Construct( &pViewFrame
->GetWindow() );
161 if ( pOldSh
&& pOldSh
->ISA( ScTabViewShell
) )
163 // store view settings, show table from TabView
164 //! store live ScViewData instead, and update on ScTablesHint?
165 //! or completely forget aSourceData on ScTablesHint?
167 ScTabViewShell
* pTabViewShell
= static_cast<ScTabViewShell
*>(pOldSh
);
168 const ScViewData
& rData
= pTabViewShell
->GetViewData();
169 rData
.WriteUserDataSequence( aSourceData
);
170 pPreview
->SetSelectedTabs(rData
.GetMarkData());
171 InitStartTable( rData
.GetTabNo() );
173 // also have to store the TabView's DesignMode state
174 // (only if draw view exists)
175 SdrView
* pDrawView
= pTabViewShell
->GetSdrView();
178 = pDrawView
->IsDesignMode() ? TRISTATE_TRUE
: TRISTATE_FALSE
;
181 new ScPreviewObj(this);
184 ScPreviewShell::~ScPreviewShell()
187 mpFrameWindow
->SetCloseHdl(Link
<>()); // Remove close handler.
189 // #108333#; notify Accessibility that Shell is dying and before destroy all
190 BroadcastAccessibility( SfxSimpleHint( SFX_HINT_DYING
) );
191 DELETEZ(pAccessibilityBroadcaster
);
193 SfxBroadcaster
* pDrawBC
= pDocShell
->GetDocument().GetDrawBroadcaster();
195 EndListening(*pDrawBC
);
196 EndListening(*SfxGetpApp());
197 EndListening(*pDocShell
);
200 pPreview
.disposeAndClear();
201 pHorScroll
.disposeAndClear();
202 pVerScroll
.disposeAndClear();
203 pCorner
.disposeAndClear();
205 // normal mode of operation is switching back to default view in the same frame,
206 // so there's no need to activate any other window here anymore
209 void ScPreviewShell::InitStartTable(SCTAB nTab
)
211 pPreview
->SetPageNo( pPreview
->GetFirstPage(nTab
) );
214 void ScPreviewShell::AdjustPosSizePixel( const Point
&rPos
, const Size
&rSize
)
216 Size
aOutSize( rSize
);
217 pPreview
->SetPosSizePixel( rPos
, aOutSize
);
219 if ( SvxZoomType::WHOLEPAGE
== eZoom
)
220 pPreview
->SetZoom( pPreview
->GetOptimalZoom(false) );
221 else if ( SvxZoomType::PAGEWIDTH
== eZoom
)
222 pPreview
->SetZoom( pPreview
->GetOptimalZoom(true) );
224 UpdateNeededScrollBars();
227 void ScPreviewShell::InnerResizePixel( const Point
&rOfs
, const Size
&rSize
)
229 AdjustPosSizePixel( rOfs
,rSize
);
232 void ScPreviewShell::OuterResizePixel( const Point
&rOfs
, const Size
&rSize
)
234 AdjustPosSizePixel( rOfs
,rSize
);
237 bool ScPreviewShell::GetPageSize( Size
& aPageSize
)
239 ScDocument
& rDoc
= pDocShell
->GetDocument();
240 SCTAB nTab
= pPreview
->GetTab();
242 ScStyleSheetPool
* pStylePool
= rDoc
.GetStyleSheetPool();
243 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( rDoc
.GetPageStyle( nTab
),
244 SFX_STYLE_FAMILY_PAGE
);
245 OSL_ENSURE(pStyleSheet
,"No style sheet");
246 if (!pStyleSheet
) return false;
247 const SfxItemSet
* pParamSet
= &pStyleSheet
->GetItemSet();
249 aPageSize
= static_cast<const SvxSizeItem
&>( pParamSet
->Get(ATTR_PAGE_SIZE
)).GetSize();
250 aPageSize
.Width() = (long) (aPageSize
.Width() * HMM_PER_TWIPS
);
251 aPageSize
.Height() = (long) (aPageSize
.Height() * HMM_PER_TWIPS
);
255 void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom
)
258 OutputDevice
* pDevice
= Application::GetDefaultDevice();
260 long nBarW
= GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
263 long aHeightOffSet
= pDevice
? pDevice
->PixelToLogic( Size( nBarW
, nBarH
), pPreview
->GetMapMode() ).Height() : 0;
264 long aWidthOffSet
= aHeightOffSet
;
266 if (!GetPageSize( aPageSize
))
269 // for centering, page size without the shadow is used
270 bool bVert
= pVerScroll
->IsVisible();
271 bool bHori
= pHorScroll
->IsVisible();
272 Size aWindowSize
= pPreview
->GetOutputSize();
273 Point aPos
= pPreview
->GetPosPixel();
274 Size aWindowPixelSize
= pPreview
->GetOutputSizePixel();
276 // if we are called from Zoom then we need to compensate for whatever
277 // scrollbars were displayed before the zoom was called
282 aWindowPixelSize
.Width() += nBarH
;
283 aWindowSize
.Width() += aHeightOffSet
;
287 aWindowPixelSize
.Height() += nBarW
;
288 aWindowSize
.Height() += aWidthOffSet
;
291 // recalculate any needed scrollbars
295 long nMaxWidthPos
= aPageSize
.Width() - aWindowSize
.Width();
296 if ( nMaxWidthPos
<0 )
301 long nMaxHeightPos
= aPageSize
.Height() - aWindowSize
.Height();
303 if ( nMaxHeightPos
< 0 )
308 // see if having a scroll bar requires the other
309 if ( bVert
!= bHori
&& ( bVert
|| bHori
) )
311 if ( bVert
&& ( (nMaxWidthPos
+ aWidthOffSet
) > 0 ) )
313 else if ( (nMaxHeightPos
+ aHeightOffSet
) > 0 )
316 pHorScroll
->Show( bHori
);
317 pVerScroll
->Show( bVert
);
319 // make room for needed scrollbars ( and reduce the size
320 // of the preview appropriately )
322 aWindowPixelSize
.Height() -= nBarW
;
324 aWindowPixelSize
.Width() -= nBarH
;
326 pPreview
->SetSizePixel( aWindowPixelSize
);
327 pHorScroll
->SetPosSizePixel( Point( aPos
.X(), aPos
.Y() + aWindowPixelSize
.Height() ),
328 Size( aWindowPixelSize
.Width(), nBarH
) );
329 pVerScroll
->SetPosSizePixel( Point( aPos
.X() + aWindowPixelSize
.Width(), aPos
.Y() ),
330 Size( nBarW
, aWindowPixelSize
.Height() ) );
331 pCorner
->SetPosSizePixel( Point( aPos
.X() + aWindowPixelSize
.Width(), aPos
.Y() + aWindowPixelSize
.Height() ),
332 Size( nBarW
, nBarH
) );
336 void ScPreviewShell::UpdateScrollBars()
339 if ( !GetPageSize( aPageSize
) )
342 // for centering, page size without the shadow is used
344 Size aWindowSize
= pPreview
->GetOutputSize();
346 Point aOfs
= pPreview
->GetOffset();
350 pHorScroll
->SetRange( Range( 0, aPageSize
.Width() ) );
351 pHorScroll
->SetLineSize( aWindowSize
.Width() / 16 );
352 pHorScroll
->SetPageSize( aWindowSize
.Width() );
353 pHorScroll
->SetVisibleSize( aWindowSize
.Width() );
354 long nMaxPos
= aPageSize
.Width() - aWindowSize
.Width();
357 // page smaller than window -> center (but put scrollbar to 0)
359 pPreview
->SetXOffset( nMaxPos
/ 2 );
361 else if (aOfs
.X() < 0)
363 // page larger than window -> never use negative offset
365 pPreview
->SetXOffset( 0 );
367 else if (aOfs
.X() > nMaxPos
)
369 // limit offset to align with right edge of window
371 pPreview
->SetXOffset(nMaxPos
);
373 pHorScroll
->SetThumbPos( aOfs
.X() );
378 long nPageNo
= pPreview
->GetPageNo();
379 long nTotalPages
= pPreview
->GetTotalPages();
381 nMaxVertPos
= aPageSize
.Height() - aWindowSize
.Height();
382 pVerScroll
->SetLineSize( aWindowSize
.Height() / 16 );
383 pVerScroll
->SetPageSize( aWindowSize
.Height() );
384 pVerScroll
->SetVisibleSize( aWindowSize
.Height() );
385 if ( nMaxVertPos
< 0 )
387 // page smaller than window -> center (but put scrollbar to 0)
389 pPreview
->SetYOffset( nMaxVertPos
/ 2 );
390 pVerScroll
->SetThumbPos( nPageNo
* aWindowSize
.Height() );
391 pVerScroll
->SetRange( Range( 0, aWindowSize
.Height() * nTotalPages
));
393 else if (aOfs
.Y() < 0)
395 // page larger than window -> never use negative offset
396 pVerScroll
->SetRange( Range( 0, aPageSize
.Height() ) );
398 pPreview
->SetYOffset( 0 );
399 pVerScroll
->SetThumbPos( aOfs
.Y() );
401 else if (aOfs
.Y() > nMaxVertPos
)
403 // limit offset to align with window bottom
404 pVerScroll
->SetRange( Range( 0, aPageSize
.Height() ) );
405 aOfs
.Y() = nMaxVertPos
;
406 pPreview
->SetYOffset( nMaxVertPos
);
407 pVerScroll
->SetThumbPos( aOfs
.Y() );
412 IMPL_LINK (ScPreviewShell
,ScrollHandler
, ScrollBar
* ,pScroll
)
414 long nPos
= pScroll
->GetThumbPos();
415 long nDelta
= pScroll
->GetDelta();
416 long nMaxRange
= pScroll
->GetRangeMax();
417 long nTotalPages
= pPreview
->GetTotalPages();
419 long nPerPageLength
= 0;
420 bool bIsDivide
= true;
423 nPerPageLength
= nMaxRange
/ nTotalPages
;
427 nPageNo
= nPos
/ nPerPageLength
;
428 if( nPos
% nPerPageLength
)
435 bool bHoriz
= ( pScroll
== pHorScroll
);
438 pPreview
->SetXOffset( nPos
);
441 if( nMaxVertPos
> 0 )
442 pPreview
->SetYOffset( nPos
);
445 Point aMousePos
= pScroll
->OutputToNormalizedScreenPixel( pScroll
->GetPointerPosPixel() );
446 Point aPos
= pScroll
->GetParent()->OutputToNormalizedScreenPixel( pScroll
->GetPosPixel() );
449 QuickHelpFlags nAlign
;
453 if ( nTotalPages
&& nPageNo
> 0 && !bIsDivide
)
454 pPreview
->SetPageNo( nPageNo
-1 );
456 pPreview
->SetPageNo( nPageNo
);
458 aHelpStr
= ScGlobal::GetRscString( STR_PAGE
) +
459 " " + OUString::number( nPageNo
) +
460 " / " + OUString::number( nTotalPages
);
462 else if( nDelta
> 0 )
464 bool bAllTested
= pPreview
->AllTested();
465 if ( nTotalPages
&& ( nPageNo
< nTotalPages
|| !bAllTested
) )
466 pPreview
->SetPageNo( nPageNo
);
468 aHelpStr
= ScGlobal::GetRscString( STR_PAGE
) +
469 " " + OUString::number( nPageNo
+1 ) +
470 " / " + OUString::number( nTotalPages
);
473 aRect
.Left() = aPos
.X() - 8;
474 aRect
.Top() = aMousePos
.Y();
475 aRect
.Right() = aRect
.Left();
476 aRect
.Bottom() = aRect
.Top();
477 nAlign
= QuickHelpFlags::Bottom
|QuickHelpFlags::Center
;
478 Help::ShowQuickHelp( pScroll
->GetParent(), aRect
, aHelpStr
, nAlign
);
485 IMPL_LINK (ScPreviewShell
, CloseHdl
, SystemWindow
*,)
491 bool ScPreviewShell::ScrollCommand( const CommandEvent
& rCEvt
)
494 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
495 if ( pData
&& pData
->GetMode() == CommandWheelMode::ZOOM
)
497 long nOld
= pPreview
->GetZoom();
499 if ( pData
->GetDelta() < 0 )
500 nNew
= std::max( (long) MINZOOM
, basegfx::zoomtools::zoomOut( nOld
));
502 nNew
= std::min( (long) MAXZOOM
, basegfx::zoomtools::zoomIn( nOld
));
506 eZoom
= SvxZoomType::PERCENT
;
507 pPreview
->SetZoom( (sal_uInt16
)nNew
);
514 bDone
= pPreview
->HandleScrollCommand( rCEvt
, pHorScroll
, pVerScroll
);
520 SfxPrinter
* ScPreviewShell::GetPrinter( bool bCreate
)
522 return pDocShell
->GetPrinter(bCreate
);
525 sal_uInt16
ScPreviewShell::SetPrinter( SfxPrinter
*pNewPrinter
, SfxPrinterChangeFlags nDiffFlags
, bool )
527 return pDocShell
->SetPrinter( pNewPrinter
, nDiffFlags
);
530 bool ScPreviewShell::HasPrintOptionsPage() const
535 VclPtr
<SfxTabPage
> ScPreviewShell::CreatePrintOptionsPage( vcl::Window
*pParent
, const SfxItemSet
&rOptions
)
537 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
538 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
539 ::CreateTabPage ScTpPrintOptionsCreate
= pFact
->GetTabPageCreatorFunc( RID_SCPAGE_PRINT
);
540 if ( ScTpPrintOptionsCreate
)
541 return ScTpPrintOptionsCreate( pParent
, &rOptions
);
542 return VclPtr
<SfxTabPage
>();
545 void ScPreviewShell::Activate(bool bMDI
)
547 SfxViewShell::Activate(bMDI
);
549 //! Basic etc. -> auslagern in eigene Datei (s. tabvwsh4)
553 // InputHdl ist jetzt meistens Null, keine Assertion mehr!
554 ScInputHandler
* pInputHdl
= SC_MOD()->GetInputHdl();
556 pInputHdl
->NotifyChange( NULL
);
560 void ScPreviewShell::Deactivate(bool bMDI
)
562 SfxViewShell::Deactivate(bMDI
);
569 void ScPreviewShell::Execute( SfxRequest
& rReq
)
571 sal_uInt16 nSlot
= rReq
.GetSlot();
572 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
577 case SID_STATUS_PAGESTYLE
:
579 pDocShell
->ExecutePageStyle( *this, rReq
, pPreview
->GetTab() );
582 pPreview
->Invalidate();
585 case SID_PREV_TABLE
: // Accelerator
586 case SID_PREVIEW_PREVIOUS
:
588 long nPage
= pPreview
->GetPageNo();
589 long nTotal
= pPreview
->GetTotalPages();
590 if (nTotal
&& nPage
> 0)
591 pPreview
->SetPageNo( nPage
-1 );
594 case SID_NEXT_TABLE
: // Accelerator
595 case SID_PREVIEW_NEXT
:
597 bool bAllTested
= pPreview
->AllTested();
598 long nPage
= pPreview
->GetPageNo();
599 long nTotal
= pPreview
->GetTotalPages();
600 if (nTotal
&& (nPage
+1 < nTotal
|| !bAllTested
))
601 pPreview
->SetPageNo( nPage
+1 );
604 case SID_CURSORTOPOFFILE
: // Accelerator
605 case SID_PREVIEW_FIRST
:
607 long nPage
= pPreview
->GetPageNo();
608 long nTotal
= pPreview
->GetTotalPages();
609 if (nTotal
&& nPage
!= 0)
610 pPreview
->SetPageNo( 0 );
613 case SID_CURSORENDOFFILE
: // Accelerator
614 case SID_PREVIEW_LAST
:
616 if (!pPreview
->AllTested())
619 long nPage
= pPreview
->GetPageNo();
620 long nTotal
= pPreview
->GetTotalPages();
621 if (nTotal
&& nPage
+1 != nTotal
)
622 pPreview
->SetPageNo( nTotal
-1 );
628 sal_uInt16 nZoom
= 100;
629 bool bCancel
= false;
631 eZoom
= SvxZoomType::PERCENT
;
636 const SvxZoomItem
& rZoomItem
= static_cast<const SvxZoomItem
&>(
637 pReqArgs
->Get(SID_ATTR_ZOOM
));
639 eZoom
= rZoomItem
.GetType();
640 nZoom
= rZoomItem
.GetValue();
644 SfxItemSet
aSet ( GetPool(), SID_ATTR_ZOOM
, SID_ATTR_ZOOM
);
645 SvxZoomItem
aZoomItem( SvxZoomType::PERCENT
, pPreview
->GetZoom(), SID_ATTR_ZOOM
);
647 aSet
.Put( aZoomItem
);
648 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
651 boost::scoped_ptr
<AbstractSvxZoomDialog
> pDlg(pFact
->CreateSvxZoomDialog(NULL
, aSet
));
652 OSL_ENSURE(pDlg
, "Dialog creation failed!");
653 pDlg
->SetLimits( 20, 400 );
654 pDlg
->HideButton( ZoomButtonId::OPTIMAL
);
655 bCancel
= ( RET_CANCEL
== pDlg
->Execute() );
659 const SvxZoomItem
& rZoomItem
= static_cast<const SvxZoomItem
&>(
660 pDlg
->GetOutputItemSet()->
661 Get( SID_ATTR_ZOOM
));
663 eZoom
= rZoomItem
.GetType();
664 nZoom
= rZoomItem
.GetValue();
673 case SvxZoomType::OPTIMAL
:
674 case SvxZoomType::WHOLEPAGE
:
675 nZoom
= pPreview
->GetOptimalZoom(false);
677 case SvxZoomType::PAGEWIDTH
:
678 nZoom
= pPreview
->GetOptimalZoom(true);
682 // added to avoid warnings
686 pPreview
->SetZoom( nZoom
);
691 case SID_PREVIEW_ZOOMIN
:
693 sal_uInt16 nNew
= pPreview
->GetZoom() + 20 ;
695 pPreview
->SetZoom( nNew
);
696 eZoom
= SvxZoomType::PERCENT
;
700 case SID_PREVIEW_ZOOMOUT
:
702 sal_uInt16 nNew
= pPreview
->GetZoom() - 1;
704 pPreview
->SetZoom( nNew
);
705 eZoom
= SvxZoomType::PERCENT
;
709 case SID_PREVIEW_MARGIN
:
711 bool bMargin
= pPreview
->GetPageMargins();
712 pPreview
->SetPageMargins( !bMargin
);
713 pPreview
->Invalidate();
717 case SID_ATTR_ZOOMSLIDER
:
719 const SfxPoolItem
* pItem
;
720 eZoom
= SvxZoomType::PERCENT
;
721 if( pReqArgs
&& SfxItemState::SET
== pReqArgs
->GetItemState( SID_ATTR_ZOOMSLIDER
, true, &pItem
) )
723 const sal_uInt16 nCurrentZoom
= static_cast<const SvxZoomSliderItem
*>(pItem
)->GetValue();
726 pPreview
->SetZoom( nCurrentZoom
);
732 case SID_PREVIEW_SCALINGFACTOR
:
734 const SfxPoolItem
* pItem
;
735 SCTAB nTab
= pPreview
->GetTab();
736 OUString aOldName
= pDocShell
->GetDocument().GetPageStyle( pPreview
->GetTab() );
737 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument().GetStyleSheetPool();
738 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
739 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
741 if ( pReqArgs
&& pStyleSheet
&& SfxItemState::SET
== pReqArgs
->GetItemState( SID_PREVIEW_SCALINGFACTOR
, true, &pItem
) )
743 const sal_uInt16 nCurrentZoom
= static_cast<const SvxZoomSliderItem
*>(pItem
)->GetValue();
744 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
745 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALE
, nCurrentZoom
) );
746 ScPrintFunc
aPrintFunc( pDocShell
, pDocShell
->GetPrinter(), nTab
);
747 aPrintFunc
.UpdatePages();
750 GetViewFrame()->GetBindings().Invalidate( nSlot
);
753 case SID_PRINTPREVIEW
:
754 case SID_PREVIEW_CLOSE
:
755 // print preview is now always in the same frame as the tab view
756 // -> always switch this frame back to normal view
757 // (ScTabViewShell ctor reads stored view data)
761 case SID_CURSORPAGEUP
:
762 case SID_CURSORPAGEDOWN
:
768 case SID_CURSORRIGHT
:
772 if( ScViewUtil::IsFullScreen( *this ) )
773 ScViewUtil::SetFullScreen( *this, false );
781 void ScPreviewShell::GetState( SfxItemSet
& rSet
)
783 pPreview
->SetInGetState(true);
785 SCTAB nTab
= pPreview
->GetTab();
786 long nPage
= pPreview
->GetPageNo();
787 long nTotal
= pPreview
->GetTotalPages();
788 sal_uInt16 nZoom
= pPreview
->GetZoom();
789 bool bAllTested
= pPreview
->AllTested();
791 SfxWhichIter
aIter(rSet
);
792 sal_uInt16 nWhich
= aIter
.FirstWhich();
797 case SID_STATUS_PAGESTYLE
:
799 pDocShell
->GetStatePageStyle( *this, rSet
, nTab
);
806 case SID_MAIL_SENDDOC
:
807 case SID_VIEW_DATA_SOURCE_BROWSER
:
809 rSet
.DisableItem(nWhich
);
811 case SID_PREVIEW_PREVIOUS
:
812 case SID_PREVIEW_FIRST
:
813 if (!nTotal
|| nPage
==0)
814 rSet
.DisableItem(nWhich
);
816 case SID_PREVIEW_NEXT
:
817 case SID_PREVIEW_LAST
:
819 if (!nTotal
|| nPage
==nTotal
-1)
820 rSet
.DisableItem(nWhich
);
822 case SID_PREVIEW_ZOOMIN
:
824 rSet
.DisableItem(nWhich
);
826 case SID_PREVIEW_ZOOMOUT
:
828 rSet
.DisableItem(nWhich
);
832 SvxZoomItem
aZoom( eZoom
, nZoom
, nWhich
);
833 aZoom
.SetValueSet( SvxZoomEnableFlags::ALL
& ~SvxZoomEnableFlags::OPTIMAL
);
837 case SID_ATTR_ZOOMSLIDER
:
839 SvxZoomSliderItem
aZoomSliderItem( nZoom
, MINZOOM
, MAXZOOM
, SID_ATTR_ZOOMSLIDER
);
840 aZoomSliderItem
.AddSnappingPoint( 100 );
841 rSet
.Put( aZoomSliderItem
);
844 case SID_PREVIEW_SCALINGFACTOR
:
846 if( pDocShell
->IsReadOnly() )
847 rSet
.DisableItem( nWhich
);
850 OUString aOldName
= pDocShell
->GetDocument().GetPageStyle( pPreview
->GetTab() );
851 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument().GetStyleSheetPool();
852 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
853 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
857 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
858 sal_uInt16 nCurrentZoom
= static_cast<const SfxUInt16Item
&>(rStyleSet
.Get(ATTR_PAGE_SCALE
)).GetValue();
861 SvxZoomSliderItem
aZoomSliderItem( nCurrentZoom
, MINZOOM_SLIDER
, MAXZOOM_SLIDER
, SID_PREVIEW_SCALINGFACTOR
);
862 aZoomSliderItem
.AddSnappingPoint( 100 );
863 rSet
.Put( aZoomSliderItem
);
866 rSet
.DisableItem( nWhich
);
871 case SID_STATUS_DOCPOS
:
872 rSet
.Put( SfxStringItem( nWhich
, pPreview
->GetPosString() ) );
874 case SID_PRINTPREVIEW
:
875 rSet
.Put( SfxBoolItem( nWhich
, true ) );
878 case SID_PREVIEW_MARGIN
:
879 if( pDocShell
->IsReadOnly() )
880 rSet
.DisableItem( nWhich
);
884 nWhich
= aIter
.NextWhich();
887 pPreview
->SetInGetState(false);
890 void ScPreviewShell::FillFieldData( ScHeaderFieldData
& rData
)
892 ScDocument
& rDoc
= pDocShell
->GetDocument();
893 SCTAB nTab
= pPreview
->GetTab();
895 rDoc
.GetName(nTab
, aTmp
);
896 rData
.aTabName
= aTmp
;
898 if( pDocShell
->getDocProperties()->getTitle().getLength() != 0 )
899 rData
.aTitle
= pDocShell
->getDocProperties()->getTitle();
901 rData
.aTitle
= pDocShell
->GetTitle();
903 const INetURLObject
& rURLObj
= pDocShell
->GetMedium()->GetURLObject();
904 rData
.aLongDocName
= rURLObj
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
905 if ( !rData
.aLongDocName
.isEmpty() )
906 rData
.aShortDocName
= rURLObj
.GetName( INetURLObject::DECODE_UNAMBIGUOUS
);
908 rData
.aShortDocName
= rData
.aLongDocName
= rData
.aTitle
;
909 rData
.nPageNo
= pPreview
->GetPageNo() + 1;
911 bool bAllTested
= pPreview
->AllTested();
913 rData
.nTotalPages
= pPreview
->GetTotalPages();
915 rData
.nTotalPages
= 99;
917 // the dialog knows eNumType
920 void ScPreviewShell::WriteUserData(OUString
& rData
, bool /* bBrowse */)
925 rData
= OUString::number(pPreview
->GetZoom());
926 rData
+= OUString(SC_USERDATA_SEP
);
927 rData
+= OUString::number(pPreview
->GetPageNo());
930 void ScPreviewShell::ReadUserData(const OUString
& rData
, bool /* bBrowse */)
932 if (!rData
.isEmpty())
934 sal_Int32 nIndex
= 0;
935 pPreview
->SetZoom((sal_uInt16
)rData
.getToken(0, SC_USERDATA_SEP
, nIndex
).toInt32());
936 pPreview
->SetPageNo(rData
.getToken(0, SC_USERDATA_SEP
, nIndex
).toInt32());
937 eZoom
= SvxZoomType::PERCENT
;
941 void ScPreviewShell::WriteUserDataSequence(uno::Sequence
< beans::PropertyValue
>& rSeq
, bool /* bBrowse */)
944 beans::PropertyValue
* pSeq
= rSeq
.getArray();
947 sal_uInt16
nViewID(GetViewFrame()->GetCurViewId());
948 pSeq
[0].Name
= SC_VIEWID
;
949 OUStringBuffer
sBuffer(SC_VIEW
);
950 ::sax::Converter::convertNumber(sBuffer
,
951 static_cast<sal_Int32
>(nViewID
));
952 pSeq
[0].Value
<<= sBuffer
.makeStringAndClear();
953 pSeq
[1].Name
= SC_ZOOMVALUE
;
954 pSeq
[1].Value
<<= sal_Int32 (pPreview
->GetZoom());
955 pSeq
[2].Name
= "PageNumber";
956 pSeq
[2].Value
<<= pPreview
->GetPageNo();
960 void ScPreviewShell::ReadUserDataSequence(const uno::Sequence
< beans::PropertyValue
>& rSeq
, bool /* bBrowse */)
962 sal_Int32
nCount(rSeq
.getLength());
965 const beans::PropertyValue
* pSeq
= rSeq
.getConstArray();
968 for(sal_Int32 i
= 0; i
< nCount
; i
++, pSeq
++)
970 OUString
sName(pSeq
->Name
);
971 if(sName
== SC_ZOOMVALUE
)
974 if (pSeq
->Value
>>= nTemp
)
975 pPreview
->SetZoom(sal_uInt16(nTemp
));
977 else if (sName
== "PageNumber")
980 if (pSeq
->Value
>>= nTemp
)
981 pPreview
->SetPageNo(nTemp
);
988 void ScPreviewShell::DoScroll( sal_uInt16 nMode
)
990 Point aCurPos
, aPrevPos
;
992 long nHRange
= pHorScroll
->GetRange().Max();
993 long nHLine
= pHorScroll
->GetLineSize();
994 long nHPage
= pHorScroll
->GetPageSize();
995 long nVRange
= pVerScroll
->GetRange().Max();
996 long nVLine
= pVerScroll
->GetLineSize();
997 long nVPage
= pVerScroll
->GetPageSize();
999 aCurPos
.X() = pHorScroll
->GetThumbPos();
1000 aCurPos
.Y() = pVerScroll
->GetThumbPos();
1003 long nThumbPos
= pVerScroll
->GetThumbPos();
1004 long nRangeMax
= pVerScroll
->GetRangeMax();
1011 long nPage
= pPreview
->GetPageNo();
1015 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1016 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1017 Execute( aSfxRequest
);
1021 aCurPos
.Y() -= nVLine
;
1023 case SID_CURSORDOWN
:
1026 long nPage
= pPreview
->GetPageNo();
1027 long nTotal
= pPreview
->GetTotalPages();
1029 // before testing for last page, make sure all page counts are calculated
1030 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1032 pPreview
->CalcAll();
1033 nTotal
= pPreview
->GetTotalPages();
1036 if( nPage
<nTotal
-1 )
1038 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1039 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1040 Execute( aSfxRequest
);
1044 aCurPos
.Y() += nVLine
;
1046 case SID_CURSORLEFT
:
1047 aCurPos
.X() -= nHLine
;
1049 case SID_CURSORRIGHT
:
1050 aCurPos
.X() += nHLine
;
1052 case SID_CURSORPAGEUP
:
1053 if( nThumbPos
==0 || nMaxVertPos
<0 )
1055 long nPage
= pPreview
->GetPageNo();
1059 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1060 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1061 Execute( aSfxRequest
);
1062 aCurPos
.Y() = nVRange
;
1066 aCurPos
.Y() -= nVPage
;
1068 case SID_CURSORPAGEDOWN
:
1069 if( (std::abs(nVPage
+nThumbPos
-nRangeMax
)<10) || nMaxVertPos
<0 )
1071 long nPage
= pPreview
->GetPageNo();
1072 long nTotal
= pPreview
->GetTotalPages();
1074 // before testing for last page, make sure all page counts are calculated
1075 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1077 pPreview
->CalcAll();
1078 nTotal
= pPreview
->GetTotalPages();
1080 if( nPage
<nTotal
-1 )
1082 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1083 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1084 Execute( aSfxRequest
);
1089 aCurPos
.Y() += nVPage
;
1091 case SID_CURSORHOME
:
1094 long nPage
= pPreview
->GetPageNo();
1095 long nTotal
= pPreview
->GetTotalPages();
1096 if( nTotal
&& nPage
!= 0 )
1098 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1099 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_FIRST
);
1100 Execute( aSfxRequest
);
1112 if( !pPreview
->AllTested() )
1113 pPreview
->CalcAll();
1114 long nPage
= pPreview
->GetPageNo();
1115 long nTotal
= pPreview
->GetTotalPages();
1116 if( nTotal
&& nPage
+1 != nTotal
)
1118 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1119 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_LAST
);
1120 Execute( aSfxRequest
);
1125 aCurPos
.Y() = nVRange
;
1126 aCurPos
.X() = nHRange
;
1131 // nHRange-nHPage might be negative, that's why we check for < 0 afterwards
1133 if( aCurPos
.Y() > (nVRange
-nVPage
) )
1134 aCurPos
.Y() = (nVRange
-nVPage
);
1135 if( aCurPos
.Y() < 0 )
1137 if( aCurPos
.X() > (nHRange
-nHPage
) )
1138 aCurPos
.X() = (nHRange
-nHPage
);
1139 if( aCurPos
.X() < 0 )
1142 if( nMaxVertPos
>=0 )
1144 if( aCurPos
.Y() != aPrevPos
.Y() )
1146 pVerScroll
->SetThumbPos( aCurPos
.Y() );
1147 pPreview
->SetYOffset( aCurPos
.Y() );
1151 if( aCurPos
.X() != aPrevPos
.X() )
1153 pHorScroll
->SetThumbPos( aCurPos
.X() );
1154 pPreview
->SetXOffset( aCurPos
.X() );
1159 void ScPreviewShell::ExitPreview()
1161 GetViewFrame()->GetDispatcher()->Execute(SID_VIEWSHELL0
, SfxCallMode::ASYNCHRON
);
1164 void ScPreviewShell::AddAccessibilityObject( SfxListener
& rObject
)
1166 if (!pAccessibilityBroadcaster
)
1167 pAccessibilityBroadcaster
= new SfxBroadcaster
;
1169 rObject
.StartListening( *pAccessibilityBroadcaster
);
1172 void ScPreviewShell::RemoveAccessibilityObject( SfxListener
& rObject
)
1174 if (pAccessibilityBroadcaster
)
1175 rObject
.EndListening( *pAccessibilityBroadcaster
);
1178 OSL_FAIL("kein Accessibility-Broadcaster?");
1182 void ScPreviewShell::BroadcastAccessibility( const SfxHint
&rHint
)
1184 if (pAccessibilityBroadcaster
)
1185 pAccessibilityBroadcaster
->Broadcast( rHint
);
1188 bool ScPreviewShell::HasAccessibilityObjects()
1190 return pAccessibilityBroadcaster
&& pAccessibilityBroadcaster
->HasListeners();
1193 const ScPreviewLocationData
& ScPreviewShell::GetLocationData()
1195 return pPreview
->GetLocationData();
1198 ScDocument
& ScPreviewShell::GetDocument()
1200 return pDocShell
->GetDocument();
1203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */