xref: /aoo4110/main/cui/source/dialogs/zoom.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 #include <tools/shl.hxx>
30 #include <svl/itemset.hxx>
31 #include <svl/itempool.hxx>
32 #include <sfx2/objsh.hxx>
33 #include <vcl/msgbox.hxx>
34 
35 #define _SVX_ZOOM_CXX
36 
37 #include <cuires.hrc>
38 #include "zoom.hrc"
39 
40 #include "zoom.hxx"
41 #include <svx/zoomitem.hxx>
42 #include <svx/viewlayoutitem.hxx>
43 #include <dialmgr.hxx>
44 #include <svx/zoom_def.hxx>
45 #include <svx/dialogs.hrc>	// RID_SVXDLG_ZOOM
46 #include <layout/layout-pre.hxx>
47 
48 #if ENABLE_LAYOUT
49 #undef CUI_RES
50 #define CUI_RES(x) #x
51 #undef SfxModalDialog
52 #define SfxModalDialog( parent, id ) Dialog( parent, "zoom.xml", id )
53 #endif /* ENABLE_LAYOUT */
54 
55 // static ----------------------------------------------------------------
56 
57 #define SPECIAL_FACTOR	((sal_uInt16)0xFFFF)
58 
59 // class SvxZoomDialog ---------------------------------------------------
60 
GetFactor() const61 sal_uInt16 SvxZoomDialog::GetFactor() const
62 {
63     if ( a100Btn.IsChecked() )
64 		return 100;
65     if ( aUserBtn.IsChecked() )
66 		return (sal_uInt16)aUserEdit.GetValue();
67 	else
68 		return SPECIAL_FACTOR;
69 }
70 
71 // -----------------------------------------------------------------------
72 
SetFactor(sal_uInt16 nNewFactor,sal_uInt16 nBtnId)73 void SvxZoomDialog::SetFactor( sal_uInt16 nNewFactor, sal_uInt16 nBtnId )
74 {
75 	aUserEdit.Disable();
76 
77 	if ( !nBtnId )
78 	{
79         if ( nNewFactor == 100 )
80 		{
81 			a100Btn.Check();
82 			a100Btn.GrabFocus();
83 		}
84         else
85 		{
86 			aUserBtn.Check();
87 			aUserEdit.Enable();
88 			aUserEdit.SetValue( (long)nNewFactor );
89 			aUserEdit.GrabFocus();
90 		}
91 	}
92 	else
93 	{
94 		aUserEdit.SetValue( (long)nNewFactor );
95 
96 		if ( ZOOMBTN_OPTIMAL == nBtnId )
97 		{
98 			aOptimalBtn.Check();
99 			aOptimalBtn.GrabFocus();
100 		}
101 		else if ( ZOOMBTN_PAGEWIDTH == nBtnId )
102 		{
103 			aPageWidthBtn.Check();
104 			aPageWidthBtn.GrabFocus();
105 		}
106 		else if ( ZOOMBTN_WHOLEPAGE == nBtnId )
107 		{
108 			aWholePageBtn.Check();
109 			aWholePageBtn.GrabFocus();
110 		}
111 	}
112 }
113 
114 // -----------------------------------------------------------------------
115 
HideButton(sal_uInt16 nBtnId)116 void SvxZoomDialog::HideButton( sal_uInt16 nBtnId )
117 {
118 	switch ( nBtnId )
119 	{
120 		case ZOOMBTN_OPTIMAL: // Optimal-Button
121 			aOptimalBtn.Hide();
122 			break;
123 
124 		case ZOOMBTN_PAGEWIDTH: // Seitenbreite-Button
125 			aPageWidthBtn.Hide();
126 			break;
127 
128 		case ZOOMBTN_WHOLEPAGE: // Ganze Seite-Button
129 			aWholePageBtn.Hide();
130 			break;
131 
132 		default:
133 			DBG_ERROR( "Falsche Button-Nummer!!!" );
134 	}
135 }
136 
137 // -----------------------------------------------------------------------
138 
SetLimits(sal_uInt16 nMin,sal_uInt16 nMax)139 void SvxZoomDialog::SetLimits( sal_uInt16 nMin, sal_uInt16 nMax )
140 {
141 	DBG_ASSERT( nMin < nMax, "invalid limits" );
142     aUserEdit.SetMin( nMin );
143 	aUserEdit.SetFirst( nMin );
144     aUserEdit.SetMax( nMax );
145 	aUserEdit.SetLast( nMax );
146 }
147 
148 // -----------------------------------------------------------------------
149 
SvxZoomDialog(Window * pParent,const SfxItemSet & rCoreSet)150 SvxZoomDialog::SvxZoomDialog( Window* pParent, const SfxItemSet& rCoreSet ) :
151 
152 	SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_ZOOM ) ),
153 
154     aZoomFl         ( this, CUI_RES( FL_ZOOM ) ),
155     aOptimalBtn     ( this, CUI_RES( BTN_OPTIMAL ) ),
156     aWholePageBtn   ( this, CUI_RES( BTN_WHOLE_PAGE ) ),
157     aPageWidthBtn   ( this, CUI_RES( BTN_PAGE_WIDTH ) ),
158     a100Btn         ( this, CUI_RES( BTN_100 ) ),
159     aUserBtn        ( this, CUI_RES( BTN_USER ) ),
160 	aUserEdit       ( this, CUI_RES( ED_USER ) ),
161 
162     aViewLayoutFl   ( this, CUI_RES( FL_VIEWLAYOUT ) ),
163     aAutomaticBtn   ( this, CUI_RES( BTN_AUTOMATIC ) ),
164     aSingleBtn      ( this, CUI_RES( BTN_SINGLE ) ),
165     aColumnsBtn     ( this, CUI_RES( BTN_COLUMNS ) ),
166     aColumnsEdit    ( this, CUI_RES( ED_COLUMNS ) ),
167     aBookModeChk    ( this, CUI_RES( CHK_BOOK ) ),
168 
169     aBottomFl       ( this, CUI_RES( FL_BOTTOM ) ),
170     aOKBtn          ( this, CUI_RES( BTN_ZOOM_OK ) ),
171 	aCancelBtn      ( this, CUI_RES( BTN_ZOOM_CANCEL ) ),
172 	aHelpBtn	    ( this, CUI_RES( BTN_ZOOM_HELP ) ),
173 
174 	rSet		( rCoreSet ),
175 	pOutSet     ( NULL ),
176 	bModified	( sal_False )
177 
178 {
179 #if ENABLE_LAYOUT
180     SetHelpId (".uno:Zoom");
181 #endif /* ENABLE_LAYOUT */
182 	Link aLink = LINK( this, SvxZoomDialog, UserHdl );
183     a100Btn.SetClickHdl( aLink );
184     aOptimalBtn.SetClickHdl( aLink );
185 	aPageWidthBtn.SetClickHdl( aLink );
186 	aWholePageBtn.SetClickHdl( aLink );
187 	aUserBtn.SetClickHdl( aLink );
188 
189     Link aViewLayoutLink = LINK( this, SvxZoomDialog, ViewLayoutUserHdl );
190     aAutomaticBtn.SetClickHdl( aViewLayoutLink );
191     aSingleBtn.SetClickHdl( aViewLayoutLink );
192     aColumnsBtn.SetClickHdl( aViewLayoutLink );
193 
194     Link aViewLayoutSpinLink = LINK( this, SvxZoomDialog, ViewLayoutSpinHdl );
195     aColumnsEdit.SetModifyHdl( aViewLayoutSpinLink );
196 
197     Link aViewLayoutCheckLink = LINK( this, SvxZoomDialog, ViewLayoutCheckHdl );
198     aBookModeChk.SetClickHdl( aViewLayoutCheckLink );
199 
200     aOKBtn.SetClickHdl( LINK( this, SvxZoomDialog, OKHdl ) );
201 	aUserEdit.SetModifyHdl( LINK( this, SvxZoomDialog, SpinHdl ) );
202 
203 	// Default-Werte
204 	sal_uInt16 nValue = 100;
205 	sal_uInt16 nMin = 10;
206 	sal_uInt16 nMax = 1000;
207 
208 	// ggf. erst den alten Wert besorgen
209 	const SfxUInt16Item* pOldUserItem = 0;
210 	SfxObjectShell* pSh = SfxObjectShell::Current();
211 
212 	if ( pSh )
213 		pOldUserItem = (const SfxUInt16Item*)pSh->GetItem( SID_ATTR_ZOOM_USER );
214 
215 	if ( pOldUserItem )
216 		nValue = pOldUserItem->GetValue();
217 
218 	// UserEdit initialisieren
219 	if ( nMin > nValue )
220 		nMin = nValue;
221 	if ( nMax < nValue )
222 		nMax = nValue;
223     aUserEdit.SetMin( nMin );
224 	aUserEdit.SetFirst( nMin );
225     aUserEdit.SetMax( nMax );
226 	aUserEdit.SetLast( nMax );
227 	aUserEdit.SetValue( nValue );
228 
229 	aUserEdit.SetAccessibleRelationLabeledBy( &aUserBtn );
230 	aUserEdit.SetAccessibleName(aUserBtn.GetText());
231 	aColumnsEdit.SetAccessibleRelationLabeledBy(&aColumnsBtn);
232 	aColumnsEdit.SetAccessibleName(aColumnsBtn.GetText());
233 	aColumnsEdit.SetAccessibleRelationMemberOf(&aColumnsBtn);
234     aBookModeChk.SetAccessibleRelationLabeledBy(&aColumnsBtn);
235 	aBookModeChk.SetAccessibleRelationMemberOf(&aColumnsBtn);
236 
237 	const SfxPoolItem& rItem = rSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_ZOOM ) );
238 
239 	if ( rItem.ISA(SvxZoomItem) )
240 	{
241 		const SvxZoomItem& rZoomItem = (const SvxZoomItem&)rItem;
242         const sal_uInt16 nZoom = rZoomItem.GetValue();
243         const SvxZoomType eType = rZoomItem.GetType();
244         const sal_uInt16 nValSet = rZoomItem.GetValueSet();
245 		sal_uInt16 nBtnId = 0;
246 
247 		switch ( eType )
248 		{
249 			case SVX_ZOOM_OPTIMAL:
250 				nBtnId = ZOOMBTN_OPTIMAL;
251 				break;
252 			case SVX_ZOOM_PAGEWIDTH:
253 				nBtnId = ZOOMBTN_PAGEWIDTH;
254 				break;
255 			case SVX_ZOOM_WHOLEPAGE:
256 				nBtnId = ZOOMBTN_WHOLEPAGE;
257 				break;
258 			case SVX_ZOOM_PERCENT:
259 				break;
260             case SVX_ZOOM_PAGEWIDTH_NOBORDER:
261                 break;
262 		}
263 
264         if ( !(SVX_ZOOM_ENABLE_100 & nValSet) )
265 			a100Btn.Disable();
266         if ( !(SVX_ZOOM_ENABLE_OPTIMAL & nValSet) )
267 			aOptimalBtn.Disable();
268 		if ( !(SVX_ZOOM_ENABLE_PAGEWIDTH & nValSet) )
269 			aPageWidthBtn.Disable();
270 		if ( !(SVX_ZOOM_ENABLE_WHOLEPAGE & nValSet) )
271 			aWholePageBtn.Disable();
272         SetFactor( nZoom, nBtnId );
273 	}
274 	else
275 	{
276         const sal_uInt16 nZoom = ( (const SfxUInt16Item&)rItem ).GetValue();
277         SetFactor( nZoom );
278 	}
279 
280     const SfxPoolItem* pViewLayoutItem = 0;
281     if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_VIEWLAYOUT, sal_False, &pViewLayoutItem ) )
282     {
283         const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>(pViewLayoutItem)->GetValue();
284         const bool bBookMode  = static_cast<const SvxViewLayoutItem*>(pViewLayoutItem)->IsBookMode();
285 
286         if ( 0 == nColumns )
287         {
288             aAutomaticBtn.Check();
289             aColumnsEdit.SetValue( 2 );
290             aColumnsEdit.Disable();
291             aBookModeChk.Disable();
292         }
293         else if ( 1 == nColumns)
294         {
295             aSingleBtn.Check();
296             aColumnsEdit.SetValue( 2 );
297             aColumnsEdit.Disable();
298             aBookModeChk.Disable();
299         }
300         else
301         {
302             aColumnsBtn.Check();
303             if ( !bBookMode )
304             {
305                 aColumnsEdit.SetValue( nColumns );
306                 if ( 0 != nColumns % 2 )
307                     aBookModeChk.Disable();
308             }
309             else
310             {
311                 aColumnsEdit.SetValue( nColumns );
312                 aBookModeChk.Check();
313             }
314         }
315     }
316     else
317     {
318         // hide view layout related controls:
319         aViewLayoutFl.Disable();
320         aAutomaticBtn.Disable();
321         aSingleBtn.Disable();
322         aColumnsBtn.Disable();
323         aColumnsEdit.Disable();
324         aBookModeChk.Disable();
325     }
326 
327 	FreeResource();
328 }
329 
330 // -----------------------------------------------------------------------
331 
~SvxZoomDialog()332 SvxZoomDialog::~SvxZoomDialog()
333 {
334 	delete pOutSet;
335 	pOutSet = 0;
336 }
337 
338 // -----------------------------------------------------------------------
339 
IMPL_LINK(SvxZoomDialog,UserHdl,RadioButton *,pBtn)340 IMPL_LINK( SvxZoomDialog, UserHdl, RadioButton *, pBtn )
341 {
342 	bModified |= sal_True;
343 
344 	if ( pBtn == &aUserBtn )
345 	{
346 		aUserEdit.Enable();
347 		aUserEdit.GrabFocus();
348 	}
349 	else
350 		aUserEdit.Disable();
351 	return 0;
352 }
353 
354 // -----------------------------------------------------------------------
355 
IMPL_LINK(SvxZoomDialog,SpinHdl,MetricField *,EMPTYARG)356 IMPL_LINK( SvxZoomDialog, SpinHdl, MetricField *, EMPTYARG )
357 {
358 	if ( !aUserBtn.IsChecked() )
359 		return 0;
360 	bModified |= sal_True;
361 	return 0;
362 }
363 
364 // -----------------------------------------------------------------------
365 
IMPL_LINK(SvxZoomDialog,ViewLayoutUserHdl,RadioButton *,pBtn)366 IMPL_LINK( SvxZoomDialog, ViewLayoutUserHdl, RadioButton *, pBtn )
367 {
368     bModified |= sal_True;
369 
370     if ( pBtn == &aAutomaticBtn )
371     {
372         aColumnsEdit.Disable();
373         aBookModeChk.Disable();
374     }
375     else if ( pBtn == &aSingleBtn )
376     {
377         aColumnsEdit.Disable();
378         aBookModeChk.Disable();
379     }
380     else if ( pBtn == &aColumnsBtn )
381     {
382         aColumnsEdit.Enable();
383         aColumnsEdit.GrabFocus();
384         if ( 0 == aColumnsEdit.GetValue() % 2 )
385             aBookModeChk.Enable();
386     }
387     else
388     {
389         DBG_ERROR( "Wrong Button" );
390         return 0;
391     }
392 
393     return 0;
394 }
395 
396 // -----------------------------------------------------------------------
397 
IMPL_LINK(SvxZoomDialog,ViewLayoutSpinHdl,MetricField *,pEdt)398 IMPL_LINK( SvxZoomDialog, ViewLayoutSpinHdl, MetricField *, pEdt )
399 {
400     if ( pEdt == &aColumnsEdit && !aColumnsBtn.IsChecked() )
401         return 0;
402 
403     if ( 0 == aColumnsEdit.GetValue() % 2 )
404         aBookModeChk.Enable();
405     else
406     {
407         aBookModeChk.Check( sal_False );
408         aBookModeChk.Disable();
409     }
410 
411     bModified |= sal_True;
412 
413     return 0;
414 }
415 
416 // -----------------------------------------------------------------------
417 
IMPL_LINK(SvxZoomDialog,ViewLayoutCheckHdl,CheckBox *,pChk)418 IMPL_LINK( SvxZoomDialog, ViewLayoutCheckHdl, CheckBox *, pChk )
419 {
420     if ( pChk == &aBookModeChk && !aColumnsBtn.IsChecked() )
421         return 0;
422 
423     bModified |= sal_True;
424 
425     return 0;
426 }
427 
428 // -----------------------------------------------------------------------
429 
IMPL_LINK(SvxZoomDialog,OKHdl,Button *,pBtn)430 IMPL_LINK( SvxZoomDialog, OKHdl, Button *, pBtn )
431 {
432 	if ( bModified || &aOKBtn != pBtn )
433 	{
434         SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, 0, rSet.GetPool()->GetWhich( SID_ATTR_ZOOM ) );
435         SvxViewLayoutItem aViewLayoutItem( 0, false, rSet.GetPool()->GetWhich( SID_ATTR_VIEWLAYOUT ) );
436 
437 		if ( &aOKBtn == pBtn )
438 		{
439 			sal_uInt16 nFactor = GetFactor();
440 
441 			if ( SPECIAL_FACTOR == nFactor )
442 			{
443 				if ( aOptimalBtn.IsChecked() )
444                     aZoomItem.SetType( SVX_ZOOM_OPTIMAL );
445 				else if ( aPageWidthBtn.IsChecked() )
446                     aZoomItem.SetType( SVX_ZOOM_PAGEWIDTH );
447 				else if ( aWholePageBtn.IsChecked() )
448                     aZoomItem.SetType( SVX_ZOOM_WHOLEPAGE );
449 			}
450 			else
451                 aZoomItem.SetValue( nFactor );
452 
453             if ( aAutomaticBtn.IsChecked() )
454             {
455                 aViewLayoutItem.SetValue( 0 );
456                 aViewLayoutItem.SetBookMode( false );
457             }
458             if ( aSingleBtn.IsChecked() )
459             {
460                 aViewLayoutItem.SetValue( 1 );
461                 aViewLayoutItem.SetBookMode( false );
462             }
463             else if ( aColumnsBtn.IsChecked() )
464             {
465                 aViewLayoutItem.SetValue( static_cast<sal_uInt16>(aColumnsEdit.GetValue()) );
466                 aViewLayoutItem.SetBookMode( aBookModeChk.IsChecked() );
467             }
468         }
469 		else
470 		{
471 			DBG_ERROR( "Wrong Button" );
472 			return 0;
473 		}
474 		pOutSet = new SfxItemSet( rSet );
475         pOutSet->Put( aZoomItem );
476 
477         // don't set attribute in case the whole viewlayout stuff is disabled:
478         if ( aViewLayoutFl.IsEnabled() )
479             pOutSet->Put( aViewLayoutItem );
480 
481 		// Wert aus dem UserEdit "uber den Dialog hinaus merken
482 		SfxObjectShell* pSh = SfxObjectShell::Current();
483 
484 		if ( pSh )
485 			pSh->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER,
486 										 (sal_uInt16)aUserEdit.GetValue() ) );
487 		EndDialog( RET_OK );
488 	}
489 	else
490 		EndDialog( RET_CANCEL );
491 	return 0;
492 }
493 
494 
495