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