1 |
From c0eb8faf3fcbf868bc1b01488b627851a8f77776 Mon Sep 17 00:00:00 2001 |
2 |
From: Troy Rollo <libreoffice@troy.rollo.name> |
3 |
Date: Tue, 6 Jun 2017 17:41:33 +1000 |
4 |
Subject: [PATCH 2/2] tdf#103091 conditional style conditions not saved |
5 |
|
6 |
Reviewed-on: https://gerrit.libreoffice.org/38451 |
7 |
Tested-by: Jenkins <ci@libreoffice.org> |
8 |
Reviewed-by: Michael Stahl <mstahl@redhat.com> |
9 |
(cherry picked from commit a5b4cb3f836c991d0647f55e1ef4920ce6115eac) |
10 |
Reviewed-on: https://gerrit.libreoffice.org/38747 |
11 |
(cherry picked from commit e9869b9b38d4e4e7f893aecb26f73d985f17e350) |
12 |
|
13 |
Change-Id: Iccf3eb531ee3382d27105e5ccce6013707a646b6 |
14 |
--- |
15 |
sw/source/core/unocore/unostyle.cxx | 3 +- |
16 |
sw/source/filter/xml/xmlfmt.cxx | 53 ++++++++++++++- |
17 |
xmloff/Library_xo.mk | 1 + |
18 |
xmloff/inc/prstylecond.hxx | 23 +++++++ |
19 |
xmloff/source/style/prstylecond.cxx | 125 ++++++++++++++++++++++++++++++++++++ |
20 |
xmloff/source/style/styleexp.cxx | 50 ++++++++++++++- |
21 |
6 files changed, 251 insertions(+), 4 deletions(-) |
22 |
create mode 100644 xmloff/inc/prstylecond.hxx |
23 |
create mode 100644 xmloff/source/style/prstylecond.cxx |
24 |
|
25 |
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx |
26 |
index 894f3393..14634dd 100644 |
27 |
--- a/sw/source/core/unocore/unostyle.cxx |
28 |
+++ b/sw/source/core/unocore/unostyle.cxx |
29 |
@@ -1892,7 +1892,8 @@ void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNa |
30 |
{ |
31 |
if(!m_pDoc) |
32 |
throw uno::RuntimeException(); |
33 |
- const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(m_rEntry.m_nPropMapType); |
34 |
+ sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; |
35 |
+ const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); |
36 |
const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap(); |
37 |
if(rPropertyNames.getLength() != rValues.getLength()) |
38 |
throw lang::IllegalArgumentException(); |
39 |
diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx |
40 |
index e0cdd96..be50e3e 100644 |
41 |
--- a/sw/source/filter/xml/xmlfmt.cxx |
42 |
+++ b/sw/source/filter/xml/xmlfmt.cxx |
43 |
@@ -30,6 +30,7 @@ |
44 |
#include "docary.hxx" |
45 |
#include <IDocumentStylePoolAccess.hxx> |
46 |
#include "unostyle.hxx" |
47 |
+#include "unoprnms.hxx" |
48 |
#include "fmtpdsc.hxx" |
49 |
#include "pagedesc.hxx" |
50 |
#include <xmloff/xmlnmspe.hxx> |
51 |
@@ -43,6 +44,7 @@ |
52 |
#include <xmloff/XMLTextMasterStylesContext.hxx> |
53 |
#include <xmloff/XMLTextShapeStyleContext.hxx> |
54 |
#include <xmloff/XMLGraphicsDefaultStyle.hxx> |
55 |
+#include <com/sun/star/beans/XPropertySet.hpp> |
56 |
#include "xmlimp.hxx" |
57 |
#include "xmltbli.hxx" |
58 |
#include "cellatr.hxx" |
59 |
@@ -50,8 +52,11 @@ |
60 |
#include <xmloff/attrlist.hxx> |
61 |
#include <unotxdoc.hxx> |
62 |
#include <docsh.hxx> |
63 |
+#include <ccoll.hxx> |
64 |
|
65 |
using namespace ::com::sun::star; |
66 |
+using namespace ::com::sun::star::beans; |
67 |
+using namespace ::com::sun::star::uno; |
68 |
using namespace ::xmloff::token; |
69 |
|
70 |
class SwXMLConditionParser_Impl |
71 |
@@ -202,8 +207,11 @@ public: |
72 |
const uno::Reference< xml::sax::XAttributeList > & xAttrList ); |
73 |
virtual ~SwXMLConditionContext_Impl(); |
74 |
|
75 |
- |
76 |
bool IsValid() const { return 0 != nCondition; } |
77 |
+ |
78 |
+ sal_uInt32 getCondition() const { return nCondition; } |
79 |
+ sal_uInt32 getSubCondition() const { return nSubCondition; } |
80 |
+ OUString const &getApplyStyle() const { return sApplyStyle; } |
81 |
}; |
82 |
|
83 |
SwXMLConditionContext_Impl::SwXMLConditionContext_Impl( |
84 |
@@ -254,10 +262,12 @@ typedef std::vector<SwXMLConditionContext_Impl*> SwXMLConditions_Impl; |
85 |
class SwXMLTextStyleContext_Impl : public XMLTextStyleContext |
86 |
{ |
87 |
SwXMLConditions_Impl *pConditions; |
88 |
+ uno::Reference < style::XStyle > xNewStyle; |
89 |
|
90 |
protected: |
91 |
|
92 |
virtual uno::Reference < style::XStyle > Create() override; |
93 |
+ virtual void Finish( bool bOverwrite ) override; |
94 |
|
95 |
public: |
96 |
|
97 |
@@ -278,7 +288,6 @@ public: |
98 |
|
99 |
uno::Reference < style::XStyle > SwXMLTextStyleContext_Impl::Create() |
100 |
{ |
101 |
- uno::Reference < style::XStyle > xNewStyle; |
102 |
|
103 |
if( pConditions && XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() ) |
104 |
{ |
105 |
@@ -300,6 +309,46 @@ uno::Reference < style::XStyle > SwXMLTextStyleContext_Impl::Create() |
106 |
return xNewStyle; |
107 |
} |
108 |
|
109 |
+void |
110 |
+SwXMLTextStyleContext_Impl::Finish( bool bOverwrite ) |
111 |
+{ |
112 |
+ |
113 |
+ if( pConditions && XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() && xNewStyle.is() ) |
114 |
+ { |
115 |
+ CommandStruct const *aCommands = SwCondCollItem::GetCmds(); |
116 |
+ |
117 |
+ Reference< XPropertySet > xPropSet( xNewStyle, UNO_QUERY ); |
118 |
+ |
119 |
+ uno::Sequence< beans::NamedValue > aSeq( pConditions->size() ); |
120 |
+ |
121 |
+ std::vector<rtl::Reference<SwXMLConditionContext_Impl>>::size_type i; |
122 |
+ unsigned j; |
123 |
+ |
124 |
+ for( i = 0; i < pConditions->size(); ++i ) |
125 |
+ { |
126 |
+ if( (*pConditions)[i]->IsValid() ) |
127 |
+ { |
128 |
+ sal_uInt32 nCond = (*pConditions)[i]->getCondition(); |
129 |
+ sal_uInt32 nSubCond = (*pConditions)[i]->getSubCondition(); |
130 |
+ |
131 |
+ for( j = 0; j < COND_COMMAND_COUNT; ++j ) |
132 |
+ { |
133 |
+ if( aCommands[j].nCnd == nCond && |
134 |
+ aCommands[j].nSubCond == nSubCond ) |
135 |
+ { |
136 |
+ aSeq[i].Name = GetCommandContextByIndex( j ); |
137 |
+ aSeq[i].Value <<= GetImport().GetStyleDisplayName( GetFamily(), (*pConditions)[i]->getApplyStyle() ); |
138 |
+ break; |
139 |
+ } |
140 |
+ } |
141 |
+ } |
142 |
+ } |
143 |
+ |
144 |
+ xPropSet->setPropertyValue( UNO_NAME_PARA_STYLE_CONDITIONS, uno::makeAny( aSeq ) ); |
145 |
+ } |
146 |
+ XMLTextStyleContext::Finish( bOverwrite ); |
147 |
+} |
148 |
+ |
149 |
SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport, |
150 |
sal_uInt16 nPrfx, const OUString& rLName, |
151 |
const uno::Reference< xml::sax::XAttributeList > & xAttrList, |
152 |
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk |
153 |
index 9575643..1abb50d 100644 |
154 |
--- a/xmloff/Library_xo.mk |
155 |
+++ b/xmloff/Library_xo.mk |
156 |
@@ -251,6 +251,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ |
157 |
xmloff/source/style/postuhdl \ |
158 |
xmloff/source/style/prhdlfac \ |
159 |
xmloff/source/style/prstylei \ |
160 |
+ xmloff/source/style/prstylecond \ |
161 |
xmloff/source/style/shadwhdl \ |
162 |
xmloff/source/style/shdwdhdl \ |
163 |
xmloff/source/style/styleexp \ |
164 |
diff --git a/xmloff/inc/prstylecond.hxx b/xmloff/inc/prstylecond.hxx |
165 |
new file mode 100644 |
166 |
index 0000000..85c9aae |
167 |
--- /dev/null |
168 |
+++ b/xmloff/inc/prstylecond.hxx |
169 |
@@ -0,0 +1,23 @@ |
170 |
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
171 |
+/* |
172 |
+ * This file is part of the LibreOffice project. |
173 |
+ * |
174 |
+ * This Source Code Form is subject to the terms of the Mozilla Public |
175 |
+ * License, v. 2.0. If a copy of the MPL was not distributed with this |
176 |
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
177 |
+ * |
178 |
+ * This file incorporates work covered by the following license notice: |
179 |
+ * |
180 |
+ * Licensed to the Apache Software Foundation (ASF) under one or more |
181 |
+ * contributor license agreements. See the NOTICE file distributed |
182 |
+ * with this work for additional information regarding copyright |
183 |
+ * ownership. The ASF licenses this file to you under the Apache |
184 |
+ * License, Version 2.0 (the "License"); you may not use this file |
185 |
+ * except in compliance with the License. You may obtain a copy of |
186 |
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
187 |
+ */ |
188 |
+ |
189 |
+OUString GetParaStyleCondExternal( OUString const &); |
190 |
+OUString GetParaStyleCondInternal( OUString const &); |
191 |
+ |
192 |
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
193 |
diff --git a/xmloff/source/style/prstylecond.cxx b/xmloff/source/style/prstylecond.cxx |
194 |
new file mode 100644 |
195 |
index 0000000..28312fb |
196 |
--- /dev/null |
197 |
+++ b/xmloff/source/style/prstylecond.cxx |
198 |
@@ -0,0 +1,125 @@ |
199 |
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
200 |
+/* |
201 |
+ * This file is part of the LibreOffice project. |
202 |
+ * |
203 |
+ * This Source Code Form is subject to the terms of the Mozilla Public |
204 |
+ * License, v. 2.0. If a copy of the MPL was not distributed with this |
205 |
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
206 |
+ * |
207 |
+ * This file incorporates work covered by the following license notice: |
208 |
+ * |
209 |
+ * Licensed to the Apache Software Foundation (ASF) under one or more |
210 |
+ * contributor license agreements. See the NOTICE file distributed |
211 |
+ * with this work for additional information regarding copyright |
212 |
+ * ownership. The ASF licenses this file to you under the Apache |
213 |
+ * License, Version 2.0 (the "License"); you may not use this file |
214 |
+ * except in compliance with the License. You may obtain a copy of |
215 |
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
216 |
+ */ |
217 |
+ |
218 |
+#include <rtl/ustring.hxx> |
219 |
+#include "prstylecond.hxx" |
220 |
+#include <xmloff/xmltoken.hxx> |
221 |
+ |
222 |
+using namespace ::xmloff::token; |
223 |
+ |
224 |
+static struct ConditionMap |
225 |
+{ |
226 |
+ char const* aInternal; |
227 |
+ XMLTokenEnum nExternal; |
228 |
+ int aValue; |
229 |
+} aConditionMap[] = |
230 |
+{ |
231 |
+ { "TableHeader", XML_TABLE_HEADER, -1 }, |
232 |
+ { "Table", XML_TABLE, -1 }, |
233 |
+ { "Frame", XML_TEXT_BOX, -1 }, // FIXME - Not in ODF spec |
234 |
+ { "Section", XML_SECTION, -1 }, |
235 |
+ { "Footnote", XML_FOOTNOTE, -1 }, |
236 |
+ { "Endnote", XML_ENDNOTE, -1 }, |
237 |
+ { "Header", XML_HEADER, -1 }, |
238 |
+ { "Footer", XML_FOOTER, -1 }, |
239 |
+ { "OutlineLevel1", XML_OUTLINE_LEVEL, 1 }, |
240 |
+ { "OutlineLevel2", XML_OUTLINE_LEVEL, 2 }, |
241 |
+ { "OutlineLevel3", XML_OUTLINE_LEVEL, 3 }, |
242 |
+ { "OutlineLevel4", XML_OUTLINE_LEVEL, 4 }, |
243 |
+ { "OutlineLevel5", XML_OUTLINE_LEVEL, 5 }, |
244 |
+ { "OutlineLevel6", XML_OUTLINE_LEVEL, 6 }, |
245 |
+ { "OutlineLevel7", XML_OUTLINE_LEVEL, 7 }, |
246 |
+ { "OutlineLevel8", XML_OUTLINE_LEVEL, 8 }, |
247 |
+ { "OutlineLevel9", XML_OUTLINE_LEVEL, 9 }, |
248 |
+ { "OutlineLevel10", XML_OUTLINE_LEVEL, 10 }, |
249 |
+ { "NumberingLevel1", XML_LIST_LEVEL, 1 }, |
250 |
+ { "NumberingLevel2", XML_LIST_LEVEL, 2 }, |
251 |
+ { "NumberingLevel3", XML_LIST_LEVEL, 3 }, |
252 |
+ { "NumberingLevel4", XML_LIST_LEVEL, 4 }, |
253 |
+ { "NumberingLevel5", XML_LIST_LEVEL, 5 }, |
254 |
+ { "NumberingLevel6", XML_LIST_LEVEL, 6 }, |
255 |
+ { "NumberingLevel7", XML_LIST_LEVEL, 7 }, |
256 |
+ { "NumberingLevel8", XML_LIST_LEVEL, 8 }, |
257 |
+ { "NumberingLevel9", XML_LIST_LEVEL, 9 }, |
258 |
+ { "NumberingLevel10", XML_LIST_LEVEL, 10 } |
259 |
+}; |
260 |
+ |
261 |
+#define CONDITION_COUNT (sizeof(aConditionMap) / sizeof(aConditionMap[0])) |
262 |
+ |
263 |
+OUString GetParaStyleCondExternal( OUString const &internal) |
264 |
+{ |
265 |
+ unsigned i; |
266 |
+ |
267 |
+ for(i = 0; i < CONDITION_COUNT; ++i) |
268 |
+ { |
269 |
+ if(internal.compareToAscii( aConditionMap[i].aInternal ) == 0) |
270 |
+ { |
271 |
+ OUString aResult( GetXMLToken( aConditionMap[i].nExternal ) ); |
272 |
+ |
273 |
+ aResult += "()"; |
274 |
+ if( aConditionMap[i].aValue != -1 ) |
275 |
+ { |
276 |
+ aResult += "="; |
277 |
+ aResult += OUString::number( aConditionMap[i].aValue ); |
278 |
+ } |
279 |
+ return aResult; |
280 |
+ } |
281 |
+ } |
282 |
+ return OUString(); |
283 |
+} |
284 |
+ |
285 |
+OUString GetParaStyleCondInternal( OUString const &external) |
286 |
+{ |
287 |
+ sal_Int32 paren = external.indexOf('('); |
288 |
+ |
289 |
+ if( paren > 0 && external[paren + 1] == ')' ) |
290 |
+ { |
291 |
+ OUString stub( external.getStr(), paren ); |
292 |
+ int numval = -1; |
293 |
+ unsigned i; |
294 |
+ |
295 |
+ if(external.getLength() > paren + 2) |
296 |
+ { |
297 |
+ if(external[paren + 2] == '=') |
298 |
+ { |
299 |
+ OUString num( external.getStr() + 3 ); |
300 |
+ |
301 |
+ numval = num.toInt32(); |
302 |
+ } |
303 |
+ else |
304 |
+ { |
305 |
+ return OUString(); |
306 |
+ } |
307 |
+ } |
308 |
+ |
309 |
+ for(i = 0; i < CONDITION_COUNT; ++i) |
310 |
+ { |
311 |
+ if( aConditionMap[i].aValue == numval && |
312 |
+ stub == GetXMLToken( aConditionMap[i].nExternal ) ) |
313 |
+ { |
314 |
+ return OUString( aConditionMap[i].aInternal, |
315 |
+ strlen( aConditionMap[i].aInternal ), |
316 |
+ RTL_TEXTENCODING_ASCII_US ); |
317 |
+ } |
318 |
+ } |
319 |
+ } |
320 |
+ return OUString(); |
321 |
+} |
322 |
+ |
323 |
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
324 |
diff --git a/xmloff/source/style/styleexp.cxx b/xmloff/source/style/styleexp.cxx |
325 |
index f96e1c7..b41e836 100644 |
326 |
--- a/xmloff/source/style/styleexp.cxx |
327 |
+++ b/xmloff/source/style/styleexp.cxx |
328 |
@@ -30,6 +30,7 @@ |
329 |
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
330 |
#include <com/sun/star/style/XStyle.hpp> |
331 |
#include <com/sun/star/container/XNameContainer.hpp> |
332 |
+#include <com/sun/star/beans/NamedValue.hpp> |
333 |
#include <com/sun/star/beans/XPropertySet.hpp> |
334 |
#include <com/sun/star/beans/XPropertyState.hpp> |
335 |
#include <com/sun/star/document/XEventsSupplier.hpp> |
336 |
@@ -41,6 +42,7 @@ |
337 |
#include <xmloff/maptype.hxx> |
338 |
#include <memory> |
339 |
#include <set> |
340 |
+#include "prstylecond.hxx" |
341 |
|
342 |
using namespace ::com::sun::star; |
343 |
using namespace ::com::sun::star::uno; |
344 |
@@ -75,8 +77,54 @@ void XMLStyleExport::exportStyleAttributes( const Reference< XStyle >& ) |
345 |
{ |
346 |
} |
347 |
|
348 |
-void XMLStyleExport::exportStyleContent( const Reference< XStyle >& ) |
349 |
+void XMLStyleExport::exportStyleContent( const Reference< XStyle >& rStyle ) |
350 |
{ |
351 |
+ Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); |
352 |
+ |
353 |
+ try |
354 |
+ { |
355 |
+ uno::Any aProperty = xPropSet->getPropertyValue( "ParaStyleConditions" ); |
356 |
+ uno::Sequence< beans::NamedValue > aSeq; |
357 |
+ int i; |
358 |
+ |
359 |
+ aProperty >>= aSeq; |
360 |
+ |
361 |
+ for(i = 0; i < aSeq.getLength(); ++i) |
362 |
+ { |
363 |
+ beans::NamedValue const& aNamedCond = aSeq[i]; |
364 |
+ OUString aStyleName; |
365 |
+ |
366 |
+ if ( aNamedCond.Value >>= aStyleName ) |
367 |
+ { |
368 |
+ if ( aStyleName.getLength() > 0 ) |
369 |
+ { |
370 |
+ OUString aExternal = GetParaStyleCondExternal( aNamedCond.Name ); |
371 |
+ |
372 |
+ if (aExternal.getLength() > 0) |
373 |
+ { |
374 |
+ bool bEncoded; |
375 |
+ |
376 |
+ |
377 |
+ GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
378 |
+ XML_CONDITION, |
379 |
+ aExternal); |
380 |
+ GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
381 |
+ XML_APPLY_STYLE_NAME, |
382 |
+ GetExport().EncodeStyleName( aStyleName, |
383 |
+ &bEncoded ) ); |
384 |
+ SvXMLElementExport aElem( GetExport(), |
385 |
+ XML_NAMESPACE_STYLE, |
386 |
+ XML_MAP, |
387 |
+ true, |
388 |
+ true ); |
389 |
+ } |
390 |
+ } |
391 |
+ } |
392 |
+ } |
393 |
+ } |
394 |
+ catch( const beans::UnknownPropertyException& ) |
395 |
+ { |
396 |
+ } |
397 |
} |
398 |
|
399 |
bool XMLStyleExport::exportStyle( |
400 |
-- |
401 |
2.9.4 |
402 |
|