xref: /trunk/main/xmloff/source/text/XMLTextMasterPageExport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <tools/debug.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/xmltoken.hxx>
33 #include <com/sun/star/text/XText.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <xmloff/xmlexp.hxx>
36 #include <xmloff/XMLTextMasterPageExport.hxx>
37 
38 
39 using ::rtl::OUString;
40 using ::rtl::OUStringBuffer;
41 
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::text;
45 using namespace ::com::sun::star::beans;
46 using namespace ::xmloff::token;
47 
48 XMLTextMasterPageExport::XMLTextMasterPageExport( SvXMLExport& rExp ) :
49     XMLPageExport( rExp ),
50     sHeaderText( RTL_CONSTASCII_USTRINGPARAM( "HeaderText" ) ),
51     sHeaderOn( RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" ) ),
52     sHeaderShareContent( RTL_CONSTASCII_USTRINGPARAM( "HeaderIsShared" ) ),
53     sHeaderTextLeft( RTL_CONSTASCII_USTRINGPARAM( "HeaderTextLeft" ) ),
54     sFooterText( RTL_CONSTASCII_USTRINGPARAM( "FooterText" ) ),
55     sFooterOn( RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" ) ),
56     sFooterShareContent( RTL_CONSTASCII_USTRINGPARAM( "FooterIsShared" ) ),
57     sFooterTextLeft( RTL_CONSTASCII_USTRINGPARAM( "FooterTextLeft" ) )
58 {
59 }
60 
61 XMLTextMasterPageExport::~XMLTextMasterPageExport()
62 {
63 }
64 
65 
66 void XMLTextMasterPageExport::exportHeaderFooterContent(
67             const Reference< XText >& rText,
68             sal_Bool bAutoStyles, sal_Bool bExportParagraph )
69 {
70     DBG_ASSERT( rText.is(), "There is the text" );
71 
72     // tracked changes (autostyles + changes list)
73     GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText);
74     GetExport().GetTextParagraphExport()->exportTrackedChanges(rText,
75                                                                bAutoStyles);
76     if( bAutoStyles )
77         GetExport().GetTextParagraphExport()
78                 ->collectTextAutoStyles( rText, sal_True, bExportParagraph );
79     else
80     {
81         GetExport().GetTextParagraphExport()->exportTextDeclarations( rText );
82         GetExport().GetTextParagraphExport()->exportText( rText, sal_True, bExportParagraph );
83     }
84 
85     // tracked changes (end of XText)
86     GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText();
87 }
88 
89 void XMLTextMasterPageExport::exportMasterPageContent(
90                 const Reference < XPropertySet > & rPropSet,
91                 sal_Bool bAutoStyles )
92 {
93     Any aAny;
94 
95     Reference < XText > xHeaderText;
96     aAny = rPropSet->getPropertyValue( sHeaderText );
97     aAny >>= xHeaderText;
98 
99     Reference < XText > xHeaderTextLeft;
100     aAny = rPropSet->getPropertyValue( sHeaderTextLeft );
101     aAny >>= xHeaderTextLeft;
102 
103     Reference < XText > xFooterText;
104     aAny = rPropSet->getPropertyValue( sFooterText );
105     aAny >>= xFooterText;
106 
107     Reference < XText > xFooterTextLeft;
108     aAny = rPropSet->getPropertyValue( sFooterTextLeft );
109     aAny >>= xFooterTextLeft;
110 
111     if( bAutoStyles )
112     {
113         if( xHeaderText.is() )
114             exportHeaderFooterContent( xHeaderText, sal_True );
115         if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
116             exportHeaderFooterContent( xHeaderTextLeft, sal_True );
117         if( xFooterText.is() )
118             exportHeaderFooterContent( xFooterText, sal_True );
119         if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
120             exportHeaderFooterContent( xFooterTextLeft, sal_True );
121     }
122     else
123     {
124         aAny = rPropSet->getPropertyValue( sHeaderOn );
125         sal_Bool bHeader = *(sal_Bool *)aAny.getValue();
126 
127         sal_Bool bHeaderLeft = sal_False;
128         if( bHeader )
129         {
130             aAny = rPropSet->getPropertyValue( sHeaderShareContent );
131             bHeaderLeft = !*(sal_Bool *)aAny.getValue();
132         }
133 
134         if( xHeaderText.is() )
135         {
136             if( !bHeader )
137                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
138                                           XML_DISPLAY, XML_FALSE );
139             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
140                                       XML_HEADER, sal_True, sal_True );
141             exportHeaderFooterContent( xHeaderText, sal_False );
142         }
143 
144         if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
145         {
146             if( !bHeaderLeft )
147                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
148                                           XML_DISPLAY, XML_FALSE );
149             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
150                                       XML_HEADER_LEFT, sal_True, sal_True );
151             exportHeaderFooterContent( xHeaderTextLeft, sal_False );
152         }
153 
154         aAny = rPropSet->getPropertyValue( sFooterOn );
155         sal_Bool bFooter = *(sal_Bool *)aAny.getValue();
156 
157         sal_Bool bFooterLeft = sal_False;
158         if( bFooter )
159         {
160             aAny = rPropSet->getPropertyValue( sFooterShareContent );
161             bFooterLeft = !*(sal_Bool *)aAny.getValue();
162         }
163 
164         if( xFooterText.is() )
165         {
166             if( !bFooter )
167                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
168                                           XML_DISPLAY, XML_FALSE );
169             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
170                                       XML_FOOTER, sal_True, sal_True );
171             exportHeaderFooterContent( xFooterText, sal_False );
172         }
173 
174         if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
175         {
176             if( !bFooterLeft )
177                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
178                                           XML_DISPLAY, XML_FALSE );
179             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
180                                       XML_FOOTER_LEFT, sal_True, sal_True );
181             exportHeaderFooterContent( xFooterTextLeft, sal_False );
182         }
183     }
184 }
185 
186