1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: prevwsh.cxx,v $
10 * $Revision: 1.44.30.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
41 #include <sfx2/app.hxx>
42 #include <svx/sizeitem.hxx>
43 #include <svx/srchitem.hxx>
44 #include <svx/zoomslideritem.hxx>
45 #include <svx/svdview.hxx>
46 //CHINA001 #include <svx/zoom.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <sfx2/objface.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/topfrm.hxx>
51 #include <svtools/printdlg.hxx>
52 #include <svtools/stritem.hxx>
53 #include <svtools/whiter.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <vcl/help.hxx>
56 #include <tools/urlobj.hxx>
57 #include <sfx2/docfile.hxx>
58 #include <sfx2/printer.hxx>
60 #ifndef _SVX_ZOOMSLIDERITEM_HXX
61 #include <svx/zoomslideritem.hxx>
63 #include "prevwsh.hxx"
64 #include "preview.hxx"
65 #include "printfun.hxx"
68 #include "inputhdl.hxx"
70 #include "tabvwsh.hxx"
71 #include "stlpool.hxx"
72 #include "editutil.hxx"
73 #include "scresid.hxx"
74 #include "globstr.hrc"
76 #include "ViewSettingsSequenceDefines.hxx"
77 #include "tpprint.hxx"
78 #include "printopt.hxx"
79 #include <xmloff/xmluconv.hxx>
80 #include <rtl/ustrbuf.hxx>
82 #include <svx/svxdlg.hxx> //CHINA001
83 #include <svx/dialogs.hrc> //CHINA001
86 #include <svx/zoom_def.hxx>
89 #include "sc.hrc" //CHINA001
90 #include "scabstdlg.hxx" //CHINA001
92 #define SC_DELTA_ZOOM 10
93 #define MINZOOM_SLIDER 10
94 #define MAXZOOM_SLIDER 400
96 #define SC_USERDATA_SEP ';'
98 using namespace com::sun::star
;
100 // -----------------------------------------------------------------------
102 #define ScPreviewShell
103 #include "scslots.hxx"
105 TYPEINIT1( ScPreviewShell
, SfxViewShell
);
107 SFX_IMPL_INTERFACE( ScPreviewShell
, SfxViewShell
, ScResId(SCSTR_PREVIEWSHELL
) )
109 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT
|SFX_VISIBILITY_STANDARD
|
110 SFX_VISIBILITY_SERVER
|SFX_VISIBILITY_READONLYDOC
,
111 ScResId(RID_OBJECTBAR_PREVIEW
));
112 SFX_POPUPMENU_REGISTRATION(ScResId(RID_POPUP_PREVIEW
));
115 SFX_IMPL_VIEWFACTORY( ScPreviewShell
, ScResId(STR_NONAME
) )
117 SFX_VIEW_REGISTRATION(ScDocShell
);
120 //------------------------------------------------------------------
122 void ScPreviewShell::Construct( Window
* pParent
)
124 eZoom
= SVX_ZOOM_WHOLEPAGE
;
126 pCorner
= new ScrollBarBox( pParent
, WB_SIZEABLE
);
128 pHorScroll
= new ScrollBar(pParent
, WB_HSCROLL
);
129 pVerScroll
= new ScrollBar(pParent
, WB_VSCROLL
);
131 // SSA: --- RTL --- no mirroring for horizontal scrollbars
132 pHorScroll
->EnableRTL( FALSE
);
134 pHorScroll
->SetEndScrollHdl( LINK( this, ScPreviewShell
, ScrollHandler
) );
135 pVerScroll
->SetEndScrollHdl( LINK( this, ScPreviewShell
, ScrollHandler
) );
137 pPreview
= new ScPreview( pParent
, pDocShell
, this );
139 SetPool( &SC_MOD()->GetPool() );
140 SetWindow( pPreview
);
141 StartListening(*pDocShell
,TRUE
);
142 StartListening(*SFX_APP(),TRUE
); // #i62045# #i62046# application is needed for Calc's own hints
143 SfxBroadcaster
* pDrawBC
= pDocShell
->GetDocument()->GetDrawBroadcaster();
145 StartListening(*pDrawBC
);
147 // pPreview->Show(); // wird vom Sfx angezeigt
151 SetHelpId( HID_SCSHELL_PREVWSH
);
152 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Preview")));
155 ScPreviewShell::ScPreviewShell( SfxViewFrame
* pViewFrame
,
156 SfxViewShell
* pOldSh
) :
157 SfxViewShell( pViewFrame
, SFX_VIEW_MAXIMIZE_FIRST
| SFX_VIEW_CAN_PRINT
| SFX_VIEW_HAS_PRINTOPTIONS
),
158 pDocShell( (ScDocShell
*)pViewFrame
->GetObjectShell() ),
159 nSourceDesignMode( SC_FORCEMODE_NONE
),
160 pAccessibilityBroadcaster( NULL
)
162 Construct( &pViewFrame
->GetWindow() );
164 if ( pOldSh
&& pOldSh
->ISA( ScTabViewShell
) )
166 // store view settings, show table from TabView
167 //! store live ScViewData instead, and update on ScTablesHint?
168 //! or completely forget aSourceData on ScTablesHint?
170 ScTabViewShell
* pTabViewShell
= ((ScTabViewShell
*)pOldSh
);
171 ScViewData
* pData
= pTabViewShell
->GetViewData();
172 pData
->WriteUserDataSequence( aSourceData
);
173 InitStartTable( pData
->GetTabNo() );
175 // #106334# also have to store the TabView's DesignMode state
176 // (only if draw view exists)
177 SdrView
* pDrawView
= pTabViewShell
->GetSdrView();
179 nSourceDesignMode
= pDrawView
->IsDesignMode();
183 __EXPORT
ScPreviewShell::~ScPreviewShell()
185 // #108333#; notify Accessibility that Shell is dying and before destroy all
186 BroadcastAccessibility( SfxSimpleHint( SFX_HINT_DYING
) );
187 DELETEZ(pAccessibilityBroadcaster
);
189 SfxBroadcaster
* pDrawBC
= pDocShell
->GetDocument()->GetDrawBroadcaster();
191 EndListening(*pDrawBC
);
192 EndListening(*SFX_APP());
193 EndListening(*pDocShell
);
201 // #97612# normal mode of operation is switching back to default view in the same frame,
202 // so there's no need to activate any other window here anymore
205 void ScPreviewShell::InitStartTable(SCTAB nTab
)
207 pPreview
->SetPageNo( pPreview
->GetFirstPage(nTab
) );
210 //------------------------------------------------------------------
212 String __EXPORT
ScPreviewShell::GetDescription() const
214 return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" ** Test ** "));
217 Size __EXPORT
ScPreviewShell::GetOptimalSizePixel() const
219 Size
aOptSize(100,100);
221 ScTabViewShell
* pViewSh
= pDocShell
->GetBestViewShell();
225 ScViewData
* pViewData
= pViewSh
->GetViewData();
226 SCTAB nCurTab
= pViewData
->GetTabNo();
227 ScDocument
* pDoc
= pDocShell
->GetDocument();
228 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
229 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find(
230 pDoc
->GetPageStyle( nCurTab
),
231 SFX_STYLE_FAMILY_PAGE
);
233 DBG_ASSERT( pStyleSheet
, "PageStyle not found :-/" );
237 const SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
238 const SvxSizeItem
& rItem
= (const SvxSizeItem
&)rSet
.Get( ATTR_PAGE_SIZE
);
239 const Size
& rPageSize
= rItem
.GetSize();
241 aOptSize
.Width() = (long) (rPageSize
.Width() * pViewData
->GetPPTX());
242 aOptSize
.Height() = (long) (rPageSize
.Height() * pViewData
->GetPPTY());
247 DBG_ERROR( "TabViewShell not found :-/" );
253 void __EXPORT
ScPreviewShell::AdjustPosSizePixel( const Point
&rPos
, const Size
&rSize
)
255 long nBarW
= GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
257 // long nBarW = pVerScroll->GetSizePixel().Width();
258 // long nBarH = pHorScroll->GetSizePixel().Height();
260 Size
aOutSize( rSize
.Width()-nBarW
, rSize
.Height()-nBarH
);
261 pPreview
->SetPosSizePixel( rPos
, aOutSize
);
262 pHorScroll
->SetPosSizePixel( Point( rPos
.X(), rPos
.Y() + aOutSize
.Height() ),
263 Size( aOutSize
.Width(), nBarH
) );
264 pVerScroll
->SetPosSizePixel( Point( rPos
.X() + aOutSize
.Width(), rPos
.Y() ),
265 Size( nBarW
, aOutSize
.Height() ) );
266 pCorner
->SetPosSizePixel( Point( rPos
.X() + aOutSize
.Width(), rPos
.Y() + aOutSize
.Height() ),
267 Size( nBarW
, nBarH
) );
269 if ( SVX_ZOOM_WHOLEPAGE
== eZoom
)
270 pPreview
->SetZoom( pPreview
->GetOptimalZoom(FALSE
) );
271 else if ( SVX_ZOOM_PAGEWIDTH
== eZoom
)
272 pPreview
->SetZoom( pPreview
->GetOptimalZoom(TRUE
) );
277 void __EXPORT
ScPreviewShell::InnerResizePixel( const Point
&rOfs
, const Size
&rSize
)
279 AdjustPosSizePixel( rOfs
,rSize
);
282 void __EXPORT
ScPreviewShell::OuterResizePixel( const Point
&rOfs
, const Size
&rSize
)
284 AdjustPosSizePixel( rOfs
,rSize
);
287 void ScPreviewShell::UpdateScrollBars()
289 ScDocument
* pDoc
= pDocShell
->GetDocument();
290 SCTAB nTab
= pPreview
->GetTab();
292 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
293 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( pDoc
->GetPageStyle( nTab
),
294 SFX_STYLE_FAMILY_PAGE
);
295 DBG_ASSERT(pStyleSheet
,"StyleSheet nicht gefunden");
296 if (!pStyleSheet
) return;
297 const SfxItemSet
* pParamSet
= &pStyleSheet
->GetItemSet();
299 Size aPageSize
= ((const SvxSizeItem
&) pParamSet
->Get(ATTR_PAGE_SIZE
)).GetSize();
300 aPageSize
.Width() = (long) (aPageSize
.Width() * HMM_PER_TWIPS
);
301 aPageSize
.Height() = (long) (aPageSize
.Height() * HMM_PER_TWIPS
);
303 // for centering, page size without the shadow is used
305 Size aWindowSize
= pPreview
->GetOutputSize();
307 Point aOfs
= pPreview
->GetOffset();
312 pHorScroll
->SetRange( Range( 0, aPageSize
.Width() ) );
313 pHorScroll
->SetLineSize( aWindowSize
.Width() / 16 );
314 pHorScroll
->SetPageSize( aWindowSize
.Width() );
315 pHorScroll
->SetVisibleSize( aWindowSize
.Width() );
316 nMaxPos
= aPageSize
.Width() - aWindowSize
.Width();
319 // page smaller than window -> center (but put scrollbar to 0)
321 pPreview
->SetXOffset( nMaxPos
/ 2 );
323 else if (aOfs
.X() < 0)
325 // page larger than window -> never use negative offset
327 pPreview
->SetXOffset( 0 );
329 else if (aOfs
.X() > nMaxPos
)
331 // limit offset to align with right edge of window
333 pPreview
->SetXOffset(nMaxPos
);
335 pHorScroll
->SetThumbPos( aOfs
.X() );
340 long nPageNo
= pPreview
->GetPageNo();
341 long nTotalPages
= pPreview
->GetTotalPages();
343 nMaxVertPos
= aPageSize
.Height() - aWindowSize
.Height();
344 pVerScroll
->SetLineSize( aWindowSize
.Height() / 16 );
345 pVerScroll
->SetPageSize( aWindowSize
.Height() );
346 pVerScroll
->SetVisibleSize( aWindowSize
.Height() );
347 if ( nMaxVertPos
< 0 )
349 // page smaller than window -> center (but put scrollbar to 0)
351 pPreview
->SetYOffset( nMaxVertPos
/ 2 );
352 pVerScroll
->SetThumbPos( nPageNo
* aWindowSize
.Height() );
353 pVerScroll
->SetRange( Range( 0, aWindowSize
.Height() * nTotalPages
));
355 else if (aOfs
.Y() < 0)
357 // page larger than window -> never use negative offset
358 pVerScroll
->SetRange( Range( 0, aPageSize
.Height() ) );
360 pPreview
->SetYOffset( 0 );
361 pVerScroll
->SetThumbPos( aOfs
.Y() );
363 else if (aOfs
.Y() > nMaxVertPos
)
365 // limit offset to align with window bottom
366 pVerScroll
->SetRange( Range( 0, aPageSize
.Height() ) );
367 aOfs
.Y() = nMaxVertPos
;
368 pPreview
->SetYOffset( nMaxVertPos
);
369 pVerScroll
->SetThumbPos( aOfs
.Y() );
374 IMPL_LINK (ScPreviewShell
,ScrollHandler
, ScrollBar
* ,pScroll
)
376 long nPos
= pScroll
->GetThumbPos();
377 long nDelta
= pScroll
->GetDelta();
378 long nMaxRange
= pScroll
->GetRangeMax();
379 long nTotalPages
= pPreview
->GetTotalPages();
381 long nPerPageLength
= 0;
382 BOOL bIsDivide
= TRUE
;
385 nPerPageLength
= nMaxRange
/ nTotalPages
;
389 nPageNo
= nPos
/ nPerPageLength
;
390 if( nPos
% nPerPageLength
)
397 BOOL bHoriz
= ( pScroll
== pHorScroll
);
400 pPreview
->SetXOffset( nPos
);
403 if( nMaxVertPos
> 0 )
404 pPreview
->SetYOffset( nPos
);
407 Point aMousePos
= pScroll
->OutputToNormalizedScreenPixel( pScroll
->GetPointerPosPixel() );
408 Point aPos
= pScroll
->GetParent()->OutputToNormalizedScreenPixel( pScroll
->GetPosPixel() );
415 if ( nTotalPages
&& nPageNo
> 0 && !bIsDivide
)
416 pPreview
->SetPageNo( nPageNo
-1 );
418 pPreview
->SetPageNo( nPageNo
);
420 aHelpStr
= ScGlobal::GetRscString( STR_PAGE
);
422 aHelpStr
+= String::CreateFromInt32( nPageNo
);
424 aHelpStr
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
425 aHelpStr
+= String::CreateFromInt32( nTotalPages
);
427 else if( nDelta
> 0 )
429 BOOL bAllTested
= pPreview
->AllTested();
430 if ( nTotalPages
&& ( nPageNo
< nTotalPages
|| !bAllTested
) )
431 pPreview
->SetPageNo( nPageNo
);
433 aHelpStr
= ScGlobal::GetRscString( STR_PAGE
);
435 aHelpStr
+= String::CreateFromInt32( nPageNo
+1 );
437 aHelpStr
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
438 aHelpStr
+= String::CreateFromInt32( nTotalPages
);
441 aRect
.Left() = aPos
.X() - 8;
442 aRect
.Top() = aMousePos
.Y();
443 aRect
.Right() = aRect
.Left();
444 aRect
.Top() = aRect
.Top();
445 nAlign
= QUICKHELP_BOTTOM
|QUICKHELP_CENTER
;
446 Help::ShowQuickHelp( pScroll
->GetParent(), aRect
, aHelpStr
, nAlign
);
453 BOOL
ScPreviewShell::ScrollCommand( const CommandEvent
& rCEvt
)
456 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
457 if ( pData
&& pData
->GetMode() == COMMAND_WHEEL_ZOOM
)
459 long nOld
= pPreview
->GetZoom();
461 if ( pData
->GetDelta() < 0 )
462 nNew
= Max( (long) MINZOOM
, (long)( nOld
- SC_DELTA_ZOOM
) );
464 nNew
= Min( (long) MAXZOOM
, (long)( nOld
+ SC_DELTA_ZOOM
) );
468 eZoom
= SVX_ZOOM_PERCENT
;
469 pPreview
->SetZoom( (USHORT
)nNew
);
476 bDone
= pPreview
->HandleScrollCommand( rCEvt
, pHorScroll
, pVerScroll
);
482 SfxPrinter
* __EXPORT
ScPreviewShell::GetPrinter( BOOL bCreate
)
484 return pDocShell
->GetPrinter(bCreate
);
487 USHORT __EXPORT
ScPreviewShell::SetPrinter( SfxPrinter
*pNewPrinter
, USHORT nDiffFlags
, bool )
489 return pDocShell
->SetPrinter( pNewPrinter
, nDiffFlags
);
492 PrintDialog
* __EXPORT
ScPreviewShell::CreatePrintDialog( Window
* pParent
)
494 pDocShell
->GetDocument()->SetPrintOptions(); // Optionen aus OFA am Printer setzen
497 const long nCurPage
= pPreview
->GetPageNo()+1;
498 const long nDocPageMax
= pPreview
->GetTotalPages();
499 PrintDialog
* pDlg
= new PrintDialog( pParent
, true );
500 // wenn zu langsam wieder einbauen
501 // if ( pPreview->AllTested() )
502 // nPageMax = pPreview->GetTotalPages();
504 pDlg
->EnableSheetRange( true, PRINTSHEETS_ALL
);
505 pDlg
->EnableSheetRange( true, PRINTSHEETS_SELECTED_SHEETS
);
506 pDlg
->EnableSheetRange( false, PRINTSHEETS_SELECTED_CELLS
);
507 bool bAllTabs
= SC_MOD()->GetPrintOptions().GetAllSheets();
508 pDlg
->CheckSheetRange( bAllTabs
? PRINTSHEETS_ALL
: PRINTSHEETS_SELECTED_SHEETS
);
510 if ( nDocPageMax
> 0 )
511 pDlg
->SetRangeText( String::CreateFromInt32( nCurPage
) );
513 pDlg
->EnableRange ( PRINTDIALOG_ALL
);
514 pDlg
->EnableRange ( PRINTDIALOG_RANGE
);
515 pDlg
->SetFirstPage ( 1 );
516 pDlg
->SetMinPage ( 1 );
517 pDlg
->SetLastPage ( (USHORT
)nDocPageMax
);
518 pDlg
->SetMaxPage ( (USHORT
)nDocPageMax
);
519 pDlg
->EnableCollate ();
521 // Selektion hier nicht
526 SfxTabPage
* ScPreviewShell::CreatePrintOptionsPage( Window
*pParent
, const SfxItemSet
&rOptions
)
528 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
529 DBG_ASSERT(pFact
, "ScAbstractFactory create fail!");//CHINA001
530 //CHINA001 return ScTpPrintOptions::Create( pParent, rOptions );
531 ::CreateTabPage ScTpPrintOptionsCreate
= pFact
->GetTabPageCreatorFunc( RID_SCPAGE_PRINT
);
532 if ( ScTpPrintOptionsCreate
)
533 return (*ScTpPrintOptionsCreate
)( pParent
, rOptions
);
537 void __EXPORT
ScPreviewShell::PreparePrint( PrintDialog
* pPrintDialog
)
539 SfxViewShell::PreparePrint( pPrintDialog
);
541 ScMarkData aMarkData
;
542 aMarkData
.SelectTable( static_cast< SCTAB
>( pPreview
->GetTab() ), TRUE
);
543 pDocShell
->PreparePrint( pPrintDialog
, &aMarkData
);
546 ErrCode
ScPreviewShell::DoPrint( SfxPrinter
*pPrinter
,
547 PrintDialog
*pPrintDialog
, BOOL bSilent
, BOOL bIsAPI
)
549 ErrCode nRet
= ERRCODE_IO_ABORT
;
551 ScMarkData aMarkData
;
552 aMarkData
.SelectTable( static_cast< SCTAB
>( pPreview
->GetTab() ), TRUE
);
554 if ( pDocShell
->CheckPrint( pPrintDialog
, &aMarkData
, false, bIsAPI
) )
556 // SfxViewShell::DoPrint calls Print (after StartJob etc.)
557 nRet
= SfxViewShell::DoPrint( pPrinter
, pPrintDialog
, bSilent
, bIsAPI
);
563 USHORT __EXPORT
ScPreviewShell::Print( SfxProgress
& rProgress
, BOOL bIsAPI
, PrintDialog
* pPrintDialog
)
565 pDocShell
->GetDocument()->SetPrintOptions(); // Optionen aus OFA am Printer setzen
567 // get the list of affected sheets before SfxViewShell::Print
568 bool bAllTabs
= ( pPrintDialog
? ( pPrintDialog
->GetCheckedSheetRange() == PRINTSHEETS_ALL
) : SC_MOD()->GetPrintOptions().GetAllSheets() );
570 ScMarkData aMarkData
;
571 aMarkData
.SelectTable( static_cast< SCTAB
>( pPreview
->GetTab() ), TRUE
);
573 uno::Sequence
< sal_Int32
> aSheets
;
574 SCTAB nTabCount
= pDocShell
->GetDocument()->GetTableCount();
575 sal_Int32 nPrinted
= 0;
576 for ( SCTAB nTab
= 0; nTab
< nTabCount
; ++nTab
)
578 if ( bAllTabs
|| aMarkData
.GetTableSelect( nTab
) )
580 aSheets
.realloc( nPrinted
+ 1 );
581 aSheets
[nPrinted
] = nTab
;
586 uno::Sequence
< beans::PropertyValue
> aProps(1);
587 aProps
[0].Name
= ::rtl::OUString::createFromAscii( "PrintSheets" );
588 aProps
[0].Value
<<= aSheets
;
589 SetAdditionalPrintOptions( aProps
);
591 SfxViewShell::Print( rProgress
, bIsAPI
, pPrintDialog
);
592 pDocShell
->Print( rProgress
, pPrintDialog
, &aMarkData
, pPreview
, FALSE
, bIsAPI
);
597 //------------------------------------------------------------------------
599 void __EXPORT
ScPreviewShell::Activate(BOOL bMDI
)
601 SfxViewShell::Activate(bMDI
);
603 //! Basic etc. -> auslagern in eigene Datei (s. tabvwsh4)
607 // InputHdl ist jetzt meistens Null, keine Assertion mehr!
608 ScInputHandler
* pInputHdl
= SC_MOD()->GetInputHdl();
610 pInputHdl
->NotifyChange( NULL
);
614 void __EXPORT
ScPreviewShell::Deactivate(BOOL bMDI
)
616 SfxViewShell::Deactivate(bMDI
);
623 //------------------------------------------------------------------------
625 void __EXPORT
ScPreviewShell::Execute( SfxRequest
& rReq
)
627 USHORT nSlot
= rReq
.GetSlot();
628 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
633 case SID_STATUS_PAGESTYLE
:
635 pDocShell
->ExecutePageStyle( *this, rReq
, pPreview
->GetTab() );
638 pPreview
->Invalidate();
641 case SID_PREV_TABLE
: // Accelerator
642 case SID_PREVIEW_PREVIOUS
:
644 long nPage
= pPreview
->GetPageNo();
645 long nTotal
= pPreview
->GetTotalPages();
646 if (nTotal
&& nPage
> 0)
647 pPreview
->SetPageNo( nPage
-1 );
650 case SID_NEXT_TABLE
: // Accelerator
651 case SID_PREVIEW_NEXT
:
653 BOOL bAllTested
= pPreview
->AllTested();
654 long nPage
= pPreview
->GetPageNo();
655 long nTotal
= pPreview
->GetTotalPages();
656 if (nTotal
&& (nPage
+1 < nTotal
|| !bAllTested
))
657 pPreview
->SetPageNo( nPage
+1 );
660 case SID_CURSORTOPOFFILE
: // Accelerator
661 case SID_PREVIEW_FIRST
:
663 long nPage
= pPreview
->GetPageNo();
664 long nTotal
= pPreview
->GetTotalPages();
665 if (nTotal
&& nPage
!= 0)
666 pPreview
->SetPageNo( 0 );
669 case SID_CURSORENDOFFILE
: // Accelerator
670 case SID_PREVIEW_LAST
:
672 if (!pPreview
->AllTested())
675 long nPage
= pPreview
->GetPageNo();
676 long nTotal
= pPreview
->GetTotalPages();
677 if (nTotal
&& nPage
+1 != nTotal
)
678 pPreview
->SetPageNo( nTotal
-1 );
685 BOOL bCancel
= FALSE
;
687 eZoom
= SVX_ZOOM_PERCENT
;
692 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)
693 pReqArgs
->Get(SID_ATTR_ZOOM
);
695 eZoom
= rZoomItem
.GetType();
696 nZoom
= rZoomItem
.GetValue();
700 SfxItemSet
aSet ( GetPool(), SID_ATTR_ZOOM
, SID_ATTR_ZOOM
);
701 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, pPreview
->GetZoom(), SID_ATTR_ZOOM
);
703 aSet
.Put( aZoomItem
);
704 //CHINA001 SvxZoomDialog* pDlg = pDlg = new SvxZoomDialog( NULL, aSet );
705 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
708 AbstractSvxZoomDialog
* pDlg
= pFact
->CreateSvxZoomDialog(NULL
, aSet
, RID_SVXDLG_ZOOM
);
709 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
710 pDlg
->SetLimits( 20, 400 );
711 pDlg
->HideButton( ZOOMBTN_OPTIMAL
);
712 bCancel
= ( RET_CANCEL
== pDlg
->Execute() );
716 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)
717 pDlg
->GetOutputItemSet()->
718 Get( SID_ATTR_ZOOM
);
720 eZoom
= rZoomItem
.GetType();
721 nZoom
= rZoomItem
.GetValue();
732 case SVX_ZOOM_OPTIMAL
:
733 case SVX_ZOOM_WHOLEPAGE
:
734 nZoom
= pPreview
->GetOptimalZoom(FALSE
);
736 case SVX_ZOOM_PAGEWIDTH
:
737 nZoom
= pPreview
->GetOptimalZoom(TRUE
);
741 // added to avoid warnings
745 pPreview
->SetZoom( nZoom
);
750 case SID_PREVIEW_ZOOMIN
:
752 USHORT nNew
= pPreview
->GetZoom() + 20 ;
754 pPreview
->SetZoom( nNew
);
755 eZoom
= SVX_ZOOM_PERCENT
;
759 case SID_PREVIEW_ZOOMOUT
:
761 USHORT nNew
= pPreview
->GetZoom() - 1;
763 pPreview
->SetZoom( nNew
);
764 eZoom
= SVX_ZOOM_PERCENT
;
768 case SID_PREVIEW_MARGIN
:
770 BOOL bMargin
= pPreview
->GetPageMargins();
771 pPreview
->SetPageMargins( !bMargin
);
772 pPreview
->Invalidate();
776 case SID_ATTR_ZOOMSLIDER
:
778 const SfxPoolItem
* pItem
;
779 eZoom
= SVX_ZOOM_PERCENT
;
780 if( pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( SID_ATTR_ZOOMSLIDER
, TRUE
, &pItem
) )
782 const USHORT nCurrentZoom
= ((const SvxZoomSliderItem
*)pItem
)->GetValue();
785 pPreview
->SetZoom( nCurrentZoom
);
791 case SID_PREVIEW_SCALINGFACTOR
:
793 const SfxPoolItem
* pItem
;
794 SCTAB nTab
= pPreview
->GetTab();
795 String aOldName
= pDocShell
->GetDocument()->GetPageStyle( pPreview
->GetTab() );
796 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument()->GetStyleSheetPool();
797 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
798 DBG_ASSERT( pStyleSheet
, "PageStyle not found! :-/" );
800 if ( pReqArgs
&& pStyleSheet
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( SID_PREVIEW_SCALINGFACTOR
, TRUE
, &pItem
) )
802 const USHORT nCurrentZoom
= ((const SvxZoomSliderItem
*)pItem
)->GetValue();
803 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
804 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALE
, nCurrentZoom
) );
805 ScPrintFunc
aPrintFunc( pDocShell
, pDocShell
->GetPrinter(), nTab
);
806 aPrintFunc
.UpdatePages();
809 GetViewFrame()->GetBindings().Invalidate( nSlot
);
812 case SID_PRINTPREVIEW
:
813 case SID_PREVIEW_CLOSE
:
814 // print preview is now always in the same frame as the tab view
815 // -> always switch this frame back to normal view
816 // (ScTabViewShell ctor reads stored view data)
818 GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0
, SFX_CALLMODE_ASYNCHRON
);
820 case SID_CURSORPAGEUP
:
821 case SID_CURSORPAGEDOWN
:
827 case SID_CURSORRIGHT
:
836 void __EXPORT
ScPreviewShell::GetState( SfxItemSet
& rSet
)
838 pPreview
->SetInGetState(TRUE
);
840 SCTAB nTab
= pPreview
->GetTab();
841 long nPage
= pPreview
->GetPageNo();
842 long nTotal
= pPreview
->GetTotalPages();
843 USHORT nZoom
= pPreview
->GetZoom();
844 BOOL bAllTested
= pPreview
->AllTested();
846 SfxWhichIter
aIter(rSet
);
847 USHORT nWhich
= aIter
.FirstWhich();
852 case SID_STATUS_PAGESTYLE
:
854 pDocShell
->GetStatePageStyle( *this, rSet
, nTab
);
859 rSet
.DisableItem(nWhich
);
861 case SID_PREVIEW_PREVIOUS
:
862 case SID_PREVIEW_FIRST
:
863 if (!nTotal
|| nPage
==0)
864 rSet
.DisableItem(nWhich
);
866 case SID_PREVIEW_NEXT
:
867 case SID_PREVIEW_LAST
:
869 if (!nTotal
|| nPage
==nTotal
-1)
870 rSet
.DisableItem(nWhich
);
872 case SID_PREVIEW_ZOOMIN
:
874 rSet
.DisableItem(nWhich
);
876 case SID_PREVIEW_ZOOMOUT
:
878 rSet
.DisableItem(nWhich
);
882 SvxZoomItem
aZoom( eZoom
, nZoom
, nWhich
);
883 aZoom
.SetValueSet( SVX_ZOOM_ENABLE_ALL
& ~SVX_ZOOM_ENABLE_OPTIMAL
);
887 case SID_ATTR_ZOOMSLIDER
:
889 SvxZoomSliderItem
aZoomSliderItem( nZoom
, MINZOOM
, MAXZOOM
, SID_ATTR_ZOOMSLIDER
);
890 aZoomSliderItem
.AddSnappingPoint( 100 );
891 rSet
.Put( aZoomSliderItem
);
894 case SID_PREVIEW_SCALINGFACTOR
:
896 if( pDocShell
->IsReadOnly() )
897 rSet
.DisableItem( nWhich
);
900 String aOldName
= pDocShell
->GetDocument()->GetPageStyle( pPreview
->GetTab() );
901 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument()->GetStyleSheetPool();
902 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
903 DBG_ASSERT( pStyleSheet
, "PageStyle not found! :-/" );
907 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
908 USHORT nCurrentZoom
= ((const SfxUInt16Item
&)rStyleSet
.Get(ATTR_PAGE_SCALE
)).GetValue();
911 SvxZoomSliderItem
aZoomSliderItem( nCurrentZoom
, MINZOOM_SLIDER
, MAXZOOM_SLIDER
, SID_PREVIEW_SCALINGFACTOR
);
912 aZoomSliderItem
.AddSnappingPoint( 100 );
913 rSet
.Put( aZoomSliderItem
);
916 rSet
.DisableItem( nWhich
);
921 case SID_STATUS_DOCPOS
:
922 rSet
.Put( SfxStringItem( nWhich
, pPreview
->GetPosString() ) );
924 case SID_PRINTPREVIEW
:
925 rSet
.Put( SfxBoolItem( nWhich
, TRUE
) );
928 case SID_PREVIEW_MARGIN
:
929 if( pDocShell
->IsReadOnly() )
930 rSet
.DisableItem( nWhich
);
934 nWhich
= aIter
.NextWhich();
937 pPreview
->SetInGetState(FALSE
);
940 void ScPreviewShell::FillFieldData( ScHeaderFieldData
& rData
)
942 ScDocument
* pDoc
= pDocShell
->GetDocument();
943 SCTAB nTab
= pPreview
->GetTab();
944 pDoc
->GetName( nTab
, rData
.aTabName
);
946 rData
.aTitle
= pDocShell
->GetTitle();
947 const INetURLObject
& rURLObj
= pDocShell
->GetMedium()->GetURLObject();
948 rData
.aLongDocName
= rURLObj
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
949 if ( rData
.aLongDocName
.Len() )
950 rData
.aShortDocName
= rURLObj
.GetName( INetURLObject::DECODE_UNAMBIGUOUS
);
952 rData
.aShortDocName
= rData
.aLongDocName
= rData
.aTitle
;
953 rData
.nPageNo
= pPreview
->GetPageNo() + 1;
955 BOOL bAllTested
= pPreview
->AllTested();
957 rData
.nTotalPages
= pPreview
->GetTotalPages();
959 rData
.nTotalPages
= 99;
961 // eNumType kennt der Dialog selber
964 void __EXPORT
ScPreviewShell::WriteUserData(String
& rData
, BOOL
/* bBrowse */)
969 rData
= String::CreateFromInt32(pPreview
->GetZoom());
970 rData
+= (sal_Unicode
) SC_USERDATA_SEP
;
971 rData
+= String::CreateFromInt32(pPreview
->GetPageNo());
974 void __EXPORT
ScPreviewShell::ReadUserData(const String
& rData
, BOOL
/* bBrowse */)
976 xub_StrLen nCount
= rData
.GetTokenCount();
979 xub_StrLen nIndex
= 0;
980 pPreview
->SetZoom((USHORT
)rData
.GetToken( 0, SC_USERDATA_SEP
, nIndex
).ToInt32());
981 pPreview
->SetPageNo(rData
.GetToken( 0, SC_USERDATA_SEP
, nIndex
).ToInt32());
982 eZoom
= SVX_ZOOM_PERCENT
;
986 void __EXPORT
ScPreviewShell::WriteUserDataSequence(uno::Sequence
< beans::PropertyValue
>& rSeq
, sal_Bool
/* bBrowse */)
989 beans::PropertyValue
* pSeq
= rSeq
.getArray();
992 sal_uInt16
nViewID(GetViewFrame()->GetCurViewId());
993 pSeq
[0].Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEWID
));
994 rtl::OUStringBuffer
sBuffer(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEW
)));
995 SvXMLUnitConverter::convertNumber(sBuffer
, static_cast<sal_Int32
>(nViewID
));
996 pSeq
[0].Value
<<= sBuffer
.makeStringAndClear();
997 pSeq
[1].Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMVALUE
));
998 pSeq
[1].Value
<<= sal_Int32 (pPreview
->GetZoom());
999 pSeq
[2].Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageNumber"));
1000 pSeq
[2].Value
<<= pPreview
->GetPageNo();
1004 void __EXPORT
ScPreviewShell::ReadUserDataSequence(const uno::Sequence
< beans::PropertyValue
>& rSeq
, sal_Bool
/* bBrowse */)
1006 sal_Int32
nCount(rSeq
.getLength());
1009 sal_Int32 nTemp
= 0;
1010 const beans::PropertyValue
* pSeq
= rSeq
.getConstArray();
1013 for(sal_Int32 i
= 0; i
< nCount
; i
++, pSeq
++)
1015 rtl::OUString
sName(pSeq
->Name
);
1016 if(sName
.compareToAscii(SC_ZOOMVALUE
) == 0)
1018 if (pSeq
->Value
>>= nTemp
)
1019 pPreview
->SetZoom(sal_uInt16(nTemp
));
1021 else if (sName
.compareToAscii("PageNumber") == 0)
1023 if (pSeq
->Value
>>= nTemp
)
1024 pPreview
->SetPageNo(nTemp
);
1031 void ScPreviewShell::DoScroll( USHORT nMode
)
1033 Point aCurPos
, aPrevPos
;
1035 long nHRange
= pHorScroll
->GetRange().Max();
1036 long nHLine
= pHorScroll
->GetLineSize();
1037 long nHPage
= pHorScroll
->GetPageSize();
1038 long nVRange
= pVerScroll
->GetRange().Max();
1039 long nVLine
= pVerScroll
->GetLineSize();
1040 long nVPage
= pVerScroll
->GetPageSize();
1042 aCurPos
.X() = pHorScroll
->GetThumbPos();
1043 aCurPos
.Y() = pVerScroll
->GetThumbPos();
1046 long nThumbPos
= pVerScroll
->GetThumbPos();
1047 long nRangeMax
= pVerScroll
->GetRangeMax();
1054 long nPage
= pPreview
->GetPageNo();
1058 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1059 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1060 Execute( aSfxRequest
);
1064 aCurPos
.Y() -= nVLine
;
1066 case SID_CURSORDOWN
:
1069 long nPage
= pPreview
->GetPageNo();
1070 long nTotal
= pPreview
->GetTotalPages();
1072 // before testing for last page, make sure all page counts are calculated
1073 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1075 pPreview
->CalcAll();
1076 nTotal
= pPreview
->GetTotalPages();
1079 if( nPage
<nTotal
-1 )
1081 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1082 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1083 Execute( aSfxRequest
);
1087 aCurPos
.Y() += nVLine
;
1089 case SID_CURSORLEFT
:
1090 aCurPos
.X() -= nHLine
;
1092 case SID_CURSORRIGHT
:
1093 aCurPos
.X() += nHLine
;
1095 case SID_CURSORPAGEUP
:
1096 if( nThumbPos
==0 || nMaxVertPos
<0 )
1098 long nPage
= pPreview
->GetPageNo();
1102 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1103 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1104 Execute( aSfxRequest
);
1105 aCurPos
.Y() = nVRange
;
1109 aCurPos
.Y() -= nVPage
;
1111 case SID_CURSORPAGEDOWN
:
1112 if( (abs(nVPage
+nThumbPos
-nRangeMax
)<10) || nMaxVertPos
<0 )
1114 long nPage
= pPreview
->GetPageNo();
1115 long nTotal
= pPreview
->GetTotalPages();
1117 // before testing for last page, make sure all page counts are calculated
1118 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1120 pPreview
->CalcAll();
1121 nTotal
= pPreview
->GetTotalPages();
1123 if( nPage
<nTotal
-1 )
1125 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1126 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1127 Execute( aSfxRequest
);
1132 aCurPos
.Y() += nVPage
;
1134 case SID_CURSORHOME
:
1137 long nPage
= pPreview
->GetPageNo();
1138 long nTotal
= pPreview
->GetTotalPages();
1139 if( nTotal
&& nPage
!= 0 )
1141 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1142 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_FIRST
);
1143 Execute( aSfxRequest
);
1155 if( !pPreview
->AllTested() )
1156 pPreview
->CalcAll();
1157 long nPage
= pPreview
->GetPageNo();
1158 long nTotal
= pPreview
->GetTotalPages();
1159 if( nTotal
&& nPage
+1 != nTotal
)
1161 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1162 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_LAST
);
1163 Execute( aSfxRequest
);
1168 aCurPos
.Y() = nVRange
;
1169 aCurPos
.X() = nHRange
;
1174 // nHRange-nHPage kann negativ sein, deshalb Abfrage auf < 0 hinterher
1176 if( aCurPos
.Y() > (nVRange
-nVPage
) )
1177 aCurPos
.Y() = (nVRange
-nVPage
);
1178 if( aCurPos
.Y() < 0 )
1180 if( aCurPos
.X() > (nHRange
-nHPage
) )
1181 aCurPos
.X() = (nHRange
-nHPage
);
1182 if( aCurPos
.X() < 0 )
1185 if( nMaxVertPos
>=0 )
1187 if( aCurPos
.Y() != aPrevPos
.Y() )
1189 pVerScroll
->SetThumbPos( aCurPos
.Y() );
1190 pPreview
->SetYOffset( aCurPos
.Y() );
1194 if( aCurPos
.X() != aPrevPos
.X() )
1196 pHorScroll
->SetThumbPos( aCurPos
.X() );
1197 pPreview
->SetXOffset( aCurPos
.X() );
1202 void ScPreviewShell::AddAccessibilityObject( SfxListener
& rObject
)
1204 if (!pAccessibilityBroadcaster
)
1205 pAccessibilityBroadcaster
= new SfxBroadcaster
;
1207 rObject
.StartListening( *pAccessibilityBroadcaster
);
1210 void ScPreviewShell::RemoveAccessibilityObject( SfxListener
& rObject
)
1212 if (pAccessibilityBroadcaster
)
1213 rObject
.EndListening( *pAccessibilityBroadcaster
);
1216 DBG_ERROR("kein Accessibility-Broadcaster?");
1220 void ScPreviewShell::BroadcastAccessibility( const SfxHint
&rHint
)
1222 if (pAccessibilityBroadcaster
)
1223 pAccessibilityBroadcaster
->Broadcast( rHint
);
1226 BOOL
ScPreviewShell::HasAccessibilityObjects()
1228 return pAccessibilityBroadcaster
&& pAccessibilityBroadcaster
->HasListeners();
1231 const ScPreviewLocationData
& ScPreviewShell::GetLocationData()
1233 return pPreview
->GetLocationData();
1236 ScDocument
* ScPreviewShell::GetDocument()
1238 return pDocShell
->GetDocument();