forms/source/component/ListBox.cxx |    2 +-
 svx/source/fmcomp/gridcell.cxx     |    6 ++++--
 toolkit/source/awt/vclxwindows.cxx |    6 ++++--
 3 files changed, 9 insertions(+), 5 deletions(-)

New commits:
commit b938c891e1b74c887ff1a849576965e5462c6287
Author:     Noel Grandin <[email protected]>
AuthorDate: Fri Nov 29 15:29:08 2024 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Nov 29 18:46:26 2024 +0100

    fix various getSelectedItemPos implementations
    
    clearly we do not often have combobox's that have nothing selected,
    otherwise these issues would have arisen sooner.
    
    The immediate cause of fixing this was the assert
    VCLXListBox::getSelectedItemPos which was triggered when using X-ray to
    examine a writer document
    
    Change-Id: Ia5ec713ef54a841010a9b680d4520f7160d48167
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177532
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/forms/source/component/ListBox.cxx 
b/forms/source/component/ListBox.cxx
index 1b54c674ef99..3ff86a4eb189 100644
--- a/forms/source/component/ListBox.cxx
+++ b/forms/source/component/ListBox.cxx
@@ -2097,7 +2097,7 @@ namespace frm
     {
         if ( m_xAggregateListBox.is() )
             return m_xAggregateListBox->getSelectedItemPos();
-        return 0;
+        return -1;
     }
 
 
diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx
index 49f87218cebd..d43351da912a 100644
--- a/svx/source/fmcomp/gridcell.cxx
+++ b/svx/source/fmcomp/gridcell.cxx
@@ -4138,12 +4138,14 @@ sal_Int16 SAL_CALL FmXListBoxCell::getSelectedItemPos()
     {
         UpdateFromColumn();
         weld::ComboBox& rBox = m_pBox->get_widget();
-        sal_Int32 nPos = rBox.get_active();
+        int nPos = rBox.get_active();
+        if (nPos == -1)
+            return -1; // nothing selected
         if (nPos > SHRT_MAX || nPos < SHRT_MIN)
             throw std::out_of_range("awt::XListBox::getSelectedItemPos can 
only return a short");
         return nPos;
     }
-    return 0;
+    return -1; // nothing selected
 }
 
 Sequence< sal_Int16 > SAL_CALL FmXListBoxCell::getSelectedItemsPos()
diff --git a/toolkit/source/awt/vclxwindows.cxx 
b/toolkit/source/awt/vclxwindows.cxx
index 2c01afaed699..ab98b6f52592 100644
--- a/toolkit/source/awt/vclxwindows.cxx
+++ b/toolkit/source/awt/vclxwindows.cxx
@@ -1573,9 +1573,11 @@ sal_Int16 VCLXListBox::getSelectedItemPos()
     SolarMutexGuard aGuard;
     VclPtr< ListBox > pBox = GetAs< ListBox >();
     if (!pBox)
-        return 0;
+        return -1; // nothing selected
     sal_Int32 nPos = pBox->GetSelectedEntryPos();
-    assert(nPos <= SAL_MAX_INT16);
+    if (nPos == LISTBOX_ENTRY_NOTFOUND)
+        return -1; // nothing selected
+    assert(nPos <= SAL_MAX_INT16 && "nPos is out of the range we can 
represent");
     return nPos;
 }
 

Reply via email to