1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_reportdesign.hxx"
24 
25 #ifndef RPT_XMLCOLUMN_HXX
26 #include "xmlColumn.hxx"
27 #endif
28 #include <xmloff/xmluconv.hxx>
29 #include "xmlfilter.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmlnmspe.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include "xmlEnums.hxx"
34 #include "xmlCell.hxx"
35 #include <tools/debug.hxx>
36 #include "xmlStyleImport.hxx"
37 #include "xmlTable.hxx"
38 #include <comphelper/namecontainer.hxx>
39 #include <comphelper/genericpropertyset.hxx>
40 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HXX_
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #endif
43 #ifndef RPT_SHARED_XMLSTRINGS_HRC
44 #include "xmlstrings.hrc"
45 #endif
46 
47 #define PROPERTY_ID_WIDTH    1
48 #define PROPERTY_ID_HEIGHT   2
49 
50 namespace rptxml
51 {
52     using namespace ::comphelper;
53 	using namespace ::com::sun::star::uno;
54 	using namespace ::com::sun::star::beans;
55 	using namespace ::com::sun::star::xml::sax;
56 
DBG_NAME(rpt_OXMLRowColumn)57 DBG_NAME( rpt_OXMLRowColumn )
58 
59 OXMLRowColumn::OXMLRowColumn( ORptFilter& rImport
60 				,sal_uInt16 nPrfx
61 				,const ::rtl::OUString& _sLocalName
62 				,const Reference< XAttributeList > & _xAttrList
63 				,OXMLTable* _pContainer
64                 ) :
65 	SvXMLImportContext( rImport, nPrfx, _sLocalName )
66 	,m_pContainer(_pContainer)
67 {
68     DBG_CTOR( rpt_OXMLRowColumn,NULL);
69 
70     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
71 	const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
72 
73 	const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
74 	for(sal_Int16 i = 0; i < nLength; ++i)
75 	{
76 	 ::rtl::OUString sLocalName;
77 		const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
78 		const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
79 		const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
80 
81 		switch( rTokenMap.Get( nPrefix, sLocalName ) )
82 		{
83 			case XML_TOK_COLUMN_STYLE_NAME:
84                 fillStyle(sValue);
85 				break;
86             default:
87                 break;
88     	}
89 	}
90 }
91 // -----------------------------------------------------------------------------
92 
~OXMLRowColumn()93 OXMLRowColumn::~OXMLRowColumn()
94 {
95     DBG_DTOR( rpt_OXMLRowColumn,NULL);
96 }
97 // -----------------------------------------------------------------------------
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)98 SvXMLImportContext* OXMLRowColumn::CreateChildContext(
99 		sal_uInt16 nPrefix,
100 		const ::rtl::OUString& rLocalName,
101 		const Reference< XAttributeList > & xAttrList )
102 {
103 	SvXMLImportContext *pContext = 0;
104     ORptFilter& rImport = GetOwnImport();
105 	const SvXMLTokenMap&	rTokenMap	= rImport.GetColumnTokenMap();
106 
107 	switch( rTokenMap.Get( nPrefix, rLocalName ) )
108 	{
109 		case XML_TOK_COLUMN:
110             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
111 			pContext = new OXMLRowColumn( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
112 			break;
113         case XML_TOK_ROW:
114             m_pContainer->incrementRowIndex();
115             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
116 			pContext = new OXMLRowColumn( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
117 			break;
118         case XML_TOK_CELL:
119             m_pContainer->incrementColumnIndex();
120             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
121 			pContext = new OXMLCell( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
122 			break;
123         case XML_TOK_COV_CELL:
124             m_pContainer->incrementColumnIndex();
125             m_pContainer->addCell(NULL);
126 			break;
127         default:
128             break;
129 	}
130 
131 	if( !pContext )
132 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
133 
134 	return pContext;
135 }
136 // -----------------------------------------------------------------------------
fillStyle(const::rtl::OUString & _sStyleName)137 void OXMLRowColumn::fillStyle(const ::rtl::OUString& _sStyleName)
138 {
139 	if ( _sStyleName.getLength() )
140 	{
141         const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
142 		if ( pAutoStyles )
143 		{
144             PropertySetInfo* pInfo = new PropertySetInfo();
145 			static PropertyMapEntry pMap[] =
146 			{
147 				{PROPERTY_WIDTH,		static_cast<sal_uInt16>(PROPERTY_WIDTH.length),		PROPERTY_ID_WIDTH,			&::getCppuType(static_cast< sal_Int32* >( NULL ))		,PropertyAttribute::BOUND,0},
148 				{PROPERTY_HEIGHT,		static_cast<sal_uInt16>(PROPERTY_HEIGHT.length),	PROPERTY_ID_HEIGHT,			&::getCppuType(static_cast< sal_Int32* >( NULL ))		,PropertyAttribute::BOUND,0},
149 				{ NULL, 0, 0, NULL, 0, 0 }
150 			};
151 			pInfo->add(pMap);
152 			Reference<XPropertySet> xProp = GenericPropertySet_CreateInstance(pInfo);
153 			XMLPropStyleContext* pAutoStyle = PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,_sStyleName));
154 			if ( pAutoStyle )
155 			{
156 				pAutoStyle->FillPropertySet(xProp);
157                 sal_Int32 nWidth = 0;
158                 xProp->getPropertyValue(PROPERTY_WIDTH) >>= nWidth;
159                 m_pContainer->addWidth(nWidth);
160 			}
161             else
162             {
163                 pAutoStyle = PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_ROW,_sStyleName));
164 			    if ( pAutoStyle )
165 			    {
166                     pAutoStyle->FillPropertySet(xProp);
167                     sal_Int32 nHeight = 0;
168                     xProp->getPropertyValue(PROPERTY_HEIGHT) >>= nHeight;
169                     m_pContainer->addHeight(nHeight);
170 			    }
171             }
172 		}
173 	}
174 }
175 // -----------------------------------------------------------------------------
GetOwnImport()176 ORptFilter& OXMLRowColumn::GetOwnImport()
177 {
178 	return static_cast<ORptFilter&>(GetImport());
179 }
180 // -----------------------------------------------------------------------------
EndElement()181 void OXMLRowColumn::EndElement()
182 {
183 }
184 //----------------------------------------------------------------------------
185 } // namespace rptxml
186 // -----------------------------------------------------------------------------
187