xref: /aoo42x/main/sd/source/ui/dlg/tpoption.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 
35 
36 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/frame/XDesktop.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/container/XEnumerationAccess.hpp>
41 #include <comphelper/processfactory.hxx>
42 #include <com/sun/star/uno/Exception.hpp>
43 #include <sfx2/module.hxx>
44 #include <sfx2/app.hxx>
45 #include <svx/svxids.hrc>
46 #include <svx/dialogs.hrc>
47 #include <svx/strarray.hxx>
48 #include <svx/dlgutil.hxx>
49 #include <vcl/msgbox.hxx>
50 
51 #include "sdattr.hxx"
52 #include "sdresid.hxx"
53 #include "optsitem.hxx"
54 #include "tpoption.hrc"
55 #include "tpoption.hxx"
56 #include "strings.hrc"
57 #include "app.hrc"
58 #include <svl/intitem.hxx>
59 #include <sfx2/request.hxx>
60 #define DLGWIN this->GetParent()->GetParent()
61 
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::uno;
64 
65 /*************************************************************************
66 |*
67 |*	TabPage zum Einstellen der Fang-Optionen
68 |*
69 \************************************************************************/
70 
71 SdTpOptionsSnap::SdTpOptionsSnap( Window* pParent, const SfxItemSet& rInAttrs  ) :
72         SvxGridTabPage(pParent, rInAttrs)
73 {
74     aGrpSnap.Show();
75     aCbxSnapHelplines.Show();
76     aCbxSnapBorder.Show();
77     aCbxSnapFrame.Show();
78     aCbxSnapPoints.Show();
79     aFtSnapArea.Show();
80     aMtrFldSnapArea.Show();
81     aGrpOrtho.Show();
82     aCbxOrtho.Show();
83     aCbxBigOrtho.Show();
84     aCbxRotate.Show();
85     aMtrFldAngle.Show();
86     aFtBezAngle.Show();
87     aMtrFldBezAngle.Show();
88     aSeparatorFL.Show();
89 }
90 
91 // -----------------------------------------------------------------------
92 
93 SdTpOptionsSnap::~SdTpOptionsSnap()
94 {
95 }
96 
97 // -----------------------------------------------------------------------
98 
99 sal_Bool SdTpOptionsSnap::FillItemSet( SfxItemSet& rAttrs )
100 {
101     SvxGridTabPage::FillItemSet(rAttrs);
102     SdOptionsSnapItem* pOptsItem = NULL;
103 //    if(SFX_ITEM_SET != rAttrs.GetItemState( ATTR_OPTIONS_SNAP, sal_False, (const SfxPoolItem**)&pOptsItem ))
104 //        pExampleSet->GetItemState( ATTR_OPTIONS_SNAP, sal_False, (const SfxPoolItem**)&pOptsItem );
105 
106 	SdOptionsSnapItem aOptsItem( ATTR_OPTIONS_SNAP );
107 
108 	aOptsItem.GetOptionsSnap().SetSnapHelplines( aCbxSnapHelplines.IsChecked() );
109 	aOptsItem.GetOptionsSnap().SetSnapBorder( aCbxSnapBorder.IsChecked() );
110 	aOptsItem.GetOptionsSnap().SetSnapFrame( aCbxSnapFrame.IsChecked() );
111 	aOptsItem.GetOptionsSnap().SetSnapPoints( aCbxSnapPoints.IsChecked() );
112 	aOptsItem.GetOptionsSnap().SetOrtho( aCbxOrtho.IsChecked() );
113 	aOptsItem.GetOptionsSnap().SetBigOrtho( aCbxBigOrtho.IsChecked() );
114 	aOptsItem.GetOptionsSnap().SetRotate( aCbxRotate.IsChecked() );
115 	aOptsItem.GetOptionsSnap().SetSnapArea( (sal_Int16) aMtrFldSnapArea.GetValue() );
116 	aOptsItem.GetOptionsSnap().SetAngle( (sal_Int16) aMtrFldAngle.GetValue() );
117 	aOptsItem.GetOptionsSnap().SetEliminatePolyPointLimitAngle( (sal_Int16) aMtrFldBezAngle.GetValue() );
118 
119 	if( pOptsItem == NULL || !(aOptsItem == *pOptsItem) )
120 		rAttrs.Put( aOptsItem );
121 
122 	// Evtl. vorhandenes GridItem wird geholt, um nicht versehentlich
123 	// irgendwelche Standardwerte einzustellen
124 	return( sal_True );
125 }
126 
127 // -----------------------------------------------------------------------
128 
129 void SdTpOptionsSnap::Reset( const SfxItemSet& rAttrs )
130 {
131     SvxGridTabPage::Reset(rAttrs);
132 
133 	SdOptionsSnapItem aOptsItem( (const SdOptionsSnapItem&) rAttrs.
134 						Get( ATTR_OPTIONS_SNAP ) );
135 
136 	aCbxSnapHelplines.Check( aOptsItem.GetOptionsSnap().IsSnapHelplines() );
137 	aCbxSnapBorder.Check( aOptsItem.GetOptionsSnap().IsSnapBorder() );
138 	aCbxSnapFrame.Check( aOptsItem.GetOptionsSnap().IsSnapFrame() );
139 	aCbxSnapPoints.Check( aOptsItem.GetOptionsSnap().IsSnapPoints() );
140 	aCbxOrtho.Check( aOptsItem.GetOptionsSnap().IsOrtho() );
141 	aCbxBigOrtho.Check( aOptsItem.GetOptionsSnap().IsBigOrtho() );
142 	aCbxRotate.Check( aOptsItem.GetOptionsSnap().IsRotate() );
143 	aMtrFldSnapArea.SetValue( aOptsItem.GetOptionsSnap().GetSnapArea() );
144 	aMtrFldAngle.SetValue( aOptsItem.GetOptionsSnap().GetAngle() );
145 	aMtrFldBezAngle.SetValue( aOptsItem.GetOptionsSnap().GetEliminatePolyPointLimitAngle() );
146 
147     aCbxRotate.GetClickHdl().Call(0);
148 }
149 
150 // -----------------------------------------------------------------------
151 
152 SfxTabPage* SdTpOptionsSnap::Create( Window* pWindow,
153 				const SfxItemSet& rAttrs )
154 {
155 	return( new SdTpOptionsSnap( pWindow, rAttrs ) );
156 }
157 
158 /*************************************************************************
159 |*
160 |*	TabPage zum Einstellen der Inhalte-Optionen
161 |*
162 \************************************************************************/
163 
164 SdTpOptionsContents::SdTpOptionsContents( Window* pParent, const SfxItemSet& rInAttrs  ) :
165 		SfxTabPage          ( pParent, SdResId( TP_OPTIONS_CONTENTS ), rInAttrs ),
166         aGrpDisplay         ( this, SdResId( GRP_DISPLAY ) ),
167 		aCbxRuler           ( this, SdResId( CBX_RULER ) ),
168 		aCbxDragStripes     ( this, SdResId( CBX_HELPLINES ) ),
169 		aCbxHandlesBezier   ( this, SdResId( CBX_HANDLES_BEZIER ) ),
170 		aCbxMoveOutline     ( this, SdResId( CBX_MOVE_OUTLINE ) )
171 {
172 	FreeResource();
173 }
174 
175 // -----------------------------------------------------------------------
176 
177 SdTpOptionsContents::~SdTpOptionsContents()
178 {
179 }
180 
181 // -----------------------------------------------------------------------
182 
183 sal_Bool SdTpOptionsContents::FillItemSet( SfxItemSet& rAttrs )
184 {
185 	sal_Bool bModified = sal_False;
186 
187     if( aCbxRuler.GetSavedValue()           != aCbxRuler.IsChecked() ||
188 		aCbxMoveOutline.GetSavedValue()		!= aCbxMoveOutline.IsChecked() ||
189 		aCbxDragStripes.GetSavedValue()		!= aCbxDragStripes.IsChecked() ||
190 		//aCbxHelplines.GetSavedValue()		!= aCbxHelplines.IsChecked() ||
191 		aCbxHandlesBezier.GetSavedValue()	!= aCbxHandlesBezier.IsChecked() )
192 	{
193         SdOptionsLayoutItem aOptsItem( ATTR_OPTIONS_LAYOUT );
194 
195         aOptsItem.GetOptionsLayout().SetRulerVisible( aCbxRuler.IsChecked() );
196         aOptsItem.GetOptionsLayout().SetMoveOutline( aCbxMoveOutline.IsChecked() );
197         aOptsItem.GetOptionsLayout().SetDragStripes( aCbxDragStripes.IsChecked() );
198         aOptsItem.GetOptionsLayout().SetHandlesBezier( aCbxHandlesBezier.IsChecked() );
199         //aOptsItem.GetOptionsLayout().SetHelplines( aCbxHelplines.IsChecked() );
200 
201         rAttrs.Put( aOptsItem );
202         bModified = sal_True;
203 	}
204     return( bModified );
205 }
206 
207 // -----------------------------------------------------------------------
208 
209 void SdTpOptionsContents::Reset( const SfxItemSet& rAttrs )
210 {
211 	SdOptionsContentsItem aOptsItem( (const SdOptionsContentsItem&) rAttrs.
212 						Get( ATTR_OPTIONS_CONTENTS ) );
213 
214     SdOptionsLayoutItem aLayoutItem( (const SdOptionsLayoutItem&) rAttrs.
215 						Get( ATTR_OPTIONS_LAYOUT ) );
216 
217     aCbxRuler.Check( aLayoutItem.GetOptionsLayout().IsRulerVisible() );
218     aCbxMoveOutline.Check( aLayoutItem.GetOptionsLayout().IsMoveOutline() );
219     aCbxDragStripes.Check( aLayoutItem.GetOptionsLayout().IsDragStripes() );
220     aCbxHandlesBezier.Check( aLayoutItem.GetOptionsLayout().IsHandlesBezier() );
221     //aCbxHelplines.Check( aLayoutItem.GetOptionsLayout().IsHelplines() );
222 
223 	aCbxRuler.SaveValue();
224 	aCbxMoveOutline.SaveValue();
225 	aCbxDragStripes.SaveValue();
226 	aCbxHandlesBezier.SaveValue();
227 	//aCbxHelplines.SaveValue();
228 }
229 
230 // -----------------------------------------------------------------------
231 
232 SfxTabPage* SdTpOptionsContents::Create( Window* pWindow,
233 				const SfxItemSet& rAttrs )
234 {
235 	return( new SdTpOptionsContents( pWindow, rAttrs ) );
236 }
237 
238 /*************************************************************************
239 |*
240 |*	TabPage zum Einstellen der Sonstige-Optionen
241 |*
242 \************************************************************************/
243 #define TABLE_COUNT 12
244 #define TOKEN (sal_Unicode(':'))
245 
246 SdTpOptionsMisc::SdTpOptionsMisc( Window* pParent, const SfxItemSet& rInAttrs  ) :
247 		SfxTabPage          ( pParent, SdResId( TP_OPTIONS_MISC ), rInAttrs ),
248 	aGrpText                    ( this, SdResId( GRP_TEXT ) ),
249 	aCbxQuickEdit               ( this, SdResId( CBX_QUICKEDIT ) ),
250 	aCbxPickThrough             ( this, SdResId( CBX_PICKTHROUGH ) ),
251 
252 	// Template & Layout laufen z.Z. synchron!
253 	aGrpProgramStart            ( this, SdResId( GRP_PROGRAMSTART ) ),
254 	aCbxStartWithTemplate       ( this, SdResId( CBX_START_WITH_TEMPLATE ) ),
255 
256     aGrpSettings                ( this, SdResId( GRP_SETTINGS ) ),
257 	aCbxMasterPageCache         ( this, SdResId( CBX_MASTERPAGE_CACHE ) ),
258 	aCbxCopy                    ( this, SdResId( CBX_COPY ) ),
259 	aCbxMarkedHitMovesAlways    ( this, SdResId( CBX_MARKED_HIT_MOVES_ALWAYS ) ),
260 	aCbxCrookNoContortion       ( this, SdResId( CBX_CROOK_NO_CONTORTION ) ),
261 
262     aTxtMetric                  ( this, SdResId( FT_METRIC ) ),
263     aLbMetric                   ( this, SdResId( LB_METRIC ) ),
264     aTxtTabstop                 ( this, SdResId( FT_TABSTOP ) ),
265     aMtrFldTabstop              ( this, SdResId( MTR_FLD_TABSTOP ) ),
266 
267 	aCbxStartWithActualPage		( this, SdResId( CBX_START_WITH_ACTUAL_PAGE ) ),
268 	aGrpStartWithActualPage     ( this, SdResId( GRP_START_WITH_ACTUAL_PAGE ) ),
269 	aTxtCompatibility			( this, SdResId( FT_COMPATIBILITY ) ),
270     aCbxUsePrinterMetrics       ( this, SdResId( CB_USE_PRINTER_METRICS ) ),
271     aCbxCompatibility           ( this, SdResId( CB_MERGE_PARA_DIST ) ),
272     aGrpScale                   ( this, SdResId( GRP_SCALE ) ),
273     aFtScale                    ( this, SdResId( FT_SCALE ) ),
274     aCbScale                    ( this, SdResId( CB_SCALE ) ),
275     aFtOriginal                 ( this, SdResId( FT_ORIGINAL ) ),
276     aFtEquivalent               ( this, SdResId( FT_EQUIVALENT ) ),
277     aFtPageWidth                ( this, SdResId( FT_PAGEWIDTH ) ),
278     aFiInfo1                    ( this, SdResId( FI_INFO_1 ) ),
279     aMtrFldOriginalWidth        ( this, SdResId( MTR_FLD_ORIGINAL_WIDTH ) ),
280     aFtPageHeight               ( this, SdResId( FT_PAGEHEIGHT ) ),
281     aFiInfo2                    ( this, SdResId( FI_INFO_2 ) ),
282     aMtrFldOriginalHeight       ( this, SdResId( MTR_FLD_ORIGINAL_HEIGHT ) ),
283     aMtrFldInfo1                ( this, WinBits( WB_HIDE ) ),
284     aMtrFldInfo2                ( this, WinBits( WB_HIDE ) )
285 {
286 	FreeResource();
287     SetExchangeSupport();
288 
289     // Metrik einstellen
290 	FieldUnit eFUnit;
291 
292 	sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
293 	if ( rInAttrs.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
294 	{
295 		const SfxUInt16Item& rItem = (SfxUInt16Item&)rInAttrs.Get( nWhich );
296 		eFUnit = (FieldUnit)rItem.GetValue();
297 	}
298 	else
299 		eFUnit = SfxModule::GetCurrentFieldUnit();
300 
301 	SetFieldUnit( aMtrFldTabstop, eFUnit );
302 
303 	// ListBox mit Metriken f"ullen
304 	SvxStringArray aMetricArr( RID_SVXSTR_FIELDUNIT_TABLE );
305 	sal_uInt16 i;
306 
307 	for ( i = 0; i < aMetricArr.Count(); ++i )
308 	{
309 		String sMetric = aMetricArr.GetStringByPos( i );
310 		long nFieldUnit = aMetricArr.GetValue( i );
311 		sal_uInt16 nPos = aLbMetric.InsertEntry( sMetric );
312 		aLbMetric.SetEntryData( nPos, (void*)nFieldUnit );
313 	}
314     aLbMetric.SetSelectHdl( LINK( this, SdTpOptionsMisc, SelectMetricHdl_Impl ) );
315 
316     SetFieldUnit( aMtrFldOriginalWidth, eFUnit );
317 	SetFieldUnit( aMtrFldOriginalHeight, eFUnit );
318 	aMtrFldOriginalWidth.SetLast( 999999999 );
319 	aMtrFldOriginalWidth.SetMax( 999999999 );
320 	aMtrFldOriginalHeight.SetLast( 999999999 );
321 	aMtrFldOriginalHeight.SetMax( 999999999 );
322 
323 	// Temporaere Fields fuer Info-Texte (fuer Formatierung/Berechnung)
324 	aMtrFldInfo1.SetUnit( eFUnit );
325 	aMtrFldInfo1.SetMax( 999999999 );
326 	aMtrFldInfo1.SetDecimalDigits( 2 );
327 	aMtrFldInfo2.SetUnit( eFUnit );
328 	aMtrFldInfo2.SetMax( 999999999 );
329 	aMtrFldInfo2.SetDecimalDigits( 2 );
330 
331 	// PoolUnit ermitteln
332     SfxItemPool* pPool = rInAttrs.GetPool();
333 	DBG_ASSERT( pPool, "Wo ist der Pool?" );
334 	ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
335 
336 	// Fuellen der CB
337 	sal_uInt16 aTable[ TABLE_COUNT ] =
338 		{ 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
339 
340     for( i = 0; i < TABLE_COUNT; i++ )
341 		aCbScale.InsertEntry( GetScale( 1, aTable[i] ) );
342 	for( i = 1; i < TABLE_COUNT; i++ )
343 		aCbScale.InsertEntry( GetScale(  aTable[i], 1 ) );
344 }
345 
346 // -----------------------------------------------------------------------
347 
348 SdTpOptionsMisc::~SdTpOptionsMisc()
349 {
350 }
351 // -----------------------------------------------------------------------
352 void SdTpOptionsMisc::ActivatePage( const SfxItemSet& rSet )
353 {
354 	// Hier muss noch einmal SaveValue gerufen werden, da sonst u.U.
355 	// der Wert in anderen TabPages keine Wirkung hat
356 	aLbMetric.SaveValue();
357     // Metrik ggfs. aendern (da TabPage im Dialog liegt,
358 	// wo die Metrik eingestellt werden kann
359 	const SfxPoolItem* pAttr = NULL;
360 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC , sal_False,
361 									(const SfxPoolItem**)&pAttr ))
362 	{
363 		const SfxUInt16Item* pItem = (SfxUInt16Item*) pAttr;
364 
365 		FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
366 
367 		if( eFUnit != aMtrFldOriginalWidth.GetUnit() )
368 		{
369 			// Metriken einstellen
370 			sal_Int64 nVal = aMtrFldOriginalWidth.Denormalize( aMtrFldOriginalWidth.GetValue( FUNIT_TWIP ) );
371 			SetFieldUnit( aMtrFldOriginalWidth, eFUnit, sal_True );
372 			aMtrFldOriginalWidth.SetValue( aMtrFldOriginalWidth.Normalize( nVal ), FUNIT_TWIP );
373 
374 			nVal = aMtrFldOriginalHeight.Denormalize( aMtrFldOriginalHeight.GetValue( FUNIT_TWIP ) );
375 			SetFieldUnit( aMtrFldOriginalHeight, eFUnit, sal_True );
376 			aMtrFldOriginalHeight.SetValue( aMtrFldOriginalHeight.Normalize( nVal ), FUNIT_TWIP );
377 
378 
379 			if( nWidth != 0 && nHeight != 0 )
380 			{
381 				aMtrFldInfo1.SetUnit( eFUnit );
382 				aMtrFldInfo2.SetUnit( eFUnit );
383 
384 				SetMetricValue( aMtrFldInfo1, nWidth, ePoolUnit );
385 				aInfo1 = aMtrFldInfo1.GetText();
386 				aFiInfo1.SetText( aInfo1 );
387 
388 				SetMetricValue( aMtrFldInfo2, nHeight, ePoolUnit );
389 				aInfo2 = aMtrFldInfo2.GetText();
390 				aFiInfo2.SetText( aInfo2 );
391 			}
392 		}
393 	}
394 }
395 
396 // -----------------------------------------------------------------------
397 
398 int SdTpOptionsMisc::DeactivatePage( SfxItemSet* pActiveSet )
399 {
400     // Parsercheck
401 	sal_Int32 nX, nY;
402 	if( SetScale( aCbScale.GetText(), nX, nY ) )
403 	{
404 		if( pActiveSet )
405 			FillItemSet( *pActiveSet );
406         return( LEAVE_PAGE );
407     }
408 	WarningBox aWarnBox( GetParent(), WB_YES_NO, String( SdResId( STR_WARN_SCALE_FAIL ) ) );
409 	short nReturn = aWarnBox.Execute();
410 
411 	if( nReturn == RET_YES )
412 		return( KEEP_PAGE );
413 
414 	if( pActiveSet )
415 		FillItemSet( *pActiveSet );
416 
417 	return( LEAVE_PAGE );
418 }
419 
420 // -----------------------------------------------------------------------
421 
422 sal_Bool SdTpOptionsMisc::FillItemSet( SfxItemSet& rAttrs )
423 {
424 	sal_Bool bModified = sal_False;
425 
426 	if( aCbxStartWithTemplate.GetSavedValue() 	!= aCbxStartWithTemplate.IsChecked() ||
427 		aCbxMarkedHitMovesAlways.GetSavedValue()!= aCbxMarkedHitMovesAlways.IsChecked() ||
428 		aCbxCrookNoContortion.GetSavedValue() 	!= aCbxCrookNoContortion.IsChecked() ||
429 		aCbxQuickEdit.GetSavedValue() 			!= aCbxQuickEdit.IsChecked() ||
430 		aCbxPickThrough.GetSavedValue() 		!= aCbxPickThrough.IsChecked() ||
431 		aCbxMasterPageCache.GetSavedValue() 	!= aCbxMasterPageCache.IsChecked() ||
432 		aCbxCopy.GetSavedValue() 				!= aCbxCopy.IsChecked() ||
433 		aCbxStartWithActualPage.GetSavedValue() != aCbxStartWithActualPage.IsChecked() ||
434 		aCbxCompatibility.GetSavedValue()		!= aCbxCompatibility.IsChecked() ||
435 		aCbxUsePrinterMetrics.GetSavedValue()   != aCbxUsePrinterMetrics.IsChecked() )
436 	{
437 		SdOptionsMiscItem aOptsItem( ATTR_OPTIONS_MISC );
438 
439 		aOptsItem.GetOptionsMisc().SetStartWithTemplate( aCbxStartWithTemplate.IsChecked() );
440 		aOptsItem.GetOptionsMisc().SetMarkedHitMovesAlways( aCbxMarkedHitMovesAlways.IsChecked() );
441 		aOptsItem.GetOptionsMisc().SetCrookNoContortion( aCbxCrookNoContortion.IsChecked() );
442 		aOptsItem.GetOptionsMisc().SetQuickEdit( aCbxQuickEdit.IsChecked() );
443 		aOptsItem.GetOptionsMisc().SetPickThrough( aCbxPickThrough.IsChecked() );
444 		aOptsItem.GetOptionsMisc().SetMasterPagePaintCaching( aCbxMasterPageCache.IsChecked() );
445 		aOptsItem.GetOptionsMisc().SetDragWithCopy( aCbxCopy.IsChecked() );
446 		aOptsItem.GetOptionsMisc().SetStartWithActualPage( aCbxStartWithActualPage.IsChecked() );
447         aOptsItem.GetOptionsMisc().SetSummationOfParagraphs( aCbxCompatibility.IsChecked() );
448         aOptsItem.GetOptionsMisc().SetPrinterIndependentLayout (
449             aCbxUsePrinterMetrics.IsChecked()
450             ? ::com::sun::star::document::PrinterIndependentLayout::DISABLED
451             : ::com::sun::star::document::PrinterIndependentLayout::ENABLED);
452 		rAttrs.Put( aOptsItem );
453 
454 		bModified = sal_True;
455 	}
456 
457 	// Metrik
458 	const sal_uInt16 nMPos = aLbMetric.GetSelectEntryPos();
459 	if ( nMPos != aLbMetric.GetSavedValue() )
460 	{
461 		sal_uInt16 nFieldUnit = (sal_uInt16)(long)aLbMetric.GetEntryData( nMPos );
462 		rAttrs.Put( SfxUInt16Item( GetWhich( SID_ATTR_METRIC ),
463 									 (sal_uInt16)nFieldUnit ) );
464 		bModified |= sal_True;
465 	}
466 
467 	// Tabulatorabstand
468 	if( aMtrFldTabstop.GetText() != aMtrFldTabstop.GetSavedValue() )
469 	{
470 		sal_uInt16 nWh = GetWhich( SID_ATTR_DEFTABSTOP );
471 		SfxMapUnit eUnit = rAttrs.GetPool()->GetMetric( nWh );
472 		SfxUInt16Item aDef( nWh,(sal_uInt16)GetCoreValue( aMtrFldTabstop, eUnit ) );
473 		rAttrs.Put( aDef );
474 		bModified |= sal_True;
475 	}
476 
477 	sal_Int32 nX, nY;
478 	if( SetScale( aCbScale.GetText(), nX, nY ) )
479 	{
480 		rAttrs.Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
481 		rAttrs.Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
482 
483 		bModified = sal_True;
484 	}
485 
486     return( bModified );
487 }
488 
489 // -----------------------------------------------------------------------
490 
491 void SdTpOptionsMisc::Reset( const SfxItemSet& rAttrs )
492 {
493 	SdOptionsMiscItem aOptsItem( (const SdOptionsMiscItem&) rAttrs.
494 						Get( ATTR_OPTIONS_MISC ) );
495 
496 	aCbxStartWithTemplate.Check( aOptsItem.GetOptionsMisc().IsStartWithTemplate() );
497 	aCbxMarkedHitMovesAlways.Check( aOptsItem.GetOptionsMisc().IsMarkedHitMovesAlways() );
498 	aCbxCrookNoContortion.Check( aOptsItem.GetOptionsMisc().IsCrookNoContortion() );
499 	aCbxQuickEdit.Check( aOptsItem.GetOptionsMisc().IsQuickEdit() );
500 	aCbxPickThrough.Check( aOptsItem.GetOptionsMisc().IsPickThrough() );
501 	aCbxMasterPageCache.Check( aOptsItem.GetOptionsMisc().IsMasterPagePaintCaching() );
502 	aCbxCopy.Check( aOptsItem.GetOptionsMisc().IsDragWithCopy() );
503 	aCbxStartWithActualPage.Check( aOptsItem.GetOptionsMisc().IsStartWithActualPage() );
504     aCbxCompatibility.Check( aOptsItem.GetOptionsMisc().IsSummationOfParagraphs() );
505     aCbxUsePrinterMetrics.Check( aOptsItem.GetOptionsMisc().GetPrinterIndependentLayout()==1 );
506 	aCbxStartWithTemplate.SaveValue();
507 	aCbxMarkedHitMovesAlways.SaveValue();
508 	aCbxCrookNoContortion.SaveValue();
509 	aCbxQuickEdit.SaveValue();
510 	aCbxPickThrough.SaveValue();
511 
512 	aCbxMasterPageCache.SaveValue();
513 	aCbxCopy.SaveValue();
514 	aCbxStartWithActualPage.SaveValue();
515 	aCbxCompatibility.SaveValue();
516 	aCbxUsePrinterMetrics.SaveValue();
517 
518     // Metrik
519 	sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
520 	aLbMetric.SetNoSelection();
521 
522 	if ( rAttrs.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
523 	{
524 		const SfxUInt16Item& rItem = (SfxUInt16Item&)rAttrs.Get( nWhich );
525 		long nFieldUnit = (long)rItem.GetValue();
526 
527 		for ( sal_uInt16 i = 0; i < aLbMetric.GetEntryCount(); ++i )
528 		{
529 			if ( (long)aLbMetric.GetEntryData( i ) == nFieldUnit )
530 			{
531 				aLbMetric.SelectEntryPos( i );
532 				break;
533 			}
534 		}
535 	}
536 
537 	// Tabulatorabstand
538 	nWhich = GetWhich( SID_ATTR_DEFTABSTOP );
539 	if( rAttrs.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
540 	{
541 		SfxMapUnit eUnit = rAttrs.GetPool()->GetMetric( nWhich );
542 		const SfxUInt16Item& rItem = (SfxUInt16Item&)rAttrs.Get( nWhich );
543 		SetMetricValue( aMtrFldTabstop, rItem.GetValue(), eUnit );
544 	}
545 	aLbMetric.SaveValue();
546 	aMtrFldTabstop.SaveValue();
547     //Scale
548     sal_Int32 nX = ( (const SfxInt32Item&) rAttrs.
549 				 Get( ATTR_OPTIONS_SCALE_X ) ).GetValue();
550 	sal_Int32 nY = ( (const SfxInt32Item&) rAttrs.
551 				 Get( ATTR_OPTIONS_SCALE_Y ) ).GetValue();
552 	nWidth = ( (const SfxUInt32Item&) rAttrs.
553 					Get( ATTR_OPTIONS_SCALE_WIDTH ) ).GetValue();
554 	nHeight = ( (const SfxUInt32Item&) rAttrs.
555 					Get( ATTR_OPTIONS_SCALE_HEIGHT ) ).GetValue();
556 
557 	aCbScale.SetText( GetScale( nX, nY ) );
558 
559     // #92067# broken feature disabled for 6.0
560     aFtOriginal.Hide();
561     aFtEquivalent.Hide();
562     aMtrFldOriginalWidth.Hide();
563     aMtrFldOriginalWidth.SetText( aInfo1 ); // leer
564     aMtrFldOriginalHeight.Hide();
565     aMtrFldOriginalHeight.SetText( aInfo2 ); //leer
566     aFtPageWidth.Hide();
567     aFtPageHeight.Hide();
568     aFiInfo1.Hide();
569     aFiInfo2.Hide();
570 
571     UpdateCompatibilityControls ();
572 }
573 
574 // -----------------------------------------------------------------------
575 
576 SfxTabPage* SdTpOptionsMisc::Create( Window* pWindow,
577 				const SfxItemSet& rAttrs )
578 {
579 	return( new SdTpOptionsMisc( pWindow, rAttrs ) );
580 }
581 //------------------------------------------------------------------------
582 
583 IMPL_LINK( SdTpOptionsMisc, SelectMetricHdl_Impl, ListBox *, EMPTYARG )
584 {
585 	sal_uInt16 nPos = aLbMetric.GetSelectEntryPos();
586 
587 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
588 	{
589 		FieldUnit eUnit = (FieldUnit)(long)aLbMetric.GetEntryData( nPos );
590 		sal_Int64 nVal =
591 			aMtrFldTabstop.Denormalize( aMtrFldTabstop.GetValue( FUNIT_TWIP ) );
592 		SetFieldUnit( aMtrFldTabstop, eUnit );
593 		aMtrFldTabstop.SetValue( aMtrFldTabstop.Normalize( nVal ), FUNIT_TWIP );
594 	}
595 	return 0;
596 }
597 
598 
599 namespace {
600 void lcl_MoveWin( Window& rWin, long nYDiff)
601 {
602     Point aPos(rWin.GetPosPixel());
603     aPos.Y() += nYDiff;
604     rWin.SetPosPixel (aPos);
605 }
606 
607 void lcl_MoveWin( Window& rWin, long nXdiff, long nYdiff)
608 {
609     Point aPos(rWin.GetPosPixel());
610     aPos.X() += nXdiff;
611     aPos.Y() += nYdiff;
612     rWin.SetPosPixel(aPos);
613 }
614 }
615 
616 void SdTpOptionsMisc::SetImpressMode (void)
617 {
618     long nDialogWidth = GetSizePixel().Width();
619     long nLineHeight = aCbxPickThrough.GetPosPixel().Y()
620         - aCbxQuickEdit.GetPosPixel().Y();
621 
622     // Put both "Text objects" check boxes side by side.
623     lcl_MoveWin (aCbxPickThrough,
624         nDialogWidth/2 - aCbxPickThrough.GetPosPixel().X(),
625         -nLineHeight);
626 
627     // Move the other controls up one line.
628     lcl_MoveWin (aGrpProgramStart, -nLineHeight);
629     lcl_MoveWin (aCbxStartWithTemplate, -nLineHeight);
630     lcl_MoveWin (aGrpSettings, -nLineHeight);
631     lcl_MoveWin (aCbxMasterPageCache, -nLineHeight);
632     lcl_MoveWin (aCbxCopy, -nLineHeight);
633     lcl_MoveWin (aCbxMarkedHitMovesAlways, -nLineHeight);
634     lcl_MoveWin (aCbxCrookNoContortion, -nLineHeight);
635     lcl_MoveWin (aTxtMetric, -nLineHeight);
636     lcl_MoveWin (aLbMetric, -nLineHeight);
637     lcl_MoveWin (aTxtTabstop, -nLineHeight);
638     lcl_MoveWin (aMtrFldTabstop, -nLineHeight);
639     lcl_MoveWin (aGrpStartWithActualPage, -nLineHeight);
640     lcl_MoveWin (aCbxStartWithActualPage, -nLineHeight);
641     lcl_MoveWin (aTxtCompatibility, -nLineHeight);
642 
643     // Move the printer-independent-metrics check box up two lines to change
644     // places with spacing-between-paragraphs check box.
645     lcl_MoveWin (aCbxUsePrinterMetrics, -2*nLineHeight);
646 }
647 
648 void    SdTpOptionsMisc::SetDrawMode()
649 {
650     aCbxStartWithTemplate.Hide();
651     aGrpProgramStart.Hide();
652     aCbxStartWithActualPage.Hide();
653 	aCbxCompatibility.Hide();
654     aGrpStartWithActualPage.Hide();
655     aCbxCrookNoContortion.Show();
656 
657     aGrpScale.Show();
658     aFtScale.Show();
659     aCbScale.Show();
660 
661     aFtOriginal.Show();
662     aFtEquivalent.Show();
663 
664     aFtPageWidth.Show();
665     aFiInfo1.Show();
666     aMtrFldOriginalWidth.Show();
667 
668     aFtPageHeight.Show();
669     aFiInfo2.Show();
670     aMtrFldOriginalHeight.Show();
671 
672     long nDiff = aGrpSettings.GetPosPixel().Y() - aGrpProgramStart.GetPosPixel().Y();
673     lcl_MoveWin( aGrpSettings, -nDiff );
674     lcl_MoveWin( aCbxMasterPageCache, -nDiff );
675     lcl_MoveWin( aCbxCopy, -nDiff );
676     lcl_MoveWin( aCbxMarkedHitMovesAlways, -nDiff );
677     lcl_MoveWin( aCbxCrookNoContortion, -nDiff );
678     nDiff -= aCbxCrookNoContortion.GetPosPixel().Y() - aCbxMarkedHitMovesAlways.GetPosPixel().Y();
679     lcl_MoveWin( aTxtMetric, -nDiff );
680     lcl_MoveWin( aLbMetric, -nDiff );
681     lcl_MoveWin( aTxtTabstop, -nDiff );
682     lcl_MoveWin( aMtrFldTabstop, -nDiff );
683 
684     // Move the scale controls so that they are visually centered betwen the
685     // group controls above and below.
686     lcl_MoveWin (aFtScale, -17);
687     lcl_MoveWin (aCbScale, -17);
688 
689     // Move the printer-independent-metrics check box in the place that the
690     // spacing-between-paragraphs check box normally is in.
691     aCbxUsePrinterMetrics.SetPosPixel (aCbxCompatibility.GetPosPixel());
692 }
693 // -----------------------------------------------------------------------
694 
695 IMPL_LINK( SdTpOptionsMisc, ModifyScaleHdl, void *, EMPTYARG )
696 {
697 	// Originalgroesse berechnen
698 	sal_Int32 nX, nY;
699 	if( SetScale( aCbScale.GetText(), nX, nY ) )
700 	{
701 		sal_Int32 nW = nWidth * nY / nX;
702 		sal_Int32 nH = nHeight * nY / nX;
703 
704 		SetMetricValue( aMtrFldOriginalWidth, nW, ePoolUnit );
705 		SetMetricValue( aMtrFldOriginalHeight, nH, ePoolUnit );
706 	}
707 
708 	return( 0L );
709 }
710 
711 // -----------------------------------------------------------------------
712 
713 IMPL_LINK( SdTpOptionsMisc, ModifyOriginalScaleHdl, void *, EMPTYARG )
714 {
715 	// Berechnen des Massstabs
716 	long nOrgW = static_cast<long>(aMtrFldOriginalWidth.GetValue());
717 	long nOrgH = static_cast<long>(aMtrFldOriginalHeight.GetValue());
718 
719 	if( nOrgW == 0 || nOrgH == 0 )
720 		return( 0L );
721 
722 	Fraction aFract1( nOrgW, static_cast<long>(aMtrFldInfo1.GetValue()) );
723 	Fraction aFract2( nOrgH, static_cast<long>(aMtrFldInfo2.GetValue()) );
724 	Fraction aFract( aFract1 > aFract2 ? aFract1 : aFract2 );
725 
726 	long nValue;
727 	if( aFract < Fraction( 1, 1 ) )
728 	{
729 		// Fraction umdrehen
730 		aFract1 = aFract;
731 		aFract = Fraction( aFract1.GetDenominator(), aFract1.GetNumerator() );
732 		nValue = aFract;
733 
734         // #92067# Swap nominator and denominator
735 		aCbScale.SetText( GetScale( nValue, 1 ) );
736 	}
737 	else
738 	{
739 		double fValue = aFract;
740 		nValue = aFract;
741 		if( fValue > (double)nValue )
742 			nValue++;
743 
744         // #92067# Swap nominator and denominator
745 		aCbScale.SetText( GetScale( 1, nValue ) );
746 	}
747 	return( 0L );
748 }
749 
750 // -----------------------------------------------------------------------
751 
752 String SdTpOptionsMisc::GetScale( sal_Int32 nX, sal_Int32 nY )
753 {
754 	String aScale( UniString::CreateFromInt32( nX ) );
755 	aScale.Append( TOKEN );
756 	aScale.Append( UniString::CreateFromInt32( nY ) );
757 
758 	return( aScale );
759 }
760 
761 // -----------------------------------------------------------------------
762 
763 sal_Bool SdTpOptionsMisc::SetScale( const String& aScale, sal_Int32& rX, sal_Int32& rY )
764 {
765 	if( aScale.GetTokenCount( TOKEN ) != 2 )
766 		return( sal_False );
767 
768 	ByteString aTmp( aScale.GetToken( 0, TOKEN ), RTL_TEXTENCODING_ASCII_US );
769 	if( !aTmp.IsNumericAscii() )
770 		return( sal_False );
771 
772 	rX = (long) aTmp.ToInt32();
773 	if( rX == 0 )
774 		return( sal_False );
775 
776 	aTmp = ByteString( aScale.GetToken( 1, TOKEN ), RTL_TEXTENCODING_ASCII_US );
777 	if( !aTmp.IsNumericAscii() )
778 		return( sal_False );
779 
780 	rY = (long) aTmp.ToInt32();
781 	if( rY == 0 )
782 		return( sal_False );
783 
784 	return( sal_True );
785 }
786 
787 
788 
789 
790 void SdTpOptionsMisc::UpdateCompatibilityControls (void)
791 {
792     // Disable the compatibility controls by default.  Enable them only when
793     // there is at least one open document.
794     sal_Bool bIsEnabled = sal_False;
795 
796     try
797     {
798         // Get a component enumeration from the desktop and search it for documents.
799         Reference<lang::XMultiServiceFactory> xFactory (
800             ::comphelper::getProcessServiceFactory ());
801         do
802         {
803             if ( ! xFactory.is())
804                 break;
805 
806             Reference<frame::XDesktop> xDesktop (xFactory->createInstance (
807                 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY);
808             if ( ! xDesktop.is())
809                 break;
810 
811             Reference<container::XEnumerationAccess> xComponents (
812                 xDesktop->getComponents(), UNO_QUERY);
813             if ( ! xComponents.is())
814                 break;
815 
816             Reference<container::XEnumeration> xEnumeration (
817                 xComponents->createEnumeration());
818             if ( ! xEnumeration.is())
819                 break;
820 
821             while (xEnumeration->hasMoreElements())
822             {
823                 Reference<frame::XModel> xModel (xEnumeration->nextElement(), UNO_QUERY);
824                 if (xModel.is())
825                 {
826                     // There is at leas one model/document: Enable the compatibility controls.
827                     bIsEnabled = sal_True;
828                     break;
829                 }
830             }
831 
832         }
833         while (false); // One 'loop'.
834     }
835     catch (uno::Exception e)
836     {
837         // When there is an exception then simply use the default value of
838         // bIsEnabled and disable the controls.
839     }
840 
841     aTxtCompatibility.Enable (bIsEnabled);
842 	aCbxCompatibility.Enable(bIsEnabled);
843     aCbxUsePrinterMetrics.Enable (bIsEnabled);
844 }
845 
846 void SdTpOptionsMisc::PageCreated (SfxAllItemSet aSet)
847 {
848 	SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_SDMODE_FLAG,sal_False);
849 	if (pFlagItem)
850 	{
851 		sal_uInt32 nFlags=pFlagItem->GetValue();
852 		if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
853 			SetDrawMode();
854 		if ( ( nFlags & SD_IMPRESS_MODE ) == SD_IMPRESS_MODE )
855 			SetImpressMode();
856 	}
857 }
858 
859