fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / items / algitem.cxx
blob1451fdb93602c87a232b552f9b04f790a61ad7c5
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 .
21 #include <svx/svxitems.hrc>
24 #include <tools/stream.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>
37 #include <svx/algitem.hxx>
38 #include <svx/dialmgr.hxx>
39 #include <editeng/itemtype.hxx>
40 #include <svx/unomid.hxx>
42 using namespace ::rtl;
43 using namespace ::com::sun::star;
45 // Konvertierung fuer UNO
46 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
47 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
49 // STATIC DATA -----------------------------------------------------------
51 //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
52 TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
53 TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
55 // class SvxOrientationItem ----------------------------------------------
57 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
58 const sal_uInt16 nId):
59 SfxEnumItem( nId, (sal_uInt16)eOrientation )
63 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, sal_Bool bStacked, const sal_uInt16 nId ) :
64 SfxEnumItem( nId )
66 SetFromRotation( nRotation, bStacked );
69 //------------------------------------------------------------------------
71 SfxItemPresentation SvxOrientationItem::GetPresentation
73 SfxItemPresentation ePres,
74 SfxMapUnit /*eCoreUnit*/,
75 SfxMapUnit /*ePresUnit*/,
76 OUString& rText, const IntlWrapper * ) const
78 switch ( ePres )
80 case SFX_ITEM_PRESENTATION_NONE:
81 rText = OUString();
82 return SFX_ITEM_PRESENTATION_NONE;
83 case SFX_ITEM_PRESENTATION_NAMELESS:
84 case SFX_ITEM_PRESENTATION_COMPLETE:
85 rText = GetValueText( GetValue() );
86 return SFX_ITEM_PRESENTATION_COMPLETE;
87 default: ; //prevent warning
89 return SFX_ITEM_PRESENTATION_NONE;
92 //------------------------------------------------------------------------
94 bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
96 table::CellOrientation eUno = table::CellOrientation_STANDARD;
97 switch ( (SvxCellOrientation)GetValue() )
99 case SVX_ORIENTATION_STANDARD: eUno = table::CellOrientation_STANDARD; break;
100 case SVX_ORIENTATION_TOPBOTTOM: eUno = table::CellOrientation_TOPBOTTOM; break;
101 case SVX_ORIENTATION_BOTTOMTOP: eUno = table::CellOrientation_BOTTOMTOP; break;
102 case SVX_ORIENTATION_STACKED: eUno = table::CellOrientation_STACKED; break;
104 rVal <<= eUno;
105 return true;
108 bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
110 table::CellOrientation eOrient;
111 if(!(rVal >>= eOrient))
113 sal_Int32 nValue = 0;
114 if(!(rVal >>= nValue))
115 return sal_False;
116 eOrient = (table::CellOrientation)nValue;
118 SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
119 switch (eOrient)
121 case table::CellOrientation_STANDARD: eSvx = SVX_ORIENTATION_STANDARD; break;
122 case table::CellOrientation_TOPBOTTOM: eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
123 case table::CellOrientation_BOTTOMTOP: eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
124 case table::CellOrientation_STACKED: eSvx = SVX_ORIENTATION_STACKED; break;
125 default: ; //prevent warning
127 SetValue( (sal_uInt16)eSvx );
128 return true;
131 //------------------------------------------------------------------------
133 XubString SvxOrientationItem::GetValueText( sal_uInt16 nVal ) const
135 DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
136 return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
139 //------------------------------------------------------------------------
141 SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
143 return new SvxOrientationItem( *this );
146 //------------------------------------------------------------------------
148 SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, sal_uInt16 ) const
150 sal_uInt16 nVal;
151 rStream >> nVal;
152 return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
155 //------------------------------------------------------------------------
157 sal_uInt16 SvxOrientationItem::GetValueCount() const
159 return SVX_ORIENTATION_STACKED + 1; // letzter Enum-Wert + 1
162 //------------------------------------------------------------------------
164 sal_Bool SvxOrientationItem::IsStacked() const
166 return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
169 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
171 sal_Int32 nAngle = nStdAngle;
172 switch( static_cast< SvxCellOrientation >( GetValue() ) )
174 case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;break;
175 case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;break;
176 default: ; //prevent warning
178 return nAngle;
181 void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation, sal_Bool bStacked )
183 if( bStacked )
185 SetValue( SVX_ORIENTATION_STACKED );
187 else switch( nRotation )
189 case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP ); break;
190 case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM ); break;
191 default: SetValue( SVX_ORIENTATION_STANDARD );
195 // class SvxMarginItem ---------------------------------------------------
197 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
199 SfxPoolItem( nId ),
201 nLeftMargin ( 20 ),
202 nTopMargin ( 20 ),
203 nRightMargin ( 20 ),
204 nBottomMargin( 20 )
208 //------------------------------------------------------------------------
210 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
211 sal_Int16 nTop,
212 sal_Int16 nRight,
213 sal_Int16 nBottom,
214 const sal_uInt16 nId ) :
215 SfxPoolItem( nId ),
217 nLeftMargin ( nLeft ),
218 nTopMargin ( nTop ),
219 nRightMargin ( nRight ),
220 nBottomMargin( nBottom )
225 //------------------------------------------------------------------------
227 SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
229 SfxPoolItem( rItem.Which() )
231 nLeftMargin = rItem.nLeftMargin;
232 nTopMargin = rItem.nTopMargin;
233 nRightMargin = rItem.nRightMargin;
234 nBottomMargin = rItem.nBottomMargin;
237 //------------------------------------------------------------------------
239 SfxItemPresentation SvxMarginItem::GetPresentation
241 SfxItemPresentation ePres,
242 SfxMapUnit eCoreUnit,
243 SfxMapUnit ePresUnit,
244 OUString& rText, const IntlWrapper *pIntl
245 ) const
247 OUString cpDelimTmp = OUString(cpDelim);
249 switch ( ePres )
251 case SFX_ITEM_PRESENTATION_NONE:
252 rText = OUString();
253 return SFX_ITEM_PRESENTATION_NONE;
254 case SFX_ITEM_PRESENTATION_NAMELESS:
256 rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
257 cpDelimTmp +
258 GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl ) +
259 cpDelimTmp +
260 GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl ) +
261 cpDelimTmp +
262 GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
263 return SFX_ITEM_PRESENTATION_NAMELESS;
265 case SFX_ITEM_PRESENTATION_COMPLETE:
267 rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT) +
268 GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
269 EE_RESSTR(GetMetricId(ePresUnit)) +
270 cpDelimTmp +
271 SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP) +
272 GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl ) +
273 EE_RESSTR(GetMetricId(ePresUnit)) +
274 cpDelimTmp +
275 SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT) +
276 GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl ) +
277 EE_RESSTR(GetMetricId(ePresUnit)) +
278 cpDelimTmp +
279 SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM) +
280 GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl ) +
281 EE_RESSTR(GetMetricId(ePresUnit));
282 return SFX_ITEM_PRESENTATION_COMPLETE;
284 default: ; //prevent warning
286 return SFX_ITEM_PRESENTATION_NONE;
289 //------------------------------------------------------------------------
291 int SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
293 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
295 return ( ( nLeftMargin == ( (SvxMarginItem&)rItem ).nLeftMargin ) &&
296 ( nTopMargin == ( (SvxMarginItem&)rItem ).nTopMargin ) &&
297 ( nRightMargin == ( (SvxMarginItem&)rItem ).nRightMargin ) &&
298 ( nBottomMargin == ( (SvxMarginItem&)rItem ).nBottomMargin ) );
301 //------------------------------------------------------------------------
303 SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
305 return new SvxMarginItem(*this);
308 //------------------------------------------------------------------------
310 SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, sal_uInt16 ) const
312 sal_Int16 nLeft;
313 sal_Int16 nTop;
314 sal_Int16 nRight;
315 sal_Int16 nBottom;
316 rStream >> nLeft;
317 rStream >> nTop;
318 rStream >> nRight;
319 rStream >> nBottom;
320 return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
323 //------------------------------------------------------------------------
325 SvStream& SvxMarginItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/) const
327 rStream << nLeftMargin;
328 rStream << nTopMargin;
329 rStream << nRightMargin;
330 rStream << nBottomMargin;
331 return rStream;
335 //------------------------------------------------------------------------
337 bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
339 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
340 nMemberId &= ~CONVERT_TWIPS;
341 switch ( nMemberId )
343 // jetzt alles signed
344 case MID_MARGIN_L_MARGIN:
345 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin );
346 break;
347 case MID_MARGIN_R_MARGIN:
348 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin );
349 break;
350 case MID_MARGIN_UP_MARGIN:
351 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nTopMargin) : nTopMargin );
352 break;
353 case MID_MARGIN_LO_MARGIN:
354 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nBottomMargin) : nBottomMargin );
355 break;
356 default:
357 OSL_FAIL("unknown MemberId");
358 return false;
360 return true;
363 //------------------------------------------------------------------------
365 bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
367 bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
368 long nMaxVal = bConvert ? TWIP_TO_MM100(SHRT_MAX) : SHRT_MAX; // Members sind sal_Int16
369 sal_Int32 nVal = 0;
370 if(!(rVal >>= nVal) || (nVal > nMaxVal))
371 return sal_False;
373 switch ( nMemberId & ~CONVERT_TWIPS )
375 case MID_MARGIN_L_MARGIN:
376 nLeftMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
377 break;
378 case MID_MARGIN_R_MARGIN:
379 nRightMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
380 break;
381 case MID_MARGIN_UP_MARGIN:
382 nTopMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
383 break;
384 case MID_MARGIN_LO_MARGIN:
385 nBottomMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
386 break;
387 default:
388 OSL_FAIL("unknown MemberId");
389 return false;
391 return true;
394 //------------------------------------------------------------------------
396 sal_Bool SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
398 nLeftMargin = nLeft;
399 return sal_True;
402 //------------------------------------------------------------------------
404 sal_Bool SvxMarginItem::SetTopMargin( sal_Int16 nTop )
406 nTopMargin = nTop;
407 return sal_True;
410 //------------------------------------------------------------------------
412 sal_Bool SvxMarginItem::SetRightMargin( sal_Int16 nRight )
414 nRightMargin = nRight;
415 return sal_True;
418 //------------------------------------------------------------------------
420 sal_Bool SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
422 nBottomMargin = nBottom;
423 return sal_True;
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */