LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/docshell - dbdocimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 303 0.0 %
Date: 2012-12-27 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <comphelper/processfactory.hxx>
      21             : #include <comphelper/types.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <svx/dataaccessdescriptor.hxx>
      24             : #include <sfx2/viewfrm.hxx>
      25             : 
      26             : #include <com/sun/star/sdb/CommandType.hpp>
      27             : #include <com/sun/star/sdb/XCompletedExecution.hpp>
      28             : #include <com/sun/star/sdbc/XRow.hpp>
      29             : #include <com/sun/star/sdbc/XRowSet.hpp>
      30             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      31             : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      32             : #include <com/sun/star/task/InteractionHandler.hpp>
      33             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      34             : #include <com/sun/star/beans/XPropertySet.hpp>
      35             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      36             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      37             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      38             : 
      39             : 
      40             : #include "dbdocfun.hxx"
      41             : #include "docsh.hxx"
      42             : #include "globstr.hrc"
      43             : #include "scerrors.hxx"
      44             : #include "dbdata.hxx"
      45             : #include "markdata.hxx"
      46             : #include "undodat.hxx"
      47             : #include "progress.hxx"
      48             : #include "patattr.hxx"
      49             : #include "docpool.hxx"
      50             : #include "attrib.hxx"
      51             : #include "dbdocutl.hxx"
      52             : #include "editable.hxx"
      53             : #include "hints.hxx"
      54             : #include "miscuno.hxx"
      55             : #include "chgtrack.hxx"
      56             : #include "column.hxx"
      57             : 
      58             : using namespace com::sun::star;
      59             : 
      60             : #define SC_SERVICE_ROWSET           "com.sun.star.sdb.RowSet"
      61             : 
      62             : //! move to a header file?
      63             : #define SC_DBPROP_DATASOURCENAME    "DataSourceName"
      64             : #define SC_DBPROP_COMMAND           "Command"
      65             : #define SC_DBPROP_COMMANDTYPE       "CommandType"
      66             : 
      67           0 : void ScDBDocFunc::ShowInBeamer( const ScImportParam& rParam, SfxViewFrame* pFrame )
      68             : {
      69             :     //  called after opening the database beamer
      70             : 
      71           0 :     if ( !pFrame || !rParam.bImport )
      72           0 :         return;
      73             : 
      74           0 :     uno::Reference<frame::XFrame> xFrame = pFrame->GetFrame().GetFrameInterface();
      75           0 :     uno::Reference<frame::XDispatchProvider> xDP(xFrame, uno::UNO_QUERY);
      76             : 
      77           0 :     uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame(
      78             :                                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_beamer")),
      79           0 :                                         frame::FrameSearchFlag::CHILDREN);
      80           0 :     if (xBeamerFrame.is())
      81             :     {
      82           0 :         uno::Reference<frame::XController> xController = xBeamerFrame->getController();
      83           0 :         uno::Reference<view::XSelectionSupplier> xControllerSelection(xController, uno::UNO_QUERY);
      84           0 :         if (xControllerSelection.is())
      85             :         {
      86             :             sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND :
      87             :                         ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY :
      88           0 :                                                         sdb::CommandType::TABLE );
      89             : 
      90           0 :             ::svx::ODataAccessDescriptor aSelection;
      91           0 :             aSelection.setDataSource(rParam.aDBName);
      92           0 :             aSelection[svx::daCommand]      <<= rParam.aStatement;
      93           0 :             aSelection[svx::daCommandType]  <<= nType;
      94             : 
      95           0 :             xControllerSelection->select(uno::makeAny(aSelection.createPropertyValueSequence()));
      96             :         }
      97             :         else
      98             :         {
      99             :             OSL_FAIL("no selection supplier in the beamer!");
     100           0 :         }
     101           0 :     }
     102             : }
     103             : 
     104             : // -----------------------------------------------------------------
     105             : 
     106           0 : bool ScDBDocFunc::DoImportUno( const ScAddress& rPos,
     107             :                                 const uno::Sequence<beans::PropertyValue>& aArgs )
     108             : {
     109           0 :     svx::ODataAccessDescriptor aDesc( aArgs );      // includes selection and result set
     110             : 
     111             :     //  create database range
     112           0 :     ScDBData* pDBData = rDocShell.GetDBData( ScRange(rPos), SC_DB_IMPORT, SC_DBSEL_KEEP );
     113             :     DBG_ASSERT(pDBData, "can't create DB data");
     114           0 :     String sTarget = pDBData->GetName();
     115             : 
     116           0 :     UpdateImport( sTarget, aDesc );
     117             : 
     118           0 :     return true;
     119             : }
     120             : 
     121             : // -----------------------------------------------------------------
     122             : 
     123           0 : bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam,
     124             :         const svx::ODataAccessDescriptor* pDescriptor, bool bRecord, bool bAddrInsert )
     125             : {
     126           0 :     ScDocument* pDoc = rDocShell.GetDocument();
     127           0 :     ScChangeTrack *pChangeTrack = NULL;
     128           0 :     ScRange aChangedRange;
     129             : 
     130           0 :     if (bRecord && !pDoc->IsUndoEnabled())
     131           0 :         bRecord = false;
     132             : 
     133           0 :     ScDBData* pDBData = NULL;
     134           0 :     if ( !bAddrInsert )
     135             :     {
     136             :         pDBData = pDoc->GetDBAtArea( nTab, rParam.nCol1, rParam.nRow1,
     137           0 :                                             rParam.nCol2, rParam.nRow2 );
     138           0 :         if (!pDBData)
     139             :         {
     140             :             OSL_FAIL( "DoImport: no DBData" );
     141           0 :             return false;
     142             :         }
     143             :     }
     144             : 
     145           0 :     Window* pWaitWin = rDocShell.GetActiveDialogParent();
     146           0 :     if (pWaitWin)
     147           0 :         pWaitWin->EnterWait();
     148           0 :     ScDocShellModificator aModificator( rDocShell );
     149             : 
     150           0 :     sal_Bool bSuccess = false;
     151           0 :     sal_Bool bApi = false;                      //! pass as argument
     152           0 :     sal_Bool bTruncated = false;                // for warning
     153           0 :     sal_uInt16 nErrStringId = 0;
     154           0 :     String aErrorMessage;
     155             : 
     156           0 :     SCCOL nCol = rParam.nCol1;
     157           0 :     SCROW nRow = rParam.nRow1;
     158           0 :     SCCOL nEndCol = nCol;                   // end of resulting database area
     159           0 :     SCROW nEndRow = nRow;
     160             :     long i;
     161             : 
     162           0 :     sal_Bool bDoSelection = false;
     163           0 :     sal_Bool bRealSelection = false;            // sal_True if not everything is selected
     164           0 :     sal_Bool bBookmarkSelection = sal_False;
     165           0 :     sal_Int32 nListPos = 0;
     166           0 :     sal_Int32 nRowsRead = 0;
     167           0 :     sal_Int32 nListCount = 0;
     168             : 
     169           0 :     uno::Sequence<uno::Any> aSelection;
     170           0 :     if ( pDescriptor && pDescriptor->has(svx::daSelection) )
     171             :     {
     172           0 :         (*pDescriptor)[svx::daSelection] >>= aSelection;
     173           0 :         nListCount = aSelection.getLength();
     174           0 :         if ( nListCount > 0 )
     175             :         {
     176           0 :             bDoSelection = true;
     177           0 :             if ( pDescriptor->has(svx::daBookmarkSelection) )
     178           0 :                 bBookmarkSelection = ScUnoHelpFunctions::GetBoolFromAny( (*pDescriptor)[svx::daBookmarkSelection] );
     179           0 :             if ( bBookmarkSelection )
     180             :             {
     181             :                 // From bookmarks, there's no way to detect if all records are selected.
     182             :                 // Rely on base to pass no selection in that case.
     183           0 :                 bRealSelection = true;
     184             :             }
     185             :         }
     186             :     }
     187             : 
     188           0 :     uno::Reference<sdbc::XResultSet> xResultSet;
     189           0 :     if ( pDescriptor && pDescriptor->has(svx::daCursor) )
     190           0 :         xResultSet.set((*pDescriptor)[svx::daCursor], uno::UNO_QUERY);
     191             : 
     192             :     // ImportDoc - also used for Redo
     193           0 :     ScDocument* pImportDoc = new ScDocument( SCDOCMODE_UNDO );
     194           0 :     pImportDoc->InitUndo( pDoc, nTab, nTab );
     195             : 
     196             :     //
     197             :     //  get data from database into import document
     198             :     //
     199             : 
     200             :     try
     201             :     {
     202             :         //  progress bar
     203             :         //  only text (title is still needed, for the cancel button)
     204           0 :         ScProgress aProgress( &rDocShell, ScGlobal::GetRscString(STR_UNDO_IMPORTDATA), 0 );
     205             : 
     206             :         uno::Reference<sdbc::XRowSet> xRowSet = uno::Reference<sdbc::XRowSet>(
     207           0 :                 xResultSet, uno::UNO_QUERY );
     208           0 :         sal_Bool bDispose = false;
     209           0 :         if ( !xRowSet.is() )
     210             :         {
     211           0 :             bDispose = sal_True;
     212             :             xRowSet = uno::Reference<sdbc::XRowSet>(
     213           0 :                     comphelper::getProcessServiceFactory()->createInstance(
     214           0 :                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_SERVICE_ROWSET )) ),
     215           0 :                     uno::UNO_QUERY);
     216           0 :             uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY );
     217             :             OSL_ENSURE( xRowProp.is(), "can't get RowSet" );
     218           0 :             if ( xRowProp.is() )
     219             :             {
     220             :                 //
     221             :                 //  set source parameters
     222             :                 //
     223             : 
     224             :                 sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND :
     225             :                             ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY :
     226           0 :                                                             sdb::CommandType::TABLE );
     227           0 :                 uno::Any aAny;
     228             : 
     229           0 :                 aAny <<= rParam.aDBName;
     230           0 :                 xRowProp->setPropertyValue(
     231           0 :                             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_DBPROP_DATASOURCENAME)), aAny );
     232             : 
     233           0 :                 aAny <<= rParam.aStatement;
     234           0 :                 xRowProp->setPropertyValue(
     235           0 :                             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_DBPROP_COMMAND)), aAny );
     236             : 
     237           0 :                 aAny <<= nType;
     238           0 :                 xRowProp->setPropertyValue(
     239           0 :                             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_DBPROP_COMMANDTYPE)), aAny );
     240             : 
     241           0 :                 uno::Reference<sdb::XCompletedExecution> xExecute( xRowSet, uno::UNO_QUERY );
     242           0 :                 if ( xExecute.is() )
     243             :                 {
     244             :                     uno::Reference<task::XInteractionHandler> xHandler(
     245             :                         task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), 0),
     246           0 :                         uno::UNO_QUERY_THROW);
     247           0 :                     xExecute->executeWithCompletion( xHandler );
     248             :                 }
     249             :                 else
     250           0 :                     xRowSet->execute();
     251           0 :             }
     252             :         }
     253           0 :         if ( xRowSet.is() )
     254             :         {
     255             :             //
     256             :             //  get column descriptions
     257             :             //
     258             : 
     259           0 :             long nColCount = 0;
     260           0 :             uno::Reference<sdbc::XResultSetMetaData> xMeta;
     261           0 :             uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY );
     262           0 :             if ( xMetaSupp.is() )
     263           0 :                 xMeta = xMetaSupp->getMetaData();
     264           0 :             if ( xMeta.is() )
     265           0 :                 nColCount = xMeta->getColumnCount();    // this is the number of real columns
     266             : 
     267           0 :             if ( rParam.nCol1 + nColCount - 1 > MAXCOL )
     268             :             {
     269           0 :                 nColCount = 0;
     270             :                 //! error message
     271             :             }
     272             : 
     273           0 :             uno::Reference<sdbcx::XRowLocate> xLocate;
     274           0 :             if ( bBookmarkSelection )
     275             :             {
     276           0 :                 xLocate.set( xRowSet, uno::UNO_QUERY );
     277           0 :                 if ( !xLocate.is() )
     278             :                 {
     279             :                     SAL_WARN( "sc.ui","can't get XRowLocate");
     280           0 :                     bDoSelection = bRealSelection = bBookmarkSelection = sal_False;
     281             :                 }
     282             :             }
     283             : 
     284           0 :             uno::Reference<sdbc::XRow> xRow( xRowSet, uno::UNO_QUERY );
     285           0 :             if ( nColCount > 0 && xRow.is() )
     286             :             {
     287           0 :                 nEndCol = (SCCOL)( rParam.nCol1 + nColCount - 1 );
     288             : 
     289           0 :                 uno::Sequence<sal_Int32> aColTypes( nColCount );    // column types
     290           0 :                 uno::Sequence<sal_Bool> aColCurr( nColCount );      // currency flag is not in types
     291           0 :                 sal_Int32* pTypeArr = aColTypes.getArray();
     292           0 :                 sal_Bool* pCurrArr = aColCurr.getArray();
     293           0 :                 for (i=0; i<nColCount; i++)
     294             :                 {
     295           0 :                     pTypeArr[i] = xMeta->getColumnType( i+1 );
     296           0 :                     pCurrArr[i] = xMeta->isCurrency( i+1 );
     297             :                 }
     298             : 
     299           0 :                 if ( !bAddrInsert )                 // read column names
     300             :                 {
     301           0 :                     nCol = rParam.nCol1;
     302           0 :                     for (i=0; i<nColCount; i++)
     303             :                     {
     304             :                         pImportDoc->SetString( nCol, nRow, nTab,
     305           0 :                                                 xMeta->getColumnLabel( i+1 ) );
     306           0 :                         ++nCol;
     307             :                     }
     308           0 :                     ++nRow;
     309             :                 }
     310             : 
     311           0 :                 sal_Bool bEnd = false;
     312           0 :                 if ( !bDoSelection )
     313           0 :                     xRowSet->beforeFirst();
     314           0 :                 sal_uInt16 nInserted = 0;
     315           0 :                 while ( !bEnd )
     316             :                 {
     317             :                     //  skip rows that are not selected
     318           0 :                     if ( !bDoSelection )
     319             :                     {
     320           0 :                         if ( (bEnd = !xRowSet->next()) == false )
     321           0 :                             ++nRowsRead;
     322             :                     }
     323             :                     else
     324             :                     {
     325           0 :                         if (nListPos < nListCount)
     326             :                         {
     327           0 :                             if ( bBookmarkSelection )
     328             :                             {
     329           0 :                                 bEnd = !xLocate->moveToBookmark(aSelection[nListPos]);
     330             :                             }
     331             :                             else    // use record numbers
     332             :                             {
     333           0 :                                 sal_Int32 nNextRow = 0;
     334           0 :                                 aSelection[nListPos] >>= nNextRow;
     335           0 :                                 if ( nRowsRead+1 < nNextRow )
     336           0 :                                     bRealSelection = true;
     337           0 :                                 bEnd = !xRowSet->absolute(nRowsRead = nNextRow);
     338             :                             }
     339           0 :                             ++nListPos;
     340             :                         }
     341             :                         else
     342             :                         {
     343           0 :                             if ( !bBookmarkSelection && xRowSet->next() )
     344           0 :                                 bRealSelection = true;                      // more data available but not used
     345           0 :                             bEnd = true;
     346             :                         }
     347             :                     }
     348             : 
     349           0 :                     if ( !bEnd )
     350             :                     {
     351           0 :                         if ( ValidRow(nRow) )
     352             :                         {
     353           0 :                             nCol = rParam.nCol1;
     354           0 :                             for (i=0; i<nColCount; i++)
     355             :                             {
     356             :                                 ScDatabaseDocUtil::PutData( pImportDoc, nCol, nRow, nTab,
     357           0 :                                                 xRow, i+1, pTypeArr[i], pCurrArr[i] );
     358           0 :                                 ++nCol;
     359             :                             }
     360           0 :                             nEndRow = nRow;
     361           0 :                             ++nRow;
     362             : 
     363             :                             //  progress bar
     364             : 
     365           0 :                             ++nInserted;
     366           0 :                             if (!(nInserted & 15))
     367             :                             {
     368           0 :                                 String aPict = ScGlobal::GetRscString( STR_PROGRESS_IMPORT );
     369           0 :                                 String aText = aPict.GetToken(0,'#');
     370           0 :                                 aText += String::CreateFromInt32( nInserted );
     371           0 :                                 aText += aPict.GetToken(1,'#');
     372             : 
     373           0 :                                 if (!aProgress.SetStateText( 0, aText ))    // stopped by user?
     374             :                                 {
     375           0 :                                     bEnd = sal_True;
     376           0 :                                     bSuccess = false;
     377           0 :                                     nErrStringId = STR_DATABASE_ABORTED;
     378           0 :                                 }
     379             :                             }
     380             :                         }
     381             :                         else        // past the end of the spreadsheet
     382             :                         {
     383           0 :                             bEnd = sal_True;            // don't continue
     384           0 :                             bTruncated = sal_True;      // warning flag
     385             :                         }
     386             :                     }
     387             :                 }
     388             : 
     389           0 :                 bSuccess = sal_True;
     390             :             }
     391             : 
     392           0 :             if ( bDispose )
     393           0 :                 ::comphelper::disposeComponent( xRowSet );
     394           0 :         }
     395             :     }
     396           0 :     catch ( const sdbc::SQLException& rError )
     397             :     {
     398           0 :         aErrorMessage = rError.Message;
     399             :     }
     400           0 :     catch ( uno::Exception& )
     401             :     {
     402             :         OSL_FAIL("Unexpected exception in database");
     403             :     }
     404             : 
     405           0 :     pImportDoc->DoColResize( nTab, rParam.nCol1,nEndCol, 0 );
     406             : 
     407             :     //
     408             :     //  test for cell protection
     409             :     //
     410             : 
     411           0 :     sal_Bool bKeepFormat = !bAddrInsert && pDBData->IsKeepFmt();
     412           0 :     sal_Bool bMoveCells = !bAddrInsert && pDBData->IsDoSize();
     413           0 :     SCCOL nFormulaCols = 0; // columns to be filled with formulas
     414           0 :     if (bMoveCells && nEndCol == rParam.nCol2)
     415             :     {
     416             :         //  if column count changes, formulas would become invalid anyway
     417             :         //  -> only set nFormulaCols for unchanged column count
     418             : 
     419           0 :         SCCOL nTestCol = rParam.nCol2 + 1;      // right of the data
     420           0 :         SCROW nTestRow = rParam.nRow1 + 1;      // below the title row
     421           0 :         while ( nTestCol <= MAXCOL &&
     422           0 :                 pDoc->GetCellType(ScAddress( nTestCol, nTestRow, nTab )) == CELLTYPE_FORMULA )
     423           0 :             ++nTestCol, ++nFormulaCols;
     424             :     }
     425             : 
     426           0 :     if (bSuccess)
     427             :     {
     428             :         //  old and new range editable?
     429           0 :         ScEditableTester aTester;
     430           0 :         aTester.TestBlock( pDoc, nTab, rParam.nCol1,rParam.nRow1,rParam.nCol2,rParam.nRow2 );
     431           0 :         aTester.TestBlock( pDoc, nTab, rParam.nCol1,rParam.nRow1,nEndCol,nEndRow );
     432           0 :         if ( !aTester.IsEditable() )
     433             :         {
     434           0 :             nErrStringId = aTester.GetMessageId();
     435           0 :             bSuccess = false;
     436             :         }
     437           0 :         else if ( (pChangeTrack = pDoc->GetChangeTrack()) != NULL )
     438             :             aChangedRange = ScRange(rParam.nCol1, rParam.nRow1, nTab,
     439           0 :                         nEndCol+nFormulaCols, nEndRow, nTab );
     440             :     }
     441             : 
     442           0 :     if ( bSuccess && bMoveCells )
     443             :     {
     444             :         ScRange aOld( rParam.nCol1, rParam.nRow1, nTab,
     445           0 :                         rParam.nCol2+nFormulaCols, rParam.nRow2, nTab );
     446             :         ScRange aNew( rParam.nCol1, rParam.nRow1, nTab,
     447           0 :                         nEndCol+nFormulaCols, nEndRow, nTab );
     448           0 :         if (!pDoc->CanFitBlock( aOld, aNew ))
     449             :         {
     450           0 :             nErrStringId = STR_MSSG_DOSUBTOTALS_2;      // can't insert cells
     451           0 :             bSuccess = false;
     452             :         }
     453             :     }
     454             : 
     455             :     //
     456             :     //  copy data from import doc into real document
     457             :     //
     458             : 
     459           0 :     if ( bSuccess )
     460             :     {
     461           0 :         if (bKeepFormat)
     462             :         {
     463             :             //  keep formatting of title and first data row from the document
     464             :             //  CopyToDocument also copies styles, Apply... needs separate calls
     465             : 
     466           0 :             SCCOL nMinEndCol = Min( rParam.nCol2, nEndCol );    // not too much
     467           0 :             nMinEndCol = sal::static_int_cast<SCCOL>( nMinEndCol + nFormulaCols );  // only if column count unchanged
     468           0 :             pImportDoc->DeleteAreaTab( 0,0, MAXCOL,MAXROW, nTab, IDF_ATTRIB );
     469             :             pDoc->CopyToDocument( rParam.nCol1, rParam.nRow1, nTab,
     470             :                                     nMinEndCol, rParam.nRow1, nTab,
     471           0 :                                     IDF_ATTRIB, false, pImportDoc );
     472             : 
     473           0 :             SCROW nDataStartRow = rParam.nRow1+1;
     474           0 :             for (SCCOL nCopyCol=rParam.nCol1; nCopyCol<=nMinEndCol; nCopyCol++)
     475             :             {
     476             :                 const ScPatternAttr* pSrcPattern = pDoc->GetPattern(
     477           0 :                                                     nCopyCol, nDataStartRow, nTab );
     478             :                 pImportDoc->ApplyPatternAreaTab( nCopyCol, nDataStartRow, nCopyCol, nEndRow,
     479           0 :                                                     nTab, *pSrcPattern );
     480           0 :                 const ScStyleSheet* pStyle = pSrcPattern->GetStyleSheet();
     481           0 :                 if (pStyle)
     482             :                     pImportDoc->ApplyStyleAreaTab( nCopyCol, nDataStartRow, nCopyCol, nEndRow,
     483           0 :                                                     nTab, *pStyle );
     484             :             }
     485             :         }
     486             : 
     487             :         //  don't set cell protection attribute if table is protected
     488           0 :         if (pDoc->IsTabProtected(nTab))
     489             :         {
     490           0 :             ScPatternAttr aPattern(pImportDoc->GetPool());
     491           0 :             aPattern.GetItemSet().Put( ScProtectionAttr( false,false,false,false ) );
     492           0 :             pImportDoc->ApplyPatternAreaTab( 0,0,MAXCOL,MAXROW, nTab, aPattern );
     493             :         }
     494             : 
     495             :         //
     496             :         //  copy old data for undo
     497             :         //
     498             : 
     499           0 :         SCCOL nUndoEndCol = Max( nEndCol, rParam.nCol2 );       // rParam = old end
     500           0 :         SCROW nUndoEndRow = Max( nEndRow, rParam.nRow2 );
     501             : 
     502           0 :         ScDocument* pUndoDoc = NULL;
     503           0 :         ScDBData* pUndoDBData = NULL;
     504           0 :         if ( bRecord )
     505             :         {
     506           0 :             pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
     507           0 :             pUndoDoc->InitUndo( pDoc, nTab, nTab );
     508             : 
     509           0 :             if ( !bAddrInsert )
     510           0 :                 pUndoDBData = new ScDBData( *pDBData );
     511             :         }
     512             : 
     513           0 :         ScMarkData aNewMark;
     514           0 :         aNewMark.SelectOneTable( nTab );
     515             : 
     516           0 :         if (bRecord)
     517             :         {
     518             :             // do not touch notes (ScUndoImportData does not support drawing undo)
     519           0 :             sal_uInt16 nCopyFlags = IDF_ALL & ~IDF_NOTE;
     520             : 
     521             :             //  nFormulaCols is set only if column count is unchanged
     522             :             pDoc->CopyToDocument( rParam.nCol1, rParam.nRow1, nTab,
     523             :                                     nEndCol+nFormulaCols, nEndRow, nTab,
     524           0 :                                     nCopyFlags, false, pUndoDoc );
     525           0 :             if ( rParam.nCol2 > nEndCol )
     526             :                 pDoc->CopyToDocument( nEndCol+1, rParam.nRow1, nTab,
     527             :                                         nUndoEndCol, nUndoEndRow, nTab,
     528           0 :                                         nCopyFlags, false, pUndoDoc );
     529           0 :             if ( rParam.nRow2 > nEndRow )
     530             :                 pDoc->CopyToDocument( rParam.nCol1, nEndRow+1, nTab,
     531             :                                         nUndoEndCol+nFormulaCols, nUndoEndRow, nTab,
     532           0 :                                         nCopyFlags, false, pUndoDoc );
     533             :         }
     534             : 
     535             :         //
     536             :         //  move new data
     537             :         //
     538             : 
     539           0 :         if (bMoveCells)
     540             :         {
     541             :             //  clear only the range without the formulas,
     542             :             //  so the formula title and first row are preserved
     543             : 
     544             :             ScRange aDelRange( rParam.nCol1, rParam.nRow1, nTab,
     545           0 :                                 rParam.nCol2, rParam.nRow2, nTab );
     546           0 :             pDoc->DeleteAreaTab( aDelRange, IDF_ALL & ~IDF_NOTE );  // ohne die Formeln
     547             : 
     548             :             ScRange aOld( rParam.nCol1, rParam.nRow1, nTab,
     549           0 :                             rParam.nCol2+nFormulaCols, rParam.nRow2, nTab );
     550             :             ScRange aNew( rParam.nCol1, rParam.nRow1, nTab,
     551           0 :                             nEndCol+nFormulaCols, nEndRow, nTab );
     552           0 :             pDoc->FitBlock( aOld, aNew, false );        // Formeln nicht loeschen
     553             :         }
     554           0 :         else if ( nEndCol < rParam.nCol2 )      // DeleteArea calls PutInOrder
     555             :             pDoc->DeleteArea( nEndCol+1, rParam.nRow1, rParam.nCol2, rParam.nRow2,
     556           0 :                                 aNewMark, IDF_CONTENTS & ~IDF_NOTE );
     557             : 
     558             :         //  CopyToDocument doesn't remove contents
     559           0 :         pDoc->DeleteAreaTab( rParam.nCol1, rParam.nRow1, nEndCol, nEndRow, nTab, IDF_CONTENTS & ~IDF_NOTE );
     560             : 
     561             :         //  remove each column from ImportDoc after copying to reduce memory usage
     562           0 :         sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
     563           0 :         pDoc->SetAutoCalc( false );             // outside of the loop
     564           0 :         for (SCCOL nCopyCol = rParam.nCol1; nCopyCol <= nEndCol; nCopyCol++)
     565             :         {
     566             :             pImportDoc->CopyToDocument( nCopyCol, rParam.nRow1, nTab, nCopyCol, nEndRow, nTab,
     567           0 :                                         IDF_ALL, false, pDoc );
     568           0 :             pImportDoc->DeleteAreaTab( nCopyCol, rParam.nRow1, nCopyCol, nEndRow, nTab, IDF_CONTENTS );
     569           0 :             pImportDoc->DoColResize( nTab, nCopyCol, nCopyCol, 0 );
     570             :         }
     571           0 :         pDoc->SetAutoCalc( bOldAutoCalc );
     572             : 
     573           0 :         if (nFormulaCols > 0)               // copy formulas
     574             :         {
     575           0 :             if (bKeepFormat)            // formats for formulas
     576             :                 pImportDoc->CopyToDocument( nEndCol+1, rParam.nRow1, nTab,
     577             :                                             nEndCol+nFormulaCols, nEndRow, nTab,
     578           0 :                                             IDF_ATTRIB, false, pDoc );
     579             :             // fill formulas
     580           0 :             ScMarkData aMark;
     581           0 :             aMark.SelectOneTable(nTab);
     582             : 
     583           0 :             sal_uLong nProgCount = nFormulaCols;
     584           0 :             nProgCount *= nEndRow-rParam.nRow1-1;
     585             :             ScProgress aProgress( pDoc->GetDocumentShell(),
     586           0 :                     ScGlobal::GetRscString(STR_FILL_SERIES_PROGRESS), nProgCount );
     587             : 
     588             :             pDoc->Fill( nEndCol+1, rParam.nRow1+1, nEndCol+nFormulaCols, rParam.nRow1+1,
     589           0 :                             &aProgress, aMark, nEndRow-rParam.nRow1-1, FILL_TO_BOTTOM, FILL_SIMPLE );
     590             :         }
     591             : 
     592             :         //  if new range is smaller, clear old contents
     593             : 
     594           0 :         if (!bMoveCells)        // move has happened above
     595             :         {
     596           0 :             if ( rParam.nCol2 > nEndCol )
     597             :                 pDoc->DeleteArea( nEndCol+1, rParam.nRow1, rParam.nCol2, rParam.nRow2,
     598           0 :                                     aNewMark, IDF_CONTENTS );
     599           0 :             if ( rParam.nRow2 > nEndRow )
     600             :                 pDoc->DeleteArea( rParam.nCol1, nEndRow+1, rParam.nCol2, rParam.nRow2,
     601           0 :                                     aNewMark, IDF_CONTENTS );
     602             :         }
     603             : 
     604           0 :         if( !bAddrInsert )      // update database range
     605             :         {
     606           0 :             pDBData->SetImportParam( rParam );
     607           0 :             pDBData->SetHeader( sal_True );
     608           0 :             pDBData->SetByRow( sal_True );
     609           0 :             pDBData->SetArea( nTab, rParam.nCol1,rParam.nRow1, nEndCol,nEndRow );
     610           0 :             pDBData->SetImportSelection( bRealSelection );
     611           0 :             pDoc->CompileDBFormula();
     612             :         }
     613             : 
     614           0 :         if (bRecord)
     615             :         {
     616           0 :             ScDocument* pRedoDoc = pImportDoc;
     617           0 :             pImportDoc = NULL;
     618             : 
     619           0 :             if (nFormulaCols > 0)                   // include filled formulas for redo
     620             :                 pDoc->CopyToDocument( rParam.nCol1, rParam.nRow1, nTab,
     621             :                                         nEndCol+nFormulaCols, nEndRow, nTab,
     622           0 :                                         IDF_ALL & ~IDF_NOTE, false, pRedoDoc );
     623             : 
     624           0 :             ScDBData* pRedoDBData = pDBData ? new ScDBData( *pDBData ) : NULL;
     625             : 
     626           0 :             rDocShell.GetUndoManager()->AddUndoAction(
     627             :                 new ScUndoImportData( &rDocShell, nTab,
     628             :                                         rParam, nUndoEndCol, nUndoEndRow,
     629             :                                         nFormulaCols,
     630           0 :                                         pUndoDoc, pRedoDoc, pUndoDBData, pRedoDBData ) );
     631             :         }
     632             : 
     633           0 :         pDoc->SetDirty();
     634           0 :         rDocShell.PostPaint(ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab), PAINT_GRID);
     635           0 :         aModificator.SetDocumentModified();
     636             : 
     637           0 :         ScDBRangeRefreshedHint aHint( rParam );
     638           0 :         pDoc->BroadcastUno( aHint );
     639             : 
     640           0 :         if (pWaitWin)
     641           0 :             pWaitWin->LeaveWait();
     642             : 
     643           0 :         if ( bTruncated && !bApi )          // show warning
     644           0 :             ErrorHandler::HandleError(SCWARN_IMPORT_RANGE_OVERFLOW);
     645             :     }
     646           0 :     else if ( !bApi )
     647             :     {
     648           0 :         if (pWaitWin)
     649           0 :             pWaitWin->LeaveWait();
     650             : 
     651           0 :         if (!aErrorMessage.Len())
     652             :         {
     653           0 :             if (!nErrStringId)
     654           0 :                 nErrStringId = STR_MSSG_IMPORTDATA_0;
     655           0 :             aErrorMessage = ScGlobal::GetRscString( nErrStringId );
     656             :         }
     657           0 :         InfoBox aInfoBox( rDocShell.GetActiveDialogParent(), aErrorMessage );
     658           0 :         aInfoBox.Execute();
     659             :     }
     660             : 
     661           0 :     delete pImportDoc;
     662             : 
     663           0 :     if (bSuccess && pChangeTrack)
     664           0 :         pChangeTrack->AppendInsert ( aChangedRange );
     665             : 
     666           0 :     return bSuccess;
     667             : }
     668             : 
     669             : 
     670             : 
     671             : 
     672             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10