LCOV - code coverage report
Current view: top level - sc/source/ui/view - dbfunc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 254 2.0 %
Date: 2012-08-25 Functions: 2 13 15.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 379 0.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "scitems.hxx"
      30                 :            : #include <sfx2/app.hxx>
      31                 :            : #include <sfx2/bindings.hxx>
      32                 :            : #include <vcl/msgbox.hxx>
      33                 :            : 
      34                 :            : #include <com/sun/star/sdbc/XResultSet.hpp>
      35                 :            : 
      36                 :            : #include "dbfunc.hxx"
      37                 :            : #include "docsh.hxx"
      38                 :            : #include "attrib.hxx"
      39                 :            : #include "sc.hrc"
      40                 :            : #include "undodat.hxx"
      41                 :            : #include "dbdata.hxx"
      42                 :            : #include "globstr.hrc"
      43                 :            : #include "global.hxx"
      44                 :            : #include "dbdocfun.hxx"
      45                 :            : #include "editable.hxx"
      46                 :            : #include "queryentry.hxx"
      47                 :            : #include "markdata.hxx"
      48                 :            : 
      49                 :            : //==================================================================
      50                 :            : 
      51                 :        229 : ScDBFunc::ScDBFunc( Window* pParent, ScDocShell& rDocSh, ScTabViewShell* pViewShell ) :
      52                 :        229 :     ScViewFunc( pParent, rDocSh, pViewShell )
      53                 :            : {
      54                 :        229 : }
      55                 :            : 
      56                 :        225 : ScDBFunc::~ScDBFunc()
      57                 :            : {
      58         [ -  + ]:        225 : }
      59                 :            : 
      60                 :            : //
      61                 :            : //      auxiliary functions
      62                 :            : //
      63                 :            : 
      64                 :          0 : void ScDBFunc::GotoDBArea( const ::rtl::OUString& rDBName )
      65                 :            : {
      66                 :          0 :     ScDocument* pDoc = GetViewData()->GetDocument();
      67                 :          0 :     ScDBCollection* pDBCol = pDoc->GetDBCollection();
      68                 :          0 :     ScDBData* pData = pDBCol->getNamedDBs().findByName(rDBName);
      69         [ #  # ]:          0 :     if (pData)
      70                 :            :     {
      71                 :          0 :         SCTAB nTab = 0;
      72                 :          0 :         SCCOL nStartCol = 0;
      73                 :          0 :         SCROW nStartRow = 0;
      74                 :          0 :         SCCOL nEndCol = 0;
      75                 :          0 :         SCROW nEndRow = 0;
      76                 :            : 
      77         [ #  # ]:          0 :         pData->GetArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
      78         [ #  # ]:          0 :         SetTabNo( nTab );
      79                 :            : 
      80                 :            :         MoveCursorAbs( nStartCol, nStartRow, ScFollowMode( SC_FOLLOW_JUMP ),
      81         [ #  # ]:          0 :                        false, false );  // bShift,bControl
      82         [ #  # ]:          0 :         DoneBlockMode();
      83         [ #  # ]:          0 :         InitBlockMode( nStartCol, nStartRow, nTab );
      84         [ #  # ]:          0 :         MarkCursor( nEndCol, nEndRow, nTab );
      85         [ #  # ]:          0 :         SelectionChanged();
      86                 :            :     }
      87                 :          0 : }
      88                 :            : 
      89                 :            : //  search current datarange for sort / filter
      90                 :            : 
      91                 :          0 : ScDBData* ScDBFunc::GetDBData( bool bMark, ScGetDBMode eMode, ScGetDBSelection eSel )
      92                 :            : {
      93                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      94                 :          0 :     ScDBData* pData = NULL;
      95                 :          0 :     ScRange aRange;
      96         [ #  # ]:          0 :     ScMarkType eMarkType = GetViewData()->GetSimpleArea(aRange);
      97 [ #  # ][ #  # ]:          0 :     if ( eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED )
      98                 :            :     {
      99                 :          0 :         bool bShrinkColumnsOnly = false;
     100         [ #  # ]:          0 :         if (eSel == SC_DBSEL_ROW_DOWN)
     101                 :            :         {
     102                 :            :             // Don't alter row range, additional rows may have been selected on
     103                 :            :             // purpose to append data, or to have a fake header row.
     104                 :          0 :             bShrinkColumnsOnly = true;
     105                 :            :             // Select further rows only if only one row or a portion thereof is
     106                 :            :             // selected.
     107         [ #  # ]:          0 :             if (aRange.aStart.Row() != aRange.aEnd.Row())
     108                 :            :             {
     109                 :            :                 // If an area is selected shrink that to the actual used
     110                 :            :                 // columns, don't draw filter buttons for empty columns.
     111                 :          0 :                 eSel = SC_DBSEL_SHRINK_TO_USED_DATA;
     112                 :            :             }
     113         [ #  # ]:          0 :             else if (aRange.aStart.Col() == aRange.aEnd.Col())
     114                 :            :             {
     115                 :            :                 // One cell only, if it is not marked obtain entire used data
     116                 :            :                 // area.
     117         [ #  # ]:          0 :                 const ScMarkData& rMarkData = GetViewData()->GetMarkData();
     118 [ #  # ][ #  # ]:          0 :                 if (!(rMarkData.IsMarked() || rMarkData.IsMultiMarked()))
                 [ #  # ]
     119                 :          0 :                     eSel = SC_DBSEL_KEEP;
     120                 :            :             }
     121                 :            :         }
     122      [ #  #  # ]:          0 :         switch (eSel)
     123                 :            :         {
     124                 :            :             case SC_DBSEL_SHRINK_TO_SHEET_DATA:
     125                 :            :                 {
     126                 :            :                     // Shrink the selection to sheet data area.
     127                 :          0 :                     ScDocument* pDoc = pDocSh->GetDocument();
     128                 :          0 :                     SCCOL nCol1 = aRange.aStart.Col(), nCol2 = aRange.aEnd.Col();
     129                 :          0 :                     SCROW nRow1 = aRange.aStart.Row(), nRow2 = aRange.aEnd.Row();
     130 [ #  # ][ #  # ]:          0 :                     if (pDoc->ShrinkToDataArea( aRange.aStart.Tab(), nCol1, nRow1, nCol2, nRow2))
     131                 :            :                     {
     132                 :          0 :                         aRange.aStart.SetCol(nCol1);
     133                 :          0 :                         aRange.aEnd.SetCol(nCol2);
     134                 :          0 :                         aRange.aStart.SetRow(nRow1);
     135                 :          0 :                         aRange.aEnd.SetRow(nRow2);
     136                 :            :                     }
     137                 :            :                 }
     138                 :          0 :                 break;
     139                 :            :             case SC_DBSEL_SHRINK_TO_USED_DATA:
     140                 :            :             case SC_DBSEL_ROW_DOWN:
     141                 :            :                 {
     142                 :            :                     // Shrink the selection to actual used area.
     143                 :          0 :                     ScDocument* pDoc = pDocSh->GetDocument();
     144                 :          0 :                     SCCOL nCol1 = aRange.aStart.Col(), nCol2 = aRange.aEnd.Col();
     145                 :          0 :                     SCROW nRow1 = aRange.aStart.Row(), nRow2 = aRange.aEnd.Row();
     146                 :            :                     bool bShrunk;
     147                 :          0 :                     pDoc->ShrinkToUsedDataArea( bShrunk, aRange.aStart.Tab(),
     148         [ #  # ]:          0 :                             nCol1, nRow1, nCol2, nRow2, bShrinkColumnsOnly);
     149         [ #  # ]:          0 :                     if (bShrunk)
     150                 :            :                     {
     151                 :          0 :                         aRange.aStart.SetCol(nCol1);
     152                 :          0 :                         aRange.aEnd.SetCol(nCol2);
     153                 :          0 :                         aRange.aStart.SetRow(nRow1);
     154                 :          0 :                         aRange.aEnd.SetRow(nRow2);
     155                 :            :                     }
     156                 :            :                 }
     157                 :          0 :                 break;
     158                 :            :             default:
     159                 :            :                 ;   // nothing
     160                 :            :         }
     161         [ #  # ]:          0 :         pData = pDocSh->GetDBData( aRange, eMode, eSel );
     162                 :            :     }
     163         [ #  # ]:          0 :     else if ( eMode != SC_DB_OLD )
     164                 :            :         pData = pDocSh->GetDBData(
     165                 :          0 :                     ScRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(),
     166                 :          0 :                              GetViewData()->GetTabNo() ),
     167         [ #  # ]:          0 :                     eMode, SC_DBSEL_KEEP );
     168                 :            : 
     169         [ #  # ]:          0 :     if (!pData)
     170                 :          0 :         return NULL;
     171                 :            : 
     172         [ #  # ]:          0 :     if (bMark)
     173                 :            :     {
     174                 :          0 :         ScRange aFound;
     175         [ #  # ]:          0 :         pData->GetArea(aFound);
     176         [ #  # ]:          0 :         MarkRange( aFound, false );
     177                 :            :     }
     178                 :          0 :     return pData;
     179                 :            : }
     180                 :            : 
     181                 :          0 : ScDBData* ScDBFunc::GetAnonymousDBData()
     182                 :            : {
     183                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     184                 :          0 :     ScRange aRange;
     185         [ #  # ]:          0 :     ScMarkType eMarkType = GetViewData()->GetSimpleArea(aRange);
     186 [ #  # ][ #  # ]:          0 :     if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
     187                 :          0 :         return NULL;
     188                 :            : 
     189                 :            :     // Expand to used data area if not explicitly marked.
     190         [ #  # ]:          0 :     const ScMarkData& rMarkData = GetViewData()->GetMarkData();
     191 [ #  # ][ #  # ]:          0 :     if (!rMarkData.IsMarked() && !rMarkData.IsMultiMarked())
                 [ #  # ]
     192                 :            :     {
     193                 :          0 :         SCCOL nCol1 = aRange.aStart.Col();
     194                 :          0 :         SCCOL nCol2 = aRange.aEnd.Col();
     195                 :          0 :         SCROW nRow1 = aRange.aStart.Row();
     196                 :          0 :         SCROW nRow2 = aRange.aEnd.Row();
     197         [ #  # ]:          0 :         pDocSh->GetDocument()->GetDataArea(aRange.aStart.Tab(), nCol1, nRow1, nCol2, nRow2, false, false);
     198                 :          0 :         aRange.aStart.SetCol(nCol1);
     199                 :          0 :         aRange.aStart.SetRow(nRow1);
     200                 :          0 :         aRange.aEnd.SetCol(nCol2);
     201                 :          0 :         aRange.aEnd.SetRow(nRow2);
     202                 :            :     }
     203                 :            : 
     204         [ #  # ]:          0 :     return pDocSh->GetAnonymousDBData(aRange);
     205                 :            : }
     206                 :            : 
     207                 :            : //  change database range (dialog)
     208                 :            : 
     209                 :          0 : void ScDBFunc::NotifyCloseDbNameDlg( const ScDBCollection& rNewColl, const std::vector<ScRange> &rDelAreaList )
     210                 :            : {
     211                 :            : 
     212                 :          0 :     ScDocShell* pDocShell = GetViewData()->GetDocShell();
     213         [ #  # ]:          0 :     ScDocShellModificator aModificator( *pDocShell );
     214                 :          0 :     ScDocument* pDoc = pDocShell->GetDocument();
     215         [ #  # ]:          0 :     ScDBCollection* pOldColl = pDoc->GetDBCollection();
     216                 :          0 :     ScDBCollection* pUndoColl = NULL;
     217                 :          0 :     ScDBCollection* pRedoColl = NULL;
     218                 :          0 :     const sal_Bool bRecord (pDoc->IsUndoEnabled());
     219                 :            : 
     220                 :          0 :     std::vector<ScRange>::const_iterator iter;
     221 [ #  # ][ #  # ]:          0 :     for (iter = rDelAreaList.begin(); iter != rDelAreaList.end(); ++iter)
     222                 :            :     {
     223                 :            :         // unregistering target in SBA no longer necessary
     224                 :          0 :         const ScAddress& rStart = iter->aStart;
     225                 :          0 :         const ScAddress& rEnd   = iter->aEnd;
     226                 :          0 :         pDocShell->DBAreaDeleted( rStart.Tab(),
     227                 :          0 :                                   rStart.Col(), rStart.Row(),
     228         [ #  # ]:          0 :                                   rEnd.Col(),   rEnd.Row() );
     229                 :            : 
     230                 :            :     }
     231                 :            : 
     232         [ #  # ]:          0 :     if (bRecord)
     233 [ #  # ][ #  # ]:          0 :         pUndoColl = new ScDBCollection( *pOldColl );
     234                 :            : 
     235                 :            :     //  register target in SBA no longer necessary
     236                 :            : 
     237         [ #  # ]:          0 :     pDoc->CompileDBFormula( sal_True );     // CreateFormulaString
     238 [ #  # ][ #  # ]:          0 :     pDoc->SetDBCollection( new ScDBCollection( rNewColl ) );
                 [ #  # ]
     239         [ #  # ]:          0 :     pDoc->CompileDBFormula( false );    // CompileFormulaString
     240                 :          0 :     pOldColl = NULL;
     241 [ #  # ][ #  # ]:          0 :     pDocShell->PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
                 [ #  # ]
     242         [ #  # ]:          0 :     aModificator.SetDocumentModified();
     243 [ #  # ][ #  # ]:          0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
         [ #  # ][ #  # ]
     244                 :            : 
     245         [ #  # ]:          0 :     if (bRecord)
     246                 :            :     {
     247 [ #  # ][ #  # ]:          0 :         pRedoColl = new ScDBCollection( rNewColl );
     248         [ #  # ]:          0 :         pDocShell->GetUndoManager()->AddUndoAction(
     249 [ #  # ][ #  # ]:          0 :             new ScUndoDBData( pDocShell, pUndoColl, pRedoColl ) );
                 [ #  # ]
     250         [ #  # ]:          0 :     }
     251                 :          0 : }
     252                 :            : 
     253                 :            : //
     254                 :            : //      main functions
     255                 :            : //
     256                 :            : 
     257                 :            : // Sort
     258                 :            : 
     259                 :          0 : void ScDBFunc::UISort( const ScSortParam& rSortParam, sal_Bool bRecord )
     260                 :            : {
     261                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     262                 :          0 :     ScDocument* pDoc = pDocSh->GetDocument();
     263                 :          0 :     SCTAB nTab = GetViewData()->GetTabNo();
     264                 :            :     ScDBData* pDBData = pDoc->GetDBAtArea( nTab, rSortParam.nCol1, rSortParam.nRow1,
     265         [ #  # ]:          0 :                                                     rSortParam.nCol2, rSortParam.nRow2 );
     266         [ #  # ]:          0 :     if (!pDBData)
     267                 :            :     {
     268                 :            :         OSL_FAIL( "Sort: no DBData" );
     269                 :          0 :         return;
     270                 :            :     }
     271                 :            : 
     272         [ #  # ]:          0 :     ScSubTotalParam aSubTotalParam;
     273         [ #  # ]:          0 :     pDBData->GetSubTotalParam( aSubTotalParam );
     274 [ #  # ][ #  # ]:          0 :     if (aSubTotalParam.bGroupActive[0] && !aSubTotalParam.bRemoveOnly)
     275                 :            :     {
     276                 :            :         //  repeat subtotals, with new sortorder
     277                 :            : 
     278         [ #  # ]:          0 :         DoSubTotals( aSubTotalParam, bRecord, &rSortParam );
     279                 :            :     }
     280                 :            :     else
     281                 :            :     {
     282         [ #  # ]:          0 :         Sort( rSortParam, bRecord );        // just sort
     283                 :            :     }
     284                 :            : }
     285                 :            : 
     286                 :          0 : void ScDBFunc::Sort( const ScSortParam& rSortParam, sal_Bool bRecord, sal_Bool bPaint )
     287                 :            : {
     288                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     289                 :          0 :     SCTAB nTab = GetViewData()->GetTabNo();
     290                 :          0 :     ScDBDocFunc aDBDocFunc( *pDocSh );
     291         [ #  # ]:          0 :     sal_Bool bSuccess = aDBDocFunc.Sort( nTab, rSortParam, bRecord, bPaint, false );
     292 [ #  # ][ #  # ]:          0 :     if ( bSuccess && !rSortParam.bInplace )
     293                 :            :     {
     294                 :            :         //  mark target
     295                 :            :         ScRange aDestRange( rSortParam.nDestCol, rSortParam.nDestRow, rSortParam.nDestTab,
     296                 :            :                             rSortParam.nDestCol + rSortParam.nCol2 - rSortParam.nCol1,
     297                 :            :                             rSortParam.nDestRow + rSortParam.nRow2 - rSortParam.nRow1,
     298                 :          0 :                             rSortParam.nDestTab );
     299         [ #  # ]:          0 :         MarkRange( aDestRange );
     300                 :          0 :     }
     301                 :          0 : }
     302                 :            : 
     303                 :            : //  filters
     304                 :            : 
     305                 :          0 : void ScDBFunc::Query( const ScQueryParam& rQueryParam, const ScRange* pAdvSource, sal_Bool bRecord )
     306                 :            : {
     307                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     308                 :          0 :     SCTAB nTab = GetViewData()->GetTabNo();
     309                 :          0 :     ScDBDocFunc aDBDocFunc( *pDocSh );
     310         [ #  # ]:          0 :     sal_Bool bSuccess = aDBDocFunc.Query( nTab, rQueryParam, pAdvSource, bRecord, false );
     311                 :            : 
     312         [ #  # ]:          0 :     if (bSuccess)
     313                 :            :     {
     314                 :          0 :         sal_Bool bCopy = !rQueryParam.bInplace;
     315         [ #  # ]:          0 :         if (bCopy)
     316                 :            :         {
     317                 :            :             //  mark target range (data base range has been set up if applicable)
     318                 :          0 :             ScDocument* pDoc = pDocSh->GetDocument();
     319                 :            :             ScDBData* pDestData = pDoc->GetDBAtCursor(
     320                 :            :                                             rQueryParam.nDestCol, rQueryParam.nDestRow,
     321         [ #  # ]:          0 :                                             rQueryParam.nDestTab, sal_True );
     322         [ #  # ]:          0 :             if (pDestData)
     323                 :            :             {
     324                 :          0 :                 ScRange aDestRange;
     325         [ #  # ]:          0 :                 pDestData->GetArea(aDestRange);
     326         [ #  # ]:          0 :                 MarkRange( aDestRange );
     327                 :            :             }
     328                 :            :         }
     329                 :            : 
     330         [ #  # ]:          0 :         if (!bCopy)
     331                 :            :         {
     332         [ #  # ]:          0 :             UpdateScrollBars();
     333         [ #  # ]:          0 :             SelectionChanged();     // for attribute states (filtered rows are ignored)
     334                 :            :         }
     335                 :            : 
     336 [ #  # ][ #  # ]:          0 :         GetViewData()->GetBindings().Invalidate( SID_UNFILTER );
     337                 :          0 :     }
     338                 :          0 : }
     339                 :            : 
     340                 :            : //  autofilter-buttons show / hide
     341                 :            : 
     342                 :          0 : void ScDBFunc::ToggleAutoFilter()
     343                 :            : {
     344                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     345         [ #  # ]:          0 :     ScDocShellModificator aModificator( *pDocSh );
     346                 :            : 
     347         [ #  # ]:          0 :     ScQueryParam    aParam;
     348         [ #  # ]:          0 :     ScDocument*     pDoc    = GetViewData()->GetDocument();
     349         [ #  # ]:          0 :     ScDBData*       pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
     350                 :            : 
     351                 :          0 :     pDBData->SetByRow( sal_True );              //! undo, retrieve beforehand ??
     352         [ #  # ]:          0 :     pDBData->GetQueryParam( aParam );
     353                 :            : 
     354                 :            : 
     355                 :            :     SCCOL  nCol;
     356                 :          0 :     SCROW  nRow = aParam.nRow1;
     357                 :          0 :     SCTAB  nTab = GetViewData()->GetTabNo();
     358                 :            :     sal_Int16   nFlag;
     359                 :          0 :     sal_Bool    bHasAuto = sal_True;
     360                 :          0 :     sal_Bool    bHeader  = pDBData->HasHeader();
     361                 :          0 :     sal_Bool    bPaint   = false;
     362                 :            : 
     363                 :            :     //!     instead retrieve from DB-range?
     364                 :            : 
     365 [ #  # ][ #  # ]:          0 :     for (nCol=aParam.nCol1; nCol<=aParam.nCol2 && bHasAuto; nCol++)
                 [ #  # ]
     366                 :            :     {
     367                 :            :         nFlag = ((ScMergeFlagAttr*) pDoc->
     368         [ #  # ]:          0 :                 GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG ))->GetValue();
     369                 :            : 
     370         [ #  # ]:          0 :         if ( (nFlag & SC_MF_AUTO) == 0 )
     371                 :          0 :             bHasAuto = false;
     372                 :            :     }
     373                 :            : 
     374         [ #  # ]:          0 :     if (bHasAuto)                               // remove
     375                 :            :     {
     376                 :            :         //  hide filter buttons
     377                 :            : 
     378         [ #  # ]:          0 :         for (nCol=aParam.nCol1; nCol<=aParam.nCol2; nCol++)
     379                 :            :         {
     380                 :            :             nFlag = ((ScMergeFlagAttr*) pDoc->
     381         [ #  # ]:          0 :                     GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG ))->GetValue();
     382 [ #  # ][ #  # ]:          0 :             pDoc->ApplyAttr( nCol, nRow, nTab, ScMergeFlagAttr( nFlag & ~SC_MF_AUTO ) );
                 [ #  # ]
     383                 :            :         }
     384                 :            : 
     385                 :            :         // use a list action for the AutoFilter buttons (ScUndoAutoFilter) and the filter operation
     386                 :            : 
     387 [ #  # ][ #  # ]:          0 :         String aUndo = ScGlobal::GetRscString( STR_UNDO_QUERY );
     388 [ #  # ][ #  # ]:          0 :         pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
     389                 :            : 
     390                 :          0 :         ScRange aRange;
     391         [ #  # ]:          0 :         pDBData->GetArea( aRange );
     392         [ #  # ]:          0 :         pDocSh->GetUndoManager()->AddUndoAction(
     393 [ #  # ][ #  # ]:          0 :             new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), false ) );
                 [ #  # ]
     394                 :            : 
     395                 :          0 :         pDBData->SetAutoFilter(false);
     396                 :            : 
     397                 :            :         //  remove filter (incl. Paint / Undo)
     398                 :            : 
     399         [ #  # ]:          0 :         SCSIZE nEC = aParam.GetEntryCount();
     400         [ #  # ]:          0 :         for (SCSIZE i=0; i<nEC; i++)
     401         [ #  # ]:          0 :             aParam.GetEntry(i).bDoQuery = false;
     402                 :          0 :         aParam.bDuplicate = sal_True;
     403         [ #  # ]:          0 :         Query( aParam, NULL, sal_True );
     404                 :            : 
     405 [ #  # ][ #  # ]:          0 :         pDocSh->GetUndoManager()->LeaveListAction();
     406                 :            : 
     407         [ #  # ]:          0 :         bPaint = sal_True;
     408                 :            :     }
     409                 :            :     else                                    // show filter buttons
     410                 :            :     {
     411         [ #  # ]:          0 :         if ( !pDoc->IsBlockEmpty( nTab,
     412                 :            :                                   aParam.nCol1, aParam.nRow1,
     413         [ #  # ]:          0 :                                   aParam.nCol2, aParam.nRow2 ) )
     414                 :            :         {
     415         [ #  # ]:          0 :             if (!bHeader)
     416                 :            :             {
     417         [ #  # ]:          0 :                 if ( MessBox( GetViewData()->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
     418         [ #  # ]:          0 :                         ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ),       // "StarCalc"
     419         [ #  # ]:          0 :                         ScGlobal::GetRscString( STR_MSSG_MAKEAUTOFILTER_0 )     // header from first row?
     420 [ #  # ][ #  # ]:          0 :                     ).Execute() == RET_YES )
         [ #  # ][ #  # ]
     421                 :            :                 {
     422                 :          0 :                     pDBData->SetHeader( sal_True );     //! Undo ??
     423                 :          0 :                     bHeader = sal_True;
     424                 :            :                 }
     425                 :            :             }
     426                 :            : 
     427                 :          0 :             ScRange aRange;
     428         [ #  # ]:          0 :             pDBData->GetArea( aRange );
     429         [ #  # ]:          0 :             pDocSh->GetUndoManager()->AddUndoAction(
     430 [ #  # ][ #  # ]:          0 :                 new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), sal_True ) );
                 [ #  # ]
     431                 :            : 
     432                 :          0 :             pDBData->SetAutoFilter(sal_True);
     433                 :            : 
     434         [ #  # ]:          0 :             for (nCol=aParam.nCol1; nCol<=aParam.nCol2; nCol++)
     435                 :            :             {
     436                 :            :                 nFlag = ((ScMergeFlagAttr*) pDoc->
     437         [ #  # ]:          0 :                         GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG ))->GetValue();
     438 [ #  # ][ #  # ]:          0 :                 pDoc->ApplyAttr( nCol, nRow, nTab, ScMergeFlagAttr( nFlag | SC_MF_AUTO ) );
                 [ #  # ]
     439                 :            :             }
     440                 :            :             pDocSh->PostPaint(ScRange(aParam.nCol1, nRow, nTab, aParam.nCol2, nRow, nTab),
     441 [ #  # ][ #  # ]:          0 :                               PAINT_GRID);
                 [ #  # ]
     442                 :          0 :             bPaint = sal_True;
     443                 :            :         }
     444                 :            :         else
     445                 :            :         {
     446                 :            :             ErrorBox aErrorBox( GetViewData()->GetDialogParent(), WinBits( WB_OK | WB_DEF_OK ),
     447 [ #  # ][ #  # ]:          0 :                                 ScGlobal::GetRscString( STR_ERR_AUTOFILTER ) );
                 [ #  # ]
     448 [ #  # ][ #  # ]:          0 :             aErrorBox.Execute();
     449                 :            :         }
     450                 :            :     }
     451                 :            : 
     452         [ #  # ]:          0 :     if ( bPaint )
     453                 :            :     {
     454         [ #  # ]:          0 :         aModificator.SetDocumentModified();
     455                 :            : 
     456         [ #  # ]:          0 :         SfxBindings& rBindings = GetViewData()->GetBindings();
     457         [ #  # ]:          0 :         rBindings.Invalidate( SID_AUTO_FILTER );
     458         [ #  # ]:          0 :         rBindings.Invalidate( SID_AUTOFILTER_HIDE );
     459 [ #  # ][ #  # ]:          0 :     }
     460                 :          0 : }
     461                 :            : 
     462                 :            : //      just hide, no data change
     463                 :            : 
     464                 :          0 : void ScDBFunc::HideAutoFilter()
     465                 :            : {
     466                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     467         [ #  # ]:          0 :     ScDocShellModificator aModificator( *pDocSh );
     468                 :            : 
     469                 :          0 :     ScDocument* pDoc = pDocSh->GetDocument();
     470                 :            : 
     471         [ #  # ]:          0 :     ScQueryParam aParam;
     472         [ #  # ]:          0 :     ScDBData* pDBData = GetDBData( false );
     473                 :            : 
     474                 :            :     SCTAB nTab;
     475                 :            :     SCCOL nCol1, nCol2;
     476                 :            :     SCROW nRow1, nRow2;
     477         [ #  # ]:          0 :     pDBData->GetArea(nTab, nCol1, nRow1, nCol2, nRow2);
     478                 :            : 
     479         [ #  # ]:          0 :     for (SCCOL nCol=nCol1; nCol<=nCol2; nCol++)
     480                 :            :     {
     481                 :            :         sal_Int16 nFlag = ((ScMergeFlagAttr*) pDoc->
     482         [ #  # ]:          0 :                                 GetAttr( nCol, nRow1, nTab, ATTR_MERGE_FLAG ))->GetValue();
     483 [ #  # ][ #  # ]:          0 :         pDoc->ApplyAttr( nCol, nRow1, nTab, ScMergeFlagAttr( nFlag & ~SC_MF_AUTO ) );
                 [ #  # ]
     484                 :            :     }
     485                 :            : 
     486                 :          0 :     ScRange aRange;
     487         [ #  # ]:          0 :     pDBData->GetArea( aRange );
     488         [ #  # ]:          0 :     pDocSh->GetUndoManager()->AddUndoAction(
     489 [ #  # ][ #  # ]:          0 :         new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), false ) );
                 [ #  # ]
     490                 :            : 
     491                 :          0 :     pDBData->SetAutoFilter(false);
     492                 :            : 
     493 [ #  # ][ #  # ]:          0 :     pDocSh->PostPaint(ScRange(nCol1, nRow1, nTab, nCol2, nRow1, nTab), PAINT_GRID );
                 [ #  # ]
     494         [ #  # ]:          0 :     aModificator.SetDocumentModified();
     495                 :            : 
     496         [ #  # ]:          0 :     SfxBindings& rBindings = GetViewData()->GetBindings();
     497         [ #  # ]:          0 :     rBindings.Invalidate( SID_AUTO_FILTER );
     498 [ #  # ][ #  # ]:          0 :     rBindings.Invalidate( SID_AUTOFILTER_HIDE );
                 [ #  # ]
     499                 :          0 : }
     500                 :            : 
     501                 :            : //      Re-Import
     502                 :            : 
     503                 :          0 : sal_Bool ScDBFunc::ImportData( const ScImportParam& rParam, sal_Bool bRecord )
     504                 :            : {
     505         [ #  # ]:          0 :     ScDocument* pDoc = GetViewData()->GetDocument();
     506                 :          0 :     ScEditableTester aTester( pDoc, GetViewData()->GetTabNo(), rParam.nCol1,rParam.nRow1,
     507         [ #  # ]:          0 :                                                             rParam.nCol2,rParam.nRow2 );
     508         [ #  # ]:          0 :     if ( !aTester.IsEditable() )
     509                 :            :     {
     510 [ #  # ][ #  # ]:          0 :         ErrorMessage(aTester.GetMessageId());
     511                 :          0 :         return false;
     512                 :            :     }
     513                 :            : 
     514                 :          0 :     ScDBDocFunc aDBDocFunc( *GetViewData()->GetDocShell() );
     515         [ #  # ]:          0 :     return aDBDocFunc.DoImport( GetViewData()->GetTabNo(), rParam, NULL, bRecord );
     516                 :            : }
     517                 :            : 
     518                 :            : 
     519                 :            : 
     520                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10