update dev300-m58
[ooovba.git] / toolkit / workben / layout / zoom.cxx
blob12dd6441a12a77fd0008b6dc6d8cd86f17d04369
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 #if !TEST_LAYOUT
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
38 #endif
40 // include ---------------------------------------------------------------
42 #if TEST_LAYOUT
43 #include <cstdio>
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>
51 #define _SVX_ZOOM_CXX
53 #include <svx/dialogs.hrc>
54 #if !TEST_LAYOUT
55 #include "zoom.hrc"
56 #endif /* !TEST_LAYOUT */
58 #include "zoom.hxx"
59 #if 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"
63 struct SvxZoomItem
65 void SetType( char const* s )
67 fputs( s, stderr );
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
81 bool IsBookMode()
83 return false;
85 USHORT GetValue()
87 return 0;
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
100 return 0;
102 SfxPoolItem* Clone( SfxItemPool* ) const
104 return 0;
106 #endif
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>
117 #if ENABLE_LAYOUT
118 #undef SVX_RES
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[] =
128 SID_ATTR_ZOOM,
129 SID_ATTR_ZOOM,
133 #define SPECIAL_FACTOR ((USHORT)0xFFFF)
135 // class SvxZoomDialog ---------------------------------------------------
137 USHORT SvxZoomDialog::GetFactor() const
139 if ( a100Btn.IsChecked() )
140 return 100;
141 if ( aUserBtn.IsChecked() )
142 return (USHORT)aUserEdit.GetValue();
143 else
144 return SPECIAL_FACTOR;
147 // -----------------------------------------------------------------------
149 void SvxZoomDialog::SetFactor( USHORT nNewFactor, USHORT nBtnId )
151 #if TEST_LAYOUT
152 printf ("\t\t set factor %d\n", (int)nNewFactor);
153 #endif /* !TEST_LAYOUT */
154 aUserEdit.Disable();
156 if ( !nBtnId )
158 if ( nNewFactor == 100 )
160 a100Btn.Check();
161 a100Btn.GrabFocus();
163 else
165 aUserBtn.Check();
166 aUserEdit.Enable();
167 aUserEdit.SetValue( (long)nNewFactor );
168 aUserEdit.GrabFocus();
171 else
173 aUserEdit.SetValue( (long)nNewFactor );
175 if ( ZOOMBTN_OPTIMAL == nBtnId )
177 aOptimalBtn.Check();
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 )
197 switch ( nBtnId )
199 case ZOOMBTN_OPTIMAL: // Optimal-Button
200 aOptimalBtn.SetText( rNewTxt );
201 break;
203 case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
204 aPageWidthBtn.SetText( rNewTxt );
205 break;
207 case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
208 aWholePageBtn.SetText( rNewTxt );
209 break;
211 default:
212 DBG_ERROR( "wrong button number" );
216 // -----------------------------------------------------------------------
218 void SvxZoomDialog::HideButton( USHORT nBtnId )
220 switch ( nBtnId )
222 case ZOOMBTN_OPTIMAL: // Optimal-Button
223 aOptimalBtn.Hide();
224 break;
226 case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
227 aPageWidthBtn.Hide();
228 break;
230 case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
231 aWholePageBtn.Hide();
232 break;
234 default:
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 // -----------------------------------------------------------------------
259 #if TEST_LAYOUT
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 ) ),
287 #if !TEST_LAYOUT
288 rSet ( rCoreSet ),
289 #endif /* !TEST_LAYOUT */
290 pOutSet ( NULL ),
291 bModified ( FALSE )
294 #if ENABLE_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 ) );
318 // Default-Werte
319 USHORT nValue = 100;
320 USHORT nMin = 10;
321 USHORT nMax = 1000;
323 #if !TEST_LAYOUT
324 // ggf. erst den alten Wert besorgen
325 const SfxUInt16Item* pOldUserItem = 0;
326 SfxObjectShell* pSh = SfxObjectShell::Current();
328 if ( pSh )
329 pOldUserItem = (const SfxUInt16Item*)pSh->GetItem( SID_ATTR_ZOOM_USER );
331 if ( pOldUserItem )
332 nValue = pOldUserItem->GetValue();
334 // UserEdit initialisieren
335 if ( nMin > nValue )
336 nMin = nValue;
337 if ( nMax < nValue )
338 nMax = nValue;
339 #endif /* !TEST_LAYOUT */
340 aUserEdit.SetMin( nMin );
341 aUserEdit.SetFirst( nMin );
342 aUserEdit.SetMax( nMax );
343 aUserEdit.SetLast( nMax );
344 aUserEdit.SetValue( nValue );
346 #if TEST_LAYOUT
347 USHORT nZoom = 100;
348 SetFactor( nZoom );
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();
358 USHORT nBtnId = 0;
360 switch ( eType )
362 case SVX_ZOOM_OPTIMAL:
363 nBtnId = ZOOMBTN_OPTIMAL;
364 break;
365 case SVX_ZOOM_PAGEWIDTH:
366 nBtnId = ZOOMBTN_PAGEWIDTH;
367 break;
368 case SVX_ZOOM_WHOLEPAGE:
369 nBtnId = ZOOMBTN_WHOLEPAGE;
370 break;
371 case SVX_ZOOM_PERCENT:
372 break;
373 case SVX_ZOOM_PAGEWIDTH_NOBORDER:
374 break;
377 if ( !(SVX_ZOOM_ENABLE_100 & nValSet) )
378 a100Btn.Disable();
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 );
387 else
389 const USHORT nZoom = ( (const SfxUInt16Item&)rItem ).GetValue();
390 SetFactor( nZoom );
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();
399 if ( 0 == nColumns )
401 aAutomaticBtn.Check();
402 aColumnsEdit.SetValue( 2 );
403 aColumnsEdit.Disable();
404 aBookModeChk.Disable();
406 else if ( 1 == nColumns)
408 aSingleBtn.Check();
409 aColumnsEdit.SetValue( 2 );
410 aColumnsEdit.Disable();
411 aBookModeChk.Disable();
413 else
415 aColumnsBtn.Check();
416 if ( !bBookMode )
418 aColumnsEdit.SetValue( nColumns );
419 if ( 0 != nColumns % 2 )
420 aBookModeChk.Disable();
422 else
424 aColumnsEdit.SetValue( nColumns );
425 aBookModeChk.Check();
429 else
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 */
441 FreeResource();
444 // -----------------------------------------------------------------------
446 SvxZoomDialog::~SvxZoomDialog()
448 delete pOutSet;
449 pOutSet = 0;
452 // -----------------------------------------------------------------------
454 USHORT* SvxZoomDialog::GetRanges()
456 return pRanges;
459 // -----------------------------------------------------------------------
461 IMPL_LINK( SvxZoomDialog, UserHdl, RadioButton *, pBtn )
463 #if TEST_LAYOUT
464 fprintf( stderr, "SvxZoomDialog::UserHdl\n" );
465 #endif /* TEST_LAYOUT */
466 bModified |= TRUE;
468 if ( pBtn == &aUserBtn )
470 aUserEdit.Enable();
471 aUserEdit.GrabFocus();
473 else
474 aUserEdit.Disable();
475 return 0;
478 // -----------------------------------------------------------------------
480 IMPL_LINK( SvxZoomDialog, SpinHdl, MetricField *, EMPTYARG )
482 if ( !aUserBtn.IsChecked() )
483 return 0;
484 bModified |= TRUE;
485 return 0;
488 // -----------------------------------------------------------------------
490 IMPL_LINK( SvxZoomDialog, ViewLayoutUserHdl, RadioButton *, pBtn )
492 bModified |= TRUE;
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();
511 else
513 DBG_ERROR( "Wrong Button" );
514 return 0;
517 return 0;
520 // -----------------------------------------------------------------------
522 IMPL_LINK( SvxZoomDialog, ViewLayoutSpinHdl, MetricField *, pEdt )
524 if ( pEdt == &aColumnsEdit && !aColumnsBtn.IsChecked() )
525 return 0;
527 if ( 0 == aColumnsEdit.GetValue() % 2 )
528 aBookModeChk.Enable();
529 else
531 aBookModeChk.Check( sal_False );
532 aBookModeChk.Disable();
535 bModified |= TRUE;
537 return 0;
540 // -----------------------------------------------------------------------
542 IMPL_LINK( SvxZoomDialog, ViewLayoutCheckHdl, CheckBox *, pChk )
544 if ( pChk == &aBookModeChk && !aColumnsBtn.IsChecked() )
545 return 0;
547 bModified |= TRUE;
549 return 0;
552 // -----------------------------------------------------------------------
554 IMPL_LINK( SvxZoomDialog, OKHdl, Button *, pBtn )
556 if ( bModified || &aOKBtn != pBtn )
558 #if TEST_LAYOUT
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 );
579 else
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() );
598 else
600 DBG_ERROR( "Wrong Button" );
601 return 0;
603 #if !TEST_LAYOUT
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();
614 if ( pSh )
615 pSh->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER,
616 (UINT16)aUserEdit.GetValue() ) );
617 #endif /* !TEST_LAYOUT */
618 EndDialog( RET_OK );
620 else
621 EndDialog( RET_CANCEL );
622 return 0;