bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / items / algitem.cxx
blob0a1577d1fbe731c4be3fc4c4b710f83a09919cd3
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/svxitems.hrc>
22 #include <tools/stream.hxx>
23 #include <tools/mapunit.hxx>
24 #include <com/sun/star/table/BorderLine.hpp>
25 #include <com/sun/star/table/ShadowLocation.hpp>
26 #include <com/sun/star/table/TableBorder.hpp>
27 #include <com/sun/star/table/ShadowFormat.hpp>
28 #include <com/sun/star/table/CellRangeAddress.hpp>
29 #include <com/sun/star/table/CellContentType.hpp>
30 #include <com/sun/star/table/TableOrientation.hpp>
31 #include <com/sun/star/util/SortField.hpp>
32 #include <com/sun/star/util/SortFieldType.hpp>
33 #include <com/sun/star/table/CellOrientation.hpp>
34 #include <com/sun/star/table/CellAddress.hpp>
36 #include <svx/algitem.hxx>
37 #include <svx/dialmgr.hxx>
38 #include <editeng/itemtype.hxx>
39 #include <svx/unomid.hxx>
41 using namespace ::com::sun::star;
43 TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
44 TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
46 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
47 const sal_uInt16 nId):
48 SfxEnumItem( nId, (sal_uInt16)eOrientation )
52 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, bool bStacked, const sal_uInt16 nId ) :
53 SfxEnumItem( nId )
55 SetFromRotation( nRotation, bStacked );
60 bool SvxOrientationItem::GetPresentation
62 SfxItemPresentation /*ePres*/,
63 SfxMapUnit /*eCoreUnit*/,
64 SfxMapUnit /*ePresUnit*/,
65 OUString& rText, const IntlWrapper * ) const
67 rText = GetValueText( GetValue() );
68 return true;
73 bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
75 table::CellOrientation eUno = table::CellOrientation_STANDARD;
76 switch ( (SvxCellOrientation)GetValue() )
78 case SVX_ORIENTATION_STANDARD: eUno = table::CellOrientation_STANDARD; break;
79 case SVX_ORIENTATION_TOPBOTTOM: eUno = table::CellOrientation_TOPBOTTOM; break;
80 case SVX_ORIENTATION_BOTTOMTOP: eUno = table::CellOrientation_BOTTOMTOP; break;
81 case SVX_ORIENTATION_STACKED: eUno = table::CellOrientation_STACKED; break;
83 rVal <<= eUno;
84 return true;
87 bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
89 table::CellOrientation eOrient;
90 if(!(rVal >>= eOrient))
92 sal_Int32 nValue = 0;
93 if(!(rVal >>= nValue))
94 return false;
95 eOrient = (table::CellOrientation)nValue;
97 SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
98 switch (eOrient)
100 case table::CellOrientation_STANDARD: eSvx = SVX_ORIENTATION_STANDARD; break;
101 case table::CellOrientation_TOPBOTTOM: eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
102 case table::CellOrientation_BOTTOMTOP: eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
103 case table::CellOrientation_STACKED: eSvx = SVX_ORIENTATION_STACKED; break;
104 default: ; //prevent warning
106 SetValue( (sal_uInt16)eSvx );
107 return true;
112 OUString SvxOrientationItem::GetValueText( sal_uInt16 nVal )
114 DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
115 return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
120 SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
122 return new SvxOrientationItem( *this );
127 SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, sal_uInt16 ) const
129 sal_uInt16 nVal;
130 rStream.ReadUInt16( nVal );
131 return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
136 sal_uInt16 SvxOrientationItem::GetValueCount() const
138 return SVX_ORIENTATION_STACKED + 1; // letzter Enum-Wert + 1
143 bool SvxOrientationItem::IsStacked() const
145 return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
148 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
150 sal_Int32 nAngle = nStdAngle;
151 switch( static_cast< SvxCellOrientation >( GetValue() ) )
153 case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;break;
154 case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;break;
155 default: ; //prevent warning
157 return nAngle;
160 void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation, bool bStacked )
162 if( bStacked )
164 SetValue( SVX_ORIENTATION_STACKED );
166 else switch( nRotation )
168 case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP ); break;
169 case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM ); break;
170 default: SetValue( SVX_ORIENTATION_STANDARD );
174 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
176 SfxPoolItem( nId ),
178 nLeftMargin ( 20 ),
179 nTopMargin ( 20 ),
180 nRightMargin ( 20 ),
181 nBottomMargin( 20 )
187 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
188 sal_Int16 nTop,
189 sal_Int16 nRight,
190 sal_Int16 nBottom,
191 const sal_uInt16 nId ) :
192 SfxPoolItem( nId ),
194 nLeftMargin ( nLeft ),
195 nTopMargin ( nTop ),
196 nRightMargin ( nRight ),
197 nBottomMargin( nBottom )
204 SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
206 SfxPoolItem( rItem.Which() )
208 nLeftMargin = rItem.nLeftMargin;
209 nTopMargin = rItem.nTopMargin;
210 nRightMargin = rItem.nRightMargin;
211 nBottomMargin = rItem.nBottomMargin;
216 bool SvxMarginItem::GetPresentation
218 SfxItemPresentation ePres,
219 SfxMapUnit eCoreUnit,
220 SfxMapUnit ePresUnit,
221 OUString& rText, const IntlWrapper *pIntl
222 ) const
224 OUString cpDelimTmp = OUString(cpDelim);
226 switch ( ePres )
228 case SFX_ITEM_PRESENTATION_NAMELESS:
230 rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
231 cpDelimTmp +
232 GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl ) +
233 cpDelimTmp +
234 GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl ) +
235 cpDelimTmp +
236 GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
237 return true;
239 case SFX_ITEM_PRESENTATION_COMPLETE:
241 rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT) +
242 GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
243 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
244 cpDelimTmp +
245 SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP) +
246 GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl ) +
247 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
248 cpDelimTmp +
249 SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT) +
250 GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl ) +
251 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
252 cpDelimTmp +
253 SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM) +
254 GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl ) +
255 " " + EE_RESSTR(GetMetricId(ePresUnit));
256 return true;
258 default: ; //prevent warning
260 return false;
265 bool SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
267 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
269 return ( ( nLeftMargin == static_cast<const SvxMarginItem&>(rItem).nLeftMargin ) &&
270 ( nTopMargin == static_cast<const SvxMarginItem&>(rItem).nTopMargin ) &&
271 ( nRightMargin == static_cast<const SvxMarginItem&>(rItem).nRightMargin ) &&
272 ( nBottomMargin == static_cast<const SvxMarginItem&>(rItem).nBottomMargin ) );
277 SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
279 return new SvxMarginItem(*this);
284 SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, sal_uInt16 ) const
286 sal_Int16 nLeft;
287 sal_Int16 nTop;
288 sal_Int16 nRight;
289 sal_Int16 nBottom;
290 rStream.ReadInt16( nLeft );
291 rStream.ReadInt16( nTop );
292 rStream.ReadInt16( nRight );
293 rStream.ReadInt16( nBottom );
294 return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
299 SvStream& SvxMarginItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/) const
301 rStream.WriteInt16( nLeftMargin );
302 rStream.WriteInt16( nTopMargin );
303 rStream.WriteInt16( nRightMargin );
304 rStream.WriteInt16( nBottomMargin );
305 return rStream;
311 bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
313 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
314 nMemberId &= ~CONVERT_TWIPS;
315 switch ( nMemberId )
317 // jetzt alles signed
318 case MID_MARGIN_L_MARGIN:
319 rVal <<= (sal_Int32)( bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin );
320 break;
321 case MID_MARGIN_R_MARGIN:
322 rVal <<= (sal_Int32)( bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin );
323 break;
324 case MID_MARGIN_UP_MARGIN:
325 rVal <<= (sal_Int32)( bConvert ? convertTwipToMm100(nTopMargin) : nTopMargin );
326 break;
327 case MID_MARGIN_LO_MARGIN:
328 rVal <<= (sal_Int32)( bConvert ? convertTwipToMm100(nBottomMargin) : nBottomMargin );
329 break;
330 default:
331 OSL_FAIL("unknown MemberId");
332 return false;
334 return true;
339 bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
341 bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
342 long nMaxVal = bConvert ? convertTwipToMm100(SHRT_MAX) : SHRT_MAX; // Members sind sal_Int16
343 sal_Int32 nVal = 0;
344 if(!(rVal >>= nVal) || (nVal > nMaxVal))
345 return false;
347 switch ( nMemberId & ~CONVERT_TWIPS )
349 case MID_MARGIN_L_MARGIN:
350 nLeftMargin = (sal_Int16)( bConvert ? convertMm100ToTwip(nVal) : nVal );
351 break;
352 case MID_MARGIN_R_MARGIN:
353 nRightMargin = (sal_Int16)( bConvert ? convertMm100ToTwip(nVal) : nVal );
354 break;
355 case MID_MARGIN_UP_MARGIN:
356 nTopMargin = (sal_Int16)( bConvert ? convertMm100ToTwip(nVal) : nVal );
357 break;
358 case MID_MARGIN_LO_MARGIN:
359 nBottomMargin = (sal_Int16)( bConvert ? convertMm100ToTwip(nVal) : nVal );
360 break;
361 default:
362 OSL_FAIL("unknown MemberId");
363 return false;
365 return true;
370 void SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
372 nLeftMargin = nLeft;
377 void SvxMarginItem::SetTopMargin( sal_Int16 nTop )
379 nTopMargin = nTop;
384 void SvxMarginItem::SetRightMargin( sal_Int16 nRight )
386 nRightMargin = nRight;
391 void SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
393 nBottomMargin = nBottom;
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */