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