bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / dialog / rulritem.cxx
blobff1bf2a74e50b538b54942e343ce077056c79ef8
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 .
20 #include <tools/string.hxx>
22 #include <svx/dialogs.hrc>
23 #include "svx/rulritem.hxx"
24 #include <com/sun/star/awt/Rectangle.hpp>
25 #include <com/sun/star/frame/status/LeftRightMargin.hpp>
26 #include <com/sun/star/frame/status/UpperLowerMargin.hpp>
28 //------------------------------------------------------------------------
30 TYPEINIT1_AUTOFACTORY(SvxPagePosSizeItem, SfxPoolItem);
31 TYPEINIT1_AUTOFACTORY(SvxLongLRSpaceItem, SfxPoolItem);
32 TYPEINIT1_AUTOFACTORY(SvxLongULSpaceItem, SfxPoolItem);
33 TYPEINIT1(SvxColumnItem, SfxPoolItem);
34 TYPEINIT1(SvxObjectItem, SfxPoolItem);
36 //------------------------------------------------------------------------
38 int SvxLongLRSpaceItem::operator==( const SfxPoolItem& rCmp) const
40 return SfxPoolItem::operator==(rCmp) &&
41 lLeft==((const SvxLongLRSpaceItem &)rCmp).lLeft &&
42 lRight==((const SvxLongLRSpaceItem &)rCmp).lRight;
46 //------------------------------------------------------------------------
48 String SvxLongLRSpaceItem::GetValueText() const
50 return String();
53 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
54 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
56 bool SvxLongLRSpaceItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
58 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
59 nMemberId &= ~CONVERT_TWIPS;
61 sal_Int32 nVal;
62 switch( nMemberId )
64 case 0:
66 ::com::sun::star::frame::status::LeftRightMargin aLeftRightMargin;
67 aLeftRightMargin.Left = bConvert ? TWIP_TO_MM100( lLeft ) : lLeft;
68 aLeftRightMargin.Right = bConvert ? TWIP_TO_MM100( lRight ) : lRight;
69 rVal <<= aLeftRightMargin;
70 return sal_True;
73 case MID_LEFT: nVal = lLeft; break;
74 case MID_RIGHT: nVal = lRight; break;
75 default: OSL_FAIL("Wrong MemberId!"); return false;
78 if ( bConvert )
79 nVal = TWIP_TO_MM100( nVal );
81 rVal <<= nVal;
82 return true;
85 // -----------------------------------------------------------------------
86 bool SvxLongLRSpaceItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
88 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
89 nMemberId &= ~CONVERT_TWIPS;
91 sal_Int32 nVal = 0;
92 if ( nMemberId == 0 )
94 ::com::sun::star::frame::status::LeftRightMargin aLeftRightMargin;
95 if ( rVal >>= aLeftRightMargin )
97 lLeft = bConvert ? MM100_TO_TWIP( aLeftRightMargin.Left ) : aLeftRightMargin.Left;
98 lRight = bConvert ? MM100_TO_TWIP( aLeftRightMargin.Right ) : aLeftRightMargin.Right;
99 return true;
102 else if ( rVal >>= nVal )
104 if ( bConvert )
105 nVal = MM100_TO_TWIP( nVal );
107 switch( nMemberId )
109 case MID_LEFT: lLeft = nVal; break;
110 case MID_RIGHT: lRight = nVal; break;
111 default: OSL_FAIL("Wrong MemberId!"); return false;
114 return true;
117 return false;
120 //------------------------------------------------------------------------
122 SfxItemPresentation SvxLongLRSpaceItem::GetPresentation
124 SfxItemPresentation /*ePres*/,
125 SfxMapUnit /*eCoreUnit*/,
126 SfxMapUnit /*ePresUnit*/,
127 OUString& /*rText*/, const IntlWrapper *
128 ) const
131 return SFX_ITEM_PRESENTATION_NONE;
134 //------------------------------------------------------------------------
136 SfxPoolItem* SvxLongLRSpaceItem::Clone(SfxItemPool *) const
138 return new SvxLongLRSpaceItem(*this);
141 //------------------------------------------------------------------------
143 SvxLongLRSpaceItem::SvxLongLRSpaceItem(long lL, long lR, sal_uInt16 nId)
144 : SfxPoolItem(nId),
145 lLeft(lL),
146 lRight(lR)
149 //------------------------------------------------------------------------
151 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
152 SfxPoolItem( 0 ),
153 lLeft( 0 ),
154 lRight( 0 )
157 //------------------------------------------------------------------------
159 SvxLongLRSpaceItem::SvxLongLRSpaceItem(const SvxLongLRSpaceItem &rCpy)
160 : SfxPoolItem(rCpy),
161 lLeft(rCpy.lLeft),
162 lRight(rCpy.lRight)
165 //------------------------------------------------------------------------
167 int SvxLongULSpaceItem::operator==( const SfxPoolItem& rCmp) const
169 return SfxPoolItem::operator==(rCmp) &&
170 lLeft==((const SvxLongULSpaceItem &)rCmp).lLeft &&
171 lRight==((const SvxLongULSpaceItem &)rCmp).lRight;
175 //------------------------------------------------------------------------
177 String SvxLongULSpaceItem::GetValueText() const
179 return String();
182 bool SvxLongULSpaceItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
184 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
185 nMemberId &= ~CONVERT_TWIPS;
187 sal_Int32 nVal;
188 switch( nMemberId )
190 case 0:
192 ::com::sun::star::frame::status::UpperLowerMargin aUpperLowerMargin;
193 aUpperLowerMargin.Upper = bConvert ? TWIP_TO_MM100( lLeft ) : lLeft;
194 aUpperLowerMargin.Lower = bConvert ? TWIP_TO_MM100( lRight ) : lRight;
195 rVal <<= aUpperLowerMargin;
196 return true;
199 case MID_UPPER: nVal = lLeft; break;
200 case MID_LOWER: nVal = lRight; break;
201 default: OSL_FAIL("Wrong MemberId!"); return false;
204 if ( bConvert )
205 nVal = TWIP_TO_MM100( nVal );
207 rVal <<= nVal;
208 return true;
211 // -----------------------------------------------------------------------
212 bool SvxLongULSpaceItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
214 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
215 nMemberId &= ~CONVERT_TWIPS;
217 sal_Int32 nVal = 0;
218 if ( nMemberId == 0 )
220 ::com::sun::star::frame::status::UpperLowerMargin aUpperLowerMargin;
221 if ( rVal >>= aUpperLowerMargin )
223 lLeft = bConvert ? MM100_TO_TWIP( aUpperLowerMargin.Upper ) : aUpperLowerMargin.Upper;
224 lRight = bConvert ? MM100_TO_TWIP( aUpperLowerMargin.Lower ) : aUpperLowerMargin.Lower;
225 return true;
228 else if ( rVal >>= nVal )
230 if ( bConvert )
231 nVal = MM100_TO_TWIP( nVal );
233 switch( nMemberId )
235 case MID_UPPER: lLeft = nVal; break;
236 case MID_LOWER: lRight = nVal; break;
237 default: OSL_FAIL("Wrong MemberId!"); return false;
240 return true;
243 return false;
246 //------------------------------------------------------------------------
248 SfxItemPresentation SvxLongULSpaceItem::GetPresentation
250 SfxItemPresentation /*ePres*/,
251 SfxMapUnit /*eCoreUnit*/,
252 SfxMapUnit /*ePresUnit*/,
253 OUString& /*rText*/, const IntlWrapper *
254 ) const
256 return SFX_ITEM_PRESENTATION_NONE;
259 //------------------------------------------------------------------------
261 SfxPoolItem* SvxLongULSpaceItem::Clone(SfxItemPool *) const
263 return new SvxLongULSpaceItem(*this);
266 //------------------------------------------------------------------------
268 SvxLongULSpaceItem::SvxLongULSpaceItem(long lL, long lR, sal_uInt16 nId)
269 : SfxPoolItem(nId),
270 lLeft(lL),
271 lRight(lR)
274 //------------------------------------------------------------------------
276 SvxLongULSpaceItem::SvxLongULSpaceItem(const SvxLongULSpaceItem &rCpy)
277 : SfxPoolItem(rCpy),
278 lLeft(rCpy.lLeft),
279 lRight(rCpy.lRight)
282 //------------------------------------------------------------------------
284 SvxLongULSpaceItem::SvxLongULSpaceItem() :
285 SfxPoolItem( 0 ),
286 lLeft( 0 ),
287 lRight( 0 )
290 //------------------------------------------------------------------------
292 int SvxPagePosSizeItem::operator==( const SfxPoolItem& rCmp) const
294 return SfxPoolItem::operator==(rCmp) &&
295 aPos == ((const SvxPagePosSizeItem &)rCmp).aPos &&
296 lWidth == ((const SvxPagePosSizeItem &)rCmp).lWidth &&
297 lHeight == ((const SvxPagePosSizeItem &)rCmp).lHeight;
300 bool SvxPagePosSizeItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
302 nMemberId &= ~CONVERT_TWIPS;
304 sal_Int32 nVal;
305 switch ( nMemberId )
307 case 0 :
309 com::sun::star::awt::Rectangle aPagePosSize;
310 aPagePosSize.X = aPos.X();
311 aPagePosSize.Y = aPos.Y();
312 aPagePosSize.Width = lWidth;
313 aPagePosSize.Height = lHeight;
314 rVal <<= aPagePosSize;
315 return true;
318 case MID_X: nVal = aPos.X(); break;
319 case MID_Y: nVal = aPos.Y(); break;
320 case MID_WIDTH: nVal = lWidth; break;
321 case MID_HEIGHT: nVal = lHeight; break;
323 default: OSL_FAIL("Wrong MemberId!"); return false;
326 rVal <<= nVal;
327 return true;
330 bool SvxPagePosSizeItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
332 nMemberId &= ~CONVERT_TWIPS;
334 sal_Int32 nVal = 0;
335 if ( nMemberId == 0 )
337 com::sun::star::awt::Rectangle aPagePosSize;
338 if ( rVal >>= aPagePosSize )
340 aPos.X() = aPagePosSize.X;
341 aPos.Y() = aPagePosSize.Y;
342 lWidth = aPagePosSize.Width;
343 lHeight = aPagePosSize.Height;
344 return sal_True;
346 else
347 return sal_False;
349 else if ( rVal >>= nVal )
351 switch ( nMemberId )
353 case MID_X: aPos.X() = nVal; break;
354 case MID_Y: aPos.Y() = nVal; break;
355 case MID_WIDTH: lWidth = nVal; break;
356 case MID_HEIGHT: lHeight = nVal; break;
358 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
361 return true;
364 return false;
367 //------------------------------------------------------------------------
369 String SvxPagePosSizeItem::GetValueText() const
371 return String();
374 //------------------------------------------------------------------------
376 SfxItemPresentation SvxPagePosSizeItem::GetPresentation
378 SfxItemPresentation /*ePres*/,
379 SfxMapUnit /*eCoreUnit*/,
380 SfxMapUnit /*ePresUnit*/,
381 OUString& /*rText*/, const IntlWrapper *
382 ) const
384 return SFX_ITEM_PRESENTATION_NONE;
387 //------------------------------------------------------------------------
389 SfxPoolItem* SvxPagePosSizeItem::Clone(SfxItemPool *) const
391 return new SvxPagePosSizeItem(*this);
394 //------------------------------------------------------------------------
396 SvxPagePosSizeItem::SvxPagePosSizeItem(const Point &rP, long lW, long lH)
397 : SfxPoolItem(SID_RULER_PAGE_POS),
398 aPos(rP),
399 lWidth(lW),
400 lHeight(lH)
403 //------------------------------------------------------------------------
405 SvxPagePosSizeItem::SvxPagePosSizeItem(const SvxPagePosSizeItem &rCpy)
406 : SfxPoolItem(rCpy),
407 aPos(rCpy.aPos),
408 lWidth(rCpy.lWidth),
409 lHeight(rCpy.lHeight)
412 //------------------------------------------------------------------------
414 SvxPagePosSizeItem::SvxPagePosSizeItem()
415 : SfxPoolItem( 0 ),
416 aPos( 0, 0 ),
417 lWidth( 0 ),
418 lHeight( 0 )
421 //------------------------------------------------------------------------
423 int SvxColumnItem::operator==(const SfxPoolItem& rCmp) const
425 if(!SfxPoolItem::operator==(rCmp) ||
426 nActColumn != ((const SvxColumnItem&)rCmp).nActColumn ||
427 nLeft != ((const SvxColumnItem&)rCmp).nLeft ||
428 nRight != ((const SvxColumnItem&)rCmp).nRight ||
429 bTable != ((const SvxColumnItem&)rCmp).bTable ||
430 Count() != ((const SvxColumnItem&)rCmp).Count())
431 return sal_False;
433 const sal_uInt16 nCount = ((const SvxColumnItem&)rCmp).Count();
434 for(sal_uInt16 i = 0; i < nCount;++i) {
435 if( (*this)[i] != ((const SvxColumnItem&)rCmp)[i] )
436 return sal_False;
438 return sal_True;
441 //------------------------------------------------------------------------
443 String SvxColumnItem::GetValueText() const
445 return String();
448 //------------------------------------------------------------------------
450 SfxItemPresentation SvxColumnItem::GetPresentation
452 SfxItemPresentation /*ePres*/,
453 SfxMapUnit /*eCoreUnit*/,
454 SfxMapUnit /*ePresUnit*/,
455 OUString& /*rText*/, const IntlWrapper *
456 ) const
458 return SFX_ITEM_PRESENTATION_NONE;
461 //------------------------------------------------------------------------
463 SfxPoolItem* SvxColumnItem::Clone( SfxItemPool * ) const
465 return new SvxColumnItem(*this);
468 //------------------------------------------------------------------------
470 SvxColumnItem::SvxColumnItem( sal_uInt16 nAct ) :
472 SfxPoolItem( SID_RULER_BORDERS ),
474 nLeft ( 0 ),
475 nRight ( 0 ),
476 nActColumn ( nAct ),
477 bTable ( sal_False ),
478 bOrtho (sal_True )
483 //------------------------------------------------------------------------
485 SvxColumnItem::SvxColumnItem( sal_uInt16 nActCol, sal_uInt16 left, sal_uInt16 right ) :
487 SfxPoolItem( SID_RULER_BORDERS ),
489 nLeft ( left ),
490 nRight ( right ),
491 nActColumn ( nActCol ),
492 bTable ( sal_True ),
493 bOrtho ( sal_True )
497 SvxColumnItem::SvxColumnItem( const SvxColumnItem& rCopy ) :
498 SfxPoolItem( rCopy ),
499 nLeft ( rCopy.nLeft ),
500 nRight ( rCopy.nRight ),
501 nActColumn( rCopy.nActColumn ),
502 bTable ( rCopy.bTable ),
503 bOrtho ( rCopy.bOrtho )
505 for(size_t i = 0; i < rCopy.Count(); ++i)
506 aColumns.push_back(rCopy[i]);
509 SvxColumnItem::~SvxColumnItem()
513 const SvxColumnItem &SvxColumnItem::operator=(const SvxColumnItem &rCopy)
515 nLeft = rCopy.nLeft;
516 nRight = rCopy.nRight;
517 bTable = rCopy.bTable;
518 nActColumn = rCopy.nActColumn;
519 aColumns.clear();
520 for(size_t i = 0; i < rCopy.Count(); ++i)
521 aColumns.push_back(rCopy[i]);
522 return *this;
525 sal_Bool SvxColumnItem::CalcOrtho() const
527 const sal_uInt16 nCount = Count();
528 DBG_ASSERT(nCount >= 2, "no columns");
529 if(nCount < 2)
530 return sal_False;
532 long nColWidth = (*this)[0].GetWidth();
533 for(sal_uInt16 i = 1; i < nCount; ++i) {
534 if( (*this)[i].GetWidth() != nColWidth)
535 return sal_False;
537 //!! Wide divider
538 return sal_True;
541 //------------------------------------------------------------------------
543 bool SvxColumnItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
545 nMemberId &= ~CONVERT_TWIPS;
546 switch ( nMemberId )
548 case MID_COLUMNARRAY:
550 return false;
552 case MID_RIGHT: rVal <<= nRight; break;
553 case MID_LEFT: rVal <<= nLeft; break;
554 case MID_ORTHO: rVal <<= (sal_Bool) bOrtho; break;
555 case MID_ACTUAL: rVal <<= (sal_Int32) nActColumn; break;
556 case MID_TABLE: rVal <<= (sal_Bool) bTable; break;
557 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
560 return true;
563 bool SvxColumnItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
565 nMemberId &= ~CONVERT_TWIPS;
566 sal_Int32 nVal = 0;
567 switch ( nMemberId )
569 case MID_COLUMNARRAY:
571 return false;
573 case MID_RIGHT: rVal >>= nRight; break;
574 case MID_LEFT: rVal >>= nLeft; break;
575 case MID_ORTHO: rVal >>= nVal; bOrtho = (sal_Bool) nVal; break;
576 case MID_ACTUAL: rVal >>= nVal; nActColumn = (sal_uInt16) nVal; break;
577 case MID_TABLE: rVal >>= nVal; bTable = (sal_Bool) nVal; break;
578 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
581 return true;
584 //------------------------------------------------------------------------
586 int SvxObjectItem::operator==( const SfxPoolItem& rCmp ) const
588 return SfxPoolItem::operator==(rCmp) &&
589 nStartX == ((const SvxObjectItem&)rCmp).nStartX &&
590 nEndX == ((const SvxObjectItem&)rCmp).nEndX &&
591 nStartY == ((const SvxObjectItem&)rCmp).nStartY &&
592 nEndY == ((const SvxObjectItem&)rCmp).nEndY &&
593 bLimits == ((const SvxObjectItem&)rCmp).bLimits;
596 //------------------------------------------------------------------------
598 String SvxObjectItem::GetValueText() const
600 return String();
603 //------------------------------------------------------------------------
605 SfxItemPresentation SvxObjectItem::GetPresentation
607 SfxItemPresentation /*ePres*/,
608 SfxMapUnit /*eCoreUnit*/,
609 SfxMapUnit /*ePresUnit*/,
610 OUString& /*rText*/, const IntlWrapper *
611 ) const
613 return SFX_ITEM_PRESENTATION_NONE;
616 //------------------------------------------------------------------------
618 SfxPoolItem* SvxObjectItem::Clone(SfxItemPool *) const
620 return new SvxObjectItem(*this);
623 //------------------------------------------------------------------------
625 SvxObjectItem::SvxObjectItem( long nSX, long nEX,
626 long nSY, long nEY, sal_Bool limits ) :
628 SfxPoolItem( SID_RULER_OBJECT ),
630 nStartX ( nSX ),
631 nEndX ( nEX ),
632 nStartY ( nSY ),
633 nEndY ( nEY ),
634 bLimits ( limits )
639 //------------------------------------------------------------------------
641 SvxObjectItem::SvxObjectItem( const SvxObjectItem& rCopy ) :
643 SfxPoolItem( rCopy ),
645 nStartX ( rCopy.nStartX ),
646 nEndX ( rCopy.nEndX ),
647 nStartY ( rCopy.nStartY ),
648 nEndY ( rCopy.nEndY ),
649 bLimits ( rCopy.bLimits )
654 bool SvxObjectItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
656 nMemberId &= ~CONVERT_TWIPS;
657 switch ( nMemberId )
659 case MID_START_X : rVal <<= nStartX; break;
660 case MID_START_Y : rVal <<= nStartY; break;
661 case MID_END_X : rVal <<= nEndX; break;
662 case MID_END_Y : rVal <<= nEndY; break;
663 case MID_LIMIT : rVal <<= bLimits; break;
664 default:
665 OSL_FAIL( "Wrong MemberId" );
666 return sal_False;
669 return true;
672 bool SvxObjectItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
674 nMemberId &= ~CONVERT_TWIPS;
675 bool bRet = false;
676 switch ( nMemberId )
678 case MID_START_X : bRet = (rVal >>= nStartX); break;
679 case MID_START_Y : bRet = (rVal >>= nStartY); break;
680 case MID_END_X : bRet = (rVal >>= nEndX); break;
681 case MID_END_Y : bRet = (rVal >>= nEndY); break;
682 case MID_LIMIT : bRet = (rVal >>= bLimits); break;
683 default: OSL_FAIL( "Wrong MemberId" );
686 return bRet;
689 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */