xref: /aoo41x/main/toolkit/workben/layout/zoom.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #if !TEST_LAYOUT
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_svx.hxx"
31*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #ifdef SVX_DLLIMPLEMENTATION
34*cdf0e10cSrcweir #undef SVX_DLLIMPLEMENTATION
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir // include ---------------------------------------------------------------
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #if TEST_LAYOUT
40*cdf0e10cSrcweir #include <cstdio>
41*cdf0e10cSrcweir #endif /* TEST_LAYOUT */
42*cdf0e10cSrcweir #include <tools/shl.hxx>
43*cdf0e10cSrcweir #include <svtools/itemset.hxx>
44*cdf0e10cSrcweir #include <svtools/itempool.hxx>
45*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
46*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #define _SVX_ZOOM_CXX
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <svx/dialogs.hrc>
51*cdf0e10cSrcweir #if !TEST_LAYOUT
52*cdf0e10cSrcweir #include "zoom.hrc"
53*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include "zoom.hxx"
56*cdf0e10cSrcweir #if TEST_LAYOUT
57*cdf0e10cSrcweir #define SVX_ZOOM_OPTIMAL "Zoom optimal"
58*cdf0e10cSrcweir #define SVX_ZOOM_PAGEWIDTH "Zoom page width"
59*cdf0e10cSrcweir #define SVX_ZOOM_WHOLEPAGE "Zoom whole page"
60*cdf0e10cSrcweir struct SvxZoomItem
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     void SetType( char const* s )
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir         fputs( s, stderr );
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     void SetValue( int n )
68*cdf0e10cSrcweir     {
69*cdf0e10cSrcweir         fprintf( stderr, "Zoom factor: %d\n", int( n ) );
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir #define SfxPoolItem LAYOUT_SfxPoolItem
73*cdf0e10cSrcweir class LAYOUT_SfxPoolItem
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir };
76*cdf0e10cSrcweir struct SvxViewLayoutItem : public LAYOUT_SfxPoolItem
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     bool IsBookMode()
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         return false;
81*cdf0e10cSrcweir     }
82*cdf0e10cSrcweir     USHORT GetValue()
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         return 0;
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     void SetValue( int n )
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         fprintf( stderr, "Zoom factor: %d\n", int( n ) );
90*cdf0e10cSrcweir     }
91*cdf0e10cSrcweir     void SetBookMode( bool )
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir     }
94*cdf0e10cSrcweir #if 0 // needed for real SfxPoolItem
95*cdf0e10cSrcweir     int operator==( const SfxPoolItem& ) const
96*cdf0e10cSrcweir     {
97*cdf0e10cSrcweir         return 0;
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir     SfxPoolItem* Clone( SfxItemPool* ) const
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         return 0;
102*cdf0e10cSrcweir     }
103*cdf0e10cSrcweir #endif
104*cdf0e10cSrcweir };
105*cdf0e10cSrcweir #else /* !TEST_LAYOUT */
106*cdf0e10cSrcweir #include <svx/zoomitem.hxx>
107*cdf0e10cSrcweir #include <svx/viewlayoutitem.hxx>
108*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
109*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
110*cdf0e10cSrcweir #include "zoom_def.hxx"
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir #include <layout/layout-pre.hxx>
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir #if ENABLE_LAYOUT
115*cdf0e10cSrcweir #undef SVX_RES
116*cdf0e10cSrcweir #define SVX_RES(x) #x
117*cdf0e10cSrcweir #undef SfxModalDialog
118*cdf0e10cSrcweir #define SfxModalDialog( parent, id ) Dialog( parent, "zoom.xml", id )
119*cdf0e10cSrcweir #endif /* ENABLE_LAYOUT */
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir // static ----------------------------------------------------------------
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir static USHORT pRanges[] =
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	SID_ATTR_ZOOM,
126*cdf0e10cSrcweir 	SID_ATTR_ZOOM,
127*cdf0e10cSrcweir 	0
128*cdf0e10cSrcweir };
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir #define SPECIAL_FACTOR	((USHORT)0xFFFF)
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir // class SvxZoomDialog ---------------------------------------------------
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir USHORT SvxZoomDialog::GetFactor() const
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     if ( a100Btn.IsChecked() )
137*cdf0e10cSrcweir 		return 100;
138*cdf0e10cSrcweir     if ( aUserBtn.IsChecked() )
139*cdf0e10cSrcweir 		return (USHORT)aUserEdit.GetValue();
140*cdf0e10cSrcweir 	else
141*cdf0e10cSrcweir 		return SPECIAL_FACTOR;
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir // -----------------------------------------------------------------------
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir void SvxZoomDialog::SetFactor( USHORT nNewFactor, USHORT nBtnId )
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir #if TEST_LAYOUT
149*cdf0e10cSrcweir     printf ("\t\t set factor %d\n", (int)nNewFactor);
150*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
151*cdf0e10cSrcweir 	aUserEdit.Disable();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	if ( !nBtnId )
154*cdf0e10cSrcweir 	{
155*cdf0e10cSrcweir         if ( nNewFactor == 100 )
156*cdf0e10cSrcweir 		{
157*cdf0e10cSrcweir 			a100Btn.Check();
158*cdf0e10cSrcweir 			a100Btn.GrabFocus();
159*cdf0e10cSrcweir 		}
160*cdf0e10cSrcweir         else
161*cdf0e10cSrcweir 		{
162*cdf0e10cSrcweir 			aUserBtn.Check();
163*cdf0e10cSrcweir 			aUserEdit.Enable();
164*cdf0e10cSrcweir 			aUserEdit.SetValue( (long)nNewFactor );
165*cdf0e10cSrcweir 			aUserEdit.GrabFocus();
166*cdf0e10cSrcweir 		}
167*cdf0e10cSrcweir 	}
168*cdf0e10cSrcweir 	else
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		aUserEdit.SetValue( (long)nNewFactor );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		if ( ZOOMBTN_OPTIMAL == nBtnId )
173*cdf0e10cSrcweir 		{
174*cdf0e10cSrcweir 			aOptimalBtn.Check();
175*cdf0e10cSrcweir 			aOptimalBtn.GrabFocus();
176*cdf0e10cSrcweir 		}
177*cdf0e10cSrcweir 		else if ( ZOOMBTN_PAGEWIDTH == nBtnId )
178*cdf0e10cSrcweir 		{
179*cdf0e10cSrcweir 			aPageWidthBtn.Check();
180*cdf0e10cSrcweir 			aPageWidthBtn.GrabFocus();
181*cdf0e10cSrcweir 		}
182*cdf0e10cSrcweir 		else if ( ZOOMBTN_WHOLEPAGE == nBtnId )
183*cdf0e10cSrcweir 		{
184*cdf0e10cSrcweir 			aWholePageBtn.Check();
185*cdf0e10cSrcweir 			aWholePageBtn.GrabFocus();
186*cdf0e10cSrcweir 		}
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir // -----------------------------------------------------------------------
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir void SvxZoomDialog::SetButtonText( USHORT nBtnId, const String& rNewTxt )
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir 	switch ( nBtnId )
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir 		case ZOOMBTN_OPTIMAL: // Optimal-Button
197*cdf0e10cSrcweir 			aOptimalBtn.SetText( rNewTxt );
198*cdf0e10cSrcweir 			break;
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 		case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
201*cdf0e10cSrcweir 			aPageWidthBtn.SetText( rNewTxt );
202*cdf0e10cSrcweir 			break;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
205*cdf0e10cSrcweir 			aWholePageBtn.SetText( rNewTxt );
206*cdf0e10cSrcweir 			break;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 		default:
209*cdf0e10cSrcweir 			DBG_ERROR( "wrong button number" );
210*cdf0e10cSrcweir 	}
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir // -----------------------------------------------------------------------
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir void SvxZoomDialog::HideButton( USHORT nBtnId )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	switch ( nBtnId )
218*cdf0e10cSrcweir 	{
219*cdf0e10cSrcweir 		case ZOOMBTN_OPTIMAL: // Optimal-Button
220*cdf0e10cSrcweir 			aOptimalBtn.Hide();
221*cdf0e10cSrcweir 			break;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
224*cdf0e10cSrcweir 			aPageWidthBtn.Hide();
225*cdf0e10cSrcweir 			break;
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 		case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
228*cdf0e10cSrcweir 			aWholePageBtn.Hide();
229*cdf0e10cSrcweir 			break;
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 		default:
232*cdf0e10cSrcweir 			DBG_ERROR( "Falsche Button-Nummer!!!" );
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir // -----------------------------------------------------------------------
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir void SvxZoomDialog::SetLimits( USHORT nMin, USHORT nMax )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	DBG_ASSERT( nMin < nMax, "invalid limits" );
241*cdf0e10cSrcweir     aUserEdit.SetMin( nMin );
242*cdf0e10cSrcweir 	aUserEdit.SetFirst( nMin );
243*cdf0e10cSrcweir     aUserEdit.SetMax( nMax );
244*cdf0e10cSrcweir 	aUserEdit.SetLast( nMax );
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir // -----------------------------------------------------------------------
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir void SvxZoomDialog::SetSpinSize( USHORT nNewSpin )
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	aUserEdit.SetSpinSize( nNewSpin );
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // -----------------------------------------------------------------------
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir #if TEST_LAYOUT
257*cdf0e10cSrcweir SvxZoomDialog::SvxZoomDialog( Window* pParent ) :
258*cdf0e10cSrcweir #else /* !TEST_LAYOUT */
259*cdf0e10cSrcweir SvxZoomDialog::SvxZoomDialog( Window* pParent, const SfxItemSet& rCoreSet ) :
260*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	SfxModalDialog( pParent, SVX_RES( RID_SVXDLG_ZOOM ) ),
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     aZoomFl         ( this, SVX_RES( FL_ZOOM ) ),
265*cdf0e10cSrcweir     aOptimalBtn     ( this, SVX_RES( BTN_OPTIMAL ) ),
266*cdf0e10cSrcweir     aWholePageBtn   ( this, SVX_RES( BTN_WHOLE_PAGE ) ),
267*cdf0e10cSrcweir     aPageWidthBtn   ( this, SVX_RES( BTN_PAGE_WIDTH ) ),
268*cdf0e10cSrcweir     a100Btn         ( this, SVX_RES( BTN_100 ) ),
269*cdf0e10cSrcweir     aUserBtn        ( this, SVX_RES( BTN_USER ) ),
270*cdf0e10cSrcweir 	aUserEdit       ( this, SVX_RES( ED_USER ) ),
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     aViewLayoutFl   ( this, SVX_RES( FL_VIEWLAYOUT ) ),
273*cdf0e10cSrcweir     aAutomaticBtn   ( this, SVX_RES( BTN_AUTOMATIC ) ),
274*cdf0e10cSrcweir     aSingleBtn      ( this, SVX_RES( BTN_SINGLE ) ),
275*cdf0e10cSrcweir     aColumnsBtn     ( this, SVX_RES( BTN_COLUMNS ) ),
276*cdf0e10cSrcweir     aColumnsEdit    ( this, SVX_RES( ED_COLUMNS ) ),
277*cdf0e10cSrcweir     aBookModeChk    ( this, SVX_RES( CHK_BOOK ) ),
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     aBottomFl       ( this, SVX_RES( FL_BOTTOM ) ),
280*cdf0e10cSrcweir     aOKBtn          ( this, SVX_RES( BTN_ZOOM_OK ) ),
281*cdf0e10cSrcweir 	aCancelBtn      ( this, SVX_RES( BTN_ZOOM_CANCEL ) ),
282*cdf0e10cSrcweir 	aHelpBtn	    ( this, SVX_RES( BTN_ZOOM_HELP ) ),
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir #if !TEST_LAYOUT
285*cdf0e10cSrcweir 	rSet		( rCoreSet ),
286*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
287*cdf0e10cSrcweir 	pOutSet     ( NULL ),
288*cdf0e10cSrcweir 	bModified	( FALSE )
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir #if ENABLE_LAYOUT
292*cdf0e10cSrcweir     SetHelpId (SID_ATTR_ZOOM);
293*cdf0e10cSrcweir #endif /* ENABLE_LAYOUT */
294*cdf0e10cSrcweir 	Link aLink = LINK( this, SvxZoomDialog, UserHdl );
295*cdf0e10cSrcweir     a100Btn.SetClickHdl( aLink );
296*cdf0e10cSrcweir     aOptimalBtn.SetClickHdl( aLink );
297*cdf0e10cSrcweir 	aPageWidthBtn.SetClickHdl( aLink );
298*cdf0e10cSrcweir 	aWholePageBtn.SetClickHdl( aLink );
299*cdf0e10cSrcweir 	aUserBtn.SetClickHdl( aLink );
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     Link aViewLayoutLink = LINK( this, SvxZoomDialog, ViewLayoutUserHdl );
302*cdf0e10cSrcweir     aAutomaticBtn.SetClickHdl( aViewLayoutLink );
303*cdf0e10cSrcweir     aSingleBtn.SetClickHdl( aViewLayoutLink );
304*cdf0e10cSrcweir     aColumnsBtn.SetClickHdl( aViewLayoutLink );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     Link aViewLayoutSpinLink = LINK( this, SvxZoomDialog, ViewLayoutSpinHdl );
307*cdf0e10cSrcweir     aColumnsEdit.SetModifyHdl( aViewLayoutSpinLink );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     Link aViewLayoutCheckLink = LINK( this, SvxZoomDialog, ViewLayoutCheckHdl );
310*cdf0e10cSrcweir     aBookModeChk.SetClickHdl( aViewLayoutCheckLink );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     aOKBtn.SetClickHdl( LINK( this, SvxZoomDialog, OKHdl ) );
313*cdf0e10cSrcweir 	aUserEdit.SetModifyHdl( LINK( this, SvxZoomDialog, SpinHdl ) );
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	// Default-Werte
316*cdf0e10cSrcweir 	USHORT nValue = 100;
317*cdf0e10cSrcweir 	USHORT nMin = 10;
318*cdf0e10cSrcweir 	USHORT nMax = 1000;
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir #if !TEST_LAYOUT
321*cdf0e10cSrcweir 	// ggf. erst den alten Wert besorgen
322*cdf0e10cSrcweir 	const SfxUInt16Item* pOldUserItem = 0;
323*cdf0e10cSrcweir 	SfxObjectShell* pSh = SfxObjectShell::Current();
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 	if ( pSh )
326*cdf0e10cSrcweir 		pOldUserItem = (const SfxUInt16Item*)pSh->GetItem( SID_ATTR_ZOOM_USER );
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	if ( pOldUserItem )
329*cdf0e10cSrcweir 		nValue = pOldUserItem->GetValue();
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	// UserEdit initialisieren
332*cdf0e10cSrcweir 	if ( nMin > nValue )
333*cdf0e10cSrcweir 		nMin = nValue;
334*cdf0e10cSrcweir 	if ( nMax < nValue )
335*cdf0e10cSrcweir 		nMax = nValue;
336*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
337*cdf0e10cSrcweir     aUserEdit.SetMin( nMin );
338*cdf0e10cSrcweir 	aUserEdit.SetFirst( nMin );
339*cdf0e10cSrcweir     aUserEdit.SetMax( nMax );
340*cdf0e10cSrcweir 	aUserEdit.SetLast( nMax );
341*cdf0e10cSrcweir 	aUserEdit.SetValue( nValue );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir #if TEST_LAYOUT
344*cdf0e10cSrcweir     USHORT nZoom = 100;
345*cdf0e10cSrcweir     SetFactor( nZoom );
346*cdf0e10cSrcweir #else /* !TEST_LAYOUT */
347*cdf0e10cSrcweir 	const SfxPoolItem& rItem = rSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_ZOOM ) );
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir 	if ( rItem.ISA(SvxZoomItem) )
350*cdf0e10cSrcweir 	{
351*cdf0e10cSrcweir 		const SvxZoomItem& rZoomItem = (const SvxZoomItem&)rItem;
352*cdf0e10cSrcweir         const USHORT nZoom = rZoomItem.GetValue();
353*cdf0e10cSrcweir         const SvxZoomType eType = rZoomItem.GetType();
354*cdf0e10cSrcweir         const USHORT nValSet = rZoomItem.GetValueSet();
355*cdf0e10cSrcweir 		USHORT nBtnId = 0;
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 		switch ( eType )
358*cdf0e10cSrcweir 		{
359*cdf0e10cSrcweir 			case SVX_ZOOM_OPTIMAL:
360*cdf0e10cSrcweir 				nBtnId = ZOOMBTN_OPTIMAL;
361*cdf0e10cSrcweir 				break;
362*cdf0e10cSrcweir 			case SVX_ZOOM_PAGEWIDTH:
363*cdf0e10cSrcweir 				nBtnId = ZOOMBTN_PAGEWIDTH;
364*cdf0e10cSrcweir 				break;
365*cdf0e10cSrcweir 			case SVX_ZOOM_WHOLEPAGE:
366*cdf0e10cSrcweir 				nBtnId = ZOOMBTN_WHOLEPAGE;
367*cdf0e10cSrcweir 				break;
368*cdf0e10cSrcweir 			case SVX_ZOOM_PERCENT:
369*cdf0e10cSrcweir 				break;
370*cdf0e10cSrcweir             case SVX_ZOOM_PAGEWIDTH_NOBORDER:
371*cdf0e10cSrcweir                 break;
372*cdf0e10cSrcweir 		}
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir         if ( !(SVX_ZOOM_ENABLE_100 & nValSet) )
375*cdf0e10cSrcweir 			a100Btn.Disable();
376*cdf0e10cSrcweir         if ( !(SVX_ZOOM_ENABLE_OPTIMAL & nValSet) )
377*cdf0e10cSrcweir 			aOptimalBtn.Disable();
378*cdf0e10cSrcweir 		if ( !(SVX_ZOOM_ENABLE_PAGEWIDTH & nValSet) )
379*cdf0e10cSrcweir 			aPageWidthBtn.Disable();
380*cdf0e10cSrcweir 		if ( !(SVX_ZOOM_ENABLE_WHOLEPAGE & nValSet) )
381*cdf0e10cSrcweir 			aWholePageBtn.Disable();
382*cdf0e10cSrcweir         SetFactor( nZoom, nBtnId );
383*cdf0e10cSrcweir 	}
384*cdf0e10cSrcweir 	else
385*cdf0e10cSrcweir 	{
386*cdf0e10cSrcweir         const USHORT nZoom = ( (const SfxUInt16Item&)rItem ).GetValue();
387*cdf0e10cSrcweir         SetFactor( nZoom );
388*cdf0e10cSrcweir 	}
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     const SfxPoolItem* pViewLayoutItem = 0;
391*cdf0e10cSrcweir     if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_VIEWLAYOUT, FALSE, &pViewLayoutItem ) )
392*cdf0e10cSrcweir     {
393*cdf0e10cSrcweir         const USHORT nColumns = static_cast<const SvxViewLayoutItem*>(pViewLayoutItem)->GetValue();
394*cdf0e10cSrcweir         const bool bBookMode  = static_cast<const SvxViewLayoutItem*>(pViewLayoutItem)->IsBookMode();
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir         if ( 0 == nColumns )
397*cdf0e10cSrcweir         {
398*cdf0e10cSrcweir             aAutomaticBtn.Check();
399*cdf0e10cSrcweir             aColumnsEdit.SetValue( 2 );
400*cdf0e10cSrcweir             aColumnsEdit.Disable();
401*cdf0e10cSrcweir             aBookModeChk.Disable();
402*cdf0e10cSrcweir         }
403*cdf0e10cSrcweir         else if ( 1 == nColumns)
404*cdf0e10cSrcweir         {
405*cdf0e10cSrcweir             aSingleBtn.Check();
406*cdf0e10cSrcweir             aColumnsEdit.SetValue( 2 );
407*cdf0e10cSrcweir             aColumnsEdit.Disable();
408*cdf0e10cSrcweir             aBookModeChk.Disable();
409*cdf0e10cSrcweir         }
410*cdf0e10cSrcweir         else
411*cdf0e10cSrcweir         {
412*cdf0e10cSrcweir             aColumnsBtn.Check();
413*cdf0e10cSrcweir             if ( !bBookMode )
414*cdf0e10cSrcweir             {
415*cdf0e10cSrcweir                 aColumnsEdit.SetValue( nColumns );
416*cdf0e10cSrcweir                 if ( 0 != nColumns % 2 )
417*cdf0e10cSrcweir                     aBookModeChk.Disable();
418*cdf0e10cSrcweir             }
419*cdf0e10cSrcweir             else
420*cdf0e10cSrcweir             {
421*cdf0e10cSrcweir                 aColumnsEdit.SetValue( nColumns );
422*cdf0e10cSrcweir                 aBookModeChk.Check();
423*cdf0e10cSrcweir             }
424*cdf0e10cSrcweir         }
425*cdf0e10cSrcweir     }
426*cdf0e10cSrcweir     else
427*cdf0e10cSrcweir     {
428*cdf0e10cSrcweir         // hide view layout related controls:
429*cdf0e10cSrcweir         aViewLayoutFl.Disable();
430*cdf0e10cSrcweir         aAutomaticBtn.Disable();
431*cdf0e10cSrcweir         aSingleBtn.Disable();
432*cdf0e10cSrcweir         aColumnsBtn.Disable();
433*cdf0e10cSrcweir         aColumnsEdit.Disable();
434*cdf0e10cSrcweir         aBookModeChk.Disable();
435*cdf0e10cSrcweir     }
436*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 	FreeResource();
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir // -----------------------------------------------------------------------
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir SvxZoomDialog::~SvxZoomDialog()
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir 	delete pOutSet;
446*cdf0e10cSrcweir 	pOutSet = 0;
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir // -----------------------------------------------------------------------
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir USHORT* SvxZoomDialog::GetRanges()
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir 	return pRanges;
454*cdf0e10cSrcweir }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir // -----------------------------------------------------------------------
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir IMPL_LINK( SvxZoomDialog, UserHdl, RadioButton *, pBtn )
459*cdf0e10cSrcweir {
460*cdf0e10cSrcweir #if TEST_LAYOUT
461*cdf0e10cSrcweir     fprintf( stderr, "SvxZoomDialog::UserHdl\n" );
462*cdf0e10cSrcweir #endif /* TEST_LAYOUT */
463*cdf0e10cSrcweir 	bModified |= TRUE;
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 	if ( pBtn == &aUserBtn )
466*cdf0e10cSrcweir 	{
467*cdf0e10cSrcweir 		aUserEdit.Enable();
468*cdf0e10cSrcweir 		aUserEdit.GrabFocus();
469*cdf0e10cSrcweir 	}
470*cdf0e10cSrcweir 	else
471*cdf0e10cSrcweir 		aUserEdit.Disable();
472*cdf0e10cSrcweir 	return 0;
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir // -----------------------------------------------------------------------
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir IMPL_LINK( SvxZoomDialog, SpinHdl, MetricField *, EMPTYARG )
478*cdf0e10cSrcweir {
479*cdf0e10cSrcweir 	if ( !aUserBtn.IsChecked() )
480*cdf0e10cSrcweir 		return 0;
481*cdf0e10cSrcweir 	bModified |= TRUE;
482*cdf0e10cSrcweir 	return 0;
483*cdf0e10cSrcweir }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir // -----------------------------------------------------------------------
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir IMPL_LINK( SvxZoomDialog, ViewLayoutUserHdl, RadioButton *, pBtn )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     bModified |= TRUE;
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir     if ( pBtn == &aAutomaticBtn )
492*cdf0e10cSrcweir     {
493*cdf0e10cSrcweir         aColumnsEdit.Disable();
494*cdf0e10cSrcweir         aBookModeChk.Disable();
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir     else if ( pBtn == &aSingleBtn )
497*cdf0e10cSrcweir     {
498*cdf0e10cSrcweir         aColumnsEdit.Disable();
499*cdf0e10cSrcweir         aBookModeChk.Disable();
500*cdf0e10cSrcweir     }
501*cdf0e10cSrcweir     else if ( pBtn == &aColumnsBtn )
502*cdf0e10cSrcweir     {
503*cdf0e10cSrcweir         aColumnsEdit.Enable();
504*cdf0e10cSrcweir         aColumnsEdit.GrabFocus();
505*cdf0e10cSrcweir         if ( 0 == aColumnsEdit.GetValue() % 2 )
506*cdf0e10cSrcweir             aBookModeChk.Enable();
507*cdf0e10cSrcweir     }
508*cdf0e10cSrcweir     else
509*cdf0e10cSrcweir     {
510*cdf0e10cSrcweir         DBG_ERROR( "Wrong Button" );
511*cdf0e10cSrcweir         return 0;
512*cdf0e10cSrcweir     }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir     return 0;
515*cdf0e10cSrcweir }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir // -----------------------------------------------------------------------
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir IMPL_LINK( SvxZoomDialog, ViewLayoutSpinHdl, MetricField *, pEdt )
520*cdf0e10cSrcweir {
521*cdf0e10cSrcweir     if ( pEdt == &aColumnsEdit && !aColumnsBtn.IsChecked() )
522*cdf0e10cSrcweir         return 0;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     if ( 0 == aColumnsEdit.GetValue() % 2 )
525*cdf0e10cSrcweir         aBookModeChk.Enable();
526*cdf0e10cSrcweir     else
527*cdf0e10cSrcweir     {
528*cdf0e10cSrcweir         aBookModeChk.Check( sal_False );
529*cdf0e10cSrcweir         aBookModeChk.Disable();
530*cdf0e10cSrcweir     }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir     bModified |= TRUE;
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     return 0;
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir // -----------------------------------------------------------------------
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir IMPL_LINK( SvxZoomDialog, ViewLayoutCheckHdl, CheckBox *, pChk )
540*cdf0e10cSrcweir {
541*cdf0e10cSrcweir     if ( pChk == &aBookModeChk && !aColumnsBtn.IsChecked() )
542*cdf0e10cSrcweir         return 0;
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir     bModified |= TRUE;
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     return 0;
547*cdf0e10cSrcweir }
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir // -----------------------------------------------------------------------
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir IMPL_LINK( SvxZoomDialog, OKHdl, Button *, pBtn )
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir 	if ( bModified || &aOKBtn != pBtn )
554*cdf0e10cSrcweir 	{
555*cdf0e10cSrcweir #if TEST_LAYOUT
556*cdf0e10cSrcweir 		SvxZoomItem aZoomItem;
557*cdf0e10cSrcweir 		SvxViewLayoutItem aViewLayoutItem;
558*cdf0e10cSrcweir #else /* !TEST_LAYOUT */
559*cdf0e10cSrcweir         SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, 0, rSet.GetPool()->GetWhich( SID_ATTR_ZOOM ) );
560*cdf0e10cSrcweir         SvxViewLayoutItem aViewLayoutItem( 0, false, rSet.GetPool()->GetWhich( SID_ATTR_VIEWLAYOUT ) );
561*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 		if ( &aOKBtn == pBtn )
564*cdf0e10cSrcweir 		{
565*cdf0e10cSrcweir 			USHORT nFactor = GetFactor();
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 			if ( SPECIAL_FACTOR == nFactor )
568*cdf0e10cSrcweir 			{
569*cdf0e10cSrcweir 				if ( aOptimalBtn.IsChecked() )
570*cdf0e10cSrcweir                     aZoomItem.SetType( SVX_ZOOM_OPTIMAL );
571*cdf0e10cSrcweir 				else if ( aPageWidthBtn.IsChecked() )
572*cdf0e10cSrcweir                     aZoomItem.SetType( SVX_ZOOM_PAGEWIDTH );
573*cdf0e10cSrcweir 				else if ( aWholePageBtn.IsChecked() )
574*cdf0e10cSrcweir                     aZoomItem.SetType( SVX_ZOOM_WHOLEPAGE );
575*cdf0e10cSrcweir 			}
576*cdf0e10cSrcweir 			else
577*cdf0e10cSrcweir                 aZoomItem.SetValue( nFactor );
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir             if ( aAutomaticBtn.IsChecked() )
580*cdf0e10cSrcweir             {
581*cdf0e10cSrcweir                 aViewLayoutItem.SetValue( 0 );
582*cdf0e10cSrcweir                 aViewLayoutItem.SetBookMode( false );
583*cdf0e10cSrcweir             }
584*cdf0e10cSrcweir             if ( aSingleBtn.IsChecked() )
585*cdf0e10cSrcweir             {
586*cdf0e10cSrcweir                 aViewLayoutItem.SetValue( 1 );
587*cdf0e10cSrcweir                 aViewLayoutItem.SetBookMode( false );
588*cdf0e10cSrcweir             }
589*cdf0e10cSrcweir             else if ( aColumnsBtn.IsChecked() )
590*cdf0e10cSrcweir             {
591*cdf0e10cSrcweir                 aViewLayoutItem.SetValue( static_cast<USHORT>(aColumnsEdit.GetValue()) );
592*cdf0e10cSrcweir                 aViewLayoutItem.SetBookMode( aBookModeChk.IsChecked() );
593*cdf0e10cSrcweir             }
594*cdf0e10cSrcweir         }
595*cdf0e10cSrcweir 		else
596*cdf0e10cSrcweir 		{
597*cdf0e10cSrcweir 			DBG_ERROR( "Wrong Button" );
598*cdf0e10cSrcweir 			return 0;
599*cdf0e10cSrcweir 		}
600*cdf0e10cSrcweir #if !TEST_LAYOUT
601*cdf0e10cSrcweir 		pOutSet = new SfxItemSet( rSet );
602*cdf0e10cSrcweir         pOutSet->Put( aZoomItem );
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir         // don't set attribute in case the whole viewlayout stuff is disabled:
605*cdf0e10cSrcweir         if ( aViewLayoutFl.IsEnabled() )
606*cdf0e10cSrcweir             pOutSet->Put( aViewLayoutItem );
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 		// Wert aus dem UserEdit "uber den Dialog hinaus merken
609*cdf0e10cSrcweir 		SfxObjectShell* pSh = SfxObjectShell::Current();
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 		if ( pSh )
612*cdf0e10cSrcweir 			pSh->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER,
613*cdf0e10cSrcweir 										 (UINT16)aUserEdit.GetValue() ) );
614*cdf0e10cSrcweir #endif /* !TEST_LAYOUT */
615*cdf0e10cSrcweir 		EndDialog( RET_OK );
616*cdf0e10cSrcweir 	}
617*cdf0e10cSrcweir 	else
618*cdf0e10cSrcweir 		EndDialog( RET_CANCEL );
619*cdf0e10cSrcweir 	return 0;
620*cdf0e10cSrcweir }
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 
623