Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <xmloff/xmluconv.hxx>
21 : #include <rtl/ustrbuf.hxx>
22 : #include <com/sun/star/uno/Any.hxx>
23 :
24 : #include <com/sun/star/awt/Rectangle.hpp>
25 : #include "XMLRectangleMembersHandler.hxx"
26 : #include <xmloff/xmltypes.hxx>
27 :
28 : using namespace ::com::sun::star;
29 : using namespace ::com::sun::star::uno;
30 : using ::rtl::OUString;
31 : using ::rtl::OUStringBuffer;
32 :
33 :
34 436 : XMLRectangleMembersHdl::XMLRectangleMembersHdl( sal_Int32 nType )
35 436 : : mnType( nType )
36 : {
37 436 : }
38 :
39 872 : XMLRectangleMembersHdl::~XMLRectangleMembersHdl()
40 : {
41 872 : }
42 :
43 0 : sal_Bool XMLRectangleMembersHdl::importXML(
44 : const OUString& rStrImpValue,
45 : Any& rValue,
46 : const SvXMLUnitConverter& rUnitConverter ) const
47 : {
48 0 : awt::Rectangle aRect( 0, 0, 0, 0 );
49 0 : if( rValue.hasValue() )
50 0 : rValue >>= aRect;
51 :
52 : sal_Int32 nValue;
53 :
54 0 : if (rUnitConverter.convertMeasureToCore( nValue, rStrImpValue ))
55 : {
56 0 : switch( mnType )
57 : {
58 : case XML_TYPE_RECTANGLE_LEFT :
59 0 : aRect.X = nValue;
60 0 : break;
61 : case XML_TYPE_RECTANGLE_TOP :
62 0 : aRect.Y = nValue;
63 0 : break;
64 : case XML_TYPE_RECTANGLE_WIDTH :
65 0 : aRect.Width = nValue;
66 0 : break;
67 : case XML_TYPE_RECTANGLE_HEIGHT :
68 0 : aRect.Height = nValue;
69 0 : break;
70 : }
71 :
72 0 : rValue <<= aRect;
73 0 : return sal_True;
74 : }
75 :
76 0 : return sal_False;
77 : }
78 :
79 0 : sal_Bool XMLRectangleMembersHdl::exportXML(
80 : OUString& rStrExpValue,
81 : const Any& rValue,
82 : const SvXMLUnitConverter& rUnitConverter ) const
83 : {
84 0 : awt::Rectangle aRect( 0, 0, 0, 0 );
85 0 : rValue >>= aRect;
86 :
87 : sal_Int32 nValue;
88 :
89 0 : switch( mnType )
90 : {
91 : case XML_TYPE_RECTANGLE_LEFT :
92 0 : nValue = aRect.X;
93 0 : break;
94 : case XML_TYPE_RECTANGLE_TOP :
95 0 : nValue = aRect.Y;
96 0 : break;
97 : case XML_TYPE_RECTANGLE_WIDTH :
98 0 : nValue = aRect.Width;
99 0 : break;
100 : case XML_TYPE_RECTANGLE_HEIGHT :
101 0 : nValue = aRect.Height;
102 0 : break;
103 : default:
104 0 : nValue = 0; // TODO What value should this be?
105 0 : break;
106 : }
107 :
108 0 : rtl::OUStringBuffer sBuffer;
109 0 : rUnitConverter.convertMeasureToXML( sBuffer, nValue );
110 0 : rStrExpValue = sBuffer.makeStringAndClear();
111 0 : return sal_True;
112 : }
113 :
114 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|