Line data Source code
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 :
21 : #include <svl/style.hxx>
22 : #include <svl/itemset.hxx>
23 : #include <svl/itempool.hxx>
24 : #include <svl/whiter.hxx>
25 :
26 : #include <svx/svdoutl.hxx>
27 : #include <editeng/xmlcnitm.hxx>
28 : #include <svx/svdotext.hxx>
29 : #include <svx/svdogrp.hxx>
30 : #include <editeng/eeitem.hxx>
31 : #include <editeng/lrspitem.hxx>
32 : #include <editeng/numitem.hxx>
33 :
34 : #include "drawdoc.hxx"
35 : #include "glob.hxx"
36 :
37 : using ::rtl::OUString;
38 : using namespace ::com::sun::star::style;
39 :
40 0 : class SdTransformOOo2xDocument
41 : {
42 : public:
43 : SdTransformOOo2xDocument( SdDrawDocument& rDocument );
44 :
45 : void transform();
46 :
47 : void transformMasterPages();
48 : void transformDrawPages();
49 :
50 : void transformStyles();
51 : void transformStyles( SfxStyleFamily eFam );
52 : void transformStyle( SfxStyleSheetBase& rSheet );
53 :
54 : void transformShapes( SdrObjList& rShapes );
55 : void transformShape( SdrObject& rObj );
56 :
57 : void transformTextShape( SdrTextObj& rTextShape );
58 :
59 : bool getBulletState( const SfxItemSet& rSet, SfxStyleSheetBase* pSheet, bool& rState );
60 : bool getBulletState( const SfxItemSet& rSet, sal_uInt16 nWhich, bool& rState );
61 :
62 : bool transformItemSet( SfxItemSet& rSet, bool bNumbering );
63 :
64 : bool removeAlienAttributes( SfxItemSet& rSet );
65 : bool removeAlienAttributes( SfxItemSet& rSet, sal_uInt16 nWhich );
66 :
67 : SdDrawDocument& mrDocument;
68 : SdrOutliner& mrOutliner;
69 : const OUString msEnableNumbering;
70 : const OUString msTextNamespace;
71 : const OUString msTrue;
72 : };
73 :
74 : /** transforms the given model from OOo 2.x to OOo 3.x. This maps
75 : the deprecated EE_PARA_BULLETSTATE and clears the EE_PARA_LRSPACE
76 : if used together with a EE_PARA_NUMBULLET */
77 0 : void TransformOOo2xDocument( SdDrawDocument* pDocument )
78 : {
79 0 : if( pDocument )
80 : {
81 0 : SdTransformOOo2xDocument aTransformer( *pDocument );
82 0 : aTransformer.transform();
83 : }
84 0 : }
85 :
86 0 : SdTransformOOo2xDocument::SdTransformOOo2xDocument( SdDrawDocument& rDocument )
87 : : mrDocument( rDocument )
88 0 : , mrOutliner( rDocument.GetDrawOutliner() )
89 : , msEnableNumbering( "enable-numbering" )
90 : , msTextNamespace( "urn:oasis:names:tc:opendocument:xmlns:text:1.0" )
91 0 : , msTrue( "true" )
92 : {
93 0 : }
94 :
95 0 : void SdTransformOOo2xDocument::transform()
96 : {
97 0 : transformMasterPages();
98 0 : transformDrawPages();
99 0 : transformStyles();
100 0 : }
101 :
102 0 : void SdTransformOOo2xDocument::transformMasterPages()
103 : {
104 0 : sal_uInt16 nMasterPageCount = mrDocument.GetMasterPageCount();
105 0 : for( sal_uInt16 nMasterPage = 0; nMasterPage < nMasterPageCount; nMasterPage++ )
106 : {
107 0 : SdrObjList* pPage = mrDocument.GetMasterPage( nMasterPage );
108 0 : if( pPage )
109 0 : transformShapes( *pPage );
110 : }
111 0 : }
112 :
113 0 : void SdTransformOOo2xDocument::transformDrawPages()
114 : {
115 0 : sal_uInt16 nPageCount = mrDocument.GetPageCount();
116 0 : for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
117 : {
118 0 : SdrObjList* pPage = mrDocument.GetPage( nPage );
119 0 : if( pPage )
120 0 : transformShapes( *pPage );
121 : }
122 0 : }
123 :
124 0 : void SdTransformOOo2xDocument::transformStyles()
125 : {
126 0 : transformStyles( SD_STYLE_FAMILY_GRAPHICS );
127 0 : transformStyles( SD_STYLE_FAMILY_MASTERPAGE );
128 0 : }
129 :
130 0 : void SdTransformOOo2xDocument::transformStyles( SfxStyleFamily eFam )
131 : {
132 :
133 0 : rtl::Reference< SfxStyleSheetBasePool > xStyleSheetPool( mrDocument.GetStyleSheetPool() );
134 :
135 0 : SfxStyleSheetIterator aIter( xStyleSheetPool.get(), eFam );
136 :
137 0 : SfxStyleSheetBase* pSheet = aIter.First();
138 0 : while( pSheet )
139 : {
140 0 : transformStyle( *pSheet );
141 0 : pSheet = aIter.Next();
142 0 : }
143 0 : }
144 :
145 0 : void SdTransformOOo2xDocument::transformStyle( SfxStyleSheetBase& rSheet )
146 : {
147 0 : SfxItemSet& rSet = rSheet.GetItemSet();
148 :
149 0 : bool bState = false;
150 0 : getBulletState( rSheet.GetItemSet(), rSheet.GetPool().Find( rSheet.GetParent(), rSheet.GetFamily() ), bState );
151 :
152 0 : transformItemSet( rSet, bState );
153 0 : removeAlienAttributes( rSet );
154 0 : }
155 :
156 0 : void SdTransformOOo2xDocument::transformShapes( SdrObjList& rShapes )
157 : {
158 0 : sal_uInt32 nShapeCount = rShapes.GetObjCount();
159 0 : for( sal_uInt32 nShape = 0; nShape < nShapeCount; nShape++ )
160 : {
161 0 : SdrObject* pObj = rShapes.GetObj( nShape );
162 0 : if( pObj )
163 0 : transformShape( *pObj );
164 : }
165 0 : }
166 :
167 0 : void SdTransformOOo2xDocument::transformShape( SdrObject& rObj )
168 : {
169 0 : SdrTextObj* pTextShape = dynamic_cast< SdrTextObj* >( &rObj );
170 0 : if( pTextShape )
171 : {
172 0 : transformTextShape( *pTextShape );
173 0 : return;
174 : }
175 :
176 0 : SdrObjGroup* pGroupShape = dynamic_cast< SdrObjGroup* >( &rObj );
177 0 : if( pGroupShape )
178 : {
179 0 : SdrObjList* pObjList = pGroupShape->GetSubList();
180 0 : if( pObjList )
181 0 : transformShapes( *pObjList );
182 0 : return;
183 : }
184 : }
185 :
186 0 : void SdTransformOOo2xDocument::transformTextShape( SdrTextObj& rTextShape )
187 : {
188 :
189 0 : if(!rTextShape.IsEmptyPresObj())
190 : {
191 0 : OutlinerParaObject* pOPO = rTextShape.GetOutlinerParaObject();
192 0 : if (pOPO)
193 : {
194 0 : mrOutliner.SetText( *pOPO );
195 :
196 0 : sal_uInt32 nCount = mrOutliner.GetParagraphCount();
197 :
198 0 : bool bChange = false;
199 :
200 0 : for(sal_uInt16 nPara = 0; nPara < nCount; nPara++)
201 : {
202 0 : SfxItemSet aParaSet( mrOutliner.GetParaAttribs( nPara ) );
203 :
204 0 : bool bItemChange = false;
205 :
206 0 : bool bState = false;
207 0 : const sal_Int16 nDepth = mrOutliner.GetDepth( nPara );
208 0 : if( (nDepth != -1) && (!getBulletState( aParaSet, mrOutliner.GetStyleSheet( nPara ), bState ) || !bState) )
209 : {
210 : // disable bullet if text::enable-bullet="false" is found
211 0 : if( (nDepth > 0 ) && (rTextShape.GetObjInventor() == SdrInventor) && (rTextShape.GetObjIdentifier() == OBJ_OUTLINETEXT) )
212 : {
213 : // for outline object and level > 0 burn in the style sheet because it will be changed to "outline 1"
214 0 : SfxStyleSheet* pStyleSheet = mrOutliner.GetStyleSheet( nPara );
215 :
216 0 : if( pStyleSheet )
217 : {
218 : // optimize me: only put items hard into paragraph that are not equal to "outline 1" style!
219 0 : SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
220 :
221 0 : SfxWhichIter aIter(aParaSet);
222 0 : sal_uInt16 nWhich(aIter.FirstWhich());
223 :
224 : // now set all none hard attributes from the style
225 0 : while(nWhich)
226 : {
227 0 : if(SFX_ITEM_SET != aParaSet.GetItemState(nWhich, true))
228 : {
229 0 : aParaSet.Put(rStyleSet.Get(nWhich));
230 0 : bItemChange = true;
231 : }
232 :
233 0 : nWhich = aIter.NextWhich();
234 0 : }
235 : }
236 : }
237 :
238 0 : mrOutliner.SetDepth( mrOutliner.GetParagraph( nPara ), -1 );
239 :
240 0 : bChange = true;
241 : }
242 :
243 0 : bItemChange |= transformItemSet( aParaSet, bState );
244 :
245 0 : bItemChange |= removeAlienAttributes( aParaSet );
246 :
247 0 : if( bItemChange )
248 : {
249 0 : mrOutliner.SetParaAttribs( nPara, aParaSet );
250 0 : bChange = true;
251 : }
252 0 : }
253 :
254 0 : if( bChange )
255 0 : rTextShape.SetOutlinerParaObject(mrOutliner.CreateParaObject());
256 :
257 0 : mrOutliner.Clear();
258 : }
259 : }
260 0 : }
261 :
262 0 : bool SdTransformOOo2xDocument::getBulletState( const SfxItemSet& rSet, SfxStyleSheetBase* pSheet, bool& rState )
263 : {
264 0 : if( getBulletState( rSet, EE_PARA_XMLATTRIBS, rState ) )
265 0 : return true;
266 :
267 0 : if( getBulletState( rSet, SDRATTR_XMLATTRIBUTES, rState ) )
268 0 : return true;
269 :
270 0 : if( pSheet && getBulletState( pSheet->GetItemSet(), pSheet->GetPool().Find( pSheet->GetParent(), pSheet->GetFamily() ), rState ) )
271 0 : return true;
272 :
273 0 : return false;
274 : }
275 :
276 0 : bool SdTransformOOo2xDocument::getBulletState( const SfxItemSet& rSet, sal_uInt16 nWhich, bool& rState )
277 : {
278 0 : if( (rSet.GetItemState( nWhich ) == SFX_ITEM_SET) )
279 : {
280 0 : const SvXMLAttrContainerItem& rAttr = *static_cast< const SvXMLAttrContainerItem* >( rSet.GetItem( nWhich ) );
281 :
282 0 : const sal_uInt16 nCount = rAttr.GetAttrCount();
283 0 : for( sal_uInt16 nItem = 0; nItem < nCount; nItem++ )
284 : {
285 0 : if( ( rAttr.GetAttrLName( nItem ) == msEnableNumbering ) && ( rAttr.GetAttrNamespace( nItem ) == msTextNamespace ) )
286 : {
287 0 : const OUString sValue( rAttr.GetAttrValue( nItem ) );
288 0 : rState = sValue.equals(msTrue);
289 0 : return true;
290 : }
291 : }
292 : }
293 :
294 0 : return false;
295 : }
296 :
297 0 : bool SdTransformOOo2xDocument::transformItemSet( SfxItemSet& rSet, bool bNumbering )
298 : {
299 0 : bool bRet = false;
300 0 : if( bNumbering )
301 : {
302 0 : SvxLRSpaceItem aItem( *static_cast<const SvxLRSpaceItem*>(rSet.GetItem( EE_PARA_LRSPACE )) );
303 0 : if( (aItem.GetLeft() != 0) || (aItem.GetTxtFirstLineOfst() != 0) )
304 : {
305 0 : aItem.SetLeftValue( 0 );
306 0 : aItem.SetTxtFirstLineOfst( 0 );
307 0 : rSet.Put( aItem );
308 0 : bRet = true;
309 0 : }
310 : }
311 :
312 0 : return bRet;
313 : }
314 :
315 0 : bool SdTransformOOo2xDocument::removeAlienAttributes( SfxItemSet& rSet )
316 : {
317 0 : return removeAlienAttributes( rSet, EE_PARA_XMLATTRIBS ) | removeAlienAttributes( rSet, SDRATTR_XMLATTRIBUTES );
318 : }
319 :
320 0 : bool SdTransformOOo2xDocument::removeAlienAttributes( SfxItemSet& rSet, sal_uInt16 nWhich )
321 : {
322 0 : if( (rSet.GetItemState( nWhich ) == SFX_ITEM_SET) )
323 : {
324 0 : const SvXMLAttrContainerItem& rAttr = *static_cast< const SvXMLAttrContainerItem* >( rSet.GetItem( nWhich ) );
325 :
326 0 : const sal_uInt16 nCount = rAttr.GetAttrCount();
327 0 : for( sal_uInt16 nItem = 0; nItem < nCount; nItem++ )
328 : {
329 0 : if( ( rAttr.GetAttrLName( nItem ) == msEnableNumbering ) && ( rAttr.GetAttrNamespace( nItem ) == msTextNamespace ) )
330 : {
331 0 : if( nCount == 1 )
332 : {
333 0 : rSet.ClearItem( nWhich );
334 : }
335 : else
336 : {
337 0 : SvXMLAttrContainerItem aNewItem( nWhich );
338 :
339 0 : const sal_uInt16 nFound = nItem;
340 0 : for( nItem = 0; nItem < nCount; nItem++ )
341 : {
342 0 : if( nItem != nFound )
343 0 : aNewItem.AddAttr( rAttr.GetAttrPrefix(nItem),rAttr.GetAttrNamespace(nItem), rAttr.GetAttrLName(nItem), rAttr.GetAttrValue(nItem ) );
344 : }
345 :
346 0 : rSet.Put( aNewItem );
347 : }
348 0 : return true;
349 : }
350 : }
351 : }
352 0 : return false;
353 : }
354 :
355 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|