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 "scitems.hxx"
21 #include <comphelper/string.hxx>
22 #include <editeng/eeitem.hxx>
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>
40 #include "prevwsh.hxx"
41 #include "preview.hxx"
42 #include "printfun.hxx"
45 #include "inputhdl.hxx"
47 #include "tabvwsh.hxx"
48 #include "stlpool.hxx"
49 #include "editutil.hxx"
50 #include "scresid.hxx"
51 #include "globstr.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>
60 #include <svx/svxdlg.hxx>
61 #include <svx/dialogs.hrc>
63 #include <basegfx/tools/zoomtools.hxx>
64 #include <svx/zoom_def.hxx>
65 #include <com/sun/star/document/XDocumentProperties.hpp>
67 #include "scabstdlg.hxx"
69 #define MINZOOM_SLIDER 10
70 #define MAXZOOM_SLIDER 400
72 #define SC_USERDATA_SEP ';'
74 using namespace com::sun::star
;
76 // -----------------------------------------------------------------------
78 #define ScPreviewShell
79 #include "scslots.hxx"
81 TYPEINIT1( ScPreviewShell
, SfxViewShell
);
83 SFX_IMPL_INTERFACE( ScPreviewShell
, SfxViewShell
, ScResId(SCSTR_PREVIEWSHELL
) )
85 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT
|SFX_VISIBILITY_STANDARD
|
86 SFX_VISIBILITY_SERVER
|SFX_VISIBILITY_READONLYDOC
,
87 ScResId(RID_OBJECTBAR_PREVIEW
));
88 SFX_POPUPMENU_REGISTRATION(ScResId(RID_POPUP_PREVIEW
));
91 SFX_IMPL_NAMED_VIEWFACTORY( ScPreviewShell
, "PrintPreview" )
93 SFX_VIEW_REGISTRATION(ScDocShell
);
96 //------------------------------------------------------------------
98 void ScPreviewShell::Construct( Window
* pParent
)
100 // Find the top-most window, and set the close window handler to intercept
101 // the window close event.
102 Window
* pWin
= pParent
;
103 while (!pWin
->IsSystemWindow())
105 if (pWin
->GetParent())
106 pWin
= pWin
->GetParent();
111 mpFrameWindow
= dynamic_cast<SystemWindow
*>(pWin
);
113 mpFrameWindow
->SetCloseHdl(LINK(this, ScPreviewShell
, CloseHdl
));
115 eZoom
= SVX_ZOOM_WHOLEPAGE
;
117 pCorner
= new ScrollBarBox( pParent
, WB_SIZEABLE
);
119 pHorScroll
= new ScrollBar(pParent
, WB_HSCROLL
);
120 pVerScroll
= new ScrollBar(pParent
, WB_VSCROLL
);
122 // SSA: --- RTL --- no mirroring for horizontal scrollbars
123 pHorScroll
->EnableRTL( false );
125 pHorScroll
->SetEndScrollHdl( LINK( this, ScPreviewShell
, ScrollHandler
) );
126 pVerScroll
->SetEndScrollHdl( LINK( this, ScPreviewShell
, ScrollHandler
) );
128 pPreview
= new ScPreview( pParent
, pDocShell
, this );
130 SetPool( &SC_MOD()->GetPool() );
131 SetWindow( pPreview
);
132 StartListening(*pDocShell
,sal_True
);
133 StartListening(*SFX_APP(),sal_True
); // #i62045# #i62046# application is needed for Calc's own hints
134 SfxBroadcaster
* pDrawBC
= pDocShell
->GetDocument()->GetDrawBroadcaster();
136 StartListening(*pDrawBC
);
138 pHorScroll
->Show( false );
139 pVerScroll
->Show( false );
141 SetHelpId( HID_SCSHELL_PREVWSH
);
142 SetName(OUString("Preview"));
145 ScPreviewShell::ScPreviewShell( SfxViewFrame
* pViewFrame
,
146 SfxViewShell
* pOldSh
) :
147 SfxViewShell( pViewFrame
, SFX_VIEW_CAN_PRINT
| SFX_VIEW_HAS_PRINTOPTIONS
),
148 pDocShell( (ScDocShell
*)pViewFrame
->GetObjectShell() ),
150 nSourceDesignMode( SC_FORCEMODE_NONE
),
151 pAccessibilityBroadcaster( NULL
)
153 Construct( &pViewFrame
->GetWindow() );
155 if ( pOldSh
&& pOldSh
->ISA( ScTabViewShell
) )
157 // store view settings, show table from TabView
158 //! store live ScViewData instead, and update on ScTablesHint?
159 //! or completely forget aSourceData on ScTablesHint?
161 ScTabViewShell
* pTabViewShell
= ((ScTabViewShell
*)pOldSh
);
162 const ScViewData
* pData
= pTabViewShell
->GetViewData();
163 pData
->WriteUserDataSequence( aSourceData
);
164 pPreview
->SetSelectedTabs(pData
->GetMarkData());
165 InitStartTable( pData
->GetTabNo() );
167 // also have to store the TabView's DesignMode state
168 // (only if draw view exists)
169 SdrView
* pDrawView
= pTabViewShell
->GetSdrView();
171 nSourceDesignMode
= pDrawView
->IsDesignMode();
174 new ScPreviewObj(this);
177 ScPreviewShell::~ScPreviewShell()
180 mpFrameWindow
->SetCloseHdl(Link()); // Remove close handler.
182 // #108333#; notify Accessibility that Shell is dying and before destroy all
183 BroadcastAccessibility( SfxSimpleHint( SFX_HINT_DYING
) );
184 DELETEZ(pAccessibilityBroadcaster
);
186 SfxBroadcaster
* pDrawBC
= pDocShell
->GetDocument()->GetDrawBroadcaster();
188 EndListening(*pDrawBC
);
189 EndListening(*SFX_APP());
190 EndListening(*pDocShell
);
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
202 void ScPreviewShell::InitStartTable(SCTAB nTab
)
204 pPreview
->SetPageNo( pPreview
->GetFirstPage(nTab
) );
207 //------------------------------------------------------------------
209 OUString
ScPreviewShell::GetDescription() const
211 return OUString(" ** Test ** ");
214 void ScPreviewShell::AdjustPosSizePixel( const Point
&rPos
, const Size
&rSize
)
216 Size
aOutSize( rSize
);
217 pPreview
->SetPosSizePixel( rPos
, aOutSize
);
219 if ( SVX_ZOOM_WHOLEPAGE
== eZoom
)
220 pPreview
->SetZoom( pPreview
->GetOptimalZoom(false) );
221 else if ( SVX_ZOOM_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
* pDoc
= pDocShell
->GetDocument();
240 SCTAB nTab
= pPreview
->GetTab();
242 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
243 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( pDoc
->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
= ((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
;
267 if (!GetPageSize( aPageSize
))
270 // for centering, page size without the shadow is used
271 bool bVert
= pVerScroll
? pVerScroll
->IsVisible() : false;
272 bool bHori
= pHorScroll
? pHorScroll
->IsVisible() : false;
273 Size aWindowSize
= pPreview
->GetOutputSize();
274 Point aPos
= pPreview
->GetPosPixel();
275 Size aWindowPixelSize
= pPreview
->GetOutputSizePixel();
277 // if we are called from Zoom then we need to compensate for whatever
278 // scrollbars were displayed before the zoom was called
283 aWindowPixelSize
.Width() += nBarH
;
284 aWindowSize
.Width() += aHeightOffSet
;
288 aWindowPixelSize
.Height() += nBarW
;
289 aWindowSize
.Height() += aWidthOffSet
;
292 // recalculate any needed scrollbars
296 long nMaxWidthPos
= aPageSize
.Width() - aWindowSize
.Width();
297 if ( nMaxWidthPos
<0 )
302 long nMaxHeightPos
= aPageSize
.Height() - aWindowSize
.Height();
304 if ( nMaxHeightPos
< 0 )
309 // see if having a scroll bar requires the other
310 if ( bVert
!= bHori
&& ( bVert
|| bHori
) )
312 if ( bVert
&& ( (nMaxWidthPos
+ aWidthOffSet
) > 0 ) )
314 else if ( (nMaxHeightPos
+ aHeightOffSet
) > 0 )
317 pHorScroll
->Show( bHori
);
318 pVerScroll
->Show( bVert
);
320 // make room for needed scrollbars ( and reduce the size
321 // of the preview appropriately )
323 aWindowPixelSize
.Height() -= nBarW
;
325 aWindowPixelSize
.Width() -= nBarH
;
327 pPreview
->SetSizePixel( aWindowPixelSize
);
328 pHorScroll
->SetPosSizePixel( Point( aPos
.X(), aPos
.Y() + aWindowPixelSize
.Height() ),
329 Size( aWindowPixelSize
.Width(), nBarH
) );
330 pVerScroll
->SetPosSizePixel( Point( aPos
.X() + aWindowPixelSize
.Width(), aPos
.Y() ),
331 Size( nBarW
, aWindowPixelSize
.Height() ) );
332 pCorner
->SetPosSizePixel( Point( aPos
.X() + aWindowPixelSize
.Width(), aPos
.Y() + aWindowPixelSize
.Height() ),
333 Size( nBarW
, nBarH
) );
337 void ScPreviewShell::UpdateScrollBars()
340 if ( !GetPageSize( aPageSize
) )
343 // for centering, page size without the shadow is used
345 Size aWindowSize
= pPreview
->GetOutputSize();
347 Point aOfs
= pPreview
->GetOffset();
351 pHorScroll
->SetRange( Range( 0, aPageSize
.Width() ) );
352 pHorScroll
->SetLineSize( aWindowSize
.Width() / 16 );
353 pHorScroll
->SetPageSize( aWindowSize
.Width() );
354 pHorScroll
->SetVisibleSize( aWindowSize
.Width() );
355 long nMaxPos
= aPageSize
.Width() - aWindowSize
.Width();
358 // page smaller than window -> center (but put scrollbar to 0)
360 pPreview
->SetXOffset( nMaxPos
/ 2 );
362 else if (aOfs
.X() < 0)
364 // page larger than window -> never use negative offset
366 pPreview
->SetXOffset( 0 );
368 else if (aOfs
.X() > nMaxPos
)
370 // limit offset to align with right edge of window
372 pPreview
->SetXOffset(nMaxPos
);
374 pHorScroll
->SetThumbPos( aOfs
.X() );
379 long nPageNo
= pPreview
->GetPageNo();
380 long nTotalPages
= pPreview
->GetTotalPages();
382 nMaxVertPos
= aPageSize
.Height() - aWindowSize
.Height();
383 pVerScroll
->SetLineSize( aWindowSize
.Height() / 16 );
384 pVerScroll
->SetPageSize( aWindowSize
.Height() );
385 pVerScroll
->SetVisibleSize( aWindowSize
.Height() );
386 if ( nMaxVertPos
< 0 )
388 // page smaller than window -> center (but put scrollbar to 0)
390 pPreview
->SetYOffset( nMaxVertPos
/ 2 );
391 pVerScroll
->SetThumbPos( nPageNo
* aWindowSize
.Height() );
392 pVerScroll
->SetRange( Range( 0, aWindowSize
.Height() * nTotalPages
));
394 else if (aOfs
.Y() < 0)
396 // page larger than window -> never use negative offset
397 pVerScroll
->SetRange( Range( 0, aPageSize
.Height() ) );
399 pPreview
->SetYOffset( 0 );
400 pVerScroll
->SetThumbPos( aOfs
.Y() );
402 else if (aOfs
.Y() > nMaxVertPos
)
404 // limit offset to align with window bottom
405 pVerScroll
->SetRange( Range( 0, aPageSize
.Height() ) );
406 aOfs
.Y() = nMaxVertPos
;
407 pPreview
->SetYOffset( nMaxVertPos
);
408 pVerScroll
->SetThumbPos( aOfs
.Y() );
413 IMPL_LINK (ScPreviewShell
,ScrollHandler
, ScrollBar
* ,pScroll
)
415 long nPos
= pScroll
->GetThumbPos();
416 long nDelta
= pScroll
->GetDelta();
417 long nMaxRange
= pScroll
->GetRangeMax();
418 long nTotalPages
= pPreview
->GetTotalPages();
420 long nPerPageLength
= 0;
421 sal_Bool bIsDivide
= sal_True
;
424 nPerPageLength
= nMaxRange
/ nTotalPages
;
428 nPageNo
= nPos
/ nPerPageLength
;
429 if( nPos
% nPerPageLength
)
436 sal_Bool bHoriz
= ( pScroll
== pHorScroll
);
439 pPreview
->SetXOffset( nPos
);
442 if( nMaxVertPos
> 0 )
443 pPreview
->SetYOffset( nPos
);
446 Point aMousePos
= pScroll
->OutputToNormalizedScreenPixel( pScroll
->GetPointerPosPixel() );
447 Point aPos
= pScroll
->GetParent()->OutputToNormalizedScreenPixel( pScroll
->GetPosPixel() );
454 if ( nTotalPages
&& nPageNo
> 0 && !bIsDivide
)
455 pPreview
->SetPageNo( nPageNo
-1 );
457 pPreview
->SetPageNo( nPageNo
);
459 aHelpStr
= ScGlobal::GetRscString( STR_PAGE
) +
460 " " + OUString::number( nPageNo
) +
461 " / " + OUString::number( nTotalPages
);
463 else if( nDelta
> 0 )
465 sal_Bool bAllTested
= pPreview
->AllTested();
466 if ( nTotalPages
&& ( nPageNo
< nTotalPages
|| !bAllTested
) )
467 pPreview
->SetPageNo( nPageNo
);
469 aHelpStr
= ScGlobal::GetRscString( STR_PAGE
) +
470 " " + OUString::number( nPageNo
+1 ) +
471 " / " + OUString::number( nTotalPages
);
474 aRect
.Left() = aPos
.X() - 8;
475 aRect
.Top() = aMousePos
.Y();
476 aRect
.Right() = aRect
.Left();
477 aRect
.Top() = aRect
.Top();
478 nAlign
= QUICKHELP_BOTTOM
|QUICKHELP_CENTER
;
479 Help::ShowQuickHelp( pScroll
->GetParent(), aRect
, aHelpStr
, nAlign
);
486 IMPL_LINK (ScPreviewShell
, CloseHdl
, SystemWindow
*, EMPTYARG
)
492 sal_Bool
ScPreviewShell::ScrollCommand( const CommandEvent
& rCEvt
)
494 sal_Bool bDone
= false;
495 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
496 if ( pData
&& pData
->GetMode() == COMMAND_WHEEL_ZOOM
)
498 long nOld
= pPreview
->GetZoom();
500 if ( pData
->GetDelta() < 0 )
501 nNew
= std::max( (long) MINZOOM
, basegfx::zoomtools::zoomOut( nOld
));
503 nNew
= std::min( (long) MAXZOOM
, basegfx::zoomtools::zoomIn( nOld
));
507 eZoom
= SVX_ZOOM_PERCENT
;
508 pPreview
->SetZoom( (sal_uInt16
)nNew
);
515 bDone
= pPreview
->HandleScrollCommand( rCEvt
, pHorScroll
, pVerScroll
);
521 SfxPrinter
* ScPreviewShell::GetPrinter( sal_Bool bCreate
)
523 return pDocShell
->GetPrinter(bCreate
);
526 sal_uInt16
ScPreviewShell::SetPrinter( SfxPrinter
*pNewPrinter
, sal_uInt16 nDiffFlags
, bool )
528 return pDocShell
->SetPrinter( pNewPrinter
, nDiffFlags
);
531 bool ScPreviewShell::HasPrintOptionsPage() const
536 SfxTabPage
* ScPreviewShell::CreatePrintOptionsPage( Window
*pParent
, const SfxItemSet
&rOptions
)
538 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
539 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
540 ::CreateTabPage ScTpPrintOptionsCreate
= pFact
->GetTabPageCreatorFunc( RID_SCPAGE_PRINT
);
541 if ( ScTpPrintOptionsCreate
)
542 return (*ScTpPrintOptionsCreate
)( pParent
, rOptions
);
546 void ScPreviewShell::Activate(sal_Bool bMDI
)
548 SfxViewShell::Activate(bMDI
);
550 //! Basic etc. -> auslagern in eigene Datei (s. tabvwsh4)
554 // InputHdl ist jetzt meistens Null, keine Assertion mehr!
555 ScInputHandler
* pInputHdl
= SC_MOD()->GetInputHdl();
557 pInputHdl
->NotifyChange( NULL
);
561 void ScPreviewShell::Deactivate(sal_Bool bMDI
)
563 SfxViewShell::Deactivate(bMDI
);
570 //------------------------------------------------------------------------
572 void ScPreviewShell::Execute( SfxRequest
& rReq
)
574 sal_uInt16 nSlot
= rReq
.GetSlot();
575 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
580 case SID_STATUS_PAGESTYLE
:
582 pDocShell
->ExecutePageStyle( *this, rReq
, pPreview
->GetTab() );
585 pPreview
->Invalidate();
588 case SID_PREV_TABLE
: // Accelerator
589 case SID_PREVIEW_PREVIOUS
:
591 long nPage
= pPreview
->GetPageNo();
592 long nTotal
= pPreview
->GetTotalPages();
593 if (nTotal
&& nPage
> 0)
594 pPreview
->SetPageNo( nPage
-1 );
597 case SID_NEXT_TABLE
: // Accelerator
598 case SID_PREVIEW_NEXT
:
600 sal_Bool bAllTested
= pPreview
->AllTested();
601 long nPage
= pPreview
->GetPageNo();
602 long nTotal
= pPreview
->GetTotalPages();
603 if (nTotal
&& (nPage
+1 < nTotal
|| !bAllTested
))
604 pPreview
->SetPageNo( nPage
+1 );
607 case SID_CURSORTOPOFFILE
: // Accelerator
608 case SID_PREVIEW_FIRST
:
610 long nPage
= pPreview
->GetPageNo();
611 long nTotal
= pPreview
->GetTotalPages();
612 if (nTotal
&& nPage
!= 0)
613 pPreview
->SetPageNo( 0 );
616 case SID_CURSORENDOFFILE
: // Accelerator
617 case SID_PREVIEW_LAST
:
619 if (!pPreview
->AllTested())
622 long nPage
= pPreview
->GetPageNo();
623 long nTotal
= pPreview
->GetTotalPages();
624 if (nTotal
&& nPage
+1 != nTotal
)
625 pPreview
->SetPageNo( nTotal
-1 );
631 sal_uInt16 nZoom
= 100;
632 sal_Bool bCancel
= false;
634 eZoom
= SVX_ZOOM_PERCENT
;
639 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)
640 pReqArgs
->Get(SID_ATTR_ZOOM
);
642 eZoom
= rZoomItem
.GetType();
643 nZoom
= rZoomItem
.GetValue();
647 SfxItemSet
aSet ( GetPool(), SID_ATTR_ZOOM
, SID_ATTR_ZOOM
);
648 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, pPreview
->GetZoom(), SID_ATTR_ZOOM
);
650 aSet
.Put( aZoomItem
);
651 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
654 AbstractSvxZoomDialog
* pDlg
= pFact
->CreateSvxZoomDialog(NULL
, aSet
);
655 OSL_ENSURE(pDlg
, "Dialogdiet fail!");
656 pDlg
->SetLimits( 20, 400 );
657 pDlg
->HideButton( ZOOMBTN_OPTIMAL
);
658 bCancel
= ( RET_CANCEL
== pDlg
->Execute() );
662 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)
663 pDlg
->GetOutputItemSet()->
664 Get( SID_ATTR_ZOOM
);
666 eZoom
= rZoomItem
.GetType();
667 nZoom
= rZoomItem
.GetValue();
678 case SVX_ZOOM_OPTIMAL
:
679 case SVX_ZOOM_WHOLEPAGE
:
680 nZoom
= pPreview
->GetOptimalZoom(false);
682 case SVX_ZOOM_PAGEWIDTH
:
683 nZoom
= pPreview
->GetOptimalZoom(sal_True
);
687 // added to avoid warnings
691 pPreview
->SetZoom( nZoom
);
696 case SID_PREVIEW_ZOOMIN
:
698 sal_uInt16 nNew
= pPreview
->GetZoom() + 20 ;
700 pPreview
->SetZoom( nNew
);
701 eZoom
= SVX_ZOOM_PERCENT
;
705 case SID_PREVIEW_ZOOMOUT
:
707 sal_uInt16 nNew
= pPreview
->GetZoom() - 1;
709 pPreview
->SetZoom( nNew
);
710 eZoom
= SVX_ZOOM_PERCENT
;
714 case SID_PREVIEW_MARGIN
:
716 sal_Bool bMargin
= pPreview
->GetPageMargins();
717 pPreview
->SetPageMargins( !bMargin
);
718 pPreview
->Invalidate();
722 case SID_ATTR_ZOOMSLIDER
:
724 const SfxPoolItem
* pItem
;
725 eZoom
= SVX_ZOOM_PERCENT
;
726 if( pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( SID_ATTR_ZOOMSLIDER
, sal_True
, &pItem
) )
728 const sal_uInt16 nCurrentZoom
= ((const SvxZoomSliderItem
*)pItem
)->GetValue();
731 pPreview
->SetZoom( nCurrentZoom
);
737 case SID_PREVIEW_SCALINGFACTOR
:
739 const SfxPoolItem
* pItem
;
740 SCTAB nTab
= pPreview
->GetTab();
741 OUString aOldName
= pDocShell
->GetDocument()->GetPageStyle( pPreview
->GetTab() );
742 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument()->GetStyleSheetPool();
743 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
744 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
746 if ( pReqArgs
&& pStyleSheet
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( SID_PREVIEW_SCALINGFACTOR
, sal_True
, &pItem
) )
748 const sal_uInt16 nCurrentZoom
= ((const SvxZoomSliderItem
*)pItem
)->GetValue();
749 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
750 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALE
, nCurrentZoom
) );
751 ScPrintFunc
aPrintFunc( pDocShell
, pDocShell
->GetPrinter(), nTab
);
752 aPrintFunc
.UpdatePages();
755 GetViewFrame()->GetBindings().Invalidate( nSlot
);
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)
766 case SID_CURSORPAGEUP
:
767 case SID_CURSORPAGEDOWN
:
773 case SID_CURSORRIGHT
:
777 if( ScViewUtil::IsFullScreen( *this ) )
778 ScViewUtil::SetFullScreen( *this, false );
786 void ScPreviewShell::GetState( SfxItemSet
& rSet
)
788 pPreview
->SetInGetState(sal_True
);
790 SCTAB nTab
= pPreview
->GetTab();
791 long nPage
= pPreview
->GetPageNo();
792 long nTotal
= pPreview
->GetTotalPages();
793 sal_uInt16 nZoom
= pPreview
->GetZoom();
794 sal_Bool bAllTested
= pPreview
->AllTested();
796 SfxWhichIter
aIter(rSet
);
797 sal_uInt16 nWhich
= aIter
.FirstWhich();
802 case SID_STATUS_PAGESTYLE
:
804 pDocShell
->GetStatePageStyle( *this, rSet
, nTab
);
811 case SID_MAIL_SENDDOC
:
812 case SID_VIEW_DATA_SOURCE_BROWSER
:
814 rSet
.DisableItem(nWhich
);
816 case SID_PREVIEW_PREVIOUS
:
817 case SID_PREVIEW_FIRST
:
818 if (!nTotal
|| nPage
==0)
819 rSet
.DisableItem(nWhich
);
821 case SID_PREVIEW_NEXT
:
822 case SID_PREVIEW_LAST
:
824 if (!nTotal
|| nPage
==nTotal
-1)
825 rSet
.DisableItem(nWhich
);
827 case SID_PREVIEW_ZOOMIN
:
829 rSet
.DisableItem(nWhich
);
831 case SID_PREVIEW_ZOOMOUT
:
833 rSet
.DisableItem(nWhich
);
837 SvxZoomItem
aZoom( eZoom
, nZoom
, nWhich
);
838 aZoom
.SetValueSet( SVX_ZOOM_ENABLE_ALL
& ~SVX_ZOOM_ENABLE_OPTIMAL
);
842 case SID_ATTR_ZOOMSLIDER
:
844 SvxZoomSliderItem
aZoomSliderItem( nZoom
, MINZOOM
, MAXZOOM
, SID_ATTR_ZOOMSLIDER
);
845 aZoomSliderItem
.AddSnappingPoint( 100 );
846 rSet
.Put( aZoomSliderItem
);
849 case SID_PREVIEW_SCALINGFACTOR
:
851 if( pDocShell
->IsReadOnly() )
852 rSet
.DisableItem( nWhich
);
855 OUString aOldName
= pDocShell
->GetDocument()->GetPageStyle( pPreview
->GetTab() );
856 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument()->GetStyleSheetPool();
857 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
858 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
862 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
863 sal_uInt16 nCurrentZoom
= ((const SfxUInt16Item
&)rStyleSet
.Get(ATTR_PAGE_SCALE
)).GetValue();
866 SvxZoomSliderItem
aZoomSliderItem( nCurrentZoom
, MINZOOM_SLIDER
, MAXZOOM_SLIDER
, SID_PREVIEW_SCALINGFACTOR
);
867 aZoomSliderItem
.AddSnappingPoint( 100 );
868 rSet
.Put( aZoomSliderItem
);
871 rSet
.DisableItem( nWhich
);
876 case SID_STATUS_DOCPOS
:
877 rSet
.Put( SfxStringItem( nWhich
, pPreview
->GetPosString() ) );
879 case SID_PRINTPREVIEW
:
880 rSet
.Put( SfxBoolItem( nWhich
, sal_True
) );
883 case SID_PREVIEW_MARGIN
:
884 if( pDocShell
->IsReadOnly() )
885 rSet
.DisableItem( nWhich
);
889 nWhich
= aIter
.NextWhich();
892 pPreview
->SetInGetState(false);
895 void ScPreviewShell::FillFieldData( ScHeaderFieldData
& rData
)
897 ScDocument
* pDoc
= pDocShell
->GetDocument();
898 SCTAB nTab
= pPreview
->GetTab();
900 pDoc
->GetName(nTab
, aTmp
);
901 rData
.aTabName
= aTmp
;
903 if( pDocShell
->getDocProperties()->getTitle().getLength() != 0 )
904 rData
.aTitle
= pDocShell
->getDocProperties()->getTitle();
906 rData
.aTitle
= pDocShell
->GetTitle();
908 const INetURLObject
& rURLObj
= pDocShell
->GetMedium()->GetURLObject();
909 rData
.aLongDocName
= rURLObj
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
910 if ( !rData
.aLongDocName
.isEmpty() )
911 rData
.aShortDocName
= rURLObj
.GetName( INetURLObject::DECODE_UNAMBIGUOUS
);
913 rData
.aShortDocName
= rData
.aLongDocName
= rData
.aTitle
;
914 rData
.nPageNo
= pPreview
->GetPageNo() + 1;
916 sal_Bool bAllTested
= pPreview
->AllTested();
918 rData
.nTotalPages
= pPreview
->GetTotalPages();
920 rData
.nTotalPages
= 99;
922 // the dialog knows eNumType
925 void ScPreviewShell::WriteUserData(OUString
& rData
, bool /* bBrowse */)
930 rData
= OUString::number(pPreview
->GetZoom());
931 rData
+= OUString(SC_USERDATA_SEP
);
932 rData
+= OUString::number(pPreview
->GetPageNo());
935 void ScPreviewShell::ReadUserData(const OUString
& rData
, bool /* bBrowse */)
937 if (!rData
.isEmpty())
939 sal_Int32 nIndex
= 0;
940 pPreview
->SetZoom((sal_uInt16
)rData
.getToken(0, SC_USERDATA_SEP
, nIndex
).toInt32());
941 pPreview
->SetPageNo(rData
.getToken(0, SC_USERDATA_SEP
, nIndex
).toInt32());
942 eZoom
= SVX_ZOOM_PERCENT
;
946 void ScPreviewShell::WriteUserDataSequence(uno::Sequence
< beans::PropertyValue
>& rSeq
, sal_Bool
/* bBrowse */)
949 beans::PropertyValue
* pSeq
= rSeq
.getArray();
952 sal_uInt16
nViewID(GetViewFrame()->GetCurViewId());
953 pSeq
[0].Name
= OUString(SC_VIEWID
);
954 OUStringBuffer
sBuffer(OUString(SC_VIEW
));
955 ::sax::Converter::convertNumber(sBuffer
,
956 static_cast<sal_Int32
>(nViewID
));
957 pSeq
[0].Value
<<= sBuffer
.makeStringAndClear();
958 pSeq
[1].Name
= OUString(SC_ZOOMVALUE
);
959 pSeq
[1].Value
<<= sal_Int32 (pPreview
->GetZoom());
960 pSeq
[2].Name
= "PageNumber";
961 pSeq
[2].Value
<<= pPreview
->GetPageNo();
965 void ScPreviewShell::ReadUserDataSequence(const uno::Sequence
< beans::PropertyValue
>& rSeq
, sal_Bool
/* bBrowse */)
967 sal_Int32
nCount(rSeq
.getLength());
970 const beans::PropertyValue
* pSeq
= rSeq
.getConstArray();
973 for(sal_Int32 i
= 0; i
< nCount
; i
++, pSeq
++)
975 OUString
sName(pSeq
->Name
);
976 if(sName
.equalsAscii(SC_ZOOMVALUE
))
979 if (pSeq
->Value
>>= nTemp
)
980 pPreview
->SetZoom(sal_uInt16(nTemp
));
982 else if (sName
.equalsAscii("PageNumber"))
985 if (pSeq
->Value
>>= nTemp
)
986 pPreview
->SetPageNo(nTemp
);
993 void ScPreviewShell::DoScroll( sal_uInt16 nMode
)
995 Point aCurPos
, aPrevPos
;
997 long nHRange
= pHorScroll
->GetRange().Max();
998 long nHLine
= pHorScroll
->GetLineSize();
999 long nHPage
= pHorScroll
->GetPageSize();
1000 long nVRange
= pVerScroll
->GetRange().Max();
1001 long nVLine
= pVerScroll
->GetLineSize();
1002 long nVPage
= pVerScroll
->GetPageSize();
1004 aCurPos
.X() = pHorScroll
->GetThumbPos();
1005 aCurPos
.Y() = pVerScroll
->GetThumbPos();
1008 long nThumbPos
= pVerScroll
->GetThumbPos();
1009 long nRangeMax
= pVerScroll
->GetRangeMax();
1016 long nPage
= pPreview
->GetPageNo();
1020 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1021 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1022 Execute( aSfxRequest
);
1026 aCurPos
.Y() -= nVLine
;
1028 case SID_CURSORDOWN
:
1031 long nPage
= pPreview
->GetPageNo();
1032 long nTotal
= pPreview
->GetTotalPages();
1034 // before testing for last page, make sure all page counts are calculated
1035 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1037 pPreview
->CalcAll();
1038 nTotal
= pPreview
->GetTotalPages();
1041 if( nPage
<nTotal
-1 )
1043 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1044 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1045 Execute( aSfxRequest
);
1049 aCurPos
.Y() += nVLine
;
1051 case SID_CURSORLEFT
:
1052 aCurPos
.X() -= nHLine
;
1054 case SID_CURSORRIGHT
:
1055 aCurPos
.X() += nHLine
;
1057 case SID_CURSORPAGEUP
:
1058 if( nThumbPos
==0 || nMaxVertPos
<0 )
1060 long nPage
= pPreview
->GetPageNo();
1064 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1065 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1066 Execute( aSfxRequest
);
1067 aCurPos
.Y() = nVRange
;
1071 aCurPos
.Y() -= nVPage
;
1073 case SID_CURSORPAGEDOWN
:
1074 if( (abs(nVPage
+nThumbPos
-nRangeMax
)<10) || nMaxVertPos
<0 )
1076 long nPage
= pPreview
->GetPageNo();
1077 long nTotal
= pPreview
->GetTotalPages();
1079 // before testing for last page, make sure all page counts are calculated
1080 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1082 pPreview
->CalcAll();
1083 nTotal
= pPreview
->GetTotalPages();
1085 if( nPage
<nTotal
-1 )
1087 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1088 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1089 Execute( aSfxRequest
);
1094 aCurPos
.Y() += nVPage
;
1096 case SID_CURSORHOME
:
1099 long nPage
= pPreview
->GetPageNo();
1100 long nTotal
= pPreview
->GetTotalPages();
1101 if( nTotal
&& nPage
!= 0 )
1103 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1104 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_FIRST
);
1105 Execute( aSfxRequest
);
1117 if( !pPreview
->AllTested() )
1118 pPreview
->CalcAll();
1119 long nPage
= pPreview
->GetPageNo();
1120 long nTotal
= pPreview
->GetTotalPages();
1121 if( nTotal
&& nPage
+1 != nTotal
)
1123 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1124 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_LAST
);
1125 Execute( aSfxRequest
);
1130 aCurPos
.Y() = nVRange
;
1131 aCurPos
.X() = nHRange
;
1136 // nHRange-nHPage might be negative, that's why we check for < 0 afterwards
1138 if( aCurPos
.Y() > (nVRange
-nVPage
) )
1139 aCurPos
.Y() = (nVRange
-nVPage
);
1140 if( aCurPos
.Y() < 0 )
1142 if( aCurPos
.X() > (nHRange
-nHPage
) )
1143 aCurPos
.X() = (nHRange
-nHPage
);
1144 if( aCurPos
.X() < 0 )
1147 if( nMaxVertPos
>=0 )
1149 if( aCurPos
.Y() != aPrevPos
.Y() )
1151 pVerScroll
->SetThumbPos( aCurPos
.Y() );
1152 pPreview
->SetYOffset( aCurPos
.Y() );
1156 if( aCurPos
.X() != aPrevPos
.X() )
1158 pHorScroll
->SetThumbPos( aCurPos
.X() );
1159 pPreview
->SetXOffset( aCurPos
.X() );
1164 void ScPreviewShell::ExitPreview()
1166 GetViewFrame()->GetDispatcher()->Execute(SID_VIEWSHELL0
, SFX_CALLMODE_ASYNCHRON
);
1169 void ScPreviewShell::AddAccessibilityObject( SfxListener
& rObject
)
1171 if (!pAccessibilityBroadcaster
)
1172 pAccessibilityBroadcaster
= new SfxBroadcaster
;
1174 rObject
.StartListening( *pAccessibilityBroadcaster
);
1177 void ScPreviewShell::RemoveAccessibilityObject( SfxListener
& rObject
)
1179 if (pAccessibilityBroadcaster
)
1180 rObject
.EndListening( *pAccessibilityBroadcaster
);
1183 OSL_FAIL("kein Accessibility-Broadcaster?");
1187 void ScPreviewShell::BroadcastAccessibility( const SfxHint
&rHint
)
1189 if (pAccessibilityBroadcaster
)
1190 pAccessibilityBroadcaster
->Broadcast( rHint
);
1193 sal_Bool
ScPreviewShell::HasAccessibilityObjects()
1195 return pAccessibilityBroadcaster
&& pAccessibilityBroadcaster
->HasListeners();
1198 const ScPreviewLocationData
& ScPreviewShell::GetLocationData()
1200 return pPreview
->GetLocationData();
1203 ScDocument
* ScPreviewShell::GetDocument()
1205 return pDocShell
->GetDocument();
1209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */