tdf#63374 Change cell background color when in edit mode

Set the edit cell background (EditView) color to CALCCELLFOCUS
and allow enabling/disabling via a checkbox
tools > options > Calc > View > Edit cell background highlighting

Change-Id: I1216dfa0880e1080d23059512e3801d6af3b3c11
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165075
Tested-by: Jenkins
Tested-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
index 5582b346..fb6edf0 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
@@ -137,6 +137,14 @@
          </info>
          <value>false</value>
        </prop>
        <prop oor:name="EditCellBackgroundHighlighting" oor:type="xs:boolean" oor:nillable="false">
          <!-- UIHints: Tools - Options -Spreadsheets - Contents - [Section] Display -->
          <info>
            <desc>Indicates whether the edit cell background highlighting is enabled or not.</desc>
            <label>Edit cell background highlighting</label>
          </info>
          <value>false</value>
        </prop>
        <prop oor:name="Anchor" oor:type="xs:boolean" oor:nillable="false">
          <!-- UIHints: Tools - Options -Spreadsheets - Contents - [Section] Display -->
          <info>
diff --git a/sc/source/ui/inc/tpview.hxx b/sc/source/ui/inc/tpview.hxx
index 97addc9..ace6583 100644
--- a/sc/source/ui/inc/tpview.hxx
+++ b/sc/source/ui/inc/tpview.hxx
@@ -47,6 +47,8 @@ class ScTpContentOptions : public SfxTabPage
    std::unique_ptr<weld::Widget> m_xValueImg;
    std::unique_ptr<weld::CheckButton> m_xColRowHighCB;
    std::unique_ptr<weld::Widget> m_xColRowHighImg;
    std::unique_ptr<weld::CheckButton> m_xEditCellBgHighCB;
    std::unique_ptr<weld::Widget> m_xEditCellBgHighImg;
    std::unique_ptr<weld::CheckButton> m_xAnchorCB;
    std::unique_ptr<weld::Widget> m_xAnchorImg;
    std::unique_ptr<weld::CheckButton> m_xRangeFindCB;
diff --git a/sc/source/ui/optdlg/tpview.cxx b/sc/source/ui/optdlg/tpview.cxx
index 779dcdd..d4d9f67 100644
--- a/sc/source/ui/optdlg/tpview.cxx
+++ b/sc/source/ui/optdlg/tpview.cxx
@@ -54,6 +54,8 @@ ScTpContentOptions::ScTpContentOptions(weld::Container* pPage, weld::DialogContr
    , m_xValueImg(m_xBuilder->weld_widget("lockvalue"))
    , m_xColRowHighCB(m_xBuilder->weld_check_button("colrowhigh"))
    , m_xColRowHighImg(m_xBuilder->weld_widget("lockcolrowhigh"))
    , m_xEditCellBgHighCB(m_xBuilder->weld_check_button("editcellbg"))
    , m_xEditCellBgHighImg(m_xBuilder->weld_widget("lockeditcellbghigh"))
    , m_xAnchorCB(m_xBuilder->weld_check_button("anchor"))
    , m_xAnchorImg(m_xBuilder->weld_widget("lockanchor"))
    , m_xRangeFindCB(m_xBuilder->weld_check_button("rangefind"))
@@ -97,6 +99,7 @@ ScTpContentOptions::ScTpContentOptions(weld::Container* pPage, weld::DialogContr
    m_xFormulaMarkCB->connect_toggled(aCBHdl);
    m_xValueCB->connect_toggled(aCBHdl);
    m_xColRowHighCB->connect_toggled(aCBHdl);
    m_xEditCellBgHighCB->connect_toggled(aCBHdl);
    m_xAnchorCB->connect_toggled(aCBHdl);

    m_xVScrollCB->connect_toggled(aCBHdl);
@@ -189,6 +192,13 @@ bool    ScTpContentOptions::FillItemSet( SfxItemSet* rCoreSet )
        pChange->commit();
        bRet = true;
    }
    if (m_xEditCellBgHighCB->get_state_changed_from_saved())
    {
        auto pChange(comphelper::ConfigurationChanges::create());
        officecfg::Office::Calc::Content::Display::EditCellBackgroundHighlighting::set(m_xEditCellBgHighCB->get_active(), pChange);
        pChange->commit();
        bRet = true;
    }

    return bRet;
}
@@ -205,6 +215,7 @@ void    ScTpContentOptions::Reset( const SfxItemSet* rCoreSet )
    m_xFormulaMarkCB->set_active(m_xLocalOptions->GetOption(VOPT_FORMULAS_MARKS));
    m_xValueCB   ->set_active(m_xLocalOptions->GetOption(VOPT_SYNTAX));
    m_xColRowHighCB->set_active(officecfg::Office::Calc::Content::Display::ColumnRowHighlighting::get());
    m_xEditCellBgHighCB->set_active(officecfg::Office::Calc::Content::Display::EditCellBackgroundHighlighting::get());
    m_xAnchorCB  ->set_active(m_xLocalOptions->GetOption(VOPT_ANCHOR));

    m_xObjGrfLB  ->set_active( static_cast<sal_uInt16>(m_xLocalOptions->GetObjMode(VOBJ_TYPE_OLE)) );
