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
:
831 if( ScViewUtil::IsFullScreen( *this ) )
832 ScViewUtil::SetFullScreen( *this, false );
840 void __EXPORT
ScPreviewShell::GetState( SfxItemSet
& rSet
)
842 pPreview
->SetInGetState(TRUE
);
844 SCTAB nTab
= pPreview
->GetTab();
845 long nPage
= pPreview
->GetPageNo();
846 long nTotal
= pPreview
->GetTotalPages();
847 USHORT nZoom
= pPreview
->GetZoom();
848 BOOL bAllTested
= pPreview
->AllTested();
850 SfxWhichIter
aIter(rSet
);
851 USHORT nWhich
= aIter
.FirstWhich();
856 case SID_STATUS_PAGESTYLE
:
858 pDocShell
->GetStatePageStyle( *this, rSet
, nTab
);
863 rSet
.DisableItem(nWhich
);
865 case SID_PREVIEW_PREVIOUS
:
866 case SID_PREVIEW_FIRST
:
867 if (!nTotal
|| nPage
==0)
868 rSet
.DisableItem(nWhich
);
870 case SID_PREVIEW_NEXT
:
871 case SID_PREVIEW_LAST
:
873 if (!nTotal
|| nPage
==nTotal
-1)
874 rSet
.DisableItem(nWhich
);
876 case SID_PREVIEW_ZOOMIN
:
878 rSet
.DisableItem(nWhich
);
880 case SID_PREVIEW_ZOOMOUT
:
882 rSet
.DisableItem(nWhich
);
886 SvxZoomItem
aZoom( eZoom
, nZoom
, nWhich
);
887 aZoom
.SetValueSet( SVX_ZOOM_ENABLE_ALL
& ~SVX_ZOOM_ENABLE_OPTIMAL
);
891 case SID_ATTR_ZOOMSLIDER
:
893 SvxZoomSliderItem
aZoomSliderItem( nZoom
, MINZOOM
, MAXZOOM
, SID_ATTR_ZOOMSLIDER
);
894 aZoomSliderItem
.AddSnappingPoint( 100 );
895 rSet
.Put( aZoomSliderItem
);
898 case SID_PREVIEW_SCALINGFACTOR
:
900 if( pDocShell
->IsReadOnly() )
901 rSet
.DisableItem( nWhich
);
904 String aOldName
= pDocShell
->GetDocument()->GetPageStyle( pPreview
->GetTab() );
905 ScStyleSheetPool
* pStylePool
= pDocShell
->GetDocument()->GetStyleSheetPool();
906 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
907 DBG_ASSERT( pStyleSheet
, "PageStyle not found! :-/" );
911 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
912 USHORT nCurrentZoom
= ((const SfxUInt16Item
&)rStyleSet
.Get(ATTR_PAGE_SCALE
)).GetValue();
915 SvxZoomSliderItem
aZoomSliderItem( nCurrentZoom
, MINZOOM_SLIDER
, MAXZOOM_SLIDER
, SID_PREVIEW_SCALINGFACTOR
);
916 aZoomSliderItem
.AddSnappingPoint( 100 );
917 rSet
.Put( aZoomSliderItem
);
920 rSet
.DisableItem( nWhich
);
925 case SID_STATUS_DOCPOS
:
926 rSet
.Put( SfxStringItem( nWhich
, pPreview
->GetPosString() ) );
928 case SID_PRINTPREVIEW
:
929 rSet
.Put( SfxBoolItem( nWhich
, TRUE
) );
932 case SID_PREVIEW_MARGIN
:
933 if( pDocShell
->IsReadOnly() )
934 rSet
.DisableItem( nWhich
);
938 nWhich
= aIter
.NextWhich();
941 pPreview
->SetInGetState(FALSE
);
944 void ScPreviewShell::FillFieldData( ScHeaderFieldData
& rData
)
946 ScDocument
* pDoc
= pDocShell
->GetDocument();
947 SCTAB nTab
= pPreview
->GetTab();
948 pDoc
->GetName( nTab
, rData
.aTabName
);
950 rData
.aTitle
= pDocShell
->GetTitle();
951 const INetURLObject
& rURLObj
= pDocShell
->GetMedium()->GetURLObject();
952 rData
.aLongDocName
= rURLObj
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
953 if ( rData
.aLongDocName
.Len() )
954 rData
.aShortDocName
= rURLObj
.GetName( INetURLObject::DECODE_UNAMBIGUOUS
);
956 rData
.aShortDocName
= rData
.aLongDocName
= rData
.aTitle
;
957 rData
.nPageNo
= pPreview
->GetPageNo() + 1;
959 BOOL bAllTested
= pPreview
->AllTested();
961 rData
.nTotalPages
= pPreview
->GetTotalPages();
963 rData
.nTotalPages
= 99;
965 // eNumType kennt der Dialog selber
968 void __EXPORT
ScPreviewShell::WriteUserData(String
& rData
, BOOL
/* bBrowse */)
973 rData
= String::CreateFromInt32(pPreview
->GetZoom());
974 rData
+= (sal_Unicode
) SC_USERDATA_SEP
;
975 rData
+= String::CreateFromInt32(pPreview
->GetPageNo());
978 void __EXPORT
ScPreviewShell::ReadUserData(const String
& rData
, BOOL
/* bBrowse */)
980 xub_StrLen nCount
= rData
.GetTokenCount();
983 xub_StrLen nIndex
= 0;
984 pPreview
->SetZoom((USHORT
)rData
.GetToken( 0, SC_USERDATA_SEP
, nIndex
).ToInt32());
985 pPreview
->SetPageNo(rData
.GetToken( 0, SC_USERDATA_SEP
, nIndex
).ToInt32());
986 eZoom
= SVX_ZOOM_PERCENT
;
990 void __EXPORT
ScPreviewShell::WriteUserDataSequence(uno::Sequence
< beans::PropertyValue
>& rSeq
, sal_Bool
/* bBrowse */)
993 beans::PropertyValue
* pSeq
= rSeq
.getArray();
996 sal_uInt16
nViewID(GetViewFrame()->GetCurViewId());
997 pSeq
[0].Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEWID
));
998 rtl::OUStringBuffer
sBuffer(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEW
)));
999 SvXMLUnitConverter::convertNumber(sBuffer
, static_cast<sal_Int32
>(nViewID
));
1000 pSeq
[0].Value
<<= sBuffer
.makeStringAndClear();
1001 pSeq
[1].Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMVALUE
));
1002 pSeq
[1].Value
<<= sal_Int32 (pPreview
->GetZoom());
1003 pSeq
[2].Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageNumber"));
1004 pSeq
[2].Value
<<= pPreview
->GetPageNo();
1008 void __EXPORT
ScPreviewShell::ReadUserDataSequence(const uno::Sequence
< beans::PropertyValue
>& rSeq
, sal_Bool
/* bBrowse */)
1010 sal_Int32
nCount(rSeq
.getLength());
1013 sal_Int32 nTemp
= 0;
1014 const beans::PropertyValue
* pSeq
= rSeq
.getConstArray();
1017 for(sal_Int32 i
= 0; i
< nCount
; i
++, pSeq
++)
1019 rtl::OUString
sName(pSeq
->Name
);
1020 if(sName
.compareToAscii(SC_ZOOMVALUE
) == 0)
1022 if (pSeq
->Value
>>= nTemp
)
1023 pPreview
->SetZoom(sal_uInt16(nTemp
));
1025 else if (sName
.compareToAscii("PageNumber") == 0)
1027 if (pSeq
->Value
>>= nTemp
)
1028 pPreview
->SetPageNo(nTemp
);
1035 void ScPreviewShell::DoScroll( USHORT nMode
)
1037 Point aCurPos
, aPrevPos
;
1039 long nHRange
= pHorScroll
->GetRange().Max();
1040 long nHLine
= pHorScroll
->GetLineSize();
1041 long nHPage
= pHorScroll
->GetPageSize();
1042 long nVRange
= pVerScroll
->GetRange().Max();
1043 long nVLine
= pVerScroll
->GetLineSize();
1044 long nVPage
= pVerScroll
->GetPageSize();
1046 aCurPos
.X() = pHorScroll
->GetThumbPos();
1047 aCurPos
.Y() = pVerScroll
->GetThumbPos();
1050 long nThumbPos
= pVerScroll
->GetThumbPos();
1051 long nRangeMax
= pVerScroll
->GetRangeMax();
1058 long nPage
= pPreview
->GetPageNo();
1062 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1063 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1064 Execute( aSfxRequest
);
1068 aCurPos
.Y() -= nVLine
;
1070 case SID_CURSORDOWN
:
1073 long nPage
= pPreview
->GetPageNo();
1074 long nTotal
= pPreview
->GetTotalPages();
1076 // before testing for last page, make sure all page counts are calculated
1077 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1079 pPreview
->CalcAll();
1080 nTotal
= pPreview
->GetTotalPages();
1083 if( nPage
<nTotal
-1 )
1085 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1086 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1087 Execute( aSfxRequest
);
1091 aCurPos
.Y() += nVLine
;
1093 case SID_CURSORLEFT
:
1094 aCurPos
.X() -= nHLine
;
1096 case SID_CURSORRIGHT
:
1097 aCurPos
.X() += nHLine
;
1099 case SID_CURSORPAGEUP
:
1100 if( nThumbPos
==0 || nMaxVertPos
<0 )
1102 long nPage
= pPreview
->GetPageNo();
1106 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1107 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_PREVIOUS
);
1108 Execute( aSfxRequest
);
1109 aCurPos
.Y() = nVRange
;
1113 aCurPos
.Y() -= nVPage
;
1115 case SID_CURSORPAGEDOWN
:
1116 if( (abs(nVPage
+nThumbPos
-nRangeMax
)<10) || nMaxVertPos
<0 )
1118 long nPage
= pPreview
->GetPageNo();
1119 long nTotal
= pPreview
->GetTotalPages();
1121 // before testing for last page, make sure all page counts are calculated
1122 if ( nPage
+1 == nTotal
&& !pPreview
->AllTested() )
1124 pPreview
->CalcAll();
1125 nTotal
= pPreview
->GetTotalPages();
1127 if( nPage
<nTotal
-1 )
1129 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1130 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_NEXT
);
1131 Execute( aSfxRequest
);
1136 aCurPos
.Y() += nVPage
;
1138 case SID_CURSORHOME
:
1141 long nPage
= pPreview
->GetPageNo();
1142 long nTotal
= pPreview
->GetTotalPages();
1143 if( nTotal
&& nPage
!= 0 )
1145 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1146 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_FIRST
);
1147 Execute( aSfxRequest
);
1159 if( !pPreview
->AllTested() )
1160 pPreview
->CalcAll();
1161 long nPage
= pPreview
->GetPageNo();
1162 long nTotal
= pPreview
->GetTotalPages();
1163 if( nTotal
&& nPage
+1 != nTotal
)
1165 SfxViewFrame
* pSfxViewFrame
= GetViewFrame();
1166 SfxRequest
aSfxRequest( pSfxViewFrame
, SID_PREVIEW_LAST
);
1167 Execute( aSfxRequest
);
1172 aCurPos
.Y() = nVRange
;
1173 aCurPos
.X() = nHRange
;
1178 // nHRange-nHPage kann negativ sein, deshalb Abfrage auf < 0 hinterher
1180 if( aCurPos
.Y() > (nVRange
-nVPage
) )
1181 aCurPos
.Y() = (nVRange
-nVPage
);
1182 if( aCurPos
.Y() < 0 )
1184 if( aCurPos
.X() > (nHRange
-nHPage
) )
1185 aCurPos
.X() = (nHRange
-nHPage
);
1186 if( aCurPos
.X() < 0 )
1189 if( nMaxVertPos
>=0 )
1191 if( aCurPos
.Y() != aPrevPos
.Y() )
1193 pVerScroll
->SetThumbPos( aCurPos
.Y() );
1194 pPreview
->SetYOffset( aCurPos
.Y() );
1198 if( aCurPos
.X() != aPrevPos
.X() )
1200 pHorScroll
->SetThumbPos( aCurPos
.X() );
1201 pPreview
->SetXOffset( aCurPos
.X() );
1206 void ScPreviewShell::AddAccessibilityObject( SfxListener
& rObject
)
1208 if (!pAccessibilityBroadcaster
)
1209 pAccessibilityBroadcaster
= new SfxBroadcaster
;
1211 rObject
.StartListening( *pAccessibilityBroadcaster
);
1214 void ScPreviewShell::RemoveAccessibilityObject( SfxListener
& rObject
)
1216 if (pAccessibilityBroadcaster
)
1217 rObject
.EndListening( *pAccessibilityBroadcaster
);
1220 DBG_ERROR("kein Accessibility-Broadcaster?");
1224 void ScPreviewShell::BroadcastAccessibility( const SfxHint
&rHint
)
1226 if (pAccessibilityBroadcaster
)
1227 pAccessibilityBroadcaster
->Broadcast( rHint
);
1230 BOOL
ScPreviewShell::HasAccessibilityObjects()
1232 return pAccessibilityBroadcaster
&& pAccessibilityBroadcaster
->HasListeners();
1235 const ScPreviewLocationData
& ScPreviewShell::GetLocationData()
1237 return pPreview
->GetLocationData();
1240 ScDocument
* ScPreviewShell::GetDocument()
1242 return pDocShell
->GetDocument();