fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / prevwsh.cxx
blobe0e05990006b827b0b1133aa08fdb33d5da049a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <cstdlib>
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"
48 #include "attrib.hxx"
49 #include "scmod.hxx"
50 #include "inputhdl.hxx"
51 #include "docsh.hxx"
52 #include "tabvwsh.hxx"
53 #include "stlpool.hxx"
54 #include "editutil.hxx"
55 #include "scresid.hxx"
56 #include "globstr.hrc"
57 #include "sc.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"
73 // for mouse wheel
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();
112 else
113 break;
116 mpFrameWindow = dynamic_cast<SystemWindow*>(pWin);
117 if (mpFrameWindow)
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();
140 if (pDrawBC)
141 StartListening(*pDrawBC);
143 pHorScroll->Show( false );
144 pVerScroll->Show( false );
145 pCorner->Show();
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()) ),
154 mpFrameWindow(NULL),
155 nSourceDesignMode( TRISTATE_INDET ),
156 nMaxVertPos(0),
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();
176 if ( pDrawView )
177 nSourceDesignMode
178 = pDrawView->IsDesignMode() ? TRISTATE_TRUE : TRISTATE_FALSE;
181 new ScPreviewObj(this);
184 ScPreviewShell::~ScPreviewShell()
186 if (mpFrameWindow)
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();
194 if (pDrawBC)
195 EndListening(*pDrawBC);
196 EndListening(*SfxGetpApp());
197 EndListening(*pDocShell);
199 SetWindow(0);
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 );
252 return true;
255 void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom )
257 Size aPageSize;
258 OutputDevice* pDevice = Application::GetDefaultDevice();
260 long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
261 long nBarH = nBarW;
263 long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0;
264 long aWidthOffSet = aHeightOffSet;
266 if (!GetPageSize( aPageSize ))
267 return;
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
278 if ( bFromZoom )
280 if ( bVert )
282 aWindowPixelSize.Width() += nBarH;
283 aWindowSize.Width() += aHeightOffSet;
285 if ( bHori )
287 aWindowPixelSize.Height() += nBarW;
288 aWindowSize.Height() += aWidthOffSet;
291 // recalculate any needed scrollbars
292 bHori = false;
293 bVert = false;
295 long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width();
296 if ( nMaxWidthPos<0 )
297 bHori = false;
298 else
299 bHori = true;
301 long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height();
303 if ( nMaxHeightPos < 0 )
304 bVert = false;
305 else
306 bVert = true;
308 // see if having a scroll bar requires the other
309 if ( bVert != bHori && ( bVert || bHori ) )
311 if ( bVert && ( (nMaxWidthPos + aWidthOffSet ) > 0 ) )
312 bHori = true;
313 else if ( (nMaxHeightPos + aHeightOffSet ) > 0 )
314 bVert = true;
316 pHorScroll->Show( bHori );
317 pVerScroll->Show( bVert );
319 // make room for needed scrollbars ( and reduce the size
320 // of the preview appropriately )
321 if ( bHori )
322 aWindowPixelSize.Height() -= nBarW;
323 if ( bVert )
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 ) );
333 UpdateScrollBars();
336 void ScPreviewShell::UpdateScrollBars()
338 Size aPageSize;
339 if ( !GetPageSize( aPageSize ) )
340 return;
342 // for centering, page size without the shadow is used
344 Size aWindowSize = pPreview->GetOutputSize();
346 Point aOfs = pPreview->GetOffset();
348 if( pHorScroll )
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();
355 if ( nMaxPos<0 )
357 // page smaller than window -> center (but put scrollbar to 0)
358 aOfs.X() = 0;
359 pPreview->SetXOffset( nMaxPos / 2 );
361 else if (aOfs.X() < 0)
363 // page larger than window -> never use negative offset
364 aOfs.X() = 0;
365 pPreview->SetXOffset( 0 );
367 else if (aOfs.X() > nMaxPos)
369 // limit offset to align with right edge of window
370 aOfs.X() = nMaxPos;
371 pPreview->SetXOffset(nMaxPos);
373 pHorScroll->SetThumbPos( aOfs.X() );
376 if( pVerScroll )
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)
388 aOfs.Y() = 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() ) );
397 aOfs.Y() = 0;
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();
418 long nPageNo = 0;
419 long nPerPageLength = 0;
420 bool bIsDivide = true;
422 if( nTotalPages )
423 nPerPageLength = nMaxRange / nTotalPages;
425 if( nPerPageLength )
427 nPageNo = nPos / nPerPageLength;
428 if( nPos % nPerPageLength )
430 bIsDivide = false;
431 nPageNo ++;
435 bool bHoriz = ( pScroll == pHorScroll );
437 if( bHoriz )
438 pPreview->SetXOffset( nPos );
439 else
441 if( nMaxVertPos > 0 )
442 pPreview->SetYOffset( nPos );
443 else
445 Point aMousePos = pScroll->OutputToNormalizedScreenPixel( pScroll->GetPointerPosPixel() );
446 Point aPos = pScroll->GetParent()->OutputToNormalizedScreenPixel( pScroll->GetPosPixel() );
447 OUString aHelpStr;
448 Rectangle aRect;
449 QuickHelpFlags nAlign;
451 if( nDelta < 0 )
453 if ( nTotalPages && nPageNo > 0 && !bIsDivide )
454 pPreview->SetPageNo( nPageNo-1 );
455 if( bIsDivide )
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 );
482 return 0;
485 IMPL_LINK (ScPreviewShell, CloseHdl, SystemWindow*,)
487 ExitPreview();
488 return 0;
491 bool ScPreviewShell::ScrollCommand( const CommandEvent& rCEvt )
493 bool bDone = false;
494 const CommandWheelData* pData = rCEvt.GetWheelData();
495 if ( pData && pData->GetMode() == CommandWheelMode::ZOOM )
497 long nOld = pPreview->GetZoom();
498 long nNew = nOld;
499 if ( pData->GetDelta() < 0 )
500 nNew = std::max( (long) MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
501 else
502 nNew = std::min( (long) MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
504 if ( nNew != nOld )
506 eZoom = SvxZoomType::PERCENT;
507 pPreview->SetZoom( (sal_uInt16)nNew );
510 bDone = true;
512 else
514 bDone = pPreview->HandleScrollCommand( rCEvt, pHorScroll, pVerScroll );
517 return bDone;
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
532 return true;
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)
551 if (bMDI)
553 // InputHdl ist jetzt meistens Null, keine Assertion mehr!
554 ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
555 if ( pInputHdl )
556 pInputHdl->NotifyChange( NULL );
560 void ScPreviewShell::Deactivate(bool bMDI)
562 SfxViewShell::Deactivate(bMDI);
564 if (bMDI)
569 void ScPreviewShell::Execute( SfxRequest& rReq )
571 sal_uInt16 nSlot = rReq.GetSlot();
572 const SfxItemSet* pReqArgs = rReq.GetArgs();
574 switch ( nSlot )
576 case SID_FORMATPAGE:
577 case SID_STATUS_PAGESTYLE:
578 case SID_HFEDIT:
579 pDocShell->ExecutePageStyle( *this, rReq, pPreview->GetTab() );
580 break;
581 case SID_REPAINT:
582 pPreview->Invalidate();
583 rReq.Done();
584 break;
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 );
593 break;
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 );
603 break;
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 );
612 break;
613 case SID_CURSORENDOFFILE: // Accelerator
614 case SID_PREVIEW_LAST:
616 if (!pPreview->AllTested())
617 pPreview->CalcAll();
619 long nPage = pPreview->GetPageNo();
620 long nTotal = pPreview->GetTotalPages();
621 if (nTotal && nPage+1 != nTotal)
622 pPreview->SetPageNo( nTotal-1 );
624 break;
625 case SID_ATTR_ZOOM:
626 case FID_SCALE:
628 sal_uInt16 nZoom = 100;
629 bool bCancel = false;
631 eZoom = SvxZoomType::PERCENT;
633 if ( pReqArgs )
636 const SvxZoomItem& rZoomItem = static_cast<const SvxZoomItem&>(
637 pReqArgs->Get(SID_ATTR_ZOOM));
639 eZoom = rZoomItem.GetType();
640 nZoom = rZoomItem.GetValue();
642 else
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();
649 if(pFact)
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() );
657 if ( !bCancel )
659 const SvxZoomItem& rZoomItem = static_cast<const SvxZoomItem&>(
660 pDlg->GetOutputItemSet()->
661 Get( SID_ATTR_ZOOM ));
663 eZoom = rZoomItem.GetType();
664 nZoom = rZoomItem.GetValue();
669 if ( !bCancel )
671 switch ( eZoom )
673 case SvxZoomType::OPTIMAL:
674 case SvxZoomType::WHOLEPAGE:
675 nZoom = pPreview->GetOptimalZoom(false);
676 break;
677 case SvxZoomType::PAGEWIDTH:
678 nZoom = pPreview->GetOptimalZoom(true);
679 break;
680 default:
682 // added to avoid warnings
686 pPreview->SetZoom( nZoom );
687 rReq.Done();
690 break;
691 case SID_PREVIEW_ZOOMIN:
693 sal_uInt16 nNew = pPreview->GetZoom() + 20 ;
694 nNew -= nNew % 20;
695 pPreview->SetZoom( nNew );
696 eZoom = SvxZoomType::PERCENT;
697 rReq.Done();
699 break;
700 case SID_PREVIEW_ZOOMOUT:
702 sal_uInt16 nNew = pPreview->GetZoom() - 1;
703 nNew -= nNew % 20;
704 pPreview->SetZoom( nNew );
705 eZoom = SvxZoomType::PERCENT;
706 rReq.Done();
708 break;
709 case SID_PREVIEW_MARGIN:
711 bool bMargin = pPreview->GetPageMargins();
712 pPreview->SetPageMargins( !bMargin );
713 pPreview->Invalidate();
714 rReq.Done();
716 break;
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();
724 if( nCurrentZoom )
726 pPreview->SetZoom( nCurrentZoom );
727 rReq.Done();
731 break;
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();
748 rReq.Done();
750 GetViewFrame()->GetBindings().Invalidate( nSlot );
752 break;
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)
759 ExitPreview();
760 break;
761 case SID_CURSORPAGEUP:
762 case SID_CURSORPAGEDOWN:
763 case SID_CURSORHOME:
764 case SID_CURSOREND:
765 case SID_CURSORUP:
766 case SID_CURSORDOWN:
767 case SID_CURSORLEFT:
768 case SID_CURSORRIGHT:
769 DoScroll( nSlot );
770 break;
771 case SID_CANCEL:
772 if( ScViewUtil::IsFullScreen( *this ) )
773 ScViewUtil::SetFullScreen( *this, false );
774 break;
776 default:
777 break;
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();
793 while ( nWhich )
795 switch (nWhich)
797 case SID_STATUS_PAGESTYLE:
798 case SID_HFEDIT:
799 pDocShell->GetStatePageStyle( *this, rSet, nTab );
800 break;
801 case SID_UNDO:
802 case SID_REDO:
803 case SID_REPEAT:
804 case SID_SAVEDOC:
805 case SID_SAVEASDOC:
806 case SID_MAIL_SENDDOC:
807 case SID_VIEW_DATA_SOURCE_BROWSER:
808 case SID_QUITAPP:
809 rSet.DisableItem(nWhich);
810 break;
811 case SID_PREVIEW_PREVIOUS:
812 case SID_PREVIEW_FIRST:
813 if (!nTotal || nPage==0)
814 rSet.DisableItem(nWhich);
815 break;
816 case SID_PREVIEW_NEXT:
817 case SID_PREVIEW_LAST:
818 if (bAllTested)
819 if (!nTotal || nPage==nTotal-1)
820 rSet.DisableItem(nWhich);
821 break;
822 case SID_PREVIEW_ZOOMIN:
823 if (nZoom >= 400)
824 rSet.DisableItem(nWhich);
825 break;
826 case SID_PREVIEW_ZOOMOUT:
827 if (nZoom <= 20)
828 rSet.DisableItem(nWhich);
829 break;
830 case SID_ATTR_ZOOM:
832 SvxZoomItem aZoom( eZoom, nZoom, nWhich );
833 aZoom.SetValueSet( SvxZoomEnableFlags::ALL & ~SvxZoomEnableFlags::OPTIMAL );
834 rSet.Put( aZoom );
836 break;
837 case SID_ATTR_ZOOMSLIDER:
839 SvxZoomSliderItem aZoomSliderItem( nZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
840 aZoomSliderItem.AddSnappingPoint( 100 );
841 rSet.Put( aZoomSliderItem );
843 break;
844 case SID_PREVIEW_SCALINGFACTOR:
846 if( pDocShell->IsReadOnly() )
847 rSet.DisableItem( nWhich );
848 else
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! :-/" );
855 if ( pStyleSheet )
857 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
858 sal_uInt16 nCurrentZoom = static_cast<const SfxUInt16Item&>(rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
859 if( nCurrentZoom )
861 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM_SLIDER, MAXZOOM_SLIDER, SID_PREVIEW_SCALINGFACTOR );
862 aZoomSliderItem.AddSnappingPoint( 100 );
863 rSet.Put( aZoomSliderItem );
865 else
866 rSet.DisableItem( nWhich );
870 break;
871 case SID_STATUS_DOCPOS:
872 rSet.Put( SfxStringItem( nWhich, pPreview->GetPosString() ) );
873 break;
874 case SID_PRINTPREVIEW:
875 rSet.Put( SfxBoolItem( nWhich, true ) );
876 break;
877 case SID_FORMATPAGE:
878 case SID_PREVIEW_MARGIN:
879 if( pDocShell->IsReadOnly() )
880 rSet.DisableItem( nWhich );
881 break;
884 nWhich = aIter.NextWhich();
887 pPreview->SetInGetState(false);
890 void ScPreviewShell::FillFieldData( ScHeaderFieldData& rData )
892 ScDocument& rDoc = pDocShell->GetDocument();
893 SCTAB nTab = pPreview->GetTab();
894 OUString aTmp;
895 rDoc.GetName(nTab, aTmp);
896 rData.aTabName = aTmp;
898 if( pDocShell->getDocProperties()->getTitle().getLength() != 0 )
899 rData.aTitle = pDocShell->getDocProperties()->getTitle();
900 else
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 );
907 else
908 rData.aShortDocName = rData.aLongDocName = rData.aTitle;
909 rData.nPageNo = pPreview->GetPageNo() + 1;
911 bool bAllTested = pPreview->AllTested();
912 if (bAllTested)
913 rData.nTotalPages = pPreview->GetTotalPages();
914 else
915 rData.nTotalPages = 99;
917 // the dialog knows eNumType
920 void ScPreviewShell::WriteUserData(OUString& rData, bool /* bBrowse */)
922 // nZoom
923 // nPageNo
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 */)
943 rSeq.realloc(3);
944 beans::PropertyValue* pSeq = rSeq.getArray();
945 if(pSeq)
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());
963 if (nCount)
965 const beans::PropertyValue* pSeq = rSeq.getConstArray();
966 if(pSeq)
968 for(sal_Int32 i = 0; i < nCount; i++, pSeq++)
970 OUString sName(pSeq->Name);
971 if(sName == SC_ZOOMVALUE)
973 sal_Int32 nTemp = 0;
974 if (pSeq->Value >>= nTemp)
975 pPreview->SetZoom(sal_uInt16(nTemp));
977 else if (sName == "PageNumber")
979 sal_Int32 nTemp = 0;
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();
1001 aPrevPos = aCurPos;
1003 long nThumbPos = pVerScroll->GetThumbPos();
1004 long nRangeMax = pVerScroll->GetRangeMax();
1006 switch( nMode )
1008 case SID_CURSORUP:
1009 if( nMaxVertPos<0 )
1011 long nPage = pPreview->GetPageNo();
1013 if( nPage>0 )
1015 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1016 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
1017 Execute( aSfxRequest );
1020 else
1021 aCurPos.Y() -= nVLine;
1022 break;
1023 case SID_CURSORDOWN:
1024 if( nMaxVertPos<0 )
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 );
1043 else
1044 aCurPos.Y() += nVLine;
1045 break;
1046 case SID_CURSORLEFT:
1047 aCurPos.X() -= nHLine;
1048 break;
1049 case SID_CURSORRIGHT:
1050 aCurPos.X() += nHLine;
1051 break;
1052 case SID_CURSORPAGEUP:
1053 if( nThumbPos==0 || nMaxVertPos<0 )
1055 long nPage = pPreview->GetPageNo();
1057 if( nPage>0 )
1059 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1060 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
1061 Execute( aSfxRequest );
1062 aCurPos.Y() = nVRange;
1065 else
1066 aCurPos.Y() -= nVPage;
1067 break;
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 );
1085 aCurPos.Y() = 0;
1088 else
1089 aCurPos.Y() += nVPage;
1090 break;
1091 case SID_CURSORHOME:
1092 if( nMaxVertPos<0 )
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 );
1103 else
1105 aCurPos.Y() = 0;
1106 aCurPos.X() = 0;
1108 break;
1109 case SID_CURSOREND:
1110 if( nMaxVertPos<0 )
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 );
1123 else
1125 aCurPos.Y() = nVRange;
1126 aCurPos.X() = nHRange;
1128 break;
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 )
1136 aCurPos.Y() = 0;
1137 if( aCurPos.X() > (nHRange-nHPage) )
1138 aCurPos.X() = (nHRange-nHPage);
1139 if( aCurPos.X() < 0 )
1140 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 );
1176 else
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: */