1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svx/dialogs.hrc>
21 #include "svx/rulritem.hxx"
22 #include <tools/mapunit.hxx>
23 #include <osl/diagnose.h>
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 TYPEINIT1_AUTOFACTORY(SvxPagePosSizeItem
, SfxPoolItem
);
29 TYPEINIT1_AUTOFACTORY(SvxLongLRSpaceItem
, SfxPoolItem
);
30 TYPEINIT1_AUTOFACTORY(SvxLongULSpaceItem
, SfxPoolItem
);
31 TYPEINIT1(SvxColumnItem
, SfxPoolItem
);
32 TYPEINIT1(SvxObjectItem
, SfxPoolItem
);
34 /* SvxLongLRSpaceItem */
36 bool SvxLongLRSpaceItem::operator==( const SfxPoolItem
& rCmp
) const
38 return SfxPoolItem::operator==(rCmp
) &&
39 mlLeft
== static_cast<const SvxLongLRSpaceItem
&>(rCmp
).mlLeft
&&
40 mlRight
== static_cast<const SvxLongLRSpaceItem
&>(rCmp
).mlRight
;
43 bool SvxLongLRSpaceItem::QueryValue( ::com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
45 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
46 nMemberId
&= ~CONVERT_TWIPS
;
53 ::com::sun::star::frame::status::LeftRightMargin aLeftRightMargin
;
54 aLeftRightMargin
.Left
= bConvert
? convertTwipToMm100( mlLeft
) : mlLeft
;
55 aLeftRightMargin
.Right
= bConvert
? convertTwipToMm100( mlRight
) : mlRight
;
56 rVal
<<= aLeftRightMargin
;
67 OSL_FAIL("Wrong MemberId!");
72 nVal
= convertTwipToMm100( nVal
);
78 bool SvxLongLRSpaceItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
80 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
81 nMemberId
&= ~CONVERT_TWIPS
;
86 ::com::sun::star::frame::status::LeftRightMargin aLeftRightMargin
;
87 if ( rVal
>>= aLeftRightMargin
)
89 mlLeft
= bConvert
? convertMm100ToTwip(aLeftRightMargin
.Left
) : aLeftRightMargin
.Left
;
90 mlRight
= bConvert
? convertMm100ToTwip(aLeftRightMargin
.Right
) : aLeftRightMargin
.Right
;
94 else if ( rVal
>>= nVal
)
97 nVal
= convertMm100ToTwip( nVal
);
108 OSL_FAIL("Wrong MemberId!");
118 bool SvxLongLRSpaceItem::GetPresentation(
119 SfxItemPresentation
/*ePres*/,
120 SfxMapUnit
/*eCoreUnit*/,
121 SfxMapUnit
/*ePresUnit*/,
123 const IntlWrapper
* /*pWrapper*/) const
128 SfxPoolItem
* SvxLongLRSpaceItem::Clone(SfxItemPool
*) const
130 return new SvxLongLRSpaceItem(*this);
133 SvxLongLRSpaceItem::SvxLongLRSpaceItem(long lLeft
, long lRight
, sal_uInt16 nId
) :
139 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
145 SvxLongLRSpaceItem::SvxLongLRSpaceItem(const SvxLongLRSpaceItem
&rCpy
) :
147 mlLeft (rCpy
.mlLeft
),
148 mlRight (rCpy
.mlRight
)
153 void SvxLongLRSpaceItem::SetLeft(long lArgLeft
)
158 void SvxLongLRSpaceItem::SetRight(long lArgRight
)
163 /* SvxLongULSpaceItem */
165 bool SvxLongULSpaceItem::operator==( const SfxPoolItem
& rCmp
) const
167 return SfxPoolItem::operator==(rCmp
) &&
168 mlLeft
== static_cast<const SvxLongULSpaceItem
&>(rCmp
).mlLeft
&&
169 mlRight
== static_cast<const SvxLongULSpaceItem
&>(rCmp
).mlRight
;
172 bool SvxLongULSpaceItem::QueryValue( ::com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
174 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
175 nMemberId
&= ~CONVERT_TWIPS
;
182 ::com::sun::star::frame::status::UpperLowerMargin aUpperLowerMargin
;
183 aUpperLowerMargin
.Upper
= bConvert
? convertTwipToMm100( mlLeft
) : mlLeft
;
184 aUpperLowerMargin
.Lower
= bConvert
? convertTwipToMm100( mlRight
) : mlRight
;
185 rVal
<<= aUpperLowerMargin
;
195 default: OSL_FAIL("Wrong MemberId!"); return false;
199 nVal
= convertTwipToMm100( nVal
);
205 bool SvxLongULSpaceItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
207 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
208 nMemberId
&= ~CONVERT_TWIPS
;
211 if ( nMemberId
== 0 )
213 ::com::sun::star::frame::status::UpperLowerMargin aUpperLowerMargin
;
214 if ( rVal
>>= aUpperLowerMargin
)
216 mlLeft
= bConvert
? convertMm100ToTwip( aUpperLowerMargin
.Upper
) : aUpperLowerMargin
.Upper
;
217 mlRight
= bConvert
? convertMm100ToTwip( aUpperLowerMargin
.Lower
) : aUpperLowerMargin
.Lower
;
221 else if ( rVal
>>= nVal
)
224 nVal
= convertMm100ToTwip( nVal
);
235 OSL_FAIL("Wrong MemberId!");
245 bool SvxLongULSpaceItem::GetPresentation(
246 SfxItemPresentation
/*ePres*/,
247 SfxMapUnit
/*eCoreUnit*/,
248 SfxMapUnit
/*ePresUnit*/,
250 const IntlWrapper
* /*pWrapper*/ ) const
255 SfxPoolItem
* SvxLongULSpaceItem::Clone(SfxItemPool
*) const
257 return new SvxLongULSpaceItem(*this);
260 SvxLongULSpaceItem::SvxLongULSpaceItem(long lLeft
, long lRight
, sal_uInt16 nId
) :
266 SvxLongULSpaceItem::SvxLongULSpaceItem(const SvxLongULSpaceItem
&rCpy
) :
268 mlLeft (rCpy
.mlLeft
),
269 mlRight (rCpy
.mlRight
)
272 SvxLongULSpaceItem::SvxLongULSpaceItem() :
280 void SvxLongULSpaceItem::SetUpper(long lArgLeft
)
285 void SvxLongULSpaceItem::SetLower(long lArgRight
)
290 /* SvxPagePosSizeItem */
292 bool SvxPagePosSizeItem::operator==( const SfxPoolItem
& rCmp
) const
294 return SfxPoolItem::operator==(rCmp
) &&
295 aPos
== static_cast<const SvxPagePosSizeItem
&>(rCmp
).aPos
&&
296 lWidth
== static_cast<const SvxPagePosSizeItem
&>(rCmp
).lWidth
&&
297 lHeight
== static_cast<const SvxPagePosSizeItem
&>(rCmp
).lHeight
;
300 bool SvxPagePosSizeItem::QueryValue( ::com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
302 nMemberId
&= ~CONVERT_TWIPS
;
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
;
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;
330 bool SvxPagePosSizeItem::PutValue( const ::com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
332 nMemberId
&= ~CONVERT_TWIPS
;
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
;
349 else if ( rVal
>>= nVal
)
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 false;
367 bool SvxPagePosSizeItem::GetPresentation(
368 SfxItemPresentation
/*ePres*/,
369 SfxMapUnit
/*eCoreUnit*/,
370 SfxMapUnit
/*ePresUnit*/,
372 const IntlWrapper
* /*pWrapper*/ ) const
377 SfxPoolItem
* SvxPagePosSizeItem::Clone(SfxItemPool
*) const
379 return new SvxPagePosSizeItem(*this);
382 SvxPagePosSizeItem::SvxPagePosSizeItem(const Point
&rP
, long lW
, long lH
) :
383 SfxPoolItem (SID_RULER_PAGE_POS
),
389 SvxPagePosSizeItem::SvxPagePosSizeItem(const SvxPagePosSizeItem
&rCpy
) :
392 lWidth (rCpy
.lWidth
),
393 lHeight (rCpy
.lHeight
)
396 SvxPagePosSizeItem::SvxPagePosSizeItem() :
405 bool SvxColumnItem::operator==(const SfxPoolItem
& rCmp
) const
407 if(!SfxPoolItem::operator==(rCmp
) ||
408 nActColumn
!= static_cast<const SvxColumnItem
&>(rCmp
).nActColumn
||
409 nLeft
!= static_cast<const SvxColumnItem
&>(rCmp
).nLeft
||
410 nRight
!= static_cast<const SvxColumnItem
&>(rCmp
).nRight
||
411 bTable
!= static_cast<const SvxColumnItem
&>(rCmp
).bTable
||
412 Count() != static_cast<const SvxColumnItem
&>(rCmp
).Count())
415 const sal_uInt16 nCount
= static_cast<const SvxColumnItem
&>(rCmp
).Count();
416 for(sal_uInt16 i
= 0; i
< nCount
;++i
)
418 if( (*this)[i
] != static_cast<const SvxColumnItem
&>(rCmp
)[i
] )
424 SvxColumnItem::SvxColumnItem( sal_uInt16 nAct
) :
425 SfxPoolItem (SID_RULER_BORDERS
),
434 SvxColumnItem::SvxColumnItem( sal_uInt16 nActCol
, sal_uInt16 left
, sal_uInt16 right
) :
435 SfxPoolItem (SID_RULER_BORDERS
),
438 nActColumn (nActCol
),
443 SvxColumnItem::SvxColumnItem( const SvxColumnItem
& rCopy
) :
446 nRight (rCopy
.nRight
),
447 nActColumn (rCopy
.nActColumn
),
448 bTable (rCopy
.bTable
),
449 bOrtho (rCopy
.bOrtho
)
451 aColumns
.resize(rCopy
.aColumns
.size());
452 std::copy(rCopy
.aColumns
.begin(), rCopy
.aColumns
.end(), aColumns
.begin());
455 SvxColumnItem::~SvxColumnItem()
458 bool SvxColumnItem::GetPresentation(
459 SfxItemPresentation
/*ePres*/,
460 SfxMapUnit
/*eCoreUnit*/,
461 SfxMapUnit
/*ePresUnit*/,
463 const IntlWrapper
* /*pWrapper*/ ) const
468 SfxPoolItem
* SvxColumnItem::Clone(SfxItemPool
* /*pPool*/) const
470 return new SvxColumnItem(*this);
473 const SvxColumnItem
& SvxColumnItem::operator=(const SvxColumnItem
& rCopy
)
476 nRight
= rCopy
.nRight
;
477 bTable
= rCopy
.bTable
;
478 nActColumn
= rCopy
.nActColumn
;
479 aColumns
.resize(rCopy
.aColumns
.size());
481 std::copy(rCopy
.aColumns
.begin(), rCopy
.aColumns
.end(), aColumns
.begin());
486 bool SvxColumnItem::CalcOrtho() const
488 const sal_uInt16 nCount
= Count();
489 DBG_ASSERT(nCount
>= 2, "no columns");
493 long nColWidth
= (*this)[0].GetWidth();
494 for(sal_uInt16 i
= 1; i
< nCount
; ++i
) {
495 if( (*this)[i
].GetWidth() != nColWidth
)
502 bool SvxColumnItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
504 nMemberId
&= ~CONVERT_TWIPS
;
507 case MID_COLUMNARRAY
:
519 rVal
<<= (sal_Int32
) nActColumn
;
525 OSL_FAIL("Wrong MemberId!");
532 bool SvxColumnItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
534 nMemberId
&= ~CONVERT_TWIPS
;
538 case MID_COLUMNARRAY
:
550 bOrtho
= (bool) nVal
;
554 nActColumn
= (sal_uInt16
) nVal
;
558 bTable
= (bool) nVal
;
561 OSL_FAIL("Wrong MemberId!");
568 sal_uInt16
SvxColumnItem::Count() const
570 return aColumns
.size();
573 SvxColumnDescription
& SvxColumnItem::At(sal_uInt16 index
)
575 return aColumns
[index
];
578 SvxColumnDescription
& SvxColumnItem::GetActiveColumnDescription()
580 return aColumns
[GetActColumn()];
583 SvxColumnDescription
& SvxColumnItem::operator[](sal_uInt16 index
)
585 return aColumns
[index
];
588 const SvxColumnDescription
& SvxColumnItem::operator[](sal_uInt16 index
) const
590 return aColumns
[index
];
593 void SvxColumnItem::Insert(const SvxColumnDescription
&rDesc
, sal_uInt16 nPos
)
595 aColumns
.insert(aColumns
.begin() + nPos
, rDesc
);
598 void SvxColumnItem::Append(const SvxColumnDescription
&rDesc
)
600 Insert(rDesc
, Count());
603 void SvxColumnItem::SetLeft(long left
)
608 void SvxColumnItem::SetRight(long right
)
614 bool SvxColumnItem::IsFirstAct() const
616 return nActColumn
== 0;
619 bool SvxColumnItem::IsLastAct() const
621 return nActColumn
== Count() - 1;
624 SvxColumnDescription::SvxColumnDescription() :
632 SvxColumnDescription::SvxColumnDescription(const SvxColumnDescription
&rCopy
) :
633 nStart (rCopy
.nStart
),
635 bVisible (rCopy
.bVisible
),
636 nEndMin (rCopy
.nEndMin
),
637 nEndMax (rCopy
.nEndMax
)
640 SvxColumnDescription::SvxColumnDescription(long start
, long end
, bool bVis
) :
648 SvxColumnDescription::SvxColumnDescription(long start
, long end
, long endMin
, long endMax
, bool bVis
) :
652 // fdo#85858 hack: clamp these to smaller value to prevent overflow
653 nEndMin(std::min
<long>(endMin
, std::numeric_limits
<unsigned short>::max())),
654 nEndMax(std::min
<long>(endMax
, std::numeric_limits
<unsigned short>::max()))
657 bool SvxColumnDescription::operator==(const SvxColumnDescription
& rCmp
) const
659 return nStart
== rCmp
.nStart
660 && bVisible
== rCmp
.bVisible
662 && nEndMin
== rCmp
.nEndMin
663 && nEndMax
== rCmp
.nEndMax
;
666 bool SvxColumnDescription::operator!=(const SvxColumnDescription
& rCmp
) const
668 return !operator==(rCmp
);
671 long SvxColumnDescription::GetWidth() const
673 return nEnd
- nStart
;
677 void SvxColumnItem::SetOrtho(bool bVal
)
682 bool SvxColumnItem::IsConsistent() const
684 return nActColumn
< aColumns
.size();
687 bool SvxObjectItem::operator==( const SfxPoolItem
& rCmp
) const
689 return SfxPoolItem::operator==(rCmp
) &&
690 nStartX
== static_cast<const SvxObjectItem
&>(rCmp
).nStartX
&&
691 nEndX
== static_cast<const SvxObjectItem
&>(rCmp
).nEndX
&&
692 nStartY
== static_cast<const SvxObjectItem
&>(rCmp
).nStartY
&&
693 nEndY
== static_cast<const SvxObjectItem
&>(rCmp
).nEndY
&&
694 bLimits
== static_cast<const SvxObjectItem
&>(rCmp
).bLimits
;
697 bool SvxObjectItem::GetPresentation(
698 SfxItemPresentation
/*ePres*/,
699 SfxMapUnit
/*eCoreUnit*/,
700 SfxMapUnit
/*ePresUnit*/,
702 const IntlWrapper
* /*pWrapper*/ ) const
707 SfxPoolItem
* SvxObjectItem::Clone(SfxItemPool
*) const
709 return new SvxObjectItem(*this);
712 SvxObjectItem::SvxObjectItem( long nSX
, long nEX
,
713 long nSY
, long nEY
, bool limits
) :
714 SfxPoolItem (SID_RULER_OBJECT
),
722 SvxObjectItem::SvxObjectItem( const SvxObjectItem
& rCopy
) :
724 nStartX (rCopy
.nStartX
),
726 nStartY (rCopy
.nStartY
),
728 bLimits (rCopy
.bLimits
)
731 bool SvxObjectItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
733 nMemberId
&= ~CONVERT_TWIPS
;
752 OSL_FAIL( "Wrong MemberId" );
759 bool SvxObjectItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
761 nMemberId
&= ~CONVERT_TWIPS
;
766 bRet
= (rVal
>>= nStartX
);
769 bRet
= (rVal
>>= nStartY
);
772 bRet
= (rVal
>>= nEndX
);
775 bRet
= (rVal
>>= nEndY
);
778 bRet
= (rVal
>>= bLimits
);
780 default: OSL_FAIL( "Wrong MemberId" );
791 void SvxObjectItem::SetStartX(long lValue
)
796 void SvxObjectItem::SetEndX(long lValue
)
801 void SvxObjectItem::SetStartY(long lValue
)
806 void SvxObjectItem::SetEndY(long lValue
)
811 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */