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