xref: /aoo42x/main/sc/source/ui/view/prevwsh.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "scitems.hxx"
32cdf0e10cSrcweir #include <editeng/eeitem.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <sfx2/app.hxx>
35cdf0e10cSrcweir #include <editeng/sizeitem.hxx>
36cdf0e10cSrcweir #include <svl/srchitem.hxx>
37cdf0e10cSrcweir #include <svx/zoomslideritem.hxx>
38cdf0e10cSrcweir #include <svx/svdview.hxx>
39cdf0e10cSrcweir //CHINA001 #include <svx/zoom.hxx>
40cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
41cdf0e10cSrcweir #include <sfx2/objface.hxx>
42cdf0e10cSrcweir #include <sfx2/request.hxx>
43cdf0e10cSrcweir #include <svl/stritem.hxx>
44cdf0e10cSrcweir #include <svl/whiter.hxx>
45cdf0e10cSrcweir #include <vcl/msgbox.hxx>
46cdf0e10cSrcweir #include <vcl/help.hxx>
47cdf0e10cSrcweir #include <tools/urlobj.hxx>
48cdf0e10cSrcweir #include <sfx2/docfile.hxx>
49cdf0e10cSrcweir #include <sfx2/printer.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #ifndef _SVX_ZOOMSLIDERITEM_HXX
52cdf0e10cSrcweir #include <svx/zoomslideritem.hxx>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #include "prevwsh.hxx"
55cdf0e10cSrcweir #include "preview.hxx"
56cdf0e10cSrcweir #include "printfun.hxx"
57cdf0e10cSrcweir #include "attrib.hxx"
58cdf0e10cSrcweir #include "scmod.hxx"
59cdf0e10cSrcweir #include "inputhdl.hxx"
60cdf0e10cSrcweir #include "docsh.hxx"
61cdf0e10cSrcweir #include "tabvwsh.hxx"
62cdf0e10cSrcweir #include "stlpool.hxx"
63cdf0e10cSrcweir #include "editutil.hxx"
64cdf0e10cSrcweir #include "scresid.hxx"
65cdf0e10cSrcweir #include "globstr.hrc"
66cdf0e10cSrcweir #include "sc.hrc"
67cdf0e10cSrcweir #include "ViewSettingsSequenceDefines.hxx"
68cdf0e10cSrcweir #include "tpprint.hxx"
69cdf0e10cSrcweir #include "printopt.hxx"
70cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
71cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #include <svx/svxdlg.hxx> //CHINA001
74cdf0e10cSrcweir #include <svx/dialogs.hrc> //CHINA001
75cdf0e10cSrcweir 
76cdf0e10cSrcweir #ifndef _SVX_ZOOM_HXX
77cdf0e10cSrcweir #include <svx/zoom_def.hxx>
78cdf0e10cSrcweir #endif
79cdf0e10cSrcweir 
80cdf0e10cSrcweir #include "sc.hrc" //CHINA001
81cdf0e10cSrcweir #include "scabstdlg.hxx" //CHINA001
82cdf0e10cSrcweir //	fuer Rad-Maus
83cdf0e10cSrcweir #define SC_DELTA_ZOOM	10
84cdf0e10cSrcweir #define MINZOOM_SLIDER 10
85cdf0e10cSrcweir #define MAXZOOM_SLIDER 400
86cdf0e10cSrcweir 
87cdf0e10cSrcweir #define SC_USERDATA_SEP	';'
88cdf0e10cSrcweir 
89cdf0e10cSrcweir using namespace com::sun::star;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // -----------------------------------------------------------------------
92cdf0e10cSrcweir 
93cdf0e10cSrcweir #define ScPreviewShell
94cdf0e10cSrcweir #include "scslots.hxx"
95cdf0e10cSrcweir 
96cdf0e10cSrcweir TYPEINIT1( ScPreviewShell, SfxViewShell );
97cdf0e10cSrcweir 
SFX_IMPL_INTERFACE(ScPreviewShell,SfxViewShell,ScResId (SCSTR_PREVIEWSHELL))98cdf0e10cSrcweir SFX_IMPL_INTERFACE( ScPreviewShell, SfxViewShell, ScResId(SCSTR_PREVIEWSHELL) )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|
101cdf0e10cSrcweir 								SFX_VISIBILITY_SERVER|SFX_VISIBILITY_READONLYDOC,
102cdf0e10cSrcweir 								ScResId(RID_OBJECTBAR_PREVIEW));
103cdf0e10cSrcweir 	SFX_POPUPMENU_REGISTRATION(ScResId(RID_POPUP_PREVIEW));
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir SFX_IMPL_NAMED_VIEWFACTORY( ScPreviewShell, "PrintPreview" )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	SFX_VIEW_REGISTRATION(ScDocShell);
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //------------------------------------------------------------------
112cdf0e10cSrcweir 
Construct(Window * pParent)113cdf0e10cSrcweir void ScPreviewShell::Construct( Window* pParent )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	eZoom = SVX_ZOOM_WHOLEPAGE;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	pCorner = new ScrollBarBox( pParent, WB_SIZEABLE );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	pHorScroll = new ScrollBar(pParent, WB_HSCROLL );
120cdf0e10cSrcweir 	pVerScroll = new ScrollBar(pParent, WB_VSCROLL);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     // SSA: --- RTL --- no mirroring for horizontal scrollbars
123cdf0e10cSrcweir     pHorScroll->EnableRTL( sal_False );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	pHorScroll->SetEndScrollHdl( LINK( this, ScPreviewShell, ScrollHandler ) );
126cdf0e10cSrcweir 	pVerScroll->SetEndScrollHdl( LINK( this, ScPreviewShell, ScrollHandler ) );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	pPreview = new ScPreview( pParent, pDocShell, this );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	SetPool( &SC_MOD()->GetPool() );
131cdf0e10cSrcweir 	SetWindow( pPreview );
132cdf0e10cSrcweir     StartListening(*pDocShell,sal_True);
133cdf0e10cSrcweir     StartListening(*SFX_APP(),sal_True);        // #i62045# #i62046# application is needed for Calc's own hints
134cdf0e10cSrcweir 	SfxBroadcaster* pDrawBC = pDocShell->GetDocument()->GetDrawBroadcaster();
135cdf0e10cSrcweir 	if (pDrawBC)
136cdf0e10cSrcweir 		StartListening(*pDrawBC);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	pHorScroll->Show();
139cdf0e10cSrcweir 	pVerScroll->Show();
140cdf0e10cSrcweir 	pCorner->Show();
141cdf0e10cSrcweir 	SetHelpId( HID_SCSHELL_PREVWSH );
142cdf0e10cSrcweir 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Preview")));
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
ScPreviewShell(SfxViewFrame * pViewFrame,SfxViewShell * pOldSh)145cdf0e10cSrcweir ScPreviewShell::ScPreviewShell( SfxViewFrame* pViewFrame,
146cdf0e10cSrcweir 								SfxViewShell* pOldSh ) :
147cdf0e10cSrcweir 	SfxViewShell( pViewFrame, SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ),
148cdf0e10cSrcweir 	pDocShell( (ScDocShell*)pViewFrame->GetObjectShell() ),
149cdf0e10cSrcweir 	nSourceDesignMode( SC_FORCEMODE_NONE ),
150cdf0e10cSrcweir 	pAccessibilityBroadcaster( NULL )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	Construct( &pViewFrame->GetWindow() );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	if ( pOldSh && pOldSh->ISA( ScTabViewShell ) )
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		//	store view settings, show table from TabView
157cdf0e10cSrcweir 		//!	store live ScViewData instead, and update on ScTablesHint?
158cdf0e10cSrcweir 		//!	or completely forget aSourceData on ScTablesHint?
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		ScTabViewShell* pTabViewShell = ((ScTabViewShell*)pOldSh);
161cdf0e10cSrcweir 		ScViewData* pData = pTabViewShell->GetViewData();
162cdf0e10cSrcweir 		pData->WriteUserDataSequence( aSourceData );
163cdf0e10cSrcweir 		InitStartTable( pData->GetTabNo() );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		//	#106334# also have to store the TabView's DesignMode state
166cdf0e10cSrcweir 		//	(only if draw view exists)
167cdf0e10cSrcweir 		SdrView* pDrawView = pTabViewShell->GetSdrView();
168cdf0e10cSrcweir 		if ( pDrawView )
169cdf0e10cSrcweir 			nSourceDesignMode = pDrawView->IsDesignMode();
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
~ScPreviewShell()173cdf0e10cSrcweir __EXPORT ScPreviewShell::~ScPreviewShell()
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     // #108333#; notify Accessibility that Shell is dying and before destroy all
176cdf0e10cSrcweir     BroadcastAccessibility( SfxSimpleHint( SFX_HINT_DYING ) );
177cdf0e10cSrcweir     DELETEZ(pAccessibilityBroadcaster);
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     SfxBroadcaster* pDrawBC = pDocShell->GetDocument()->GetDrawBroadcaster();
180cdf0e10cSrcweir 	if (pDrawBC)
181cdf0e10cSrcweir 		EndListening(*pDrawBC);
182cdf0e10cSrcweir 	EndListening(*SFX_APP());
183cdf0e10cSrcweir 	EndListening(*pDocShell);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	SetWindow(0);
186cdf0e10cSrcweir 	delete pPreview;
187cdf0e10cSrcweir 	delete pHorScroll;
188cdf0e10cSrcweir 	delete pVerScroll;
189cdf0e10cSrcweir 	delete pCorner;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	//	#97612# normal mode of operation is switching back to default view in the same frame,
192cdf0e10cSrcweir 	//	so there's no need to activate any other window here anymore
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
InitStartTable(SCTAB nTab)195cdf0e10cSrcweir void ScPreviewShell::InitStartTable(SCTAB nTab)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	pPreview->SetPageNo( pPreview->GetFirstPage(nTab) );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //------------------------------------------------------------------
201cdf0e10cSrcweir 
GetDescription() const202cdf0e10cSrcweir String __EXPORT ScPreviewShell::GetDescription() const
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" ** Test ** "));
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
GetOptimalSizePixel() const207cdf0e10cSrcweir Size __EXPORT ScPreviewShell::GetOptimalSizePixel() const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	Size aOptSize(100,100);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	ScTabViewShell*     pViewSh = pDocShell->GetBestViewShell();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	if ( pViewSh )
214cdf0e10cSrcweir 	{
215cdf0e10cSrcweir 		ScViewData*			pViewData	= pViewSh->GetViewData();
216cdf0e10cSrcweir 		SCTAB				nCurTab		= pViewData->GetTabNo();
217cdf0e10cSrcweir 		ScDocument*			pDoc		= pDocShell->GetDocument();
218cdf0e10cSrcweir 		ScStyleSheetPool*	pStylePool  = pDoc->GetStyleSheetPool();
219cdf0e10cSrcweir 		SfxStyleSheetBase*	pStyleSheet = pStylePool->Find(
220cdf0e10cSrcweir 											pDoc->GetPageStyle( nCurTab ),
221cdf0e10cSrcweir 											SFX_STYLE_FAMILY_PAGE );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 		DBG_ASSERT( pStyleSheet, "PageStyle not found :-/" );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 		if ( pStyleSheet )
226cdf0e10cSrcweir 		{
227cdf0e10cSrcweir 			const SfxItemSet&  rSet 	 = pStyleSheet->GetItemSet();
228cdf0e10cSrcweir 			const SvxSizeItem& rItem	 = (const SvxSizeItem&)rSet.Get( ATTR_PAGE_SIZE );
229cdf0e10cSrcweir 			const Size&		   rPageSize = rItem.GetSize();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 			aOptSize.Width()  = (long) (rPageSize.Width()  * pViewData->GetPPTX());
232cdf0e10cSrcweir 			aOptSize.Height() = (long) (rPageSize.Height() * pViewData->GetPPTY());
233cdf0e10cSrcweir 		}
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 	else
236cdf0e10cSrcweir 	{
237cdf0e10cSrcweir 		DBG_ERROR( "TabViewShell not found :-/" );
238cdf0e10cSrcweir 	}
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	return aOptSize;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
AdjustPosSizePixel(const Point & rPos,const Size & rSize)243cdf0e10cSrcweir void __EXPORT ScPreviewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
246cdf0e10cSrcweir 	long nBarH = nBarW;
247cdf0e10cSrcweir //	long nBarW = pVerScroll->GetSizePixel().Width();
248cdf0e10cSrcweir //	long nBarH = pHorScroll->GetSizePixel().Height();
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	Size aOutSize( rSize.Width()-nBarW, rSize.Height()-nBarH );
251cdf0e10cSrcweir 	pPreview->SetPosSizePixel( rPos, aOutSize );
252cdf0e10cSrcweir 	pHorScroll->SetPosSizePixel( Point( rPos.X(), rPos.Y() + aOutSize.Height() ),
253cdf0e10cSrcweir 								 Size( aOutSize.Width(), nBarH ) );
254cdf0e10cSrcweir 	pVerScroll->SetPosSizePixel( Point( rPos.X() + aOutSize.Width(), rPos.Y() ),
255cdf0e10cSrcweir 								 Size( nBarW, aOutSize.Height() ) );
256cdf0e10cSrcweir 	pCorner->SetPosSizePixel( Point( rPos.X() + aOutSize.Width(), rPos.Y() + aOutSize.Height() ),
257cdf0e10cSrcweir 							  Size( nBarW, nBarH ) );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 	if ( SVX_ZOOM_WHOLEPAGE == eZoom )
260cdf0e10cSrcweir 		pPreview->SetZoom( pPreview->GetOptimalZoom(sal_False) );
261cdf0e10cSrcweir 	else if ( SVX_ZOOM_PAGEWIDTH == eZoom )
262cdf0e10cSrcweir 		pPreview->SetZoom( pPreview->GetOptimalZoom(sal_True) );
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	UpdateScrollBars();
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
InnerResizePixel(const Point & rOfs,const Size & rSize)267cdf0e10cSrcweir void __EXPORT ScPreviewShell::InnerResizePixel( const Point &rOfs, const Size &rSize )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	AdjustPosSizePixel( rOfs,rSize );
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
OuterResizePixel(const Point & rOfs,const Size & rSize)272cdf0e10cSrcweir void __EXPORT ScPreviewShell::OuterResizePixel( const Point &rOfs, const Size &rSize )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir 	AdjustPosSizePixel( rOfs,rSize );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
UpdateScrollBars()277cdf0e10cSrcweir void ScPreviewShell::UpdateScrollBars()
278cdf0e10cSrcweir {
279cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
280cdf0e10cSrcweir 	SCTAB nTab = pPreview->GetTab();
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 	ScStyleSheetPool*	pStylePool	= pDoc->GetStyleSheetPool();
283cdf0e10cSrcweir 	SfxStyleSheetBase*	pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ),
284cdf0e10cSrcweir 														SFX_STYLE_FAMILY_PAGE );
285cdf0e10cSrcweir 	DBG_ASSERT(pStyleSheet,"StyleSheet nicht gefunden");
286cdf0e10cSrcweir 	if (!pStyleSheet) return;
287cdf0e10cSrcweir 	const SfxItemSet* pParamSet = &pStyleSheet->GetItemSet();
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	Size aPageSize = ((const SvxSizeItem&) pParamSet->Get(ATTR_PAGE_SIZE)).GetSize();
290cdf0e10cSrcweir 	aPageSize.Width()  = (long) (aPageSize.Width()  * HMM_PER_TWIPS );
291cdf0e10cSrcweir 	aPageSize.Height() = (long) (aPageSize.Height() * HMM_PER_TWIPS );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	//	for centering, page size without the shadow is used
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 	Size aWindowSize = pPreview->GetOutputSize();
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	Point aOfs = pPreview->GetOffset();
298cdf0e10cSrcweir 	long nMaxPos;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     if( pHorScroll )
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir         pHorScroll->SetRange( Range( 0, aPageSize.Width() ) );
303cdf0e10cSrcweir         pHorScroll->SetLineSize( aWindowSize.Width() / 16 );
304cdf0e10cSrcweir         pHorScroll->SetPageSize( aWindowSize.Width() );
305cdf0e10cSrcweir         pHorScroll->SetVisibleSize( aWindowSize.Width() );
306cdf0e10cSrcweir         nMaxPos = aPageSize.Width() - aWindowSize.Width();
307cdf0e10cSrcweir         if ( nMaxPos<0 )
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir             //	page smaller than window -> center (but put scrollbar to 0)
310cdf0e10cSrcweir             aOfs.X() = 0;
311cdf0e10cSrcweir             pPreview->SetXOffset( nMaxPos / 2 );
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         else if (aOfs.X() < 0)
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             //	page larger than window -> never use negative offset
316cdf0e10cSrcweir             aOfs.X() = 0;
317cdf0e10cSrcweir             pPreview->SetXOffset( 0 );
318cdf0e10cSrcweir         }
319cdf0e10cSrcweir         else if (aOfs.X() > nMaxPos)
320cdf0e10cSrcweir         {
321cdf0e10cSrcweir             //	limit offset to align with right edge of window
322cdf0e10cSrcweir             aOfs.X() = nMaxPos;
323cdf0e10cSrcweir             pPreview->SetXOffset(nMaxPos);
324cdf0e10cSrcweir         }
325cdf0e10cSrcweir         pHorScroll->SetThumbPos( aOfs.X() );
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     if( pVerScroll )
329cdf0e10cSrcweir     {
330cdf0e10cSrcweir         long nPageNo     = pPreview->GetPageNo();
331cdf0e10cSrcweir         long nTotalPages = pPreview->GetTotalPages();
332cdf0e10cSrcweir 
333cdf0e10cSrcweir         nMaxVertPos = aPageSize.Height() - aWindowSize.Height();
334cdf0e10cSrcweir         pVerScroll->SetLineSize( aWindowSize.Height() / 16  );
335cdf0e10cSrcweir         pVerScroll->SetPageSize( aWindowSize.Height() );
336cdf0e10cSrcweir         pVerScroll->SetVisibleSize( aWindowSize.Height() );
337cdf0e10cSrcweir         if ( nMaxVertPos < 0 )
338cdf0e10cSrcweir         {
339cdf0e10cSrcweir             //	page smaller than window -> center (but put scrollbar to 0)
340cdf0e10cSrcweir             aOfs.Y() = 0;
341cdf0e10cSrcweir             pPreview->SetYOffset( nMaxVertPos / 2 );
342cdf0e10cSrcweir             pVerScroll->SetThumbPos( nPageNo * aWindowSize.Height() );
343cdf0e10cSrcweir             pVerScroll->SetRange( Range( 0, aWindowSize.Height() * nTotalPages ));
344cdf0e10cSrcweir         }
345cdf0e10cSrcweir         else if (aOfs.Y() < 0)
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir             //	page larger than window -> never use negative offset
348cdf0e10cSrcweir             pVerScroll->SetRange( Range( 0, aPageSize.Height() ) );
349cdf0e10cSrcweir             aOfs.Y() = 0;
350cdf0e10cSrcweir             pPreview->SetYOffset( 0 );
351cdf0e10cSrcweir             pVerScroll->SetThumbPos( aOfs.Y() );
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir         else if (aOfs.Y() > nMaxVertPos )
354cdf0e10cSrcweir         {
355cdf0e10cSrcweir             //	limit offset to align with window bottom
356cdf0e10cSrcweir             pVerScroll->SetRange( Range( 0, aPageSize.Height() ) );
357cdf0e10cSrcweir             aOfs.Y() = nMaxVertPos;
358cdf0e10cSrcweir             pPreview->SetYOffset( nMaxVertPos );
359cdf0e10cSrcweir             pVerScroll->SetThumbPos( aOfs.Y() );
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
IMPL_LINK(ScPreviewShell,ScrollHandler,ScrollBar *,pScroll)364cdf0e10cSrcweir IMPL_LINK (ScPreviewShell,ScrollHandler, ScrollBar* ,pScroll )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     long nPos           = pScroll->GetThumbPos();
367cdf0e10cSrcweir     long nDelta         = pScroll->GetDelta();
368cdf0e10cSrcweir     long nMaxRange      = pScroll->GetRangeMax();
369cdf0e10cSrcweir     long nTotalPages    = pPreview->GetTotalPages();
370cdf0e10cSrcweir     long nPageNo        = 0;
371cdf0e10cSrcweir     long nPerPageLength = 0;
372cdf0e10cSrcweir     sal_Bool bIsDivide      = sal_True;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     if( nTotalPages )
375cdf0e10cSrcweir         nPerPageLength = nMaxRange / nTotalPages;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     if( nPerPageLength )
378cdf0e10cSrcweir     {
379cdf0e10cSrcweir         nPageNo = nPos / nPerPageLength;
380cdf0e10cSrcweir         if( nPos % nPerPageLength )
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir             bIsDivide = sal_False;
383cdf0e10cSrcweir             nPageNo ++;
384cdf0e10cSrcweir         }
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     sal_Bool bHoriz = ( pScroll == pHorScroll );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     if( bHoriz )
390cdf0e10cSrcweir         pPreview->SetXOffset( nPos );
391cdf0e10cSrcweir     else
392cdf0e10cSrcweir     {
393cdf0e10cSrcweir         if( nMaxVertPos > 0 )
394cdf0e10cSrcweir             pPreview->SetYOffset( nPos );
395cdf0e10cSrcweir         else
396cdf0e10cSrcweir         {
397cdf0e10cSrcweir             Point  aMousePos = pScroll->OutputToNormalizedScreenPixel( pScroll->GetPointerPosPixel() );
398cdf0e10cSrcweir             Point  aPos      = pScroll->GetParent()->OutputToNormalizedScreenPixel( pScroll->GetPosPixel() );
399cdf0e10cSrcweir             String aHelpStr;
400cdf0e10cSrcweir             Rectangle aRect;
401cdf0e10cSrcweir             sal_uInt16   nAlign;
402cdf0e10cSrcweir 
403cdf0e10cSrcweir             if( nDelta < 0 )
404cdf0e10cSrcweir             {
405cdf0e10cSrcweir                 if ( nTotalPages && nPageNo > 0 && !bIsDivide )
406cdf0e10cSrcweir                     pPreview->SetPageNo( nPageNo-1 );
407cdf0e10cSrcweir                 if( bIsDivide )
408cdf0e10cSrcweir                     pPreview->SetPageNo( nPageNo );
409cdf0e10cSrcweir 
410cdf0e10cSrcweir                 aHelpStr = ScGlobal::GetRscString( STR_PAGE );
411cdf0e10cSrcweir                 aHelpStr += ' ';
412cdf0e10cSrcweir                 aHelpStr += String::CreateFromInt32( nPageNo );
413cdf0e10cSrcweir 
414cdf0e10cSrcweir                 aHelpStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
415cdf0e10cSrcweir                 aHelpStr += String::CreateFromInt32( nTotalPages );
416cdf0e10cSrcweir             }
417cdf0e10cSrcweir             else if( nDelta > 0 )
418cdf0e10cSrcweir             {
419cdf0e10cSrcweir                 sal_Bool bAllTested	= pPreview->AllTested();
420cdf0e10cSrcweir                 if ( nTotalPages && ( nPageNo < nTotalPages || !bAllTested ) )
421cdf0e10cSrcweir                     pPreview->SetPageNo( nPageNo );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir                 aHelpStr = ScGlobal::GetRscString( STR_PAGE );
424cdf0e10cSrcweir                 aHelpStr += ' ';
425cdf0e10cSrcweir                 aHelpStr += String::CreateFromInt32( nPageNo+1 );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir                 aHelpStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
428cdf0e10cSrcweir                 aHelpStr += String::CreateFromInt32( nTotalPages );
429cdf0e10cSrcweir             }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir             aRect.Left()    = aPos.X() - 8;
432cdf0e10cSrcweir             aRect.Top()	    = aMousePos.Y();
433cdf0e10cSrcweir             aRect.Right() 	= aRect.Left();
434cdf0e10cSrcweir             aRect.Top()		= aRect.Top();
435cdf0e10cSrcweir             nAlign		    = QUICKHELP_BOTTOM|QUICKHELP_CENTER;
436cdf0e10cSrcweir             Help::ShowQuickHelp( pScroll->GetParent(), aRect, aHelpStr, nAlign );
437cdf0e10cSrcweir         }
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 	return 0;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
ScrollCommand(const CommandEvent & rCEvt)443cdf0e10cSrcweir sal_Bool ScPreviewShell::ScrollCommand( const CommandEvent& rCEvt )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
446cdf0e10cSrcweir 	const CommandWheelData* pData = rCEvt.GetWheelData();
447cdf0e10cSrcweir 	if ( pData && pData->GetMode() == COMMAND_WHEEL_ZOOM )
448cdf0e10cSrcweir 	{
449cdf0e10cSrcweir 		long nOld = pPreview->GetZoom();
450cdf0e10cSrcweir 		long nNew = nOld;
451cdf0e10cSrcweir 		if ( pData->GetDelta() < 0 )
452cdf0e10cSrcweir 			nNew = Max( (long) MINZOOM, (long)( nOld - SC_DELTA_ZOOM ) );
453cdf0e10cSrcweir 		else
454cdf0e10cSrcweir 			nNew = Min( (long) MAXZOOM, (long)( nOld + SC_DELTA_ZOOM ) );
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 		if ( nNew != nOld )
457cdf0e10cSrcweir 		{
458cdf0e10cSrcweir 			eZoom = SVX_ZOOM_PERCENT;
459cdf0e10cSrcweir 			pPreview->SetZoom( (sal_uInt16)nNew );
460cdf0e10cSrcweir 		}
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 		bDone = sal_True;
463cdf0e10cSrcweir 	}
464cdf0e10cSrcweir 	else
465cdf0e10cSrcweir 	{
466cdf0e10cSrcweir 		bDone = pPreview->HandleScrollCommand( rCEvt, pHorScroll, pVerScroll );
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	return bDone;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
GetPrinter(sal_Bool bCreate)472cdf0e10cSrcweir SfxPrinter* __EXPORT ScPreviewShell::GetPrinter( sal_Bool bCreate )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir 	return pDocShell->GetPrinter(bCreate);
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
SetPrinter(SfxPrinter * pNewPrinter,sal_uInt16 nDiffFlags,bool)477cdf0e10cSrcweir sal_uInt16 __EXPORT ScPreviewShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir 	return pDocShell->SetPrinter( pNewPrinter, nDiffFlags );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
CreatePrintOptionsPage(Window * pParent,const SfxItemSet & rOptions)482cdf0e10cSrcweir SfxTabPage* ScPreviewShell::CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir 	ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
485cdf0e10cSrcweir 	DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
486cdf0e10cSrcweir 	//CHINA001 return ScTpPrintOptions::Create( pParent, rOptions );
487cdf0e10cSrcweir 	::CreateTabPage ScTpPrintOptionsCreate = 	pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
488cdf0e10cSrcweir 	if ( ScTpPrintOptionsCreate )
489cdf0e10cSrcweir 		return  (*ScTpPrintOptionsCreate)( pParent, rOptions);
490cdf0e10cSrcweir 	return 0;
491cdf0e10cSrcweir }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir //------------------------------------------------------------------------
494cdf0e10cSrcweir 
Activate(sal_Bool bMDI)495cdf0e10cSrcweir void __EXPORT ScPreviewShell::Activate(sal_Bool bMDI)
496cdf0e10cSrcweir {
497cdf0e10cSrcweir 	SfxViewShell::Activate(bMDI);
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	//!	Basic etc. -> auslagern in eigene Datei (s. tabvwsh4)
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 	if (bMDI)
502cdf0e10cSrcweir 	{
503cdf0e10cSrcweir 		// InputHdl ist jetzt meistens Null, keine Assertion mehr!
504cdf0e10cSrcweir 		ScInputHandler*	pInputHdl = SC_MOD()->GetInputHdl();
505cdf0e10cSrcweir 		if ( pInputHdl )
506cdf0e10cSrcweir 			pInputHdl->NotifyChange( NULL );
507cdf0e10cSrcweir 	}
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
Deactivate(sal_Bool bMDI)510cdf0e10cSrcweir void __EXPORT ScPreviewShell::Deactivate(sal_Bool bMDI)
511cdf0e10cSrcweir {
512cdf0e10cSrcweir 	SfxViewShell::Deactivate(bMDI);
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 	if (bMDI)
515cdf0e10cSrcweir 	{
516cdf0e10cSrcweir 	}
517cdf0e10cSrcweir }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir //------------------------------------------------------------------------
520cdf0e10cSrcweir 
Execute(SfxRequest & rReq)521cdf0e10cSrcweir void __EXPORT ScPreviewShell::Execute( SfxRequest& rReq )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir 	sal_uInt16 nSlot = rReq.GetSlot();
524cdf0e10cSrcweir 	const SfxItemSet* pReqArgs = rReq.GetArgs();
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	switch ( nSlot )
527cdf0e10cSrcweir 	{
528cdf0e10cSrcweir 		case SID_FORMATPAGE:
529cdf0e10cSrcweir 		case SID_STATUS_PAGESTYLE:
530cdf0e10cSrcweir 		case SID_HFEDIT:
531cdf0e10cSrcweir 			pDocShell->ExecutePageStyle( *this, rReq, pPreview->GetTab() );
532cdf0e10cSrcweir 			break;
533cdf0e10cSrcweir 		case SID_REPAINT:
534cdf0e10cSrcweir 			pPreview->Invalidate();
535cdf0e10cSrcweir 			rReq.Done();
536cdf0e10cSrcweir 			break;
537cdf0e10cSrcweir 		case SID_PREV_TABLE: // Accelerator
538cdf0e10cSrcweir 		case SID_PREVIEW_PREVIOUS:
539cdf0e10cSrcweir 			{
540cdf0e10cSrcweir 				long nPage = pPreview->GetPageNo();
541cdf0e10cSrcweir 				long nTotal = pPreview->GetTotalPages();
542cdf0e10cSrcweir 				if (nTotal && nPage > 0)
543cdf0e10cSrcweir 					pPreview->SetPageNo( nPage-1 );
544cdf0e10cSrcweir 			}
545cdf0e10cSrcweir 			break;
546cdf0e10cSrcweir 		case SID_NEXT_TABLE: // Accelerator
547cdf0e10cSrcweir 		case SID_PREVIEW_NEXT:
548cdf0e10cSrcweir 			{
549cdf0e10cSrcweir 				sal_Bool bAllTested	= pPreview->AllTested();
550cdf0e10cSrcweir 				long nPage = pPreview->GetPageNo();
551cdf0e10cSrcweir 				long nTotal = pPreview->GetTotalPages();
552cdf0e10cSrcweir 				if (nTotal && (nPage+1 < nTotal || !bAllTested))
553cdf0e10cSrcweir 					pPreview->SetPageNo( nPage+1 );
554cdf0e10cSrcweir 			}
555cdf0e10cSrcweir 			break;
556cdf0e10cSrcweir 		case SID_CURSORTOPOFFILE: // Accelerator
557cdf0e10cSrcweir 		case SID_PREVIEW_FIRST:
558cdf0e10cSrcweir 			{
559cdf0e10cSrcweir 				long nPage = pPreview->GetPageNo();
560cdf0e10cSrcweir 				long nTotal = pPreview->GetTotalPages();
561cdf0e10cSrcweir 				if (nTotal && nPage != 0)
562cdf0e10cSrcweir 					pPreview->SetPageNo( 0 );
563cdf0e10cSrcweir 			}
564cdf0e10cSrcweir 			break;
565cdf0e10cSrcweir 		case SID_CURSORENDOFFILE: // Accelerator
566cdf0e10cSrcweir 		case SID_PREVIEW_LAST:
567cdf0e10cSrcweir 			{
568cdf0e10cSrcweir 				if (!pPreview->AllTested())
569cdf0e10cSrcweir 					pPreview->CalcAll();
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 				long nPage = pPreview->GetPageNo();
572cdf0e10cSrcweir 				long nTotal = pPreview->GetTotalPages();
573cdf0e10cSrcweir 				if (nTotal && nPage+1 != nTotal)
574cdf0e10cSrcweir 					pPreview->SetPageNo( nTotal-1 );
575cdf0e10cSrcweir 			}
576cdf0e10cSrcweir 			break;
577cdf0e10cSrcweir 		case SID_ATTR_ZOOM:
578cdf0e10cSrcweir 		case FID_SCALE:
579cdf0e10cSrcweir 			{
580cdf0e10cSrcweir 				sal_uInt16		nZoom		= 100;
581cdf0e10cSrcweir 				sal_Bool		bCancel		= sal_False;
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 				eZoom = SVX_ZOOM_PERCENT;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 				if ( pReqArgs )
586cdf0e10cSrcweir 				{
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 					const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
589cdf0e10cSrcweir 												   pReqArgs->Get(SID_ATTR_ZOOM);
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 					eZoom = rZoomItem.GetType();
592cdf0e10cSrcweir 					nZoom = rZoomItem.GetValue();
593cdf0e10cSrcweir 				}
594cdf0e10cSrcweir 				else
595cdf0e10cSrcweir 				{
596cdf0e10cSrcweir 					SfxItemSet		aSet	 ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
597cdf0e10cSrcweir 					SvxZoomItem		aZoomItem( SVX_ZOOM_PERCENT, pPreview->GetZoom(), SID_ATTR_ZOOM );
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 					aSet.Put( aZoomItem );
600cdf0e10cSrcweir 					//CHINA001 SvxZoomDialog* pDlg = pDlg = new SvxZoomDialog( NULL, aSet );
601cdf0e10cSrcweir 					SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
602cdf0e10cSrcweir 					if(pFact)
603cdf0e10cSrcweir 					{
604cdf0e10cSrcweir 						AbstractSvxZoomDialog* pDlg = pFact->CreateSvxZoomDialog(NULL, aSet);
605cdf0e10cSrcweir 						DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
606cdf0e10cSrcweir 						pDlg->SetLimits( 20, 400 );
607cdf0e10cSrcweir 						pDlg->HideButton( ZOOMBTN_OPTIMAL );
608cdf0e10cSrcweir 						bCancel = ( RET_CANCEL == pDlg->Execute() );
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 						if ( !bCancel )
611cdf0e10cSrcweir 						{
612cdf0e10cSrcweir 							const SvxZoomItem&	rZoomItem = (const SvxZoomItem&)
613cdf0e10cSrcweir 													pDlg->GetOutputItemSet()->
614cdf0e10cSrcweir 														Get( SID_ATTR_ZOOM );
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 							eZoom = rZoomItem.GetType();
617cdf0e10cSrcweir 							nZoom = rZoomItem.GetValue();
618cdf0e10cSrcweir 						}
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 						delete pDlg;
621cdf0e10cSrcweir 					}
622cdf0e10cSrcweir 				}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 				if ( !bCancel )
625cdf0e10cSrcweir 				{
626cdf0e10cSrcweir 					switch ( eZoom )
627cdf0e10cSrcweir 					{
628cdf0e10cSrcweir 						case SVX_ZOOM_OPTIMAL:
629cdf0e10cSrcweir 						case SVX_ZOOM_WHOLEPAGE:
630cdf0e10cSrcweir 							nZoom = pPreview->GetOptimalZoom(sal_False);
631cdf0e10cSrcweir 							break;
632cdf0e10cSrcweir 						case SVX_ZOOM_PAGEWIDTH:
633cdf0e10cSrcweir 							nZoom = pPreview->GetOptimalZoom(sal_True);
634cdf0e10cSrcweir 							break;
635cdf0e10cSrcweir                         default:
636cdf0e10cSrcweir                         {
637cdf0e10cSrcweir                             // added to avoid warnings
638cdf0e10cSrcweir                         }
639cdf0e10cSrcweir 					}
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 					pPreview->SetZoom( nZoom );
642cdf0e10cSrcweir 					rReq.Done();
643cdf0e10cSrcweir 				}
644cdf0e10cSrcweir 			}
645cdf0e10cSrcweir 			break;
646cdf0e10cSrcweir 		case SID_PREVIEW_ZOOMIN:
647cdf0e10cSrcweir 			{
648cdf0e10cSrcweir 				sal_uInt16 nNew = pPreview->GetZoom() + 20 ;
649cdf0e10cSrcweir 				nNew -= nNew % 20;
650cdf0e10cSrcweir 				pPreview->SetZoom( nNew );
651cdf0e10cSrcweir 				eZoom = SVX_ZOOM_PERCENT;
652cdf0e10cSrcweir 				rReq.Done();
653cdf0e10cSrcweir 			}
654cdf0e10cSrcweir 			break;
655cdf0e10cSrcweir 		case SID_PREVIEW_ZOOMOUT:
656cdf0e10cSrcweir 			{
657cdf0e10cSrcweir 				sal_uInt16 nNew = pPreview->GetZoom() - 1;
658cdf0e10cSrcweir 				nNew -= nNew % 20;
659cdf0e10cSrcweir 				pPreview->SetZoom( nNew );
660cdf0e10cSrcweir 				eZoom = SVX_ZOOM_PERCENT;
661cdf0e10cSrcweir 				rReq.Done();
662cdf0e10cSrcweir 			}
663cdf0e10cSrcweir 			break;
664cdf0e10cSrcweir         case SID_PREVIEW_MARGIN:
665cdf0e10cSrcweir             {
666cdf0e10cSrcweir                 sal_Bool bMargin = pPreview->GetPageMargins();
667cdf0e10cSrcweir                 pPreview->SetPageMargins( !bMargin );
668cdf0e10cSrcweir                 pPreview->Invalidate();
669cdf0e10cSrcweir                 rReq.Done();
670cdf0e10cSrcweir             }
671cdf0e10cSrcweir             break;
672cdf0e10cSrcweir         case SID_ATTR_ZOOMSLIDER:
673cdf0e10cSrcweir             {
674cdf0e10cSrcweir                 const SfxPoolItem* pItem;
675cdf0e10cSrcweir                 eZoom = SVX_ZOOM_PERCENT;
676cdf0e10cSrcweir                 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_ZOOMSLIDER, sal_True, &pItem ) )
677cdf0e10cSrcweir                 {
678cdf0e10cSrcweir                     const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem*)pItem)->GetValue();
679cdf0e10cSrcweir                     if( nCurrentZoom )
680cdf0e10cSrcweir                     {
681cdf0e10cSrcweir                         pPreview->SetZoom( nCurrentZoom );
682cdf0e10cSrcweir                         rReq.Done();
683cdf0e10cSrcweir                     }
684cdf0e10cSrcweir                 }
685cdf0e10cSrcweir             }
686cdf0e10cSrcweir             break;
687cdf0e10cSrcweir         case SID_PREVIEW_SCALINGFACTOR:
688cdf0e10cSrcweir             {
689cdf0e10cSrcweir                 const SfxPoolItem* pItem;
690cdf0e10cSrcweir                 SCTAB nTab                      = pPreview->GetTab();
691cdf0e10cSrcweir                 String aOldName                 = pDocShell->GetDocument()->GetPageStyle( pPreview->GetTab() );
692cdf0e10cSrcweir                 ScStyleSheetPool* pStylePool    = pDocShell->GetDocument()->GetStyleSheetPool();
693cdf0e10cSrcweir                 SfxStyleSheetBase* pStyleSheet  = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
694cdf0e10cSrcweir                 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
695cdf0e10cSrcweir 
696cdf0e10cSrcweir                 if ( pReqArgs && pStyleSheet && SFX_ITEM_SET == pReqArgs->GetItemState( SID_PREVIEW_SCALINGFACTOR, sal_True, &pItem ) )
697cdf0e10cSrcweir                 {
698cdf0e10cSrcweir                     const sal_uInt16 nCurrentZoom   = ((const SvxZoomSliderItem *)pItem)->GetValue();
699cdf0e10cSrcweir                     SfxItemSet& rSet            = pStyleSheet->GetItemSet();
700cdf0e10cSrcweir                     rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nCurrentZoom ) );
701cdf0e10cSrcweir                     ScPrintFunc aPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab );
702cdf0e10cSrcweir                     aPrintFunc.UpdatePages();
703cdf0e10cSrcweir                     rReq.Done();
704cdf0e10cSrcweir                 }
705cdf0e10cSrcweir                 GetViewFrame()->GetBindings().Invalidate( nSlot );
706cdf0e10cSrcweir             }
707cdf0e10cSrcweir             break;
708cdf0e10cSrcweir 		case SID_PRINTPREVIEW:
709cdf0e10cSrcweir 		case SID_PREVIEW_CLOSE:
710cdf0e10cSrcweir 			//	print preview is now always in the same frame as the tab view
711cdf0e10cSrcweir 			//	-> always switch this frame back to normal view
712cdf0e10cSrcweir 			//	(ScTabViewShell ctor reads stored view data)
713cdf0e10cSrcweir 
714cdf0e10cSrcweir             GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_ASYNCHRON );
715cdf0e10cSrcweir 			break;
716cdf0e10cSrcweir 		case SID_CURSORPAGEUP:
717cdf0e10cSrcweir 		case SID_CURSORPAGEDOWN:
718cdf0e10cSrcweir 		case SID_CURSORHOME:
719cdf0e10cSrcweir 		case SID_CURSOREND:
720cdf0e10cSrcweir 		case SID_CURSORUP:
721cdf0e10cSrcweir 		case SID_CURSORDOWN:
722cdf0e10cSrcweir 		case SID_CURSORLEFT:
723cdf0e10cSrcweir 		case SID_CURSORRIGHT:
724cdf0e10cSrcweir 			DoScroll( nSlot );
725cdf0e10cSrcweir 			break;
726cdf0e10cSrcweir         case SID_CANCEL:
727cdf0e10cSrcweir             if( ScViewUtil::IsFullScreen( *this ) )
728cdf0e10cSrcweir                 ScViewUtil::SetFullScreen( *this, false );
729cdf0e10cSrcweir             break;
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 		default:
732cdf0e10cSrcweir 			break;
733cdf0e10cSrcweir 	}
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
GetState(SfxItemSet & rSet)736cdf0e10cSrcweir void __EXPORT ScPreviewShell::GetState( SfxItemSet& rSet )
737cdf0e10cSrcweir {
738cdf0e10cSrcweir 	pPreview->SetInGetState(sal_True);
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 	SCTAB nTab		= pPreview->GetTab();
741cdf0e10cSrcweir 	long nPage		= pPreview->GetPageNo();
742cdf0e10cSrcweir 	long nTotal		= pPreview->GetTotalPages();
743cdf0e10cSrcweir 	sal_uInt16 nZoom	= pPreview->GetZoom();
744cdf0e10cSrcweir 	sal_Bool bAllTested	= pPreview->AllTested();
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
747cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
748cdf0e10cSrcweir 	while ( nWhich )
749cdf0e10cSrcweir 	{
750cdf0e10cSrcweir 		switch (nWhich)
751cdf0e10cSrcweir 		{
752cdf0e10cSrcweir 			case SID_STATUS_PAGESTYLE:
753cdf0e10cSrcweir 			case SID_HFEDIT:
754cdf0e10cSrcweir 				pDocShell->GetStatePageStyle( *this, rSet, nTab );
755cdf0e10cSrcweir 				break;
756cdf0e10cSrcweir 			case SID_UNDO:
757cdf0e10cSrcweir 			case SID_REDO:
758cdf0e10cSrcweir 			case SID_REPEAT:
759cdf0e10cSrcweir 				rSet.DisableItem(nWhich);
760cdf0e10cSrcweir 				break;
761cdf0e10cSrcweir 			case SID_PREVIEW_PREVIOUS:
762cdf0e10cSrcweir 			case SID_PREVIEW_FIRST:
763cdf0e10cSrcweir 				if (!nTotal || nPage==0)
764cdf0e10cSrcweir 					rSet.DisableItem(nWhich);
765cdf0e10cSrcweir 				break;
766cdf0e10cSrcweir 			case SID_PREVIEW_NEXT:
767cdf0e10cSrcweir 			case SID_PREVIEW_LAST:
768cdf0e10cSrcweir 				if (bAllTested)
769cdf0e10cSrcweir 					if (!nTotal || nPage==nTotal-1)
770cdf0e10cSrcweir 						rSet.DisableItem(nWhich);
771cdf0e10cSrcweir 				break;
772cdf0e10cSrcweir 			case SID_PREVIEW_ZOOMIN:
773cdf0e10cSrcweir 				if (nZoom >= 400)
774cdf0e10cSrcweir 					rSet.DisableItem(nWhich);
775cdf0e10cSrcweir 				break;
776cdf0e10cSrcweir 			case SID_PREVIEW_ZOOMOUT:
777cdf0e10cSrcweir 				if (nZoom <= 20)
778cdf0e10cSrcweir 					rSet.DisableItem(nWhich);
779cdf0e10cSrcweir 				break;
780cdf0e10cSrcweir 			case SID_ATTR_ZOOM:
781cdf0e10cSrcweir 				{
782cdf0e10cSrcweir 					SvxZoomItem aZoom( eZoom, nZoom, nWhich );
783cdf0e10cSrcweir 					aZoom.SetValueSet( SVX_ZOOM_ENABLE_ALL & ~SVX_ZOOM_ENABLE_OPTIMAL );
784cdf0e10cSrcweir 					rSet.Put( aZoom );
785cdf0e10cSrcweir 				}
786cdf0e10cSrcweir 				break;
787cdf0e10cSrcweir             case SID_ATTR_ZOOMSLIDER:
788cdf0e10cSrcweir                 {
789cdf0e10cSrcweir                     SvxZoomSliderItem aZoomSliderItem( nZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
790cdf0e10cSrcweir                     aZoomSliderItem.AddSnappingPoint( 100 );
791cdf0e10cSrcweir                     rSet.Put( aZoomSliderItem );
792cdf0e10cSrcweir                 }
793cdf0e10cSrcweir                 break;
794cdf0e10cSrcweir             case SID_PREVIEW_SCALINGFACTOR:
795cdf0e10cSrcweir                 {
796cdf0e10cSrcweir                     if( pDocShell->IsReadOnly() )
797cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
798cdf0e10cSrcweir                     else
799cdf0e10cSrcweir                     {
800cdf0e10cSrcweir                         String aOldName                 = pDocShell->GetDocument()->GetPageStyle( pPreview->GetTab() );
801cdf0e10cSrcweir                         ScStyleSheetPool* pStylePool    = pDocShell->GetDocument()->GetStyleSheetPool();
802cdf0e10cSrcweir                         SfxStyleSheetBase* pStyleSheet  = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
803cdf0e10cSrcweir                         DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
804cdf0e10cSrcweir 
805cdf0e10cSrcweir                         if ( pStyleSheet )
806cdf0e10cSrcweir                         {
807cdf0e10cSrcweir                             SfxItemSet& rStyleSet   = pStyleSheet->GetItemSet();
808cdf0e10cSrcweir                             sal_uInt16 nCurrentZoom     = ((const SfxUInt16Item&)rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
809cdf0e10cSrcweir                             if( nCurrentZoom )
810cdf0e10cSrcweir                             {
811cdf0e10cSrcweir                                 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM_SLIDER, MAXZOOM_SLIDER, SID_PREVIEW_SCALINGFACTOR );
812cdf0e10cSrcweir                                 aZoomSliderItem.AddSnappingPoint( 100 );
813cdf0e10cSrcweir                                 rSet.Put( aZoomSliderItem );
814cdf0e10cSrcweir                             }
815cdf0e10cSrcweir                             else
816cdf0e10cSrcweir                                 rSet.DisableItem( nWhich );
817cdf0e10cSrcweir                         }
818cdf0e10cSrcweir                     }
819cdf0e10cSrcweir                 }
820cdf0e10cSrcweir                 break;
821cdf0e10cSrcweir 			case SID_STATUS_DOCPOS:
822cdf0e10cSrcweir 				rSet.Put( SfxStringItem( nWhich, pPreview->GetPosString() ) );
823cdf0e10cSrcweir 				break;
824cdf0e10cSrcweir 			case SID_PRINTPREVIEW:
825cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( nWhich, sal_True ) );
826cdf0e10cSrcweir 				break;
827cdf0e10cSrcweir 			case SID_FORMATPAGE:
828cdf0e10cSrcweir             case SID_PREVIEW_MARGIN:
829cdf0e10cSrcweir                 if( pDocShell->IsReadOnly() )
830cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
831cdf0e10cSrcweir 				break;
832cdf0e10cSrcweir 		}
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
835cdf0e10cSrcweir 	}
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 	pPreview->SetInGetState(sal_False);
838cdf0e10cSrcweir }
839cdf0e10cSrcweir 
FillFieldData(ScHeaderFieldData & rData)840cdf0e10cSrcweir void ScPreviewShell::FillFieldData( ScHeaderFieldData& rData )
841cdf0e10cSrcweir {
842cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
843cdf0e10cSrcweir 	SCTAB nTab = pPreview->GetTab();
844cdf0e10cSrcweir 	pDoc->GetName( nTab, rData.aTabName );
845cdf0e10cSrcweir 
846cdf0e10cSrcweir 	rData.aTitle		= pDocShell->GetTitle();
847cdf0e10cSrcweir 	const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
848cdf0e10cSrcweir 	rData.aLongDocName	= rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
849cdf0e10cSrcweir 	if ( rData.aLongDocName.Len() )
850cdf0e10cSrcweir 		rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS );
851cdf0e10cSrcweir 	else
852cdf0e10cSrcweir 		rData.aShortDocName = rData.aLongDocName = rData.aTitle;
853cdf0e10cSrcweir 	rData.nPageNo		= pPreview->GetPageNo() + 1;
854cdf0e10cSrcweir 
855cdf0e10cSrcweir 	sal_Bool bAllTested	= pPreview->AllTested();
856cdf0e10cSrcweir 	if (bAllTested)
857cdf0e10cSrcweir 		rData.nTotalPages = pPreview->GetTotalPages();
858cdf0e10cSrcweir 	else
859cdf0e10cSrcweir 		rData.nTotalPages = 99;
860cdf0e10cSrcweir 
861cdf0e10cSrcweir 	//	eNumType kennt der Dialog selber
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
WriteUserData(String & rData,sal_Bool)864cdf0e10cSrcweir void __EXPORT ScPreviewShell::WriteUserData(String& rData, sal_Bool /* bBrowse */)
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	//	nZoom
867cdf0e10cSrcweir 	//	nPageNo
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	rData =  String::CreateFromInt32(pPreview->GetZoom());
870cdf0e10cSrcweir 	rData += (sal_Unicode) SC_USERDATA_SEP;
871cdf0e10cSrcweir 	rData += String::CreateFromInt32(pPreview->GetPageNo());
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
ReadUserData(const String & rData,sal_Bool)874cdf0e10cSrcweir void __EXPORT ScPreviewShell::ReadUserData(const String& rData, sal_Bool /* bBrowse */)
875cdf0e10cSrcweir {
876cdf0e10cSrcweir 	xub_StrLen nCount = rData.GetTokenCount();
877cdf0e10cSrcweir 	if (nCount)
878cdf0e10cSrcweir 	{
879cdf0e10cSrcweir 		xub_StrLen nIndex = 0;
880cdf0e10cSrcweir 		pPreview->SetZoom((sal_uInt16)rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32());
881cdf0e10cSrcweir 		pPreview->SetPageNo(rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32());
882cdf0e10cSrcweir 		eZoom = SVX_ZOOM_PERCENT;
883cdf0e10cSrcweir 	}
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
WriteUserDataSequence(uno::Sequence<beans::PropertyValue> & rSeq,sal_Bool)886cdf0e10cSrcweir void __EXPORT ScPreviewShell::WriteUserDataSequence(uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */)
887cdf0e10cSrcweir {
888cdf0e10cSrcweir 	rSeq.realloc(3);
889cdf0e10cSrcweir 	beans::PropertyValue* pSeq = rSeq.getArray();
890cdf0e10cSrcweir 	if(pSeq)
891cdf0e10cSrcweir 	{
892cdf0e10cSrcweir 		sal_uInt16 nViewID(GetViewFrame()->GetCurViewId());
893cdf0e10cSrcweir 		pSeq[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEWID));
894cdf0e10cSrcweir 		rtl::OUStringBuffer sBuffer(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEW)));
895cdf0e10cSrcweir 		SvXMLUnitConverter::convertNumber(sBuffer, static_cast<sal_Int32>(nViewID));
896cdf0e10cSrcweir 		pSeq[0].Value <<= sBuffer.makeStringAndClear();
897cdf0e10cSrcweir 		pSeq[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMVALUE));
898cdf0e10cSrcweir 		pSeq[1].Value <<= sal_Int32 (pPreview->GetZoom());
899cdf0e10cSrcweir 		pSeq[2].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageNumber"));
900cdf0e10cSrcweir 		pSeq[2].Value <<= pPreview->GetPageNo();
901cdf0e10cSrcweir 	}
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
ReadUserDataSequence(const uno::Sequence<beans::PropertyValue> & rSeq,sal_Bool)904cdf0e10cSrcweir void __EXPORT ScPreviewShell::ReadUserDataSequence(const uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */)
905cdf0e10cSrcweir {
906cdf0e10cSrcweir 	sal_Int32 nCount(rSeq.getLength());
907cdf0e10cSrcweir 	if (nCount)
908cdf0e10cSrcweir 	{
909cdf0e10cSrcweir 		sal_Int32 nTemp = 0;
910cdf0e10cSrcweir 		const beans::PropertyValue* pSeq = rSeq.getConstArray();
911cdf0e10cSrcweir 		if(pSeq)
912cdf0e10cSrcweir 		{
913cdf0e10cSrcweir 			for(sal_Int32 i = 0; i < nCount; i++, pSeq++)
914cdf0e10cSrcweir 			{
915cdf0e10cSrcweir 				rtl::OUString sName(pSeq->Name);
916cdf0e10cSrcweir 				if(sName.compareToAscii(SC_ZOOMVALUE) == 0)
917cdf0e10cSrcweir 				{
918cdf0e10cSrcweir 					if (pSeq->Value >>= nTemp)
919cdf0e10cSrcweir 						pPreview->SetZoom(sal_uInt16(nTemp));
920cdf0e10cSrcweir 				}
921cdf0e10cSrcweir 				else if (sName.compareToAscii("PageNumber") == 0)
922cdf0e10cSrcweir 				{
923cdf0e10cSrcweir 					if (pSeq->Value >>= nTemp)
924cdf0e10cSrcweir 						pPreview->SetPageNo(nTemp);
925cdf0e10cSrcweir 				}
926cdf0e10cSrcweir 			}
927cdf0e10cSrcweir 		}
928cdf0e10cSrcweir 	}
929cdf0e10cSrcweir }
930cdf0e10cSrcweir 
DoScroll(sal_uInt16 nMode)931cdf0e10cSrcweir void ScPreviewShell::DoScroll( sal_uInt16 nMode )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir 	Point	aCurPos, aPrevPos;
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 	long nHRange	= pHorScroll->GetRange().Max();
936cdf0e10cSrcweir 	long nHLine		= pHorScroll->GetLineSize();
937cdf0e10cSrcweir 	long nHPage		= pHorScroll->GetPageSize();
938cdf0e10cSrcweir 	long nVRange	= pVerScroll->GetRange().Max();
939cdf0e10cSrcweir 	long nVLine		= pVerScroll->GetLineSize();
940cdf0e10cSrcweir 	long nVPage		= pVerScroll->GetPageSize();
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 	aCurPos.X() = pHorScroll->GetThumbPos();
943cdf0e10cSrcweir 	aCurPos.Y() = pVerScroll->GetThumbPos();
944cdf0e10cSrcweir 	aPrevPos = aCurPos;
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 	long nThumbPos	= pVerScroll->GetThumbPos();
947cdf0e10cSrcweir 	long nRangeMax	= pVerScroll->GetRangeMax();
948cdf0e10cSrcweir 
949cdf0e10cSrcweir 	switch( nMode )
950cdf0e10cSrcweir 	{
951cdf0e10cSrcweir         case SID_CURSORUP:
952cdf0e10cSrcweir             if( nMaxVertPos<0 )
953cdf0e10cSrcweir             {
954cdf0e10cSrcweir                 long nPage = pPreview->GetPageNo();
955cdf0e10cSrcweir 
956cdf0e10cSrcweir                 if( nPage>0 )
957cdf0e10cSrcweir                 {
958cdf0e10cSrcweir                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
959cdf0e10cSrcweir                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
960cdf0e10cSrcweir                     Execute( aSfxRequest );
961cdf0e10cSrcweir                 }
962cdf0e10cSrcweir             }
963cdf0e10cSrcweir             else
964cdf0e10cSrcweir                 aCurPos.Y() -= nVLine;
965cdf0e10cSrcweir             break;
966cdf0e10cSrcweir         case SID_CURSORDOWN:
967cdf0e10cSrcweir             if( nMaxVertPos<0 )
968cdf0e10cSrcweir             {
969cdf0e10cSrcweir                 long nPage = pPreview->GetPageNo();
970cdf0e10cSrcweir                 long nTotal = pPreview->GetTotalPages();
971cdf0e10cSrcweir 
972cdf0e10cSrcweir                 // before testing for last page, make sure all page counts are calculated
973cdf0e10cSrcweir                 if ( nPage+1 == nTotal && !pPreview->AllTested() )
974cdf0e10cSrcweir                 {
975cdf0e10cSrcweir                     pPreview->CalcAll();
976cdf0e10cSrcweir                     nTotal = pPreview->GetTotalPages();
977cdf0e10cSrcweir                 }
978cdf0e10cSrcweir 
979cdf0e10cSrcweir                 if( nPage<nTotal-1 )
980cdf0e10cSrcweir                 {
981cdf0e10cSrcweir                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
982cdf0e10cSrcweir                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT );
983cdf0e10cSrcweir                     Execute( aSfxRequest );
984cdf0e10cSrcweir                 }
985cdf0e10cSrcweir             }
986cdf0e10cSrcweir             else
987cdf0e10cSrcweir                 aCurPos.Y() += nVLine;
988cdf0e10cSrcweir             break;
989cdf0e10cSrcweir         case SID_CURSORLEFT:
990cdf0e10cSrcweir             aCurPos.X() -= nHLine;
991cdf0e10cSrcweir             break;
992cdf0e10cSrcweir         case SID_CURSORRIGHT:
993cdf0e10cSrcweir             aCurPos.X() += nHLine;
994cdf0e10cSrcweir             break;
995cdf0e10cSrcweir         case SID_CURSORPAGEUP:
996cdf0e10cSrcweir             if( nThumbPos==0 || nMaxVertPos<0 )
997cdf0e10cSrcweir             {
998cdf0e10cSrcweir                 long nPage = pPreview->GetPageNo();
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir                 if( nPage>0 )
1001cdf0e10cSrcweir                 {
1002cdf0e10cSrcweir                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
1003cdf0e10cSrcweir                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS );
1004cdf0e10cSrcweir                     Execute( aSfxRequest );
1005cdf0e10cSrcweir                     aCurPos.Y() = nVRange;
1006cdf0e10cSrcweir                 }
1007cdf0e10cSrcweir             }
1008cdf0e10cSrcweir             else
1009cdf0e10cSrcweir                 aCurPos.Y() -= nVPage;
1010cdf0e10cSrcweir             break;
1011cdf0e10cSrcweir         case SID_CURSORPAGEDOWN:
1012cdf0e10cSrcweir             if( (abs(nVPage+nThumbPos-nRangeMax)<10) || nMaxVertPos<0 )
1013cdf0e10cSrcweir             {
1014cdf0e10cSrcweir                 long nPage = pPreview->GetPageNo();
1015cdf0e10cSrcweir                 long nTotal = pPreview->GetTotalPages();
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir                 // before testing for last page, make sure all page counts are calculated
1018cdf0e10cSrcweir                 if ( nPage+1 == nTotal && !pPreview->AllTested() )
1019cdf0e10cSrcweir                 {
1020cdf0e10cSrcweir                     pPreview->CalcAll();
1021cdf0e10cSrcweir                     nTotal = pPreview->GetTotalPages();
1022cdf0e10cSrcweir                 }
1023cdf0e10cSrcweir                 if( nPage<nTotal-1 )
1024cdf0e10cSrcweir                 {
1025cdf0e10cSrcweir                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
1026cdf0e10cSrcweir                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT );
1027cdf0e10cSrcweir                     Execute( aSfxRequest );
1028cdf0e10cSrcweir                     aCurPos.Y() = 0;
1029cdf0e10cSrcweir                 }
1030cdf0e10cSrcweir             }
1031cdf0e10cSrcweir             else
1032cdf0e10cSrcweir                 aCurPos.Y() += nVPage;
1033cdf0e10cSrcweir             break;
1034cdf0e10cSrcweir         case SID_CURSORHOME:
1035cdf0e10cSrcweir             if( nMaxVertPos<0 )
1036cdf0e10cSrcweir             {
1037cdf0e10cSrcweir                 long nPage  = pPreview->GetPageNo();
1038cdf0e10cSrcweir                 long nTotal = pPreview->GetTotalPages();
1039cdf0e10cSrcweir                 if( nTotal && nPage != 0 )
1040cdf0e10cSrcweir                 {
1041cdf0e10cSrcweir                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
1042cdf0e10cSrcweir                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_FIRST );
1043cdf0e10cSrcweir                     Execute( aSfxRequest );
1044cdf0e10cSrcweir                 }
1045cdf0e10cSrcweir             }
1046cdf0e10cSrcweir             else
1047cdf0e10cSrcweir             {
1048cdf0e10cSrcweir                 aCurPos.Y() = 0;
1049cdf0e10cSrcweir                 aCurPos.X() = 0;
1050cdf0e10cSrcweir             }
1051cdf0e10cSrcweir             break;
1052cdf0e10cSrcweir         case SID_CURSOREND:
1053cdf0e10cSrcweir             if( nMaxVertPos<0 )
1054cdf0e10cSrcweir             {
1055cdf0e10cSrcweir                 if( !pPreview->AllTested() )
1056cdf0e10cSrcweir                     pPreview->CalcAll();
1057cdf0e10cSrcweir                 long nPage  = pPreview->GetPageNo();
1058cdf0e10cSrcweir                 long nTotal = pPreview->GetTotalPages();
1059cdf0e10cSrcweir                 if( nTotal && nPage+1 != nTotal )
1060cdf0e10cSrcweir                 {
1061cdf0e10cSrcweir                     SfxViewFrame* pSfxViewFrame = GetViewFrame();
1062cdf0e10cSrcweir                     SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_LAST );
1063cdf0e10cSrcweir                     Execute( aSfxRequest );
1064cdf0e10cSrcweir                 }
1065cdf0e10cSrcweir             }
1066cdf0e10cSrcweir             else
1067cdf0e10cSrcweir             {
1068cdf0e10cSrcweir                 aCurPos.Y() = nVRange;
1069cdf0e10cSrcweir                 aCurPos.X() = nHRange;
1070cdf0e10cSrcweir             }
1071cdf0e10cSrcweir             break;
1072cdf0e10cSrcweir 	}
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 		// nHRange-nHPage kann negativ sein, deshalb Abfrage auf < 0 hinterher
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir     if( aCurPos.Y() > (nVRange-nVPage) )
1077cdf0e10cSrcweir         aCurPos.Y() = (nVRange-nVPage);
1078cdf0e10cSrcweir     if( aCurPos.Y() < 0 )
1079cdf0e10cSrcweir         aCurPos.Y() = 0;
1080cdf0e10cSrcweir     if( aCurPos.X() > (nHRange-nHPage) )
1081cdf0e10cSrcweir         aCurPos.X() = (nHRange-nHPage);
1082cdf0e10cSrcweir     if( aCurPos.X() < 0 )
1083cdf0e10cSrcweir         aCurPos.X() = 0;
1084cdf0e10cSrcweir 
1085cdf0e10cSrcweir     if( nMaxVertPos>=0 )
1086cdf0e10cSrcweir     {
1087cdf0e10cSrcweir 	    if( aCurPos.Y() != aPrevPos.Y() )
1088cdf0e10cSrcweir 	    {
1089cdf0e10cSrcweir 	    	pVerScroll->SetThumbPos( aCurPos.Y() );
1090cdf0e10cSrcweir 	        pPreview->SetYOffset( aCurPos.Y() );
1091cdf0e10cSrcweir 	    }
1092cdf0e10cSrcweir     }
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir 	if( aCurPos.X() != aPrevPos.X() )
1095cdf0e10cSrcweir 	{
1096cdf0e10cSrcweir 		pHorScroll->SetThumbPos( aCurPos.X() );
1097cdf0e10cSrcweir 		pPreview->SetXOffset( aCurPos.X() );
1098cdf0e10cSrcweir 	}
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir }
1101cdf0e10cSrcweir 
AddAccessibilityObject(SfxListener & rObject)1102cdf0e10cSrcweir void ScPreviewShell::AddAccessibilityObject( SfxListener& rObject )
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir 	if (!pAccessibilityBroadcaster)
1105cdf0e10cSrcweir 		pAccessibilityBroadcaster = new SfxBroadcaster;
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir 	rObject.StartListening( *pAccessibilityBroadcaster );
1108cdf0e10cSrcweir }
1109cdf0e10cSrcweir 
RemoveAccessibilityObject(SfxListener & rObject)1110cdf0e10cSrcweir void ScPreviewShell::RemoveAccessibilityObject( SfxListener& rObject )
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir 	if (pAccessibilityBroadcaster)
1113cdf0e10cSrcweir 		rObject.EndListening( *pAccessibilityBroadcaster );
1114cdf0e10cSrcweir 	else
1115cdf0e10cSrcweir 	{
1116cdf0e10cSrcweir 		DBG_ERROR("kein Accessibility-Broadcaster?");
1117cdf0e10cSrcweir 	}
1118cdf0e10cSrcweir }
1119cdf0e10cSrcweir 
BroadcastAccessibility(const SfxHint & rHint)1120cdf0e10cSrcweir void ScPreviewShell::BroadcastAccessibility( const SfxHint &rHint )
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir 	if (pAccessibilityBroadcaster)
1123cdf0e10cSrcweir 		pAccessibilityBroadcaster->Broadcast( rHint );
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir 
HasAccessibilityObjects()1126cdf0e10cSrcweir sal_Bool ScPreviewShell::HasAccessibilityObjects()
1127cdf0e10cSrcweir {
1128cdf0e10cSrcweir 	return pAccessibilityBroadcaster && pAccessibilityBroadcaster->HasListeners();
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir 
GetLocationData()1131cdf0e10cSrcweir const ScPreviewLocationData& ScPreviewShell::GetLocationData()
1132cdf0e10cSrcweir {
1133cdf0e10cSrcweir 	return pPreview->GetLocationData();
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir 
GetDocument()1136cdf0e10cSrcweir ScDocument* ScPreviewShell::GetDocument()
1137cdf0e10cSrcweir {
1138cdf0e10cSrcweir 	return pDocShell->GetDocument();
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir 
1142