diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2023-02-10 15:18:46 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2023-02-24 07:32:10 +0000 |
commit | 7e7b69829db63e64b8aed8d03c6eaed6d8f1a27c (patch) | |
tree | 8e43564f5a951cfc41616341eed6eaf7626e6ca5 /editeng | |
parent | afdee56418182b7250eb61269dd26cbacc56f87f (diff) |
editeng: split SvxLRSpaceItem into 1 class per attribute
The tricky part is that there are actually 2 different kinds of left
margins:
Those on entities that aren't paragraphs are simple, so class
SvxLeftMarginItem is simple.
Those on paragraphs are entangled with the first-line-offset,
because there is a left margin value (same as for everything else)
and a text-left-margin value, which includes a negative
first-line-offset; the text-left-margin value is exported as API
property so stored as-is in the item, and the left-margin is computed on
demand (based on corresponding first-line-offset) in
SvxTextLeftMarginItem::GetLeft().
Separate classes for these is a better separation than what commit
a0875d09d9eeb368e9e319f3f2f29ec3be71b56c did.
(some functions aren't implemented because the SvxLRSpaceItem did
nothing for these cases; not sure if that's intended.)
Change-Id: Iae5cd4bf8167754eec65d2585430f5fe3d00839f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147023
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/items/frmitems.cxx | 953 |
1 files changed, 953 insertions, 0 deletions
diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx index b3b71522ee0e..75f48150465a 100644 --- a/editeng/source/items/frmitems.cxx +++ b/editeng/source/items/frmitems.cxx @@ -86,6 +86,12 @@ using namespace ::com::sun::star::table::BorderLineStyle; SfxPoolItem* SvxPaperBinItem::CreateDefault() { return new SvxPaperBinItem(0);} SfxPoolItem* SvxSizeItem::CreateDefault() { return new SvxSizeItem(0);} +SfxPoolItem* SvxLeftMarginItem::CreateDefault() { return new SvxLeftMarginItem(0); } +SfxPoolItem* SvxTextLeftMarginItem::CreateDefault() { return new SvxTextLeftMarginItem(0); } +SfxPoolItem* SvxFirstLineIndentItem::CreateDefault() { return new SvxFirstLineIndentItem(0); } +SfxPoolItem* SvxRightMarginItem::CreateDefault() { return new SvxRightMarginItem(0); } +SfxPoolItem* SvxGutterLeftMarginItem::CreateDefault() { return new SvxGutterLeftMarginItem(0); } +SfxPoolItem* SvxGutterRightMarginItem::CreateDefault() { return new SvxGutterRightMarginItem(0); } SfxPoolItem* SvxLRSpaceItem::CreateDefault() { return new SvxLRSpaceItem(0);} SfxPoolItem* SvxULSpaceItem::CreateDefault() { return new SvxULSpaceItem(0);} SfxPoolItem* SvxProtectItem::CreateDefault() { return new SvxProtectItem(0);} @@ -463,6 +469,12 @@ bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) return true; } +void SvxLeftMarginItem::SetLeft(const tools::Long nL, const sal_uInt16 nProp) +{ + m_nLeftMargin = (nL * nProp) / 100; + m_nPropLeftMargin = nProp; +} + void SvxLRSpaceItem::SetLeft(const tools::Long nL, const sal_uInt16 nProp) { nLeftMargin = (nL * nProp) / 100; @@ -470,6 +482,12 @@ void SvxLRSpaceItem::SetLeft(const tools::Long nL, const sal_uInt16 nProp) nPropLeftMargin = nProp; } +void SvxRightMarginItem::SetRight(const tools::Long nR, const sal_uInt16 nProp) +{ + m_nRightMargin = (nR * nProp) / 100; + m_nPropRightMargin = nProp; +} + void SvxLRSpaceItem::SetRight(const tools::Long nR, const sal_uInt16 nProp) { if (0 == nR) @@ -480,6 +498,13 @@ void SvxLRSpaceItem::SetRight(const tools::Long nR, const sal_uInt16 nProp) nPropRightMargin = nProp; } +void SvxFirstLineIndentItem::SetTextFirstLineOffset( + const short nF, const sal_uInt16 nProp) +{ + m_nFirstLineOffset = short((tools::Long(nF) * nProp ) / 100); + m_nPropFirstLineOffset = nProp; +} + void SvxLRSpaceItem::SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp) { // note: left margin contains any negative first line offset - preserve it! @@ -495,6 +520,26 @@ void SvxLRSpaceItem::SetTextFirstLineOffset(const short nF, const sal_uInt16 nPr } } +#if 0 +void SvxTextLeftMarginItem::SetLeft(SvxFirstLineIndentItem const& rFirstLine, + const tools::Long nL, const sal_uInt16 nProp) +{ + m_nTextLeftMargin = (nL * nProp) / 100; + m_nPropLeftMargin = nProp; + // note: text left margin contains any negative first line offset + if (rFirstLine.GetTextFirstLineOffset() < 0) + { + m_nTextLeftMargin += rFirstLine.GetTextFirstLineOffset(); + } +} +#endif + +void SvxTextLeftMarginItem::SetTextLeft(const tools::Long nL, const sal_uInt16 nProp) +{ + m_nTextLeftMargin = (nL * nProp) / 100; + m_nPropLeftMargin = nProp; +} + void SvxLRSpaceItem::SetTextLeft(const tools::Long nL, const sal_uInt16 nProp) { if (0 == nL) @@ -510,6 +555,19 @@ void SvxLRSpaceItem::SetTextLeft(const tools::Long nL, const sal_uInt16 nProp) nLeftMargin = nTxtLeft; } +tools::Long SvxTextLeftMarginItem::GetTextLeft() const +{ + return m_nTextLeftMargin; +} + +tools::Long SvxTextLeftMarginItem::GetLeft(SvxFirstLineIndentItem const& rFirstLine) const +{ + // add any negative first line offset to text left margin to get left + return (rFirstLine.GetTextFirstLineOffset() < 0) + ? m_nTextLeftMargin + rFirstLine.GetTextFirstLineOffset() + : m_nTextLeftMargin; +} + tools::Long SvxLRSpaceItem::GetTextLeft() const { // remove any negative first line offset from left margin to get text-left @@ -518,6 +576,901 @@ tools::Long SvxLRSpaceItem::GetTextLeft() const : nLeftMargin; } +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(const tools::Long nLeft, const sal_uInt16 nId) + : SfxPoolItem(nId) + , m_nTextLeftMargin(nLeft) +{ +} + +bool SvxTextLeftMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const +{ + bool bRet = true; + bool bConvert = 0 != (nMemberId & CONVERT_TWIPS); + nMemberId &= ~CONVERT_TWIPS; + switch (nMemberId) + { + case MID_TXT_LMARGIN : + rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(GetTextLeft()) : GetTextLeft()); + 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 SvxTextLeftMarginItem::PutValue(const uno::Any& rVal, sal_uInt8 nMemberId) +{ + 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(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 SvxTextLeftMarginItem::operator==(const SfxPoolItem& rAttr) const +{ + assert(SfxPoolItem::operator==(rAttr)); + + const SvxTextLeftMarginItem& rOther = static_cast<const SvxTextLeftMarginItem&>(rAttr); + + return (m_nTextLeftMargin == rOther.GetTextLeft() + && m_nPropLeftMargin == rOther.GetPropLeft()); +} + +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 + { + rText = GetMetricText(m_nTextLeftMargin, + 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_nTextLeftMargin, eCoreUnit, ePresUnit, &rIntl) + + " " + EditResId(GetMetricId(ePresUnit)); + } + return true; + } + default: ; // prevent warning + } + return false; +} + +void SvxTextLeftMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv) +{ + m_nTextLeftMargin = BigInt::Scale(m_nTextLeftMargin, 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_nTextLeftMargin"), BAD_CAST(OString::number(m_nTextLeftMargin).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(); + + boost::property_tree::ptree aState; + + MapUnit eTargetUnit = MapUnit::MapInch; + + OUString sLeft = GetMetricText(GetTextLeft(), + MapUnit::MapTwip, eTargetUnit, nullptr); + + aState.put("left", sLeft); + aState.put("unit", "inch"); + + aTree.push_back(std::make_pair("state", aState)); + + return aTree; +} + +SvxFirstLineIndentItem::SvxFirstLineIndentItem(const sal_uInt16 nId) + : SfxPoolItem(nId) +{ +} + +SvxFirstLineIndentItem::SvxFirstLineIndentItem(const short nFirst, const sal_uInt16 nId) + : SfxPoolItem(nId) + , m_nFirstLineOffset(nFirst) +{ +} + +bool SvxFirstLineIndentItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const +{ + bool bRet = true; + bool bConvert = 0 != (nMemberId & CONVERT_TWIPS); + nMemberId &= ~CONVERT_TWIPS; + switch (nMemberId) + { + case MID_FIRST_LINE_INDENT: + rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nFirstLineOffset) : m_nFirstLineOffset); + break; + case MID_FIRST_LINE_REL_INDENT: + rVal <<= static_cast<sal_Int16>(m_nPropFirstLineOffset); + break; + case MID_FIRST_AUTO: + rVal <<= IsAutoFirst(); + 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) +{ + 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_nFirstLineOffset = 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_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 (m_nFirstLineOffset == rOther.GetTextFirstLineOffset() + && m_nPropFirstLineOffset == rOther.GetPropTextFirstLineOffset() + && m_bAutoFirst == rOther.IsAutoFirst()); +} + +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 + { + rText += GetMetricText(static_cast<tools::Long>(m_nFirstLineOffset), + 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 + { + rText += GetMetricText(static_cast<tools::Long>(m_nFirstLineOffset), + eCoreUnit, ePresUnit, &rIntl) + + " " + EditResId(GetMetricId(ePresUnit)); + } + return true; + } + default: ; // prevent warning + } + return false; +} + +void SvxFirstLineIndentItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv) +{ + m_nFirstLineOffset = static_cast<short>(BigInt::Scale(m_nFirstLineOffset, 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_nFirstLineOffset"), BAD_CAST(OString::number(m_nFirstLineOffset).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(); + + boost::property_tree::ptree aState; + + MapUnit eTargetUnit = MapUnit::MapInch; + + OUString sFirstline = GetMetricText(GetTextFirstLineOffset(), + MapUnit::MapTwip, eTargetUnit, nullptr); + + aState.put("firstline", sFirstline); + aState.put("unit", "inch"); + + aTree.push_back(std::make_pair("state", aState)); + + return aTree; +} + +SvxRightMarginItem::SvxRightMarginItem(const sal_uInt16 nId) + : SfxPoolItem(nId) +{ +} + +SvxRightMarginItem::SvxRightMarginItem(const tools::Long nRight, const sal_uInt16 nId) + : SfxPoolItem(nId) + , m_nRightMargin(nRight) +{ +} + +bool SvxRightMarginItem::QueryValue(uno::Any& rVal, sal_uInt8 nMemberId) const +{ + bool bRet = true; + bool bConvert = 0 != (nMemberId & CONVERT_TWIPS); + nMemberId &= ~CONVERT_TWIPS; + switch (nMemberId) + { + case MID_R_MARGIN: + rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(m_nRightMargin) : m_nRightMargin); + break; + case MID_R_REL_MARGIN: + rVal <<= static_cast<sal_Int16>(m_nPropRightMargin); + 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) +{ + 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(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; + 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 (m_nRightMargin == rOther.GetRight() + && m_nPropRightMargin == rOther.GetPropRight()); +} + +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_nRightMargin) + { + rText += unicode::formatPercent(m_nRightMargin, + Application::GetSettings().GetUILanguageTag()); + } + else + { + rText += GetMetricText(m_nRightMargin, + 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 + { + rText += GetMetricText(m_nRightMargin, + eCoreUnit, ePresUnit, &rIntl) + + " " + EditResId(GetMetricId(ePresUnit)); + } + return true; + } + default: ; // prevent warning + } + return false; +} + +void SvxRightMarginItem::ScaleMetrics(tools::Long const nMult, tools::Long const nDiv) +{ + m_nRightMargin = BigInt::Scale(m_nRightMargin, 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_nRightMargin"), BAD_CAST(OString::number(m_nRightMargin).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(); + + boost::property_tree::ptree aState; + + MapUnit eTargetUnit = MapUnit::MapInch; + + OUString sRight = GetMetricText(GetRight(), + MapUnit::MapTwip, eTargetUnit, nullptr); + + aState.put("right", sRight); + aState.put("unit", "inch"); + + 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"); + } +#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; + } +#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)); |