Related: tdf#129300 add ScLineBreakCell to provide a description

Change-Id: Ief739616163c68e0e30d6287fdac90c1bcc9d13f
Reviewed-on: https://gerrit.libreoffice.org/84879
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/cui/source/tabpages/align.cxx b/cui/source/tabpages/align.cxx
index 9238ff5..1994a7e8 100644
--- a/cui/source/tabpages/align.cxx
+++ b/cui/source/tabpages/align.cxx
@@ -287,7 +287,12 @@ bool AlignmentTabPage::FillItemSet( SfxItemSet* rSet )

    if (m_xBtnWrap->get_state_changed_from_saved())
    {
        rSet->Put(SfxBoolItem(GetWhich(SID_ATTR_ALIGN_LINEBREAK), m_xBtnWrap->get_active()));
        const SfxBoolItem* pWrapItem = static_cast<const SfxBoolItem*>(GetOldItem(
                                            *rSet, SID_ATTR_ALIGN_LINEBREAK));
        assert(pWrapItem);
        std::unique_ptr<SfxBoolItem> pNewWrapItem(static_cast<SfxBoolItem*>(pWrapItem->Clone()));
        pNewWrapItem->SetValue(m_xBtnWrap->get_active());
        rSet->Put(*pNewWrapItem);
        bChanged = true;
    }

diff --git a/sc/inc/attrib.hxx b/sc/inc/attrib.hxx
index 9b6a6b9..100766e 100644
--- a/sc/inc/attrib.hxx
+++ b/sc/inc/attrib.hxx
@@ -321,6 +321,18 @@ public:
                                 const IntlWrapper& rIntl) const override;
};

class SC_DLLPUBLIC ScLineBreakCell final : public SfxBoolItem
{
public:
    ScLineBreakCell(bool bLineBreak = false);
    virtual ScLineBreakCell* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText,
                                 const IntlWrapper& rIntl) const override;
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index ceedfbe..518d033 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -519,6 +519,8 @@
#define STR_SHRINKTOFITCELL_OFF                 NC_("STR_SHRINKTOFITCELL_OFF", "Shrink to fit cell: Off")
#define STR_VERTICALSTACKCELL_ON                NC_("STR_VERTICALSTACKCELL_ON", "Vertically stacked: On")
#define STR_VERTICALSTACKCELL_OFF               NC_("STR_VERTICALSTACKCELL_OFF", "Vertically stacked: Off")
#define STR_LINEBREAKCELL_ON                    NC_("STR_LINEBREAKCELL_ON", "Wrap text automatically: On")
#define STR_LINEBREAKCELL_OFF                   NC_("STR_LINEBREAKCELL_OFF", "Wrap text automatically: Off")

#endif

diff --git a/sc/inc/scitems.hxx b/sc/inc/scitems.hxx
index 9093d54..ce40a2c 100644
--- a/sc/inc/scitems.hxx
+++ b/sc/inc/scitems.hxx
@@ -50,7 +50,9 @@ class SvxVerJustifyItem;
class SvxBrushItem;
class SvxBoxItem;
class ScCondFormatItem;
class ScLineBreakCell;
class ScRotateValueItem;
class ScShrinkToFitCell;
class SvxLineItem;
class SvxRotateModeItem;
class SfxStringItem;
@@ -118,12 +120,12 @@ class SvxSizeItem;
#define ATTR_INDENT             TypedWhichId<SfxUInt16Item>(131)
#define ATTR_VER_JUSTIFY        TypedWhichId<SvxVerJustifyItem>(132)
#define ATTR_VER_JUSTIFY_METHOD TypedWhichId<SvxJustifyMethodItem>(133)
#define ATTR_STACKED            TypedWhichId<SfxBoolItem>(134)
#define ATTR_STACKED            TypedWhichId<ScShrinkToFitCell>(134)
#define ATTR_ROTATE_VALUE       TypedWhichId<ScRotateValueItem>(135)
#define ATTR_ROTATE_MODE        TypedWhichId<SvxRotateModeItem>(136)
#define ATTR_VERTICAL_ASIAN     TypedWhichId<SfxBoolItem>(137)
#define ATTR_WRITINGDIR         TypedWhichId<SvxFrameDirectionItem>(138)
#define ATTR_LINEBREAK          TypedWhichId<SfxBoolItem>(139)
#define ATTR_LINEBREAK          TypedWhichId<ScLineBreakCell>(139)
#define ATTR_SHRINKTOFIT        TypedWhichId<SfxBoolItem>(140)
#define ATTR_BORDER_TLBR        TypedWhichId<SvxLineItem>(141)
#define ATTR_BORDER_BLTR        TypedWhichId<SvxLineItem>(142)
diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx
index 5d759af..70f8761 100644
--- a/sc/qa/extras/anchor.cxx
+++ b/sc/qa/extras/anchor.cxx
@@ -177,7 +177,7 @@ void ScAnchorTest::testTdf76183()
    const tools::Rectangle& rNewRect = pObj->GetLogicRect();

    // Set word wrap to true
    rDoc.ApplyAttr(0, 0, 0, SfxBoolItem(ATTR_LINEBREAK, true));
    rDoc.ApplyAttr(0, 0, 0, ScLineBreakCell(true));
    // Add multi-line text to cell to initiate optimal height change
    uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, uno::UNO_QUERY_THROW);
    uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW);
diff --git a/sc/source/core/data/attrib.cxx b/sc/source/core/data/attrib.cxx
index 24d1a09..75337c0 100644
--- a/sc/source/core/data/attrib.cxx
+++ b/sc/source/core/data/attrib.cxx
@@ -779,13 +779,33 @@ ScVerticalStackCell* ScVerticalStackCell::Clone(SfxItemPool*) const
}

bool ScVerticalStackCell::GetPresentation(SfxItemPresentation,
                                        MapUnit, MapUnit,
                                        OUString& rText,
                                        const IntlWrapper&) const
                                          MapUnit, MapUnit,
                                          OUString& rText,
                                          const IntlWrapper&) const
{
    const char* pId = GetValue() ? STR_VERTICALSTACKCELL_ON : STR_VERTICALSTACKCELL_OFF;
    rText = ScResId(pId);
    return true;
}

ScLineBreakCell::ScLineBreakCell(bool bStack)
    : SfxBoolItem(ATTR_LINEBREAK, bStack)
{
}

ScLineBreakCell* ScLineBreakCell::Clone(SfxItemPool*) const
{
    return new ScLineBreakCell(GetValue());
}

bool ScLineBreakCell::GetPresentation(SfxItemPresentation,
                                      MapUnit, MapUnit,
                                      OUString& rText,
                                      const IntlWrapper&) const
{
    const char* pId = GetValue() ? STR_LINEBREAKCELL_ON : STR_LINEBREAKCELL_OFF;
    rText = ScResId(pId);
    return true;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 00d978f..6120e71 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -145,7 +145,7 @@ long ScColumn::GetNeededSize(
        bBreak = true;
    else if ( pCondSet &&
                pCondSet->GetItemState(ATTR_LINEBREAK, true, &pCondItem) == SfxItemState::SET)
        bBreak = static_cast<const SfxBoolItem*>(pCondItem)->GetValue();
        bBreak = static_cast<const ScLineBreakCell*>(pCondItem)->GetValue();
    else
        bBreak = pPattern->GetItem(ATTR_LINEBREAK).GetValue();

diff --git a/sc/source/core/data/docpool.cxx b/sc/source/core/data/docpool.cxx
index e379f75..2df0bfc 100644
--- a/sc/source/core/data/docpool.cxx
+++ b/sc/source/core/data/docpool.cxx
@@ -257,7 +257,7 @@ ScDocumentPool::ScDocumentPool()
    //  so that value is returned when asking for a default cell's attributes.
    //  The value from the page style is set as DefaultHorizontalTextDirection for the EditEngine.
    mvPoolDefaults[ ATTR_WRITINGDIR      - ATTR_STARTINDEX ] = new SvxFrameDirectionItem( SvxFrameDirection::Environment, ATTR_WRITINGDIR );
    mvPoolDefaults[ ATTR_LINEBREAK       - ATTR_STARTINDEX ] = new SfxBoolItem( ATTR_LINEBREAK );
    mvPoolDefaults[ ATTR_LINEBREAK       - ATTR_STARTINDEX ] = new ScLineBreakCell();
    mvPoolDefaults[ ATTR_SHRINKTOFIT     - ATTR_STARTINDEX ] = new ScShrinkToFitCell();
    mvPoolDefaults[ ATTR_BORDER_TLBR     - ATTR_STARTINDEX ] = new SvxLineItem( ATTR_BORDER_TLBR );
    mvPoolDefaults[ ATTR_BORDER_BLTR     - ATTR_STARTINDEX ] = new SvxLineItem( ATTR_BORDER_BLTR );
diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx
index d5f290e..ff6c8e4 100644
--- a/sc/source/core/tool/autoform.cxx
+++ b/sc/source/core/tool/autoform.cxx
@@ -193,9 +193,9 @@ ScAutoFormatDataField::ScAutoFormatDataField()
    m_aAdjust = std::make_unique<SvxAdjustItem>(SvxAdjust::Left, 0);
    m_aHorJustify = std::make_unique<SvxHorJustifyItem>(SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY);
    m_aVerJustify = std::make_unique<SvxVerJustifyItem>(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY);
    m_aStacked = std::make_unique<SfxBoolItem>();
    m_aStacked = std::make_unique<ScVerticalStackCell>();
    m_aMargin = std::make_unique<SvxMarginItem>(ATTR_MARGIN);
    m_aLinebreak = std::make_unique<SfxBoolItem>(ATTR_LINEBREAK);
    m_aLinebreak = std::make_unique<ScLineBreakCell>();
    m_aRotateAngle = std::make_unique<ScRotateValueItem>(0);
    m_aRotateMode = std::make_unique<SvxRotateModeItem>(SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE);
}
@@ -371,7 +371,7 @@ void ScAutoFormatData::PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem )
        case ATTR_VER_JUSTIFY:      rField.SetVerJustify( static_cast<const SvxVerJustifyItem&>(rItem) );  break;
        case ATTR_STACKED:          rField.SetStacked( static_cast<const ScVerticalStackCell&>(rItem) );   break;
        case ATTR_MARGIN:           rField.SetMargin( static_cast<const SvxMarginItem&>(rItem) );          break;
        case ATTR_LINEBREAK:        rField.SetLinebreak( static_cast<const SfxBoolItem&>(rItem) );         break;
        case ATTR_LINEBREAK:        rField.SetLinebreak( static_cast<const ScLineBreakCell&>(rItem) );         break;
        case ATTR_ROTATE_VALUE:     rField.SetRotateAngle( static_cast<const ScRotateValueItem&>(rItem) ); break;
        case ATTR_ROTATE_MODE:      rField.SetRotateMode( static_cast<const SvxRotateModeItem&>(rItem) );  break;
    }
diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx
index 00320dd..89c5406 100644
--- a/sc/source/filter/excel/xistyle.cxx
+++ b/sc/source/filter/excel/xistyle.cxx
@@ -814,7 +814,7 @@ void XclImpCellAlign::FillToItemSet( SfxItemSet& rItemSet, const XclImpFont* pFo

    // text wrap (#i74508# always if vertical alignment is justified or distributed)
    bool bLineBreak = mbLineBreak || (mnVerAlign == EXC_XF_VER_JUSTIFY) || (mnVerAlign == EXC_XF_VER_DISTRIB);
    ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_LINEBREAK, bLineBreak ), bSkipPoolDefs );
    ScfTools::PutItem( rItemSet, ScLineBreakCell( bLineBreak ), bSkipPoolDefs );

    // vertical alignment
    ScfTools::PutItem( rItemSet, SvxVerJustifyItem( GetScVerAlign(), ATTR_VER_JUSTIFY ), bSkipPoolDefs );
diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index e8d0819..a45f497 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -51,6 +51,7 @@

#include <rtl/tencinfo.h>

#include <attrib.hxx>
#include <htmlpars.hxx>
#include <global.hxx>
#include <document.hxx>
@@ -831,7 +832,7 @@ void ScHTMLLayoutParser::CloseEntry( const HtmlImportInfo* pInfo )
        rSel.nEndPara = rSel.nStartPara;
    }
    if ( rSel.HasRange() )
        mxActEntry->aItemSet.Put( SfxBoolItem( ATTR_LINEBREAK, true ) );
        mxActEntry->aItemSet.Put( ScLineBreakCell(true) );
    maList.push_back(mxActEntry);
    NewActEntry(mxActEntry.get()); // New free flying mxActEntry
}
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 378ae7c..f373f0a 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -1301,7 +1301,7 @@ void Alignment::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
    // indent
    ScfTools::PutItem( rItemSet, SfxUInt16Item( ATTR_INDENT, maApiData.mnIndent ), bSkipPoolDefs );
    // line wrap
    ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_LINEBREAK, maApiData.mbWrapText ), bSkipPoolDefs );
    ScfTools::PutItem( rItemSet, ScLineBreakCell( maApiData.mbWrapText ), bSkipPoolDefs );
    ScfTools::PutItem( rItemSet, ScShrinkToFitCell( maApiData.mbShrink ), bSkipPoolDefs );
}

diff --git a/sc/source/filter/qpro/qprostyle.cxx b/sc/source/filter/qpro/qprostyle.cxx
index af66281..00938af0 100644
--- a/sc/source/filter/qpro/qprostyle.cxx
+++ b/sc/source/filter/qpro/qprostyle.cxx
@@ -30,6 +30,7 @@
#include <editeng/fontitem.hxx>
#include <editeng/justifyitem.hxx>

#include <attrib.hxx>
#include <global.hxx>
#include <docpool.hxx>
#include <patattr.hxx>
@@ -107,8 +108,7 @@ void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, 
    // Wrap cell contents
    if( nTmp & 0x80 )
    {
        SfxBoolItem aWrapItem( ATTR_LINEBREAK );
        aWrapItem.SetValue( true );
        ScLineBreakCell aWrapItem(true);
        rItemSet.Put( aWrapItem );
    }

diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx b/sc/source/ui/Accessibility/AccessibleText.cxx
index 540e9ac..e0a7b72 100644
--- a/sc/source/ui/Accessibility/AccessibleText.cxx
+++ b/sc/source/ui/Accessibility/AccessibleText.cxx
@@ -545,7 +545,7 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
        else
        {
            // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
            const SfxBoolItem* pLineBreakItem = rDoc.GetAttr( aCellPos, ATTR_LINEBREAK );
            const ScLineBreakCell* pLineBreakItem = rDoc.GetAttr( aCellPos, ATTR_LINEBREAK );
            bool bLineBreak = ( pLineBreakItem && pLineBreakItem->GetValue() );
            if ( !bLineBreak )
            {
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 9e9008f..4c8f4fa 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -59,6 +59,7 @@
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <comphelper/lok.hxx>

#include <attrib.hxx>
#include <inputwin.hxx>
#include <tabvwsh.hxx>
#include <docsh.hxx>
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 28fe4e8..379761b 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -1710,7 +1710,7 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
                {
                    const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
                    bool bOld = pAttrs->GetItem(ATTR_LINEBREAK).GetValue();
                    SfxBoolItem aBreakItem( ATTR_LINEBREAK, !bOld );
                    ScLineBreakCell aBreakItem(!bOld);
                    pTabViewShell->ApplyAttr( aBreakItem );

                    SfxAllItemSet aNewSet( GetPool() );
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 8f5b723..8a057dcf 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -1646,7 +1646,7 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                        // Disable line break when the cell content is numeric.
                        aAltPatterns.push_back(std::make_unique<ScPatternAttr>(*pPattern));
                        ScPatternAttr* pAltPattern = aAltPatterns.back().get();
                        SfxBoolItem aLineBreak(ATTR_LINEBREAK, false);
                        ScLineBreakCell aLineBreak(false);
                        pAltPattern->GetItemSet().Put(aLineBreak);
                        pPattern = pAltPattern;
                    }