merge the formfield patch from ooo-build
[ooovba.git] / svx / source / dialog / rulritem.cxx
blob386e25b739e750a8f28315d7edc1c8d120d20804
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: rulritem.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"
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
63 return String();
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;
74 sal_Int32 nVal;
75 switch( nMemberId )
77 case 0:
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;
83 return TRUE;
86 case MID_LEFT: nVal = lLeft; break;
87 case MID_RIGHT: nVal = lRight; break;
88 default: DBG_ERROR("Wrong MemberId!"); return sal_False;
91 if ( bConvert )
92 nVal = TWIP_TO_MM100( nVal );
94 rVal <<= nVal;
95 return TRUE;
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;
104 sal_Int32 nVal = 0;
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;
112 return sal_True;
115 else if ( rVal >>= nVal )
117 if ( bConvert )
118 nVal = MM100_TO_TWIP( nVal );
120 switch( nMemberId )
122 case MID_LEFT: lLeft = nVal; break;
123 case MID_RIGHT: lRight = nVal; break;
124 default: DBG_ERROR("Wrong MemberId!"); return sal_False;
127 return sal_True;
130 return sal_False;
133 //------------------------------------------------------------------------
135 SfxItemPresentation SvxLongLRSpaceItem::GetPresentation
137 SfxItemPresentation /*ePres*/,
138 SfxMapUnit /*eCoreUnit*/,
139 SfxMapUnit /*ePresUnit*/,
140 String& /*rText*/, const IntlWrapper *
141 ) const
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)
157 : SfxPoolItem(nId),
158 lLeft(lL),
159 lRight(lR)
162 //------------------------------------------------------------------------
164 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
165 SfxPoolItem( 0 ),
166 lLeft( 0 ),
167 lRight( 0 )
170 //------------------------------------------------------------------------
172 SvxLongLRSpaceItem::SvxLongLRSpaceItem(const SvxLongLRSpaceItem &rCpy)
173 : SfxPoolItem(rCpy),
174 lLeft(rCpy.lLeft),
175 lRight(rCpy.lRight)
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
192 return String();
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;
200 sal_Int32 nVal;
201 switch( nMemberId )
203 case 0:
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;
209 return TRUE;
212 case MID_UPPER: nVal = lLeft; break;
213 case MID_LOWER: nVal = lRight; break;
214 default: DBG_ERROR("Wrong MemberId!"); return sal_False;
217 if ( bConvert )
218 nVal = TWIP_TO_MM100( nVal );
220 rVal <<= nVal;
221 return TRUE;
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;
230 sal_Int32 nVal = 0;
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;
238 return sal_True;
241 else if ( rVal >>= nVal )
243 if ( bConvert )
244 nVal = MM100_TO_TWIP( nVal );
246 switch( nMemberId )
248 case MID_UPPER: lLeft = nVal; break;
249 case MID_LOWER: lRight = nVal; break;
250 default: DBG_ERROR("Wrong MemberId!"); return sal_False;
253 return sal_True;
256 return sal_False;
259 //------------------------------------------------------------------------
261 SfxItemPresentation SvxLongULSpaceItem::GetPresentation
263 SfxItemPresentation /*ePres*/,
264 SfxMapUnit /*eCoreUnit*/,
265 SfxMapUnit /*ePresUnit*/,
266 String& /*rText*/, const IntlWrapper *
267 ) const
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)
282 : SfxPoolItem(nId),
283 lLeft(lL),
284 lRight(lR)
287 //------------------------------------------------------------------------
289 SvxLongULSpaceItem::SvxLongULSpaceItem(const SvxLongULSpaceItem &rCpy)
290 : SfxPoolItem(rCpy),
291 lLeft(rCpy.lLeft),
292 lRight(rCpy.lRight)
295 //------------------------------------------------------------------------
297 SvxLongULSpaceItem::SvxLongULSpaceItem() :
298 SfxPoolItem( 0 ),
299 lLeft( 0 ),
300 lRight( 0 )
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;
317 sal_Int32 nVal;
318 switch ( nMemberId )
320 case 0 :
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;
328 return TRUE;
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;
339 rVal <<= nVal;
340 return TRUE;
343 sal_Bool SvxPagePosSizeItem::PutValue( const ::com::sun::star::uno::Any& rVal, BYTE nMemberId )
345 nMemberId &= ~CONVERT_TWIPS;
347 sal_Int32 nVal = 0;
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;
357 return sal_True;
359 else
360 return sal_False;
362 else if ( rVal >>= nVal )
364 switch ( nMemberId )
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;
374 return sal_True;
377 return sal_False;
380 //------------------------------------------------------------------------
382 String SvxPagePosSizeItem::GetValueText() const
384 return String();
387 //------------------------------------------------------------------------
389 SfxItemPresentation SvxPagePosSizeItem::GetPresentation
391 SfxItemPresentation /*ePres*/,
392 SfxMapUnit /*eCoreUnit*/,
393 SfxMapUnit /*ePresUnit*/,
394 String& /*rText*/, const IntlWrapper *
395 ) const
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),
411 aPos(rP),
412 lWidth(lW),
413 lHeight(lH)
416 //------------------------------------------------------------------------
418 SvxPagePosSizeItem::SvxPagePosSizeItem(const SvxPagePosSizeItem &rCpy)
419 : SfxPoolItem(rCpy),
420 aPos(rCpy.aPos),
421 lWidth(rCpy.lWidth),
422 lHeight(rCpy.lHeight)
425 //------------------------------------------------------------------------
427 SvxPagePosSizeItem::SvxPagePosSizeItem()
428 : SfxPoolItem( 0 ),
429 aPos( 0, 0 ),
430 lWidth( 0 ),
431 lHeight( 0 )
434 //------------------------------------------------------------------------
436 void SvxColumnItem::DeleteAndDestroyColumns()
438 for( USHORT i = aColumns.Count(); i>0; )
440 SvxColumnDescription *pTmp = (SvxColumnDescription *)aColumns[--i];
441 aColumns.Remove( i );
442 delete pTmp;
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())
456 return FALSE;
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];
464 #endif
465 if( (*this)[i] != ((const SvxColumnItem&)rCmp)[i] )
466 return FALSE;
468 return TRUE;
471 //------------------------------------------------------------------------
473 String SvxColumnItem::GetValueText() const
475 return String();
478 //------------------------------------------------------------------------
480 SfxItemPresentation SvxColumnItem::GetPresentation
482 SfxItemPresentation /*ePres*/,
483 SfxMapUnit /*eCoreUnit*/,
484 SfxMapUnit /*ePresUnit*/,
485 String& /*rText*/, const IntlWrapper *
486 ) const
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 ),
504 nLeft ( 0 ),
505 nRight ( 0 ),
506 nActColumn ( nAct ),
507 bTable ( FALSE ),
508 bOrtho (TRUE )
513 //------------------------------------------------------------------------
515 SvxColumnItem::SvxColumnItem( USHORT nActCol, USHORT left, USHORT right ) :
517 SfxPoolItem( SID_RULER_BORDERS ),
519 nLeft ( left ),
520 nRight ( right ),
521 nActColumn ( nActCol ),
522 bTable ( TRUE ),
523 bOrtho ( TRUE )
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 )
544 Append( rCopy[i] );
547 //------------------------------------------------------------------------
549 SvxColumnItem::~SvxColumnItem()
551 DeleteAndDestroyColumns();
554 //------------------------------------------------------------------------
556 const SvxColumnItem &SvxColumnItem::operator=(const SvxColumnItem &rCopy)
558 nLeft = rCopy.nLeft;
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)
565 Insert(rCopy[i], i);
566 return *this;
569 //------------------------------------------------------------------------
571 BOOL SvxColumnItem::CalcOrtho() const
573 const USHORT nCount = Count();
574 DBG_ASSERT(nCount >= 2, "keine Spalten");
575 if(nCount < 2)
576 return FALSE;
578 long nColWidth = (*this)[0].GetWidth();
579 for(USHORT i = 1; i < nCount; ++i) {
580 if( (*this)[i].GetWidth() != nColWidth)
581 return FALSE;
583 //!! Breite Trenner
584 return TRUE;
587 //------------------------------------------------------------------------
589 long SvxColumnItem::GetVisibleRight() const
591 USHORT nIdx = 0;
593 for ( USHORT i = 0; i < nActColumn; ++i )
595 if ( (*this)[i].bVisible )
596 ++nIdx;
598 return (*this)[nIdx].nEnd;
601 sal_Bool SvxColumnItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
603 nMemberId &= ~CONVERT_TWIPS;
604 switch ( nMemberId )
606 case MID_COLUMNARRAY:
608 return sal_False;
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;
618 return sal_True;
621 sal_Bool SvxColumnItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
623 nMemberId &= ~CONVERT_TWIPS;
624 sal_Int32 nVal = 0;
625 switch ( nMemberId )
627 case MID_COLUMNARRAY:
629 return sal_False;
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;
639 return sal_True;
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
658 return String();
661 //------------------------------------------------------------------------
663 SfxItemPresentation SvxObjectItem::GetPresentation
665 SfxItemPresentation /*ePres*/,
666 SfxMapUnit /*eCoreUnit*/,
667 SfxMapUnit /*ePresUnit*/,
668 String& /*rText*/, const IntlWrapper *
669 ) const
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 ),
688 nStartX ( nSX ),
689 nEndX ( nEX ),
690 nStartY ( nSY ),
691 nEndY ( nEY ),
692 bLimits ( limits )
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;
715 switch ( nMemberId )
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;
722 default:
723 DBG_ERROR( "Wrong MemberId" );
724 return sal_False;
727 return TRUE;
730 sal_Bool SvxObjectItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
732 nMemberId &= ~CONVERT_TWIPS;
733 BOOL bRet=FALSE;
734 switch ( nMemberId )
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" );
744 return bRet;