Update ooo320-m1
[ooovba.git] / sw / source / filter / xml / xmlfmte.cxx
blob84a39dd84b15b9d11db28d72e6f37e39bf55d6cf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfmte.cxx,v $
10 * $Revision: 1.51 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <com/sun/star/text/XTextDocument.hpp>
36 #include <xmloff/xmlnmspe.hxx>
37 #include <xmloff/attrlist.hxx>
38 #include "xmlexpit.hxx"
39 #include <xmloff/nmspmap.hxx>
40 #include <xmloff/XMLTextListAutoStylePool.hxx>
41 #ifndef _XMLOFF_XMLTEXTMASTERPAGEEXPORT
42 #include <xmloff/XMLTextMasterPageExport.hxx>
43 #endif
45 #ifndef _XMLOFF_TXTPRMAP_HXX
46 #include <xmloff/txtprmap.hxx>
47 #endif
48 #include <xmloff/xmlaustp.hxx>
49 #include <xmloff/families.hxx>
50 #include <xmloff/ProgressBarHelper.hxx>
51 #include <format.hxx>
52 #include <fmtpdsc.hxx>
53 #include <pagedesc.hxx>
54 #include <unostyle.hxx>
55 #include <cellatr.hxx>
56 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include "xmlexp.hxx"
59 #include <SwStyleNameMapper.hxx>
61 using ::rtl::OUString;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::text;
65 using namespace ::com::sun::star::drawing;
66 using namespace ::com::sun::star::lang;
67 using namespace ::xmloff::token;
69 void SwXMLExport::ExportFmt( const SwFmt& rFmt, enum XMLTokenEnum eFamily )
71 // <style:style ...>
72 CheckAttrList();
74 // style:family="..."
75 DBG_ASSERT( RES_FRMFMT==rFmt.Which(), "frame format expected" );
76 if( RES_FRMFMT != rFmt.Which() )
77 return;
78 DBG_ASSERT( eFamily != XML_TOKEN_INVALID, "family must be specified" );
79 // style:name="..."
80 sal_Bool bEncoded = sal_False;
81 AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, EncodeStyleName(
82 rFmt.GetName(), &bEncoded ) );
83 if( bEncoded )
84 AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, rFmt.GetName() );
87 if( eFamily != XML_TOKEN_INVALID )
88 AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, eFamily );
90 #ifndef PRODUCT
91 // style:parent-style-name="..." (if its not the default only)
92 const SwFmt* pParent = rFmt.DerivedFrom();
93 // Parent-Namen nur uebernehmen, wenn kein Default
94 ASSERT( !pParent || pParent->IsDefault(), "unexpected parent" );
96 ASSERT( USHRT_MAX == rFmt.GetPoolFmtId(), "pool ids arent'supported" );
97 ASSERT( USHRT_MAX == rFmt.GetPoolHelpId(), "help ids arent'supported" );
98 ASSERT( USHRT_MAX == rFmt.GetPoolHelpId() ||
99 UCHAR_MAX == rFmt.GetPoolHlpFileId(), "help file ids aren't supported" );
100 #endif
102 // style:master-page-name
103 if( RES_FRMFMT == rFmt.Which() && XML_TABLE == eFamily )
105 const SfxPoolItem *pItem;
106 if( SFX_ITEM_SET == rFmt.GetAttrSet().GetItemState( RES_PAGEDESC,
107 sal_False, &pItem ) )
109 String sName;
110 const SwPageDesc *pPageDesc =
111 ((const SwFmtPageDesc *)pItem)->GetPageDesc();
112 if( pPageDesc )
113 SwStyleNameMapper::FillProgName(
114 pPageDesc->GetName(),
115 sName,
116 nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC,
117 sal_True);
118 AddAttribute( XML_NAMESPACE_STYLE, XML_MASTER_PAGE_NAME,
119 EncodeStyleName( sName ) );
123 if( XML_TABLE_CELL == eFamily )
125 DBG_ASSERT(RES_FRMFMT == rFmt.Which(), "only frame format");
127 const SfxPoolItem *pItem;
128 if( SFX_ITEM_SET ==
129 rFmt.GetAttrSet().GetItemState( RES_BOXATR_FORMAT,
130 sal_False, &pItem ) )
132 sal_Int32 nFormat = (sal_Int32)
133 ((const SwTblBoxNumFormat *)pItem)->GetValue();
135 if ( (nFormat != -1) && (nFormat != NUMBERFORMAT_TEXT) )
137 // if we have a format, register and then export
138 // (Careful: here we assume that data styles will be
139 // written after cell styles)
140 addDataStyle(nFormat);
141 OUString sDataStyleName = getDataStyleName(nFormat);
142 if( sDataStyleName.getLength() > 0 )
143 AddAttribute( XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME,
144 sDataStyleName );
150 SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_STYLE,
151 sal_True, sal_True );
153 SvXMLItemMapEntriesRef xItemMap;
154 XMLTokenEnum ePropToken = XML_TABLE_PROPERTIES;
155 if( XML_TABLE == eFamily )
157 xItemMap = xTableItemMap;
159 else if( XML_TABLE_ROW == eFamily )
161 xItemMap = xTableRowItemMap;
162 ePropToken = XML_TABLE_ROW_PROPERTIES;
164 else if( XML_TABLE_CELL == eFamily )
166 xItemMap = xTableCellItemMap;
167 ePropToken = XML_TABLE_CELL_PROPERTIES;
170 if( xItemMap.Is() )
172 SvXMLExportItemMapper& rItemMapper = GetTableItemMapper();
173 rItemMapper.setMapEntries( xItemMap );
175 GetTableItemMapper().exportXML( *this,
176 rFmt.GetAttrSet(),
177 GetTwipUnitConverter(),
178 ePropToken,
179 XML_EXPORT_FLAG_IGN_WS );
185 void SwXMLExport::_ExportStyles( sal_Bool bUsed )
187 SvXMLExport::_ExportStyles( bUsed );
189 // drawing defaults
190 GetShapeExport()->ExportGraphicDefaults();
192 GetTextParagraphExport()->exportTextStyles( bUsed
193 ,IsShowProgress()
195 //page defaults
196 GetPageExport()->exportDefaultStyle();
199 void SwXMLExport::_ExportAutoStyles()
201 // The order in which styles are collected *MUST* be the same as
202 // the order in which they are exported. Otherwise, caching will
203 // fail.
205 if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
207 if( (getExportFlags() & EXPORT_CONTENT) == 0 )
209 // only master pages are exported => styles for frames bound
210 // to frames (but none for frames bound to pages) need to be
211 // collected.
212 // TODO: exclude PageBoundFrames on export
216 // exported in _ExportMasterStyles
217 if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
218 GetPageExport()->collectAutoStyles( sal_False );
220 // if we don't export styles (i.e. in content stream only, but not
221 // in single-stream case), then we can save ourselves a bit of
222 // work and memory by not collecting field masters
223 if( (getExportFlags() & EXPORT_STYLES ) == 0 )
224 GetTextParagraphExport()->exportUsedDeclarations( sal_False );
226 // exported in _ExportContent
227 if( (getExportFlags() & EXPORT_CONTENT) != 0 )
229 GetTextParagraphExport()->exportTrackedChanges( sal_True );
230 Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
231 Reference < XText > xText = xTextDoc->getText();
233 // collect form autostyle
234 // (do this before collectTextAutoStyles, 'cause the shapes need the results of the work
235 // done by examineForms)
236 Reference<XDrawPageSupplier> xDrawPageSupplier( GetModel(), UNO_QUERY );
237 if (xDrawPageSupplier.is() && GetFormExport().is())
239 Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
240 if (xPage.is())
241 GetFormExport()->examineForms(xPage);
244 GetTextParagraphExport()->collectTextAutoStylesOptimized( bShowProgress );
245 //GetTextParagraphExport()->collectTextAutoStyles( xText, bShowProgress, sal_True, bPortions );
248 GetTextParagraphExport()->exportTextAutoStyles();
249 GetShapeExport()->exportAutoStyles();
250 if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
251 GetPageExport()->exportAutoStyles();
253 // we rely on data styles being written after cell styles in the
254 // ExportFmt() method; so be careful when changing order.
255 exportAutoDataStyles();
257 sal_uInt16 nContentAutostyles = EXPORT_CONTENT | EXPORT_AUTOSTYLES;
258 if ( ( getExportFlags() & nContentAutostyles ) == nContentAutostyles )
259 GetFormExport()->exportAutoStyles();
262 XMLPageExport* SwXMLExport::CreatePageExport()
264 return new XMLTextMasterPageExport( *this );
267 void SwXMLExport::_ExportMasterStyles()
269 // export master styles
270 GetPageExport()->exportMasterStyles( sal_False );
273 // ---------------------------------------------------------------------
274 class SwXMLAutoStylePoolP : public SvXMLAutoStylePoolP
276 SvXMLExport& rExport;
277 const OUString sListStyleName;
278 const OUString sMasterPageName;
279 const OUString sCDATA;
281 protected:
283 virtual void exportStyleAttributes(
284 SvXMLAttributeList& rAttrList,
285 sal_Int32 nFamily,
286 const ::std::vector< XMLPropertyState >& rProperties,
287 const SvXMLExportPropertyMapper& rPropExp
288 , const SvXMLUnitConverter& rUnitConverter,
289 const SvXMLNamespaceMap& rNamespaceMap
290 ) const;
291 public:
293 SwXMLAutoStylePoolP( SvXMLExport& rExport );
294 virtual ~SwXMLAutoStylePoolP();
297 void SwXMLAutoStylePoolP::exportStyleAttributes(
298 SvXMLAttributeList& rAttrList,
299 sal_Int32 nFamily,
300 const ::std::vector< XMLPropertyState >& rProperties,
301 const SvXMLExportPropertyMapper& rPropExp
302 , const SvXMLUnitConverter& rUnitConverter,
303 const SvXMLNamespaceMap& rNamespaceMap
304 ) const
306 SvXMLAutoStylePoolP::exportStyleAttributes( rAttrList, nFamily, rProperties, rPropExp, rUnitConverter, rNamespaceMap);
308 if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily )
310 for( ::std::vector< XMLPropertyState >::const_iterator
311 aProperty = rProperties.begin();
312 aProperty != rProperties.end();
313 aProperty++ )
315 if (aProperty->mnIndex != -1) // #i26762#
317 switch( rPropExp.getPropertySetMapper()->
318 GetEntryContextId( aProperty->mnIndex ) )
320 case CTF_NUMBERINGSTYLENAME:
322 OUString sStyleName;
323 aProperty->maValue >>= sStyleName;
324 // --> OD 2008-11-19 #i70748#
325 // export also empty list styles
326 if( sStyleName.getLength() )
328 OUString sTmp = rExport.GetTextParagraphExport()->GetListAutoStylePool().Find( sStyleName );
329 if( sTmp.getLength() )
330 sStyleName = sTmp;
332 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
333 sListStyleName,
334 GetExport().EncodeStyleName( sStyleName ) );
335 // <--
337 break;
338 case CTF_PAGEDESCNAME:
340 OUString sStyleName;
341 aProperty->maValue >>= sStyleName;
342 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
343 sMasterPageName,
344 GetExport().EncodeStyleName( sStyleName ) );
346 break;
353 SwXMLAutoStylePoolP::SwXMLAutoStylePoolP(SvXMLExport& rExp ) :
354 SvXMLAutoStylePoolP( rExp ),
355 rExport( rExp ),
356 sListStyleName( GetXMLToken( XML_LIST_STYLE_NAME ) ),
357 sMasterPageName( GetXMLToken( XML_MASTER_PAGE_NAME ) ),
358 sCDATA( GetXMLToken( XML_CDATA ) )
363 SwXMLAutoStylePoolP::~SwXMLAutoStylePoolP()
367 SvXMLAutoStylePoolP* SwXMLExport::CreateAutoStylePool()
369 return new SwXMLAutoStylePoolP( *this );