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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
40 #include <tools/shl.hxx>
41 #include <svtools/itemset.hxx>
42 #include <svtools/itempool.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <vcl/msgbox.hxx>
48 #include <svx/dialogs.hrc>
52 #include <svx/zoomitem.hxx>
53 #include <svx/viewlayoutitem.hxx>
54 #include <svx/dialmgr.hxx>
55 #include "zoom_def.hxx"
57 #include <layout/layout-pre.hxx>
63 #define SfxModalDialog( parent, id ) Dialog( parent, "zoom.xml", id )
64 #endif /* ENABLE_LAYOUT */
66 // static ----------------------------------------------------------------
68 static USHORT pRanges
[] =
75 #define SPECIAL_FACTOR ((USHORT)0xFFFF)
77 // class SvxZoomDialog ---------------------------------------------------
79 USHORT
SvxZoomDialog::GetFactor() const
81 if ( a100Btn
.IsChecked() )
83 if ( aUserBtn
.IsChecked() )
84 return (USHORT
)aUserEdit
.GetValue();
86 return SPECIAL_FACTOR
;
89 // -----------------------------------------------------------------------
91 void SvxZoomDialog::SetFactor( USHORT nNewFactor
, USHORT nBtnId
)
97 if ( nNewFactor
== 100 )
106 aUserEdit
.SetValue( (long)nNewFactor
);
107 aUserEdit
.GrabFocus();
112 aUserEdit
.SetValue( (long)nNewFactor
);
114 if ( ZOOMBTN_OPTIMAL
== nBtnId
)
117 aOptimalBtn
.GrabFocus();
119 else if ( ZOOMBTN_PAGEWIDTH
== nBtnId
)
121 aPageWidthBtn
.Check();
122 aPageWidthBtn
.GrabFocus();
124 else if ( ZOOMBTN_WHOLEPAGE
== nBtnId
)
126 aWholePageBtn
.Check();
127 aWholePageBtn
.GrabFocus();
132 // -----------------------------------------------------------------------
134 void SvxZoomDialog::SetButtonText( USHORT nBtnId
, const String
& rNewTxt
)
138 case ZOOMBTN_OPTIMAL
: // Optimal-Button
139 aOptimalBtn
.SetText( rNewTxt
);
142 case ZOOMBTN_PAGEWIDTH
: // Seitenbreite-Button
143 aPageWidthBtn
.SetText( rNewTxt
);
146 case ZOOMBTN_WHOLEPAGE
: // Ganze Seite-Button
147 aWholePageBtn
.SetText( rNewTxt
);
151 DBG_ERROR( "wrong button number" );
155 // -----------------------------------------------------------------------
157 void SvxZoomDialog::HideButton( USHORT nBtnId
)
161 case ZOOMBTN_OPTIMAL
: // Optimal-Button
165 case ZOOMBTN_PAGEWIDTH
: // Seitenbreite-Button
166 aPageWidthBtn
.Hide();
169 case ZOOMBTN_WHOLEPAGE
: // Ganze Seite-Button
170 aWholePageBtn
.Hide();
174 DBG_ERROR( "Falsche Button-Nummer!!!" );
178 // -----------------------------------------------------------------------
180 void SvxZoomDialog::SetLimits( USHORT nMin
, USHORT nMax
)
182 DBG_ASSERT( nMin
< nMax
, "invalid limits" );
183 aUserEdit
.SetMin( nMin
);
184 aUserEdit
.SetFirst( nMin
);
185 aUserEdit
.SetMax( nMax
);
186 aUserEdit
.SetLast( nMax
);
189 // -----------------------------------------------------------------------
191 void SvxZoomDialog::SetSpinSize( USHORT nNewSpin
)
193 aUserEdit
.SetSpinSize( nNewSpin
);
196 // -----------------------------------------------------------------------
198 SvxZoomDialog::SvxZoomDialog( Window
* pParent
, const SfxItemSet
& rCoreSet
) :
200 SfxModalDialog( pParent
, SVX_RES( RID_SVXDLG_ZOOM
) ),
202 aZoomFl ( this, SVX_RES( FL_ZOOM
) ),
203 aOptimalBtn ( this, SVX_RES( BTN_OPTIMAL
) ),
204 aWholePageBtn ( this, SVX_RES( BTN_WHOLE_PAGE
) ),
205 aPageWidthBtn ( this, SVX_RES( BTN_PAGE_WIDTH
) ),
206 a100Btn ( this, SVX_RES( BTN_100
) ),
207 aUserBtn ( this, SVX_RES( BTN_USER
) ),
208 aUserEdit ( this, SVX_RES( ED_USER
) ),
210 aViewLayoutFl ( this, SVX_RES( FL_VIEWLAYOUT
) ),
211 aAutomaticBtn ( this, SVX_RES( BTN_AUTOMATIC
) ),
212 aSingleBtn ( this, SVX_RES( BTN_SINGLE
) ),
213 aColumnsBtn ( this, SVX_RES( BTN_COLUMNS
) ),
214 aColumnsEdit ( this, SVX_RES( ED_COLUMNS
) ),
215 aBookModeChk ( this, SVX_RES( CHK_BOOK
) ),
217 aBottomFl ( this, SVX_RES( FL_BOTTOM
) ),
218 aOKBtn ( this, SVX_RES( BTN_ZOOM_OK
) ),
219 aCancelBtn ( this, SVX_RES( BTN_ZOOM_CANCEL
) ),
220 aHelpBtn ( this, SVX_RES( BTN_ZOOM_HELP
) ),
228 SetHelpId (SID_ATTR_ZOOM
);
229 #endif /* ENABLE_LAYOUT */
230 Link aLink
= LINK( this, SvxZoomDialog
, UserHdl
);
231 a100Btn
.SetClickHdl( aLink
);
232 aOptimalBtn
.SetClickHdl( aLink
);
233 aPageWidthBtn
.SetClickHdl( aLink
);
234 aWholePageBtn
.SetClickHdl( aLink
);
235 aUserBtn
.SetClickHdl( aLink
);
237 Link aViewLayoutLink
= LINK( this, SvxZoomDialog
, ViewLayoutUserHdl
);
238 aAutomaticBtn
.SetClickHdl( aViewLayoutLink
);
239 aSingleBtn
.SetClickHdl( aViewLayoutLink
);
240 aColumnsBtn
.SetClickHdl( aViewLayoutLink
);
242 Link aViewLayoutSpinLink
= LINK( this, SvxZoomDialog
, ViewLayoutSpinHdl
);
243 aColumnsEdit
.SetModifyHdl( aViewLayoutSpinLink
);
245 Link aViewLayoutCheckLink
= LINK( this, SvxZoomDialog
, ViewLayoutCheckHdl
);
246 aBookModeChk
.SetClickHdl( aViewLayoutCheckLink
);
248 aOKBtn
.SetClickHdl( LINK( this, SvxZoomDialog
, OKHdl
) );
249 aUserEdit
.SetModifyHdl( LINK( this, SvxZoomDialog
, SpinHdl
) );
256 // ggf. erst den alten Wert besorgen
257 const SfxUInt16Item
* pOldUserItem
= 0;
258 SfxObjectShell
* pSh
= SfxObjectShell::Current();
261 pOldUserItem
= (const SfxUInt16Item
*)pSh
->GetItem( SID_ATTR_ZOOM_USER
);
264 nValue
= pOldUserItem
->GetValue();
266 // UserEdit initialisieren
271 aUserEdit
.SetMin( nMin
);
272 aUserEdit
.SetFirst( nMin
);
273 aUserEdit
.SetMax( nMax
);
274 aUserEdit
.SetLast( nMax
);
275 aUserEdit
.SetValue( nValue
);
277 const SfxPoolItem
& rItem
= rSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_ZOOM
) );
279 if ( rItem
.ISA(SvxZoomItem
) )
281 const SvxZoomItem
& rZoomItem
= (const SvxZoomItem
&)rItem
;
282 const USHORT nZoom
= rZoomItem
.GetValue();
283 const SvxZoomType eType
= rZoomItem
.GetType();
284 const USHORT nValSet
= rZoomItem
.GetValueSet();
289 case SVX_ZOOM_OPTIMAL
:
290 nBtnId
= ZOOMBTN_OPTIMAL
;
292 case SVX_ZOOM_PAGEWIDTH
:
293 nBtnId
= ZOOMBTN_PAGEWIDTH
;
295 case SVX_ZOOM_WHOLEPAGE
:
296 nBtnId
= ZOOMBTN_WHOLEPAGE
;
298 case SVX_ZOOM_PERCENT
:
300 case SVX_ZOOM_PAGEWIDTH_NOBORDER
:
304 if ( !(SVX_ZOOM_ENABLE_100
& nValSet
) )
306 if ( !(SVX_ZOOM_ENABLE_OPTIMAL
& nValSet
) )
307 aOptimalBtn
.Disable();
308 if ( !(SVX_ZOOM_ENABLE_PAGEWIDTH
& nValSet
) )
309 aPageWidthBtn
.Disable();
310 if ( !(SVX_ZOOM_ENABLE_WHOLEPAGE
& nValSet
) )
311 aWholePageBtn
.Disable();
312 SetFactor( nZoom
, nBtnId
);
316 const USHORT nZoom
= ( (const SfxUInt16Item
&)rItem
).GetValue();
320 const SfxPoolItem
* pViewLayoutItem
= 0;
321 if ( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_VIEWLAYOUT
, FALSE
, &pViewLayoutItem
) )
323 const USHORT nColumns
= static_cast<const SvxViewLayoutItem
*>(pViewLayoutItem
)->GetValue();
324 const bool bBookMode
= static_cast<const SvxViewLayoutItem
*>(pViewLayoutItem
)->IsBookMode();
328 aAutomaticBtn
.Check();
329 aColumnsEdit
.SetValue( 2 );
330 aColumnsEdit
.Disable();
331 aBookModeChk
.Disable();
333 else if ( 1 == nColumns
)
336 aColumnsEdit
.SetValue( 2 );
337 aColumnsEdit
.Disable();
338 aBookModeChk
.Disable();
345 aColumnsEdit
.SetValue( nColumns
);
346 if ( 0 != nColumns
% 2 )
347 aBookModeChk
.Disable();
351 aColumnsEdit
.SetValue( nColumns
);
352 aBookModeChk
.Check();
358 // hide view layout related controls:
359 aViewLayoutFl
.Disable();
360 aAutomaticBtn
.Disable();
361 aSingleBtn
.Disable();
362 aColumnsBtn
.Disable();
363 aColumnsEdit
.Disable();
364 aBookModeChk
.Disable();
370 // -----------------------------------------------------------------------
372 SvxZoomDialog::~SvxZoomDialog()
378 // -----------------------------------------------------------------------
380 USHORT
* SvxZoomDialog::GetRanges()
385 // -----------------------------------------------------------------------
387 IMPL_LINK( SvxZoomDialog
, UserHdl
, RadioButton
*, pBtn
)
391 if ( pBtn
== &aUserBtn
)
394 aUserEdit
.GrabFocus();
401 // -----------------------------------------------------------------------
403 IMPL_LINK( SvxZoomDialog
, SpinHdl
, MetricField
*, EMPTYARG
)
405 if ( !aUserBtn
.IsChecked() )
411 // -----------------------------------------------------------------------
413 IMPL_LINK( SvxZoomDialog
, ViewLayoutUserHdl
, RadioButton
*, pBtn
)
417 if ( pBtn
== &aAutomaticBtn
)
419 aColumnsEdit
.Disable();
420 aBookModeChk
.Disable();
422 else if ( pBtn
== &aSingleBtn
)
424 aColumnsEdit
.Disable();
425 aBookModeChk
.Disable();
427 else if ( pBtn
== &aColumnsBtn
)
429 aColumnsEdit
.Enable();
430 aColumnsEdit
.GrabFocus();
431 if ( 0 == aColumnsEdit
.GetValue() % 2 )
432 aBookModeChk
.Enable();
436 DBG_ERROR( "Wrong Button" );
443 // -----------------------------------------------------------------------
445 IMPL_LINK( SvxZoomDialog
, ViewLayoutSpinHdl
, MetricField
*, pEdt
)
447 if ( pEdt
== &aColumnsEdit
&& !aColumnsBtn
.IsChecked() )
450 if ( 0 == aColumnsEdit
.GetValue() % 2 )
451 aBookModeChk
.Enable();
454 aBookModeChk
.Check( sal_False
);
455 aBookModeChk
.Disable();
463 // -----------------------------------------------------------------------
465 IMPL_LINK( SvxZoomDialog
, ViewLayoutCheckHdl
, CheckBox
*, pChk
)
467 if ( pChk
== &aBookModeChk
&& !aColumnsBtn
.IsChecked() )
475 // -----------------------------------------------------------------------
477 IMPL_LINK( SvxZoomDialog
, OKHdl
, Button
*, pBtn
)
479 if ( bModified
|| &aOKBtn
!= pBtn
)
481 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, 0, rSet
.GetPool()->GetWhich( SID_ATTR_ZOOM
) );
482 SvxViewLayoutItem
aViewLayoutItem( 0, false, rSet
.GetPool()->GetWhich( SID_ATTR_VIEWLAYOUT
) );
484 if ( &aOKBtn
== pBtn
)
486 USHORT nFactor
= GetFactor();
488 if ( SPECIAL_FACTOR
== nFactor
)
490 if ( aOptimalBtn
.IsChecked() )
491 aZoomItem
.SetType( SVX_ZOOM_OPTIMAL
);
492 else if ( aPageWidthBtn
.IsChecked() )
493 aZoomItem
.SetType( SVX_ZOOM_PAGEWIDTH
);
494 else if ( aWholePageBtn
.IsChecked() )
495 aZoomItem
.SetType( SVX_ZOOM_WHOLEPAGE
);
498 aZoomItem
.SetValue( nFactor
);
500 if ( aAutomaticBtn
.IsChecked() )
502 aViewLayoutItem
.SetValue( 0 );
503 aViewLayoutItem
.SetBookMode( false );
505 if ( aSingleBtn
.IsChecked() )
507 aViewLayoutItem
.SetValue( 1 );
508 aViewLayoutItem
.SetBookMode( false );
510 else if ( aColumnsBtn
.IsChecked() )
512 aViewLayoutItem
.SetValue( static_cast<USHORT
>(aColumnsEdit
.GetValue()) );
513 aViewLayoutItem
.SetBookMode( aBookModeChk
.IsChecked() );
518 DBG_ERROR( "Wrong Button" );
521 pOutSet
= new SfxItemSet( rSet
);
522 pOutSet
->Put( aZoomItem
);
524 // don't set attribute in case the whole viewlayout stuff is disabled:
525 if ( aViewLayoutFl
.IsEnabled() )
526 pOutSet
->Put( aViewLayoutItem
);
528 // Wert aus dem UserEdit "uber den Dialog hinaus merken
529 SfxObjectShell
* pSh
= SfxObjectShell::Current();
532 pSh
->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER
,
533 (UINT16
)aUserEdit
.GetValue() ) );
537 EndDialog( RET_CANCEL
);