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