[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/inc sc/source

Katarina Machalkova bubli at kemper.freedesktop.org
Tue Apr 12 15:05:08 PDT 2011


 sc/inc/dbcolect.hxx              |    2 
 sc/inc/document.hxx              |    2 
 sc/inc/table.hxx                 |    1 
 sc/source/core/data/documen3.cxx |    8 +
 sc/source/core/data/table2.cxx   |   14 ++
 sc/source/core/data/table4.cxx   |  263 ++++++++++++++++++++++-----------------
 sc/source/core/tool/dbcolect.cxx |   21 +++
 7 files changed, 202 insertions(+), 109 deletions(-)

New commits:
commit 8d2c113480e47de7d556b693fe6354a5734dbeef
Author: Katarina Machalkova <kmachalkova at suse.cz>
Date:   Tue Apr 12 23:50:03 2011 +0200

    fdo#35345: Don't overwrite hidden cells in drag-fill operation
    
    Also i#89232. Extracting relevant parts from 'calc66' CWS

diff --git a/sc/inc/dbcolect.hxx b/sc/inc/dbcolect.hxx
index 3c60675..c0e36f2 100644
--- a/sc/inc/dbcolect.hxx
+++ b/sc/inc/dbcolect.hxx
@@ -44,6 +44,7 @@ class ScDocument;
 
 class ScDBData : public ScDataObject, public ScRefreshTimer
 {
+friend class ScDBCollection;
 private:
     // DBParam
     String			aName;
@@ -214,6 +215,7 @@ public:
     virtual	sal_Bool		IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
             ScDBData*	GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
             ScDBData*	GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
+            ScDBData*   GetFilterDBAtTable(SCTAB nTab) const;
             ScDBData*   GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab );
 
     sal_Bool	SearchName( const String& rName, sal_uInt16& rIndex ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 8f793e8..b58782c 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -484,6 +484,8 @@ public:
     ScDBData*		GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab,
                                         sal_Bool bStartOnly = false) const;
     ScDBData*		GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
+    ScDBData*       GetFilterDBAtTable(SCTAB nTab) const;
+
 
     SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, String* pName=NULL ) const;
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index b41c179..5df9875 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -690,6 +690,7 @@ public:
                 /// @return  the index of the last changed row (flags and row height, auto pagebreak is ignored).
     SCROW      GetLastChangedRow() const;
 
+    sal_Bool            IsDataFiltered() const;
     sal_uInt8		GetColFlags( SCCOL nCol ) const;
     sal_uInt8		GetRowFlags( SCROW nRow ) const;
 
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index e82abc2..a57a1d3 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -238,6 +238,14 @@ ScDBData* ScDocument::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nC
         return NULL;
 }
 
+ScDBData* ScDocument::GetFilterDBAtTable(SCTAB nTab) const
+{
+    if (pDBCollection)
+        return pDBCollection->GetFilterDBAtTable(nTab);
+    else
+    return NULL;
+}
+
 ScDPCollection* ScDocument::GetDPCollection()
 {
     if (!pDPCollection)
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index b59270d..141e221 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2628,6 +2628,20 @@ void ScTable::ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
     DecRecalcLevel();
 }
 
+sal_Bool ScTable::IsDataFiltered() const
+{
+    sal_Bool bAnyQuery = sal_False;
+    ScDBData* pDBData = pDocument->GetFilterDBAtTable(nTab);
+    if ( pDBData )
+    {
+    ScQueryParam aParam;
+    pDBData->GetQueryParam( aParam );
+    if ( aParam.GetEntry(0).bDoQuery )
+        bAnyQuery = sal_True;
+    }
+    return bAnyQuery;
+}
+
 
 void ScTable::SetColFlags( SCCOL nCol, sal_uInt8 nNewFlags )
 {
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 0e46b14..4522130 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -79,6 +79,7 @@
 #include "rangenam.hxx"
 #include "docpool.hxx"
 #include "progress.hxx"
+#include "segmenttree.hxx"
 
 #include <math.h>
 
@@ -199,7 +200,7 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
     rMinDigits = 0;
     rListData = NULL;
     rCmd = FILL_SIMPLE;
-    if ( nScFillModeMouseModifier & KEY_MOD1 )
+    if ( (nScFillModeMouseModifier & KEY_MOD1) || IsDataFiltered() )
         return ;		// Ctrl-Taste: Copy
 
     SCCOL nAddX;
@@ -525,10 +526,15 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
     sal_uLong nIMin = nIStart;
     sal_uLong nIMax = nIEnd;
     PutInOrder(nIMin,nIMax);
-    if (bVertical)
-        DeleteArea(nCol1, static_cast<SCROW>(nIMin), nCol2, static_cast<SCROW>(nIMax), IDF_AUTOFILL);
-    else
-        DeleteArea(static_cast<SCCOL>(nIMin), nRow1, static_cast<SCCOL>(nIMax), nRow2, IDF_AUTOFILL);
+    sal_Bool bHasFiltered = IsDataFiltered();
+
+    if (!bHasFiltered)
+    {
+        if (bVertical)
+            DeleteArea(nCol1, static_cast<SCROW>(nIMin), nCol2, static_cast<SCROW>(nIMax), IDF_AUTOFILL);
+        else
+            DeleteArea(static_cast<SCCOL>(nIMin), nRow1, static_cast<SCCOL>(nIMax), nRow2, IDF_AUTOFILL);
+    }
 
     sal_uLong nProgress = rProgress.GetState();
 
@@ -575,7 +581,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                     pNewPattern = NULL;
             }
 
-            if ( bVertical && nISrcStart == nISrcEnd )
+            if ( bVertical && nISrcStart == nISrcEnd && !bHasFiltered )
             {
                 //	Attribute komplett am Stueck setzen
                 if (pNewPattern || pSrcPattern != pDocument->GetDefPattern())
@@ -593,37 +599,44 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                 break;		// Schleife abbrechen
             }
 
-            if ( pSrcPattern != aCol[nCol].GetPattern( static_cast<SCROW>(nRow) ) )
+            if (!RowFiltered( nRow ))
             {
-                //	Vorlage auch uebernehmen
-                //!	am AttrArray mit ApplyPattern zusammenfassen ??
-                if ( pStyleSheet )
-                    aCol[nCol].ApplyStyle( static_cast<SCROW>(nRow), *pStyleSheet );
+                if ( bHasFiltered )
+                    DeleteArea(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow),
+                               static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), IDF_AUTOFILL);
 
-                //	ApplyPattern statt SetPattern um alte MergeFlags stehenzulassen
-                if ( pNewPattern )
-                    aCol[nCol].ApplyPattern( static_cast<SCROW>(nRow), *pNewPattern );
-                else
-                    aCol[nCol].ApplyPattern( static_cast<SCROW>(nRow), *pSrcPattern );
-            }
+                if ( pSrcPattern != aCol[nCol].GetPattern( static_cast<SCROW>(nRow) ) )
+                {
+                    // Vorlage auch uebernehmen
+                    //! am AttrArray mit ApplyPattern zusammenfassen ??
+                    if ( pStyleSheet )
+                        aCol[nCol].ApplyStyle( static_cast<SCROW>(nRow), *pStyleSheet );
 
-            if (nAtSrc==nISrcEnd)
-            {
-                if ( nAtSrc != nISrcStart )
-                {	// mehr als eine Source-Zelle
-                    nAtSrc = nISrcStart;
+                    //    ApplyPattern statt SetPattern um alte MergeFlags stehenzulassen
+                    if ( pNewPattern )
+                        aCol[nCol].ApplyPattern( static_cast<SCROW>(nRow), *pNewPattern );
+                    else
+                        aCol[nCol].ApplyPattern( static_cast<SCROW>(nRow), *pSrcPattern );
+                }
+
+                if (nAtSrc==nISrcEnd)
+                {
+                    if ( nAtSrc != nISrcStart )
+                    {    // mehr als eine Source-Zelle
+                        nAtSrc = nISrcStart;
+                        bGetPattern = sal_True;
+                    }
+                }
+                else if (bPositive)
+                {
+                    ++nAtSrc;
+                    bGetPattern = sal_True;
+                }
+                else
+                {
+                    --nAtSrc;
                     bGetPattern = sal_True;
                 }
-            }
-            else if (bPositive)
-            {
-                ++nAtSrc;
-                bGetPattern = sal_True;
-            }
-            else
-            {
-                --nAtSrc;
-                bGetPattern = sal_True;
             }
 
             if (rInner == nIEnd) break;
@@ -691,7 +704,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
         {
             sal_uLong nSource = nISrcStart;
             double nDelta;
-            if ( nScFillModeMouseModifier & KEY_MOD1 )
+            if ( (nScFillModeMouseModifier & KEY_MOD1) || bHasFiltered )
                 nDelta = 0.0;
             else if ( bPositive )
                 nDelta = 1.0;
@@ -708,6 +721,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
             ScBaseCell* pSrcCell = NULL;
             CellType eCellType = CELLTYPE_NONE;
             sal_Bool bIsOrdinalSuffix = false;
+            sal_Bool bRowFiltered = false;
 
             rInner = nIStart;
             while (true)        // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
@@ -733,7 +747,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                                     ((ScStringCell*)pSrcCell)->GetString( aValue );
                                 else
                                     ((ScEditCell*)pSrcCell)->GetString( aValue );
-                                if ( !(nScFillModeMouseModifier & KEY_MOD1) )
+                                if ( !(nScFillModeMouseModifier & KEY_MOD1) && !bHasFiltered )
                                 {
                                     nCellDigits = 0;	// look at each source cell individually
                                     nHeadNoneTail = lcl_DecompValueString(
@@ -752,94 +766,103 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                     else
                         eCellType = CELLTYPE_NONE;
                 }
-                switch (eCellType)
-                {
-                    case CELLTYPE_VALUE:
-                        aCol[nCol].Insert(static_cast<SCROW>(nRow), new ScValueCell(nVal + nDelta));
-                        break;
-                    case CELLTYPE_STRING:
-                    case CELLTYPE_EDIT:
-                        if ( nHeadNoneTail )
-                        {
-                            // #i48009# with the "nStringValue+(long)nDelta" expression within the
-                            // lcl_ValueString calls, gcc 3.4.1 makes wrong optimizations (ok in 3.4.3),
-                            // so nNextValue is now calculated ahead.
-                            sal_Int32 nNextValue = nStringValue+(sal_Int32)nDelta;
 
-                            String aStr;
-                            if ( nHeadNoneTail < 0 )
+                bRowFiltered = mpFilteredRows->getValue(nRow);
+
+         if (!bRowFiltered)
+         {
+                    switch (eCellType)
+                    {
+                        case CELLTYPE_VALUE:
+                            aCol[nCol].Insert(static_cast<SCROW>(nRow), new ScValueCell(nVal + nDelta));
+                            break;
+                        case CELLTYPE_STRING:
+                        case CELLTYPE_EDIT:
+                            if ( nHeadNoneTail )
                             {
-                                aCol[nCol].Insert( static_cast<SCROW>(nRow),
-                                        lcl_getSuffixCell( pDocument,
-                                            nNextValue, nCellDigits, aValue,
-                                            eCellType, bIsOrdinalSuffix));
+                                // #i48009# with the "nStringValue+(long)nDelta" expression within the
+                                // lcl_ValueString calls, gcc 3.4.1 makes wrong optimizations (ok in 3.4.3),
+                                // so nNextValue is now calculated ahead.
+                                sal_Int32 nNextValue = nStringValue+(sal_Int32)nDelta;
+
+                                String aStr;
+                                if ( nHeadNoneTail < 0 )
+                                {
+                                    aCol[nCol].Insert( static_cast<SCROW>(nRow),
+                                            lcl_getSuffixCell( pDocument,
+                                                nNextValue, nCellDigits, aValue,
+                                                eCellType, bIsOrdinalSuffix));
+                                }
+                                else
+                                {
+                                    aStr = aValue;
+                                    aStr += lcl_ValueString( nNextValue, nCellDigits );
+                                    aCol[nCol].Insert( static_cast<SCROW>(nRow),
+                                            new ScStringCell( aStr));
+                                }
                             }
                             else
                             {
-                                aStr = aValue;
-                                aStr += lcl_ValueString( nNextValue, nCellDigits );
-                                aCol[nCol].Insert( static_cast<SCROW>(nRow),
-                                        new ScStringCell( aStr));
-                            }
-                        }
-                        else
-                        {
-                            ScAddress aDestPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), nTab );
-                            switch ( eCellType )
-                            {
-                                case CELLTYPE_STRING:
-                                case CELLTYPE_EDIT:
-                                    aCol[nCol].Insert( aDestPos.Row(), pSrcCell->CloneWithoutNote( *pDocument ) );
-                                break;
-                                default:
+                                ScAddress aDestPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), nTab );
+                                switch ( eCellType )
                                 {
-                                    // added to avoid warnings
+                                    case CELLTYPE_STRING:
+                                    case CELLTYPE_EDIT:
+                                        aCol[nCol].Insert( aDestPos.Row(), pSrcCell->CloneWithoutNote( *pDocument ) );
+                                    break;
+                                    default:
+                                    {
+                                        // added to avoid warnings
+                                    }
                                 }
                             }
+                            break;
+                        case CELLTYPE_FORMULA :
+                            FillFormula( nFormulaCounter, bFirst,
+                                    (ScFormulaCell*) pSrcCell,
+                                    static_cast<SCCOL>(nCol),
+                                    static_cast<SCROW>(nRow), (rInner == nIEnd) );
+                            if (nFormulaCounter - nActFormCnt > nMaxFormCnt)
+                                nMaxFormCnt = nFormulaCounter - nActFormCnt;
+                            break;
+                        default:
+                        {
+                            // added to avoid warnings
                         }
-                        break;
-                    case CELLTYPE_FORMULA :
-                        FillFormula( nFormulaCounter, bFirst,
-                                (ScFormulaCell*) pSrcCell,
-                                static_cast<SCCOL>(nCol),
-                                static_cast<SCROW>(nRow), (rInner == nIEnd) );
-                        if (nFormulaCounter - nActFormCnt > nMaxFormCnt)
-                            nMaxFormCnt = nFormulaCounter - nActFormCnt;
-                        break;
-                    default:
-                    {
-                        // added to avoid warnings
                     }
-                }
 
-                if (nSource==nISrcEnd)
-                {
-                    if ( nSource != nISrcStart )
-                    {	// mehr als eine Source-Zelle
-                        nSource = nISrcStart;
+                    if (nSource==nISrcEnd)
+                    {
+                        if ( nSource != nISrcStart )
+                        {   // mehr als eine Source-Zelle
+                            nSource = nISrcStart;
+                            bGetCell = sal_True;
+                        }
+                        if ( !(nScFillModeMouseModifier & KEY_MOD1) && !bHasFiltered )
+                        {
+                            if ( bPositive )
+                                nDelta += 1.0;
+                            else
+                                nDelta -= 1.0;
+                        }
+                        nFormulaCounter = nActFormCnt;
+                        bFirst = false;
+                    }
+                    else if (bPositive)
+                    {
+                        ++nSource;
                         bGetCell = sal_True;
                     }
-                    if ( !(nScFillModeMouseModifier & KEY_MOD1) )
+                    else
                     {
-                        if ( bPositive )
-                            nDelta += 1.0;
-                        else
-                            nDelta -= 1.0;
+                        --nSource;
+                        bGetCell = sal_True;
                     }
-                    nFormulaCounter = nActFormCnt;
-                    bFirst = false;
-                }
-                else if (bPositive)
-                {
-                    ++nSource;
-                    bGetCell = sal_True;
-                }
-                else
-                {
-                    --nSource;
-                    bGetCell = sal_True;
                 }
 
+                if (rInner == nIEnd) break;
+                if (bPositive) ++rInner; else --rInner;
+
                 //	Progress in der inneren Schleife nur bei teuren Zellen,
                 //	und auch dann nicht fuer jede einzelne
 
@@ -847,8 +870,6 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                 if ( eCellType == CELLTYPE_FORMULA || eCellType == CELLTYPE_EDIT )
                     rProgress.SetStateOnPercent( nProgress );
 
-                if (rInner == nIEnd) break;
-                if (bPositive) ++rInner; else --rInner;
             }
             rProgress.SetStateOnPercent( nProgress );
         }
@@ -936,6 +957,30 @@ String ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW n
         }
         else if ( eFillCmd == FILL_SIMPLE )			// Auffuellen mit Muster
         {
+            if ((eFillDir == FILL_TO_BOTTOM)||(eFillDir == FILL_TO_TOP))
+          {
+          long nBegin = 0;
+          long nEnd = 0;
+          if (nEndY > nRow1)
+          {
+              nBegin = nRow2+1;
+              nEnd = nEndY;
+          }
+          else
+          {
+              nBegin = nEndY;
+              nEnd = nRow1 -1;
+          }
+
+                long nNonFiltered = CountNonFilteredRows(nBegin, nEnd);
+                long nFiltered = nEnd + 1 - nBegin - nNonFiltered;
+
+          if (nIndex >0)
+                    nIndex = nIndex - nFiltered;
+          else
+                    nIndex = nIndex + nFiltered;
+          }
+
             long nPosIndex = nIndex;
             while ( nPosIndex < 0 )
                 nPosIndex += nSrcCount;
@@ -966,7 +1011,7 @@ String ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW n
                             ((ScStringCell*)pCell)->GetString( aValue );
                         else
                             ((ScEditCell*)pCell)->GetString( aValue );
-                        if ( !(nScFillModeMouseModifier & KEY_MOD1) )
+                        if ( !(nScFillModeMouseModifier & KEY_MOD1) && !IsDataFiltered() )
                         {
                             sal_Int32 nVal;
                             sal_uInt16 nCellDigits = 0;	// look at each source cell individually
@@ -987,7 +1032,7 @@ String ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW n
                     {
                         //	dabei kann's keinen Ueberlauf geben...
                         double nVal = ((ScValueCell*)pCell)->GetValue();
-                        if ( !(nScFillModeMouseModifier & KEY_MOD1) )
+                        if ( !(nScFillModeMouseModifier & KEY_MOD1) && !IsDataFiltered() )
                             nVal += (double) nDelta;
 
                         Color* pColor;
diff --git a/sc/source/core/tool/dbcolect.cxx b/sc/source/core/tool/dbcolect.cxx
index 7c793df..bdb09ef 100644
--- a/sc/source/core/tool/dbcolect.cxx
+++ b/sc/source/core/tool/dbcolect.cxx
@@ -820,6 +820,27 @@ ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCO
     return NULL;	
 }
 
+ScDBData* ScDBCollection::GetFilterDBAtTable(SCTAB nTab) const
+{
+    ScDBData* pDataEmpty = NULL;
+    if (pItems)
+    {
+        for (sal_uInt16 i = 0; i < nCount; i++)
+        {
+            ScDBData* pDBTemp = (ScDBData*)pItems[i];
+            if ( pDBTemp->nTable == nTab )                        
+            {                
+                sal_Bool bFilter = pDBTemp->HasAutoFilter() || pDBTemp->HasQueryParam();              
+              
+                if ( bFilter )                 
+                    return pDBTemp;
+            }
+        }
+    }
+
+    return pDataEmpty;
+}
+
 sal_Bool ScDBCollection::SearchName( const String& rName, sal_uInt16& rIndex ) const
 {
     if (rtl::OUString(rName)==rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)))


More information about the Libreoffice-commits mailing list