1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmloff/xmlnamespace.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <com/sun/star/text/XText.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <xmloff/xmlexp.hxx>
25 #include <xmloff/XMLTextMasterPageExport.hxx>
26 #include <sal/log.hxx>
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::text
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::xmloff::token
;
35 constexpr OUStringLiteral
gsHeaderText( u
"HeaderText" );
36 constexpr OUStringLiteral
gsHeaderOn( u
"HeaderIsOn" );
37 constexpr OUStringLiteral
gsHeaderShareContent( u
"HeaderIsShared" );
38 constexpr OUStringLiteral
gsHeaderTextFirst( u
"HeaderTextFirst" );
39 constexpr OUStringLiteral
gsHeaderTextLeft( u
"HeaderTextLeft" );
40 constexpr OUString
gsFirstShareContent( u
"FirstIsShared"_ustr
);
41 constexpr OUStringLiteral
gsFooterText( u
"FooterText" );
42 constexpr OUStringLiteral
gsFooterOn( u
"FooterIsOn" );
43 constexpr OUStringLiteral
gsFooterShareContent( u
"FooterIsShared" );
44 constexpr OUStringLiteral
gsFooterTextFirst( u
"FooterTextFirst" );
45 constexpr OUStringLiteral
gsFooterTextLeft( u
"FooterTextLeft" );
47 XMLTextMasterPageExport::XMLTextMasterPageExport( SvXMLExport
& rExp
) :
52 XMLTextMasterPageExport::~XMLTextMasterPageExport()
57 void XMLTextMasterPageExport::exportHeaderFooterContent(
58 const Reference
< XText
>& rText
,
59 bool bAutoStyles
, bool bExportParagraph
)
61 SAL_WARN_IF( !rText
.is(), "xmloff", "There is the text" );
63 // tracked changes (autostyles + changes list)
64 GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText
);
65 GetExport().GetTextParagraphExport()->exportTrackedChanges(rText
,
68 GetExport().GetTextParagraphExport()
69 ->collectTextAutoStyles( rText
, true, bExportParagraph
);
72 GetExport().GetTextParagraphExport()->exportTextDeclarations( rText
);
73 GetExport().GetTextParagraphExport()->exportText( rText
, true, bExportParagraph
);
76 // tracked changes (end of XText)
77 GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText();
80 void XMLTextMasterPageExport::exportMasterPageContent(
81 const Reference
< XPropertySet
> & rPropSet
,
86 Reference
< XText
> xHeaderText
;
87 aAny
= rPropSet
->getPropertyValue( gsHeaderText
);
90 Reference
< XText
> xHeaderTextFirst
;
91 aAny
= rPropSet
->getPropertyValue( gsHeaderTextFirst
);
92 aAny
>>= xHeaderTextFirst
;
94 Reference
< XText
> xHeaderTextLeft
;
95 aAny
= rPropSet
->getPropertyValue( gsHeaderTextLeft
);
96 aAny
>>= xHeaderTextLeft
;
98 Reference
< XText
> xFooterText
;
99 aAny
= rPropSet
->getPropertyValue( gsFooterText
);
100 aAny
>>= xFooterText
;
102 Reference
< XText
> xFooterTextFirst
;
103 aAny
= rPropSet
->getPropertyValue( gsFooterTextFirst
);
104 aAny
>>= xFooterTextFirst
;
106 Reference
< XText
> xFooterTextLeft
;
107 aAny
= rPropSet
->getPropertyValue( gsFooterTextLeft
);
108 aAny
>>= xFooterTextLeft
;
112 if( xHeaderText
.is() )
113 exportHeaderFooterContent( xHeaderText
, true );
114 if( xHeaderTextFirst
.is() && xHeaderTextFirst
!= xHeaderText
)
115 exportHeaderFooterContent( xHeaderTextFirst
, true );
116 if( xHeaderTextLeft
.is() && xHeaderTextLeft
!= xHeaderText
)
117 exportHeaderFooterContent( xHeaderTextLeft
, true );
118 if( xFooterText
.is() )
119 exportHeaderFooterContent( xFooterText
, true );
120 if( xFooterTextFirst
.is() && xFooterTextFirst
!= xFooterText
)
121 exportHeaderFooterContent( xFooterTextFirst
, true );
122 if( xFooterTextLeft
.is() && xFooterTextLeft
!= xFooterText
)
123 exportHeaderFooterContent( xFooterTextLeft
, true );
127 auto const nVersion(GetExport().getSaneDefaultVersion());
129 aAny
= rPropSet
->getPropertyValue( gsHeaderOn
);
130 bool bHeader
= false;
133 bool bHeaderFirstShared
= false;
136 aAny
= rPropSet
->getPropertyValue( gsFirstShareContent
);
137 aAny
>>= bHeaderFirstShared
;
140 bool bHeaderLeftShared
= false;
143 aAny
= rPropSet
->getPropertyValue( gsHeaderShareContent
);
144 aAny
>>= bHeaderLeftShared
;
147 if( xHeaderText
.is() )
150 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
151 XML_DISPLAY
, XML_FALSE
);
152 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
,
153 XML_HEADER
, true, true );
154 exportHeaderFooterContent( xHeaderText
, false );
157 if( xHeaderTextLeft
.is() && xHeaderTextLeft
!= xHeaderText
)
159 if (bHeaderLeftShared
)
160 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
161 XML_DISPLAY
, XML_FALSE
);
162 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
,
163 XML_HEADER_LEFT
, true, true );
164 exportHeaderFooterContent( xHeaderTextLeft
, false );
167 if (xHeaderTextFirst
.is() && xHeaderTextFirst
!= xHeaderText
168 && SvtSaveOptions::ODFSVER_012
< nVersion
)
170 if (bHeaderFirstShared
)
171 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
172 XML_DISPLAY
, XML_FALSE
);
173 // ODF 1.3 OFFICE-3789
174 SvXMLElementExport
aElem( GetExport(),
175 SvtSaveOptions::ODFSVER_013
<= nVersion
176 ? XML_NAMESPACE_STYLE
177 : XML_NAMESPACE_LO_EXT
,
178 XML_HEADER_FIRST
, true, true );
179 exportHeaderFooterContent( xHeaderTextFirst
, false );
182 aAny
= rPropSet
->getPropertyValue( gsFooterOn
);
183 bool bFooter
= false;
186 bool bFooterFirstShared
= false;
189 aAny
= rPropSet
->getPropertyValue( gsFirstShareContent
);
190 aAny
>>= bFooterFirstShared
;
193 bool bFooterLeftShared
= false;
196 aAny
= rPropSet
->getPropertyValue( gsFooterShareContent
);
197 aAny
>>= bFooterLeftShared
;
200 if( xFooterText
.is() )
203 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
204 XML_DISPLAY
, XML_FALSE
);
205 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
,
206 XML_FOOTER
, true, true );
207 exportHeaderFooterContent( xFooterText
, false );
210 if( xFooterTextLeft
.is() && xFooterTextLeft
!= xFooterText
)
212 if (bFooterLeftShared
)
213 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
214 XML_DISPLAY
, XML_FALSE
);
215 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
,
216 XML_FOOTER_LEFT
, true, true );
217 exportHeaderFooterContent( xFooterTextLeft
, false );
220 if (xFooterTextFirst
.is() && xFooterTextFirst
!= xFooterText
221 && SvtSaveOptions::ODFSVER_012
< nVersion
)
223 if (bFooterFirstShared
)
224 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
225 XML_DISPLAY
, XML_FALSE
);
226 // ODF 1.3 OFFICE-3789
227 SvXMLElementExport
aElem( GetExport(),
228 SvtSaveOptions::ODFSVER_013
<= nVersion
229 ? XML_NAMESPACE_STYLE
230 : XML_NAMESPACE_LO_EXT
,
231 XML_FOOTER_FIRST
, true, true );
232 exportHeaderFooterContent( xFooterTextFirst
, false );
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */