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