LibreOffice Module sw (master)  1
navicfg.cxx
Go to the documentation of this file.
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 <swtypes.hxx>
21 #include <navicfg.hxx>
22 #include <swcont.hxx>
23 #include <o3tl/any.hxx>
24 #include <osl/diagnose.h>
25 #include <sal/log.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <map>
28 
29 using namespace ::utl;
30 using namespace ::com::sun::star::uno;
31 
32 namespace {
33  std::map<OUString, ContentTypeId> mPropNameToContentTypeId
34  {
35  {"TableTracking", ContentTypeId::TABLE},
36  {"FrameTracking", ContentTypeId::FRAME},
37  {"ImageTracking", ContentTypeId::GRAPHIC},
38  {"OLEobjectTracking", ContentTypeId::OLE},
39  {"BookmarkTracking", ContentTypeId::BOOKMARK},
40  {"SectionTracking", ContentTypeId::REGION},
41  {"HyperlinkTracking", ContentTypeId::URLFIELD},
42  {"ReferenceTracking", ContentTypeId::REFERENCE},
43  {"IndexTracking", ContentTypeId::INDEX},
44  {"CommentTracking", ContentTypeId::POSTIT},
45  {"DrawingObjectTracking", ContentTypeId::DRAWOBJECT},
46  {"FieldTracking", ContentTypeId::TEXTFIELD},
47  {"FootnoteTracking", ContentTypeId::FOOTNOTE},
48  {"EndnoteTracking", ContentTypeId::ENDNOTE}
49  };
50 }
51 
53 {
54  return css::uno::Sequence<OUString>{
55  OUString("RootType"),
56  OUString("SelectedPosition"),
57  OUString("OutlineLevel"),
58  OUString("InsertMode"),
59  OUString("ActiveBlock"),
60  OUString("ShowListBox"),
61  OUString("GlobalDocMode"),
62  OUString("OutlineTracking"),
63  OUString("TableTracking"),
64  OUString("SectionTracking"),
65  OUString("FrameTracking"),
66  OUString("ImageTracking"),
67  OUString("OLEobjectTracking"),
68  OUString("BookmarkTracking"),
69  OUString("HyperlinkTracking"),
70  OUString("ReferenceTracking"),
71  OUString("IndexTracking"),
72  OUString("CommentTracking"),
73  OUString("DrawingObjectTracking"),
74  OUString("FieldTracking"),
75  OUString("FootnoteTracking"),
76  OUString("EndnoteTracking"),
77  OUString("NavigateOnSelect")};
78 }
79 
81  utl::ConfigItem("Office.Writer/Navigator"),
82  m_nRootType(ContentTypeId::UNKNOWN),
83  m_nSelectedPos(0),
84  m_nOutlineLevel(MAXLEVEL),
85  m_nRegionMode(RegionMode::NONE),
86  m_nActiveBlock(0),
87  m_bIsSmall(false),
88  m_bIsGlobalActive(true),
89  m_nOutlineTracking(1),
90  m_bIsNavigateOnSelect(false)
91 {
92  Load();
94 }
95 
97 {
99  Sequence<Any> aValues = GetProperties(aNames);
100  const Any* pValues = aValues.getConstArray();
101  OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
102  if(aValues.getLength() != aNames.getLength())
103  return;
104 
105  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
106  {
107  if(pValues[nProp].hasValue())
108  {
109  switch(nProp)
110  {
111  case 0:
112  {
113  sal_Int32 nTmp = {}; // spurious -Werror=maybe-uninitialized
114  if (pValues[nProp] >>= nTmp)
115  {
116  if (nTmp < sal_Int32(ContentTypeId::UNKNOWN)
117  || nTmp > sal_Int32(ContentTypeId::LAST))
118  {
119  SAL_WARN(
120  "sw",
121  "out-of-bounds ContentTypeId " << nTmp);
122  nTmp = sal_Int32(ContentTypeId::UNKNOWN);
123  }
124  m_nRootType = static_cast<ContentTypeId>(nTmp);
125  }
126  break;
127  }
128  case 1: pValues[nProp] >>= m_nSelectedPos; break;
129  case 2: pValues[nProp] >>= m_nOutlineLevel; break;
130  case 3:
131  {
132  sal_Int32 nTmp;
133  if (pValues[nProp] >>= nTmp)
134  m_nRegionMode = static_cast<RegionMode>(nTmp);
135  break;
136  }
137  case 4: pValues[nProp] >>= m_nActiveBlock; break;
138  case 5: m_bIsSmall = *o3tl::doAccess<bool>(pValues[nProp]); break;
139  case 6: m_bIsGlobalActive = *o3tl::doAccess<bool>(pValues[nProp]); break;
140  case 7: pValues[nProp] >>= m_nOutlineTracking; break;
141  case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16:
142  case 17: case 18: case 19: case 20: case 21:
143  {
144  mContentTypeTrack[mPropNameToContentTypeId[aNames[nProp]]] =
145  *o3tl::doAccess<bool>(pValues[nProp]);
146  break;
147  }
148  case 22: m_bIsNavigateOnSelect = *o3tl::doAccess<bool>(pValues[nProp]); break;
149  }
150  }
151  }
152 }
153 
155 {
156 }
157 
159 {
161  Sequence<Any> aValues(aNames.getLength());
162  Any* pValues = aValues.getArray();
163 
164  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
165  {
166  switch(nProp)
167  {
168  case 0: pValues[nProp] <<= static_cast<sal_Int32>(m_nRootType); break;
169  case 1: pValues[nProp] <<= m_nSelectedPos; break;
170  case 2: pValues[nProp] <<= m_nOutlineLevel; break;
171  case 3: pValues[nProp] <<= static_cast<sal_uInt16>(m_nRegionMode); break;
172  case 4: pValues[nProp] <<= m_nActiveBlock; break;
173  case 5: pValues[nProp] <<= m_bIsSmall; break;
174  case 6: pValues[nProp] <<= m_bIsGlobalActive; break;
175  case 7: pValues[nProp] <<= m_nOutlineTracking; break;
176  case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16:
177  case 17: case 18: case 19: case 20: case 21:
178  {
179  pValues[nProp] <<= mContentTypeTrack[mPropNameToContentTypeId[aNames[nProp]]];
180  break;
181  }
182  case 22: pValues[nProp] <<= m_bIsNavigateOnSelect; break;
183  }
184  }
185  PutProperties(aNames, aValues);
186 }
187 
188 void SwNavigationConfig::Notify( const css::uno::Sequence< OUString >& )
189 {
190  Load();
191 }
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ContentTypeId
Definition: swcont.hxx:29
sal_Int32 m_nOutlineTracking
Definition: navicfg.hxx:35
bool m_bIsGlobalActive
Definition: navicfg.hxx:34
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:92
ContentTypeId m_nRootType
Definition: navicfg.hxx:28
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: navicfg.cxx:188
RegionMode m_nRegionMode
Definition: navicfg.hxx:31
virtual ~SwNavigationConfig() override
Definition: navicfg.cxx:154
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
virtual void ImplCommit() override
Definition: navicfg.cxx:158
UNKNOWN
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
static css::uno::Sequence< OUString > GetPropertyNames()
Definition: navicfg.cxx:52
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
sal_Int32 m_nOutlineLevel
Definition: navicfg.hxx:30
RegionMode
sal_Int32 m_nSelectedPos
Definition: navicfg.hxx:29
sal_Int32 m_nActiveBlock
Definition: navicfg.hxx:32
o3tl::enumarray< ContentTypeId, bool > mContentTypeTrack
Definition: navicfg.hxx:38
const PropertyValue * pValues
bool m_bIsNavigateOnSelect
Definition: navicfg.hxx:36
#define SAL_WARN(area, stream)
bool m_bDetectedRangeSegmentation false