cui/source/dialogs/cuicharmap.cxx    |    2 +
 cui/uiconfig/ui/specialcharacters.ui |    4 +-
 include/svx/searchcharmap.hxx        |    1 
 sc/source/core/tool/interpr1.cxx     |   63 ++++++++++++++++++++++++++++-------
 svx/source/dialog/searchcharmap.cxx  |   11 ++++--
 5 files changed, 65 insertions(+), 16 deletions(-)

New commits:
commit 01469641afde155efddf3c9b52e86b78a6056828
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Sun Mar 12 15:20:45 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Mar 19 14:20:44 2023 +0100

    Resolves: tdf#154125 Fix INDEX() one-dimensional vector access
    
    For i62850 a (not documented by Excel in
    
https://support.microsoft.com/en-us/office/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd?ui=en-us&rs=en-us&ad=us)
    one-dimensional vector's element access was implemented with
    non-sufficient conditions that prevented returning an entire
    vector. Later ODFF defined proper conditions for that, see
    
https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part4-formula/OpenDocument-v1.3-os-part4-formula.html#INDEX
    
    Also, that vector element case assumed vector replication to the
    other dimension as usual, which is not the case here, access to
    the other dimension's index >1 must return error.
    
    Change-Id: I604c2355f0aca2988cb13f0d4f54ccd2d74c3b0d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148736
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit df706f47a2b62248d222911db12c674e6507e5c6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148755
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 5673bb7ecda2..ac0fb22b6231 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -8674,10 +8674,17 @@ void ScInterpreter::ScIndex()
         nArea = GetUInt32();
     else
         nArea = 1;
+    bool bColMissing;
     if (nParamCount >= 3)
+    {
+        bColMissing = IsMissing();
         nCol = static_cast<SCCOL>(GetInt16());
+    }
     else
+    {
+        bColMissing = false;
         nCol = 0;
+    }
     if (nParamCount >= 2)
         nRow = static_cast<SCROW>(GetInt32());
     else
@@ -8710,25 +8717,57 @@ void ScInterpreter::ScIndex()
                 {
                     SCSIZE nC, nR;
                     pMat->GetDimensions(nC, nR);
+
                     // Access one element of a vector independent of col/row
-                    // orientation?
-                    bool bVector = ((nCol == 0 || nRow == 0) && (nC == 1 || nR 
== 1));
-                    SCSIZE nElement = ::std::max( static_cast<SCSIZE>(nCol),
-                            static_cast<SCSIZE>(nRow));
+                    // orientation. Excel documentation does not mention, but
+                    // i62850 had a .xls example of a row vector accessed by
+                    // row number returning one element. This
+                    // INDEX(row_vector;element) behaves the same as
+                    // INDEX(row_vector;0;element) and thus contradicts Excel
+                    // documentation where the second parameter is always
+                    // row_num.
+                    //
+                    // ODFF v1.3 in 6.14.6 INDEX states "If DataSource is a
+                    // one-dimensional row vector, Row is optional, which
+                    // effectively makes Row act as the column offset into the
+                    // vector". Guess the first Row is a typo and should read
+                    // Column instead.
+
+                    const bool bRowVectorSpecial = (nParamCount == 2 || 
bColMissing);
+                    const bool bRowVectorElement = (nR == 1 && (nCol != 0 || 
(bRowVectorSpecial && nRow != 0)));
+                    const bool bVectorElement = (bRowVectorElement || (nC == 1 
&& nRow != 0));
+
                     if (nC == 0 || nR == 0 ||
-                            (!bVector && (o3tl::make_unsigned(nCol) > nC ||
-                                          o3tl::make_unsigned(nRow) > nR)) ||
-                            (bVector && nElement > nC * nR))
+                            (!bVectorElement && (o3tl::make_unsigned(nCol) > 
nC ||
+                                                 o3tl::make_unsigned(nRow) > 
nR)))
                         PushIllegalArgument();
                     else if (nCol == 0 && nRow == 0)
                         sp = nOldSp;
-                    else if (bVector)
+                    else if (bVectorElement)
                     {
-                        --nElement;
-                        if (pMat->IsStringOrEmpty( nElement))
-                            PushString( pMat->GetString(nElement).getString());
+                        // Vectors here don't replicate to the other dimension.
+                        SCSIZE nElement, nOtherDimension;
+                        if (bRowVectorElement && !bRowVectorSpecial)
+                        {
+                            nElement = o3tl::make_unsigned(nCol);
+                            nOtherDimension = o3tl::make_unsigned(nRow);
+                        }
                         else
-                            PushDouble( pMat->GetDouble( nElement));
+                        {
+                            nElement = o3tl::make_unsigned(nRow);
+                            nOtherDimension = o3tl::make_unsigned(nCol);
+                        }
+
+                        if (nElement == 0 || nElement > nC * nR || 
nOtherDimension > 1)
+                            PushIllegalArgument();
+                        else
+                        {
+                            --nElement;
+                            if (pMat->IsStringOrEmpty( nElement))
+                                PushString( 
pMat->GetString(nElement).getString());
+                            else
+                                PushDouble( pMat->GetDouble( nElement));
+                        }
                     }
                     else if (nCol == 0)
                     {
commit 02d869d0bfe5be751286e7db6dfe9c89c6351313
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Fri Mar 10 11:13:17 2023 +0000
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Mar 19 14:20:44 2023 +0100

    Resolves: tdf#154087 update scrollbar range when search criteria change
    
    Change-Id: Iaf5f20c8952b15f3dcccb65277dadb171a705605
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148607
    Tested-by: Jenkins
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/cui/source/dialogs/cuicharmap.cxx 
b/cui/source/dialogs/cuicharmap.cxx
index 457b5238ccdd..c6994000e36d 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -885,6 +885,8 @@ IMPL_LINK_NOARG(SvxCharacterMap, SearchUpdateHdl, 
weld::Entry&, void)
             if(!sName.isEmpty() && 
sName.toAsciiLowerCase().indexOf(aKeyword.toAsciiLowerCase()) >= 0)
                 m_xSearchSet->AppendCharToList(sChar);
         }
+
+        m_xSearchSet->UpdateScrollRange();
     }
     else
     {
diff --git a/cui/uiconfig/ui/specialcharacters.ui 
b/cui/uiconfig/ui/specialcharacters.ui
index b8a7261f20af..a397c2e5762d 100644
--- a/cui/uiconfig/ui/specialcharacters.ui
+++ b/cui/uiconfig/ui/specialcharacters.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
 <interface domain="cui">
   <requires lib="gtk+" version="3.20"/>
   <object class="GtkDialog" id="SpecialCharactersDialog">
@@ -855,6 +855,8 @@
                     <property name="can-focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="vexpand">True</property>
+                    <property name="hscrollbar-policy">never</property>
+                    <property name="vscrollbar-policy">always</property>
                     <property name="shadow-type">in</property>
                     <child>
                       <object class="GtkViewport">
diff --git a/include/svx/searchcharmap.hxx b/include/svx/searchcharmap.hxx
index 33d7432096d8..1af4ce5fe1a6 100644
--- a/include/svx/searchcharmap.hxx
+++ b/include/svx/searchcharmap.hxx
@@ -50,6 +50,7 @@ public:
     virtual void                        SelectIndex( int index, bool bFocus = 
false ) override;
     void                                AppendCharToList(sal_UCS4 cChar);
     void                                ClearPreviousData();
+    void                                UpdateScrollRange();
 
     virtual sal_Int32                   getMaxCharCount() const override;
 
diff --git a/svx/source/dialog/searchcharmap.cxx 
b/svx/source/dialog/searchcharmap.cxx
index 034ebd317a5a..2d8eeaab8967 100644
--- a/svx/source/dialog/searchcharmap.cxx
+++ b/svx/source/dialog/searchcharmap.cxx
@@ -307,9 +307,7 @@ void SvxSearchCharSet::RecalculateFont(vcl::RenderContext& 
rRenderContext)
     nX = aSize.Width() / COLUMN_COUNT;
     nY = aSize.Height() / ROW_COUNT;
 
-    //scrollbar settings -- error
-    int nLastRow = (nCount - 1 + COLUMN_COUNT) / COLUMN_COUNT;
-    mxScrollArea->vadjustment_configure(mxScrollArea->vadjustment_get_value(), 
0, nLastRow, 1, ROW_COUNT - 1, ROW_COUNT);
+    UpdateScrollRange();
 
     // rearrange CharSet element in sync with nX- and nY-multiples
     Size aDrawSize(nX * COLUMN_COUNT, nY * ROW_COUNT);
@@ -319,6 +317,13 @@ void SvxSearchCharSet::RecalculateFont(vcl::RenderContext& 
rRenderContext)
     mbRecalculateFont = false;
 }
 
+void SvxSearchCharSet::UpdateScrollRange()
+{
+    //scrollbar settings
+    int nLastRow = (nCount - 1 + COLUMN_COUNT) / COLUMN_COUNT;
+    mxScrollArea->vadjustment_configure(mxScrollArea->vadjustment_get_value(), 
0, nLastRow, 1, ROW_COUNT - 1, ROW_COUNT);
+}
+
 void SvxSearchCharSet::SelectIndex(int nNewIndex, bool bFocus)
 {
     if (!mxFontCharMap.is())

Reply via email to