/src/libreoffice/sw/source/uibase/utlui/navicfg.cxx
Line | Count | Source |
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 | | |
52 | | Sequence<OUString> SwNavigationConfig::GetPropertyNames() |
53 | 0 | { |
54 | 0 | return css::uno::Sequence<OUString>{ |
55 | 0 | u"RootType"_ustr, |
56 | 0 | u"SelectedPosition"_ustr, |
57 | 0 | u"OutlineLevel"_ustr, |
58 | 0 | u"ActiveBlock"_ustr, |
59 | 0 | u"ShowListBox"_ustr, |
60 | 0 | u"GlobalDocMode"_ustr, |
61 | 0 | u"OutlineTracking"_ustr, |
62 | 0 | u"TableTracking"_ustr, |
63 | 0 | u"SectionTracking"_ustr, |
64 | 0 | u"FrameTracking"_ustr, |
65 | 0 | u"ImageTracking"_ustr, |
66 | 0 | u"OLEobjectTracking"_ustr, |
67 | 0 | u"BookmarkTracking"_ustr, |
68 | 0 | u"HyperlinkTracking"_ustr, |
69 | 0 | u"ReferenceTracking"_ustr, |
70 | 0 | u"IndexTracking"_ustr, |
71 | 0 | u"CommentTracking"_ustr, |
72 | 0 | u"DrawingObjectTracking"_ustr, |
73 | 0 | u"FieldTracking"_ustr, |
74 | 0 | u"FootnoteTracking"_ustr, |
75 | 0 | u"EndnoteTracking"_ustr, |
76 | 0 | u"NavigateOnSelect"_ustr, |
77 | 0 | u"SortAlphabeticallyBlock"_ustr}; |
78 | 0 | } |
79 | | |
80 | | SwNavigationConfig::SwNavigationConfig() : |
81 | 0 | utl::ConfigItem(u"Office.Writer/Navigator"_ustr), |
82 | 0 | m_nRootType(ContentTypeId::UNKNOWN), |
83 | 0 | m_nSelectedPos(0), |
84 | 0 | m_nOutlineLevel(MAXLEVEL), |
85 | 0 | m_nActiveBlock(0), |
86 | 0 | m_bIsSmall(false), |
87 | 0 | m_bIsGlobalActive(true), |
88 | 0 | m_nOutlineTracking(1), |
89 | 0 | m_bIsNavigateOnSelect(false) |
90 | 0 | { |
91 | 0 | Load(); |
92 | 0 | EnableNotification(GetPropertyNames()); |
93 | 0 | } |
94 | | |
95 | | void SwNavigationConfig::Load() |
96 | 0 | { |
97 | 0 | Sequence<OUString> aNames = GetPropertyNames(); |
98 | 0 | Sequence<Any> aValues = GetProperties(aNames); |
99 | 0 | const Any* pValues = aValues.getConstArray(); |
100 | 0 | OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed"); |
101 | 0 | if(aValues.getLength() != aNames.getLength()) |
102 | 0 | return; |
103 | | |
104 | 0 | for(int nProp = 0; nProp < aNames.getLength(); nProp++) |
105 | 0 | { |
106 | 0 | if(pValues[nProp].hasValue()) |
107 | 0 | { |
108 | 0 | switch(nProp) |
109 | 0 | { |
110 | 0 | case 0: |
111 | 0 | { |
112 | 0 | sal_Int32 nTmp = {}; // spurious -Werror=maybe-uninitialized |
113 | 0 | if (pValues[nProp] >>= nTmp) |
114 | 0 | { |
115 | 0 | if (nTmp < sal_Int32(ContentTypeId::UNKNOWN) |
116 | 0 | || nTmp > sal_Int32(ContentTypeId::LAST)) |
117 | 0 | { |
118 | 0 | SAL_WARN( |
119 | 0 | "sw", |
120 | 0 | "out-of-bounds ContentTypeId " << nTmp); |
121 | 0 | nTmp = sal_Int32(ContentTypeId::UNKNOWN); |
122 | 0 | } |
123 | 0 | m_nRootType = static_cast<ContentTypeId>(nTmp); |
124 | 0 | } |
125 | 0 | break; |
126 | 0 | } |
127 | 0 | case 1: pValues[nProp] >>= m_nSelectedPos; break; |
128 | 0 | case 2: pValues[nProp] >>= m_nOutlineLevel; break; |
129 | 0 | case 3: pValues[nProp] >>= m_nActiveBlock; break; |
130 | 0 | case 4: m_bIsSmall = *o3tl::doAccess<bool>(pValues[nProp]); break; |
131 | 0 | case 5: m_bIsGlobalActive = *o3tl::doAccess<bool>(pValues[nProp]); break; |
132 | 0 | case 6: pValues[nProp] >>= m_nOutlineTracking; break; |
133 | 0 | case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: |
134 | 0 | case 16: case 17: case 18: case 19: case 20: |
135 | 0 | { |
136 | 0 | mContentTypeTrack[mPropNameToContentTypeId[aNames[nProp]]] = |
137 | 0 | *o3tl::doAccess<bool>(pValues[nProp]); |
138 | 0 | break; |
139 | 0 | } |
140 | 0 | case 21: m_bIsNavigateOnSelect = *o3tl::doAccess<bool>(pValues[nProp]); break; |
141 | 0 | case 22: pValues[nProp] >>= m_nSortAlphabeticallyBlock; break; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | } |
145 | 0 | } |
146 | | |
147 | | SwNavigationConfig::~SwNavigationConfig() |
148 | 0 | { |
149 | 0 | } |
150 | | |
151 | | void SwNavigationConfig::ImplCommit() |
152 | 0 | { |
153 | 0 | Sequence<OUString> aNames = GetPropertyNames(); |
154 | 0 | Sequence<Any> aValues(aNames.getLength()); |
155 | 0 | Any* pValues = aValues.getArray(); |
156 | |
|
157 | 0 | for(int nProp = 0; nProp < aNames.getLength(); nProp++) |
158 | 0 | { |
159 | 0 | switch(nProp) |
160 | 0 | { |
161 | 0 | case 0: pValues[nProp] <<= static_cast<sal_Int32>(m_nRootType); break; |
162 | 0 | case 1: pValues[nProp] <<= m_nSelectedPos; break; |
163 | 0 | case 2: pValues[nProp] <<= m_nOutlineLevel; break; |
164 | 0 | case 3: pValues[nProp] <<= m_nActiveBlock; break; |
165 | 0 | case 4: pValues[nProp] <<= m_bIsSmall; break; |
166 | 0 | case 5: pValues[nProp] <<= m_bIsGlobalActive; break; |
167 | 0 | case 6: pValues[nProp] <<= m_nOutlineTracking; break; |
168 | 0 | case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: |
169 | 0 | case 16: case 17: case 18: case 19: case 20: |
170 | 0 | { |
171 | 0 | pValues[nProp] <<= mContentTypeTrack[mPropNameToContentTypeId[aNames[nProp]]]; |
172 | 0 | break; |
173 | 0 | } |
174 | 0 | case 21: pValues[nProp] <<= m_bIsNavigateOnSelect; break; |
175 | 0 | case 22: pValues[nProp] <<= m_nSortAlphabeticallyBlock; break; |
176 | 0 | } |
177 | 0 | } |
178 | 0 | PutProperties(aNames, aValues); |
179 | 0 | } |
180 | | |
181 | | void SwNavigationConfig::Notify( const css::uno::Sequence< OUString >& ) |
182 | 0 | { |
183 | 0 | Load(); |
184 | 0 | } |
185 | | |
186 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |