1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <com/sun/star/text/XTextColumns.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/text/TextColumn.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
41*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
42*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
43*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
44*cdf0e10cSrcweir #include "XMLTextColumnsExport.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace ::com::sun::star::style;
47*cdf0e10cSrcweir using namespace ::com::sun::star::text;
48*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
50*cdf0e10cSrcweir using ::rtl::OUString;
51*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
52*cdf0e10cSrcweir using namespace ::xmloff::token;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) :
56*cdf0e10cSrcweir 	rExport( rExp ),
57*cdf0e10cSrcweir 	sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")),
58*cdf0e10cSrcweir 	sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")),
59*cdf0e10cSrcweir 	sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")),
60*cdf0e10cSrcweir 	sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")),
61*cdf0e10cSrcweir 	sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")),
62*cdf0e10cSrcweir     sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")),
63*cdf0e10cSrcweir     sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance"))
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir void XMLTextColumnsExport::exportXML( const Any& rAny )
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	Reference < XTextColumns > xColumns;
70*cdf0e10cSrcweir 	rAny >>= xColumns;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	Sequence < TextColumn > aColumns = xColumns->getColumns();
73*cdf0e10cSrcweir 	const TextColumn *pColumns = aColumns.getArray();
74*cdf0e10cSrcweir 	sal_Int32 nCount = aColumns.getLength();
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	OUStringBuffer sValue;
77*cdf0e10cSrcweir 	GetExport().GetMM100UnitConverter().convertNumber( sValue, nCount ? nCount : 1 );
78*cdf0e10cSrcweir 	GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
79*cdf0e10cSrcweir 							  sValue.makeStringAndClear() );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     // handle 'automatic' columns
82*cdf0e10cSrcweir 	Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
83*cdf0e10cSrcweir     if( xPropSet.is() )
84*cdf0e10cSrcweir     {
85*cdf0e10cSrcweir         Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
86*cdf0e10cSrcweir         if ( *(sal_Bool*)aAny.getValue() )
87*cdf0e10cSrcweir         {
88*cdf0e10cSrcweir             aAny = xPropSet->getPropertyValue( sAutomaticDistance );
89*cdf0e10cSrcweir             sal_Int32 nDistance = 0;
90*cdf0e10cSrcweir             aAny >>= nDistance;
91*cdf0e10cSrcweir             OUStringBuffer aBuffer;
92*cdf0e10cSrcweir             GetExport().GetMM100UnitConverter().convertMeasure(
93*cdf0e10cSrcweir                 aBuffer, nDistance );
94*cdf0e10cSrcweir             GetExport().AddAttribute( XML_NAMESPACE_FO,
95*cdf0e10cSrcweir                                       XML_COLUMN_GAP,
96*cdf0e10cSrcweir                                       aBuffer.makeStringAndClear() );
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
101*cdf0e10cSrcweir 							  sal_True, sal_True );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	if( xPropSet.is() )
104*cdf0e10cSrcweir 	{
105*cdf0e10cSrcweir 		Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
106*cdf0e10cSrcweir 		if( *(sal_Bool *)aAny.getValue() )
107*cdf0e10cSrcweir 		{
108*cdf0e10cSrcweir 			// style:width
109*cdf0e10cSrcweir 			aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
110*cdf0e10cSrcweir 			sal_Int32 nWidth = 0;
111*cdf0e10cSrcweir 			aAny >>= nWidth;
112*cdf0e10cSrcweir 			GetExport().GetMM100UnitConverter().convertMeasure( sValue,
113*cdf0e10cSrcweir 																nWidth );
114*cdf0e10cSrcweir 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
115*cdf0e10cSrcweir 									  sValue.makeStringAndClear() );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 			// style:color
118*cdf0e10cSrcweir 			aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
119*cdf0e10cSrcweir 			sal_Int32 nColor = 0;
120*cdf0e10cSrcweir 			aAny >>= nColor;
121*cdf0e10cSrcweir 			GetExport().GetMM100UnitConverter().convertColor( sValue,
122*cdf0e10cSrcweir 															  nColor );
123*cdf0e10cSrcweir 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
124*cdf0e10cSrcweir 									  sValue.makeStringAndClear() );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 			// style:height
127*cdf0e10cSrcweir 			aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
128*cdf0e10cSrcweir 			sal_Int8 nHeight = 0;
129*cdf0e10cSrcweir 			aAny >>= nHeight;
130*cdf0e10cSrcweir 			GetExport().GetMM100UnitConverter().convertPercent( sValue,
131*cdf0e10cSrcweir 																nHeight );
132*cdf0e10cSrcweir 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
133*cdf0e10cSrcweir 									  sValue.makeStringAndClear() );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 			// style:vertical-align
136*cdf0e10cSrcweir 			aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
137*cdf0e10cSrcweir 			VerticalAlignment eVertAlign;
138*cdf0e10cSrcweir 			aAny >>= eVertAlign;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 			enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
141*cdf0e10cSrcweir 			switch( eVertAlign )
142*cdf0e10cSrcweir 			{
143*cdf0e10cSrcweir //			case VerticalAlignment_TOP: eStr = XML_TOP;
144*cdf0e10cSrcweir 			case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
145*cdf0e10cSrcweir 			case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
146*cdf0e10cSrcweir 			default:
147*cdf0e10cSrcweir 				break;
148*cdf0e10cSrcweir 			}
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 			if( eStr != XML_TOKEN_INVALID)
151*cdf0e10cSrcweir 				GetExport().AddAttribute( XML_NAMESPACE_STYLE,
152*cdf0e10cSrcweir                                           XML_VERTICAL_ALIGN, eStr );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 			// style:column-sep
155*cdf0e10cSrcweir 			SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
156*cdf0e10cSrcweir 									  XML_COLUMN_SEP,
157*cdf0e10cSrcweir 									  sal_True, sal_True );
158*cdf0e10cSrcweir 		}
159*cdf0e10cSrcweir 	}
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	while( nCount-- )
162*cdf0e10cSrcweir 	{
163*cdf0e10cSrcweir 		// style:rel-width
164*cdf0e10cSrcweir 		GetExport().GetMM100UnitConverter().convertNumber( sValue,
165*cdf0e10cSrcweir 													   pColumns->Width );
166*cdf0e10cSrcweir 		sValue.append( (sal_Unicode)'*' );
167*cdf0e10cSrcweir 		GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
168*cdf0e10cSrcweir 								  sValue.makeStringAndClear() );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 		// fo:margin-left
171*cdf0e10cSrcweir 		GetExport().GetMM100UnitConverter().convertMeasure( sValue,
172*cdf0e10cSrcweir 													   pColumns->LeftMargin );
173*cdf0e10cSrcweir 		GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
174*cdf0e10cSrcweir 			   				  	  sValue.makeStringAndClear() );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 		// fo:margin-right
177*cdf0e10cSrcweir 		GetExport().GetMM100UnitConverter().convertMeasure( sValue,
178*cdf0e10cSrcweir 													   pColumns->RightMargin );
179*cdf0e10cSrcweir 		GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
180*cdf0e10cSrcweir 				  				  sValue.makeStringAndClear() );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		// style:column
183*cdf0e10cSrcweir 		SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
184*cdf0e10cSrcweir 								  sal_True, sal_True );
185*cdf0e10cSrcweir 		pColumns++;
186*cdf0e10cSrcweir 	}
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 
190