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