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_sc.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 "XMLTableMasterPageExport.hxx"
32 #include <comphelper/extract.hxx>
33 
34 #include "unonames.hxx"
35 #include "xmlexprt.hxx"
36 
37 using ::rtl::OUString;
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 
XMLTableMasterPageExport(ScXMLExport & rExp)44 XMLTableMasterPageExport::XMLTableMasterPageExport( ScXMLExport& rExp ) :
45 		XMLTextMasterPageExport ( rExp )
46 {
47 }
48 
~XMLTableMasterPageExport()49 XMLTableMasterPageExport::~XMLTableMasterPageExport()
50 {
51 }
52 
exportHeaderFooterContent(const Reference<XText> & rText,sal_Bool bAutoStyles,sal_Bool bProgress)53 void XMLTableMasterPageExport::exportHeaderFooterContent(
54 			const Reference< XText >& rText,
55 	        sal_Bool bAutoStyles, sal_Bool bProgress )
56 {
57 	DBG_ASSERT( rText.is(), "There is the text" );
58 
59 	if( bAutoStyles )
60 		GetExport().GetTextParagraphExport()
61 				->collectTextAutoStyles( rText, bProgress, sal_False );
62 	else
63 	{
64 		GetExport().GetTextParagraphExport()->exportTextDeclarations( rText );
65 		GetExport().GetTextParagraphExport()->exportText( rText, bProgress, sal_False );
66 	}
67 }
68 
exportHeaderFooter(const com::sun::star::uno::Reference<com::sun::star::sheet::XHeaderFooterContent> & xHeaderFooter,const XMLTokenEnum aName,const sal_Bool bDisplay)69 void XMLTableMasterPageExport::exportHeaderFooter(const com::sun::star::uno::Reference < com::sun::star::sheet::XHeaderFooterContent >& xHeaderFooter,
70 													const XMLTokenEnum aName,
71 													const sal_Bool bDisplay)
72 {
73 	if( xHeaderFooter.is() )
74 	{
75 		Reference < XText > xCenter(xHeaderFooter->getCenterText());
76 		Reference < XText > xLeft(xHeaderFooter->getLeftText());
77 		Reference < XText > xRight(xHeaderFooter->getRightText());
78 		if (xCenter.is() && xLeft.is() && xRight.is())
79 		{
80 			rtl::OUString sCenter (xCenter->getString());
81 			rtl::OUString sLeft (xLeft->getString());
82 			rtl::OUString sRight (xRight->getString());
83 
84 			if( !bDisplay )
85 				GetExport().AddAttribute( XML_NAMESPACE_STYLE,
86 												XML_DISPLAY, XML_FALSE );
87 			SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
88 								  	aName, sal_True, sal_True );
89 			if (sCenter.getLength() && !sLeft.getLength() && !sRight.getLength())
90 				exportHeaderFooterContent( xCenter, sal_False, sal_False );
91 			else
92 			{
93 				if (sLeft.getLength())
94 				{
95 					SvXMLElementExport aSubElem( GetExport(), XML_NAMESPACE_STYLE,
96 								  	  		XML_REGION_LEFT, sal_True, sal_True );
97 					exportHeaderFooterContent( xLeft, sal_False, sal_False );
98 				}
99 				if (sCenter.getLength())
100 				{
101 					SvXMLElementExport aSubElem( GetExport(), XML_NAMESPACE_STYLE,
102 								  	  		XML_REGION_CENTER, sal_True, sal_True );
103 					exportHeaderFooterContent( xCenter, sal_False, sal_False );
104 				}
105 				if (sRight.getLength())
106 				{
107 					SvXMLElementExport aSubElem( GetExport(), XML_NAMESPACE_STYLE,
108 								  	  		XML_REGION_RIGHT, sal_True, sal_True );
109 					exportHeaderFooterContent( xRight, sal_False, sal_False );
110 				}
111 			}
112 		}
113 	}
114 }
115 
exportMasterPageContent(const Reference<XPropertySet> & rPropSet,sal_Bool bAutoStyles)116 void XMLTableMasterPageExport::exportMasterPageContent(
117 				const Reference < XPropertySet > & rPropSet,
118 				sal_Bool bAutoStyles )
119 {
120     Reference < sheet::XHeaderFooterContent > xHeader(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_RIGHTHDRCON ) ) ), uno::UNO_QUERY);
121 
122 	Reference < sheet::XHeaderFooterContent > xHeaderLeft(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_LEFTHDRCONT ) ) ), uno::UNO_QUERY);
123 
124 	Reference < sheet::XHeaderFooterContent > xFooter(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_RIGHTFTRCON ) ) ), uno::UNO_QUERY);
125 
126 	Reference < sheet::XHeaderFooterContent > xFooterLeft(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_LEFTFTRCONT ) ) ), uno::UNO_QUERY);
127 
128 	if( bAutoStyles )
129 	{
130 		if( xHeader.is() )
131 		{
132 			exportHeaderFooterContent( xHeader->getCenterText(), sal_True, sal_False );
133 			exportHeaderFooterContent( xHeader->getLeftText(), sal_True, sal_False );
134 			exportHeaderFooterContent( xHeader->getRightText(), sal_True, sal_False );
135 		}
136 		if( xHeaderLeft.is())
137 		{
138 			exportHeaderFooterContent( xHeaderLeft->getCenterText(), sal_True, sal_False );
139 			exportHeaderFooterContent( xHeaderLeft->getLeftText(), sal_True, sal_False );
140 			exportHeaderFooterContent( xHeaderLeft->getRightText(), sal_True, sal_False );
141 		}
142 		if( xFooter.is() )
143 		{
144 			exportHeaderFooterContent( xFooter->getCenterText(), sal_True, sal_False );
145 			exportHeaderFooterContent( xFooter->getLeftText(), sal_True, sal_False );
146 			exportHeaderFooterContent( xFooter->getRightText(), sal_True, sal_False );
147 		}
148 		if( xFooterLeft.is())
149 		{
150 			exportHeaderFooterContent( xFooterLeft->getCenterText(), sal_True, sal_False );
151 			exportHeaderFooterContent( xFooterLeft->getLeftText(), sal_True, sal_False );
152 			exportHeaderFooterContent( xFooterLeft->getRightText(), sal_True, sal_False );
153 		}
154 	}
155 	else
156 	{
157         sal_Bool bHeader(::cppu::any2bool(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_HDRON ) ) )));
158 
159 		exportHeaderFooter(xHeader, XML_HEADER, bHeader );
160 
161 		sal_Bool bLeftHeader(!::cppu::any2bool(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_HDRSHARED ) ) )) && bHeader);
162 
163 		exportHeaderFooter( xHeaderLeft, XML_HEADER_LEFT, bLeftHeader );
164 
165 		sal_Bool bFooter(::cppu::any2bool(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_FTRON ) ) )));
166 
167 		exportHeaderFooter( xFooter, XML_FOOTER, bFooter );
168 
169 		sal_Bool bLeftFooter = (!::cppu::any2bool(rPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNO_PAGE_FTRSHARED ) ) )) && bFooter);
170 
171 		exportHeaderFooter( xFooterLeft, XML_FOOTER_LEFT, bLeftFooter );
172 	}
173 }
174 
175