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());
559 rText
+= GetMetricText( nLeftMargin
, eCoreUnit
, ePresUnit
, &rIntl
) +
560 " " + EditResId(GetMetricId(ePresUnit
));
562 rText
+= OUString(cpDelim
);
563 if ( 100 != nPropFirstLineOfst
|| nFirstLineOfst
)
565 rText
+= EditResId(RID_SVXITEMS_LRSPACE_FLINE
);
566 if ( 100 != nPropFirstLineOfst
)
567 rText
+= unicode::formatPercent(nPropFirstLineOfst
,
568 Application::GetSettings().GetUILanguageTag());
571 rText
+= GetMetricText( static_cast<long>(nFirstLineOfst
),
572 eCoreUnit
, ePresUnit
, &rIntl
) +
573 " " + EditResId(GetMetricId(ePresUnit
));
575 rText
+= OUString(cpDelim
);
577 rText
+= EditResId(RID_SVXITEMS_LRSPACE_RIGHT
);
578 if ( 100 != nPropRightMargin
)
579 rText
+= unicode::formatPercent(nPropRightMargin
,
580 Application::GetSettings().GetUILanguageTag());
583 rText
+= GetMetricText( nRightMargin
,
584 eCoreUnit
, ePresUnit
, &rIntl
) +
585 " " + EditResId(GetMetricId(ePresUnit
));
589 default: ; // prevent warning
595 void SvxLRSpaceItem::ScaleMetrics( long nMult
, long nDiv
)
597 nFirstLineOfst
= static_cast<short>(Scale( nFirstLineOfst
, nMult
, nDiv
));
598 nTxtLeft
= Scale( nTxtLeft
, nMult
, nDiv
);
599 nLeftMargin
= Scale( nLeftMargin
, nMult
, nDiv
);
600 nRightMargin
= Scale( nRightMargin
, nMult
, nDiv
);
604 bool SvxLRSpaceItem::HasMetrics() const
610 void SvxLRSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
612 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxLRSpaceItem"));
613 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
614 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nFirstLineOfst"), BAD_CAST(OString::number(nFirstLineOfst
).getStr()));
615 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nTxtLeft"), BAD_CAST(OString::number(nTxtLeft
).getStr()));
616 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nLeftMargin"), BAD_CAST(OString::number(nLeftMargin
).getStr()));
617 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nRightMargin"), BAD_CAST(OString::number(nRightMargin
).getStr()));
618 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropFirstLineOfst"), BAD_CAST(OString::number(nPropFirstLineOfst
).getStr()));
619 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropLeftMargin"), BAD_CAST(OString::number(nPropLeftMargin
).getStr()));
620 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropRightMargin"), BAD_CAST(OString::number(nPropRightMargin
).getStr()));
621 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bAutoFirst"), BAD_CAST(OString::number(int(bAutoFirst
)).getStr()));
622 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bExplicitZeroMarginValRight"), BAD_CAST(OString::number(int(bExplicitZeroMarginValRight
)).getStr()));
623 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bExplicitZeroMarginValLeft"), BAD_CAST(OString::number(int(bExplicitZeroMarginValLeft
)).getStr()));
624 xmlTextWriterEndElement(pWriter
);
628 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nId
)
639 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nUp
, const sal_uInt16 nLow
,
640 const sal_uInt16 nId
)
651 bool SvxULSpaceItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
653 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
654 nMemberId
&= ~CONVERT_TWIPS
;
660 css::frame::status::UpperLowerMarginScale aUpperLowerMarginScale
;
661 aUpperLowerMarginScale
.Upper
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nUpper
) : nUpper
);
662 aUpperLowerMarginScale
.Lower
= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nLower
) : nPropUpper
);
663 aUpperLowerMarginScale
.ScaleUpper
= static_cast<sal_Int16
>(nPropUpper
);
664 aUpperLowerMarginScale
.ScaleLower
= static_cast<sal_Int16
>(nPropLower
);
665 rVal
<<= aUpperLowerMarginScale
;
668 case MID_UP_MARGIN
: rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nUpper
) : nUpper
); break;
669 case MID_LO_MARGIN
: rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nLower
) : nLower
); break;
670 case MID_CTX_MARGIN
: rVal
<<= bContext
; break;
671 case MID_UP_REL_MARGIN
: rVal
<<= static_cast<sal_Int16
>(nPropUpper
); break;
672 case MID_LO_REL_MARGIN
: rVal
<<= static_cast<sal_Int16
>(nPropLower
); break;
678 bool SvxULSpaceItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
680 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
681 nMemberId
&= ~CONVERT_TWIPS
;
688 css::frame::status::UpperLowerMarginScale aUpperLowerMarginScale
;
689 if ( !(rVal
>>= aUpperLowerMarginScale
))
692 SetUpper(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip( aUpperLowerMarginScale
.Upper
) : aUpperLowerMarginScale
.Upper
));
693 SetLower(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip( aUpperLowerMarginScale
.Lower
) : aUpperLowerMarginScale
.Lower
));
694 if( aUpperLowerMarginScale
.ScaleUpper
> 1 )
695 nPropUpper
= aUpperLowerMarginScale
.ScaleUpper
;
696 if( aUpperLowerMarginScale
.ScaleLower
> 1 )
697 nPropUpper
= aUpperLowerMarginScale
.ScaleLower
;
702 if(!(rVal
>>= nVal
) || nVal
< 0)
704 SetUpper(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip(nVal
) : nVal
));
707 if(!(rVal
>>= nVal
) || nVal
< 0)
709 SetLower(static_cast<sal_uInt16
>(bConvert
? convertMm100ToTwip(nVal
) : nVal
));
711 case MID_CTX_MARGIN
:
712 if (!(rVal
>>= bVal
))
714 SetContextValue(bVal
);
716 case MID_UP_REL_MARGIN
:
717 case MID_LO_REL_MARGIN
:
720 if((rVal
>>= nRel
) && nRel
> 1 )
722 if(MID_UP_REL_MARGIN
== nMemberId
)
723 nPropUpper
= static_cast<sal_uInt16
>(nRel
);
725 nPropLower
= static_cast<sal_uInt16
>(nRel
);
733 OSL_FAIL("unknown MemberId");
740 bool SvxULSpaceItem::operator==( const SfxPoolItem
& rAttr
) const
742 assert(SfxPoolItem::operator==(rAttr
));
744 const SvxULSpaceItem
& rSpaceItem
= static_cast<const SvxULSpaceItem
&>( rAttr
);
745 return ( nUpper
== rSpaceItem
.nUpper
&&
746 nLower
== rSpaceItem
.nLower
&&
747 bContext
== rSpaceItem
.bContext
&&
748 nPropUpper
== rSpaceItem
.nPropUpper
&&
749 nPropLower
== rSpaceItem
.nPropLower
);
753 SfxPoolItem
* SvxULSpaceItem::Clone( SfxItemPool
* ) const
755 return new SvxULSpaceItem( *this );
759 bool SvxULSpaceItem::GetPresentation
761 SfxItemPresentation ePres
,
765 const IntlWrapper
& rIntl
770 case SfxItemPresentation::Nameless
:
772 if ( 100 != nPropUpper
)
774 rText
= unicode::formatPercent(nPropUpper
,
775 Application::GetSettings().GetUILanguageTag());
778 rText
= GetMetricText( static_cast<long>(nUpper
), eCoreUnit
, ePresUnit
, &rIntl
);
779 rText
+= OUString(cpDelim
);
780 if ( 100 != nPropLower
)
782 rText
+= unicode::formatPercent(nPropLower
,
783 Application::GetSettings().GetUILanguageTag());
786 rText
+= GetMetricText( static_cast<long>(nLower
), eCoreUnit
, ePresUnit
, &rIntl
);
789 case SfxItemPresentation::Complete
:
791 rText
= EditResId(RID_SVXITEMS_ULSPACE_UPPER
);
792 if ( 100 != nPropUpper
)
794 rText
+= unicode::formatPercent(nPropUpper
,
795 Application::GetSettings().GetUILanguageTag());
799 rText
+= GetMetricText( static_cast<long>(nUpper
), eCoreUnit
, ePresUnit
, &rIntl
) +
800 " " + EditResId(GetMetricId(ePresUnit
));
802 rText
+= cpDelim
+ EditResId(RID_SVXITEMS_ULSPACE_LOWER
);
803 if ( 100 != nPropLower
)
805 rText
+= unicode::formatPercent(nPropLower
,
806 Application::GetSettings().GetUILanguageTag());
810 rText
+= GetMetricText( static_cast<long>(nLower
), eCoreUnit
, ePresUnit
, &rIntl
) +
811 " " + EditResId(GetMetricId(ePresUnit
));
815 default: ; // prevent warning
821 void SvxULSpaceItem::ScaleMetrics( long nMult
, long nDiv
)
823 nUpper
= static_cast<sal_uInt16
>(Scale( nUpper
, nMult
, nDiv
));
824 nLower
= static_cast<sal_uInt16
>(Scale( nLower
, nMult
, nDiv
));
828 bool SvxULSpaceItem::HasMetrics() const
834 void SvxULSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
836 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxULSpaceItem"));
837 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
838 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nUpper"), BAD_CAST(OString::number(nUpper
).getStr()));
839 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nLower"), BAD_CAST(OString::number(nLower
).getStr()));
840 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("bContext"), BAD_CAST(OString::boolean(bContext
).getStr()));
841 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropUpper"), BAD_CAST(OString::number(nPropUpper
).getStr()));
842 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nPropLower"), BAD_CAST(OString::number(nPropLower
).getStr()));
843 xmlTextWriterEndElement(pWriter
);
847 SfxPoolItem
* SvxPrintItem::Clone( SfxItemPool
* ) const
849 return new SvxPrintItem( *this );
853 bool SvxPrintItem::GetPresentation
855 SfxItemPresentation
/*ePres*/,
856 MapUnit
/*eCoreUnit*/,
857 MapUnit
/*ePresUnit*/,
858 OUString
& rText
, const IntlWrapper
&
861 const char* pId
= RID_SVXITEMS_PRINT_FALSE
;
864 pId
= RID_SVXITEMS_PRINT_TRUE
;
865 rText
= EditResId(pId
);
870 SfxPoolItem
* SvxOpaqueItem::Clone( SfxItemPool
* ) const
872 return new SvxOpaqueItem( *this );
876 bool SvxOpaqueItem::GetPresentation
878 SfxItemPresentation
/*ePres*/,
879 MapUnit
/*eCoreUnit*/,
880 MapUnit
/*ePresUnit*/,
881 OUString
& rText
, const IntlWrapper
&
884 const char* pId
= RID_SVXITEMS_OPAQUE_FALSE
;
887 pId
= RID_SVXITEMS_OPAQUE_TRUE
;
888 rText
= EditResId(pId
);
893 bool SvxProtectItem::operator==( const SfxPoolItem
& rAttr
) const
895 assert(SfxPoolItem::operator==(rAttr
));
897 const SvxProtectItem
& rItem
= static_cast<const SvxProtectItem
&>(rAttr
);
898 return ( bCntnt
== rItem
.bCntnt
&&
899 bSize
== rItem
.bSize
&&
900 bPos
== rItem
.bPos
);
904 bool SvxProtectItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
906 nMemberId
&= ~CONVERT_TWIPS
;
910 case MID_PROTECT_CONTENT
: bValue
= bCntnt
; break;
911 case MID_PROTECT_SIZE
: bValue
= bSize
; break;
912 case MID_PROTECT_POSITION
: bValue
= bPos
; break;
914 OSL_FAIL("Wrong MemberId");
923 bool SvxProtectItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
925 nMemberId
&= ~CONVERT_TWIPS
;
926 bool bVal( Any2Bool(rVal
) );
929 case MID_PROTECT_CONTENT
: bCntnt
= bVal
; break;
930 case MID_PROTECT_SIZE
: bSize
= bVal
; break;
931 case MID_PROTECT_POSITION
: bPos
= bVal
; break;
933 OSL_FAIL("Wrong MemberId");
940 SfxPoolItem
* SvxProtectItem::Clone( SfxItemPool
* ) const
942 return new SvxProtectItem( *this );
946 bool SvxProtectItem::GetPresentation
948 SfxItemPresentation
/*ePres*/,
949 MapUnit
/*eCoreUnit*/,
950 MapUnit
/*ePresUnit*/,
951 OUString
& rText
, const IntlWrapper
&
954 const char* pId
= RID_SVXITEMS_PROT_CONTENT_FALSE
;
957 pId
= RID_SVXITEMS_PROT_CONTENT_TRUE
;
958 rText
= EditResId(pId
) + cpDelim
;
959 pId
= RID_SVXITEMS_PROT_SIZE_FALSE
;
962 pId
= RID_SVXITEMS_PROT_SIZE_TRUE
;
963 rText
+= EditResId(pId
) + cpDelim
;
964 pId
= RID_SVXITEMS_PROT_POS_FALSE
;
967 pId
= RID_SVXITEMS_PROT_POS_TRUE
;
968 rText
+= EditResId(pId
);
973 void SvxProtectItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
975 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxProtectItem"));
976 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
977 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("content"), BAD_CAST(OString::boolean(bCntnt
).getStr()));
978 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("size"), BAD_CAST(OString::boolean(bSize
).getStr()));
979 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("position"), BAD_CAST(OString::boolean(bPos
).getStr()));
980 xmlTextWriterEndElement(pWriter
);
984 SvxShadowItem::SvxShadowItem( const sal_uInt16 nId
,
985 const Color
*pColor
, const sal_uInt16 nW
,
986 const SvxShadowLocation eLoc
) :
987 SfxEnumItemInterface( nId
),
988 aShadowColor(COL_GRAY
),
993 aShadowColor
= *pColor
;
997 bool SvxShadowItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
999 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1000 nMemberId
&= ~CONVERT_TWIPS
;
1002 table::ShadowFormat aShadow
;
1003 table::ShadowLocation eSet
= table::ShadowLocation_NONE
;
1006 case SvxShadowLocation::TopLeft
: eSet
= table::ShadowLocation_TOP_LEFT
; break;
1007 case SvxShadowLocation::TopRight
: eSet
= table::ShadowLocation_TOP_RIGHT
; break;
1008 case SvxShadowLocation::BottomLeft
: eSet
= table::ShadowLocation_BOTTOM_LEFT
; break;
1009 case SvxShadowLocation::BottomRight
: eSet
= table::ShadowLocation_BOTTOM_RIGHT
; break;
1010 default: ; // prevent warning
1012 aShadow
.Location
= eSet
;
1013 aShadow
.ShadowWidth
= bConvert
? convertTwipToMm100(nWidth
) : nWidth
;
1014 aShadow
.IsTransparent
= aShadowColor
.GetTransparency() > 0;
1015 aShadow
.Color
= sal_Int32(aShadowColor
);
1017 sal_Int8 nTransparence
= rtl::math::round(float(aShadowColor
.GetTransparency() * 100) / 255);
1019 switch ( nMemberId
)
1021 case MID_LOCATION
: rVal
<<= aShadow
.Location
; break;
1022 case MID_WIDTH
: rVal
<<= aShadow
.ShadowWidth
; break;
1023 case MID_TRANSPARENT
: rVal
<<= aShadow
.IsTransparent
; break;
1024 case MID_BG_COLOR
: rVal
<<= aShadow
.Color
; break;
1025 case 0: rVal
<<= aShadow
; break;
1026 case MID_SHADOW_TRANSPARENCE
: rVal
<<= nTransparence
; break;
1027 default: OSL_FAIL("Wrong MemberId!"); return false;
1033 bool SvxShadowItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
1035 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1036 nMemberId
&= ~CONVERT_TWIPS
;
1038 table::ShadowFormat aShadow
;
1040 bool bRet
= QueryValue( aAny
, bConvert
? CONVERT_TWIPS
: 0 ) && ( aAny
>>= aShadow
);
1041 switch ( nMemberId
)
1045 bRet
= (rVal
>>= aShadow
.Location
);
1049 bRet
= (rVal
>>= nVal
);
1050 aShadow
.Location
= static_cast<table::ShadowLocation
>(nVal
);
1056 case MID_WIDTH
: rVal
>>= aShadow
.ShadowWidth
; break;
1057 case MID_TRANSPARENT
: rVal
>>= aShadow
.IsTransparent
; break;
1058 case MID_BG_COLOR
: rVal
>>= aShadow
.Color
; break;
1059 case 0: rVal
>>= aShadow
; break;
1060 case MID_SHADOW_TRANSPARENCE
:
1062 sal_Int32 nTransparence
= 0;
1063 if ((rVal
>>= nTransparence
) && !o3tl::checked_multiply
<sal_Int32
>(nTransparence
, 255, nTransparence
))
1065 Color
aColor(aShadow
.Color
);
1066 aColor
.SetTransparency(rtl::math::round(float(nTransparence
) / 100));
1067 aShadow
.Color
= sal_Int32(aColor
);
1071 default: OSL_FAIL("Wrong MemberId!"); return false;
1076 // SvxShadowLocation eSet = SvxShadowLocation::NONE;
1077 switch( aShadow
.Location
)
1079 case table::ShadowLocation_TOP_LEFT
: eLocation
= SvxShadowLocation::TopLeft
; break;
1080 case table::ShadowLocation_TOP_RIGHT
: eLocation
= SvxShadowLocation::TopRight
; break;
1081 case table::ShadowLocation_BOTTOM_LEFT
: eLocation
= SvxShadowLocation::BottomLeft
; break;
1082 case table::ShadowLocation_BOTTOM_RIGHT
: eLocation
= SvxShadowLocation::BottomRight
; break;
1083 default: ; // prevent warning
1086 nWidth
= bConvert
? convertMm100ToTwip(aShadow
.ShadowWidth
) : aShadow
.ShadowWidth
;
1087 Color
aSet(aShadow
.Color
);
1088 aShadowColor
= aSet
;
1095 bool SvxShadowItem::operator==( const SfxPoolItem
& rAttr
) const
1097 assert(SfxPoolItem::operator==(rAttr
));
1099 const SvxShadowItem
& rItem
= static_cast<const SvxShadowItem
&>(rAttr
);
1100 return ( ( aShadowColor
== rItem
.aShadowColor
) &&
1101 ( nWidth
== rItem
.GetWidth() ) &&
1102 ( eLocation
== rItem
.GetLocation() ) );
1106 SfxPoolItem
* SvxShadowItem::Clone( SfxItemPool
* ) const
1108 return new SvxShadowItem( *this );
1112 sal_uInt16
SvxShadowItem::CalcShadowSpace( SvxShadowItemSide nShadow
) const
1114 sal_uInt16 nSpace
= 0;
1118 case SvxShadowItemSide::TOP
:
1119 if ( eLocation
== SvxShadowLocation::TopLeft
||
1120 eLocation
== SvxShadowLocation::TopRight
)
1124 case SvxShadowItemSide::BOTTOM
:
1125 if ( eLocation
== SvxShadowLocation::BottomLeft
||
1126 eLocation
== SvxShadowLocation::BottomRight
)
1130 case SvxShadowItemSide::LEFT
:
1131 if ( eLocation
== SvxShadowLocation::TopLeft
||
1132 eLocation
== SvxShadowLocation::BottomLeft
)
1136 case SvxShadowItemSide::RIGHT
:
1137 if ( eLocation
== SvxShadowLocation::TopRight
||
1138 eLocation
== SvxShadowLocation::BottomRight
)
1143 OSL_FAIL( "wrong shadow" );
1148 static const char* RID_SVXITEMS_SHADOW
[] =
1150 RID_SVXITEMS_SHADOW_NONE
,
1151 RID_SVXITEMS_SHADOW_TOPLEFT
,
1152 RID_SVXITEMS_SHADOW_TOPRIGHT
,
1153 RID_SVXITEMS_SHADOW_BOTTOMLEFT
,
1154 RID_SVXITEMS_SHADOW_BOTTOMRIGHT
1157 bool SvxShadowItem::GetPresentation
1159 SfxItemPresentation ePres
,
1162 OUString
& rText
, const IntlWrapper
& rIntl
1167 case SfxItemPresentation::Nameless
:
1169 rText
= ::GetColorString( aShadowColor
) + cpDelim
;
1170 const char* pId
= RID_SVXITEMS_TRANSPARENT_FALSE
;
1172 if ( aShadowColor
.GetTransparency() )
1173 pId
= RID_SVXITEMS_TRANSPARENT_TRUE
;
1174 rText
+= EditResId(pId
) +
1176 GetMetricText( static_cast<long>(nWidth
), eCoreUnit
, ePresUnit
, &rIntl
) +
1178 EditResId(RID_SVXITEMS_SHADOW
[static_cast<int>(eLocation
)]);
1181 case SfxItemPresentation::Complete
:
1183 rText
= EditResId(RID_SVXITEMS_SHADOW_COMPLETE
) +
1184 ::GetColorString( aShadowColor
) +
1187 const char* pId
= RID_SVXITEMS_TRANSPARENT_FALSE
;
1188 if ( aShadowColor
.GetTransparency() )
1189 pId
= RID_SVXITEMS_TRANSPARENT_TRUE
;
1190 rText
+= EditResId(pId
) +
1192 GetMetricText( static_cast<long>(nWidth
), eCoreUnit
, ePresUnit
, &rIntl
) +
1193 " " + EditResId(GetMetricId(ePresUnit
)) +
1195 EditResId(RID_SVXITEMS_SHADOW
[static_cast<int>(eLocation
)]);
1198 default: ; // prevent warning
1204 void SvxShadowItem::ScaleMetrics( long nMult
, long nDiv
)
1206 nWidth
= static_cast<sal_uInt16
>(Scale( nWidth
, nMult
, nDiv
));
1210 bool SvxShadowItem::HasMetrics() const
1216 sal_uInt16
SvxShadowItem::GetValueCount() const
1218 return sal_uInt16(SvxShadowLocation::End
); // SvxShadowLocation::BottomRight + 1
1221 sal_uInt16
SvxShadowItem::GetEnumValue() const
1223 return static_cast<sal_uInt16
>(GetLocation());
1227 void SvxShadowItem::SetEnumValue( sal_uInt16 nVal
)
1229 SetLocation( static_cast<SvxShadowLocation
>(nVal
) );
1232 void SvxShadowItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
1234 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxShadowItem"));
1235 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1236 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("aShadowColor"), BAD_CAST(aShadowColor
.AsRGBHexString().toUtf8().getStr()));
1237 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("nWidth"), BAD_CAST(OString::number(nWidth
).getStr()));
1238 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("eLocation"), BAD_CAST(OString::number(static_cast<int>(eLocation
)).getStr()));
1239 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("presentation"), BAD_CAST(EditResId(RID_SVXITEMS_SHADOW
[static_cast<int>(eLocation
)]).toUtf8().getStr()));
1240 xmlTextWriterEndElement(pWriter
);
1243 // class SvxBoxItem ------------------------------------------------------
1245 SvxBoxItem::SvxBoxItem( const SvxBoxItem
& rCpy
) :
1247 SfxPoolItem ( rCpy
),
1248 pTop ( rCpy
.pTop
? new SvxBorderLine( *rCpy
.pTop
) : nullptr ),
1249 pBottom ( rCpy
.pBottom
? new SvxBorderLine( *rCpy
.pBottom
) : nullptr ),
1250 pLeft ( rCpy
.pLeft
? new SvxBorderLine( *rCpy
.pLeft
) : nullptr ),
1251 pRight ( rCpy
.pRight
? new SvxBorderLine( *rCpy
.pRight
) : nullptr ),
1252 nTopDist ( rCpy
.nTopDist
),
1253 nBottomDist ( rCpy
.nBottomDist
),
1254 nLeftDist ( rCpy
.nLeftDist
),
1255 nRightDist ( rCpy
.nRightDist
),
1256 bRemoveAdjCellBorder ( rCpy
.bRemoveAdjCellBorder
)
1261 SvxBoxItem::SvxBoxItem( const sal_uInt16 nId
) :
1267 bRemoveAdjCellBorder ( false )
1272 SvxBoxItem::~SvxBoxItem()
1277 static bool CmpBrdLn( const std::unique_ptr
<SvxBorderLine
> & pBrd1
, const SvxBorderLine
* pBrd2
)
1279 if( pBrd1
.get() == pBrd2
)
1281 if( pBrd1
== nullptr || pBrd2
== nullptr)
1283 return *pBrd1
== *pBrd2
;
1287 bool SvxBoxItem::operator==( const SfxPoolItem
& rAttr
) const
1289 assert(SfxPoolItem::operator==(rAttr
));
1291 const SvxBoxItem
& rBoxItem
= static_cast<const SvxBoxItem
&>(rAttr
);
1293 ( nTopDist
== rBoxItem
.nTopDist
) &&
1294 ( nBottomDist
== rBoxItem
.nBottomDist
) &&
1295 ( nLeftDist
== rBoxItem
.nLeftDist
) &&
1296 ( nRightDist
== rBoxItem
.nRightDist
) &&
1297 ( bRemoveAdjCellBorder
== rBoxItem
.bRemoveAdjCellBorder
) &&
1298 CmpBrdLn( pTop
, rBoxItem
.GetTop() ) &&
1299 CmpBrdLn( pBottom
, rBoxItem
.GetBottom() ) &&
1300 CmpBrdLn( pLeft
, rBoxItem
.GetLeft() ) &&
1301 CmpBrdLn( pRight
, rBoxItem
.GetRight() ) );
1305 table::BorderLine2
SvxBoxItem::SvxLineToLine(const SvxBorderLine
* pLine
, bool bConvert
)
1307 table::BorderLine2 aLine
;
1310 aLine
.Color
= sal_Int32(pLine
->GetColor());
1311 aLine
.InnerLineWidth
= sal_uInt16( bConvert
? convertTwipToMm100(pLine
->GetInWidth() ): pLine
->GetInWidth() );
1312 aLine
.OuterLineWidth
= sal_uInt16( bConvert
? convertTwipToMm100(pLine
->GetOutWidth()): pLine
->GetOutWidth() );
1313 aLine
.LineDistance
= sal_uInt16( bConvert
? convertTwipToMm100(pLine
->GetDistance()): pLine
->GetDistance() );
1314 aLine
.LineStyle
= sal_Int16(pLine
->GetBorderLineStyle());
1315 aLine
.LineWidth
= sal_uInt32( bConvert
? convertTwipToMm100( pLine
->GetWidth( ) ) : pLine
->GetWidth( ) );
1318 aLine
.Color
= aLine
.InnerLineWidth
= aLine
.OuterLineWidth
= aLine
.LineDistance
= 0;
1322 bool SvxBoxItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
1324 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1325 table::BorderLine2 aRetLine
;
1326 sal_uInt16 nDist
= 0;
1327 bool bDistMember
= false;
1328 nMemberId
&= ~CONVERT_TWIPS
;
1333 // 4 Borders and 5 distances
1334 uno::Sequence
< uno::Any
> aSeq( 9 );
1335 aSeq
[0] <<= SvxBoxItem::SvxLineToLine(GetLeft(), bConvert
);
1336 aSeq
[1] <<= SvxBoxItem::SvxLineToLine(GetRight(), bConvert
);
1337 aSeq
[2] <<= SvxBoxItem::SvxLineToLine(GetBottom(), bConvert
);
1338 aSeq
[3] <<= SvxBoxItem::SvxLineToLine(GetTop(), bConvert
);
1339 aSeq
[4] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( GetSmallestDistance()) : GetSmallestDistance());
1340 aSeq
[5] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nTopDist
) : nTopDist
);
1341 aSeq
[6] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nBottomDist
) : nBottomDist
);
1342 aSeq
[7] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nLeftDist
) : nLeftDist
);
1343 aSeq
[8] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100( nRightDist
) : nRightDist
);
1347 case MID_LEFT_BORDER
:
1349 aRetLine
= SvxBoxItem::SvxLineToLine(GetLeft(), bConvert
);
1351 case MID_RIGHT_BORDER
:
1353 aRetLine
= SvxBoxItem::SvxLineToLine(GetRight(), bConvert
);
1355 case MID_BOTTOM_BORDER
:
1357 aRetLine
= SvxBoxItem::SvxLineToLine(GetBottom(), bConvert
);
1359 case MID_TOP_BORDER
:
1361 aRetLine
= SvxBoxItem::SvxLineToLine(GetTop(), bConvert
);
1363 case BORDER_DISTANCE
:
1364 nDist
= GetSmallestDistance();
1367 case TOP_BORDER_DISTANCE
:
1371 case BOTTOM_BORDER_DISTANCE
:
1372 nDist
= nBottomDist
;
1375 case LEFT_BORDER_DISTANCE
:
1379 case RIGHT_BORDER_DISTANCE
:
1385 // it doesn't make sense to return a value for these since it's
1386 // probably ambiguous
1392 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(nDist
) : nDist
);
1403 lcl_lineToSvxLine(const table::BorderLine
& rLine
, SvxBorderLine
& rSvxLine
, bool bConvert
, bool bGuessWidth
)
1405 rSvxLine
.SetColor( Color(rLine
.Color
));
1408 rSvxLine
.GuessLinesWidths( rSvxLine
.GetBorderLineStyle(),
1409 sal_uInt16( bConvert
? convertMm100ToTwip(rLine
.OuterLineWidth
) : rLine
.OuterLineWidth
),
1410 sal_uInt16( bConvert
? convertMm100ToTwip(rLine
.InnerLineWidth
) : rLine
.InnerLineWidth
),
1411 sal_uInt16( bConvert
? convertMm100ToTwip(rLine
.LineDistance
) : rLine
.LineDistance
));
1414 bool bRet
= !rSvxLine
.isEmpty();
1421 bool SvxBoxItem::LineToSvxLine(const css::table::BorderLine
& rLine
, SvxBorderLine
& rSvxLine
, bool bConvert
)
1423 return lcl_lineToSvxLine(rLine
, rSvxLine
, bConvert
, true);
1427 SvxBoxItem::LineToSvxLine(const css::table::BorderLine2
& rLine
, SvxBorderLine
& rSvxLine
, bool bConvert
)
1429 SvxBorderLineStyle
const nStyle
=
1430 (rLine
.LineStyle
< 0 || BORDER_LINE_STYLE_MAX
< rLine
.LineStyle
)
1431 ? SvxBorderLineStyle::SOLID
// default
1432 : static_cast<SvxBorderLineStyle
>(rLine
.LineStyle
);
1434 rSvxLine
.SetBorderLineStyle( nStyle
);
1436 bool bGuessWidth
= true;
1437 if ( rLine
.LineWidth
)
1439 rSvxLine
.SetWidth( bConvert
? convertMm100ToTwip( rLine
.LineWidth
) : rLine
.LineWidth
);
1440 // fdo#46112: double does not necessarily mean symmetric
1441 // for backwards compatibility
1442 bGuessWidth
= (SvxBorderLineStyle::DOUBLE
== nStyle
|| SvxBorderLineStyle::DOUBLE_THIN
== nStyle
) &&
1443 (rLine
.InnerLineWidth
> 0) && (rLine
.OuterLineWidth
> 0);
1446 return lcl_lineToSvxLine(rLine
, rSvxLine
, bConvert
, bGuessWidth
);
1454 lcl_extractBorderLine(const uno::Any
& rAny
, table::BorderLine2
& rLine
)
1459 table::BorderLine aBorderLine
;
1460 if (rAny
>>= aBorderLine
)
1462 rLine
.Color
= aBorderLine
.Color
;
1463 rLine
.InnerLineWidth
= aBorderLine
.InnerLineWidth
;
1464 rLine
.OuterLineWidth
= aBorderLine
.OuterLineWidth
;
1465 rLine
.LineDistance
= aBorderLine
.LineDistance
;
1466 rLine
.LineStyle
= table::BorderLineStyle::SOLID
;
1473 template<typename Item
, typename Line
>
1475 lcl_setLine(const uno::Any
& rAny
, Item
& rItem
, Line nLine
, const bool bConvert
)
1478 table::BorderLine2 aBorderLine
;
1479 if (lcl_extractBorderLine(rAny
, aBorderLine
))
1481 SvxBorderLine aLine
;
1482 bool bSet
= SvxBoxItem::LineToSvxLine(aBorderLine
, aLine
, bConvert
);
1483 rItem
.SetLine( bSet
? &aLine
: nullptr, nLine
);
1491 bool SvxBoxItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
1493 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
1494 SvxBoxItemLine nLine
= SvxBoxItemLine::TOP
;
1495 bool bDistMember
= false;
1496 nMemberId
&= ~CONVERT_TWIPS
;
1501 uno::Sequence
< uno::Any
> aSeq
;
1502 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == 9 ))
1504 // 4 Borders and 5 distances
1505 const SvxBoxItemLine aBorders
[] = { SvxBoxItemLine::LEFT
, SvxBoxItemLine::RIGHT
, SvxBoxItemLine::BOTTOM
, SvxBoxItemLine::TOP
};
1506 for (int n(0); n
!= SAL_N_ELEMENTS(aBorders
); ++n
)
1508 if (!lcl_setLine(aSeq
[n
], *this, aBorders
[n
], bConvert
))
1512 // WTH are the borders and the distances saved in different order?
1513 SvxBoxItemLine
const nLines
[4] = { SvxBoxItemLine::TOP
, SvxBoxItemLine::BOTTOM
, SvxBoxItemLine::LEFT
, SvxBoxItemLine::RIGHT
};
1514 for ( sal_Int32 n
= 4; n
< 9; n
++ )
1516 sal_Int32 nDist
= 0;
1517 if ( aSeq
[n
] >>= nDist
)
1520 nDist
= convertMm100ToTwip(nDist
);
1522 SetAllDistances(sal_uInt16(nDist
));
1524 SetDistance( sal_uInt16( nDist
), nLines
[n
-5] );
1535 case LEFT_BORDER_DISTANCE
:
1539 case MID_LEFT_BORDER
:
1540 nLine
= SvxBoxItemLine::LEFT
;
1542 case RIGHT_BORDER_DISTANCE
:
1546 case MID_RIGHT_BORDER
:
1547 nLine
= SvxBoxItemLine::RIGHT
;
1549 case BOTTOM_BORDER_DISTANCE
:
1553 case MID_BOTTOM_BORDER
:
1554 nLine
= SvxBoxItemLine::BOTTOM
;
1556 case TOP_BORDER_DISTANCE
:
1560 case MID_TOP_BORDER
:
1561 nLine
= SvxBoxItemLine::TOP
;
1565 drawing::LineStyle eDrawingStyle
;
1566 rVal
>>= eDrawingStyle
;
1567 SvxBorderLineStyle eBorderStyle
= SvxBorderLineStyle::NONE
;
1568 switch ( eDrawingStyle
)
1571 case drawing::LineStyle_NONE
:
1573 case drawing::LineStyle_SOLID
:
1574 eBorderStyle
= SvxBorderLineStyle::SOLID
;
1576 case drawing::LineStyle_DASH
:
1577 eBorderStyle
= SvxBorderLineStyle::DASHED
;
1581 // Set the line style on all borders
1582 for( SvxBoxItemLine n
: o3tl::enumrange
<SvxBoxItemLine
>() )
1584 editeng::SvxBorderLine
* pLine
= const_cast< editeng::SvxBorderLine
* >( GetLine( n
) );
1586 pLine
->SetBorderLineStyle( eBorderStyle
);
1593 // Set the line width on all borders
1597 nWidth
= convertMm100ToTwip( nWidth
);
1599 // Set the line Width on all borders
1600 for( SvxBoxItemLine n
: o3tl::enumrange
<SvxBoxItemLine
>() )
1602 editeng::SvxBorderLine
* pLine
= const_cast< editeng::SvxBorderLine
* >( GetLine( n
) );
1604 pLine
->SetWidth( nWidth
);
1610 if( bDistMember
|| nMemberId
== BORDER_DISTANCE
)
1612 sal_Int32 nDist
= 0;
1613 if(!(rVal
>>= nDist
))
1619 nDist
= convertMm100ToTwip(nDist
);
1620 if( nMemberId
== BORDER_DISTANCE
)
1621 SetAllDistances(sal_uInt16(nDist
));
1623 SetDistance( sal_uInt16( nDist
), nLine
);
1628 SvxBorderLine aLine
;
1629 if( !rVal
.hasValue() )
1632 table::BorderLine2 aBorderLine
;
1633 if( lcl_extractBorderLine(rVal
, aBorderLine
) )
1637 else if (rVal
.getValueTypeClass() == uno::TypeClass_SEQUENCE
)
1639 // serialization for basic macro recording
1640 uno::Reference
< script::XTypeConverter
> xConverter
1641 ( script::Converter::create(::comphelper::getProcessComponentContext()) );
1642 uno::Sequence
< uno::Any
> aSeq
;
1644 try { aNew
= xConverter
->convertTo( rVal
, cppu::UnoType
<uno::Sequence
< uno::Any
>>::get() ); }
1645 catch (const uno::Exception
&) {}
1648 if (aSeq
.getLength() >= 4 && aSeq
.getLength() <= 6)
1651 if ( aSeq
[0] >>= nVal
)
1652 aBorderLine
.Color
= nVal
;
1653 if ( aSeq
[1] >>= nVal
)
1654 aBorderLine
.InnerLineWidth
= static_cast<sal_Int16
>(nVal
);
1655 if ( aSeq
[2] >>= nVal
)
1656 aBorderLine
.OuterLineWidth
= static_cast<sal_Int16
>(nVal
);
1657 if ( aSeq
[3] >>= nVal
)
1658 aBorderLine
.LineDistance
= static_cast<sal_Int16
>(nVal
);
1659 if (aSeq
.getLength() >= 5) // fdo#40874 added fields
1661 if (aSeq
[4] >>= nVal
)
1663 aBorderLine
.LineStyle
= nVal
;
1665 if (aSeq
.getLength() >= 6)
1667 if (aSeq
[5] >>= nVal
)
1669 aBorderLine
.LineWidth
= nVal
;
1680 bool bSet
= SvxBoxItem::LineToSvxLine(aBorderLine
, aLine
, bConvert
);
1681 SetLine(bSet
? &aLine
: nullptr, nLine
);
1688 SfxPoolItem
* SvxBoxItem::Clone( SfxItemPool
* ) const
1690 return new SvxBoxItem( *this );
1694 bool SvxBoxItem::GetPresentation
1696 SfxItemPresentation ePres
,
1699 OUString
& rText
, const IntlWrapper
& rIntl
1702 OUString
cpDelimTmp(cpDelim
);
1705 case SfxItemPresentation::Nameless
:
1711 rText
= pTop
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1713 if( !(pTop
&& pBottom
&& pLeft
&& pRight
&&
1714 *pTop
== *pBottom
&& *pTop
== *pLeft
&& *pTop
== *pRight
) )
1718 rText
+= pBottom
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1722 rText
+= pLeft
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1726 rText
+= pRight
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
) + cpDelimTmp
;
1729 rText
+= GetMetricText( static_cast<long>(nTopDist
), eCoreUnit
, ePresUnit
, &rIntl
);
1730 if( nTopDist
!= nBottomDist
|| nTopDist
!= nLeftDist
||
1731 nTopDist
!= nRightDist
)
1733 rText
+= cpDelimTmp
+
1734 GetMetricText( static_cast<long>(nBottomDist
), eCoreUnit
,
1735 ePresUnit
, &rIntl
) +
1737 GetMetricText( static_cast<long>(nLeftDist
), eCoreUnit
, ePresUnit
, &rIntl
) +
1739 GetMetricText( static_cast<long>(nRightDist
), eCoreUnit
,
1740 ePresUnit
, &rIntl
);
1744 case SfxItemPresentation::Complete
:
1746 if( !(pTop
|| pBottom
|| pLeft
|| pRight
) )
1748 rText
= EditResId(RID_SVXITEMS_BORDER_NONE
) + cpDelimTmp
;
1752 rText
= EditResId(RID_SVXITEMS_BORDER_COMPLETE
);
1753 if( pTop
&& pBottom
&& pLeft
&& pRight
&&
1754 *pTop
== *pBottom
&& *pTop
== *pLeft
&& *pTop
== *pRight
)
1756 rText
+= pTop
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) + cpDelimTmp
;
1762 rText
+= EditResId(RID_SVXITEMS_BORDER_TOP
) +
1763 pTop
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1768 rText
+= EditResId(RID_SVXITEMS_BORDER_BOTTOM
) +
1769 pBottom
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1774 rText
+= EditResId(RID_SVXITEMS_BORDER_LEFT
) +
1775 pLeft
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1780 rText
+= EditResId(RID_SVXITEMS_BORDER_RIGHT
) +
1781 pRight
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
, true ) +
1787 rText
+= EditResId(RID_SVXITEMS_BORDER_DISTANCE
);
1788 if( nTopDist
== nBottomDist
&& nTopDist
== nLeftDist
&&
1789 nTopDist
== nRightDist
)
1791 rText
+= GetMetricText( static_cast<long>(nTopDist
), eCoreUnit
,
1792 ePresUnit
, &rIntl
) +
1793 " " + EditResId(GetMetricId(ePresUnit
));
1797 rText
+= EditResId(RID_SVXITEMS_BORDER_TOP
) +
1798 GetMetricText( static_cast<long>(nTopDist
), eCoreUnit
,
1799 ePresUnit
, &rIntl
) +
1800 " " + EditResId(GetMetricId(ePresUnit
)) +
1802 EditResId(RID_SVXITEMS_BORDER_BOTTOM
) +
1803 GetMetricText( static_cast<long>(nBottomDist
), eCoreUnit
,
1804 ePresUnit
, &rIntl
) +
1805 " " + EditResId(GetMetricId(ePresUnit
)) +
1807 EditResId(RID_SVXITEMS_BORDER_LEFT
) +
1808 GetMetricText( static_cast<long>(nLeftDist
), eCoreUnit
,
1809 ePresUnit
, &rIntl
) +
1810 " " + EditResId(GetMetricId(ePresUnit
)) +
1812 EditResId(RID_SVXITEMS_BORDER_RIGHT
) +
1813 GetMetricText( static_cast<long>(nRightDist
), eCoreUnit
,
1814 ePresUnit
, &rIntl
) +
1815 " " + EditResId(GetMetricId(ePresUnit
));
1819 default: ; // prevent warning
1825 void SvxBoxItem::ScaleMetrics( long nMult
, long nDiv
)
1827 if ( pTop
) pTop
->ScaleMetrics( nMult
, nDiv
);
1828 if ( pBottom
) pBottom
->ScaleMetrics( nMult
, nDiv
);
1829 if ( pLeft
) pLeft
->ScaleMetrics( nMult
, nDiv
);
1830 if ( pRight
) pRight
->ScaleMetrics( nMult
, nDiv
);
1831 nTopDist
= static_cast<sal_uInt16
>(Scale( nTopDist
, nMult
, nDiv
));
1832 nBottomDist
= static_cast<sal_uInt16
>(Scale( nBottomDist
, nMult
, nDiv
));
1833 nLeftDist
= static_cast<sal_uInt16
>(Scale( nLeftDist
, nMult
, nDiv
));
1834 nRightDist
= static_cast<sal_uInt16
>(Scale( nRightDist
, nMult
, nDiv
));
1838 bool SvxBoxItem::HasMetrics() const
1844 const SvxBorderLine
*SvxBoxItem::GetLine( SvxBoxItemLine nLine
) const
1846 const SvxBorderLine
*pRet
= nullptr;
1850 case SvxBoxItemLine::TOP
:
1853 case SvxBoxItemLine::BOTTOM
:
1854 pRet
= pBottom
.get();
1856 case SvxBoxItemLine::LEFT
:
1859 case SvxBoxItemLine::RIGHT
:
1860 pRet
= pRight
.get();
1863 OSL_FAIL( "wrong line" );
1871 void SvxBoxItem::SetLine( const SvxBorderLine
* pNew
, SvxBoxItemLine nLine
)
1873 std::unique_ptr
<SvxBorderLine
> pTmp( pNew
? new SvxBorderLine( *pNew
) : nullptr );
1877 case SvxBoxItemLine::TOP
:
1878 pTop
= std::move( pTmp
);
1880 case SvxBoxItemLine::BOTTOM
:
1881 pBottom
= std::move( pTmp
);
1883 case SvxBoxItemLine::LEFT
:
1884 pLeft
= std::move( pTmp
);
1886 case SvxBoxItemLine::RIGHT
:
1887 pRight
= std::move( pTmp
);
1890 OSL_FAIL( "wrong line" );
1895 sal_uInt16
SvxBoxItem::GetSmallestDistance() const
1897 // The smallest distance that is not 0 will be returned.
1898 sal_uInt16 nDist
= nTopDist
;
1899 if( nBottomDist
&& (!nDist
|| nBottomDist
< nDist
) )
1900 nDist
= nBottomDist
;
1901 if( nLeftDist
&& (!nDist
|| nLeftDist
< nDist
) )
1903 if( nRightDist
&& (!nDist
|| nRightDist
< nDist
) )
1910 sal_uInt16
SvxBoxItem::GetDistance( SvxBoxItemLine nLine
) const
1912 sal_uInt16 nDist
= 0;
1915 case SvxBoxItemLine::TOP
:
1918 case SvxBoxItemLine::BOTTOM
:
1919 nDist
= nBottomDist
;
1921 case SvxBoxItemLine::LEFT
:
1924 case SvxBoxItemLine::RIGHT
:
1928 OSL_FAIL( "wrong line" );
1935 void SvxBoxItem::SetDistance( sal_uInt16 nNew
, SvxBoxItemLine nLine
)
1939 case SvxBoxItemLine::TOP
:
1942 case SvxBoxItemLine::BOTTOM
:
1945 case SvxBoxItemLine::LEFT
:
1948 case SvxBoxItemLine::RIGHT
:
1952 OSL_FAIL( "wrong line" );
1956 sal_uInt16
SvxBoxItem::CalcLineWidth( SvxBoxItemLine nLine
) const
1958 SvxBorderLine
* pTmp
= nullptr;
1959 sal_uInt16 nWidth
= 0;
1962 case SvxBoxItemLine::TOP
:
1965 case SvxBoxItemLine::BOTTOM
:
1966 pTmp
= pBottom
.get();
1968 case SvxBoxItemLine::LEFT
:
1971 case SvxBoxItemLine::RIGHT
:
1972 pTmp
= pRight
.get();
1975 OSL_FAIL( "wrong line" );
1979 nWidth
= pTmp
->GetScaledWidth();
1984 sal_uInt16
SvxBoxItem::CalcLineSpace( SvxBoxItemLine nLine
, bool bEvenIfNoLine
) const
1986 SvxBorderLine
* pTmp
= nullptr;
1987 sal_uInt16 nDist
= 0;
1990 case SvxBoxItemLine::TOP
:
1994 case SvxBoxItemLine::BOTTOM
:
1995 pTmp
= pBottom
.get();
1996 nDist
= nBottomDist
;
1998 case SvxBoxItemLine::LEFT
:
2002 case SvxBoxItemLine::RIGHT
:
2003 pTmp
= pRight
.get();
2007 OSL_FAIL( "wrong line" );
2012 nDist
= nDist
+ pTmp
->GetScaledWidth();
2014 else if( !bEvenIfNoLine
)
2019 bool SvxBoxItem::HasBorder( bool bTreatPaddingAsBorder
) const
2021 return CalcLineSpace( SvxBoxItemLine::BOTTOM
, bTreatPaddingAsBorder
)
2022 || CalcLineSpace( SvxBoxItemLine::RIGHT
, bTreatPaddingAsBorder
)
2023 || CalcLineSpace( SvxBoxItemLine::TOP
, bTreatPaddingAsBorder
)
2024 || CalcLineSpace( SvxBoxItemLine::LEFT
, bTreatPaddingAsBorder
);
2027 // class SvxBoxInfoItem --------------------------------------------------
2029 SvxBoxInfoItem::SvxBoxInfoItem( const sal_uInt16 nId
) :
2031 mbEnableHor( false ),
2032 mbEnableVer( false ),
2035 bDist
= bMinDist
= false;
2040 SvxBoxInfoItem::SvxBoxInfoItem( const SvxBoxInfoItem
& rCpy
) :
2041 SfxPoolItem( rCpy
),
2042 pHori( rCpy
.pHori
? new SvxBorderLine( *rCpy
.pHori
) : nullptr ),
2043 pVert( rCpy
.pVert
? new SvxBorderLine( *rCpy
.pVert
) : nullptr ),
2044 mbEnableHor( rCpy
.mbEnableHor
),
2045 mbEnableVer( rCpy
.mbEnableVer
),
2046 bDist( rCpy
.bDist
),
2047 bMinDist ( rCpy
.bMinDist
),
2048 nValidFlags( rCpy
.nValidFlags
),
2049 nDefDist( rCpy
.nDefDist
)
2053 SvxBoxInfoItem::~SvxBoxInfoItem()
2057 bool SvxBoxInfoItem::operator==( const SfxPoolItem
& rAttr
) const
2059 assert(SfxPoolItem::operator==(rAttr
));
2061 const SvxBoxInfoItem
& rBoxInfo
= static_cast<const SvxBoxInfoItem
&>(rAttr
);
2063 return ( mbEnableHor
== rBoxInfo
.mbEnableHor
2064 && mbEnableVer
== rBoxInfo
.mbEnableVer
2065 && bDist
== rBoxInfo
.IsDist()
2066 && bMinDist
== rBoxInfo
.IsMinDist()
2067 && nValidFlags
== rBoxInfo
.nValidFlags
2068 && nDefDist
== rBoxInfo
.GetDefDist()
2069 && CmpBrdLn( pHori
, rBoxInfo
.GetHori() )
2070 && CmpBrdLn( pVert
, rBoxInfo
.GetVert() )
2075 void SvxBoxInfoItem::SetLine( const SvxBorderLine
* pNew
, SvxBoxInfoItemLine nLine
)
2077 std::unique_ptr
<SvxBorderLine
> pTmp( pNew
? new SvxBorderLine( *pNew
) : nullptr );
2079 if ( SvxBoxInfoItemLine::HORI
== nLine
)
2081 pHori
= std::move(pTmp
);
2083 else if ( SvxBoxInfoItemLine::VERT
== nLine
)
2085 pVert
= std::move(pTmp
);
2089 OSL_FAIL( "wrong line" );
2094 SfxPoolItem
* SvxBoxInfoItem::Clone( SfxItemPool
* ) const
2096 return new SvxBoxInfoItem( *this );
2100 bool SvxBoxInfoItem::GetPresentation
2102 SfxItemPresentation
/*ePres*/,
2103 MapUnit
/*eCoreUnit*/,
2104 MapUnit
/*ePresUnit*/,
2105 OUString
& rText
, const IntlWrapper
&
2113 void SvxBoxInfoItem::ScaleMetrics( long nMult
, long nDiv
)
2115 if ( pHori
) pHori
->ScaleMetrics( nMult
, nDiv
);
2116 if ( pVert
) pVert
->ScaleMetrics( nMult
, nDiv
);
2117 nDefDist
= static_cast<sal_uInt16
>(Scale( nDefDist
, nMult
, nDiv
));
2121 bool SvxBoxInfoItem::HasMetrics() const
2127 void SvxBoxInfoItem::ResetFlags()
2129 nValidFlags
= static_cast<SvxBoxInfoItemValidFlags
>(0x7F); // all valid except Disable
2132 bool SvxBoxInfoItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
2134 bool bConvert
= 0 != (nMemberId
& CONVERT_TWIPS
);
2135 table::BorderLine2 aRetLine
;
2137 bool bIntMember
= false;
2138 nMemberId
&= ~CONVERT_TWIPS
;
2143 // 2 BorderLines, flags, valid flags and distance
2144 css::uno::Sequence
< css::uno::Any
> aSeq( 5 );
2145 aSeq
[0] <<= SvxBoxItem::SvxLineToLine( pHori
.get(), bConvert
);
2146 aSeq
[1] <<= SvxBoxItem::SvxLineToLine( pVert
.get(), bConvert
);
2154 aSeq
[3] <<= static_cast<sal_Int16
>(nValidFlags
);
2155 aSeq
[4] <<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(GetDefDist()) : GetDefDist());
2160 case MID_HORIZONTAL
:
2161 aRetLine
= SvxBoxItem::SvxLineToLine( pHori
.get(), bConvert
);
2164 aRetLine
= SvxBoxItem::SvxLineToLine( pVert
.get(), bConvert
);
2176 case MID_VALIDFLAGS
:
2178 rVal
<<= static_cast<sal_Int16
>(nValidFlags
);
2182 rVal
<<= static_cast<sal_Int32
>(bConvert
? convertTwipToMm100(GetDefDist()) : GetDefDist());
2184 default: OSL_FAIL("Wrong MemberId!"); return false;
2194 bool SvxBoxInfoItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
2196 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
2197 nMemberId
&= ~CONVERT_TWIPS
;
2203 css::uno::Sequence
< css::uno::Any
> aSeq
;
2204 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == 5 ))
2206 // 2 BorderLines, flags, valid flags and distance
2207 if (!lcl_setLine(aSeq
[0], *this, SvxBoxInfoItemLine::HORI
, bConvert
))
2209 if (!lcl_setLine(aSeq
[1], *this, SvxBoxInfoItemLine::VERT
, bConvert
))
2212 sal_Int16
nFlags( 0 );
2213 sal_Int32
nVal( 0 );
2214 if ( aSeq
[2] >>= nFlags
)
2216 SetTable ( ( nFlags
& 0x01 ) != 0 );
2217 SetDist ( ( nFlags
& 0x02 ) != 0 );
2218 SetMinDist( ( nFlags
& 0x04 ) != 0 );
2222 if ( aSeq
[3] >>= nFlags
)
2223 nValidFlags
= static_cast<SvxBoxInfoItemValidFlags
>(nFlags
);
2226 if (( aSeq
[4] >>= nVal
) && ( nVal
>= 0 ))
2229 nVal
= convertMm100ToTwip(nVal
);
2230 SetDefDist( static_cast<sal_uInt16
>(nVal
) );
2236 case MID_HORIZONTAL
:
2239 if( !rVal
.hasValue() )
2242 table::BorderLine2 aBorderLine
;
2243 if( lcl_extractBorderLine(rVal
, aBorderLine
) )
2247 else if (rVal
.getValueTypeClass() == uno::TypeClass_SEQUENCE
)
2249 // serialization for basic macro recording
2250 uno::Reference
< script::XTypeConverter
> xConverter( script::Converter::create(::comphelper::getProcessComponentContext()) );
2252 uno::Sequence
< uno::Any
> aSeq
;
2253 try { aNew
= xConverter
->convertTo( rVal
, cppu::UnoType
<uno::Sequence
< uno::Any
>>::get() ); }
2254 catch (const uno::Exception
&) {}
2256 if ((aNew
>>= aSeq
) &&
2257 aSeq
.getLength() >= 4 && aSeq
.getLength() <= 6)
2260 if ( aSeq
[0] >>= nVal
)
2261 aBorderLine
.Color
= nVal
;
2262 if ( aSeq
[1] >>= nVal
)
2263 aBorderLine
.InnerLineWidth
= static_cast<sal_Int16
>(nVal
);
2264 if ( aSeq
[2] >>= nVal
)
2265 aBorderLine
.OuterLineWidth
= static_cast<sal_Int16
>(nVal
);
2266 if ( aSeq
[3] >>= nVal
)
2267 aBorderLine
.LineDistance
= static_cast<sal_Int16
>(nVal
);
2268 if (aSeq
.getLength() >= 5) // fdo#40874 added fields
2270 if (aSeq
[4] >>= nVal
)
2272 aBorderLine
.LineStyle
= nVal
;
2274 if (aSeq
.getLength() >= 6)
2276 if (aSeq
[5] >>= nVal
)
2278 aBorderLine
.LineWidth
= nVal
;
2286 else if (rVal
.getValueType() == cppu::UnoType
<css::uno::Sequence
< sal_Int16
>>::get() )
2288 // serialization for basic macro recording
2289 css::uno::Sequence
< sal_Int16
> aSeq
;
2291 if (aSeq
.getLength() >= 4 && aSeq
.getLength() <= 6)
2293 aBorderLine
.Color
= aSeq
[0];
2294 aBorderLine
.InnerLineWidth
= aSeq
[1];
2295 aBorderLine
.OuterLineWidth
= aSeq
[2];
2296 aBorderLine
.LineDistance
= aSeq
[3];
2297 if (aSeq
.getLength() >= 5) // fdo#40874 added fields
2299 aBorderLine
.LineStyle
= aSeq
[4];
2300 if (aSeq
.getLength() >= 6)
2302 aBorderLine
.LineWidth
= aSeq
[5];
2312 SvxBorderLine aLine
;
2313 bool bSet
= SvxBoxItem::LineToSvxLine(aBorderLine
, aLine
, bConvert
);
2315 SetLine( &aLine
, nMemberId
== MID_HORIZONTAL
? SvxBoxInfoItemLine::HORI
: SvxBoxInfoItemLine::VERT
);
2320 sal_Int16 nFlags
= sal_Int16();
2321 bRet
= (rVal
>>= nFlags
);
2324 SetTable ( ( nFlags
& 0x01 ) != 0 );
2325 SetDist ( ( nFlags
& 0x02 ) != 0 );
2326 SetMinDist( ( nFlags
& 0x04 ) != 0 );
2331 case MID_VALIDFLAGS
:
2333 sal_Int16 nFlags
= sal_Int16();
2334 bRet
= (rVal
>>= nFlags
);
2336 nValidFlags
= static_cast<SvxBoxInfoItemValidFlags
>(nFlags
);
2342 bRet
= (rVal
>>= nVal
);
2343 if ( bRet
&& nVal
>=0 )
2346 nVal
= convertMm100ToTwip(nVal
);
2347 SetDefDist( static_cast<sal_uInt16
>(nVal
) );
2351 default: OSL_FAIL("Wrong MemberId!"); return false;
2361 void BorderDistanceFromWord(bool bFromEdge
, sal_Int32
& nMargin
, sal_Int32
& nBorderDistance
,
2362 sal_Int32 nBorderWidth
)
2364 // See https://wiki.openoffice.org/wiki/Writer/MSInteroperability/PageBorder
2366 sal_Int32 nNewMargin
= nMargin
;
2367 sal_Int32 nNewBorderDistance
= nBorderDistance
;
2371 nNewMargin
= nBorderDistance
;
2372 nNewBorderDistance
= nMargin
- nBorderDistance
- nBorderWidth
;
2376 nNewMargin
-= nBorderDistance
+ nBorderWidth
;
2379 // Ensure correct distance from page edge to text in cases not supported by us:
2380 // when border is outside entire page area (!bFromEdge && BorderDistance > Margin),
2381 // and when border is inside page body area (bFromEdge && BorderDistance > Margin)
2385 nNewBorderDistance
= std::max
<sal_Int32
>(nMargin
- nBorderWidth
, 0);
2387 else if (nNewBorderDistance
< 0)
2389 nNewMargin
= std::max
<sal_Int32
>(nMargin
- nBorderWidth
, 0);
2390 nNewBorderDistance
= 0;
2393 nMargin
= nNewMargin
;
2394 nBorderDistance
= nNewBorderDistance
;
2397 // Heuristics to decide if we need to use "from edge" offset of borders
2399 // There are two cases when we can safely use "from text" or "from edge" offset without distorting
2400 // border position (modulo rounding errors):
2401 // 1. When distance of all borders from text is no greater than 31 pt, we use "from text"
2402 // 2. Otherwise, if distance of all borders from edge is no greater than 31 pt, we use "from edge"
2403 // In all other cases, the position of borders would be distorted on export, because Word doesn't
2404 // support the offset of >31 pts (https://msdn.microsoft.com/en-us/library/ff533820), and we need
2405 // to decide which type of offset would provide less wrong result (i.e., the result would look
2406 // closer to original). Here, we just check sum of distances from text to borders, and if it is
2407 // less than sum of distances from borders to edges. The alternative would be to compare total areas
2408 // between text-and-borders and between borders-and-edges (taking into account different lengths of
2409 // borders, and visual impact of that).
2410 void BorderDistancesToWord(const SvxBoxItem
& rBox
, const WordPageMargins
& rMargins
,
2411 WordBorderDistances
& rDistances
)
2413 // Use signed sal_Int32 that can hold sal_uInt16, to prevent overflow at subtraction below
2414 const sal_Int32 nT
= rBox
.GetDistance(SvxBoxItemLine::TOP
);
2415 const sal_Int32 nL
= rBox
.GetDistance(SvxBoxItemLine::LEFT
);
2416 const sal_Int32 nB
= rBox
.GetDistance(SvxBoxItemLine::BOTTOM
);
2417 const sal_Int32 nR
= rBox
.GetDistance(SvxBoxItemLine::RIGHT
);
2419 // Only take into account existing borders
2420 const SvxBorderLine
* pLnT
= rBox
.GetLine(SvxBoxItemLine::TOP
);
2421 const SvxBorderLine
* pLnL
= rBox
.GetLine(SvxBoxItemLine::LEFT
);
2422 const SvxBorderLine
* pLnB
= rBox
.GetLine(SvxBoxItemLine::BOTTOM
);
2423 const SvxBorderLine
* pLnR
= rBox
.GetLine(SvxBoxItemLine::RIGHT
);
2425 // We need to take border widths into account
2426 const long nWidthT
= pLnT
? pLnT
->GetScaledWidth() : 0;
2427 const long nWidthL
= pLnL
? pLnL
->GetScaledWidth() : 0;
2428 const long nWidthB
= pLnB
? pLnB
->GetScaledWidth() : 0;
2429 const long nWidthR
= pLnR
? pLnR
->GetScaledWidth() : 0;
2431 // Resulting distances from text to borders
2432 const sal_Int32 nT2BT
= pLnT
? nT
: 0;
2433 const sal_Int32 nT2BL
= pLnL
? nL
: 0;
2434 const sal_Int32 nT2BB
= pLnB
? nB
: 0;
2435 const sal_Int32 nT2BR
= pLnR
? nR
: 0;
2437 // Resulting distances from edge to borders
2438 const sal_Int32 nE2BT
= pLnT
? std::max
<sal_Int32
>(rMargins
.nTop
- nT
- nWidthT
, 0) : 0;
2439 const sal_Int32 nE2BL
= pLnL
? std::max
<sal_Int32
>(rMargins
.nLeft
- nL
- nWidthL
, 0) : 0;
2440 const sal_Int32 nE2BB
= pLnB
? std::max
<sal_Int32
>(rMargins
.nBottom
- nB
- nWidthB
, 0) : 0;
2441 const sal_Int32 nE2BR
= pLnR
? std::max
<sal_Int32
>(rMargins
.nRight
- nR
- nWidthR
, 0) : 0;
2443 const sal_Int32 n32pt
= 32 * 20;
2444 // 1. If all borders are in range of 31 pts from text
2445 if (nT2BT
< n32pt
&& nT2BL
< n32pt
&& nT2BB
< n32pt
&& nT2BR
< n32pt
)
2447 rDistances
.bFromEdge
= false;
2451 // 2. If all borders are in range of 31 pts from edge
2452 if (nE2BT
< n32pt
&& nE2BL
< n32pt
&& nE2BB
< n32pt
&& nE2BR
< n32pt
)
2454 rDistances
.bFromEdge
= true;
2458 // Let's try to guess which would be the best approximation
2459 rDistances
.bFromEdge
=
2460 (nT2BT
+ nT2BL
+ nT2BB
+ nT2BR
) > (nE2BT
+ nE2BL
+ nE2BB
+ nE2BR
);
2464 if (rDistances
.bFromEdge
)
2466 rDistances
.nTop
= sal::static_int_cast
<sal_uInt16
>(nE2BT
);
2467 rDistances
.nLeft
= sal::static_int_cast
<sal_uInt16
>(nE2BL
);
2468 rDistances
.nBottom
= sal::static_int_cast
<sal_uInt16
>(nE2BB
);
2469 rDistances
.nRight
= sal::static_int_cast
<sal_uInt16
>(nE2BR
);
2473 rDistances
.nTop
= sal::static_int_cast
<sal_uInt16
>(nT2BT
);
2474 rDistances
.nLeft
= sal::static_int_cast
<sal_uInt16
>(nT2BL
);
2475 rDistances
.nBottom
= sal::static_int_cast
<sal_uInt16
>(nT2BB
);
2476 rDistances
.nRight
= sal::static_int_cast
<sal_uInt16
>(nT2BR
);
2482 // class SvxFormatBreakItem -------------------------------------------------
2484 bool SvxFormatBreakItem::operator==( const SfxPoolItem
& rAttr
) const
2486 assert(SfxPoolItem::operator==(rAttr
));
2488 return GetValue() == static_cast<const SvxFormatBreakItem
&>( rAttr
).GetValue();
2492 bool SvxFormatBreakItem::GetPresentation
2494 SfxItemPresentation
/*ePres*/,
2495 MapUnit
/*eCoreUnit*/,
2496 MapUnit
/*ePresUnit*/,
2497 OUString
& rText
, const IntlWrapper
&
2500 rText
= GetValueTextByPos( GetEnumValue() );
2504 OUString
SvxFormatBreakItem::GetValueTextByPos( sal_uInt16 nPos
)
2506 static const char* RID_SVXITEMS_BREAK
[] =
2508 RID_SVXITEMS_BREAK_NONE
,
2509 RID_SVXITEMS_BREAK_COLUMN_BEFORE
,
2510 RID_SVXITEMS_BREAK_COLUMN_AFTER
,
2511 RID_SVXITEMS_BREAK_COLUMN_BOTH
,
2512 RID_SVXITEMS_BREAK_PAGE_BEFORE
,
2513 RID_SVXITEMS_BREAK_PAGE_AFTER
,
2514 RID_SVXITEMS_BREAK_PAGE_BOTH
2516 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_BREAK
) == size_t(SvxBreak::End
), "unexpected size");
2517 assert(nPos
< sal_uInt16(SvxBreak::End
) && "enum overflow!");
2518 return EditResId(RID_SVXITEMS_BREAK
[nPos
]);
2521 bool SvxFormatBreakItem::QueryValue( uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
2523 style::BreakType eBreak
= style::BreakType_NONE
;
2524 switch ( GetBreak() )
2526 case SvxBreak::ColumnBefore
: eBreak
= style::BreakType_COLUMN_BEFORE
; break;
2527 case SvxBreak::ColumnAfter
: eBreak
= style::BreakType_COLUMN_AFTER
; break;
2528 case SvxBreak::ColumnBoth
: eBreak
= style::BreakType_COLUMN_BOTH
; break;
2529 case SvxBreak::PageBefore
: eBreak
= style::BreakType_PAGE_BEFORE
; break;
2530 case SvxBreak::PageAfter
: eBreak
= style::BreakType_PAGE_AFTER
; break;
2531 case SvxBreak::PageBoth
: eBreak
= style::BreakType_PAGE_BOTH
; break;
2532 default: ; // prevent warning
2538 bool SvxFormatBreakItem::PutValue( const uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
2540 style::BreakType nBreak
;
2542 if(!(rVal
>>= nBreak
))
2544 sal_Int32 nValue
= 0;
2545 if(!(rVal
>>= nValue
))
2548 nBreak
= static_cast<style::BreakType
>(nValue
);
2551 SvxBreak eBreak
= SvxBreak::NONE
;
2554 case style::BreakType_COLUMN_BEFORE
: eBreak
= SvxBreak::ColumnBefore
; break;
2555 case style::BreakType_COLUMN_AFTER
: eBreak
= SvxBreak::ColumnAfter
; break;
2556 case style::BreakType_COLUMN_BOTH
: eBreak
= SvxBreak::ColumnBoth
; break;
2557 case style::BreakType_PAGE_BEFORE
: eBreak
= SvxBreak::PageBefore
; break;
2558 case style::BreakType_PAGE_AFTER
: eBreak
= SvxBreak::PageAfter
; break;
2559 case style::BreakType_PAGE_BOTH
: eBreak
= SvxBreak::PageBoth
; break;
2560 default: ; // prevent warning
2568 SfxPoolItem
* SvxFormatBreakItem::Clone( SfxItemPool
* ) const
2570 return new SvxFormatBreakItem( *this );
2574 sal_uInt16
SvxFormatBreakItem::GetValueCount() const
2576 return sal_uInt16(SvxBreak::End
); // SvxBreak::PageBoth + 1
2580 SfxPoolItem
* SvxFormatKeepItem::Clone( SfxItemPool
* ) const
2582 return new SvxFormatKeepItem( *this );
2586 bool SvxFormatKeepItem::GetPresentation
2588 SfxItemPresentation
/*ePres*/,
2589 MapUnit
/*eCoreUnit*/,
2590 MapUnit
/*ePresUnit*/,
2591 OUString
& rText
, const IntlWrapper
&
2594 const char* pId
= RID_SVXITEMS_FMTKEEP_FALSE
;
2597 pId
= RID_SVXITEMS_FMTKEEP_TRUE
;
2598 rText
= EditResId(pId
);
2603 SvxLineItem::SvxLineItem( const sal_uInt16 nId
) :
2609 SvxLineItem::SvxLineItem( const SvxLineItem
& rCpy
) :
2610 SfxPoolItem ( rCpy
),
2611 pLine(rCpy
.pLine
? new SvxBorderLine( *rCpy
.pLine
) : nullptr)
2616 SvxLineItem::~SvxLineItem()
2621 bool SvxLineItem::operator==( const SfxPoolItem
& rAttr
) const
2623 assert(SfxPoolItem::operator==(rAttr
));
2625 return CmpBrdLn( pLine
, static_cast<const SvxLineItem
&>(rAttr
).GetLine() );
2629 SfxPoolItem
* SvxLineItem::Clone( SfxItemPool
* ) const
2631 return new SvxLineItem( *this );
2635 bool SvxLineItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemId
) const
2637 bool bConvert
= 0!=(nMemId
&CONVERT_TWIPS
);
2638 nMemId
&= ~CONVERT_TWIPS
;
2641 rVal
<<= SvxBoxItem::SvxLineToLine(pLine
.get(), bConvert
);
2648 case MID_FG_COLOR
: rVal
<<= pLine
->GetColor(); break;
2649 case MID_OUTER_WIDTH
: rVal
<<= sal_Int32(pLine
->GetOutWidth()); break;
2650 case MID_INNER_WIDTH
: rVal
<<= sal_Int32(pLine
->GetInWidth( )); break;
2651 case MID_DISTANCE
: rVal
<<= sal_Int32(pLine
->GetDistance()); break;
2653 OSL_FAIL( "Wrong MemberId" );
2662 bool SvxLineItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemId
)
2664 bool bConvert
= 0!=(nMemId
&CONVERT_TWIPS
);
2665 nMemId
&= ~CONVERT_TWIPS
;
2669 table::BorderLine2 aLine
;
2670 if ( lcl_extractBorderLine(rVal
, aLine
) )
2673 pLine
.reset( new SvxBorderLine
);
2674 if( !SvxBoxItem::LineToSvxLine(aLine
, *pLine
, bConvert
) )
2680 else if ( rVal
>>= nVal
)
2683 pLine
.reset( new SvxBorderLine
);
2687 case MID_FG_COLOR
: pLine
->SetColor( Color(nVal
) ); break;
2688 case MID_LINE_STYLE
:
2689 pLine
->SetBorderLineStyle(static_cast<SvxBorderLineStyle
>(nVal
));
2692 OSL_FAIL( "Wrong MemberId" );
2703 bool SvxLineItem::GetPresentation
2705 SfxItemPresentation ePres
,
2708 OUString
& rText
, const IntlWrapper
& rIntl
2714 rText
= pLine
->GetValueString( eCoreUnit
, ePresUnit
, &rIntl
,
2715 (SfxItemPresentation::Complete
== ePres
) );
2720 void SvxLineItem::ScaleMetrics( long nMult
, long nDiv
)
2722 if ( pLine
) pLine
->ScaleMetrics( nMult
, nDiv
);
2726 bool SvxLineItem::HasMetrics() const
2732 void SvxLineItem::SetLine( const SvxBorderLine
* pNew
)
2734 pLine
.reset( pNew
? new SvxBorderLine( *pNew
) : nullptr );
2737 SvxBrushItem::SvxBrushItem(sal_uInt16 _nWhich
)
2738 : SfxPoolItem(_nWhich
)
2739 , aColor(COL_TRANSPARENT
)
2740 , nShadingValue(ShadingPattern::CLEAR
)
2741 , nGraphicTransparency(0)
2742 , eGraphicPos(GPOS_NONE
)
2747 SvxBrushItem::SvxBrushItem(const Color
& rColor
, sal_uInt16 _nWhich
)
2748 : SfxPoolItem(_nWhich
)
2750 , nShadingValue(ShadingPattern::CLEAR
)
2751 , nGraphicTransparency(0)
2752 , eGraphicPos(GPOS_NONE
)
2757 SvxBrushItem::SvxBrushItem(const Graphic
& rGraphic
, SvxGraphicPosition ePos
, sal_uInt16 _nWhich
)
2758 : SfxPoolItem(_nWhich
)
2759 , aColor(COL_TRANSPARENT
)
2760 , nShadingValue(ShadingPattern::CLEAR
)
2761 , xGraphicObject(new GraphicObject(rGraphic
))
2762 , nGraphicTransparency(0)
2763 , eGraphicPos((GPOS_NONE
!= ePos
) ? ePos
: GPOS_MM
)
2766 DBG_ASSERT( GPOS_NONE
!= ePos
, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
2769 SvxBrushItem::SvxBrushItem(const GraphicObject
& rGraphicObj
, SvxGraphicPosition ePos
, sal_uInt16 _nWhich
)
2770 : SfxPoolItem(_nWhich
)
2771 , aColor(COL_TRANSPARENT
)
2772 , nShadingValue(ShadingPattern::CLEAR
)
2773 , xGraphicObject(new GraphicObject(rGraphicObj
))
2774 , nGraphicTransparency(0)
2775 , eGraphicPos((GPOS_NONE
!= ePos
) ? ePos
: GPOS_MM
)
2778 DBG_ASSERT( GPOS_NONE
!= ePos
, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
2781 SvxBrushItem::SvxBrushItem(const OUString
& rLink
, const OUString
& rFilter
,
2782 SvxGraphicPosition ePos
, sal_uInt16 _nWhich
)
2783 : SfxPoolItem(_nWhich
)
2784 , aColor(COL_TRANSPARENT
)
2785 , nShadingValue(ShadingPattern::CLEAR
)
2786 , nGraphicTransparency(0)
2788 , maStrFilter(rFilter
)
2789 , eGraphicPos((GPOS_NONE
!= ePos
) ? ePos
: GPOS_MM
)
2792 DBG_ASSERT( GPOS_NONE
!= ePos
, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
2795 SvxBrushItem::SvxBrushItem(const SvxBrushItem
& rItem
)
2796 : SfxPoolItem(rItem
)
2797 , aColor(rItem
.aColor
)
2798 , nShadingValue(rItem
.nShadingValue
)
2799 , xGraphicObject(rItem
.xGraphicObject
? new GraphicObject(*rItem
.xGraphicObject
) : nullptr)
2800 , nGraphicTransparency(rItem
.nGraphicTransparency
)
2801 , maStrLink(rItem
.maStrLink
)
2802 , maStrFilter(rItem
.maStrFilter
)
2803 , eGraphicPos(rItem
.eGraphicPos
)
2804 , bLoadAgain(rItem
.bLoadAgain
)
2808 SvxBrushItem::SvxBrushItem(SvxBrushItem
&& rItem
)
2809 : SfxPoolItem(std::move(rItem
))
2810 , aColor(std::move(rItem
.aColor
))
2811 , nShadingValue(std::move(rItem
.nShadingValue
))
2812 , xGraphicObject(std::move(rItem
.xGraphicObject
))
2813 , nGraphicTransparency(std::move(rItem
.nGraphicTransparency
))
2814 , maStrLink(std::move(rItem
.maStrLink
))
2815 , maStrFilter(std::move(rItem
.maStrFilter
))
2816 , eGraphicPos(std::move(rItem
.eGraphicPos
))
2817 , bLoadAgain(std::move(rItem
.bLoadAgain
))
2821 SvxBrushItem::~SvxBrushItem()
2825 bool SvxBrushItem::isUsed() const
2827 if (GPOS_NONE
!= GetGraphicPos())
2832 else if (0xff != GetColor().GetTransparency())
2842 static sal_Int8
lcl_PercentToTransparency(long nPercent
)
2844 // 0xff must not be returned!
2845 return sal_Int8(nPercent
? (50 + 0xfe * nPercent
) / 100 : 0);
2849 sal_Int8
SvxBrushItem::TransparencyToPercent(sal_Int32 nTrans
)
2851 return static_cast<sal_Int8
>((nTrans
* 100 + 127) / 254);
2855 bool SvxBrushItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
2857 nMemberId
&= ~CONVERT_TWIPS
;
2860 case MID_BACK_COLOR
:
2863 case MID_BACK_COLOR_R_G_B
:
2864 rVal
<<= aColor
.GetRGBColor();
2866 case MID_BACK_COLOR_TRANSPARENCY
:
2867 rVal
<<= SvxBrushItem::TransparencyToPercent(aColor
.GetTransparency());
2869 case MID_GRAPHIC_POSITION
:
2870 rVal
<<= static_cast<style::GraphicLocation
>(static_cast<sal_Int16
>(eGraphicPos
));
2873 case MID_GRAPHIC_TRANSPARENT
:
2874 rVal
<<= ( aColor
.GetTransparency() == 0xff );
2877 case MID_GRAPHIC_URL
:
2879 SAL_INFO("editeng.items", "Getting GraphicURL property is not supported");
2885 uno::Reference
<graphic::XGraphic
> xGraphic
;
2886 if (!maStrLink
.isEmpty())
2888 Graphic
aGraphic(vcl::graphic::loadFromURL(maStrLink
));
2889 xGraphic
= aGraphic
.GetXGraphic();
2891 else if (xGraphicObject
)
2893 xGraphic
= xGraphicObject
->GetGraphic().GetXGraphic();
2899 case MID_GRAPHIC_FILTER
:
2901 rVal
<<= maStrFilter
;
2905 case MID_GRAPHIC_TRANSPARENCY
:
2906 rVal
<<= nGraphicTransparency
;
2909 case MID_SHADING_VALUE
:
2911 rVal
<<= nShadingValue
;
2920 bool SvxBrushItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
2922 nMemberId
&= ~CONVERT_TWIPS
;
2925 case MID_BACK_COLOR
:
2926 case MID_BACK_COLOR_R_G_B
:
2929 if ( !( rVal
>>= aNewCol
) )
2931 if(MID_BACK_COLOR_R_G_B
== nMemberId
)
2933 aNewCol
.SetTransparency(aColor
.GetTransparency());
2938 case MID_BACK_COLOR_TRANSPARENCY
:
2940 sal_Int32 nTrans
= 0;
2941 if ( !( rVal
>>= nTrans
) || nTrans
< 0 || nTrans
> 100 )
2943 aColor
.SetTransparency(lcl_PercentToTransparency(nTrans
));
2947 case MID_GRAPHIC_POSITION
:
2949 style::GraphicLocation eLocation
;
2950 if ( !( rVal
>>=eLocation
) )
2952 sal_Int32 nValue
= 0;
2953 if ( !( rVal
>>= nValue
) )
2955 eLocation
= static_cast<style::GraphicLocation
>(nValue
);
2957 SetGraphicPos( static_cast<SvxGraphicPosition
>(static_cast<sal_uInt16
>(eLocation
)) );
2961 case MID_GRAPHIC_TRANSPARENT
:
2962 aColor
.SetTransparency( Any2Bool( rVal
) ? 0xff : 0 );
2965 case MID_GRAPHIC_URL
:
2970 if (rVal
.getValueType() == ::cppu::UnoType
<OUString
>::get())
2972 OUString aURL
= rVal
.get
<OUString
>();
2973 aGraphic
= vcl::graphic::loadFromURL(aURL
);
2975 else if (rVal
.getValueType() == cppu::UnoType
<graphic::XGraphic
>::get())
2977 auto xGraphic
= rVal
.get
<uno::Reference
<graphic::XGraphic
>>();
2978 aGraphic
= Graphic(xGraphic
);
2981 if (!aGraphic
.IsNone())
2985 std::unique_ptr
<GraphicObject
> xOldGrfObj(std::move(xGraphicObject
));
2986 xGraphicObject
.reset(new GraphicObject(aGraphic
));
2987 ApplyGraphicTransparency_Impl();
2990 if (!aGraphic
.IsNone() && eGraphicPos
== GPOS_NONE
)
2992 eGraphicPos
= GPOS_MM
;
2994 else if (aGraphic
.IsNone())
2996 eGraphicPos
= GPOS_NONE
;
3002 case MID_GRAPHIC_FILTER
:
3004 if( rVal
.getValueType() == ::cppu::UnoType
<OUString
>::get() )
3008 SetGraphicFilter( sLink
);
3012 case MID_GRAPHIC_TRANSPARENCY
:
3016 if(nTmp
>= 0 && nTmp
<= 100)
3018 nGraphicTransparency
= sal_Int8(nTmp
);
3020 ApplyGraphicTransparency_Impl();
3025 case MID_SHADING_VALUE
:
3028 if (!(rVal
>>= nVal
))
3031 nShadingValue
= nVal
;
3040 bool SvxBrushItem::GetPresentation
3042 SfxItemPresentation
/*ePres*/,
3043 MapUnit
/*eCoreUnit*/,
3044 MapUnit
/*ePresUnit*/,
3045 OUString
& rText
, const IntlWrapper
&
3048 if ( GPOS_NONE
== eGraphicPos
)
3050 rText
= ::GetColorString( aColor
) + cpDelim
;
3051 const char* pId
= RID_SVXITEMS_TRANSPARENT_FALSE
;
3053 if ( aColor
.GetTransparency() )
3054 pId
= RID_SVXITEMS_TRANSPARENT_TRUE
;
3055 rText
+= EditResId(pId
);
3059 rText
= EditResId(RID_SVXITEMS_GRAPHIC
);
3065 bool SvxBrushItem::operator==( const SfxPoolItem
& rAttr
) const
3067 assert(SfxPoolItem::operator==(rAttr
));
3069 const SvxBrushItem
& rCmp
= static_cast<const SvxBrushItem
&>(rAttr
);
3070 bool bEqual
= ( aColor
== rCmp
.aColor
&& eGraphicPos
== rCmp
.eGraphicPos
&&
3071 nGraphicTransparency
== rCmp
.nGraphicTransparency
);
3075 if ( GPOS_NONE
!= eGraphicPos
)
3077 bEqual
= maStrLink
== rCmp
.maStrLink
;
3081 bEqual
= maStrFilter
== rCmp
.maStrFilter
;
3086 if (!rCmp
.xGraphicObject
)
3087 bEqual
= !xGraphicObject
;
3089 bEqual
= xGraphicObject
&&
3090 (*xGraphicObject
== *rCmp
.xGraphicObject
);
3096 bEqual
= nShadingValue
== rCmp
.nShadingValue
;
3104 SfxPoolItem
* SvxBrushItem::Clone( SfxItemPool
* ) const
3106 return new SvxBrushItem( *this );
3110 const GraphicObject
* SvxBrushItem::GetGraphicObject(OUString
const & referer
) const
3112 if (bLoadAgain
&& !maStrLink
.isEmpty() && !xGraphicObject
)
3113 // when graphics already loaded, use as a cache
3115 if (maSecOptions
.isUntrustedReferer(referer
)) {
3119 // tdf#94088 prepare graphic and state
3121 bool bGraphicLoaded
= false;
3123 // try to create stream directly from given URL
3124 std::unique_ptr
<SvStream
> xStream(utl::UcbStreamHelper::CreateStream(maStrLink
, StreamMode::STD_READ
));
3125 // tdf#94088 if we have a stream, try to load it directly as graphic
3126 if (xStream
&& !xStream
->GetError())
3128 if (ERRCODE_NONE
== GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, maStrLink
, *xStream
,
3129 GRFILTER_FORMAT_DONTKNOW
, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg
))
3131 bGraphicLoaded
= true;
3135 // tdf#94088 if no succeeded, try if the string (which is not empty) contains
3136 // a 'data:' scheme url and try to load that (embedded graphics)
3139 INetURLObject
aGraphicURL( maStrLink
);
3141 if( INetProtocol::Data
== aGraphicURL
.GetProtocol() )
3143 std::unique_ptr
<SvMemoryStream
> const xMemStream(aGraphicURL
.getData());
3146 if (ERRCODE_NONE
== GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, "", *xMemStream
))
3148 bGraphicLoaded
= true;
3150 // tdf#94088 delete the no longer needed data scheme URL which
3151 // is potentially pretty // large, containing a base64 encoded copy of the graphic
3152 const_cast< SvxBrushItem
* >(this)->maStrLink
.clear();
3158 // tdf#94088 when we got a graphic, set it
3159 if(bGraphicLoaded
&& GraphicType::NONE
!= aGraphic
.GetType())
3161 xGraphicObject
.reset(new GraphicObject
);
3162 xGraphicObject
->SetGraphic(aGraphic
);
3163 const_cast < SvxBrushItem
*> (this)->ApplyGraphicTransparency_Impl();
3171 return xGraphicObject
.get();
3174 void SvxBrushItem::setGraphicTransparency(sal_Int8 nNew
)
3176 if (nNew
!= nGraphicTransparency
)
3178 nGraphicTransparency
= nNew
;
3179 ApplyGraphicTransparency_Impl();
3183 const Graphic
* SvxBrushItem::GetGraphic(OUString
const & referer
) const
3185 const GraphicObject
* pGrafObj
= GetGraphicObject(referer
);
3186 return( pGrafObj
? &( pGrafObj
->GetGraphic() ) : nullptr );
3189 void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew
)
3193 if ( GPOS_NONE
== eGraphicPos
)
3195 xGraphicObject
.reset();
3197 maStrFilter
.clear();
3201 if (!xGraphicObject
&& maStrLink
.isEmpty())
3203 xGraphicObject
.reset(new GraphicObject
); // Creating a dummy
3208 void SvxBrushItem::SetGraphic( const Graphic
& rNew
)
3210 if ( maStrLink
.isEmpty() )
3213 xGraphicObject
->SetGraphic(rNew
);
3215 xGraphicObject
.reset(new GraphicObject(rNew
));
3217 ApplyGraphicTransparency_Impl();
3219 if ( GPOS_NONE
== eGraphicPos
)
3220 eGraphicPos
= GPOS_MM
; // None would be brush, then Default: middle
3224 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
3228 void SvxBrushItem::SetGraphicObject( const GraphicObject
& rNewObj
)
3230 if ( maStrLink
.isEmpty() )
3233 *xGraphicObject
= rNewObj
;
3235 xGraphicObject
.reset(new GraphicObject(rNewObj
));
3237 ApplyGraphicTransparency_Impl();
3239 if ( GPOS_NONE
== eGraphicPos
)
3240 eGraphicPos
= GPOS_MM
; // None would be brush, then Default: middle
3244 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
3248 void SvxBrushItem::SetGraphicLink( const OUString
& rNew
)
3250 if ( rNew
.isEmpty() )
3255 xGraphicObject
.reset();
3259 void SvxBrushItem::SetGraphicFilter( const OUString
& rNew
)
3264 void SvxBrushItem::ApplyGraphicTransparency_Impl()
3266 DBG_ASSERT(xGraphicObject
, "no GraphicObject available" );
3269 GraphicAttr
aAttr(xGraphicObject
->GetAttr());
3270 aAttr
.SetTransparency(lcl_PercentToTransparency(
3271 nGraphicTransparency
));
3272 xGraphicObject
->SetAttr(aAttr
);
3276 void SvxBrushItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
3278 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxBrushItem"));
3279 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
3280 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("color"), BAD_CAST(aColor
.AsRGBHexString().toUtf8().getStr()));
3281 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("shadingValue"), BAD_CAST(OString::number(nShadingValue
).getStr()));
3282 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("link"), BAD_CAST(maStrLink
.toUtf8().getStr()));
3283 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("filter"), BAD_CAST(maStrFilter
.toUtf8().getStr()));
3284 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("graphicPos"), BAD_CAST(OString::number(eGraphicPos
).getStr()));
3285 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("loadAgain"), BAD_CAST(OString::boolean(bLoadAgain
).getStr()));
3286 xmlTextWriterEndElement(pWriter
);
3290 SvxFrameDirectionItem::SvxFrameDirectionItem( SvxFrameDirection nValue
,
3291 sal_uInt16 _nWhich
)
3292 : SfxEnumItem
<SvxFrameDirection
>( _nWhich
, nValue
)
3297 SvxFrameDirectionItem::~SvxFrameDirectionItem()
3302 SfxPoolItem
* SvxFrameDirectionItem::Clone( SfxItemPool
* ) const
3304 return new SvxFrameDirectionItem( *this );
3308 const char* getFrmDirResId(size_t nIndex
)
3310 const char* const RID_SVXITEMS_FRMDIR
[] =
3312 RID_SVXITEMS_FRMDIR_HORI_LEFT_TOP
,
3313 RID_SVXITEMS_FRMDIR_HORI_RIGHT_TOP
,
3314 RID_SVXITEMS_FRMDIR_VERT_TOP_RIGHT
,
3315 RID_SVXITEMS_FRMDIR_VERT_TOP_LEFT
,
3316 RID_SVXITEMS_FRMDIR_ENVIRONMENT
,
3317 RID_SVXITEMS_FRMDIR_VERT_BOT_LEFT
3319 return RID_SVXITEMS_FRMDIR
[nIndex
];
3322 bool SvxFrameDirectionItem::GetPresentation(
3323 SfxItemPresentation
/*ePres*/,
3324 MapUnit
/*eCoreUnit*/,
3325 MapUnit
/*ePresUnit*/,
3326 OUString
& rText
, const IntlWrapper
&) const
3328 rText
= EditResId(getFrmDirResId(GetEnumValue()));
3332 bool SvxFrameDirectionItem::PutValue( const css::uno::Any
& rVal
,
3335 sal_Int16 nVal
= sal_Int16();
3336 bool bRet
= ( rVal
>>= nVal
);
3339 // translate WritingDirection2 constants into SvxFrameDirection
3342 case text::WritingMode2::LR_TB
:
3343 SetValue( SvxFrameDirection::Horizontal_LR_TB
);
3345 case text::WritingMode2::RL_TB
:
3346 SetValue( SvxFrameDirection::Horizontal_RL_TB
);
3348 case text::WritingMode2::TB_RL
:
3349 SetValue( SvxFrameDirection::Vertical_RL_TB
);
3351 case text::WritingMode2::TB_LR
:
3352 SetValue( SvxFrameDirection::Vertical_LR_TB
);
3354 case text::WritingMode2::BT_LR
:
3355 SetValue( SvxFrameDirection::Vertical_LR_BT
);
3357 case text::WritingMode2::PAGE
:
3358 SetValue( SvxFrameDirection::Environment
);
3370 bool SvxFrameDirectionItem::QueryValue( css::uno::Any
& rVal
,
3373 // translate SvxFrameDirection into WritingDirection2
3376 switch( GetValue() )
3378 case SvxFrameDirection::Horizontal_LR_TB
:
3379 nVal
= text::WritingMode2::LR_TB
;
3381 case SvxFrameDirection::Horizontal_RL_TB
:
3382 nVal
= text::WritingMode2::RL_TB
;
3384 case SvxFrameDirection::Vertical_RL_TB
:
3385 nVal
= text::WritingMode2::TB_RL
;
3387 case SvxFrameDirection::Vertical_LR_TB
:
3388 nVal
= text::WritingMode2::TB_LR
;
3390 case SvxFrameDirection::Vertical_LR_BT
:
3391 nVal
= text::WritingMode2::BT_LR
;
3393 case SvxFrameDirection::Environment
:
3394 nVal
= text::WritingMode2::PAGE
;
3397 OSL_FAIL("Unknown SvxFrameDirection value!");
3402 // return value + error state
3410 void SvxFrameDirectionItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
3412 xmlTextWriterStartElement(pWriter
, BAD_CAST("SvxFrameDirectionItem"));
3413 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("m_nWhich"),
3414 BAD_CAST(OString::number(Which()).getStr()));
3415 xmlTextWriterWriteAttribute(
3416 pWriter
, BAD_CAST("m_nValue"),
3417 BAD_CAST(OString::number(static_cast<sal_Int16
>(GetValue())).getStr()));
3418 xmlTextWriterEndElement(pWriter
);
3421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */