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