1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rulritem.cxx,v $
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"
33 #include <tools/string.hxx>
35 #include <svx/dialogs.hrc>
36 #include "rulritem.hxx"
37 #include <com/sun/star/awt/Rectangle.hpp>
38 #include <com/sun/star/frame/status/LeftRightMargin.hpp>
39 #include <com/sun/star/frame/status/UpperLowerMargin.hpp>
41 //------------------------------------------------------------------------
43 TYPEINIT1_AUTOFACTORY(SvxPagePosSizeItem
, SfxPoolItem
);
44 TYPEINIT1_AUTOFACTORY(SvxLongLRSpaceItem
, SfxPoolItem
);
45 TYPEINIT1_AUTOFACTORY(SvxLongULSpaceItem
, SfxPoolItem
);
46 TYPEINIT1(SvxColumnItem
, SfxPoolItem
);
47 TYPEINIT1(SvxObjectItem
, SfxPoolItem
);
49 //------------------------------------------------------------------------
51 int SvxLongLRSpaceItem::operator==( const SfxPoolItem
& rCmp
) const
53 return SfxPoolItem::operator==(rCmp
) &&
54 lLeft
==((const SvxLongLRSpaceItem
&)rCmp
).lLeft
&&
55 lRight
==((const SvxLongLRSpaceItem
&)rCmp
).lRight
;
59 //------------------------------------------------------------------------
61 String
SvxLongLRSpaceItem::GetValueText() const
66 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
67 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
69 sal_Bool
SvxLongLRSpaceItem::QueryValue( ::com::sun::star::uno::Any
& rVal
, BYTE nMemberId
) const
71 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
72 nMemberId
&= ~CONVERT_TWIPS
;
79 ::com::sun::star::frame::status::LeftRightMargin aLeftRightMargin
;
80 aLeftRightMargin
.Left
= bConvert
? TWIP_TO_MM100( lLeft
) : lLeft
;
81 aLeftRightMargin
.Right
= bConvert
? TWIP_TO_MM100( lRight
) : lRight
;
82 rVal
<<= aLeftRightMargin
;
86 case MID_LEFT
: nVal
= lLeft
; break;
87 case MID_RIGHT
: nVal
= lRight
; break;
88 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
92 nVal
= TWIP_TO_MM100( nVal
);
98 // -----------------------------------------------------------------------
99 sal_Bool
SvxLongLRSpaceItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, BYTE nMemberId
)
101 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
102 nMemberId
&= ~CONVERT_TWIPS
;
105 if ( nMemberId
== 0 )
107 ::com::sun::star::frame::status::LeftRightMargin aLeftRightMargin
;
108 if ( rVal
>>= aLeftRightMargin
)
110 lLeft
= bConvert
? MM100_TO_TWIP( aLeftRightMargin
.Left
) : aLeftRightMargin
.Left
;
111 lRight
= bConvert
? MM100_TO_TWIP( aLeftRightMargin
.Right
) : aLeftRightMargin
.Right
;
115 else if ( rVal
>>= nVal
)
118 nVal
= MM100_TO_TWIP( nVal
);
122 case MID_LEFT
: lLeft
= nVal
; break;
123 case MID_RIGHT
: lRight
= nVal
; break;
124 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
133 //------------------------------------------------------------------------
135 SfxItemPresentation
SvxLongLRSpaceItem::GetPresentation
137 SfxItemPresentation
/*ePres*/,
138 SfxMapUnit
/*eCoreUnit*/,
139 SfxMapUnit
/*ePresUnit*/,
140 String
& /*rText*/, const IntlWrapper
*
144 return SFX_ITEM_PRESENTATION_NONE
;
147 //------------------------------------------------------------------------
149 SfxPoolItem
* SvxLongLRSpaceItem::Clone(SfxItemPool
*) const
151 return new SvxLongLRSpaceItem(*this);
154 //------------------------------------------------------------------------
156 SvxLongLRSpaceItem::SvxLongLRSpaceItem(long lL
, long lR
, USHORT nId
)
162 //------------------------------------------------------------------------
164 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
170 //------------------------------------------------------------------------
172 SvxLongLRSpaceItem::SvxLongLRSpaceItem(const SvxLongLRSpaceItem
&rCpy
)
178 //------------------------------------------------------------------------
180 int SvxLongULSpaceItem::operator==( const SfxPoolItem
& rCmp
) const
182 return SfxPoolItem::operator==(rCmp
) &&
183 lLeft
==((const SvxLongULSpaceItem
&)rCmp
).lLeft
&&
184 lRight
==((const SvxLongULSpaceItem
&)rCmp
).lRight
;
188 //------------------------------------------------------------------------
190 String
SvxLongULSpaceItem::GetValueText() const
195 sal_Bool
SvxLongULSpaceItem::QueryValue( ::com::sun::star::uno::Any
& rVal
, BYTE nMemberId
) const
197 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
198 nMemberId
&= ~CONVERT_TWIPS
;
205 ::com::sun::star::frame::status::UpperLowerMargin aUpperLowerMargin
;
206 aUpperLowerMargin
.Upper
= bConvert
? TWIP_TO_MM100( lLeft
) : lLeft
;
207 aUpperLowerMargin
.Lower
= bConvert
? TWIP_TO_MM100( lRight
) : lRight
;
208 rVal
<<= aUpperLowerMargin
;
212 case MID_UPPER
: nVal
= lLeft
; break;
213 case MID_LOWER
: nVal
= lRight
; break;
214 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
218 nVal
= TWIP_TO_MM100( nVal
);
224 // -----------------------------------------------------------------------
225 sal_Bool
SvxLongULSpaceItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, BYTE nMemberId
)
227 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
228 nMemberId
&= ~CONVERT_TWIPS
;
231 if ( nMemberId
== 0 )
233 ::com::sun::star::frame::status::UpperLowerMargin aUpperLowerMargin
;
234 if ( rVal
>>= aUpperLowerMargin
)
236 lLeft
= bConvert
? MM100_TO_TWIP( aUpperLowerMargin
.Upper
) : aUpperLowerMargin
.Upper
;
237 lRight
= bConvert
? MM100_TO_TWIP( aUpperLowerMargin
.Lower
) : aUpperLowerMargin
.Lower
;
241 else if ( rVal
>>= nVal
)
244 nVal
= MM100_TO_TWIP( nVal
);
248 case MID_UPPER
: lLeft
= nVal
; break;
249 case MID_LOWER
: lRight
= nVal
; break;
250 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
259 //------------------------------------------------------------------------
261 SfxItemPresentation
SvxLongULSpaceItem::GetPresentation
263 SfxItemPresentation
/*ePres*/,
264 SfxMapUnit
/*eCoreUnit*/,
265 SfxMapUnit
/*ePresUnit*/,
266 String
& /*rText*/, const IntlWrapper
*
269 return SFX_ITEM_PRESENTATION_NONE
;
272 //------------------------------------------------------------------------
274 SfxPoolItem
* SvxLongULSpaceItem::Clone(SfxItemPool
*) const
276 return new SvxLongULSpaceItem(*this);
279 //------------------------------------------------------------------------
281 SvxLongULSpaceItem::SvxLongULSpaceItem(long lL
, long lR
, USHORT nId
)
287 //------------------------------------------------------------------------
289 SvxLongULSpaceItem::SvxLongULSpaceItem(const SvxLongULSpaceItem
&rCpy
)
295 //------------------------------------------------------------------------
297 SvxLongULSpaceItem::SvxLongULSpaceItem() :
303 //------------------------------------------------------------------------
305 int SvxPagePosSizeItem::operator==( const SfxPoolItem
& rCmp
) const
307 return SfxPoolItem::operator==(rCmp
) &&
308 aPos
== ((const SvxPagePosSizeItem
&)rCmp
).aPos
&&
309 lWidth
== ((const SvxPagePosSizeItem
&)rCmp
).lWidth
&&
310 lHeight
== ((const SvxPagePosSizeItem
&)rCmp
).lHeight
;
313 sal_Bool
SvxPagePosSizeItem::QueryValue( ::com::sun::star::uno::Any
& rVal
, BYTE nMemberId
) const
315 nMemberId
&= ~CONVERT_TWIPS
;
322 com::sun::star::awt::Rectangle aPagePosSize
;
323 aPagePosSize
.X
= aPos
.X();
324 aPagePosSize
.Y
= aPos
.Y();
325 aPagePosSize
.Width
= lWidth
;
326 aPagePosSize
.Height
= lHeight
;
327 rVal
<<= aPagePosSize
;
331 case MID_X
: nVal
= aPos
.X(); break;
332 case MID_Y
: nVal
= aPos
.Y(); break;
333 case MID_WIDTH
: nVal
= lWidth
; break;
334 case MID_HEIGHT
: nVal
= lHeight
; break;
336 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
343 sal_Bool
SvxPagePosSizeItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, BYTE nMemberId
)
345 nMemberId
&= ~CONVERT_TWIPS
;
348 if ( nMemberId
== 0 )
350 com::sun::star::awt::Rectangle aPagePosSize
;
351 if ( rVal
>>= aPagePosSize
)
353 aPos
.X() = aPagePosSize
.X
;
354 aPos
.Y() = aPagePosSize
.Y
;
355 lWidth
= aPagePosSize
.Width
;
356 lHeight
= aPagePosSize
.Height
;
362 else if ( rVal
>>= nVal
)
366 case MID_X
: aPos
.X() = nVal
; break;
367 case MID_Y
: aPos
.Y() = nVal
; break;
368 case MID_WIDTH
: lWidth
= nVal
; break;
369 case MID_HEIGHT
: lHeight
= nVal
; break;
371 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
380 //------------------------------------------------------------------------
382 String
SvxPagePosSizeItem::GetValueText() const
387 //------------------------------------------------------------------------
389 SfxItemPresentation
SvxPagePosSizeItem::GetPresentation
391 SfxItemPresentation
/*ePres*/,
392 SfxMapUnit
/*eCoreUnit*/,
393 SfxMapUnit
/*ePresUnit*/,
394 String
& /*rText*/, const IntlWrapper
*
397 return SFX_ITEM_PRESENTATION_NONE
;
400 //------------------------------------------------------------------------
402 SfxPoolItem
* SvxPagePosSizeItem::Clone(SfxItemPool
*) const
404 return new SvxPagePosSizeItem(*this);
407 //------------------------------------------------------------------------
409 SvxPagePosSizeItem::SvxPagePosSizeItem(const Point
&rP
, long lW
, long lH
)
410 : SfxPoolItem(SID_RULER_PAGE_POS
),
416 //------------------------------------------------------------------------
418 SvxPagePosSizeItem::SvxPagePosSizeItem(const SvxPagePosSizeItem
&rCpy
)
422 lHeight(rCpy
.lHeight
)
425 //------------------------------------------------------------------------
427 SvxPagePosSizeItem::SvxPagePosSizeItem()
434 //------------------------------------------------------------------------
436 void SvxColumnItem::DeleteAndDestroyColumns()
438 for( USHORT i
= aColumns
.Count(); i
>0; )
440 SvxColumnDescription
*pTmp
= (SvxColumnDescription
*)aColumns
[--i
];
441 aColumns
.Remove( i
);
446 //------------------------------------------------------------------------
448 int SvxColumnItem::operator==(const SfxPoolItem
& rCmp
) const
450 if(!SfxPoolItem::operator==(rCmp
) ||
451 nActColumn
!= ((const SvxColumnItem
&)rCmp
).nActColumn
||
452 nLeft
!= ((const SvxColumnItem
&)rCmp
).nLeft
||
453 nRight
!= ((const SvxColumnItem
&)rCmp
).nRight
||
454 bTable
!= ((const SvxColumnItem
&)rCmp
).bTable
||
455 Count() != ((const SvxColumnItem
&)rCmp
).Count())
458 const USHORT nCount
= ((const SvxColumnItem
&)rCmp
).Count();
459 for(USHORT i
= 0; i
< nCount
;++i
) {
460 #if OSL_DEBUG_LEVEL > 1
461 SvxColumnDescription
*p1
, *p2
;
462 p1
= (SvxColumnDescription
*)aColumns
[i
];
463 p2
= (SvxColumnDescription
*)((const SvxColumnItem
&)rCmp
).aColumns
[i
];
465 if( (*this)[i
] != ((const SvxColumnItem
&)rCmp
)[i
] )
471 //------------------------------------------------------------------------
473 String
SvxColumnItem::GetValueText() const
478 //------------------------------------------------------------------------
480 SfxItemPresentation
SvxColumnItem::GetPresentation
482 SfxItemPresentation
/*ePres*/,
483 SfxMapUnit
/*eCoreUnit*/,
484 SfxMapUnit
/*ePresUnit*/,
485 String
& /*rText*/, const IntlWrapper
*
488 return SFX_ITEM_PRESENTATION_NONE
;
491 //------------------------------------------------------------------------
493 SfxPoolItem
* SvxColumnItem::Clone( SfxItemPool
* ) const
495 return new SvxColumnItem(*this);
498 //------------------------------------------------------------------------
500 SvxColumnItem::SvxColumnItem( USHORT nAct
) :
502 SfxPoolItem( SID_RULER_BORDERS
),
513 //------------------------------------------------------------------------
515 SvxColumnItem::SvxColumnItem( USHORT nActCol
, USHORT left
, USHORT right
) :
517 SfxPoolItem( SID_RULER_BORDERS
),
521 nActColumn ( nActCol
),
527 //------------------------------------------------------------------------
529 SvxColumnItem::SvxColumnItem( const SvxColumnItem
& rCopy
) :
531 SfxPoolItem( rCopy
),
533 aColumns ( (BYTE
)rCopy
.Count() ),
534 nLeft ( rCopy
.nLeft
),
535 nRight ( rCopy
.nRight
),
536 nActColumn( rCopy
.nActColumn
),
537 bTable ( rCopy
.bTable
),
538 bOrtho ( rCopy
.bOrtho
)
541 const USHORT nCount
= rCopy
.Count();
543 for ( USHORT i
= 0; i
< nCount
; ++i
)
547 //------------------------------------------------------------------------
549 SvxColumnItem::~SvxColumnItem()
551 DeleteAndDestroyColumns();
554 //------------------------------------------------------------------------
556 const SvxColumnItem
&SvxColumnItem::operator=(const SvxColumnItem
&rCopy
)
559 nRight
= rCopy
.nRight
;
560 bTable
= rCopy
.bTable
;
561 nActColumn
= rCopy
.nActColumn
;
562 DeleteAndDestroyColumns();
563 const USHORT nCount
= rCopy
.Count();
564 for(USHORT i
= 0; i
< nCount
;++i
)
569 //------------------------------------------------------------------------
571 BOOL
SvxColumnItem::CalcOrtho() const
573 const USHORT nCount
= Count();
574 DBG_ASSERT(nCount
>= 2, "keine Spalten");
578 long nColWidth
= (*this)[0].GetWidth();
579 for(USHORT i
= 1; i
< nCount
; ++i
) {
580 if( (*this)[i
].GetWidth() != nColWidth
)
587 //------------------------------------------------------------------------
589 long SvxColumnItem::GetVisibleRight() const
593 for ( USHORT i
= 0; i
< nActColumn
; ++i
)
595 if ( (*this)[i
].bVisible
)
598 return (*this)[nIdx
].nEnd
;
601 sal_Bool
SvxColumnItem::QueryValue( com::sun::star::uno::Any
& rVal
, BYTE nMemberId
) const
603 nMemberId
&= ~CONVERT_TWIPS
;
606 case MID_COLUMNARRAY
:
610 case MID_RIGHT
: rVal
<<= nRight
; break;
611 case MID_LEFT
: rVal
<<= nLeft
; break;
612 case MID_ORTHO
: rVal
<<= (sal_Bool
) bOrtho
; break;
613 case MID_ACTUAL
: rVal
<<= (sal_Int32
) nActColumn
; break;
614 case MID_TABLE
: rVal
<<= (sal_Bool
) bTable
; break;
615 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
621 sal_Bool
SvxColumnItem::PutValue( const com::sun::star::uno::Any
& rVal
, BYTE nMemberId
)
623 nMemberId
&= ~CONVERT_TWIPS
;
627 case MID_COLUMNARRAY
:
631 case MID_RIGHT
: rVal
>>= nRight
; break;
632 case MID_LEFT
: rVal
>>= nLeft
; break;
633 case MID_ORTHO
: rVal
>>= nVal
; bOrtho
= (BOOL
) nVal
; break;
634 case MID_ACTUAL
: rVal
>>= nVal
; nActColumn
= (USHORT
) nVal
; break;
635 case MID_TABLE
: rVal
>>= nVal
; bTable
= (BOOL
) nVal
; break;
636 default: DBG_ERROR("Wrong MemberId!"); return sal_False
;
642 //------------------------------------------------------------------------
644 int SvxObjectItem::operator==( const SfxPoolItem
& rCmp
) const
646 return SfxPoolItem::operator==(rCmp
) &&
647 nStartX
== ((const SvxObjectItem
&)rCmp
).nStartX
&&
648 nEndX
== ((const SvxObjectItem
&)rCmp
).nEndX
&&
649 nStartY
== ((const SvxObjectItem
&)rCmp
).nStartY
&&
650 nEndY
== ((const SvxObjectItem
&)rCmp
).nEndY
&&
651 bLimits
== ((const SvxObjectItem
&)rCmp
).bLimits
;
654 //------------------------------------------------------------------------
656 String
SvxObjectItem::GetValueText() const
661 //------------------------------------------------------------------------
663 SfxItemPresentation
SvxObjectItem::GetPresentation
665 SfxItemPresentation
/*ePres*/,
666 SfxMapUnit
/*eCoreUnit*/,
667 SfxMapUnit
/*ePresUnit*/,
668 String
& /*rText*/, const IntlWrapper
*
671 return SFX_ITEM_PRESENTATION_NONE
;
674 //------------------------------------------------------------------------
676 SfxPoolItem
* SvxObjectItem::Clone(SfxItemPool
*) const
678 return new SvxObjectItem(*this);
681 //------------------------------------------------------------------------
683 SvxObjectItem::SvxObjectItem( long nSX
, long nEX
,
684 long nSY
, long nEY
, BOOL limits
) :
686 SfxPoolItem( SID_RULER_OBJECT
),
697 //------------------------------------------------------------------------
699 SvxObjectItem::SvxObjectItem( const SvxObjectItem
& rCopy
) :
701 SfxPoolItem( rCopy
),
703 nStartX ( rCopy
.nStartX
),
704 nEndX ( rCopy
.nEndX
),
705 nStartY ( rCopy
.nStartY
),
706 nEndY ( rCopy
.nEndY
),
707 bLimits ( rCopy
.bLimits
)
712 sal_Bool
SvxObjectItem::QueryValue( com::sun::star::uno::Any
& rVal
, BYTE nMemberId
) const
714 nMemberId
&= ~CONVERT_TWIPS
;
717 case MID_START_X
: rVal
<<= nStartX
; break;
718 case MID_START_Y
: rVal
<<= nStartY
; break;
719 case MID_END_X
: rVal
<<= nEndX
; break;
720 case MID_END_Y
: rVal
<<= nEndY
; break;
721 case MID_LIMIT
: rVal
<<= bLimits
; break;
723 DBG_ERROR( "Wrong MemberId" );
730 sal_Bool
SvxObjectItem::PutValue( const com::sun::star::uno::Any
& rVal
, BYTE nMemberId
)
732 nMemberId
&= ~CONVERT_TWIPS
;
736 case MID_START_X
: bRet
= (rVal
>>= nStartX
); break;
737 case MID_START_Y
: bRet
= (rVal
>>= nStartY
); break;
738 case MID_END_X
: bRet
= (rVal
>>= nEndX
); break;
739 case MID_END_Y
: bRet
= (rVal
>>= nEndY
); break;
740 case MID_LIMIT
: bRet
= (rVal
>>= bLimits
); break;
741 default: DBG_ERROR( "Wrong MemberId" );