sc/source/ui/view/gridwin.cxx    |    2 
 sc/source/ui/view/select.cxx     |  106 ++++++++++++++++++++++++++++++---------
 sc/source/ui/view/tableshell.cxx |   17 ++++--
 3 files changed, 97 insertions(+), 28 deletions(-)

New commits:
commit 81337418cf7d421449dd0b00c10178eea32f9e8d
Author:     Balazs Varga <[email protected]>
AuthorDate: Wed Oct 22 12:51:47 2025 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Nov 17 19:02:04 2025 +0100

    Implement the database range behaviour by using similar
    
    (but not the same) algorytm as ScFillMode::FILL, therefore
    we can only expand a DBRange in one direction at a time
    (same as in MSO). In case of an outside range the first Column
    or first two ( because of header/total row) will be selected.
    Also (will) simplify a bit the undo/redo parts.
    
    Also use PointerStyle::SESize instead of PointerStyle::Cross.
    
    cherry-pick from: 7db1fff2a3f8a7841f890dd0a6d68b154cc016a4
    
    Change-Id: Ia4ba85494f9b7824118f68277a59156e6ea2a036
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192839
    Reviewed-by: Balazs Varga <[email protected]>
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193677
    Tested-by: Andras Timar <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index d85723ea7ec6..553cd12236f4 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -1770,7 +1770,7 @@ bool ScGridWindow::TestMouse( const MouseEvent& rMEvt, 
bool bAction )
                 }
                 else if (mpDBExpandRect && mpDBExpandRect->Contains(aMousePos))
                 {
-                    SetPointer( PointerStyle::Cross );     //! bold cross ?
+                    SetPointer( PointerStyle::SESize );
                     if (bAction)
                     {
                         SCCOL nX = maDBRange.aEnd.Col();
diff --git a/sc/source/ui/view/select.cxx b/sc/source/ui/view/select.cxx
index 612a04c9c0e8..56dc3fe7cb5f 100644
--- a/sc/source/ui/view/select.cxx
+++ b/sc/source/ui/view/select.cxx
@@ -627,38 +627,98 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, 
SCROW nPosY, bool bScroll
     }
     else if (m_pViewData->IsDBExpandMode())
     {
-        SCCOL nFillColStart;
-        SCROW nFillRowStart;
-        SCCOL nFillColEnd;
-        SCROW nFillRowEnd;
-        m_pViewData->GetFillData(nFillColStart, nFillRowStart, nFillColEnd, 
nFillRowEnd);
-
-        bool bNegX = ( nPosX < nFillColStart );
-        bool bNegY = ( nPosY < nFillRowStart );
+        SCCOL nStartX, nEndX;
+        SCROW nStartY, nEndY;
+        m_pViewData->GetFillData(nStartX, nStartY, nEndX, nEndY);
 
-        if ( bNegX )
+        if (m_pViewData->GetRefType() != SC_REFTYPE_FILL)
         {
-            //  in SetCursorAtPoint hidden columns are skipped.
-            //  They must be skipped here too, or the result will always be 
the first hidden column.
-            while ( nPosX<nFillColStart && rDoc.ColHidden(nPosX, nTab) ) 
++nPosX;
+            pView->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
+            CreateAnchor();
         }
 
-        if ( bNegY )
+        if ( nPosX >= nStartX && nPosX <= nEndX &&
+             nPosY >= nStartY && nPosY <= nEndY &&
+             ( nPosX != nEndX || nPosY != nEndY ) )
         {
-            //  in SetCursorAtPoint hidden rows are skipped.
-            //  They must be skipped here too, or the result will always be 
the first hidden row.
-            if (nPosY < nFillRowStart)
+            // inside
+            tools::Long nSizeX = 0;
+            for (SCCOL i = nPosX + 1; i <= nEndX; i++)
+                nSizeX += rDoc.GetColWidth(i, nTab);
+            tools::Long nSizeY = rDoc.GetRowHeight(nPosY + 1, nEndY, nTab);
+
+            if (nSizeX > nSizeY)
             {
-                nPosY = rDoc.FirstVisibleRow(nPosY, nFillRowStart-1, nTab);
-                if (!rDoc.ValidRow(nPosY))
-                    nPosY = nFillRowStart;
+                nPosY = nEndY;
+            }
+            else
+            {
+                nPosX = nEndX;
             }
-        }
 
-        if ( nFillColStart != m_pViewData->GetRefStartX() || nFillRowStart != 
m_pViewData->GetRefStartY() )
+            // Header row or first row
+            if (nPosY == nStartY)
+                nPosY++;
+
+            if ( nStartX != m_pViewData->GetRefStartX() || nStartY != 
m_pViewData->GetRefStartY() )
+            {
+                m_pViewData->GetView()->DoneRefMode();
+                m_pViewData->GetView()->InitRefMode( nStartX, nStartY, nTab, 
SC_REFTYPE_FILL );
+            }
+        }
+        else
         {
-            m_pViewData->GetView()->DoneRefMode();
-            m_pViewData->GetView()->InitRefMode( nFillColStart, nFillRowStart, 
nTab, SC_REFTYPE_FILL );
+            // outside
+            bool bNegX = ( nPosX < nStartX );
+            bool bNegY = ( nPosY < nStartY );
+
+            tools::Long nSizeX = 0;
+            if ( bNegX )
+            {
+                //  in SetCursorAtPoint hidden columns are skipped.
+                //  They must be skipped here too, or the result will always 
be the first hidden column.
+                do ++nPosX; while ( nPosX<nStartX && rDoc.ColHidden(nPosX, 
nTab) );
+                for (SCCOL i=nPosX; i<nStartX; i++)
+                    nSizeX += rDoc.GetColWidth( i, nTab );
+            }
+            else
+                for (SCCOL i=nEndX+1; i<=nPosX; i++)
+                    nSizeX += rDoc.GetColWidth( i, nTab );
+
+            tools::Long nSizeY = 0;
+            if ( bNegY )
+            {
+                //  in SetCursorAtPoint hidden rows are skipped.
+                //  They must be skipped here too, or the result will always 
be the first hidden row.
+                if (++nPosY < nStartY)
+                {
+                    nPosY = rDoc.FirstVisibleRow(nPosY, nStartY-1, nTab);
+                    if (!rDoc.ValidRow(nPosY))
+                        nPosY = nStartY;
+                }
+                nSizeY += rDoc.GetRowHeight( nPosY, nStartY-1, nTab );
+            }
+            else
+                nSizeY += rDoc.GetRowHeight( nEndY+1, nPosY, nTab );
+
+            if ( nSizeX > nSizeY ) // Fill only ever in one direction
+            {
+                nPosY = nEndY;
+                bNegY = false;
+            }
+            else
+            {
+                nPosX = nEndX;
+                bNegX = false;
+            }
+
+            nPosX = bNegX ? nStartX : nPosX;
+            nPosY = bNegY ? nStartY + 1 : nPosY; // Header row or first row
+            if ( nStartX != m_pViewData->GetRefStartX() || nStartY != 
m_pViewData->GetRefStartY() )
+            {
+                m_pViewData->GetView()->DoneRefMode();
+                m_pViewData->GetView()->InitRefMode( nStartX, nStartY, nTab, 
SC_REFTYPE_FILL );
+            }
         }
 
         pView->UpdateRef( nPosX, nPosY, nTab );
commit d6b7227dc302c75ad045e0e9079a747ef378c17c
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Oct 16 08:27:37 2025 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Nov 17 19:01:49 2025 +0100

    Fix crash when we select a normal dbrange without table style
    
    Change-Id: I16c635c243aa2a32f8291836be957f78a146601c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192472
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193676
    Tested-by: Andras Timar <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>

diff --git a/sc/source/ui/view/tableshell.cxx b/sc/source/ui/view/tableshell.cxx
index 8fc525e1d5a1..c7ff2c881666 100644
--- a/sc/source/ui/view/tableshell.cxx
+++ b/sc/source/ui/view/tableshell.cxx
@@ -114,10 +114,19 @@ void ScTableShell::GetDatabaseSettings(SfxItemSet& rSet)
                 if (pDBData)
                 {
                     const ScTableStyleParam* pParam = 
pDBData->GetTableStyleInfo();
-                    rSet.Put(ScDatabaseSettingItem(pDBData->HasHeader(), 
pDBData->HasTotals(),
-                                                   pParam->mbFirstColumn, 
pParam->mbLastColumn,
-                                                   pParam->mbRowStripes, 
pParam->mbColumnStripes,
-                                                   pDBData->HasAutoFilter()));
+                    if (pParam)
+                    {
+                        rSet.Put(ScDatabaseSettingItem(
+                            pDBData->HasHeader(), pDBData->HasTotals(), 
pParam->mbFirstColumn,
+                            pParam->mbLastColumn, pParam->mbRowStripes, 
pParam->mbColumnStripes,
+                            pDBData->HasAutoFilter()));
+                    }
+                    else
+                    {
+                        rSet.Put(ScDatabaseSettingItem(pDBData->HasHeader(), 
pDBData->HasTotals(),
+                                                       false, false, false, 
false,
+                                                       
pDBData->HasAutoFilter()));
+                    }
                 }
                 break;
         }

Reply via email to