Prepare the dialog for cell style editing

Change-Id: I54ec1486f49f240e1ab88662b9d1b0b741cf8878
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142905
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <[email protected]>
diff --git a/cui/qa/unit/cui-dialogs-test.cxx b/cui/qa/unit/cui-dialogs-test.cxx
index f4f73fa..cf8c302 100644
--- a/cui/qa/unit/cui-dialogs-test.cxx
+++ b/cui/qa/unit/cui-dialogs-test.cxx
@@ -69,7 +69,8 @@
    {
        case 0: // "cui/ui/formatcellsdialog.ui"
        {
            pReturnDialog = mpFact->CreateSvxFormatCellsDialog(nullptr, mxAttr.get(), *mxModel);
            pReturnDialog
                = mpFact->CreateSvxFormatCellsDialog(nullptr, mxAttr.get(), *mxModel, true);
            break;
        }

diff --git a/cui/source/dialogs/sdrcelldlg.cxx b/cui/source/dialogs/sdrcelldlg.cxx
index fda8b4c..3afbc0f 100644
--- a/cui/source/dialogs/sdrcelldlg.cxx
+++ b/cui/source/dialogs/sdrcelldlg.cxx
@@ -21,10 +21,15 @@
#include <cuitabarea.hxx>
#include <svx/svdmodel.hxx>
#include <border.hxx>
#include <paragrph.hxx>
#include <svl/intitem.hxx>
#include <svl/cjkoptions.hxx>
#include <svx/flagsdef.hxx>
#include <svx/svxids.hrc>
#include <svx/dialogs.hrc>

SvxFormatCellsDialog::SvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel)
    : SfxTabDialogController(pParent, "cui/ui/formatcellsdialog.ui", "FormatCellsDialog", pAttr)
SvxFormatCellsDialog::SvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel, bool bStyle)
    : SfxTabDialogController(pParent, "cui/ui/formatcellsdialog.ui", "FormatCellsDialog", pAttr, bStyle)
    , mrOutAttrs(*pAttr)
    , mpColorTab(rModel.GetColorList())
    , mnColorTabState ( ChangeType::NONE )
@@ -37,7 +42,29 @@
    AddTabPage("effects", RID_SVXPAGE_CHAR_EFFECTS);
    AddTabPage("border", RID_SVXPAGE_BORDER );
    AddTabPage("area", RID_SVXPAGE_AREA);
    AddTabPage("shadow", SvxShadowTabPage::Create, nullptr);

    if (bStyle)
    {
        AddTabPage("position", RID_SVXPAGE_CHAR_POSITION);
        AddTabPage("highlight", RID_SVXPAGE_BKG);
        AddTabPage("indentspacing", RID_SVXPAGE_STD_PARAGRAPH);
        AddTabPage("alignment", SvxParaAlignTabPage::Create, SvxParaAlignTabPage::GetSdrRanges);
        RemoveTabPage("shadow");
    }
    else
    {
        RemoveTabPage("position");
        RemoveTabPage("highlight");
        RemoveTabPage("indentspacing");
        RemoveTabPage("alignment");
        AddTabPage("shadow", SvxShadowTabPage::Create, nullptr);
        RemoveStandardButton();
    }

    if (bStyle && SvtCJKOptions::IsAsianTypographyEnabled())
        AddTabPage("asian", RID_SVXPAGE_PARA_ASIAN);
    else
        RemoveTabPage("asian");
}

void SvxFormatCellsDialog::PageCreated(const OString& rId, SfxTabPage &rPage)
@@ -62,6 +89,16 @@
        static_cast<SvxShadowTabPage&>(rPage).SetColorList( mpColorTab );
        static_cast<SvxShadowTabPage&>(rPage).SetColorChgd( &mnColorTabState );
    }
    else if (rId == "alignment")
    {
        static_cast<SvxParaAlignTabPage&>(rPage).EnableSdrVertAlign();
    }
    else if (rId == "highlight")
    {
        SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
        aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR)));
        rPage.PageCreated(aSet);
    }
    else
        SfxTabDialogController::PageCreated(rId, rPage);
}
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index fb61daf..930452d 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -1428,9 +1428,9 @@
    return VclPtr<AbstractLinksDialog_Impl>::Create(std::move(xLinkDlg));
}

VclPtr<SfxAbstractTabDialog> AbstractDialogFactory_Impl::CreateSvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel)
VclPtr<SfxAbstractTabDialog> AbstractDialogFactory_Impl::CreateSvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel, bool bStyle)
{
    return VclPtr<CuiAbstractTabController_Impl>::Create(std::make_shared<SvxFormatCellsDialog>(pParent, pAttr, rModel));
    return VclPtr<CuiAbstractTabController_Impl>::Create(std::make_shared<SvxFormatCellsDialog>(pParent, pAttr, rModel, bStyle));
}

