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 <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
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
;
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
;
73 case MID_LEFT
: nVal
= lLeft
; break;
74 case MID_RIGHT
: nVal
= lRight
; break;
75 default: OSL_FAIL("Wrong MemberId!"); return false;
79 nVal
= TWIP_TO_MM100( nVal
);
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
;
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
;
102 else if ( rVal
>>= nVal
)
105 nVal
= MM100_TO_TWIP( nVal
);
109 case MID_LEFT
: lLeft
= nVal
; break;
110 case MID_RIGHT
: lRight
= nVal
; break;
111 default: OSL_FAIL("Wrong MemberId!"); return false;
120 //------------------------------------------------------------------------
122 SfxItemPresentation
SvxLongLRSpaceItem::GetPresentation
124 SfxItemPresentation
/*ePres*/,
125 SfxMapUnit
/*eCoreUnit*/,
126 SfxMapUnit
/*ePresUnit*/,
127 OUString
& /*rText*/, const IntlWrapper
*
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
)
149 //------------------------------------------------------------------------
151 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
157 //------------------------------------------------------------------------
159 SvxLongLRSpaceItem::SvxLongLRSpaceItem(const SvxLongLRSpaceItem
&rCpy
)
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
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
;
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
;
199 case MID_UPPER
: nVal
= lLeft
; break;
200 case MID_LOWER
: nVal
= lRight
; break;
201 default: OSL_FAIL("Wrong MemberId!"); return false;
205 nVal
= TWIP_TO_MM100( nVal
);
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
;
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
;
228 else if ( rVal
>>= nVal
)
231 nVal
= MM100_TO_TWIP( nVal
);
235 case MID_UPPER
: lLeft
= nVal
; break;
236 case MID_LOWER
: lRight
= nVal
; break;
237 default: OSL_FAIL("Wrong MemberId!"); return false;
246 //------------------------------------------------------------------------
248 SfxItemPresentation
SvxLongULSpaceItem::GetPresentation
250 SfxItemPresentation
/*ePres*/,
251 SfxMapUnit
/*eCoreUnit*/,
252 SfxMapUnit
/*ePresUnit*/,
253 OUString
& /*rText*/, const IntlWrapper
*
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
)
274 //------------------------------------------------------------------------
276 SvxLongULSpaceItem::SvxLongULSpaceItem(const SvxLongULSpaceItem
&rCpy
)
282 //------------------------------------------------------------------------
284 SvxLongULSpaceItem::SvxLongULSpaceItem() :
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
;
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 sal_False
;
367 //------------------------------------------------------------------------
369 String
SvxPagePosSizeItem::GetValueText() const
374 //------------------------------------------------------------------------
376 SfxItemPresentation
SvxPagePosSizeItem::GetPresentation
378 SfxItemPresentation
/*ePres*/,
379 SfxMapUnit
/*eCoreUnit*/,
380 SfxMapUnit
/*ePresUnit*/,
381 OUString
& /*rText*/, const IntlWrapper
*
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
),
403 //------------------------------------------------------------------------
405 SvxPagePosSizeItem::SvxPagePosSizeItem(const SvxPagePosSizeItem
&rCpy
)
409 lHeight(rCpy
.lHeight
)
412 //------------------------------------------------------------------------
414 SvxPagePosSizeItem::SvxPagePosSizeItem()
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())
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
] )
441 //------------------------------------------------------------------------
443 String
SvxColumnItem::GetValueText() const
448 //------------------------------------------------------------------------
450 SfxItemPresentation
SvxColumnItem::GetPresentation
452 SfxItemPresentation
/*ePres*/,
453 SfxMapUnit
/*eCoreUnit*/,
454 SfxMapUnit
/*ePresUnit*/,
455 OUString
& /*rText*/, const IntlWrapper
*
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
),
477 bTable ( sal_False
),
483 //------------------------------------------------------------------------
485 SvxColumnItem::SvxColumnItem( sal_uInt16 nActCol
, sal_uInt16 left
, sal_uInt16 right
) :
487 SfxPoolItem( SID_RULER_BORDERS
),
491 nActColumn ( nActCol
),
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
)
516 nRight
= rCopy
.nRight
;
517 bTable
= rCopy
.bTable
;
518 nActColumn
= rCopy
.nActColumn
;
520 for(size_t i
= 0; i
< rCopy
.Count(); ++i
)
521 aColumns
.push_back(rCopy
[i
]);
525 sal_Bool
SvxColumnItem::CalcOrtho() const
527 const sal_uInt16 nCount
= Count();
528 DBG_ASSERT(nCount
>= 2, "no columns");
532 long nColWidth
= (*this)[0].GetWidth();
533 for(sal_uInt16 i
= 1; i
< nCount
; ++i
) {
534 if( (*this)[i
].GetWidth() != nColWidth
)
541 //------------------------------------------------------------------------
543 bool SvxColumnItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
545 nMemberId
&= ~CONVERT_TWIPS
;
548 case MID_COLUMNARRAY
:
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
;
563 bool SvxColumnItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
565 nMemberId
&= ~CONVERT_TWIPS
;
569 case MID_COLUMNARRAY
:
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
;
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
603 //------------------------------------------------------------------------
605 SfxItemPresentation
SvxObjectItem::GetPresentation
607 SfxItemPresentation
/*ePres*/,
608 SfxMapUnit
/*eCoreUnit*/,
609 SfxMapUnit
/*ePresUnit*/,
610 OUString
& /*rText*/, const IntlWrapper
*
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
),
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
;
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;
665 OSL_FAIL( "Wrong MemberId" );
672 bool SvxObjectItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
674 nMemberId
&= ~CONVERT_TWIPS
;
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" );
689 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */