bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / view / prevwsh.cxx
blob710fe9f23e2d398eea6f186d221c2bce4d5bcba5
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 "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"
43 #include "attrib.hxx"
44 #include "scmod.hxx"
45 #include "inputhdl.hxx"
46 #include "docsh.hxx"
47 #include "tabvwsh.hxx"
48 #include "stlpool.hxx"
49 #include "editutil.hxx"
50 #include "scresid.hxx"
51 #include "globstr.hrc"
52 #include "sc.hrc"
53 #include "ViewSettingsSequenceDefines.hxx"
54 #include "tpprint.hxx"
55 #include "printopt.hxx"
56 #include "viewuno.hxx"
57 #include <sax/tools/converter.hxx>
58 #include <rtl/ustrbuf.hxx>
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"
68 // for mouse wheel
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();
107 else
108 break;
111 mpFrameWindow = dynamic_cast<SystemWindow*>(pWin);
112 if (mpFrameWindow)
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();
135 if (pDrawBC)
136 StartListening(*pDrawBC);
138 pHorScroll->Show( false );
139 pVerScroll->Show( false );
140 pCorner->Show();
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() ),
149 mpFrameWindow(NULL),
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();
170 if ( pDrawView )
171 nSourceDesignMode = pDrawView->IsDesignMode();
174 new ScPreviewObj(this);
177 ScPreviewShell::~ScPreviewShell()
179 if (mpFrameWindow)
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();
187 if (pDrawBC)
188 EndListening(*pDrawBC);
189 EndListening(*SFX_APP());
190 EndListening(*pDocShell);
192 SetWindow(0);
193 delete pPreview;
194 delete pHorScroll;
195 delete pVerScroll;
196 delete pCorner;
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 String 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 );
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;
267 if (!GetPageSize( aPageSize ))
268 return;
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
279 if ( bFromZoom )
281 if ( bVert )
283 aWindowPixelSize.Width() += nBarH;
284 aWindowSize.Width() += aHeightOffSet;
286 if ( bHori )
288 aWindowPixelSize.Height() += nBarW;
289 aWindowSize.Height() += aWidthOffSet;
292 // recalculate any needed scrollbars
293 bHori = false;
294 bVert = false;
296 long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width();
297 if ( nMaxWidthPos<0 )
298 bHori = false;
299 else
300 bHori = true;
302 long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height();
304 if ( nMaxHeightPos < 0 )
305 bVert = false;
306 else
307 bVert = true;
309 // see if having a scroll bar requires the other
310 if ( bVert != bHori && ( bVert || bHori ) )
312 if ( bVert && ( (nMaxWidthPos + aWidthOffSet ) > 0 ) )
313 bHori = true;
314 else if ( (nMaxHeightPos + aHeightOffSet ) > 0 )
315 bVert = true;
317 pHorScroll->Show( bHori );
318 pVerScroll->Show( bVert );
320 // make room for needed scrollbars ( and reduce the size
321 // of the preview appropriately )
322 if ( bHori )
323 aWindowPixelSize.Height() -= nBarW;
324 if ( bVert )
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 ) );
334 UpdateScrollBars();
337 void ScPreviewShell::UpdateScrollBars()
339 Size aPageSize;
340 if ( !GetPageSize( aPageSize ) )
341 return;
343 // for centering, page size without the shadow is used
345 Size aWindowSize = pPreview->GetOutputSize();
347 Point aOfs = pPreview->GetOffset();
349 if( pHorScroll )
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();
356 if ( nMaxPos<0 )
358 // page smaller than window -> center (but put scrollbar to 0)
359 aOfs.X() = 0;
360 pPreview->SetXOffset( nMaxPos / 2 );
362 else if (aOfs.X() < 0)
364 // page larger than window -> never use negative offset
365 aOfs.X() = 0;
366 pPreview->SetXOffset( 0 );
368 else if (aOfs.X() > nMaxPos)
370 // limit offset to align with right edge of window
371 aOfs.X() = nMaxPos;
372 pPreview->SetXOffset(nMaxPos);
374 pHorScroll->SetThumbPos( aOfs.X() );
377 if( pVerScroll )
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)
389 aOfs.Y() = 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() ) );
398 aOfs.Y() = 0;
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();
419 long nPageNo = 0;
420 long nPerPageLength = 0;
421 sal_Bool bIsDivide = sal_True;
423 if( nTotalPages )
424 nPerPageLength = nMaxRange / nTotalPages;
426 if( nPerPageLength )
428 nPageNo = nPos / nPerPageLength;
429 if( nPos % nPerPageLength )
431 bIsDivide = false;
432 nPageNo ++;
436 sal_Bool bHoriz = ( pScroll == pHorScroll );
438 if( bHoriz )
439 pPreview->SetXOffset( nPos );
440 else
442 if( nMaxVertPos > 0 )
443 pPreview->SetYOffset( nPos );
444 else
446 Point aMousePos = pScroll->OutputToNormalizedScreenPixel( pScroll->GetPointerPosPixel() );
447 Point aPos = pScroll->GetParent()->OutputToNormalizedScreenPixel( pScroll->GetPosPixel() );
448 OUString aHelpStr;
449 Rectangle aRect;
450 sal_uInt16 nAlign;
452 if( nDelta < 0 )
454 if ( nTotalPages && nPageNo > 0 && !bIsDivide )
455 pPreview->SetPageNo( nPageNo-1 );
456 if( bIsDivide )
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 );
483 return 0;
486 IMPL_LINK (ScPreviewShell, CloseHdl, SystemWindow*, EMPTYARG)
488 ExitPreview();
489 return 0;
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();
499 long nNew = nOld;
500 if ( pData->GetDelta() < 0 )
501 nNew = std::max( (long) MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
502 else
503 nNew = std::min( (long) MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
505 if ( nNew != nOld )
507 eZoom = SVX_ZOOM_PERCENT;
508 pPreview->SetZoom( (sal_uInt16)nNew );
511 bDone = sal_True;
513 else
515 bDone = pPreview->HandleScrollCommand( rCEvt, pHorScroll, pVerScroll );
518 return bDone;
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
533 return true;
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);
543 return 0;
546 void ScPreviewShell::Activate(sal_Bool bMDI)
548 SfxViewShell::Activate(bMDI);
550 //! Basic etc. -> auslagern in eigene Datei (s. tabvwsh4)
552 if (bMDI)
554 // InputHdl ist jetzt meistens Null, keine Assertion mehr!
555 ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
556 if ( pInputHdl )
557 pInputHdl->NotifyChange( NULL );
561 void ScPreviewShell::Deactivate(sal_Bool bMDI)
563 SfxViewShell::Deactivate(bMDI);
565 if (bMDI)
570 //------------------------------------------------------------------------
572 void ScPreviewShell::Execute( SfxRequest& rReq )
574 sal_uInt16 nSlot = rReq.GetSlot();
575 const SfxItemSet* pReqArgs = rReq.GetArgs();
577 switch ( nSlot )
579 case SID_FORMATPAGE:
580 case SID_STATUS_PAGESTYLE:
581 case SID_HFEDIT:
582 pDocShell->ExecutePageStyle( *this, rReq, pPreview->GetTab() );
583 break;
584 case SID_REPAINT:
585 pPreview->Invalidate();
586 rReq.Done();
587 break;
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 );
596 break;
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 );
606 break;
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 );
615 break;
616 case SID_CURSORENDOFFILE: // Accelerator
617 case SID_PREVIEW_LAST:
619 if (!pPreview->AllTested())
620 pPreview->CalcAll();
622 long nPage = pPreview->GetPageNo();
623 long nTotal = pPreview->GetTotalPages();
624 if (nTotal && nPage+1 != nTotal)
625 pPreview->SetPageNo( nTotal-1 );
627 break;
628 case SID_ATTR_ZOOM:
629 case FID_SCALE:
631 sal_uInt16 nZoom = 100;
632 sal_Bool bCancel = false;
634 eZoom = SVX_ZOOM_PERCENT;
636 if ( pReqArgs )
639 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
640 pReqArgs->Get(SID_ATTR_ZOOM);
642 eZoom = rZoomItem.GetType();
643 nZoom = rZoomItem.GetValue();
645 else
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();
652 if(pFact)
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() );
660 if ( !bCancel )
662 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
663 pDlg->GetOutputItemSet()->
664 Get( SID_ATTR_ZOOM );
666 eZoom = rZoomItem.GetType();
667 nZoom = rZoomItem.GetValue();
670 delete pDlg;
674 if ( !bCancel )
676 switch ( eZoom )
678 case SVX_ZOOM_OPTIMAL:
679 case SVX_ZOOM_WHOLEPAGE:
680 nZoom = pPreview->GetOptimalZoom(false);
681 break;
682 case SVX_ZOOM_PAGEWIDTH:
683 nZoom = pPreview->GetOptimalZoom(sal_True);
684 break;
685 default:
687 // added to avoid warnings
691 pPreview->SetZoom( nZoom );
692 rReq.Done();
695 break;
696 case SID_PREVIEW_ZOOMIN:
698 sal_uInt16 nNew = pPreview->GetZoom() + 20 ;
699 nNew -= nNew % 20;
700 pPreview->SetZoom( nNew );
701 eZoom = SVX_ZOOM_PERCENT;
702 rReq.Done();
704 break;
705 case SID_PREVIEW_ZOOMOUT:
707 sal_uInt16 nNew = pPreview->GetZoom() - 1;
708 nNew -= nNew % 20;
709 pPreview->SetZoom( nNew );
710 eZoom = SVX_ZOOM_PERCENT;
711 rReq.Done();
713 break;
714 case SID_PREVIEW_MARGIN:
716 sal_Bool bMargin = pPreview->GetPageMargins();
717 pPreview->SetPageMargins( !bMargin );
718 pPreview->Invalidate();
719 rReq.Done();
721 break;
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();
729 if( nCurrentZoom )
731 pPreview->SetZoom( nCurrentZoom );
732 rReq.Done();
736 break;
737 case SID_PREVIEW_SCALINGFACTOR:
739 const SfxPoolItem* pItem;
740 SCTAB nTab = pPreview->GetTab();
741 String 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();
753 rReq.Done();
755 GetViewFrame()->GetBindings().Invalidate( nSlot );
757 break;
758 case SID_PRINTPREVIEW:
759 case SID_PREVIEW_CLOSE:
760 // print preview is now always in the same frame as the tab view
761 // -> always switch this frame back to normal view
762 // (ScTabViewShell ctor reads stored view data)
764 ExitPreview();
765 break;
766 case SID_CURSORPAGEUP:
767 case SID_CURSORPAGEDOWN:
768 case SID_CURSORHOME:
769 case SID_CURSOREND:
770 case SID_CURSORUP:
771 case SID_CURSORDOWN:
772 case SID_CURSORLEFT:
773 case SID_CURSORRIGHT:
774 DoScroll( nSlot );
775 break;
776 case SID_CANCEL:
777 if( ScViewUtil::IsFullScreen( *this ) )
778 ScViewUtil::SetFullScreen( *this, false );
779 break;
781 default:
782 break;
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();
798 while ( nWhich )
800 switch (nWhich)
802 case SID_STATUS_PAGESTYLE:
803 case SID_HFEDIT:
804 pDocShell->GetStatePageStyle( *this, rSet, nTab );
805 break;
806 case SID_UNDO:
807 case SID_REDO:
808 case SID_REPEAT:
809 case SID_SAVEDOC:
810 case SID_SAVEASDOC:
811 case SID_MAIL_SENDDOC:
812 case SID_VIEW_DATA_SOURCE_BROWSER:
813 case SID_QUITAPP:
814 rSet.DisableItem(nWhich);
815 break;
816 case SID_PREVIEW_PREVIOUS:
817 case SID_PREVIEW_FIRST:
818 if (!nTotal || nPage==0)
819 rSet.DisableItem(nWhich);
820 break;
821 case SID_PREVIEW_NEXT:
822 case SID_PREVIEW_LAST:
823 if (bAllTested)
824 if (!nTotal || nPage==nTotal-1)
825 rSet.DisableItem(nWhich);
826 break;
827 case SID_PREVIEW_ZOOMIN:
828 if (nZoom >= 400)
829 rSet.DisableItem(nWhich);
830 break;
831 case SID_PREVIEW_ZOOMOUT:
832 if (nZoom <= 20)
833 rSet.DisableItem(nWhich);
834 break;
835 case SID_ATTR_ZOOM:
837 SvxZoomItem aZoom( eZoom, nZoom, nWhich );
838 aZoom.SetValueSet( SVX_ZOOM_ENABLE_ALL & ~SVX_ZOOM_ENABLE_OPTIMAL );
839 rSet.Put( aZoom );
841 break;
842 case SID_ATTR_ZOOMSLIDER:
844 SvxZoomSliderItem aZoomSliderItem( nZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
845 aZoomSliderItem.AddSnappingPoint( 100 );
846 rSet.Put( aZoomSliderItem );
848 break;
849 case SID_PREVIEW_SCALINGFACTOR:
851 if( pDocShell->IsReadOnly() )
852 rSet.DisableItem( nWhich );
853 else
855 String 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! :-/" );
860 if ( pStyleSheet )
862 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
863 sal_uInt16 nCurrentZoom = ((const SfxUInt16Item&)rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
864 if( nCurrentZoom )
866 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM_SLIDER, MAXZOOM_SLIDER, SID_PREVIEW_SCALINGFACTOR );
867 aZoomSliderItem.AddSnappingPoint( 100 );
868 rSet.Put( aZoomSliderItem );
870 else
871 rSet.DisableItem( nWhich );
875 break;
876 case SID_STATUS_DOCPOS:
877 rSet.Put( SfxStringItem( nWhich, pPreview->GetPosString() ) );
878 break;
879 case SID_PRINTPREVIEW:
880 rSet.Put( SfxBoolItem( nWhich, sal_True ) );
881 break;
882 case SID_FORMATPAGE:
883 case SID_PREVIEW_MARGIN:
884 if( pDocShell->IsReadOnly() )
885 rSet.DisableItem( nWhich );
886 break;
889 nWhich = aIter.NextWhich();
892 pPreview->SetInGetState(false);
895 void ScPreviewShell::FillFieldData( ScHeaderFieldData& rData )
897 ScDocument* pDoc = pDocShell->GetDocument();
898 SCTAB nTab = pPreview->GetTab();
899 OUString aTmp;
900 pDoc->GetName(nTab, aTmp);
901 rData.aTabName = aTmp;
903 if( pDocShell->getDocProperties()->getTitle().getLength() != 0 )
904 rData.aTitle = pDocShell->getDocProperties()->getTitle();
905 else
906 rData.aTitle = pDocShell->GetTitle();
908 const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
909 rData.aLongDocName = rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
910 if ( rData.aLongDocName.Len() )
911 rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS );
912 else
913 rData.aShortDocName = rData.aLongDocName = rData.aTitle;
914 rData.nPageNo = pPreview->GetPageNo() + 1;
916 sal_Bool bAllTested = pPreview->AllTested();
917 if (bAllTested)
918 rData.nTotalPages = pPreview->GetTotalPages();
919 else
920 rData.nTotalPages = 99;
922 // the dialog knows eNumType
925 void ScPreviewShell::WriteUserData(String& rData, sal_Bool /* bBrowse */)
927 // nZoom
928 // nPageNo
930 rData = OUString::number(pPreview->GetZoom());
931 rData += (sal_Unicode) SC_USERDATA_SEP;
932 rData += OUString::number(pPreview->GetPageNo());
935 void ScPreviewShell::ReadUserData(const String& rData, sal_Bool /* bBrowse */)
937 xub_StrLen nCount = comphelper::string::getTokenCount(rData, ';');
938 if (nCount)
940 sal_Int32 nIndex = 0;
941 pPreview->SetZoom((sal_uInt16)rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32());
942 pPreview->SetPageNo(rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32());
943 eZoom = SVX_ZOOM_PERCENT;
947 void ScPreviewShell::WriteUserDataSequence(uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */)
949 rSeq.realloc(3);
950 beans::PropertyValue* pSeq = rSeq.getArray();
951 if(pSeq)
953 sal_uInt16 nViewID(GetViewFrame()->GetCurViewId());
954 pSeq[0].Name = OUString(SC_VIEWID);
955 OUStringBuffer sBuffer(OUString(SC_VIEW));
956 ::sax::Converter::convertNumber(sBuffer,
957 static_cast<sal_Int32>(nViewID));
958 pSeq[0].Value <<= sBuffer.makeStringAndClear();
959 pSeq[1].Name = OUString(SC_ZOOMVALUE);
960 pSeq[1].Value <<= sal_Int32 (pPreview->GetZoom());
961 pSeq[2].Name = OUString("PageNumber");
962 pSeq[2].Value <<= pPreview->GetPageNo();
966 void ScPreviewShell::ReadUserDataSequence(const uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */)
968 sal_Int32 nCount(rSeq.getLength());
969 if (nCount)
971 const beans::PropertyValue* pSeq = rSeq.getConstArray();
972 if(pSeq)
974 for(sal_Int32 i = 0; i < nCount; i++, pSeq++)
976 OUString sName(pSeq->Name);
977 if(sName.compareToAscii(SC_ZOOMVALUE) == 0)
979 sal_Int32 nTemp = 0;
980 if (pSeq->Value >>= nTemp)
981 pPreview->SetZoom(sal_uInt16(nTemp));
983 else if (sName.compareToAscii("PageNumber") == 0)
985 sal_Int32 nTemp = 0;
986 if (pSeq->Value >>= nTemp)
987 pPreview->SetPageNo(nTemp);
994 void ScPreviewShell::DoScroll( sal_uInt16 nMode )
996 Point aCurPos, aPrevPos;
998 long nHRange = pHorScroll->GetRange().Max();
999 long nHLine = pHorScroll->GetLineSize();
1000 long nHPage = pHorScroll->GetPageSize();
1001 long nVRange = pVerScroll->GetRange().Max();
1002 long nVLine = pVerScroll->GetLineSize();
1003 long nVPage = pVerScroll->GetPageSize();
1005 aCurPos.X() = pHorScroll->GetThumbPos();
1006 aCurPos.Y() = pVerScroll->GetThumbPos();
1007 aPrevPos = aCurPos;
1009 long nThumbPos = pVerScroll->GetThumbPos();
1010 long nRangeMax = pVerScroll->GetRangeMax();
1012 switch( nMode )
1014 case SID_CURSORUP:
1015 if( nMaxVertPos<0 )
1017 long nPage = pPreview->GetPageNo();
1019 if( nPage>0 )
1021 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1022 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
1023 Execute( aSfxRequest );
1026 else
1027 aCurPos.Y() -= nVLine;
1028 break;
1029 case SID_CURSORDOWN:
1030 if( nMaxVertPos<0 )
1032 long nPage = pPreview->GetPageNo();
1033 long nTotal = pPreview->GetTotalPages();
1035 // before testing for last page, make sure all page counts are calculated
1036 if ( nPage+1 == nTotal && !pPreview->AllTested() )
1038 pPreview->CalcAll();
1039 nTotal = pPreview->GetTotalPages();
1042 if( nPage<nTotal-1 )
1044 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1045 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT );
1046 Execute( aSfxRequest );
1049 else
1050 aCurPos.Y() += nVLine;
1051 break;
1052 case SID_CURSORLEFT:
1053 aCurPos.X() -= nHLine;
1054 break;
1055 case SID_CURSORRIGHT:
1056 aCurPos.X() += nHLine;
1057 break;
1058 case SID_CURSORPAGEUP:
1059 if( nThumbPos==0 || nMaxVertPos<0 )
1061 long nPage = pPreview->GetPageNo();
1063 if( nPage>0 )
1065 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1066 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
1067 Execute( aSfxRequest );
1068 aCurPos.Y() = nVRange;
1071 else
1072 aCurPos.Y() -= nVPage;
1073 break;
1074 case SID_CURSORPAGEDOWN:
1075 if( (abs(nVPage+nThumbPos-nRangeMax)<10) || nMaxVertPos<0 )
1077 long nPage = pPreview->GetPageNo();
1078 long nTotal = pPreview->GetTotalPages();
1080 // before testing for last page, make sure all page counts are calculated
1081 if ( nPage+1 == nTotal && !pPreview->AllTested() )
1083 pPreview->CalcAll();
1084 nTotal = pPreview->GetTotalPages();
1086 if( nPage<nTotal-1 )
1088 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1089 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT );
1090 Execute( aSfxRequest );
1091 aCurPos.Y() = 0;
1094 else
1095 aCurPos.Y() += nVPage;
1096 break;
1097 case SID_CURSORHOME:
1098 if( nMaxVertPos<0 )
1100 long nPage = pPreview->GetPageNo();
1101 long nTotal = pPreview->GetTotalPages();
1102 if( nTotal && nPage != 0 )
1104 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1105 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_FIRST );
1106 Execute( aSfxRequest );
1109 else
1111 aCurPos.Y() = 0;
1112 aCurPos.X() = 0;
1114 break;
1115 case SID_CURSOREND:
1116 if( nMaxVertPos<0 )
1118 if( !pPreview->AllTested() )
1119 pPreview->CalcAll();
1120 long nPage = pPreview->GetPageNo();
1121 long nTotal = pPreview->GetTotalPages();
1122 if( nTotal && nPage+1 != nTotal )
1124 SfxViewFrame* pSfxViewFrame = GetViewFrame();
1125 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_LAST );
1126 Execute( aSfxRequest );
1129 else
1131 aCurPos.Y() = nVRange;
1132 aCurPos.X() = nHRange;
1134 break;
1137 // nHRange-nHPage might be negative, that's why we check for < 0 afterwards
1139 if( aCurPos.Y() > (nVRange-nVPage) )
1140 aCurPos.Y() = (nVRange-nVPage);
1141 if( aCurPos.Y() < 0 )
1142 aCurPos.Y() = 0;
1143 if( aCurPos.X() > (nHRange-nHPage) )
1144 aCurPos.X() = (nHRange-nHPage);
1145 if( aCurPos.X() < 0 )
1146 aCurPos.X() = 0;
1148 if( nMaxVertPos>=0 )
1150 if( aCurPos.Y() != aPrevPos.Y() )
1152 pVerScroll->SetThumbPos( aCurPos.Y() );
1153 pPreview->SetYOffset( aCurPos.Y() );
1157 if( aCurPos.X() != aPrevPos.X() )
1159 pHorScroll->SetThumbPos( aCurPos.X() );
1160 pPreview->SetXOffset( aCurPos.X() );
1165 void ScPreviewShell::ExitPreview()
1167 GetViewFrame()->GetDispatcher()->Execute(SID_VIEWSHELL0, SFX_CALLMODE_ASYNCHRON);
1170 void ScPreviewShell::AddAccessibilityObject( SfxListener& rObject )
1172 if (!pAccessibilityBroadcaster)
1173 pAccessibilityBroadcaster = new SfxBroadcaster;
1175 rObject.StartListening( *pAccessibilityBroadcaster );
1178 void ScPreviewShell::RemoveAccessibilityObject( SfxListener& rObject )
1180 if (pAccessibilityBroadcaster)
1181 rObject.EndListening( *pAccessibilityBroadcaster );
1182 else
1184 OSL_FAIL("kein Accessibility-Broadcaster?");
1188 void ScPreviewShell::BroadcastAccessibility( const SfxHint &rHint )
1190 if (pAccessibilityBroadcaster)
1191 pAccessibilityBroadcaster->Broadcast( rHint );
1194 sal_Bool ScPreviewShell::HasAccessibilityObjects()
1196 return pAccessibilityBroadcaster && pAccessibilityBroadcaster->HasListeners();
1199 const ScPreviewLocationData& ScPreviewShell::GetLocationData()
1201 return pPreview->GetLocationData();
1204 ScDocument* ScPreviewShell::GetDocument()
1206 return pDocShell->GetDocument();
1210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */