/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http: // mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http: // www.apache.org/licenses/LICENSE-2.0 .
*/
#include <memory>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/script/Converter.hpp>
#include <com/sun/star/table/ShadowLocation.hpp>
#include <com/sun/star/table/ShadowFormat.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/BorderLineStyle.hpp>
#include <com/sun/star/style/BreakType.hpp>
#include <com/sun/star/style/GraphicLocation.hpp>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/beans/Pair.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
#include <com/sun/star/frame/status/UpperLowerMarginScale.hpp>
#include <com/sun/star/frame/status/LeftRightMarginScale.hpp>
#include <com/sun/star/drawing/ShadingPattern.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/util/XComplexColor.hpp>
#include <osl/diagnose.h>
#include <i18nutil/unicode.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <comphelper/processfactory.hxx>
#include <utility>
#include <vcl/GraphicObject.hxx>
#include <tools/urlobj.hxx>
#include <tools/bigint.hxx>
#include <svl/memberid.h>
#include <rtl/math.hxx>
#include <rtl/ustring.hxx>
#include <tools/mapunit.hxx>
#include <tools/UnitConversion.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <editeng/editrids.hrc>
#include <editeng/pbinitem.hxx>
#include <editeng/sizeitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/prntitem.hxx>
#include <editeng/opaqitem.hxx>
#include <editeng/protitem.hxx>
#include <editeng/shaditem.hxx>
#include <editeng/borderline.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/formatbreakitem.hxx>
#include <editeng/keepitem.hxx>
#include <editeng/lineitem.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/frmdiritem.hxx>
#include <editeng/itemtype.hxx>
#include <editeng/eerdll.hxx>
#include <editeng/memberids.h>
#include <libxml/xmlwriter.h>
#include <o3tl/enumrange.hxx>
#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <sax/tools/converter.hxx>
#include <vcl/GraphicLoader.hxx>
#include <unotools/securityoptions.hxx>
#include <docmodel/uno/UnoComplexColor.hxx>
#include <boost/property_tree/ptree.hpp>
using namespace ::editeng;
using namespace ::com::sun::star;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::table::BorderLineStyle;
SfxPoolItem* SvxPaperBinItem::CreateDefault() { return new SvxPaperBinItem(0);}
SfxPoolItem* SvxSizeItem::CreateDefault() { return new SvxSizeItem(0);}
SfxPoolItem* SvxLRSpaceItem::CreateDefault() { return new SvxLRSpaceItem(0);}
SfxPoolItem* SvxULSpaceItem::CreateDefault() { return new SvxULSpaceItem(0);}
SfxPoolItem* SvxProtectItem::CreateDefault() { return new SvxProtectItem(0);}
SfxPoolItem* SvxBrushItem::CreateDefault() { return new SvxBrushItem(0);}
SfxPoolItem* SvxShadowItem::CreateDefault() { return new SvxShadowItem(0);}
SfxPoolItem* SvxBoxItem::CreateDefault() { return new SvxBoxItem(0);}
SfxPoolItem* SvxBoxInfoItem::CreateDefault() { return new SvxBoxInfoItem(0);}
SfxPoolItem* SvxFormatBreakItem::CreateDefault() { return new SvxFormatBreakItem(SvxBreak::NONE, 0);}
SfxPoolItem* SvxFormatKeepItem::CreateDefault() { return new SvxFormatKeepItem(false , 0);}
SfxPoolItem* SvxLineItem::CreateDefault() { return new SvxLineItem(0);}
SvxPaperBinItem* SvxPaperBinItem::Clone( SfxItemPool* ) const
{
return new SvxPaperBinItem( *this );
}
bool SvxPaperBinItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
switch ( ePres )
{
case SfxItemPresentation::Nameless:
rText = OUString::number( GetValue() );
return true ;
case SfxItemPresentation::Complete:
{
sal_uInt8 nValue = GetValue();
if ( PAPERBIN_PRINTER_SETTINGS == nValue )
rText = EditResId(RID_SVXSTR_PAPERBIN_SETTINGS);
else
{
rText = EditResId(RID_SVXSTR_PAPERBIN) + " " + OUString::number( nValue );
}
return true ;
}
//no break necessary
default : ; //prevent warning
}
return false ;
}
SvxSizeItem::SvxSizeItem( const sal_uInt16 nId, const Size& rSize ) :
SfxPoolItem( nId ),
m_aSize( rSize )
{
}
bool SvxSizeItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
awt::Size aTmp(m_aSize.Width(), m_aSize.Height());
if ( bConvert )
{
aTmp.Height = convertTwipToMm100(aTmp.Height);
aTmp.Width = convertTwipToMm100(aTmp.Width);
}
switch ( nMemberId )
{
case MID_SIZE_SIZE: rVal <<= aTmp; break ;
case MID_SIZE_WIDTH: rVal <<= aTmp.Width; break ;
case MID_SIZE_HEIGHT: rVal <<= aTmp.Height; break ;
default : OSL_FAIL("Wrong MemberId!" ); return false ;
}
return true ;
}
bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch ( nMemberId )
{
case MID_SIZE_SIZE:
{
awt::Size aTmp;
if ( rVal >>= aTmp )
{
if (bConvert)
{
aTmp.Height = o3tl::toTwips(aTmp.Height, o3tl::Length::mm100);
aTmp.Width = o3tl::toTwips(aTmp.Width, o3tl::Length::mm100);
}
m_aSize = Size( aTmp.Width, aTmp.Height );
}
else
{
return false ;
}
}
break ;
case MID_SIZE_WIDTH:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal ))
return false ;
m_aSize.setWidth( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
}
break ;
case MID_SIZE_HEIGHT:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal))
return true ;
m_aSize.setHeight( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal );
}
break ;
default : OSL_FAIL("Wrong MemberId!" );
return false ;
}
return true ;
}
SvxSizeItem::SvxSizeItem( const sal_uInt16 nId ) :
SfxPoolItem( nId )
{
}
bool SvxSizeItem::operator ==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator ==(rAttr));
return ( m_aSize == static_cast <const SvxSizeItem&>( rAttr ).GetSize() );
}
SvxSizeItem* SvxSizeItem::Clone( SfxItemPool* ) const
{
return new SvxSizeItem( *this );
}
bool SvxSizeItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
OUString cpDelimTmp(cpDelim);
switch ( ePres )
{
case SfxItemPresentation::Nameless:
rText = GetMetricText( m_aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
cpDelimTmp +
GetMetricText( m_aSize.Height(), eCoreUnit, ePresUnit, &rIntl );
return true ;
case SfxItemPresentation::Complete:
rText = EditResId(RID_SVXITEMS_SIZE_WIDTH) +
GetMetricText( m_aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit)) +
cpDelimTmp +
EditResId(RID_SVXITEMS_SIZE_HEIGHT) +
GetMetricText( m_aSize.Height(), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit));
return true ;
// no break necessary
default : ; // prevent warning
}
return false ;
}
void SvxSizeItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
{
m_aSize.setWidth( BigInt::Scale( m_aSize.Width(), nMult, nDiv ) );
m_aSize.setHeight( BigInt::Scale( m_aSize.Height(), nMult, nDiv ) );
}
bool SvxSizeItem::HasMetrics() const
{
return true ;
}
double SvxIndentValue::ResolveDouble(const SvxFontUnitMetrics& rMetrics) const
{
if (m_nUnit == css::util::MeasureUnit::TWIP)
return m_dValue;
SAL_WARN_IF(!rMetrics.m_bInitialized, "editeng" , "font-relative indentation lost" );
switch (m_nUnit)
{
case css::util::MeasureUnit::FONT_EM:
return m_dValue * rMetrics.m_dEmTwips;
case css::util::MeasureUnit::FONT_CJK_ADVANCE:
return m_dValue * rMetrics.m_dIcTwips;
default :
SAL_WARN("editeng" , "unhandled type conversion" );
return 0.0;
}
}
sal_Int32 SvxIndentValue::Resolve(const SvxFontUnitMetrics& rMetrics) const
{
return static_cast <sal_Int32>(std::llround(ResolveDouble(rMetrics)));
}
sal_Int32 SvxIndentValue::ResolveFixedPart() const
{
if (m_nUnit == css::util::MeasureUnit::TWIP)
return Resolve({});
return 0;
}
sal_Int32 SvxIndentValue::ResolveVariablePart(const SvxFontUnitMetrics& rMetrics) const
{
if (m_nUnit == css::util::MeasureUnit::TWIP)
return 0;
return Resolve(rMetrics);
}
void SvxIndentValue::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
{
m_dValue = (m_dValue * static_cast <double >(nMult)) / static_cast <double >(nDiv);
}
size_t SvxIndentValue::hashCode() const
{
std::size_t seed(0);
o3tl::hash_combine(seed, m_dValue);
o3tl::hash_combine(seed, m_nUnit);
return seed;
}
namespace
{
boost::property_tree::ptree lcl_IndentValueToJson(const char * aName, SvxIndentValue stValue)
{
boost::property_tree::ptree aState;
switch (stValue.m_nUnit)
{
case css::util::MeasureUnit::TWIP:
{
OUString sValue
= GetMetricText(stValue.m_dValue, MapUnit::MapTwip, MapUnit::MapInch, nullptr);
aState.put(aName, sValue);
aState.put("unit" , "inch" );
}
break ;
case css::util::MeasureUnit::FONT_EM:
aState.put(aName, stValue.m_dValue);
aState.put("unit" , "em" );
break ;
case css::util::MeasureUnit::FONT_CJK_ADVANCE:
aState.put(aName, stValue.m_dValue);
aState.put("unit" , "ic" );
break ;
default :
SAL_WARN("editeng" , "unhandled type conversion" );
break ;
}
return aState;
}
bool lcl_FillAbsoluteMeasureAny(const SvxIndentValue& rIndent, uno::Any& rVal, bool bConvert)
{
if (rIndent.m_nUnit == css::util::MeasureUnit::TWIP)
{
auto nConvOffset = (bConvert ? convertTwipToMm100(rIndent.m_dValue) : rIndent.m_dValue);
rVal <<= static_cast <sal_Int32>(std::llround(nConvOffset));
return true ;
}
return false ;
}
bool lcl_FillRelativeMeasureAny(const SvxIndentValue& rIndent, uno::Any& rVal)
{
if (rIndent.m_nUnit != css::util::MeasureUnit::TWIP)
{
rVal <<= css::beans::Pair<double , sal_Int16>{ rIndent.m_dValue, rIndent.m_nUnit };
return true ;
}
return false ;
}
}
SvxLRSpaceItem::SvxLRSpaceItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
, m_nGutterMargin(0)
, m_nRightGutterMargin(0),
nPropFirstLineOffset( 100 ),
nPropLeftMargin( 100 ),
nPropRightMargin( 100 ),
bAutoFirst ( false ),
bExplicitZeroMarginValRight(false ),
bExplicitZeroMarginValLeft(false )
{
}
SvxLRSpaceItem::SvxLRSpaceItem(SvxIndentValue stLeft, SvxIndentValue stRight,
SvxIndentValue stOffset, const sal_uInt16 nId)
: SfxPoolItem(nId)
, m_nGutterMargin(0)
, m_nRightGutterMargin(0)
, nPropFirstLineOffset(100)
, nPropLeftMargin(100)
, nPropRightMargin(100)
, bAutoFirst(false )
, bExplicitZeroMarginValRight(false )
, bExplicitZeroMarginValLeft(false )
{
SetLeft(stLeft);
SetRight(stRight);
SetTextFirstLineOffset(stOffset);
}
bool SvxLRSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
bool bRet = true ;
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch ( nMemberId )
{
// now all signed
case 0:
{
css::frame::status::LeftRightMarginScale aLRSpace;
auto nLeftTwips = ResolveLeft({});
aLRSpace.Left
= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(nLeftTwips) : nLeftTwips);
auto nTextLeftTwips = ResolveTextLeft({});
aLRSpace.TextLeft = static_cast <sal_Int32>(bConvert ? convertTwipToMm100(nTextLeftTwips)
: nTextLeftTwips);
auto nRightTwips = ResolveRight({});
aLRSpace.Right
= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(nRightTwips) : nRightTwips);
aLRSpace.ScaleLeft = static_cast <sal_Int16>(nPropLeftMargin);
aLRSpace.ScaleRight = static_cast <sal_Int16>(nPropRightMargin);
auto nFirstLineOffsetTwips = ResolveTextFirstLineOffset({});
aLRSpace.FirstLine = static_cast <sal_Int32>(bConvert ? convertTwipToMm100(nFirstLineOffsetTwips) : nFirstLineOffsetTwips);
aLRSpace.ScaleFirstLine = static_cast <sal_Int16>(nPropFirstLineOffset);
aLRSpace.AutoFirstLine = IsAutoFirst();
rVal <<= aLRSpace;
break ;
}
case MID_L_MARGIN:
bRet = lcl_FillAbsoluteMeasureAny(GetLeft(), rVal, bConvert);
break ;
case MID_TXT_LMARGIN:
bRet = lcl_FillAbsoluteMeasureAny(GetTextLeft(), rVal, bConvert);
break ;
case MID_L_UNIT_MARGIN:
bRet = lcl_FillRelativeMeasureAny(GetTextLeft(), rVal);
break ;
case MID_R_MARGIN:
bRet = lcl_FillAbsoluteMeasureAny(m_stRightMargin, rVal, bConvert);
break ;
case MID_R_UNIT_MARGIN:
bRet = lcl_FillRelativeMeasureAny(m_stRightMargin, rVal);
break ;
case MID_L_REL_MARGIN:
rVal <<= static_cast <sal_Int16>(nPropLeftMargin);
break ;
case MID_R_REL_MARGIN:
rVal <<= static_cast <sal_Int16>(nPropRightMargin);
break ;
case MID_FIRST_LINE_INDENT:
bRet = lcl_FillAbsoluteMeasureAny(m_stFirstLineOffset, rVal, bConvert);
break ;
case MID_FIRST_LINE_REL_INDENT:
rVal <<= static_cast <sal_Int16>(nPropFirstLineOffset);
break ;
case MID_FIRST_LINE_UNIT_INDENT:
bRet = lcl_FillRelativeMeasureAny(m_stFirstLineOffset, rVal);
break ;
case MID_FIRST_AUTO:
rVal <<= IsAutoFirst();
break ;
case MID_GUTTER_MARGIN:
rVal <<= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(m_nGutterMargin)
: m_nGutterMargin);
break ;
default :
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
return bRet;
}
bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
bool bConvert = 0 != (nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
sal_Int32 nVal = 0;
if (nMemberId != 0 && nMemberId != MID_FIRST_AUTO && nMemberId != MID_L_REL_MARGIN
&& nMemberId != MID_R_REL_MARGIN && nMemberId != MID_FIRST_LINE_UNIT_INDENT
&& nMemberId != MID_L_UNIT_MARGIN && nMemberId != MID_R_UNIT_MARGIN)
if (!(rVal >>= nVal))
return false ;
switch ( nMemberId )
{
case 0:
{
css::frame::status::LeftRightMarginScale aLRSpace;
if (!(rVal >>= aLRSpace))
return false ;
SetLeft(SvxIndentValue::twips(
bConvert ? o3tl::toTwips(aLRSpace.Left, o3tl::Length::mm100) : aLRSpace.Left));
SetTextLeft(SvxIndentValue::twips(
bConvert ? o3tl::toTwips(aLRSpace.TextLeft, o3tl::Length::mm100)
: aLRSpace.TextLeft));
SetRight(SvxIndentValue::twips(
bConvert ? o3tl::toTwips(aLRSpace.Right, o3tl::Length::mm100) : aLRSpace.Right));
nPropLeftMargin = aLRSpace.ScaleLeft;
nPropRightMargin = aLRSpace.ScaleRight;
SetTextFirstLineOffset(SvxIndentValue::twips(
bConvert ? o3tl::toTwips(aLRSpace.FirstLine, o3tl::Length::mm100)
: aLRSpace.FirstLine));
SetPropTextFirstLineOffset ( aLRSpace.ScaleFirstLine );
SetAutoFirst( aLRSpace.AutoFirstLine );
break ;
}
case MID_L_MARGIN:
SetLeft(
SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal));
break ;
case MID_TXT_LMARGIN:
SetTextLeft(
SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal));
break ;
case MID_L_UNIT_MARGIN:
{
css::beans::Pair<double , sal_Int16> stVal;
if (!(rVal >>= stVal))
{
return false ;
}
SetTextLeft(SvxIndentValue{ stVal.First, stVal.Second });
break ;
}
case MID_R_MARGIN:
SetRight(
SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal));
break ;
case MID_R_UNIT_MARGIN:
{
css::beans::Pair<double , sal_Int16> stVal;
if (!(rVal >>= stVal))
{
return false ;
}
SetRight(SvxIndentValue{ stVal.First, stVal.Second });
break ;
}
case MID_L_REL_MARGIN:
case MID_R_REL_MARGIN:
{
sal_Int32 nRel = 0;
if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
{
if (MID_L_REL_MARGIN== nMemberId)
nPropLeftMargin = static_cast <sal_uInt16>(nRel);
else
nPropRightMargin = static_cast <sal_uInt16>(nRel);
}
else
return false ;
}
break ;
case MID_FIRST_LINE_INDENT:
SetTextFirstLineOffset(
SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal));
break ;
case MID_FIRST_LINE_REL_INDENT:
SetPropTextFirstLineOffset ( nVal );
break ;
case MID_FIRST_LINE_UNIT_INDENT:
{
css::beans::Pair<double , sal_Int16> stVal;
if (!(rVal >>= stVal))
{
return false ;
}
SetTextFirstLineOffset(SvxIndentValue{ stVal.First, stVal.Second });
break ;
}
case MID_FIRST_AUTO:
SetAutoFirst( Any2Bool(rVal) );
break ;
case MID_GUTTER_MARGIN:
SetGutterMargin(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
break ;
default :
OSL_FAIL("unknown MemberId" );
return false ;
}
return true ;
}
void SvxLeftMarginItem::SetLeft(const tools::Long nL, const sal_uInt16 nProp)
{
m_nLeftMargin = (nL * nProp) / 100;
m_nPropLeftMargin = nProp;
}
void SvxLRSpaceItem::SetLeft(SvxIndentValue stL, const sal_uInt16 nProp)
{
SAL_WARN_IF(m_stFirstLineOffset.m_dValue != 0.0, "editeng" ,
"probably call SetTextLeft instead? looks inconsistent otherwise" );
m_stLeftMargin = stL;
nPropLeftMargin = nProp;
if (nProp != 100)
{
m_stLeftMargin.m_dValue = (stL.m_dValue * static_cast <double >(nProp)) / 100.0;
}
}
SvxIndentValue SvxLRSpaceItem::GetLeft() const { return m_stLeftMargin; }
sal_Int32 SvxLRSpaceItem::ResolveLeft(const SvxFontUnitMetrics& rMetrics) const
{
return m_stLeftMargin.Resolve(rMetrics);
}
void SvxRightMarginItem::SetRight(SvxIndentValue stR, const sal_uInt16 nProp)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_stRightMargin = stR;
m_nPropRightMargin = nProp;
if (nProp != 100)
{
m_stRightMargin.m_dValue = (stR.m_dValue * static_cast <double >(nProp)) / 100.0;
}
}
SvxIndentValue SvxRightMarginItem::GetRight() const { return m_stRightMargin; }
SvxIndentValue SvxLRSpaceItem::GetRight() const { return m_stRightMargin; }
sal_Int32 SvxRightMarginItem::ResolveRight(const SvxFontUnitMetrics& rMetrics) const
{
return m_stRightMargin.Resolve(rMetrics);
}
sal_Int32 SvxLRSpaceItem::ResolveRight(const SvxFontUnitMetrics& rMetrics) const
{
return m_stRightMargin.Resolve(rMetrics);
}
sal_Int32 SvxRightMarginItem::ResolveRightFixedPart() const
{
return m_stRightMargin.ResolveFixedPart();
}
sal_Int32 SvxRightMarginItem::ResolveRightVariablePart(const SvxFontUnitMetrics& rMetrics) const
{
return m_stRightMargin.ResolveVariablePart(rMetrics);
}
sal_uInt16 SvxRightMarginItem::GetPropRight() const { return m_nPropRightMargin; }
void SvxLRSpaceItem::SetRight(SvxIndentValue stR, const sal_uInt16 nProp)
{
if (0.0 == stR.m_dValue)
{
SetExplicitZeroMarginValRight(true );
}
m_stRightMargin = stR;
nPropRightMargin = nProp;
if (nProp != 100)
{
m_stRightMargin.m_dValue = (stR.m_dValue * static_cast <double >(nProp)) / 100.0;
}
}
void SvxLRSpaceItem::SetTextFirstLineOffset(SvxIndentValue stValue, sal_uInt16 nProp)
{
// note: left margin contains any negative first line offset - preserve it!
if (m_stFirstLineOffset.m_dValue < 0.0)
{
m_stLeftMargin
= SvxIndentValue::twips(m_stLeftMargin.Resolve({}) - ResolveTextFirstLineOffset({}));
}
m_stFirstLineOffset = stValue;
nPropFirstLineOffset = nProp;
if (nProp != 100)
{
m_stFirstLineOffset.m_dValue = (stValue.m_dValue * static_cast <double >(nProp)) / 100.0;
}
if (m_stFirstLineOffset.m_dValue < 0.0)
{
m_stLeftMargin
= SvxIndentValue::twips(m_stLeftMargin.Resolve({}) + ResolveTextFirstLineOffset({}));
}
}
void SvxTextLeftMarginItem::SetTextLeft(SvxIndentValue stL, const sal_uInt16 nProp)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_stTextLeftMargin = stL;
m_nPropLeftMargin = nProp;
if (nProp != 100)
{
m_stTextLeftMargin.m_dValue = (stL.m_dValue * static_cast <double >(nProp)) / 100.0;
}
}
void SvxLRSpaceItem::SetTextLeft(SvxIndentValue stL, const sal_uInt16 nProp)
{
if (0.0 == stL.m_dValue)
{
SetExplicitZeroMarginValLeft(true );
}
m_stLeftMargin = stL;
nPropLeftMargin = nProp;
if (nProp != 100)
{
m_stLeftMargin.m_dValue = (stL.m_dValue * static_cast <double >(nProp)) / 100.0;
}
// note: left margin contains any negative first line offset
if (0.0 > m_stFirstLineOffset.m_dValue)
{
m_stLeftMargin
= SvxIndentValue::twips(m_stLeftMargin.Resolve({}) + ResolveTextFirstLineOffset({}));
}
}
SvxIndentValue SvxLRSpaceItem::GetTextFirstLineOffset() const
{
return m_stFirstLineOffset;
}
sal_Int32 SvxLRSpaceItem::ResolveTextFirstLineOffset(const SvxFontUnitMetrics& rMetrics) const
{
return m_stFirstLineOffset.Resolve(rMetrics);
}
SvxIndentValue SvxTextLeftMarginItem::GetTextLeft() const { return m_stTextLeftMargin; }
sal_Int32 SvxTextLeftMarginItem::ResolveTextLeft(const SvxFontUnitMetrics& rMetrics) const
{
return m_stTextLeftMargin.Resolve(rMetrics);
}
sal_Int32 SvxTextLeftMarginItem::ResolveLeft(const SvxFirstLineIndentItem& rFirstLine,
const SvxFontUnitMetrics& rMetrics) const
{
auto nLeft = m_stTextLeftMargin.Resolve(rMetrics);
// add any negative first line offset to text left margin to get left
auto nFirstLine = rFirstLine.GetTextFirstLineOffset().Resolve(rMetrics);
if (nFirstLine < 0)
{
nLeft += nFirstLine;
}
return nLeft;
}
sal_Int32
SvxTextLeftMarginItem::ResolveLeftFixedPart(const SvxFirstLineIndentItem& rFirstLine) const
{
auto nLeft = m_stTextLeftMargin.ResolveFixedPart();
// add any negative first line offset to text left margin to get left
auto nFirstLine = rFirstLine.GetTextFirstLineOffset().ResolveFixedPart();
if (nFirstLine < 0)
{
nLeft += nFirstLine;
}
return nLeft;
}
sal_Int32 SvxTextLeftMarginItem::ResolveLeftVariablePart(const SvxFirstLineIndentItem& rFirstLine,
const SvxFontUnitMetrics& rMetrics) const
{
auto nLeft = m_stTextLeftMargin.ResolveVariablePart(rMetrics);
// add any negative first line offset to text left margin to get left
auto nFirstLine = rFirstLine.GetTextFirstLineOffset().ResolveVariablePart(rMetrics);
if (nFirstLine < 0)
{
nLeft += nFirstLine;
}
return nLeft;
}
sal_uInt16 SvxTextLeftMarginItem::GetPropLeft() const { return m_nPropLeftMargin; }
SvxIndentValue SvxLRSpaceItem::GetTextLeft() const
{
// remove any negative first line offset from left margin to get text-left
if (m_stFirstLineOffset.m_dValue < 0.0)
{
return SvxIndentValue::twips(m_stLeftMargin.Resolve({}) - ResolveTextFirstLineOffset({}));
}
return m_stLeftMargin;
}
sal_Int32 SvxLRSpaceItem::ResolveTextLeft(const SvxFontUnitMetrics& rMetrics) const
{
// remove any negative first line offset from left margin to get text-left
if (m_stFirstLineOffset.m_dValue < 0.0)
{
return m_stLeftMargin.Resolve(rMetrics) - ResolveTextFirstLineOffset(rMetrics);
}
return m_stLeftMargin.Resolve(rMetrics);
}
SvxLeftMarginItem::SvxLeftMarginItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
SvxLeftMarginItem::SvxLeftMarginItem(const tools::Long nLeft, const sal_uInt16 nId)
: SfxPoolItem(nId)
, m_nLeftMargin(nLeft)
{
}
bool SvxLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
{
bool bRet = true ;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_L_MARGIN:
rVal <<= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(m_nLeftMargin) : m_nLeftMargin);
break ;
case MID_L_REL_MARGIN:
rVal <<= static_cast <sal_Int16>(m_nPropLeftMargin);
break ;
default :
assert(false );
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
return bRet;
}
bool SvxLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
{
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_L_MARGIN:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal))
{
return false ;
}
SetLeft(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
break ;
}
case MID_L_REL_MARGIN:
{
sal_Int32 nRel = 0;
if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
{
m_nPropLeftMargin = static_cast <sal_uInt16>(nRel);
}
else
{
return false ;
}
}
break ;
default :
assert(false );
OSL_FAIL("unknown MemberId" );
return false ;
}
return true ;
}
bool SvxLeftMarginItem::operator ==(const SfxPoolItem& rAttr) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxLeftMarginItem& rOther = static_cast <const SvxLeftMarginItem&>(rAttr);
return (m_nLeftMargin == rOther.GetLeft()
&& m_nPropLeftMargin == rOther.GetPropLeft());
}
SvxLeftMarginItem* SvxLeftMarginItem::Clone(SfxItemPool *) const
{
return new SvxLeftMarginItem(*this );
}
bool SvxLeftMarginItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
switch (ePres)
{
case SfxItemPresentation::Nameless:
{
if (100 != m_nPropLeftMargin)
{
rText = unicode::formatPercent(m_nPropLeftMargin,
Application::GetSettings().GetUILanguageTag());
}
else
{
rText = GetMetricText(m_nLeftMargin,
eCoreUnit, ePresUnit, &rIntl);
}
return true ;
}
case SfxItemPresentation::Complete:
{
rText = EditResId(RID_SVXITEMS_LRSPACE_LEFT);
if (100 != m_nPropLeftMargin)
{
rText += unicode::formatPercent(m_nPropLeftMargin,
Application::GetSettings().GetUILanguageTag());
}
else
{
rText += GetMetricText(m_nLeftMargin, eCoreUnit, ePresUnit, &rIntl)
+ " " + EditResId(GetMetricId(ePresUnit));
}
return true ;
}
default : ; // prevent warning
}
return false ;
}
void SvxLeftMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
{
m_nLeftMargin = BigInt::Scale(m_nLeftMargin, nMult, nDiv);
}
bool SvxLeftMarginItem::HasMetrics() const
{
return true ;
}
void SvxLeftMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void )xmlTextWriterStartElement(pWriter, BAD_CAST("SvxLeftMarginItem" ));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId" ), BAD_CAST(OString::number(Which()).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLeftMargin" ), BAD_CAST(OString::number(m_nLeftMargin).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropLeftMargin" ), BAD_CAST(OString::number(m_nPropLeftMargin).getStr()));
(void )xmlTextWriterEndElement(pWriter);
}
boost::property_tree::ptree SvxLeftMarginItem::dumpAsJSON() const
{
boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
boost::property_tree::ptree aState;
MapUnit eTargetUnit = MapUnit::MapInch;
OUString sLeft = GetMetricText(GetLeft(),
MapUnit::MapTwip, eTargetUnit, nullptr);
aState.put("left" , sLeft);
aState.put("unit" , "inch" );
aTree.push_back(std::make_pair("state" , aState));
return aTree;
}
SvxTextLeftMarginItem::SvxTextLeftMarginItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
SvxTextLeftMarginItem::SvxTextLeftMarginItem(SvxIndentValue stLeft, const sal_uInt16 nId)
: SfxPoolItem(nId)
{
SetTextLeft(stLeft);
}
bool SvxTextLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
{
bool bRet = false ;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
// tdf#154282 - return both values for the hardcoded 0 in SfxDispatchController_Impl::StateChanged
case 0:
{
css::frame::status::LeftRightMarginScale aLRSpace;
auto nLeftTwips = m_stTextLeftMargin.Resolve({});
aLRSpace.TextLeft
= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(nLeftTwips) : nLeftTwips);
aLRSpace.ScaleLeft = static_cast <sal_Int16>(m_nPropLeftMargin);
rVal <<= aLRSpace;
bRet = true ;
break ;
}
case MID_TXT_LMARGIN :
bRet = lcl_FillAbsoluteMeasureAny(m_stTextLeftMargin, rVal, bConvert);
break ;
case MID_L_REL_MARGIN:
rVal <<= static_cast <sal_Int16>(m_nPropLeftMargin);
bRet = true ;
break ;
case MID_L_UNIT_MARGIN:
bRet = lcl_FillRelativeMeasureAny(m_stTextLeftMargin, rVal);
break ;
default :
assert(false );
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
return bRet;
}
bool SvxTextLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_TXT_LMARGIN:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal))
{
return false ;
}
SetTextLeft(
SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal));
break ;
}
case MID_L_REL_MARGIN:
{
sal_Int32 nRel = 0;
if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
{
m_nPropLeftMargin = static_cast <sal_uInt16>(nRel);
}
else
{
return false ;
}
break ;
}
case MID_L_UNIT_MARGIN:
{
css::beans::Pair<double , sal_Int16> stVal;
if (!(rVal >>= stVal))
{
return false ;
}
SetTextLeft(SvxIndentValue{ stVal.First, stVal.Second });
break ;
}
default :
assert(false );
OSL_FAIL("unknown MemberId" );
return false ;
}
return true ;
}
bool SvxTextLeftMarginItem::operator ==(const SfxPoolItem& rAttr) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxTextLeftMarginItem& rOther = static_cast <const SvxTextLeftMarginItem&>(rAttr);
return std::tie(m_stTextLeftMargin, m_nPropLeftMargin)
== std::tie(rOther.m_stTextLeftMargin, rOther.m_nPropLeftMargin);
}
size_t SvxTextLeftMarginItem::hashCode() const
{
std::size_t seed(0);
o3tl::hash_combine(seed, m_stTextLeftMargin.hashCode());
o3tl::hash_combine(seed, m_nPropLeftMargin);
return seed;
}
SvxTextLeftMarginItem* SvxTextLeftMarginItem::Clone(SfxItemPool *) const
{
return new SvxTextLeftMarginItem(*this );
}
bool SvxTextLeftMarginItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
switch (ePres)
{
case SfxItemPresentation::Nameless:
{
if (100 != m_nPropLeftMargin)
{
rText = unicode::formatPercent(m_nPropLeftMargin,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stTextLeftMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stTextLeftMargin.m_dValue,
m_stTextLeftMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText = GetMetricText(m_stTextLeftMargin.m_dValue, eCoreUnit, ePresUnit, &rIntl);
}
return true ;
}
case SfxItemPresentation::Complete:
{
rText = EditResId(RID_SVXITEMS_LRSPACE_LEFT);
if (100 != m_nPropLeftMargin)
{
rText += unicode::formatPercent(m_nPropLeftMargin,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stTextLeftMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stTextLeftMargin.m_dValue,
m_stTextLeftMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(m_stTextLeftMargin.m_dValue, eCoreUnit, ePresUnit, &rIntl)
+ " " + EditResId(GetMetricId(ePresUnit));
}
return true ;
}
default : ; // prevent warning
}
return false ;
}
void SvxTextLeftMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_stTextLeftMargin.ScaleMetrics(nMult, nDiv);
}
bool SvxTextLeftMarginItem::HasMetrics() const
{
return true ;
}
void SvxTextLeftMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void )xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTextLeftMarginItem" ));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId" ), BAD_CAST(OString::number(Which()).getStr()));
(void )xmlTextWriterWriteAttribute(
pWriter, BAD_CAST("m_dTextLeftMargin" ),
BAD_CAST(OString::number(m_stTextLeftMargin.m_dValue).getStr()));
(void )xmlTextWriterWriteAttribute(
pWriter, BAD_CAST("m_nUnit" ),
BAD_CAST(OString::number(m_stTextLeftMargin.m_nUnit).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropLeftMargin" ), BAD_CAST(OString::number(m_nPropLeftMargin).getStr()));
(void )xmlTextWriterEndElement(pWriter);
}
boost::property_tree::ptree SvxTextLeftMarginItem::dumpAsJSON() const
{
boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
auto aState = lcl_IndentValueToJson("left" , m_stTextLeftMargin);
aTree.push_back(std::make_pair("state" , aState));
return aTree;
}
SvxFirstLineIndentItem::SvxFirstLineIndentItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
SvxFirstLineIndentItem::SvxFirstLineIndentItem(SvxIndentValue stValue, const sal_uInt16 nId)
: SvxFirstLineIndentItem(nId)
{
SetTextFirstLineOffset(stValue);
}
bool SvxFirstLineIndentItem::IsAutoFirst() const { return m_bAutoFirst; }
void SvxFirstLineIndentItem::SetAutoFirst(bool bNew)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_bAutoFirst = bNew;
}
void SvxFirstLineIndentItem::SetPropTextFirstLineOffset(sal_uInt16 nProp)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_nPropFirstLineOffset = nProp;
}
sal_uInt16 SvxFirstLineIndentItem::GetPropTextFirstLineOffset() const
{
return m_nPropFirstLineOffset;
}
void SvxFirstLineIndentItem::SetTextFirstLineOffset(SvxIndentValue stValue, sal_uInt16 nProp)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_stFirstLineOffset = stValue;
m_nPropFirstLineOffset = nProp;
if (nProp != 100)
{
m_stFirstLineOffset.m_dValue = (stValue.m_dValue * static_cast <double >(nProp)) / 100.0;
}
}
SvxIndentValue SvxFirstLineIndentItem::GetTextFirstLineOffset() const
{
return m_stFirstLineOffset;
}
sal_Int32
SvxFirstLineIndentItem::ResolveTextFirstLineOffset(const SvxFontUnitMetrics& rMetrics) const
{
return m_stFirstLineOffset.Resolve(rMetrics);
}
bool SvxFirstLineIndentItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
{
bool bRet = false ;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_FIRST_LINE_INDENT:
bRet = lcl_FillAbsoluteMeasureAny(m_stFirstLineOffset, rVal, bConvert);
break ;
case MID_FIRST_LINE_REL_INDENT:
rVal <<= static_cast <sal_Int16>(m_nPropFirstLineOffset);
bRet = true ;
break ;
case MID_FIRST_LINE_UNIT_INDENT:
bRet = lcl_FillRelativeMeasureAny(m_stFirstLineOffset, rVal);
break ;
case MID_FIRST_AUTO:
rVal <<= IsAutoFirst();
bRet = true ;
break ;
default :
assert(false );
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
return bRet;
}
bool SvxFirstLineIndentItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_FIRST_LINE_INDENT:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal))
{
return false ;
}
m_stFirstLineOffset
= SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
m_nPropFirstLineOffset = 100;
break ;
}
case MID_FIRST_LINE_REL_INDENT:
{
sal_Int32 nRel = 0;
if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
{
SetPropTextFirstLineOffset(nRel);
}
else
{
return false ;
}
break ;
}
case MID_FIRST_LINE_UNIT_INDENT:
{
css::beans::Pair<double , sal_Int16> stVal;
if (!(rVal >>= stVal))
{
return false ;
}
SetTextFirstLineOffset(SvxIndentValue{ stVal.First, stVal.Second });
break ;
}
case MID_FIRST_AUTO:
SetAutoFirst(Any2Bool(rVal));
break ;
default :
assert(false );
OSL_FAIL("unknown MemberId" );
return false ;
}
return true ;
}
bool SvxFirstLineIndentItem::operator ==(const SfxPoolItem& rAttr) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxFirstLineIndentItem& rOther = static_cast <const SvxFirstLineIndentItem&>(rAttr);
return std::tie(m_stFirstLineOffset, m_nPropFirstLineOffset, m_bAutoFirst)
== std::tie(rOther.m_stFirstLineOffset, rOther.m_nPropFirstLineOffset,
rOther.m_bAutoFirst);
}
size_t SvxFirstLineIndentItem::hashCode() const
{
std::size_t seed(0);
o3tl::hash_combine(seed, m_stFirstLineOffset.hashCode());
o3tl::hash_combine(seed, m_nPropFirstLineOffset);
o3tl::hash_combine(seed, m_bAutoFirst);
return seed;
}
SvxFirstLineIndentItem* SvxFirstLineIndentItem::Clone(SfxItemPool *) const
{
return new SvxFirstLineIndentItem(*this );
}
bool SvxFirstLineIndentItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
switch (ePres)
{
case SfxItemPresentation::Nameless:
{
if (100 != m_nPropFirstLineOffset)
{
rText += unicode::formatPercent(m_nPropFirstLineOffset,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stFirstLineOffset.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stFirstLineOffset.m_dValue,
m_stFirstLineOffset.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(m_stFirstLineOffset.m_dValue, eCoreUnit, ePresUnit, &rIntl);
}
return true ;
}
case SfxItemPresentation::Complete:
{
rText += EditResId(RID_SVXITEMS_LRSPACE_FLINE);
if (100 != m_nPropFirstLineOffset)
{
rText += unicode::formatPercent(m_nPropFirstLineOffset,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stFirstLineOffset.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stFirstLineOffset.m_dValue,
m_stFirstLineOffset.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(m_stFirstLineOffset.m_dValue, eCoreUnit, ePresUnit, &rIntl)
+ " " + EditResId(GetMetricId(ePresUnit));
}
return true ;
}
default : ; // prevent warning
}
return false ;
}
void SvxFirstLineIndentItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_stFirstLineOffset.ScaleMetrics(nMult, nDiv);
}
bool SvxFirstLineIndentItem::HasMetrics() const
{
return true ;
}
void SvxFirstLineIndentItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void )xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFirstLineIndentItem" ));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId" ), BAD_CAST(OString::number(Which()).getStr()));
(void )xmlTextWriterWriteAttribute(
pWriter, BAD_CAST("m_dFirstLineOffset" ),
BAD_CAST(OString::number(m_stFirstLineOffset.m_dValue).getStr()));
(void )xmlTextWriterWriteAttribute(
pWriter, BAD_CAST("m_nUnit" ),
BAD_CAST(OString::number(m_stFirstLineOffset.m_nUnit).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropFirstLineOffset" ), BAD_CAST(OString::number(m_nPropFirstLineOffset).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_bAutoFirst" ), BAD_CAST(OString::number(int (m_bAutoFirst)).getStr()));
(void )xmlTextWriterEndElement(pWriter);
}
boost::property_tree::ptree SvxFirstLineIndentItem::dumpAsJSON() const
{
boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
auto aState = lcl_IndentValueToJson("firstline" , m_stFirstLineOffset);
aTree.push_back(std::make_pair("state" , aState));
return aTree;
}
SvxRightMarginItem::SvxRightMarginItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
SvxRightMarginItem::SvxRightMarginItem(SvxIndentValue stRight, const sal_uInt16 nId)
: SfxPoolItem(nId)
{
SetRight(stRight);
}
bool SvxRightMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
{
bool bRet = false ;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
// tdf#154282 - return both values for the hardcoded 0 in SfxDispatchController_Impl::StateChanged
case 0:
{
css::frame::status::LeftRightMarginScale aLRSpace;
auto nRightTwips = ResolveRight({});
aLRSpace.Right
= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(nRightTwips) : nRightTwips);
aLRSpace.ScaleRight = static_cast <sal_Int16>(m_nPropRightMargin);
rVal <<= aLRSpace;
bRet = true ;
break ;
}
case MID_R_MARGIN:
bRet = lcl_FillAbsoluteMeasureAny(m_stRightMargin, rVal, bConvert);
break ;
case MID_R_REL_MARGIN:
rVal <<= static_cast <sal_Int16>(m_nPropRightMargin);
bRet = true ;
break ;
case MID_R_UNIT_MARGIN:
bRet = lcl_FillRelativeMeasureAny(m_stRightMargin, rVal);
break ;
default :
assert(false );
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
return bRet;
}
bool SvxRightMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_R_MARGIN:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal))
{
return false ;
}
SetRight(
SvxIndentValue::twips(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal));
break ;
}
case MID_R_REL_MARGIN:
{
sal_Int32 nRel = 0;
if ((rVal >>= nRel) && nRel >= 0 && nRel < SAL_MAX_UINT16)
{
m_nPropRightMargin = static_cast <sal_uInt16>(nRel);
}
else
{
return false ;
}
break ;
}
case MID_R_UNIT_MARGIN:
{
css::beans::Pair<double , sal_Int16> stVal;
if (!(rVal >>= stVal))
{
return false ;
}
SetRight(SvxIndentValue{ stVal.First, stVal.Second });
break ;
}
default :
assert(false );
OSL_FAIL("unknown MemberId" );
return false ;
}
return true ;
}
bool SvxRightMarginItem::operator ==(const SfxPoolItem& rAttr) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxRightMarginItem& rOther = static_cast <const SvxRightMarginItem&>(rAttr);
return std::tie(m_stRightMargin, m_nPropRightMargin)
== std::tie(rOther.m_stRightMargin, rOther.m_nPropRightMargin);
}
size_t SvxRightMarginItem::hashCode() const
{
std::size_t seed(0);
o3tl::hash_combine(seed, m_stRightMargin.hashCode());
o3tl::hash_combine(seed, m_nPropRightMargin);
return seed;
}
SvxRightMarginItem* SvxRightMarginItem::Clone(SfxItemPool *) const
{
return new SvxRightMarginItem(*this );
}
bool SvxRightMarginItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
switch (ePres)
{
case SfxItemPresentation::Nameless:
{
if (100 != m_nPropRightMargin)
{
rText += unicode::formatPercent(m_nPropRightMargin,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stRightMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stRightMargin.m_dValue,
m_stRightMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(m_stRightMargin.m_dValue, eCoreUnit, ePresUnit, &rIntl);
}
return true ;
}
case SfxItemPresentation::Complete:
{
rText += EditResId(RID_SVXITEMS_LRSPACE_RIGHT);
if (100 != m_nPropRightMargin)
{
rText += unicode::formatPercent(m_nPropRightMargin,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stRightMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stRightMargin.m_dValue,
m_stRightMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(m_stRightMargin.m_dValue, eCoreUnit, ePresUnit, &rIntl) + " "
+ EditResId(GetMetricId(ePresUnit));
}
return true ;
}
default : ; // prevent warning
}
return false ;
}
void SvxRightMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv)
{
ASSERT_CHANGE_REFCOUNTED_ITEM;
m_stRightMargin.ScaleMetrics(nMult, nDiv);
}
bool SvxRightMarginItem::HasMetrics() const
{
return true ;
}
void SvxRightMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void )xmlTextWriterStartElement(pWriter, BAD_CAST("SvxRightMarginItem" ));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId" ), BAD_CAST(OString::number(Which()).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_dRightMargin" ),
BAD_CAST(OString::number(m_stRightMargin.m_dValue).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nUnit" ),
BAD_CAST(OString::number(m_stRightMargin.m_nUnit).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nPropRightMargin" ), BAD_CAST(OString::number(m_nPropRightMargin).getStr()));
(void )xmlTextWriterEndElement(pWriter);
}
boost::property_tree::ptree SvxRightMarginItem::dumpAsJSON() const
{
boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
auto aState = lcl_IndentValueToJson("right" , m_stRightMargin);
aTree.push_back(std::make_pair("state" , aState));
return aTree;
}
SvxGutterLeftMarginItem::SvxGutterLeftMarginItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
bool SvxGutterLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const
{
bool bRet = true ;
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_GUTTER_MARGIN:
rVal <<= static_cast <sal_Int32>(bConvert ? convertTwipToMm100(m_nGutterMargin)
: m_nGutterMargin);
break ;
default :
assert(false );
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
return bRet;
}
bool SvxGutterLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId)
{
bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch (nMemberId)
{
case MID_GUTTER_MARGIN:
{
sal_Int32 nVal = 0;
if (!(rVal >>= nVal))
{
return false ;
}
SetGutterMargin(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal);
break ;
}
default :
assert(false );
OSL_FAIL("unknown MemberId" );
return false ;
}
return true ;
}
bool SvxGutterLeftMarginItem::operator ==(const SfxPoolItem& rAttr) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxGutterLeftMarginItem& rOther = static_cast <const SvxGutterLeftMarginItem&>(rAttr);
return (m_nGutterMargin == rOther.GetGutterMargin());
}
SvxGutterLeftMarginItem* SvxGutterLeftMarginItem::Clone(SfxItemPool * ) const
{
return new SvxGutterLeftMarginItem(*this );
}
bool SvxGutterLeftMarginItem::GetPresentation
(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& /*rText*/, const IntlWrapper& /*rIntl*/
) const
{
// TODO?
return false ;
}
void SvxGutterLeftMarginItem::ScaleMetrics(tools::Long const /*nMult*/, tools::Long const /*nDiv*/)
{
// TODO?
}
bool SvxGutterLeftMarginItem::HasMetrics() const
{
return true ;
}
void SvxGutterLeftMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void )xmlTextWriterStartElement(pWriter, BAD_CAST("SvxGutterLeftMarginItem" ));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId" ), BAD_CAST(OString::number(Which()).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nGutterMargin" ),
BAD_CAST(OString::number(m_nGutterMargin).getStr()));
(void )xmlTextWriterEndElement(pWriter);
}
boost::property_tree::ptree SvxGutterLeftMarginItem::dumpAsJSON() const
{
boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
boost::property_tree::ptree aState;
// TODO?
aState.put("unit" , "inch" );
aTree.push_back(std::make_pair("state" , aState));
return aTree;
}
SvxGutterRightMarginItem::SvxGutterRightMarginItem(const sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
bool SvxGutterRightMarginItem::QueryValue(uno::Any& /*rVal*/, sal_uInt8 nMemberId) const
{
bool bRet = true ;
//bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
#ifndef _MSC_VER
switch (nMemberId)
{
// TODO?
default :
assert(false );
bRet = false ;
// 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?
OSL_FAIL("unknown MemberId" );
}
#else
(void ) nMemberId;
#endif
return bRet;
}
bool SvxGutterRightMarginItem::PutValue(const uno::Any& /*rVal*/, sal_uInt8 nMemberId)
{
//bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
#ifndef _MSC_VER
switch (nMemberId)
{
// TODO?
default :
assert(false );
OSL_FAIL("unknown MemberId" );
return false ;
}
#else
(void ) nMemberId;
#endif
return true ;
}
bool SvxGutterRightMarginItem::operator ==(const SfxPoolItem& rAttr) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxGutterRightMarginItem& rOther = static_cast <const SvxGutterRightMarginItem&>(rAttr);
return (m_nRightGutterMargin == rOther.GetRightGutterMargin());
}
SvxGutterRightMarginItem* SvxGutterRightMarginItem::Clone(SfxItemPool *) const
{
return new SvxGutterRightMarginItem(*this );
}
bool SvxGutterRightMarginItem::GetPresentation
(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& /*rText*/, const IntlWrapper& /*rIntl*/
) const
{
// TODO?
return false ;
}
void SvxGutterRightMarginItem::ScaleMetrics(tools::Long const /*nMult*/, tools::Long const /*nDiv*/)
{
// TODO?
}
bool SvxGutterRightMarginItem::HasMetrics() const
{
return true ;
}
void SvxGutterRightMarginItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void )xmlTextWriterStartElement(pWriter, BAD_CAST("SvxGutterRightMarginItem" ));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId" ), BAD_CAST(OString::number(Which()).getStr()));
(void )xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nRightGutterMargin" ),
BAD_CAST(OString::number(m_nRightGutterMargin).getStr()));
(void )xmlTextWriterEndElement(pWriter);
}
boost::property_tree::ptree SvxGutterRightMarginItem::dumpAsJSON() const
{
boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
boost::property_tree::ptree aState;
// TODO?
aState.put("unit" , "inch" );
aTree.push_back(std::make_pair("state" , aState));
return aTree;
}
bool SvxLRSpaceItem::operator ==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator ==(rAttr));
const SvxLRSpaceItem& rOther = static_cast <const SvxLRSpaceItem&>(rAttr);
return std::tie(m_stFirstLineOffset, m_nGutterMargin, m_nRightGutterMargin, m_stLeftMargin,
m_stRightMargin, nPropFirstLineOffset, nPropLeftMargin, nPropRightMargin,
bAutoFirst, bExplicitZeroMarginValRight, bExplicitZeroMarginValLeft)
== std::tie(rOther.m_stFirstLineOffset, rOther.m_nGutterMargin,
rOther.m_nRightGutterMargin, rOther.m_stLeftMargin, rOther.m_stRightMargin,
rOther.nPropFirstLineOffset, rOther.nPropLeftMargin, rOther.nPropRightMargin,
rOther.bAutoFirst, rOther.bExplicitZeroMarginValRight,
rOther.bExplicitZeroMarginValLeft);
}
SvxLRSpaceItem* SvxLRSpaceItem::Clone( SfxItemPool* ) const
{
return new SvxLRSpaceItem( *this );
}
bool SvxLRSpaceItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
switch ( ePres )
{
case SfxItemPresentation::Nameless:
{
if ( 100 != nPropLeftMargin )
{
rText = unicode::formatPercent(nPropLeftMargin,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stLeftMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stLeftMargin.m_dValue,
m_stLeftMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
rText = GetMetricText(static_cast <tools::Long >(m_stLeftMargin.m_dValue), eCoreUnit,
ePresUnit, &rIntl);
rText += cpDelim;
if ( 100 != nPropFirstLineOffset )
{
rText += unicode::formatPercent(nPropFirstLineOffset,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stFirstLineOffset.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stFirstLineOffset.m_dValue,
m_stFirstLineOffset.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
rText += GetMetricText(static_cast <tools::Long >(m_stFirstLineOffset.m_dValue),
eCoreUnit, ePresUnit, &rIntl);
rText += cpDelim;
if (100 != nPropRightMargin)
{
rText += unicode::formatPercent(nPropRightMargin,
Application::GetSettings().GetUILanguageTag());
}
else if (m_stRightMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stRightMargin.m_dValue,
m_stRightMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
rText += GetMetricText(static_cast <tools::Long >(m_stRightMargin.m_dValue),
eCoreUnit, ePresUnit, &rIntl);
return true ;
}
case SfxItemPresentation::Complete:
{
rText = EditResId(RID_SVXITEMS_LRSPACE_LEFT);
if ( 100 != nPropLeftMargin )
rText += unicode::formatPercent(nPropLeftMargin,
Application::GetSettings().GetUILanguageTag());
else if (m_stLeftMargin.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stLeftMargin.m_dValue,
m_stLeftMargin.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(static_cast <tools::Long >(m_stLeftMargin.m_dValue), eCoreUnit,
ePresUnit, &rIntl)
+ " " + EditResId(GetMetricId(ePresUnit));
}
rText += cpDelim;
if (100 != nPropFirstLineOffset || m_stFirstLineOffset.m_dValue != 0.0)
{
rText += EditResId(RID_SVXITEMS_LRSPACE_FLINE);
if ( 100 != nPropFirstLineOffset )
rText += unicode::formatPercent(nPropFirstLineOffset,
Application::GetSettings().GetUILanguageTag());
else if (m_stFirstLineOffset.m_nUnit != css::util::MeasureUnit::TWIP)
{
OUStringBuffer stBuf;
sax::Converter::convertMeasureUnit(stBuf, m_stFirstLineOffset.m_dValue,
m_stFirstLineOffset.m_nUnit);
rText += stBuf.makeStringAndClear();
}
else
{
rText += GetMetricText(static_cast <tools::Long >(m_stFirstLineOffset.m_dValue),
eCoreUnit, ePresUnit, &rIntl)
+ " " + EditResId(GetMetricId(ePresUnit));
}
rText += cpDelim;
}
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5 C=98 H=100 G=98
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet)
¤
*© Formatika GbR, Deutschland