@@ -269,6 +280,10 @@ void    ScTpContentOptions::Reset( const SfxItemSet* rCoreSet )
    m_xColRowHighCB->set_sensitive(!bReadOnly);
    m_xColRowHighImg->set_visible(bReadOnly);

    bReadOnly = officecfg::Office::Calc::Content::Display::EditCellBackgroundHighlighting::isReadOnly();
    m_xEditCellBgHighCB->set_sensitive(!bReadOnly);
    m_xEditCellBgHighImg->set_visible(bReadOnly);

    bReadOnly = officecfg::Office::Calc::Content::Display::Anchor::isReadOnly();
    m_xAnchorCB->set_sensitive(!bReadOnly);
    m_xAnchorImg->set_visible(bReadOnly);
@@ -331,6 +346,7 @@ void    ScTpContentOptions::Reset( const SfxItemSet* rCoreSet )
    m_xFormulaMarkCB->save_state();
    m_xValueCB->save_state();
    m_xColRowHighCB->save_state();
    m_xEditCellBgHighCB->save_state();
    m_xAnchorCB->save_state();
    m_xObjGrfLB->save_value();
    m_xDiagramLB->save_value();
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 5c4ea63..896d44f 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -38,6 +38,7 @@
#include <comphelper/lok.hxx>
#include <sfx2/lokhelper.hxx>
#include <sfx2/lokcomponenthelpers.hxx>
#include <officecfg/Office/Calc.hxx>

#include <svx/svdview.hxx>
#include <svx/svdpagv.hxx>
@@ -720,6 +721,15 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
        SCCOL nEditEndCol = mrViewData.GetEditEndCol();
        SCROW nEditEndRow = mrViewData.GetEditEndRow();

        if (officecfg::Office::Calc::Content::Display::EditCellBackgroundHighlighting::get()
                && !getViewData().GetMarkData().IsMarked())
        {
            const Color aBackgroundColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
            Color aHighlightColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::CALCCELLFOCUS).nColor;
            aHighlightColor.Merge(aBackgroundColor, 100);
            pEditView->SetBackgroundColor(aHighlightColor);
        }

        if ( nEditEndCol >= nX1 && nEditCol <= nX2 && nEditEndRow >= nY1 && nEditRow <= nY2 )
            aOutputData.SetEditCell( nEditCol, nEditRow );
        else
diff --git a/sc/uiconfig/scalc/ui/tpviewpage.ui b/sc/uiconfig/scalc/ui/tpviewpage.ui
index 2213fd2..68d41c2 100644
--- a/sc/uiconfig/scalc/ui/tpviewpage.ui
+++ b/sc/uiconfig/scalc/ui/tpviewpage.ui
@@ -20,7 +20,7 @@
            <property name="label-xalign">0</property>
            <property name="shadow-type">none</property>
            <child>
              <!-- n-columns=2 n-rows=8 -->
              <!-- n-columns=2 n-rows=9 -->
              <object class="GtkGrid" id="grid6">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
@@ -127,7 +127,7 @@
                  </object>
                  <packing>
                    <property name="left-attach">1</property>
                    <property name="top-attach">7</property>
                    <property name="top-attach">8</property>
                  </packing>
                </child>
                <child>
@@ -192,7 +192,7 @@
                  </object>
                  <packing>
                    <property name="left-attach">0</property>
                    <property name="top-attach">6</property>
                    <property name="top-attach">7</property>
                  </packing>
                </child>
                <child>
@@ -224,7 +224,7 @@
                  </object>
                  <packing>
                    <property name="left-attach">1</property>
                    <property name="top-attach">6</property>
                    <property name="top-attach">7</property>
                  </packing>
                </child>
                <child>
@@ -237,7 +237,7 @@
                  </object>
                  <packing>
                    <property name="left-attach">0</property>
                    <property name="top-attach">7</property>
                    <property name="top-attach">8</property>
                  </packing>
                </child>
                <child>
@@ -272,6 +272,38 @@
                    <property name="top-attach">5</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkCheckButton" id="editcellbg">
                    <property name="label" translatable="yes" context="tpviewpage|value">Edit cell background highlighting</property>
                    <property name="visible">True</property>
                    <property name="can-focus">True</property>
                    <property name="receives-default">False</property>
                    <property name="use-underline">True</property>
                    <property name="draw-indicator">True</property>
                    <child internal-child="accessible">
                      <object class="AtkObject" id="editcellbg-atkobject">
                        <property name="AtkObject::accessible-description" translatable="yes" context="extended_tip|value">Mark the Edit cell background highlighting checkbox to show cell frame background color as the edit cell background.</property>
                      </object>
                    </child>
                  </object>
                  <packing>
                    <property name="left-attach">1</property>
                    <property name="top-attach">6</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkImage" id="lockeditcellbghigh">
                    <property name="can-focus">False</property>
                    <property name="no-show-all">True</property>
                    <property name="halign">center</property>
                    <property name="valign">center</property>
                    <property name="icon-name">res/lock.png</property>
                  </object>
                  <packing>
                    <property name="left-attach">0</property>
                    <property name="top-attach">6</property>
                  </packing>
                </child>
              </object>
            </child>
            <child type="label">