xref: /trunk/main/svx/source/items/algitem.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/svxitems.hrc>
32 
33 
34 #include <tools/stream.hxx>
35 #include <com/sun/star/table/BorderLine.hpp>
36 #include <com/sun/star/table/CellVertJustify.hpp>
37 #include <com/sun/star/table/ShadowLocation.hpp>
38 #include <com/sun/star/table/TableBorder.hpp>
39 #include <com/sun/star/table/ShadowFormat.hpp>
40 #include <com/sun/star/table/CellRangeAddress.hpp>
41 #include <com/sun/star/table/CellContentType.hpp>
42 #include <com/sun/star/table/TableOrientation.hpp>
43 #include <com/sun/star/table/CellHoriJustify.hpp>
44 #include <com/sun/star/style/ParagraphAdjust.hpp>
45 #include "com/sun/star/style/VerticalAlignment.hpp"
46 #include <com/sun/star/util/SortField.hpp>
47 #include <com/sun/star/util/SortFieldType.hpp>
48 #include <com/sun/star/table/CellOrientation.hpp>
49 #include <com/sun/star/table/CellAddress.hpp>
50 
51 #include <svx/algitem.hxx>
52 #include <svx/dialmgr.hxx>
53 #include <editeng/itemtype.hxx>
54 #include <svx/unomid.hxx>
55 
56 using namespace ::rtl;
57 using namespace ::com::sun::star;
58 
59 // Konvertierung fuer UNO
60 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
61 #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
62 
63 // STATIC DATA -----------------------------------------------------------
64 
65 //TYPEINIT1_AUTOFACTORY( SvxHorJustifyItem, SfxEnumItem );
66 TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0))
67 TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
68 TYPEINIT1_FACTORY( SvxOrientationItem, SfxEnumItem, new SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0) );
69 TYPEINIT1_FACTORY( SvxMarginItem, SfxPoolItem, new SvxMarginItem(0) );
70 
71 // class SvxHorJustifyItem -----------------------------------------------
72 
73 
74 SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
75     SfxEnumItem( nId, (sal_uInt16)SVX_HOR_JUSTIFY_STANDARD )
76 {
77 }
78 
79 SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
80                                       const sal_uInt16 nId ) :
81     SfxEnumItem( nId, (sal_uInt16)eJustify )
82 {
83 }
84 
85 //------------------------------------------------------------------------
86 
87 SfxItemPresentation SvxHorJustifyItem::GetPresentation
88 (
89     SfxItemPresentation ePres,
90     SfxMapUnit          /*eCoreUnit*/,
91     SfxMapUnit          /*ePresUnit*/,
92     XubString&              rText, const IntlWrapper *)    const
93 {
94     switch ( ePres )
95     {
96         case SFX_ITEM_PRESENTATION_NONE:
97             rText.Erase();
98             return SFX_ITEM_PRESENTATION_NONE;
99         case SFX_ITEM_PRESENTATION_NAMELESS:
100         case SFX_ITEM_PRESENTATION_COMPLETE:
101             rText = GetValueText( GetValue() );
102             return SFX_ITEM_PRESENTATION_COMPLETE;
103         default: ; //prevent warning
104     }
105     return SFX_ITEM_PRESENTATION_NONE;
106 }
107 
108 //------------------------------------------------------------------------
109 
110 sal_Bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
111 {
112 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
113     nMemberId &= ~CONVERT_TWIPS;
114     switch ( nMemberId )
115     {
116         case MID_HORJUST_HORJUST:
117             {
118                 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
119                 switch ( (SvxCellHorJustify)GetValue() )
120                 {
121                     case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
122                     case SVX_HOR_JUSTIFY_LEFT:     eUno = table::CellHoriJustify_LEFT;     break;
123                     case SVX_HOR_JUSTIFY_CENTER:   eUno = table::CellHoriJustify_CENTER;   break;
124                     case SVX_HOR_JUSTIFY_RIGHT:    eUno = table::CellHoriJustify_RIGHT;    break;
125                     case SVX_HOR_JUSTIFY_BLOCK:    eUno = table::CellHoriJustify_BLOCK;    break;
126                     case SVX_HOR_JUSTIFY_REPEAT:   eUno = table::CellHoriJustify_REPEAT;   break;
127                 }
128                 rVal <<= eUno;
129             }
130             break;
131         case MID_HORJUST_ADJUST:
132             {
133                 //  ParagraphAdjust values, as in SvxAdjustItem
134                 //  (same value for ParaAdjust and ParaLastLineAdjust)
135 
136                 sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
137                 switch ( (SvxCellHorJustify)GetValue() )
138                 {
139                     // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
140                     case SVX_HOR_JUSTIFY_STANDARD:
141                     case SVX_HOR_JUSTIFY_REPEAT:
142                     case SVX_HOR_JUSTIFY_LEFT:   nAdjust = style::ParagraphAdjust_LEFT;   break;
143                     case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
144                     case SVX_HOR_JUSTIFY_RIGHT:  nAdjust = style::ParagraphAdjust_RIGHT;  break;
145                     case SVX_HOR_JUSTIFY_BLOCK:  nAdjust = style::ParagraphAdjust_BLOCK;  break;
146                 }
147                 rVal <<= nAdjust;       // as sal_Int16
148             }
149             break;
150     }
151     return sal_True;
152 }
153 
154 sal_Bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
155 {
156 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
157     nMemberId &= ~CONVERT_TWIPS;
158     switch ( nMemberId )
159     {
160         case MID_HORJUST_HORJUST:
161             {
162                 table::CellHoriJustify eUno;
163                 if(!(rVal >>= eUno))
164                 {
165                     sal_Int32 nValue = 0;
166                     if(!(rVal >>= nValue))
167                         return sal_False;
168                     eUno = (table::CellHoriJustify)nValue;
169                 }
170                 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
171                 switch (eUno)
172                 {
173                     case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
174                     case table::CellHoriJustify_LEFT:     eSvx = SVX_HOR_JUSTIFY_LEFT;     break;
175                     case table::CellHoriJustify_CENTER:   eSvx = SVX_HOR_JUSTIFY_CENTER;   break;
176                     case table::CellHoriJustify_RIGHT:    eSvx = SVX_HOR_JUSTIFY_RIGHT;    break;
177                     case table::CellHoriJustify_BLOCK:    eSvx = SVX_HOR_JUSTIFY_BLOCK;    break;
178                     case table::CellHoriJustify_REPEAT:   eSvx = SVX_HOR_JUSTIFY_REPEAT;   break;
179                     default: ; //prevent warning
180                 }
181                 SetValue( (sal_uInt16)eSvx );
182             }
183             break;
184         case MID_HORJUST_ADJUST:
185             {
186                 //  property contains ParagraphAdjust values as sal_Int16
187                 sal_Int16 nVal = sal_Int16();
188                 if(!(rVal >>= nVal))
189                     return sal_False;
190 
191                 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
192                 switch (nVal)
193                 {
194                     //  STRETCH is treated as BLOCK
195                     case style::ParagraphAdjust_LEFT:    eSvx = SVX_HOR_JUSTIFY_LEFT;   break;
196                     case style::ParagraphAdjust_RIGHT:   eSvx = SVX_HOR_JUSTIFY_RIGHT;  break;
197                     case style::ParagraphAdjust_STRETCH:
198                     case style::ParagraphAdjust_BLOCK:   eSvx = SVX_HOR_JUSTIFY_BLOCK;  break;
199                     case style::ParagraphAdjust_CENTER:  eSvx = SVX_HOR_JUSTIFY_CENTER; break;
200                 }
201                 SetValue( (sal_uInt16)eSvx );
202             }
203     }
204     return sal_True;
205 }
206 
207 //------------------------------------------------------------------------
208 
209 XubString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal ) const
210 {
211     DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
212     return SVX_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
213 }
214 
215 //------------------------------------------------------------------------
216 
217 SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
218 {
219     return new SvxHorJustifyItem( *this );
220 }
221 
222 //------------------------------------------------------------------------
223 
224 SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
225 {
226     sal_uInt16 nVal;
227     rStream >> nVal;
228     return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
229 }
230 //------------------------------------------------------------------------
231 
232 sal_uInt16 SvxHorJustifyItem::GetValueCount() const
233 {
234     return SVX_HOR_JUSTIFY_REPEAT + 1;  // letzter Enum-Wert + 1
235 }
236 
237 // class SvxVerJustifyItem -----------------------------------------------
238 
239 SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
240     SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
241 {
242 }
243 
244 SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
245                                       const sal_uInt16 nId ) :
246     SfxEnumItem( nId, (sal_uInt16)eJustify )
247 {
248 }
249 
250 //------------------------------------------------------------------------
251 
252 SfxItemPresentation SvxVerJustifyItem::GetPresentation
253 (
254     SfxItemPresentation ePres,
255     SfxMapUnit          /*eCoreUnit*/,
256     SfxMapUnit          /*ePresUnit*/,
257     XubString&              rText,
258     const IntlWrapper * )    const
259 {
260     switch ( ePres )
261     {
262         case SFX_ITEM_PRESENTATION_NONE:
263             rText.Erase();
264             return SFX_ITEM_PRESENTATION_NONE;
265         case SFX_ITEM_PRESENTATION_NAMELESS:
266         case SFX_ITEM_PRESENTATION_COMPLETE:
267             rText = GetValueText( GetValue() );
268             return SFX_ITEM_PRESENTATION_COMPLETE;
269         default: ; //prevent warning
270     }
271     return SFX_ITEM_PRESENTATION_NONE;
272 }
273 
274 //------------------------------------------------------------------------
275 
276 sal_Bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
277 {
278     nMemberId &= ~CONVERT_TWIPS;
279     switch ( nMemberId )
280     {
281         case MID_HORJUST_ADJUST:
282             {
283                 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
284                 switch ( (SvxCellVerJustify)GetValue() )
285                 {
286                     case SVX_VER_JUSTIFY_TOP:      eUno = style::VerticalAlignment_TOP;     break;
287                     case SVX_VER_JUSTIFY_CENTER:   eUno = style::VerticalAlignment_MIDDLE;  break;
288                     case SVX_VER_JUSTIFY_BOTTOM:   eUno = style::VerticalAlignment_BOTTOM;  break;
289                     default: ; //prevent warning
290                 }
291                 rVal <<= eUno;
292                 break;
293             }
294         default:
295             {
296                 table::CellVertJustify eUno = table::CellVertJustify_STANDARD;
297                 switch ( (SvxCellVerJustify)GetValue() )
298                 {
299                     case SVX_VER_JUSTIFY_STANDARD: eUno = table::CellVertJustify_STANDARD; break;
300                     case SVX_VER_JUSTIFY_TOP:      eUno = table::CellVertJustify_TOP;       break;
301                     case SVX_VER_JUSTIFY_CENTER:   eUno = table::CellVertJustify_CENTER;    break;
302                     case SVX_VER_JUSTIFY_BOTTOM:   eUno = table::CellVertJustify_BOTTOM;    break;
303                     default: ; //prevent warning
304                 }
305                 rVal <<= eUno;
306                 break;
307             }
308     }
309     return sal_True;
310 }
311 
312 sal_Bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
313 {
314     nMemberId &= ~CONVERT_TWIPS;
315     switch ( nMemberId )
316     {
317         case MID_HORJUST_ADJUST:
318             {
319                 //  property contains ParagraphAdjust values as sal_Int16
320                 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
321                 if(!(rVal >>= nVal))
322                     return sal_False;
323 
324                 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
325                 switch (nVal)
326                 {
327                     case style::VerticalAlignment_TOP:      eSvx = SVX_VER_JUSTIFY_TOP;     break;
328                     case style::VerticalAlignment_MIDDLE:   eSvx = SVX_VER_JUSTIFY_CENTER;  break;
329                     case style::VerticalAlignment_BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;  break;
330                     default:;
331                 }
332                 SetValue( (sal_uInt16)eSvx );
333                 break;
334             }
335         default:
336             {
337                 table::CellVertJustify eUno;
338                 if(!(rVal >>= eUno))
339                 {
340                     sal_Int32 nValue = 0;
341                     if(!(rVal >>= nValue))
342                         return sal_False;
343                     eUno = (table::CellVertJustify)nValue;
344                 }
345 
346                 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
347                 switch (eUno)
348                 {
349                     case table::CellVertJustify_STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD;  break;
350                     case table::CellVertJustify_TOP:      eSvx = SVX_VER_JUSTIFY_TOP;       break;
351                     case table::CellVertJustify_CENTER:   eSvx = SVX_VER_JUSTIFY_CENTER;    break;
352                     case table::CellVertJustify_BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;    break;
353                     default: ; //prevent warning
354                 }
355                 SetValue( (sal_uInt16)eSvx );
356                 break;
357             }
358     }
359 
360     return sal_True;
361 }
362 
363 //------------------------------------------------------------------------
364 
365 XubString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal ) const
366 {
367     DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
368     return SVX_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
369 }
370 
371 //------------------------------------------------------------------------
372 
373 SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
374 {
375     return new SvxVerJustifyItem( *this );
376 }
377 
378 //------------------------------------------------------------------------
379 
380 SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
381 {
382     sal_uInt16 nVal;
383     rStream >> nVal;
384     return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
385 }
386 
387 //------------------------------------------------------------------------
388 
389 sal_uInt16 SvxVerJustifyItem::GetValueCount() const
390 {
391     return SVX_VER_JUSTIFY_BOTTOM + 1;  // letzter Enum-Wert + 1
392 }
393 
394 // class SvxOrientationItem ----------------------------------------------
395 
396 SvxOrientationItem::SvxOrientationItem( const SvxCellOrientation eOrientation,
397                                         const sal_uInt16 nId):
398     SfxEnumItem( nId, (sal_uInt16)eOrientation )
399 {
400 }
401 
402 SvxOrientationItem::SvxOrientationItem( sal_Int32 nRotation, sal_Bool bStacked, const sal_uInt16 nId ) :
403     SfxEnumItem( nId )
404 {
405     SetFromRotation( nRotation, bStacked );
406 }
407 
408 //------------------------------------------------------------------------
409 
410 SfxItemPresentation SvxOrientationItem::GetPresentation
411 (
412     SfxItemPresentation ePres,
413     SfxMapUnit          /*eCoreUnit*/,
414     SfxMapUnit          /*ePresUnit*/,
415     XubString&              rText, const IntlWrapper * ) const
416 {
417     switch ( ePres )
418     {
419         case SFX_ITEM_PRESENTATION_NONE:
420             rText.Erase();
421             return SFX_ITEM_PRESENTATION_NONE;
422         case SFX_ITEM_PRESENTATION_NAMELESS:
423         case SFX_ITEM_PRESENTATION_COMPLETE:
424             rText = GetValueText( GetValue() );
425             return SFX_ITEM_PRESENTATION_COMPLETE;
426         default: ; //prevent warning
427     }
428     return SFX_ITEM_PRESENTATION_NONE;
429 }
430 
431 //------------------------------------------------------------------------
432 
433 sal_Bool SvxOrientationItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
434 {
435     table::CellOrientation eUno = table::CellOrientation_STANDARD;
436     switch ( (SvxCellOrientation)GetValue() )
437     {
438     case SVX_ORIENTATION_STANDARD:  eUno = table::CellOrientation_STANDARD;  break;
439     case SVX_ORIENTATION_TOPBOTTOM: eUno = table::CellOrientation_TOPBOTTOM; break;
440     case SVX_ORIENTATION_BOTTOMTOP: eUno = table::CellOrientation_BOTTOMTOP; break;
441     case SVX_ORIENTATION_STACKED:   eUno = table::CellOrientation_STACKED;    break;
442     }
443     rVal <<= eUno;
444     return sal_True;
445 }
446 
447 sal_Bool SvxOrientationItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
448 {
449     table::CellOrientation eOrient;
450     if(!(rVal >>= eOrient))
451     {
452         sal_Int32 nValue = 0;
453         if(!(rVal >>= nValue))
454             return sal_False;
455         eOrient = (table::CellOrientation)nValue;
456     }
457     SvxCellOrientation eSvx = SVX_ORIENTATION_STANDARD;
458     switch (eOrient)
459     {
460         case table::CellOrientation_STANDARD:   eSvx = SVX_ORIENTATION_STANDARD;  break;
461         case table::CellOrientation_TOPBOTTOM:  eSvx = SVX_ORIENTATION_TOPBOTTOM; break;
462         case table::CellOrientation_BOTTOMTOP:  eSvx = SVX_ORIENTATION_BOTTOMTOP; break;
463         case table::CellOrientation_STACKED:    eSvx = SVX_ORIENTATION_STACKED;   break;
464         default: ; //prevent warning
465     }
466     SetValue( (sal_uInt16)eSvx );
467     return sal_True;
468 }
469 
470 //------------------------------------------------------------------------
471 
472 XubString SvxOrientationItem::GetValueText( sal_uInt16 nVal ) const
473 {
474     DBG_ASSERT( nVal <= SVX_ORIENTATION_STACKED, "enum overflow!" );
475     return SVX_RESSTR(RID_SVXITEMS_ORI_STANDARD + nVal);
476 }
477 
478 //------------------------------------------------------------------------
479 
480 SfxPoolItem* SvxOrientationItem::Clone( SfxItemPool* ) const
481 {
482     return new SvxOrientationItem( *this );
483 }
484 
485 //------------------------------------------------------------------------
486 
487 SfxPoolItem* SvxOrientationItem::Create( SvStream& rStream, sal_uInt16 ) const
488 {
489     sal_uInt16 nVal;
490     rStream >> nVal;
491     return new SvxOrientationItem( (SvxCellOrientation)nVal, Which() );
492 }
493 
494 //------------------------------------------------------------------------
495 
496 sal_uInt16 SvxOrientationItem::GetValueCount() const
497 {
498     return SVX_ORIENTATION_STACKED + 1; // letzter Enum-Wert + 1
499 }
500 
501 //------------------------------------------------------------------------
502 
503 sal_Bool SvxOrientationItem::IsStacked() const
504 {
505     return static_cast< SvxCellOrientation >( GetValue() ) == SVX_ORIENTATION_STACKED;
506 }
507 
508 sal_Int32 SvxOrientationItem::GetRotation( sal_Int32 nStdAngle ) const
509 {
510     sal_Int32 nAngle = nStdAngle;
511     switch( static_cast< SvxCellOrientation >( GetValue() ) )
512     {
513         case SVX_ORIENTATION_BOTTOMTOP: nAngle = 9000;
514         case SVX_ORIENTATION_TOPBOTTOM: nAngle = 27000;
515         default: ; //prevent warning
516     }
517     return nAngle;
518 }
519 
520 void SvxOrientationItem::SetFromRotation( sal_Int32 nRotation, sal_Bool bStacked )
521 {
522     if( bStacked )
523     {
524         SetValue( SVX_ORIENTATION_STACKED );
525     }
526     else switch( nRotation )
527     {
528         case 9000:  SetValue( SVX_ORIENTATION_BOTTOMTOP );  break;
529         case 27000: SetValue( SVX_ORIENTATION_TOPBOTTOM );  break;
530         default:    SetValue( SVX_ORIENTATION_STANDARD );
531     }
532 }
533 
534 // class SvxMarginItem ---------------------------------------------------
535 
536 SvxMarginItem::SvxMarginItem( const sal_uInt16 nId ) :
537 
538     SfxPoolItem( nId ),
539 
540     nLeftMargin  ( 20 ),
541     nTopMargin   ( 20 ),
542     nRightMargin ( 20 ),
543     nBottomMargin( 20 )
544 {
545 }
546 
547 //------------------------------------------------------------------------
548 
549 SvxMarginItem::SvxMarginItem( sal_Int16 nLeft,
550                               sal_Int16 nTop,
551                               sal_Int16 nRight,
552                               sal_Int16 nBottom,
553                               const sal_uInt16 nId ) :
554     SfxPoolItem( nId ),
555 
556     nLeftMargin  ( nLeft ),
557     nTopMargin   ( nTop ),
558     nRightMargin ( nRight ),
559     nBottomMargin( nBottom )
560 {
561 }
562 
563 
564 //------------------------------------------------------------------------
565 
566 SvxMarginItem::SvxMarginItem( const SvxMarginItem& rItem ) :
567 
568     SfxPoolItem( rItem.Which() )
569 {
570     nLeftMargin = rItem.nLeftMargin;
571     nTopMargin = rItem.nTopMargin;
572     nRightMargin = rItem.nRightMargin;
573     nBottomMargin = rItem.nBottomMargin;
574 }
575 
576 //------------------------------------------------------------------------
577 
578 SfxItemPresentation SvxMarginItem::GetPresentation
579 (
580     SfxItemPresentation ePres,
581     SfxMapUnit          eCoreUnit,
582     SfxMapUnit          ePresUnit,
583     XubString&          rText, const IntlWrapper *pIntl
584 )   const
585 {
586 #ifndef SVX_LIGHT
587     switch ( ePres )
588     {
589         case SFX_ITEM_PRESENTATION_NONE:
590             rText.Erase();
591             return SFX_ITEM_PRESENTATION_NONE;
592         case SFX_ITEM_PRESENTATION_NAMELESS:
593         {
594             rText = GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
595             rText += cpDelim;
596             rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
597             rText += cpDelim;
598             rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
599             rText += cpDelim;
600             rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
601             return SFX_ITEM_PRESENTATION_NAMELESS;
602         }
603         case SFX_ITEM_PRESENTATION_COMPLETE:
604         {
605             rText = SVX_RESSTR(RID_SVXITEMS_MARGIN_LEFT);
606             rText += GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl );
607             rText += SVX_RESSTR(GetMetricId(ePresUnit));
608             rText += cpDelim;
609             rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_TOP);
610             rText += GetMetricText( (long)nTopMargin, eCoreUnit, ePresUnit, pIntl );
611             rText += SVX_RESSTR(GetMetricId(ePresUnit));
612             rText += cpDelim;
613             rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_RIGHT);
614             rText += GetMetricText( (long)nRightMargin, eCoreUnit, ePresUnit, pIntl );
615             rText += SVX_RESSTR(GetMetricId(ePresUnit));
616             rText += cpDelim;
617             rText += SVX_RESSTR(RID_SVXITEMS_MARGIN_BOTTOM);
618             rText += GetMetricText( (long)nBottomMargin, eCoreUnit, ePresUnit, pIntl );
619             rText += SVX_RESSTR(GetMetricId(ePresUnit));
620             return SFX_ITEM_PRESENTATION_COMPLETE;
621         }
622         default: ; //prevent warning
623     }
624 #endif
625     return SFX_ITEM_PRESENTATION_NONE;
626 }
627 
628 //------------------------------------------------------------------------
629 
630 int SvxMarginItem::operator==( const SfxPoolItem& rItem ) const
631 {
632     DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
633 
634     return ( ( nLeftMargin == ( (SvxMarginItem&)rItem ).nLeftMargin )   &&
635              ( nTopMargin == ( (SvxMarginItem&)rItem ).nTopMargin )     &&
636              ( nRightMargin == ( (SvxMarginItem&)rItem ).nRightMargin ) &&
637              ( nBottomMargin == ( (SvxMarginItem&)rItem ).nBottomMargin ) );
638 }
639 
640 //------------------------------------------------------------------------
641 
642 SfxPoolItem* SvxMarginItem::Clone( SfxItemPool* ) const
643 {
644     return new SvxMarginItem(*this);
645 }
646 
647 //------------------------------------------------------------------------
648 
649 SfxPoolItem* SvxMarginItem::Create( SvStream& rStream, sal_uInt16 ) const
650 {
651     sal_Int16   nLeft;
652     sal_Int16   nTop;
653     sal_Int16   nRight;
654     sal_Int16   nBottom;
655     rStream >> nLeft;
656     rStream >> nTop;
657     rStream >> nRight;
658     rStream >> nBottom;
659     return new SvxMarginItem( nLeft, nTop, nRight, nBottom, Which() );
660 }
661 
662 //------------------------------------------------------------------------
663 
664 SvStream& SvxMarginItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/) const
665 {
666     rStream << nLeftMargin;
667     rStream << nTopMargin;
668     rStream << nRightMargin;
669     rStream << nBottomMargin;
670     return rStream;
671 }
672 
673 
674 //------------------------------------------------------------------------
675 
676 sal_Bool SvxMarginItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
677 {
678     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
679     nMemberId &= ~CONVERT_TWIPS;
680     switch ( nMemberId )
681     {
682         //  jetzt alles signed
683         case MID_MARGIN_L_MARGIN:
684             rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin );
685             break;
686         case MID_MARGIN_R_MARGIN:
687             rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin );
688             break;
689         case MID_MARGIN_UP_MARGIN:
690             rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nTopMargin) : nTopMargin );
691             break;
692         case MID_MARGIN_LO_MARGIN:
693             rVal <<= (sal_Int32)( bConvert ? TWIP_TO_MM100(nBottomMargin) : nBottomMargin );
694             break;
695         default:
696             DBG_ERROR("unknown MemberId");
697             return sal_False;
698     }
699     return sal_True;
700 }
701 
702 //------------------------------------------------------------------------
703 
704 sal_Bool SvxMarginItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
705 {
706     sal_Bool bConvert = ( ( nMemberId & CONVERT_TWIPS ) != 0 );
707     long nMaxVal = bConvert ? TWIP_TO_MM100(SHRT_MAX) : SHRT_MAX;   // Members sind sal_Int16
708     sal_Int32 nVal = 0;
709     if(!(rVal >>= nVal) || (nVal > nMaxVal))
710         return sal_False;
711 
712     switch ( nMemberId & ~CONVERT_TWIPS )
713     {
714         case MID_MARGIN_L_MARGIN:
715             nLeftMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
716             break;
717         case MID_MARGIN_R_MARGIN:
718             nRightMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
719             break;
720         case MID_MARGIN_UP_MARGIN:
721             nTopMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
722             break;
723         case MID_MARGIN_LO_MARGIN:
724             nBottomMargin = (sal_Int16)( bConvert ? MM100_TO_TWIP(nVal) : nVal );
725             break;
726         default:
727             DBG_ERROR("unknown MemberId");
728             return sal_False;
729     }
730     return sal_True;
731 }
732 
733 //------------------------------------------------------------------------
734 
735 sal_Bool SvxMarginItem::SetLeftMargin( sal_Int16 nLeft )
736 {
737     nLeftMargin = nLeft;
738     return sal_True;
739 }
740 
741 //------------------------------------------------------------------------
742 
743 sal_Bool SvxMarginItem::SetTopMargin( sal_Int16 nTop )
744 {
745     nTopMargin = nTop;
746     return sal_True;
747 }
748 
749 //------------------------------------------------------------------------
750 
751 sal_Bool SvxMarginItem::SetRightMargin( sal_Int16 nRight )
752 {
753     nRightMargin = nRight;
754     return sal_True;
755 }
756 
757 //------------------------------------------------------------------------
758 
759 sal_Bool SvxMarginItem::SetBottomMargin( sal_Int16 nBottom )
760 {
761     nBottomMargin = nBottom;
762     return sal_True;
763 }
764 
765 
766