Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / tpoption.cxx
blob53c4487681fb0962313f62cbac9fcab053d02d2c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/frame/Desktop.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <com/sun/star/container/XEnumerationAccess.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <comphelper/string.hxx>
27 #include <com/sun/star/uno/Exception.hpp>
28 #include <sfx2/module.hxx>
29 #include <sfx2/app.hxx>
30 #include <svx/svxids.hrc>
31 #include <svx/dialogs.hrc>
32 #include <svx/strarray.hxx>
33 #include <svx/dlgutil.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/weld.hxx>
37 #include <sdattr.hxx>
38 #include <sdresid.hxx>
39 #include <optsitem.hxx>
40 #include <tpoption.hxx>
41 #include <strings.hrc>
42 #include <app.hrc>
43 #include <svl/intitem.hxx>
44 #include <sfx2/request.hxx>
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
49 SdTpOptionsSnap::SdTpOptionsSnap( vcl::Window* pParent, const SfxItemSet& rInAttrs ) :
50 SvxGridTabPage(pParent, rInAttrs)
52 pSnapFrames->Show();
55 SdTpOptionsSnap::~SdTpOptionsSnap()
59 bool SdTpOptionsSnap::FillItemSet( SfxItemSet* rAttrs )
61 SvxGridTabPage::FillItemSet(rAttrs);
62 SdOptionsSnapItem aOptsItem;
64 aOptsItem.GetOptionsSnap().SetSnapHelplines( pCbxSnapHelplines->IsChecked() );
65 aOptsItem.GetOptionsSnap().SetSnapBorder( pCbxSnapBorder->IsChecked() );
66 aOptsItem.GetOptionsSnap().SetSnapFrame( pCbxSnapFrame->IsChecked() );
67 aOptsItem.GetOptionsSnap().SetSnapPoints( pCbxSnapPoints->IsChecked() );
68 aOptsItem.GetOptionsSnap().SetOrtho( pCbxOrtho->IsChecked() );
69 aOptsItem.GetOptionsSnap().SetBigOrtho( pCbxBigOrtho->IsChecked() );
70 aOptsItem.GetOptionsSnap().SetRotate( pCbxRotate->IsChecked() );
71 aOptsItem.GetOptionsSnap().SetSnapArea( static_cast<sal_Int16>(pMtrFldSnapArea->GetValue()) );
72 aOptsItem.GetOptionsSnap().SetAngle( static_cast<sal_Int16>(pMtrFldAngle->GetValue()) );
73 aOptsItem.GetOptionsSnap().SetEliminatePolyPointLimitAngle( static_cast<sal_Int16>(pMtrFldBezAngle->GetValue()) );
75 rAttrs->Put( aOptsItem );
77 // we get a possible existing GridItem, this ensures that we do not set
78 // some default values by accident
79 return true;
82 void SdTpOptionsSnap::Reset( const SfxItemSet* rAttrs )
84 SvxGridTabPage::Reset(rAttrs);
86 SdOptionsSnapItem aOptsItem( static_cast<const SdOptionsSnapItem&>( rAttrs->
87 Get( ATTR_OPTIONS_SNAP ) ) );
89 pCbxSnapHelplines->Check( aOptsItem.GetOptionsSnap().IsSnapHelplines() );
90 pCbxSnapBorder->Check( aOptsItem.GetOptionsSnap().IsSnapBorder() );
91 pCbxSnapFrame->Check( aOptsItem.GetOptionsSnap().IsSnapFrame() );
92 pCbxSnapPoints->Check( aOptsItem.GetOptionsSnap().IsSnapPoints() );
93 pCbxOrtho->Check( aOptsItem.GetOptionsSnap().IsOrtho() );
94 pCbxBigOrtho->Check( aOptsItem.GetOptionsSnap().IsBigOrtho() );
95 pCbxRotate->Check( aOptsItem.GetOptionsSnap().IsRotate() );
96 pMtrFldSnapArea->SetValue( aOptsItem.GetOptionsSnap().GetSnapArea() );
97 pMtrFldAngle->SetValue( aOptsItem.GetOptionsSnap().GetAngle() );
98 pMtrFldBezAngle->SetValue( aOptsItem.GetOptionsSnap().GetEliminatePolyPointLimitAngle() );
100 pCbxRotate->GetClickHdl().Call(nullptr);
103 VclPtr<SfxTabPage> SdTpOptionsSnap::Create( TabPageParent pWindow,
104 const SfxItemSet* rAttrs )
106 return VclPtr<SdTpOptionsSnap>::Create( pWindow.pParent, *rAttrs );
109 /*************************************************************************
111 |* TabPage to adjust the content options
113 \************************************************************************/
115 SdTpOptionsContents::SdTpOptionsContents( vcl::Window* pParent, const SfxItemSet& rInAttrs ) :
116 SfxTabPage ( pParent, "SdViewPage", "modules/simpress/ui/sdviewpage.ui", &rInAttrs )
118 get( m_pCbxRuler, "ruler");
119 get( m_pCbxDragStripes, "dragstripes");
120 get( m_pCbxHandlesBezier, "handlesbezier");
121 get( m_pCbxMoveOutline, "moveoutline");
124 SdTpOptionsContents::~SdTpOptionsContents()
126 disposeOnce();
129 void SdTpOptionsContents::dispose()
131 m_pCbxRuler.clear();
132 m_pCbxDragStripes.clear();
133 m_pCbxHandlesBezier.clear();
134 m_pCbxMoveOutline.clear();
135 SfxTabPage::dispose();
138 bool SdTpOptionsContents::FillItemSet( SfxItemSet* rAttrs )
140 bool bModified = false;
142 if( m_pCbxRuler->IsValueChangedFromSaved() ||
143 m_pCbxMoveOutline->IsValueChangedFromSaved() ||
144 m_pCbxDragStripes->IsValueChangedFromSaved() ||
145 m_pCbxHandlesBezier->IsValueChangedFromSaved() )
147 SdOptionsLayoutItem aOptsItem;
149 aOptsItem.GetOptionsLayout().SetRulerVisible( m_pCbxRuler->IsChecked() );
150 aOptsItem.GetOptionsLayout().SetMoveOutline( m_pCbxMoveOutline->IsChecked() );
151 aOptsItem.GetOptionsLayout().SetDragStripes( m_pCbxDragStripes->IsChecked() );
152 aOptsItem.GetOptionsLayout().SetHandlesBezier( m_pCbxHandlesBezier->IsChecked() );
154 rAttrs->Put( aOptsItem );
155 bModified = true;
157 return bModified;
160 void SdTpOptionsContents::Reset( const SfxItemSet* rAttrs )
162 SdOptionsLayoutItem aLayoutItem( static_cast<const SdOptionsLayoutItem&>( rAttrs->
163 Get( ATTR_OPTIONS_LAYOUT ) ) );
165 m_pCbxRuler->Check( aLayoutItem.GetOptionsLayout().IsRulerVisible() );
166 m_pCbxMoveOutline->Check( aLayoutItem.GetOptionsLayout().IsMoveOutline() );
167 m_pCbxDragStripes->Check( aLayoutItem.GetOptionsLayout().IsDragStripes() );
168 m_pCbxHandlesBezier->Check( aLayoutItem.GetOptionsLayout().IsHandlesBezier() );
170 m_pCbxRuler->SaveValue();
171 m_pCbxMoveOutline->SaveValue();
172 m_pCbxDragStripes->SaveValue();
173 m_pCbxHandlesBezier->SaveValue();
176 VclPtr<SfxTabPage> SdTpOptionsContents::Create( TabPageParent pWindow,
177 const SfxItemSet* rAttrs )
179 return VclPtr<SdTpOptionsContents>::Create( pWindow.pParent, *rAttrs );
182 /*************************************************************************
184 |* TabPage to adjust the misc options
186 \************************************************************************/
187 #define TABLE_COUNT 12
188 #define TOKEN ':'
190 SdTpOptionsMisc::SdTpOptionsMisc(vcl::Window* pParent, const SfxItemSet& rInAttrs)
191 : SfxTabPage(pParent, "OptSavePage", "modules/simpress/ui/optimpressgeneralpage.ui", &rInAttrs)
192 , nWidth(0)
193 , nHeight(0)
195 get(m_pCbxQuickEdit , "qickedit");
196 get(m_pCbxPickThrough , "textselected");
197 get(m_pNewDocumentFrame, "newdocumentframe");
198 get(m_pCbxStartWithTemplate,"startwithwizard");
199 get(m_pCbxMasterPageCache , "backgroundback");
200 get(m_pCbxCopy , "copywhenmove");
201 get(m_pCbxMarkedHitMovesAlways , "objalwymov");
202 get(m_pLbMetric , "units");
203 get(m_pCbxEnableSdremote , "enremotcont");
204 get(m_pCbxEnablePresenterScreen , "enprsntcons");
205 get(m_pCbxUsePrinterMetrics , "printermetrics");
206 get(m_pPresentationFrame , "presentationframe");
207 get(m_pScaleFrame , "scaleframe");
208 get(m_pCbScale , "scaleBox");
209 get(m_pMtrFldTabstop , "metricFields");
210 get(m_pMtrFldOriginalWidth , "metricWidthFields");
211 get(m_pMtrFldOriginalHeight , "metricHeightFields");
212 get(m_pMtrFldInfo1 , "metricInfo1Fields");
213 get(m_pMtrFldInfo2 , "metricInfo2Fields");
214 get(m_pCbxCompatibility ,"cbCompatibility" );
215 get(m_pFiInfo1 , "info1");
216 get(m_pFiInfo2 , "info2");
217 get(m_pNewDocLb , "newdoclbl");
218 get(m_pWidthLb , "widthlbl");
219 get(m_pHeightLb , "heightlbl");
220 get(m_pCbxDistrot , "distrotcb");
222 SetExchangeSupport();
224 // set metric
225 FieldUnit eFUnit;
227 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
228 if ( rInAttrs.GetItemState( nWhich ) >= SfxItemState::DEFAULT )
230 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rInAttrs.Get( nWhich ));
231 eFUnit = static_cast<FieldUnit>(rItem.GetValue());
233 else
234 eFUnit = SfxModule::GetCurrentFieldUnit();
236 SetFieldUnit( *m_pMtrFldTabstop , eFUnit );
238 // Impress is default mode, let' hide the entire scale frame etc.
239 m_pCbxDistrot->Hide();
240 m_pScaleFrame->Hide();
242 // fill ListBox with metrics
243 for (sal_uInt32 i = 0; i < SvxFieldUnitTable::Count(); ++i)
245 OUString sMetric = SvxFieldUnitTable::GetString(i);
246 sal_IntPtr nFieldUnit = SvxFieldUnitTable::GetValue(i);
247 sal_Int32 nPos = m_pLbMetric->InsertEntry( sMetric );
248 m_pLbMetric->SetEntryData( nPos, reinterpret_cast<void*>(nFieldUnit) );
250 m_pLbMetric->SetSelectHdl( LINK( this, SdTpOptionsMisc, SelectMetricHdl_Impl ) );
252 SetFieldUnit( *m_pMtrFldOriginalWidth, eFUnit );
253 SetFieldUnit( *m_pMtrFldOriginalHeight, eFUnit );
254 m_pMtrFldOriginalWidth->SetLast( 999999999 );
255 m_pMtrFldOriginalWidth->SetMax( 999999999 );
256 m_pMtrFldOriginalHeight->SetLast( 999999999 );
257 m_pMtrFldOriginalHeight->SetMax( 999999999 );
259 // temporary fields for info texts (for formatting/calculation)
260 m_pMtrFldInfo1->SetUnit( eFUnit );
261 m_pMtrFldInfo1->SetMax( 999999999 );
262 m_pMtrFldInfo1->SetDecimalDigits( 2 );
263 m_pMtrFldInfo2->SetUnit( eFUnit );
264 m_pMtrFldInfo2->SetMax( 999999999 );
265 m_pMtrFldInfo2->SetDecimalDigits( 2 );
267 // determine PoolUnit
268 SfxItemPool* pPool = rInAttrs.GetPool();
269 DBG_ASSERT( pPool, "Where is the Pool?" );
270 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
272 // Fill the CB
273 sal_uInt16 aTable[ TABLE_COUNT ] =
274 { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
276 for( sal_uInt16 i = 0; i < TABLE_COUNT; i++ )
277 m_pCbScale->InsertEntry( GetScale( 1, aTable[i] ) );
278 for( sal_uInt16 i = 1; i < TABLE_COUNT; i++ )
279 m_pCbScale->InsertEntry( GetScale( aTable[i], 1 ) );
282 SdTpOptionsMisc::~SdTpOptionsMisc()
284 disposeOnce();
287 void SdTpOptionsMisc::dispose()
289 m_pCbxQuickEdit.clear();
290 m_pCbxPickThrough.clear();
291 m_pNewDocumentFrame.clear();
292 m_pCbxStartWithTemplate.clear();
293 m_pCbxMasterPageCache.clear();
294 m_pCbxCopy.clear();
295 m_pCbxMarkedHitMovesAlways.clear();
296 m_pPresentationFrame.clear();
297 m_pLbMetric.clear();
298 m_pMtrFldTabstop.clear();
299 m_pCbxEnableSdremote.clear();
300 m_pCbxEnablePresenterScreen.clear();
301 m_pCbxUsePrinterMetrics.clear();
302 m_pCbxCompatibility.clear();
303 m_pScaleFrame.clear();
304 m_pCbScale.clear();
305 m_pNewDocLb.clear();
306 m_pFiInfo1.clear();
307 m_pMtrFldOriginalWidth.clear();
308 m_pWidthLb.clear();
309 m_pHeightLb.clear();
310 m_pFiInfo2.clear();
311 m_pMtrFldOriginalHeight.clear();
312 m_pCbxDistrot.clear();
313 m_pMtrFldInfo1.clear();
314 m_pMtrFldInfo2.clear();
315 SfxTabPage::dispose();
318 void SdTpOptionsMisc::ActivatePage( const SfxItemSet& rSet )
320 // We have to call SaveValue again since it can happen that the value
321 // has no effect on other TabPages
322 m_pLbMetric->SaveValue();
323 // change metric if necessary (since TabPage is in the Dialog where
324 // the metric is set)
325 const SfxPoolItem* pAttr = nullptr;
326 if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_METRIC , false,
327 &pAttr ))
329 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr);
331 FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<long>(pItem->GetValue()));
333 if( eFUnit != m_pMtrFldOriginalWidth->GetUnit() )
335 // set metrics
336 sal_Int64 nVal = m_pMtrFldOriginalWidth->Denormalize( m_pMtrFldOriginalWidth->GetValue( FUNIT_TWIP ) );
337 SetFieldUnit( *m_pMtrFldOriginalWidth, eFUnit, true );
338 m_pMtrFldOriginalWidth->SetValue( m_pMtrFldOriginalWidth->Normalize( nVal ), FUNIT_TWIP );
340 nVal = m_pMtrFldOriginalHeight->Denormalize( m_pMtrFldOriginalHeight->GetValue( FUNIT_TWIP ) );
341 SetFieldUnit( *m_pMtrFldOriginalHeight, eFUnit, true );
342 m_pMtrFldOriginalHeight->SetValue( m_pMtrFldOriginalHeight->Normalize( nVal ), FUNIT_TWIP );
344 if( nWidth != 0 && nHeight != 0 )
346 m_pMtrFldInfo1->SetUnit( eFUnit );
347 m_pMtrFldInfo2->SetUnit( eFUnit );
349 SetMetricValue( *m_pMtrFldInfo1, nWidth, ePoolUnit );
350 aInfo1 = m_pMtrFldInfo1->GetText();
351 m_pFiInfo1->SetText( aInfo1 );
353 SetMetricValue( *m_pMtrFldInfo2, nHeight, ePoolUnit );
354 aInfo2 = m_pMtrFldInfo2->GetText();
355 m_pFiInfo2->SetText( aInfo2 );
361 DeactivateRC SdTpOptionsMisc::DeactivatePage( SfxItemSet* pActiveSet )
363 // check parser
364 sal_Int32 nX, nY;
365 if( SetScale( m_pCbScale->GetText(), nX, nY ) )
367 if( pActiveSet )
368 FillItemSet( pActiveSet );
369 return DeactivateRC::LeavePage;
372 vcl::Window* pWin = GetParent();
373 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr,
374 VclMessageType::Warning, VclButtonsType::YesNo,
375 SdResId(STR_WARN_SCALE_FAIL)));
376 if (xWarn->run() == RET_YES)
377 return DeactivateRC::KeepPage;
379 if( pActiveSet )
380 FillItemSet( pActiveSet );
382 return DeactivateRC::LeavePage;
385 bool SdTpOptionsMisc::FillItemSet( SfxItemSet* rAttrs )
387 bool bModified = false;
389 if( m_pCbxStartWithTemplate->IsValueChangedFromSaved() ||
390 m_pCbxMarkedHitMovesAlways->IsValueChangedFromSaved() ||
391 m_pCbxQuickEdit->IsValueChangedFromSaved() ||
392 m_pCbxPickThrough->IsValueChangedFromSaved() ||
393 m_pCbxMasterPageCache->IsValueChangedFromSaved() ||
394 m_pCbxCopy->IsValueChangedFromSaved() ||
395 m_pCbxEnableSdremote->IsValueChangedFromSaved() ||
396 m_pCbxEnablePresenterScreen->IsValueChangedFromSaved() ||
397 m_pCbxCompatibility->IsValueChangedFromSaved() ||
398 m_pCbxUsePrinterMetrics->IsValueChangedFromSaved() )
400 SdOptionsMiscItem aOptsItem;
402 aOptsItem.GetOptionsMisc().SetStartWithTemplate( m_pCbxStartWithTemplate->IsChecked() );
403 aOptsItem.GetOptionsMisc().SetMarkedHitMovesAlways( m_pCbxMarkedHitMovesAlways->IsChecked() );
404 aOptsItem.GetOptionsMisc().SetQuickEdit( m_pCbxQuickEdit->IsChecked() );
405 aOptsItem.GetOptionsMisc().SetPickThrough( m_pCbxPickThrough->IsChecked() );
406 aOptsItem.GetOptionsMisc().SetMasterPagePaintCaching( m_pCbxMasterPageCache->IsChecked() );
407 aOptsItem.GetOptionsMisc().SetDragWithCopy( m_pCbxCopy->IsChecked() );
408 aOptsItem.GetOptionsMisc().SetEnableSdremote( m_pCbxEnableSdremote->IsChecked() );
409 aOptsItem.GetOptionsMisc().SetEnablePresenterScreen( m_pCbxEnablePresenterScreen->IsChecked() );
410 aOptsItem.GetOptionsMisc().SetSummationOfParagraphs( m_pCbxCompatibility->IsChecked() );
411 aOptsItem.GetOptionsMisc().SetPrinterIndependentLayout (
412 m_pCbxUsePrinterMetrics->IsChecked()
413 ? css::document::PrinterIndependentLayout::DISABLED
414 : css::document::PrinterIndependentLayout::ENABLED);
415 rAttrs->Put( aOptsItem );
417 bModified = true;
420 // metric
421 const sal_Int32 nMPos = m_pLbMetric->GetSelectedEntryPos();
422 if ( m_pLbMetric->IsValueChangedFromSaved() )
424 sal_uInt16 nFieldUnit = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(m_pLbMetric->GetEntryData( nMPos )));
425 rAttrs->Put( SfxUInt16Item( GetWhich( SID_ATTR_METRIC ), nFieldUnit ) );
426 bModified = true;
429 // tabulator space
430 if( m_pMtrFldTabstop->IsValueChangedFromSaved() )
432 sal_uInt16 nWh = GetWhich( SID_ATTR_DEFTABSTOP );
433 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWh );
434 SfxUInt16Item aDef( nWh,static_cast<sal_uInt16>(GetCoreValue( *m_pMtrFldTabstop, eUnit )) );
435 rAttrs->Put( aDef );
436 bModified = true;
439 sal_Int32 nX, nY;
440 if( SetScale( m_pCbScale->GetText(), nX, nY ) )
442 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
443 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
445 bModified = true;
448 return bModified;
451 void SdTpOptionsMisc::Reset( const SfxItemSet* rAttrs )
453 SdOptionsMiscItem aOptsItem( static_cast<const SdOptionsMiscItem&>( rAttrs->
454 Get( ATTR_OPTIONS_MISC ) ) );
456 m_pCbxStartWithTemplate->Check( aOptsItem.GetOptionsMisc().IsStartWithTemplate() );
457 m_pCbxMarkedHitMovesAlways->Check( aOptsItem.GetOptionsMisc().IsMarkedHitMovesAlways() );
458 m_pCbxQuickEdit->Check( aOptsItem.GetOptionsMisc().IsQuickEdit() );
459 m_pCbxPickThrough->Check( aOptsItem.GetOptionsMisc().IsPickThrough() );
460 m_pCbxMasterPageCache->Check( aOptsItem.GetOptionsMisc().IsMasterPagePaintCaching() );
461 m_pCbxCopy->Check( aOptsItem.GetOptionsMisc().IsDragWithCopy() );
462 m_pCbxEnableSdremote->Check( aOptsItem.GetOptionsMisc().IsEnableSdremote() );
463 m_pCbxEnablePresenterScreen->Check( aOptsItem.GetOptionsMisc().IsEnablePresenterScreen() );
464 m_pCbxCompatibility->Check( aOptsItem.GetOptionsMisc().IsSummationOfParagraphs() );
465 m_pCbxUsePrinterMetrics->Check( aOptsItem.GetOptionsMisc().GetPrinterIndependentLayout()==1 );
466 m_pCbxStartWithTemplate->SaveValue();
467 m_pCbxMarkedHitMovesAlways->SaveValue();
468 m_pCbxQuickEdit->SaveValue();
469 m_pCbxPickThrough->SaveValue();
471 m_pCbxMasterPageCache->SaveValue();
472 m_pCbxCopy->SaveValue();
473 m_pCbxEnableSdremote->SaveValue();
474 m_pCbxEnablePresenterScreen->SaveValue();
475 m_pCbxCompatibility->SaveValue();
476 m_pCbxUsePrinterMetrics->SaveValue();
478 // metric
479 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
480 m_pLbMetric->SetNoSelection();
482 if ( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT )
484 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich ));
485 long nFieldUnit = static_cast<long>(rItem.GetValue());
487 for ( sal_Int32 i = 0; i < m_pLbMetric->GetEntryCount(); ++i )
489 if ( reinterpret_cast<sal_IntPtr>(m_pLbMetric->GetEntryData( i )) == nFieldUnit )
491 m_pLbMetric->SelectEntryPos( i );
492 break;
497 // tabulator space
498 nWhich = GetWhich( SID_ATTR_DEFTABSTOP );
499 if( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT )
501 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWhich );
502 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich ));
503 SetMetricValue( *m_pMtrFldTabstop, rItem.GetValue(), eUnit );
505 m_pLbMetric->SaveValue();
506 m_pMtrFldTabstop->SaveValue();
507 //Scale
508 sal_Int32 nX = static_cast<const SfxInt32Item&>( rAttrs->
509 Get( ATTR_OPTIONS_SCALE_X ) ).GetValue();
510 sal_Int32 nY = static_cast<const SfxInt32Item&>( rAttrs->
511 Get( ATTR_OPTIONS_SCALE_Y ) ).GetValue();
512 nWidth = static_cast<const SfxUInt32Item&>( rAttrs->
513 Get( ATTR_OPTIONS_SCALE_WIDTH ) ).GetValue();
514 nHeight = static_cast<const SfxUInt32Item&>( rAttrs->
515 Get( ATTR_OPTIONS_SCALE_HEIGHT ) ).GetValue();
517 m_pCbScale->SetText( GetScale( nX, nY ) );
519 m_pMtrFldOriginalWidth->Hide();
520 m_pMtrFldOriginalWidth->SetText( aInfo1 ); // empty
521 m_pMtrFldOriginalHeight->Hide();
522 m_pMtrFldOriginalHeight->SetText( aInfo2 ); //empty
523 m_pFiInfo1->Hide();
524 m_pFiInfo2->Hide();
526 UpdateCompatibilityControls ();
529 VclPtr<SfxTabPage> SdTpOptionsMisc::Create( TabPageParent pWindow,
530 const SfxItemSet* rAttrs )
532 return VclPtr<SdTpOptionsMisc>::Create( pWindow.pParent, *rAttrs );
535 IMPL_LINK_NOARG(SdTpOptionsMisc, SelectMetricHdl_Impl, ListBox&, void)
537 sal_Int32 nPos = m_pLbMetric->GetSelectedEntryPos();
539 if( nPos != LISTBOX_ENTRY_NOTFOUND )
541 FieldUnit eUnit = static_cast<FieldUnit>(reinterpret_cast<sal_IntPtr>(m_pLbMetric->GetEntryData( nPos )));
542 sal_Int64 nVal =
543 m_pMtrFldTabstop->Denormalize( m_pMtrFldTabstop->GetValue( FUNIT_TWIP ) );
544 SetFieldUnit( *m_pMtrFldTabstop, eUnit );
545 m_pMtrFldTabstop->SetValue( m_pMtrFldTabstop->Normalize( nVal ), FUNIT_TWIP );
549 void SdTpOptionsMisc::SetImpressMode()
551 #ifndef ENABLE_SDREMOTE_BLUETOOTH
552 m_pCbxEnableSdremote->Hide();
553 #else
554 (void) this; // loplugin:staticmethods
555 #endif
558 void SdTpOptionsMisc::SetDrawMode()
560 m_pScaleFrame->Show();
561 m_pNewDocumentFrame->Hide();
562 m_pCbxEnableSdremote->Hide();
563 m_pCbxEnablePresenterScreen->Hide();
564 m_pCbxCompatibility->Hide();
565 m_pNewDocLb->Hide();
566 m_pCbScale->Show();
567 m_pPresentationFrame->Hide();
568 m_pMtrFldInfo1->Hide();
569 m_pMtrFldInfo2->Hide();
570 m_pWidthLb->Hide();
571 m_pHeightLb->Hide();
572 m_pFiInfo1->Show();
573 m_pMtrFldOriginalWidth->Show();
574 m_pFiInfo2->Show();
575 m_pMtrFldOriginalHeight->Show();
576 m_pCbxDistrot->Show();
577 m_pCbxCompatibility->Hide();
578 // Move the printer-independent-metrics check box in the place that the
579 // spacing-between-paragraphs check box normally is in.
580 m_pCbxUsePrinterMetrics->SetPosPixel (m_pCbxCompatibility->GetPosPixel());
583 OUString SdTpOptionsMisc::GetScale( sal_Int32 nX, sal_Int32 nY )
585 return OUString::number(nX) + OUStringLiteral1(TOKEN) + OUString::number(nY);
588 bool SdTpOptionsMisc::SetScale( const OUString& aScale, sal_Int32& rX, sal_Int32& rY )
590 if( comphelper::string::getTokenCount(aScale, TOKEN) != 2 )
591 return false;
593 OUString aTmp(aScale.getToken(0, TOKEN));
594 if (!comphelper::string::isdigitAsciiString(aTmp))
595 return false;
597 rX = static_cast<long>(aTmp.toInt32());
598 if( rX == 0 )
599 return false;
601 aTmp = aScale.getToken(1, TOKEN);
602 if (!comphelper::string::isdigitAsciiString(aTmp))
603 return false;
605 rY = static_cast<long>(aTmp.toInt32());
606 return rY != 0;
609 void SdTpOptionsMisc::UpdateCompatibilityControls()
611 // Disable the compatibility controls by default. Enable them only when
612 // there is at least one open document.
613 bool bIsEnabled = false;
617 // Get a component enumeration from the desktop and search it for documents.
618 Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext());
621 Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
623 Reference<container::XEnumerationAccess> xComponents (
624 xDesktop->getComponents(), UNO_QUERY);
625 if ( ! xComponents.is())
626 break;
628 Reference<container::XEnumeration> xEnumeration (
629 xComponents->createEnumeration());
630 if ( ! xEnumeration.is())
631 break;
633 while (xEnumeration->hasMoreElements())
635 Reference<frame::XModel> xModel (xEnumeration->nextElement(), UNO_QUERY);
636 if (xModel.is())
638 // There is at least one model/document: Enable the compatibility controls.
639 bIsEnabled = true;
640 break;
645 while (false); // One 'loop'.
647 catch (const uno::Exception&)
649 // When there is an exception then simply use the default value of
650 // bIsEnabled and disable the controls.
653 m_pCbxCompatibility->Enable(bIsEnabled);
654 m_pCbxUsePrinterMetrics->Enable (bIsEnabled);
657 void SdTpOptionsMisc::PageCreated(const SfxAllItemSet& aSet)
659 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false);
660 if (pFlagItem)
662 sal_uInt32 nFlags=pFlagItem->GetValue();
663 if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
664 SetDrawMode();
665 if ( ( nFlags & SD_IMPRESS_MODE ) == SD_IMPRESS_MODE )
666 SetImpressMode();
670 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */