xref: /core/sw/source/uibase/config/usrpref.cxx (revision 3f916b8614ab615be9eedabfa8bff6603bf4b57e)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <osl/diagnose.h>
23 #include <o3tl/any.hxx>
24 #include <tools/UnitConversion.hxx>
25 #include <comphelper/configuration.hxx>
26 #include <unotools/syslocale.hxx>
27 
28 #include <usrpref.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <unotools/localedatawrapper.hxx>
32 
33 #if defined(__GNUC__) && !defined(__clang__)
34 #include <cstring>
35 #endif
36 
37 using namespace utl;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 
SetUsrPref(const SwViewOption & rCopy)41 void SwMasterUsrPref::SetUsrPref(const SwViewOption &rCopy)
42 {
43     *static_cast<SwViewOption*>(this) = rCopy;
44 }
45 
lclGetFieldUnit()46 static FieldUnit lclGetFieldUnit()
47 {
48     if (comphelper::IsFuzzing())
49         return FieldUnit::CM;
50     MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
51     return MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH;
52 }
53 
SwMasterUsrPref(bool bWeb)54 SwMasterUsrPref::SwMasterUsrPref(bool bWeb) :
55     m_eFieldUpdateFlags(AUTOUPD_OFF),
56     m_nLinkUpdateMode(0),
57     m_eUserMetric(lclGetFieldUnit()),
58     m_eHScrollMetric(m_eUserMetric),
59     m_bIsHScrollMetricSet(false),
60     m_eVScrollMetric(m_eUserMetric),
61     m_bIsVScrollMetricSet(false),
62     m_nDefTabInMm100( 2000 ), // 2 cm
63     m_bIsSquaredPageMode(false),
64     m_bIsAlignMathObjectsToBaseline(false),
65     m_bApplyCharUnit(false),
66     m_bUseDefaultZoom(true),
67     m_nDefaultZoomValue(100),
68     m_eDefaultZoomType(SvxZoomType::PERCENT),
69     m_aContentConfig(bWeb, *this),
70     m_aLayoutConfig(bWeb, *this),
71     m_aGridConfig(bWeb, *this),
72     m_aCursorConfig(*this),
73     m_pWebColorConfig(bWeb ? new SwWebColorConfig(*this) : nullptr),
74     m_aFmtAidsAutoComplConfig(*this)
75 {
76     if (comphelper::IsFuzzing())
77     {
78         // match defaults
79         SetCore2Option(true, ViewOptCoreFlags2::CursorInProt);
80         SetCore2Option(false, ViewOptCoreFlags2::HiddenPara);
81         m_nDefTabInMm100 = 1250;
82         return;
83     }
84 }
85 
~SwMasterUsrPref()86 SwMasterUsrPref::~SwMasterUsrPref()
87 {
88 }
89 
90 const auto g_UpdateLinkIndex = 17;
91 const auto g_DefaultAnchor = 25;
92 const auto g_ZoomType = 27;
93 const auto g_ZoomValue = 28;
94 
GetPropertyNames() const95 Sequence<OUString> SwContentViewConfig::GetPropertyNames() const
96 {
97     static constexpr const char*const aPropNames[] =
98     {
99         "Display/GraphicObject",                    //  0
100         "Display/Table",                            //  1
101         "Display/DrawingControl",                   //  2
102         "Display/FieldCode",                        //  3
103         "Display/Note",                             //  4
104         "Display/ShowContentTips",                  //  5
105         "NonprintingCharacter/MetaCharacters",      //  6
106         "NonprintingCharacter/ParagraphEnd",        //  7
107         "NonprintingCharacter/OptionalHyphen",      //  8
108         "NonprintingCharacter/Space",               //  9
109         "NonprintingCharacter/Break",               // 10
110         "NonprintingCharacter/ProtectedSpace",      // 11
111         "NonprintingCharacter/Tab",             // 12 //not in Writer/Web
112         "NonprintingCharacter/HiddenText",      // 13
113         "NonprintingCharacter/HiddenParagraph", // 14
114         "NonprintingCharacter/HiddenCharacter",      // 15
115         "NonprintingCharacter/Bookmarks",       // 16
116         "Update/Link",                          // 17
117         "Update/Field",                         // 18
118         "Update/Chart",                         // 19
119         "Display/ShowInlineTooltips",           // 20
120         "Display/UseHeaderFooterMenu",          // 21
121         "Display/ShowOutlineContentVisibilityButton", // 22
122         "Display/TreatSubOutlineLevelsAsContent",     // 23
123         "Display/ShowChangesInMargin",          // 24
124         "Display/DefaultAnchor",                // 25
125         "Zoom/DefaultZoom",                     // 26
126         "Zoom/ZoomType",                        // 27
127         "Zoom/ZoomValue",                       // 28
128         "Display/TextBoundaries",               // 29
129         "Display/TextBoundariesFull",           // 30
130         "Display/SectionBoundaries",            // 31
131         "Display/TableBoundaries",              // 32
132         "Display/ShowBoundaries",               // 33
133         "Draw/ClickChangeRotation"              // 34
134     };
135 #if defined(__GNUC__) && !defined(__clang__)
136     // clang 8.0.0 says strcmp isn't constexpr
137     static_assert(std::strcmp("Update/Link", aPropNames[g_UpdateLinkIndex]) == 0);
138     static_assert(std::strcmp("Display/DefaultAnchor", aPropNames[g_DefaultAnchor]) == 0);
139     static_assert(std::strcmp("Zoom/ZoomType", aPropNames[g_ZoomType]) == 0);
140     static_assert(std::strcmp("Zoom/ZoomValue", aPropNames[g_ZoomValue]) == 0);
141 #endif
142     const int nCount = m_bWeb ? 12 : SAL_N_ELEMENTS(aPropNames);
143     Sequence<OUString> aNames(nCount);
144     OUString* pNames = aNames.getArray();
145     for(int i = 0; i < nCount; i++)
146     {
147         pNames[i] = OUString::createFromAscii(aPropNames[i]);
148     }
149     return aNames;
150 }
151 
SwContentViewConfig(bool bIsWeb,SwMasterUsrPref & rPar)152 SwContentViewConfig::SwContentViewConfig(bool bIsWeb, SwMasterUsrPref& rPar) :
153     ConfigItem(bIsWeb ? u"Office.WriterWeb/Content"_ustr :  u"Office.Writer/Content"_ustr),
154     m_rParent(rPar),
155     m_bWeb(bIsWeb)
156 {
157     Load();
158     EnableNotification( GetPropertyNames() );
159 }
160 
~SwContentViewConfig()161 SwContentViewConfig::~SwContentViewConfig()
162 {
163 }
164 
Notify(const Sequence<OUString> &)165 void SwContentViewConfig::Notify( const Sequence< OUString > & /*rPropertyNames*/ )
166 {
167     Load();
168 }
169 
ImplCommit()170 void SwContentViewConfig::ImplCommit()
171 {
172     Sequence<OUString> aNames = GetPropertyNames();
173 
174     Sequence<Any> aValues(aNames.getLength());
175     Any* pValues = aValues.getArray();
176 
177     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
178     {
179         bool bVal = false;
180         switch(nProp)
181         {
182             case  0: bVal = m_rParent.IsGraphic();    break;// "Display/GraphicObject",
183             case  1: bVal = m_rParent.IsTable();  break;// "Display/Table",
184             case  2: bVal = m_rParent.IsDraw();       break;// "Display/DrawingControl",
185             case  3: bVal = m_rParent.IsFieldName();    break;// "Display/FieldCode",
186             case  4: bVal = m_rParent.IsPostIts();    break;// "Display/Note",
187             case  5: bVal = m_rParent.IsShowContentTips(); break; // "Display/ShowContentTips"
188             case  6: bVal = m_rParent.IsViewMetaChars(); break; //"NonprintingCharacter/MetaCharacters"
189             case  7: bVal = m_rParent.IsParagraph(true); break;// "NonprintingCharacter/ParagraphEnd",
190             case  8: bVal = m_rParent.IsSoftHyph(); break;// "NonprintingCharacter/OptionalHyphen",
191             case  9: bVal = m_rParent.IsBlank(true);  break;// "NonprintingCharacter/Space",
192             case 10: bVal = m_rParent.IsLineBreak(true);break;// "NonprintingCharacter/Break",
193             case 11: bVal = m_rParent.IsHardBlank(); break;// "NonprintingCharacter/ProtectedSpace",
194             case 12: bVal = m_rParent.IsTab(true);        break;// "NonprintingCharacter/Tab",
195             case 13: bVal = m_rParent.IsShowHiddenField(); break;// "NonprintingCharacter/Fields: HiddenText",
196             case 14: bVal = m_rParent.IsShowHiddenPara(); break;// "NonprintingCharacter/Fields: HiddenParagraph",
197             case 15: bVal = m_rParent.IsShowHiddenChar(true);    break;// "NonprintingCharacter/HiddenCharacter",
198             case 16: bVal = m_rParent.IsShowBookmarks(true);    break;// "NonprintingCharacter/Bookmarks",
199             case 17: pValues[nProp] <<= m_rParent.GetUpdateLinkMode();    break;// "Update/Link",
200             case 18: bVal = m_rParent.IsUpdateFields(); break;// "Update/Field",
201             case 19: bVal = m_rParent.IsUpdateCharts(); break;// "Update/Chart"
202             case 20: bVal = m_rParent.IsShowInlineTooltips(); break;// "Display/ShowInlineTooltips"
203             case 21: bVal = m_rParent.IsUseHeaderFooterMenu(); break;// "Display/UseHeaderFooterMenu"
204             case 22: bVal = m_rParent.IsShowOutlineContentVisibilityButton(); break;// "Display/ShowOutlineContentVisibilityButton"
205             case 23: bVal = m_rParent.IsTreatSubOutlineLevelsAsContent(); break;// "Display/TreatSubOutlineLevelsAsContent"
206             case 24: bVal = m_rParent.IsShowChangesInMargin(); break;// "Display/ShowChangesInMargin"
207             case 25: pValues[nProp] <<= m_rParent.GetDefaultAnchor(); break;// "Display/DefaultAnchor"
208                 //TODO: Save zoom preferred, zoom type, zoom value
209             case 26: bVal = m_rParent.IsDefaultZoom(); break;// "Zoom/DefaultZoom"
210             case 27:pValues[nProp] <<= static_cast<sal_Int32>(m_rParent.GetDefaultZoomType()); break; // "Zoom/ZoomType"
211             case 28: pValues[nProp] <<= static_cast<sal_Int32>(m_rParent.GetDefaultZoomValue()); break; // "Zoom/ZoomValue"
212             case 29: bVal = m_rParent.IsTextBoundaries(); break; // "Display/TextBoundaries"
213             case 30: bVal = m_rParent.IsTextBoundariesFull(); break; // "Display/TextBoundariesFull"
214             case 31: bVal = m_rParent.IsSectionBoundaries(); break; // "Display/SectionBoundaries"
215             case 32: bVal = m_rParent.IsTableBoundaries(); break; // "Display/TableBoundaries"
216             case 33: bVal = m_rParent.IsShowBoundaries(); break; // "Display/ShowBoundaries"
217             case 34: bVal = m_rParent.IsClickChangeRotation(); break; // "Draw/ClickChangeRotation"
218         }
219         if ((nProp != g_UpdateLinkIndex) && (nProp != g_DefaultAnchor) &&
220             (nProp != g_ZoomType) && (nProp != g_ZoomValue))
221             pValues[nProp] <<= bVal;
222     }
223     PutProperties(aNames, aValues);
224 }
225 
Load()226 void SwContentViewConfig::Load()
227 {
228     Sequence<OUString> aNames = GetPropertyNames();
229     Sequence<Any> aValues = GetProperties(aNames);
230     const Any* pValues = aValues.getConstArray();
231     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
232     if(aValues.getLength() != aNames.getLength())
233         return;
234     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
235     {
236         if(pValues[nProp].hasValue())
237         {
238             bool bSet = ((nProp != g_UpdateLinkIndex) && (nProp != g_DefaultAnchor) && (nProp != g_ZoomType)&& (nProp != g_ZoomValue))
239                         && *o3tl::doAccess<bool>(pValues[nProp]);
240             switch(nProp)
241             {
242                 case  0: m_rParent.SetGraphic(bSet);  break;// "Display/GraphicObject",
243                 case  1: m_rParent.SetTable(bSet);    break;// "Display/Table",
244                 case  2: m_rParent.SetDraw(bSet);     break;// "Display/DrawingControl",
245                 case  3: m_rParent.SetFieldName(bSet);  break;// "Display/FieldCode",
246                 case  4: m_rParent.SetPostIts(bSet);  break;// "Display/Note",
247                 case  5: m_rParent.SetShowContentTips(bSet);  break;// "Display/ShowContentTips",
248                 case  6: m_rParent.SetViewMetaChars(bSet); break; //"NonprintingCharacter/MetaCharacters"
249                 case  7: m_rParent.SetParagraph(bSet); break;// "NonprintingCharacter/ParagraphEnd",
250                 case  8: m_rParent.SetSoftHyph(bSet); break;// "NonprintingCharacter/OptionalHyphen",
251                 case  9: m_rParent.SetBlank(bSet);    break;// "NonprintingCharacter/Space",
252                 case 10: m_rParent.SetLineBreak(bSet);break;// "NonprintingCharacter/Break",
253                 case 11: m_rParent.SetHardBlank(bSet); break;// "NonprintingCharacter/ProtectedSpace",
254                 case 12: m_rParent.SetTab(bSet);      break;// "NonprintingCharacter/Tab",
255                 case 13: m_rParent.SetShowHiddenField(bSet);   break;// "NonprintingCharacter/Fields: HiddenText",
256                 case 14: m_rParent.SetShowHiddenPara(bSet); break;// "NonprintingCharacter/Fields: HiddenParagraph",
257                 case 15: m_rParent.SetShowHiddenChar(bSet); break;// "NonprintingCharacter/HiddenCharacter",
258                 case 16: m_rParent.SetShowBookmarks(bSet); break;// "NonprintingCharacter/Bookmarks",
259                 case 17:
260                 {
261                     sal_Int32 nSet = 0;
262                     pValues[nProp] >>= nSet;
263                     m_rParent.SetUpdateLinkMode(nSet, true);
264                 }
265                 break;// "Update/Link",
266                 case 18: m_rParent.SetUpdateFields(bSet); break;// "Update/Field",
267                 case 19: m_rParent.SetUpdateCharts(bSet); break;// "Update/Chart"
268                 case 20: m_rParent.SetShowInlineTooltips(bSet); break;// "Display/ShowInlineTooltips"
269                 case 21: m_rParent.SetUseHeaderFooterMenu(bSet); break;// "Display/UseHeaderFooterMenu"
270                 case 22: m_rParent.SetShowOutlineContentVisibilityButton(bSet); break;// "Display/ShowOutlineContententVisibilityButton"
271                 case 23: m_rParent.SetTreatSubOutlineLevelsAsContent(bSet); break;// "Display/TreatSubOutlineLevelsAsContent"
272                 case 24: m_rParent.SetShowChangesInMargin(bSet); break;// "Display/ShowChangesInMargin"
273                 case 25:
274                 {
275                     sal_Int32 nSet = 0;
276                     pValues[nProp] >>= nSet;
277                     m_rParent.SetDefaultAnchor(nSet);
278                 }
279                 break; // "Display/DefaultAnchor"
280                 case 26:  m_rParent.SetDefaultZoom(bSet); break; // "Zoom/DefaultZoom"
281                 case 27:
282                 {
283                     sal_Int32 nSet = 0;
284                     pValues[nProp] >>= nSet;
285                     m_rParent.SetDefaultZoomType(static_cast<SvxZoomType>(nSet), true);
286                 }
287                 break; //"Zoom/ZoomType", // 27
288                 case 28:
289                 {
290                     sal_Int32 nSet = 0;
291                     pValues[nProp] >>= nSet;
292                     m_rParent.SetDefaultZoomValue(static_cast<sal_uInt16>(nSet), true);
293                 }
294                 break; //"Zoom/ZoomValue" // 28
295                 case 29: m_rParent.SetTextBoundaries(bSet); break; //"Display/TextBoundaries"
296                 case 30: m_rParent.SetTextBoundariesFull(bSet); break; //"Display/TextBoundariesFull"
297                 case 31: m_rParent.SetSectionBoundaries(bSet); break; //"Display/SectionBoundaries"
298                 case 32: m_rParent.SetTableBoundaries(bSet); break; //"Display/TableBoundaries"
299                 case 33: m_rParent.SetShowBoundaries(bSet); break; //"Display/ShowBoundaries"
300                 case 34: m_rParent.SetClickChangeRotation(bSet); break; // "Draw/ClickChangeRotation"
301             }
302         }
303     }
304 }
305 
GetPropertyNames() const306 Sequence<OUString> SwLayoutViewConfig::GetPropertyNames() const
307 {
308     static const char* const aPropNames[] =
309     {
310         "Line/Guide",                           // 0
311         "Window/HorizontalScroll",              // 1
312         "Window/VerticalScroll",                // 2
313         "Window/ShowRulers",                    // 3
314         "Window/HorizontalRuler",               // 4
315         "Window/VerticalRuler",                 // 5
316         "Window/HorizontalRulerUnit",           // 6
317         "Window/VerticalRulerUnit",             // 7
318         "Window/SmoothScroll",                  // 8
319         "Zoom/Value",                           // 9
320         "Zoom/Type",                            //10
321         "Other/IsAlignMathObjectsToBaseline",   //11
322         "Other/MeasureUnit",                    //12
323         // below properties are not available in WriterWeb
324         "Other/TabStop",                        //13
325         "Window/IsVerticalRulerRight",          //14
326         "ViewLayout/Columns",                   //15
327         "ViewLayout/BookMode",                  //16
328         "Other/IsSquaredPageMode",              //17
329         "Other/ApplyCharUnit",                  //18
330         "Window/ShowScrollBarTips",             //19
331     };
332     const int nCount = m_bWeb ? 13 : 20;
333     Sequence<OUString> aNames(nCount);
334     OUString* pNames = aNames.getArray();
335     for(int i = 0; i < nCount; i++)
336     {
337         pNames[i] = OUString::createFromAscii(aPropNames[i]);
338     }
339     return aNames;
340 }
341 
SwLayoutViewConfig(bool bIsWeb,SwMasterUsrPref & rPar)342 SwLayoutViewConfig::SwLayoutViewConfig(bool bIsWeb, SwMasterUsrPref& rPar)
343     : ConfigItem(bIsWeb ? u"Office.WriterWeb/Layout"_ustr :  u"Office.Writer/Layout"_ustr)
344     , m_rParent(rPar)
345     , m_bWeb(bIsWeb)
346 {
347     Load();
348     EnableNotification(GetPropertyNames());
349 }
350 
~SwLayoutViewConfig()351 SwLayoutViewConfig::~SwLayoutViewConfig()
352 {
353 }
354 
ImplCommit()355 void SwLayoutViewConfig::ImplCommit()
356 {
357     Sequence<OUString> aNames = GetPropertyNames();
358 
359     Sequence<Any> aValues(aNames.getLength());
360     Any* pValues = aValues.getArray();
361 
362     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
363     {
364         Any &rVal = pValues[nProp];
365         switch(nProp)
366         {
367             case  0: rVal <<= m_rParent.IsCrossHair(); break;              // "Line/Guide",
368             case  1: rVal <<= m_rParent.IsViewHScrollBar(); break;         // "Window/HorizontalScroll",
369             case  2: rVal <<= m_rParent.IsViewVScrollBar(); break;         // "Window/VerticalScroll",
370             case  3: rVal <<= m_rParent.IsViewAnyRuler(); break;           // "Window/ShowRulers"
371             // #i14593# use IsView*Ruler(true) instead of IsView*Ruler()
372             // this preserves the single ruler states even if "Window/ShowRulers" is off
373             case  4: rVal <<= m_rParent.IsViewHRuler(true); break;         // "Window/HorizontalRuler",
374             case  5: rVal <<= m_rParent.IsViewVRuler(true); break;         // "Window/VerticalRuler",
375             case  6:
376                 if(m_rParent.m_bIsHScrollMetricSet)
377                     rVal <<= static_cast<sal_Int32>(m_rParent.m_eHScrollMetric);                     // "Window/HorizontalRulerUnit"
378             break;
379             case  7:
380                 if(m_rParent.m_bIsVScrollMetricSet)
381                     rVal <<= static_cast<sal_Int32>(m_rParent.m_eVScrollMetric);                     // "Window/VerticalRulerUnit"
382             break;
383             case  8: rVal <<= m_rParent.IsSmoothScroll(); break;                      // "Window/SmoothScroll",
384             case  9: rVal <<= static_cast<sal_Int32>(m_rParent.GetZoom()); break;                  // "Zoom/Value",
385             case 10: rVal <<= static_cast<sal_Int32>(m_rParent.GetZoomType()); break;              // "Zoom/Type",
386             case 11: rVal <<= m_rParent.IsAlignMathObjectsToBaseline(); break;        // "Other/IsAlignMathObjectsToBaseline"
387             case 12: rVal <<= static_cast<sal_Int32>(m_rParent.GetMetric()); break;                // "Other/MeasureUnit",
388             case 13: rVal <<= m_rParent.GetDefTabInMm100(); break;// "Other/TabStop",
389             case 14: rVal <<= m_rParent.IsVRulerRight(); break;                       // "Window/IsVerticalRulerRight",
390             case 15: rVal <<= static_cast<sal_Int32>(m_rParent.GetViewLayoutColumns()); break;     // "ViewLayout/Columns",
391             case 16: rVal <<= m_rParent.IsViewLayoutBookMode(); break;                // "ViewLayout/BookMode",
392             case 17: rVal <<= m_rParent.IsSquaredPageMode(); break;                   // "Other/IsSquaredPageMode",
393             case 18: rVal <<= m_rParent.IsApplyCharUnit(); break;                     // "Other/ApplyCharUnit",
394             case 19: rVal <<= m_rParent.IsShowScrollBarTips(); break;                 // "Window/ShowScrollBarTips",
395         }
396     }
397     PutProperties(aNames, aValues);
398 }
399 
Load()400 void SwLayoutViewConfig::Load()
401 {
402     Sequence<OUString> aNames = GetPropertyNames();
403     Sequence<Any> aValues = GetProperties(aNames);
404     const Any* pValues = aValues.getConstArray();
405     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
406     if(aValues.getLength() != aNames.getLength())
407         return;
408 
409     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
410     {
411         if(pValues[nProp].hasValue())
412         {
413             sal_Int32   nInt32Val   = 0;
414             bool    bSet        = false;
415             pValues[nProp] >>= nInt32Val;
416             pValues[nProp] >>= bSet;
417 
418             switch(nProp)
419             {
420                 case  0: m_rParent.SetCrossHair(bSet); break;// "Line/Guide",
421                 case  1: m_rParent.SetViewHScrollBar(bSet); break;// "Window/HorizontalScroll",
422                 case  2: m_rParent.SetViewVScrollBar(bSet); break;// "Window/VerticalScroll",
423                 case  3: m_rParent.SetViewAnyRuler(bSet);break; // "Window/ShowRulers"
424                 case  4: m_rParent.SetViewHRuler(bSet); break;// "Window/HorizontalRuler",
425                 case  5: m_rParent.SetViewVRuler(bSet); break;// "Window/VerticalRuler",
426                 case  6:
427                 {
428                     m_rParent.m_bIsHScrollMetricSet = true;
429                     m_rParent.m_eHScrollMetric = static_cast<FieldUnit>(nInt32Val);  // "Window/HorizontalRulerUnit"
430                 }
431                 break;
432                 case  7:
433                 {
434                     m_rParent.m_bIsVScrollMetricSet = true;
435                     m_rParent.m_eVScrollMetric = static_cast<FieldUnit>(nInt32Val); // "Window/VerticalRulerUnit"
436                 }
437                 break;
438                 case  8: m_rParent.SetSmoothScroll(bSet); break;// "Window/SmoothScroll",
439                 case  9: m_rParent.SetZoom( static_cast< sal_uInt16 >(nInt32Val) ); break;// "Zoom/Value",
440                 case 10: m_rParent.SetZoomType( static_cast< SvxZoomType >(nInt32Val) ); break;// "Zoom/Type",
441                 case 11: m_rParent.SetAlignMathObjectsToBaseline(bSet, true); break;// "Other/IsAlignMathObjectsToBaseline"
442                 case 12: m_rParent.SetMetric(static_cast<FieldUnit>(nInt32Val), true); break;// "Other/MeasureUnit",
443                 case 13: m_rParent.SetDefTabInMm100(nInt32Val, true); break;// "Other/TabStop",
444                 case 14: m_rParent.SetVRulerRight(bSet); break;// "Window/IsVerticalRulerRight",
445                 case 15: m_rParent.SetViewLayoutColumns( o3tl::narrowing<sal_uInt16>(nInt32Val) ); break;// "ViewLayout/Columns",
446                 case 16: m_rParent.SetViewLayoutBookMode(bSet); break;// "ViewLayout/BookMode",
447                 case 17: m_rParent.SetDefaultPageMode(bSet,true); break;// "Other/IsSquaredPageMode",
448                 case 18: m_rParent.SetApplyCharUnit(bSet, true); break;// "Other/ApplyUserChar"
449                 case 19: m_rParent.SetShowScrollBarTips(bSet); break;// "Window/ShowScrollBarTips",
450             }
451         }
452     }
453 }
454 
Notify(const css::uno::Sequence<OUString> &)455 void SwLayoutViewConfig::Notify(const css::uno::Sequence<OUString>&)
456 {
457     Load();
458 }
459 
GetPropertyNames()460 Sequence<OUString> SwGridConfig::GetPropertyNames()
461 {
462     static const char* const aPropNames[] =
463     {
464         "Option/SnapToGrid",            // 0
465         "Option/VisibleGrid",           // 1
466         "Option/Synchronize",           // 2
467         "Resolution/XAxis",             // 3
468         "Resolution/YAxis",             // 4
469         "Subdivision/XAxis",            // 5
470         "Subdivision/YAxis"             // 6
471     };
472     const int nCount = 7;
473     Sequence<OUString> aNames(nCount);
474     OUString* pNames = aNames.getArray();
475     for(int i = 0; i < nCount; i++)
476     {
477         pNames[i] = OUString::createFromAscii(aPropNames[i]);
478     }
479     return aNames;
480 }
481 
SwGridConfig(bool bIsWeb,SwMasterUsrPref & rPar)482 SwGridConfig::SwGridConfig(bool bIsWeb, SwMasterUsrPref& rPar) :
483     ConfigItem(bIsWeb ? u"Office.WriterWeb/Grid"_ustr :  u"Office.Writer/Grid"_ustr),
484     m_rParent(rPar)
485 {
486     Load();
487     EnableNotification(GetPropertyNames());
488 }
489 
~SwGridConfig()490 SwGridConfig::~SwGridConfig()
491 {
492 }
493 
ImplCommit()494 void SwGridConfig::ImplCommit()
495 {
496     Sequence<OUString> aNames = GetPropertyNames();
497 
498     Sequence<Any> aValues(aNames.getLength());
499     Any* pValues = aValues.getArray();
500 
501     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
502     {
503         switch(nProp)
504         {
505             case  0: pValues[nProp] <<= m_rParent.IsSnap(); break;//      "Option/SnapToGrid",
506             case  1: pValues[nProp] <<= m_rParent.IsGridVisible(); break;//"Option/VisibleGrid",
507             case  2: pValues[nProp] <<= m_rParent.IsSynchronize(); break;//  "Option/Synchronize",
508             case  3: pValues[nProp] <<= static_cast<sal_Int32>(convertTwipToMm100(m_rParent.GetSnapSize().Width())); break;//      "Resolution/XAxis",
509             case  4: pValues[nProp] <<= static_cast<sal_Int32>(convertTwipToMm100(m_rParent.GetSnapSize().Height())); break;//      "Resolution/YAxis",
510             case  5: pValues[nProp] <<= static_cast<sal_Int16>(m_rParent.GetDivisionX()); break;//   "Subdivision/XAxis",
511             case  6: pValues[nProp] <<= static_cast<sal_Int16>(m_rParent.GetDivisionY()); break;//   "Subdivision/YAxis"
512         }
513     }
514     PutProperties(aNames, aValues);
515 }
516 
Load()517 void SwGridConfig::Load()
518 {
519     Sequence<OUString> aNames = GetPropertyNames();
520     Sequence<Any> aValues = GetProperties(aNames);
521     const Any* pValues = aValues.getConstArray();
522     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
523     if(aValues.getLength() != aNames.getLength())
524         return;
525 
526     Size aSnap(m_rParent.GetSnapSize());
527     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
528     {
529         if(pValues[nProp].hasValue())
530         {
531             bool bSet = nProp < 3 && *o3tl::doAccess<bool>(pValues[nProp]);
532             sal_Int32 nSet = 0;
533             if(nProp >= 3)
534                 pValues[nProp] >>= nSet;
535             switch(nProp)
536             {
537                 case  0: m_rParent.SetSnap(bSet); break;//        "Option/SnapToGrid",
538                 case  1: m_rParent.SetGridVisible(bSet); break;//"Option/VisibleGrid",
539                 case  2: m_rParent.SetSynchronize(bSet); break;//  "Option/Synchronize",
540                 case  3: aSnap.setWidth( o3tl::toTwips(nSet, o3tl::Length::mm100) ); break;//      "Resolution/XAxis",
541                 case  4: aSnap.setHeight( o3tl::toTwips(nSet, o3tl::Length::mm100) ); break;//      "Resolution/YAxis",
542                 case  5: m_rParent.SetDivisionX(static_cast<short>(nSet)); break;//   "Subdivision/XAxis",
543                 case  6: m_rParent.SetDivisionY(static_cast<short>(nSet)); break;//   "Subdivision/YAxis"
544             }
545         }
546     }
547     m_rParent.SetSnapSize(aSnap);
548 }
549 
Notify(const css::uno::Sequence<OUString> &)550 void SwGridConfig::Notify( const css::uno::Sequence< OUString >& )
551 {
552     Load();
553 }
554 
GetPropertyNames()555 Sequence<OUString> SwCursorConfig::GetPropertyNames()
556 {
557     static const char* const aPropNames[] =
558     {
559         "DirectCursor/UseDirectCursor", // 0
560         "DirectCursor/Insert",          // 1
561         "Option/ProtectedArea",         // 2
562     };
563     const int nCount = SAL_N_ELEMENTS(aPropNames);
564     Sequence<OUString> aNames(nCount);
565     OUString* pNames = aNames.getArray();
566     for(int i = 0; i < nCount; i++)
567         pNames[i] = OUString::createFromAscii(aPropNames[i]);
568     return aNames;
569 }
570 
SwCursorConfig(SwMasterUsrPref & rPar)571 SwCursorConfig::SwCursorConfig(SwMasterUsrPref& rPar)
572     : ConfigItem(u"Office.Writer/Cursor"_ustr)
573     , m_rParent(rPar)
574 {
575     Load();
576     EnableNotification(GetPropertyNames());
577 }
578 
~SwCursorConfig()579 SwCursorConfig::~SwCursorConfig()
580 {
581 }
582 
ImplCommit()583 void SwCursorConfig::ImplCommit()
584 {
585     Sequence<OUString> aNames = GetPropertyNames();
586 
587     Sequence<Any> aValues(aNames.getLength());
588     Any* pValues = aValues.getArray();
589 
590     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
591     {
592         switch(nProp)
593         {
594             case  0: pValues[nProp] <<= m_rParent.IsShadowCursor();                   break; // "DirectCursor/UseDirectCursor",
595             case  1: pValues[nProp] <<= static_cast<sal_Int32>(m_rParent.GetShdwCursorFillMode()); break; // "DirectCursor/Insert",
596             case  2: pValues[nProp] <<= m_rParent.IsCursorInProtectedArea();          break; // "Option/ProtectedArea"
597         }
598     }
599     PutProperties(aNames, aValues);
600 }
601 
Load()602 void SwCursorConfig::Load()
603 {
604     Sequence<OUString> aNames = GetPropertyNames();
605     Sequence<Any> aValues = GetProperties(aNames);
606     const Any* pValues = aValues.getConstArray();
607     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
608     if(aValues.getLength() != aNames.getLength())
609         return;
610 
611 
612     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
613     {
614         if(pValues[nProp].hasValue())
615         {
616             bool bSet = false;
617             sal_Int32 nSet = 0;
618             if(nProp != 1 )
619                 bSet = *o3tl::doAccess<bool>(pValues[nProp]);
620             else
621                 pValues[nProp] >>= nSet;
622             switch(nProp)
623             {
624                 case  0: m_rParent.SetShadowCursor(bSet);                  break; // "DirectCursor/UseDirectCursor",
625                 case  1: m_rParent.SetShdwCursorFillMode(static_cast<SwFillMode>(nSet)); break; // "DirectCursor/Insert",
626                 case  2: m_rParent.SetCursorInProtectedArea(bSet);         break; // "Option/ProtectedArea"
627             }
628         }
629     }
630 }
631 
Notify(const css::uno::Sequence<OUString> &)632 void SwCursorConfig::Notify(const css::uno::Sequence<OUString>& )
633 {
634     Load();
635 }
636 
GetPropertyNames()637 Sequence<OUString> SwFmtAidsAutoComplConfig::GetPropertyNames()
638 {
639     static const char* const aPropNames[] = {
640         "EncloseWithCharacters", // 0
641     };
642     const int nCount = SAL_N_ELEMENTS(aPropNames);
643     Sequence<OUString> aNames(nCount);
644     OUString* pNames = aNames.getArray();
645     for (int i = 0; i < nCount; i++)
646         pNames[i] = OUString::createFromAscii(aPropNames[i]);
647     return aNames;
648 }
649 
SwFmtAidsAutoComplConfig(SwMasterUsrPref & rPar)650 SwFmtAidsAutoComplConfig::SwFmtAidsAutoComplConfig(SwMasterUsrPref& rPar)
651     : ConfigItem(u"Office.Writer/FmtAidsAutocomplete"_ustr)
652     , m_rParent(rPar)
653 {
654     Load();
655     EnableNotification(GetPropertyNames());
656 }
657 
~SwFmtAidsAutoComplConfig()658 SwFmtAidsAutoComplConfig::~SwFmtAidsAutoComplConfig() {}
659 
ImplCommit()660 void SwFmtAidsAutoComplConfig::ImplCommit()
661 {
662     Sequence<OUString> aNames = GetPropertyNames();
663 
664     Sequence<Any> aValues(aNames.getLength());
665     Any* pValues = aValues.getArray();
666 
667     for (int nProp = 0; nProp < aNames.getLength(); nProp++)
668     {
669         switch (nProp)
670         {
671             case 0:
672                 pValues[nProp] <<= m_rParent.IsEncloseWithCharactersOn();
673                 break; // "FmtAidsAutocomplete/EncloseWithCharacters"
674         }
675     }
676     PutProperties(aNames, aValues);
677 }
678 
Load()679 void SwFmtAidsAutoComplConfig::Load()
680 {
681     Sequence<OUString> aNames = GetPropertyNames();
682     Sequence<Any> aValues = GetProperties(aNames);
683     const Any* pValues = aValues.getConstArray();
684     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
685     if (aValues.getLength() != aNames.getLength())
686         return;
687 
688     for (int nProp = 0; nProp < aNames.getLength(); nProp++)
689     {
690         if (pValues[nProp].hasValue())
691         {
692             switch (nProp)
693             {
694                 case 0:
695                 {
696                     bool bSet = false;
697                     pValues[nProp] >>= bSet;
698                     m_rParent.SetEncloseWithCharactersOn(bSet);
699                     break; // "FmtAidsAutocomplete/EncloseWithCharacters"
700                 }
701             }
702         }
703     }
704 }
705 
Notify(const css::uno::Sequence<OUString> &)706 void SwFmtAidsAutoComplConfig::Notify(const css::uno::Sequence<OUString>&)
707 {
708     Load();
709 }
710 
SwWebColorConfig(SwMasterUsrPref & rPar)711 SwWebColorConfig::SwWebColorConfig(SwMasterUsrPref& rPar)
712     : ConfigItem(u"Office.WriterWeb/Background"_ustr)
713     , m_rParent(rPar)
714     , m_aPropNames(1)
715 {
716     m_aPropNames.getArray()[0] = "Color";
717     Load();
718     EnableNotification(m_aPropNames);
719 }
720 
~SwWebColorConfig()721 SwWebColorConfig::~SwWebColorConfig()
722 {
723 }
724 
ImplCommit()725 void SwWebColorConfig::ImplCommit()
726 {
727     Sequence<Any> aValues(m_aPropNames.getLength());
728     Any* pValues = aValues.getArray();
729     for(int nProp = 0; nProp < m_aPropNames.getLength(); nProp++)
730     {
731         switch(nProp)
732         {
733             case  0: pValues[nProp] <<= m_rParent.GetRetoucheColor();   break;// "Color",
734         }
735     }
736     PutProperties(m_aPropNames, aValues);
737 }
738 
Notify(const css::uno::Sequence<OUString> &)739 void SwWebColorConfig::Notify(const css::uno::Sequence<OUString>&)
740 {
741     Load();
742 }
743 
Load()744 void SwWebColorConfig::Load()
745 {
746     Sequence<Any> aValues = GetProperties(m_aPropNames);
747     const Any* pValues = aValues.getConstArray();
748     OSL_ENSURE(aValues.getLength() == m_aPropNames.getLength(), "GetProperties failed");
749     if(aValues.getLength() != m_aPropNames.getLength())
750         return;
751 
752     for(int nProp = 0; nProp < m_aPropNames.getLength(); nProp++)
753     {
754         if(pValues[nProp].hasValue())
755         {
756             switch(nProp)
757             {
758                 case  0:
759                     Color nSet;
760                     pValues[nProp] >>= nSet; m_rParent.SetRetoucheColor(nSet);
761                 break;// "Color",
762             }
763         }
764     }
765 }
766 
767 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
768