1b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5b3f79822SAndrew Rist * distributed with this work for additional information 6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14b3f79822SAndrew Rist * software distributed under the License is distributed on an 15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17b3f79822SAndrew Rist * specific language governing permissions and limitations 18b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20b3f79822SAndrew Rist *************************************************************/ 21b3f79822SAndrew Rist 22b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29cdf0e10cSrcweir // INCLUDE --------------------------------------------------------------- 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "scitems.hxx" 32cdf0e10cSrcweir #include <sfx2/app.hxx> 33cdf0e10cSrcweir #include <sfx2/bindings.hxx> 34cdf0e10cSrcweir #include <vcl/msgbox.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include "dbfunc.hxx" 39cdf0e10cSrcweir #include "docsh.hxx" 40cdf0e10cSrcweir #include "attrib.hxx" 41cdf0e10cSrcweir #include "sc.hrc" 42cdf0e10cSrcweir #include "undodat.hxx" 43cdf0e10cSrcweir #include "dbcolect.hxx" 44cdf0e10cSrcweir #include "globstr.hrc" 45cdf0e10cSrcweir #include "global.hxx" 46cdf0e10cSrcweir #include "dbdocfun.hxx" 47cdf0e10cSrcweir #include "editable.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir //================================================================== 50cdf0e10cSrcweir 51cdf0e10cSrcweir ScDBFunc::ScDBFunc( Window* pParent, ScDocShell& rDocSh, ScTabViewShell* pViewShell ) : 52cdf0e10cSrcweir ScViewFunc( pParent, rDocSh, pViewShell ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir //UNUSED2008-05 ScDBFunc::ScDBFunc( Window* pParent, const ScDBFunc& rDBFunc, ScTabViewShell* pViewShell ) : 57cdf0e10cSrcweir //UNUSED2008-05 ScViewFunc( pParent, rDBFunc, pViewShell ) 58cdf0e10cSrcweir //UNUSED2008-05 { 59cdf0e10cSrcweir //UNUSED2008-05 } 60cdf0e10cSrcweir 61cdf0e10cSrcweir ScDBFunc::~ScDBFunc() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // 66cdf0e10cSrcweir // Hilfsfunktionen 67cdf0e10cSrcweir // 68cdf0e10cSrcweir 69cdf0e10cSrcweir void ScDBFunc::GotoDBArea( const String& rDBName ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir ScDocument* pDoc = GetViewData()->GetDocument(); 72cdf0e10cSrcweir ScDBCollection* pDBCol = pDoc->GetDBCollection(); 73cdf0e10cSrcweir 74cdf0e10cSrcweir sal_uInt16 nFoundAt = 0; 75cdf0e10cSrcweir if ( pDBCol->SearchName( rDBName, nFoundAt ) ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir ScDBData* pData = (*pDBCol)[nFoundAt]; 78cdf0e10cSrcweir DBG_ASSERT( pData, "GotoDBArea: Datenbankbereich nicht gefunden!" ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir if ( pData ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir SCTAB nTab = 0; 83cdf0e10cSrcweir SCCOL nStartCol = 0; 84cdf0e10cSrcweir SCROW nStartRow = 0; 85cdf0e10cSrcweir SCCOL nEndCol = 0; 86cdf0e10cSrcweir SCROW nEndRow = 0; 87cdf0e10cSrcweir 88cdf0e10cSrcweir pData->GetArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow ); 89cdf0e10cSrcweir SetTabNo( nTab ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir MoveCursorAbs( nStartCol, nStartRow, ScFollowMode( SC_FOLLOW_JUMP ), 92cdf0e10cSrcweir sal_False, sal_False ); // bShift,bControl 93cdf0e10cSrcweir DoneBlockMode(); 94cdf0e10cSrcweir InitBlockMode( nStartCol, nStartRow, nTab ); 95cdf0e10cSrcweir MarkCursor( nEndCol, nEndRow, nTab ); 96cdf0e10cSrcweir SelectionChanged(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // aktuellen Datenbereich fuer Sortieren / Filtern suchen 102cdf0e10cSrcweir 103cdf0e10cSrcweir ScDBData* ScDBFunc::GetDBData( sal_Bool bMark, ScGetDBMode eMode, ScGetDBSelection eSel ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir ScDocShell* pDocSh = GetViewData()->GetDocShell(); 106cdf0e10cSrcweir ScDBData* pData = NULL; 107cdf0e10cSrcweir ScRange aRange; 108cdf0e10cSrcweir ScMarkType eMarkType = GetViewData()->GetSimpleArea(aRange); 109cdf0e10cSrcweir if ( eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir bool bShrinkColumnsOnly = false; 112cdf0e10cSrcweir if (eSel == SC_DBSEL_ROW_DOWN) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir // Don't alter row range, additional rows may have been selected on 115cdf0e10cSrcweir // purpose to append data, or to have a fake header row. 116cdf0e10cSrcweir bShrinkColumnsOnly = true; 117cdf0e10cSrcweir // Select further rows only if only one row or a portion thereof is 118cdf0e10cSrcweir // selected. 119cdf0e10cSrcweir if (aRange.aStart.Row() != aRange.aEnd.Row()) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir // If an area is selected shrink that to the actual used 122cdf0e10cSrcweir // columns, don't draw filter buttons for empty columns. 123cdf0e10cSrcweir eSel = SC_DBSEL_SHRINK_TO_USED_DATA; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else if (aRange.aStart.Col() == aRange.aEnd.Col()) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir // One cell only, if it is not marked obtain entire used data 128cdf0e10cSrcweir // area. 129cdf0e10cSrcweir const ScMarkData& rMarkData = GetViewData()->GetMarkData(); 130cdf0e10cSrcweir if (!(rMarkData.IsMarked() || rMarkData.IsMultiMarked())) 131cdf0e10cSrcweir eSel = SC_DBSEL_KEEP; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir switch (eSel) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir case SC_DBSEL_SHRINK_TO_SHEET_DATA: 137cdf0e10cSrcweir { 138cdf0e10cSrcweir // Shrink the selection to sheet data area. 139cdf0e10cSrcweir ScDocument* pDoc = pDocSh->GetDocument(); 140cdf0e10cSrcweir SCCOL nCol1 = aRange.aStart.Col(), nCol2 = aRange.aEnd.Col(); 141cdf0e10cSrcweir SCROW nRow1 = aRange.aStart.Row(), nRow2 = aRange.aEnd.Row(); 142cdf0e10cSrcweir if (pDoc->ShrinkToDataArea( aRange.aStart.Tab(), nCol1, nRow1, nCol2, nRow2)) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir aRange.aStart.SetCol(nCol1); 145cdf0e10cSrcweir aRange.aEnd.SetCol(nCol2); 146cdf0e10cSrcweir aRange.aStart.SetRow(nRow1); 147cdf0e10cSrcweir aRange.aEnd.SetRow(nRow2); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir break; 151cdf0e10cSrcweir case SC_DBSEL_SHRINK_TO_USED_DATA: 152cdf0e10cSrcweir case SC_DBSEL_ROW_DOWN: 153cdf0e10cSrcweir { 154cdf0e10cSrcweir // Shrink the selection to actual used area. 155cdf0e10cSrcweir ScDocument* pDoc = pDocSh->GetDocument(); 156cdf0e10cSrcweir SCCOL nCol1 = aRange.aStart.Col(), nCol2 = aRange.aEnd.Col(); 157cdf0e10cSrcweir SCROW nRow1 = aRange.aStart.Row(), nRow2 = aRange.aEnd.Row(); 158cdf0e10cSrcweir bool bShrunk; 159cdf0e10cSrcweir pDoc->ShrinkToUsedDataArea( bShrunk, aRange.aStart.Tab(), 160cdf0e10cSrcweir nCol1, nRow1, nCol2, nRow2, bShrinkColumnsOnly); 161cdf0e10cSrcweir if (bShrunk) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir aRange.aStart.SetCol(nCol1); 164cdf0e10cSrcweir aRange.aEnd.SetCol(nCol2); 165cdf0e10cSrcweir aRange.aStart.SetRow(nRow1); 166cdf0e10cSrcweir aRange.aEnd.SetRow(nRow2); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir break; 170cdf0e10cSrcweir default: 171cdf0e10cSrcweir ; // nothing 172cdf0e10cSrcweir } 173cdf0e10cSrcweir pData = pDocSh->GetDBData( aRange, eMode, eSel ); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir else if ( eMode != SC_DB_OLD ) 176cdf0e10cSrcweir pData = pDocSh->GetDBData( 177cdf0e10cSrcweir ScRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(), 178cdf0e10cSrcweir GetViewData()->GetTabNo() ), 179cdf0e10cSrcweir eMode, SC_DBSEL_KEEP ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir if ( pData && bMark ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir ScRange aFound; 184cdf0e10cSrcweir pData->GetArea(aFound); 185cdf0e10cSrcweir MarkRange( aFound, sal_False ); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir return pData; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir // Datenbankbereiche aendern (Dialog) 191cdf0e10cSrcweir 192cdf0e10cSrcweir void ScDBFunc::NotifyCloseDbNameDlg( const ScDBCollection& rNewColl, const List& rDelAreaList ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir 195cdf0e10cSrcweir ScDocShell* pDocShell = GetViewData()->GetDocShell(); 196cdf0e10cSrcweir ScDocShellModificator aModificator( *pDocShell ); 197cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 198cdf0e10cSrcweir ScDBCollection* pOldColl = pDoc->GetDBCollection(); 199cdf0e10cSrcweir ScDBCollection* pUndoColl = NULL; 200cdf0e10cSrcweir ScDBCollection* pRedoColl = NULL; 201cdf0e10cSrcweir const sal_Bool bRecord (pDoc->IsUndoEnabled()); 202cdf0e10cSrcweir 203cdf0e10cSrcweir long nDelCount = rDelAreaList.Count(); 204cdf0e10cSrcweir for (long nDelPos=0; nDelPos<nDelCount; nDelPos++) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir ScRange* pEntry = (ScRange*) rDelAreaList.GetObject(nDelPos); 207cdf0e10cSrcweir 208cdf0e10cSrcweir if ( pEntry ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir ScAddress& rStart = pEntry->aStart; 211cdf0e10cSrcweir ScAddress& rEnd = pEntry->aEnd; 212cdf0e10cSrcweir pDocShell->DBAreaDeleted( rStart.Tab(), 213cdf0e10cSrcweir rStart.Col(), rStart.Row(), 214cdf0e10cSrcweir rEnd.Col(), rEnd.Row() ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir // Targets am SBA abmelden nicht mehr noetig 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir if (bRecord) 221cdf0e10cSrcweir pUndoColl = new ScDBCollection( *pOldColl ); 222cdf0e10cSrcweir 223cdf0e10cSrcweir // neue Targets am SBA anmelden nicht mehr noetig 224cdf0e10cSrcweir 225cdf0e10cSrcweir pDoc->CompileDBFormula( sal_True ); // CreateFormulaString 226cdf0e10cSrcweir pDoc->SetDBCollection( new ScDBCollection( rNewColl ) ); 227cdf0e10cSrcweir pDoc->CompileDBFormula( sal_False ); // CompileFormulaString 228cdf0e10cSrcweir pOldColl = NULL; 229cdf0e10cSrcweir pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); 230cdf0e10cSrcweir aModificator.SetDocumentModified(); 231cdf0e10cSrcweir SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir if (bRecord) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir pRedoColl = new ScDBCollection( rNewColl ); 236cdf0e10cSrcweir pDocShell->GetUndoManager()->AddUndoAction( 237cdf0e10cSrcweir new ScUndoDBData( pDocShell, pUndoColl, pRedoColl ) ); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir // 242cdf0e10cSrcweir // wirkliche Funktionen 243cdf0e10cSrcweir // 244cdf0e10cSrcweir 245cdf0e10cSrcweir // Sortieren 246cdf0e10cSrcweir 247cdf0e10cSrcweir void ScDBFunc::UISort( const ScSortParam& rSortParam, sal_Bool bRecord ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir ScDocShell* pDocSh = GetViewData()->GetDocShell(); 250cdf0e10cSrcweir ScDocument* pDoc = pDocSh->GetDocument(); 251cdf0e10cSrcweir SCTAB nTab = GetViewData()->GetTabNo(); 252cdf0e10cSrcweir ScDBData* pDBData = pDoc->GetDBAtArea( nTab, rSortParam.nCol1, rSortParam.nRow1, 253cdf0e10cSrcweir rSortParam.nCol2, rSortParam.nRow2 ); 254cdf0e10cSrcweir if (!pDBData) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir DBG_ERROR( "Sort: keine DBData" ); 257cdf0e10cSrcweir return; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir ScSubTotalParam aSubTotalParam; 261cdf0e10cSrcweir pDBData->GetSubTotalParam( aSubTotalParam ); 262cdf0e10cSrcweir if (aSubTotalParam.bGroupActive[0] && !aSubTotalParam.bRemoveOnly) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir // Subtotals wiederholen, mit neuer Sortierung 265cdf0e10cSrcweir 266cdf0e10cSrcweir DoSubTotals( aSubTotalParam, bRecord, &rSortParam ); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir else 269cdf0e10cSrcweir { 270cdf0e10cSrcweir Sort( rSortParam, bRecord ); // nur sortieren 271cdf0e10cSrcweir } 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir void ScDBFunc::Sort( const ScSortParam& rSortParam, sal_Bool bRecord, sal_Bool bPaint ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir ScDocShell* pDocSh = GetViewData()->GetDocShell(); 277cdf0e10cSrcweir SCTAB nTab = GetViewData()->GetTabNo(); 278cdf0e10cSrcweir ScDBDocFunc aDBDocFunc( *pDocSh ); 279cdf0e10cSrcweir sal_Bool bSuccess = aDBDocFunc.Sort( nTab, rSortParam, bRecord, bPaint, sal_False ); 280cdf0e10cSrcweir if ( bSuccess && !rSortParam.bInplace ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir // Ziel markieren 283cdf0e10cSrcweir ScRange aDestRange( rSortParam.nDestCol, rSortParam.nDestRow, rSortParam.nDestTab, 284cdf0e10cSrcweir rSortParam.nDestCol + rSortParam.nCol2 - rSortParam.nCol1, 285cdf0e10cSrcweir rSortParam.nDestRow + rSortParam.nRow2 - rSortParam.nRow1, 286cdf0e10cSrcweir rSortParam.nDestTab ); 287cdf0e10cSrcweir MarkRange( aDestRange ); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir // Filtern 292cdf0e10cSrcweir 293cdf0e10cSrcweir void ScDBFunc::Query( const ScQueryParam& rQueryParam, const ScRange* pAdvSource, sal_Bool bRecord ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir ScDocShell* pDocSh = GetViewData()->GetDocShell(); 296cdf0e10cSrcweir SCTAB nTab = GetViewData()->GetTabNo(); 297cdf0e10cSrcweir ScDBDocFunc aDBDocFunc( *pDocSh ); 298cdf0e10cSrcweir sal_Bool bSuccess = aDBDocFunc.Query( nTab, rQueryParam, pAdvSource, bRecord, sal_False ); 299cdf0e10cSrcweir 300cdf0e10cSrcweir if (bSuccess) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir sal_Bool bCopy = !rQueryParam.bInplace; 303cdf0e10cSrcweir if (bCopy) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir // Zielbereich markieren (DB-Bereich wurde ggf. angelegt) 306cdf0e10cSrcweir ScDocument* pDoc = pDocSh->GetDocument(); 307cdf0e10cSrcweir ScDBData* pDestData = pDoc->GetDBAtCursor( 308cdf0e10cSrcweir rQueryParam.nDestCol, rQueryParam.nDestRow, 309cdf0e10cSrcweir rQueryParam.nDestTab, sal_True ); 310cdf0e10cSrcweir if (pDestData) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir ScRange aDestRange; 313cdf0e10cSrcweir pDestData->GetArea(aDestRange); 314cdf0e10cSrcweir MarkRange( aDestRange ); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir if (!bCopy) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir UpdateScrollBars(); 321cdf0e10cSrcweir SelectionChanged(); // for attribute states (filtered rows are ignored) 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir GetViewData()->GetBindings().Invalidate( SID_UNFILTER ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir // Autofilter-Knoepfe ein-/ausblenden 329cdf0e10cSrcweir 330cdf0e10cSrcweir void ScDBFunc::ToggleAutoFilter() 331cdf0e10cSrcweir { 332cdf0e10cSrcweir ScDocShell* pDocSh = GetViewData()->GetDocShell(); 333cdf0e10cSrcweir ScDocShellModificator aModificator( *pDocSh ); 334cdf0e10cSrcweir 335*22407013SOliver-Rainer Wittmann ScDBData* pDBData = GetDBData( sal_False, SC_DB_MAKE_AUTOFILTER, SC_DBSEL_ROW_DOWN ); 336*22407013SOliver-Rainer Wittmann if ( pDBData == NULL ) 337cdf0e10cSrcweir { 338*22407013SOliver-Rainer Wittmann return; 339cdf0e10cSrcweir } 340cdf0e10cSrcweir 341cdf0e10cSrcweir // use a list action for the AutoFilter buttons (ScUndoAutoFilter) and the filter operation 342*22407013SOliver-Rainer Wittmann const String aUndo = ScGlobal::GetRscString( STR_UNDO_QUERY ); 343cdf0e10cSrcweir pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo ); 344cdf0e10cSrcweir 345*22407013SOliver-Rainer Wittmann pDBData->SetByRow( sal_True ); 346*22407013SOliver-Rainer Wittmann ScQueryParam aParam; 347*22407013SOliver-Rainer Wittmann pDBData->GetQueryParam( aParam ); 348*22407013SOliver-Rainer Wittmann 349*22407013SOliver-Rainer Wittmann ScDocument* pDoc = GetViewData()->GetDocument(); 350*22407013SOliver-Rainer Wittmann 351*22407013SOliver-Rainer Wittmann bool bHasAutoFilter = true; 352*22407013SOliver-Rainer Wittmann const SCROW nRow = aParam.nRow1; 353*22407013SOliver-Rainer Wittmann const SCTAB nTab = GetViewData()->GetTabNo(); 354*22407013SOliver-Rainer Wittmann for ( SCCOL nCol=aParam.nCol1; nCol<=aParam.nCol2 && bHasAutoFilter; ++nCol ) 355*22407013SOliver-Rainer Wittmann { 356*22407013SOliver-Rainer Wittmann const sal_Int16 nFlag = 357*22407013SOliver-Rainer Wittmann ((ScMergeFlagAttr*) pDoc->GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG ))->GetValue(); 358*22407013SOliver-Rainer Wittmann 359*22407013SOliver-Rainer Wittmann if ( (nFlag & SC_MF_AUTO) == 0 ) 360*22407013SOliver-Rainer Wittmann bHasAutoFilter = false; 361*22407013SOliver-Rainer Wittmann } 362*22407013SOliver-Rainer Wittmann 363*22407013SOliver-Rainer Wittmann bool bPaint = false; 364*22407013SOliver-Rainer Wittmann 365*22407013SOliver-Rainer Wittmann if ( bHasAutoFilter ) 366*22407013SOliver-Rainer Wittmann { 367*22407013SOliver-Rainer Wittmann // switch filter buttons 368*22407013SOliver-Rainer Wittmann for ( SCCOL nCol=aParam.nCol1; nCol<=aParam.nCol2; ++nCol ) 369*22407013SOliver-Rainer Wittmann { 370*22407013SOliver-Rainer Wittmann const sal_Int16 nFlag = 371*22407013SOliver-Rainer Wittmann ((ScMergeFlagAttr*) pDoc->GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG ))->GetValue(); 372*22407013SOliver-Rainer Wittmann pDoc->ApplyAttr( nCol, nRow, nTab, ScMergeFlagAttr( nFlag & ~SC_MF_AUTO ) ); 373*22407013SOliver-Rainer Wittmann } 374*22407013SOliver-Rainer Wittmann 375cdf0e10cSrcweir ScRange aRange; 376cdf0e10cSrcweir pDBData->GetArea( aRange ); 377*22407013SOliver-Rainer Wittmann pDocSh->GetUndoManager()->AddUndoAction( new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), sal_False ) ); 378cdf0e10cSrcweir 379cdf0e10cSrcweir pDBData->SetAutoFilter(sal_False); 380cdf0e10cSrcweir 381*22407013SOliver-Rainer Wittmann // switch off filter 382*22407013SOliver-Rainer Wittmann const SCSIZE nEC = aParam.GetEntryCount(); 383*22407013SOliver-Rainer Wittmann for ( SCSIZE i=0; i<nEC; ++i ) 384*22407013SOliver-Rainer Wittmann { 385cdf0e10cSrcweir aParam.GetEntry(i).bDoQuery = sal_False; 386*22407013SOliver-Rainer Wittmann } 387cdf0e10cSrcweir aParam.bDuplicate = sal_True; 388cdf0e10cSrcweir Query( aParam, NULL, sal_True ); 389cdf0e10cSrcweir 390*22407013SOliver-Rainer Wittmann // delete internal database range for auto filter 391*22407013SOliver-Rainer Wittmann if ( pDBData->IsInternalForAutoFilter() ) 392*22407013SOliver-Rainer Wittmann { 393*22407013SOliver-Rainer Wittmann ScDBDocFunc aFunc(*pDocSh); 394*22407013SOliver-Rainer Wittmann aFunc.DeleteDBRange( pDBData->GetName(), sal_False ); 395cdf0e10cSrcweir } 396*22407013SOliver-Rainer Wittmann pDBData = NULL; 39757b4fa3cSWang Lei 398*22407013SOliver-Rainer Wittmann bPaint = true; 399*22407013SOliver-Rainer Wittmann } 400*22407013SOliver-Rainer Wittmann else 401cdf0e10cSrcweir { 402*22407013SOliver-Rainer Wittmann if ( !pDoc->IsBlockEmpty( 403*22407013SOliver-Rainer Wittmann nTab, 404*22407013SOliver-Rainer Wittmann aParam.nCol1, 405*22407013SOliver-Rainer Wittmann aParam.nRow1, 406*22407013SOliver-Rainer Wittmann aParam.nCol2, 407*22407013SOliver-Rainer Wittmann aParam.nRow2 ) ) 408cdf0e10cSrcweir { 409*22407013SOliver-Rainer Wittmann if ( !pDBData->HasHeader() ) 410cdf0e10cSrcweir { 411*22407013SOliver-Rainer Wittmann if ( MessBox( 412*22407013SOliver-Rainer Wittmann GetViewData()->GetDialogParent(), 413*22407013SOliver-Rainer Wittmann WinBits(WB_YES_NO | WB_DEF_YES), 414*22407013SOliver-Rainer Wittmann ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ), 415*22407013SOliver-Rainer Wittmann ScGlobal::GetRscString( STR_MSSG_MAKEAUTOFILTER_0 ) ).Execute() == RET_YES ) 416*22407013SOliver-Rainer Wittmann { 417*22407013SOliver-Rainer Wittmann pDBData->SetHeader( sal_True ); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir ScRange aRange; 422cdf0e10cSrcweir pDBData->GetArea( aRange ); 423*22407013SOliver-Rainer Wittmann pDocSh->GetUndoManager()->AddUndoAction( new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), sal_True ) ); 424cdf0e10cSrcweir 425cdf0e10cSrcweir pDBData->SetAutoFilter(sal_True); 426cdf0e10cSrcweir 427*22407013SOliver-Rainer Wittmann for ( SCCOL nCol=aParam.nCol1; nCol<=aParam.nCol2; ++nCol ) 428cdf0e10cSrcweir { 429*22407013SOliver-Rainer Wittmann const sal_Int16 nFlag = 430*22407013SOliver-Rainer Wittmann ((ScMergeFlagAttr*) pDoc->GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG ))->GetValue(); 431cdf0e10cSrcweir pDoc->ApplyAttr( nCol, nRow, nTab, ScMergeFlagAttr( nFlag | SC_MF_AUTO ) ); 432cdf0e10cSrcweir } 433*22407013SOliver-Rainer Wittmann pDocSh->PostPaint( aParam.nCol1, nRow, nTab, aParam.nCol2, nRow, nTab, PAINT_GRID ); 434*22407013SOliver-Rainer Wittmann bPaint = true; 435cdf0e10cSrcweir } 436cdf0e10cSrcweir else 437cdf0e10cSrcweir { 438*22407013SOliver-Rainer Wittmann ErrorBox aErrorBox( 439*22407013SOliver-Rainer Wittmann GetViewData()->GetDialogParent(), 440*22407013SOliver-Rainer Wittmann WinBits( WB_OK | WB_DEF_OK ), 441cdf0e10cSrcweir ScGlobal::GetRscString( STR_ERR_AUTOFILTER ) ); 442cdf0e10cSrcweir aErrorBox.Execute(); 443cdf0e10cSrcweir } 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446*22407013SOliver-Rainer Wittmann pDocSh->GetUndoManager()->LeaveListAction(); 447*22407013SOliver-Rainer Wittmann 448cdf0e10cSrcweir if ( bPaint ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir aModificator.SetDocumentModified(); 451cdf0e10cSrcweir 452cdf0e10cSrcweir SfxBindings& rBindings = GetViewData()->GetBindings(); 453cdf0e10cSrcweir rBindings.Invalidate( SID_AUTO_FILTER ); 454cdf0e10cSrcweir rBindings.Invalidate( SID_AUTOFILTER_HIDE ); 455cdf0e10cSrcweir } 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir // nur ausblenden, keine Daten veraendern 459cdf0e10cSrcweir 460cdf0e10cSrcweir void ScDBFunc::HideAutoFilter() 461cdf0e10cSrcweir { 462cdf0e10cSrcweir ScDocShell* pDocSh = GetViewData()->GetDocShell(); 463cdf0e10cSrcweir ScDocShellModificator aModificator( *pDocSh ); 464cdf0e10cSrcweir 465*22407013SOliver-Rainer Wittmann ScDBData* pDBData = GetDBData( sal_False ); 466cdf0e10cSrcweir SCTAB nTab; 467cdf0e10cSrcweir SCCOL nCol1, nCol2; 468cdf0e10cSrcweir SCROW nRow1, nRow2; 469cdf0e10cSrcweir pDBData->GetArea(nTab, nCol1, nRow1, nCol2, nRow2); 470cdf0e10cSrcweir 471*22407013SOliver-Rainer Wittmann { 472*22407013SOliver-Rainer Wittmann ScDocument* pDoc = pDocSh->GetDocument(); 473cdf0e10cSrcweir for (SCCOL nCol=nCol1; nCol<=nCol2; nCol++) 474cdf0e10cSrcweir { 475*22407013SOliver-Rainer Wittmann const sal_Int16 nFlag = 476*22407013SOliver-Rainer Wittmann ((ScMergeFlagAttr*) pDoc->GetAttr( nCol, nRow1, nTab, ATTR_MERGE_FLAG ))->GetValue(); 477cdf0e10cSrcweir pDoc->ApplyAttr( nCol, nRow1, nTab, ScMergeFlagAttr( nFlag & ~SC_MF_AUTO ) ); 478cdf0e10cSrcweir } 479*22407013SOliver-Rainer Wittmann } 480cdf0e10cSrcweir 481*22407013SOliver-Rainer Wittmann const String aUndo = ScGlobal::GetRscString( STR_UNDO_QUERY ); 482*22407013SOliver-Rainer Wittmann pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo ); 483*22407013SOliver-Rainer Wittmann { 484cdf0e10cSrcweir ScRange aRange; 485cdf0e10cSrcweir pDBData->GetArea( aRange ); 486cdf0e10cSrcweir pDocSh->GetUndoManager()->AddUndoAction( 487cdf0e10cSrcweir new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), sal_False ) ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir pDBData->SetAutoFilter(sal_False); 490cdf0e10cSrcweir 491*22407013SOliver-Rainer Wittmann // delete internal database range for auto filter 492*22407013SOliver-Rainer Wittmann if ( pDBData->IsInternalForAutoFilter() ) 493*22407013SOliver-Rainer Wittmann { 494*22407013SOliver-Rainer Wittmann ScDBDocFunc aFunc(*pDocSh); 495*22407013SOliver-Rainer Wittmann aFunc.DeleteDBRange( pDBData->GetName(), sal_False ); 496*22407013SOliver-Rainer Wittmann } 497*22407013SOliver-Rainer Wittmann pDBData = NULL; 498*22407013SOliver-Rainer Wittmann } 499*22407013SOliver-Rainer Wittmann pDocSh->GetUndoManager()->LeaveListAction(); 500*22407013SOliver-Rainer Wittmann 501cdf0e10cSrcweir pDocSh->PostPaint( nCol1,nRow1,nTab, nCol2,nRow1,nTab, PAINT_GRID ); 502cdf0e10cSrcweir aModificator.SetDocumentModified(); 503cdf0e10cSrcweir 504cdf0e10cSrcweir SfxBindings& rBindings = GetViewData()->GetBindings(); 505cdf0e10cSrcweir rBindings.Invalidate( SID_AUTO_FILTER ); 506cdf0e10cSrcweir rBindings.Invalidate( SID_AUTOFILTER_HIDE ); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir 509cdf0e10cSrcweir // Re-Import 510cdf0e10cSrcweir 511cdf0e10cSrcweir sal_Bool ScDBFunc::ImportData( const ScImportParam& rParam, sal_Bool bRecord ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir ScDocument* pDoc = GetViewData()->GetDocument(); 514cdf0e10cSrcweir ScEditableTester aTester( pDoc, GetViewData()->GetTabNo(), rParam.nCol1,rParam.nRow1, 515cdf0e10cSrcweir rParam.nCol2,rParam.nRow2 ); 516cdf0e10cSrcweir if ( !aTester.IsEditable() ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir ErrorMessage(aTester.GetMessageId()); 519cdf0e10cSrcweir return sal_False; 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir ScDBDocFunc aDBDocFunc( *GetViewData()->GetDocShell() ); 523cdf0e10cSrcweir return aDBDocFunc.DoImport( GetViewData()->GetTabNo(), rParam, NULL, bRecord ); 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir 527cdf0e10cSrcweir 528