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 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
31cdf0e10cSrcweir #include "xmloff/VisAreaContext.hxx"
32cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
33cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
34cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
35cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
36cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
37cdf0e10cSrcweir #include <tools/gen.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace com::sun::star;
40cdf0e10cSrcweir using namespace ::xmloff::token;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //------------------------------------------------------------------
43cdf0e10cSrcweir 
XMLVisAreaContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,Rectangle & rRect,const MapUnit aMapUnit)44cdf0e10cSrcweir XMLVisAreaContext::XMLVisAreaContext( SvXMLImport& rImport,
45cdf0e10cSrcweir 											  sal_uInt16 nPrfx,
46cdf0e10cSrcweir 				   	  						  const rtl::OUString& rLName,
47cdf0e10cSrcweir 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
48cdf0e10cSrcweir 									  		Rectangle& rRect, const MapUnit aMapUnit ) :
49cdf0e10cSrcweir 	SvXMLImportContext( rImport, nPrfx, rLName )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	awt::Rectangle rAwtRect( rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight() );
52cdf0e10cSrcweir 	process( xAttrList, rAwtRect, (sal_Int16)aMapUnit );
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	rRect.setX( rAwtRect.X );
55cdf0e10cSrcweir 	rRect.setY( rAwtRect.Y );
56cdf0e10cSrcweir 	rRect.setWidth( rAwtRect.Width );
57cdf0e10cSrcweir 	rRect.setHeight( rAwtRect.Height );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
XMLVisAreaContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,::com::sun::star::awt::Rectangle & rRect,const sal_Int16 nMeasureUnit)60cdf0e10cSrcweir XMLVisAreaContext::XMLVisAreaContext( SvXMLImport& rImport,
61cdf0e10cSrcweir 										 sal_uInt16 nPrfx,
62cdf0e10cSrcweir 				   	  						  const rtl::OUString& rLName,
63cdf0e10cSrcweir 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
64cdf0e10cSrcweir 											::com::sun::star::awt::Rectangle& rRect, const sal_Int16 nMeasureUnit ) :
65cdf0e10cSrcweir 	SvXMLImportContext( rImport, nPrfx, rLName )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	process( xAttrList, rRect, nMeasureUnit );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
~XMLVisAreaContext()70cdf0e10cSrcweir XMLVisAreaContext::~XMLVisAreaContext()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
process(const uno::Reference<xml::sax::XAttributeList> & xAttrList,awt::Rectangle & rRect,const sal_Int16 nMeasureUnit)74cdf0e10cSrcweir void XMLVisAreaContext::process( const uno::Reference< xml::sax::XAttributeList>& xAttrList, awt::Rectangle& rRect, const sal_Int16 nMeasureUnit )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	MapUnit aMapUnit = (MapUnit)nMeasureUnit;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	sal_Int32 nX(0);
79cdf0e10cSrcweir 	sal_Int32 nY(0);
80cdf0e10cSrcweir 	sal_Int32 nWidth(0);
81cdf0e10cSrcweir 	sal_Int32 nHeight(0);
82cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
83cdf0e10cSrcweir 	for( sal_Int16 i=0; i < nAttrCount; i++ )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
86cdf0e10cSrcweir 		rtl::OUString aLocalName;
87cdf0e10cSrcweir 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
88cdf0e10cSrcweir 											sAttrName, &aLocalName );
89cdf0e10cSrcweir 		rtl::OUString sValue = xAttrList->getValueByIndex( i );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		if (nPrefix == XML_NAMESPACE_OFFICE)
92cdf0e10cSrcweir 		{
93cdf0e10cSrcweir 			if (IsXMLToken( aLocalName, XML_X ))
94cdf0e10cSrcweir 			{
95cdf0e10cSrcweir 				SvXMLUnitConverter::convertMeasure(nX, sValue, aMapUnit);
96cdf0e10cSrcweir 				rRect.X = nX;
97cdf0e10cSrcweir 			}
98cdf0e10cSrcweir 			else if (IsXMLToken( aLocalName, XML_Y ))
99cdf0e10cSrcweir 			{
100cdf0e10cSrcweir 				SvXMLUnitConverter::convertMeasure(nY, sValue, aMapUnit);
101cdf0e10cSrcweir 				rRect.Y = nY;
102cdf0e10cSrcweir 			}
103cdf0e10cSrcweir 			else if (IsXMLToken( aLocalName, XML_WIDTH ))
104cdf0e10cSrcweir 			{
105cdf0e10cSrcweir 				SvXMLUnitConverter::convertMeasure(nWidth, sValue, aMapUnit);
106cdf0e10cSrcweir 				rRect.Width = nWidth;
107cdf0e10cSrcweir 			}
108cdf0e10cSrcweir 			else if (IsXMLToken( aLocalName, XML_HEIGHT ))
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				SvXMLUnitConverter::convertMeasure(nHeight, sValue, aMapUnit);
111cdf0e10cSrcweir 				rRect.Height = nHeight;
112cdf0e10cSrcweir 			}
113cdf0e10cSrcweir 		}
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)117cdf0e10cSrcweir SvXMLImportContext *XMLVisAreaContext::CreateChildContext( sal_uInt16 nPrefix,
118cdf0e10cSrcweir 									 const rtl::OUString& rLocalName,
119cdf0e10cSrcweir 									 const ::com::sun::star::uno::Reference<
120cdf0e10cSrcweir 									  	::com::sun::star::xml::sax::XAttributeList>& )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	// here is no context
123cdf0e10cSrcweir 	SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	return pContext;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
EndElement()128cdf0e10cSrcweir void XMLVisAreaContext::EndElement()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir }
131