xref: /trunk/main/xmloff/source/text/XMLTextColumnsContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <com/sun/star/text/XTextColumns.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/text/TextColumn.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
35*cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
36*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
37*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
38*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
39*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
40*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
41*cdf0e10cSrcweir #include "XMLTextColumnsContext.hxx"
42*cdf0e10cSrcweir #define _SVSTDARR_USHORTS
43*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir using ::rtl::OUString;
46*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace ::com::sun::star;
49*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
51*cdf0e10cSrcweir using namespace ::com::sun::star::text;
52*cdf0e10cSrcweir using namespace ::com::sun::star::style;
53*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
54*cdf0e10cSrcweir using namespace ::xmloff::token;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir enum SvXMLTokenMapAttrs
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir     XML_TOK_COLUMN_WIDTH,
59*cdf0e10cSrcweir     XML_TOK_COLUMN_MARGIN_LEFT,
60*cdf0e10cSrcweir     XML_TOK_COLUMN_MARGIN_RIGHT,
61*cdf0e10cSrcweir     XML_TOK_COLUMN_END=XML_TOK_UNKNOWN
62*cdf0e10cSrcweir };
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir enum SvXMLSepTokenMapAttrs
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir     XML_TOK_COLUMN_SEP_WIDTH,
67*cdf0e10cSrcweir     XML_TOK_COLUMN_SEP_HEIGHT,
68*cdf0e10cSrcweir     XML_TOK_COLUMN_SEP_COLOR,
69*cdf0e10cSrcweir     XML_TOK_COLUMN_SEP_ALIGN,
70*cdf0e10cSrcweir     XML_TOK_COLUMN_SEP_END=XML_TOK_UNKNOWN
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aColAttrTokenMap[] =
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_REL_WIDTH,      XML_TOK_COLUMN_WIDTH },
76*cdf0e10cSrcweir     { XML_NAMESPACE_FO,     XML_START_INDENT,   XML_TOK_COLUMN_MARGIN_LEFT },
77*cdf0e10cSrcweir     { XML_NAMESPACE_FO,     XML_END_INDENT,     XML_TOK_COLUMN_MARGIN_RIGHT },
78*cdf0e10cSrcweir     XML_TOKEN_MAP_END
79*cdf0e10cSrcweir };
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aColSepAttrTokenMap[] =
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_WIDTH,          XML_TOK_COLUMN_SEP_WIDTH },
84*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_COLOR,          XML_TOK_COLUMN_SEP_COLOR },
85*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_HEIGHT,         XML_TOK_COLUMN_SEP_HEIGHT },
86*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_VERTICAL_ALIGN, XML_TOK_COLUMN_SEP_ALIGN },
87*cdf0e10cSrcweir     XML_TOKEN_MAP_END
88*cdf0e10cSrcweir };
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir SvXMLEnumMapEntry __READONLY_DATA pXML_Sep_Align_Enum[] =
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     { XML_TOP,          VerticalAlignment_TOP   },
93*cdf0e10cSrcweir     { XML_MIDDLE,       VerticalAlignment_MIDDLE },
94*cdf0e10cSrcweir     { XML_BOTTOM,       VerticalAlignment_BOTTOM },
95*cdf0e10cSrcweir     { XML_TOKEN_INVALID, 0 }
96*cdf0e10cSrcweir };
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir class XMLTextColumnContext_Impl: public SvXMLImportContext
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     text::TextColumn aColumn;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir public:
103*cdf0e10cSrcweir     TYPEINFO();
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     XMLTextColumnContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
106*cdf0e10cSrcweir                                const OUString& rLName,
107*cdf0e10cSrcweir                                const uno::Reference<
108*cdf0e10cSrcweir                                     xml::sax::XAttributeList > & xAttrList,
109*cdf0e10cSrcweir                                const SvXMLTokenMap& rTokenMap );
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     virtual ~XMLTextColumnContext_Impl();
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     text::TextColumn& getTextColumn() { return aColumn; }
114*cdf0e10cSrcweir };
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir TYPEINIT1( XMLTextColumnContext_Impl, SvXMLImportContext );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir XMLTextColumnContext_Impl::XMLTextColumnContext_Impl(
119*cdf0e10cSrcweir                                SvXMLImport& rImport, sal_uInt16 nPrfx,
120*cdf0e10cSrcweir                                const OUString& rLName,
121*cdf0e10cSrcweir                                const uno::Reference<
122*cdf0e10cSrcweir                                     xml::sax::XAttributeList > & xAttrList,
123*cdf0e10cSrcweir                                const SvXMLTokenMap& rTokenMap ) :
124*cdf0e10cSrcweir     SvXMLImportContext( rImport, nPrfx, rLName )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     aColumn.Width = 0;
127*cdf0e10cSrcweir     aColumn.LeftMargin = 0;
128*cdf0e10cSrcweir     aColumn.RightMargin = 0;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
131*cdf0e10cSrcweir     for( sal_Int16 i=0; i < nAttrCount; i++ )
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         const OUString& rAttrName = xAttrList->getNameByIndex( i );
134*cdf0e10cSrcweir         OUString aLocalName;
135*cdf0e10cSrcweir         sal_uInt16 nPrefix =
136*cdf0e10cSrcweir             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
137*cdf0e10cSrcweir                                                             &aLocalName );
138*cdf0e10cSrcweir         const OUString& rValue = xAttrList->getValueByIndex( i );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         sal_Int32 nVal;
141*cdf0e10cSrcweir         switch( rTokenMap.Get( nPrefix, aLocalName ) )
142*cdf0e10cSrcweir         {
143*cdf0e10cSrcweir         case XML_TOK_COLUMN_WIDTH:
144*cdf0e10cSrcweir             {
145*cdf0e10cSrcweir                 sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'*' );
146*cdf0e10cSrcweir                 if( nPos != -1 && nPos+1 == rValue.getLength() )
147*cdf0e10cSrcweir                 {
148*cdf0e10cSrcweir                     OUString sTmp( rValue.copy( 0, nPos ) );
149*cdf0e10cSrcweir                     if( GetImport().GetMM100UnitConverter().
150*cdf0e10cSrcweir                                         convertNumber( nVal, sTmp, 0, USHRT_MAX ) )
151*cdf0e10cSrcweir                     aColumn.Width = nVal;
152*cdf0e10cSrcweir                 }
153*cdf0e10cSrcweir             }
154*cdf0e10cSrcweir             break;
155*cdf0e10cSrcweir         case XML_TOK_COLUMN_MARGIN_LEFT:
156*cdf0e10cSrcweir             if( GetImport().GetMM100UnitConverter().
157*cdf0e10cSrcweir                                         convertMeasure( nVal, rValue ) )
158*cdf0e10cSrcweir                 aColumn.LeftMargin = nVal;
159*cdf0e10cSrcweir             break;
160*cdf0e10cSrcweir         case XML_TOK_COLUMN_MARGIN_RIGHT:
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir             if( GetImport().GetMM100UnitConverter().
163*cdf0e10cSrcweir                                         convertMeasure( nVal, rValue ) )
164*cdf0e10cSrcweir                 aColumn.RightMargin = nVal;
165*cdf0e10cSrcweir             break;
166*cdf0e10cSrcweir         default:
167*cdf0e10cSrcweir             break;
168*cdf0e10cSrcweir         }
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir XMLTextColumnContext_Impl::~XMLTextColumnContext_Impl()
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir // --------------------------------------------------------------------------
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir class XMLTextColumnSepContext_Impl: public SvXMLImportContext
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     sal_Int32 nWidth;
181*cdf0e10cSrcweir     sal_Int32 nColor;
182*cdf0e10cSrcweir     sal_Int8 nHeight;
183*cdf0e10cSrcweir     VerticalAlignment eVertAlign;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir public:
187*cdf0e10cSrcweir     TYPEINFO();
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     XMLTextColumnSepContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
190*cdf0e10cSrcweir                                const OUString& rLName,
191*cdf0e10cSrcweir                                const uno::Reference<
192*cdf0e10cSrcweir                                     xml::sax::XAttributeList > & xAttrList,
193*cdf0e10cSrcweir                                const SvXMLTokenMap& rTokenMap );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     virtual ~XMLTextColumnSepContext_Impl();
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     sal_Int32 GetWidth() const { return nWidth; }
198*cdf0e10cSrcweir     sal_Int32 GetColor() const { return  nColor; }
199*cdf0e10cSrcweir     sal_Int8 GetHeight() const { return nHeight; }
200*cdf0e10cSrcweir     VerticalAlignment GetVertAlign() const { return eVertAlign; }
201*cdf0e10cSrcweir };
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir TYPEINIT1( XMLTextColumnSepContext_Impl, SvXMLImportContext );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir XMLTextColumnSepContext_Impl::XMLTextColumnSepContext_Impl(
207*cdf0e10cSrcweir                                SvXMLImport& rImport, sal_uInt16 nPrfx,
208*cdf0e10cSrcweir                                const OUString& rLName,
209*cdf0e10cSrcweir                                const uno::Reference<
210*cdf0e10cSrcweir                                     xml::sax::XAttributeList > & xAttrList,
211*cdf0e10cSrcweir                                const SvXMLTokenMap& rTokenMap ) :
212*cdf0e10cSrcweir     SvXMLImportContext( rImport, nPrfx, rLName ),
213*cdf0e10cSrcweir     nWidth( 2 ),
214*cdf0e10cSrcweir     nColor( 0 ),
215*cdf0e10cSrcweir     nHeight( 100 ),
216*cdf0e10cSrcweir     eVertAlign( VerticalAlignment_TOP )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
219*cdf0e10cSrcweir     for( sal_Int16 i=0; i < nAttrCount; i++ )
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir         const OUString& rAttrName = xAttrList->getNameByIndex( i );
222*cdf0e10cSrcweir         OUString aLocalName;
223*cdf0e10cSrcweir         sal_uInt16 nPrefix =
224*cdf0e10cSrcweir             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
225*cdf0e10cSrcweir                                                             &aLocalName );
226*cdf0e10cSrcweir         const OUString& rValue = xAttrList->getValueByIndex( i );
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         sal_Int32 nVal;
229*cdf0e10cSrcweir         switch( rTokenMap.Get( nPrefix, aLocalName ) )
230*cdf0e10cSrcweir         {
231*cdf0e10cSrcweir         case XML_TOK_COLUMN_SEP_WIDTH:
232*cdf0e10cSrcweir             if( GetImport().GetMM100UnitConverter().
233*cdf0e10cSrcweir                                 convertMeasure( nVal, rValue ) )
234*cdf0e10cSrcweir                 nWidth = nVal;
235*cdf0e10cSrcweir             break;
236*cdf0e10cSrcweir         case XML_TOK_COLUMN_SEP_HEIGHT:
237*cdf0e10cSrcweir             if( GetImport().GetMM100UnitConverter().
238*cdf0e10cSrcweir                                         convertPercent( nVal, rValue ) &&
239*cdf0e10cSrcweir                 nVal >=1 && nVal <= 100 )
240*cdf0e10cSrcweir                 nHeight = (sal_Int8)nVal;
241*cdf0e10cSrcweir             break;
242*cdf0e10cSrcweir         case XML_TOK_COLUMN_SEP_COLOR:
243*cdf0e10cSrcweir             {
244*cdf0e10cSrcweir                 Color aColor;
245*cdf0e10cSrcweir                 if( GetImport().GetMM100UnitConverter().
246*cdf0e10cSrcweir                                             convertColor( aColor, rValue ) )
247*cdf0e10cSrcweir                     nColor = (sal_Int32)aColor.GetColor();
248*cdf0e10cSrcweir             }
249*cdf0e10cSrcweir             break;
250*cdf0e10cSrcweir         case XML_TOK_COLUMN_SEP_ALIGN:
251*cdf0e10cSrcweir             {
252*cdf0e10cSrcweir                 sal_uInt16 nAlign;
253*cdf0e10cSrcweir                 if( GetImport().GetMM100UnitConverter().
254*cdf0e10cSrcweir                                         convertEnum( nAlign, rValue,
255*cdf0e10cSrcweir                                                      pXML_Sep_Align_Enum ) )
256*cdf0e10cSrcweir                     eVertAlign = (VerticalAlignment)nAlign;
257*cdf0e10cSrcweir             }
258*cdf0e10cSrcweir             break;
259*cdf0e10cSrcweir         }
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir XMLTextColumnSepContext_Impl::~XMLTextColumnSepContext_Impl()
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir // --------------------------------------------------------------------------
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir typedef XMLTextColumnContext_Impl *XMLTextColumnContext_ImplPtr;
270*cdf0e10cSrcweir SV_DECL_PTRARR( XMLTextColumnsArray_Impl, XMLTextColumnContext_ImplPtr, 5, 5 )
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir TYPEINIT1( XMLTextColumnsContext, XMLElementPropertyContext );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir XMLTextColumnsContext::XMLTextColumnsContext(
275*cdf0e10cSrcweir                                 SvXMLImport& rImport, sal_uInt16 nPrfx,
276*cdf0e10cSrcweir                                 const OUString& rLName,
277*cdf0e10cSrcweir                                 const Reference< xml::sax::XAttributeList >&
278*cdf0e10cSrcweir                                     xAttrList,
279*cdf0e10cSrcweir                                 const XMLPropertyState& rProp,
280*cdf0e10cSrcweir                                 ::std::vector< XMLPropertyState > &rProps )
281*cdf0e10cSrcweir :   XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps )
282*cdf0e10cSrcweir ,   sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn"))
283*cdf0e10cSrcweir ,   sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth"))
284*cdf0e10cSrcweir ,   sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor"))
285*cdf0e10cSrcweir ,   sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight"))
286*cdf0e10cSrcweir ,   sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment"))
287*cdf0e10cSrcweir ,   sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic"))
288*cdf0e10cSrcweir ,   sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance"))
289*cdf0e10cSrcweir ,   pColumns( 0 )
290*cdf0e10cSrcweir ,   pColumnSep( 0 )
291*cdf0e10cSrcweir ,   pColumnAttrTokenMap( new SvXMLTokenMap(aColAttrTokenMap) )
292*cdf0e10cSrcweir ,   pColumnSepAttrTokenMap( new SvXMLTokenMap(aColSepAttrTokenMap) )
293*cdf0e10cSrcweir ,   nCount( 0 )
294*cdf0e10cSrcweir ,   bAutomatic( sal_False )
295*cdf0e10cSrcweir ,   nAutomaticDistance( 0 )
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
298*cdf0e10cSrcweir     sal_Int32 nVal;
299*cdf0e10cSrcweir     for( sal_Int16 i=0; i < nAttrCount; i++ )
300*cdf0e10cSrcweir     {
301*cdf0e10cSrcweir         const OUString& rAttrName = xAttrList->getNameByIndex( i );
302*cdf0e10cSrcweir         OUString aLocalName;
303*cdf0e10cSrcweir         sal_uInt16 nPrefix =
304*cdf0e10cSrcweir             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
305*cdf0e10cSrcweir                                                             &aLocalName );
306*cdf0e10cSrcweir         const OUString& rValue = xAttrList->getValueByIndex( i );
307*cdf0e10cSrcweir         if( XML_NAMESPACE_FO == nPrefix )
308*cdf0e10cSrcweir         {
309*cdf0e10cSrcweir             if( IsXMLToken( aLocalName, XML_COLUMN_COUNT ) &&
310*cdf0e10cSrcweir                 GetImport().GetMM100UnitConverter().
311*cdf0e10cSrcweir                                 convertNumber( nVal, rValue, 0, SHRT_MAX ) )
312*cdf0e10cSrcweir             {
313*cdf0e10cSrcweir                 nCount = (sal_Int16)nVal;
314*cdf0e10cSrcweir             }
315*cdf0e10cSrcweir             else if( IsXMLToken( aLocalName, XML_COLUMN_GAP ) )
316*cdf0e10cSrcweir             {
317*cdf0e10cSrcweir                 bAutomatic = GetImport().GetMM100UnitConverter().
318*cdf0e10cSrcweir                     convertMeasure( nAutomaticDistance, rValue );
319*cdf0e10cSrcweir             }
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir     }
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir XMLTextColumnsContext::~XMLTextColumnsContext()
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir     if( pColumns )
327*cdf0e10cSrcweir     {
328*cdf0e10cSrcweir         sal_uInt16 nColCount = pColumns->Count();
329*cdf0e10cSrcweir         while( nColCount )
330*cdf0e10cSrcweir         {
331*cdf0e10cSrcweir             nColCount--;
332*cdf0e10cSrcweir             XMLTextColumnContext_Impl *pColumn = (*pColumns)[nColCount];
333*cdf0e10cSrcweir             pColumns->Remove( nColCount, 1 );
334*cdf0e10cSrcweir             pColumn->ReleaseRef();
335*cdf0e10cSrcweir         }
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir     if( pColumnSep )
338*cdf0e10cSrcweir         pColumnSep->ReleaseRef();
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     delete pColumns;
341*cdf0e10cSrcweir     delete pColumnAttrTokenMap;
342*cdf0e10cSrcweir     delete pColumnSepAttrTokenMap;
343*cdf0e10cSrcweir }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir SvXMLImportContext *XMLTextColumnsContext::CreateChildContext(
346*cdf0e10cSrcweir     sal_uInt16 nPrefix,
347*cdf0e10cSrcweir     const OUString& rLocalName,
348*cdf0e10cSrcweir     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     if( XML_NAMESPACE_STYLE == nPrefix &&
353*cdf0e10cSrcweir         IsXMLToken( rLocalName, XML_COLUMN ) )
354*cdf0e10cSrcweir     {
355*cdf0e10cSrcweir         XMLTextColumnContext_Impl *pColumn =
356*cdf0e10cSrcweir             new XMLTextColumnContext_Impl( GetImport(), nPrefix, rLocalName,
357*cdf0e10cSrcweir                                            xAttrList, *pColumnAttrTokenMap );
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir         // add new tabstop to array of tabstops
360*cdf0e10cSrcweir         if( !pColumns )
361*cdf0e10cSrcweir             pColumns = new XMLTextColumnsArray_Impl;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir         pColumns->Insert( pColumn, pColumns->Count() );
364*cdf0e10cSrcweir         pColumn->AddRef();
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir         pContext = pColumn;
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir     else if( XML_NAMESPACE_STYLE == nPrefix &&
369*cdf0e10cSrcweir              IsXMLToken( rLocalName, XML_COLUMN_SEP ) )
370*cdf0e10cSrcweir     {
371*cdf0e10cSrcweir         pColumnSep =
372*cdf0e10cSrcweir             new XMLTextColumnSepContext_Impl( GetImport(), nPrefix, rLocalName,
373*cdf0e10cSrcweir                                            xAttrList, *pColumnSepAttrTokenMap );
374*cdf0e10cSrcweir         pColumnSep->AddRef();
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir         pContext = pColumnSep;
377*cdf0e10cSrcweir     }
378*cdf0e10cSrcweir     else
379*cdf0e10cSrcweir     {
380*cdf0e10cSrcweir         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
381*cdf0e10cSrcweir     }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     return pContext;
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir void XMLTextColumnsContext::EndElement( )
387*cdf0e10cSrcweir {
388*cdf0e10cSrcweir     Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
389*cdf0e10cSrcweir     if( !xFactory.is() )
390*cdf0e10cSrcweir         return;
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     Reference<XInterface> xIfc = xFactory->createInstance(
393*cdf0e10cSrcweir         OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextColumns")));
394*cdf0e10cSrcweir     if( !xIfc.is() )
395*cdf0e10cSrcweir         return;
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir     Reference< XTextColumns > xColumns( xIfc, UNO_QUERY );
398*cdf0e10cSrcweir     if ( 0 == nCount )
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         // zero columns = no columns -> 1 column
401*cdf0e10cSrcweir         xColumns->setColumnCount( 1 );
402*cdf0e10cSrcweir     }
403*cdf0e10cSrcweir     else if( !bAutomatic && pColumns &&
404*cdf0e10cSrcweir              pColumns->Count() == (sal_uInt16)nCount )
405*cdf0e10cSrcweir     {
406*cdf0e10cSrcweir         // if we have column descriptions, one per column, and we don't use
407*cdf0e10cSrcweir         // automatic width, then set the column widths
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir         sal_Int32 nRelWidth = 0;
410*cdf0e10cSrcweir         sal_uInt16 nColumnsWithWidth = 0;
411*cdf0e10cSrcweir         sal_Int16 i;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir         for( i = 0; i < nCount; i++ )
414*cdf0e10cSrcweir         {
415*cdf0e10cSrcweir             const TextColumn& rColumn =
416*cdf0e10cSrcweir                 (*pColumns)[(sal_uInt16)i]->getTextColumn();
417*cdf0e10cSrcweir             if( rColumn.Width > 0 )
418*cdf0e10cSrcweir             {
419*cdf0e10cSrcweir                 nRelWidth += rColumn.Width;
420*cdf0e10cSrcweir                 nColumnsWithWidth++;
421*cdf0e10cSrcweir             }
422*cdf0e10cSrcweir         }
423*cdf0e10cSrcweir         if( nColumnsWithWidth < nCount )
424*cdf0e10cSrcweir         {
425*cdf0e10cSrcweir             sal_Int32 nColWidth = 0==nRelWidth
426*cdf0e10cSrcweir                                         ? USHRT_MAX / nCount
427*cdf0e10cSrcweir                                         : nRelWidth / nColumnsWithWidth;
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir             for( i=0; i < nCount; i++ )
430*cdf0e10cSrcweir             {
431*cdf0e10cSrcweir                 TextColumn& rColumn =
432*cdf0e10cSrcweir                     (*pColumns)[(sal_uInt16)i]->getTextColumn();
433*cdf0e10cSrcweir                 if( rColumn.Width == 0 )
434*cdf0e10cSrcweir                 {
435*cdf0e10cSrcweir                     rColumn.Width = nColWidth;
436*cdf0e10cSrcweir                     nRelWidth += rColumn.Width;
437*cdf0e10cSrcweir                     if( 0 == --nColumnsWithWidth )
438*cdf0e10cSrcweir                         break;
439*cdf0e10cSrcweir                 }
440*cdf0e10cSrcweir             }
441*cdf0e10cSrcweir         }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir         Sequence< TextColumn > aColumns( (sal_Int32)nCount );
444*cdf0e10cSrcweir         TextColumn *pTextColumns = aColumns.getArray();
445*cdf0e10cSrcweir         for( i=0; i < nCount; i++ )
446*cdf0e10cSrcweir             *pTextColumns++ = (*pColumns)[(sal_uInt16)i]->getTextColumn();
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         xColumns->setColumns( aColumns );
449*cdf0e10cSrcweir     }
450*cdf0e10cSrcweir     else
451*cdf0e10cSrcweir     {
452*cdf0e10cSrcweir         // only set column count (and let the columns be distributed
453*cdf0e10cSrcweir         // automatically)
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir         xColumns->setColumnCount( nCount );
456*cdf0e10cSrcweir     }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
459*cdf0e10cSrcweir     if( xPropSet.is() )
460*cdf0e10cSrcweir     {
461*cdf0e10cSrcweir         Any aAny;
462*cdf0e10cSrcweir         sal_Bool bOn = pColumnSep != 0;
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir         aAny.setValue( &bOn, ::getBooleanCppuType() );
465*cdf0e10cSrcweir         xPropSet->setPropertyValue( sSeparatorLineIsOn, aAny );
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir         if( pColumnSep )
468*cdf0e10cSrcweir         {
469*cdf0e10cSrcweir             if( pColumnSep->GetWidth() )
470*cdf0e10cSrcweir             {
471*cdf0e10cSrcweir                 aAny <<= pColumnSep->GetWidth();
472*cdf0e10cSrcweir                 xPropSet->setPropertyValue( sSeparatorLineWidth, aAny );
473*cdf0e10cSrcweir             }
474*cdf0e10cSrcweir             if( pColumnSep->GetHeight() )
475*cdf0e10cSrcweir             {
476*cdf0e10cSrcweir                 aAny <<= pColumnSep->GetHeight();
477*cdf0e10cSrcweir                 xPropSet->setPropertyValue( sSeparatorLineRelativeHeight,
478*cdf0e10cSrcweir                                             aAny );
479*cdf0e10cSrcweir             }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir             aAny <<= pColumnSep->GetColor();
483*cdf0e10cSrcweir             xPropSet->setPropertyValue( sSeparatorLineColor, aAny );
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir             aAny <<= pColumnSep->GetVertAlign();
487*cdf0e10cSrcweir             xPropSet->setPropertyValue( sSeparatorLineVerticalAlignment, aAny );
488*cdf0e10cSrcweir         }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir         // handle 'automatic columns': column distance
491*cdf0e10cSrcweir         if( bAutomatic )
492*cdf0e10cSrcweir         {
493*cdf0e10cSrcweir             aAny <<= nAutomaticDistance;
494*cdf0e10cSrcweir             xPropSet->setPropertyValue( sAutomaticDistance, aAny );
495*cdf0e10cSrcweir         }
496*cdf0e10cSrcweir     }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir     aProp.maValue <<= xColumns;
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     SetInsert( sal_True );
501*cdf0e10cSrcweir     XMLElementPropertyContext::EndElement();
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir }
504