VclPtr<SvxAbstractSplitTableDialog> AbstractDialogFactory_Impl::CreateSvxSplitTableDialog(weld::Window* pParent, bool bIsTableVertical, tools::Long nMaxVertical)
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index 079af32..1c60d07 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -571,7 +571,7 @@
                const sal_uInt16 _nInitiallySelectedEvent
            ) override;

    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel) override;
    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel, bool bStyle) override;

    virtual VclPtr<SvxAbstractSplitTableDialog> CreateSvxSplitTableDialog(weld::Window* pParent, bool bIsTableVertical, tools::Long nMaxVertical) override;

diff --git a/cui/source/inc/paragrph.hxx b/cui/source/inc/paragrph.hxx
index 991641e..8f9147e 100644
--- a/cui/source/inc/paragrph.hxx
+++ b/cui/source/inc/paragrph.hxx
@@ -121,7 +121,9 @@

class SvxParaAlignTabPage : public SfxTabPage
{
    static const WhichRangesContainer pAlignRanges;
    static const WhichRangesContainer pAlignRanges, pSdrAlignRanges;

    bool m_bSdrVertAlign;

    SvxParaPrevWindow m_aExampleWin;

@@ -144,6 +146,8 @@
    //vertical alignment
    std::unique_ptr<weld::Widget> m_xVertAlignFL;
    std::unique_ptr<weld::ComboBox> m_xVertAlignLB;
    std::unique_ptr<weld::Label> m_xVertAlign;
    std::unique_ptr<weld::Label> m_xVertAlignSdr;

    std::unique_ptr<weld::Widget> m_xPropertiesFL;
    std::unique_ptr<svx::FrameDirectionListBox>  m_xTextDirectionLB;
@@ -164,12 +168,14 @@
    virtual ~SvxParaAlignTabPage() override;

    static WhichRangesContainer GetRanges() { return pAlignRanges; }
    static WhichRangesContainer GetSdrRanges() { return pSdrAlignRanges; }

    virtual bool            FillItemSet( SfxItemSet* rSet ) override;
    virtual void            Reset( const SfxItemSet* rSet ) override;
    virtual void            ChangesApplied() override;

    void                    EnableJustifyExt();
    void                    EnableSdrVertAlign();
    virtual void            PageCreated(const SfxAllItemSet& aSet) override;
};

diff --git a/cui/source/inc/sdrcelldlg.hxx b/cui/source/inc/sdrcelldlg.hxx
index 5b7e9ca..c8fcbf7 100644
--- a/cui/source/inc/sdrcelldlg.hxx
+++ b/cui/source/inc/sdrcelldlg.hxx
@@ -38,7 +38,7 @@
    XPatternListRef     mpPatternList;

public:
    SvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel);
    SvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel, bool bStyle);

    virtual void PageCreated(const OString& rId, SfxTabPage &rPage) override;

diff --git a/cui/source/tabpages/paragrph.cxx b/cui/source/tabpages/paragrph.cxx
index 78a1cdd..bd2fa72 100644
--- a/cui/source/tabpages/paragrph.cxx
+++ b/cui/source/tabpages/paragrph.cxx
@@ -25,6 +25,7 @@
#include <vcl/settings.hxx>
#include <svx/flagsdef.hxx>
#include <svx/svxids.hrc>
#include <svx/sdtaitm.hxx>

#include <svl/cjkoptions.hxx>
#include <editeng/pgrditem.hxx>
@@ -60,6 +61,13 @@
const WhichRangesContainer SvxParaAlignTabPage::pAlignRanges(
    svl::Items<SID_ATTR_PARA_ADJUST, SID_ATTR_PARA_ADJUST>);  // 10027

const WhichRangesContainer SvxParaAlignTabPage::pSdrAlignRanges(
    svl::Items<
    SDRATTR_TEXT_VERTADJUST, SDRATTR_TEXT_VERTADJUST, // 1076
    SID_ATTR_PARA_ADJUST, SID_ATTR_PARA_ADJUST ,      // 10027
    SID_ATTR_FRAMEDIRECTION, SID_ATTR_FRAMEDIRECTION  // 10944
    >);

const WhichRangesContainer SvxExtParagraphTabPage::pExtRanges(svl::Items<
    SID_ATTR_PARA_PAGEBREAK, SID_ATTR_PARA_WIDOWS, // 10037 - 10041
    SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP        // 10065 - 10066
@@ -976,6 +984,7 @@

SvxParaAlignTabPage::SvxParaAlignTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
    : SfxTabPage(pPage, pController, "cui/ui/paragalignpage.ui", "ParaAlignPage", &rSet)
    , m_bSdrVertAlign(false)
    , m_xLeft(m_xBuilder->weld_radio_button("radioBTN_LEFTALIGN"))
    , m_xRight(m_xBuilder->weld_radio_button("radioBTN_RIGHTALIGN"))
    , m_xCenter(m_xBuilder->weld_radio_button("radioBTN_CENTERALIGN"))
@@ -989,6 +998,8 @@
    , m_xExampleWin(new weld::CustomWeld(*m_xBuilder, "drawingareaWN_EXAMPLE", m_aExampleWin))
    , m_xVertAlignFL(m_xBuilder->weld_widget("frameFL_VERTALIGN"))
    , m_xVertAlignLB(m_xBuilder->weld_combo_box("comboLB_VERTALIGN"))
    , m_xVertAlign(m_xBuilder->weld_label("labelFL_VERTALIGN"))
    , m_xVertAlignSdr(m_xBuilder->weld_label("labelST_VERTALIGN_SDR"))
    , m_xPropertiesFL(m_xBuilder->weld_widget("framePROPERTIES"))
    , m_xTextDirectionLB(new svx::FrameDirectionListBox(m_xBuilder->weld_combo_box("comboLB_TEXTDIRECTION")))
{
@@ -1105,7 +1116,10 @@

    if (m_xVertAlignLB->get_value_changed_from_saved())
    {
        rOutSet->Put(SvxParaVertAlignItem(static_cast<SvxParaVertAlignItem::Align>(m_xVertAlignLB->get_active()), GetWhich( SID_PARA_VERTALIGN )));
        if (m_bSdrVertAlign)
            rOutSet->Put(SdrTextVertAdjustItem(static_cast<SdrTextVertAdjust>(m_xVertAlignLB->get_active())));
        else
            rOutSet->Put(SvxParaVertAlignItem(static_cast<SvxParaVertAlignItem::Align>(m_xVertAlignLB->get_active()), GetWhich( SID_PARA_VERTALIGN )));
        bModified = true;
    }

@@ -1191,16 +1205,23 @@
        m_xSnapToGridCB->set_active(rSnap.GetValue());
    }

    _nWhich = GetWhich( SID_PARA_VERTALIGN );
    _nWhich = m_bSdrVertAlign ? SDRATTR_TEXT_VERTADJUST : GetWhich( SID_PARA_VERTALIGN );
    eItemState = rSet->GetItemState( _nWhich );

    if ( eItemState >= SfxItemState::DEFAULT )
    {
        m_xVertAlignFL->show();

        const SvxParaVertAlignItem& rAlign = static_cast<const SvxParaVertAlignItem&>(rSet->Get( _nWhich ));

        m_xVertAlignLB->set_active(static_cast<sal_Int32>(rAlign.GetValue()));
        if (m_bSdrVertAlign)
        {
            const SdrTextVertAdjustItem& rAlign = static_cast<const SdrTextVertAdjustItem&>(rSet->Get( _nWhich ));
            m_xVertAlignLB->set_active(rAlign.GetValue());
        }
        else
        {
            const SvxParaVertAlignItem& rAlign = static_cast<const SvxParaVertAlignItem&>(rSet->Get( _nWhich ));
            m_xVertAlignLB->set_active(static_cast<sal_Int32>(rAlign.GetValue()));
        }
    }

    _nWhich = GetWhich( SID_ATTR_FRAMEDIRECTION );
@@ -1330,6 +1351,15 @@

}

void SvxParaAlignTabPage::EnableSdrVertAlign()
{
    m_bSdrVertAlign = true;

    m_xVertAlignLB->remove_id("0");
    m_xVertAlignLB->remove_id("1");
    m_xVertAlign->set_label(m_xVertAlignSdr->get_label());
}

void SvxParaAlignTabPage::PageCreated (const SfxAllItemSet& aSet)
{
    const SfxBoolItem* pBoolItem = aSet.GetItem<SfxBoolItem>(SID_SVXPARAALIGNTABPAGE_ENABLEJUSTIFYEXT, false);
diff --git a/cui/uiconfig/ui/formatcellsdialog.ui b/cui/uiconfig/ui/formatcellsdialog.ui
index 0ced6ff..c2756aa 100644
--- a/cui/uiconfig/ui/formatcellsdialog.ui
+++ b/cui/uiconfig/ui/formatcellsdialog.ui
@@ -34,6 +34,20 @@
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="standard">
                <property name="label" translatable="yes" context="formatcellsdialog|standard">_Standard</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
                <property name="use-underline">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="ok">
                <property name="label" translatable="yes" context="stock">_OK</property>
                <property name="visible">True</property>
@@ -46,7 +60,7 @@
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">1</property>
                <property name="position">2</property>
              </packing>
            </child>
            <child>
@@ -60,7 +74,7 @@
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">2</property>
                <property name="position">3</property>
              </packing>
            </child>
            <child>
@@ -74,7 +88,7 @@
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">3</property>
                <property name="position">4</property>
                <property name="secondary">True</property>
              </packing>
            </child>
@@ -152,10 +166,10 @@
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="border">
              <object class="GtkLabel" id="position">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|border">Borders</property>
                <property name="label" translatable="yes" context="formatcellsdialog|position">Position</property>
              </object>
              <packing>
                <property name="position">2</property>
@@ -176,10 +190,10 @@
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="area">
              <object class="GtkLabel" id="highlight">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|area">Background</property>
                <property name="label" translatable="yes" context="formatcellsdialog|highlight">Highlighting</property>
              </object>
              <packing>
                <property name="position">3</property>
@@ -200,13 +214,133 @@
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="indentspacing">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|indentspacing">Indents &amp; Spacing</property>
              </object>
              <packing>
                <property name="position">4</property>
                <property name="tab-fill">False</property>
              </packing>
            </child>
            <child>
              <!-- n-columns=1 n-rows=1 -->
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <child>
                  <placeholder/>
                </child>
              </object>
              <packing>
                <property name="position">5</property>
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="asian">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|asian">Asian Typography</property>
              </object>
              <packing>
                <property name="position">5</property>
                <property name="tab-fill">False</property>
              </packing>
            </child>
            <child>
              <!-- n-columns=1 n-rows=1 -->
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <child>
                  <placeholder/>
                </child>
              </object>
              <packing>
                <property name="position">6</property>
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="alignment">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|alignment">Alignment</property>
              </object>
              <packing>
                <property name="position">6</property>
                <property name="tab-fill">False</property>
              </packing>
            </child>
            <child>
              <!-- n-columns=1 n-rows=1 -->
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <child>
                  <placeholder/>
                </child>
              </object>
              <packing>
                <property name="position">7</property>
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="border">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|border">Borders</property>
              </object>
              <packing>
                <property name="position">7</property>
                <property name="tab-fill">False</property>
              </packing>
            </child>
            <child>
              <!-- n-columns=1 n-rows=1 -->
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <child>
                  <placeholder/>
                </child>
              </object>
              <packing>
                <property name="position">8</property>
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="area">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|area">Background</property>
              </object>
              <packing>
                <property name="position">8</property>
                <property name="tab-fill">False</property>
              </packing>
            </child>
            <child>
              <!-- n-columns=1 n-rows=1 -->
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <child>
                  <placeholder/>
                </child>
              </object>
              <packing>
                <property name="position">9</property>
              </packing>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="shadow">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="label" translatable="yes" context="formatcellsdialog|shadow">Shadow</property>
              </object>
              <packing>
                <property name="position">5</property>
                <property name="position">9</property>
                <property name="tab-fill">False</property>
              </packing>
            </child>
@@ -221,6 +355,7 @@
    </child>
    <action-widgets>
      <action-widget response="101">reset</action-widget>
      <action-widget response="102">standard</action-widget>
      <action-widget response="-5">ok</action-widget>
      <action-widget response="-6">cancel</action-widget>
      <action-widget response="-11">help</action-widget>
diff --git a/cui/uiconfig/ui/paragalignpage.ui b/cui/uiconfig/ui/paragalignpage.ui
index 07bda24..47f5865 100644
--- a/cui/uiconfig/ui/paragalignpage.ui
+++ b/cui/uiconfig/ui/paragalignpage.ui
@@ -190,6 +190,17 @@
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkLabel" id="labelST_VERTALIGN_SDR">
                        <property name="can-focus">False</property>
                        <property name="label" translatable="yes" context="paragalignpage|labelST_VERTALIGN_SDR">Vertical</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="fill">True</property>
                        <property name="position">2</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="left-attach">0</property>
diff --git a/include/svx/svxdlg.hxx b/include/svx/svxdlg.hxx
index d697da7..ded2d20 100644
--- a/include/svx/svxdlg.hxx
+++ b/include/svx/svxdlg.hxx
@@ -437,7 +437,7 @@
                const sal_uInt16 _nInitiallySelectedEvent
            ) = 0;

    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel )=0;
    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog(weld::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel, bool bStyle)=0;

    virtual VclPtr<SvxAbstractSplitTableDialog> CreateSvxSplitTableDialog(weld::Window* pParent, bool bIsTableVertical, tools::Long nMaxVertical) = 0;

diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index 5342621..9b3d868 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -944,7 +944,7 @@
    VclPtr<SfxAbstractTabDialog> xDlg( pFact->CreateSvxFormatCellsDialog(
        rReq.GetFrameWeld(),
        &aNewAttr,
        rModel) );
        rModel, false) );

    // Even Cancel Button is returning positive(101) value,
    xDlg->StartExecuteAsync([xDlg, this, aBoxItem, aBoxInfoItem](int nResult){