bump product version to 7.6.3.2-android
[LibreOffice.git] / editeng / source / items / frmitems.cxx
blob94b7704303baab18a5c227c6deaa208cc402dfb8
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 <memory>
21 #include <com/sun/star/uno/Any.hxx>
22 #include <com/sun/star/drawing/LineStyle.hpp>
23 #include <com/sun/star/script/Converter.hpp>
24 #include <com/sun/star/table/ShadowLocation.hpp>
25 #include <com/sun/star/table/ShadowFormat.hpp>
26 #include <com/sun/star/table/BorderLine2.hpp>
27 #include <com/sun/star/table/BorderLineStyle.hpp>
28 #include <com/sun/star/style/BreakType.hpp>
29 #include <com/sun/star/style/GraphicLocation.hpp>
30 #include <com/sun/star/awt/Size.hpp>
31 #include <com/sun/star/text/WritingMode2.hpp>
32 #include <com/sun/star/frame/status/UpperLowerMarginScale.hpp>
33 #include <com/sun/star/frame/status/LeftRightMarginScale.hpp>
34 #include <com/sun/star/drawing/ShadingPattern.hpp>
35 #include <com/sun/star/graphic/XGraphic.hpp>
36 #include <com/sun/star/util/XComplexColor.hpp>
38 #include <osl/diagnose.h>
39 #include <i18nutil/unicode.hxx>
40 #include <unotools/ucbstreamhelper.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <utility>
43 #include <vcl/GraphicObject.hxx>
44 #include <tools/urlobj.hxx>
45 #include <tools/bigint.hxx>
46 #include <svl/memberid.h>
47 #include <rtl/math.hxx>
48 #include <rtl/ustring.hxx>
49 #include <tools/mapunit.hxx>
50 #include <tools/UnitConversion.hxx>
51 #include <vcl/graphicfilter.hxx>
52 #include <vcl/settings.hxx>
53 #include <vcl/svapp.hxx>
54 #include <editeng/editrids.hrc>
55 #include <editeng/pbinitem.hxx>
56 #include <editeng/sizeitem.hxx>
57 #include <editeng/lrspitem.hxx>
58 #include <editeng/ulspitem.hxx>
59 #include <editeng/prntitem.hxx>
60 #include <editeng/opaqitem.hxx>
61 #include <editeng/protitem.hxx>
62 #include <editeng/shaditem.hxx>
63 #include <editeng/borderline.hxx>
64 #include <editeng/boxitem.hxx>
65 #include <editeng/formatbreakitem.hxx>
66 #include <editeng/keepitem.hxx>
67 #include <editeng/lineitem.hxx>
68 #include <editeng/brushitem.hxx>
69 #include <editeng/frmdiritem.hxx>
70 #include <editeng/itemtype.hxx>
71 #include <editeng/eerdll.hxx>
72 #include <editeng/memberids.h>
73 #include <libxml/xmlwriter.h>
74 #include <o3tl/enumrange.hxx>
75 #include <o3tl/safeint.hxx>
76 #include <sal/log.hxx>
77 #include <vcl/GraphicLoader.hxx>
78 #include <unotools/securityoptions.hxx>
79 #include <docmodel/uno/UnoComplexColor.hxx>
81 #include <boost/property_tree/ptree.hpp>
83 using namespace ::editeng;
84 using namespace ::com::sun::star;
85 using namespace ::com::sun::star::drawing;
86 using namespace ::com::sun::star::table::BorderLineStyle;
89 SfxPoolItem* SvxPaperBinItem::CreateDefault() { return new SvxPaperBinItem(0);}
90 SfxPoolItem* SvxSizeItem::CreateDefault() { return new SvxSizeItem(0);}
91 SfxPoolItem* SvxLRSpaceItem::CreateDefault() { return new SvxLRSpaceItem(0);}
92 SfxPoolItem* SvxULSpaceItem::CreateDefault() { return new SvxULSpaceItem(0);}
93 SfxPoolItem* SvxProtectItem::CreateDefault() { return new SvxProtectItem(0);}
94 SfxPoolItem* SvxBrushItem::CreateDefault() { return new SvxBrushItem(0);}
95 SfxPoolItem* SvxShadowItem::CreateDefault() { return new SvxShadowItem(0);}
96 SfxPoolItem* SvxBoxItem::CreateDefault() { return new SvxBoxItem(0);}
97 SfxPoolItem* SvxBoxInfoItem::CreateDefault() { return new SvxBoxInfoItem(0);}
98 SfxPoolItem* SvxFormatBreakItem::CreateDefault() { return new SvxFormatBreakItem(SvxBreak::NONE, 0);}
99 SfxPoolItem* SvxFormatKeepItem::CreateDefault() { return new SvxFormatKeepItem(false, 0);}
100 SfxPoolItem* SvxLineItem::CreateDefault() { return new SvxLineItem(0);}
102 SvxPaperBinItem* SvxPaperBinItem::Clone( SfxItemPool* ) const
104 return new SvxPaperBinItem( *this );
107 bool SvxPaperBinItem::GetPresentation
109 SfxItemPresentation ePres,
110 MapUnit /*eCoreUnit*/,
111 MapUnit /*ePresUnit*/,
112 OUString& rText, const IntlWrapper&
113 ) const
115 switch ( ePres )
117 case SfxItemPresentation::Nameless:
118 rText = OUString::number( GetValue() );
119 return true;
121 case SfxItemPresentation::Complete:
123 sal_uInt8 nValue = GetValue();
125 if ( PAPERBIN_PRINTER_SETTINGS == nValue )
126 rText = EditResId(RID_SVXSTR_PAPERBIN_SETTINGS);
127 else
129 rText = EditResId(RID_SVXSTR_PAPERBIN) + " " + OUString::number( nValue );
131 return true;
133 //no break necessary
134 default: ; //prevent warning
137 return false;
141 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId, const Size& rSize ) :
143 SfxPoolItem( nId ),
145 m_aSize( rSize )
150 bool SvxSizeItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
152 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
153 nMemberId &= ~CONVERT_TWIPS;
155 awt::Size aTmp(m_aSize.Width(), m_aSize.Height());
156 if( bConvert )
158 aTmp.Height = convertTwipToMm100(aTmp.Height);
159 aTmp.Width = convertTwipToMm100(aTmp.Width);
162 switch( nMemberId )
164 case MID_SIZE_SIZE: rVal <<= aTmp; break;
165 case MID_SIZE_WIDTH: rVal <<= aTmp.Width; break;
166 case MID_SIZE_HEIGHT: rVal <<= aTmp.Height; break;
167 default: OSL_FAIL("Wrong MemberId!"); return false;
170 return true;
174 bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
176 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
177 nMemberId &= ~CONVERT_TWIPS;
179 switch( nMemberId )
181 case MID_SIZE_SIZE:
183 awt::Size aTmp;
184 if( rVal >>= aTmp )
186 if(bConvert)
188 aTmp.Height = o3tl::toTwips(aTmp.Height, o3tl::Length::mm100);
189 aTmp.Width = o3tl::toTwips(aTmp.Width, o3tl::Length::mm100);
191 m_aSize = Size( aTmp.Width, aTmp.Height );
193 else
195 return false;
198 break;
199 case MID_SIZE_WIDTH:
201 sal_Int32 nVal = 0;
202 if(!(rVal >>= nVal ))
203 return false;
205 m_aSize.setWidth( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
207 break;
208 case MID_SIZE_HEIGHT:
210 sal_Int32 nVal = 0;
211 if(!(rVal >>= nVal))
212 return true;
214 m_aSize.setHeight( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
216 break;
217 default: OSL_FAIL("Wrong MemberId!");
218 return false;
220 return true;
224 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId ) :
226 SfxPoolItem( nId )
231 bool SvxSizeItem::operator==( const SfxPoolItem& rAttr ) const
233 assert(SfxPoolItem::operator==(rAttr));
235 return ( m_aSize == static_cast<const SvxSizeItem&>( rAttr ).GetSize() );
238 SvxSizeItem* SvxSizeItem::Clone( SfxItemPool* ) const
240 return new SvxSizeItem( *this );
243 bool SvxSizeItem::GetPresentation
245 SfxItemPresentation ePres,
246 MapUnit eCoreUnit,
247 MapUnit ePresUnit,
248 OUString& rText, const IntlWrapper& rIntl
249 ) const
251 OUString cpDelimTmp(cpDelim);
252 switch ( ePres )
254 case SfxItemPresentation::Nameless:
255 rText = GetMetricText( m_aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
256 cpDelimTmp +
257 GetMetricText( m_aSize.Height(), eCoreUnit, ePresUnit, &rIntl );
258 return true;
260 case SfxItemPresentation::Complete:
261 rText = EditResId(RID_SVXITEMS_SIZE_WIDTH) +
262 GetMetricText( m_aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
263 " " + EditResId(GetMetricId(ePresUnit)) +
264 cpDelimTmp +
265 EditResId(RID_SVXITEMS_SIZE_HEIGHT) +
266 GetMetricText( m_aSize.Height(), eCoreUnit, ePresUnit, &rIntl ) +
267 " " + EditResId(GetMetricId(ePresUnit));
268 return true;
269 // no break necessary
270 default: ; // prevent warning
273 return false;
277 void SvxSizeItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
279 m_aSize.setWidth( BigInt::Scale( m_aSize.Width(), nMult, nDiv ) );
280 m_aSize.setHeight( BigInt::Scale( m_aSize.Height(), nMult, nDiv ) );
284 bool SvxSizeItem::HasMetrics() const
286 return true;
290 SvxLRSpaceItem::SvxLRSpaceItem(const sal_uInt16 nId)
291 : SfxPoolItem(nId)
292 , nFirstLineOffset(0)
293 , nLeftMargin(0)
294 , nRightMargin(0)
295 , m_nGutterMargin(0)
296 , m_nRightGutterMargin(0),
297 nPropFirstLineOffset( 100 ),
298 nPropLeftMargin( 100 ),
299 nPropRightMargin( 100 ),
300 bAutoFirst ( false ),
301 bExplicitZeroMarginValRight(false),
302 bExplicitZeroMarginValLeft(false)
307 SvxLRSpaceItem::SvxLRSpaceItem( const tools::Long nLeft, const tools::Long nRight,
308 const short nOfset,
309 const sal_uInt16 nId )
310 : SfxPoolItem(nId)
311 , nFirstLineOffset(nOfset)
312 , nLeftMargin(nLeft)
313 , nRightMargin(nRight)
314 , m_nGutterMargin(0)
315 , m_nRightGutterMargin(0),
316 nPropFirstLineOffset( 100 ),
317 nPropLeftMargin( 100 ),
318 nPropRightMargin( 100 ),
319 bAutoFirst ( false ),
320 bExplicitZeroMarginValRight(false),
321 bExplicitZeroMarginValLeft(false)
326 bool SvxLRSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
328 bool bRet = true;
329 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
330 nMemberId &= ~CONVERT_TWIPS;
331 switch( nMemberId )
333 // now all signed
334 case 0:
336 css::frame::status::LeftRightMarginScale aLRSpace;
337 aLRSpace.Left = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin);
338 aLRSpace.TextLeft = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetTextLeft()) : GetTextLeft());
339 aLRSpace.Right = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin);
340 aLRSpace.ScaleLeft = static_cast<sal_Int16>(nPropLeftMargin);
341 aLRSpace.ScaleRight = static_cast<sal_Int16>(nPropRightMargin);
342 aLRSpace.FirstLine = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nFirstLineOffset) : nFirstLineOffset);
343 aLRSpace.ScaleFirstLine = static_cast<sal_Int16>(nPropFirstLineOffset);
344 aLRSpace.AutoFirstLine = IsAutoFirst();
345 rVal <<= aLRSpace;
346 break;
348 case MID_L_MARGIN:
349 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin);
350 break;
352 case MID_TXT_LMARGIN :
353 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetTextLeft()) : GetTextLeft());
354 break;
355 case MID_R_MARGIN:
356 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin);
357 break;
358 case MID_L_REL_MARGIN:
359 rVal <<= static_cast<sal_Int16>(nPropLeftMargin);
360 break;
361 case MID_R_REL_MARGIN:
362 rVal <<= static_cast<sal_Int16>(nPropRightMargin);
363 break;
365 case MID_FIRST_LINE_INDENT:
366 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nFirstLineOffset) : nFirstLineOffset);
367 break;
369 case MID_FIRST_LINE_REL_INDENT:
370 rVal <<= static_cast<sal_Int16>(nPropFirstLineOffset);
371 break;
373 case MID_FIRST_AUTO:
374 rVal <<= IsAutoFirst();
375 break;
377 case MID_GUTTER_MARGIN:
378 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nGutterMargin)
379 : m_nGutterMargin);
380 break;
382 default:
383 bRet = false;
384 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
385 OSL_FAIL("unknown MemberId");
387 return bRet;
391 bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
393 bool bConvert = 0 != (nMemberId&CONVERT_TWIPS);
394 nMemberId &= ~CONVERT_TWIPS;
395 sal_Int32 nVal = 0;
396 if( nMemberId != 0 && nMemberId != MID_FIRST_AUTO &&
397 nMemberId != MID_L_REL_MARGIN && nMemberId != MID_R_REL_MARGIN)
398 if(!(rVal >>= nVal))
399 return false;
401 switch( nMemberId )
403 case 0:
405 css::frame::status::LeftRightMarginScale aLRSpace;
406 if(!(rVal >>= aLRSpace))
407 return false;
409 SetLeft( bConvert ? o3tl::toTwips(aLRSpace.Left, o3tl::Length::mm100) : aLRSpace.Left );
410 SetTextLeft( bConvert ? o3tl::toTwips(aLRSpace.TextLeft, o3tl::Length::mm100) : aLRSpace.TextLeft );
411 SetRight(bConvert ? o3tl::toTwips(aLRSpace.Right, o3tl::Length::mm100) : aLRSpace.Right);
412 nPropLeftMargin = aLRSpace.ScaleLeft;
413 nPropRightMargin = aLRSpace.ScaleRight;
414 SetTextFirstLineOffset(bConvert ? o3tl::toTwips(aLRSpace.FirstLine, o3tl::Length::mm100) : aLRSpace.FirstLine);
415 SetPropTextFirstLineOffset ( aLRSpace.ScaleFirstLine );
416 SetAutoFirst( aLRSpace.AutoFirstLine );
417 break;
419 case MID_L_MARGIN:
420 SetLeft( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
421 break;
423 case MID_TXT_LMARGIN :
424 SetTextLeft( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
425 break;
427 case MID_R_MARGIN:
428 SetRight(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
429 break;
430 case MID_L_REL_MARGIN:
431 case MID_R_REL_MARGIN:
433 sal_Int32 nRel = 0;
434 if((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
436 if(MID_L_REL_MARGIN== nMemberId)
437 nPropLeftMargin = static_cast<sal_uInt16>(nRel);
438 else
439 nPropRightMargin = static_cast<sal_uInt16>(nRel);
441 else
442 return false;
444 break;
445 case MID_FIRST_LINE_INDENT :
446 SetTextFirstLineOffset(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
447 break;
449 case MID_FIRST_LINE_REL_INDENT:
450 SetPropTextFirstLineOffset ( nVal );
451 break;
453 case MID_FIRST_AUTO:
454 SetAutoFirst( Any2Bool(rVal) );
455 break;
457 case MID_GUTTER_MARGIN:
458 SetGutterMargin(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
459 break;
461 default:
462 OSL_FAIL("unknown MemberId");
463 return false;
465 return true;
468 void SvxLeftMarginItem::SetLeft(const tools::Long nL, const sal_uInt16 nProp)
470 m_nLeftMargin = (nL * nProp) / 100;
471 m_nPropLeftMargin = nProp;
474 void SvxLRSpaceItem::SetLeft(const tools::Long nL, const sal_uInt16 nProp)
476 nLeftMargin = (nL * nProp) / 100;
477 SAL_WARN_IF(nFirstLineOffset != 0, "editeng", "probably call SetTextLeft instead? looks inconsistent otherwise");
478 nPropLeftMargin = nProp;
481 void SvxRightMarginItem::SetRight(const tools::Long nR, const sal_uInt16 nProp)
483 m_nRightMargin = (nR * nProp) / 100;
484 m_nPropRightMargin = nProp;
487 void SvxLRSpaceItem::SetRight(const tools::Long nR, const sal_uInt16 nProp)
489 if (0 == nR)
491 SetExplicitZeroMarginValRight(true);
493 nRightMargin = (nR * nProp) / 100;
494 nPropRightMargin = nProp;
497 void SvxFirstLineIndentItem::SetTextFirstLineOffset(
498 const short nF, const sal_uInt16 nProp)
500 m_nFirstLineOffset = short((tools::Long(nF) * nProp ) / 100);
501 m_nPropFirstLineOffset = nProp;
504 void SvxLRSpaceItem::SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp)
506 // note: left margin contains any negative first line offset - preserve it!
507 if (nFirstLineOffset < 0)
509 nLeftMargin -= nFirstLineOffset;
511 nFirstLineOffset = short((tools::Long(nF) * nProp ) / 100);
512 nPropFirstLineOffset = nProp;
513 if (nFirstLineOffset < 0)
515 nLeftMargin += nFirstLineOffset;
519 #if 0
520 void SvxTextLeftMarginItem::SetLeft(SvxFirstLineIndentItem const& rFirstLine,
521 const tools::Long nL, const sal_uInt16 nProp)
523 m_nTextLeftMargin = (nL * nProp) / 100;
524 m_nPropLeftMargin = nProp;
525 // note: text left margin contains any negative first line offset
526 if (rFirstLine.GetTextFirstLineOffset() < 0)
528 m_nTextLeftMargin += rFirstLine.GetTextFirstLineOffset();
531 #endif
533 void SvxTextLeftMarginItem::SetTextLeft(const tools::Long nL, const sal_uInt16 nProp)
535 m_nTextLeftMargin = (nL * nProp) / 100;
536 m_nPropLeftMargin = nProp;
539 void SvxLRSpaceItem::SetTextLeft(const tools::Long nL, const sal_uInt16 nProp)
541 if (0 == nL)
543 SetExplicitZeroMarginValLeft(true);
545 auto const nTxtLeft = (nL * nProp) / 100;
546 nPropLeftMargin = nProp;
547 // note: left margin contains any negative first line offset
548 if ( 0 > nFirstLineOffset )
549 nLeftMargin = nTxtLeft + nFirstLineOffset;
550 else
551 nLeftMargin = nTxtLeft;
554 tools::Long SvxTextLeftMarginItem::GetTextLeft() const
556 return m_nTextLeftMargin;
559 tools::Long SvxTextLeftMarginItem::GetLeft(SvxFirstLineIndentItem const& rFirstLine) const
561 // add any negative first line offset to text left margin to get left
562 return (rFirstLine.GetTextFirstLineOffset() < 0)
563 ? m_nTextLeftMargin + rFirstLine.GetTextFirstLineOffset()
564 : m_nTextLeftMargin;
567 tools::Long SvxLRSpaceItem::GetTextLeft() const
569 // remove any negative first line offset from left margin to get text-left
570 return (nFirstLineOffset < 0)
571 ? nLeftMargin - nFirstLineOffset
572 : nLeftMargin;
575 SvxLeftMarginItem::SvxLeftMarginItem(const sal_uInt16 nId)
576 : SfxPoolItem(nId)
580 SvxLeftMarginItem::SvxLeftMarginItem(const tools::Long nLeft, const sal_uInt16 nId)
581 : SfxPoolItem(nId)
582 , m_nLeftMargin(nLeft)
586 bool SvxLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
588 bool bRet = true;
589 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
590 nMemberId &= ~CONVERT_TWIPS;
591 switch (nMemberId)
593 case MID_L_MARGIN:
594 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nLeftMargin) : m_nLeftMargin);
595 break;
596 case MID_L_REL_MARGIN:
597 rVal <<= static_cast<sal_Int16>(m_nPropLeftMargin);
598 break;
599 default:
600 assert(false);
601 bRet = false;
602 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
603 OSL_FAIL("unknown MemberId");
605 return bRet;
608 bool SvxLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
610 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
611 nMemberId &= ~CONVERT_TWIPS;
613 switch (nMemberId)
615 case MID_L_MARGIN:
617 sal_Int32 nVal = 0;
618 if (!(rVal >>= nVal))
620 return false;
622 SetLeft(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
623 break;
625 case MID_L_REL_MARGIN:
627 sal_Int32 nRel = 0;
628 if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
630 m_nPropLeftMargin = static_cast<sal_uInt16>(nRel);
632 else
634 return false;
637 break;
638 default:
639 assert(false);
640 OSL_FAIL("unknown MemberId");
641 return false;
643 return true;
646 bool SvxLeftMarginItem::operator==(const SfxPoolItem& rAttr) const
648 assert(SfxPoolItem::operator==(rAttr));
650 const SvxLeftMarginItem& rOther = static_cast<const SvxLeftMarginItem&>(rAttr);
652 return (m_nLeftMargin == rOther.GetLeft()
653 && m_nPropLeftMargin == rOther.GetPropLeft());
656 SvxLeftMarginItem* SvxLeftMarginItem::Clone(SfxItemPool *) const
658 return new SvxLeftMarginItem(*this);
661 bool SvxLeftMarginItem::GetPresentation
663 SfxItemPresentation ePres,
664 MapUnit eCoreUnit,
665 MapUnit ePresUnit,
666 OUString& rText, const IntlWrapper& rIntl
667 ) const
669 switch (ePres)
671 case SfxItemPresentation::Nameless:
673 if (100 != m_nPropLeftMargin)
675 rText = unicode::formatPercent(m_nPropLeftMargin,
676 Application::GetSettings().GetUILanguageTag());
678 else
680 rText = GetMetricText(m_nLeftMargin,
681 eCoreUnit, ePresUnit, &rIntl);
683 return true;
685 case SfxItemPresentation::Complete:
687 rText = EditResId(RID_SVXITEMS_LRSPACE_LEFT);
688 if (100 != m_nPropLeftMargin)
690 rText += unicode::formatPercent(m_nPropLeftMargin,
691 Application::GetSettings().GetUILanguageTag());
693 else
695 rText += GetMetricText(m_nLeftMargin, eCoreUnit, ePresUnit, &rIntl)
696 + " " + EditResId(GetMetricId(ePresUnit));
698 return true;
700 default: ; // prevent warning
702 return false;
705 void SvxLeftMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
707 m_nLeftMargin = BigInt::Scale(m_nLeftMargin, nMult, nDiv);
710 bool SvxLeftMarginItem::HasMetrics() const
712 return true;
715 void SvxLeftMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
717 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxLeftMarginItem"));
718 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
719 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLeftMargin"), BAD_CAST(OString::number(m_nLeftMargin).getStr()));
720 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropLeftMargin"), BAD_CAST(OString::number(m_nPropLeftMargin).getStr()));
721 (void)xmlTextWriterEndElement(pWriter);
724 boost::property_tree::ptree SvxLeftMarginItem::dumpAsJSON() const
726 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
728 boost::property_tree::ptree aState;
730 MapUnit eTargetUnit = MapUnit::MapInch;
732 OUString sLeft = GetMetricText(GetLeft(),
733 MapUnit::MapTwip, eTargetUnit, nullptr);
735 aState.put("left", sLeft);
736 aState.put("unit", "inch");
738 aTree.push_back(std::make_pair("state", aState));
740 return aTree;
743 SvxTextLeftMarginItem::SvxTextLeftMarginItem(const sal_uInt16 nId)
744 : SfxPoolItem(nId)
748 SvxTextLeftMarginItem::SvxTextLeftMarginItem(const tools::Long nLeft, const sal_uInt16 nId)
749 : SfxPoolItem(nId)
750 , m_nTextLeftMargin(nLeft)
754 bool SvxTextLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
756 bool bRet = true;
757 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
758 nMemberId &= ~CONVERT_TWIPS;
759 switch (nMemberId)
761 // tdf#154282 - return both values for the hardcoded 0 in SfxDispatchController_Impl::StateChanged
762 case 0:
764 css::frame::status::LeftRightMarginScale aLRSpace;
765 aLRSpace.TextLeft = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetTextLeft()) : GetTextLeft());
766 aLRSpace.ScaleLeft = static_cast<sal_Int16>(m_nPropLeftMargin);
767 rVal <<= aLRSpace;
768 break;
770 case MID_TXT_LMARGIN :
771 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetTextLeft()) : GetTextLeft());
772 break;
773 case MID_L_REL_MARGIN:
774 rVal <<= static_cast<sal_Int16>(m_nPropLeftMargin);
775 break;
776 default:
777 assert(false);
778 bRet = false;
779 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
780 OSL_FAIL("unknown MemberId");
782 return bRet;
785 bool SvxTextLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
787 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
788 nMemberId &= ~CONVERT_TWIPS;
790 switch (nMemberId)
792 case MID_TXT_LMARGIN:
794 sal_Int32 nVal = 0;
795 if (!(rVal >>= nVal))
797 return false;
799 SetTextLeft(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
801 break;
802 case MID_L_REL_MARGIN:
804 sal_Int32 nRel = 0;
805 if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
807 m_nPropLeftMargin = static_cast<sal_uInt16>(nRel);
809 else
811 return false;
814 break;
815 default:
816 assert(false);
817 OSL_FAIL("unknown MemberId");
818 return false;
820 return true;
823 bool SvxTextLeftMarginItem::operator==(const SfxPoolItem& rAttr) const
825 assert(SfxPoolItem::operator==(rAttr));
827 const SvxTextLeftMarginItem& rOther = static_cast<const SvxTextLeftMarginItem&>(rAttr);
829 return (m_nTextLeftMargin == rOther.GetTextLeft()
830 && m_nPropLeftMargin == rOther.GetPropLeft());
833 SvxTextLeftMarginItem* SvxTextLeftMarginItem::Clone(SfxItemPool *) const
835 return new SvxTextLeftMarginItem(*this);
838 bool SvxTextLeftMarginItem::GetPresentation
840 SfxItemPresentation ePres,
841 MapUnit eCoreUnit,
842 MapUnit ePresUnit,
843 OUString& rText, const IntlWrapper& rIntl
844 ) const
846 switch (ePres)
848 case SfxItemPresentation::Nameless:
850 if (100 != m_nPropLeftMargin)
852 rText = unicode::formatPercent(m_nPropLeftMargin,
853 Application::GetSettings().GetUILanguageTag());
855 else
857 rText = GetMetricText(m_nTextLeftMargin,
858 eCoreUnit, ePresUnit, &rIntl);
860 return true;
862 case SfxItemPresentation::Complete:
864 rText = EditResId(RID_SVXITEMS_LRSPACE_LEFT);
865 if (100 != m_nPropLeftMargin)
867 rText += unicode::formatPercent(m_nPropLeftMargin,
868 Application::GetSettings().GetUILanguageTag());
870 else
872 rText += GetMetricText(m_nTextLeftMargin, eCoreUnit, ePresUnit, &rIntl)
873 + " " + EditResId(GetMetricId(ePresUnit));
875 return true;
877 default: ; // prevent warning
879 return false;
882 void SvxTextLeftMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
884 m_nTextLeftMargin = BigInt::Scale(m_nTextLeftMargin, nMult, nDiv);
887 bool SvxTextLeftMarginItem::HasMetrics() const
889 return true;
892 void SvxTextLeftMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
894 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTextLeftMarginItem"));
895 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
896 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nTextLeftMargin"), BAD_CAST(OString::number(m_nTextLeftMargin).getStr()));
897 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropLeftMargin"), BAD_CAST(OString::number(m_nPropLeftMargin).getStr()));
898 (void)xmlTextWriterEndElement(pWriter);
901 boost::property_tree::ptree SvxTextLeftMarginItem::dumpAsJSON() const
903 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
905 boost::property_tree::ptree aState;
907 MapUnit eTargetUnit = MapUnit::MapInch;
909 OUString sLeft = GetMetricText(GetTextLeft(),
910 MapUnit::MapTwip, eTargetUnit, nullptr);
912 aState.put("left", sLeft);
913 aState.put("unit", "inch");
915 aTree.push_back(std::make_pair("state", aState));
917 return aTree;
920 SvxFirstLineIndentItem::SvxFirstLineIndentItem(const sal_uInt16 nId)
921 : SfxPoolItem(nId)
925 SvxFirstLineIndentItem::SvxFirstLineIndentItem(const short nFirst, const sal_uInt16 nId)
926 : SfxPoolItem(nId)
927 , m_nFirstLineOffset(nFirst)
931 bool SvxFirstLineIndentItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
933 bool bRet = true;
934 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
935 nMemberId &= ~CONVERT_TWIPS;
936 switch (nMemberId)
938 case MID_FIRST_LINE_INDENT:
939 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nFirstLineOffset) : m_nFirstLineOffset);
940 break;
941 case MID_FIRST_LINE_REL_INDENT:
942 rVal <<= static_cast<sal_Int16>(m_nPropFirstLineOffset);
943 break;
944 case MID_FIRST_AUTO:
945 rVal <<= IsAutoFirst();
946 break;
947 default:
948 assert(false);
949 bRet = false;
950 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
951 OSL_FAIL("unknown MemberId");
953 return bRet;
956 bool SvxFirstLineIndentItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
958 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
959 nMemberId &= ~CONVERT_TWIPS;
961 switch (nMemberId)
963 case MID_FIRST_LINE_INDENT:
965 sal_Int32 nVal = 0;
966 if (!(rVal >>= nVal))
968 return false;
970 m_nFirstLineOffset = bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal;
971 m_nPropFirstLineOffset = 100;
972 break;
974 case MID_FIRST_LINE_REL_INDENT:
976 sal_Int32 nRel = 0;
977 if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
979 SetPropTextFirstLineOffset(nRel);
981 else
983 return false;
985 break;
987 case MID_FIRST_AUTO:
988 SetAutoFirst(Any2Bool(rVal));
989 break;
990 default:
991 assert(false);
992 OSL_FAIL("unknown MemberId");
993 return false;
995 return true;
998 bool SvxFirstLineIndentItem::operator==(const SfxPoolItem& rAttr) const
1000 assert(SfxPoolItem::operator==(rAttr));
1002 const SvxFirstLineIndentItem& rOther = static_cast<const SvxFirstLineIndentItem&>(rAttr);
1004 return (m_nFirstLineOffset == rOther.GetTextFirstLineOffset()
1005 && m_nPropFirstLineOffset == rOther.GetPropTextFirstLineOffset()
1006 && m_bAutoFirst == rOther.IsAutoFirst());
1009 SvxFirstLineIndentItem* SvxFirstLineIndentItem::Clone(SfxItemPool *) const
1011 return new SvxFirstLineIndentItem(*this);
1014 bool SvxFirstLineIndentItem::GetPresentation
1016 SfxItemPresentation ePres,
1017 MapUnit eCoreUnit,
1018 MapUnit ePresUnit,
1019 OUString& rText, const IntlWrapper& rIntl
1020 ) const
1022 switch (ePres)
1024 case SfxItemPresentation::Nameless:
1026 if (100 != m_nPropFirstLineOffset)
1028 rText += unicode::formatPercent(m_nPropFirstLineOffset,
1029 Application::GetSettings().GetUILanguageTag());
1031 else
1033 rText += GetMetricText(static_cast<tools::Long>(m_nFirstLineOffset),
1034 eCoreUnit, ePresUnit, &rIntl);
1036 return true;
1038 case SfxItemPresentation::Complete:
1040 rText += EditResId(RID_SVXITEMS_LRSPACE_FLINE);
1041 if (100 != m_nPropFirstLineOffset)
1043 rText += unicode::formatPercent(m_nPropFirstLineOffset,
1044 Application::GetSettings().GetUILanguageTag());
1046 else
1048 rText += GetMetricText(static_cast<tools::Long>(m_nFirstLineOffset),
1049 eCoreUnit, ePresUnit, &rIntl)
1050 + " " + EditResId(GetMetricId(ePresUnit));
1052 return true;
1054 default: ; // prevent warning
1056 return false;
1059 void SvxFirstLineIndentItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
1061 m_nFirstLineOffset = static_cast<short>(BigInt::Scale(m_nFirstLineOffset, nMult, nDiv));
1064 bool SvxFirstLineIndentItem::HasMetrics() const
1066 return true;
1069 void SvxFirstLineIndentItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1071 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFirstLineIndentItem"));
1072 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1073 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFirstLineOffset"), BAD_CAST(OString::number(m_nFirstLineOffset).getStr()));
1074 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropFirstLineOffset"), BAD_CAST(OString::number(m_nPropFirstLineOffset).getStr()));
1075 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_bAutoFirst"), BAD_CAST(OString::number(int(m_bAutoFirst)).getStr()));
1076 (void)xmlTextWriterEndElement(pWriter);
1079 boost::property_tree::ptree SvxFirstLineIndentItem::dumpAsJSON() const
1081 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
1083 boost::property_tree::ptree aState;
1085 MapUnit eTargetUnit = MapUnit::MapInch;
1087 OUString sFirstline = GetMetricText(GetTextFirstLineOffset(),
1088 MapUnit::MapTwip, eTargetUnit, nullptr);
1090 aState.put("firstline", sFirstline);
1091 aState.put("unit", "inch");
1093 aTree.push_back(std::make_pair("state", aState));
1095 return aTree;
1098 SvxRightMarginItem::SvxRightMarginItem(const sal_uInt16 nId)
1099 : SfxPoolItem(nId)
1103 SvxRightMarginItem::SvxRightMarginItem(const tools::Long nRight, const sal_uInt16 nId)
1104 : SfxPoolItem(nId)
1105 , m_nRightMargin(nRight)
1109 bool SvxRightMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
1111 bool bRet = true;
1112 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
1113 nMemberId &= ~CONVERT_TWIPS;
1114 switch (nMemberId)
1116 // tdf#154282 - return both values for the hardcoded 0 in SfxDispatchController_Impl::StateChanged
1117 case 0:
1119 css::frame::status::LeftRightMarginScale aLRSpace;
1120 aLRSpace.Right = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nRightMargin) : m_nRightMargin);
1121 aLRSpace.ScaleRight = static_cast<sal_Int16>(m_nPropRightMargin);
1122 rVal <<= aLRSpace;
1123 break;
1125 case MID_R_MARGIN:
1126 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nRightMargin) : m_nRightMargin);
1127 break;
1128 case MID_R_REL_MARGIN:
1129 rVal <<= static_cast<sal_Int16>(m_nPropRightMargin);
1130 break;
1131 default:
1132 assert(false);
1133 bRet = false;
1134 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
1135 OSL_FAIL("unknown MemberId");
1137 return bRet;
1140 bool SvxRightMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
1142 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
1143 nMemberId &= ~CONVERT_TWIPS;
1145 switch (nMemberId)
1147 case MID_R_MARGIN:
1149 sal_Int32 nVal = 0;
1150 if (!(rVal >>= nVal))
1152 return false;
1154 SetRight(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
1155 break;
1157 case MID_R_REL_MARGIN:
1159 sal_Int32 nRel = 0;
1160 if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
1162 m_nPropRightMargin = static_cast<sal_uInt16>(nRel);
1164 else
1166 return false;
1169 break;
1170 default:
1171 assert(false);
1172 OSL_FAIL("unknown MemberId");
1173 return false;
1175 return true;
1178 bool SvxRightMarginItem::operator==(const SfxPoolItem& rAttr) const
1180 assert(SfxPoolItem::operator==(rAttr));
1182 const SvxRightMarginItem& rOther = static_cast<const SvxRightMarginItem&>(rAttr);
1184 return (m_nRightMargin == rOther.GetRight()
1185 && m_nPropRightMargin == rOther.GetPropRight());
1188 SvxRightMarginItem* SvxRightMarginItem::Clone(SfxItemPool *) const
1190 return new SvxRightMarginItem(*this);
1193 bool SvxRightMarginItem::GetPresentation
1195 SfxItemPresentation ePres,
1196 MapUnit eCoreUnit,
1197 MapUnit ePresUnit,
1198 OUString& rText, const IntlWrapper& rIntl
1199 ) const
1201 switch (ePres)
1203 case SfxItemPresentation::Nameless:
1205 if (100 != m_nRightMargin)
1207 rText += unicode::formatPercent(m_nRightMargin,
1208 Application::GetSettings().GetUILanguageTag());
1210 else
1212 rText += GetMetricText(m_nRightMargin,
1213 eCoreUnit, ePresUnit, &rIntl);
1215 return true;
1217 case SfxItemPresentation::Complete:
1219 rText += EditResId(RID_SVXITEMS_LRSPACE_RIGHT);
1220 if (100 != m_nPropRightMargin)
1222 rText += unicode::formatPercent(m_nPropRightMargin,
1223 Application::GetSettings().GetUILanguageTag());
1225 else
1227 rText += GetMetricText(m_nRightMargin,
1228 eCoreUnit, ePresUnit, &rIntl)
1229 + " " + EditResId(GetMetricId(ePresUnit));
1231 return true;
1233 default: ; // prevent warning
1235 return false;
1238 void SvxRightMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
1240 m_nRightMargin = BigInt::Scale(m_nRightMargin, nMult, nDiv);
1243 bool SvxRightMarginItem::HasMetrics() const
1245 return true;
1248 void SvxRightMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1250 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxRightMarginItem"));
1251 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1252 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nRightMargin"), BAD_CAST(OString::number(m_nRightMargin).getStr()));
1253 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropRightMargin"), BAD_CAST(OString::number(m_nPropRightMargin).getStr()));
1254 (void)xmlTextWriterEndElement(pWriter);
1257 boost::property_tree::ptree SvxRightMarginItem::dumpAsJSON() const
1259 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
1261 boost::property_tree::ptree aState;
1263 MapUnit eTargetUnit = MapUnit::MapInch;
1265 OUString sRight = GetMetricText(GetRight(),
1266 MapUnit::MapTwip, eTargetUnit, nullptr);
1268 aState.put("right", sRight);
1269 aState.put("unit", "inch");
1271 aTree.push_back(std::make_pair("state", aState));
1273 return aTree;
1276 SvxGutterLeftMarginItem::SvxGutterLeftMarginItem(const sal_uInt16 nId)
1277 : SfxPoolItem(nId)
1281 bool SvxGutterLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
1283 bool bRet = true;
1284 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
1285 nMemberId &= ~CONVERT_TWIPS;
1286 switch (nMemberId)
1288 case MID_GUTTER_MARGIN:
1289 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nGutterMargin)
1290 : m_nGutterMargin);
1291 break;
1292 default:
1293 assert(false);
1294 bRet = false;
1295 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
1296 OSL_FAIL("unknown MemberId");
1298 return bRet;
1301 bool SvxGutterLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
1303 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
1304 nMemberId &= ~CONVERT_TWIPS;
1306 switch (nMemberId)
1308 case MID_GUTTER_MARGIN:
1310 sal_Int32 nVal = 0;
1311 if (!(rVal >>= nVal))
1313 return false;
1315 SetGutterMargin(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
1316 break;
1318 default:
1319 assert(false);
1320 OSL_FAIL("unknown MemberId");
1321 return false;
1323 return true;
1326 bool SvxGutterLeftMarginItem::operator==(const SfxPoolItem& rAttr) const
1328 assert(SfxPoolItem::operator==(rAttr));
1330 const SvxGutterLeftMarginItem& rOther = static_cast<const SvxGutterLeftMarginItem&>(rAttr);
1332 return (m_nGutterMargin == rOther.GetGutterMargin());
1335 SvxGutterLeftMarginItem* SvxGutterLeftMarginItem::Clone(SfxItemPool * ) const
1337 return new SvxGutterLeftMarginItem(*this);
1340 bool SvxGutterLeftMarginItem::GetPresentation
1342 SfxItemPresentation /*ePres*/,
1343 MapUnit /*eCoreUnit*/,
1344 MapUnit /*ePresUnit*/,
1345 OUString& /*rText*/, const IntlWrapper& /*rIntl*/
1346 ) const
1348 // TODO?
1349 return false;
1352 void SvxGutterLeftMarginItem::ScaleMetrics(tools::Long const /*nMult*/, tools::Long const /*nDiv*/)
1354 // TODO?
1357 bool SvxGutterLeftMarginItem::HasMetrics() const
1359 return true;
1362 void SvxGutterLeftMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1364 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxGutterLeftMarginItem"));
1365 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1366 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nGutterMargin"),
1367 BAD_CAST(OString::number(m_nGutterMargin).getStr()));
1368 (void)xmlTextWriterEndElement(pWriter);
1371 boost::property_tree::ptree SvxGutterLeftMarginItem::dumpAsJSON() const
1373 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
1375 boost::property_tree::ptree aState;
1377 // TODO?
1378 aState.put("unit", "inch");
1380 aTree.push_back(std::make_pair("state", aState));
1382 return aTree;
1385 SvxGutterRightMarginItem::SvxGutterRightMarginItem(const sal_uInt16 nId)
1386 : SfxPoolItem(nId)
1390 bool SvxGutterRightMarginItem::QueryValue(uno::Any& /*rVal*/, sal_uInt8 nMemberId) const
1392 bool bRet = true;
1393 //bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
1394 nMemberId &= ~CONVERT_TWIPS;
1395 #ifndef _MSC_VER
1396 switch (nMemberId)
1398 // TODO?
1399 default:
1400 assert(false);
1401 bRet = false;
1402 // SfxDispatchController_Impl::StateChanged calls this with hardcoded 0 triggering this; there used to be a MID_LR_MARGIN 0 but what type would it have?
1403 OSL_FAIL("unknown MemberId");
1405 #else
1406 (void) nMemberId;
1407 #endif
1408 return bRet;
1411 bool SvxGutterRightMarginItem::PutValue(const uno::Any& /*rVal*/, sal_uInt8 nMemberId)
1413 //bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
1414 nMemberId &= ~CONVERT_TWIPS;
1416 #ifndef _MSC_VER
1417 switch (nMemberId)
1419 // TODO?
1420 default:
1421 assert(false);
1422 OSL_FAIL("unknown MemberId");
1423 return false;
1425 #else
1426 (void) nMemberId;
1427 #endif
1428 return true;
1432 bool SvxGutterRightMarginItem::operator==(const SfxPoolItem& rAttr) const
1434 assert(SfxPoolItem::operator==(rAttr));
1436 const SvxGutterRightMarginItem& rOther = static_cast<const SvxGutterRightMarginItem&>(rAttr);
1438 return (m_nRightGutterMargin == rOther.GetRightGutterMargin());
1441 SvxGutterRightMarginItem* SvxGutterRightMarginItem::Clone(SfxItemPool *) const
1443 return new SvxGutterRightMarginItem(*this);
1446 bool SvxGutterRightMarginItem::GetPresentation
1448 SfxItemPresentation /*ePres*/,
1449 MapUnit /*eCoreUnit*/,
1450 MapUnit /*ePresUnit*/,
1451 OUString& /*rText*/, const IntlWrapper& /*rIntl*/
1452 ) const
1454 // TODO?
1455 return false;
1458 void SvxGutterRightMarginItem::ScaleMetrics(tools::Long const /*nMult*/, tools::Long const /*nDiv*/)
1460 // TODO?
1463 bool SvxGutterRightMarginItem::HasMetrics() const
1465 return true;
1468 void SvxGutterRightMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1470 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxGutterRightMarginItem"));
1471 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1472 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nRightGutterMargin"),
1473 BAD_CAST(OString::number(m_nRightGutterMargin).getStr()));
1474 (void)xmlTextWriterEndElement(pWriter);
1477 boost::property_tree::ptree SvxGutterRightMarginItem::dumpAsJSON() const
1479 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
1481 boost::property_tree::ptree aState;
1483 // TODO?
1484 aState.put("unit", "inch");
1486 aTree.push_back(std::make_pair("state", aState));
1488 return aTree;
1492 bool SvxLRSpaceItem::operator==( const SfxPoolItem& rAttr ) const
1494 assert(SfxPoolItem::operator==(rAttr));
1496 const SvxLRSpaceItem& rOther = static_cast<const SvxLRSpaceItem&>(rAttr);
1498 return (
1499 nFirstLineOffset == rOther.GetTextFirstLineOffset() &&
1500 m_nGutterMargin == rOther.GetGutterMargin() &&
1501 m_nRightGutterMargin == rOther.GetRightGutterMargin() &&
1502 nLeftMargin == rOther.GetLeft() &&
1503 nRightMargin == rOther.GetRight() &&
1504 nPropFirstLineOffset == rOther.GetPropTextFirstLineOffset() &&
1505 nPropLeftMargin == rOther.GetPropLeft() &&
1506 nPropRightMargin == rOther.GetPropRight() &&
1507 bAutoFirst == rOther.IsAutoFirst() &&
1508 bExplicitZeroMarginValRight == rOther.IsExplicitZeroMarginValRight() &&
1509 bExplicitZeroMarginValLeft == rOther.IsExplicitZeroMarginValLeft() );
1512 SvxLRSpaceItem* SvxLRSpaceItem::Clone( SfxItemPool* ) const
1514 return new SvxLRSpaceItem( *this );
1517 bool SvxLRSpaceItem::GetPresentation
1519 SfxItemPresentation ePres,
1520 MapUnit eCoreUnit,
1521 MapUnit ePresUnit,
1522 OUString& rText, const IntlWrapper& rIntl
1523 ) const
1525 switch ( ePres )
1527 case SfxItemPresentation::Nameless:
1529 if ( 100 != nPropLeftMargin )
1531 rText = unicode::formatPercent(nPropLeftMargin,
1532 Application::GetSettings().GetUILanguageTag());
1534 else
1535 rText = GetMetricText( nLeftMargin,
1536 eCoreUnit, ePresUnit, &rIntl );
1537 rText += cpDelim;
1538 if ( 100 != nPropFirstLineOffset )
1540 rText += unicode::formatPercent(nPropFirstLineOffset,
1541 Application::GetSettings().GetUILanguageTag());
1543 else
1544 rText += GetMetricText( static_cast<tools::Long>(nFirstLineOffset),
1545 eCoreUnit, ePresUnit, &rIntl );
1546 rText += cpDelim;
1547 if ( 100 != nRightMargin )
1549 rText += unicode::formatPercent(nRightMargin,
1550 Application::GetSettings().GetUILanguageTag());
1552 else
1553 rText += GetMetricText( nRightMargin,
1554 eCoreUnit, ePresUnit, &rIntl );
1555 return true;
1557 case SfxItemPresentation::Complete:
1559 rText = EditResId(RID_SVXITEMS_LRSPACE_LEFT);
1560 if ( 100 != nPropLeftMargin )
1561 rText += unicode::formatPercent(nPropLeftMargin,
1562 Application::GetSettings().GetUILanguageTag());
1563 else
1565 rText += GetMetricText( nLeftMargin, eCoreUnit, ePresUnit, &rIntl ) +
1566 " " + EditResId(GetMetricId(ePresUnit));
1568 rText += cpDelim;
1569 if ( 100 != nPropFirstLineOffset || nFirstLineOffset )
1571 rText += EditResId(RID_SVXITEMS_LRSPACE_FLINE);
1572 if ( 100 != nPropFirstLineOffset )
1573 rText += unicode::formatPercent(nPropFirstLineOffset,
1574 Application::GetSettings().GetUILanguageTag());
1575 else
1577 rText += GetMetricText( static_cast<tools::Long>(nFirstLineOffset),
1578 eCoreUnit, ePresUnit, &rIntl ) +
1579 " " + EditResId(GetMetricId(ePresUnit));
1581 rText += cpDelim;
1583 rText += EditResId(RID_SVXITEMS_LRSPACE_RIGHT);
1584 if ( 100 != nPropRightMargin )
1585 rText += unicode::formatPercent(nPropRightMargin,
1586 Application::GetSettings().GetUILanguageTag());
1587 else
1589 rText += GetMetricText( nRightMargin,
1590 eCoreUnit, ePresUnit, &rIntl ) +
1591 " " + EditResId(GetMetricId(ePresUnit));
1593 return true;
1595 default: ; // prevent warning
1597 return false;
1601 void SvxLRSpaceItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
1603 nFirstLineOffset = static_cast<short>(BigInt::Scale( nFirstLineOffset, nMult, nDiv ));
1604 nLeftMargin = BigInt::Scale( nLeftMargin, nMult, nDiv );
1605 nRightMargin = BigInt::Scale( nRightMargin, nMult, nDiv );
1609 bool SvxLRSpaceItem::HasMetrics() const
1611 return true;
1615 void SvxLRSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1617 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxLRSpaceItem"));
1618 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1619 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nFirstLineOffset"), BAD_CAST(OString::number(nFirstLineOffset).getStr()));
1620 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nLeftMargin"), BAD_CAST(OString::number(nLeftMargin).getStr()));
1621 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nRightMargin"), BAD_CAST(OString::number(nRightMargin).getStr()));
1622 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nGutterMargin"),
1623 BAD_CAST(OString::number(m_nGutterMargin).getStr()));
1624 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nRightGutterMargin"),
1625 BAD_CAST(OString::number(m_nRightGutterMargin).getStr()));
1626 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropFirstLineOffset"), BAD_CAST(OString::number(nPropFirstLineOffset).getStr()));
1627 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropLeftMargin"), BAD_CAST(OString::number(nPropLeftMargin).getStr()));
1628 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropRightMargin"), BAD_CAST(OString::number(nPropRightMargin).getStr()));
1629 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bAutoFirst"), BAD_CAST(OString::number(int(bAutoFirst)).getStr()));
1630 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bExplicitZeroMarginValRight"), BAD_CAST(OString::number(int(bExplicitZeroMarginValRight)).getStr()));
1631 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bExplicitZeroMarginValLeft"), BAD_CAST(OString::number(int(bExplicitZeroMarginValLeft)).getStr()));
1632 (void)xmlTextWriterEndElement(pWriter);
1636 boost::property_tree::ptree SvxLRSpaceItem::dumpAsJSON() const
1638 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
1640 boost::property_tree::ptree aState;
1642 MapUnit eTargetUnit = MapUnit::MapInch;
1644 OUString sLeft = GetMetricText(GetLeft(),
1645 MapUnit::MapTwip, eTargetUnit, nullptr);
1647 OUString sRight = GetMetricText(GetRight(),
1648 MapUnit::MapTwip, eTargetUnit, nullptr);
1650 OUString sFirstline = GetMetricText(GetTextFirstLineOffset(),
1651 MapUnit::MapTwip, eTargetUnit, nullptr);
1653 aState.put("left", sLeft);
1654 aState.put("right", sRight);
1655 aState.put("firstline", sFirstline);
1656 aState.put("unit", "inch");
1658 aTree.push_back(std::make_pair("state", aState));
1660 return aTree;
1664 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nId )
1665 : SfxPoolItem(nId)
1666 , nUpper(0)
1667 , nLower(0)
1668 , bContext(false)
1669 , nPropUpper(100)
1670 , nPropLower(100)
1675 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nUp, const sal_uInt16 nLow,
1676 const sal_uInt16 nId )
1677 : SfxPoolItem(nId)
1678 , nUpper(nUp)
1679 , nLower(nLow)
1680 , bContext(false)
1681 , nPropUpper(100)
1682 , nPropLower(100)
1687 bool SvxULSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1689 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1690 nMemberId &= ~CONVERT_TWIPS;
1691 switch( nMemberId )
1693 // now all signed
1694 case 0:
1696 css::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
1697 aUpperLowerMarginScale.Upper = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nUpper) : nUpper);
1698 aUpperLowerMarginScale.Lower = static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nLower) : nPropUpper);
1699 aUpperLowerMarginScale.ScaleUpper = static_cast<sal_Int16>(nPropUpper);
1700 aUpperLowerMarginScale.ScaleLower = static_cast<sal_Int16>(nPropLower);
1701 rVal <<= aUpperLowerMarginScale;
1702 break;
1704 case MID_UP_MARGIN: rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nUpper) : nUpper); break;
1705 case MID_LO_MARGIN: rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nLower) : nLower); break;
1706 case MID_CTX_MARGIN: rVal <<= bContext; break;
1707 case MID_UP_REL_MARGIN: rVal <<= static_cast<sal_Int16>(nPropUpper); break;
1708 case MID_LO_REL_MARGIN: rVal <<= static_cast<sal_Int16>(nPropLower); break;
1710 return true;
1714 bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1716 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1717 nMemberId &= ~CONVERT_TWIPS;
1718 sal_Int32 nVal = 0;
1719 bool bVal = false;
1720 switch( nMemberId )
1722 case 0:
1724 css::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
1725 if ( !(rVal >>= aUpperLowerMarginScale ))
1726 return false;
1728 SetUpper(bConvert ? o3tl::toTwips(aUpperLowerMarginScale.Upper, o3tl::Length::mm100) : aUpperLowerMarginScale.Upper);
1729 SetLower(bConvert ? o3tl::toTwips(aUpperLowerMarginScale.Lower, o3tl::Length::mm100) : aUpperLowerMarginScale.Lower);
1730 if( aUpperLowerMarginScale.ScaleUpper > 1 )
1731 nPropUpper = aUpperLowerMarginScale.ScaleUpper;
1732 if( aUpperLowerMarginScale.ScaleLower > 1 )
1733 nPropUpper = aUpperLowerMarginScale.ScaleLower;
1736 break;
1737 case MID_UP_MARGIN :
1738 if(!(rVal >>= nVal))
1739 return false;
1740 SetUpper(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
1741 break;
1742 case MID_LO_MARGIN :
1743 if(!(rVal >>= nVal) || nVal < 0)
1744 return false;
1745 SetLower(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
1746 break;
1747 case MID_CTX_MARGIN :
1748 if (!(rVal >>= bVal))
1749 return false;
1750 SetContextValue(bVal);
1751 break;
1752 case MID_UP_REL_MARGIN:
1753 case MID_LO_REL_MARGIN:
1755 sal_Int32 nRel = 0;
1756 if((rVal >>= nRel) && nRel > 1 )
1758 if(MID_UP_REL_MARGIN == nMemberId)
1759 nPropUpper = static_cast<sal_uInt16>(nRel);
1760 else
1761 nPropLower = static_cast<sal_uInt16>(nRel);
1763 else
1764 return false;
1766 break;
1768 default:
1769 OSL_FAIL("unknown MemberId");
1770 return false;
1772 return true;
1776 bool SvxULSpaceItem::operator==( const SfxPoolItem& rAttr ) const
1778 assert(SfxPoolItem::operator==(rAttr));
1780 const SvxULSpaceItem& rSpaceItem = static_cast<const SvxULSpaceItem&>( rAttr );
1781 return ( nUpper == rSpaceItem.nUpper &&
1782 nLower == rSpaceItem.nLower &&
1783 bContext == rSpaceItem.bContext &&
1784 nPropUpper == rSpaceItem.nPropUpper &&
1785 nPropLower == rSpaceItem.nPropLower );
1788 SvxULSpaceItem* SvxULSpaceItem::Clone( SfxItemPool* ) const
1790 return new SvxULSpaceItem( *this );
1793 bool SvxULSpaceItem::GetPresentation
1795 SfxItemPresentation ePres,
1796 MapUnit eCoreUnit,
1797 MapUnit ePresUnit,
1798 OUString& rText,
1799 const IntlWrapper& rIntl
1800 ) const
1802 switch ( ePres )
1804 case SfxItemPresentation::Nameless:
1806 if ( 100 != nPropUpper )
1808 rText = unicode::formatPercent(nPropUpper,
1809 Application::GetSettings().GetUILanguageTag());
1811 else
1812 rText = GetMetricText( static_cast<tools::Long>(nUpper), eCoreUnit, ePresUnit, &rIntl );
1813 rText += cpDelim;
1814 if ( 100 != nPropLower )
1816 rText += unicode::formatPercent(nPropLower,
1817 Application::GetSettings().GetUILanguageTag());
1819 else
1820 rText += GetMetricText( static_cast<tools::Long>(nLower), eCoreUnit, ePresUnit, &rIntl );
1821 return true;
1823 case SfxItemPresentation::Complete:
1825 rText = EditResId(RID_SVXITEMS_ULSPACE_UPPER);
1826 if ( 100 != nPropUpper )
1828 rText += unicode::formatPercent(nPropUpper,
1829 Application::GetSettings().GetUILanguageTag());
1831 else
1833 rText += GetMetricText( static_cast<tools::Long>(nUpper), eCoreUnit, ePresUnit, &rIntl ) +
1834 " " + EditResId(GetMetricId(ePresUnit));
1836 rText += cpDelim + EditResId(RID_SVXITEMS_ULSPACE_LOWER);
1837 if ( 100 != nPropLower )
1839 rText += unicode::formatPercent(nPropLower,
1840 Application::GetSettings().GetUILanguageTag());
1842 else
1844 rText += GetMetricText( static_cast<tools::Long>(nLower), eCoreUnit, ePresUnit, &rIntl ) +
1845 " " + EditResId(GetMetricId(ePresUnit));
1847 return true;
1849 default: ; // prevent warning
1851 return false;
1855 void SvxULSpaceItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
1857 nUpper = static_cast<sal_uInt16>(BigInt::Scale( nUpper, nMult, nDiv ));
1858 nLower = static_cast<sal_uInt16>(BigInt::Scale( nLower, nMult, nDiv ));
1862 bool SvxULSpaceItem::HasMetrics() const
1864 return true;
1868 void SvxULSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1870 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxULSpaceItem"));
1871 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1872 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nUpper"), BAD_CAST(OString::number(nUpper).getStr()));
1873 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nLower"), BAD_CAST(OString::number(nLower).getStr()));
1874 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bContext"), BAD_CAST(OString::boolean(bContext).getStr()));
1875 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropUpper"), BAD_CAST(OString::number(nPropUpper).getStr()));
1876 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropLower"), BAD_CAST(OString::number(nPropLower).getStr()));
1877 (void)xmlTextWriterEndElement(pWriter);
1880 boost::property_tree::ptree SvxULSpaceItem::dumpAsJSON() const
1882 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
1884 boost::property_tree::ptree aState;
1886 MapUnit eTargetUnit = MapUnit::MapInch;
1888 OUString sUpper = GetMetricText(GetUpper(),
1889 MapUnit::MapTwip, eTargetUnit, nullptr);
1891 OUString sLower = GetMetricText(GetLower(),
1892 MapUnit::MapTwip, eTargetUnit, nullptr);
1894 aState.put("upper", sUpper);
1895 aState.put("lower", sLower);
1896 aState.put("unit", "inch");
1898 aTree.push_back(std::make_pair("state", aState));
1900 return aTree;
1903 SvxPrintItem* SvxPrintItem::Clone( SfxItemPool* ) const
1905 return new SvxPrintItem( *this );
1908 bool SvxPrintItem::GetPresentation
1910 SfxItemPresentation /*ePres*/,
1911 MapUnit /*eCoreUnit*/,
1912 MapUnit /*ePresUnit*/,
1913 OUString& rText, const IntlWrapper&
1914 ) const
1916 TranslateId pId = RID_SVXITEMS_PRINT_FALSE;
1918 if ( GetValue() )
1919 pId = RID_SVXITEMS_PRINT_TRUE;
1920 rText = EditResId(pId);
1921 return true;
1924 SvxOpaqueItem* SvxOpaqueItem::Clone( SfxItemPool* ) const
1926 return new SvxOpaqueItem( *this );
1929 bool SvxOpaqueItem::GetPresentation
1931 SfxItemPresentation /*ePres*/,
1932 MapUnit /*eCoreUnit*/,
1933 MapUnit /*ePresUnit*/,
1934 OUString& rText, const IntlWrapper&
1935 ) const
1937 TranslateId pId = RID_SVXITEMS_OPAQUE_FALSE;
1939 if ( GetValue() )
1940 pId = RID_SVXITEMS_OPAQUE_TRUE;
1941 rText = EditResId(pId);
1942 return true;
1946 bool SvxProtectItem::operator==( const SfxPoolItem& rAttr ) const
1948 assert(SfxPoolItem::operator==(rAttr));
1950 const SvxProtectItem& rItem = static_cast<const SvxProtectItem&>(rAttr);
1951 return ( bCntnt == rItem.bCntnt &&
1952 bSize == rItem.bSize &&
1953 bPos == rItem.bPos );
1957 bool SvxProtectItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1959 nMemberId &= ~CONVERT_TWIPS;
1960 bool bValue;
1961 switch(nMemberId)
1963 case MID_PROTECT_CONTENT : bValue = bCntnt; break;
1964 case MID_PROTECT_SIZE : bValue = bSize; break;
1965 case MID_PROTECT_POSITION: bValue = bPos; break;
1966 default:
1967 OSL_FAIL("Wrong MemberId");
1968 return false;
1971 rVal <<= bValue;
1972 return true;
1976 bool SvxProtectItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1978 nMemberId &= ~CONVERT_TWIPS;
1979 bool bVal( Any2Bool(rVal) );
1980 switch(nMemberId)
1982 case MID_PROTECT_CONTENT : bCntnt = bVal; break;
1983 case MID_PROTECT_SIZE : bSize = bVal; break;
1984 case MID_PROTECT_POSITION: bPos = bVal; break;
1985 default:
1986 OSL_FAIL("Wrong MemberId");
1987 return false;
1989 return true;
1992 SvxProtectItem* SvxProtectItem::Clone( SfxItemPool* ) const
1994 return new SvxProtectItem( *this );
1997 bool SvxProtectItem::GetPresentation
1999 SfxItemPresentation /*ePres*/,
2000 MapUnit /*eCoreUnit*/,
2001 MapUnit /*ePresUnit*/,
2002 OUString& rText, const IntlWrapper&
2003 ) const
2005 TranslateId pId = RID_SVXITEMS_PROT_CONTENT_FALSE;
2007 if ( bCntnt )
2008 pId = RID_SVXITEMS_PROT_CONTENT_TRUE;
2009 rText = EditResId(pId) + cpDelim;
2010 pId = RID_SVXITEMS_PROT_SIZE_FALSE;
2012 if ( bSize )
2013 pId = RID_SVXITEMS_PROT_SIZE_TRUE;
2014 rText += EditResId(pId) + cpDelim;
2015 pId = RID_SVXITEMS_PROT_POS_FALSE;
2017 if ( bPos )
2018 pId = RID_SVXITEMS_PROT_POS_TRUE;
2019 rText += EditResId(pId);
2020 return true;
2024 void SvxProtectItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2026 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxProtectItem"));
2027 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2028 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("content"), BAD_CAST(OString::boolean(bCntnt).getStr()));
2029 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("size"), BAD_CAST(OString::boolean(bSize).getStr()));
2030 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("position"), BAD_CAST(OString::boolean(bPos).getStr()));
2031 (void)xmlTextWriterEndElement(pWriter);
2035 SvxShadowItem::SvxShadowItem( const sal_uInt16 nId,
2036 const Color *pColor, const sal_uInt16 nW,
2037 const SvxShadowLocation eLoc ) :
2038 SfxEnumItemInterface( nId ),
2039 aShadowColor(COL_GRAY),
2040 nWidth ( nW ),
2041 eLocation ( eLoc )
2043 if ( pColor )
2044 aShadowColor = *pColor;
2048 bool SvxShadowItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2050 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2051 nMemberId &= ~CONVERT_TWIPS;
2053 table::ShadowFormat aShadow;
2054 table::ShadowLocation eSet = table::ShadowLocation_NONE;
2055 switch( eLocation )
2057 case SvxShadowLocation::TopLeft : eSet = table::ShadowLocation_TOP_LEFT ; break;
2058 case SvxShadowLocation::TopRight : eSet = table::ShadowLocation_TOP_RIGHT ; break;
2059 case SvxShadowLocation::BottomLeft : eSet = table::ShadowLocation_BOTTOM_LEFT ; break;
2060 case SvxShadowLocation::BottomRight: eSet = table::ShadowLocation_BOTTOM_RIGHT; break;
2061 default: ; // prevent warning
2063 aShadow.Location = eSet;
2064 aShadow.ShadowWidth = bConvert ? convertTwipToMm100(nWidth) : nWidth;
2065 aShadow.IsTransparent = aShadowColor.IsTransparent();
2066 aShadow.Color = sal_Int32(aShadowColor);
2068 sal_Int8 nTransparence = rtl::math::round((float(255 - aShadowColor.GetAlpha()) * 100) / 255);
2070 switch ( nMemberId )
2072 case MID_LOCATION: rVal <<= aShadow.Location; break;
2073 case MID_WIDTH: rVal <<= aShadow.ShadowWidth; break;
2074 case MID_TRANSPARENT: rVal <<= aShadow.IsTransparent; break;
2075 case MID_BG_COLOR: rVal <<= aShadow.Color; break;
2076 case 0: rVal <<= aShadow; break;
2077 case MID_SHADOW_TRANSPARENCE: rVal <<= nTransparence; break;
2078 default: OSL_FAIL("Wrong MemberId!"); return false;
2081 return true;
2084 bool SvxShadowItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2086 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2087 nMemberId &= ~CONVERT_TWIPS;
2089 table::ShadowFormat aShadow;
2090 uno::Any aAny;
2091 bool bRet = QueryValue( aAny, bConvert ? CONVERT_TWIPS : 0 ) && ( aAny >>= aShadow );
2092 switch ( nMemberId )
2094 case MID_LOCATION:
2096 bRet = (rVal >>= aShadow.Location);
2097 if ( !bRet )
2099 sal_Int16 nVal = 0;
2100 bRet = (rVal >>= nVal);
2101 aShadow.Location = static_cast<table::ShadowLocation>(nVal);
2104 break;
2107 case MID_WIDTH: rVal >>= aShadow.ShadowWidth; break;
2108 case MID_TRANSPARENT: rVal >>= aShadow.IsTransparent; break;
2109 case MID_BG_COLOR: rVal >>= aShadow.Color; break;
2110 case 0: rVal >>= aShadow; break;
2111 case MID_SHADOW_TRANSPARENCE:
2113 sal_Int32 nTransparence = 0;
2114 if ((rVal >>= nTransparence) && !o3tl::checked_multiply<sal_Int32>(nTransparence, 255, nTransparence))
2116 Color aColor(ColorTransparency, aShadow.Color);
2117 aColor.SetAlpha(255 - rtl::math::round(float(nTransparence) / 100));
2118 aShadow.Color = sal_Int32(aColor);
2120 break;
2122 default: OSL_FAIL("Wrong MemberId!"); return false;
2125 if ( bRet )
2127 switch( aShadow.Location )
2129 case table::ShadowLocation_NONE : eLocation = SvxShadowLocation::NONE; break;
2130 case table::ShadowLocation_TOP_LEFT : eLocation = SvxShadowLocation::TopLeft; break;
2131 case table::ShadowLocation_TOP_RIGHT : eLocation = SvxShadowLocation::TopRight; break;
2132 case table::ShadowLocation_BOTTOM_LEFT : eLocation = SvxShadowLocation::BottomLeft ; break;
2133 case table::ShadowLocation_BOTTOM_RIGHT: eLocation = SvxShadowLocation::BottomRight; break;
2134 default: ; // prevent warning
2137 nWidth = bConvert ? o3tl::toTwips(aShadow.ShadowWidth, o3tl::Length::mm100) : aShadow.ShadowWidth;
2138 Color aSet(ColorTransparency, aShadow.Color);
2139 aShadowColor = aSet;
2142 return bRet;
2146 bool SvxShadowItem::operator==( const SfxPoolItem& rAttr ) const
2148 assert(SfxPoolItem::operator==(rAttr));
2150 const SvxShadowItem& rItem = static_cast<const SvxShadowItem&>(rAttr);
2151 return ( ( aShadowColor == rItem.aShadowColor ) &&
2152 ( nWidth == rItem.GetWidth() ) &&
2153 ( eLocation == rItem.GetLocation() ) );
2156 SvxShadowItem* SvxShadowItem::Clone( SfxItemPool* ) const
2158 return new SvxShadowItem( *this );
2161 sal_uInt16 SvxShadowItem::CalcShadowSpace( SvxShadowItemSide nShadow ) const
2163 sal_uInt16 nSpace = 0;
2165 switch ( nShadow )
2167 case SvxShadowItemSide::TOP:
2168 if ( eLocation == SvxShadowLocation::TopLeft ||
2169 eLocation == SvxShadowLocation::TopRight )
2170 nSpace = nWidth;
2171 break;
2173 case SvxShadowItemSide::BOTTOM:
2174 if ( eLocation == SvxShadowLocation::BottomLeft ||
2175 eLocation == SvxShadowLocation::BottomRight )
2176 nSpace = nWidth;
2177 break;
2179 case SvxShadowItemSide::LEFT:
2180 if ( eLocation == SvxShadowLocation::TopLeft ||
2181 eLocation == SvxShadowLocation::BottomLeft )
2182 nSpace = nWidth;
2183 break;
2185 case SvxShadowItemSide::RIGHT:
2186 if ( eLocation == SvxShadowLocation::TopRight ||
2187 eLocation == SvxShadowLocation::BottomRight )
2188 nSpace = nWidth;
2189 break;
2191 default:
2192 OSL_FAIL( "wrong shadow" );
2194 return nSpace;
2197 static TranslateId RID_SVXITEMS_SHADOW[] =
2199 RID_SVXITEMS_SHADOW_NONE,
2200 RID_SVXITEMS_SHADOW_TOPLEFT,
2201 RID_SVXITEMS_SHADOW_TOPRIGHT,
2202 RID_SVXITEMS_SHADOW_BOTTOMLEFT,
2203 RID_SVXITEMS_SHADOW_BOTTOMRIGHT
2206 bool SvxShadowItem::GetPresentation
2208 SfxItemPresentation ePres,
2209 MapUnit eCoreUnit,
2210 MapUnit ePresUnit,
2211 OUString& rText, const IntlWrapper& rIntl
2212 ) const
2214 switch ( ePres )
2216 case SfxItemPresentation::Nameless:
2218 rText = ::GetColorString( aShadowColor ) + cpDelim;
2219 TranslateId pId = RID_SVXITEMS_TRANSPARENT_FALSE;
2221 if ( aShadowColor.IsTransparent() )
2222 pId = RID_SVXITEMS_TRANSPARENT_TRUE;
2223 rText += EditResId(pId) +
2224 cpDelim +
2225 GetMetricText( static_cast<tools::Long>(nWidth), eCoreUnit, ePresUnit, &rIntl ) +
2226 cpDelim +
2227 EditResId(RID_SVXITEMS_SHADOW[static_cast<int>(eLocation)]);
2228 return true;
2230 case SfxItemPresentation::Complete:
2232 rText = EditResId(RID_SVXITEMS_SHADOW_COMPLETE) +
2233 ::GetColorString( aShadowColor ) +
2234 cpDelim;
2236 TranslateId pId = RID_SVXITEMS_TRANSPARENT_FALSE;
2237 if ( aShadowColor.IsTransparent() )
2238 pId = RID_SVXITEMS_TRANSPARENT_TRUE;
2239 rText += EditResId(pId) +
2240 cpDelim +
2241 GetMetricText( static_cast<tools::Long>(nWidth), eCoreUnit, ePresUnit, &rIntl ) +
2242 " " + EditResId(GetMetricId(ePresUnit)) +
2243 cpDelim +
2244 EditResId(RID_SVXITEMS_SHADOW[static_cast<int>(eLocation)]);
2245 return true;
2247 default: ; // prevent warning
2249 return false;
2253 void SvxShadowItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
2255 nWidth = static_cast<sal_uInt16>(BigInt::Scale( nWidth, nMult, nDiv ));
2259 bool SvxShadowItem::HasMetrics() const
2261 return true;
2265 sal_uInt16 SvxShadowItem::GetValueCount() const
2267 return sal_uInt16(SvxShadowLocation::End); // SvxShadowLocation::BottomRight + 1
2270 sal_uInt16 SvxShadowItem::GetEnumValue() const
2272 return static_cast<sal_uInt16>(GetLocation());
2276 void SvxShadowItem::SetEnumValue( sal_uInt16 nVal )
2278 SetLocation( static_cast<SvxShadowLocation>(nVal) );
2281 void SvxShadowItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2283 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxShadowItem"));
2284 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2285 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("aShadowColor"), BAD_CAST(aShadowColor.AsRGBHexString().toUtf8().getStr()));
2286 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nWidth"), BAD_CAST(OString::number(nWidth).getStr()));
2287 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("eLocation"), BAD_CAST(OString::number(static_cast<int>(eLocation)).getStr()));
2288 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(EditResId(RID_SVXITEMS_SHADOW[static_cast<int>(eLocation)]).toUtf8().getStr()));
2289 (void)xmlTextWriterEndElement(pWriter);
2292 // class SvxBoxItem ------------------------------------------------------
2294 SvxBoxItem::SvxBoxItem(const SvxBoxItem& rCopy)
2295 : SfxPoolItem (rCopy)
2296 , mpTopBorderLine(rCopy.mpTopBorderLine ? new SvxBorderLine(*rCopy.mpTopBorderLine) : nullptr)
2297 , mpBottomBorderLine(rCopy.mpBottomBorderLine ? new SvxBorderLine(*rCopy.mpBottomBorderLine) : nullptr)
2298 , mpLeftBorderLine(rCopy.mpLeftBorderLine ? new SvxBorderLine(*rCopy.mpLeftBorderLine) : nullptr)
2299 , mpRightBorderLine(rCopy.mpRightBorderLine ? new SvxBorderLine(*rCopy.mpRightBorderLine) : nullptr)
2300 , mnTopDistance(rCopy.mnTopDistance)
2301 , mnBottomDistance(rCopy.mnBottomDistance)
2302 , mnLeftDistance(rCopy.mnLeftDistance)
2303 , mnRightDistance(rCopy.mnRightDistance)
2304 , maTempComplexColors(rCopy.maTempComplexColors)
2305 , mbRemoveAdjCellBorder(rCopy.mbRemoveAdjCellBorder)
2310 SvxBoxItem::SvxBoxItem(const sal_uInt16 nId)
2311 : SfxPoolItem(nId)
2316 SvxBoxItem::~SvxBoxItem()
2320 void SvxBoxItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2322 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxBoxItem"));
2323 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("top-dist"),
2324 BAD_CAST(OString::number(mnTopDistance).getStr()));
2325 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bottom-dist"),
2326 BAD_CAST(OString::number(mnBottomDistance).getStr()));
2327 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("left-dist"),
2328 BAD_CAST(OString::number(mnLeftDistance).getStr()));
2329 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("right-dist"),
2330 BAD_CAST(OString::number(mnRightDistance).getStr()));
2331 SfxPoolItem::dumpAsXml(pWriter);
2332 (void)xmlTextWriterEndElement(pWriter);
2335 boost::property_tree::ptree SvxBoxItem::dumpAsJSON() const
2337 boost::property_tree::ptree aTree;
2339 boost::property_tree::ptree aState;
2340 aState.put("top", GetTop() && !GetTop()->isEmpty());
2341 aState.put("bottom", GetBottom() && !GetBottom()->isEmpty());
2342 aState.put("left", GetLeft() && !GetLeft()->isEmpty());
2343 aState.put("right", GetRight() && !GetRight()->isEmpty());
2345 aTree.push_back(std::make_pair("state", aState));
2346 aTree.put("commandName", ".uno:BorderOuter");
2348 return aTree;
2352 static bool CompareBorderLine(const std::unique_ptr<SvxBorderLine> & pBrd1, const SvxBorderLine* pBrd2)
2354 if( pBrd1.get() == pBrd2 )
2355 return true;
2356 if( pBrd1 == nullptr || pBrd2 == nullptr)
2357 return false;
2358 return *pBrd1 == *pBrd2;
2362 bool SvxBoxItem::operator==( const SfxPoolItem& rAttr ) const
2364 assert(SfxPoolItem::operator==(rAttr));
2366 const SvxBoxItem& rBoxItem = static_cast<const SvxBoxItem&>(rAttr);
2367 return (
2368 (mnTopDistance == rBoxItem.mnTopDistance) &&
2369 (mnBottomDistance == rBoxItem.mnBottomDistance) &&
2370 (mnLeftDistance == rBoxItem.mnLeftDistance) &&
2371 (mnRightDistance == rBoxItem.mnRightDistance) &&
2372 (mbRemoveAdjCellBorder == rBoxItem.mbRemoveAdjCellBorder ) &&
2373 (maTempComplexColors == rBoxItem.maTempComplexColors) &&
2374 CompareBorderLine(mpTopBorderLine, rBoxItem.GetTop()) &&
2375 CompareBorderLine(mpBottomBorderLine, rBoxItem.GetBottom()) &&
2376 CompareBorderLine(mpLeftBorderLine, rBoxItem.GetLeft()) &&
2377 CompareBorderLine(mpRightBorderLine, rBoxItem.GetRight()));
2381 table::BorderLine2 SvxBoxItem::SvxLineToLine(const SvxBorderLine* pLine, bool bConvert)
2383 table::BorderLine2 aLine;
2384 if(pLine)
2386 aLine.Color = sal_Int32(pLine->GetColor());
2387 aLine.InnerLineWidth = sal_uInt16( bConvert ? convertTwipToMm100(pLine->GetInWidth() ): pLine->GetInWidth() );
2388 aLine.OuterLineWidth = sal_uInt16( bConvert ? convertTwipToMm100(pLine->GetOutWidth()): pLine->GetOutWidth() );
2389 aLine.LineDistance = sal_uInt16( bConvert ? convertTwipToMm100(pLine->GetDistance()): pLine->GetDistance() );
2390 aLine.LineStyle = sal_Int16(pLine->GetBorderLineStyle());
2391 aLine.LineWidth = sal_uInt32( bConvert ? convertTwipToMm100( pLine->GetWidth( ) ) : pLine->GetWidth( ) );
2393 else
2395 aLine.Color = aLine.InnerLineWidth = aLine.OuterLineWidth = aLine.LineDistance = 0;
2396 aLine.LineStyle = table::BorderLineStyle::NONE; // 0 is SOLID!
2398 return aLine;
2401 bool SvxBoxItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2403 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2404 table::BorderLine2 aRetLine;
2405 sal_Int16 nDist = 0;
2406 bool bDistMember = false;
2407 nMemberId &= ~CONVERT_TWIPS;
2408 switch(nMemberId)
2410 case 0:
2412 // 4 Borders and 5 distances
2413 uno::Sequence< uno::Any > aSeq{
2414 uno::Any(SvxBoxItem::SvxLineToLine(GetLeft(), bConvert)),
2415 uno::Any(SvxBoxItem::SvxLineToLine(GetRight(), bConvert)),
2416 uno::Any(SvxBoxItem::SvxLineToLine(GetBottom(), bConvert)),
2417 uno::Any(SvxBoxItem::SvxLineToLine(GetTop(), bConvert)),
2418 uno::Any(static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetSmallestDistance()) : GetSmallestDistance())),
2419 uno::Any(static_cast<sal_Int32>(bConvert ? convertTwipToMm100(mnTopDistance) : mnTopDistance)),
2420 uno::Any(static_cast<sal_Int32>(bConvert ? convertTwipToMm100(mnBottomDistance) : mnBottomDistance)),
2421 uno::Any(static_cast<sal_Int32>(bConvert ? convertTwipToMm100(mnLeftDistance) : mnLeftDistance)),
2422 uno::Any(static_cast<sal_Int32>(bConvert ? convertTwipToMm100(mnRightDistance) : mnRightDistance))
2424 rVal <<= aSeq;
2425 return true;
2427 case MID_LEFT_BORDER:
2428 case LEFT_BORDER:
2429 aRetLine = SvxBoxItem::SvxLineToLine(GetLeft(), bConvert);
2430 break;
2431 case MID_RIGHT_BORDER:
2432 case RIGHT_BORDER:
2433 aRetLine = SvxBoxItem::SvxLineToLine(GetRight(), bConvert);
2434 break;
2435 case MID_BOTTOM_BORDER:
2436 case BOTTOM_BORDER:
2437 aRetLine = SvxBoxItem::SvxLineToLine(GetBottom(), bConvert);
2438 break;
2439 case MID_TOP_BORDER:
2440 case TOP_BORDER:
2441 aRetLine = SvxBoxItem::SvxLineToLine(GetTop(), bConvert);
2442 break;
2443 case BORDER_DISTANCE:
2444 nDist = GetSmallestDistance();
2445 bDistMember = true;
2446 break;
2447 case TOP_BORDER_DISTANCE:
2448 nDist = mnTopDistance;
2449 bDistMember = true;
2450 break;
2451 case BOTTOM_BORDER_DISTANCE:
2452 nDist = mnBottomDistance;
2453 bDistMember = true;
2454 break;
2455 case LEFT_BORDER_DISTANCE:
2456 nDist = mnLeftDistance;
2457 bDistMember = true;
2458 break;
2459 case RIGHT_BORDER_DISTANCE:
2460 nDist = mnRightDistance;
2461 bDistMember = true;
2462 break;
2463 case MID_BORDER_BOTTOM_COLOR:
2465 if (mpBottomBorderLine)
2467 rVal <<= model::color::createXComplexColor(mpBottomBorderLine->getComplexColor());
2469 else if (maTempComplexColors[size_t(SvxBoxItemLine::BOTTOM)].getType() != model::ColorType::Unused)
2471 rVal <<= model::color::createXComplexColor(maTempComplexColors[size_t(SvxBoxItemLine::BOTTOM)]);
2473 return true;
2475 case MID_BORDER_LEFT_COLOR:
2477 if (mpLeftBorderLine)
2479 rVal <<= model::color::createXComplexColor(mpLeftBorderLine->getComplexColor());
2481 else if (maTempComplexColors[size_t(SvxBoxItemLine::LEFT)].getType() != model::ColorType::Unused)
2483 rVal <<= model::color::createXComplexColor(maTempComplexColors[size_t(SvxBoxItemLine::LEFT)]);
2485 return true;
2487 case MID_BORDER_RIGHT_COLOR:
2489 if (mpRightBorderLine)
2491 rVal <<= model::color::createXComplexColor(mpRightBorderLine->getComplexColor());
2493 else if (maTempComplexColors[size_t(SvxBoxItemLine::RIGHT)].getType() != model::ColorType::Unused)
2495 rVal <<= model::color::createXComplexColor(maTempComplexColors[size_t(SvxBoxItemLine::RIGHT)]);
2497 return true;
2499 case MID_BORDER_TOP_COLOR:
2501 if (mpTopBorderLine)
2503 rVal <<= model::color::createXComplexColor(mpTopBorderLine->getComplexColor());
2505 else if (maTempComplexColors[size_t(SvxBoxItemLine::TOP)].getType() != model::ColorType::Unused)
2507 rVal <<= model::color::createXComplexColor(maTempComplexColors[size_t(SvxBoxItemLine::TOP)]);
2509 return true;
2511 case LINE_STYLE:
2512 case LINE_WIDTH:
2513 // it doesn't make sense to return a value for these since it's
2514 // probably ambiguous
2515 return true;
2518 if( bDistMember )
2519 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(nDist) : nDist);
2520 else
2521 rVal <<= aRetLine;
2523 return true;
2526 namespace
2529 bool
2530 lcl_lineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine, bool bConvert, bool bGuessWidth)
2532 rSvxLine.SetColor( Color(ColorTransparency, rLine.Color));
2533 if ( bGuessWidth )
2535 rSvxLine.GuessLinesWidths( rSvxLine.GetBorderLineStyle(),
2536 bConvert ? o3tl::toTwips(rLine.OuterLineWidth, o3tl::Length::mm100) : rLine.OuterLineWidth,
2537 bConvert ? o3tl::toTwips(rLine.InnerLineWidth, o3tl::Length::mm100) : rLine.InnerLineWidth,
2538 bConvert ? o3tl::toTwips(rLine.LineDistance, o3tl::Length::mm100) : rLine.LineDistance );
2541 bool bRet = !rSvxLine.isEmpty();
2542 return bRet;
2548 bool SvxBoxItem::LineToSvxLine(const css::table::BorderLine& rLine, SvxBorderLine& rSvxLine, bool bConvert)
2550 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, true);
2553 bool
2554 SvxBoxItem::LineToSvxLine(const css::table::BorderLine2& rLine, SvxBorderLine& rSvxLine, bool bConvert)
2556 SvxBorderLineStyle const nStyle =
2557 (rLine.LineStyle < 0 || BORDER_LINE_STYLE_MAX < rLine.LineStyle)
2558 ? SvxBorderLineStyle::SOLID // default
2559 : static_cast<SvxBorderLineStyle>(rLine.LineStyle);
2561 rSvxLine.SetBorderLineStyle( nStyle );
2563 bool bGuessWidth = true;
2564 if ( rLine.LineWidth )
2566 rSvxLine.SetWidth( bConvert? o3tl::toTwips(rLine.LineWidth, o3tl::Length::mm100) : rLine.LineWidth );
2567 // fdo#46112: double does not necessarily mean symmetric
2568 // for backwards compatibility
2569 bGuessWidth = (SvxBorderLineStyle::DOUBLE == nStyle || SvxBorderLineStyle::DOUBLE_THIN == nStyle) &&
2570 (rLine.InnerLineWidth > 0) && (rLine.OuterLineWidth > 0);
2573 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, bGuessWidth);
2577 namespace
2580 bool
2581 lcl_extractBorderLine(const uno::Any& rAny, table::BorderLine2& rLine)
2583 if (rAny >>= rLine)
2584 return true;
2586 table::BorderLine aBorderLine;
2587 if (rAny >>= aBorderLine)
2589 rLine.Color = aBorderLine.Color;
2590 rLine.InnerLineWidth = aBorderLine.InnerLineWidth;
2591 rLine.OuterLineWidth = aBorderLine.OuterLineWidth;
2592 rLine.LineDistance = aBorderLine.LineDistance;
2593 rLine.LineStyle = table::BorderLineStyle::SOLID;
2594 return true;
2597 return false;
2600 template<typename Item, typename Line>
2601 bool
2602 lcl_setLine(const uno::Any& rAny, Item& rItem, Line nLine, const bool bConvert)
2604 bool bDone = false;
2605 table::BorderLine2 aBorderLine;
2606 if (lcl_extractBorderLine(rAny, aBorderLine))
2608 SvxBorderLine aLine;
2609 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2610 rItem.SetLine( bSet ? &aLine : nullptr, nLine);
2611 bDone = true;
2613 return bDone;
2618 bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2620 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2621 SvxBoxItemLine nLine = SvxBoxItemLine::TOP;
2622 bool bDistMember = false;
2623 nMemberId &= ~CONVERT_TWIPS;
2624 switch(nMemberId)
2626 case 0:
2628 uno::Sequence< uno::Any > aSeq;
2629 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ))
2631 // 4 Borders and 5 distances
2632 const SvxBoxItemLine aBorders[] = { SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT, SvxBoxItemLine::BOTTOM, SvxBoxItemLine::TOP };
2633 for (size_t n(0); n != std::size(aBorders); ++n)
2635 if (!lcl_setLine(aSeq[n], *this, aBorders[n], bConvert))
2636 return false;
2637 tryMigrateComplexColor(aBorders[n]);
2640 // WTH are the borders and the distances saved in different order?
2641 SvxBoxItemLine const nLines[4] = { SvxBoxItemLine::TOP, SvxBoxItemLine::BOTTOM, SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT };
2642 for ( sal_Int32 n = 4; n < 9; n++ )
2644 sal_Int32 nDist = 0;
2645 if ( aSeq[n] >>= nDist )
2647 if( bConvert )
2648 nDist = o3tl::toTwips(nDist, o3tl::Length::mm100);
2649 if ( n == 4 )
2650 SetAllDistances(nDist);
2651 else
2652 SetDistance( nDist, nLines[n-5] );
2654 else
2655 return false;
2658 return true;
2660 else
2661 return false;
2663 case LEFT_BORDER_DISTANCE:
2664 bDistMember = true;
2665 [[fallthrough]];
2666 case LEFT_BORDER:
2667 case MID_LEFT_BORDER:
2668 nLine = SvxBoxItemLine::LEFT;
2669 break;
2670 case RIGHT_BORDER_DISTANCE:
2671 bDistMember = true;
2672 [[fallthrough]];
2673 case RIGHT_BORDER:
2674 case MID_RIGHT_BORDER:
2675 nLine = SvxBoxItemLine::RIGHT;
2676 break;
2677 case BOTTOM_BORDER_DISTANCE:
2678 bDistMember = true;
2679 [[fallthrough]];
2680 case BOTTOM_BORDER:
2681 case MID_BOTTOM_BORDER:
2682 nLine = SvxBoxItemLine::BOTTOM;
2683 break;
2684 case TOP_BORDER_DISTANCE:
2685 bDistMember = true;
2686 [[fallthrough]];
2687 case TOP_BORDER:
2688 case MID_TOP_BORDER:
2689 nLine = SvxBoxItemLine::TOP;
2690 break;
2691 case LINE_STYLE:
2693 drawing::LineStyle eDrawingStyle;
2694 rVal >>= eDrawingStyle;
2695 SvxBorderLineStyle eBorderStyle = SvxBorderLineStyle::NONE;
2696 switch ( eDrawingStyle )
2698 default:
2699 case drawing::LineStyle_NONE:
2700 break;
2701 case drawing::LineStyle_SOLID:
2702 eBorderStyle = SvxBorderLineStyle::SOLID;
2703 break;
2704 case drawing::LineStyle_DASH:
2705 eBorderStyle = SvxBorderLineStyle::DASHED;
2706 break;
2709 // Set the line style on all borders
2710 for( SvxBoxItemLine n : o3tl::enumrange<SvxBoxItemLine>() )
2712 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( n ) );
2713 if( pLine )
2714 pLine->SetBorderLineStyle( eBorderStyle );
2716 return true;
2718 break;
2719 case LINE_WIDTH:
2721 // Set the line width on all borders
2722 tools::Long nWidth(0);
2723 rVal >>= nWidth;
2724 if( bConvert )
2725 nWidth = o3tl::toTwips(nWidth, o3tl::Length::mm100);
2727 // Set the line Width on all borders
2728 for( SvxBoxItemLine n : o3tl::enumrange<SvxBoxItemLine>() )
2730 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( n ) );
2731 if( pLine )
2732 pLine->SetWidth( nWidth );
2735 return true;
2736 case MID_BORDER_BOTTOM_COLOR:
2738 if (mpBottomBorderLine)
2739 return mpBottomBorderLine->setComplexColorFromAny(rVal);
2740 else
2742 css::uno::Reference<css::util::XComplexColor> xComplexColor;
2743 if (!(rVal >>= xComplexColor))
2744 return false;
2746 if (xComplexColor.is())
2747 maTempComplexColors[size_t(SvxBoxItemLine::BOTTOM)] = model::color::getFromXComplexColor(xComplexColor);
2749 return true;
2751 case MID_BORDER_LEFT_COLOR:
2753 if (mpLeftBorderLine)
2754 return mpLeftBorderLine->setComplexColorFromAny(rVal);
2755 else
2757 css::uno::Reference<css::util::XComplexColor> xComplexColor;
2758 if (!(rVal >>= xComplexColor))
2759 return false;
2761 if (xComplexColor.is())
2762 maTempComplexColors[size_t(SvxBoxItemLine::LEFT)] = model::color::getFromXComplexColor(xComplexColor);
2764 return true;
2766 case MID_BORDER_RIGHT_COLOR:
2768 if (mpRightBorderLine)
2769 return mpRightBorderLine->setComplexColorFromAny(rVal);
2770 else
2772 css::uno::Reference<css::util::XComplexColor> xComplexColor;
2773 if (!(rVal >>= xComplexColor))
2774 return false;
2776 if (xComplexColor.is())
2777 maTempComplexColors[size_t(SvxBoxItemLine::RIGHT)] = model::color::getFromXComplexColor(xComplexColor);
2779 return true;
2781 case MID_BORDER_TOP_COLOR:
2783 if (mpTopBorderLine)
2784 return mpTopBorderLine->setComplexColorFromAny(rVal);
2785 else
2787 css::uno::Reference<css::util::XComplexColor> xComplexColor;
2788 if (!(rVal >>= xComplexColor))
2789 return false;
2791 if (xComplexColor.is())
2792 maTempComplexColors[size_t(SvxBoxItemLine::TOP)] = model::color::getFromXComplexColor(xComplexColor);
2794 return true;
2798 if( bDistMember || nMemberId == BORDER_DISTANCE )
2800 sal_Int32 nDist = 0;
2801 if(!(rVal >>= nDist))
2802 return false;
2805 if( bConvert )
2806 nDist = o3tl::toTwips(nDist, o3tl::Length::mm100);
2807 if( nMemberId == BORDER_DISTANCE )
2808 SetAllDistances(nDist);
2809 else
2810 SetDistance( nDist, nLine );
2813 else
2815 SvxBorderLine aLine;
2816 if( !rVal.hasValue() )
2817 return false;
2819 table::BorderLine2 aBorderLine;
2820 if( lcl_extractBorderLine(rVal, aBorderLine) )
2822 // usual struct
2824 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2826 // serialization for basic macro recording
2827 uno::Reference < script::XTypeConverter > xConverter
2828 ( script::Converter::create(::comphelper::getProcessComponentContext()) );
2829 uno::Sequence < uno::Any > aSeq;
2830 uno::Any aNew;
2831 try { aNew = xConverter->convertTo( rVal, cppu::UnoType<uno::Sequence < uno::Any >>::get() ); }
2832 catch (const uno::Exception&) {}
2834 aNew >>= aSeq;
2835 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2837 sal_Int32 nVal = 0;
2838 if ( aSeq[0] >>= nVal )
2839 aBorderLine.Color = nVal;
2840 if ( aSeq[1] >>= nVal )
2841 aBorderLine.InnerLineWidth = static_cast<sal_Int16>(nVal);
2842 if ( aSeq[2] >>= nVal )
2843 aBorderLine.OuterLineWidth = static_cast<sal_Int16>(nVal);
2844 if ( aSeq[3] >>= nVal )
2845 aBorderLine.LineDistance = static_cast<sal_Int16>(nVal);
2846 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2848 if (aSeq[4] >>= nVal)
2850 aBorderLine.LineStyle = nVal;
2852 if (aSeq.getLength() >= 6)
2854 if (aSeq[5] >>= nVal)
2856 aBorderLine.LineWidth = nVal;
2861 else
2862 return false;
2864 else
2865 return false;
2867 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2868 SetLine(bSet ? &aLine : nullptr, nLine);
2869 tryMigrateComplexColor(nLine);
2872 return true;
2875 SvxBoxItem* SvxBoxItem::Clone( SfxItemPool* ) const
2877 return new SvxBoxItem( *this );
2880 bool SvxBoxItem::GetPresentation
2882 SfxItemPresentation ePres,
2883 MapUnit eCoreUnit,
2884 MapUnit ePresUnit,
2885 OUString& rText, const IntlWrapper& rIntl
2886 ) const
2888 OUString cpDelimTmp(cpDelim);
2889 switch ( ePres )
2891 case SfxItemPresentation::Nameless:
2893 rText.clear();
2895 if (mpTopBorderLine)
2897 rText = mpTopBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl ) + cpDelimTmp;
2899 if ( !(mpTopBorderLine && mpBottomBorderLine && mpLeftBorderLine && mpRightBorderLine &&
2900 *mpTopBorderLine == *mpBottomBorderLine &&
2901 *mpTopBorderLine == *mpLeftBorderLine &&
2902 *mpTopBorderLine == *mpRightBorderLine))
2904 if (mpBottomBorderLine)
2906 rText += mpBottomBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl ) + cpDelimTmp;
2908 if (mpLeftBorderLine)
2910 rText += mpLeftBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl ) + cpDelimTmp;
2912 if (mpRightBorderLine)
2914 rText += mpRightBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl ) + cpDelimTmp;
2917 rText += GetMetricText( static_cast<tools::Long>(mnTopDistance), eCoreUnit, ePresUnit, &rIntl );
2918 if (mnTopDistance != mnBottomDistance ||
2919 mnTopDistance != mnLeftDistance ||
2920 mnTopDistance != mnRightDistance)
2922 rText += cpDelimTmp +
2923 GetMetricText( tools::Long(mnBottomDistance), eCoreUnit, ePresUnit, &rIntl ) +
2924 cpDelimTmp +
2925 GetMetricText( tools::Long(mnLeftDistance), eCoreUnit, ePresUnit, &rIntl ) +
2926 cpDelimTmp +
2927 GetMetricText( tools::Long(mnRightDistance), eCoreUnit, ePresUnit, &rIntl );
2929 return true;
2931 case SfxItemPresentation::Complete:
2933 if (!(mpTopBorderLine || mpBottomBorderLine || mpLeftBorderLine || mpRightBorderLine))
2935 rText = EditResId(RID_SVXITEMS_BORDER_NONE) + cpDelimTmp;
2937 else
2939 rText = EditResId(RID_SVXITEMS_BORDER_COMPLETE);
2940 if (mpTopBorderLine && mpBottomBorderLine && mpLeftBorderLine && mpRightBorderLine &&
2941 *mpTopBorderLine == *mpBottomBorderLine &&
2942 *mpTopBorderLine == *mpLeftBorderLine &&
2943 *mpTopBorderLine == *mpRightBorderLine)
2945 rText += mpTopBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl, true ) + cpDelimTmp;
2947 else
2949 if (mpTopBorderLine)
2951 rText += EditResId(RID_SVXITEMS_BORDER_TOP) +
2952 mpTopBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl, true ) +
2953 cpDelimTmp;
2955 if (mpBottomBorderLine)
2957 rText += EditResId(RID_SVXITEMS_BORDER_BOTTOM) +
2958 mpBottomBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl, true ) +
2959 cpDelimTmp;
2961 if (mpLeftBorderLine)
2963 rText += EditResId(RID_SVXITEMS_BORDER_LEFT) +
2964 mpLeftBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl, true ) +
2965 cpDelimTmp;
2967 if (mpRightBorderLine)
2969 rText += EditResId(RID_SVXITEMS_BORDER_RIGHT) +
2970 mpRightBorderLine->GetValueString( eCoreUnit, ePresUnit, &rIntl, true ) +
2971 cpDelimTmp;
2976 rText += EditResId(RID_SVXITEMS_BORDER_DISTANCE);
2977 if (mnTopDistance == mnBottomDistance &&
2978 mnTopDistance == mnLeftDistance &&
2979 mnTopDistance == mnRightDistance)
2981 rText += GetMetricText(tools::Long(mnTopDistance), eCoreUnit, ePresUnit, &rIntl ) +
2982 " " + EditResId(GetMetricId(ePresUnit));
2984 else
2986 rText += EditResId(RID_SVXITEMS_BORDER_TOP) +
2987 GetMetricText(tools::Long(mnTopDistance), eCoreUnit, ePresUnit, &rIntl) +
2988 " " + EditResId(GetMetricId(ePresUnit)) +
2989 cpDelimTmp +
2990 EditResId(RID_SVXITEMS_BORDER_BOTTOM) +
2991 GetMetricText(tools::Long(mnBottomDistance), eCoreUnit, ePresUnit, &rIntl) +
2992 " " + EditResId(GetMetricId(ePresUnit)) +
2993 cpDelimTmp +
2994 EditResId(RID_SVXITEMS_BORDER_LEFT) +
2995 GetMetricText(tools::Long(mnLeftDistance), eCoreUnit, ePresUnit, &rIntl) +
2996 " " + EditResId(GetMetricId(ePresUnit)) +
2997 cpDelimTmp +
2998 EditResId(RID_SVXITEMS_BORDER_RIGHT) +
2999 GetMetricText(tools::Long(mnRightDistance), eCoreUnit, ePresUnit, &rIntl) +
3000 " " + EditResId(GetMetricId(ePresUnit));
3002 return true;
3004 default: ; // prevent warning
3006 return false;
3010 void SvxBoxItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
3012 if (mpTopBorderLine)
3013 mpTopBorderLine->ScaleMetrics( nMult, nDiv );
3014 if (mpBottomBorderLine)
3015 mpBottomBorderLine->ScaleMetrics( nMult, nDiv );
3016 if (mpLeftBorderLine)
3017 mpLeftBorderLine->ScaleMetrics( nMult, nDiv );
3018 if (mpRightBorderLine)
3019 mpRightBorderLine->ScaleMetrics( nMult, nDiv );
3021 mnTopDistance = static_cast<sal_Int16>(BigInt::Scale(mnTopDistance, nMult, nDiv));
3022 mnBottomDistance = static_cast<sal_Int16>(BigInt::Scale(mnBottomDistance, nMult, nDiv));
3023 mnLeftDistance = static_cast<sal_Int16>(BigInt::Scale(mnLeftDistance, nMult, nDiv));
3024 mnRightDistance = static_cast<sal_Int16>(BigInt::Scale(mnRightDistance, nMult, nDiv));
3028 bool SvxBoxItem::HasMetrics() const
3030 return true;
3034 const SvxBorderLine *SvxBoxItem::GetLine( SvxBoxItemLine nLine ) const
3036 const SvxBorderLine *pRet = nullptr;
3038 switch ( nLine )
3040 case SvxBoxItemLine::TOP:
3041 pRet = mpTopBorderLine.get();
3042 break;
3043 case SvxBoxItemLine::BOTTOM:
3044 pRet = mpBottomBorderLine.get();
3045 break;
3046 case SvxBoxItemLine::LEFT:
3047 pRet = mpLeftBorderLine.get();
3048 break;
3049 case SvxBoxItemLine::RIGHT:
3050 pRet = mpRightBorderLine.get();
3051 break;
3052 default:
3053 OSL_FAIL( "wrong line" );
3054 break;
3057 return pRet;
3061 void SvxBoxItem::SetLine( const SvxBorderLine* pNew, SvxBoxItemLine nLine )
3063 std::unique_ptr<SvxBorderLine> pTmp( pNew ? new SvxBorderLine( *pNew ) : nullptr );
3065 switch ( nLine )
3067 case SvxBoxItemLine::TOP:
3068 mpTopBorderLine = std::move(pTmp);
3069 break;
3070 case SvxBoxItemLine::BOTTOM:
3071 mpBottomBorderLine = std::move(pTmp);
3072 break;
3073 case SvxBoxItemLine::LEFT:
3074 mpLeftBorderLine = std::move(pTmp);
3075 break;
3076 case SvxBoxItemLine::RIGHT:
3077 mpRightBorderLine = std::move(pTmp);
3078 break;
3079 default:
3080 OSL_FAIL( "wrong line" );
3085 sal_uInt16 SvxBoxItem::GetSmallestDistance() const
3087 // The smallest distance that is not 0 will be returned.
3088 sal_uInt16 nDist = mnTopDistance;
3089 if (mnBottomDistance && (!nDist || mnBottomDistance < nDist))
3090 nDist = mnBottomDistance;
3091 if (mnLeftDistance && (!nDist || mnLeftDistance < nDist))
3092 nDist = mnLeftDistance;
3093 if (mnRightDistance && (!nDist || mnRightDistance < nDist))
3094 nDist = mnRightDistance;
3096 return nDist;
3100 sal_Int16 SvxBoxItem::GetDistance( SvxBoxItemLine nLine, bool bAllowNegative ) const
3102 sal_Int16 nDist = 0;
3103 switch ( nLine )
3105 case SvxBoxItemLine::TOP:
3106 nDist = mnTopDistance;
3107 break;
3108 case SvxBoxItemLine::BOTTOM:
3109 nDist = mnBottomDistance;
3110 break;
3111 case SvxBoxItemLine::LEFT:
3112 nDist = mnLeftDistance;
3113 break;
3114 case SvxBoxItemLine::RIGHT:
3115 nDist = mnRightDistance;
3116 break;
3117 default:
3118 OSL_FAIL( "wrong line" );
3121 if (!bAllowNegative && nDist < 0)
3123 nDist = 0;
3125 return nDist;
3129 void SvxBoxItem::SetDistance( sal_Int16 nNew, SvxBoxItemLine nLine )
3131 switch ( nLine )
3133 case SvxBoxItemLine::TOP:
3134 mnTopDistance = nNew;
3135 break;
3136 case SvxBoxItemLine::BOTTOM:
3137 mnBottomDistance = nNew;
3138 break;
3139 case SvxBoxItemLine::LEFT:
3140 mnLeftDistance = nNew;
3141 break;
3142 case SvxBoxItemLine::RIGHT:
3143 mnRightDistance = nNew;
3144 break;
3145 default:
3146 OSL_FAIL( "wrong line" );
3150 sal_uInt16 SvxBoxItem::CalcLineWidth( SvxBoxItemLine nLine ) const
3152 SvxBorderLine* pTmp = nullptr;
3153 sal_uInt16 nWidth = 0;
3154 switch ( nLine )
3156 case SvxBoxItemLine::TOP:
3157 pTmp = mpTopBorderLine.get();
3158 break;
3159 case SvxBoxItemLine::BOTTOM:
3160 pTmp = mpBottomBorderLine.get();
3161 break;
3162 case SvxBoxItemLine::LEFT:
3163 pTmp = mpLeftBorderLine.get();
3164 break;
3165 case SvxBoxItemLine::RIGHT:
3166 pTmp = mpRightBorderLine.get();
3167 break;
3168 default:
3169 OSL_FAIL( "wrong line" );
3172 if( pTmp )
3173 nWidth = pTmp->GetScaledWidth();
3175 return nWidth;
3178 sal_Int16 SvxBoxItem::CalcLineSpace( SvxBoxItemLine nLine, bool bEvenIfNoLine, bool bAllowNegative ) const
3180 SvxBorderLine* pTmp = nullptr;
3181 sal_Int16 nDist = 0;
3182 switch ( nLine )
3184 case SvxBoxItemLine::TOP:
3185 pTmp = mpTopBorderLine.get();
3186 nDist = mnTopDistance;
3187 break;
3188 case SvxBoxItemLine::BOTTOM:
3189 pTmp = mpBottomBorderLine.get();
3190 nDist = mnBottomDistance;
3191 break;
3192 case SvxBoxItemLine::LEFT:
3193 pTmp = mpLeftBorderLine.get();
3194 nDist = mnLeftDistance;
3195 break;
3196 case SvxBoxItemLine::RIGHT:
3197 pTmp = mpRightBorderLine.get();
3198 nDist = mnRightDistance;
3199 break;
3200 default:
3201 OSL_FAIL( "wrong line" );
3204 if( pTmp )
3206 nDist = nDist + pTmp->GetScaledWidth();
3208 else if( !bEvenIfNoLine )
3209 nDist = 0;
3211 if (!bAllowNegative && nDist < 0)
3213 nDist = 0;
3216 return nDist;
3219 void SvxBoxItem::tryMigrateComplexColor(SvxBoxItemLine eLine)
3221 if (!GetLine(eLine))
3222 return;
3224 auto nIndex = size_t(eLine);
3226 if (maTempComplexColors[nIndex].getType() == model::ColorType::Unused)
3227 return;
3229 switch (eLine)
3231 case SvxBoxItemLine::TOP:
3232 mpTopBorderLine->setComplexColor(maTempComplexColors[nIndex]);
3233 break;
3234 case SvxBoxItemLine::BOTTOM:
3235 mpBottomBorderLine->setComplexColor(maTempComplexColors[nIndex]);
3236 break;
3237 case SvxBoxItemLine::LEFT:
3238 mpLeftBorderLine->setComplexColor(maTempComplexColors[nIndex]);
3239 break;
3240 case SvxBoxItemLine::RIGHT:
3241 mpRightBorderLine->setComplexColor(maTempComplexColors[nIndex]);
3242 break;
3245 maTempComplexColors[nIndex] = model::ComplexColor();
3248 bool SvxBoxItem::HasBorder( bool bTreatPaddingAsBorder ) const
3250 return CalcLineSpace( SvxBoxItemLine::BOTTOM, bTreatPaddingAsBorder )
3251 || CalcLineSpace( SvxBoxItemLine::RIGHT, bTreatPaddingAsBorder )
3252 || CalcLineSpace( SvxBoxItemLine::TOP, bTreatPaddingAsBorder )
3253 || CalcLineSpace( SvxBoxItemLine::LEFT, bTreatPaddingAsBorder );
3256 // class SvxBoxInfoItem --------------------------------------------------
3258 SvxBoxInfoItem::SvxBoxInfoItem(const sal_uInt16 nId)
3259 : SfxPoolItem(nId)
3260 , mbDistance(false)
3261 , mbMinimumDistance(false)
3263 ResetFlags();
3267 SvxBoxInfoItem::SvxBoxInfoItem( const SvxBoxInfoItem& rCopy )
3268 : SfxPoolItem(rCopy)
3269 , mpHorizontalLine(rCopy.mpHorizontalLine ? new SvxBorderLine(*rCopy.mpHorizontalLine) : nullptr)
3270 , mpVerticalLine(rCopy.mpVerticalLine ? new SvxBorderLine(*rCopy.mpVerticalLine) : nullptr)
3271 , mbEnableHorizontalLine(rCopy.mbEnableHorizontalLine)
3272 , mbEnableVerticalLine(rCopy.mbEnableVerticalLine)
3273 , mbDistance(rCopy.mbDistance)
3274 , mbMinimumDistance (rCopy.mbMinimumDistance)
3275 , mnValidFlags(rCopy.mnValidFlags)
3276 , mnDefaultMinimumDistance(rCopy.mnDefaultMinimumDistance)
3280 SvxBoxInfoItem::~SvxBoxInfoItem()
3285 boost::property_tree::ptree SvxBoxInfoItem::dumpAsJSON() const
3287 boost::property_tree::ptree aTree;
3289 boost::property_tree::ptree aState;
3290 aState.put("vertical", GetVert() && !GetVert()->isEmpty());
3291 aState.put("horizontal", GetHori() && !GetHori()->isEmpty());
3293 aTree.push_back(std::make_pair("state", aState));
3294 aTree.put("commandName", ".uno:BorderInner");
3296 return aTree;
3300 bool SvxBoxInfoItem::operator==( const SfxPoolItem& rAttr ) const
3302 assert(SfxPoolItem::operator==(rAttr));
3304 const SvxBoxInfoItem& rBoxInfo = static_cast<const SvxBoxInfoItem&>(rAttr);
3306 return (mbEnableHorizontalLine == rBoxInfo.mbEnableHorizontalLine
3307 && mbEnableVerticalLine == rBoxInfo.mbEnableVerticalLine
3308 && mbDistance == rBoxInfo.mbDistance
3309 && mbMinimumDistance == rBoxInfo.mbMinimumDistance
3310 && mnValidFlags == rBoxInfo.mnValidFlags
3311 && mnDefaultMinimumDistance == rBoxInfo.mnDefaultMinimumDistance
3312 && CompareBorderLine(mpHorizontalLine, rBoxInfo.GetHori())
3313 && CompareBorderLine(mpVerticalLine, rBoxInfo.GetVert()));
3317 void SvxBoxInfoItem::SetLine( const SvxBorderLine* pNew, SvxBoxInfoItemLine nLine )
3319 std::unique_ptr<SvxBorderLine> pCopy(pNew ? new SvxBorderLine(*pNew) : nullptr);
3321 if ( SvxBoxInfoItemLine::HORI == nLine )
3323 mpHorizontalLine = std::move(pCopy);
3325 else if ( SvxBoxInfoItemLine::VERT == nLine )
3327 mpVerticalLine = std::move(pCopy);
3329 else
3331 OSL_FAIL( "wrong line" );
3335 SvxBoxInfoItem* SvxBoxInfoItem::Clone( SfxItemPool* ) const
3337 return new SvxBoxInfoItem( *this );
3340 bool SvxBoxInfoItem::GetPresentation
3342 SfxItemPresentation /*ePres*/,
3343 MapUnit /*eCoreUnit*/,
3344 MapUnit /*ePresUnit*/,
3345 OUString& rText, const IntlWrapper&
3346 ) const
3348 rText.clear();
3349 return false;
3353 void SvxBoxInfoItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
3355 if (mpHorizontalLine)
3356 mpHorizontalLine->ScaleMetrics(nMult, nDiv);
3357 if (mpVerticalLine)
3358 mpVerticalLine->ScaleMetrics(nMult, nDiv);
3359 mnDefaultMinimumDistance = sal_uInt16(BigInt::Scale(mnDefaultMinimumDistance, nMult, nDiv));
3363 bool SvxBoxInfoItem::HasMetrics() const
3365 return true;
3369 void SvxBoxInfoItem::ResetFlags()
3371 mnValidFlags = static_cast<SvxBoxInfoItemValidFlags>(0x7F); // all valid except Disable
3374 bool SvxBoxInfoItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
3376 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
3377 table::BorderLine2 aRetLine;
3378 sal_Int16 nVal=0;
3379 bool bIntMember = false;
3380 nMemberId &= ~CONVERT_TWIPS;
3381 switch(nMemberId)
3383 case 0:
3385 // 2 BorderLines, flags, valid flags and distance
3386 if ( IsTable() )
3387 nVal |= 0x01;
3388 if ( IsDist() )
3389 nVal |= 0x02;
3390 if ( IsMinDist() )
3391 nVal |= 0x04;
3392 css::uno::Sequence< css::uno::Any > aSeq{
3393 uno::Any(SvxBoxItem::SvxLineToLine(mpHorizontalLine.get(), bConvert)),
3394 uno::Any(SvxBoxItem::SvxLineToLine(mpVerticalLine.get(), bConvert)),
3395 uno::Any(nVal),
3396 uno::Any(static_cast<sal_Int16>(mnValidFlags)),
3397 uno::Any(static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetDefDist()) : GetDefDist()))
3399 rVal <<= aSeq;
3400 return true;
3403 case MID_HORIZONTAL:
3404 aRetLine = SvxBoxItem::SvxLineToLine(mpHorizontalLine.get(), bConvert);
3405 break;
3406 case MID_VERTICAL:
3407 aRetLine = SvxBoxItem::SvxLineToLine(mpVerticalLine.get(), bConvert);
3408 break;
3409 case MID_FLAGS:
3410 bIntMember = true;
3411 if ( IsTable() )
3412 nVal |= 0x01;
3413 if ( IsDist() )
3414 nVal |= 0x02;
3415 if ( IsMinDist() )
3416 nVal |= 0x04;
3417 rVal <<= nVal;
3418 break;
3419 case MID_VALIDFLAGS:
3420 bIntMember = true;
3421 rVal <<= static_cast<sal_Int16>(mnValidFlags);
3422 break;
3423 case MID_DISTANCE:
3424 bIntMember = true;
3425 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetDefDist()) : GetDefDist());
3426 break;
3427 default: OSL_FAIL("Wrong MemberId!"); return false;
3430 if( !bIntMember )
3431 rVal <<= aRetLine;
3433 return true;
3437 bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
3439 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
3440 nMemberId &= ~CONVERT_TWIPS;
3441 bool bRet;
3442 switch(nMemberId)
3444 case 0:
3446 css::uno::Sequence< css::uno::Any > aSeq;
3447 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 5 ))
3449 // 2 BorderLines, flags, valid flags and distance
3450 if (!lcl_setLine(aSeq[0], *this, SvxBoxInfoItemLine::HORI, bConvert))
3451 return false;
3452 if (!lcl_setLine(aSeq[1], *this, SvxBoxInfoItemLine::VERT, bConvert))
3453 return false;
3455 sal_Int16 nFlags( 0 );
3456 sal_Int32 nVal( 0 );
3457 if ( aSeq[2] >>= nFlags )
3459 SetTable ( ( nFlags & 0x01 ) != 0 );
3460 SetDist ( ( nFlags & 0x02 ) != 0 );
3461 SetMinDist( ( nFlags & 0x04 ) != 0 );
3463 else
3464 return false;
3465 if ( aSeq[3] >>= nFlags )
3466 mnValidFlags = static_cast<SvxBoxInfoItemValidFlags>(nFlags);
3467 else
3468 return false;
3469 if (( aSeq[4] >>= nVal ) && ( nVal >= 0 ))
3471 if( bConvert )
3472 nVal = o3tl::toTwips(nVal, o3tl::Length::mm100);
3473 SetDefDist( nVal );
3476 return true;
3479 case MID_HORIZONTAL:
3480 case MID_VERTICAL:
3482 if( !rVal.hasValue() )
3483 return false;
3485 table::BorderLine2 aBorderLine;
3486 if( lcl_extractBorderLine(rVal, aBorderLine) )
3488 // usual struct
3490 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
3492 // serialization for basic macro recording
3493 uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(::comphelper::getProcessComponentContext()) );
3494 uno::Any aNew;
3495 uno::Sequence < uno::Any > aSeq;
3496 try { aNew = xConverter->convertTo( rVal, cppu::UnoType<uno::Sequence < uno::Any >>::get() ); }
3497 catch (const uno::Exception&) {}
3499 if ((aNew >>= aSeq) &&
3500 aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
3502 sal_Int32 nVal = 0;
3503 if ( aSeq[0] >>= nVal )
3504 aBorderLine.Color = nVal;
3505 if ( aSeq[1] >>= nVal )
3506 aBorderLine.InnerLineWidth = static_cast<sal_Int16>(nVal);
3507 if ( aSeq[2] >>= nVal )
3508 aBorderLine.OuterLineWidth = static_cast<sal_Int16>(nVal);
3509 if ( aSeq[3] >>= nVal )
3510 aBorderLine.LineDistance = static_cast<sal_Int16>(nVal);
3511 if (aSeq.getLength() >= 5) // fdo#40874 added fields
3513 if (aSeq[4] >>= nVal)
3515 aBorderLine.LineStyle = nVal;
3517 if (aSeq.getLength() >= 6)
3519 if (aSeq[5] >>= nVal)
3521 aBorderLine.LineWidth = nVal;
3526 else
3527 return false;
3529 else if (rVal.getValueType() == cppu::UnoType<css::uno::Sequence < sal_Int16 >>::get() )
3531 // serialization for basic macro recording
3532 css::uno::Sequence < sal_Int16 > aSeq;
3533 rVal >>= aSeq;
3534 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
3536 aBorderLine.Color = aSeq[0];
3537 aBorderLine.InnerLineWidth = aSeq[1];
3538 aBorderLine.OuterLineWidth = aSeq[2];
3539 aBorderLine.LineDistance = aSeq[3];
3540 if (aSeq.getLength() >= 5) // fdo#40874 added fields
3542 aBorderLine.LineStyle = aSeq[4];
3543 if (aSeq.getLength() >= 6)
3545 aBorderLine.LineWidth = aSeq[5];
3549 else
3550 return false;
3552 else
3553 return false;
3555 SvxBorderLine aLine;
3556 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
3557 if ( bSet )
3558 SetLine( &aLine, nMemberId == MID_HORIZONTAL ? SvxBoxInfoItemLine::HORI : SvxBoxInfoItemLine::VERT );
3559 break;
3561 case MID_FLAGS:
3563 sal_Int16 nFlags = sal_Int16();
3564 bRet = (rVal >>= nFlags);
3565 if ( bRet )
3567 SetTable ( ( nFlags & 0x01 ) != 0 );
3568 SetDist ( ( nFlags & 0x02 ) != 0 );
3569 SetMinDist( ( nFlags & 0x04 ) != 0 );
3572 break;
3574 case MID_VALIDFLAGS:
3576 sal_Int16 nFlags = sal_Int16();
3577 bRet = (rVal >>= nFlags);
3578 if ( bRet )
3579 mnValidFlags = static_cast<SvxBoxInfoItemValidFlags>(nFlags);
3580 break;
3582 case MID_DISTANCE:
3584 sal_Int32 nVal = 0;
3585 bRet = (rVal >>= nVal);
3586 if ( bRet && nVal>=0 )
3588 if( bConvert )
3589 nVal = o3tl::toTwips(nVal, o3tl::Length::mm100);
3590 SetDefDist( static_cast<sal_uInt16>(nVal) );
3592 break;
3594 default: OSL_FAIL("Wrong MemberId!"); return false;
3597 return true;
3601 namespace editeng
3604 void BorderDistanceFromWord(bool bFromEdge, sal_Int32& nMargin, sal_Int32& nBorderDistance,
3605 sal_Int32 nBorderWidth)
3607 // See https://wiki.openoffice.org/wiki/Writer/MSInteroperability/PageBorder
3609 sal_Int32 nNewMargin = nMargin;
3610 sal_Int32 nNewBorderDistance = nBorderDistance;
3612 if (bFromEdge)
3614 nNewMargin = nBorderDistance;
3615 nNewBorderDistance = nMargin - nBorderDistance - nBorderWidth;
3617 else
3619 nNewMargin -= nBorderDistance + nBorderWidth;
3622 // Ensure correct distance from page edge to text in cases not supported by us:
3623 // when border is outside entire page area (!bFromEdge && BorderDistance > Margin),
3624 // and when border is inside page body area (bFromEdge && BorderDistance > Margin)
3625 if (nNewMargin < 0)
3627 nNewMargin = 0;
3628 nNewBorderDistance = std::max<sal_Int32>(nMargin - nBorderWidth, 0);
3630 else if (nNewBorderDistance < 0)
3632 nNewMargin = nMargin;
3635 nMargin = nNewMargin;
3636 nBorderDistance = nNewBorderDistance;
3639 // Heuristics to decide if we need to use "from edge" offset of borders
3641 // There are two cases when we can safely use "from text" or "from edge" offset without distorting
3642 // border position (modulo rounding errors):
3643 // 1. When distance of all borders from text is no greater than 31 pt, we use "from text"
3644 // 2. Otherwise, if distance of all borders from edge is no greater than 31 pt, we use "from edge"
3645 // In all other cases, the position of borders would be distorted on export, because Word doesn't
3646 // support the offset of >31 pts (https://msdn.microsoft.com/en-us/library/ff533820), and we need
3647 // to decide which type of offset would provide less wrong result (i.e., the result would look
3648 // closer to original). Here, we just check sum of distances from text to borders, and if it is
3649 // less than sum of distances from borders to edges. The alternative would be to compare total areas
3650 // between text-and-borders and between borders-and-edges (taking into account different lengths of
3651 // borders, and visual impact of that).
3652 void BorderDistancesToWord(const SvxBoxItem& rBox, const WordPageMargins& rMargins,
3653 WordBorderDistances& rDistances)
3655 // Use signed sal_Int32 that can hold sal_uInt16, to prevent overflow at subtraction below
3656 const sal_Int32 nT = rBox.GetDistance(SvxBoxItemLine::TOP, /*bAllowNegative=*/true);
3657 const sal_Int32 nL = rBox.GetDistance(SvxBoxItemLine::LEFT, /*bAllowNegative=*/true);
3658 const sal_Int32 nB = rBox.GetDistance(SvxBoxItemLine::BOTTOM, /*bAllowNegative=*/true);
3659 const sal_Int32 nR = rBox.GetDistance(SvxBoxItemLine::RIGHT, /*bAllowNegative=*/true);
3661 // Only take into account existing borders
3662 const SvxBorderLine* pLnT = rBox.GetLine(SvxBoxItemLine::TOP);
3663 const SvxBorderLine* pLnL = rBox.GetLine(SvxBoxItemLine::LEFT);
3664 const SvxBorderLine* pLnB = rBox.GetLine(SvxBoxItemLine::BOTTOM);
3665 const SvxBorderLine* pLnR = rBox.GetLine(SvxBoxItemLine::RIGHT);
3667 // We need to take border widths into account
3668 const tools::Long nWidthT = pLnT ? pLnT->GetScaledWidth() : 0;
3669 const tools::Long nWidthL = pLnL ? pLnL->GetScaledWidth() : 0;
3670 const tools::Long nWidthB = pLnB ? pLnB->GetScaledWidth() : 0;
3671 const tools::Long nWidthR = pLnR ? pLnR->GetScaledWidth() : 0;
3673 // Resulting distances from text to borders
3674 const sal_Int32 nT2BT = pLnT ? nT : 0;
3675 const sal_Int32 nT2BL = pLnL ? nL : 0;
3676 const sal_Int32 nT2BB = pLnB ? nB : 0;
3677 const sal_Int32 nT2BR = pLnR ? nR : 0;
3679 // Resulting distances from edge to borders
3680 const sal_Int32 nE2BT = pLnT ? std::max<sal_Int32>(rMargins.nTop - nT - nWidthT, 0) : 0;
3681 const sal_Int32 nE2BL = pLnL ? std::max<sal_Int32>(rMargins.nLeft - nL - nWidthL, 0) : 0;
3682 const sal_Int32 nE2BB = pLnB ? std::max<sal_Int32>(rMargins.nBottom - nB - nWidthB, 0) : 0;
3683 const sal_Int32 nE2BR = pLnR ? std::max<sal_Int32>(rMargins.nRight - nR - nWidthR, 0) : 0;
3685 const sal_Int32 n32pt = 32 * 20;
3686 // 1. If all borders are in range of 31 pts from text
3687 if (nT2BT >= 0 && nT2BT < n32pt && nT2BL >= 0 && nT2BL < n32pt && nT2BB >= 0 && nT2BB < n32pt && nT2BR >= 0 && nT2BR < n32pt)
3689 rDistances.bFromEdge = false;
3691 else
3693 // 2. If all borders are in range of 31 pts from edge
3694 if (nE2BT < n32pt && nE2BL < n32pt && nE2BB < n32pt && nE2BR < n32pt)
3696 rDistances.bFromEdge = true;
3698 else
3700 // Let's try to guess which would be the best approximation
3701 rDistances.bFromEdge =
3702 (nT2BT + nT2BL + nT2BB + nT2BR) > (nE2BT + nE2BL + nE2BB + nE2BR);
3706 if (rDistances.bFromEdge)
3708 rDistances.nTop = sal::static_int_cast<sal_uInt16>(nE2BT);
3709 rDistances.nLeft = sal::static_int_cast<sal_uInt16>(nE2BL);
3710 rDistances.nBottom = sal::static_int_cast<sal_uInt16>(nE2BB);
3711 rDistances.nRight = sal::static_int_cast<sal_uInt16>(nE2BR);
3713 else
3715 rDistances.nTop = sal::static_int_cast<sal_uInt16>(nT2BT);
3716 rDistances.nLeft = sal::static_int_cast<sal_uInt16>(nT2BL);
3717 rDistances.nBottom = sal::static_int_cast<sal_uInt16>(nT2BB);
3718 rDistances.nRight = sal::static_int_cast<sal_uInt16>(nT2BR);
3724 // class SvxFormatBreakItem -------------------------------------------------
3726 bool SvxFormatBreakItem::operator==( const SfxPoolItem& rAttr ) const
3728 assert(SfxPoolItem::operator==(rAttr));
3730 return GetValue() == static_cast<const SvxFormatBreakItem&>( rAttr ).GetValue();
3734 bool SvxFormatBreakItem::GetPresentation
3736 SfxItemPresentation /*ePres*/,
3737 MapUnit /*eCoreUnit*/,
3738 MapUnit /*ePresUnit*/,
3739 OUString& rText, const IntlWrapper&
3740 ) const
3742 rText = GetValueTextByPos( GetEnumValue() );
3743 return true;
3746 OUString SvxFormatBreakItem::GetValueTextByPos( sal_uInt16 nPos )
3748 static TranslateId RID_SVXITEMS_BREAK[] =
3750 RID_SVXITEMS_BREAK_NONE,
3751 RID_SVXITEMS_BREAK_COLUMN_BEFORE,
3752 RID_SVXITEMS_BREAK_COLUMN_AFTER,
3753 RID_SVXITEMS_BREAK_COLUMN_BOTH,
3754 RID_SVXITEMS_BREAK_PAGE_BEFORE,
3755 RID_SVXITEMS_BREAK_PAGE_AFTER,
3756 RID_SVXITEMS_BREAK_PAGE_BOTH
3758 static_assert(std::size(RID_SVXITEMS_BREAK) == size_t(SvxBreak::End), "unexpected size");
3759 assert(nPos < sal_uInt16(SvxBreak::End) && "enum overflow!");
3760 return EditResId(RID_SVXITEMS_BREAK[nPos]);
3763 bool SvxFormatBreakItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
3765 style::BreakType eBreak = style::BreakType_NONE;
3766 switch ( GetBreak() )
3768 case SvxBreak::ColumnBefore: eBreak = style::BreakType_COLUMN_BEFORE; break;
3769 case SvxBreak::ColumnAfter: eBreak = style::BreakType_COLUMN_AFTER ; break;
3770 case SvxBreak::ColumnBoth: eBreak = style::BreakType_COLUMN_BOTH ; break;
3771 case SvxBreak::PageBefore: eBreak = style::BreakType_PAGE_BEFORE ; break;
3772 case SvxBreak::PageAfter: eBreak = style::BreakType_PAGE_AFTER ; break;
3773 case SvxBreak::PageBoth: eBreak = style::BreakType_PAGE_BOTH ; break;
3774 default: ; // prevent warning
3776 rVal <<= eBreak;
3777 return true;
3780 bool SvxFormatBreakItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
3782 style::BreakType nBreak;
3784 if(!(rVal >>= nBreak))
3786 sal_Int32 nValue = 0;
3787 if(!(rVal >>= nValue))
3788 return false;
3790 nBreak = static_cast<style::BreakType>(nValue);
3793 SvxBreak eBreak = SvxBreak::NONE;
3794 switch( nBreak )
3796 case style::BreakType_COLUMN_BEFORE: eBreak = SvxBreak::ColumnBefore; break;
3797 case style::BreakType_COLUMN_AFTER: eBreak = SvxBreak::ColumnAfter; break;
3798 case style::BreakType_COLUMN_BOTH: eBreak = SvxBreak::ColumnBoth; break;
3799 case style::BreakType_PAGE_BEFORE: eBreak = SvxBreak::PageBefore; break;
3800 case style::BreakType_PAGE_AFTER: eBreak = SvxBreak::PageAfter; break;
3801 case style::BreakType_PAGE_BOTH: eBreak = SvxBreak::PageBoth; break;
3802 default: ; // prevent warning
3804 SetValue(eBreak);
3806 return true;
3809 SvxFormatBreakItem* SvxFormatBreakItem::Clone( SfxItemPool* ) const
3811 return new SvxFormatBreakItem( *this );
3814 sal_uInt16 SvxFormatBreakItem::GetValueCount() const
3816 return sal_uInt16(SvxBreak::End); // SvxBreak::PageBoth + 1
3819 SvxFormatKeepItem* SvxFormatKeepItem::Clone( SfxItemPool* ) const
3821 return new SvxFormatKeepItem( *this );
3824 bool SvxFormatKeepItem::GetPresentation
3826 SfxItemPresentation /*ePres*/,
3827 MapUnit /*eCoreUnit*/,
3828 MapUnit /*ePresUnit*/,
3829 OUString& rText, const IntlWrapper&
3830 ) const
3832 TranslateId pId = RID_SVXITEMS_FMTKEEP_FALSE;
3834 if ( GetValue() )
3835 pId = RID_SVXITEMS_FMTKEEP_TRUE;
3836 rText = EditResId(pId);
3837 return true;
3840 void SvxFormatKeepItem::dumpAsXml(xmlTextWriterPtr pWriter) const
3842 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFormatKeepItem"));
3844 SfxBoolItem::dumpAsXml(pWriter);
3846 (void)xmlTextWriterEndElement(pWriter);
3849 SvxLineItem::SvxLineItem( const sal_uInt16 nId ) :
3850 SfxPoolItem ( nId )
3855 SvxLineItem::SvxLineItem( const SvxLineItem& rCpy ) :
3856 SfxPoolItem ( rCpy ),
3857 pLine(rCpy.pLine ? new SvxBorderLine( *rCpy.pLine ) : nullptr)
3862 SvxLineItem::~SvxLineItem()
3867 bool SvxLineItem::operator==( const SfxPoolItem& rAttr ) const
3869 assert(SfxPoolItem::operator==(rAttr));
3871 return CompareBorderLine(pLine, static_cast<const SvxLineItem&>(rAttr).GetLine());
3874 SvxLineItem* SvxLineItem::Clone( SfxItemPool* ) const
3876 return new SvxLineItem( *this );
3879 bool SvxLineItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemId ) const
3881 bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3882 nMemId &= ~CONVERT_TWIPS;
3883 if ( nMemId == 0 )
3885 rVal <<= SvxBoxItem::SvxLineToLine(pLine.get(), bConvert);
3886 return true;
3888 else if ( pLine )
3890 switch ( nMemId )
3892 case MID_FG_COLOR: rVal <<= pLine->GetColor(); break;
3893 case MID_OUTER_WIDTH: rVal <<= sal_Int32(pLine->GetOutWidth()); break;
3894 case MID_INNER_WIDTH: rVal <<= sal_Int32(pLine->GetInWidth( )); break;
3895 case MID_DISTANCE: rVal <<= sal_Int32(pLine->GetDistance()); break;
3896 default:
3897 OSL_FAIL( "Wrong MemberId" );
3898 return false;
3902 return true;
3906 bool SvxLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemId )
3908 bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3909 nMemId &= ~CONVERT_TWIPS;
3910 sal_Int32 nVal = 0;
3911 if ( nMemId == 0 )
3913 table::BorderLine2 aLine;
3914 if ( lcl_extractBorderLine(rVal, aLine) )
3916 if ( !pLine )
3917 pLine.reset( new SvxBorderLine );
3918 if( !SvxBoxItem::LineToSvxLine(aLine, *pLine, bConvert) )
3919 pLine.reset();
3920 return true;
3922 return false;
3924 else if ( rVal >>= nVal )
3926 if ( !pLine )
3927 pLine.reset( new SvxBorderLine );
3929 switch ( nMemId )
3931 case MID_FG_COLOR: pLine->SetColor( Color(ColorTransparency, nVal) ); break;
3932 case MID_LINE_STYLE:
3933 pLine->SetBorderLineStyle(static_cast<SvxBorderLineStyle>(nVal));
3934 break;
3935 default:
3936 OSL_FAIL( "Wrong MemberId" );
3937 return false;
3940 return true;
3943 return false;
3947 bool SvxLineItem::GetPresentation
3949 SfxItemPresentation ePres,
3950 MapUnit eCoreUnit,
3951 MapUnit ePresUnit,
3952 OUString& rText, const IntlWrapper& rIntl
3953 ) const
3955 rText.clear();
3957 if ( pLine )
3958 rText = pLine->GetValueString( eCoreUnit, ePresUnit, &rIntl,
3959 (SfxItemPresentation::Complete == ePres) );
3960 return true;
3964 void SvxLineItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
3966 if ( pLine ) pLine->ScaleMetrics( nMult, nDiv );
3970 bool SvxLineItem::HasMetrics() const
3972 return true;
3976 void SvxLineItem::SetLine( const SvxBorderLine* pNew )
3978 pLine.reset( pNew ? new SvxBorderLine( *pNew ) : nullptr );
3981 SvxBrushItem::SvxBrushItem(sal_uInt16 _nWhich)
3982 : SfxPoolItem(_nWhich)
3983 , aColor(COL_TRANSPARENT)
3984 , aFilterColor(COL_TRANSPARENT)
3985 , nShadingValue(ShadingPattern::CLEAR)
3986 , nGraphicTransparency(0)
3987 , eGraphicPos(GPOS_NONE)
3988 , bLoadAgain(true)
3992 SvxBrushItem::SvxBrushItem(const Color& rColor, sal_uInt16 _nWhich)
3993 : SfxPoolItem(_nWhich)
3994 , aColor(rColor)
3995 , aFilterColor(COL_TRANSPARENT)
3996 , nShadingValue(ShadingPattern::CLEAR)
3997 , nGraphicTransparency(0)
3998 , eGraphicPos(GPOS_NONE)
3999 , bLoadAgain(true)
4003 SvxBrushItem::SvxBrushItem(Color const& rColor, model::ComplexColor const& rComplexColor, sal_uInt16 nWhich)
4004 : SfxPoolItem(nWhich)
4005 , aColor(rColor)
4006 , maComplexColor(rComplexColor)
4007 , aFilterColor(COL_TRANSPARENT)
4008 , nShadingValue(ShadingPattern::CLEAR)
4009 , nGraphicTransparency(0)
4010 , eGraphicPos(GPOS_NONE)
4011 , bLoadAgain(true)
4015 SvxBrushItem::SvxBrushItem(const Graphic& rGraphic, SvxGraphicPosition ePos, sal_uInt16 _nWhich)
4016 : SfxPoolItem(_nWhich)
4017 , aColor(COL_TRANSPARENT)
4018 , aFilterColor(COL_TRANSPARENT)
4019 , nShadingValue(ShadingPattern::CLEAR)
4020 , xGraphicObject(new GraphicObject(rGraphic))
4021 , nGraphicTransparency(0)
4022 , eGraphicPos((GPOS_NONE != ePos) ? ePos : GPOS_MM)
4023 , bLoadAgain(true)
4025 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
4028 SvxBrushItem::SvxBrushItem(const GraphicObject& rGraphicObj, SvxGraphicPosition ePos, sal_uInt16 _nWhich)
4029 : SfxPoolItem(_nWhich)
4030 , aColor(COL_TRANSPARENT)
4031 , aFilterColor(COL_TRANSPARENT)
4032 , nShadingValue(ShadingPattern::CLEAR)
4033 , xGraphicObject(new GraphicObject(rGraphicObj))
4034 , nGraphicTransparency(0)
4035 , eGraphicPos((GPOS_NONE != ePos) ? ePos : GPOS_MM)
4036 , bLoadAgain(true)
4038 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
4041 SvxBrushItem::SvxBrushItem(OUString aLink, OUString aFilter,
4042 SvxGraphicPosition ePos, sal_uInt16 _nWhich)
4043 : SfxPoolItem(_nWhich)
4044 , aColor(COL_TRANSPARENT)
4045 , aFilterColor(COL_TRANSPARENT)
4046 , nShadingValue(ShadingPattern::CLEAR)
4047 , nGraphicTransparency(0)
4048 , maStrLink(std::move(aLink))
4049 , maStrFilter(std::move(aFilter))
4050 , eGraphicPos((GPOS_NONE != ePos) ? ePos : GPOS_MM)
4051 , bLoadAgain(true)
4053 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
4056 SvxBrushItem::SvxBrushItem(const SvxBrushItem& rItem)
4057 : SfxPoolItem(rItem)
4058 , aColor(rItem.aColor)
4059 , maComplexColor(rItem.maComplexColor)
4060 , aFilterColor(rItem.aFilterColor)
4061 , nShadingValue(rItem.nShadingValue)
4062 , xGraphicObject(rItem.xGraphicObject ? new GraphicObject(*rItem.xGraphicObject) : nullptr)
4063 , nGraphicTransparency(rItem.nGraphicTransparency)
4064 , maStrLink(rItem.maStrLink)
4065 , maStrFilter(rItem.maStrFilter)
4066 , eGraphicPos(rItem.eGraphicPos)
4067 , bLoadAgain(rItem.bLoadAgain)
4071 SvxBrushItem::SvxBrushItem(SvxBrushItem&& rItem)
4072 : SfxPoolItem(std::move(rItem))
4073 , aColor(std::move(rItem.aColor))
4074 , maComplexColor(std::move(rItem.maComplexColor))
4075 , aFilterColor(std::move(rItem.aFilterColor))
4076 , nShadingValue(std::move(rItem.nShadingValue))
4077 , xGraphicObject(std::move(rItem.xGraphicObject))
4078 , nGraphicTransparency(std::move(rItem.nGraphicTransparency))
4079 , maStrLink(std::move(rItem.maStrLink))
4080 , maStrFilter(std::move(rItem.maStrFilter))
4081 , eGraphicPos(std::move(rItem.eGraphicPos))
4082 , bLoadAgain(std::move(rItem.bLoadAgain))
4086 SvxBrushItem::~SvxBrushItem()
4090 bool SvxBrushItem::isUsed() const
4092 if (GPOS_NONE != GetGraphicPos())
4094 // graphic used
4095 return true;
4097 else if (!GetColor().IsFullyTransparent())
4099 // color used
4100 return true;
4103 return false;
4107 static sal_Int8 lcl_PercentToTransparency(tools::Long nPercent)
4109 // 0xff must not be returned!
4110 return sal_Int8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
4114 sal_Int8 SvxBrushItem::TransparencyToPercent(sal_Int32 nTrans)
4116 return static_cast<sal_Int8>((nTrans * 100 + 127) / 254);
4120 bool SvxBrushItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
4122 nMemberId &= ~CONVERT_TWIPS;
4123 switch( nMemberId)
4125 case MID_BACK_COLOR:
4126 rVal <<= aColor;
4127 break;
4128 case MID_BACK_COLOR_R_G_B:
4129 rVal <<= aColor.GetRGBColor();
4130 break;
4131 case MID_BACK_COLOR_TRANSPARENCY:
4132 rVal <<= SvxBrushItem::TransparencyToPercent(255 - aColor.GetAlpha());
4133 break;
4135 case MID_BACKGROUND_COMPLEX_COLOR:
4137 auto xComplexColor = model::color::createXComplexColor(maComplexColor);
4138 rVal <<= xComplexColor;
4139 break;
4141 break;
4143 case MID_GRAPHIC_POSITION:
4144 rVal <<= static_cast<style::GraphicLocation>(static_cast<sal_Int16>(eGraphicPos));
4145 break;
4147 case MID_GRAPHIC_TRANSPARENT:
4148 rVal <<= ( aColor.GetAlpha() == 0 );
4149 break;
4151 case MID_GRAPHIC_URL:
4152 case MID_GRAPHIC:
4154 uno::Reference<graphic::XGraphic> xGraphic;
4155 if (!maStrLink.isEmpty())
4157 Graphic aGraphic(vcl::graphic::loadFromURL(maStrLink));
4158 xGraphic = aGraphic.GetXGraphic();
4160 else if (xGraphicObject)
4162 xGraphic = xGraphicObject->GetGraphic().GetXGraphic();
4164 rVal <<= xGraphic;
4166 break;
4168 case MID_GRAPHIC_FILTER:
4170 rVal <<= maStrFilter;
4172 break;
4174 case MID_GRAPHIC_TRANSPARENCY:
4175 rVal <<= nGraphicTransparency;
4176 break;
4178 case MID_SHADING_VALUE:
4180 rVal <<= nShadingValue;
4182 break;
4185 return true;
4189 bool SvxBrushItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
4191 nMemberId &= ~CONVERT_TWIPS;
4192 switch( nMemberId)
4194 case MID_BACK_COLOR:
4195 case MID_BACK_COLOR_R_G_B:
4197 Color aNewCol;
4198 if ( !( rVal >>= aNewCol ) )
4199 return false;
4200 if(MID_BACK_COLOR_R_G_B == nMemberId)
4202 aNewCol.SetAlpha(aColor.GetAlpha());
4204 aColor = aNewCol;
4206 break;
4207 case MID_BACK_COLOR_TRANSPARENCY:
4209 sal_Int32 nTrans = 0;
4210 if ( !( rVal >>= nTrans ) || nTrans < 0 || nTrans > 100 )
4211 return false;
4212 aColor.SetAlpha(255 - lcl_PercentToTransparency(nTrans));
4214 break;
4216 case MID_BACKGROUND_COMPLEX_COLOR:
4218 css::uno::Reference<css::util::XComplexColor> xComplexColor;
4219 if (!(rVal >>= xComplexColor))
4220 return false;
4222 if (xComplexColor.is())
4223 maComplexColor = model::color::getFromXComplexColor(xComplexColor);
4225 break;
4227 case MID_GRAPHIC_POSITION:
4229 style::GraphicLocation eLocation;
4230 if ( !( rVal>>=eLocation ) )
4232 sal_Int32 nValue = 0;
4233 if ( !( rVal >>= nValue ) )
4234 return false;
4235 eLocation = static_cast<style::GraphicLocation>(nValue);
4237 SetGraphicPos( static_cast<SvxGraphicPosition>(static_cast<sal_uInt16>(eLocation)) );
4239 break;
4241 case MID_GRAPHIC_TRANSPARENT:
4242 aColor.SetAlpha( Any2Bool( rVal ) ? 0 : 255 );
4243 break;
4245 case MID_GRAPHIC_URL:
4246 case MID_GRAPHIC:
4248 Graphic aGraphic;
4250 if (rVal.getValueType() == ::cppu::UnoType<OUString>::get())
4252 OUString aURL = rVal.get<OUString>();
4253 aGraphic = vcl::graphic::loadFromURL(aURL);
4255 else if (rVal.getValueType() == cppu::UnoType<graphic::XGraphic>::get())
4257 auto xGraphic = rVal.get<uno::Reference<graphic::XGraphic>>();
4258 aGraphic = Graphic(xGraphic);
4261 if (!aGraphic.IsNone())
4263 maStrLink.clear();
4265 std::unique_ptr<GraphicObject> xOldGrfObj(std::move(xGraphicObject));
4266 xGraphicObject.reset(new GraphicObject(aGraphic));
4267 ApplyGraphicTransparency_Impl();
4268 xOldGrfObj.reset();
4270 if (!aGraphic.IsNone() && eGraphicPos == GPOS_NONE)
4272 eGraphicPos = GPOS_MM;
4274 else if (aGraphic.IsNone())
4276 eGraphicPos = GPOS_NONE;
4280 break;
4282 case MID_GRAPHIC_FILTER:
4284 if( rVal.getValueType() == ::cppu::UnoType<OUString>::get() )
4286 OUString sLink;
4287 rVal >>= sLink;
4288 SetGraphicFilter( sLink );
4291 break;
4292 case MID_GRAPHIC_TRANSPARENCY :
4294 sal_Int32 nTmp = 0;
4295 rVal >>= nTmp;
4296 if(nTmp >= 0 && nTmp <= 100)
4298 nGraphicTransparency = sal_Int8(nTmp);
4299 if (xGraphicObject)
4300 ApplyGraphicTransparency_Impl();
4303 break;
4305 case MID_SHADING_VALUE:
4307 sal_Int32 nVal = 0;
4308 if (!(rVal >>= nVal))
4309 return false;
4311 nShadingValue = nVal;
4313 break;
4316 return true;
4320 bool SvxBrushItem::GetPresentation
4322 SfxItemPresentation /*ePres*/,
4323 MapUnit /*eCoreUnit*/,
4324 MapUnit /*ePresUnit*/,
4325 OUString& rText, const IntlWrapper&
4326 ) const
4328 if ( GPOS_NONE == eGraphicPos )
4330 rText = ::GetColorString( aColor ) + cpDelim;
4331 TranslateId pId = RID_SVXITEMS_TRANSPARENT_FALSE;
4333 if ( aColor.IsTransparent() )
4334 pId = RID_SVXITEMS_TRANSPARENT_TRUE;
4335 rText += EditResId(pId);
4337 else
4339 rText = EditResId(RID_SVXITEMS_GRAPHIC);
4342 return true;
4345 bool SvxBrushItem::operator==( const SfxPoolItem& rAttr ) const
4347 assert(SfxPoolItem::operator==(rAttr));
4349 const SvxBrushItem& rCmp = static_cast<const SvxBrushItem&>(rAttr);
4350 bool bEqual =
4351 aColor == rCmp.aColor &&
4352 maComplexColor == rCmp.maComplexColor &&
4353 aFilterColor == rCmp.aFilterColor &&
4354 eGraphicPos == rCmp.eGraphicPos &&
4355 nGraphicTransparency == rCmp.nGraphicTransparency;
4357 if ( bEqual )
4359 if ( GPOS_NONE != eGraphicPos )
4361 bEqual = maStrLink == rCmp.maStrLink;
4363 if ( bEqual )
4365 bEqual = maStrFilter == rCmp.maStrFilter;
4368 if ( bEqual )
4370 if (!rCmp.xGraphicObject)
4371 bEqual = !xGraphicObject;
4372 else
4373 bEqual = xGraphicObject &&
4374 (*xGraphicObject == *rCmp.xGraphicObject);
4378 if (bEqual)
4380 bEqual = nShadingValue == rCmp.nShadingValue;
4384 return bEqual;
4387 SvxBrushItem* SvxBrushItem::Clone( SfxItemPool* ) const
4389 return new SvxBrushItem( *this );
4392 const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) const
4394 if (bLoadAgain && !maStrLink.isEmpty() && !xGraphicObject)
4395 // when graphics already loaded, use as a cache
4397 if (SvtSecurityOptions::isUntrustedReferer(referer)) {
4398 return nullptr;
4401 // tdf#94088 prepare graphic and state
4402 Graphic aGraphic;
4403 bool bGraphicLoaded = false;
4405 // try to create stream directly from given URL
4406 std::unique_ptr<SvStream> xStream(utl::UcbStreamHelper::CreateStream(maStrLink, StreamMode::STD_READ));
4407 // tdf#94088 if we have a stream, try to load it directly as graphic
4408 if (xStream && !xStream->GetError())
4410 if (ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, maStrLink, *xStream,
4411 GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg))
4413 bGraphicLoaded = true;
4417 // tdf#94088 if no succeeded, try if the string (which is not empty) contains
4418 // a 'data:' scheme url and try to load that (embedded graphics)
4419 if(!bGraphicLoaded)
4421 INetURLObject aGraphicURL( maStrLink );
4423 if( INetProtocol::Data == aGraphicURL.GetProtocol() )
4425 std::unique_ptr<SvMemoryStream> const xMemStream(aGraphicURL.getData());
4426 if (xMemStream)
4428 if (ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, u"", *xMemStream))
4430 bGraphicLoaded = true;
4432 // tdf#94088 delete the no longer needed data scheme URL which
4433 // is potentially pretty // large, containing a base64 encoded copy of the graphic
4434 const_cast< SvxBrushItem* >(this)->maStrLink.clear();
4440 // tdf#94088 when we got a graphic, set it
4441 if(bGraphicLoaded && GraphicType::NONE != aGraphic.GetType())
4443 xGraphicObject.reset(new GraphicObject);
4444 xGraphicObject->SetGraphic(aGraphic);
4445 const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl();
4447 else
4449 bLoadAgain = false;
4453 return xGraphicObject.get();
4456 void SvxBrushItem::setGraphicTransparency(sal_Int8 nNew)
4458 if (nNew != nGraphicTransparency)
4460 nGraphicTransparency = nNew;
4461 ApplyGraphicTransparency_Impl();
4465 const Graphic* SvxBrushItem::GetGraphic(OUString const & referer) const
4467 const GraphicObject* pGrafObj = GetGraphicObject(referer);
4468 return( pGrafObj ? &( pGrafObj->GetGraphic() ) : nullptr );
4471 void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew )
4473 eGraphicPos = eNew;
4475 if ( GPOS_NONE == eGraphicPos )
4477 xGraphicObject.reset();
4478 maStrLink.clear();
4479 maStrFilter.clear();
4481 else
4483 if (!xGraphicObject && maStrLink.isEmpty())
4485 xGraphicObject.reset(new GraphicObject); // Creating a dummy
4490 void SvxBrushItem::SetGraphic( const Graphic& rNew )
4492 if ( maStrLink.isEmpty() )
4494 if (xGraphicObject)
4495 xGraphicObject->SetGraphic(rNew);
4496 else
4497 xGraphicObject.reset(new GraphicObject(rNew));
4499 ApplyGraphicTransparency_Impl();
4501 if ( GPOS_NONE == eGraphicPos )
4502 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4504 else
4506 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4510 void SvxBrushItem::SetGraphicObject( const GraphicObject& rNewObj )
4512 if ( maStrLink.isEmpty() )
4514 if (xGraphicObject)
4515 *xGraphicObject = rNewObj;
4516 else
4517 xGraphicObject.reset(new GraphicObject(rNewObj));
4519 ApplyGraphicTransparency_Impl();
4521 if ( GPOS_NONE == eGraphicPos )
4522 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4524 else
4526 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4530 void SvxBrushItem::SetGraphicLink( const OUString& rNew )
4532 if ( rNew.isEmpty() )
4533 maStrLink.clear();
4534 else
4536 maStrLink = rNew;
4537 xGraphicObject.reset();
4541 void SvxBrushItem::SetGraphicFilter( const OUString& rNew )
4543 maStrFilter = rNew;
4546 void SvxBrushItem::ApplyGraphicTransparency_Impl()
4548 DBG_ASSERT(xGraphicObject, "no GraphicObject available" );
4549 if (xGraphicObject)
4551 GraphicAttr aAttr(xGraphicObject->GetAttr());
4552 aAttr.SetAlpha(255 - lcl_PercentToTransparency(
4553 nGraphicTransparency));
4554 xGraphicObject->SetAttr(aAttr);
4558 void SvxBrushItem::dumpAsXml(xmlTextWriterPtr pWriter) const
4560 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxBrushItem"));
4561 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
4562 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("color"), BAD_CAST(aColor.AsRGBHexString().toUtf8().getStr()));
4563 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("filtercolor"), BAD_CAST(aFilterColor.AsRGBHexString().toUtf8().getStr()));
4564 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("shadingValue"), BAD_CAST(OString::number(nShadingValue).getStr()));
4565 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("link"), BAD_CAST(maStrLink.toUtf8().getStr()));
4566 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("filter"), BAD_CAST(maStrFilter.toUtf8().getStr()));
4567 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("graphicPos"), BAD_CAST(OString::number(eGraphicPos).getStr()));
4568 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("loadAgain"), BAD_CAST(OString::boolean(bLoadAgain).getStr()));
4569 (void)xmlTextWriterEndElement(pWriter);
4573 SvxFrameDirectionItem::SvxFrameDirectionItem( SvxFrameDirection nValue ,
4574 sal_uInt16 _nWhich )
4575 : SfxEnumItem<SvxFrameDirection>( _nWhich, nValue )
4580 SvxFrameDirectionItem::~SvxFrameDirectionItem()
4584 SvxFrameDirectionItem* SvxFrameDirectionItem::Clone( SfxItemPool * ) const
4586 return new SvxFrameDirectionItem( *this );
4589 TranslateId getFrmDirResId(size_t nIndex)
4591 TranslateId const RID_SVXITEMS_FRMDIR[] =
4593 RID_SVXITEMS_FRMDIR_HORI_LEFT_TOP,
4594 RID_SVXITEMS_FRMDIR_HORI_RIGHT_TOP,
4595 RID_SVXITEMS_FRMDIR_VERT_TOP_RIGHT,
4596 RID_SVXITEMS_FRMDIR_VERT_TOP_LEFT,
4597 RID_SVXITEMS_FRMDIR_ENVIRONMENT,
4598 RID_SVXITEMS_FRMDIR_VERT_BOT_LEFT,
4599 RID_SVXITEMS_FRMDIR_VERT_TOP_RIGHT90
4601 return RID_SVXITEMS_FRMDIR[nIndex];
4604 bool SvxFrameDirectionItem::GetPresentation(
4605 SfxItemPresentation /*ePres*/,
4606 MapUnit /*eCoreUnit*/,
4607 MapUnit /*ePresUnit*/,
4608 OUString& rText, const IntlWrapper&) const
4610 rText = EditResId(getFrmDirResId(GetEnumValue()));
4611 return true;
4614 bool SvxFrameDirectionItem::PutValue( const css::uno::Any& rVal,
4615 sal_uInt8 )
4617 sal_Int16 nVal = sal_Int16();
4618 bool bRet = ( rVal >>= nVal );
4619 if( bRet )
4621 // translate WritingDirection2 constants into SvxFrameDirection
4622 switch( nVal )
4624 case text::WritingMode2::LR_TB:
4625 SetValue( SvxFrameDirection::Horizontal_LR_TB );
4626 break;
4627 case text::WritingMode2::RL_TB:
4628 SetValue( SvxFrameDirection::Horizontal_RL_TB );
4629 break;
4630 case text::WritingMode2::TB_RL:
4631 SetValue( SvxFrameDirection::Vertical_RL_TB );
4632 break;
4633 case text::WritingMode2::TB_LR:
4634 SetValue( SvxFrameDirection::Vertical_LR_TB );
4635 break;
4636 case text::WritingMode2::BT_LR:
4637 SetValue( SvxFrameDirection::Vertical_LR_BT );
4638 break;
4639 case text::WritingMode2::TB_RL90:
4640 SetValue(SvxFrameDirection::Vertical_RL_TB90);
4641 break;
4642 case text::WritingMode2::PAGE:
4643 SetValue( SvxFrameDirection::Environment );
4644 break;
4645 default:
4646 bRet = false;
4647 break;
4651 return bRet;
4655 bool SvxFrameDirectionItem::QueryValue( css::uno::Any& rVal,
4656 sal_uInt8 ) const
4658 // translate SvxFrameDirection into WritingDirection2
4659 sal_Int16 nVal;
4660 bool bRet = true;
4661 switch( GetValue() )
4663 case SvxFrameDirection::Horizontal_LR_TB:
4664 nVal = text::WritingMode2::LR_TB;
4665 break;
4666 case SvxFrameDirection::Horizontal_RL_TB:
4667 nVal = text::WritingMode2::RL_TB;
4668 break;
4669 case SvxFrameDirection::Vertical_RL_TB:
4670 nVal = text::WritingMode2::TB_RL;
4671 break;
4672 case SvxFrameDirection::Vertical_LR_TB:
4673 nVal = text::WritingMode2::TB_LR;
4674 break;
4675 case SvxFrameDirection::Vertical_LR_BT:
4676 nVal = text::WritingMode2::BT_LR;
4677 break;
4678 case SvxFrameDirection::Vertical_RL_TB90:
4679 nVal = text::WritingMode2::TB_RL90;
4680 break;
4681 case SvxFrameDirection::Environment:
4682 nVal = text::WritingMode2::PAGE;
4683 break;
4684 default:
4685 OSL_FAIL("Unknown SvxFrameDirection value!");
4686 bRet = false;
4687 break;
4690 // return value + error state
4691 if( bRet )
4693 rVal <<= nVal;
4695 return bRet;
4698 void SvxFrameDirectionItem::dumpAsXml(xmlTextWriterPtr pWriter) const
4700 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFrameDirectionItem"));
4701 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nWhich"),
4702 BAD_CAST(OString::number(Which()).getStr()));
4703 (void)xmlTextWriterWriteAttribute(
4704 pWriter, BAD_CAST("m_nValue"),
4705 BAD_CAST(OString::number(static_cast<sal_Int16>(GetValue())).getStr()));
4706 (void)xmlTextWriterEndElement(pWriter);
4709 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */