merge the formfield patch from ooo-build
[ooovba.git] / svx / source / items / algitem.cxx
blob4ce57b6603498718fd6d0f924117f6a3169d7c0f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: algitem.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svxitems.hrc>
37 #include <tools/stream.hxx>
38 #include <com/sun/star/table/BorderLine.hpp>
39 #include <com/sun/star/table/CellVertJustify.hpp>
40 #include <com/sun/star/table/ShadowLocation.hpp>
41 #include <com/sun/star/table/TableBorder.hpp>
42 #include <com/sun/star/table/ShadowFormat.hpp>
43 #include <com/sun/star/table/CellRangeAddress.hpp>
44 #include <com/sun/star/table/CellContentType.hpp>
45 #include <com/sun/star/table/TableOrientation.hpp>
46 #include <com/sun/star/table/CellHoriJustify.hpp>
47 #include <com/sun/star/style/ParagraphAdjust.hpp>
48 #include "com/sun/star/style/VerticalAlignment.hpp"
49 #include <com/sun/star/util/SortField.hpp>
50 #include <com/sun/star/util/SortFieldType.hpp>
51 #include <com/sun/star/table/CellOrientation.hpp>
52 #include <com/sun/star/table/CellAddress.hpp>
54 #include <svx/algitem.hxx>
55 #include <svx/dialmgr.hxx>
56 #include <svx/itemtype.hxx>
57 #include <svx/unomid.hxx>
59 using namespace ::rtl;
60 using namespace ::com::sun::star;
62 // Konvertierung fuer UNO
63 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
64 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
66 // STATIC DATA -----------------------------------------------------------
68 //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
69 TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0))
70 TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
71 TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
72 TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
74 // class SvxHorJustifyItem -----------------------------------------------
77 SvxHorJustifyItem::SvxHorJustifyItem( const USHORT nId ) :
78 SfxEnumItem( nId, (USHORT)SVX_HOR_JUSTIFY_STANDARD )
82 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
83 const USHORT nId ) :
84 SfxEnumItem( nId, (USHORT)eJustify )
88 //------------------------------------------------------------------------
90 SfxItemPresentation SvxHorJustifyItem::GetPresentation
92 SfxItemPresentation ePres,
93 SfxMapUnit /*eCoreUnit*/,
94 SfxMapUnit /*ePresUnit*/,
95 XubString& rText, const IntlWrapper *) const
97 switch ( ePres )
99 case SFX_ITEM_PRESENTATION_NONE:
100 rText.Erase();
101 return SFX_ITEM_PRESENTATION_NONE;
102 case SFX_ITEM_PRESENTATION_NAMELESS:
103 case SFX_ITEM_PRESENTATION_COMPLETE:
104 rText = GetValueText( GetValue() );
105 return SFX_ITEM_PRESENTATION_COMPLETE;
106 default: ; //prevent warning
108 return SFX_ITEM_PRESENTATION_NONE;
111 //------------------------------------------------------------------------
113 sal_Bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
115 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
116 nMemberId &= ~CONVERT_TWIPS;
117 switch ( nMemberId )
119 case MID_HORJUST_HORJUST:
121 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
122 switch ( (SvxCellHorJustify)GetValue() )
124 case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
125 case SVX_HOR_JUSTIFY_LEFT: eUno = table::CellHoriJustify_LEFT; break;
126 case SVX_HOR_JUSTIFY_CENTER: eUno = table::CellHoriJustify_CENTER; break;
127 case SVX_HOR_JUSTIFY_RIGHT: eUno = table::CellHoriJustify_RIGHT; break;
128 case SVX_HOR_JUSTIFY_BLOCK: eUno = table::CellHoriJustify_BLOCK; break;
129 case SVX_HOR_JUSTIFY_REPEAT: eUno = table::CellHoriJustify_REPEAT; break;
131 rVal <<= eUno;
133 break;
134 case MID_HORJUST_ADJUST:
136 // ParagraphAdjust values, as in SvxAdjustItem
137 // (same value for ParaAdjust and ParaLastLineAdjust)
139 sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
140 switch ( (SvxCellHorJustify)GetValue() )
142 // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
143 case SVX_HOR_JUSTIFY_STANDARD:
144 case SVX_HOR_JUSTIFY_REPEAT:
145 case SVX_HOR_JUSTIFY_LEFT: nAdjust = style::ParagraphAdjust_LEFT; break;
146 case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
147 case SVX_HOR_JUSTIFY_RIGHT: nAdjust = style::ParagraphAdjust_RIGHT; break;
148 case SVX_HOR_JUSTIFY_BLOCK: nAdjust = style::ParagraphAdjust_BLOCK; break;
150 rVal <<= nAdjust; // as sal_Int16
152 break;
154 return sal_True;
157 sal_Bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, BYTE nMemberId )
159 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
160 nMemberId &= ~CONVERT_TWIPS;
161 switch ( nMemberId )
163 case MID_HORJUST_HORJUST:
165 table::CellHoriJustify eUno;
166 if(!(rVal >>= eUno))
168 sal_Int32 nValue = 0;
169 if(!(rVal >>= nValue))
170 return sal_False;
171 eUno = (table::CellHoriJustify)nValue;
173 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
174 switch (eUno)
176 case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
177 case table::CellHoriJustify_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
178 case table::CellHoriJustify_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
179 case table::CellHoriJustify_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
180 case table::CellHoriJustify_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
181 case table::CellHoriJustify_REPEAT: eSvx = SVX_HOR_JUSTIFY_REPEAT; break;
182 default: ; //prevent warning
184 SetValue( (USHORT)eSvx );
186 break;
187 case MID_HORJUST_ADJUST:
189 // property contains ParagraphAdjust values as sal_Int16
190 sal_Int16 nVal = sal_Int16();
191 if(!(rVal >>= nVal))
192 return sal_False;
194 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
195 switch (nVal)
197 // STRETCH is treated as BLOCK
198 case style::ParagraphAdjust_LEFT: eSvx = SVX_HOR_JUSTIFY_LEFT; break;
199 case style::ParagraphAdjust_RIGHT: eSvx = SVX_HOR_JUSTIFY_RIGHT; break;
200 case style::ParagraphAdjust_STRETCH:
201 case style::ParagraphAdjust_BLOCK: eSvx = SVX_HOR_JUSTIFY_BLOCK; break;
202 case style::ParagraphAdjust_CENTER: eSvx = SVX_HOR_JUSTIFY_CENTER; break;
204 SetValue( (USHORT)eSvx );
207 return sal_True;
210 //------------------------------------------------------------------------
212 XubString SvxHorJustifyItem::GetValueText( USHORT nVal ) const
214 DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
215 return SVX_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
218 //------------------------------------------------------------------------
220 SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
222 return new SvxHorJustifyItem( *this );
225 //------------------------------------------------------------------------
227 SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, USHORT ) const
229 USHORT nVal;
230 rStream >> nVal;
231 return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
233 //------------------------------------------------------------------------
235 USHORT SvxHorJustifyItem::GetValueCount() const
237 return SVX_HOR_JUSTIFY_REPEAT + 1; // letzter Enum-Wert + 1
240 // class SvxVerJustifyItem -----------------------------------------------
242 SvxVerJustifyItem::SvxVerJustifyItem( const USHORT nId ) :
243 SfxEnumItem( nId, (USHORT)SVX_VER_JUSTIFY_STANDARD )
247 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
248 const USHORT nId ) :
249 SfxEnumItem( nId, (USHORT)eJustify )
253 //------------------------------------------------------------------------
255 SfxItemPresentation SvxVerJustifyItem::GetPresentation
257 SfxItemPresentation ePres,
258 SfxMapUnit /*eCoreUnit*/,
259 SfxMapUnit /*ePresUnit*/,
260 XubString& rText,
261 const IntlWrapper * ) const
263 switch ( ePres )
265 case SFX_ITEM_PRESENTATION_NONE:
266 rText.Erase();
267 return SFX_ITEM_PRESENTATION_NONE;
268 case SFX_ITEM_PRESENTATION_NAMELESS:
269 case SFX_ITEM_PRESENTATION_COMPLETE:
270 rText = GetValueText( GetValue() );
271 return SFX_ITEM_PRESENTATION_COMPLETE;
272 default: ; //prevent warning
274 return SFX_ITEM_PRESENTATION_NONE;
277 //------------------------------------------------------------------------
279 sal_Bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
281 nMemberId &= ~CONVERT_TWIPS;
282 switch ( nMemberId )
284 case MID_HORJUST_ADJUST:
286 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
287 switch ( (SvxCellVerJustify)GetValue() )
289 case SVX_VER_JUSTIFY_TOP: eUno = style::VerticalAlignment_TOP; break;
290 case SVX_VER_JUSTIFY_CENTER: eUno = style::VerticalAlignment_MIDDLE; break;
291 case SVX_VER_JUSTIFY_BOTTOM: eUno = style::VerticalAlignment_BOTTOM; break;
292 default: ; //prevent warning
294 rVal <<= eUno;
295 break;
297 default:
299 table::CellVertJustify eUno = table::CellVertJustify_STANDARD;
300 switch ( (SvxCellVerJustify)GetValue() )
302 case SVX_VER_JUSTIFY_STANDARD: eUno = table::CellVertJustify_STANDARD; break;
303 case SVX_VER_JUSTIFY_TOP: eUno = table::CellVertJustify_TOP; break;
304 case SVX_VER_JUSTIFY_CENTER: eUno = table::CellVertJustify_CENTER; break;
305 case SVX_VER_JUSTIFY_BOTTOM: eUno = table::CellVertJustify_BOTTOM; break;
306 default: ; //prevent warning
308 rVal <<= eUno;
309 break;
312 return sal_True;
315 sal_Bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, BYTE nMemberId )
317 nMemberId &= ~CONVERT_TWIPS;
318 switch ( nMemberId )
320 case MID_HORJUST_ADJUST:
322 // property contains ParagraphAdjust values as sal_Int16
323 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
324 if(!(rVal >>= nVal))
325 return sal_False;
327 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
328 switch (nVal)
330 case style::VerticalAlignment_TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
331 case style::VerticalAlignment_MIDDLE: eSvx = SVX_VER_JUSTIFY_CENTER; break;
332 case style::VerticalAlignment_BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
333 default:;
335 SetValue( (USHORT)eSvx );
336 break;
338 default:
340 table::CellVertJustify eUno;
341 if(!(rVal >>= eUno))
343 sal_Int32 nValue = 0;
344 if(!(rVal >>= nValue))
345 return sal_False;
346 eUno = (table::CellVertJustify)nValue;
349 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
350 switch (eUno)
352 case table::CellVertJustify_STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD; break;
353 case table::CellVertJustify_TOP: eSvx = SVX_VER_JUSTIFY_TOP; break;
354 case table::CellVertJustify_CENTER: eSvx = SVX_VER_JUSTIFY_CENTER; break;
355 case table::CellVertJustify_BOTTOM: eSvx = SVX_VER_JUSTIFY_BOTTOM; break;
356 default: ; //prevent warning
358 SetValue( (USHORT)eSvx );
359 break;
363 return sal_True;
366 //------------------------------------------------------------------------
368 XubString SvxVerJustifyItem::GetValueText( USHORT nVal ) const
370 DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
371 return SVX_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
374 //------------------------------------------------------------------------
376 SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
378 return new SvxVerJustifyItem( *this );
381 //------------------------------------------------------------------------
383 SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, USHORT ) const
385 USHORT nVal;
386 rStream >> nVal;
387 return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
390 //------------------------------------------------------------------------
392 USHORT SvxVerJustifyItem::GetValueCount() const
394 return SVX_VER_JUSTIFY_BOTTOM + 1; // letzter Enum-Wert + 1
397 // class SvxOrientationItem ----------------------------------------------
399 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
400 const USHORT nId):
401 SfxEnumItem( nId, (USHORT)eOrientation )
405 SvxOrientationItem::SvxOrientationItem( INT32 nRotation, BOOL bStacked, const USHORT nId ) :
406 SfxEnumItem( nId )
408 SetFromRotation( nRotation, bStacked );
411 //------------------------------------------------------------------------
413 SfxItemPresentation SvxOrientationItem::GetPresentation
415 SfxItemPresentation ePres,
416 SfxMapUnit /*eCoreUnit*/,
417 SfxMapUnit /*ePresUnit*/,
418 XubString& rText, const IntlWrapper * ) const
420 switch ( ePres )
422 case SFX_ITEM_PRESENTATION_NONE:
423 rText.Erase();
424 return SFX_ITEM_PRESENTATION_NONE;
425 case SFX_ITEM_PRESENTATION_NAMELESS:
426 case SFX_ITEM_PRESENTATION_COMPLETE:
427 rText = GetValueText( GetValue() );
428 return SFX_ITEM_PRESENTATION_COMPLETE;
429 default: ; //prevent warning
431 return SFX_ITEM_PRESENTATION_NONE;
434 //------------------------------------------------------------------------
436 sal_Bool SvxOrientationItem::QueryValue( uno::Any& rVal, BYTE /*nMemberId*/ ) const
438 table::CellOrientation eUno = table::CellOrientation_STANDARD;
439 switch ( (SvxCellOrientation)GetValue() )
441 case SVX_ORIENTATION_STANDARD: eUno = table::CellOrientation_STANDARD; break;
442 case SVX_ORIENTATION_TOPBOTTOM: eUno = table::CellOrientation_TOPBOTTOM; break;
443 case SVX_ORIENTATION_BOTTOMTOP: eUno = table::CellOrientation_BOTTOMTOP; break;
444 case SVX_ORIENTATION_STACKED: eUno = table::CellOrientation_STACKED; break;
446 rVal <<= eUno;
447 return sal_True;
450 sal_Bool SvxOrientationItem::PutValue( const uno::Any& rVal, BYTE /*nMemberId*/ )
452 table::CellOrientation eOrient;
453 if(!(rVal >>= eOrient))
455 sal_Int32 nValue = 0;
456 if(!(rVal >>= nValue))
457 return sal_False;
458 eOrient = (table::CellOrientation)nValue;
460 SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
461 switch (eOrient)
463 case table::CellOrientation_STANDARD: eSvx = SVX_ORIENTATION_STANDARD; break;
464 case table::CellOrientation_TOPBOTTOM: eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
465 case table::CellOrientation_BOTTOMTOP: eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
466 case table::CellOrientation_STACKED: eSvx = SVX_ORIENTATION_STACKED; break;
467 default: ; //prevent warning
469 SetValue( (USHORT)eSvx );
470 return sal_True;
473 //------------------------------------------------------------------------
475 XubString SvxOrientationItem::GetValueText( USHORT nVal ) const
477 DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
478 return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
481 //------------------------------------------------------------------------
483 SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
485 return new SvxOrientationItem( *this );
488 //------------------------------------------------------------------------
490 SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, USHORT ) const
492 USHORT nVal;
493 rStream >> nVal;
494 return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
497 //------------------------------------------------------------------------
499 USHORT SvxOrientationItem::GetValueCount() const
501 return SVX_ORIENTATION_STACKED + 1; // letzter Enum-Wert + 1
504 //------------------------------------------------------------------------
506 BOOL SvxOrientationItem::IsStacked() const
508 return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
511 INT32 SvxOrientationItem::GetRotation( INT32 nStdAngle ) const
513 INT32 nAngle = nStdAngle;
514 switch( static_cast< SvxCellOrientation >( GetValue() ) )
516 case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;
517 case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;
518 default: ; //prevent warning
520 return nAngle;
523 void SvxOrientationItem::SetFromRotation( INT32 nRotation, BOOL bStacked )
525 if( bStacked )
527 SetValue( SVX_ORIENTATION_STACKED );
529 else switch( nRotation )
531 case 9000: SetValue( SVX_ORIENTATION_BOTTOMTOP ); break;
532 case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM ); break;
533 default: SetValue( SVX_ORIENTATION_STANDARD );
537 // class SvxMarginItem ---------------------------------------------------
539 SvxMarginItem::SvxMarginItem( const USHORT nId ) :
541 SfxPoolItem( nId ),
543 nLeftMargin ( 20 ),
544 nTopMargin ( 20 ),
545 nRightMargin ( 20 ),
546 nBottomMargin( 20 )
550 //------------------------------------------------------------------------
552 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
553 sal_Int16 nTop,
554 sal_Int16 nRight,
555 sal_Int16 nBottom,
556 const USHORT nId ) :
557 SfxPoolItem( nId ),
559 nLeftMargin ( nLeft ),
560 nTopMargin ( nTop ),
561 nRightMargin ( nRight ),
562 nBottomMargin( nBottom )
567 //------------------------------------------------------------------------
569 SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
571 SfxPoolItem( rItem.Which() )
573 nLeftMargin = rItem.nLeftMargin;
574 nTopMargin = rItem.nTopMargin;
575 nRightMargin = rItem.nRightMargin;
576 nBottomMargin = rItem.nBottomMargin;
579 //------------------------------------------------------------------------
581 SfxItemPresentation SvxMarginItem::GetPresentation
583 SfxItemPresentation ePres,
584 SfxMapUnit eCoreUnit,
585 SfxMapUnit ePresUnit,
586 XubString& rText, const IntlWrapper *pIntl
587 ) const
589 #ifndef SVX_LIGHT
590 switch ( ePres )
592 case SFX_ITEM_PRESENTATION_NONE:
593 rText.Erase();
594 return SFX_ITEM_PRESENTATION_NONE;
595 case SFX_ITEM_PRESENTATION_NAMELESS:
597 rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
598 rText += cpDelim;
599 rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
600 rText += cpDelim;
601 rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
602 rText += cpDelim;
603 rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
604 return SFX_ITEM_PRESENTATION_NAMELESS;
606 case SFX_ITEM_PRESENTATION_COMPLETE:
608 rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT);
609 rText += GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
610 rText += SVX_RESSTR(GetMetricId(ePresUnit));
611 rText += cpDelim;
612 rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP);
613 rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
614 rText += SVX_RESSTR(GetMetricId(ePresUnit));
615 rText += cpDelim;
616 rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT);
617 rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
618 rText += SVX_RESSTR(GetMetricId(ePresUnit));
619 rText += cpDelim;
620 rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM);
621 rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
622 rText += SVX_RESSTR(GetMetricId(ePresUnit));
623 return SFX_ITEM_PRESENTATION_COMPLETE;
625 default: ; //prevent warning
627 #endif
628 return SFX_ITEM_PRESENTATION_NONE;
631 //------------------------------------------------------------------------
633 int SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
635 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
637 return ( ( nLeftMargin == ( (SvxMarginItem&)rItem ).nLeftMargin ) &&
638 ( nTopMargin == ( (SvxMarginItem&)rItem ).nTopMargin ) &&
639 ( nRightMargin == ( (SvxMarginItem&)rItem ).nRightMargin ) &&
640 ( nBottomMargin == ( (SvxMarginItem&)rItem ).nBottomMargin ) );
643 //------------------------------------------------------------------------
645 SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
647 return new SvxMarginItem(*this);
650 //------------------------------------------------------------------------
652 SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, USHORT ) const
654 sal_Int16 nLeft;
655 sal_Int16 nTop;
656 sal_Int16 nRight;
657 sal_Int16 nBottom;
658 rStream >> nLeft;
659 rStream >> nTop;
660 rStream >> nRight;
661 rStream >> nBottom;
662 return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
665 //------------------------------------------------------------------------
667 SvStream& SvxMarginItem::Store( SvStream &rStream, USHORT /*nItemVersion*/) const
669 rStream << nLeftMargin;
670 rStream << nTopMargin;
671 rStream << nRightMargin;
672 rStream << nBottomMargin;
673 return rStream;
677 //------------------------------------------------------------------------
679 sal_Bool SvxMarginItem::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
681 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
682 nMemberId &= ~CONVERT_TWIPS;
683 switch ( nMemberId )
685 // jetzt alles signed
686 case MID_MARGIN_L_MARGIN:
687 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin );
688 break;
689 case MID_MARGIN_R_MARGIN:
690 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin );
691 break;
692 case MID_MARGIN_UP_MARGIN:
693 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nTopMargin) : nTopMargin );
694 break;
695 case MID_MARGIN_LO_MARGIN:
696 rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nBottomMargin) : nBottomMargin );
697 break;
698 default:
699 DBG_ERROR("unknown MemberId");
700 return sal_False;
702 return sal_True;
705 //------------------------------------------------------------------------
707 sal_Bool SvxMarginItem::PutValue( const uno::Any& rVal, BYTE nMemberId )
709 sal_Bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
710 long nMaxVal = bConvert ? TWIP_TO_MM100(SHRT_MAX) : SHRT_MAX; // Members sind sal_Int16
711 sal_Int32 nVal = 0;
712 if(!(rVal >>= nVal) || (nVal > nMaxVal))
713 return sal_False;
715 switch ( nMemberId & ~CONVERT_TWIPS )
717 case MID_MARGIN_L_MARGIN:
718 nLeftMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
719 break;
720 case MID_MARGIN_R_MARGIN:
721 nRightMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
722 break;
723 case MID_MARGIN_UP_MARGIN:
724 nTopMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
725 break;
726 case MID_MARGIN_LO_MARGIN:
727 nBottomMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
728 break;
729 default:
730 DBG_ERROR("unknown MemberId");
731 return sal_False;
733 return sal_True;
736 //------------------------------------------------------------------------
738 sal_Bool SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
740 nLeftMargin = nLeft;
741 return sal_True;
744 //------------------------------------------------------------------------
746 sal_Bool SvxMarginItem::SetTopMargin( sal_Int16 nTop )
748 nTopMargin = nTop;
749 return sal_True;
752 //------------------------------------------------------------------------
754 sal_Bool SvxMarginItem::SetRightMargin( sal_Int16 nRight )
756 nRightMargin = nRight;
757 return sal_True;
760 //------------------------------------------------------------------------
762 sal_Bool SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
764 nBottomMargin = nBottom;
765 return sal_True;