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 
123 
125 {
126  return SvxResId(RID_SVXITEMS_ORI_STANDARD + static_cast<int>(nVal));
127 }
128 
129 
131 {
132  return new SvxOrientationItem( *this );
133 }
134 
135 
137 {
138  return static_cast<sal_uInt16>(SvxCellOrientation::Stacked) + 1; // last enum value + 1
139 }
140 
141 
143 {
144  return GetValue() == SvxCellOrientation::Stacked;
145 }
146 
147 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
148 {
149  sal_Int32 nAngle = nStdAngle;
150  switch( GetValue() )
151  {
152  case SvxCellOrientation::BottomUp: nAngle = 9000;break;
153  case SvxCellOrientation::TopBottom: nAngle = 27000;break;
154  default: ; //prevent warning
155  }
156  return nAngle;
157 }
158 
159 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
160 
161  SfxPoolItem( nId ),
162 
163  nLeftMargin ( 20 ),
164  nTopMargin ( 20 ),
165  nRightMargin ( 20 ),
166  nBottomMargin( 20 )
167 {
168 }
169 
170 
172  sal_Int16 nTop,
173  sal_Int16 nRight,
174  sal_Int16 nBottom,
175  const sal_uInt16 nId ) :
176  SfxPoolItem( nId ),
177 
178  nLeftMargin ( nLeft ),
179  nTopMargin ( nTop ),
180  nRightMargin ( nRight ),
181  nBottomMargin( nBottom )
182 {
183 }
184 
185 
187 (
188  SfxItemPresentation ePres,
189  MapUnit eCoreUnit,
190  MapUnit ePresUnit,
191  OUString& rText, const IntlWrapper& rIntl
192 ) const
193 {
194  OUString cpDelimTmp(cpDelim);
195 
196  switch ( ePres )
197  {
198  case SfxItemPresentation::Nameless:
199  {
200  rText = GetMetricText( static_cast<long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
201  cpDelimTmp +
202  GetMetricText( static_cast<long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
203  cpDelimTmp +
204  GetMetricText( static_cast<long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
205  cpDelimTmp +
206  GetMetricText( static_cast<long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl );
207  return true;
208  }
209  case SfxItemPresentation::Complete:
210  {
211  rText = SvxResId(RID_SVXITEMS_MARGIN_LEFT) +
212  GetMetricText( static_cast<long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
213  " " + EditResId(GetMetricId(ePresUnit)) +
214  cpDelimTmp +
215  SvxResId(RID_SVXITEMS_MARGIN_TOP) +
216  GetMetricText( static_cast<long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
217  " " + EditResId(GetMetricId(ePresUnit)) +
218  cpDelimTmp +
219  SvxResId(RID_SVXITEMS_MARGIN_RIGHT) +
220  GetMetricText( static_cast<long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
221  " " + EditResId(GetMetricId(ePresUnit)) +
222  cpDelimTmp +
223  SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) +
224  GetMetricText( static_cast<long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) +
225  " " + EditResId(GetMetricId(ePresUnit));
226  return true;
227  }
228  default: ; //prevent warning
229  }
230  return false;
231 }
232 
233 
234 bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
235 {
236  assert(SfxPoolItem::operator==(rItem));
237 
238  return ( ( nLeftMargin == static_cast<const SvxMarginItem&>(rItem).nLeftMargin ) &&
239  ( nTopMargin == static_cast<const SvxMarginItem&>(rItem).nTopMargin ) &&
240  ( nRightMargin == static_cast<const SvxMarginItem&>(rItem).nRightMargin ) &&
241  ( nBottomMargin == static_cast<const SvxMarginItem&>(rItem).nBottomMargin ) );
242 }
243 
244 
246 {
247  return new SvxMarginItem(*this);
248 }
249 
250 
251 bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
252 {
253  bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
254  nMemberId &= ~CONVERT_TWIPS;
255  switch ( nMemberId )
256  {
257  // now sign everything
258  case MID_MARGIN_L_MARGIN:
259  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin );
260  break;
261  case MID_MARGIN_R_MARGIN:
262  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin );
263  break;
265  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
266  break;
268  rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
269  break;
270  default:
271  OSL_FAIL("unknown MemberId");
272  return false;
273  }
274  return true;
275 }
276 
277 
278 bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
279 {
280  bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
281  long nMaxVal = bConvert ? convertTwipToMm100(SHRT_MAX) : SHRT_MAX; // members are sal_Int16
282  sal_Int32 nVal = 0;
283  if(!(rVal >>= nVal) || (nVal > nMaxVal))
284  return false;
285 
286  switch ( nMemberId & ~CONVERT_TWIPS )
287  {
288  case MID_MARGIN_L_MARGIN:
289  nLeftMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
290  break;
291  case MID_MARGIN_R_MARGIN:
292  nRightMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
293  break;
295  nTopMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
296  break;
298  nBottomMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
299  break;
300  default:
301  OSL_FAIL("unknown MemberId");
302  return false;
303  }
304  return true;
305 }
306 
307 
308 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
309 {
310  nLeftMargin = nLeft;
311 }
312 
313 
314 void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
315 {
316  nTopMargin = nTop;
317 }
318 
319 
320 void SvxMarginItem::SetRightMargin( sal_Int16 nRight )
321 {
322  nRightMargin = nRight;
323 }
324 
325 
326 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
327 {
328  nBottomMargin = nBottom;
329 }
330 
331 
332 /* 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:147
SvxMarginItem(const sal_uInt16 nId)
Definition: algitem.cxx:159
sal_Int16 nBottomMargin
Definition: algitem.hxx:66
void SetLeftMargin(sal_Int16 nLeft)
Definition: algitem.cxx:308
std::string GetValue
virtual sal_uInt16 GetValueCount() const override
Definition: algitem.cxx:136
static OUString GetValueText(SvxCellOrientation nVal)
Definition: algitem.cxx:124
SvxOrientationItem(const SvxCellOrientation eOrientation, const sal_uInt16 nId)
Definition: algitem.cxx:51
#define MID_MARGIN_LO_MARGIN
Definition: unomid.hxx:36
#define MID_MARGIN_R_MARGIN
Definition: unomid.hxx:34
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
virtual bool operator==(const SfxPoolItem &) const override
Definition: algitem.cxx:234
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
static SfxPoolItem * CreateDefault()
Definition: algitem.cxx:49
#define MID_MARGIN_L_MARGIN
Definition: unomid.hxx:33
void SetTopMargin(sal_Int16 nTop)
Definition: algitem.cxx:314
long const nTopMargin
bool IsStacked() const
Returns sal_True, if the item represents STACKED state.
Definition: algitem.cxx:142
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: algitem.cxx:278
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:320
void SetValue(EnumT nTheValue)
void SetBottomMargin(sal_Int16 nBottom)
Definition: algitem.cxx:326
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:187
#define MID_MARGIN_UP_MARGIN
Definition: unomid.hxx:35
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:251
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
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: algitem.cxx:130
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
MapUnit
sal_Int16 nRightMargin
Definition: algitem.hxx:65
long const nBottomMargin
SvxCellOrientation
long const nRightMargin
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: algitem.cxx:245
#define CONVERT_TWIPS