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/rectitem.hxx>
22 : : #include <com/sun/star/uno/Any.hxx>
23 : : #include <com/sun/star/awt/Rectangle.hpp>
24 : : #include <tools/stream.hxx>
25 : :
26 : : #include <svl/poolitem.hxx>
27 : : #include <svl/memberid.hrc>
28 : :
29 : : // STATIC DATA -----------------------------------------------------------
30 : :
31 : : DBG_NAME(SfxRectangleItem)
32 : :
33 : :
34 : : // -----------------------------------------------------------------------
35 : :
36 [ + + ][ - + ]: 7744 : TYPEINIT1_AUTOFACTORY(SfxRectangleItem, SfxPoolItem);
[ # # ]
37 : :
38 : : // -----------------------------------------------------------------------
39 : :
40 [ # # ]: 0 : SfxRectangleItem::SfxRectangleItem()
41 : : {
42 : : DBG_CTOR(SfxRectangleItem, 0);
43 : 0 : }
44 : :
45 : : // -----------------------------------------------------------------------
46 : :
47 : 815 : SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, const Rectangle& rVal ) :
48 : : SfxPoolItem( nW ),
49 : 815 : aVal( rVal )
50 : : {
51 : : DBG_CTOR(SfxRectangleItem, 0);
52 : 815 : }
53 : :
54 : : // -----------------------------------------------------------------------
55 : :
56 : 3273 : SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem& rItem ) :
57 : : SfxPoolItem( rItem ),
58 : 3273 : aVal( rItem.aVal )
59 : : {
60 : : DBG_CTOR(SfxRectangleItem, 0);
61 : 3273 : }
62 : :
63 : : // -----------------------------------------------------------------------
64 : :
65 : 0 : SfxItemPresentation SfxRectangleItem::GetPresentation
66 : : (
67 : : SfxItemPresentation /*ePresentation*/,
68 : : SfxMapUnit /*eCoreMetric*/,
69 : : SfxMapUnit /*ePresentationMetric*/,
70 : : XubString& rText,
71 : : const IntlWrapper *
72 : : ) const
73 : : {
74 : : DBG_CHKTHIS(SfxRectangleItem, 0);
75 [ # # ]: 0 : rText = UniString::CreateFromInt32(aVal.Top());
76 : 0 : rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
77 [ # # ]: 0 : rText += UniString::CreateFromInt32(aVal.Left());
78 : 0 : rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
79 [ # # ]: 0 : rText += UniString::CreateFromInt32(aVal.Bottom());
80 : 0 : rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
81 [ # # ]: 0 : rText += UniString::CreateFromInt32(aVal.Right());
82 : 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
83 : : }
84 : :
85 : : // -----------------------------------------------------------------------
86 : :
87 : 152 : int SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
88 : : {
89 : : DBG_CHKTHIS(SfxRectangleItem, 0);
90 : : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
91 : 152 : return ((SfxRectangleItem&)rItem).aVal == aVal;
92 : : }
93 : :
94 : : // -----------------------------------------------------------------------
95 : :
96 : 2149 : SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const
97 : : {
98 : : DBG_CHKTHIS(SfxRectangleItem, 0);
99 [ + - ]: 2149 : return new SfxRectangleItem( *this );
100 : : }
101 : :
102 : : // -----------------------------------------------------------------------
103 : :
104 : 0 : SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, sal_uInt16 ) const
105 : : {
106 : : DBG_CHKTHIS(SfxRectangleItem, 0);
107 [ # # ]: 0 : Rectangle aStr;
108 [ # # ]: 0 : rStream >> aStr;
109 [ # # ][ # # ]: 0 : return new SfxRectangleItem(Which(), aStr);
110 : : }
111 : :
112 : : // -----------------------------------------------------------------------
113 : :
114 : 0 : SvStream& SfxRectangleItem::Store(SvStream &rStream, sal_uInt16 ) const
115 : : {
116 : : DBG_CHKTHIS(SfxRectangleItem, 0);
117 : 0 : rStream << aVal;
118 : 0 : return rStream;
119 : : }
120 : :
121 : :
122 : : // -----------------------------------------------------------------------
123 : 0 : bool SfxRectangleItem::QueryValue( com::sun::star::uno::Any& rVal,
124 : : sal_uInt8 nMemberId) const
125 : : {
126 : 0 : nMemberId &= ~CONVERT_TWIPS;
127 [ # # # # : 0 : switch ( nMemberId )
# # ]
128 : : {
129 : : case 0:
130 : : {
131 : 0 : rVal <<= com::sun::star::awt::Rectangle( aVal.getX(),
132 : 0 : aVal.getY(),
133 : 0 : aVal.getWidth(),
134 [ # # ]: 0 : aVal.getHeight() );
135 : 0 : break;
136 : : }
137 [ # # ]: 0 : case MID_RECT_LEFT: rVal <<= aVal.getX(); break;
138 [ # # ]: 0 : case MID_RECT_RIGHT: rVal <<= aVal.getY(); break;
139 [ # # ]: 0 : case MID_WIDTH: rVal <<= aVal.getWidth(); break;
140 [ # # ]: 0 : case MID_HEIGHT: rVal <<= aVal.getHeight(); break;
141 : 0 : default: OSL_FAIL("Wrong MemberID!"); return false;
142 : : }
143 : :
144 : 0 : return true;
145 : : }
146 : :
147 : : // -----------------------------------------------------------------------
148 : 0 : bool SfxRectangleItem::PutValue( const com::sun::star::uno::Any& rVal,
149 : : sal_uInt8 nMemberId )
150 : : {
151 : 0 : bool bRet = false;
152 : 0 : nMemberId &= ~CONVERT_TWIPS;
153 : 0 : com::sun::star::awt::Rectangle aValue;
154 : 0 : sal_Int32 nVal = 0;
155 [ # # ]: 0 : if ( !nMemberId )
156 [ # # ]: 0 : bRet = (rVal >>= aValue);
157 : : else
158 : 0 : bRet = (rVal >>= nVal);
159 : :
160 [ # # ]: 0 : if ( bRet )
161 : : {
162 [ # # # # : 0 : switch ( nMemberId )
# # ]
163 : : {
164 : : case 0:
165 : 0 : aVal.setX( aValue.X );
166 : 0 : aVal.setY( aValue.Y );
167 : 0 : aVal.setWidth( aValue.Width );
168 : 0 : aVal.setHeight( aValue.Height );
169 : 0 : break;
170 : 0 : case MID_RECT_LEFT: aVal.setX( nVal ); break;
171 : 0 : case MID_RECT_RIGHT: aVal.setY( nVal ); break;
172 : 0 : case MID_WIDTH: aVal.setWidth( nVal ); break;
173 : 0 : case MID_HEIGHT: aVal.setHeight( nVal ); break;
174 : 0 : default: OSL_FAIL("Wrong MemberID!"); return false;
175 : : }
176 : : }
177 : :
178 : 0 : return bRet;
179 : : }
180 : :
181 : :
182 : :
183 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|