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