1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_svx.hxx"
31 #endif /* !TEST_LAYOUT */
33 #ifdef SVX_DLLIMPLEMENTATION
34 #undef SVX_DLLIMPLEMENTATION
37 // include ---------------------------------------------------------------
41 #endif /* TEST_LAYOUT */
42 #include <tools/shl.hxx>
43 #include <svtools/itemset.hxx>
44 #include <svtools/itempool.hxx>
45 #include <sfx2/objsh.hxx>
46 #include <vcl/msgbox.hxx>
50 #include <svx/dialogs.hrc>
53 #endif /* !TEST_LAYOUT */
57 #define SVX_ZOOM_OPTIMAL "Zoom optimal"
58 #define SVX_ZOOM_PAGEWIDTH "Zoom page width"
59 #define SVX_ZOOM_WHOLEPAGE "Zoom whole page"
62 void SetType( char const* s
)
67 void SetValue( int n
)
69 fprintf( stderr
, "Zoom factor: %d\n", int( n
) );
72 #define SfxPoolItem LAYOUT_SfxPoolItem
73 class LAYOUT_SfxPoolItem
76 struct SvxViewLayoutItem
: public LAYOUT_SfxPoolItem
87 void SetValue( int n
)
89 fprintf( stderr
, "Zoom factor: %d\n", int( n
) );
91 void SetBookMode( bool )
94 #if 0 // needed for real SfxPoolItem
95 int operator==( const SfxPoolItem
& ) const
99 SfxPoolItem
* Clone( SfxItemPool
* ) const
105 #else /* !TEST_LAYOUT */
106 #include <svx/zoomitem.hxx>
107 #include <svx/viewlayoutitem.hxx>
108 #include <svx/dialmgr.hxx>
109 #endif /* !TEST_LAYOUT */
110 #include "zoom_def.hxx"
112 #include <layout/layout-pre.hxx>
116 #define SVX_RES(x) #x
117 #undef SfxModalDialog
118 #define SfxModalDialog( parent, id ) Dialog( parent, "zoom.xml", id )
119 #endif /* ENABLE_LAYOUT */
121 // static ----------------------------------------------------------------
123 static USHORT pRanges
[] =
130 #define SPECIAL_FACTOR ((USHORT)0xFFFF)
132 // class SvxZoomDialog ---------------------------------------------------
134 USHORT
SvxZoomDialog::GetFactor() const
136 if ( a100Btn
.IsChecked() )
138 if ( aUserBtn
.IsChecked() )
139 return (USHORT
)aUserEdit
.GetValue();
141 return SPECIAL_FACTOR
;
144 // -----------------------------------------------------------------------
146 void SvxZoomDialog::SetFactor( USHORT nNewFactor
, USHORT nBtnId
)
149 printf ("\t\t set factor %d\n", (int)nNewFactor
);
150 #endif /* !TEST_LAYOUT */
155 if ( nNewFactor
== 100 )
164 aUserEdit
.SetValue( (long)nNewFactor
);
165 aUserEdit
.GrabFocus();
170 aUserEdit
.SetValue( (long)nNewFactor
);
172 if ( ZOOMBTN_OPTIMAL
== nBtnId
)
175 aOptimalBtn
.GrabFocus();
177 else if ( ZOOMBTN_PAGEWIDTH
== nBtnId
)
179 aPageWidthBtn
.Check();
180 aPageWidthBtn
.GrabFocus();
182 else if ( ZOOMBTN_WHOLEPAGE
== nBtnId
)
184 aWholePageBtn
.Check();
185 aWholePageBtn
.GrabFocus();
190 // -----------------------------------------------------------------------
192 void SvxZoomDialog::SetButtonText( USHORT nBtnId
, const String
& rNewTxt
)
196 case ZOOMBTN_OPTIMAL
: // Optimal-Button
197 aOptimalBtn
.SetText( rNewTxt
);
200 case ZOOMBTN_PAGEWIDTH
: // Seitenbreite-Button
201 aPageWidthBtn
.SetText( rNewTxt
);
204 case ZOOMBTN_WHOLEPAGE
: // Ganze Seite-Button
205 aWholePageBtn
.SetText( rNewTxt
);
209 DBG_ERROR( "wrong button number" );
213 // -----------------------------------------------------------------------
215 void SvxZoomDialog::HideButton( USHORT nBtnId
)
219 case ZOOMBTN_OPTIMAL
: // Optimal-Button
223 case ZOOMBTN_PAGEWIDTH
: // Seitenbreite-Button
224 aPageWidthBtn
.Hide();
227 case ZOOMBTN_WHOLEPAGE
: // Ganze Seite-Button
228 aWholePageBtn
.Hide();
232 DBG_ERROR( "Falsche Button-Nummer!!!" );
236 // -----------------------------------------------------------------------
238 void SvxZoomDialog::SetLimits( USHORT nMin
, USHORT nMax
)
240 DBG_ASSERT( nMin
< nMax
, "invalid limits" );
241 aUserEdit
.SetMin( nMin
);
242 aUserEdit
.SetFirst( nMin
);
243 aUserEdit
.SetMax( nMax
);
244 aUserEdit
.SetLast( nMax
);
247 // -----------------------------------------------------------------------
249 void SvxZoomDialog::SetSpinSize( USHORT nNewSpin
)
251 aUserEdit
.SetSpinSize( nNewSpin
);
254 // -----------------------------------------------------------------------
257 SvxZoomDialog::SvxZoomDialog( Window
* pParent
) :
258 #else /* !TEST_LAYOUT */
259 SvxZoomDialog::SvxZoomDialog( Window
* pParent
, const SfxItemSet
& rCoreSet
) :
260 #endif /* !TEST_LAYOUT */
262 SfxModalDialog( pParent
, SVX_RES( RID_SVXDLG_ZOOM
) ),
264 aZoomFl ( this, SVX_RES( FL_ZOOM
) ),
265 aOptimalBtn ( this, SVX_RES( BTN_OPTIMAL
) ),
266 aWholePageBtn ( this, SVX_RES( BTN_WHOLE_PAGE
) ),
267 aPageWidthBtn ( this, SVX_RES( BTN_PAGE_WIDTH
) ),
268 a100Btn ( this, SVX_RES( BTN_100
) ),
269 aUserBtn ( this, SVX_RES( BTN_USER
) ),
270 aUserEdit ( this, SVX_RES( ED_USER
) ),
272 aViewLayoutFl ( this, SVX_RES( FL_VIEWLAYOUT
) ),
273 aAutomaticBtn ( this, SVX_RES( BTN_AUTOMATIC
) ),
274 aSingleBtn ( this, SVX_RES( BTN_SINGLE
) ),
275 aColumnsBtn ( this, SVX_RES( BTN_COLUMNS
) ),
276 aColumnsEdit ( this, SVX_RES( ED_COLUMNS
) ),
277 aBookModeChk ( this, SVX_RES( CHK_BOOK
) ),
279 aBottomFl ( this, SVX_RES( FL_BOTTOM
) ),
280 aOKBtn ( this, SVX_RES( BTN_ZOOM_OK
) ),
281 aCancelBtn ( this, SVX_RES( BTN_ZOOM_CANCEL
) ),
282 aHelpBtn ( this, SVX_RES( BTN_ZOOM_HELP
) ),
286 #endif /* !TEST_LAYOUT */
292 SetHelpId (SID_ATTR_ZOOM
);
293 #endif /* ENABLE_LAYOUT */
294 Link aLink
= LINK( this, SvxZoomDialog
, UserHdl
);
295 a100Btn
.SetClickHdl( aLink
);
296 aOptimalBtn
.SetClickHdl( aLink
);
297 aPageWidthBtn
.SetClickHdl( aLink
);
298 aWholePageBtn
.SetClickHdl( aLink
);
299 aUserBtn
.SetClickHdl( aLink
);
301 Link aViewLayoutLink
= LINK( this, SvxZoomDialog
, ViewLayoutUserHdl
);
302 aAutomaticBtn
.SetClickHdl( aViewLayoutLink
);
303 aSingleBtn
.SetClickHdl( aViewLayoutLink
);
304 aColumnsBtn
.SetClickHdl( aViewLayoutLink
);
306 Link aViewLayoutSpinLink
= LINK( this, SvxZoomDialog
, ViewLayoutSpinHdl
);
307 aColumnsEdit
.SetModifyHdl( aViewLayoutSpinLink
);
309 Link aViewLayoutCheckLink
= LINK( this, SvxZoomDialog
, ViewLayoutCheckHdl
);
310 aBookModeChk
.SetClickHdl( aViewLayoutCheckLink
);
312 aOKBtn
.SetClickHdl( LINK( this, SvxZoomDialog
, OKHdl
) );
313 aUserEdit
.SetModifyHdl( LINK( this, SvxZoomDialog
, SpinHdl
) );
321 // ggf. erst den alten Wert besorgen
322 const SfxUInt16Item
* pOldUserItem
= 0;
323 SfxObjectShell
* pSh
= SfxObjectShell::Current();
326 pOldUserItem
= (const SfxUInt16Item
*)pSh
->GetItem( SID_ATTR_ZOOM_USER
);
329 nValue
= pOldUserItem
->GetValue();
331 // UserEdit initialisieren
336 #endif /* !TEST_LAYOUT */
337 aUserEdit
.SetMin( nMin
);
338 aUserEdit
.SetFirst( nMin
);
339 aUserEdit
.SetMax( nMax
);
340 aUserEdit
.SetLast( nMax
);
341 aUserEdit
.SetValue( nValue
);
346 #else /* !TEST_LAYOUT */
347 const SfxPoolItem
& rItem
= rSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_ZOOM
) );
349 if ( rItem
.ISA(SvxZoomItem
) )
351 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)rItem
;
352 const USHORT nZoom
= rZoomItem
.GetValue();
353 const SvxZoomType eType
= rZoomItem
.GetType();
354 const USHORT nValSet
= rZoomItem
.GetValueSet();
359 case SVX_ZOOM_OPTIMAL
:
360 nBtnId
= ZOOMBTN_OPTIMAL
;
362 case SVX_ZOOM_PAGEWIDTH
:
363 nBtnId
= ZOOMBTN_PAGEWIDTH
;
365 case SVX_ZOOM_WHOLEPAGE
:
366 nBtnId
= ZOOMBTN_WHOLEPAGE
;
368 case SVX_ZOOM_PERCENT
:
370 case SVX_ZOOM_PAGEWIDTH_NOBORDER
:
374 if ( !(SVX_ZOOM_ENABLE_100
& nValSet
) )
376 if ( !(SVX_ZOOM_ENABLE_OPTIMAL
& nValSet
) )
377 aOptimalBtn
.Disable();
378 if ( !(SVX_ZOOM_ENABLE_PAGEWIDTH
& nValSet
) )
379 aPageWidthBtn
.Disable();
380 if ( !(SVX_ZOOM_ENABLE_WHOLEPAGE
& nValSet
) )
381 aWholePageBtn
.Disable();
382 SetFactor( nZoom
, nBtnId
);
386 const USHORT nZoom
= ( (const SfxUInt16Item
&)rItem
).GetValue();
390 const SfxPoolItem
* pViewLayoutItem
= 0;
391 if ( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_VIEWLAYOUT
, FALSE
, &pViewLayoutItem
) )
393 const USHORT nColumns
= static_cast<const SvxViewLayoutItem
*>(pViewLayoutItem
)->GetValue();
394 const bool bBookMode
= static_cast<const SvxViewLayoutItem
*>(pViewLayoutItem
)->IsBookMode();
398 aAutomaticBtn
.Check();
399 aColumnsEdit
.SetValue( 2 );
400 aColumnsEdit
.Disable();
401 aBookModeChk
.Disable();
403 else if ( 1 == nColumns
)
406 aColumnsEdit
.SetValue( 2 );
407 aColumnsEdit
.Disable();
408 aBookModeChk
.Disable();
415 aColumnsEdit
.SetValue( nColumns
);
416 if ( 0 != nColumns
% 2 )
417 aBookModeChk
.Disable();
421 aColumnsEdit
.SetValue( nColumns
);
422 aBookModeChk
.Check();
428 // hide view layout related controls:
429 aViewLayoutFl
.Disable();
430 aAutomaticBtn
.Disable();
431 aSingleBtn
.Disable();
432 aColumnsBtn
.Disable();
433 aColumnsEdit
.Disable();
434 aBookModeChk
.Disable();
436 #endif /* !TEST_LAYOUT */
441 // -----------------------------------------------------------------------
443 SvxZoomDialog::~SvxZoomDialog()
449 // -----------------------------------------------------------------------
451 USHORT
* SvxZoomDialog::GetRanges()
456 // -----------------------------------------------------------------------
458 IMPL_LINK( SvxZoomDialog
, UserHdl
, RadioButton
*, pBtn
)
461 fprintf( stderr
, "SvxZoomDialog::UserHdl\n" );
462 #endif /* TEST_LAYOUT */
465 if ( pBtn
== &aUserBtn
)
468 aUserEdit
.GrabFocus();
475 // -----------------------------------------------------------------------
477 IMPL_LINK( SvxZoomDialog
, SpinHdl
, MetricField
*, EMPTYARG
)
479 if ( !aUserBtn
.IsChecked() )
485 // -----------------------------------------------------------------------
487 IMPL_LINK( SvxZoomDialog
, ViewLayoutUserHdl
, RadioButton
*, pBtn
)
491 if ( pBtn
== &aAutomaticBtn
)
493 aColumnsEdit
.Disable();
494 aBookModeChk
.Disable();
496 else if ( pBtn
== &aSingleBtn
)
498 aColumnsEdit
.Disable();
499 aBookModeChk
.Disable();
501 else if ( pBtn
== &aColumnsBtn
)
503 aColumnsEdit
.Enable();
504 aColumnsEdit
.GrabFocus();
505 if ( 0 == aColumnsEdit
.GetValue() % 2 )
506 aBookModeChk
.Enable();
510 DBG_ERROR( "Wrong Button" );
517 // -----------------------------------------------------------------------
519 IMPL_LINK( SvxZoomDialog
, ViewLayoutSpinHdl
, MetricField
*, pEdt
)
521 if ( pEdt
== &aColumnsEdit
&& !aColumnsBtn
.IsChecked() )
524 if ( 0 == aColumnsEdit
.GetValue() % 2 )
525 aBookModeChk
.Enable();
528 aBookModeChk
.Check( sal_False
);
529 aBookModeChk
.Disable();
537 // -----------------------------------------------------------------------
539 IMPL_LINK( SvxZoomDialog
, ViewLayoutCheckHdl
, CheckBox
*, pChk
)
541 if ( pChk
== &aBookModeChk
&& !aColumnsBtn
.IsChecked() )
549 // -----------------------------------------------------------------------
551 IMPL_LINK( SvxZoomDialog
, OKHdl
, Button
*, pBtn
)
553 if ( bModified
|| &aOKBtn
!= pBtn
)
556 SvxZoomItem aZoomItem
;
557 SvxViewLayoutItem aViewLayoutItem
;
558 #else /* !TEST_LAYOUT */
559 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, 0, rSet
.GetPool()->GetWhich( SID_ATTR_ZOOM
) );
560 SvxViewLayoutItem
aViewLayoutItem( 0, false, rSet
.GetPool()->GetWhich( SID_ATTR_VIEWLAYOUT
) );
561 #endif /* !TEST_LAYOUT */
563 if ( &aOKBtn
== pBtn
)
565 USHORT nFactor
= GetFactor();
567 if ( SPECIAL_FACTOR
== nFactor
)
569 if ( aOptimalBtn
.IsChecked() )
570 aZoomItem
.SetType( SVX_ZOOM_OPTIMAL
);
571 else if ( aPageWidthBtn
.IsChecked() )
572 aZoomItem
.SetType( SVX_ZOOM_PAGEWIDTH
);
573 else if ( aWholePageBtn
.IsChecked() )
574 aZoomItem
.SetType( SVX_ZOOM_WHOLEPAGE
);
577 aZoomItem
.SetValue( nFactor
);
579 if ( aAutomaticBtn
.IsChecked() )
581 aViewLayoutItem
.SetValue( 0 );
582 aViewLayoutItem
.SetBookMode( false );
584 if ( aSingleBtn
.IsChecked() )
586 aViewLayoutItem
.SetValue( 1 );
587 aViewLayoutItem
.SetBookMode( false );
589 else if ( aColumnsBtn
.IsChecked() )
591 aViewLayoutItem
.SetValue( static_cast<USHORT
>(aColumnsEdit
.GetValue()) );
592 aViewLayoutItem
.SetBookMode( aBookModeChk
.IsChecked() );
597 DBG_ERROR( "Wrong Button" );
601 pOutSet
= new SfxItemSet( rSet
);
602 pOutSet
->Put( aZoomItem
);
604 // don't set attribute in case the whole viewlayout stuff is disabled:
605 if ( aViewLayoutFl
.IsEnabled() )
606 pOutSet
->Put( aViewLayoutItem
);
608 // Wert aus dem UserEdit "uber den Dialog hinaus merken
609 SfxObjectShell
* pSh
= SfxObjectShell::Current();
612 pSh
->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER
,
613 (UINT16
)aUserEdit
.GetValue() ) );
614 #endif /* !TEST_LAYOUT */
618 EndDialog( RET_CANCEL
);