Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / utlui / navicfg.cxx
blob0170a8f68a9747539043175af057a936f71339ee
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 <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>
29 using namespace ::utl;
30 using namespace ::com::sun::star::uno;
32 namespace {
33 std::map<OUString, ContentTypeId> mPropNameToContentTypeId
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}
52 Sequence<OUString> SwNavigationConfig::GetPropertyNames()
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")};
80 SwNavigationConfig::SwNavigationConfig() :
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)
92 Load();
93 EnableNotification(GetPropertyNames());
96 void SwNavigationConfig::Load()
98 Sequence<OUString> aNames = GetPropertyNames();
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;
105 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
107 if(pValues[nProp].hasValue())
109 switch(nProp)
111 case 0:
113 sal_Int32 nTmp = {}; // spurious -Werror=maybe-uninitialized
114 if (pValues[nProp] >>= nTmp)
116 if (nTmp < sal_Int32(ContentTypeId::UNKNOWN)
117 || nTmp > sal_Int32(ContentTypeId::LAST))
119 SAL_WARN(
120 "sw",
121 "out-of-bounds ContentTypeId " << nTmp);
122 nTmp = sal_Int32(ContentTypeId::UNKNOWN);
124 m_nRootType = static_cast<ContentTypeId>(nTmp);
126 break;
128 case 1: pValues[nProp] >>= m_nSelectedPos; break;
129 case 2: pValues[nProp] >>= m_nOutlineLevel; break;
130 case 3:
132 sal_Int32 nTmp;
133 if (pValues[nProp] >>= nTmp)
134 m_nRegionMode = static_cast<RegionMode>(nTmp);
135 break;
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:
144 mContentTypeTrack[mPropNameToContentTypeId[aNames[nProp]]] =
145 *o3tl::doAccess<bool>(pValues[nProp]);
146 break;
148 case 22: m_bIsNavigateOnSelect = *o3tl::doAccess<bool>(pValues[nProp]); break;
154 SwNavigationConfig::~SwNavigationConfig()
158 void SwNavigationConfig::ImplCommit()
160 Sequence<OUString> aNames = GetPropertyNames();
161 Sequence<Any> aValues(aNames.getLength());
162 Any* pValues = aValues.getArray();
164 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
166 switch(nProp)
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:
179 pValues[nProp] <<= mContentTypeTrack[mPropNameToContentTypeId[aNames[nProp]]];
180 break;
182 case 22: pValues[nProp] <<= m_bIsNavigateOnSelect; break;
185 PutProperties(aNames, aValues);
188 void SwNavigationConfig::Notify( const css::uno::Sequence< OUString >& )
190 Load();
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */