1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http: // mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http: // www.apache.org/licenses/LICENSE-2.0 .
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/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/table/ShadowLocation.hpp>
26 #include <com/sun/star/table/TableBorder.hpp>
27 #include <com/sun/star/table/ShadowFormat.hpp>
28 #include <com/sun/star/table/CellRangeAddress.hpp>
29 #include <com/sun/star/table/CellContentType.hpp>
30 #include <com/sun/star/table/TableOrientation.hpp>
31 #include <com/sun/star/util/SortField.hpp>
32 #include <com/sun/star/util/SortFieldType.hpp>
33 #include <com/sun/star/table/BorderLine2.hpp>
34 #include <com/sun/star/table/BorderLineStyle.hpp>
35 #include <com/sun/star/table/CellOrientation.hpp>
36 #include <com/sun/star/table/CellAddress.hpp>
37 #include <com/sun/star/style/PageStyleLayout.hpp>
38 #include <com/sun/star/style/BreakType.hpp>
39 #include <com/sun/star/style/GraphicLocation.hpp>
40 #include <com/sun/star/awt/Rectangle.hpp>
41 #include <com/sun/star/awt/Selection.hpp>
42 #include <com/sun/star/awt/Size.hpp>
43 #include <com/sun/star/text/WritingMode2.hpp>
44 #include <com/sun/star/frame/status/UpperLowerMarginScale.hpp>
45 #include <com/sun/star/frame/status/LeftRightMarginScale.hpp>
46 #include <com/sun/star/drawing/ShadingPattern.hpp>
47 #include <com/sun/star/graphic/XGraphic.hpp>
49 #include <osl/diagnose.h>
50 #include <sal/log.hxx>
51 #include <i18nutil/unicode.hxx>
52 #include <unotools/ucbstreamhelper.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <vcl/GraphicObject.hxx>
56 #include <tools/urlobj.hxx>
57 #include <comphelper/fileformat.h>
58 #include <svl/memberid.h>
59 #include <svtools/borderhelper.hxx>
60 #include <rtl/ustring.hxx>
61 #include <rtl/ustrbuf.hxx>
62 #include <tools/mapunit.hxx>
63 #include <vcl/graphicfilter.hxx>
64 #include <vcl/settings.hxx>
65 #include <vcl/svapp.hxx>
66 #include <editeng/editids.hrc>
67 #include <editeng/editrids.hrc>
68 #include <editeng/pbinitem.hxx>
69 #include <editeng/sizeitem.hxx>
70 #include <editeng/lrspitem.hxx>
71 #include <editeng/ulspitem.hxx>
72 #include <editeng/prntitem.hxx>
73 #include <editeng/opaqitem.hxx>
74 #include <editeng/protitem.hxx>
75 #include <editeng/shaditem.hxx>
76 #include <editeng/borderline.hxx>
77 #include <editeng/boxitem.hxx>
78 #include <editeng/formatbreakitem.hxx>
79 #include <editeng/keepitem.hxx>
80 #include <editeng/lineitem.hxx>
81 #include <editeng/brushitem.hxx>
82 #include <editeng/frmdiritem.hxx>
83 #include <editeng/itemtype.hxx>
84 #include <editeng/eerdll.hxx>
85 #include <editeng/unoprnms.hxx>
86 #include <editeng/memberids.h>
87 #include <editeng/editerr.hxx>
88 #include <libxml/xmlwriter.h>
89 #include <o3tl/enumrange.hxx>
90 #include <o3tl/safeint.hxx>
91 #include <vcl/GraphicLoader.hxx>
93 using namespace ::editeng
;
94 using namespace ::com::sun::star
;
95 using namespace ::com::sun::star::drawing
;
96 using namespace ::com::sun::star::table::BorderLineStyle
;
99 SfxPoolItem
* SvxPaperBinItem::CreateDefault() { return new SvxPaperBinItem(0);}
100 SfxPoolItem
* SvxSizeItem::CreateDefault() { return new SvxSizeItem(0);}
101 SfxPoolItem
* SvxLRSpaceItem::CreateDefault() { return new SvxLRSpaceItem(0);}
102 SfxPoolItem
* SvxULSpaceItem::CreateDefault() { return new SvxULSpaceItem(0);}
103 SfxPoolItem
* SvxProtectItem::CreateDefault() { return new SvxProtectItem(0);}
104 SfxPoolItem
* SvxBrushItem::CreateDefault() { return new SvxBrushItem(0);}
105 SfxPoolItem
* SvxShadowItem::CreateDefault() { return new SvxShadowItem(0);}
106 SfxPoolItem
* SvxBoxItem::CreateDefault() { return new SvxBoxItem(0);}
107 SfxPoolItem
* SvxBoxInfoItem::CreateDefault() { return new SvxBoxInfoItem(0);}
108 SfxPoolItem
* SvxFormatBreakItem::CreateDefault() { return new SvxFormatBreakItem(SvxBreak::NONE
, 0);}
109 SfxPoolItem
* SvxFormatKeepItem::CreateDefault() { return new SvxFormatKeepItem(false, 0);}
110 SfxPoolItem
* SvxLineItem::CreateDefault() { return new SvxLineItem(0);}
113 SfxPoolItem
* SvxPaperBinItem::Clone( SfxItemPool
* ) const
115 return new SvxPaperBinItem( *this );
119 bool SvxPaperBinItem::GetPresentation
121 SfxItemPresentation ePres
,
122 MapUnit
/*eCoreUnit*/,
123 MapUnit
/*ePresUnit*/,
124 OUString
& rText
, const IntlWrapper
&
129 case SfxItemPresentation::Nameless
:
130 rText
= OUString::number( GetValue() );
133 case SfxItemPresentation::Complete
:
135 sal_uInt8 nValue
= GetValue();
137 if ( PAPERBIN_PRINTER_SETTINGS
== nValue
)
138 rText
= EditResId(RID_SVXSTR_PAPERBIN_SETTINGS
);
141 rText
= EditResId(RID_SVXSTR_PAPERBIN
) + " " + OUString::number( nValue
);
146 default: ; //prevent warning
153 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId
, const Size
& rSize
) :
162 bool SvxSizeItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
164 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
165 nMemberId
&= ~CONVERT_TWIPS
;
167 awt::Size
aTmp(m_aSize
.Width(), m_aSize
.Height());
170 aTmp
.Height
= convertTwipToMm100(aTmp
.Height
);
171 aTmp
.Width
= convertTwipToMm100(aTmp
.Width
);
176 case MID_SIZE_SIZE
: rVal
<<= aTmp
; break;
177 case MID_SIZE_WIDTH
: rVal
<<= aTmp
.Width
; break;
178 case MID_SIZE_HEIGHT
: rVal
<<= aTmp
.Height
; break;
179 default: OSL_FAIL("Wrong MemberId!"); return false;
186 bool SvxSizeItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
188 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
189 nMemberId
&= ~CONVERT_TWIPS
;
200 aTmp
.Height
= convertMm100ToTwip(aTmp
.Height
);
201 aTmp
.Width
= convertMm100ToTwip(aTmp
.Width
);
203 m_aSize
= Size( aTmp
.Width
, aTmp
.Height
);
214 if(!(rVal
>>= nVal
))
217 m_aSize
.setWidth( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
220 case MID_SIZE_HEIGHT
:
226 m_aSize
.setHeight( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
229 default: OSL_FAIL("Wrong MemberId!");
236 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId
) :
243 bool SvxSizeItem::operator==( const SfxPoolItem
& rAttr
) const
245 assert(SfxPoolItem::operator==(rAttr
));
247 return ( m_aSize
== static_cast<const SvxSizeItem
&>( rAttr
).GetSize() );
251 SfxPoolItem
* SvxSizeItem::Clone( SfxItemPool
* ) const
253 return new SvxSizeItem( *this );
257 bool SvxSizeItem::GetPresentation
259 SfxItemPresentation ePres
,
262 OUString
& rText
, const IntlWrapper
& rIntl
265 OUString
cpDelimTmp(cpDelim
);
268 case SfxItemPresentation::Nameless
:
269 rText
= GetMetricText( m_aSize
.Width(), eCoreUnit
, ePresUnit
, &rIntl
) +
271 GetMetricText( m_aSize
.Height(), eCoreUnit
, ePresUnit
, &rIntl
);
274 case SfxItemPresentation::Complete
:
275 rText
= EditResId(RID_SVXITEMS_SIZE_WIDTH
) +
276 GetMetricText( m_aSize
.Width(), eCoreUnit
, ePresUnit
, &rIntl
) +
277 " " + EditResId(GetMetricId(ePresUnit
)) +
279 EditResId(RID_SVXITEMS_SIZE_HEIGHT
) +
280 GetMetricText( m_aSize
.Height(), eCoreUnit
, ePresUnit
, &rIntl
) +
281 " " + EditResId(GetMetricId(ePresUnit
));
283 // no break necessary
284 default: ; // prevent warning
291 void SvxSizeItem::ScaleMetrics( long nMult
, long nDiv
)
293 m_aSize
.setWidth( Scale( m_aSize
.Width(), nMult
, nDiv
) );
294 m_aSize
.setHeight( Scale( m_aSize
.Height(), nMult
, nDiv
) );
298 bool SvxSizeItem::HasMetrics() const
304 SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId
) :
311 nPropFirstLineOfst( 100 ),
312 nPropLeftMargin( 100 ),
313 nPropRightMargin( 100 ),
314 nFirstLineOfst ( 0 ),
315 bAutoFirst ( false ),
316 bExplicitZeroMarginValRight(false),
317 bExplicitZeroMarginValLeft(false)
322 SvxLRSpaceItem::SvxLRSpaceItem( const long nLeft
, const long nRight
,
323 const long nTLeft
, const short nOfset
,
324 const sal_uInt16 nId
)
325 : SfxPoolItem( nId
),
328 nLeftMargin ( nLeft
),
329 nRightMargin ( nRight
),
330 nPropFirstLineOfst( 100 ),
331 nPropLeftMargin( 100 ),
332 nPropRightMargin( 100 ),
333 nFirstLineOfst ( nOfset
),
334 bAutoFirst ( false ),
335 bExplicitZeroMarginValRight(false),
336 bExplicitZeroMarginValLeft(false)
341 bool SvxLRSpaceItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
344 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
345 nMemberId
&= ~CONVERT_TWIPS
;
351 css::frame::status::LeftRightMarginScale aLRSpace
;
352 aLRSpace
.Left
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nLeftMargin
) : nLeftMargin
);
353 aLRSpace
.TextLeft
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nTxtLeft
) : nTxtLeft
);
354 aLRSpace
.Right
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nRightMargin
) : nRightMargin
);
355 aLRSpace
.ScaleLeft
= static_cast<sal_Int16
>(nPropLeftMargin
);
356 aLRSpace
.ScaleRight
= static_cast<sal_Int16
>(nPropRightMargin
);
357 aLRSpace
.FirstLine
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nFirstLineOfst
) : nFirstLineOfst
);
358 aLRSpace
.ScaleFirstLine
= static_cast<sal_Int16
>(nPropFirstLineOfst
);
359 aLRSpace
.AutoFirstLine
= IsAutoFirst();
364 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nLeftMargin
) : nLeftMargin
);
367 case MID_TXT_LMARGIN
:
368 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nTxtLeft
) : nTxtLeft
);
371 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nRightMargin
) : nRightMargin
);
373 case MID_L_REL_MARGIN
:
374 rVal
<<= static_cast<sal_Int16
>(nPropLeftMargin
);
376 case MID_R_REL_MARGIN
:
377 rVal
<<= static_cast<sal_Int16
>(nPropRightMargin
);
380 case MID_FIRST_LINE_INDENT
:
381 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nFirstLineOfst
) : nFirstLineOfst
);
384 case MID_FIRST_LINE_REL_INDENT
:
385 rVal
<<= static_cast<sal_Int16
>(nPropFirstLineOfst
);
389 rVal
<<= IsAutoFirst();
394 // 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?
395 OSL_FAIL("unknown MemberId");
401 bool SvxLRSpaceItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
403 bool bConvert
= 0 != (nMemberId
&CONVERT_TWIPS
);
404 nMemberId
&= ~CONVERT_TWIPS
;
406 if( nMemberId
!= 0 && nMemberId
!= MID_FIRST_AUTO
&&
407 nMemberId
!= MID_L_REL_MARGIN
&& nMemberId
!= MID_R_REL_MARGIN
)
415 css::frame::status::LeftRightMarginScale aLRSpace
;
416 if(!(rVal
>>= aLRSpace
))
419 SetLeft( bConvert
? convertMm100ToTwip(aLRSpace
.Left
) : aLRSpace
.Left
);
420 SetTextLeft( bConvert
? convertMm100ToTwip(aLRSpace
.TextLeft
) : aLRSpace
.TextLeft
);
421 SetRight(bConvert
? convertMm100ToTwip(aLRSpace
.Right
) : aLRSpace
.Right
);
422 nPropLeftMargin
= aLRSpace
.ScaleLeft
;
423 nPropRightMargin
= aLRSpace
.ScaleRight
;
424 SetTextFirstLineOfst(static_cast<short>(bConvert
? convertMm100ToTwip(aLRSpace
.FirstLine
) : aLRSpace
.FirstLine
));
425 SetPropTextFirstLineOfst ( static_cast<sal_uInt16
>(aLRSpace
.ScaleFirstLine
) );
426 SetAutoFirst( aLRSpace
.AutoFirstLine
);
430 SetLeft( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
433 case MID_TXT_LMARGIN
:
434 SetTextLeft( bConvert
? convertMm100ToTwip(nVal
) : nVal
);
438 SetRight(bConvert
? convertMm100ToTwip(nVal
) : nVal
);
440 case MID_L_REL_MARGIN
:
441 case MID_R_REL_MARGIN
:
444 if((rVal
>>= nRel
) && nRel
>= 0 && nRel
< SAL_MAX_UINT16
)
446 if(MID_L_REL_MARGIN
== nMemberId
)
447 nPropLeftMargin
= static_cast<sal_uInt16
>(nRel
);
449 nPropRightMargin
= static_cast<sal_uInt16
>(nRel
);
455 case MID_FIRST_LINE_INDENT
:
456 SetTextFirstLineOfst(static_cast<short>(bConvert
? convertMm100ToTwip(nVal
) : nVal
));
459 case MID_FIRST_LINE_REL_INDENT
:
460 SetPropTextFirstLineOfst ( static_cast<sal_uInt16
>(nVal
) );
464 SetAutoFirst( Any2Bool(rVal
) );
468 OSL_FAIL("unknown MemberId");
475 /// Adapt nLeftMargin and nTxtLeft.
476 void SvxLRSpaceItem::AdjustLeft()
478 if ( 0 > nFirstLineOfst
)
479 nLeftMargin
= nTxtLeft
+ nFirstLineOfst
;
481 nLeftMargin
= nTxtLeft
;
485 bool SvxLRSpaceItem::operator==( const SfxPoolItem
& rAttr
) const
487 assert(SfxPoolItem::operator==(rAttr
));
489 const SvxLRSpaceItem
& rOther
= static_cast<const SvxLRSpaceItem
&>(rAttr
);
492 nFirstLineOfst
== rOther
.GetTextFirstLineOfst() &&
493 nTxtLeft
== rOther
.GetTextLeft() &&
494 nLeftMargin
== rOther
.GetLeft() &&
495 nRightMargin
== rOther
.GetRight() &&
496 nPropFirstLineOfst
== rOther
.GetPropTextFirstLineOfst() &&
497 nPropLeftMargin
== rOther
.GetPropLeft() &&
498 nPropRightMargin
== rOther
.GetPropRight() &&
499 bAutoFirst
== rOther
.IsAutoFirst() &&
500 bExplicitZeroMarginValRight
== rOther
.IsExplicitZeroMarginValRight() &&
501 bExplicitZeroMarginValLeft
== rOther
.IsExplicitZeroMarginValLeft() );
505 SfxPoolItem
* SvxLRSpaceItem::Clone( SfxItemPool
* ) const
507 return new SvxLRSpaceItem( *this );
511 bool SvxLRSpaceItem::GetPresentation
513 SfxItemPresentation ePres
,
516 OUString
& rText
, const IntlWrapper
& rIntl
521 case SfxItemPresentation::Nameless
:
523 if ( 100 != nPropLeftMargin
)
525 rText
= unicode::formatPercent(nPropLeftMargin
,
526 Application::GetSettings().GetUILanguageTag());
529 rText
= GetMetricText( nLeftMargin
,
530 eCoreUnit
, ePresUnit
, &rIntl
);
531 rText
+= OUString(cpDelim
);
532 if ( 100 != nPropFirstLineOfst
)
534 rText
+= unicode::formatPercent(nPropFirstLineOfst
,
535 Application::GetSettings().GetUILanguageTag());
538 rText
+= GetMetricText( static_cast<long>(nFirstLineOfst
),
539 eCoreUnit
, ePresUnit
, &rIntl
);
540 rText
+= OUString(cpDelim
);
541 if ( 100 != nRightMargin
)
543 rText
+= unicode::formatPercent(nRightMargin
,
544 Application::GetSettings().GetUILanguageTag());
547 rText
+= GetMetricText( nRightMargin
,
548 eCoreUnit
, ePresUnit
, &rIntl
);
551 case SfxItemPresentation::Complete
:
553 rText
= EditResId(RID_SVXITEMS_LRSPACE_LEFT
);
554 if ( 100 != nPropLeftMargin
)
555 rText
+= unicode::formatPercent(nPropLeftMargin
,
556 Application::GetSettings().GetUILanguageTag());
560 GetMetricText( nLeftMargin
, eCoreUnit
, ePresUnit
, &rIntl
) +
561 " " + EditResId(GetMetricId(ePresUnit
));
563 rText
+= OUString(cpDelim
);
564 if ( 100 != nPropFirstLineOfst
|| nFirstLineOfst
)
566 rText
+= EditResId(RID_SVXITEMS_LRSPACE_FLINE
);
567 if ( 100 != nPropFirstLineOfst
)
568 rText
= rText
+ unicode::formatPercent(nPropFirstLineOfst
,
569 Application::GetSettings().GetUILanguageTag());
573 GetMetricText( static_cast<long>(nFirstLineOfst
),
574 eCoreUnit
, ePresUnit
, &rIntl
) +
575 " " + EditResId(GetMetricId(ePresUnit
));
577 rText
+= OUString(cpDelim
);
579 rText
+= EditResId(RID_SVXITEMS_LRSPACE_RIGHT
);
580 if ( 100 != nPropRightMargin
)
581 rText
= rText
+ unicode::formatPercent(nPropRightMargin
,
582 Application::GetSettings().GetUILanguageTag());
586 GetMetricText( nRightMargin
,
587 eCoreUnit
, ePresUnit
, &rIntl
) +
588 " " + EditResId(GetMetricId(ePresUnit
));
592 default: ; // prevent warning
598 void SvxLRSpaceItem::ScaleMetrics( long nMult
, long nDiv
)
600 nFirstLineOfst
= static_cast<short>(Scale( nFirstLineOfst
, nMult
, nDiv
));
601 nTxtLeft
= Scale( nTxtLeft
, nMult
, nDiv
);
602 nLeftMargin
= Scale( nLeftMargin
, nMult
, nDiv
);
603 nRightMargin
= Scale( nRightMargin
, nMult
, nDiv
);
607 bool SvxLRSpaceItem::HasMetrics() const
613 void SvxLRSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
615 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxLRSpaceItem"));
616 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
617 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nFirstLineOfst"), BAD_CAST(OString::number(nFirstLineOfst
).getStr()));
618 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nTxtLeft"), BAD_CAST(OString::number(nTxtLeft
).getStr()));
619 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nLeftMargin"), BAD_CAST(OString::number(nLeftMargin
).getStr()));
620 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nRightMargin"), BAD_CAST(OString::number(nRightMargin
).getStr()));
621 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropFirstLineOfst"), BAD_CAST(OString::number(nPropFirstLineOfst
).getStr()));
622 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropLeftMargin"), BAD_CAST(OString::number(nPropLeftMargin
).getStr()));
623 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropRightMargin"), BAD_CAST(OString::number(nPropRightMargin
).getStr()));
624 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bAutoFirst"), BAD_CAST(OString::number(int(bAutoFirst
)).getStr()));
625 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bExplicitZeroMarginValRight"), BAD_CAST(OString::number(int(bExplicitZeroMarginValRight
)).getStr()));
626 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bExplicitZeroMarginValLeft"), BAD_CAST(OString::number(int(bExplicitZeroMarginValLeft
)).getStr()));
627 xmlTextWriterEndElement(pWriter
);
631 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nId
)
642 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nUp
, const sal_uInt16 nLow
,
643 const sal_uInt16 nId
)
654 bool SvxULSpaceItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
656 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
657 nMemberId
&= ~CONVERT_TWIPS
;
663 css::frame::status::UpperLowerMarginScale aUpperLowerMarginScale
;
664 aUpperLowerMarginScale
.Upper
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nUpper
) : nUpper
);
665 aUpperLowerMarginScale
.Lower
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nLower
) : nPropUpper
);
666 aUpperLowerMarginScale
.ScaleUpper
= static_cast<sal_Int16
>(nPropUpper
);
667 aUpperLowerMarginScale
.ScaleLower
= static_cast<sal_Int16
>(nPropLower
);
668 rVal
<<= aUpperLowerMarginScale
;
671 case MID_UP_MARGIN
: rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nUpper
) : nUpper
); break;
672 case MID_LO_MARGIN
: rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nLower
) : nLower
); break;
673 case MID_CTX_MARGIN
: rVal
<<= bContext
; break;
674 case MID_UP_REL_MARGIN
: rVal
<<= static_cast<sal_Int16
>(nPropUpper
); break;
675 case MID_LO_REL_MARGIN
: rVal
<<= static_cast<sal_Int16
>(nPropLower
); break;
681 bool SvxULSpaceItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
683 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
684 nMemberId
&= ~CONVERT_TWIPS
;
691 css::frame::status::UpperLowerMarginScale aUpperLowerMarginScale
;
692 if ( !(rVal
>>= aUpperLowerMarginScale
))
695 SetUpper(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip( aUpperLowerMarginScale
.Upper
) : aUpperLowerMarginScale
.Upper
));
696 SetLower(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip( aUpperLowerMarginScale
.Lower
) : aUpperLowerMarginScale
.Lower
));
697 if( aUpperLowerMarginScale
.ScaleUpper
> 1 )
698 nPropUpper
= aUpperLowerMarginScale
.ScaleUpper
;
699 if( aUpperLowerMarginScale
.ScaleLower
> 1 )
700 nPropUpper
= aUpperLowerMarginScale
.ScaleLower
;
705 if(!(rVal
>>= nVal
) || nVal
< 0)
707 SetUpper(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip(nVal
) : nVal
));
710 if(!(rVal
>>= nVal
) || nVal
< 0)
712 SetLower(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip(nVal
) : nVal
));
714 case MID_CTX_MARGIN
:
715 if (!(rVal
>>= bVal
))
717 SetContextValue(bVal
);
719 case MID_UP_REL_MARGIN
:
720 case MID_LO_REL_MARGIN
:
723 if((rVal
>>= nRel
) && nRel
> 1 )
725 if(MID_UP_REL_MARGIN
== nMemberId
)
726 nPropUpper
= static_cast<sal_uInt16
>(nRel
);
728 nPropLower
= static_cast<sal_uInt16
>(nRel
);
736 OSL_FAIL("unknown MemberId");
743 bool SvxULSpaceItem::operator==( const SfxPoolItem
& rAttr
) const
745 assert(SfxPoolItem::operator==(rAttr
));
747 const SvxULSpaceItem
& rSpaceItem
= static_cast<const SvxULSpaceItem
&>( rAttr
);
748 return ( nUpper
== rSpaceItem
.nUpper
&&
749 nLower
== rSpaceItem
.nLower
&&
750 bContext
== rSpaceItem
.bContext
&&
751 nPropUpper
== rSpaceItem
.nPropUpper
&&
752 nPropLower
== rSpaceItem
.nPropLower
);
756 SfxPoolItem
* SvxULSpaceItem::Clone( SfxItemPool
* ) const
758 return new SvxULSpaceItem( *this );
762 bool SvxULSpaceItem::GetPresentation
764 SfxItemPresentation ePres
,
768 const IntlWrapper
& rIntl
773 case SfxItemPresentation::Nameless
:
775 if ( 100 != nPropUpper
)
777 rText
= unicode::formatPercent(nPropUpper
,
778 Application::GetSettings().GetUILanguageTag());
781 rText
= GetMetricText( static_cast<long>(nUpper
), eCoreUnit
, ePresUnit
, &rIntl
);
782 rText
+= OUString(cpDelim
);
783 if ( 100 != nPropLower
)
785 rText
+= unicode::formatPercent(nPropLower
,
786 Application::GetSettings().GetUILanguageTag());
789 rText
+= GetMetricText( static_cast<long>(nLower
), eCoreUnit
, ePresUnit
, &rIntl
);
792 case SfxItemPresentation::Complete
:
794 rText
= EditResId(RID_SVXITEMS_ULSPACE_UPPER
);
795 if ( 100 != nPropUpper
)
797 rText
+= unicode::formatPercent(nPropUpper
,
798 Application::GetSettings().GetUILanguageTag());
803 GetMetricText( static_cast<long>(nUpper
), eCoreUnit
, ePresUnit
, &rIntl
) +
804 " " + EditResId(GetMetricId(ePresUnit
));
806 rText
= rText
+ OUString(cpDelim
) + EditResId(RID_SVXITEMS_ULSPACE_LOWER
);
807 if ( 100 != nPropLower
)
809 rText
+= unicode::formatPercent(nPropLower
,
810 Application::GetSettings().GetUILanguageTag());
815 GetMetricText( static_cast<long>(nLower
), eCoreUnit
, ePresUnit
, &rIntl
) +
816 " " + EditResId(GetMetricId(ePresUnit
));
820 default: ; // prevent warning
826 void SvxULSpaceItem::ScaleMetrics( long nMult
, long nDiv
)
828 nUpper
= static_cast<sal_uInt16
>(Scale( nUpper
, nMult
, nDiv
));
829 nLower
= static_cast<sal_uInt16
>(Scale( nLower
, nMult
, nDiv
));
833 bool SvxULSpaceItem::HasMetrics() const
839 void SvxULSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
841 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxULSpaceItem"));
842 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
843 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nUpper"), BAD_CAST(OString::number(nUpper
).getStr()));
844 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nLower"), BAD_CAST(OString::number(nLower
).getStr()));
845 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bContext"), BAD_CAST(OString::boolean(bContext
).getStr()));
846 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropUpper"), BAD_CAST(OString::number(nPropUpper
).getStr()));
847 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropLower"), BAD_CAST(OString::number(nPropLower
).getStr()));
848 xmlTextWriterEndElement(pWriter
);
852 SfxPoolItem
* SvxPrintItem::Clone( SfxItemPool
* ) const
854 return new SvxPrintItem( *this );
858 bool SvxPrintItem::GetPresentation
860 SfxItemPresentation
/*ePres*/,
861 MapUnit
/*eCoreUnit*/,
862 MapUnit
/*ePresUnit*/,
863 OUString
& rText
, const IntlWrapper
&
866 const char* pId
= RID_SVXITEMS_PRINT_FALSE
;
869 pId
= RID_SVXITEMS_PRINT_TRUE
;
870 rText
= EditResId(pId
);
875 SfxPoolItem
* SvxOpaqueItem::Clone( SfxItemPool
* ) const
877 return new SvxOpaqueItem( *this );
881 bool SvxOpaqueItem::GetPresentation
883 SfxItemPresentation
/*ePres*/,
884 MapUnit
/*eCoreUnit*/,
885 MapUnit
/*ePresUnit*/,
886 OUString
& rText
, const IntlWrapper
&
889 const char* pId
= RID_SVXITEMS_OPAQUE_FALSE
;
892 pId
= RID_SVXITEMS_OPAQUE_TRUE
;
893 rText
= EditResId(pId
);
898 bool SvxProtectItem::operator==( const SfxPoolItem
& rAttr
) const
900 assert(SfxPoolItem::operator==(rAttr
));
902 const SvxProtectItem
& rItem
= static_cast<const SvxProtectItem
&>(rAttr
);
903 return ( bCntnt
== rItem
.bCntnt
&&
904 bSize
== rItem
.bSize
&&
905 bPos
== rItem
.bPos
);
909 bool SvxProtectItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
911 nMemberId
&= ~CONVERT_TWIPS
;
915 case MID_PROTECT_CONTENT
: bValue
= bCntnt
; break;
916 case MID_PROTECT_SIZE
: bValue
= bSize
; break;
917 case MID_PROTECT_POSITION
: bValue
= bPos
; break;
919 OSL_FAIL("Wrong MemberId");
928 bool SvxProtectItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
930 nMemberId
&= ~CONVERT_TWIPS
;
931 bool bVal( Any2Bool(rVal
) );
934 case MID_PROTECT_CONTENT
: bCntnt
= bVal
; break;
935 case MID_PROTECT_SIZE
: bSize
= bVal
; break;
936 case MID_PROTECT_POSITION
: bPos
= bVal
; break;
938 OSL_FAIL("Wrong MemberId");
945 SfxPoolItem
* SvxProtectItem::Clone( SfxItemPool
* ) const
947 return new SvxProtectItem( *this );
951 bool SvxProtectItem::GetPresentation
953 SfxItemPresentation
/*ePres*/,
954 MapUnit
/*eCoreUnit*/,
955 MapUnit
/*ePresUnit*/,
956 OUString
& rText
, const IntlWrapper
&
959 const char* pId
= RID_SVXITEMS_PROT_CONTENT_FALSE
;
962 pId
= RID_SVXITEMS_PROT_CONTENT_TRUE
;
963 rText
= EditResId(pId
) + OUString(cpDelim
);
964 pId
= RID_SVXITEMS_PROT_SIZE_FALSE
;
967 pId
= RID_SVXITEMS_PROT_SIZE_TRUE
;
968 rText
= rText
+ EditResId(pId
) + OUString(cpDelim
);
969 pId
= RID_SVXITEMS_PROT_POS_FALSE
;
972 pId
= RID_SVXITEMS_PROT_POS_TRUE
;
973 rText
+= EditResId(pId
);
978 void SvxProtectItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
980 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxProtectItem"));
981 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
982 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("content"), BAD_CAST(OString::boolean(bCntnt
).getStr()));
983 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("size"), BAD_CAST(OString::boolean(bSize
).getStr()));
984 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("position"), BAD_CAST(OString::boolean(bPos
).getStr()));
985 xmlTextWriterEndElement(pWriter
);
989 SvxShadowItem::SvxShadowItem( const sal_uInt16 nId
,
990 const Color
*pColor
, const sal_uInt16 nW
,
991 const SvxShadowLocation eLoc
) :
992 SfxEnumItemInterface( nId
),
993 aShadowColor(COL_GRAY
),
998 aShadowColor
= *pColor
;
1002 bool SvxShadowItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
1004 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1005 nMemberId
&= ~CONVERT_TWIPS
;
1007 table::ShadowFormat aShadow
;
1008 table::ShadowLocation eSet
= table::ShadowLocation_NONE
;
1011 case SvxShadowLocation::TopLeft
: eSet
= table::ShadowLocation_TOP_LEFT
; break;
1012 case SvxShadowLocation::TopRight
: eSet
= table::ShadowLocation_TOP_RIGHT
; break;
1013 case SvxShadowLocation::BottomLeft
: eSet
= table::ShadowLocation_BOTTOM_LEFT
; break;
1014 case SvxShadowLocation::BottomRight
: eSet
= table::ShadowLocation_BOTTOM_RIGHT
; break;
1015 default: ; // prevent warning
1017 aShadow
.Location
= eSet
;
1018 aShadow
.ShadowWidth
= bConvert
? convertTwipToMm100(nWidth
) : nWidth
;
1019 aShadow
.IsTransparent
= aShadowColor
.GetTransparency() > 0;
1020 aShadow
.Color
= sal_Int32(aShadowColor
);
1022 sal_Int8 nTransparence
= rtl::math::round(float(aShadowColor
.GetTransparency() * 100) / 255);
1024 switch ( nMemberId
)
1026 case MID_LOCATION
: rVal
<<= aShadow
.Location
; break;
1027 case MID_WIDTH
: rVal
<<= aShadow
.ShadowWidth
; break;
1028 case MID_TRANSPARENT
: rVal
<<= aShadow
.IsTransparent
; break;
1029 case MID_BG_COLOR
: rVal
<<= aShadow
.Color
; break;
1030 case 0: rVal
<<= aShadow
; break;
1031 case MID_SHADOW_TRANSPARENCE
: rVal
<<= nTransparence
; break;
1032 default: OSL_FAIL("Wrong MemberId!"); return false;
1038 bool SvxShadowItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
1040 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1041 nMemberId
&= ~CONVERT_TWIPS
;
1043 table::ShadowFormat aShadow
;
1045 bool bRet
= QueryValue( aAny
, bConvert
? CONVERT_TWIPS
: 0 ) && ( aAny
>>= aShadow
);
1046 switch ( nMemberId
)
1050 bRet
= (rVal
>>= aShadow
.Location
);
1054 bRet
= (rVal
>>= nVal
);
1055 aShadow
.Location
= static_cast<table::ShadowLocation
>(nVal
);
1061 case MID_WIDTH
: rVal
>>= aShadow
.ShadowWidth
; break;
1062 case MID_TRANSPARENT
: rVal
>>= aShadow
.IsTransparent
; break;
1063 case MID_BG_COLOR
: rVal
>>= aShadow
.Color
; break;
1064 case 0: rVal
>>= aShadow
; break;
1065 case MID_SHADOW_TRANSPARENCE
:
1067 sal_Int32 nTransparence
= 0;
1068 if ((rVal
>>= nTransparence
) && !o3tl::checked_multiply
<sal_Int32
>(nTransparence
, 255, nTransparence
))
1070 Color
aColor(aShadow
.Color
);
1071 aColor
.SetTransparency(rtl::math::round(float(nTransparence
) / 100));
1072 aShadow
.Color
= sal_Int32(aColor
);
1076 default: OSL_FAIL("Wrong MemberId!"); return false;
1081 // SvxShadowLocation eSet = SvxShadowLocation::NONE;
1082 switch( aShadow
.Location
)
1084 case table::ShadowLocation_TOP_LEFT
: eLocation
= SvxShadowLocation::TopLeft
; break;
1085 case table::ShadowLocation_TOP_RIGHT
: eLocation
= SvxShadowLocation::TopRight
; break;
1086 case table::ShadowLocation_BOTTOM_LEFT
: eLocation
= SvxShadowLocation::BottomLeft
; break;
1087 case table::ShadowLocation_BOTTOM_RIGHT
: eLocation
= SvxShadowLocation::BottomRight
; break;
1088 default: ; // prevent warning
1091 nWidth
= bConvert
? convertMm100ToTwip(aShadow
.ShadowWidth
) : aShadow
.ShadowWidth
;
1092 Color
aSet(aShadow
.Color
);
1093 aShadowColor
= aSet
;
1100 bool SvxShadowItem::operator==( const SfxPoolItem
& rAttr
) const
1102 assert(SfxPoolItem::operator==(rAttr
));
1104 const SvxShadowItem
& rItem
= static_cast<const SvxShadowItem
&>(rAttr
);
1105 return ( ( aShadowColor
== rItem
.aShadowColor
) &&
1106 ( nWidth
== rItem
.GetWidth() ) &&
1107 ( eLocation
== rItem
.GetLocation() ) );
1111 SfxPoolItem
* SvxShadowItem::Clone( SfxItemPool
* ) const
1113 return new SvxShadowItem( *this );
1117 sal_uInt16
SvxShadowItem::CalcShadowSpace( SvxShadowItemSide nShadow
) const
1119 sal_uInt16 nSpace
= 0;
1123 case SvxShadowItemSide::TOP
:
1124 if ( eLocation
== SvxShadowLocation::TopLeft
||
1125 eLocation
== SvxShadowLocation::TopRight
)
1129 case SvxShadowItemSide::BOTTOM
:
1130 if ( eLocation
== SvxShadowLocation::BottomLeft
||
1131 eLocation
== SvxShadowLocation::BottomRight
)
1135 case SvxShadowItemSide::LEFT
:
1136 if ( eLocation
== SvxShadowLocation::TopLeft
||
1137 eLocation
== SvxShadowLocation::BottomLeft
)
1141 case SvxShadowItemSide::RIGHT
:
1142 if ( eLocation
== SvxShadowLocation::TopRight
||
1143 eLocation
== SvxShadowLocation::BottomRight
)
1148 OSL_FAIL( "wrong shadow" );
1153 static const char* RID_SVXITEMS_SHADOW
[] =
1155 RID_SVXITEMS_SHADOW_NONE
,
1156 RID_SVXITEMS_SHADOW_TOPLEFT
,
1157 RID_SVXITEMS_SHADOW_TOPRIGHT
,
1158 RID_SVXITEMS_SHADOW_BOTTOMLEFT
,
1159 RID_SVXITEMS_SHADOW_BOTTOMRIGHT
1162 bool SvxShadowItem::GetPresentation
1164 SfxItemPresentation ePres
,
1167 OUString
& rText
, const IntlWrapper
& rIntl
1172 case SfxItemPresentation::Nameless
:
1174 rText
= ::GetColorString( aShadowColor
) + OUString(cpDelim
);
1175 const char* pId
= RID_SVXITEMS_TRANSPARENT_FALSE
;
1177 if ( aShadowColor
.GetTransparency() )
1178 pId
= RID_SVXITEMS_TRANSPARENT_TRUE
;
1182 GetMetricText( static_cast<long>(nWidth
), eCoreUnit
, ePresUnit
, &rIntl
) +
1184 EditResId(RID_SVXITEMS_SHADOW
[static_cast<int>(eLocation
)]);
1187 case SfxItemPresentation::Complete
:
1189 rText
= EditResId(RID_SVXITEMS_SHADOW_COMPLETE
) +
1190 ::GetColorString( aShadowColor
) +
1193 const char* pId
= RID_SVXITEMS_TRANSPARENT_FALSE
;
1194 if ( aShadowColor
.GetTransparency() )
1195 pId
= RID_SVXITEMS_TRANSPARENT_TRUE
;
1199 GetMetricText( static_cast<long>(nWidth
), eCoreUnit
, ePresUnit
, &rIntl
) +
1200 " " + EditResId(GetMetricId(ePresUnit
)) +
1202 EditResId(RID_SVXITEMS_SHADOW
[static_cast<int>(eLocation
)]);
1205 default: ; // prevent warning
1211 void SvxShadowItem::ScaleMetrics( long nMult
, long nDiv
)
1213 nWidth
= static_cast<sal_uInt16
>(Scale( nWidth
, nMult
, nDiv
));
1217 bool SvxShadowItem::HasMetrics() const
1223 sal_uInt16
SvxShadowItem::GetValueCount() const
1225 return sal_uInt16(SvxShadowLocation::End
); // SvxShadowLocation::BottomRight + 1
1228 sal_uInt16
SvxShadowItem::GetEnumValue() const
1230 return static_cast<sal_uInt16
>(GetLocation());
1234 void SvxShadowItem::SetEnumValue( sal_uInt16 nVal
)
1236 SetLocation( static_cast<SvxShadowLocation
>(nVal
) );
1239 void SvxShadowItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
1241 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxShadowItem"));
1242 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1243 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("aShadowColor"), BAD_CAST(aShadowColor
.AsRGBHexString().toUtf8().getStr()));
1244 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nWidth"), BAD_CAST(OString::number(nWidth
).getStr()));
1245 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("eLocation"), BAD_CAST(OString::number(static_cast<int>(eLocation
)).getStr()));
1246 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("presentation"), BAD_CAST(EditResId(RID_SVXITEMS_SHADOW
[static_cast<int>(eLocation
)]).toUtf8().getStr()));
1247 xmlTextWriterEndElement(pWriter
);
1250 // class SvxBoxItem ------------------------------------------------------
1252 SvxBoxItem::SvxBoxItem( const SvxBoxItem
& rCpy
) :
1254 SfxPoolItem ( rCpy
),
1255 pTop ( rCpy
.pTop
? new SvxBorderLine( *rCpy
.pTop
) : nullptr ),
1256 pBottom ( rCpy
.pBottom
? new SvxBorderLine( *rCpy
.pBottom
) : nullptr ),
1257 pLeft ( rCpy
.pLeft
? new SvxBorderLine( *rCpy
.pLeft
) : nullptr ),
1258 pRight ( rCpy
.pRight
? new SvxBorderLine( *rCpy
.pRight
) : nullptr ),
1259 nTopDist ( rCpy
.nTopDist
),
1260 nBottomDist ( rCpy
.nBottomDist
),
1261 nLeftDist ( rCpy
.nLeftDist
),
1262 nRightDist ( rCpy
.nRightDist
),
1263 bRemoveAdjCellBorder ( rCpy
.bRemoveAdjCellBorder
)
1268 SvxBoxItem::SvxBoxItem( const sal_uInt16 nId
) :
1274 bRemoveAdjCellBorder ( false )
1279 SvxBoxItem::~SvxBoxItem()
1284 static bool CmpBrdLn( const std::unique_ptr
<SvxBorderLine
> & pBrd1
, const SvxBorderLine
* pBrd2
)
1286 if( pBrd1
.get() == pBrd2
)
1288 if( pBrd1
== nullptr || pBrd2
== nullptr)
1290 return *pBrd1
== *pBrd2
;
1294 bool SvxBoxItem::operator==( const SfxPoolItem
& rAttr
) const
1296 assert(SfxPoolItem::operator==(rAttr
));
1298 const SvxBoxItem
& rBoxItem
= static_cast<const SvxBoxItem
&>(rAttr
);
1300 ( nTopDist
== rBoxItem
.nTopDist
) &&
1301 ( nBottomDist
== rBoxItem
.nBottomDist
) &&
1302 ( nLeftDist
== rBoxItem
.nLeftDist
) &&
1303 ( nRightDist
== rBoxItem
.nRightDist
) &&
1304 ( bRemoveAdjCellBorder
== rBoxItem
.bRemoveAdjCellBorder
) &&
1305 CmpBrdLn( pTop
, rBoxItem
.GetTop() ) &&
1306 CmpBrdLn( pBottom
, rBoxItem
.GetBottom() ) &&
1307 CmpBrdLn( pLeft
, rBoxItem
.GetLeft() ) &&
1308 CmpBrdLn( pRight
, rBoxItem
.GetRight() ) );
1312 table::BorderLine2
SvxBoxItem::SvxLineToLine(const SvxBorderLine
* pLine
, bool bConvert
)
1314 table::BorderLine2 aLine
;
1317 aLine
.Color
= sal_Int32(pLine
->GetColor());
1318 aLine
.InnerLineWidth
= sal_uInt16( bConvert
? convertTwipToMm100(pLine
->GetInWidth() ): pLine
->GetInWidth() );
1319 aLine
.OuterLineWidth
= sal_uInt16( bConvert
? convertTwipToMm100(pLine
->GetOutWidth()): pLine
->GetOutWidth() );
1320 aLine
.LineDistance
= sal_uInt16( bConvert
? convertTwipToMm100(pLine
->GetDistance()): pLine
->GetDistance() );
1321 aLine
.LineStyle
= sal_Int16(pLine
->GetBorderLineStyle());
1322 aLine
.LineWidth
= sal_uInt32( bConvert
? convertTwipToMm100( pLine
->GetWidth( ) ) : pLine
->GetWidth( ) );
1325 aLine
.Color
= aLine
.InnerLineWidth
= aLine
.OuterLineWidth
= aLine
.LineDistance
= 0;
1329 bool SvxBoxItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
1331 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1332 table::BorderLine2 aRetLine
;
1333 sal_uInt16 nDist
= 0;
1334 bool bDistMember
= false;
1335 nMemberId
&= ~CONVERT_TWIPS
;
1340 // 4 Borders and 5 distances
1341 uno::Sequence
< uno::Any
> aSeq( 9 );
1342 aSeq
[0] <<= SvxBoxItem::SvxLineToLine(GetLeft(), bConvert
);
1343 aSeq
[1] <<= SvxBoxItem::SvxLineToLine(GetRight(), bConvert
);
1344 aSeq
[2] <<= SvxBoxItem::SvxLineToLine(GetBottom(), bConvert
);
1345 aSeq
[3] <<= SvxBoxItem::SvxLineToLine(GetTop(), bConvert
);
1346 aSeq
[4] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( GetSmallestDistance()) : GetSmallestDistance());
1347 aSeq
[5] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nTopDist
) : nTopDist
);
1348 aSeq
[6] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nBottomDist
) : nBottomDist
);
1349 aSeq
[7] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nLeftDist
) : nLeftDist
);
1350 aSeq
[8] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nRightDist
) : nRightDist
);
1354 case MID_LEFT_BORDER
:
1356 aRetLine
= SvxBoxItem::SvxLineToLine(GetLeft(), bConvert
);
1358 case MID_RIGHT_BORDER
:
1360 aRetLine
= SvxBoxItem::SvxLineToLine(GetRight(), bConvert
);
1362 case MID_BOTTOM_BORDER
:
1364 aRetLine
= SvxBoxItem::SvxLineToLine(GetBottom(), bConvert
);
1366 case MID_TOP_BORDER
:
1368 aRetLine
= SvxBoxItem::SvxLineToLine(GetTop(), bConvert
);
1370 case BORDER_DISTANCE
:
1371 nDist
= GetSmallestDistance();
1374 case TOP_BORDER_DISTANCE
:
1378 case BOTTOM_BORDER_DISTANCE
:
1379 nDist
= nBottomDist
;
1382 case LEFT_BORDER_DISTANCE
:
1386 case RIGHT_BORDER_DISTANCE
:
1392 // it doesn't make sense to return a value for these since it's
1393 // probably ambiguous
1399 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nDist
) : nDist
);
1410 lcl_lineToSvxLine(const table::BorderLine
& rLine
, SvxBorderLine
& rSvxLine
, bool bConvert
, bool bGuessWidth
)
1412 rSvxLine
.SetColor( Color(rLine
.Color
));
1415 rSvxLine
.GuessLinesWidths( rSvxLine
.GetBorderLineStyle(),
1416 sal_uInt16( bConvert
? convertMm100ToTwip(rLine
.OuterLineWidth
) : rLine
.OuterLineWidth
),
1417 sal_uInt16( bConvert
? convertMm100ToTwip(rLine
.InnerLineWidth
) : rLine
.InnerLineWidth
),
1418 sal_uInt16( bConvert
? convertMm100ToTwip(rLine
.LineDistance
) : rLine
.LineDistance
));
1421 bool bRet
= !rSvxLine
.isEmpty();
1428 bool SvxBoxItem::LineToSvxLine(const css::table::BorderLine
& rLine
, SvxBorderLine
& rSvxLine
, bool bConvert
)
1430 return lcl_lineToSvxLine(rLine
, rSvxLine
, bConvert
, true);
1434 SvxBoxItem::LineToSvxLine(const css::table::BorderLine2
& rLine
, SvxBorderLine
& rSvxLine
, bool bConvert
)
1436 SvxBorderLineStyle
const nStyle
=
1437 (rLine
.LineStyle
< 0 || BORDER_LINE_STYLE_MAX
< rLine
.LineStyle
)
1438 ? SvxBorderLineStyle::SOLID
// default
1439 : static_cast<SvxBorderLineStyle
>(rLine
.LineStyle
);
1441 rSvxLine
.SetBorderLineStyle( nStyle
);
1443 bool bGuessWidth
= true;
1444 if ( rLine
.LineWidth
)
1446 rSvxLine
.SetWidth( bConvert
? convertMm100ToTwip( rLine
.LineWidth
) : rLine
.LineWidth
);
1447 // fdo#46112: double does not necessarily mean symmetric
1448 // for backwards compatibility
1449 bGuessWidth
= (SvxBorderLineStyle::DOUBLE
== nStyle
|| SvxBorderLineStyle::DOUBLE_THIN
== nStyle
) &&
1450 (rLine
.InnerLineWidth
> 0) && (rLine
.OuterLineWidth
> 0);
1453 return lcl_lineToSvxLine(rLine
, rSvxLine
, bConvert
, bGuessWidth
);
1461 lcl_extractBorderLine(const uno::Any
& rAny
, table::BorderLine2
& rLine
)
1466 table::BorderLine aBorderLine
;
1467 if (rAny
>>= aBorderLine
)
1469 rLine
.Color
= aBorderLine
.Color
;
1470 rLine
.InnerLineWidth
= aBorderLine
.InnerLineWidth
;
1471 rLine
.OuterLineWidth
= aBorderLine
.OuterLineWidth
;
1472 rLine
.LineDistance
= aBorderLine
.LineDistance
;
1473 rLine
.LineStyle
= table::BorderLineStyle::SOLID
;
1480 template<typename Item
, typename Line
>
1482 lcl_setLine(const uno::Any
& rAny
, Item
& rItem
, Line nLine
, const bool bConvert
)
1485 table::BorderLine2 aBorderLine
;
1486 if (lcl_extractBorderLine(rAny
, aBorderLine
))
1488 SvxBorderLine aLine
;
1489 bool bSet
= SvxBoxItem::LineToSvxLine(aBorderLine
, aLine
, bConvert
);
1490 rItem
.SetLine( bSet
? &aLine
: nullptr, nLine
);
1498 bool SvxBoxItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
1500 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1501 SvxBoxItemLine nLine
= SvxBoxItemLine::TOP
;
1502 bool bDistMember
= false;
1503 nMemberId
&= ~CONVERT_TWIPS
;
1508 uno::Sequence
< uno::Any
> aSeq
;
1509 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == 9 ))
1511 // 4 Borders and 5 distances
1512 const SvxBoxItemLine aBorders
[] = { SvxBoxItemLine::LEFT
, SvxBoxItemLine::RIGHT
, SvxBoxItemLine::BOTTOM
, SvxBoxItemLine::TOP
};
1513 for (int n(0); n
!= SAL_N_ELEMENTS(aBorders
); ++n
)
1515 if (!lcl_setLine(aSeq
[n
], *this, aBorders
[n
], bConvert
))
1519 // WTH are the borders and the distances saved in different order?
1520 SvxBoxItemLine
const nLines
[4] = { SvxBoxItemLine::TOP
, SvxBoxItemLine::BOTTOM
, SvxBoxItemLine::LEFT
, SvxBoxItemLine::RIGHT
};
1521 for ( sal_Int32 n
= 4; n
< 9; n
++ )
1523 sal_Int32 nDist
= 0;
1524 if ( aSeq
[n
] >>= nDist
)
1527 nDist
= convertMm100ToTwip(nDist
);
1529 SetAllDistances(sal_uInt16(nDist
));
1531 SetDistance( sal_uInt16( nDist
), nLines
[n
-5] );
1542 case LEFT_BORDER_DISTANCE
:
1546 case MID_LEFT_BORDER
:
1547 nLine
= SvxBoxItemLine::LEFT
;
1549 case RIGHT_BORDER_DISTANCE
:
1553 case MID_RIGHT_BORDER
:
1554 nLine
= SvxBoxItemLine::RIGHT
;
1556 case BOTTOM_BORDER_DISTANCE
:
1560 case MID_BOTTOM_BORDER
:
1561 nLine
= SvxBoxItemLine::BOTTOM
;
1563 case TOP_BORDER_DISTANCE
:
1567 case MID_TOP_BORDER
:
1568 nLine
= SvxBoxItemLine::TOP
;
1572 drawing::LineStyle eDrawingStyle
;
1573 rVal
>>= eDrawingStyle
;
1574 SvxBorderLineStyle eBorderStyle
= SvxBorderLineStyle::NONE
;
1575 switch ( eDrawingStyle
)
1578 case drawing::LineStyle_NONE
:
1580 case drawing::LineStyle_SOLID
:
1581 eBorderStyle
= SvxBorderLineStyle::SOLID
;
1583 case drawing::LineStyle_DASH
:
1584 eBorderStyle
= SvxBorderLineStyle::DASHED
;
1588 // Set the line style on all borders
1589 for( SvxBoxItemLine n
: o3tl::enumrange
<SvxBoxItemLine
>() )
1591 editeng::SvxBorderLine
* pLine
= const_cast< editeng::SvxBorderLine
* >( GetLine( n
) );
1593 pLine
->SetBorderLineStyle( eBorderStyle
);
1600 // Set the line width on all borders
1604 nWidth
= convertMm100ToTwip( nWidth
);
1606 // Set the line Width on all borders
1607 for( SvxBoxItemLine n
: o3tl::enumrange
<SvxBoxItemLine
>() )
1609 editeng::SvxBorderLine
* pLine
= const_cast< editeng::SvxBorderLine
* >( GetLine( n
) );
1611 pLine
->SetWidth( nWidth
);
1617 if( bDistMember
|| nMemberId
== BORDER_DISTANCE
)
1619 sal_Int32 nDist
= 0;
1620 if(!(rVal
>>= nDist
))
1626 nDist
= convertMm100ToTwip(nDist
);
1627 if( nMemberId
== BORDER_DISTANCE
)
1628 SetAllDistances(sal_uInt16(nDist
));
1630 SetDistance( sal_uInt16( nDist
), nLine
);
1635 SvxBorderLine aLine
;
1636 if( !rVal
.hasValue() )
1639 table::BorderLine2 aBorderLine
;
1640 if( lcl_extractBorderLine(rVal
, aBorderLine
) )
1644 else if (rVal
.getValueTypeClass() == uno::TypeClass_SEQUENCE
)
1646 // serialization for basic macro recording
1647 uno::Reference
< script::XTypeConverter
> xConverter
1648 ( script::Converter::create(::comphelper::getProcessComponentContext()) );
1649 uno::Sequence
< uno::Any
> aSeq
;
1651 try { aNew
= xConverter
->convertTo( rVal
, cppu::UnoType
<uno::Sequence
< uno::Any
>>::get() ); }
1652 catch (const uno::Exception
&) {}
1655 if (aSeq
.getLength() >= 4 && aSeq
.getLength() <= 6)
1658 if ( aSeq
[0] >>= nVal
)
1659 aBorderLine
.Color
= nVal
;
1660 if ( aSeq
[1] >>= nVal
)
1661 aBorderLine
.InnerLineWidth
= static_cast<sal_Int16
>(nVal
);
1662 if ( aSeq
[2] >>= nVal
)
1663 aBorderLine
.OuterLineWidth
= static_cast<sal_Int16
>(nVal
);
1664 if ( aSeq
[3] >>= nVal
)
1665 aBorderLine
.LineDistance
= static_cast<sal_Int16
>(nVal
);
1666 if (aSeq
.getLength() >= 5) // fdo#40874 added fields
1668 if (aSeq
[4] >>= nVal
)
1670 aBorderLine
.LineStyle
= nVal
;
1672 if (aSeq
.getLength() >= 6)
1674 if (aSeq
[5] >>= nVal
)
1676 aBorderLine
.LineWidth
= nVal
;
1687 bool bSet
= SvxBoxItem::LineToSvxLine(aBorderLine
, aLine
, bConvert
);
1688 SetLine(bSet
? &aLine
: nullptr, nLine
);
1695 SfxPoolItem
* SvxBoxItem::Clone( SfxItemPool
* ) const
1697 return new SvxBoxItem( *this );
1701 bool SvxBoxItem::GetPresentation
1703 SfxItemPresentation ePres
,
1706 OUString
& rText
, const IntlWrapper
& rIntl
1709 OUString
cpDelimTmp(cpDelim
);
1712 case SfxItemPresentation::Nameless
:
1718 rText
= pTop
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1720 if( !(pTop
&& pBottom
&& pLeft
&& pRight
&&
1721 *pTop
== *pBottom
&& *pTop
== *pLeft
&& *pTop
== *pRight
) )
1725 rText
= rText
+ pBottom
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1729 rText
= rText
+ pLeft
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1733 rText
= rText
+ pRight
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1736 rText
+= GetMetricText( static_cast<long>(nTopDist
), eCoreUnit
, ePresUnit
, &rIntl
);
1737 if( nTopDist
!= nBottomDist
|| nTopDist
!= nLeftDist
||
1738 nTopDist
!= nRightDist
)
1742 GetMetricText( static_cast<long>(nBottomDist
), eCoreUnit
,
1743 ePresUnit
, &rIntl
) +
1745 GetMetricText( static_cast<long>(nLeftDist
), eCoreUnit
, ePresUnit
, &rIntl
) +
1747 GetMetricText( static_cast<long>(nRightDist
), eCoreUnit
,
1748 ePresUnit
, &rIntl
);
1752 case SfxItemPresentation::Complete
:
1754 if( !(pTop
|| pBottom
|| pLeft
|| pRight
) )
1756 rText
= EditResId(RID_SVXITEMS_BORDER_NONE
) + cpDelimTmp
;
1760 rText
= EditResId(RID_SVXITEMS_BORDER_COMPLETE
);
1761 if( pTop
&& pBottom
&& pLeft
&& pRight
&&
1762 *pTop
== *pBottom
&& *pTop
== *pLeft
&& *pTop
== *pRight
)
1764 rText
+= pTop
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) + cpDelimTmp
;
1771 EditResId(RID_SVXITEMS_BORDER_TOP
) +
1772 pTop
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1778 EditResId(RID_SVXITEMS_BORDER_BOTTOM
) +
1779 pBottom
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1785 EditResId(RID_SVXITEMS_BORDER_LEFT
) +
1786 pLeft
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1792 EditResId(RID_SVXITEMS_BORDER_RIGHT
) +
1793 pRight
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1799 rText
+= EditResId(RID_SVXITEMS_BORDER_DISTANCE
);
1800 if( nTopDist
== nBottomDist
&& nTopDist
== nLeftDist
&&
1801 nTopDist
== nRightDist
)
1804 GetMetricText( static_cast<long>(nTopDist
), eCoreUnit
,
1805 ePresUnit
, &rIntl
) +
1806 " " + EditResId(GetMetricId(ePresUnit
));
1811 EditResId(RID_SVXITEMS_BORDER_TOP
) +
1812 GetMetricText( static_cast<long>(nTopDist
), eCoreUnit
,
1813 ePresUnit
, &rIntl
) +
1814 " " + EditResId(GetMetricId(ePresUnit
)) +
1816 EditResId(RID_SVXITEMS_BORDER_BOTTOM
) +
1817 GetMetricText( static_cast<long>(nBottomDist
), eCoreUnit
,
1818 ePresUnit
, &rIntl
) +
1819 " " + EditResId(GetMetricId(ePresUnit
)) +
1821 EditResId(RID_SVXITEMS_BORDER_LEFT
) +
1822 GetMetricText( static_cast<long>(nLeftDist
), eCoreUnit
,
1823 ePresUnit
, &rIntl
) +
1824 " " + EditResId(GetMetricId(ePresUnit
)) +
1826 EditResId(RID_SVXITEMS_BORDER_RIGHT
) +
1827 GetMetricText( static_cast<long>(nRightDist
), eCoreUnit
,
1828 ePresUnit
, &rIntl
) +
1829 " " + EditResId(GetMetricId(ePresUnit
));
1833 default: ; // prevent warning
1839 void SvxBoxItem::ScaleMetrics( long nMult
, long nDiv
)
1841 if ( pTop
) pTop
->ScaleMetrics( nMult
, nDiv
);
1842 if ( pBottom
) pBottom
->ScaleMetrics( nMult
, nDiv
);
1843 if ( pLeft
) pLeft
->ScaleMetrics( nMult
, nDiv
);
1844 if ( pRight
) pRight
->ScaleMetrics( nMult
, nDiv
);
1845 nTopDist
= static_cast<sal_uInt16
>(Scale( nTopDist
, nMult
, nDiv
));
1846 nBottomDist
= static_cast<sal_uInt16
>(Scale( nBottomDist
, nMult
, nDiv
));
1847 nLeftDist
= static_cast<sal_uInt16
>(Scale( nLeftDist
, nMult
, nDiv
));
1848 nRightDist
= static_cast<sal_uInt16
>(Scale( nRightDist
, nMult
, nDiv
));
1852 bool SvxBoxItem::HasMetrics() const
1858 const SvxBorderLine
*SvxBoxItem::GetLine( SvxBoxItemLine nLine
) const
1860 const SvxBorderLine
*pRet
= nullptr;
1864 case SvxBoxItemLine::TOP
:
1867 case SvxBoxItemLine::BOTTOM
:
1868 pRet
= pBottom
.get();
1870 case SvxBoxItemLine::LEFT
:
1873 case SvxBoxItemLine::RIGHT
:
1874 pRet
= pRight
.get();
1877 OSL_FAIL( "wrong line" );
1885 void SvxBoxItem::SetLine( const SvxBorderLine
* pNew
, SvxBoxItemLine nLine
)
1887 std::unique_ptr
<SvxBorderLine
> pTmp( pNew
? new SvxBorderLine( *pNew
) : nullptr );
1891 case SvxBoxItemLine::TOP
:
1892 pTop
= std::move( pTmp
);
1894 case SvxBoxItemLine::BOTTOM
:
1895 pBottom
= std::move( pTmp
);
1897 case SvxBoxItemLine::LEFT
:
1898 pLeft
= std::move( pTmp
);
1900 case SvxBoxItemLine::RIGHT
:
1901 pRight
= std::move( pTmp
);
1904 OSL_FAIL( "wrong line" );
1909 sal_uInt16
SvxBoxItem::GetSmallestDistance() const
1911 // The smallest distance that is not 0 will be returned.
1912 sal_uInt16 nDist
= nTopDist
;
1913 if( nBottomDist
&& (!nDist
|| nBottomDist
< nDist
) )
1914 nDist
= nBottomDist
;
1915 if( nLeftDist
&& (!nDist
|| nLeftDist
< nDist
) )
1917 if( nRightDist
&& (!nDist
|| nRightDist
< nDist
) )
1924 sal_uInt16
SvxBoxItem::GetDistance( SvxBoxItemLine nLine
) const
1926 sal_uInt16 nDist
= 0;
1929 case SvxBoxItemLine::TOP
:
1932 case SvxBoxItemLine::BOTTOM
:
1933 nDist
= nBottomDist
;
1935 case SvxBoxItemLine::LEFT
:
1938 case SvxBoxItemLine::RIGHT
:
1942 OSL_FAIL( "wrong line" );
1949 void SvxBoxItem::SetDistance( sal_uInt16 nNew
, SvxBoxItemLine nLine
)
1953 case SvxBoxItemLine::TOP
:
1956 case SvxBoxItemLine::BOTTOM
:
1959 case SvxBoxItemLine::LEFT
:
1962 case SvxBoxItemLine::RIGHT
:
1966 OSL_FAIL( "wrong line" );
1970 sal_uInt16
SvxBoxItem::CalcLineWidth( SvxBoxItemLine nLine
) const
1972 SvxBorderLine
* pTmp
= nullptr;
1973 sal_uInt16 nWidth
= 0;
1976 case SvxBoxItemLine::TOP
:
1979 case SvxBoxItemLine::BOTTOM
:
1980 pTmp
= pBottom
.get();
1982 case SvxBoxItemLine::LEFT
:
1985 case SvxBoxItemLine::RIGHT
:
1986 pTmp
= pRight
.get();
1989 OSL_FAIL( "wrong line" );
1993 nWidth
= pTmp
->GetScaledWidth();
1998 sal_uInt16
SvxBoxItem::CalcLineSpace( SvxBoxItemLine nLine
, bool bEvenIfNoLine
) const
2000 SvxBorderLine
* pTmp
= nullptr;
2001 sal_uInt16 nDist
= 0;
2004 case SvxBoxItemLine::TOP
:
2008 case SvxBoxItemLine::BOTTOM
:
2009 pTmp
= pBottom
.get();
2010 nDist
= nBottomDist
;
2012 case SvxBoxItemLine::LEFT
:
2016 case SvxBoxItemLine::RIGHT
:
2017 pTmp
= pRight
.get();
2021 OSL_FAIL( "wrong line" );
2026 nDist
= nDist
+ pTmp
->GetScaledWidth();
2028 else if( !bEvenIfNoLine
)
2033 bool SvxBoxItem::HasBorder( bool bTreatPaddingAsBorder
) const
2035 return CalcLineSpace( SvxBoxItemLine::BOTTOM
, bTreatPaddingAsBorder
)
2036 || CalcLineSpace( SvxBoxItemLine::RIGHT
, bTreatPaddingAsBorder
)
2037 || CalcLineSpace( SvxBoxItemLine::TOP
, bTreatPaddingAsBorder
)
2038 || CalcLineSpace( SvxBoxItemLine::LEFT
, bTreatPaddingAsBorder
);
2041 // class SvxBoxInfoItem --------------------------------------------------
2043 SvxBoxInfoItem::SvxBoxInfoItem( const sal_uInt16 nId
) :
2045 mbEnableHor( false ),
2046 mbEnableVer( false ),
2049 bDist
= bMinDist
= false;
2054 SvxBoxInfoItem::SvxBoxInfoItem( const SvxBoxInfoItem
& rCpy
) :
2055 SfxPoolItem( rCpy
),
2056 pHori( rCpy
.pHori
? new SvxBorderLine( *rCpy
.pHori
) : nullptr ),
2057 pVert( rCpy
.pVert
? new SvxBorderLine( *rCpy
.pVert
) : nullptr ),
2058 mbEnableHor( rCpy
.mbEnableHor
),
2059 mbEnableVer( rCpy
.mbEnableVer
),
2060 bDist( rCpy
.bDist
),
2061 bMinDist ( rCpy
.bMinDist
),
2062 nValidFlags( rCpy
.nValidFlags
),
2063 nDefDist( rCpy
.nDefDist
)
2067 SvxBoxInfoItem::~SvxBoxInfoItem()
2071 bool SvxBoxInfoItem::operator==( const SfxPoolItem
& rAttr
) const
2073 assert(SfxPoolItem::operator==(rAttr
));
2075 const SvxBoxInfoItem
& rBoxInfo
= static_cast<const SvxBoxInfoItem
&>(rAttr
);
2077 return ( mbEnableHor
== rBoxInfo
.mbEnableHor
2078 && mbEnableVer
== rBoxInfo
.mbEnableVer
2079 && bDist
== rBoxInfo
.IsDist()
2080 && bMinDist
== rBoxInfo
.IsMinDist()
2081 && nValidFlags
== rBoxInfo
.nValidFlags
2082 && nDefDist
== rBoxInfo
.GetDefDist()
2083 && CmpBrdLn( pHori
, rBoxInfo
.GetHori() )
2084 && CmpBrdLn( pVert
, rBoxInfo
.GetVert() )
2089 void SvxBoxInfoItem::SetLine( const SvxBorderLine
* pNew
, SvxBoxInfoItemLine nLine
)
2091 std::unique_ptr
<SvxBorderLine
> pTmp( pNew
? new SvxBorderLine( *pNew
) : nullptr );
2093 if ( SvxBoxInfoItemLine::HORI
== nLine
)
2095 pHori
= std::move(pTmp
);
2097 else if ( SvxBoxInfoItemLine::VERT
== nLine
)
2099 pVert
= std::move(pTmp
);
2103 OSL_FAIL( "wrong line" );
2108 SfxPoolItem
* SvxBoxInfoItem::Clone( SfxItemPool
* ) const
2110 return new SvxBoxInfoItem( *this );
2114 bool SvxBoxInfoItem::GetPresentation
2116 SfxItemPresentation
/*ePres*/,
2117 MapUnit
/*eCoreUnit*/,
2118 MapUnit
/*ePresUnit*/,
2119 OUString
& rText
, const IntlWrapper
&
2127 void SvxBoxInfoItem::ScaleMetrics( long nMult
, long nDiv
)
2129 if ( pHori
) pHori
->ScaleMetrics( nMult
, nDiv
);
2130 if ( pVert
) pVert
->ScaleMetrics( nMult
, nDiv
);
2131 nDefDist
= static_cast<sal_uInt16
>(Scale( nDefDist
, nMult
, nDiv
));
2135 bool SvxBoxInfoItem::HasMetrics() const
2141 void SvxBoxInfoItem::ResetFlags()
2143 nValidFlags
= static_cast<SvxBoxInfoItemValidFlags
>(0x7F); // all valid except Disable
2146 bool SvxBoxInfoItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
2148 bool bConvert
= 0 != (nMemberId
& CONVERT_TWIPS
);
2149 table::BorderLine2 aRetLine
;
2151 bool bIntMember
= false;
2152 nMemberId
&= ~CONVERT_TWIPS
;
2157 // 2 BorderLines, flags, valid flags and distance
2158 css::uno::Sequence
< css::uno::Any
> aSeq( 5 );
2159 aSeq
[0] <<= SvxBoxItem::SvxLineToLine( pHori
.get(), bConvert
);
2160 aSeq
[1] <<= SvxBoxItem::SvxLineToLine( pVert
.get(), bConvert
);
2168 aSeq
[3] <<= static_cast<sal_Int16
>(nValidFlags
);
2169 aSeq
[4] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(GetDefDist()) : GetDefDist());
2174 case MID_HORIZONTAL
:
2175 aRetLine
= SvxBoxItem::SvxLineToLine( pHori
.get(), bConvert
);
2178 aRetLine
= SvxBoxItem::SvxLineToLine( pVert
.get(), bConvert
);
2190 case MID_VALIDFLAGS
:
2192 rVal
<<= static_cast<sal_Int16
>(nValidFlags
);
2196 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(GetDefDist()) : GetDefDist());
2198 default: OSL_FAIL("Wrong MemberId!"); return false;
2208 bool SvxBoxInfoItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
2210 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
2211 nMemberId
&= ~CONVERT_TWIPS
;
2217 css::uno::Sequence
< css::uno::Any
> aSeq
;
2218 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == 5 ))
2220 // 2 BorderLines, flags, valid flags and distance
2221 if (!lcl_setLine(aSeq
[0], *this, SvxBoxInfoItemLine::HORI
, bConvert
))
2223 if (!lcl_setLine(aSeq
[1], *this, SvxBoxInfoItemLine::VERT
, bConvert
))
2226 sal_Int16
nFlags( 0 );
2227 sal_Int32
nVal( 0 );
2228 if ( aSeq
[2] >>= nFlags
)
2230 SetTable ( ( nFlags
& 0x01 ) != 0 );
2231 SetDist ( ( nFlags
& 0x02 ) != 0 );
2232 SetMinDist( ( nFlags
& 0x04 ) != 0 );
2236 if ( aSeq
[3] >>= nFlags
)
2237 nValidFlags
= static_cast<SvxBoxInfoItemValidFlags
>(nFlags
);
2240 if (( aSeq
[4] >>= nVal
) && ( nVal
>= 0 ))
2243 nVal
= convertMm100ToTwip(nVal
);
2244 SetDefDist( static_cast<sal_uInt16
>(nVal
) );
2250 case MID_HORIZONTAL
:
2253 if( !rVal
.hasValue() )
2256 table::BorderLine2 aBorderLine
;
2257 if( lcl_extractBorderLine(rVal
, aBorderLine
) )
2261 else if (rVal
.getValueTypeClass() == uno::TypeClass_SEQUENCE
)
2263 // serialization for basic macro recording
2264 uno::Reference
< script::XTypeConverter
> xConverter( script::Converter::create(::comphelper::getProcessComponentContext()) );
2266 uno::Sequence
< uno::Any
> aSeq
;
2267 try { aNew
= xConverter
->convertTo( rVal
, cppu::UnoType
<uno::Sequence
< uno::Any
>>::get() ); }
2268 catch (const uno::Exception
&) {}
2270 if ((aNew
>>= aSeq
) &&
2271 aSeq
.getLength() >= 4 && aSeq
.getLength() <= 6)
2274 if ( aSeq
[0] >>= nVal
)
2275 aBorderLine
.Color
= nVal
;
2276 if ( aSeq
[1] >>= nVal
)
2277 aBorderLine
.InnerLineWidth
= static_cast<sal_Int16
>(nVal
);
2278 if ( aSeq
[2] >>= nVal
)
2279 aBorderLine
.OuterLineWidth
= static_cast<sal_Int16
>(nVal
);
2280 if ( aSeq
[3] >>= nVal
)
2281 aBorderLine
.LineDistance
= static_cast<sal_Int16
>(nVal
);
2282 if (aSeq
.getLength() >= 5) // fdo#40874 added fields
2284 if (aSeq
[4] >>= nVal
)
2286 aBorderLine
.LineStyle
= nVal
;
2288 if (aSeq
.getLength() >= 6)
2290 if (aSeq
[5] >>= nVal
)
2292 aBorderLine
.LineWidth
= nVal
;
2300 else if (rVal
.getValueType() == cppu::UnoType
<css::uno::Sequence
< sal_Int16
>>::get() )
2302 // serialization for basic macro recording
2303 css::uno::Sequence
< sal_Int16
> aSeq
;
2305 if (aSeq
.getLength() >= 4 && aSeq
.getLength() <= 6)
2307 aBorderLine
.Color
= aSeq
[0];
2308 aBorderLine
.InnerLineWidth
= aSeq
[1];
2309 aBorderLine
.OuterLineWidth
= aSeq
[2];
2310 aBorderLine
.LineDistance
= aSeq
[3];
2311 if (aSeq
.getLength() >= 5) // fdo#40874 added fields
2313 aBorderLine
.LineStyle
= aSeq
[4];
2314 if (aSeq
.getLength() >= 6)
2316 aBorderLine
.LineWidth
= aSeq
[5];
2326 SvxBorderLine aLine
;
2327 bool bSet
= SvxBoxItem::LineToSvxLine(aBorderLine
, aLine
, bConvert
);
2329 SetLine( &aLine
, nMemberId
== MID_HORIZONTAL
? SvxBoxInfoItemLine::HORI
: SvxBoxInfoItemLine::VERT
);
2334 sal_Int16 nFlags
= sal_Int16();
2335 bRet
= (rVal
>>= nFlags
);
2338 SetTable ( ( nFlags
& 0x01 ) != 0 );
2339 SetDist ( ( nFlags
& 0x02 ) != 0 );
2340 SetMinDist( ( nFlags
& 0x04 ) != 0 );
2345 case MID_VALIDFLAGS
:
2347 sal_Int16 nFlags
= sal_Int16();
2348 bRet
= (rVal
>>= nFlags
);
2350 nValidFlags
= static_cast<SvxBoxInfoItemValidFlags
>(nFlags
);
2356 bRet
= (rVal
>>= nVal
);
2357 if ( bRet
&& nVal
>=0 )
2360 nVal
= convertMm100ToTwip(nVal
);
2361 SetDefDist( static_cast<sal_uInt16
>(nVal
) );
2365 default: OSL_FAIL("Wrong MemberId!"); return false;
2375 void BorderDistanceFromWord(bool bFromEdge
, sal_Int32
& nMargin
, sal_Int32
& nBorderDistance
,
2376 sal_Int32 nBorderWidth
)
2378 // See https://wiki.openoffice.org/wiki/Writer/MSInteroperability/PageBorder
2380 sal_Int32 nNewMargin
= nMargin
;
2381 sal_Int32 nNewBorderDistance
= nBorderDistance
;
2385 nNewMargin
= nBorderDistance
;
2386 nNewBorderDistance
= nMargin
- nBorderDistance
- nBorderWidth
;
2390 nNewMargin
-= nBorderDistance
+ nBorderWidth
;
2393 // Ensure correct distance from page edge to text in cases not supported by us:
2394 // when border is outside entire page area (!bFromEdge && BorderDistance > Margin),
2395 // and when border is inside page body area (bFromEdge && BorderDistance > Margin)
2399 nNewBorderDistance
= std::max
<sal_Int32
>(nMargin
- nBorderWidth
, 0);
2401 else if (nNewBorderDistance
< 0)
2403 nNewMargin
= std::max
<sal_Int32
>(nMargin
- nBorderWidth
, 0);
2404 nNewBorderDistance
= 0;
2407 nMargin
= nNewMargin
;
2408 nBorderDistance
= nNewBorderDistance
;
2411 // Heuristics to decide if we need to use "from edge" offset of borders
2413 // There are two cases when we can safely use "from text" or "from edge" offset without distorting
2414 // border position (modulo rounding errors):
2415 // 1. When distance of all borders from text is no greater than 31 pt, we use "from text"
2416 // 2. Otherwise, if distance of all borders from edge is no greater than 31 pt, we use "from edge"
2417 // In all other cases, the position of borders would be distorted on export, because Word doesn't
2418 // support the offset of >31 pts (https://msdn.microsoft.com/en-us/library/ff533820), and we need
2419 // to decide which type of offset would provide less wrong result (i.e., the result would look
2420 // closer to original). Here, we just check sum of distances from text to borders, and if it is
2421 // less than sum of distances from borders to edges. The alternative would be to compare total areas
2422 // between text-and-borders and between borders-and-edges (taking into account different lengths of
2423 // borders, and visual impact of that).
2424 void BorderDistancesToWord(const SvxBoxItem
& rBox
, const WordPageMargins
& rMargins
,
2425 WordBorderDistances
& rDistances
)
2427 // Use signed sal_Int32 that can hold sal_uInt16, to prevent overflow at subtraction below
2428 const sal_Int32 nT
= rBox
.GetDistance(SvxBoxItemLine::TOP
);
2429 const sal_Int32 nL
= rBox
.GetDistance(SvxBoxItemLine::LEFT
);
2430 const sal_Int32 nB
= rBox
.GetDistance(SvxBoxItemLine::BOTTOM
);
2431 const sal_Int32 nR
= rBox
.GetDistance(SvxBoxItemLine::RIGHT
);
2433 // Only take into account existing borders
2434 const SvxBorderLine
* pLnT
= rBox
.GetLine(SvxBoxItemLine::TOP
);
2435 const SvxBorderLine
* pLnL
= rBox
.GetLine(SvxBoxItemLine::LEFT
);
2436 const SvxBorderLine
* pLnB
= rBox
.GetLine(SvxBoxItemLine::BOTTOM
);
2437 const SvxBorderLine
* pLnR
= rBox
.GetLine(SvxBoxItemLine::RIGHT
);
2439 // We need to take border widths into account
2440 const long nWidthT
= pLnT
? pLnT
->GetScaledWidth() : 0;
2441 const long nWidthL
= pLnL
? pLnL
->GetScaledWidth() : 0;
2442 const long nWidthB
= pLnB
? pLnB
->GetScaledWidth() : 0;
2443 const long nWidthR
= pLnR
? pLnR
->GetScaledWidth() : 0;
2445 // Resulting distances from text to borders
2446 const sal_Int32 nT2BT
= pLnT
? nT
: 0;
2447 const sal_Int32 nT2BL
= pLnL
? nL
: 0;
2448 const sal_Int32 nT2BB
= pLnB
? nB
: 0;
2449 const sal_Int32 nT2BR
= pLnR
? nR
: 0;
2451 // Resulting distances from edge to borders
2452 const sal_Int32 nE2BT
= pLnT
? std::max
<sal_Int32
>(rMargins
.nTop
- nT
- nWidthT
, 0) : 0;
2453 const sal_Int32 nE2BL
= pLnL
? std::max
<sal_Int32
>(rMargins
.nLeft
- nL
- nWidthL
, 0) : 0;
2454 const sal_Int32 nE2BB
= pLnB
? std::max
<sal_Int32
>(rMargins
.nBottom
- nB
- nWidthB
, 0) : 0;
2455 const sal_Int32 nE2BR
= pLnR
? std::max
<sal_Int32
>(rMargins
.nRight
- nR
- nWidthR
, 0) : 0;
2457 const sal_Int32 n32pt
= 32 * 20;
2458 // 1. If all borders are in range of 31 pts from text
2459 if (nT2BT
< n32pt
&& nT2BL
< n32pt
&& nT2BB
< n32pt
&& nT2BR
< n32pt
)
2461 rDistances
.bFromEdge
= false;
2465 // 2. If all borders are in range of 31 pts from edge
2466 if (nE2BT
< n32pt
&& nE2BL
< n32pt
&& nE2BB
< n32pt
&& nE2BR
< n32pt
)
2468 rDistances
.bFromEdge
= true;
2472 // Let's try to guess which would be the best approximation
2473 rDistances
.bFromEdge
=
2474 (nT2BT
+ nT2BL
+ nT2BB
+ nT2BR
) > (nE2BT
+ nE2BL
+ nE2BB
+ nE2BR
);
2478 if (rDistances
.bFromEdge
)
2480 rDistances
.nTop
= sal::static_int_cast
<sal_uInt16
>(nE2BT
);
2481 rDistances
.nLeft
= sal::static_int_cast
<sal_uInt16
>(nE2BL
);
2482 rDistances
.nBottom
= sal::static_int_cast
<sal_uInt16
>(nE2BB
);
2483 rDistances
.nRight
= sal::static_int_cast
<sal_uInt16
>(nE2BR
);
2487 rDistances
.nTop
= sal::static_int_cast
<sal_uInt16
>(nT2BT
);
2488 rDistances
.nLeft
= sal::static_int_cast
<sal_uInt16
>(nT2BL
);
2489 rDistances
.nBottom
= sal::static_int_cast
<sal_uInt16
>(nT2BB
);
2490 rDistances
.nRight
= sal::static_int_cast
<sal_uInt16
>(nT2BR
);
2496 // class SvxFormatBreakItem -------------------------------------------------
2498 bool SvxFormatBreakItem::operator==( const SfxPoolItem
& rAttr
) const
2500 assert(SfxPoolItem::operator==(rAttr
));
2502 return GetValue() == static_cast<const SvxFormatBreakItem
&>( rAttr
).GetValue();
2506 bool SvxFormatBreakItem::GetPresentation
2508 SfxItemPresentation
/*ePres*/,
2509 MapUnit
/*eCoreUnit*/,
2510 MapUnit
/*ePresUnit*/,
2511 OUString
& rText
, const IntlWrapper
&
2514 rText
= GetValueTextByPos( GetEnumValue() );
2518 OUString
SvxFormatBreakItem::GetValueTextByPos( sal_uInt16 nPos
)
2520 static const char* RID_SVXITEMS_BREAK
[] =
2522 RID_SVXITEMS_BREAK_NONE
,
2523 RID_SVXITEMS_BREAK_COLUMN_BEFORE
,
2524 RID_SVXITEMS_BREAK_COLUMN_AFTER
,
2525 RID_SVXITEMS_BREAK_COLUMN_BOTH
,
2526 RID_SVXITEMS_BREAK_PAGE_BEFORE
,
2527 RID_SVXITEMS_BREAK_PAGE_AFTER
,
2528 RID_SVXITEMS_BREAK_PAGE_BOTH
2530 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_BREAK
) == size_t(SvxBreak::End
), "unexpected size");
2531 assert(nPos
< sal_uInt16(SvxBreak::End
) && "enum overflow!");
2532 return EditResId(RID_SVXITEMS_BREAK
[nPos
]);
2535 bool SvxFormatBreakItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
2537 style::BreakType eBreak
= style::BreakType_NONE
;
2538 switch ( GetBreak() )
2540 case SvxBreak::ColumnBefore
: eBreak
= style::BreakType_COLUMN_BEFORE
; break;
2541 case SvxBreak::ColumnAfter
: eBreak
= style::BreakType_COLUMN_AFTER
; break;
2542 case SvxBreak::ColumnBoth
: eBreak
= style::BreakType_COLUMN_BOTH
; break;
2543 case SvxBreak::PageBefore
: eBreak
= style::BreakType_PAGE_BEFORE
; break;
2544 case SvxBreak::PageAfter
: eBreak
= style::BreakType_PAGE_AFTER
; break;
2545 case SvxBreak::PageBoth
: eBreak
= style::BreakType_PAGE_BOTH
; break;
2546 default: ; // prevent warning
2552 bool SvxFormatBreakItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
2554 style::BreakType nBreak
;
2556 if(!(rVal
>>= nBreak
))
2558 sal_Int32 nValue
= 0;
2559 if(!(rVal
>>= nValue
))
2562 nBreak
= static_cast<style::BreakType
>(nValue
);
2565 SvxBreak eBreak
= SvxBreak::NONE
;
2568 case style::BreakType_COLUMN_BEFORE
: eBreak
= SvxBreak::ColumnBefore
; break;
2569 case style::BreakType_COLUMN_AFTER
: eBreak
= SvxBreak::ColumnAfter
; break;
2570 case style::BreakType_COLUMN_BOTH
: eBreak
= SvxBreak::ColumnBoth
; break;
2571 case style::BreakType_PAGE_BEFORE
: eBreak
= SvxBreak::PageBefore
; break;
2572 case style::BreakType_PAGE_AFTER
: eBreak
= SvxBreak::PageAfter
; break;
2573 case style::BreakType_PAGE_BOTH
: eBreak
= SvxBreak::PageBoth
; break;
2574 default: ; // prevent warning
2582 SfxPoolItem
* SvxFormatBreakItem::Clone( SfxItemPool
* ) const
2584 return new SvxFormatBreakItem( *this );
2588 sal_uInt16
SvxFormatBreakItem::GetValueCount() const
2590 return sal_uInt16(SvxBreak::End
); // SvxBreak::PageBoth + 1
2594 SfxPoolItem
* SvxFormatKeepItem::Clone( SfxItemPool
* ) const
2596 return new SvxFormatKeepItem( *this );
2600 bool SvxFormatKeepItem::GetPresentation
2602 SfxItemPresentation
/*ePres*/,
2603 MapUnit
/*eCoreUnit*/,
2604 MapUnit
/*ePresUnit*/,
2605 OUString
& rText
, const IntlWrapper
&
2608 const char* pId
= RID_SVXITEMS_FMTKEEP_FALSE
;
2611 pId
= RID_SVXITEMS_FMTKEEP_TRUE
;
2612 rText
= EditResId(pId
);
2617 SvxLineItem::SvxLineItem( const sal_uInt16 nId
) :
2623 SvxLineItem::SvxLineItem( const SvxLineItem
& rCpy
) :
2624 SfxPoolItem ( rCpy
),
2625 pLine(rCpy
.pLine
? new SvxBorderLine( *rCpy
.pLine
) : nullptr)
2630 SvxLineItem::~SvxLineItem()
2635 bool SvxLineItem::operator==( const SfxPoolItem
& rAttr
) const
2637 assert(SfxPoolItem::operator==(rAttr
));
2639 return CmpBrdLn( pLine
, static_cast<const SvxLineItem
&>(rAttr
).GetLine() );
2643 SfxPoolItem
* SvxLineItem::Clone( SfxItemPool
* ) const
2645 return new SvxLineItem( *this );
2649 bool SvxLineItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemId
) const
2651 bool bConvert
= 0!=(nMemId
&CONVERT_TWIPS
);
2652 nMemId
&= ~CONVERT_TWIPS
;
2655 rVal
<<= SvxBoxItem::SvxLineToLine(pLine
.get(), bConvert
);
2662 case MID_FG_COLOR
: rVal
<<= pLine
->GetColor(); break;
2663 case MID_OUTER_WIDTH
: rVal
<<= sal_Int32(pLine
->GetOutWidth()); break;
2664 case MID_INNER_WIDTH
: rVal
<<= sal_Int32(pLine
->GetInWidth( )); break;
2665 case MID_DISTANCE
: rVal
<<= sal_Int32(pLine
->GetDistance()); break;
2667 OSL_FAIL( "Wrong MemberId" );
2676 bool SvxLineItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemId
)
2678 bool bConvert
= 0!=(nMemId
&CONVERT_TWIPS
);
2679 nMemId
&= ~CONVERT_TWIPS
;
2683 table::BorderLine2 aLine
;
2684 if ( lcl_extractBorderLine(rVal
, aLine
) )
2687 pLine
.reset( new SvxBorderLine
);
2688 if( !SvxBoxItem::LineToSvxLine(aLine
, *pLine
, bConvert
) )
2694 else if ( rVal
>>= nVal
)
2697 pLine
.reset( new SvxBorderLine
);
2701 case MID_FG_COLOR
: pLine
->SetColor( Color(nVal
) ); break;
2702 case MID_LINE_STYLE
:
2703 pLine
->SetBorderLineStyle(static_cast<SvxBorderLineStyle
>(nVal
));
2706 OSL_FAIL( "Wrong MemberId" );
2717 bool SvxLineItem::GetPresentation
2719 SfxItemPresentation ePres
,
2722 OUString
& rText
, const IntlWrapper
& rIntl
2728 rText
= pLine
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
,
2729 (SfxItemPresentation::Complete
== ePres
) );
2734 void SvxLineItem::ScaleMetrics( long nMult
, long nDiv
)
2736 if ( pLine
) pLine
->ScaleMetrics( nMult
, nDiv
);
2740 bool SvxLineItem::HasMetrics() const
2746 void SvxLineItem::SetLine( const SvxBorderLine
* pNew
)
2748 pLine
.reset( pNew
? new SvxBorderLine( *pNew
) : nullptr );
2751 SvxBrushItem::SvxBrushItem(sal_uInt16 _nWhich
)
2752 : SfxPoolItem(_nWhich
)
2753 , aColor(COL_TRANSPARENT
)
2754 , nShadingValue(ShadingPattern::CLEAR
)
2755 , nGraphicTransparency(0)
2756 , eGraphicPos(GPOS_NONE
)
2761 SvxBrushItem::SvxBrushItem(const Color
& rColor
, sal_uInt16 _nWhich
)
2762 : SfxPoolItem(_nWhich
)
2764 , nShadingValue(ShadingPattern::CLEAR
)
2765 , nGraphicTransparency(0)
2766 , eGraphicPos(GPOS_NONE
)
2771 SvxBrushItem::SvxBrushItem(const Graphic
& rGraphic
, SvxGraphicPosition ePos
, sal_uInt16 _nWhich
)
2772 : SfxPoolItem(_nWhich
)
2773 , aColor(COL_TRANSPARENT
)
2774 , nShadingValue(ShadingPattern::CLEAR
)
2775 , xGraphicObject(new GraphicObject(rGraphic
))
2776 , nGraphicTransparency(0)
2777 , eGraphicPos((GPOS_NONE
!= ePos
) ? ePos
: GPOS_MM
)
2780 DBG_ASSERT( GPOS_NONE
!= ePos
, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
2783 SvxBrushItem::SvxBrushItem(const GraphicObject
& rGraphicObj
, SvxGraphicPosition ePos
, sal_uInt16 _nWhich
)
2784 : SfxPoolItem(_nWhich
)
2785 , aColor(COL_TRANSPARENT
)
2786 , nShadingValue(ShadingPattern::CLEAR
)
2787 , xGraphicObject(new GraphicObject(rGraphicObj
))
2788 , nGraphicTransparency(0)
2789 , eGraphicPos((GPOS_NONE
!= ePos
) ? ePos
: GPOS_MM
)
2792 DBG_ASSERT( GPOS_NONE
!= ePos
, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
2795 SvxBrushItem::SvxBrushItem(const OUString
& rLink
, const OUString
& rFilter
,
2796 SvxGraphicPosition ePos
, sal_uInt16 _nWhich
)
2797 : SfxPoolItem(_nWhich
)
2798 , aColor(COL_TRANSPARENT
)
2799 , nShadingValue(ShadingPattern::CLEAR
)
2800 , nGraphicTransparency(0)
2802 , maStrFilter(rFilter
)
2803 , eGraphicPos((GPOS_NONE
!= ePos
) ? ePos
: GPOS_MM
)
2806 DBG_ASSERT( GPOS_NONE
!= ePos
, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
2809 SvxBrushItem::SvxBrushItem(const SvxBrushItem
& rItem
)
2810 : SfxPoolItem(rItem
)
2811 , aColor(rItem
.aColor
)
2812 , nShadingValue(rItem
.nShadingValue
)
2813 , xGraphicObject(rItem
.xGraphicObject
? new GraphicObject(*rItem
.xGraphicObject
) : nullptr)
2814 , nGraphicTransparency(rItem
.nGraphicTransparency
)
2815 , maStrLink(rItem
.maStrLink
)
2816 , maStrFilter(rItem
.maStrFilter
)
2817 , eGraphicPos(rItem
.eGraphicPos
)
2818 , bLoadAgain(rItem
.bLoadAgain
)
2822 SvxBrushItem::SvxBrushItem(SvxBrushItem
&& rItem
)
2823 : SfxPoolItem(std::move(rItem
))
2824 , aColor(std::move(rItem
.aColor
))
2825 , nShadingValue(std::move(rItem
.nShadingValue
))
2826 , xGraphicObject(std::move(rItem
.xGraphicObject
))
2827 , nGraphicTransparency(std::move(rItem
.nGraphicTransparency
))
2828 , maStrLink(std::move(rItem
.maStrLink
))
2829 , maStrFilter(std::move(rItem
.maStrFilter
))
2830 , eGraphicPos(std::move(rItem
.eGraphicPos
))
2831 , bLoadAgain(std::move(rItem
.bLoadAgain
))
2835 SvxBrushItem::~SvxBrushItem()
2839 bool SvxBrushItem::isUsed() const
2841 if (GPOS_NONE
!= GetGraphicPos())
2846 else if (0xff != GetColor().GetTransparency())
2856 static sal_Int8
lcl_PercentToTransparency(long nPercent
)
2858 // 0xff must not be returned!
2859 return sal_Int8(nPercent
? (50 + 0xfe * nPercent
) / 100 : 0);
2863 sal_Int8
SvxBrushItem::TransparencyToPercent(sal_Int32 nTrans
)
2865 return static_cast<sal_Int8
>((nTrans
* 100 + 127) / 254);
2869 bool SvxBrushItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
2871 nMemberId
&= ~CONVERT_TWIPS
;
2874 case MID_BACK_COLOR
:
2877 case MID_BACK_COLOR_R_G_B
:
2878 rVal
<<= aColor
.GetRGBColor();
2880 case MID_BACK_COLOR_TRANSPARENCY
:
2881 rVal
<<= SvxBrushItem::TransparencyToPercent(aColor
.GetTransparency());
2883 case MID_GRAPHIC_POSITION
:
2884 rVal
<<= static_cast<style::GraphicLocation
>(static_cast<sal_Int16
>(eGraphicPos
));
2887 case MID_GRAPHIC_TRANSPARENT
:
2888 rVal
<<= ( aColor
.GetTransparency() == 0xff );
2891 case MID_GRAPHIC_URL
:
2893 SAL_INFO("editeng.items", "Getting GraphicURL property is not supported");
2899 uno::Reference
<graphic::XGraphic
> xGraphic
;
2900 if (!maStrLink
.isEmpty())
2902 Graphic
aGraphic(vcl::graphic::loadFromURL(maStrLink
));
2903 xGraphic
= aGraphic
.GetXGraphic();
2905 else if (xGraphicObject
)
2907 xGraphic
= xGraphicObject
->GetGraphic().GetXGraphic();
2913 case MID_GRAPHIC_FILTER
:
2915 rVal
<<= maStrFilter
;
2919 case MID_GRAPHIC_TRANSPARENCY
:
2920 rVal
<<= nGraphicTransparency
;
2923 case MID_SHADING_VALUE
:
2925 rVal
<<= nShadingValue
;
2934 bool SvxBrushItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
2936 nMemberId
&= ~CONVERT_TWIPS
;
2939 case MID_BACK_COLOR
:
2940 case MID_BACK_COLOR_R_G_B
:
2943 if ( !( rVal
>>= aNewCol
) )
2945 if(MID_BACK_COLOR_R_G_B
== nMemberId
)
2947 aNewCol
.SetTransparency(aColor
.GetTransparency());
2952 case MID_BACK_COLOR_TRANSPARENCY
:
2954 sal_Int32 nTrans
= 0;
2955 if ( !( rVal
>>= nTrans
) || nTrans
< 0 || nTrans
> 100 )
2957 aColor
.SetTransparency(lcl_PercentToTransparency(nTrans
));
2961 case MID_GRAPHIC_POSITION
:
2963 style::GraphicLocation eLocation
;
2964 if ( !( rVal
>>=eLocation
) )
2966 sal_Int32 nValue
= 0;
2967 if ( !( rVal
>>= nValue
) )
2969 eLocation
= static_cast<style::GraphicLocation
>(nValue
);
2971 SetGraphicPos( static_cast<SvxGraphicPosition
>(static_cast<sal_uInt16
>(eLocation
)) );
2975 case MID_GRAPHIC_TRANSPARENT
:
2976 aColor
.SetTransparency( Any2Bool( rVal
) ? 0xff : 0 );
2979 case MID_GRAPHIC_URL
:
2984 if (rVal
.getValueType() == ::cppu::UnoType
<OUString
>::get())
2986 OUString aURL
= rVal
.get
<OUString
>();
2987 aGraphic
= vcl::graphic::loadFromURL(aURL
);
2989 else if (rVal
.getValueType() == cppu::UnoType
<graphic::XGraphic
>::get())
2991 auto xGraphic
= rVal
.get
<uno::Reference
<graphic::XGraphic
>>();
2992 aGraphic
= Graphic(xGraphic
);
2995 if (!aGraphic
.IsNone())
2999 std::unique_ptr
<GraphicObject
> xOldGrfObj(std::move(xGraphicObject
));
3000 xGraphicObject
.reset(new GraphicObject(aGraphic
));
3001 ApplyGraphicTransparency_Impl();
3004 if (!aGraphic
.IsNone() && eGraphicPos
== GPOS_NONE
)
3006 eGraphicPos
= GPOS_MM
;
3008 else if (aGraphic
.IsNone())
3010 eGraphicPos
= GPOS_NONE
;
3016 case MID_GRAPHIC_FILTER
:
3018 if( rVal
.getValueType() == ::cppu::UnoType
<OUString
>::get() )
3022 SetGraphicFilter( sLink
);
3026 case MID_GRAPHIC_TRANSPARENCY
:
3030 if(nTmp
>= 0 && nTmp
<= 100)
3032 nGraphicTransparency
= sal_Int8(nTmp
);
3034 ApplyGraphicTransparency_Impl();
3039 case MID_SHADING_VALUE
:
3042 if (!(rVal
>>= nVal
))
3045 nShadingValue
= nVal
;
3054 bool SvxBrushItem::GetPresentation
3056 SfxItemPresentation
/*ePres*/,
3057 MapUnit
/*eCoreUnit*/,
3058 MapUnit
/*ePresUnit*/,
3059 OUString
& rText
, const IntlWrapper
&
3062 if ( GPOS_NONE
== eGraphicPos
)
3064 rText
= ::GetColorString( aColor
) + OUString(cpDelim
);
3065 const char* pId
= RID_SVXITEMS_TRANSPARENT_FALSE
;
3067 if ( aColor
.GetTransparency() )
3068 pId
= RID_SVXITEMS_TRANSPARENT_TRUE
;
3069 rText
+= EditResId(pId
);
3073 rText
= EditResId(RID_SVXITEMS_GRAPHIC
);
3079 bool SvxBrushItem::operator==( const SfxPoolItem
& rAttr
) const
3081 assert(SfxPoolItem::operator==(rAttr
));
3083 const SvxBrushItem
& rCmp
= static_cast<const SvxBrushItem
&>(rAttr
);
3084 bool bEqual
= ( aColor
== rCmp
.aColor
&& eGraphicPos
== rCmp
.eGraphicPos
&&
3085 nGraphicTransparency
== rCmp
.nGraphicTransparency
);
3089 if ( GPOS_NONE
!= eGraphicPos
)
3091 bEqual
= maStrLink
== rCmp
.maStrLink
;
3095 bEqual
= maStrFilter
== rCmp
.maStrFilter
;
3100 if (!rCmp
.xGraphicObject
)
3101 bEqual
= !xGraphicObject
;
3103 bEqual
= xGraphicObject
&&
3104 (*xGraphicObject
== *rCmp
.xGraphicObject
);
3110 bEqual
= nShadingValue
== rCmp
.nShadingValue
;
3118 SfxPoolItem
* SvxBrushItem::Clone( SfxItemPool
* ) const
3120 return new SvxBrushItem( *this );
3124 const GraphicObject
* SvxBrushItem::GetGraphicObject(OUString
const & referer
) const
3126 if (bLoadAgain
&& !maStrLink
.isEmpty() && !xGraphicObject
)
3127 // when graphics already loaded, use as a cache
3129 if (maSecOptions
.isUntrustedReferer(referer
)) {
3133 // tdf#94088 prepare graphic and state
3135 bool bGraphicLoaded
= false;
3137 // try to create stream directly from given URL
3138 std::unique_ptr
<SvStream
> xStream(utl::UcbStreamHelper::CreateStream(maStrLink
, StreamMode::STD_READ
));
3139 // tdf#94088 if we have a stream, try to load it directly as graphic
3140 if (xStream
&& !xStream
->GetError())
3142 if (ERRCODE_NONE
== GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, maStrLink
, *xStream
,
3143 GRFILTER_FORMAT_DONTKNOW
, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg
))
3145 bGraphicLoaded
= true;
3149 // tdf#94088 if no succeeded, try if the string (which is not empty) contains
3150 // a 'data:' scheme url and try to load that (embedded graphics)
3153 INetURLObject
aGraphicURL( maStrLink
);
3155 if( INetProtocol::Data
== aGraphicURL
.GetProtocol() )
3157 std::unique_ptr
<SvMemoryStream
> const xMemStream(aGraphicURL
.getData());
3160 if (ERRCODE_NONE
== GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, "", *xMemStream
))
3162 bGraphicLoaded
= true;
3164 // tdf#94088 delete the no longer needed data scheme URL which
3165 // is potentially pretty // large, containing a base64 encoded copy of the graphic
3166 const_cast< SvxBrushItem
* >(this)->maStrLink
.clear();
3172 // tdf#94088 when we got a graphic, set it
3173 if(bGraphicLoaded
&& GraphicType::NONE
!= aGraphic
.GetType())
3175 xGraphicObject
.reset(new GraphicObject
);
3176 xGraphicObject
->SetGraphic(aGraphic
);
3177 const_cast < SvxBrushItem
*> (this)->ApplyGraphicTransparency_Impl();
3185 return xGraphicObject
.get();
3188 void SvxBrushItem::setGraphicTransparency(sal_Int8 nNew
)
3190 if (nNew
!= nGraphicTransparency
)
3192 nGraphicTransparency
= nNew
;
3193 ApplyGraphicTransparency_Impl();
3197 const Graphic
* SvxBrushItem::GetGraphic(OUString
const & referer
) const
3199 const GraphicObject
* pGrafObj
= GetGraphicObject(referer
);
3200 return( pGrafObj
? &( pGrafObj
->GetGraphic() ) : nullptr );
3203 void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew
)
3207 if ( GPOS_NONE
== eGraphicPos
)
3209 xGraphicObject
.reset();
3211 maStrFilter
.clear();
3215 if (!xGraphicObject
&& maStrLink
.isEmpty())
3217 xGraphicObject
.reset(new GraphicObject
); // Creating a dummy
3222 void SvxBrushItem::SetGraphic( const Graphic
& rNew
)
3224 if ( maStrLink
.isEmpty() )
3227 xGraphicObject
->SetGraphic(rNew
);
3229 xGraphicObject
.reset(new GraphicObject(rNew
));
3231 ApplyGraphicTransparency_Impl();
3233 if ( GPOS_NONE
== eGraphicPos
)
3234 eGraphicPos
= GPOS_MM
; // None would be brush, then Default: middle
3238 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
3242 void SvxBrushItem::SetGraphicObject( const GraphicObject
& rNewObj
)
3244 if ( maStrLink
.isEmpty() )
3247 *xGraphicObject
= rNewObj
;
3249 xGraphicObject
.reset(new GraphicObject(rNewObj
));
3251 ApplyGraphicTransparency_Impl();
3253 if ( GPOS_NONE
== eGraphicPos
)
3254 eGraphicPos
= GPOS_MM
; // None would be brush, then Default: middle
3258 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
3262 void SvxBrushItem::SetGraphicLink( const OUString
& rNew
)
3264 if ( rNew
.isEmpty() )
3269 xGraphicObject
.reset();
3273 void SvxBrushItem::SetGraphicFilter( const OUString
& rNew
)
3278 void SvxBrushItem::ApplyGraphicTransparency_Impl()
3280 DBG_ASSERT(xGraphicObject
, "no GraphicObject available" );
3283 GraphicAttr
aAttr(xGraphicObject
->GetAttr());
3284 aAttr
.SetTransparency(lcl_PercentToTransparency(
3285 nGraphicTransparency
));
3286 xGraphicObject
->SetAttr(aAttr
);
3290 void SvxBrushItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
3292 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxBrushItem"));
3293 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
3294 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("color"), BAD_CAST(aColor
.AsRGBHexString().toUtf8().getStr()));
3295 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("shadingValue"), BAD_CAST(OString::number(nShadingValue
).getStr()));
3296 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("link"), BAD_CAST(maStrLink
.toUtf8().getStr()));
3297 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("filter"), BAD_CAST(maStrFilter
.toUtf8().getStr()));
3298 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("graphicPos"), BAD_CAST(OString::number(eGraphicPos
).getStr()));
3299 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("loadAgain"), BAD_CAST(OString::boolean(bLoadAgain
).getStr()));
3300 xmlTextWriterEndElement(pWriter
);
3304 SvxFrameDirectionItem::SvxFrameDirectionItem( SvxFrameDirection nValue
,
3305 sal_uInt16 _nWhich
)
3306 : SfxEnumItem
<SvxFrameDirection
>( _nWhich
, nValue
)
3311 SvxFrameDirectionItem::~SvxFrameDirectionItem()
3316 SfxPoolItem
* SvxFrameDirectionItem::Clone( SfxItemPool
* ) const
3318 return new SvxFrameDirectionItem( *this );
3322 const char* getFrmDirResId(size_t nIndex
)
3324 const char* const RID_SVXITEMS_FRMDIR
[] =
3326 RID_SVXITEMS_FRMDIR_HORI_LEFT_TOP
,
3327 RID_SVXITEMS_FRMDIR_HORI_RIGHT_TOP
,
3328 RID_SVXITEMS_FRMDIR_VERT_TOP_RIGHT
,
3329 RID_SVXITEMS_FRMDIR_VERT_TOP_LEFT
,
3330 RID_SVXITEMS_FRMDIR_ENVIRONMENT
3332 return RID_SVXITEMS_FRMDIR
[nIndex
];
3335 bool SvxFrameDirectionItem::GetPresentation(
3336 SfxItemPresentation
/*ePres*/,
3337 MapUnit
/*eCoreUnit*/,
3338 MapUnit
/*ePresUnit*/,
3339 OUString
& rText
, const IntlWrapper
&) const
3341 rText
= EditResId(getFrmDirResId(GetEnumValue()));
3345 bool SvxFrameDirectionItem::PutValue( const css::uno::Any
& rVal
,
3348 sal_Int16 nVal
= sal_Int16();
3349 bool bRet
= ( rVal
>>= nVal
);
3352 // translate WritingDirection2 constants into SvxFrameDirection
3355 case text::WritingMode2::LR_TB
:
3356 SetValue( SvxFrameDirection::Horizontal_LR_TB
);
3358 case text::WritingMode2::RL_TB
:
3359 SetValue( SvxFrameDirection::Horizontal_RL_TB
);
3361 case text::WritingMode2::TB_RL
:
3362 SetValue( SvxFrameDirection::Vertical_RL_TB
);
3364 case text::WritingMode2::TB_LR
:
3365 SetValue( SvxFrameDirection::Vertical_LR_TB
);
3367 case text::WritingMode2::BT_LR
:
3368 SetValue( SvxFrameDirection::Vertical_LR_BT
);
3370 case text::WritingMode2::PAGE
:
3371 SetValue( SvxFrameDirection::Environment
);
3383 bool SvxFrameDirectionItem::QueryValue( css::uno::Any
& rVal
,
3386 // translate SvxFrameDirection into WritingDirection2
3389 switch( GetValue() )
3391 case SvxFrameDirection::Horizontal_LR_TB
:
3392 nVal
= text::WritingMode2::LR_TB
;
3394 case SvxFrameDirection::Horizontal_RL_TB
:
3395 nVal
= text::WritingMode2::RL_TB
;
3397 case SvxFrameDirection::Vertical_RL_TB
:
3398 nVal
= text::WritingMode2::TB_RL
;
3400 case SvxFrameDirection::Vertical_LR_TB
:
3401 nVal
= text::WritingMode2::TB_LR
;
3403 case SvxFrameDirection::Vertical_LR_BT
:
3404 nVal
= text::WritingMode2::BT_LR
;
3406 case SvxFrameDirection::Environment
:
3407 nVal
= text::WritingMode2::PAGE
;
3410 OSL_FAIL("Unknown SvxFrameDirection value!");
3415 // return value + error state
3423 void SvxFrameDirectionItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
3425 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxFrameDirectionItem"));
3426 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("m_nWhich"),
3427 BAD_CAST(OString::number(Which()).getStr()));
3428 xmlTextWriterWriteAttribute(
3429 pWriter
, BAD_CAST("m_nValue"),
3430 BAD_CAST(OString::number(static_cast<sal_Int16
>(GetValue())).getStr()));
3431 xmlTextWriterEndElement(pWriter
);
3434 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */