Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / items / algitem.cxx
blob58a71f11594cb6e58a7aadf805e783cb633437c9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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>
32 #include <climits>
34 using namespace ::com::sun::star;
37 SfxPoolItem* SvxMarginItem::CreateDefault() { return new SvxMarginItem(0) ;}
39 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
40 const sal_uInt16 nId):
41 SfxEnumItem( nId, eOrientation )
45 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, bool bStacked, const sal_uInt16 nId ) :
46 SfxEnumItem( nId, SvxCellOrientation::Standard )
48 if( bStacked )
50 SetValue( SvxCellOrientation::Stacked );
52 else switch( nRotation )
54 case 9000: SetValue( SvxCellOrientation::BottomUp ); break;
55 case 27000: SetValue( SvxCellOrientation::TopBottom ); break;
56 default: SetValue( SvxCellOrientation::Standard );
61 bool SvxOrientationItem::GetPresentation
63 SfxItemPresentation /*ePres*/,
64 MapUnit /*eCoreUnit*/,
65 MapUnit /*ePresUnit*/,
66 OUString& rText,
67 const IntlWrapper& ) const
69 rText = GetValueText( GetValue() );
70 return true;
74 bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
76 table::CellOrientation eUno = table::CellOrientation_STANDARD;
77 switch ( GetValue() )
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;
84 rVal <<= eUno;
85 return true;
88 bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
90 table::CellOrientation eOrient;
91 if(!(rVal >>= eOrient))
93 sal_Int32 nValue = 0;
94 if(!(rVal >>= nValue))
95 return false;
96 eOrient = static_cast<table::CellOrientation>(nValue);
98 SvxCellOrientation eSvx = SvxCellOrientation::Standard;
99 switch (eOrient)
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
107 SetValue( eSvx );
108 return true;
111 OUString SvxOrientationItem::GetValueText( SvxCellOrientation nVal )
113 return SvxResId(RID_SVXITEMS_ORI_STANDARD + static_cast<int>(nVal));
116 SvxOrientationItem* SvxOrientationItem::Clone( SfxItemPool* ) const
118 return new SvxOrientationItem( *this );
121 sal_uInt16 SvxOrientationItem::GetValueCount() const
123 return static_cast<sal_uInt16>(SvxCellOrientation::Stacked) + 1; // last enum value + 1
126 bool SvxOrientationItem::IsStacked() const
128 return GetValue() == SvxCellOrientation::Stacked;
131 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
133 sal_Int32 nAngle = nStdAngle;
134 switch( GetValue() )
136 case SvxCellOrientation::BottomUp: nAngle = 9000;break;
137 case SvxCellOrientation::TopBottom: nAngle = 27000;break;
138 default: ; //prevent warning
140 return nAngle;
143 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
145 SfxPoolItem( nId ),
147 nLeftMargin ( 20 ),
148 nTopMargin ( 20 ),
149 nRightMargin ( 20 ),
150 nBottomMargin( 20 )
155 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
156 sal_Int16 nTop,
157 sal_Int16 nRight,
158 sal_Int16 nBottom,
159 const sal_uInt16 nId ) :
160 SfxPoolItem( nId ),
162 nLeftMargin ( nLeft ),
163 nTopMargin ( nTop ),
164 nRightMargin ( nRight ),
165 nBottomMargin( nBottom )
170 bool SvxMarginItem::GetPresentation
172 SfxItemPresentation ePres,
173 MapUnit eCoreUnit,
174 MapUnit ePresUnit,
175 OUString& rText, const IntlWrapper& rIntl
176 ) const
178 OUString cpDelimTmp(cpDelim);
180 switch ( ePres )
182 case SfxItemPresentation::Nameless:
184 rText = GetMetricText( static_cast<tools::Long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
185 cpDelimTmp +
186 GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
187 cpDelimTmp +
188 GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
189 cpDelimTmp +
190 GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl );
191 return true;
193 case SfxItemPresentation::Complete:
195 rText = SvxResId(RID_SVXITEMS_MARGIN_LEFT) +
196 GetMetricText( static_cast<tools::Long>(nLeftMargin), eCoreUnit, ePresUnit, &rIntl ) +
197 " " + EditResId(GetMetricId(ePresUnit)) +
198 cpDelimTmp +
199 SvxResId(RID_SVXITEMS_MARGIN_TOP) +
200 GetMetricText( static_cast<tools::Long>(nTopMargin), eCoreUnit, ePresUnit, &rIntl ) +
201 " " + EditResId(GetMetricId(ePresUnit)) +
202 cpDelimTmp +
203 SvxResId(RID_SVXITEMS_MARGIN_RIGHT) +
204 GetMetricText( static_cast<tools::Long>(nRightMargin), eCoreUnit, ePresUnit, &rIntl ) +
205 " " + EditResId(GetMetricId(ePresUnit)) +
206 cpDelimTmp +
207 SvxResId(RID_SVXITEMS_MARGIN_BOTTOM) +
208 GetMetricText( static_cast<tools::Long>(nBottomMargin), eCoreUnit, ePresUnit, &rIntl ) +
209 " " + EditResId(GetMetricId(ePresUnit));
210 return true;
212 default: ; //prevent warning
214 return false;
218 bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
220 assert(SfxPoolItem::operator==(rItem));
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 ) );
228 SvxMarginItem* SvxMarginItem::Clone( SfxItemPool* ) const
230 return new SvxMarginItem(*this);
233 bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
235 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
236 nMemberId &= ~CONVERT_TWIPS;
237 switch ( nMemberId )
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;
246 case MID_MARGIN_UP_MARGIN:
247 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
248 break;
249 case MID_MARGIN_LO_MARGIN:
250 rVal <<= static_cast<sal_Int32>( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
251 break;
252 default:
253 OSL_FAIL("unknown MemberId");
254 return false;
256 return true;
260 bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
262 bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
263 tools::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;
268 switch ( nMemberId & ~CONVERT_TWIPS )
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;
276 case MID_MARGIN_UP_MARGIN:
277 nTopMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
278 break;
279 case MID_MARGIN_LO_MARGIN:
280 nBottomMargin = static_cast<sal_Int16>( bConvert ? convertMm100ToTwip(nVal) : nVal );
281 break;
282 default:
283 OSL_FAIL("unknown MemberId");
284 return false;
286 return true;
290 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
292 nLeftMargin = nLeft;
296 void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
298 nTopMargin = nTop;
302 void SvxMarginItem::SetRightMargin( sal_Int16 nRight )
304 nRightMargin = nRight;
308 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
310 nBottomMargin = nBottom;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */