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