sc/source/ui/view/viewfunc.cxx |   29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

New commits:
commit 9494b7d3602aeccec0e434219c71a8b0223dfe82
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sun May 21 21:18:58 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon May 22 14:08:39 2023 +0200

    tdf#155368 Can't toggle Wrap Text on all cells if cell already has
    
    The problem is not so much that we cannot toggle, it is that we
    cannot unset a toggle property.
    And the reason for that, is that the state of the toggle never
    goes off because the view state as computed by
    ScViewFunc::GetSelectionPattern is different
    from the state that is seen in ScViewFunc::ApplySelectionPattern
    where we apply the pattern.
    
    So make the same shrink-data-area adjustment in GetSelectionPattern.
    
    Change-Id: Ic56145ee98ead931278767851f74e0ce7422a150
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152074
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    (cherry picked from commit 8cc51cf9886a1e2f185c3824b71c960c08a9bf2e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152092
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 6e15f9b3e0f8..b5953bbf26f0 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -904,17 +904,25 @@ SvtScriptType ScViewFunc::GetSelectionScriptType()
     return nScript;
 }
 
+static void ShrinkToDataArea(ScMarkData& rFuncMark, ScDocument& rDoc);
+
 const ScPatternAttr* ScViewFunc::GetSelectionPattern()
 {
     // Don't use UnmarkFiltered in slot state functions, for performance 
reasons.
     // The displayed state is always that of the whole selection including 
filtered rows.
 
-    const ScMarkData& rMark = GetViewData().GetMarkData();
+    ScMarkData aMark = GetViewData().GetMarkData();
     ScDocument& rDoc = GetViewData().GetDocument();
-    if ( rMark.IsMarked() || rMark.IsMultiMarked() )
+
+    // tdf#155368 if the selection is the whole sheet, we need to shrink the 
mark area, otherwise
+    // we will not return a consistent result
+    // (consistent compared to what happens in 
ScViewFunc::ApplySelectionPattern)
+    ShrinkToDataArea( aMark, rDoc );
+
+    if ( aMark.IsMarked() || aMark.IsMultiMarked() )
     {
         //  MarkToMulti is no longer necessary for rDoc.GetSelectionPattern
-        const ScPatternAttr* pAttr = rDoc.GetSelectionPattern( rMark );
+        const ScPatternAttr* pAttr = rDoc.GetSelectionPattern( aMark );
         return pAttr;
     }
     else
@@ -923,9 +931,9 @@ const ScPatternAttr* ScViewFunc::GetSelectionPattern()
         SCROW  nRow = GetViewData().GetCurY();
         SCTAB  nTab = GetViewData().GetTabNo();
 
-        ScMarkData aTempMark( rMark );      // copy sheet selection
-        aTempMark.SetMarkArea( ScRange( nCol, nRow, nTab ) );
-        const ScPatternAttr* pAttr = rDoc.GetSelectionPattern( aTempMark );
+        // copy sheet selection
+        aMark.SetMarkArea( ScRange( nCol, nRow, nTab ) );
+        const ScPatternAttr* pAttr = rDoc.GetSelectionPattern( aMark );
         return pAttr;
     }
 }
@@ -1181,11 +1189,14 @@ void ScViewFunc::ApplyPatternLines( const 
ScPatternAttr& rAttr, const SvxBoxItem
     StartFormatArea();
 }
 
+// tdf#147842 if the marked area is the entire sheet, then shrink it to the 
data area.
+// Otherwise ctrl-A, perform-action, will take a very long time as it tries to 
modify
+// cells that we are not using.
 static void ShrinkToDataArea(ScMarkData& rFuncMark, ScDocument& rDoc)
 {
-    // tdf#147842 if the marked area is the entire sheet, then shrink it to 
the data area.
-    // Otherwise ctrl-A, perform-action, will take a very long time as it 
tries to modify
-    // cells then we are not using.
+    // do not make it marked if it is not already marked
+    if (!rFuncMark.IsMarked())
+        return;
     if (rFuncMark.IsMultiMarked())
         return;
     ScRange aMarkArea = rFuncMark.GetMarkArea();

Reply via email to