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/svxids.hrc>
21 #include <svx/rulritem.hxx>
22 #include <svx/unomid.hxx>
23 #include <tools/debug.hxx>
24 #include <tools/mapunit.hxx>
25 #include <tools/UnitConversion.hxx>
26 #include <osl/diagnose.h>
27 #include <sal/log.hxx>
28 #include <com/sun/star/awt/Rectangle.hpp>
29 #include <com/sun/star/frame/status/LeftRightMargin.hpp>
30 #include <com/sun/star/frame/status/UpperLowerMargin.hpp>
32 SfxPoolItem
* SvxPagePosSizeItem::CreateDefault() { return new SvxPagePosSizeItem
; }
33 SfxPoolItem
* SvxLongLRSpaceItem::CreateDefault() { return new SvxLongLRSpaceItem
; }
34 SfxPoolItem
* SvxLongULSpaceItem::CreateDefault() { return new SvxLongULSpaceItem
; }
35 SfxPoolItem
* SvxColumnItem::CreateDefault() { return new SvxColumnItem
; }
36 SfxPoolItem
* SvxObjectItem::CreateDefault() { SAL_WARN( "svx", "No SvxObjectItem factory available"); return nullptr; }
38 /* SvxLongLRSpaceItem */
40 bool SvxLongLRSpaceItem::operator==( const SfxPoolItem
& rCmp
) const
42 return SfxPoolItem::operator==(rCmp
) &&
43 mlLeft
== static_cast<const SvxLongLRSpaceItem
&>(rCmp
).mlLeft
&&
44 mlRight
== static_cast<const SvxLongLRSpaceItem
&>(rCmp
).mlRight
;
47 bool SvxLongLRSpaceItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
49 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
50 nMemberId
&= ~CONVERT_TWIPS
;
57 css::frame::status::LeftRightMargin aLeftRightMargin
;
58 aLeftRightMargin
.Left
= bConvert
? convertTwipToMm100( mlLeft
) : mlLeft
;
59 aLeftRightMargin
.Right
= bConvert
? convertTwipToMm100( mlRight
) : mlRight
;
60 rVal
<<= aLeftRightMargin
;
71 OSL_FAIL("Wrong MemberId!");
76 nVal
= convertTwipToMm100( nVal
);
82 bool SvxLongLRSpaceItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
84 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
85 nMemberId
&= ~CONVERT_TWIPS
;
90 css::frame::status::LeftRightMargin aLeftRightMargin
;
91 if ( rVal
>>= aLeftRightMargin
)
93 mlLeft
= bConvert
? o3tl::toTwips(aLeftRightMargin
.Left
, o3tl::Length::mm100
) : aLeftRightMargin
.Left
;
94 mlRight
= bConvert
? o3tl::toTwips(aLeftRightMargin
.Right
, o3tl::Length::mm100
) : aLeftRightMargin
.Right
;
98 else if ( rVal
>>= nVal
)
101 nVal
= o3tl::toTwips(nVal
, o3tl::Length::mm100
);
112 OSL_FAIL("Wrong MemberId!");
122 bool SvxLongLRSpaceItem::GetPresentation(
123 SfxItemPresentation
/*ePres*/,
124 MapUnit
/*eCoreUnit*/,
125 MapUnit
/*ePresUnit*/,
127 const IntlWrapper
& /*rWrapper*/) const
132 SvxLongLRSpaceItem
* SvxLongLRSpaceItem::Clone(SfxItemPool
*) const
134 return new SvxLongLRSpaceItem(*this);
137 SvxLongLRSpaceItem::SvxLongLRSpaceItem(tools::Long lLeft
, tools::Long lRight
, TypedWhichId
<SvxLongLRSpaceItem
> nId
) :
143 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
149 void SvxLongLRSpaceItem::SetLeft(tools::Long lArgLeft
)
154 void SvxLongLRSpaceItem::SetRight(tools::Long lArgRight
)
159 /* SvxLongULSpaceItem */
161 bool SvxLongULSpaceItem::operator==( const SfxPoolItem
& rCmp
) const
163 return SfxPoolItem::operator==(rCmp
) &&
164 mlLeft
== static_cast<const SvxLongULSpaceItem
&>(rCmp
).mlLeft
&&
165 mlRight
== static_cast<const SvxLongULSpaceItem
&>(rCmp
).mlRight
;
168 bool SvxLongULSpaceItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
170 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
171 nMemberId
&= ~CONVERT_TWIPS
;
178 css::frame::status::UpperLowerMargin aUpperLowerMargin
;
179 aUpperLowerMargin
.Upper
= bConvert
? convertTwipToMm100( mlLeft
) : mlLeft
;
180 aUpperLowerMargin
.Lower
= bConvert
? convertTwipToMm100( mlRight
) : mlRight
;
181 rVal
<<= aUpperLowerMargin
;
191 default: OSL_FAIL("Wrong MemberId!"); return false;
195 nVal
= convertTwipToMm100( nVal
);
201 bool SvxLongULSpaceItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
203 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
204 nMemberId
&= ~CONVERT_TWIPS
;
207 if ( nMemberId
== 0 )
209 css::frame::status::UpperLowerMargin aUpperLowerMargin
;
210 if ( rVal
>>= aUpperLowerMargin
)
212 mlLeft
= bConvert
? o3tl::toTwips(aUpperLowerMargin
.Upper
, o3tl::Length::mm100
) : aUpperLowerMargin
.Upper
;
213 mlRight
= bConvert
? o3tl::toTwips(aUpperLowerMargin
.Lower
, o3tl::Length::mm100
) : aUpperLowerMargin
.Lower
;
217 else if ( rVal
>>= nVal
)
220 nVal
= o3tl::toTwips(nVal
, o3tl::Length::mm100
);
231 OSL_FAIL("Wrong MemberId!");
241 bool SvxLongULSpaceItem::GetPresentation(
242 SfxItemPresentation
/*ePres*/,
243 MapUnit
/*eCoreUnit*/,
244 MapUnit
/*ePresUnit*/,
246 const IntlWrapper
& /*rWrapper*/ ) const
251 SvxLongULSpaceItem
* SvxLongULSpaceItem::Clone(SfxItemPool
*) const
253 return new SvxLongULSpaceItem(*this);
256 SvxLongULSpaceItem::SvxLongULSpaceItem(tools::Long lLeft
, tools::Long lRight
, TypedWhichId
<SvxLongULSpaceItem
> nId
) :
262 SvxLongULSpaceItem::SvxLongULSpaceItem() :
269 void SvxLongULSpaceItem::SetUpper(tools::Long lArgLeft
)
274 void SvxLongULSpaceItem::SetLower(tools::Long lArgRight
)
279 /* SvxPagePosSizeItem */
281 bool SvxPagePosSizeItem::operator==( const SfxPoolItem
& rCmp
) const
283 return SfxPoolItem::operator==(rCmp
) &&
284 aPos
== static_cast<const SvxPagePosSizeItem
&>(rCmp
).aPos
&&
285 lWidth
== static_cast<const SvxPagePosSizeItem
&>(rCmp
).lWidth
&&
286 lHeight
== static_cast<const SvxPagePosSizeItem
&>(rCmp
).lHeight
;
289 bool SvxPagePosSizeItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
291 nMemberId
&= ~CONVERT_TWIPS
;
298 css::awt::Rectangle aPagePosSize
;
299 aPagePosSize
.X
= aPos
.X();
300 aPagePosSize
.Y
= aPos
.Y();
301 aPagePosSize
.Width
= lWidth
;
302 aPagePosSize
.Height
= lHeight
;
303 rVal
<<= aPagePosSize
;
307 case MID_X
: nVal
= aPos
.X(); break;
308 case MID_Y
: nVal
= aPos
.Y(); break;
309 case MID_WIDTH
: nVal
= lWidth
; break;
310 case MID_HEIGHT
: nVal
= lHeight
; break;
312 default: OSL_FAIL("Wrong MemberId!"); return false;
319 bool SvxPagePosSizeItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
321 nMemberId
&= ~CONVERT_TWIPS
;
324 if ( nMemberId
== 0 )
326 css::awt::Rectangle aPagePosSize
;
327 if ( rVal
>>= aPagePosSize
)
329 aPos
.setX( aPagePosSize
.X
);
330 aPos
.setY( aPagePosSize
.Y
);
331 lWidth
= aPagePosSize
.Width
;
332 lHeight
= aPagePosSize
.Height
;
338 else if ( rVal
>>= nVal
)
342 case MID_X
: aPos
.setX( nVal
); break;
343 case MID_Y
: aPos
.setY( nVal
); break;
344 case MID_WIDTH
: lWidth
= nVal
; break;
345 case MID_HEIGHT
: lHeight
= nVal
; break;
347 default: OSL_FAIL("Wrong MemberId!"); return false;
356 bool SvxPagePosSizeItem::GetPresentation(
357 SfxItemPresentation
/*ePres*/,
358 MapUnit
/*eCoreUnit*/,
359 MapUnit
/*ePresUnit*/,
361 const IntlWrapper
& /*rWrapper*/ ) const
366 SvxPagePosSizeItem
* SvxPagePosSizeItem::Clone(SfxItemPool
*) const
368 return new SvxPagePosSizeItem(*this);
371 SvxPagePosSizeItem::SvxPagePosSizeItem(const Point
&rP
, tools::Long lW
, tools::Long lH
) :
372 SfxPoolItem (SID_RULER_PAGE_POS
),
378 SvxPagePosSizeItem::SvxPagePosSizeItem() :
387 bool SvxColumnItem::operator==(const SfxPoolItem
& rCmp
) const
389 if(!SfxPoolItem::operator==(rCmp
) ||
390 nActColumn
!= static_cast<const SvxColumnItem
&>(rCmp
).nActColumn
||
391 nLeft
!= static_cast<const SvxColumnItem
&>(rCmp
).nLeft
||
392 nRight
!= static_cast<const SvxColumnItem
&>(rCmp
).nRight
||
393 bTable
!= static_cast<const SvxColumnItem
&>(rCmp
).bTable
||
394 Count() != static_cast<const SvxColumnItem
&>(rCmp
).Count())
397 const sal_uInt16 nCount
= static_cast<const SvxColumnItem
&>(rCmp
).Count();
398 for(sal_uInt16 i
= 0; i
< nCount
;++i
)
400 if( (*this)[i
] != static_cast<const SvxColumnItem
&>(rCmp
)[i
] )
406 SvxColumnItem::SvxColumnItem( sal_uInt16 nAct
) :
407 SfxPoolItem (SID_RULER_BORDERS
),
416 SvxColumnItem::SvxColumnItem( sal_uInt16 nActCol
, sal_uInt16 left
, sal_uInt16 right
) :
417 SfxPoolItem (SID_RULER_BORDERS
),
420 nActColumn (nActCol
),
425 bool SvxColumnItem::GetPresentation(
426 SfxItemPresentation
/*ePres*/,
427 MapUnit
/*eCoreUnit*/,
428 MapUnit
/*ePresUnit*/,
430 const IntlWrapper
& /*rWrapper*/ ) const
435 SvxColumnItem
* SvxColumnItem::Clone(SfxItemPool
* /*pPool*/) const
437 return new SvxColumnItem(*this);
440 bool SvxColumnItem::CalcOrtho() const
442 const sal_uInt16 nCount
= Count();
443 DBG_ASSERT(nCount
>= 2, "no columns");
447 tools::Long nColWidth
= (*this)[0].GetWidth();
448 for(sal_uInt16 i
= 1; i
< nCount
; ++i
) {
449 if( (*this)[i
].GetWidth() != nColWidth
)
456 bool SvxColumnItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
458 nMemberId
&= ~CONVERT_TWIPS
;
462 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this;
463 SAL_INFO("svx", "SvxColumnItem::QueryValue with nMemberId of 0");
465 case MID_COLUMNARRAY
:
477 rVal
<<= static_cast<sal_Int32
>(nActColumn
);
483 SAL_WARN("svx", "Wrong MemberId!");
490 bool SvxColumnItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
492 nMemberId
&= ~CONVERT_TWIPS
;
496 case MID_COLUMNARRAY
:
508 bOrtho
= static_cast<bool>(nVal
);
512 nActColumn
= static_cast<sal_uInt16
>(nVal
);
516 bTable
= static_cast<bool>(nVal
);
519 OSL_FAIL("Wrong MemberId!");
526 sal_uInt16
SvxColumnItem::Count() const
528 return aColumns
.size();
531 SvxColumnDescription
& SvxColumnItem::At(sal_uInt16 index
)
533 return aColumns
[index
];
536 SvxColumnDescription
& SvxColumnItem::GetActiveColumnDescription()
538 return aColumns
[GetActColumn()];
541 SvxColumnDescription
& SvxColumnItem::operator[](sal_uInt16 index
)
543 return aColumns
[index
];
546 const SvxColumnDescription
& SvxColumnItem::operator[](sal_uInt16 index
) const
548 return aColumns
[index
];
551 void SvxColumnItem::Append(const SvxColumnDescription
&rDesc
)
553 aColumns
.push_back(rDesc
);
556 void SvxColumnItem::SetLeft(tools::Long left
)
561 void SvxColumnItem::SetRight(tools::Long right
)
567 bool SvxColumnItem::IsFirstAct() const
569 return nActColumn
== 0;
572 bool SvxColumnItem::IsLastAct() const
574 return nActColumn
== Count() - 1;
577 SvxColumnDescription::SvxColumnDescription(tools::Long start
, tools::Long end
, bool bVis
) :
585 SvxColumnDescription::SvxColumnDescription(tools::Long start
, tools::Long end
, tools::Long endMin
, tools::Long endMax
, bool bVis
) :
589 // fdo#85858 hack: clamp these to smaller value to prevent overflow
590 nEndMin(std::min
<tools::Long
>(endMin
, std::numeric_limits
<unsigned short>::max())),
591 nEndMax(std::min
<tools::Long
>(endMax
, std::numeric_limits
<unsigned short>::max()))
594 bool SvxColumnDescription::operator==(const SvxColumnDescription
& rCmp
) const
596 return nStart
== rCmp
.nStart
597 && bVisible
== rCmp
.bVisible
599 && nEndMin
== rCmp
.nEndMin
600 && nEndMax
== rCmp
.nEndMax
;
603 bool SvxColumnDescription::operator!=(const SvxColumnDescription
& rCmp
) const
605 return !operator==(rCmp
);
608 tools::Long
SvxColumnDescription::GetWidth() const
610 return nEnd
- nStart
;
614 void SvxColumnItem::SetOrtho(bool bVal
)
619 bool SvxColumnItem::IsConsistent() const
621 return nActColumn
< aColumns
.size();
624 bool SvxObjectItem::operator==( const SfxPoolItem
& rCmp
) const
626 return SfxPoolItem::operator==(rCmp
) &&
627 nStartX
== static_cast<const SvxObjectItem
&>(rCmp
).nStartX
&&
628 nEndX
== static_cast<const SvxObjectItem
&>(rCmp
).nEndX
&&
629 nStartY
== static_cast<const SvxObjectItem
&>(rCmp
).nStartY
&&
630 nEndY
== static_cast<const SvxObjectItem
&>(rCmp
).nEndY
&&
631 bLimits
== static_cast<const SvxObjectItem
&>(rCmp
).bLimits
;
634 bool SvxObjectItem::GetPresentation(
635 SfxItemPresentation
/*ePres*/,
636 MapUnit
/*eCoreUnit*/,
637 MapUnit
/*ePresUnit*/,
639 const IntlWrapper
& /*rWrapper*/ ) const
644 SvxObjectItem
* SvxObjectItem::Clone(SfxItemPool
*) const
646 return new SvxObjectItem(*this);
649 SvxObjectItem::SvxObjectItem( tools::Long nSX
, tools::Long nEX
,
650 tools::Long nSY
, tools::Long nEY
) :
651 SfxPoolItem (SID_RULER_OBJECT
),
659 bool SvxObjectItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
661 nMemberId
&= ~CONVERT_TWIPS
;
680 OSL_FAIL( "Wrong MemberId" );
687 bool SvxObjectItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
689 nMemberId
&= ~CONVERT_TWIPS
;
694 bRet
= (rVal
>>= nStartX
);
697 bRet
= (rVal
>>= nStartY
);
700 bRet
= (rVal
>>= nEndX
);
703 bRet
= (rVal
>>= nEndY
);
706 bRet
= (rVal
>>= bLimits
);
708 default: OSL_FAIL( "Wrong MemberId" );
715 void SvxObjectItem::SetStartX(tools::Long lValue
)
720 void SvxObjectItem::SetEndX(tools::Long lValue
)
725 void SvxObjectItem::SetStartY(tools::Long lValue
)
730 void SvxObjectItem::SetEndY(tools::Long lValue
)
735 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */