xref: /aoo41x/main/xmloff/source/style/xmltabe.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 #include <tools/debug.hxx>
32 #include <com/sun/star/style/TabStop.hpp>
33 #include <com/sun/star/style/TabAlign.hpp>
34 #include <rtl/ustrbuf.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include "xmloff/xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #include <xmloff/xmlexp.hxx>
40 #include "xmloff/xmltabe.hxx"
41 
42 using ::rtl::OUString;
43 using ::rtl::OUStringBuffer;
44 
45 using namespace ::com::sun::star;
46 using namespace ::xmloff::token;
47 
48 SvXMLEnumMapEntry pXML_tabstop_style[] =
49 {
50 	{ XML_LEFT,     style::TabAlign_LEFT	},
51 	{ XML_CENTER,   style::TabAlign_CENTER	},
52 	{ XML_RIGHT,    style::TabAlign_RIGHT	},
53 	{ XML_CHAR,     style::TabAlign_DECIMAL	},
54 	{ XML_DEFAULT,  style::TabAlign_DEFAULT  },	// ?????????????????????????????????????
55 	{ XML_TOKEN_INVALID,        0 }
56 };
57 
58 void SvxXMLTabStopExport::exportTabStop( const ::com::sun::star::style::TabStop* pTabStop )
59 {
60     SvXMLUnitConverter& rUnitConv = rExport.GetMM100UnitConverter();
61 
62 	// text:level
63 	OUStringBuffer sBuffer;
64 
65 	// position attribute
66 	rUnitConv.convertMeasure( sBuffer, pTabStop->Position );
67 	rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_POSITION,
68                            sBuffer.makeStringAndClear() );
69 
70 	// type attribute
71 	if( style::TabAlign_LEFT != pTabStop->Alignment )
72 	{
73 		rUnitConv.convertEnum( sBuffer, pTabStop->Alignment,
74 								   pXML_tabstop_style );
75 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_TYPE,
76                                sBuffer.makeStringAndClear() );
77 	}
78 
79 	// char
80 	if( style::TabAlign_DECIMAL == pTabStop->Alignment &&
81 		pTabStop->DecimalChar != 0 )
82 	{
83 		sBuffer.append( pTabStop->DecimalChar );
84 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_CHAR,
85                                sBuffer.makeStringAndClear() );
86 	}
87 
88 	// leader-char
89 	if( ' ' != pTabStop->FillChar && 0 != pTabStop->FillChar )
90 	{
91 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEADER_STYLE,
92 					  GetXMLToken('.' == pTabStop->FillChar ? XML_DOTTED
93 							   							    : XML_SOLID) );
94 
95 		sBuffer.append( pTabStop->FillChar );
96 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEADER_TEXT,
97                                sBuffer.makeStringAndClear() );
98 	}
99 
100     SvXMLElementExport rElem( rExport, XML_NAMESPACE_STYLE, XML_TAB_STOP,
101                               sal_True, sal_True );
102 }
103 
104 
105 SvxXMLTabStopExport::SvxXMLTabStopExport(
106     SvXMLExport& rExp)
107     : rExport( rExp )
108 {
109 }
110 
111 SvxXMLTabStopExport::~SvxXMLTabStopExport()
112 {
113 }
114 
115 void SvxXMLTabStopExport::Export( const uno::Any& rAny )
116 {
117 	uno::Sequence< ::com::sun::star::style::TabStop> aSeq;
118 	if(!(rAny >>= aSeq))
119 	{
120 		DBG_ERROR( "SvxXMLTabStopExport needs a Sequence ::com::sun::star::style::TabStop>" );
121 	}
122 	else
123 	{
124 		const ::com::sun::star::style::TabStop* pTabs = aSeq.getConstArray();
125 		const sal_Int32 nTabs   = aSeq.getLength();
126 
127 		// ignore default tab stop here
128 		//if( 1 == nTabs && style::TabAlign_DEFAULT == pTabs[0].Alignment )
129 		//	return;
130 
131         SvXMLElementExport rElem( rExport, XML_NAMESPACE_STYLE, XML_TAB_STOPS,
132                                   sal_True, sal_True );
133 
134 		for( sal_Int32 nIndex = 0; nIndex < nTabs; nIndex++ )
135 		{
136 			if( style::TabAlign_DEFAULT != pTabs[nIndex].Alignment )
137 				exportTabStop( &(pTabs[nIndex]) );
138 		}
139 	}
140 }
141 
142 
143