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: zoom.cxx,v $
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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
34 #endif /* !TEST_LAYOUT */
36 #ifdef SVX_DLLIMPLEMENTATION
37 #undef SVX_DLLIMPLEMENTATION
40 // include ---------------------------------------------------------------
44 #endif /* TEST_LAYOUT */
45 #include <tools/shl.hxx>
46 #include <svtools/itemset.hxx>
47 #include <svtools/itempool.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <vcl/msgbox.hxx>
53 #include <svx/dialogs.hrc>
56 #endif /* !TEST_LAYOUT */
60 #define SVX_ZOOM_OPTIMAL "Zoom optimal"
61 #define SVX_ZOOM_PAGEWIDTH "Zoom page width"
62 #define SVX_ZOOM_WHOLEPAGE "Zoom whole page"
65 void SetType( char const* s
)
70 void SetValue( int n
)
72 fprintf( stderr
, "Zoom factor: %d\n", int( n
) );
75 #define SfxPoolItem LAYOUT_SfxPoolItem
76 class LAYOUT_SfxPoolItem
79 struct SvxViewLayoutItem
: public LAYOUT_SfxPoolItem
90 void SetValue( int n
)
92 fprintf( stderr
, "Zoom factor: %d\n", int( n
) );
94 void SetBookMode( bool )
97 #if 0 // needed for real SfxPoolItem
98 int operator==( const SfxPoolItem
& ) const
102 SfxPoolItem
* Clone( SfxItemPool
* ) const
108 #else /* !TEST_LAYOUT */
109 #include <svx/zoomitem.hxx>
110 #include <svx/viewlayoutitem.hxx>
111 #include <svx/dialmgr.hxx>
112 #endif /* !TEST_LAYOUT */
113 #include "zoom_def.hxx"
115 #include <layout/layout-pre.hxx>
119 #define SVX_RES(x) #x
120 #undef SfxModalDialog
121 #define SfxModalDialog( parent, id ) Dialog( parent, "zoom.xml", id )
122 #endif /* ENABLE_LAYOUT */
124 // static ----------------------------------------------------------------
126 static USHORT pRanges
[] =
133 #define SPECIAL_FACTOR ((USHORT)0xFFFF)
135 // class SvxZoomDialog ---------------------------------------------------
137 USHORT
SvxZoomDialog::GetFactor() const
139 if ( a100Btn
.IsChecked() )
141 if ( aUserBtn
.IsChecked() )
142 return (USHORT
)aUserEdit
.GetValue();
144 return SPECIAL_FACTOR
;
147 // -----------------------------------------------------------------------
149 void SvxZoomDialog::SetFactor( USHORT nNewFactor
, USHORT nBtnId
)
152 printf ("\t\t set factor %d\n", (int)nNewFactor
);
153 #endif /* !TEST_LAYOUT */
158 if ( nNewFactor
== 100 )
167 aUserEdit
.SetValue( (long)nNewFactor
);
168 aUserEdit
.GrabFocus();
173 aUserEdit
.SetValue( (long)nNewFactor
);
175 if ( ZOOMBTN_OPTIMAL
== nBtnId
)
178 aOptimalBtn
.GrabFocus();
180 else if ( ZOOMBTN_PAGEWIDTH
== nBtnId
)
182 aPageWidthBtn
.Check();
183 aPageWidthBtn
.GrabFocus();
185 else if ( ZOOMBTN_WHOLEPAGE
== nBtnId
)
187 aWholePageBtn
.Check();
188 aWholePageBtn
.GrabFocus();
193 // -----------------------------------------------------------------------
195 void SvxZoomDialog::SetButtonText( USHORT nBtnId
, const String
& rNewTxt
)
199 case ZOOMBTN_OPTIMAL
: // Optimal-Button
200 aOptimalBtn
.SetText( rNewTxt
);
203 case ZOOMBTN_PAGEWIDTH
: // Seitenbreite-Button
204 aPageWidthBtn
.SetText( rNewTxt
);
207 case ZOOMBTN_WHOLEPAGE
: // Ganze Seite-Button
208 aWholePageBtn
.SetText( rNewTxt
);
212 DBG_ERROR( "wrong button number" );
216 // -----------------------------------------------------------------------
218 void SvxZoomDialog::HideButton( USHORT nBtnId
)
222 case ZOOMBTN_OPTIMAL
: // Optimal-Button
226 case ZOOMBTN_PAGEWIDTH
: // Seitenbreite-Button
227 aPageWidthBtn
.Hide();
230 case ZOOMBTN_WHOLEPAGE
: // Ganze Seite-Button
231 aWholePageBtn
.Hide();
235 DBG_ERROR( "Falsche Button-Nummer!!!" );
239 // -----------------------------------------------------------------------
241 void SvxZoomDialog::SetLimits( USHORT nMin
, USHORT nMax
)
243 DBG_ASSERT( nMin
< nMax
, "invalid limits" );
244 aUserEdit
.SetMin( nMin
);
245 aUserEdit
.SetFirst( nMin
);
246 aUserEdit
.SetMax( nMax
);
247 aUserEdit
.SetLast( nMax
);
250 // -----------------------------------------------------------------------
252 void SvxZoomDialog::SetSpinSize( USHORT nNewSpin
)
254 aUserEdit
.SetSpinSize( nNewSpin
);
257 // -----------------------------------------------------------------------
260 SvxZoomDialog::SvxZoomDialog( Window
* pParent
) :
261 #else /* !TEST_LAYOUT */
262 SvxZoomDialog::SvxZoomDialog( Window
* pParent
, const SfxItemSet
& rCoreSet
) :
263 #endif /* !TEST_LAYOUT */
265 SfxModalDialog( pParent
, SVX_RES( RID_SVXDLG_ZOOM
) ),
267 aZoomFl ( this, SVX_RES( FL_ZOOM
) ),
268 aOptimalBtn ( this, SVX_RES( BTN_OPTIMAL
) ),
269 aWholePageBtn ( this, SVX_RES( BTN_WHOLE_PAGE
) ),
270 aPageWidthBtn ( this, SVX_RES( BTN_PAGE_WIDTH
) ),
271 a100Btn ( this, SVX_RES( BTN_100
) ),
272 aUserBtn ( this, SVX_RES( BTN_USER
) ),
273 aUserEdit ( this, SVX_RES( ED_USER
) ),
275 aViewLayoutFl ( this, SVX_RES( FL_VIEWLAYOUT
) ),
276 aAutomaticBtn ( this, SVX_RES( BTN_AUTOMATIC
) ),
277 aSingleBtn ( this, SVX_RES( BTN_SINGLE
) ),
278 aColumnsBtn ( this, SVX_RES( BTN_COLUMNS
) ),
279 aColumnsEdit ( this, SVX_RES( ED_COLUMNS
) ),
280 aBookModeChk ( this, SVX_RES( CHK_BOOK
) ),
282 aBottomFl ( this, SVX_RES( FL_BOTTOM
) ),
283 aOKBtn ( this, SVX_RES( BTN_ZOOM_OK
) ),
284 aCancelBtn ( this, SVX_RES( BTN_ZOOM_CANCEL
) ),
285 aHelpBtn ( this, SVX_RES( BTN_ZOOM_HELP
) ),
289 #endif /* !TEST_LAYOUT */
295 SetHelpId (SID_ATTR_ZOOM
);
296 #endif /* ENABLE_LAYOUT */
297 Link aLink
= LINK( this, SvxZoomDialog
, UserHdl
);
298 a100Btn
.SetClickHdl( aLink
);
299 aOptimalBtn
.SetClickHdl( aLink
);
300 aPageWidthBtn
.SetClickHdl( aLink
);
301 aWholePageBtn
.SetClickHdl( aLink
);
302 aUserBtn
.SetClickHdl( aLink
);
304 Link aViewLayoutLink
= LINK( this, SvxZoomDialog
, ViewLayoutUserHdl
);
305 aAutomaticBtn
.SetClickHdl( aViewLayoutLink
);
306 aSingleBtn
.SetClickHdl( aViewLayoutLink
);
307 aColumnsBtn
.SetClickHdl( aViewLayoutLink
);
309 Link aViewLayoutSpinLink
= LINK( this, SvxZoomDialog
, ViewLayoutSpinHdl
);
310 aColumnsEdit
.SetModifyHdl( aViewLayoutSpinLink
);
312 Link aViewLayoutCheckLink
= LINK( this, SvxZoomDialog
, ViewLayoutCheckHdl
);
313 aBookModeChk
.SetClickHdl( aViewLayoutCheckLink
);
315 aOKBtn
.SetClickHdl( LINK( this, SvxZoomDialog
, OKHdl
) );
316 aUserEdit
.SetModifyHdl( LINK( this, SvxZoomDialog
, SpinHdl
) );
324 // ggf. erst den alten Wert besorgen
325 const SfxUInt16Item
* pOldUserItem
= 0;
326 SfxObjectShell
* pSh
= SfxObjectShell::Current();
329 pOldUserItem
= (const SfxUInt16Item
*)pSh
->GetItem( SID_ATTR_ZOOM_USER
);
332 nValue
= pOldUserItem
->GetValue();
334 // UserEdit initialisieren
339 #endif /* !TEST_LAYOUT */
340 aUserEdit
.SetMin( nMin
);
341 aUserEdit
.SetFirst( nMin
);
342 aUserEdit
.SetMax( nMax
);
343 aUserEdit
.SetLast( nMax
);
344 aUserEdit
.SetValue( nValue
);
349 #else /* !TEST_LAYOUT */
350 const SfxPoolItem
& rItem
= rSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_ZOOM
) );
352 if ( rItem
.ISA(SvxZoomItem
) )
354 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)rItem
;
355 const USHORT nZoom
= rZoomItem
.GetValue();
356 const SvxZoomType eType
= rZoomItem
.GetType();
357 const USHORT nValSet
= rZoomItem
.GetValueSet();
362 case SVX_ZOOM_OPTIMAL
:
363 nBtnId
= ZOOMBTN_OPTIMAL
;
365 case SVX_ZOOM_PAGEWIDTH
:
366 nBtnId
= ZOOMBTN_PAGEWIDTH
;
368 case SVX_ZOOM_WHOLEPAGE
:
369 nBtnId
= ZOOMBTN_WHOLEPAGE
;
371 case SVX_ZOOM_PERCENT
:
373 case SVX_ZOOM_PAGEWIDTH_NOBORDER
:
377 if ( !(SVX_ZOOM_ENABLE_100
& nValSet
) )
379 if ( !(SVX_ZOOM_ENABLE_OPTIMAL
& nValSet
) )
380 aOptimalBtn
.Disable();
381 if ( !(SVX_ZOOM_ENABLE_PAGEWIDTH
& nValSet
) )
382 aPageWidthBtn
.Disable();
383 if ( !(SVX_ZOOM_ENABLE_WHOLEPAGE
& nValSet
) )
384 aWholePageBtn
.Disable();
385 SetFactor( nZoom
, nBtnId
);
389 const USHORT nZoom
= ( (const SfxUInt16Item
&)rItem
).GetValue();
393 const SfxPoolItem
* pViewLayoutItem
= 0;
394 if ( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_VIEWLAYOUT
, FALSE
, &pViewLayoutItem
) )
396 const USHORT nColumns
= static_cast<const SvxViewLayoutItem
*>(pViewLayoutItem
)->GetValue();
397 const bool bBookMode
= static_cast<const SvxViewLayoutItem
*>(pViewLayoutItem
)->IsBookMode();
401 aAutomaticBtn
.Check();
402 aColumnsEdit
.SetValue( 2 );
403 aColumnsEdit
.Disable();
404 aBookModeChk
.Disable();
406 else if ( 1 == nColumns
)
409 aColumnsEdit
.SetValue( 2 );
410 aColumnsEdit
.Disable();
411 aBookModeChk
.Disable();
418 aColumnsEdit
.SetValue( nColumns
);
419 if ( 0 != nColumns
% 2 )
420 aBookModeChk
.Disable();
424 aColumnsEdit
.SetValue( nColumns
);
425 aBookModeChk
.Check();
431 // hide view layout related controls:
432 aViewLayoutFl
.Disable();
433 aAutomaticBtn
.Disable();
434 aSingleBtn
.Disable();
435 aColumnsBtn
.Disable();
436 aColumnsEdit
.Disable();
437 aBookModeChk
.Disable();
439 #endif /* !TEST_LAYOUT */
444 // -----------------------------------------------------------------------
446 SvxZoomDialog::~SvxZoomDialog()
452 // -----------------------------------------------------------------------
454 USHORT
* SvxZoomDialog::GetRanges()
459 // -----------------------------------------------------------------------
461 IMPL_LINK( SvxZoomDialog
, UserHdl
, RadioButton
*, pBtn
)
464 fprintf( stderr
, "SvxZoomDialog::UserHdl\n" );
465 #endif /* TEST_LAYOUT */
468 if ( pBtn
== &aUserBtn
)
471 aUserEdit
.GrabFocus();
478 // -----------------------------------------------------------------------
480 IMPL_LINK( SvxZoomDialog
, SpinHdl
, MetricField
*, EMPTYARG
)
482 if ( !aUserBtn
.IsChecked() )
488 // -----------------------------------------------------------------------
490 IMPL_LINK( SvxZoomDialog
, ViewLayoutUserHdl
, RadioButton
*, pBtn
)
494 if ( pBtn
== &aAutomaticBtn
)
496 aColumnsEdit
.Disable();
497 aBookModeChk
.Disable();
499 else if ( pBtn
== &aSingleBtn
)
501 aColumnsEdit
.Disable();
502 aBookModeChk
.Disable();
504 else if ( pBtn
== &aColumnsBtn
)
506 aColumnsEdit
.Enable();
507 aColumnsEdit
.GrabFocus();
508 if ( 0 == aColumnsEdit
.GetValue() % 2 )
509 aBookModeChk
.Enable();
513 DBG_ERROR( "Wrong Button" );
520 // -----------------------------------------------------------------------
522 IMPL_LINK( SvxZoomDialog
, ViewLayoutSpinHdl
, MetricField
*, pEdt
)
524 if ( pEdt
== &aColumnsEdit
&& !aColumnsBtn
.IsChecked() )
527 if ( 0 == aColumnsEdit
.GetValue() % 2 )
528 aBookModeChk
.Enable();
531 aBookModeChk
.Check( sal_False
);
532 aBookModeChk
.Disable();
540 // -----------------------------------------------------------------------
542 IMPL_LINK( SvxZoomDialog
, ViewLayoutCheckHdl
, CheckBox
*, pChk
)
544 if ( pChk
== &aBookModeChk
&& !aColumnsBtn
.IsChecked() )
552 // -----------------------------------------------------------------------
554 IMPL_LINK( SvxZoomDialog
, OKHdl
, Button
*, pBtn
)
556 if ( bModified
|| &aOKBtn
!= pBtn
)
559 SvxZoomItem aZoomItem
;
560 SvxViewLayoutItem aViewLayoutItem
;
561 #else /* !TEST_LAYOUT */
562 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, 0, rSet
.GetPool()->GetWhich( SID_ATTR_ZOOM
) );
563 SvxViewLayoutItem
aViewLayoutItem( 0, false, rSet
.GetPool()->GetWhich( SID_ATTR_VIEWLAYOUT
) );
564 #endif /* !TEST_LAYOUT */
566 if ( &aOKBtn
== pBtn
)
568 USHORT nFactor
= GetFactor();
570 if ( SPECIAL_FACTOR
== nFactor
)
572 if ( aOptimalBtn
.IsChecked() )
573 aZoomItem
.SetType( SVX_ZOOM_OPTIMAL
);
574 else if ( aPageWidthBtn
.IsChecked() )
575 aZoomItem
.SetType( SVX_ZOOM_PAGEWIDTH
);
576 else if ( aWholePageBtn
.IsChecked() )
577 aZoomItem
.SetType( SVX_ZOOM_WHOLEPAGE
);
580 aZoomItem
.SetValue( nFactor
);
582 if ( aAutomaticBtn
.IsChecked() )
584 aViewLayoutItem
.SetValue( 0 );
585 aViewLayoutItem
.SetBookMode( false );
587 if ( aSingleBtn
.IsChecked() )
589 aViewLayoutItem
.SetValue( 1 );
590 aViewLayoutItem
.SetBookMode( false );
592 else if ( aColumnsBtn
.IsChecked() )
594 aViewLayoutItem
.SetValue( static_cast<USHORT
>(aColumnsEdit
.GetValue()) );
595 aViewLayoutItem
.SetBookMode( aBookModeChk
.IsChecked() );
600 DBG_ERROR( "Wrong Button" );
604 pOutSet
= new SfxItemSet( rSet
);
605 pOutSet
->Put( aZoomItem
);
607 // don't set attribute in case the whole viewlayout stuff is disabled:
608 if ( aViewLayoutFl
.IsEnabled() )
609 pOutSet
->Put( aViewLayoutItem
);
611 // Wert aus dem UserEdit "uber den Dialog hinaus merken
612 SfxObjectShell
* pSh
= SfxObjectShell::Current();
615 pSh
->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER
,
616 (UINT16
)aUserEdit
.GetValue() ) );
617 #endif /* !TEST_LAYOUT */
621 EndDialog( RET_CANCEL
);