update ooo310-m15
[ooovba.git] / applied_patches / 0536-calc-autofilter-shrink-selection.diff
blob015ec6a4bfea92ff82807787e5694d798ce60155
1 diff --git sc/inc/document.hxx sc/inc/document.hxx
2 index fe64a22..862682c 100644
3 --- sc/inc/document.hxx
4 +++ sc/inc/document.hxx
5 @@ -880,6 +880,8 @@ public:
7 USHORT GetErrCode( const ScAddress& ) const;
9 + bool ShrinkToDataArea(SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow) const;
11 void GetDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow,
12 SCCOL& rEndCol, SCROW& rEndRow, BOOL bIncludeOld ) const;
13 SC_DLLPUBLIC BOOL GetCellArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const;
14 diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
15 index ea3f282..c69dc5c 100644
16 --- sc/source/core/data/document.cxx
17 +++ sc/source/core/data/document.cxx
18 @@ -642,6 +642,32 @@ BOOL ScDocument::GetTableArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) cons
19 return FALSE;
22 +bool ScDocument::ShrinkToDataArea(SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow) const
24 + if (!ValidTab(nTab) || !pTab[nTab])
25 + return false;
27 + SCCOL nCol1, nCol2;
28 + SCROW nRow1, nRow2;
29 + pTab[nTab]->GetFirstDataPos(nCol1, nRow1);
30 + pTab[nTab]->GetLastDataPos(nCol2, nRow2);
32 + if (nCol1 > nCol2 || nRow1 > nRow2)
33 + // invalid range.
34 + return false;
36 + // Make sure the area only shrinks, and doesn't grow.
37 + if (rStartCol < nCol1)
38 + rStartCol = nCol1;
39 + if (nCol2 < rEndCol)
40 + rEndCol = nCol2;
41 + if (rStartRow < nRow1)
42 + rStartRow = nRow1;
43 + if (nRow2 < rEndRow)
44 + rEndRow = nRow2;
46 + return true; // success!
49 // zusammenhaengender Bereich
51 diff --git sc/source/core/data/table2.cxx sc/source/core/data/table2.cxx
52 index 4274be7..7907caa 100644
53 --- sc/source/core/data/table2.cxx
54 +++ sc/source/core/data/table2.cxx
55 @@ -978,6 +978,9 @@ void ScTable::GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const
57 rCol = 0;
58 rRow = 0;
59 + while (aCol[rCol].IsEmptyData() && rCol < MAXCOL)
60 + ++rCol;
61 + rRow = aCol[rCol].GetFirstDataPos();
64 void ScTable::GetLastDataPos(SCCOL& rCol, SCROW& rRow) const
65 diff --git sc/source/ui/inc/dbfunc.hxx sc/source/ui/inc/dbfunc.hxx
66 index 3f25558..8dfafd9 100644
67 --- sc/source/ui/inc/dbfunc.hxx
68 +++ sc/source/ui/inc/dbfunc.hxx
69 @@ -80,7 +80,7 @@ public:
70 void GotoDBArea( const String& rDBName );
72 // DB-Bereich vom Cursor
73 - ScDBData* GetDBData( bool bMarkArea = true, ScGetDBMode eMode = SC_DB_MAKE, bool bExpandRows = false );
74 + ScDBData* GetDBData( bool bMarkArea = true, ScGetDBMode eMode = SC_DB_MAKE, bool bExpandRows = false, bool bShrinkToData = false );
76 void NotifyCloseDbNameDlg( const ScDBCollection& rNewColl, const List& rDelAreaList );
78 diff --git sc/source/ui/view/dbfunc.cxx sc/source/ui/view/dbfunc.cxx
79 index b985912..ce3dede 100644
80 --- sc/source/ui/view/dbfunc.cxx
81 +++ sc/source/ui/view/dbfunc.cxx
82 @@ -108,13 +108,29 @@ void ScDBFunc::GotoDBArea( const String& rDBName )
84 // aktuellen Datenbereich fuer Sortieren / Filtern suchen
86 -ScDBData* ScDBFunc::GetDBData( bool bMark, ScGetDBMode eMode, bool bExpandRows )
87 +ScDBData* ScDBFunc::GetDBData( bool bMark, ScGetDBMode eMode, bool bExpandRows, bool bShrinkToData )
89 ScDocShell* pDocSh = GetViewData()->GetDocShell();
90 ScDBData* pData = NULL;
91 ScRange aRange;
92 if ( GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE )
93 + {
94 + if (bShrinkToData)
95 + {
96 + // Shrink the range to only include data area.
97 + ScDocument* pDoc = pDocSh->GetDocument();
98 + SCCOL nCol1 = aRange.aStart.Col(), nCol2 = aRange.aEnd.Col();
99 + SCROW nRow1 = aRange.aStart.Row(), nRow2 = aRange.aEnd.Row();
100 + if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nCol1, nRow1, nCol2, nRow2))
102 + aRange.aStart.SetCol(nCol1);
103 + aRange.aEnd.SetCol(nCol2);
104 + aRange.aStart.SetRow(nRow1);
105 + aRange.aEnd.SetRow(nRow2);
108 pData = pDocSh->GetDBData( aRange, eMode, FALSE );
110 else if ( eMode != SC_DB_OLD )
111 pData = pDocSh->GetDBData(
112 ScRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(),
113 @@ -286,7 +302,7 @@ void ScDBFunc::ToggleAutoFilter()
115 ScQueryParam aParam;
116 ScDocument* pDoc = GetViewData()->GetDocument();
117 - ScDBData* pDBData = GetDBData( FALSE );
118 + ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, false, true);
120 pDBData->SetByRow( TRUE ); //! Undo, vorher abfragen ??
121 pDBData->GetQueryParam( aParam );