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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <xmloff/xmluconv.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 
30 #ifndef _COM_SUN_STAR_AWT_RECTANGLE_HDL_
31 #include <com/sun/star/awt/Rectangle.hdl>
32 #endif
33 #include "XMLRectangleMembersHandler.hxx"
34 #include <xmloff/xmltypes.hxx>
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 
41 
XMLRectangleMembersHdl(sal_Int32 nType)42 XMLRectangleMembersHdl::XMLRectangleMembersHdl( sal_Int32 nType )
43 : mnType( nType )
44 {
45 }
46 
~XMLRectangleMembersHdl()47 XMLRectangleMembersHdl::~XMLRectangleMembersHdl()
48 {
49 }
50 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter & rUnitConverter) const51 sal_Bool XMLRectangleMembersHdl::importXML(
52 	const OUString& rStrImpValue,
53 	Any& rValue,
54 	const SvXMLUnitConverter& rUnitConverter ) const
55 {
56 	awt::Rectangle aRect( 0, 0, 0, 0 );
57 	if( rValue.hasValue() )
58 		rValue >>= aRect;
59 
60 	sal_Int32 nValue;
61 
62 	if( rUnitConverter.convertMeasure( nValue, rStrImpValue ) )
63 	{
64 		switch( mnType )
65 		{
66 			case XML_TYPE_RECTANGLE_LEFT :
67 				aRect.X = nValue;
68 				break;
69 			case XML_TYPE_RECTANGLE_TOP :
70 				aRect.Y = nValue;
71 				break;
72 			case XML_TYPE_RECTANGLE_WIDTH :
73 				aRect.Width = nValue;
74 				break;
75 			case XML_TYPE_RECTANGLE_HEIGHT :
76 				aRect.Height = nValue;
77 				break;
78 		}
79 
80 		rValue <<= aRect;
81 		return sal_True;
82 	}
83 
84 	return sal_False;
85 }
86 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const87 sal_Bool XMLRectangleMembersHdl::exportXML(
88 	OUString& rStrExpValue,
89 	const Any& rValue,
90 	const SvXMLUnitConverter& rUnitConverter ) const
91 {
92 	awt::Rectangle aRect( 0, 0, 0, 0 );
93 	rValue >>= aRect;
94 
95 	sal_Int32 nValue;
96 
97 	switch( mnType )
98 	{
99 		case XML_TYPE_RECTANGLE_LEFT :
100 			nValue = aRect.X;
101 			break;
102 		case XML_TYPE_RECTANGLE_TOP :
103 			nValue = aRect.Y;
104 			break;
105 		case XML_TYPE_RECTANGLE_WIDTH :
106 			nValue = aRect.Width;
107 			break;
108 		case XML_TYPE_RECTANGLE_HEIGHT :
109 			nValue = aRect.Height;
110 			break;
111 		default:
112 			nValue = 0;  // TODO What value should this be?
113 			break;
114 	}
115 
116 	rtl::OUStringBuffer sBuffer;
117 	rUnitConverter.convertMeasure( sBuffer, nValue );
118 	rStrExpValue = sBuffer.makeStringAndClear();
119 	return sal_True;
120 }
121 
122