Resolves tdf#63374 and tdf#160908

Show edit highlight only when arrow keys won't commit.
Use shorter UI label.

Edit mode can be activated in two major ways, in which arrow keys
behave differently.

a) F2 | double_click | edit > Cell Edit Mode, in which case, the
   arrow keys either move the caret "|" or "reference cell frame".
b) just start typing on the cell, in which case, pressing arrow
   keys commit the change.

Edit highlight should be shown in case "a" to differentiate between
the two. If the cell has some background color, or multiselection,
then highlight is not shown.

Change-Id: I710aa641cd47e8ca279dd8bd0e3b4e857d1b0c40
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167092
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 1c1aaf0..85ecd8f 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -2870,6 +2870,7 @@ void ScInputHandler::UpdateFormulaMode()
    {
        if (!bFormulaMode)
        {
            pActiveViewSh->GetViewData().SetEditHighlight(true);
            bFormulaMode = true;
            pRefViewSh = pActiveViewSh;
            pSfxApp->Broadcast( SfxHint( SfxHintId::ScRefModeChanged ) );
@@ -2891,6 +2892,7 @@ void ScInputHandler::UpdateFormulaMode()
    {
        if (bFormulaMode)
        {
            pActiveViewSh->GetViewData().SetEditHighlight(false);
            ShowRefFrame();
            bFormulaMode = false;
            pRefViewSh = nullptr;
@@ -3054,6 +3056,7 @@ void ScInputHandler::SetMode( ScInputMode eNewMode, const OUString* pInitText, S
    {
        if (pTableView)
            pTableView->SetEditEngineUpdateLayout(true);
        pActiveViewSh->GetViewData().SetEditHighlight(true);
    }
    else
    {
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 673ab24..7c79bb9 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -329,6 +329,7 @@ private:
    bool                bPagebreak:1;               // Page break preview mode
    bool                bSelCtrlMouseClick:1;       // special selection handling for ctrl-mouse-click
    bool                bMoveArea:1;
    bool                bEditHighlight:1;

    bool                bGrowing;
    sal_Int16           nFormulaBarLines;           // Visible lines in the formula bar
@@ -569,6 +570,9 @@ public:
    bool    IsOutlineMode   () const            { return maOptions.GetOption(VOPT_OUTLINER); }
    bool    IsThemedCursor  () const            { return maOptions.GetOption(VOPT_THEMEDCURSOR); }

    bool    GetEditHighlight() const            { return bEditHighlight; }
    void    SetEditHighlight(bool bNewHighlight) { bEditHighlight = bNewHighlight; }

    /// Force page size for PgUp/PgDown to overwrite the computation based on m_aVisArea.
    void ForcePageUpDownOffset(tools::Long nTwips) { m_nLOKPageUpDownOffset = nTwips; }
    tools::Long GetPageUpDownOffset() const { return m_nLOKPageUpDownOffset; }
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 4b03921..a9492df 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -758,13 +758,22 @@ 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())

        if (officecfg::Office::Calc::Content::Display::EditCellBackgroundHighlighting::get())
        {
            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);
            Color aDocColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
            if (!getViewData().GetMarkData().IsMarked() && mrViewData.GetEditHighlight())
            {
                Color aHighlightColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::CALCCELLFOCUS).nColor;
                aHighlightColor.Merge(aDocColor, 100);
                aDocColor = aHighlightColor;
            }

            Color aBackColor = rDoc.GetPattern(nEditCol, nEditRow, getViewData().GetTabNo())->GetItem(ATTR_BACKGROUND).GetColor();
            if (!aBackColor.IsTransparent())
                aDocColor = aBackColor;

            pEditView->SetBackgroundColor(aDocColor);
        }

        if ( nEditEndCol >= nX1 && nEditCol <= nX2 && nEditEndRow >= nY1 && nEditRow <= nY2 )
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index 55bb2f8..aafc46a 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -785,6 +785,7 @@ void ScTabViewShell::SetEditShell(EditView* pView, bool bActive )
    else if(bActiveEditSh)
    {
        SetCurSubShell(OST_Cell);
        GetViewData().SetEditHighlight(false);
    }
    bActiveEditSh = bActive;
}
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 3bed82b..1c0ad55 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -816,6 +816,7 @@ ScViewData::ScViewData(ScDocument* pDoc, ScDocShell* pDocSh, ScTabViewShell* pVi
        bPagebreak  ( false ),
        bSelCtrlMouseClick( false ),
        bMoveArea ( false ),
        bEditHighlight ( false ),
        bGrowing (false),
        nFormulaBarLines(1),
        m_nLOKPageUpDownOffset( 0 )
diff --git a/sc/uiconfig/scalc/ui/tpviewpage.ui b/sc/uiconfig/scalc/ui/tpviewpage.ui
index fb19f01..4fd40a3 100644
--- a/sc/uiconfig/scalc/ui/tpviewpage.ui
+++ b/sc/uiconfig/scalc/ui/tpviewpage.ui
@@ -274,7 +274,7 @@
                </child>
                <child>
                  <object class="GtkCheckButton" id="editcellbg">
                    <property name="label" translatable="yes" context="tpviewpage|value">Edit cell background highlighting</property>
                    <property name="label" translatable="yes" context="tpviewpage|value">Edit cell highlighting</property>
                    <property name="visible">True</property>
                    <property name="can-focus">True</property>
                    <property name="receives-default">False</property>
@@ -282,7 +282,7 @@
                    <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>
                        <property name="AtkObject::accessible-description" translatable="yes" context="extended_tip|value">Mark this box to show highlighted background when the cell is in edit mode.</property>
                      </object>
                    </child>
                  </object>