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