/src/libreoffice/svx/source/items/algitem.cxx
Line | Count | Source |
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 | | #include <svx/strings.hrc> |
21 | | #include <osl/diagnose.h> |
22 | | #include <tools/mapunit.hxx> |
23 | | #include <tools/UnitConversion.hxx> |
24 | | #include <com/sun/star/table/CellOrientation.hpp> |
25 | | |
26 | | #include <svx/algitem.hxx> |
27 | | #include <svx/dialmgr.hxx> |
28 | | #include <editeng/itemtype.hxx> |
29 | | #include <editeng/eerdll.hxx> |
30 | | #include <svx/unomid.hxx> |
31 | | #include <o3tl/hash_combine.hxx> |
32 | | |
33 | | #include <climits> |
34 | | |
35 | | using namespace ::com::sun::star; |
36 | | |
37 | | |
38 | 0 | SfxPoolItem* SvxMarginItem::CreateDefault() { return new SvxMarginItem(TypedWhichId<SvxMarginItem>(0)) ;} |
39 | | |
40 | | SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation, |
41 | | const TypedWhichId<SvxOrientationItem> nId): |
42 | 604k | SfxEnumItem( nId, eOrientation ) |
43 | 604k | { |
44 | 604k | } |
45 | | |
46 | | SvxOrientationItem::SvxOrientationItem( Degree100 nRotation, bool bStacked, const TypedWhichId<SvxOrientationItem> nId ) : |
47 | 0 | SfxEnumItem( nId, SvxCellOrientation::Standard ) |
48 | 0 | { |
49 | 0 | if( bStacked ) |
50 | 0 | { |
51 | 0 | SetValue( SvxCellOrientation::Stacked ); |
52 | 0 | } |
53 | 0 | else switch( nRotation.get() ) |
54 | 0 | { |
55 | 0 | case 9000: SetValue( SvxCellOrientation::BottomUp ); break; |
56 | 0 | case 27000: SetValue( SvxCellOrientation::TopBottom ); break; |
57 | 0 | default: SetValue( SvxCellOrientation::Standard ); |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | |
62 | | bool SvxOrientationItem::GetPresentation |
63 | | ( |
64 | | SfxItemPresentation /*ePres*/, |
65 | | MapUnit /*eCoreUnit*/, |
66 | | MapUnit /*ePresUnit*/, |
67 | | OUString& rText, |
68 | | const IntlWrapper& ) const |
69 | 0 | { |
70 | 0 | rText = GetValueText( GetValue() ); |
71 | 0 | return true; |
72 | 0 | } |
73 | | |
74 | | |
75 | | bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const |
76 | 0 | { |
77 | 0 | table::CellOrientation eUno = table::CellOrientation_STANDARD; |
78 | 0 | switch ( GetValue() ) |
79 | 0 | { |
80 | 0 | case SvxCellOrientation::Standard: eUno = table::CellOrientation_STANDARD; break; |
81 | 0 | case SvxCellOrientation::TopBottom: eUno = table::CellOrientation_TOPBOTTOM; break; |
82 | 0 | case SvxCellOrientation::BottomUp: eUno = table::CellOrientation_BOTTOMTOP; break; |
83 | 0 | case SvxCellOrientation::Stacked: eUno = table::CellOrientation_STACKED; break; |
84 | 0 | } |
85 | 0 | rVal <<= eUno; |
86 | 0 | return true; |
87 | 0 | } |
88 | | |
89 | | bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) |
90 | 0 | { |
91 | 0 | table::CellOrientation eOrient; |
92 | 0 | if(!(rVal >>= eOrient)) |
93 | 0 | { |
94 | 0 | sal_Int32 nValue = 0; |
95 | 0 | if(!(rVal >>= nValue)) |
96 | 0 | return false; |
97 | 0 | eOrient = static_cast<table::CellOrientation>(nValue); |
98 | 0 | } |
99 | 0 | SvxCellOrientation eSvx = SvxCellOrientation::Standard; |
100 | 0 | switch (eOrient) |
101 | 0 | { |
102 | 0 | case table::CellOrientation_STANDARD: eSvx = SvxCellOrientation::Standard; break; |
103 | 0 | case table::CellOrientation_TOPBOTTOM: eSvx = SvxCellOrientation::TopBottom; break; |
104 | 0 | case table::CellOrientation_BOTTOMTOP: eSvx = SvxCellOrientation::BottomUp; break; |
105 | 0 | case table::CellOrientation_STACKED: eSvx = SvxCellOrientation::Stacked; break; |
106 | 0 | default: ; //prevent warning |
107 | 0 | } |
108 | 0 | SetValue( eSvx ); |
109 | 0 | return true; |
110 | 0 | } |
111 | | |
112 | | OUString SvxOrientationItem::GetValueText( SvxCellOrientation nVal ) |
113 | 0 | { |
114 | 0 | OString id = OString::Concat(RID_SVXITEMS_ORI_STANDARD.getId()) + OString::number(static_cast<int>(nVal)); |
115 | 0 | return SvxResId(TranslateId(RID_SVXITEMS_ORI_STANDARD.mpContext, id.getStr())); |
116 | 0 | } |
117 | | |
118 | | SvxOrientationItem* SvxOrientationItem::Clone( SfxItemPool* ) const |
119 | 0 | { |
120 | 0 | return new SvxOrientationItem( *this ); |
121 | 0 | } |
122 | | |
123 | | bool SvxOrientationItem::IsStacked() const |
124 | 0 | { |
125 | 0 | return GetValue() == SvxCellOrientation::Stacked; |
126 | 0 | } |
127 | | |
128 | | Degree100 SvxOrientationItem::GetRotation( Degree100 nStdAngle ) const |
129 | 0 | { |
130 | 0 | Degree100 nAngle = nStdAngle; |
131 | 0 | switch( GetValue() ) |
132 | 0 | { |
133 | 0 | case SvxCellOrientation::BottomUp: nAngle = 9000_deg100; break; |
134 | 0 | case SvxCellOrientation::TopBottom: nAngle = 27000_deg100; break; |
135 | 0 | default: ; //prevent warning |
136 | 0 | } |
137 | 0 | return nAngle; |
138 | 0 | } |
139 | | |
140 | | SvxMarginItem::SvxMarginItem( const TypedWhichId<SvxMarginItem> nId ) : |
141 | | |
142 | 2.28k | SfxPoolItem( nId ), |
143 | | |
144 | 2.28k | nLeftMargin ( 20 ), |
145 | 2.28k | nTopMargin ( 20 ), |
146 | 2.28k | nRightMargin ( 20 ), |
147 | 2.28k | nBottomMargin( 20 ) |
148 | 2.28k | { |
149 | 2.28k | } |
150 | | |
151 | | |
152 | | SvxMarginItem::SvxMarginItem( sal_Int16 nLeft, |
153 | | sal_Int16 nTop, |
154 | | sal_Int16 nRight, |
155 | | sal_Int16 nBottom, |
156 | | const TypedWhichId<SvxMarginItem> nId ) : |
157 | 134k | SfxPoolItem( nId ), |
158 | | |
159 | 134k | nLeftMargin ( nLeft ), |
160 | 134k | nTopMargin ( nTop ), |
161 | 134k | nRightMargin ( nRight ), |
162 | 134k | nBottomMargin( nBottom ) |
163 | 134k | { |
164 | 134k | } |
165 | | |
166 | | |
167 | | bool SvxMarginItem::GetPresentation |
168 | | ( |
169 | | SfxItemPresentation ePres, |
170 | | MapUnit eCoreUnit, |
171 | | MapUnit ePresUnit, |
172 | | OUString& rText, const IntlWrapper& rIntl |
173 | | ) const |
174 | 0 | { |
175 | 0 | OUString cpDelimTmp(cpDelim); |
176 | |
|
177 | 0 | switch ( ePres ) |
178 | 0 | { |
179 | 0 | case SfxItemPresentation::Nameless: |
180 | 0 | { |
181 | 0 | rText = GetMetricText( static_cast<tools::Long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) + |
182 | 0 | cpDelimTmp + |
183 | 0 | GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) + |
184 | 0 | cpDelimTmp + |
185 | 0 | GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) + |
186 | 0 | cpDelimTmp + |
187 | 0 | GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ); |
188 | 0 | return true; |
189 | 0 | } |
190 | 0 | case SfxItemPresentation::Complete: |
191 | 0 | { |
192 | 0 | rText = SvxResId(RID_SVXITEMS_MARGIN_LEFT) + |
193 | 0 | GetMetricText( static_cast<tools::Long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) + |
194 | 0 | " " + EditResId(GetMetricId(ePresUnit)) + |
195 | 0 | cpDelimTmp + |
196 | 0 | SvxResId(RID_SVXITEMS_MARGIN_TOP) + |
197 | 0 | GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) + |
198 | 0 | " " + EditResId(GetMetricId(ePresUnit)) + |
199 | 0 | cpDelimTmp + |
200 | 0 | SvxResId(RID_SVXITEMS_MARGIN_RIGHT) + |
201 | 0 | GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) + |
202 | 0 | " " + EditResId(GetMetricId(ePresUnit)) + |
203 | 0 | cpDelimTmp + |
204 | 0 | SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) + |
205 | 0 | GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) + |
206 | 0 | " " + EditResId(GetMetricId(ePresUnit)); |
207 | 0 | return true; |
208 | 0 | } |
209 | 0 | default: ; //prevent warning |
210 | 0 | } |
211 | 0 | return false; |
212 | 0 | } |
213 | | |
214 | | |
215 | | bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const |
216 | 267k | { |
217 | 267k | assert(SfxPoolItem::operator==(rItem)); |
218 | | |
219 | 267k | return ( ( nLeftMargin == static_cast<const SvxMarginItem&>(rItem).nLeftMargin ) && |
220 | 265k | ( nTopMargin == static_cast<const SvxMarginItem&>(rItem).nTopMargin ) && |
221 | 265k | ( nRightMargin == static_cast<const SvxMarginItem&>(rItem).nRightMargin ) && |
222 | 265k | ( nBottomMargin == static_cast<const SvxMarginItem&>(rItem).nBottomMargin ) ); |
223 | 267k | } |
224 | | |
225 | | SvxMarginItem* SvxMarginItem::Clone( SfxItemPool* ) const |
226 | 134k | { |
227 | 134k | return new SvxMarginItem(*this); |
228 | 134k | } |
229 | | |
230 | | bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const |
231 | 0 | { |
232 | 0 | bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); |
233 | 0 | nMemberId &= ~CONVERT_TWIPS; |
234 | 0 | switch ( nMemberId ) |
235 | 0 | { |
236 | | // now sign everything |
237 | 0 | case MID_MARGIN_L_MARGIN: |
238 | 0 | rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin ); |
239 | 0 | break; |
240 | 0 | case MID_MARGIN_R_MARGIN: |
241 | 0 | rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin ); |
242 | 0 | break; |
243 | 0 | case MID_MARGIN_UP_MARGIN: |
244 | 0 | rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin ); |
245 | 0 | break; |
246 | 0 | case MID_MARGIN_LO_MARGIN: |
247 | 0 | rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin ); |
248 | 0 | break; |
249 | 0 | default: |
250 | 0 | OSL_FAIL("unknown MemberId"); |
251 | 0 | return false; |
252 | 0 | } |
253 | 0 | return true; |
254 | 0 | } |
255 | | |
256 | | |
257 | | bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) |
258 | 282 | { |
259 | 282 | ASSERT_CHANGE_REFCOUNTED_ITEM; |
260 | 282 | bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 ); |
261 | 282 | tools::Long nMaxVal = bConvert ? convertTwipToMm100(SHRT_MAX) : SHRT_MAX; // members are sal_Int16 |
262 | 282 | sal_Int32 nVal = 0; |
263 | 282 | if(!(rVal >>= nVal) || (nVal > nMaxVal)) |
264 | 0 | return false; |
265 | | |
266 | 282 | switch ( nMemberId & ~CONVERT_TWIPS ) |
267 | 282 | { |
268 | 70 | case MID_MARGIN_L_MARGIN: |
269 | 70 | nLeftMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); |
270 | 70 | break; |
271 | 70 | case MID_MARGIN_R_MARGIN: |
272 | 70 | nRightMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); |
273 | 70 | break; |
274 | 72 | case MID_MARGIN_UP_MARGIN: |
275 | 72 | nTopMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); |
276 | 72 | break; |
277 | 70 | case MID_MARGIN_LO_MARGIN: |
278 | 70 | nBottomMargin = static_cast<sal_Int16>( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); |
279 | 70 | break; |
280 | 0 | default: |
281 | 0 | OSL_FAIL("unknown MemberId"); |
282 | 0 | return false; |
283 | 282 | } |
284 | 282 | return true; |
285 | 282 | } |
286 | | |
287 | | |
288 | | void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft ) |
289 | 0 | { |
290 | 0 | ASSERT_CHANGE_REFCOUNTED_ITEM; |
291 | 0 | nLeftMargin = nLeft; |
292 | 0 | } |
293 | | |
294 | | |
295 | | void SvxMarginItem::SetTopMargin( sal_Int16 nTop ) |
296 | 0 | { |
297 | 0 | ASSERT_CHANGE_REFCOUNTED_ITEM; |
298 | 0 | nTopMargin = nTop; |
299 | 0 | } |
300 | | |
301 | | |
302 | | void SvxMarginItem::SetRightMargin( sal_Int16 nRight ) |
303 | 0 | { |
304 | 0 | ASSERT_CHANGE_REFCOUNTED_ITEM; |
305 | 0 | nRightMargin = nRight; |
306 | 0 | } |
307 | | |
308 | | |
309 | | void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom ) |
310 | 0 | { |
311 | | ASSERT_CHANGE_REFCOUNTED_ITEM; |
312 | 0 | nBottomMargin = nBottom; |
313 | 0 | } |
314 | | |
315 | | |
316 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |