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