xref: /AOO41X/main/xmloff/source/text/XMLTextMasterPageExport.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
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_xmloff.hxx"
26 #include <tools/debug.hxx>
27 #include "xmloff/xmlnmspe.hxx"
28 #include <xmloff/xmltoken.hxx>
29 #include <com/sun/star/text/XText.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <xmloff/xmlexp.hxx>
32 #include <xmloff/XMLTextMasterPageExport.hxx>
33 
34 
35 using ::rtl::OUString;
36 using ::rtl::OUStringBuffer;
37 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::text;
41 using namespace ::com::sun::star::beans;
42 using namespace ::xmloff::token;
43 
XMLTextMasterPageExport(SvXMLExport & rExp)44 XMLTextMasterPageExport::XMLTextMasterPageExport( SvXMLExport& rExp ) :
45     XMLPageExport( rExp ),
46     sHeaderText( RTL_CONSTASCII_USTRINGPARAM( "HeaderText" ) ),
47     sHeaderOn( RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" ) ),
48     sHeaderShareContent( RTL_CONSTASCII_USTRINGPARAM( "HeaderIsShared" ) ),
49     sHeaderTextLeft( RTL_CONSTASCII_USTRINGPARAM( "HeaderTextLeft" ) ),
50     sFooterText( RTL_CONSTASCII_USTRINGPARAM( "FooterText" ) ),
51     sFooterOn( RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" ) ),
52     sFooterShareContent( RTL_CONSTASCII_USTRINGPARAM( "FooterIsShared" ) ),
53     sFooterTextLeft( RTL_CONSTASCII_USTRINGPARAM( "FooterTextLeft" ) )
54 {
55 }
56 
~XMLTextMasterPageExport()57 XMLTextMasterPageExport::~XMLTextMasterPageExport()
58 {
59 }
60 
61 
exportHeaderFooterContent(const Reference<XText> & rText,sal_Bool bAutoStyles,sal_Bool bExportParagraph)62 void XMLTextMasterPageExport::exportHeaderFooterContent(
63             const Reference< XText >& rText,
64             sal_Bool bAutoStyles, sal_Bool bExportParagraph )
65 {
66     DBG_ASSERT( rText.is(), "There is the text" );
67 
68     // tracked changes (autostyles + changes list)
69     GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText);
70     GetExport().GetTextParagraphExport()->exportTrackedChanges(rText,
71                                                                bAutoStyles);
72     if( bAutoStyles )
73         GetExport().GetTextParagraphExport()
74                 ->collectTextAutoStyles( rText, sal_True, bExportParagraph );
75     else
76     {
77         GetExport().GetTextParagraphExport()->exportTextDeclarations( rText );
78         GetExport().GetTextParagraphExport()->exportText( rText, sal_True, bExportParagraph );
79     }
80 
81     // tracked changes (end of XText)
82     GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText();
83 }
84 
exportMasterPageContent(const Reference<XPropertySet> & rPropSet,sal_Bool bAutoStyles)85 void XMLTextMasterPageExport::exportMasterPageContent(
86                 const Reference < XPropertySet > & rPropSet,
87                 sal_Bool bAutoStyles )
88 {
89     Any aAny;
90 
91     Reference < XText > xHeaderText;
92     aAny = rPropSet->getPropertyValue( sHeaderText );
93     aAny >>= xHeaderText;
94 
95     Reference < XText > xHeaderTextLeft;
96     aAny = rPropSet->getPropertyValue( sHeaderTextLeft );
97     aAny >>= xHeaderTextLeft;
98 
99     Reference < XText > xFooterText;
100     aAny = rPropSet->getPropertyValue( sFooterText );
101     aAny >>= xFooterText;
102 
103     Reference < XText > xFooterTextLeft;
104     aAny = rPropSet->getPropertyValue( sFooterTextLeft );
105     aAny >>= xFooterTextLeft;
106 
107     if( bAutoStyles )
108     {
109         if( xHeaderText.is() )
110             exportHeaderFooterContent( xHeaderText, sal_True );
111         if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
112             exportHeaderFooterContent( xHeaderTextLeft, sal_True );
113         if( xFooterText.is() )
114             exportHeaderFooterContent( xFooterText, sal_True );
115         if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
116             exportHeaderFooterContent( xFooterTextLeft, sal_True );
117     }
118     else
119     {
120         aAny = rPropSet->getPropertyValue( sHeaderOn );
121         sal_Bool bHeader = *(sal_Bool *)aAny.getValue();
122 
123         sal_Bool bHeaderLeft = sal_False;
124         if( bHeader )
125         {
126             aAny = rPropSet->getPropertyValue( sHeaderShareContent );
127             bHeaderLeft = !*(sal_Bool *)aAny.getValue();
128         }
129 
130         if( xHeaderText.is() )
131         {
132             if( !bHeader )
133                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
134                                           XML_DISPLAY, XML_FALSE );
135             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
136                                       XML_HEADER, sal_True, sal_True );
137             exportHeaderFooterContent( xHeaderText, sal_False );
138         }
139 
140         if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
141         {
142             if( !bHeaderLeft )
143                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
144                                           XML_DISPLAY, XML_FALSE );
145             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
146                                       XML_HEADER_LEFT, sal_True, sal_True );
147             exportHeaderFooterContent( xHeaderTextLeft, sal_False );
148         }
149 
150         aAny = rPropSet->getPropertyValue( sFooterOn );
151         sal_Bool bFooter = *(sal_Bool *)aAny.getValue();
152 
153         sal_Bool bFooterLeft = sal_False;
154         if( bFooter )
155         {
156             aAny = rPropSet->getPropertyValue( sFooterShareContent );
157             bFooterLeft = !*(sal_Bool *)aAny.getValue();
158         }
159 
160         if( xFooterText.is() )
161         {
162             if( !bFooter )
163                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
164                                           XML_DISPLAY, XML_FALSE );
165             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
166                                       XML_FOOTER, sal_True, sal_True );
167             exportHeaderFooterContent( xFooterText, sal_False );
168         }
169 
170         if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
171         {
172             if( !bFooterLeft )
173                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
174                                           XML_DISPLAY, XML_FALSE );
175             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
176                                       XML_FOOTER_LEFT, sal_True, sal_True );
177             exportHeaderFooterContent( xFooterTextLeft, sal_False );
178         }
179     }
180 }
181 
182