merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / text / txtftne.cxx
blobc8b2b0158cf72d361c3c47e2d33522ca9b427df6
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: txtftne.cxx,v $
10 * $Revision: 1.24 $
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_xmloff.hxx"
35 /** @#file
37 * This file implements XMLTextParagraphExport methods to export
38 * - footnotes
39 * - endnotes
40 * - footnote configuration elements
41 * - endnote configuration elements
43 #include <tools/debug.hxx>
44 #include <rtl/ustrbuf.hxx>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/XPropertyState.hpp>
48 #include <com/sun/star/text/XTextDocument.hpp>
49 #include <com/sun/star/text/XText.hpp>
50 #include <com/sun/star/text/XTextContent.hpp>
51 #include <com/sun/star/text/XFootnote.hpp>
52 #include <com/sun/star/text/XFootnotesSupplier.hpp>
53 #include <com/sun/star/text/XEndnotesSupplier.hpp>
54 #include <com/sun/star/text/FootnoteNumbering.hpp>
55 #include <com/sun/star/container/XNameReplace.hpp>
56 #include <xmloff/xmltoken.hxx>
57 #include "xmlnmspe.hxx"
58 #include <xmloff/xmlnumfe.hxx>
59 #include <xmloff/xmluconv.hxx>
60 #include <xmloff/nmspmap.hxx>
61 #include <xmloff/xmlexp.hxx>
62 #include <xmloff/families.hxx>
63 #include <xmloff/xmlnume.hxx>
64 #include "XMLTextCharStyleNamesElementExport.hxx"
65 #include <xmloff/XMLEventExport.hxx>
66 #ifndef _XMLOFF_TXTPARAE_HXX
67 #include <xmloff/txtparae.hxx>
68 #endif
70 using ::rtl::OUString;
71 using ::rtl::OUStringBuffer;
73 using namespace ::com::sun::star;
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::beans;
77 using namespace ::com::sun::star::text;
78 using namespace ::com::sun::star::container;
79 using namespace ::xmloff::token;
82 void XMLTextParagraphExport::exportTextFootnote(
83 const Reference<XPropertySet> & rPropSet,
84 const OUString& rText,
85 sal_Bool bAutoStyles, sal_Bool bIsProgress )
87 // get footnote and associated text
88 Any aAny;
89 aAny = rPropSet->getPropertyValue(sFootnote);
90 Reference<XFootnote> xFootnote;
91 aAny >>= xFootnote;
92 Reference<XText> xText(xFootnote, UNO_QUERY);
94 // are we an endnote?
95 Reference<XServiceInfo> xServiceInfo( xFootnote, UNO_QUERY );
96 sal_Bool bIsEndnote = xServiceInfo->supportsService(sTextEndnoteService);
98 if (bAutoStyles)
100 // handle formatting of citation mark
101 Add( XML_STYLE_FAMILY_TEXT_TEXT, rPropSet );
103 // handle formatting within footnote
104 exportTextFootnoteHelper(xFootnote, xText, rText,
105 bAutoStyles, bIsEndnote, bIsProgress );
107 else
109 // create span (for citation mark) if necessary; footnote content
110 // wil be handled via exportTextFootnoteHelper, exportText
111 sal_Bool bHasHyperlink;
112 sal_Bool bIsUICharStyle = sal_False;
113 sal_Bool bHasAutoStyle = sal_False;
115 OUString sStyle = FindTextStyleAndHyperlink( rPropSet, bHasHyperlink,
116 bIsUICharStyle, bHasAutoStyle );
118 // export hyperlink (if we have one)
119 Reference < XPropertySetInfo > xPropSetInfo;
120 if( bHasHyperlink )
122 Reference<XPropertyState> xPropState( rPropSet, UNO_QUERY );
123 xPropSetInfo = rPropSet->getPropertySetInfo();
124 bHasHyperlink =
125 addHyperlinkAttributes( rPropSet, xPropState, xPropSetInfo );
127 SvXMLElementExport aHyperlink( GetExport(), bHasHyperlink,
128 XML_NAMESPACE_TEXT, XML_A,
129 sal_False, sal_False );
131 if( bHasHyperlink )
133 // export events (if supported)
134 OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
135 "HyperLinkEvents"));
136 if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
138 Any a = rPropSet->getPropertyValue(sHyperLinkEvents);
139 Reference<XNameReplace> xName;
140 a >>= xName;
141 GetExport().GetEventExport().Export(xName, sal_False);
146 XMLTextCharStyleNamesElementExport aCharStylesExport(
147 GetExport(), bIsUICharStyle &&
148 aCharStyleNamesPropInfoCache.hasProperty(
149 rPropSet ), bHasAutoStyle,
150 rPropSet, sCharStyleNames );
151 if( sStyle.getLength() )
153 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
154 GetExport().EncodeStyleName( sStyle ) );
155 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
156 XML_SPAN, sal_False, sal_False );
157 exportTextFootnoteHelper(xFootnote, xText, rText,
158 bAutoStyles, bIsEndnote, bIsProgress );
160 else
162 exportTextFootnoteHelper(xFootnote, xText, rText,
163 bAutoStyles, bIsEndnote, bIsProgress );
170 void XMLTextParagraphExport::exportTextFootnoteHelper(
171 const Reference<XFootnote> & rFootnote,
172 const Reference<XText> & rText,
173 const OUString& rTextString,
174 sal_Bool bAutoStyles,
175 sal_Bool bIsEndnote,
176 sal_Bool bIsProgress )
178 if (bAutoStyles)
180 exportText(rText, bAutoStyles, bIsProgress, sal_True );
182 else
184 // export reference Id (for reference fields)
185 Reference<XPropertySet> xPropSet(rFootnote, UNO_QUERY);
186 Any aAny = xPropSet->getPropertyValue(sReferenceId);
187 sal_Int32 nNumber = 0;
188 aAny >>= nNumber;
189 OUStringBuffer aBuf;
190 aBuf.appendAscii("ftn");
191 aBuf.append(nNumber);
192 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_ID,
193 aBuf.makeStringAndClear());
194 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
195 GetXMLToken( bIsEndnote ? XML_ENDNOTE
196 : XML_FOOTNOTE ) );
198 SvXMLElementExport aNote(GetExport(), XML_NAMESPACE_TEXT,
199 XML_NOTE, sal_False, sal_False);
201 // handle label vs. automatic numbering
202 OUString sLabel = rFootnote->getLabel();
203 if (sLabel.getLength()>0)
205 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_LABEL,
206 sLabel);
208 // else: automatic numbering -> no attribute
210 SvXMLElementExport aCite(GetExport(), XML_NAMESPACE_TEXT,
211 XML_NOTE_CITATION, sal_False, sal_False);
212 GetExport().Characters(rTextString);
216 SvXMLElementExport aBody(GetExport(), XML_NAMESPACE_TEXT,
217 XML_NOTE_BODY, sal_False, sal_False);
218 exportText(rText, bAutoStyles, bIsProgress, sal_True );
224 void XMLTextParagraphExport::exportTextFootnoteConfiguration()
226 // footnote settings
227 Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
228 UNO_QUERY);
229 Reference<XPropertySet> aFootnoteConfiguration(
230 aFootnotesSupplier->getFootnoteSettings());
231 exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, sal_False);
233 // endnote settings
234 Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
235 UNO_QUERY);
236 Reference<XPropertySet> aEndnoteConfiguration(
237 aEndnotesSupplier->getEndnoteSettings());
238 exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, sal_True);
242 void lcl_exportString(
243 SvXMLExport& rExport,
244 const Reference<XPropertySet> & rPropSet,
245 const OUString& sProperty,
246 sal_uInt16 nPrefix,
247 enum XMLTokenEnum eElement,
248 sal_Bool bEncodeName,
249 sal_Bool bOmitIfEmpty)
251 DBG_ASSERT( eElement != XML_TOKEN_INVALID, "need element token");
253 Any aAny = rPropSet->getPropertyValue(sProperty);
254 OUString sTmp;
255 aAny >>= sTmp;
256 if (!bOmitIfEmpty || (sTmp.getLength() > 0))
258 if( bEncodeName )
259 sTmp = rExport.EncodeStyleName( sTmp );
260 rExport.AddAttribute(nPrefix, eElement, sTmp);
264 void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
265 const Reference<XPropertySet> & rFootnoteConfig,
266 sal_Bool bIsEndnote)
268 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
269 GetXMLToken( bIsEndnote ? XML_ENDNOTE
270 : XML_FOOTNOTE ) );
271 // default/paragraph style
272 lcl_exportString( GetExport(), rFootnoteConfig,
273 sParaStyleName,
274 XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME,
275 sal_True, sal_True);
277 // citation style
278 lcl_exportString( GetExport(), rFootnoteConfig,
279 sCharStyleName,
280 XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME,
281 sal_True, sal_True);
283 // citation body style
284 lcl_exportString( GetExport(), rFootnoteConfig,
285 sAnchorCharStyleName,
286 XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME,
287 sal_True, sal_True);
289 // page style
290 lcl_exportString( GetExport(), rFootnoteConfig,
291 sPageStyleName,
292 XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME,
293 sal_True, sal_True );
295 // prefix
296 lcl_exportString( GetExport(), rFootnoteConfig, sPrefix,
297 XML_NAMESPACE_STYLE, XML_NUM_PREFIX, sal_False, sal_True);
299 // suffix
300 lcl_exportString( GetExport(), rFootnoteConfig, sSuffix,
301 XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, sal_False, sal_True);
305 Any aAny;
307 // numbering style
308 OUStringBuffer sBuffer;
309 aAny = rFootnoteConfig->getPropertyValue(sNumberingType);
310 sal_Int16 nNumbering = 0;
311 aAny >>= nNumbering;
312 GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering);
313 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
314 sBuffer.makeStringAndClear() );
315 GetExport().GetMM100UnitConverter().convertNumLetterSync( sBuffer, nNumbering);
316 if (sBuffer.getLength() )
318 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
319 sBuffer.makeStringAndClear());
322 // StartAt / start-value
323 aAny = rFootnoteConfig->getPropertyValue(sStartAt);
324 sal_Int16 nOffset = 0;
325 aAny >>= nOffset;
326 SvXMLUnitConverter::convertNumber(sBuffer, (sal_Int32)nOffset);
327 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
328 sBuffer.makeStringAndClear());
330 // some properties are for footnotes only
331 if (!bIsEndnote)
333 // footnotes position
334 aAny = rFootnoteConfig->getPropertyValue(
335 sPositionEndOfDoc);
336 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION,
337 ( (*(sal_Bool *)aAny.getValue()) ?
338 XML_DOCUMENT : XML_PAGE ) );
340 aAny = rFootnoteConfig->getPropertyValue(sFootnoteCounting);
341 sal_Int16 nTmp = 0;
342 aAny >>= nTmp;
343 enum XMLTokenEnum eElement;
344 switch (nTmp)
346 case FootnoteNumbering::PER_PAGE:
347 eElement = XML_PAGE;
348 break;
349 case FootnoteNumbering::PER_CHAPTER:
350 eElement = XML_CHAPTER;
351 break;
352 case FootnoteNumbering::PER_DOCUMENT:
353 default:
354 eElement = XML_DOCUMENT;
355 break;
357 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
358 XML_START_NUMBERING_AT, eElement);
361 // element
362 SvXMLElementExport aFootnoteConfigElement(
363 GetExport(), XML_NAMESPACE_TEXT,
364 XML_NOTES_CONFIGURATION,
365 sal_True, sal_True);
367 // two element for footnote content
368 if (!bIsEndnote)
370 OUString sTmp;
372 // end notice / quo vadis
373 aAny = rFootnoteConfig->getPropertyValue(sEndNotice);
374 aAny >>= sTmp;
376 if (sTmp.getLength() > 0)
378 SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
379 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD,
380 sal_True, sal_False);
381 GetExport().Characters(sTmp);
384 // begin notice / ergo sum
385 aAny = rFootnoteConfig->getPropertyValue(sBeginNotice);
386 aAny >>= sTmp;
388 if (sTmp.getLength() > 0)
390 SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
391 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD,
392 sal_True, sal_False);
393 GetExport().Characters(sTmp);