offapi/com/sun/star/sheet/SpreadsheetViewSettings.idl |    7 ++
 sc/inc/ViewSettingsSequenceDefines.hxx                |    3 +
 sc/inc/unonames.hxx                                   |    1 
 sc/source/ui/app/inputwin.cxx                         |   43 ++++++++++++++----
 sc/source/ui/inc/inputwin.hxx                         |    8 ++-
 sc/source/ui/inc/viewdata.hxx                         |   10 ++++
 sc/source/ui/unoobj/viewuno.cxx                       |   24 +++++++++-
 sc/source/ui/view/viewdata.cxx                        |   21 ++++++++
 test/source/sheet/spreadsheetviewsettings.cxx         |   10 ++++
 9 files changed, 115 insertions(+), 12 deletions(-)

New commits:
commit d0cacf09a1105d89bf3df84b18623d790e3aeb82
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Wed Apr 27 11:45:04 2022 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Tue May 3 14:52:07 2022 +0200

    tdf#99708 Save formula bar height to document
    
    Save the current state of the Calc formula bar to the document.
    Number of visible lines is saved into the document settings
    and restored when loading that document.
    
    Also adds a UNO property, so that the formula bar height can be
    changed via UNO.
    
    Change-Id: Ifef0c9e42cb4f7465516629d2c22974367e0eb33
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133499
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/offapi/com/sun/star/sheet/SpreadsheetViewSettings.idl 
b/offapi/com/sun/star/sheet/SpreadsheetViewSettings.idl
index 9dc5b853f61d..69da69013db0 100644
--- a/offapi/com/sun/star/sheet/SpreadsheetViewSettings.idl
+++ b/offapi/com/sun/star/sheet/SpreadsheetViewSettings.idl
@@ -152,6 +152,13 @@ published service SpreadsheetViewSettings
         com::sun::star::view::DocumentZoomType::BY_VALUE.
     */
     [property] short ZoomValue;
+
+    /** Number of lines shown in the Formula bar
+        Default is 1, maximum value is 25.
+
+        @since LibreOffice 7.4
+    */
+    [optional, property] short FormulaBarHeight;
 };
 
 
diff --git a/sc/inc/ViewSettingsSequenceDefines.hxx 
b/sc/inc/ViewSettingsSequenceDefines.hxx
index 8fdbb5bb16ec..7fd754a07b6d 100644
--- a/sc/inc/ViewSettingsSequenceDefines.hxx
+++ b/sc/inc/ViewSettingsSequenceDefines.hxx
@@ -50,6 +50,7 @@
 #define SC_RASTERSUBX                       21
 #define SC_RASTERSUBY                       22
 #define SC_RASTERSYNC                       23
+#define SC_FORMULA_BAR_HEIGHT               24
 
 // this are the defines for the position of the settings in the
 // TableViewSettingsSequence
@@ -70,6 +71,7 @@
 #define SC_TABLE_ZOOM_TYPE                  11
 #define SC_TABLE_ZOOM_VALUE                 12
 #define SC_TABLE_PAGE_VIEW_ZOOM_VALUE       13
+#define SC_FORMULA_BAR_HEIGHT_VALUE         14
 #define SC_TABLE_SHOWGRID                   15
 
 inline constexpr OUStringLiteral SC_CURSORPOSITIONX = u"CursorPositionX";
@@ -95,6 +97,7 @@ inline constexpr OUStringLiteral SC_ZOOMTYPE = u"ZoomType";
 inline constexpr OUStringLiteral SC_ZOOMVALUE = u"ZoomValue";
 inline constexpr OUStringLiteral SC_PAGEVIEWZOOMVALUE = u"PageViewZoomValue";
 inline constexpr OUStringLiteral SC_SHOWPAGEBREAKPREVIEW = 
u"ShowPageBreakPreview";
+inline constexpr OUStringLiteral SC_FORMULABARHEIGHT = u"FormulaBarHeight";
 inline constexpr OUStringLiteral SC_VIEWID = u"ViewId";
 #define SC_VIEW                             "view"
 
diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx
index 7a73176cfd29..b21f7405d035 100644
--- a/sc/inc/unonames.hxx
+++ b/sc/inc/unonames.hxx
@@ -576,6 +576,7 @@ inline constexpr OUStringLiteral 
SC_SERVICENAME_CHART_PIVOTTABLE_DATAPROVIDER =
 #define SC_UNO_UPDTEMPL             "UpdateFromTemplate"
 #define SC_UNO_FILTERED_RANGE_SELECTION       "FilteredRangeSelection"
 #define SC_UNO_VISAREASCREEN        "VisibleAreaOnScreen"
+#define SC_UNO_FORMULABARHEIGHT     "FormulaBarHeight"
 #define SC_UNO_IMAGE_PREFERRED_DPI  "ImagePreferredDPI"
 
 /*Stampit enable/disable print cancel */
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index e50c682a1703..ab258fe6368c 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -677,6 +677,11 @@ void ScInputWindow::EnableButtons( bool bEnable )
 //  Invalidate();
 }
 
+void ScInputWindow::NumLinesChanged()
+{
+    mxTextWindow->NumLinesChanged();
+}
+
 void ScInputWindow::StateChanged( StateChangedType nType )
 {
     ToolBox::StateChanged( nType );
@@ -908,6 +913,7 @@ void ScInputBarGroup::Resize()
 {
     mxTextWndGroup->SetScrollPolicy();
     InterimItemWindow::Resize();
+    TriggerToolboxLayout();
 }
 
 void ScInputBarGroup::StopEditEngine(bool bAll)
@@ -1034,16 +1040,25 @@ IMPL_LINK_NOARG(ScInputWindow, DropdownClickHdl, 
ToolBox *, void)
 IMPL_LINK_NOARG(ScInputBarGroup, ClickHdl, weld::Button&, void)
 {
     if (mxTextWndGroup->GetNumLines() > 1)
-    {
         mxTextWndGroup->SetNumLines(1);
-        mxButtonUp->hide();
-        mxButtonDown->show();
-    }
     else
-    {
         mxTextWndGroup->SetNumLines(mxTextWndGroup->GetLastNumExpandedLines());
+
+    NumLinesChanged();
+}
+
+void ScInputBarGroup::NumLinesChanged()
+{
+    if (mxTextWndGroup->GetNumLines() > 1)
+    {
         mxButtonDown->hide();
         mxButtonUp->show();
+        mxTextWndGroup->SetLastNumExpandedLines(mxTextWndGroup->GetNumLines());
+    }
+    else
+    {
+        mxButtonUp->hide();
+        mxButtonDown->show();
     }
     TriggerToolboxLayout();
 
@@ -1165,6 +1180,11 @@ tools::Long ScTextWndGroup::GetLastNumExpandedLines() 
const
     return mxTextWnd->GetLastNumExpandedLines();
 }
 
+void ScTextWndGroup::SetLastNumExpandedLines(tools::Long nLastExpandedLines)
+{
+    mxTextWnd->SetLastNumExpandedLines(nLastExpandedLines);
+}
+
 tools::Long ScTextWndGroup::GetNumLines() const
 {
     return mxTextWnd->GetNumLines();
@@ -1301,9 +1321,17 @@ int ScTextWnd::GetPixelHeightForLines(tools::Long nLines)
     return rDevice.LogicToPixel(Size(0, nLines * 
rDevice.GetTextHeight())).Height() + 1;
 }
 
+tools::Long ScTextWnd::GetNumLines() const
+{
+    ScViewData& rViewData = mpViewShell->GetViewData();
+    return rViewData.GetFormulaBarLines();
+}
+
 void ScTextWnd::SetNumLines(tools::Long nLines)
 {
-    mnLines = nLines;
+    ScViewData& rViewData = mpViewShell->GetViewData();
+    rViewData.SetFormulaBarLines(nLines);
+
     if ( nLines > 1 )
     {
         mnLastExpandedLines = nLines;
@@ -1567,7 +1595,6 @@ ScTextWnd::ScTextWnd(ScTextWndGroup& rParent, 
ScTabViewShell* pViewSh) :
         bInputMode   (false),
         mpViewShell(pViewSh),
         mrGroupBar(rParent),
-        mnLines(1),
         mnLastExpandedLines(INPUTWIN_MULTILINES),
         mbInvalidate(false)
 {
@@ -1931,7 +1958,7 @@ void ScTextWnd::SetTextString( const OUString& rNewString 
)
         // Find position of the change, only paint the rest
         if (!m_xEditEngine)
         {
-            bool bPaintAll = mnLines > 1 || bIsRTL;
+            bool bPaintAll = GetNumLines() > 1 || bIsRTL;
             if (!bPaintAll)
             {
                 //  test if CTL script type is involved
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index 6bd4c3152712..12bc461f2836 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -104,9 +104,10 @@ public:
     int GetPixelHeightForLines(tools::Long nLines);
     int GetEditEngTxtHeight() const;
 
-    virtual tools::Long GetNumLines() const override { return mnLines; }
+    virtual tools::Long GetNumLines() const override;
     void SetNumLines(tools::Long nLines);
     tools::Long GetLastNumExpandedLines() const { return mnLastExpandedLines; }
+    void SetLastNumExpandedLines(tools::Long nLastExpandedLines) { 
mnLastExpandedLines = nLastExpandedLines; }
 
     void DoScroll();
 
@@ -153,7 +154,6 @@ private:
 
     ScTabViewShell* mpViewShell;
     ScTextWndGroup& mrGroupBar;
-    tools::Long mnLines;
     tools::Long mnLastExpandedLines;
     bool mbInvalidate;
 };
@@ -209,6 +209,7 @@ public:
     const OutputDevice&     GetEditViewDevice() const;
     Point                   GetCursorScreenPixelPos(bool bBelowLine);
     tools::Long             GetLastNumExpandedLines() const;
+    void SetLastNumExpandedLines(tools::Long nLastExpandedLines);
     virtual tools::Long     GetNumLines() const override;
     int                     GetPixelHeightForLines(tools::Long nLines);
     weld::ScrolledWindow&   GetScrollWin();
@@ -259,6 +260,7 @@ public:
     bool                    IsInputActive() override;
     void                    IncrementVerticalSize();
     void                    DecrementVerticalSize();
+    void                    NumLinesChanged();
     virtual tools::Long            GetNumLines() const override { return 
mxTextWndGroup->GetNumLines(); }
     tools::Long                    GetVertOffset() const { return  
mnVertOffset; }
 
@@ -300,6 +302,8 @@ public:
     void            SetOkCancelMode();
     void            SetSumAssignMode();
     void            EnableButtons( bool bEnable );
+    /// Update Input bar after the number of lines was changed externally
+    void            NumLinesChanged();
 
     void            StartFormula();
     void            SetFormulaMode( bool bSet );
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 76c65bf46a59..34bc8c49c4f6 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -329,6 +329,7 @@ private:
     bool                bMoveArea:1;
 
     bool                bGrowing;
+    sal_Int16           nFormulaBarLines;           // Visible lines in the 
formula bar
 
     tools::Long                m_nLOKPageUpDownOffset;
     tools::Rectangle    maLOKVisibleArea;///< The visible area in the 
LibreOfficeKit client.
@@ -467,6 +468,15 @@ public:
     double          GetPPTX() const { return nPPTX; }
     double          GetPPTY() const { return nPPTY; }
 
+    void SetFormulaBarLines(sal_Int16 nLines)
+    {
+        // Formula bar must be between 1 and 25 lines (see 
SpreadsheetViewSettings.idl)
+        nLines = std::max(nLines, static_cast<sal_Int16>(1));
+        nLines = std::min(nLines, static_cast<sal_Int16>(25));
+        nFormulaBarLines = nLines;
+    }
+    sal_Int16 GetFormulaBarLines() const { return nFormulaBarLines; };
+
     ScMarkType      GetSimpleArea( SCCOL& rStartCol, SCROW& rStartRow, SCTAB& 
rStartTab,
                                     SCCOL& rEndCol, SCROW& rEndRow, SCTAB& 
rEndTab ) const;
     ScMarkType      GetSimpleArea( ScRange& rRange ) const;
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index 5c6d599dd74f..4fe5b0c1f7d9 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -65,6 +65,8 @@
 #include <markdata.hxx>
 #include <scextopt.hxx>
 #include <preview.hxx>
+#include <inputhdl.hxx>
+#include <inputwin.hxx>
 #include <svx/sdrhittesthelper.hxx>
 #include <formatsh.hxx>
 #include <sfx2/app.hxx>
@@ -107,6 +109,7 @@ static const SfxItemPropertyMapEntry* 
lcl_GetViewOptPropertyMap()
         { SC_UNO_ZOOMTYPE,     0,  cppu::UnoType<sal_Int16>::get(),    0, 0},
         { SC_UNO_ZOOMVALUE,    0,  cppu::UnoType<sal_Int16>::get(),    0, 0},
         { SC_UNO_VISAREASCREEN,0,  cppu::UnoType<awt::Rectangle>::get(), 0, 0},
+        { SC_UNO_FORMULABARHEIGHT,0,cppu::UnoType<sal_Int16>::get(),     0, 0},
         { u"", 0, css::uno::Type(), 0, 0 }
     };
     return aViewOptPropertyMap_Impl;
@@ -1793,6 +1796,22 @@ void SAL_CALL ScTabViewObj::setPropertyValue(
         if ( aValue >>= nIntVal )
             SetZoom(nIntVal);
     }
+    else if ( aPropertyName == SC_UNO_FORMULABARHEIGHT )
+    {
+        sal_Int16 nIntVal = ScUnoHelpFunctions::GetInt16FromAny(aValue);
+        if (nIntVal > 0)
+        {
+            rViewData.SetFormulaBarLines(nIntVal);
+            // Notify formula bar about changed lines
+            ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
+            if (pInputHdl)
+            {
+                ScInputWindow* pInputWin = pInputHdl->GetInputWindow();
+                if (pInputWin)
+                    pInputWin->NumLinesChanged();
+            }
+        }
+    }
 
     //  Options are set on the view and document (for new views),
     //  so that they remain during saving.
@@ -1832,7 +1851,8 @@ uno::Any SAL_CALL ScTabViewObj::getPropertyValue( const 
OUString& aPropertyName
     ScTabViewShell* pViewSh = GetViewShell();
     if (pViewSh)
     {
-        const ScViewOptions& rOpt = pViewSh->GetViewData().GetOptions();
+        ScViewData& rViewData = pViewSh->GetViewData();
+        const ScViewOptions& rOpt = rViewData.GetOptions();
 
         if ( aPropertyName == SC_UNO_COLROWHDR || aPropertyName == 
OLD_UNO_COLROWHDR )
             aRet <<= rOpt.GetOption( VOPT_HEADER );
@@ -1860,9 +1880,9 @@ uno::Any SAL_CALL ScTabViewObj::getPropertyValue( const 
OUString& aPropertyName
         else if ( aPropertyName == SC_UNO_VISAREA ) aRet <<= GetVisArea();
         else if ( aPropertyName == SC_UNO_ZOOMTYPE ) aRet <<= GetZoomType();
         else if ( aPropertyName == SC_UNO_ZOOMVALUE ) aRet <<= GetZoom();
+        else if ( aPropertyName == SC_UNO_FORMULABARHEIGHT ) aRet <<= 
rViewData.GetFormulaBarLines();
         else if ( aPropertyName == SC_UNO_VISAREASCREEN )
         {
-            ScViewData& rViewData = pViewSh->GetViewData();
             vcl::Window* pActiveWin = rViewData.GetActiveWin();
             if ( pActiveWin )
             {
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 90c63e6a95fb..31f3e5fdeaa9 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -53,6 +53,8 @@
 #include <miscuno.hxx>
 #include <unonames.hxx>
 #include <inputopt.hxx>
+#include <inputhdl.hxx>
+#include <inputwin.hxx>
 #include <viewutil.hxx>
 #include <markdata.hxx>
 #include <ViewSettingsSequenceDefines.hxx>
@@ -814,6 +816,7 @@ ScViewData::ScViewData(ScDocument* pDoc, ScDocShell* 
pDocSh, ScTabViewShell* pVi
         bSelCtrlMouseClick( false ),
         bMoveArea ( false ),
         bGrowing (false),
+        nFormulaBarLines(1),
         m_nLOKPageUpDownOffset( 0 )
 {
     assert(bool(pDoc) != bool(pDocSh)); // either one or the other, not both
@@ -3764,6 +3767,8 @@ void ScViewData::WriteUserDataSequence(uno::Sequence 
<beans::PropertyValue>& rSe
     pSettings[SC_OUTLSYMB].Value <<= maOptions.GetOption(VOPT_OUTLINER);
     pSettings[SC_VALUE_HIGHLIGHTING].Name = SC_UNO_VALUEHIGH;
     pSettings[SC_VALUE_HIGHLIGHTING].Value <<= 
maOptions.GetOption(VOPT_SYNTAX);
+    pSettings[SC_FORMULA_BAR_HEIGHT_VALUE].Name = SC_FORMULABARHEIGHT;
+    pSettings[SC_FORMULA_BAR_HEIGHT_VALUE].Value <<= GetFormulaBarLines();;
 
     const ScGridOptions& aGridOpt = maOptions.GetGridOptions();
     pSettings[SC_SNAPTORASTER].Name = SC_UNO_SNAPTORASTER;
@@ -3791,6 +3796,7 @@ void ScViewData::ReadUserDataSequence(const uno::Sequence 
<beans::PropertyValue>
 
     sal_Int32 nTemp32(0);
     sal_Int16 nTemp16(0);
+    sal_Int16 nFormulaBarLineCount(0);
     bool bPageMode(false);
 
     EnsureTabDataSize(GetDocument().GetTableCount());
@@ -3868,6 +3874,21 @@ void ScViewData::ReadUserDataSequence(const 
uno::Sequence <beans::PropertyValue>
                 aDefPageZoomX = aDefPageZoomY = aZoom;
             }
         }
+        else if (sName == SC_FORMULABARHEIGHT)
+        {
+            if (rSetting.Value >>= nFormulaBarLineCount)
+            {
+                SetFormulaBarLines(nFormulaBarLineCount);
+                // Notify formula bar about changed lines
+                ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
+                if (pInputHdl)
+                {
+                    ScInputWindow* pInputWin = pInputHdl->GetInputWindow();
+                    if (pInputWin)
+                        pInputWin->NumLinesChanged();
+                }
+            }
+        }
         else if (sName == SC_SHOWPAGEBREAKPREVIEW)
             bPageMode = ScUnoHelpFunctions::GetBoolFromAny( rSetting.Value );
         else if ( sName == SC_UNO_SHOWZERO )
diff --git a/test/source/sheet/spreadsheetviewsettings.cxx 
b/test/source/sheet/spreadsheetviewsettings.cxx
index b77bcb4c6921..1a5916dcfe39 100644
--- a/test/source/sheet/spreadsheetviewsettings.cxx
+++ b/test/source/sheet/spreadsheetviewsettings.cxx
@@ -235,6 +235,16 @@ void 
SpreadsheetViewSettings::testSpreadsheetViewSettingsProperties()
     xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue);
     CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= 
aZoomValue);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ZoomValue", 
sal_Int16(1), aZoomValue);
+
+    propName = "FormulaBarHeight";
+    sal_Int16 aFormulaBarHeight;
+    CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= 
aFormulaBarHeight);
+
+    aNewValue <<= sal_Int16(15);
+    xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue);
+    CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= 
aFormulaBarHeight);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue 
FormulaBarHeight", sal_Int16(15),
+                                 aFormulaBarHeight);
 }
 }
 

Reply via email to