Update ooo320-m1
[ooovba.git] / svx / source / cui / zoom.cxx
blob78fc77a3363d7c5ec071c0c828765409d707206d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: zoom.cxx,v $
10 * $Revision: 1.12 $
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
36 #endif
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>
46 #define _SVX_ZOOM_CXX
48 #include <svx/dialogs.hrc>
49 #include "zoom.hrc"
51 #include "zoom.hxx"
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>
59 #if ENABLE_LAYOUT
60 #undef SVX_RES
61 #define SVX_RES(x) #x
62 #undef SfxModalDialog
63 #define SfxModalDialog( parent, id ) Dialog( parent, "zoom.xml", id )
64 #endif /* ENABLE_LAYOUT */
66 // static ----------------------------------------------------------------
68 static USHORT pRanges[] =
70 SID_ATTR_ZOOM,
71 SID_ATTR_ZOOM,
75 #define SPECIAL_FACTOR ((USHORT)0xFFFF)
77 // class SvxZoomDialog ---------------------------------------------------
79 USHORT SvxZoomDialog::GetFactor() const
81 if ( a100Btn.IsChecked() )
82 return 100;
83 if ( aUserBtn.IsChecked() )
84 return (USHORT)aUserEdit.GetValue();
85 else
86 return SPECIAL_FACTOR;
89 // -----------------------------------------------------------------------
91 void SvxZoomDialog::SetFactor( USHORT nNewFactor, USHORT nBtnId )
93 aUserEdit.Disable();
95 if ( !nBtnId )
97 if ( nNewFactor == 100 )
99 a100Btn.Check();
100 a100Btn.GrabFocus();
102 else
104 aUserBtn.Check();
105 aUserEdit.Enable();
106 aUserEdit.SetValue( (long)nNewFactor );
107 aUserEdit.GrabFocus();
110 else
112 aUserEdit.SetValue( (long)nNewFactor );
114 if ( ZOOMBTN_OPTIMAL == nBtnId )
116 aOptimalBtn.Check();
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 )
136 switch ( nBtnId )
138 case ZOOMBTN_OPTIMAL: // Optimal-Button
139 aOptimalBtn.SetText( rNewTxt );
140 break;
142 case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
143 aPageWidthBtn.SetText( rNewTxt );
144 break;
146 case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
147 aWholePageBtn.SetText( rNewTxt );
148 break;
150 default:
151 DBG_ERROR( "wrong button number" );
155 // -----------------------------------------------------------------------
157 void SvxZoomDialog::HideButton( USHORT nBtnId )
159 switch ( nBtnId )
161 case ZOOMBTN_OPTIMAL: // Optimal-Button
162 aOptimalBtn.Hide();
163 break;
165 case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
166 aPageWidthBtn.Hide();
167 break;
169 case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
170 aWholePageBtn.Hide();
171 break;
173 default:
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 ) ),
222 rSet ( rCoreSet ),
223 pOutSet ( NULL ),
224 bModified ( FALSE )
227 #if ENABLE_LAYOUT
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 ) );
251 // Default-Werte
252 USHORT nValue = 100;
253 USHORT nMin = 10;
254 USHORT nMax = 1000;
256 // ggf. erst den alten Wert besorgen
257 const SfxUInt16Item* pOldUserItem = 0;
258 SfxObjectShell* pSh = SfxObjectShell::Current();
260 if ( pSh )
261 pOldUserItem = (const SfxUInt16Item*)pSh->GetItem( SID_ATTR_ZOOM_USER );
263 if ( pOldUserItem )
264 nValue = pOldUserItem->GetValue();
266 // UserEdit initialisieren
267 if ( nMin > nValue )
268 nMin = nValue;
269 if ( nMax < nValue )
270 nMax = nValue;
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();
285 USHORT nBtnId = 0;
287 switch ( eType )
289 case SVX_ZOOM_OPTIMAL:
290 nBtnId = ZOOMBTN_OPTIMAL;
291 break;
292 case SVX_ZOOM_PAGEWIDTH:
293 nBtnId = ZOOMBTN_PAGEWIDTH;
294 break;
295 case SVX_ZOOM_WHOLEPAGE:
296 nBtnId = ZOOMBTN_WHOLEPAGE;
297 break;
298 case SVX_ZOOM_PERCENT:
299 break;
300 case SVX_ZOOM_PAGEWIDTH_NOBORDER:
301 break;
304 if ( !(SVX_ZOOM_ENABLE_100 & nValSet) )
305 a100Btn.Disable();
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 );
314 else
316 const USHORT nZoom = ( (const SfxUInt16Item&)rItem ).GetValue();
317 SetFactor( nZoom );
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();
326 if ( 0 == nColumns )
328 aAutomaticBtn.Check();
329 aColumnsEdit.SetValue( 2 );
330 aColumnsEdit.Disable();
331 aBookModeChk.Disable();
333 else if ( 1 == nColumns)
335 aSingleBtn.Check();
336 aColumnsEdit.SetValue( 2 );
337 aColumnsEdit.Disable();
338 aBookModeChk.Disable();
340 else
342 aColumnsBtn.Check();
343 if ( !bBookMode )
345 aColumnsEdit.SetValue( nColumns );
346 if ( 0 != nColumns % 2 )
347 aBookModeChk.Disable();
349 else
351 aColumnsEdit.SetValue( nColumns );
352 aBookModeChk.Check();
356 else
358 // hide view layout related controls:
359 aViewLayoutFl.Disable();
360 aAutomaticBtn.Disable();
361 aSingleBtn.Disable();
362 aColumnsBtn.Disable();
363 aColumnsEdit.Disable();
364 aBookModeChk.Disable();
367 FreeResource();
370 // -----------------------------------------------------------------------
372 SvxZoomDialog::~SvxZoomDialog()
374 delete pOutSet;
375 pOutSet = 0;
378 // -----------------------------------------------------------------------
380 USHORT* SvxZoomDialog::GetRanges()
382 return pRanges;
385 // -----------------------------------------------------------------------
387 IMPL_LINK( SvxZoomDialog, UserHdl, RadioButton *, pBtn )
389 bModified |= TRUE;
391 if ( pBtn == &aUserBtn )
393 aUserEdit.Enable();
394 aUserEdit.GrabFocus();
396 else
397 aUserEdit.Disable();
398 return 0;
401 // -----------------------------------------------------------------------
403 IMPL_LINK( SvxZoomDialog, SpinHdl, MetricField *, EMPTYARG )
405 if ( !aUserBtn.IsChecked() )
406 return 0;
407 bModified |= TRUE;
408 return 0;
411 // -----------------------------------------------------------------------
413 IMPL_LINK( SvxZoomDialog, ViewLayoutUserHdl, RadioButton *, pBtn )
415 bModified |= TRUE;
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();
434 else
436 DBG_ERROR( "Wrong Button" );
437 return 0;
440 return 0;
443 // -----------------------------------------------------------------------
445 IMPL_LINK( SvxZoomDialog, ViewLayoutSpinHdl, MetricField *, pEdt )
447 if ( pEdt == &aColumnsEdit && !aColumnsBtn.IsChecked() )
448 return 0;
450 if ( 0 == aColumnsEdit.GetValue() % 2 )
451 aBookModeChk.Enable();
452 else
454 aBookModeChk.Check( sal_False );
455 aBookModeChk.Disable();
458 bModified |= TRUE;
460 return 0;
463 // -----------------------------------------------------------------------
465 IMPL_LINK( SvxZoomDialog, ViewLayoutCheckHdl, CheckBox *, pChk )
467 if ( pChk == &aBookModeChk && !aColumnsBtn.IsChecked() )
468 return 0;
470 bModified |= TRUE;
472 return 0;
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 );
497 else
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() );
516 else
518 DBG_ERROR( "Wrong Button" );
519 return 0;
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();
531 if ( pSh )
532 pSh->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER,
533 (UINT16)aUserEdit.GetValue() ) );
534 EndDialog( RET_OK );
536 else
537 EndDialog( RET_CANCEL );
538 return 0;