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