Update git submodules
[LibreOffice.git] / sd / source / ui / dlg / tpoption.cxx
blob3d214f56df7253be5997ad7bbb934b68ae19c2a9
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>
40 #include <o3tl/string_view.hxx>
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
45 SdTpOptionsSnap::SdTpOptionsSnap(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
46 : SvxGridTabPage(pPage, pController, rInAttrs)
48 m_xSnapFrames->show();
51 SdTpOptionsSnap::~SdTpOptionsSnap()
55 bool SdTpOptionsSnap::FillItemSet( SfxItemSet* rAttrs )
57 SvxGridTabPage::FillItemSet(rAttrs);
58 SdOptionsSnapItem aOptsItem;
60 aOptsItem.GetOptionsSnap().SetSnapHelplines( m_xCbxSnapHelplines->get_active() );
61 aOptsItem.GetOptionsSnap().SetSnapBorder( m_xCbxSnapBorder->get_active() );
62 aOptsItem.GetOptionsSnap().SetSnapFrame( m_xCbxSnapFrame->get_active() );
63 aOptsItem.GetOptionsSnap().SetSnapPoints( m_xCbxSnapPoints->get_active() );
64 aOptsItem.GetOptionsSnap().SetOrtho( m_xCbxOrtho->get_active() );
65 aOptsItem.GetOptionsSnap().SetBigOrtho( m_xCbxBigOrtho->get_active() );
66 aOptsItem.GetOptionsSnap().SetRotate( m_xCbxRotate->get_active() );
67 aOptsItem.GetOptionsSnap().SetSnapArea(static_cast<sal_Int16>(m_xMtrFldSnapArea->get_value(FieldUnit::PIXEL)));
68 aOptsItem.GetOptionsSnap().SetAngle(Degree100(m_xMtrFldAngle->get_value(FieldUnit::DEGREE)));
69 aOptsItem.GetOptionsSnap().SetEliminatePolyPointLimitAngle(Degree100(m_xMtrFldBezAngle->get_value(FieldUnit::DEGREE)));
71 rAttrs->Put( aOptsItem );
73 // we get a possible existing GridItem, this ensures that we do not set
74 // some default values by accident
75 return true;
78 void SdTpOptionsSnap::Reset( const SfxItemSet* rAttrs )
80 SvxGridTabPage::Reset(rAttrs);
82 SdOptionsSnapItem aOptsItem( rAttrs->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().get(), FieldUnit::DEGREE);
93 m_xMtrFldBezAngle->set_value(aOptsItem.GetOptionsSnap().GetEliminatePolyPointLimitAngle().get(), FieldUnit::DEGREE);
95 ClickRotateHdl_Impl(*m_xCbxRotate);
98 std::unique_ptr<SfxTabPage> SdTpOptionsSnap::Create( weld::Container* pPage, weld::DialogController* pController,
99 const SfxItemSet* rAttrs )
101 return std::make_unique<SdTpOptionsSnap>(pPage, pController, *rAttrs);
104 /*************************************************************************
106 |* TabPage to adjust the content options
108 \************************************************************************/
109 SdTpOptionsContents::SdTpOptionsContents(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
110 : SfxTabPage(pPage, pController, "modules/simpress/ui/sdviewpage.ui", "SdViewPage", &rInAttrs)
111 , m_xCbxRuler(m_xBuilder->weld_check_button("ruler"))
112 , m_xCbxDragStripes(m_xBuilder->weld_check_button("dragstripes"))
113 , m_xCbxHandlesBezier(m_xBuilder->weld_check_button("handlesbezier"))
114 , m_xCbxMoveOutline(m_xBuilder->weld_check_button("moveoutline"))
118 SdTpOptionsContents::~SdTpOptionsContents()
122 bool SdTpOptionsContents::FillItemSet( SfxItemSet* rAttrs )
124 bool bModified = false;
126 if( m_xCbxRuler->get_state_changed_from_saved() ||
127 m_xCbxMoveOutline->get_state_changed_from_saved() ||
128 m_xCbxDragStripes->get_state_changed_from_saved() ||
129 m_xCbxHandlesBezier->get_state_changed_from_saved() )
131 SdOptionsLayoutItem aOptsItem;
133 aOptsItem.GetOptionsLayout().SetRulerVisible( m_xCbxRuler->get_active() );
134 aOptsItem.GetOptionsLayout().SetMoveOutline( m_xCbxMoveOutline->get_active() );
135 aOptsItem.GetOptionsLayout().SetDragStripes( m_xCbxDragStripes->get_active() );
136 aOptsItem.GetOptionsLayout().SetHandlesBezier( m_xCbxHandlesBezier->get_active() );
138 rAttrs->Put( aOptsItem );
139 bModified = true;
141 return bModified;
144 void SdTpOptionsContents::Reset( const SfxItemSet* rAttrs )
146 SdOptionsLayoutItem aLayoutItem( rAttrs->Get( ATTR_OPTIONS_LAYOUT ) );
148 m_xCbxRuler->set_active( aLayoutItem.GetOptionsLayout().IsRulerVisible() );
149 m_xCbxMoveOutline->set_active( aLayoutItem.GetOptionsLayout().IsMoveOutline() );
150 m_xCbxDragStripes->set_active( aLayoutItem.GetOptionsLayout().IsDragStripes() );
151 m_xCbxHandlesBezier->set_active( aLayoutItem.GetOptionsLayout().IsHandlesBezier() );
153 m_xCbxRuler->save_state();
154 m_xCbxMoveOutline->save_state();
155 m_xCbxDragStripes->save_state();
156 m_xCbxHandlesBezier->save_state();
159 std::unique_ptr<SfxTabPage> SdTpOptionsContents::Create( weld::Container* pPage, weld::DialogController* pController,
160 const SfxItemSet* rAttrs )
162 return std::make_unique<SdTpOptionsContents>(pPage, pController, *rAttrs);
165 /*************************************************************************
167 |* TabPage to adjust the misc options
169 \************************************************************************/
170 #define TABLE_COUNT 12
171 #define TOKEN ':'
173 SdTpOptionsMisc::SdTpOptionsMisc(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
174 : SfxTabPage(pPage, pController, "modules/simpress/ui/optimpressgeneralpage.ui", "OptSavePage", &rInAttrs)
175 , nWidth(0)
176 , nHeight(0)
177 , m_xCbxQuickEdit(m_xBuilder->weld_check_button("qickedit"))
178 , m_xCbxPickThrough(m_xBuilder->weld_check_button("textselected"))
179 , m_xNewDocumentFrame(m_xBuilder->weld_frame("newdocumentframe"))
180 , m_xCbxStartWithTemplate(m_xBuilder->weld_check_button("startwithwizard"))
181 , m_xCbxMasterPageCache(m_xBuilder->weld_check_button("backgroundback"))
182 , m_xCbxCopy(m_xBuilder->weld_check_button("copywhenmove"))
183 , m_xCbxMarkedHitMovesAlways(m_xBuilder->weld_check_button("objalwymov"))
184 , m_xPresentationFrame(m_xBuilder->weld_frame("presentationframe"))
185 , m_xLbMetric(m_xBuilder->weld_combo_box("units"))
186 , m_xMtrFldTabstop(m_xBuilder->weld_metric_spin_button("metricFields", FieldUnit::MM))
187 , m_xCbxEnableSdremote(m_xBuilder->weld_check_button("enremotcont"))
188 , m_xCbxEnablePresenterScreen(m_xBuilder->weld_check_button("enprsntcons"))
189 , m_xCbxPresenterScreenFullScreen(m_xBuilder->weld_check_button("enprsntconsfullscreen"))
190 , m_xCbxCompatibility(m_xBuilder->weld_check_button("cbCompatibility"))
191 , m_xScaleFrame(m_xBuilder->weld_frame("scaleframe"))
192 , m_xCbScale(m_xBuilder->weld_combo_box("scaleBox"))
193 , m_xNewDocLb(m_xBuilder->weld_label("newdoclbl"))
194 , m_xFiInfo1(m_xBuilder->weld_label("info1"))
195 , m_xMtrFldOriginalWidth(m_xBuilder->weld_metric_spin_button("metricWidthFields", FieldUnit::MM))
196 , m_xWidthLb(m_xBuilder->weld_label("widthlbl"))
197 , m_xHeightLb(m_xBuilder->weld_label("heightlbl"))
198 , m_xFiInfo2(m_xBuilder->weld_label("info2"))
199 , m_xMtrFldOriginalHeight(m_xBuilder->weld_metric_spin_button("metricHeightFields", FieldUnit::MM))
200 , m_xCbxDistort(m_xBuilder->weld_check_button("distortcb"))
201 , m_xMtrFldInfo1(m_xBuilder->weld_metric_spin_button("metricInfo1Fields", FieldUnit::MM))
202 , m_xMtrFldInfo2(m_xBuilder->weld_metric_spin_button("metricInfo2Fields", FieldUnit::MM))
204 SetExchangeSupport();
206 // set metric
207 FieldUnit eFUnit;
209 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
210 if ( rInAttrs.GetItemState( nWhich ) >= SfxItemState::DEFAULT )
212 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rInAttrs.Get( nWhich ));
213 eFUnit = static_cast<FieldUnit>(rItem.GetValue());
215 else
216 eFUnit = SfxModule::GetCurrentFieldUnit();
218 SetFieldUnit( *m_xMtrFldTabstop , eFUnit );
219 // tdf#148292 - avoid right frame to change position depending on width of this control
220 m_xMtrFldTabstop->set_size_request(150, -1);
221 // Impress is default mode, let' hide the entire scale frame etc.
222 m_xCbxDistort->hide();
223 m_xScaleFrame->hide();
225 // fill ListBox with metrics
226 for (sal_uInt32 i = 0; i < SvxFieldUnitTable::Count(); ++i)
228 OUString sMetric = SvxFieldUnitTable::GetString(i);
229 sal_uInt32 nFieldUnit = sal_uInt32(SvxFieldUnitTable::GetValue(i));
230 m_xLbMetric->append(OUString::number(nFieldUnit), sMetric);
232 m_xLbMetric->connect_changed( LINK( this, SdTpOptionsMisc, SelectMetricHdl_Impl ) );
234 SetFieldUnit( *m_xMtrFldOriginalWidth, eFUnit );
235 SetFieldUnit( *m_xMtrFldOriginalHeight, eFUnit );
236 m_xMtrFldOriginalWidth->set_max(999999999, FieldUnit::NONE);
237 m_xMtrFldOriginalHeight->set_max(999999999, FieldUnit::NONE);
239 // temporary fields for info texts (for formatting/calculation)
240 m_xMtrFldInfo1->set_unit( eFUnit );
241 m_xMtrFldInfo1->set_max(999999999, FieldUnit::NONE);
242 m_xMtrFldInfo1->set_digits( 2 );
243 m_xMtrFldInfo2->set_unit( eFUnit );
244 m_xMtrFldInfo2->set_max(999999999, FieldUnit::NONE);
245 m_xMtrFldInfo2->set_digits( 2 );
247 // determine PoolUnit
248 SfxItemPool* pPool = rInAttrs.GetPool();
249 DBG_ASSERT( pPool, "Where is the Pool?" );
250 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
252 // Fill the CB
253 sal_uInt16 aTable[ TABLE_COUNT ] =
254 { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
256 for( sal_uInt16 i = TABLE_COUNT-1; i > 0 ; i-- )
257 m_xCbScale->append_text( GetScale( 1, aTable[i] ) );
258 for( sal_uInt16 i = 0; i < TABLE_COUNT; i++ )
259 m_xCbScale->append_text( GetScale( aTable[i], 1 ) );
262 SdTpOptionsMisc::~SdTpOptionsMisc()
266 void SdTpOptionsMisc::ActivatePage( const SfxItemSet& rSet )
268 // We have to call save_state again since it can happen that the value
269 // has no effect on other TabPages
270 m_xLbMetric->save_value();
271 // change metric if necessary (since TabPage is in the Dialog where
272 // the metric is set)
273 const SfxUInt16Item* pAttr = rSet.GetItemIfSet( SID_ATTR_METRIC , false );
274 if( !pAttr )
275 return;
277 FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<tools::Long>(pAttr->GetValue()));
279 if( eFUnit == m_xMtrFldOriginalWidth->get_unit() )
280 return;
282 // set metrics
283 sal_Int64 nVal = m_xMtrFldOriginalWidth->denormalize( m_xMtrFldOriginalWidth->get_value( FieldUnit::TWIP ) );
284 SetFieldUnit( *m_xMtrFldOriginalWidth, eFUnit, true );
285 m_xMtrFldOriginalWidth->set_value( m_xMtrFldOriginalWidth->normalize( nVal ), FieldUnit::TWIP );
287 nVal = m_xMtrFldOriginalHeight->denormalize( m_xMtrFldOriginalHeight->get_value( FieldUnit::TWIP ) );
288 SetFieldUnit( *m_xMtrFldOriginalHeight, eFUnit, true );
289 m_xMtrFldOriginalHeight->set_value( m_xMtrFldOriginalHeight->normalize( nVal ), FieldUnit::TWIP );
291 if( nWidth == 0 || nHeight == 0 )
292 return;
294 m_xMtrFldInfo1->set_unit( eFUnit );
295 m_xMtrFldInfo2->set_unit( eFUnit );
297 SetMetricValue( *m_xMtrFldInfo1, nWidth, ePoolUnit );
298 aInfo1 = m_xMtrFldInfo1->get_text();
299 m_xFiInfo1->set_label( aInfo1 );
301 SetMetricValue( *m_xMtrFldInfo2, nHeight, ePoolUnit );
302 aInfo2 = m_xMtrFldInfo2->get_text();
303 m_xFiInfo2->set_label( aInfo2 );
306 DeactivateRC SdTpOptionsMisc::DeactivatePage( SfxItemSet* pActiveSet )
308 // check parser
309 sal_Int32 nX, nY;
310 if( SetScale( m_xCbScale->get_active_text(), nX, nY ) )
312 if( pActiveSet )
313 FillItemSet( pActiveSet );
314 return DeactivateRC::LeavePage;
317 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
318 VclMessageType::Warning, VclButtonsType::YesNo,
319 SdResId(STR_WARN_SCALE_FAIL)));
320 if (xWarn->run() == RET_YES)
321 return DeactivateRC::KeepPage;
323 if( pActiveSet )
324 FillItemSet( pActiveSet );
326 return DeactivateRC::LeavePage;
329 bool SdTpOptionsMisc::FillItemSet( SfxItemSet* rAttrs )
331 bool bModified = false;
333 if( m_xCbxStartWithTemplate->get_state_changed_from_saved() ||
334 m_xCbxMarkedHitMovesAlways->get_state_changed_from_saved() ||
335 m_xCbxQuickEdit->get_state_changed_from_saved() ||
336 m_xCbxPickThrough->get_state_changed_from_saved() ||
337 m_xCbxMasterPageCache->get_state_changed_from_saved() ||
338 m_xCbxCopy->get_state_changed_from_saved() ||
339 m_xCbxEnableSdremote->get_state_changed_from_saved() ||
340 m_xCbxEnablePresenterScreen->get_state_changed_from_saved() ||
341 m_xCbxPresenterScreenFullScreen->get_state_changed_from_saved() ||
342 m_xCbxCompatibility->get_state_changed_from_saved() ||
343 m_xCbxDistort->get_state_changed_from_saved())
345 SdOptionsMiscItem aOptsItem;
347 aOptsItem.GetOptionsMisc().SetStartWithTemplate( m_xCbxStartWithTemplate->get_active() );
348 aOptsItem.GetOptionsMisc().SetMarkedHitMovesAlways( m_xCbxMarkedHitMovesAlways->get_active() );
349 aOptsItem.GetOptionsMisc().SetQuickEdit( m_xCbxQuickEdit->get_active() );
350 aOptsItem.GetOptionsMisc().SetPickThrough( m_xCbxPickThrough->get_active() );
351 aOptsItem.GetOptionsMisc().SetMasterPagePaintCaching( m_xCbxMasterPageCache->get_active() );
352 aOptsItem.GetOptionsMisc().SetDragWithCopy( m_xCbxCopy->get_active() );
353 aOptsItem.GetOptionsMisc().SetEnableSdremote( m_xCbxEnableSdremote->get_active() );
354 aOptsItem.GetOptionsMisc().SetEnablePresenterScreen( m_xCbxEnablePresenterScreen->get_active() );
355 aOptsItem.GetOptionsMisc().SetPresenterScreenFullScreen( m_xCbxPresenterScreenFullScreen->get_active() );
356 aOptsItem.GetOptionsMisc().SetSummationOfParagraphs( m_xCbxCompatibility->get_active() );
357 aOptsItem.GetOptionsMisc().SetCrookNoContortion( m_xCbxDistort->get_active() );
358 rAttrs->Put( aOptsItem );
360 bModified = true;
363 // metric
364 if (m_xLbMetric->get_value_changed_from_saved())
366 const sal_Int32 nMPos = m_xLbMetric->get_active();
367 sal_uInt16 nFieldUnit = m_xLbMetric->get_id(nMPos).toUInt32();
368 rAttrs->Put( SfxUInt16Item( GetWhich( SID_ATTR_METRIC ), nFieldUnit ) );
369 bModified = true;
372 // tabulator space
373 if( m_xMtrFldTabstop->get_value_changed_from_saved() )
375 MapUnit eUnit = rAttrs->GetPool()->GetMetric( SID_ATTR_DEFTABSTOP );
376 SfxUInt16Item aDef( SID_ATTR_DEFTABSTOP, static_cast<sal_uInt16>(GetCoreValue( *m_xMtrFldTabstop, eUnit )) );
377 rAttrs->Put( aDef );
378 bModified = true;
381 sal_Int32 nX, nY;
382 if( SetScale( m_xCbScale->get_active_text(), nX, nY ) )
384 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
385 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
387 bModified = true;
390 return bModified;
393 void SdTpOptionsMisc::Reset( const SfxItemSet* rAttrs )
395 SdOptionsMiscItem aOptsItem( rAttrs->Get( ATTR_OPTIONS_MISC ) );
397 m_xCbxStartWithTemplate->set_active( aOptsItem.GetOptionsMisc().IsStartWithTemplate() );
398 m_xCbxMarkedHitMovesAlways->set_active( aOptsItem.GetOptionsMisc().IsMarkedHitMovesAlways() );
399 m_xCbxQuickEdit->set_active( aOptsItem.GetOptionsMisc().IsQuickEdit() );
400 m_xCbxPickThrough->set_active( aOptsItem.GetOptionsMisc().IsPickThrough() );
401 m_xCbxMasterPageCache->set_active( aOptsItem.GetOptionsMisc().IsMasterPagePaintCaching() );
402 m_xCbxCopy->set_active( aOptsItem.GetOptionsMisc().IsDragWithCopy() );
403 m_xCbxEnableSdremote->set_active( aOptsItem.GetOptionsMisc().IsEnableSdremote() );
404 m_xCbxEnablePresenterScreen->set_active( aOptsItem.GetOptionsMisc().IsEnablePresenterScreen() );
405 m_xCbxPresenterScreenFullScreen->set_active( aOptsItem.GetOptionsMisc().IsPresenterScreenFullScreen() );
406 m_xCbxCompatibility->set_active( aOptsItem.GetOptionsMisc().IsSummationOfParagraphs() );
407 m_xCbxDistort->set_active( aOptsItem.GetOptionsMisc().IsCrookNoContortion() );
408 m_xCbxStartWithTemplate->save_state();
409 m_xCbxMarkedHitMovesAlways->save_state();
410 m_xCbxQuickEdit->save_state();
411 m_xCbxPickThrough->save_state();
413 m_xCbxMasterPageCache->save_state();
414 m_xCbxCopy->save_state();
415 m_xCbxEnableSdremote->save_state();
416 m_xCbxEnablePresenterScreen->save_state();
417 m_xCbxPresenterScreenFullScreen->save_state();
418 m_xCbxCompatibility->save_state();
419 m_xCbxDistort->save_state();
421 // metric
422 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
423 m_xLbMetric->set_active(-1);
425 if ( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT )
427 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich ));
428 sal_uInt32 nFieldUnit = static_cast<sal_uInt32>(rItem.GetValue());
430 for (sal_Int32 i = 0, nEntryCount = m_xLbMetric->get_count(); i < nEntryCount; ++i)
432 if (m_xLbMetric->get_id(i).toUInt32() == nFieldUnit)
434 m_xLbMetric->set_active( i );
435 break;
440 // tabulator space
441 constexpr auto nWhich2 = SID_ATTR_DEFTABSTOP;
442 if( rAttrs->GetItemState( nWhich2 ) >= SfxItemState::DEFAULT )
444 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWhich2 );
445 const SfxUInt16Item& rItem = rAttrs->Get( nWhich2 );
446 SetMetricValue( *m_xMtrFldTabstop, rItem.GetValue(), eUnit );
448 m_xLbMetric->save_value();
449 m_xMtrFldTabstop->save_value();
450 //Scale
451 sal_Int32 nX = rAttrs->Get( ATTR_OPTIONS_SCALE_X ).GetValue();
452 sal_Int32 nY = rAttrs->Get( ATTR_OPTIONS_SCALE_Y ).GetValue();
453 nWidth = static_cast<const SfxUInt32Item&>( rAttrs->
454 Get( ATTR_OPTIONS_SCALE_WIDTH ) ).GetValue();
455 nHeight = static_cast<const SfxUInt32Item&>( rAttrs->
456 Get( ATTR_OPTIONS_SCALE_HEIGHT ) ).GetValue();
458 m_xCbScale->set_entry_text( GetScale( nX, nY ) );
460 m_xMtrFldOriginalWidth->hide();
461 m_xMtrFldOriginalWidth->set_text( aInfo1 ); // empty
462 m_xMtrFldOriginalHeight->hide();
463 m_xMtrFldOriginalHeight->set_text( aInfo2 ); //empty
464 m_xFiInfo1->hide();
465 m_xFiInfo2->hide();
467 UpdateCompatibilityControls ();
470 std::unique_ptr<SfxTabPage> SdTpOptionsMisc::Create( weld::Container* pPage, weld::DialogController* pController,
471 const SfxItemSet* rAttrs )
473 return std::make_unique<SdTpOptionsMisc>( pPage, pController, *rAttrs );
476 IMPL_LINK_NOARG(SdTpOptionsMisc, SelectMetricHdl_Impl, weld::ComboBox&, void)
478 int nPos = m_xLbMetric->get_active();
479 if (nPos != -1)
481 FieldUnit eUnit = static_cast<FieldUnit>(m_xLbMetric->get_id(nPos).toUInt32());
482 sal_Int64 nVal =
483 m_xMtrFldTabstop->denormalize(m_xMtrFldTabstop->get_value(FieldUnit::TWIP));
484 SetFieldUnit( *m_xMtrFldTabstop, eUnit );
485 m_xMtrFldTabstop->set_value( m_xMtrFldTabstop->normalize( nVal ), FieldUnit::TWIP );
489 void SdTpOptionsMisc::SetImpressMode()
491 #ifndef ENABLE_SDREMOTE
492 m_xCbxEnableSdremote->hide();
493 #else
494 (void) this; // loplugin:staticmethods
495 #endif
498 void SdTpOptionsMisc::SetDrawMode()
500 m_xScaleFrame->show();
501 m_xNewDocumentFrame->hide();
502 m_xCbxEnableSdremote->hide();
503 m_xCbxEnablePresenterScreen->hide();
504 m_xCbxPresenterScreenFullScreen->hide();
505 m_xCbxCompatibility->hide();
506 m_xNewDocLb->hide();
507 m_xCbScale->show();
508 m_xPresentationFrame->hide();
509 m_xMtrFldInfo1->hide();
510 m_xMtrFldInfo2->hide();
511 m_xWidthLb->hide();
512 m_xHeightLb->hide();
513 m_xFiInfo1->show();
514 m_xMtrFldOriginalWidth->show();
515 m_xFiInfo2->show();
516 m_xMtrFldOriginalHeight->show();
517 m_xCbxDistort->show();
518 m_xCbxCompatibility->hide();
521 OUString SdTpOptionsMisc::GetScale( sal_Int32 nX, sal_Int32 nY )
523 return OUString::number(nX) + OUStringChar(TOKEN) + OUString::number(nY);
526 bool SdTpOptionsMisc::SetScale( std::u16string_view aScale, sal_Int32& rX, sal_Int32& rY )
528 if (aScale.empty())
529 return false;
531 sal_Int32 nIdx {0};
533 std::u16string_view aTmp(o3tl::getToken(aScale, 0, TOKEN, nIdx));
534 if (nIdx<0)
535 return false; // we expect another token!
537 if (!comphelper::string::isdigitAsciiString(aTmp))
538 return false;
540 rX = static_cast<tools::Long>(o3tl::toInt32(aTmp));
541 if( rX == 0 )
542 return false;
544 aTmp = o3tl::getToken(aScale, 0, TOKEN, nIdx);
545 if (nIdx>=0)
546 return false; // we require just 2 tokens!
548 if (!comphelper::string::isdigitAsciiString(aTmp))
549 return false;
551 rY = static_cast<tools::Long>(o3tl::toInt32(aTmp));
552 return rY != 0;
555 void SdTpOptionsMisc::UpdateCompatibilityControls()
557 // Disable the compatibility controls by default. Enable them only when
558 // there is at least one open document.
559 bool bIsEnabled = false;
563 // Get a component enumeration from the desktop and search it for documents.
564 Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext());
567 Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
569 Reference<container::XEnumerationAccess> xComponents =
570 xDesktop->getComponents();
571 if ( ! xComponents.is())
572 break;
574 Reference<container::XEnumeration> xEnumeration (
575 xComponents->createEnumeration());
576 if ( ! xEnumeration.is())
577 break;
579 while (xEnumeration->hasMoreElements())
581 Reference<frame::XModel> xModel (xEnumeration->nextElement(), UNO_QUERY);
582 if (xModel.is())
584 // There is at least one model/document: Enable the compatibility controls.
585 bIsEnabled = true;
586 break;
591 while (false); // One 'loop'.
593 catch (const uno::Exception&)
595 // When there is an exception then simply use the default value of
596 // bIsEnabled and disable the controls.
599 m_xCbxCompatibility->set_sensitive(bIsEnabled);
602 void SdTpOptionsMisc::PageCreated(const SfxAllItemSet& aSet)
604 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false);
605 if (pFlagItem)
607 sal_uInt32 nFlags=pFlagItem->GetValue();
608 if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
609 SetDrawMode();
610 if ( ( nFlags & SD_IMPRESS_MODE ) == SD_IMPRESS_MODE )
611 SetImpressMode();
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */