bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / tpoption.cxx
blob71f7017e0154676d561cee543f92d57356644e68
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/frame/Desktop.hpp>
22 #include <com/sun/star/container/XEnumerationAccess.hpp>
23 #include <comphelper/processfactory.hxx>
24 #include <comphelper/string.hxx>
25 #include <com/sun/star/uno/Exception.hpp>
26 #include <sfx2/module.hxx>
27 #include <svx/svxids.hrc>
28 #include <svx/strarray.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/weld.hxx>
31 #include <svtools/unitconv.hxx>
33 #include <sdattr.hrc>
34 #include <sdresid.hxx>
35 #include <optsitem.hxx>
36 #include <tpoption.hxx>
37 #include <strings.hrc>
38 #include <app.hrc>
39 #include <svl/intitem.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
44 SdTpOptionsSnap::SdTpOptionsSnap(TabPageParent pParent, const SfxItemSet& rInAttrs)
45 : SvxGridTabPage(pParent, rInAttrs)
47 m_xSnapFrames->show();
50 SdTpOptionsSnap::~SdTpOptionsSnap()
54 bool SdTpOptionsSnap::FillItemSet( SfxItemSet* rAttrs )
56 SvxGridTabPage::FillItemSet(rAttrs);
57 SdOptionsSnapItem aOptsItem;
59 aOptsItem.GetOptionsSnap().SetSnapHelplines( m_xCbxSnapHelplines->get_active() );
60 aOptsItem.GetOptionsSnap().SetSnapBorder( m_xCbxSnapBorder->get_active() );
61 aOptsItem.GetOptionsSnap().SetSnapFrame( m_xCbxSnapFrame->get_active() );
62 aOptsItem.GetOptionsSnap().SetSnapPoints( m_xCbxSnapPoints->get_active() );
63 aOptsItem.GetOptionsSnap().SetOrtho( m_xCbxOrtho->get_active() );
64 aOptsItem.GetOptionsSnap().SetBigOrtho( m_xCbxBigOrtho->get_active() );
65 aOptsItem.GetOptionsSnap().SetRotate( m_xCbxRotate->get_active() );
66 aOptsItem.GetOptionsSnap().SetSnapArea(static_cast<sal_Int16>(m_xMtrFldSnapArea->get_value(FieldUnit::PIXEL)));
67 aOptsItem.GetOptionsSnap().SetAngle(static_cast<sal_Int16>(m_xMtrFldAngle->get_value(FieldUnit::DEGREE)));
68 aOptsItem.GetOptionsSnap().SetEliminatePolyPointLimitAngle(static_cast<sal_Int16>(m_xMtrFldBezAngle->get_value(FieldUnit::DEGREE)));
70 rAttrs->Put( aOptsItem );
72 // we get a possible existing GridItem, this ensures that we do not set
73 // some default values by accident
74 return true;
77 void SdTpOptionsSnap::Reset( const SfxItemSet* rAttrs )
79 SvxGridTabPage::Reset(rAttrs);
81 SdOptionsSnapItem aOptsItem( static_cast<const SdOptionsSnapItem&>( rAttrs->
82 Get( ATTR_OPTIONS_SNAP ) ) );
84 m_xCbxSnapHelplines->set_active( aOptsItem.GetOptionsSnap().IsSnapHelplines() );
85 m_xCbxSnapBorder->set_active( aOptsItem.GetOptionsSnap().IsSnapBorder() );
86 m_xCbxSnapFrame->set_active( aOptsItem.GetOptionsSnap().IsSnapFrame() );
87 m_xCbxSnapPoints->set_active( aOptsItem.GetOptionsSnap().IsSnapPoints() );
88 m_xCbxOrtho->set_active( aOptsItem.GetOptionsSnap().IsOrtho() );
89 m_xCbxBigOrtho->set_active( aOptsItem.GetOptionsSnap().IsBigOrtho() );
90 m_xCbxRotate->set_active( aOptsItem.GetOptionsSnap().IsRotate() );
91 m_xMtrFldSnapArea->set_value(aOptsItem.GetOptionsSnap().GetSnapArea(), FieldUnit::PIXEL);
92 m_xMtrFldAngle->set_value(aOptsItem.GetOptionsSnap().GetAngle(), FieldUnit::DEGREE);
93 m_xMtrFldBezAngle->set_value(aOptsItem.GetOptionsSnap().GetEliminatePolyPointLimitAngle(), FieldUnit::DEGREE);
95 ClickRotateHdl_Impl(*m_xCbxRotate);
98 VclPtr<SfxTabPage> SdTpOptionsSnap::Create( TabPageParent pWindow,
99 const SfxItemSet* rAttrs )
101 return VclPtr<SdTpOptionsSnap>::Create(pWindow, *rAttrs);
104 /*************************************************************************
106 |* TabPage to adjust the content options
108 \************************************************************************/
110 SdTpOptionsContents::SdTpOptionsContents( vcl::Window* pParent, const SfxItemSet& rInAttrs ) :
111 SfxTabPage ( pParent, "SdViewPage", "modules/simpress/ui/sdviewpage.ui", &rInAttrs )
113 get( m_pCbxRuler, "ruler");
114 get( m_pCbxDragStripes, "dragstripes");
115 get( m_pCbxHandlesBezier, "handlesbezier");
116 get( m_pCbxMoveOutline, "moveoutline");
119 SdTpOptionsContents::~SdTpOptionsContents()
121 disposeOnce();
124 void SdTpOptionsContents::dispose()
126 m_pCbxRuler.clear();
127 m_pCbxDragStripes.clear();
128 m_pCbxHandlesBezier.clear();
129 m_pCbxMoveOutline.clear();
130 SfxTabPage::dispose();
133 bool SdTpOptionsContents::FillItemSet( SfxItemSet* rAttrs )
135 bool bModified = false;
137 if( m_pCbxRuler->IsValueChangedFromSaved() ||
138 m_pCbxMoveOutline->IsValueChangedFromSaved() ||
139 m_pCbxDragStripes->IsValueChangedFromSaved() ||
140 m_pCbxHandlesBezier->IsValueChangedFromSaved() )
142 SdOptionsLayoutItem aOptsItem;
144 aOptsItem.GetOptionsLayout().SetRulerVisible( m_pCbxRuler->IsChecked() );
145 aOptsItem.GetOptionsLayout().SetMoveOutline( m_pCbxMoveOutline->IsChecked() );
146 aOptsItem.GetOptionsLayout().SetDragStripes( m_pCbxDragStripes->IsChecked() );
147 aOptsItem.GetOptionsLayout().SetHandlesBezier( m_pCbxHandlesBezier->IsChecked() );
149 rAttrs->Put( aOptsItem );
150 bModified = true;
152 return bModified;
155 void SdTpOptionsContents::Reset( const SfxItemSet* rAttrs )
157 SdOptionsLayoutItem aLayoutItem( static_cast<const SdOptionsLayoutItem&>( rAttrs->
158 Get( ATTR_OPTIONS_LAYOUT ) ) );
160 m_pCbxRuler->Check( aLayoutItem.GetOptionsLayout().IsRulerVisible() );
161 m_pCbxMoveOutline->Check( aLayoutItem.GetOptionsLayout().IsMoveOutline() );
162 m_pCbxDragStripes->Check( aLayoutItem.GetOptionsLayout().IsDragStripes() );
163 m_pCbxHandlesBezier->Check( aLayoutItem.GetOptionsLayout().IsHandlesBezier() );
165 m_pCbxRuler->SaveValue();
166 m_pCbxMoveOutline->SaveValue();
167 m_pCbxDragStripes->SaveValue();
168 m_pCbxHandlesBezier->SaveValue();
171 VclPtr<SfxTabPage> SdTpOptionsContents::Create( TabPageParent pWindow,
172 const SfxItemSet* rAttrs )
174 return VclPtr<SdTpOptionsContents>::Create( pWindow.pParent, *rAttrs );
177 /*************************************************************************
179 |* TabPage to adjust the misc options
181 \************************************************************************/
182 #define TABLE_COUNT 12
183 #define TOKEN ':'
185 SdTpOptionsMisc::SdTpOptionsMisc(vcl::Window* pParent, const SfxItemSet& rInAttrs)
186 : SfxTabPage(pParent, "OptSavePage", "modules/simpress/ui/optimpressgeneralpage.ui", &rInAttrs)
187 , nWidth(0)
188 , nHeight(0)
190 get(m_pCbxQuickEdit , "qickedit");
191 get(m_pCbxPickThrough , "textselected");
192 get(m_pNewDocumentFrame, "newdocumentframe");
193 get(m_pCbxStartWithTemplate,"startwithwizard");
194 get(m_pCbxMasterPageCache , "backgroundback");
195 get(m_pCbxCopy , "copywhenmove");
196 get(m_pCbxMarkedHitMovesAlways , "objalwymov");
197 get(m_pLbMetric , "units");
198 get(m_pCbxEnableSdremote , "enremotcont");
199 get(m_pCbxEnablePresenterScreen , "enprsntcons");
200 get(m_pCbxUsePrinterMetrics , "printermetrics");
201 get(m_pPresentationFrame , "presentationframe");
202 get(m_pScaleFrame , "scaleframe");
203 get(m_pCbScale , "scaleBox");
204 get(m_pMtrFldTabstop , "metricFields");
205 get(m_pMtrFldOriginalWidth , "metricWidthFields");
206 get(m_pMtrFldOriginalHeight , "metricHeightFields");
207 get(m_pMtrFldInfo1 , "metricInfo1Fields");
208 get(m_pMtrFldInfo2 , "metricInfo2Fields");
209 get(m_pCbxCompatibility ,"cbCompatibility" );
210 get(m_pFiInfo1 , "info1");
211 get(m_pFiInfo2 , "info2");
212 get(m_pNewDocLb , "newdoclbl");
213 get(m_pWidthLb , "widthlbl");
214 get(m_pHeightLb , "heightlbl");
215 get(m_pCbxDistrot , "distrotcb");
217 SetExchangeSupport();
219 // set metric
220 FieldUnit eFUnit;
222 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
223 if ( rInAttrs.GetItemState( nWhich ) >= SfxItemState::DEFAULT )
225 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rInAttrs.Get( nWhich ));
226 eFUnit = static_cast<FieldUnit>(rItem.GetValue());
228 else
229 eFUnit = SfxModule::GetCurrentFieldUnit();
231 SetFieldUnit( *m_pMtrFldTabstop , eFUnit );
233 // Impress is default mode, let' hide the entire scale frame etc.
234 m_pCbxDistrot->Hide();
235 m_pScaleFrame->Hide();
237 // fill ListBox with metrics
238 for (sal_uInt32 i = 0; i < SvxFieldUnitTable::Count(); ++i)
240 OUString sMetric = SvxFieldUnitTable::GetString(i);
241 sal_IntPtr nFieldUnit = sal_uInt16(SvxFieldUnitTable::GetValue(i));
242 sal_Int32 nPos = m_pLbMetric->InsertEntry( sMetric );
243 m_pLbMetric->SetEntryData( nPos, reinterpret_cast<void*>(nFieldUnit) );
245 m_pLbMetric->SetSelectHdl( LINK( this, SdTpOptionsMisc, SelectMetricHdl_Impl ) );
247 SetFieldUnit( *m_pMtrFldOriginalWidth, eFUnit );
248 SetFieldUnit( *m_pMtrFldOriginalHeight, eFUnit );
249 m_pMtrFldOriginalWidth->SetLast( 999999999 );
250 m_pMtrFldOriginalWidth->SetMax( 999999999 );
251 m_pMtrFldOriginalHeight->SetLast( 999999999 );
252 m_pMtrFldOriginalHeight->SetMax( 999999999 );
254 // temporary fields for info texts (for formatting/calculation)
255 m_pMtrFldInfo1->SetUnit( eFUnit );
256 m_pMtrFldInfo1->SetMax( 999999999 );
257 m_pMtrFldInfo1->SetDecimalDigits( 2 );
258 m_pMtrFldInfo2->SetUnit( eFUnit );
259 m_pMtrFldInfo2->SetMax( 999999999 );
260 m_pMtrFldInfo2->SetDecimalDigits( 2 );
262 // determine PoolUnit
263 SfxItemPool* pPool = rInAttrs.GetPool();
264 DBG_ASSERT( pPool, "Where is the Pool?" );
265 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
267 // Fill the CB
268 sal_uInt16 aTable[ TABLE_COUNT ] =
269 { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
271 for( sal_uInt16 i = 0; i < TABLE_COUNT; i++ )
272 m_pCbScale->InsertEntry( GetScale( 1, aTable[i] ) );
273 for( sal_uInt16 i = 1; i < TABLE_COUNT; i++ )
274 m_pCbScale->InsertEntry( GetScale( aTable[i], 1 ) );
277 SdTpOptionsMisc::~SdTpOptionsMisc()
279 disposeOnce();
282 void SdTpOptionsMisc::dispose()
284 m_pCbxQuickEdit.clear();
285 m_pCbxPickThrough.clear();
286 m_pNewDocumentFrame.clear();
287 m_pCbxStartWithTemplate.clear();
288 m_pCbxMasterPageCache.clear();
289 m_pCbxCopy.clear();
290 m_pCbxMarkedHitMovesAlways.clear();
291 m_pPresentationFrame.clear();
292 m_pLbMetric.clear();
293 m_pMtrFldTabstop.clear();
294 m_pCbxEnableSdremote.clear();
295 m_pCbxEnablePresenterScreen.clear();
296 m_pCbxUsePrinterMetrics.clear();
297 m_pCbxCompatibility.clear();
298 m_pScaleFrame.clear();
299 m_pCbScale.clear();
300 m_pNewDocLb.clear();
301 m_pFiInfo1.clear();
302 m_pMtrFldOriginalWidth.clear();
303 m_pWidthLb.clear();
304 m_pHeightLb.clear();
305 m_pFiInfo2.clear();
306 m_pMtrFldOriginalHeight.clear();
307 m_pCbxDistrot.clear();
308 m_pMtrFldInfo1.clear();
309 m_pMtrFldInfo2.clear();
310 SfxTabPage::dispose();
313 void SdTpOptionsMisc::ActivatePage( const SfxItemSet& rSet )
315 // We have to call SaveValue again since it can happen that the value
316 // has no effect on other TabPages
317 m_pLbMetric->SaveValue();
318 // change metric if necessary (since TabPage is in the Dialog where
319 // the metric is set)
320 const SfxPoolItem* pAttr = nullptr;
321 if( SfxItemState::SET != rSet.GetItemState( SID_ATTR_METRIC , false,
322 &pAttr ))
323 return;
325 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr);
327 FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<long>(pItem->GetValue()));
329 if( eFUnit == m_pMtrFldOriginalWidth->GetUnit() )
330 return;
332 // set metrics
333 sal_Int64 nVal = m_pMtrFldOriginalWidth->Denormalize( m_pMtrFldOriginalWidth->GetValue( FieldUnit::TWIP ) );
334 SetFieldUnit( *m_pMtrFldOriginalWidth, eFUnit, true );
335 m_pMtrFldOriginalWidth->SetValue( m_pMtrFldOriginalWidth->Normalize( nVal ), FieldUnit::TWIP );
337 nVal = m_pMtrFldOriginalHeight->Denormalize( m_pMtrFldOriginalHeight->GetValue( FieldUnit::TWIP ) );
338 SetFieldUnit( *m_pMtrFldOriginalHeight, eFUnit, true );
339 m_pMtrFldOriginalHeight->SetValue( m_pMtrFldOriginalHeight->Normalize( nVal ), FieldUnit::TWIP );
341 if( nWidth == 0 || nHeight == 0 )
342 return;
344 m_pMtrFldInfo1->SetUnit( eFUnit );
345 m_pMtrFldInfo2->SetUnit( eFUnit );
347 SetMetricValue( *m_pMtrFldInfo1, nWidth, ePoolUnit );
348 aInfo1 = m_pMtrFldInfo1->GetText();
349 m_pFiInfo1->SetText( aInfo1 );
351 SetMetricValue( *m_pMtrFldInfo2, nHeight, ePoolUnit );
352 aInfo2 = m_pMtrFldInfo2->GetText();
353 m_pFiInfo2->SetText( aInfo2 );
356 DeactivateRC SdTpOptionsMisc::DeactivatePage( SfxItemSet* pActiveSet )
358 // check parser
359 sal_Int32 nX, nY;
360 if( SetScale( m_pCbScale->GetText(), nX, nY ) )
362 if( pActiveSet )
363 FillItemSet( pActiveSet );
364 return DeactivateRC::LeavePage;
367 vcl::Window* pWin = GetParent();
368 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr,
369 VclMessageType::Warning, VclButtonsType::YesNo,
370 SdResId(STR_WARN_SCALE_FAIL)));
371 if (xWarn->run() == RET_YES)
372 return DeactivateRC::KeepPage;
374 if( pActiveSet )
375 FillItemSet( pActiveSet );
377 return DeactivateRC::LeavePage;
380 bool SdTpOptionsMisc::FillItemSet( SfxItemSet* rAttrs )
382 bool bModified = false;
384 if( m_pCbxStartWithTemplate->IsValueChangedFromSaved() ||
385 m_pCbxMarkedHitMovesAlways->IsValueChangedFromSaved() ||
386 m_pCbxQuickEdit->IsValueChangedFromSaved() ||
387 m_pCbxPickThrough->IsValueChangedFromSaved() ||
388 m_pCbxMasterPageCache->IsValueChangedFromSaved() ||
389 m_pCbxCopy->IsValueChangedFromSaved() ||
390 m_pCbxEnableSdremote->IsValueChangedFromSaved() ||
391 m_pCbxEnablePresenterScreen->IsValueChangedFromSaved() ||
392 m_pCbxCompatibility->IsValueChangedFromSaved() ||
393 m_pCbxUsePrinterMetrics->IsValueChangedFromSaved() )
395 SdOptionsMiscItem aOptsItem;
397 aOptsItem.GetOptionsMisc().SetStartWithTemplate( m_pCbxStartWithTemplate->IsChecked() );
398 aOptsItem.GetOptionsMisc().SetMarkedHitMovesAlways( m_pCbxMarkedHitMovesAlways->IsChecked() );
399 aOptsItem.GetOptionsMisc().SetQuickEdit( m_pCbxQuickEdit->IsChecked() );
400 aOptsItem.GetOptionsMisc().SetPickThrough( m_pCbxPickThrough->IsChecked() );
401 aOptsItem.GetOptionsMisc().SetMasterPagePaintCaching( m_pCbxMasterPageCache->IsChecked() );
402 aOptsItem.GetOptionsMisc().SetDragWithCopy( m_pCbxCopy->IsChecked() );
403 aOptsItem.GetOptionsMisc().SetEnableSdremote( m_pCbxEnableSdremote->IsChecked() );
404 aOptsItem.GetOptionsMisc().SetEnablePresenterScreen( m_pCbxEnablePresenterScreen->IsChecked() );
405 aOptsItem.GetOptionsMisc().SetSummationOfParagraphs( m_pCbxCompatibility->IsChecked() );
406 aOptsItem.GetOptionsMisc().SetPrinterIndependentLayout (
407 m_pCbxUsePrinterMetrics->IsChecked()
408 ? css::document::PrinterIndependentLayout::DISABLED
409 : css::document::PrinterIndependentLayout::ENABLED);
410 rAttrs->Put( aOptsItem );
412 bModified = true;
415 // metric
416 const sal_Int32 nMPos = m_pLbMetric->GetSelectedEntryPos();
417 if ( m_pLbMetric->IsValueChangedFromSaved() )
419 sal_uInt16 nFieldUnit = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(m_pLbMetric->GetEntryData( nMPos )));
420 rAttrs->Put( SfxUInt16Item( GetWhich( SID_ATTR_METRIC ), nFieldUnit ) );
421 bModified = true;
424 // tabulator space
425 if( m_pMtrFldTabstop->IsValueChangedFromSaved() )
427 sal_uInt16 nWh = GetWhich( SID_ATTR_DEFTABSTOP );
428 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWh );
429 SfxUInt16Item aDef( nWh,static_cast<sal_uInt16>(GetCoreValue( *m_pMtrFldTabstop, eUnit )) );
430 rAttrs->Put( aDef );
431 bModified = true;
434 sal_Int32 nX, nY;
435 if( SetScale( m_pCbScale->GetText(), nX, nY ) )
437 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
438 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
440 bModified = true;
443 return bModified;
446 void SdTpOptionsMisc::Reset( const SfxItemSet* rAttrs )
448 SdOptionsMiscItem aOptsItem( static_cast<const SdOptionsMiscItem&>( rAttrs->
449 Get( ATTR_OPTIONS_MISC ) ) );
451 m_pCbxStartWithTemplate->Check( aOptsItem.GetOptionsMisc().IsStartWithTemplate() );
452 m_pCbxMarkedHitMovesAlways->Check( aOptsItem.GetOptionsMisc().IsMarkedHitMovesAlways() );
453 m_pCbxQuickEdit->Check( aOptsItem.GetOptionsMisc().IsQuickEdit() );
454 m_pCbxPickThrough->Check( aOptsItem.GetOptionsMisc().IsPickThrough() );
455 m_pCbxMasterPageCache->Check( aOptsItem.GetOptionsMisc().IsMasterPagePaintCaching() );
456 m_pCbxCopy->Check( aOptsItem.GetOptionsMisc().IsDragWithCopy() );
457 m_pCbxEnableSdremote->Check( aOptsItem.GetOptionsMisc().IsEnableSdremote() );
458 m_pCbxEnablePresenterScreen->Check( aOptsItem.GetOptionsMisc().IsEnablePresenterScreen() );
459 m_pCbxCompatibility->Check( aOptsItem.GetOptionsMisc().IsSummationOfParagraphs() );
460 m_pCbxUsePrinterMetrics->Check( aOptsItem.GetOptionsMisc().GetPrinterIndependentLayout()==1 );
461 m_pCbxStartWithTemplate->SaveValue();
462 m_pCbxMarkedHitMovesAlways->SaveValue();
463 m_pCbxQuickEdit->SaveValue();
464 m_pCbxPickThrough->SaveValue();
466 m_pCbxMasterPageCache->SaveValue();
467 m_pCbxCopy->SaveValue();
468 m_pCbxEnableSdremote->SaveValue();
469 m_pCbxEnablePresenterScreen->SaveValue();
470 m_pCbxCompatibility->SaveValue();
471 m_pCbxUsePrinterMetrics->SaveValue();
473 // metric
474 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
475 m_pLbMetric->SetNoSelection();
477 if ( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT )
479 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich ));
480 long nFieldUnit = static_cast<long>(rItem.GetValue());
482 for ( sal_Int32 i = 0; i < m_pLbMetric->GetEntryCount(); ++i )
484 if ( reinterpret_cast<sal_IntPtr>(m_pLbMetric->GetEntryData( i )) == nFieldUnit )
486 m_pLbMetric->SelectEntryPos( i );
487 break;
492 // tabulator space
493 nWhich = GetWhich( SID_ATTR_DEFTABSTOP );
494 if( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT )
496 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWhich );
497 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich ));
498 SetMetricValue( *m_pMtrFldTabstop, rItem.GetValue(), eUnit );
500 m_pLbMetric->SaveValue();
501 m_pMtrFldTabstop->SaveValue();
502 //Scale
503 sal_Int32 nX = static_cast<const SfxInt32Item&>( rAttrs->
504 Get( ATTR_OPTIONS_SCALE_X ) ).GetValue();
505 sal_Int32 nY = static_cast<const SfxInt32Item&>( rAttrs->
506 Get( ATTR_OPTIONS_SCALE_Y ) ).GetValue();
507 nWidth = static_cast<const SfxUInt32Item&>( rAttrs->
508 Get( ATTR_OPTIONS_SCALE_WIDTH ) ).GetValue();
509 nHeight = static_cast<const SfxUInt32Item&>( rAttrs->
510 Get( ATTR_OPTIONS_SCALE_HEIGHT ) ).GetValue();
512 m_pCbScale->SetText( GetScale( nX, nY ) );
514 m_pMtrFldOriginalWidth->Hide();
515 m_pMtrFldOriginalWidth->SetText( aInfo1 ); // empty
516 m_pMtrFldOriginalHeight->Hide();
517 m_pMtrFldOriginalHeight->SetText( aInfo2 ); //empty
518 m_pFiInfo1->Hide();
519 m_pFiInfo2->Hide();
521 UpdateCompatibilityControls ();
524 VclPtr<SfxTabPage> SdTpOptionsMisc::Create( TabPageParent pWindow,
525 const SfxItemSet* rAttrs )
527 return VclPtr<SdTpOptionsMisc>::Create( pWindow.pParent, *rAttrs );
530 IMPL_LINK_NOARG(SdTpOptionsMisc, SelectMetricHdl_Impl, ListBox&, void)
532 sal_Int32 nPos = m_pLbMetric->GetSelectedEntryPos();
534 if( nPos != LISTBOX_ENTRY_NOTFOUND )
536 FieldUnit eUnit = static_cast<FieldUnit>(reinterpret_cast<sal_IntPtr>(m_pLbMetric->GetEntryData( nPos )));
537 sal_Int64 nVal =
538 m_pMtrFldTabstop->Denormalize( m_pMtrFldTabstop->GetValue( FieldUnit::TWIP ) );
539 SetFieldUnit( *m_pMtrFldTabstop, eUnit );
540 m_pMtrFldTabstop->SetValue( m_pMtrFldTabstop->Normalize( nVal ), FieldUnit::TWIP );
544 void SdTpOptionsMisc::SetImpressMode()
546 #ifndef ENABLE_SDREMOTE_BLUETOOTH
547 m_pCbxEnableSdremote->Hide();
548 #else
549 (void) this; // loplugin:staticmethods
550 #endif
553 void SdTpOptionsMisc::SetDrawMode()
555 m_pScaleFrame->Show();
556 m_pNewDocumentFrame->Hide();
557 m_pCbxEnableSdremote->Hide();
558 m_pCbxEnablePresenterScreen->Hide();
559 m_pCbxCompatibility->Hide();
560 m_pNewDocLb->Hide();
561 m_pCbScale->Show();
562 m_pPresentationFrame->Hide();
563 m_pMtrFldInfo1->Hide();
564 m_pMtrFldInfo2->Hide();
565 m_pWidthLb->Hide();
566 m_pHeightLb->Hide();
567 m_pFiInfo1->Show();
568 m_pMtrFldOriginalWidth->Show();
569 m_pFiInfo2->Show();
570 m_pMtrFldOriginalHeight->Show();
571 m_pCbxDistrot->Show();
572 m_pCbxCompatibility->Hide();
573 // Move the printer-independent-metrics check box in the place that the
574 // spacing-between-paragraphs check box normally is in.
575 m_pCbxUsePrinterMetrics->SetPosPixel (m_pCbxCompatibility->GetPosPixel());
578 OUString SdTpOptionsMisc::GetScale( sal_Int32 nX, sal_Int32 nY )
580 return OUString::number(nX) + OUStringLiteral1(TOKEN) + OUString::number(nY);
583 bool SdTpOptionsMisc::SetScale( const OUString& aScale, sal_Int32& rX, sal_Int32& rY )
585 if (aScale.isEmpty())
586 return false;
588 sal_Int32 nIdx {0};
590 OUString aTmp(aScale.getToken(0, TOKEN, nIdx));
591 if (nIdx<0)
592 return false; // we expect another 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(0, TOKEN, nIdx);
602 if (nIdx>=0)
603 return false; // we require just 2 tokens!
605 if (!comphelper::string::isdigitAsciiString(aTmp))
606 return false;
608 rY = static_cast<long>(aTmp.toInt32());
609 return rY != 0;
612 void SdTpOptionsMisc::UpdateCompatibilityControls()
614 // Disable the compatibility controls by default. Enable them only when
615 // there is at least one open document.
616 bool bIsEnabled = false;
620 // Get a component enumeration from the desktop and search it for documents.
621 Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext());
624 Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
626 Reference<container::XEnumerationAccess> xComponents (
627 xDesktop->getComponents(), UNO_QUERY);
628 if ( ! xComponents.is())
629 break;
631 Reference<container::XEnumeration> xEnumeration (
632 xComponents->createEnumeration());
633 if ( ! xEnumeration.is())
634 break;
636 while (xEnumeration->hasMoreElements())
638 Reference<frame::XModel> xModel (xEnumeration->nextElement(), UNO_QUERY);
639 if (xModel.is())
641 // There is at least one model/document: Enable the compatibility controls.
642 bIsEnabled = true;
643 break;
648 while (false); // One 'loop'.
650 catch (const uno::Exception&)
652 // When there is an exception then simply use the default value of
653 // bIsEnabled and disable the controls.
656 m_pCbxCompatibility->Enable(bIsEnabled);
657 m_pCbxUsePrinterMetrics->Enable (bIsEnabled);
660 void SdTpOptionsMisc::PageCreated(const SfxAllItemSet& aSet)
662 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false);
663 if (pFlagItem)
665 sal_uInt32 nFlags=pFlagItem->GetValue();
666 if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
667 SetDrawMode();
668 if ( ( nFlags & SD_IMPRESS_MODE ) == SD_IMPRESS_MODE )
669 SetImpressMode();
673 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */