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