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 :
21 : #include <svl/ptitem.hxx>
22 : #include <com/sun/star/uno/Any.hxx>
23 : #include <com/sun/star/awt/Point.hpp>
24 : #include <tools/stream.hxx>
25 :
26 : #include <svl/poolitem.hxx>
27 : #include <svl/memberid.hrc>
28 :
29 : using namespace ::com::sun::star;
30 :
31 : #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
32 : #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
33 :
34 :
35 :
36 1754 : TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem);
37 :
38 :
39 :
40 115 : SfxPointItem::SfxPointItem()
41 : {
42 115 : }
43 :
44 :
45 :
46 513 : SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) :
47 : SfxPoolItem( nW ),
48 513 : aVal( rVal )
49 : {
50 513 : }
51 :
52 :
53 :
54 383 : SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) :
55 : SfxPoolItem( rItem ),
56 383 : aVal( rItem.aVal )
57 : {
58 383 : }
59 :
60 :
61 :
62 0 : SfxItemPresentation SfxPointItem::GetPresentation
63 : (
64 : SfxItemPresentation /*ePresentation*/,
65 : SfxMapUnit /*eCoreMetric*/,
66 : SfxMapUnit /*ePresentationMetric*/,
67 : OUString& rText,
68 : const IntlWrapper *
69 : ) const
70 : {
71 0 : rText = OUString::number(aVal.X()) + ", " + OUString::number(aVal.Y()) + ", ";
72 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
73 : }
74 :
75 :
76 :
77 28 : bool SfxPointItem::operator==( const SfxPoolItem& rItem ) const
78 : {
79 : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
80 28 : return ((SfxPointItem&)rItem).aVal == aVal;
81 : }
82 :
83 :
84 :
85 383 : SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const
86 : {
87 383 : return new SfxPointItem( *this );
88 : }
89 :
90 :
91 :
92 0 : SfxPoolItem* SfxPointItem::Create(SvStream &rStream, sal_uInt16 ) const
93 : {
94 0 : Point aStr;
95 0 : ReadPair( rStream, aStr );
96 0 : return new SfxPointItem(Which(), aStr);
97 : }
98 :
99 :
100 :
101 0 : SvStream& SfxPointItem::Store(SvStream &rStream, sal_uInt16 ) const
102 : {
103 0 : WritePair( rStream, aVal );
104 0 : return rStream;
105 : }
106 :
107 :
108 :
109 115 : bool SfxPointItem::QueryValue( uno::Any& rVal,
110 : sal_uInt8 nMemberId ) const
111 : {
112 115 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
113 115 : awt::Point aTmp(aVal.X(), aVal.Y());
114 115 : if( bConvert )
115 : {
116 0 : aTmp.X = TWIP_TO_MM100(aTmp.X);
117 0 : aTmp.Y = TWIP_TO_MM100(aTmp.Y);
118 : }
119 115 : nMemberId &= ~CONVERT_TWIPS;
120 115 : switch ( nMemberId )
121 : {
122 115 : case 0: rVal <<= aTmp; break;
123 0 : case MID_X: rVal <<= aTmp.X; break;
124 0 : case MID_Y: rVal <<= aTmp.Y; break;
125 0 : default: OSL_FAIL("Wrong MemberId!"); return true;
126 : }
127 :
128 115 : return true;
129 : }
130 :
131 :
132 :
133 115 : bool SfxPointItem::PutValue( const uno::Any& rVal,
134 : sal_uInt8 nMemberId )
135 : {
136 115 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
137 115 : nMemberId &= ~CONVERT_TWIPS;
138 115 : bool bRet = false;
139 115 : awt::Point aValue;
140 115 : sal_Int32 nVal = 0;
141 115 : if ( !nMemberId )
142 : {
143 115 : bRet = ( rVal >>= aValue );
144 115 : if( bConvert )
145 : {
146 0 : aValue.X = MM100_TO_TWIP(aValue.X);
147 0 : aValue.Y = MM100_TO_TWIP(aValue.Y);
148 : }
149 : }
150 : else
151 : {
152 0 : bRet = ( rVal >>= nVal );
153 0 : if( bConvert )
154 0 : nVal = MM100_TO_TWIP( nVal );
155 : }
156 :
157 115 : if ( bRet )
158 : {
159 115 : switch ( nMemberId )
160 : {
161 115 : case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
162 0 : case MID_X: aVal.setX( nVal ); break;
163 0 : case MID_Y: aVal.setY( nVal ); break;
164 0 : default: OSL_FAIL("Wrong MemberId!"); return false;
165 : }
166 : }
167 :
168 115 : return bRet;
169 : }
170 :
171 :
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|