Update git submodules
[LibreOffice.git] / sd / source / ui / dlg / tpoption.cxx
blob8b97d4df7aecb2dc7383a8b4e7c8d380bbb522e1
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 <officecfg/Office/Impress.hxx>
27 #include <officecfg/Office/Draw.hxx>
28 #include <sfx2/module.hxx>
29 #include <svx/svxids.hrc>
30 #include <svx/strarray.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/weld.hxx>
33 #include <svtools/unitconv.hxx>
35 #include <sdattr.hrc>
36 #include <sdresid.hxx>
37 #include <optsitem.hxx>
38 #include <tpoption.hxx>
39 #include <strings.hrc>
40 #include <app.hrc>
41 #include <svl/intitem.hxx>
42 #include <o3tl/string_view.hxx>
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
47 SdTpOptionsSnap::SdTpOptionsSnap(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
48 : SvxGridTabPage(pPage, pController, rInAttrs)
50 m_xSnapFrames->show();
53 SdTpOptionsSnap::~SdTpOptionsSnap()
57 bool SdTpOptionsSnap::FillItemSet( SfxItemSet* rAttrs )
59 SvxGridTabPage::FillItemSet(rAttrs);
60 bool bDrawMode = SvxGridTabPage::IsDrawMode();
62 std::shared_ptr<comphelper::ConfigurationChanges> batch(
63 comphelper::ConfigurationChanges::create());
65 if (bDrawMode)
67 officecfg::Office::Draw::Snap::Object::SnapLine::set( m_xCbxSnapHelplines->get_active(), batch );
68 officecfg::Office::Draw::Snap::Object::PageMargin::set( m_xCbxSnapBorder->get_active(), batch );
69 officecfg::Office::Draw::Snap::Object::ObjectFrame::set( m_xCbxSnapFrame->get_active(), batch );
70 officecfg::Office::Draw::Snap::Object::ObjectPoint::set( m_xCbxSnapPoints->get_active(), batch );
71 officecfg::Office::Draw::Snap::Position::CreatingMoving::set( m_xCbxOrtho->get_active(), batch );
72 officecfg::Office::Draw::Snap::Position::ExtendEdges::set( m_xCbxBigOrtho->get_active(), batch );
73 officecfg::Office::Draw::Snap::Position::Rotating::set( m_xCbxRotate->get_active(), batch );
74 officecfg::Office::Draw::Snap::Object::Range::set( static_cast<sal_Int16>(m_xMtrFldSnapArea->get_value(FieldUnit::PIXEL)), batch );
75 officecfg::Office::Draw::Snap::Position::RotatingValue::set( static_cast<sal_Int32>(Degree100(m_xMtrFldAngle->get_value(FieldUnit::DEGREE))), batch );
76 officecfg::Office::Draw::Snap::Position::PointReduction::set ( static_cast<sal_Int32>(Degree100(m_xMtrFldBezAngle->get_value(FieldUnit::DEGREE))), batch );
78 else
80 officecfg::Office::Impress::Snap::Object::SnapLine::set( m_xCbxSnapHelplines->get_active(), batch );
81 officecfg::Office::Impress::Snap::Object::PageMargin::set( m_xCbxSnapBorder->get_active(), batch );
82 officecfg::Office::Impress::Snap::Object::ObjectFrame::set( m_xCbxSnapFrame->get_active(), batch );
83 officecfg::Office::Impress::Snap::Object::ObjectPoint::set( m_xCbxSnapPoints->get_active(), batch );
84 officecfg::Office::Impress::Snap::Position::CreatingMoving::set( m_xCbxOrtho->get_active(), batch );
85 officecfg::Office::Impress::Snap::Position::ExtendEdges::set( m_xCbxBigOrtho->get_active(), batch );
86 officecfg::Office::Impress::Snap::Position::Rotating::set( m_xCbxRotate->get_active(), batch );
87 officecfg::Office::Impress::Snap::Object::Range::set( static_cast<sal_Int16>(m_xMtrFldSnapArea->get_value(FieldUnit::PIXEL)), batch );
88 officecfg::Office::Impress::Snap::Position::RotatingValue::set( static_cast<sal_Int32>(Degree100(m_xMtrFldAngle->get_value(FieldUnit::DEGREE))), batch );
89 officecfg::Office::Impress::Snap::Position::PointReduction::set ( static_cast<sal_Int32>(Degree100(m_xMtrFldBezAngle->get_value(FieldUnit::DEGREE))), batch );
92 batch->commit();
94 // we get a possible existing GridItem, this ensures that we do not set
95 // some default values by accident
96 return true;
99 void SdTpOptionsSnap::Reset( const SfxItemSet* rAttrs )
101 SvxGridTabPage::Reset(rAttrs);
103 bool bDrawMode = SvxGridTabPage::IsDrawMode();
104 if (bDrawMode)
106 m_xCbxSnapHelplines->set_active( officecfg::Office::Draw::Snap::Object::SnapLine::get() );
107 m_xCbxSnapBorder->set_active( officecfg::Office::Draw::Snap::Object::PageMargin::get() );
108 m_xCbxSnapFrame->set_active( officecfg::Office::Draw::Snap::Object::ObjectFrame::get() );
109 m_xCbxSnapPoints->set_active( officecfg::Office::Draw::Snap::Object::ObjectPoint::get() );
110 m_xCbxOrtho->set_active( officecfg::Office::Draw::Snap::Position::CreatingMoving::get() );
111 m_xCbxBigOrtho->set_active( officecfg::Office::Draw::Snap::Position::ExtendEdges::get() );
112 m_xCbxRotate->set_active( officecfg::Office::Draw::Snap::Position::Rotating::get() );
113 m_xMtrFldSnapArea->set_value( officecfg::Office::Draw::Snap::Object::Range::get(), FieldUnit::PIXEL);
114 m_xMtrFldAngle->set_value( officecfg::Office::Draw::Snap::Position::RotatingValue::get(), FieldUnit::DEGREE);
115 m_xMtrFldBezAngle->set_value( officecfg::Office::Draw::Snap::Position::PointReduction::get(), FieldUnit::DEGREE);
117 else
119 m_xCbxSnapHelplines->set_active( officecfg::Office::Impress::Snap::Object::SnapLine::get() );
120 m_xCbxSnapBorder->set_active( officecfg::Office::Impress::Snap::Object::PageMargin::get() );
121 m_xCbxSnapFrame->set_active( officecfg::Office::Impress::Snap::Object::ObjectFrame::get() );
122 m_xCbxSnapPoints->set_active( officecfg::Office::Impress::Snap::Object::ObjectPoint::get() );
123 m_xCbxOrtho->set_active( officecfg::Office::Impress::Snap::Position::CreatingMoving::get() );
124 m_xCbxBigOrtho->set_active( officecfg::Office::Impress::Snap::Position::ExtendEdges::get() );
125 m_xCbxRotate->set_active( officecfg::Office::Impress::Snap::Position::Rotating::get() );
126 m_xMtrFldSnapArea->set_value( officecfg::Office::Impress::Snap::Object::Range::get(), FieldUnit::PIXEL);
127 m_xMtrFldAngle->set_value( officecfg::Office::Impress::Snap::Position::RotatingValue::get(), FieldUnit::DEGREE);
128 m_xMtrFldBezAngle->set_value( officecfg::Office::Impress::Snap::Position::PointReduction::get(), FieldUnit::DEGREE);
131 bool bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Object::SnapLine::isReadOnly() :
132 officecfg::Office::Impress::Snap::Object::SnapLine::isReadOnly();
133 m_xCbxSnapHelplines->set_sensitive(!bReadOnly);
134 m_xCbxSnapHelplinesImg->set_visible(bReadOnly);
136 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Object::PageMargin::isReadOnly() :
137 officecfg::Office::Impress::Snap::Object::PageMargin::isReadOnly();
138 m_xCbxSnapBorder->set_sensitive(!bReadOnly);
139 m_xCbxSnapBorderImg->set_visible(bReadOnly);
141 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Object::ObjectFrame::isReadOnly() :
142 officecfg::Office::Impress::Snap::Object::ObjectFrame::isReadOnly();
143 m_xCbxSnapFrame->set_sensitive(!bReadOnly);
144 m_xCbxSnapFrameImg->set_visible(bReadOnly);
146 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Object::ObjectPoint::isReadOnly() :
147 officecfg::Office::Impress::Snap::Object::ObjectPoint::isReadOnly();
148 m_xCbxSnapPoints->set_sensitive(!bReadOnly);
149 m_xCbxSnapPointsImg->set_visible(bReadOnly);
151 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Position::CreatingMoving::isReadOnly() :
152 officecfg::Office::Impress::Snap::Position::CreatingMoving::isReadOnly();
153 m_xCbxOrtho->set_sensitive(!bReadOnly);
154 m_xCbxOrthoImg->set_visible(bReadOnly);
156 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Position::ExtendEdges::isReadOnly() :
157 officecfg::Office::Impress::Snap::Position::ExtendEdges::isReadOnly();
158 m_xCbxBigOrtho->set_sensitive(!bReadOnly);
159 m_xCbxBigOrthoImg->set_visible(bReadOnly);
161 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Position::Rotating::isReadOnly() :
162 officecfg::Office::Impress::Snap::Position::Rotating::isReadOnly();
163 m_xCbxRotate->set_sensitive(!bReadOnly);
164 m_xCbxRotateImg->set_visible(bReadOnly);
166 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Object::Range::isReadOnly() :
167 officecfg::Office::Impress::Snap::Object::Range::isReadOnly();
168 m_xMtrFldSnapArea->set_sensitive(!bReadOnly);
169 m_xMtrFldSnapAreaImg->set_visible(bReadOnly);
171 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Position::RotatingValue::isReadOnly() :
172 officecfg::Office::Impress::Snap::Position::RotatingValue::isReadOnly();
173 m_xMtrFldAngle->set_sensitive(!bReadOnly);
175 bReadOnly = bDrawMode ? officecfg::Office::Draw::Snap::Position::PointReduction::isReadOnly() :
176 officecfg::Office::Impress::Snap::Position::PointReduction::isReadOnly();
177 m_xMtrFldBezAngle->set_sensitive(!bReadOnly);
178 m_xMtrFldBezAngleImg->set_visible(bReadOnly);
180 ClickRotateHdl_Impl(*m_xCbxRotate);
183 std::unique_ptr<SfxTabPage> SdTpOptionsSnap::Create( weld::Container* pPage, weld::DialogController* pController,
184 const SfxItemSet* rAttrs )
186 return std::make_unique<SdTpOptionsSnap>(pPage, pController, *rAttrs);
189 /*************************************************************************
191 |* TabPage to adjust the content options
193 \************************************************************************/
194 SdTpOptionsContents::SdTpOptionsContents(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
195 : SfxTabPage(pPage, pController, u"modules/simpress/ui/sdviewpage.ui"_ustr, u"SdViewPage"_ustr, &rInAttrs)
196 , m_bDrawMode(false)
197 , m_xCbxRuler(m_xBuilder->weld_check_button(u"ruler"_ustr))
198 , m_xCbxRulerImg(m_xBuilder->weld_widget(u"lockruler"_ustr))
199 , m_xCbxDragStripes(m_xBuilder->weld_check_button(u"dragstripes"_ustr))
200 , m_xCbxDragStripesImg(m_xBuilder->weld_widget(u"lockdragstripes"_ustr))
201 , m_xCbxHandlesBezier(m_xBuilder->weld_check_button(u"handlesbezier"_ustr))
202 , m_xCbxHandlesBezierImg(m_xBuilder->weld_widget(u"lockhandlesbezier"_ustr))
203 , m_xCbxMoveOutline(m_xBuilder->weld_check_button(u"moveoutline"_ustr))
204 , m_xCbxMoveOutlineImg(m_xBuilder->weld_widget(u"lockmoveoutline"_ustr))
208 SdTpOptionsContents::~SdTpOptionsContents()
212 OUString SdTpOptionsContents::GetAllStrings()
214 OUString sAllStrings;
215 OUString labels[] = { u"label1"_ustr };
217 for (const auto& label : labels)
219 if (const auto pString = m_xBuilder->weld_label(label))
220 sAllStrings += pString->get_label() + " ";
223 OUString checkButton[] = { u"ruler"_ustr, u"dragstripes"_ustr, u"handlesbezier"_ustr, u"moveoutline"_ustr };
225 for (const auto& check : checkButton)
227 if (const auto pString = m_xBuilder->weld_check_button(check))
228 sAllStrings += pString->get_label() + " ";
231 return sAllStrings.replaceAll("_", "");
234 bool SdTpOptionsContents::FillItemSet( SfxItemSet* )
236 bool bModified = false;
238 if( m_xCbxRuler->get_state_changed_from_saved() ||
239 m_xCbxMoveOutline->get_state_changed_from_saved() ||
240 m_xCbxDragStripes->get_state_changed_from_saved() ||
241 m_xCbxHandlesBezier->get_state_changed_from_saved() )
243 std::shared_ptr<comphelper::ConfigurationChanges> batch(
244 comphelper::ConfigurationChanges::create());
246 if (m_bDrawMode)
248 officecfg::Office::Draw::Layout::Display::Ruler::set(m_xCbxRuler->get_active(), batch);
249 officecfg::Office::Draw::Layout::Display::Contour::set(m_xCbxMoveOutline->get_active(), batch);
250 officecfg::Office::Draw::Layout::Display::Guide::set(m_xCbxDragStripes->get_active(), batch);
251 officecfg::Office::Draw::Layout::Display::Bezier::set(m_xCbxHandlesBezier->get_active(), batch);
252 batch->commit();
254 else
256 officecfg::Office::Impress::Layout::Display::Ruler::set(m_xCbxRuler->get_active(), batch);
257 officecfg::Office::Impress::Layout::Display::Contour::set(m_xCbxMoveOutline->get_active(), batch);
258 officecfg::Office::Impress::Layout::Display::Guide::set(m_xCbxDragStripes->get_active(), batch);
259 officecfg::Office::Impress::Layout::Display::Bezier::set(m_xCbxHandlesBezier->get_active(), batch);
260 batch->commit();
262 bModified = true;
264 return bModified;
267 void SdTpOptionsContents::Reset( const SfxItemSet* )
269 if (m_bDrawMode)
271 m_xCbxRuler->set_active(officecfg::Office::Draw::Layout::Display::Ruler::get());
272 m_xCbxMoveOutline->set_active(officecfg::Office::Draw::Layout::Display::Contour::get());
273 m_xCbxDragStripes->set_active(officecfg::Office::Draw::Layout::Display::Guide::get());
274 m_xCbxHandlesBezier->set_active(officecfg::Office::Draw::Layout::Display::Bezier::get());
276 else
278 m_xCbxRuler->set_active(officecfg::Office::Impress::Layout::Display::Ruler::get());
279 m_xCbxMoveOutline->set_active(officecfg::Office::Impress::Layout::Display::Contour::get());
280 m_xCbxDragStripes->set_active(officecfg::Office::Impress::Layout::Display::Guide::get());
281 m_xCbxHandlesBezier->set_active(officecfg::Office::Impress::Layout::Display::Bezier::get());
284 bool bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Display::Ruler::isReadOnly() :
285 officecfg::Office::Impress::Layout::Display::Ruler::isReadOnly();
286 m_xCbxRuler->set_sensitive(!bReadOnly);
287 m_xCbxRulerImg->set_visible(bReadOnly);
289 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Display::Contour::isReadOnly() :
290 officecfg::Office::Impress::Layout::Display::Contour::isReadOnly();
291 m_xCbxMoveOutline->set_sensitive(!bReadOnly);
292 m_xCbxMoveOutlineImg->set_visible(bReadOnly);
294 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Display::Guide::isReadOnly() :
295 officecfg::Office::Impress::Layout::Display::Guide::isReadOnly();
296 m_xCbxDragStripes->set_sensitive(!bReadOnly);
297 m_xCbxDragStripesImg->set_visible(bReadOnly);
299 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Display::Bezier::isReadOnly() :
300 officecfg::Office::Impress::Layout::Display::Bezier::isReadOnly();
301 m_xCbxHandlesBezier->set_sensitive(!bReadOnly);
302 m_xCbxHandlesBezierImg->set_visible(bReadOnly);
304 m_xCbxRuler->save_state();
305 m_xCbxMoveOutline->save_state();
306 m_xCbxDragStripes->save_state();
307 m_xCbxHandlesBezier->save_state();
310 std::unique_ptr<SfxTabPage> SdTpOptionsContents::Create( weld::Container* pPage, weld::DialogController* pController,
311 const SfxItemSet* rAttrs )
313 return std::make_unique<SdTpOptionsContents>(pPage, pController, *rAttrs);
316 void SdTpOptionsContents::PageCreated( const SfxAllItemSet& aSet )
318 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false);
319 if (pFlagItem)
321 sal_uInt32 nFlags = pFlagItem->GetValue();
322 if ((nFlags & SD_DRAW_MODE) == SD_DRAW_MODE)
323 SetDrawMode();
327 /*************************************************************************
329 |* TabPage to adjust the misc options
331 \************************************************************************/
332 #define TABLE_COUNT 12
333 #define TOKEN ':'
335 SdTpOptionsMisc::SdTpOptionsMisc(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
336 : SfxTabPage(pPage, pController, u"modules/simpress/ui/optimpressgeneralpage.ui"_ustr, u"OptSavePage"_ustr, &rInAttrs)
337 , nWidth(0)
338 , nHeight(0)
339 , m_bDrawMode(false)
340 , m_xCbxQuickEdit(m_xBuilder->weld_check_button(u"qickedit"_ustr))
341 , m_xCbxQuickEditImg(m_xBuilder->weld_widget(u"lockqickedit"_ustr))
342 , m_xCbxPickThrough(m_xBuilder->weld_check_button(u"textselected"_ustr))
343 , m_xCbxPickThroughImg(m_xBuilder->weld_widget(u"locktextselected"_ustr))
344 , m_xNewDocumentFrame(m_xBuilder->weld_frame(u"newdocumentframe"_ustr))
345 , m_xCbxStartWithTemplate(m_xBuilder->weld_check_button(u"startwithwizard"_ustr))
346 , m_xCbxStartWithTemplateImg(m_xBuilder->weld_widget(u"lockstartwithwizard"_ustr))
347 , m_xCbxMasterPageCache(m_xBuilder->weld_check_button(u"backgroundback"_ustr))
348 , m_xCbxMasterPageCacheImg(m_xBuilder->weld_widget(u"lockbackgroundback"_ustr))
349 , m_xCbxCopy(m_xBuilder->weld_check_button(u"copywhenmove"_ustr))
350 , m_xCbxCopyImg(m_xBuilder->weld_widget(u"lockcopywhenmove"_ustr))
351 , m_xCbxMarkedHitMovesAlways(m_xBuilder->weld_check_button(u"objalwymov"_ustr))
352 , m_xCbxMarkedHitMovesAlwaysImg(m_xBuilder->weld_widget(u"lockobjalwymov"_ustr))
353 , m_xLbMetric(m_xBuilder->weld_combo_box(u"units"_ustr))
354 , m_xLbMetricImg(m_xBuilder->weld_widget(u"lockunits"_ustr))
355 , m_xMtrFldTabstop(m_xBuilder->weld_metric_spin_button(u"metricFields"_ustr, FieldUnit::MM))
356 , m_xMtrFldTabstopImg(m_xBuilder->weld_widget(u"locktabstop"_ustr))
357 , m_xCbxCompatibility(m_xBuilder->weld_check_button(u"cbCompatibility"_ustr))
358 , m_xCbxCompatibilityImg(m_xBuilder->weld_widget(u"lockcbCompatibility"_ustr))
359 , m_xScaleFrame(m_xBuilder->weld_frame(u"scaleframe"_ustr))
360 , m_xCbScale(m_xBuilder->weld_combo_box(u"scaleBox"_ustr))
361 , m_xCbScaleImg(m_xBuilder->weld_widget(u"lockscaleBox"_ustr))
362 , m_xNewDocLb(m_xBuilder->weld_label(u"newdoclbl"_ustr))
363 , m_xFiInfo1(m_xBuilder->weld_label(u"info1"_ustr))
364 , m_xMtrFldOriginalWidth(m_xBuilder->weld_metric_spin_button(u"metricWidthFields"_ustr, FieldUnit::MM))
365 , m_xWidthLb(m_xBuilder->weld_label(u"widthlbl"_ustr))
366 , m_xHeightLb(m_xBuilder->weld_label(u"heightlbl"_ustr))
367 , m_xFiInfo2(m_xBuilder->weld_label(u"info2"_ustr))
368 , m_xMtrFldOriginalHeight(m_xBuilder->weld_metric_spin_button(u"metricHeightFields"_ustr, FieldUnit::MM))
369 , m_xCbxDistort(m_xBuilder->weld_check_button(u"distortcb"_ustr))
370 , m_xCbxDistortImg(m_xBuilder->weld_widget(u"lockdistortcb"_ustr))
371 , m_xMtrFldInfo1(m_xBuilder->weld_metric_spin_button(u"metricInfo1Fields"_ustr, FieldUnit::MM))
372 , m_xMtrFldInfo2(m_xBuilder->weld_metric_spin_button(u"metricInfo2Fields"_ustr, FieldUnit::MM))
374 SetExchangeSupport();
376 // set metric
377 FieldUnit eFUnit;
379 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
380 if ( rInAttrs.GetItemState( nWhich ) >= SfxItemState::DEFAULT )
382 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rInAttrs.Get( nWhich ));
383 eFUnit = static_cast<FieldUnit>(rItem.GetValue());
385 else
386 eFUnit = SfxModule::GetCurrentFieldUnit();
388 SetFieldUnit( *m_xMtrFldTabstop , eFUnit );
389 // tdf#148292 - avoid right frame to change position depending on width of this control
390 m_xMtrFldTabstop->set_size_request(150, -1);
391 // Impress is default mode, let' hide the entire scale frame etc.
392 m_xCbxDistort->hide();
393 m_xScaleFrame->hide();
395 // fill ListBox with metrics
396 for (sal_uInt32 i = 0; i < SvxFieldUnitTable::Count(); ++i)
398 OUString sMetric = SvxFieldUnitTable::GetString(i);
399 sal_uInt32 nFieldUnit = sal_uInt32(SvxFieldUnitTable::GetValue(i));
400 m_xLbMetric->append(OUString::number(nFieldUnit), sMetric);
402 m_xLbMetric->connect_changed( LINK( this, SdTpOptionsMisc, SelectMetricHdl_Impl ) );
404 SetFieldUnit( *m_xMtrFldOriginalWidth, eFUnit );
405 SetFieldUnit( *m_xMtrFldOriginalHeight, eFUnit );
406 m_xMtrFldOriginalWidth->set_max(999999999, FieldUnit::NONE);
407 m_xMtrFldOriginalHeight->set_max(999999999, FieldUnit::NONE);
409 // temporary fields for info texts (for formatting/calculation)
410 m_xMtrFldInfo1->set_unit( eFUnit );
411 m_xMtrFldInfo1->set_max(999999999, FieldUnit::NONE);
412 m_xMtrFldInfo1->set_digits( 2 );
413 m_xMtrFldInfo2->set_unit( eFUnit );
414 m_xMtrFldInfo2->set_max(999999999, FieldUnit::NONE);
415 m_xMtrFldInfo2->set_digits( 2 );
417 // determine PoolUnit
418 SfxItemPool* pPool = rInAttrs.GetPool();
419 assert(pPool && "Where is the Pool?");
420 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
422 // Fill the CB
423 sal_uInt16 aTable[ TABLE_COUNT ] =
424 { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
426 for( sal_uInt16 i = TABLE_COUNT-1; i > 0 ; i-- )
427 m_xCbScale->append_text( GetScale( 1, aTable[i] ) );
428 for( sal_uInt16 i = 0; i < TABLE_COUNT; i++ )
429 m_xCbScale->append_text( GetScale( aTable[i], 1 ) );
432 SdTpOptionsMisc::~SdTpOptionsMisc()
436 void SdTpOptionsMisc::ActivatePage( const SfxItemSet& rSet )
438 // We have to call save_state again since it can happen that the value
439 // has no effect on other TabPages
440 m_xLbMetric->save_value();
441 // change metric if necessary (since TabPage is in the Dialog where
442 // the metric is set)
443 const SfxUInt16Item* pAttr = rSet.GetItemIfSet( SID_ATTR_METRIC , false );
444 if( !pAttr )
445 return;
447 FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<tools::Long>(pAttr->GetValue()));
449 if( eFUnit == m_xMtrFldOriginalWidth->get_unit() )
450 return;
452 // set metrics
453 sal_Int64 nVal = m_xMtrFldOriginalWidth->denormalize( m_xMtrFldOriginalWidth->get_value( FieldUnit::TWIP ) );
454 SetFieldUnit( *m_xMtrFldOriginalWidth, eFUnit, true );
455 m_xMtrFldOriginalWidth->set_value( m_xMtrFldOriginalWidth->normalize( nVal ), FieldUnit::TWIP );
457 nVal = m_xMtrFldOriginalHeight->denormalize( m_xMtrFldOriginalHeight->get_value( FieldUnit::TWIP ) );
458 SetFieldUnit( *m_xMtrFldOriginalHeight, eFUnit, true );
459 m_xMtrFldOriginalHeight->set_value( m_xMtrFldOriginalHeight->normalize( nVal ), FieldUnit::TWIP );
461 if( nWidth == 0 || nHeight == 0 )
462 return;
464 m_xMtrFldInfo1->set_unit( eFUnit );
465 m_xMtrFldInfo2->set_unit( eFUnit );
467 SetMetricValue( *m_xMtrFldInfo1, nWidth, ePoolUnit );
468 aInfo1 = m_xMtrFldInfo1->get_text();
469 m_xFiInfo1->set_label( aInfo1 );
471 SetMetricValue( *m_xMtrFldInfo2, nHeight, ePoolUnit );
472 aInfo2 = m_xMtrFldInfo2->get_text();
473 m_xFiInfo2->set_label( aInfo2 );
476 DeactivateRC SdTpOptionsMisc::DeactivatePage( SfxItemSet* pActiveSet )
478 // check parser
479 sal_Int32 nX, nY;
480 if( SetScale( m_xCbScale->get_active_text(), nX, nY ) )
482 if( pActiveSet )
483 FillItemSet( pActiveSet );
484 return DeactivateRC::LeavePage;
487 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
488 VclMessageType::Warning, VclButtonsType::YesNo,
489 SdResId(STR_WARN_SCALE_FAIL)));
490 if (xWarn->run() == RET_YES)
491 return DeactivateRC::KeepPage;
493 if( pActiveSet )
494 FillItemSet( pActiveSet );
496 return DeactivateRC::LeavePage;
499 OUString SdTpOptionsMisc::GetAllStrings()
501 OUString sAllStrings;
502 OUString labels[]
503 = { u"newdoclbl"_ustr, u"label4"_ustr, u"label6"_ustr, u"tabstoplabel"_ustr, u"label1"_ustr, u"label7"_ustr, u"label2"_ustr,
504 u"label5"_ustr, u"label8"_ustr, u"widthlbl"_ustr, u"info1"_ustr, u"heightlbl"_ustr, u"info2"_ustr };
506 for (const auto& label : labels)
508 if (const auto pString = m_xBuilder->weld_label(label))
509 sAllStrings += pString->get_label() + " ";
512 OUString checkButton[] = { u"startwithwizard"_ustr, u"copywhenmove"_ustr, u"backgroundback"_ustr,
513 u"objalwymov"_ustr, u"distortcb"_ustr, u"cbCompatibility"_ustr,
514 u"qickedit"_ustr, u"textselected"_ustr};
516 for (const auto& check : checkButton)
518 if (const auto pString = m_xBuilder->weld_check_button(check))
519 sAllStrings += pString->get_label() + " ";
522 return sAllStrings.replaceAll("_", "");
525 bool SdTpOptionsMisc::FillItemSet( SfxItemSet* rAttrs )
527 bool bModified = false;
529 if( m_xCbxStartWithTemplate->get_state_changed_from_saved() ||
530 m_xCbxMarkedHitMovesAlways->get_state_changed_from_saved() ||
531 m_xCbxQuickEdit->get_state_changed_from_saved() ||
532 m_xCbxPickThrough->get_state_changed_from_saved() ||
533 m_xCbxMasterPageCache->get_state_changed_from_saved() ||
534 m_xCbxCopy->get_state_changed_from_saved() ||
535 m_xCbxCompatibility->get_state_changed_from_saved() ||
536 m_xCbxDistort->get_state_changed_from_saved())
538 SdOptionsMiscItem aOptsItem;
540 aOptsItem.GetOptionsMisc().SetStartWithTemplate( m_xCbxStartWithTemplate->get_active() );
541 aOptsItem.GetOptionsMisc().SetMarkedHitMovesAlways( m_xCbxMarkedHitMovesAlways->get_active() );
542 aOptsItem.GetOptionsMisc().SetQuickEdit( m_xCbxQuickEdit->get_active() );
543 aOptsItem.GetOptionsMisc().SetPickThrough( m_xCbxPickThrough->get_active() );
544 aOptsItem.GetOptionsMisc().SetMasterPagePaintCaching( m_xCbxMasterPageCache->get_active() );
545 aOptsItem.GetOptionsMisc().SetDragWithCopy( m_xCbxCopy->get_active() );
546 aOptsItem.GetOptionsMisc().SetSummationOfParagraphs( m_xCbxCompatibility->get_active() );
547 aOptsItem.GetOptionsMisc().SetCrookNoContortion( m_xCbxDistort->get_active() );
548 rAttrs->Put( aOptsItem );
550 bModified = true;
553 // metric
554 if (m_xLbMetric->get_value_changed_from_saved())
556 const sal_Int32 nMPos = m_xLbMetric->get_active();
557 sal_uInt16 nFieldUnit = m_xLbMetric->get_id(nMPos).toUInt32();
558 rAttrs->Put( SfxUInt16Item( GetWhich( SID_ATTR_METRIC ), nFieldUnit ) );
559 bModified = true;
562 // tabulator space
563 if( m_xMtrFldTabstop->get_value_changed_from_saved() )
565 MapUnit eUnit = rAttrs->GetPool()->GetMetric( SID_ATTR_DEFTABSTOP );
566 SfxUInt16Item aDef( SID_ATTR_DEFTABSTOP, static_cast<sal_uInt16>(GetCoreValue( *m_xMtrFldTabstop, eUnit )) );
567 rAttrs->Put( aDef );
568 bModified = true;
571 sal_Int32 nX, nY;
572 if( SetScale( m_xCbScale->get_active_text(), nX, nY ) )
574 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
575 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
577 bModified = true;
580 return bModified;
583 void SdTpOptionsMisc::Reset( const SfxItemSet* rAttrs )
585 SdOptionsMiscItem aOptsItem( rAttrs->Get( ATTR_OPTIONS_MISC ) );
587 bool bReadOnly = m_bDrawMode ? false : officecfg::Office::Impress::Misc::NewDoc::AutoPilot::isReadOnly();
588 m_xCbxStartWithTemplate->set_active( aOptsItem.GetOptionsMisc().IsStartWithTemplate() );
589 m_xCbxStartWithTemplate->set_sensitive(!bReadOnly);
590 m_xCbxStartWithTemplateImg->set_visible(bReadOnly);
592 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Misc::ObjectMoveable::isReadOnly() :
593 officecfg::Office::Impress::Misc::ObjectMoveable::isReadOnly();
594 m_xCbxMarkedHitMovesAlways->set_active( aOptsItem.GetOptionsMisc().IsMarkedHitMovesAlways() );
595 m_xCbxMarkedHitMovesAlways->set_sensitive(!bReadOnly);
596 m_xCbxMarkedHitMovesAlwaysImg->set_visible(bReadOnly);
598 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Misc::TextObject::QuickEditing::isReadOnly() :
599 officecfg::Office::Impress::Misc::TextObject::QuickEditing::isReadOnly();
600 m_xCbxQuickEdit->set_active( aOptsItem.GetOptionsMisc().IsQuickEdit() );
601 m_xCbxQuickEdit->set_sensitive(!bReadOnly);
602 m_xCbxQuickEditImg->set_visible(bReadOnly);
604 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Misc::TextObject::Selectable::isReadOnly() :
605 officecfg::Office::Impress::Misc::TextObject::Selectable::isReadOnly();
606 m_xCbxPickThrough->set_active( aOptsItem.GetOptionsMisc().IsPickThrough() );
607 m_xCbxPickThrough->set_sensitive(!bReadOnly);
608 m_xCbxPickThroughImg->set_visible(bReadOnly);
610 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Misc::BackgroundCache::isReadOnly() :
611 officecfg::Office::Impress::Misc::BackgroundCache::isReadOnly();
612 m_xCbxMasterPageCache->set_active( aOptsItem.GetOptionsMisc().IsMasterPagePaintCaching() );
613 m_xCbxMasterPageCache->set_sensitive(!bReadOnly);
614 m_xCbxMasterPageCacheImg->set_visible(bReadOnly);
616 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Misc::CopyWhileMoving::isReadOnly() :
617 officecfg::Office::Impress::Misc::CopyWhileMoving::isReadOnly();
618 m_xCbxCopy->set_active( aOptsItem.GetOptionsMisc().IsDragWithCopy() );
619 m_xCbxCopy->set_sensitive(!bReadOnly);
620 m_xCbxCopyImg->set_visible(bReadOnly);
622 bReadOnly = m_bDrawMode ? false : officecfg::Office::Impress::Misc::Compatibility::AddBetween::isReadOnly();
623 m_xCbxCompatibility->set_active( aOptsItem.GetOptionsMisc().IsSummationOfParagraphs() );
624 m_xCbxCompatibility->set_sensitive(!bReadOnly);
625 m_xCbxCompatibilityImg->set_visible(bReadOnly);
627 m_xCbxDistort->set_active( aOptsItem.GetOptionsMisc().IsCrookNoContortion() );
628 if (m_bDrawMode)
630 bReadOnly = officecfg::Office::Draw::Misc::NoDistort::isReadOnly();
631 m_xCbxDistort->set_sensitive(!bReadOnly);
632 m_xCbxDistortImg->set_visible(bReadOnly);
635 m_xCbxStartWithTemplate->save_state();
636 m_xCbxMarkedHitMovesAlways->save_state();
637 m_xCbxQuickEdit->save_state();
638 m_xCbxPickThrough->save_state();
640 m_xCbxMasterPageCache->save_state();
641 m_xCbxCopy->save_state();
642 m_xCbxCompatibility->save_state();
643 m_xCbxDistort->save_state();
645 // metric
646 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
647 m_xLbMetric->set_active(-1);
649 if ( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT )
651 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich ));
652 sal_uInt32 nFieldUnit = static_cast<sal_uInt32>(rItem.GetValue());
654 for (sal_Int32 i = 0, nEntryCount = m_xLbMetric->get_count(); i < nEntryCount; ++i)
656 if (m_xLbMetric->get_id(i).toUInt32() == nFieldUnit)
658 m_xLbMetric->set_active( i );
659 break;
664 // tabulator space
665 constexpr auto nWhich2 = SID_ATTR_DEFTABSTOP;
666 if( rAttrs->GetItemState( nWhich2 ) >= SfxItemState::DEFAULT )
668 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWhich2 );
669 const SfxUInt16Item& rItem = rAttrs->Get( nWhich2 );
670 SetMetricValue( *m_xMtrFldTabstop, rItem.GetValue(), eUnit );
673 if (SdOptionsGeneric::isMetricSystem())
675 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::isReadOnly() :
676 officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::isReadOnly();
678 else
680 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::isReadOnly() :
681 officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::isReadOnly();
683 m_xLbMetric->set_sensitive(!bReadOnly);
684 m_xLbMetricImg->set_visible(bReadOnly);
686 if (SdOptionsGeneric::isMetricSystem())
688 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Other::TabStop::Metric::isReadOnly() :
689 officecfg::Office::Impress::Layout::Other::TabStop::Metric::isReadOnly();
691 else
693 bReadOnly = m_bDrawMode ? officecfg::Office::Draw::Layout::Other::TabStop::NonMetric::isReadOnly() :
694 officecfg::Office::Impress::Layout::Other::TabStop::NonMetric::isReadOnly();
696 m_xMtrFldTabstop->set_sensitive(!bReadOnly);
697 m_xMtrFldTabstopImg->set_visible(bReadOnly);
699 m_xLbMetric->save_value();
700 m_xMtrFldTabstop->save_value();
701 //Scale
702 sal_Int32 nX = rAttrs->Get( ATTR_OPTIONS_SCALE_X ).GetValue();
703 sal_Int32 nY = rAttrs->Get( ATTR_OPTIONS_SCALE_Y ).GetValue();
704 nWidth = rAttrs->Get( ATTR_OPTIONS_SCALE_WIDTH ).GetValue();
705 nHeight = rAttrs->Get( ATTR_OPTIONS_SCALE_HEIGHT ).GetValue();
707 m_xCbScale->set_entry_text( GetScale( nX, nY ) );
708 if (m_bDrawMode)
710 bReadOnly = officecfg::Office::Draw::Zoom::ScaleX::isReadOnly() &&
711 officecfg::Office::Draw::Zoom::ScaleY::isReadOnly();
712 m_xCbScale->set_sensitive(!bReadOnly);
713 m_xCbScaleImg->set_visible(bReadOnly);
716 m_xMtrFldOriginalWidth->hide();
717 m_xMtrFldOriginalWidth->set_text( aInfo1 ); // empty
718 m_xMtrFldOriginalHeight->hide();
719 m_xMtrFldOriginalHeight->set_text( aInfo2 ); //empty
720 m_xFiInfo1->hide();
721 m_xFiInfo2->hide();
723 UpdateCompatibilityControls ();
726 std::unique_ptr<SfxTabPage> SdTpOptionsMisc::Create( weld::Container* pPage, weld::DialogController* pController,
727 const SfxItemSet* rAttrs )
729 return std::make_unique<SdTpOptionsMisc>( pPage, pController, *rAttrs );
732 IMPL_LINK_NOARG(SdTpOptionsMisc, SelectMetricHdl_Impl, weld::ComboBox&, void)
734 int nPos = m_xLbMetric->get_active();
735 if (nPos != -1)
737 FieldUnit eUnit = static_cast<FieldUnit>(m_xLbMetric->get_id(nPos).toUInt32());
738 sal_Int64 nVal =
739 m_xMtrFldTabstop->denormalize(m_xMtrFldTabstop->get_value(FieldUnit::TWIP));
740 SetFieldUnit( *m_xMtrFldTabstop, eUnit );
741 m_xMtrFldTabstop->set_value( m_xMtrFldTabstop->normalize( nVal ), FieldUnit::TWIP );
745 void SdTpOptionsMisc::SetDrawMode()
747 m_xScaleFrame->show();
748 m_xNewDocumentFrame->hide();
749 m_xCbxCompatibility->hide();
750 m_xNewDocLb->hide();
751 m_xCbScale->show();
752 m_xMtrFldInfo1->hide();
753 m_xMtrFldInfo2->hide();
754 m_xWidthLb->hide();
755 m_xHeightLb->hide();
756 m_xFiInfo1->show();
757 m_xMtrFldOriginalWidth->show();
758 m_xFiInfo2->show();
759 m_xMtrFldOriginalHeight->show();
760 m_xCbxDistort->show();
761 m_xCbxCompatibility->hide();
763 m_bDrawMode = true;
766 OUString SdTpOptionsMisc::GetScale( sal_Int32 nX, sal_Int32 nY )
768 return OUString::number(nX) + OUStringChar(TOKEN) + OUString::number(nY);
771 bool SdTpOptionsMisc::SetScale( std::u16string_view aScale, sal_Int32& rX, sal_Int32& rY )
773 if (aScale.empty())
774 return false;
776 sal_Int32 nIdx {0};
778 std::u16string_view aTmp(o3tl::getToken(aScale, 0, TOKEN, nIdx));
779 if (nIdx<0)
780 return false; // we expect another token!
782 if (!comphelper::string::isdigitAsciiString(aTmp))
783 return false;
785 rX = static_cast<tools::Long>(o3tl::toInt32(aTmp));
786 if( rX == 0 )
787 return false;
789 aTmp = o3tl::getToken(aScale, 0, TOKEN, nIdx);
790 if (nIdx>=0)
791 return false; // we require just 2 tokens!
793 if (!comphelper::string::isdigitAsciiString(aTmp))
794 return false;
796 rY = static_cast<tools::Long>(o3tl::toInt32(aTmp));
797 return rY != 0;
800 void SdTpOptionsMisc::UpdateCompatibilityControls()
802 // Disable the compatibility controls by default. Enable them only when
803 // there is at least one open document.
804 bool bIsEnabled = false;
808 // Get a component enumeration from the desktop and search it for documents.
809 const Reference<uno::XComponentContext>& xContext( ::comphelper::getProcessComponentContext());
812 Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
814 Reference<container::XEnumerationAccess> xComponents =
815 xDesktop->getComponents();
816 if ( ! xComponents.is())
817 break;
819 Reference<container::XEnumeration> xEnumeration (
820 xComponents->createEnumeration());
821 if ( ! xEnumeration.is())
822 break;
824 while (xEnumeration->hasMoreElements())
826 Reference<frame::XModel> xModel (xEnumeration->nextElement(), UNO_QUERY);
827 if (xModel.is())
829 // There is at least one model/document: Enable the compatibility controls.
830 bIsEnabled = true;
831 break;
836 while (false); // One 'loop'.
838 catch (const uno::Exception&)
840 // When there is an exception then simply use the default value of
841 // bIsEnabled and disable the controls.
844 m_xCbxCompatibility->set_sensitive(bIsEnabled && !officecfg::Office::Impress::Misc::Compatibility::AddBetween::isReadOnly());
847 void SdTpOptionsMisc::PageCreated(const SfxAllItemSet& aSet)
849 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false);
850 if (pFlagItem)
852 sal_uInt32 nFlags=pFlagItem->GetValue();
853 if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
854 SetDrawMode();
858 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */