Best effort to create directories of SAL_LOG_FILE
[LibreOffice.git] / svx / source / dialog / rulritem.cxx
blob8e61bf381c3dfdba6548bf6ae2074d9fff111915
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 <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;
52 sal_Int32 nVal;
53 switch( nMemberId )
55 case 0:
57 css::frame::status::LeftRightMargin aLeftRightMargin;
58 aLeftRightMargin.Left = bConvert ? convertTwipToMm100( mlLeft ) : mlLeft;
59 aLeftRightMargin.Right = bConvert ? convertTwipToMm100( mlRight ) : mlRight;
60 rVal <<= aLeftRightMargin;
61 return true;
64 case MID_LEFT:
65 nVal = mlLeft;
66 break;
67 case MID_RIGHT:
68 nVal = mlRight;
69 break;
70 default:
71 OSL_FAIL("Wrong MemberId!");
72 return false;
75 if ( bConvert )
76 nVal = convertTwipToMm100( nVal );
78 rVal <<= nVal;
79 return true;
82 bool SvxLongLRSpaceItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
84 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
85 nMemberId &= ~CONVERT_TWIPS;
87 sal_Int32 nVal = 0;
88 if ( nMemberId == 0 )
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;
95 return true;
98 else if ( rVal >>= nVal )
100 if ( bConvert )
101 nVal = o3tl::toTwips(nVal, o3tl::Length::mm100);
103 switch( nMemberId )
105 case MID_LEFT:
106 mlLeft = nVal;
107 break;
108 case MID_RIGHT:
109 mlRight = nVal;
110 break;
111 default:
112 OSL_FAIL("Wrong MemberId!");
113 return false;
116 return true;
119 return false;
122 bool SvxLongLRSpaceItem::GetPresentation(
123 SfxItemPresentation /*ePres*/,
124 MapUnit /*eCoreUnit*/,
125 MapUnit /*ePresUnit*/,
126 OUString& /*rText*/,
127 const IntlWrapper& /*rWrapper*/) const
129 return false;
132 SvxLongLRSpaceItem* SvxLongLRSpaceItem::Clone(SfxItemPool *) const
134 return new SvxLongLRSpaceItem(*this);
137 SvxLongLRSpaceItem::SvxLongLRSpaceItem(tools::Long lLeft, tools::Long lRight, TypedWhichId<SvxLongLRSpaceItem> nId) :
138 SfxPoolItem (nId),
139 mlLeft (lLeft),
140 mlRight (lRight)
143 SvxLongLRSpaceItem::SvxLongLRSpaceItem() :
144 SfxPoolItem (0),
145 mlLeft (0),
146 mlRight (0)
149 void SvxLongLRSpaceItem::SetLeft(tools::Long lArgLeft)
151 mlLeft = lArgLeft;
154 void SvxLongLRSpaceItem::SetRight(tools::Long lArgRight)
156 mlRight = 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;
173 sal_Int32 nVal;
174 switch( nMemberId )
176 case 0:
178 css::frame::status::UpperLowerMargin aUpperLowerMargin;
179 aUpperLowerMargin.Upper = bConvert ? convertTwipToMm100( mlLeft ) : mlLeft;
180 aUpperLowerMargin.Lower = bConvert ? convertTwipToMm100( mlRight ) : mlRight;
181 rVal <<= aUpperLowerMargin;
182 return true;
185 case MID_UPPER:
186 nVal = mlLeft;
187 break;
188 case MID_LOWER:
189 nVal = mlRight;
190 break;
191 default: OSL_FAIL("Wrong MemberId!"); return false;
194 if ( bConvert )
195 nVal = convertTwipToMm100( nVal );
197 rVal <<= nVal;
198 return true;
201 bool SvxLongULSpaceItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
203 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
204 nMemberId &= ~CONVERT_TWIPS;
206 sal_Int32 nVal = 0;
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;
214 return true;
217 else if ( rVal >>= nVal )
219 if ( bConvert )
220 nVal = o3tl::toTwips(nVal, o3tl::Length::mm100);
222 switch( nMemberId )
224 case MID_UPPER:
225 mlLeft = nVal;
226 break;
227 case MID_LOWER:
228 mlRight = nVal;
229 break;
230 default:
231 OSL_FAIL("Wrong MemberId!");
232 return false;
235 return true;
238 return false;
241 bool SvxLongULSpaceItem::GetPresentation(
242 SfxItemPresentation /*ePres*/,
243 MapUnit /*eCoreUnit*/,
244 MapUnit /*ePresUnit*/,
245 OUString& /*rText*/,
246 const IntlWrapper& /*rWrapper*/ ) const
248 return false;
251 SvxLongULSpaceItem* SvxLongULSpaceItem::Clone(SfxItemPool *) const
253 return new SvxLongULSpaceItem(*this);
256 SvxLongULSpaceItem::SvxLongULSpaceItem(tools::Long lLeft, tools::Long lRight, TypedWhichId<SvxLongULSpaceItem> nId) :
257 SfxPoolItem (nId),
258 mlLeft (lLeft),
259 mlRight (lRight)
262 SvxLongULSpaceItem::SvxLongULSpaceItem() :
263 SfxPoolItem (0),
264 mlLeft (0),
265 mlRight (0)
269 void SvxLongULSpaceItem::SetUpper(tools::Long lArgLeft)
271 mlLeft = lArgLeft;
274 void SvxLongULSpaceItem::SetLower(tools::Long lArgRight)
276 mlRight = 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;
293 sal_Int32 nVal;
294 switch ( nMemberId )
296 case 0 :
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;
304 return true;
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;
315 rVal <<= nVal;
316 return true;
319 bool SvxPagePosSizeItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
321 nMemberId &= ~CONVERT_TWIPS;
323 sal_Int32 nVal = 0;
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;
333 return true;
335 else
336 return false;
338 else if ( rVal >>= nVal )
340 switch ( nMemberId )
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;
350 return true;
353 return false;
356 bool SvxPagePosSizeItem::GetPresentation(
357 SfxItemPresentation /*ePres*/,
358 MapUnit /*eCoreUnit*/,
359 MapUnit /*ePresUnit*/,
360 OUString& /*rText*/,
361 const IntlWrapper& /*rWrapper*/ ) const
363 return false;
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),
373 aPos (rP),
374 lWidth (lW),
375 lHeight (lH)
378 SvxPagePosSizeItem::SvxPagePosSizeItem() :
379 SfxPoolItem (0),
380 aPos (0, 0),
381 lWidth (0),
382 lHeight (0)
385 /* SvxColumnItem */
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())
395 return false;
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] )
401 return false;
403 return true;
406 SvxColumnItem::SvxColumnItem( sal_uInt16 nAct ) :
407 SfxPoolItem (SID_RULER_BORDERS),
408 nLeft (0),
409 nRight (0),
410 nActColumn (nAct),
411 bTable (false),
412 bOrtho (true)
416 SvxColumnItem::SvxColumnItem( sal_uInt16 nActCol, sal_uInt16 left, sal_uInt16 right ) :
417 SfxPoolItem (SID_RULER_BORDERS),
418 nLeft (left),
419 nRight (right),
420 nActColumn (nActCol),
421 bTable (true),
422 bOrtho (true)
425 bool SvxColumnItem::GetPresentation(
426 SfxItemPresentation /*ePres*/,
427 MapUnit /*eCoreUnit*/,
428 MapUnit /*ePresUnit*/,
429 OUString& /*rText*/,
430 const IntlWrapper& /*rWrapper*/ ) const
432 return false;
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");
444 if(nCount < 2)
445 return false;
447 tools::Long nColWidth = (*this)[0].GetWidth();
448 for(sal_uInt16 i = 1; i < nCount; ++i) {
449 if( (*this)[i].GetWidth() != nColWidth)
450 return false;
452 //!! Wide divider
453 return true;
456 bool SvxColumnItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
458 nMemberId &= ~CONVERT_TWIPS;
459 switch ( nMemberId )
461 case 0:
462 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this;
463 SAL_INFO("svx", "SvxColumnItem::QueryValue with nMemberId of 0");
464 return false;
465 case MID_COLUMNARRAY:
466 return false;
467 case MID_RIGHT:
468 rVal <<= nRight;
469 break;
470 case MID_LEFT:
471 rVal <<= nLeft;
472 break;
473 case MID_ORTHO:
474 rVal <<= bOrtho;
475 break;
476 case MID_ACTUAL:
477 rVal <<= static_cast<sal_Int32>(nActColumn);
478 break;
479 case MID_TABLE:
480 rVal <<= bTable;
481 break;
482 default:
483 SAL_WARN("svx", "Wrong MemberId!");
484 return false;
487 return true;
490 bool SvxColumnItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
492 nMemberId &= ~CONVERT_TWIPS;
493 sal_Int32 nVal = 0;
494 switch ( nMemberId )
496 case MID_COLUMNARRAY:
498 return false;
500 case MID_RIGHT:
501 rVal >>= nRight;
502 break;
503 case MID_LEFT:
504 rVal >>= nLeft;
505 break;
506 case MID_ORTHO:
507 rVal >>= nVal;
508 bOrtho = static_cast<bool>(nVal);
509 break;
510 case MID_ACTUAL:
511 rVal >>= nVal;
512 nActColumn = static_cast<sal_uInt16>(nVal);
513 break;
514 case MID_TABLE:
515 rVal >>= nVal;
516 bTable = static_cast<bool>(nVal);
517 break;
518 default:
519 OSL_FAIL("Wrong MemberId!");
520 return false;
523 return true;
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)
558 nLeft = left;
561 void SvxColumnItem::SetRight(tools::Long right)
563 nRight = 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) :
578 nStart (start),
579 nEnd (end),
580 bVisible (bVis),
581 nEndMin (0),
582 nEndMax (0)
585 SvxColumnDescription::SvxColumnDescription(tools::Long start, tools::Long end, tools::Long endMin, tools::Long endMax, bool bVis) :
586 nStart (start),
587 nEnd (end),
588 bVisible (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
598 && nEnd == rCmp.nEnd
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;
613 /* SvxColumnItem */
614 void SvxColumnItem::SetOrtho(bool bVal)
616 bOrtho = 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*/,
638 OUString& /*rText*/,
639 const IntlWrapper& /*rWrapper*/ ) const
641 return false;
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),
652 nStartX (nSX),
653 nEndX (nEX),
654 nStartY (nSY),
655 nEndY (nEY),
656 bLimits (false)
659 bool SvxObjectItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
661 nMemberId &= ~CONVERT_TWIPS;
662 switch (nMemberId)
664 case MID_START_X:
665 rVal <<= nStartX;
666 break;
667 case MID_START_Y:
668 rVal <<= nStartY;
669 break;
670 case MID_END_X:
671 rVal <<= nEndX;
672 break;
673 case MID_END_Y:
674 rVal <<= nEndY;
675 break;
676 case MID_LIMIT:
677 rVal <<= bLimits;
678 break;
679 default:
680 OSL_FAIL( "Wrong MemberId" );
681 return false;
684 return true;
687 bool SvxObjectItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
689 nMemberId &= ~CONVERT_TWIPS;
690 bool bRet = false;
691 switch (nMemberId)
693 case MID_START_X:
694 bRet = (rVal >>= nStartX);
695 break;
696 case MID_START_Y:
697 bRet = (rVal >>= nStartY);
698 break;
699 case MID_END_X:
700 bRet = (rVal >>= nEndX);
701 break;
702 case MID_END_Y:
703 bRet = (rVal >>= nEndY);
704 break;
705 case MID_LIMIT:
706 bRet = (rVal >>= bLimits);
707 break;
708 default: OSL_FAIL( "Wrong MemberId" );
711 return bRet;
715 void SvxObjectItem::SetStartX(tools::Long lValue)
717 nStartX = lValue;
720 void SvxObjectItem::SetEndX(tools::Long lValue)
722 nEndX = lValue;
725 void SvxObjectItem::SetStartY(tools::Long lValue)
727 nStartY = lValue;
730 void SvxObjectItem::SetEndY(tools::Long lValue)
732 nEndY = lValue;
735 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */