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>
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 
32 #include <climits>
33 
34 using namespace ::com::sun::star;
35 
36 
38 
40  const sal_uInt16 nId):
41  SfxEnumItem( nId, eOrientation )
42 {
43 }
44 
45 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, bool bStacked, const sal_uInt16 nId ) :
47 {
48  if( bStacked )
49  {
50  SetValue( SvxCellOrientation::Stacked );
51  }
52  else switch( nRotation )
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 
74 bool 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 
88 bool 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  return SvxResId(RID_SVXITEMS_ORI_STANDARD + static_cast<int>(nVal));
114 }
115 
117 {
118  return new SvxOrientationItem( *this );
119 }
120 
122 {
123  return static_cast<sal_uInt16>(SvxCellOrientation::Stacked) + 1; // last enum value + 1
124 }
125 
127 {
128  return GetValue() == SvxCellOrientation::Stacked;
129 }
130 
131 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
132 {
133  sal_Int32 nAngle = nStdAngle;
134  switch( GetValue() )
135  {
136  case SvxCellOrientation::BottomUp: nAngle = 9000;break;
137  case SvxCellOrientation::TopBottom: nAngle = 27000;break;
138  default: ; //prevent warning
139  }
140  return nAngle;
141 }
142 
143 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
144 
145  SfxPoolItem( nId ),
146 
147  nLeftMargin ( 20 ),
148  nTopMargin ( 20 ),
149  nRightMargin ( 20 ),
150  nBottomMargin( 20 )
151 {
152 }
153 
154 
156  sal_Int16 nTop,
157  sal_Int16 nRight,
158  sal_Int16 nBottom,
159  const sal_uInt16 nId ) :
160  SfxPoolItem( nId ),
161 
162  nLeftMargin ( nLeft ),
163  nTopMargin ( nTop ),
164  nRightMargin ( nRight ),
165  nBottomMargin( nBottom )
166 {
167 }
168 
169 
171 (
172  SfxItemPresentation ePres,
173  MapUnit eCoreUnit,
174  MapUnit ePresUnit,
175  OUString& rText, const IntlWrapper& rIntl
176 ) const
177 {
178  OUString cpDelimTmp(cpDelim);
179 
180  switch ( ePres )
181  {
182  case SfxItemPresentation::Nameless:
183  {
184  rText = GetMetricText( static_cast<long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
185  cpDelimTmp +
186  GetMetricText( static_cast<long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
187  cpDelimTmp +
188  GetMetricText( static_cast<long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
189  cpDelimTmp +
190  GetMetricText( static_cast<long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl );
191  return true;
192  }
193  case SfxItemPresentation::Complete:
194  {
195  rText = SvxResId(RID_SVXITEMS_MARGIN_LEFT) +
196  GetMetricText( static_cast<long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
197  " " + EditResId(GetMetricId(ePresUnit)) +
198  cpDelimTmp +
199  SvxResId(RID_SVXITEMS_MARGIN_TOP) +
200  GetMetricText( static_cast<long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
201  " " + EditResId(GetMetricId(ePresUnit)) +
202  cpDelimTmp +
203  SvxResId(RID_SVXITEMS_MARGIN_RIGHT) +
204  GetMetricText( static_cast<long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
205  " " + EditResId(GetMetricId(ePresUnit)) +
206  cpDelimTmp +
207  SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) +
208  GetMetricText( static_cast<long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) +
209  " " + EditResId(GetMetricId(ePresUnit));
210  return true;
211  }
212  default: ; //prevent warning
213  }
214  return false;
215 }
216 
217 
218 bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
219 {
220  assert(SfxPoolItem::operator==(rItem));
221 
222  return ( ( nLeftMargin == static_cast<const SvxMarginItem&>(rItem).nLeftMargin ) &&
223  ( nTopMargin == static_cast<const SvxMarginItem&>(rItem).nTopMargin ) &&
224  ( nRightMargin == static_cast<const SvxMarginItem&>(rItem).nRightMargin ) &&
225  ( nBottomMargin == static_cast<const SvxMarginItem&>(rItem).nBottomMargin ) );
226 }
227 
229 {
230  return new SvxMarginItem(*this);
231 }
232 
233 bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
234 {
235  bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
236  nMemberId &= ~CONVERT_TWIPS;
237  switch ( nMemberId )
238  {
239  // now sign everything
240  case MID_MARGIN_L_MARGIN:
241  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin );
242  break;
243  case MID_MARGIN_R_MARGIN:
244  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin );
245  break;
247  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
248  break;
250  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
251  break;
252  default:
253  OSL_FAIL("unknown MemberId");
254  return false;
255  }
256  return true;
257 }
258 
259 
260 bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
261 {
262  bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
263  long nMaxVal = bConvert ? convertTwipToMm100(SHRT_MAX) : SHRT_MAX; // members are sal_Int16
264  sal_Int32 nVal = 0;
265  if(!(rVal >>= nVal) || (nVal > nMaxVal))
266  return false;
267 
268  switch ( nMemberId & ~CONVERT_TWIPS )
269  {
270  case MID_MARGIN_L_MARGIN:
271  nLeftMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
272  break;
273  case MID_MARGIN_R_MARGIN:
274  nRightMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
275  break;
277  nTopMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
278  break;
280  nBottomMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
281  break;
282  default:
283  OSL_FAIL("unknown MemberId");
284  return false;
285  }
286  return true;
287 }
288 
289 
290 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
291 {
292  nLeftMargin = nLeft;
293 }
294 
295 
296 void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
297 {
298  nTopMargin = nTop;
299 }
300 
301 
302 void SvxMarginItem::SetRightMargin( sal_Int16 nRight )
303 {
304  nRightMargin = nRight;
305 }
306 
307 
308 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
309 {
310  nBottomMargin = nBottom;
311 }
312 
313 
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long const nBottomMargin
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: algitem.cxx:74
sal_Int32 GetRotation(sal_Int32 nStdAngle) const
Returns the rotation this item represents (returns nStdAngle for STANDARD and STACKED state)...
Definition: algitem.cxx:131
SvxMarginItem(const sal_uInt16 nId)
Definition: algitem.cxx:143
sal_Int16 nBottomMargin
Definition: algitem.hxx:66
void SetLeftMargin(sal_Int16 nLeft)
Definition: algitem.cxx:290
std::string GetValue
virtual sal_uInt16 GetValueCount() const override
Definition: algitem.cxx:121
tools::Long const nLeftMargin
static OUString GetValueText(SvxCellOrientation nVal)
Definition: algitem.cxx:111
SvxOrientationItem(const SvxCellOrientation eOrientation, const sal_uInt16 nId)
Definition: algitem.cxx:39
#define MID_MARGIN_LO_MARGIN
Definition: unomid.hxx:31
const sal_Unicode cpDelim[]
#define MID_MARGIN_R_MARGIN
Definition: unomid.hxx:29
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
virtual bool operator==(const SfxPoolItem &) const override
Definition: algitem.cxx:218
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static SfxPoolItem * CreateDefault()
Definition: algitem.cxx:37
#define MID_MARGIN_L_MARGIN
Definition: unomid.hxx:28
void SetTopMargin(sal_Int16 nTop)
Definition: algitem.cxx:296
bool IsStacked() const
Returns sal_True, if the item represents STACKED state.
Definition: algitem.cxx:126
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: algitem.cxx:260
SfxItemPresentation
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: algitem.cxx:88
void SetRightMargin(sal_Int16 nRight)
Definition: algitem.cxx:302
void SetValue(EnumT nTheValue)
OUString GetMetricText(tools::Long nVal, MapUnit eSrcUnit, MapUnit eDestUnit, const IntlWrapper *pIntl)
void SetBottomMargin(sal_Int16 nBottom)
Definition: algitem.cxx:308
const char * GetMetricId(MapUnit eUnit)
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: algitem.cxx:171
#define MID_MARGIN_UP_MARGIN
Definition: unomid.hxx:30
sal_Int16 nLeftMargin
Definition: algitem.hxx:63
tools::Long const nTopMargin
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: algitem.cxx:233
unsigned char sal_uInt8
OUString EditResId(const char *pId)
sal_Int16 nTopMargin
Definition: algitem.hxx:64
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: algitem.cxx:62
tools::Long const nRightMargin
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
MapUnit
virtual SvxMarginItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: algitem.cxx:228
sal_Int16 nRightMargin
Definition: algitem.hxx:65
virtual SvxOrientationItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: algitem.cxx:116
SvxCellOrientation
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
#define CONVERT_TWIPS