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