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