LCOV - code coverage report
Current view: top level - sc/source/ui/docshell - arealink.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 159 236 67.4 %
Date: 2012-08-25 Functions: 10 21 47.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 173 500 34.6 %

           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 <comphelper/string.hxx>
      30                 :            : #include <sfx2/app.hxx>
      31                 :            : #include <sfx2/docfile.hxx>
      32                 :            : #include <sfx2/fcontnr.hxx>
      33                 :            : #include <sfx2/linkmgr.hxx>
      34                 :            : #include <svl/stritem.hxx>
      35                 :            : #include <vcl/msgbox.hxx>
      36                 :            : 
      37                 :            : #include "arealink.hxx"
      38                 :            : 
      39                 :            : #include "tablink.hxx"
      40                 :            : #include "document.hxx"
      41                 :            : #include "docsh.hxx"
      42                 :            : #include "rangenam.hxx"
      43                 :            : #include "dbdata.hxx"
      44                 :            : #include "undoblk.hxx"
      45                 :            : #include "globstr.hrc"
      46                 :            : #include "markdata.hxx"
      47                 :            : #include "hints.hxx"
      48                 :            : #include "filter.hxx"
      49                 :            : 
      50                 :            : #include "attrib.hxx"           // raus, wenn ResetAttrib am Dokument
      51                 :            : #include "patattr.hxx"          // raus, wenn ResetAttrib am Dokument
      52                 :            : #include "docpool.hxx"          // raus, wenn ResetAttrib am Dokument
      53                 :            : 
      54                 :            : #include "sc.hrc"
      55                 :            : #include "scabstdlg.hxx"
      56                 :            : #include "clipparam.hxx"
      57                 :            : 
      58                 :            : struct AreaLink_Impl
      59                 :            : {
      60                 :            :     ScDocShell* m_pDocSh;
      61                 :            :     AbstractScLinkedAreaDlg* m_pDialog;
      62                 :            : 
      63                 :         16 :     AreaLink_Impl() : m_pDocSh( NULL ), m_pDialog( NULL ) {}
      64                 :            : };
      65                 :            : 
      66 [ +  + ][ -  + ]:        318 : TYPEINIT1(ScAreaLink,::sfx2::SvBaseLink);
      67                 :            : 
      68                 :            : //------------------------------------------------------------------------
      69                 :            : 
      70                 :         16 : ScAreaLink::ScAreaLink( SfxObjectShell* pShell, const String& rFile,
      71                 :            :                         const String& rFilter, const String& rOpt,
      72                 :            :                         const String& rArea, const ScRange& rDest,
      73                 :            :                         sal_uLong nRefresh ) :
      74                 :            :     ::sfx2::SvBaseLink(sfx2::LINKUPDATE_ONCALL,FORMAT_FILE),
      75                 :            :     ScRefreshTimer  ( nRefresh ),
      76                 :            :     pImpl           ( new AreaLink_Impl() ),
      77                 :            :     aFileName       (rFile),
      78                 :            :     aFilterName     (rFilter),
      79                 :            :     aOptions        (rOpt),
      80                 :            :     aSourceArea     (rArea),
      81                 :            :     aDestArea       (rDest),
      82                 :            :     bAddUndo        (true),
      83                 :            :     bInCreate       (false),
      84 [ +  - ][ +  - ]:         16 :     bDoInsert       (true)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      85                 :            : {
      86                 :            :     OSL_ENSURE(pShell->ISA(ScDocShell), "ScAreaLink mit falscher ObjectShell");
      87                 :         16 :     pImpl->m_pDocSh = static_cast< ScDocShell* >( pShell );
      88         [ +  - ]:         16 :     SetRefreshHandler( LINK( this, ScAreaLink, RefreshHdl ) );
      89                 :         16 :     SetRefreshControl( pImpl->m_pDocSh->GetDocument()->GetRefreshTimerControlAddress() );
      90                 :         16 : }
      91                 :            : 
      92 [ +  - ][ +  - ]:         16 : ScAreaLink::~ScAreaLink()
         [ +  - ][ +  - ]
                 [ +  - ]
      93                 :            : {
      94         [ +  - ]:         16 :     StopRefreshTimer();
      95                 :         16 :     delete pImpl;
      96         [ -  + ]:         32 : }
      97                 :            : 
      98                 :          0 : void ScAreaLink::Edit(Window* pParent, const Link& /* rEndEditHdl */ )
      99                 :            : {
     100                 :            :     //  use own dialog instead of SvBaseLink::Edit...
     101                 :            :     //  DefModalDialogParent setzen, weil evtl. aus der DocShell beim ConvertFrom
     102                 :            :     //  ein Optionen-Dialog kommt...
     103                 :            : 
     104                 :          0 :     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     105                 :            :     OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
     106                 :            : 
     107                 :          0 :     AbstractScLinkedAreaDlg* pDlg = pFact->CreateScLinkedAreaDlg( pParent, RID_SCDLG_LINKAREA);
     108                 :            :     OSL_ENSURE(pDlg, "Dialog create fail!");
     109                 :          0 :     pDlg->InitFromOldLink( aFileName, aFilterName, aOptions, aSourceArea, GetRefreshDelay() );
     110                 :          0 :     pImpl->m_pDialog = pDlg;
     111         [ #  # ]:          0 :     pDlg->StartExecuteModal( LINK( this, ScAreaLink, AreaEndEditHdl ) );
     112                 :          0 : }
     113                 :            : 
     114                 :         16 : ::sfx2::SvBaseLink::UpdateResult ScAreaLink::DataChanged(
     115                 :            :     const String&, const ::com::sun::star::uno::Any& )
     116                 :            : {
     117                 :            :     //  bei bInCreate nichts tun, damit Update gerufen werden kann, um den Status im
     118                 :            :     //  LinkManager zu setzen, ohne die Daten im Dokument zu aendern
     119                 :            : 
     120         [ -  + ]:         16 :     if (bInCreate)
     121                 :          0 :         return SUCCESS;
     122                 :            : 
     123                 :         16 :     sfx2::LinkManager* pLinkManager=pImpl->m_pDocSh->GetDocument()->GetLinkManager();
     124         [ +  - ]:         16 :     if (pLinkManager!=NULL)
     125                 :            :     {
     126                 :         16 :         rtl::OUString aFile, aArea, aFilter;
     127         [ +  - ]:         16 :         pLinkManager->GetDisplayNames(this, NULL, &aFile, &aArea, &aFilter);
     128                 :            : 
     129                 :            :         //  the file dialog returns the filter name with the application prefix
     130                 :            :         //  -> remove prefix
     131         [ +  - ]:         16 :         ScDocumentLoader::RemoveAppPrefix( aFilter );
     132                 :            : 
     133                 :            :         // dialog doesn't set area, so keep old one
     134         [ -  + ]:         16 :         if (aArea.isEmpty())
     135                 :            :         {
     136         [ #  # ]:          0 :             aArea = aSourceArea;
     137                 :            : 
     138                 :            :             // adjust in dialog:
     139         [ #  # ]:          0 :             String aNewLinkName;
     140         [ #  # ]:          0 :             String aTmp = aFilter;
     141 [ #  # ][ #  # ]:          0 :             sfx2::MakeLnkName(aNewLinkName, NULL, aFile, aArea, &aTmp);
         [ #  # ][ #  # ]
                 [ #  # ]
     142         [ #  # ]:          0 :             aFilter = aTmp;
     143 [ #  # ][ #  # ]:          0 :             SetName( aNewLinkName );
                 [ #  # ]
     144                 :            :         }
     145                 :            : 
     146 [ +  - ][ +  - ]:         16 :         Refresh( aFile, aFilter, aArea, GetRefreshDelay() );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     147                 :            :     }
     148                 :            : 
     149                 :         16 :     return SUCCESS;
     150                 :            : }
     151                 :            : 
     152                 :          0 : void ScAreaLink::Closed()
     153                 :            : {
     154                 :            :     // Verknuepfung loeschen: Undo
     155                 :            : 
     156                 :          0 :     ScDocument* pDoc = pImpl->m_pDocSh->GetDocument();
     157                 :          0 :     sal_Bool bUndo (pDoc->IsUndoEnabled());
     158 [ #  # ][ #  # ]:          0 :     if (bAddUndo && bUndo)
     159                 :            :     {
     160                 :          0 :         pImpl->m_pDocSh->GetUndoManager()->AddUndoAction( new ScUndoRemoveAreaLink( pImpl->m_pDocSh,
     161                 :            :                                                         aFileName, aFilterName, aOptions,
     162         [ #  # ]:          0 :                                                         aSourceArea, aDestArea, GetRefreshDelay() ) );
     163                 :            : 
     164                 :          0 :         bAddUndo = false;   // nur einmal
     165                 :            :     }
     166                 :            : 
     167                 :          0 :     SCTAB nDestTab = aDestArea.aStart.Tab();
     168         [ #  # ]:          0 :     if (pDoc->IsStreamValid(nDestTab))
     169                 :          0 :         pDoc->SetStreamValid(nDestTab, false);
     170                 :            : 
     171                 :          0 :     SvBaseLink::Closed();
     172                 :          0 : }
     173                 :            : 
     174                 :          0 : void ScAreaLink::SetDestArea(const ScRange& rNew)
     175                 :            : {
     176                 :          0 :     aDestArea = rNew;           // fuer Undo
     177                 :          0 : }
     178                 :            : 
     179                 :          0 : void ScAreaLink::SetSource(const String& rDoc, const String& rFlt, const String& rOpt,
     180                 :            :                                 const String& rArea)
     181                 :            : {
     182         [ #  # ]:          0 :     aFileName   = rDoc;
     183         [ #  # ]:          0 :     aFilterName = rFlt;
     184         [ #  # ]:          0 :     aOptions    = rOpt;
     185         [ #  # ]:          0 :     aSourceArea = rArea;
     186                 :            : 
     187                 :            :     //  also update link name for dialog
     188         [ #  # ]:          0 :     String aNewLinkName;
     189         [ #  # ]:          0 :     sfx2::MakeLnkName( aNewLinkName, NULL, aFileName, aSourceArea, &aFilterName );
     190 [ #  # ][ #  # ]:          0 :     SetName( aNewLinkName );
     191                 :          0 : }
     192                 :            : 
     193                 :          0 : bool ScAreaLink::IsEqual( const String& rFile, const String& rFilter, const String& rOpt,
     194                 :            :                             const String& rSource, const ScRange& rDest ) const
     195                 :            : {
     196                 :          0 :     return aFileName == rFile && aFilterName == rFilter && aOptions == rOpt &&
     197 [ #  # ][ #  # ]:          0 :             aSourceArea == rSource && aDestArea.aStart == rDest.aStart;
           [ #  #  #  #  
                   #  # ]
     198                 :            : }
     199                 :            : 
     200                 :            : // find a range with name >rAreaName< in >pSrcDoc<, return it in >rRange<
     201                 :          8 : bool ScAreaLink::FindExtRange( ScRange& rRange, ScDocument* pSrcDoc, const String& rAreaName )
     202                 :            : {
     203                 :          8 :     bool bFound = false;
     204                 :          8 :     ScRangeName* pNames = pSrcDoc->GetRangeName();
     205         [ +  - ]:          8 :     if (pNames)         // benannte Bereiche
     206                 :            :     {
     207 [ +  - ][ +  - ]:          8 :         const ScRangeData* p = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(rAreaName));
     208 [ #  # ][ -  + ]:          8 :         if (p && p->IsValidReference(rRange))
                 [ -  + ]
     209                 :          0 :             bFound = true;
     210                 :            :     }
     211         [ +  - ]:          8 :     if (!bFound)        // Datenbankbereiche
     212                 :            :     {
     213                 :          8 :         ScDBCollection* pDBColl = pSrcDoc->GetDBCollection();
     214         [ +  - ]:          8 :         if (pDBColl)
     215                 :            :         {
     216 [ +  - ][ +  - ]:          8 :             const ScDBData* pDB = pDBColl->getNamedDBs().findByName(rAreaName);
     217         [ -  + ]:          8 :             if (pDB)
     218                 :            :             {
     219                 :            :                 SCTAB nTab;
     220                 :            :                 SCCOL nCol1, nCol2;
     221                 :            :                 SCROW nRow1, nRow2;
     222         [ #  # ]:          0 :                 pDB->GetArea(nTab,nCol1,nRow1,nCol2,nRow2);
     223                 :          0 :                 rRange = ScRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
     224                 :          0 :                 bFound = true;
     225                 :            :             }
     226                 :            :         }
     227                 :            :     }
     228         [ +  - ]:          8 :     if (!bFound)        // direct reference (range or cell)
     229                 :            :     {
     230         [ +  - ]:          8 :         ScAddress::Details aDetails(pSrcDoc->GetAddressConvention(), 0, 0);
     231 [ +  - ][ +  - ]:          8 :         if ( rRange.ParseAny( rAreaName, pSrcDoc, aDetails ) & SCA_VALID )
     232                 :          8 :             bFound = true;
     233                 :            :     }
     234                 :          8 :     return bFound;
     235                 :            : }
     236                 :            : 
     237                 :            : //  ausfuehren:
     238                 :            : 
     239                 :         16 : sal_Bool ScAreaLink::Refresh( const String& rNewFile, const String& rNewFilter,
     240                 :            :                             const String& rNewArea, sal_uLong nNewRefresh )
     241                 :            : {
     242                 :            :     //  Dokument laden - wie TabLink
     243                 :            : 
     244 [ +  - ][ -  + ]:         16 :     if (!rNewFile.Len() || !rNewFilter.Len())
                 [ -  + ]
     245                 :          0 :         return false;
     246                 :            : 
     247         [ +  - ]:         16 :     String aNewUrl( ScGlobal::GetAbsDocName( rNewFile, pImpl->m_pDocSh ) );
     248         [ +  - ]:         16 :     sal_Bool bNewUrlName = (aNewUrl != aFileName);
     249                 :            : 
     250 [ +  - ][ +  - ]:         16 :     const SfxFilter* pFilter = pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
                 [ +  - ]
     251         [ +  + ]:         16 :     if (!pFilter)
     252                 :         12 :         return false;
     253                 :            : 
     254                 :          4 :     ScDocument* pDoc = pImpl->m_pDocSh->GetDocument();
     255                 :            : 
     256                 :          4 :     sal_Bool bUndo (pDoc->IsUndoEnabled());
     257         [ +  - ]:          4 :     pDoc->SetInLinkUpdate( sal_True );
     258                 :            : 
     259                 :            :     //  wenn neuer Filter ausgewaehlt wurde, Optionen vergessen
     260 [ +  - ][ -  + ]:          4 :     if ( rNewFilter != aFilterName )
     261         [ #  # ]:          0 :         aOptions.Erase();
     262                 :            : 
     263                 :            :     //  ItemSet immer anlegen, damit die DocShell die Optionen setzen kann
     264 [ +  - ][ +  - ]:          4 :     SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
                 [ +  - ]
     265         [ -  + ]:          4 :     if ( aOptions.Len() )
     266 [ #  # ][ #  # ]:          0 :         pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
                 [ #  # ]
     267                 :            : 
     268 [ +  - ][ +  - ]:          4 :     SfxMedium* pMed = new SfxMedium(aNewUrl, STREAM_STD_READ, pFilter);
     269                 :            : 
     270                 :            :     // aRef->DoClose() will be closed explicitly, but it is still more safe to use SfxObjectShellLock here
     271 [ +  - ][ +  - ]:          4 :     ScDocShell* pSrcShell = new ScDocShell(SFX_CREATE_MODE_INTERNAL);
     272                 :          4 :     SfxObjectShellRef aRef = pSrcShell;
     273         [ +  - ]:          4 :     pSrcShell->DoLoad(pMed);
     274                 :            : 
     275                 :          4 :     ScDocument* pSrcDoc = pSrcShell->GetDocument();
     276                 :            : 
     277                 :            :     // Optionen koennten gesetzt worden sein
     278 [ +  - ][ +  - ]:          4 :     String aNewOpt = ScDocumentLoader::GetOptions(*pMed);
     279         [ +  - ]:          4 :     if (!aNewOpt.Len())
     280         [ +  - ]:          4 :         aNewOpt = aOptions;
     281                 :            : 
     282                 :            :     // correct source range name list for web query import
     283         [ +  - ]:          4 :     String aTempArea;
     284                 :            : 
     285 [ +  - ][ +  - ]:          4 :     if( rNewFilter == ScDocShell::GetWebQueryFilterName() )
         [ +  - ][ -  + ]
     286 [ #  # ][ #  # ]:          0 :         aTempArea = ScFormatFilter::Get().GetHTMLRangeNameList( pSrcDoc, rNewArea );
         [ #  # ][ #  # ]
     287                 :            :     else
     288         [ +  - ]:          4 :         aTempArea = rNewArea;
     289                 :            : 
     290                 :            :     // find total size of source area
     291                 :          4 :     SCCOL nWidth = 0;
     292                 :          4 :     SCROW nHeight = 0;
     293 [ +  - ][ +  - ]:          4 :     xub_StrLen nTokenCnt = comphelper::string::getTokenCount(aTempArea, ';');
     294                 :          4 :     xub_StrLen nStringIx = 0;
     295                 :            :     xub_StrLen nToken;
     296                 :            : 
     297         [ +  + ]:          8 :     for( nToken = 0; nToken < nTokenCnt; nToken++ )
     298                 :            :     {
     299         [ +  - ]:          4 :         String aToken( aTempArea.GetToken( 0, ';', nStringIx ) );
     300                 :          4 :         ScRange aTokenRange;
     301 [ +  - ][ +  - ]:          4 :         if( FindExtRange( aTokenRange, pSrcDoc, aToken ) )
     302                 :            :         {
     303                 :            :             // columns: find maximum
     304                 :          4 :             nWidth = Max( nWidth, (SCCOL)(aTokenRange.aEnd.Col() - aTokenRange.aStart.Col() + 1) );
     305                 :            :             // rows: add row range + 1 empty row
     306                 :          4 :             nHeight += aTokenRange.aEnd.Row() - aTokenRange.aStart.Row() + 2;
     307                 :            :         }
     308         [ +  - ]:          4 :     }
     309                 :            :     // remove the last empty row
     310         [ +  - ]:          4 :     if( nHeight > 0 )
     311                 :          4 :         nHeight--;
     312                 :            : 
     313                 :            :     //  alte Daten loeschen / neue kopieren
     314                 :            : 
     315                 :          4 :     ScAddress aDestPos = aDestArea.aStart;
     316                 :          4 :     SCTAB nDestTab = aDestPos.Tab();
     317                 :          4 :     ScRange aOldRange = aDestArea;
     318                 :          4 :     ScRange aNewRange = aDestArea;          // alter Bereich, wenn Datei nicht gefunden o.ae.
     319 [ +  - ][ +  - ]:          4 :     if (nWidth > 0 && nHeight > 0)
     320                 :            :     {
     321                 :          4 :         aNewRange.aEnd.SetCol( aNewRange.aStart.Col() + nWidth - 1 );
     322                 :          4 :         aNewRange.aEnd.SetRow( aNewRange.aStart.Row() + nHeight - 1 );
     323                 :            :     }
     324                 :            : 
     325                 :            :     //! check CanFitBlock only if bDoInsert is set?
     326                 :          4 :     sal_Bool bCanDo = ValidColRow( aNewRange.aEnd.Col(), aNewRange.aEnd.Row() ) &&
     327 [ +  - ][ +  - ]:          4 :                   pDoc->CanFitBlock( aOldRange, aNewRange );
                 [ +  - ]
     328         [ +  - ]:          4 :     if (bCanDo)
     329                 :            :     {
     330         [ +  - ]:          4 :         ScDocShellModificator aModificator( *pImpl->m_pDocSh );
     331                 :            : 
     332                 :          4 :         SCCOL nOldEndX = aOldRange.aEnd.Col();
     333                 :          4 :         SCROW nOldEndY = aOldRange.aEnd.Row();
     334                 :          4 :         SCCOL nNewEndX = aNewRange.aEnd.Col();
     335                 :          4 :         SCROW nNewEndY = aNewRange.aEnd.Row();
     336                 :            :         ScRange aMaxRange( aDestPos,
     337                 :          4 :                     ScAddress(Max(nOldEndX,nNewEndX), Max(nOldEndY,nNewEndY), nDestTab) );
     338                 :            : 
     339                 :            :         //  Undo initialisieren
     340                 :            : 
     341                 :          4 :         ScDocument* pUndoDoc = NULL;
     342                 :          4 :         ScDocument* pRedoDoc = NULL;
     343 [ +  - ][ +  - ]:          4 :         if ( bAddUndo && bUndo )
     344                 :            :         {
     345 [ +  - ][ +  - ]:          4 :             pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
     346         [ +  + ]:          4 :             if ( bDoInsert )
     347                 :            :             {
     348 [ +  - ][ -  + ]:          1 :                 if ( nNewEndX != nOldEndX || nNewEndY != nOldEndY )             // Bereich veraendert?
     349                 :            :                 {
     350 [ #  # ][ #  # ]:          0 :                     pUndoDoc->InitUndo( pDoc, 0, pDoc->GetTableCount()-1 );
     351                 :            :                     pDoc->CopyToDocument( 0,0,0,MAXCOL,MAXROW,MAXTAB,
     352         [ #  # ]:          0 :                                             IDF_FORMULA, false, pUndoDoc );     // alle Formeln
     353                 :            :                 }
     354                 :            :                 else
     355         [ +  - ]:          1 :                     pUndoDoc->InitUndo( pDoc, nDestTab, nDestTab );             // nur Zieltabelle
     356         [ +  - ]:          1 :                 pDoc->CopyToDocument( aOldRange, IDF_ALL & ~IDF_NOTE, false, pUndoDoc );
     357                 :            :             }
     358                 :            :             else        // ohne Einfuegen
     359                 :            :             {
     360         [ +  - ]:          3 :                 pUndoDoc->InitUndo( pDoc, nDestTab, nDestTab );             // nur Zieltabelle
     361         [ +  - ]:          3 :                 pDoc->CopyToDocument( aMaxRange, IDF_ALL & ~IDF_NOTE, false, pUndoDoc );
     362                 :            :             }
     363                 :            :         }
     364                 :            : 
     365                 :            :         //  Zellen einfuegen / loeschen
     366                 :            :         //  DeleteAreaTab loescht auch MERGE_FLAG Attribute
     367                 :            : 
     368         [ +  + ]:          4 :         if (bDoInsert)
     369         [ +  - ]:          1 :             pDoc->FitBlock( aOldRange, aNewRange );         // incl. loeschen
     370                 :            :         else
     371         [ +  - ]:          3 :             pDoc->DeleteAreaTab( aMaxRange, IDF_ALL & ~IDF_NOTE );
     372                 :            : 
     373                 :            :         //  Daten kopieren
     374                 :            : 
     375 [ +  - ][ +  - ]:          4 :         if (nWidth > 0 && nHeight > 0)
     376                 :            :         {
     377         [ +  - ]:          4 :             ScDocument aClipDoc( SCDOCMODE_CLIP );
     378                 :          4 :             ScRange aNewTokenRange( aNewRange.aStart );
     379                 :          4 :             nStringIx = 0;
     380         [ +  + ]:          8 :             for( nToken = 0; nToken < nTokenCnt; nToken++ )
     381                 :            :             {
     382         [ +  - ]:          4 :                 String aToken( aTempArea.GetToken( 0, ';', nStringIx ) );
     383                 :          4 :                 ScRange aTokenRange;
     384 [ +  - ][ +  - ]:          4 :                 if( FindExtRange( aTokenRange, pSrcDoc, aToken ) )
     385                 :            :                 {
     386                 :          4 :                     SCTAB nSrcTab = aTokenRange.aStart.Tab();
     387         [ +  - ]:          4 :                     ScMarkData aSourceMark;
     388         [ +  - ]:          4 :                     aSourceMark.SelectOneTable( nSrcTab );      // selektieren fuer CopyToClip
     389         [ +  - ]:          4 :                     aSourceMark.SetMarkArea( aTokenRange );
     390                 :            : 
     391         [ +  - ]:          4 :                     ScClipParam aClipParam(aTokenRange, false);
     392         [ +  - ]:          4 :                     pSrcDoc->CopyToClip(aClipParam, &aClipDoc, &aSourceMark);
     393                 :            : 
     394 [ +  - ][ -  + ]:          4 :                     if ( aClipDoc.HasAttrib( 0,0,nSrcTab, MAXCOL,MAXROW,nSrcTab,
     395                 :          4 :                                             HASATTR_MERGED | HASATTR_OVERLAPPED ) )
     396                 :            :                     {
     397                 :            :                         //! ResetAttrib am Dokument !!!
     398                 :            : 
     399 [ #  # ][ #  # ]:          0 :                         ScPatternAttr aPattern( pSrcDoc->GetPool() );
     400 [ #  # ][ #  # ]:          0 :                         aPattern.GetItemSet().Put( ScMergeAttr() );             // Defaults
                 [ #  # ]
     401 [ #  # ][ #  # ]:          0 :                         aPattern.GetItemSet().Put( ScMergeFlagAttr() );
                 [ #  # ]
     402 [ #  # ][ #  # ]:          0 :                         aClipDoc.ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nSrcTab, aPattern );
     403                 :            :                     }
     404                 :            : 
     405                 :          4 :                     aNewTokenRange.aEnd.SetCol( aNewTokenRange.aStart.Col() + (aTokenRange.aEnd.Col() - aTokenRange.aStart.Col()) );
     406                 :          4 :                     aNewTokenRange.aEnd.SetRow( aNewTokenRange.aStart.Row() + (aTokenRange.aEnd.Row() - aTokenRange.aStart.Row()) );
     407         [ +  - ]:          4 :                     ScMarkData aDestMark;
     408         [ +  - ]:          4 :                     aDestMark.SelectOneTable( nDestTab );
     409         [ +  - ]:          4 :                     aDestMark.SetMarkArea( aNewTokenRange );
     410         [ +  - ]:          4 :                     pDoc->CopyFromClip( aNewTokenRange, aDestMark, IDF_ALL, NULL, &aClipDoc, false );
     411 [ +  - ][ +  - ]:          4 :                     aNewTokenRange.aStart.SetRow( aNewTokenRange.aEnd.Row() + 2 );
                 [ +  - ]
     412                 :            :                 }
     413 [ +  - ][ +  - ]:          8 :             }
     414                 :            :         }
     415                 :            :         else
     416                 :            :         {
     417 [ #  # ][ #  # ]:          0 :             String aErr = ScGlobal::GetRscString(STR_LINKERROR);
     418 [ #  # ][ #  # ]:          0 :             pDoc->SetString( aDestPos.Col(), aDestPos.Row(), aDestPos.Tab(), aErr );
                 [ #  # ]
     419                 :            :         }
     420                 :            : 
     421                 :            :         //  Undo eintragen
     422                 :            : 
     423 [ +  - ][ +  - ]:          4 :         if ( bAddUndo && bUndo)
     424                 :            :         {
     425 [ +  - ][ +  - ]:          4 :             pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
     426         [ +  - ]:          4 :             pRedoDoc->InitUndo( pDoc, nDestTab, nDestTab );
     427         [ +  - ]:          4 :             pDoc->CopyToDocument( aNewRange, IDF_ALL & ~IDF_NOTE, false, pRedoDoc );
     428                 :            : 
     429         [ +  - ]:          4 :             pImpl->m_pDocSh->GetUndoManager()->AddUndoAction(
     430                 :            :                 new ScUndoUpdateAreaLink( pImpl->m_pDocSh,
     431                 :            :                                             aFileName, aFilterName, aOptions,
     432                 :          4 :                                             aSourceArea, aOldRange, GetRefreshDelay(),
     433                 :            :                                             aNewUrl, rNewFilter, aNewOpt,
     434                 :            :                                             rNewArea, aNewRange, nNewRefresh,
     435 [ +  - ][ +  - ]:          4 :                                             pUndoDoc, pRedoDoc, bDoInsert ) );
                 [ +  - ]
     436                 :            :         }
     437                 :            : 
     438                 :            :         //  neue Einstellungen merken
     439                 :            : 
     440         [ -  + ]:          4 :         if ( bNewUrlName )
     441         [ #  # ]:          0 :             aFileName = aNewUrl;
     442 [ +  - ][ -  + ]:          4 :         if ( rNewFilter != aFilterName )
     443         [ #  # ]:          0 :             aFilterName = rNewFilter;
     444 [ +  - ][ -  + ]:          4 :         if ( rNewArea != aSourceArea )
     445         [ #  # ]:          0 :             aSourceArea = rNewArea;
     446 [ +  - ][ -  + ]:          4 :         if ( aNewOpt != aOptions )
     447         [ #  # ]:          0 :             aOptions = aNewOpt;
     448                 :            : 
     449         [ +  + ]:          4 :         if ( aNewRange != aDestArea )
     450                 :          3 :             aDestArea = aNewRange;
     451                 :            : 
     452         [ -  + ]:          4 :         if ( nNewRefresh != GetRefreshDelay() )
     453         [ #  # ]:          0 :             SetRefreshDelay( nNewRefresh );
     454                 :            : 
     455                 :          4 :         SCCOL nPaintEndX = Max( aOldRange.aEnd.Col(), aNewRange.aEnd.Col() );
     456                 :          4 :         SCROW nPaintEndY = Max( aOldRange.aEnd.Row(), aNewRange.aEnd.Row() );
     457                 :            : 
     458         [ +  + ]:          4 :         if ( aOldRange.aEnd.Col() != aNewRange.aEnd.Col() )
     459                 :          3 :             nPaintEndX = MAXCOL;
     460         [ +  + ]:          4 :         if ( aOldRange.aEnd.Row() != aNewRange.aEnd.Row() )
     461                 :          3 :             nPaintEndY = MAXROW;
     462                 :            : 
     463 [ +  - ][ +  - ]:          4 :         if ( !pImpl->m_pDocSh->AdjustRowHeight( aDestPos.Row(), nPaintEndY, nDestTab ) )
     464                 :            :             pImpl->m_pDocSh->PostPaint(
     465                 :          4 :                 ScRange(aDestPos.Col(), aDestPos.Row(), nDestTab, nPaintEndX, nPaintEndY, nDestTab),
     466 [ +  - ][ +  - ]:          8 :                 PAINT_GRID);
                 [ +  - ]
     467 [ +  - ][ +  - ]:          4 :         aModificator.SetDocumentModified();
     468                 :            :     }
     469                 :            :     else
     470                 :            :     {
     471                 :            :         //  CanFitBlock sal_False -> Probleme mit zusammengefassten Zellen
     472                 :            :         //                       oder Tabellengrenze erreicht!
     473                 :            :         //! Zellschutz ???
     474                 :            : 
     475                 :            :         //! Link-Dialog muss Default-Parent setzen
     476                 :            :         //  "kann keine Zeilen einfuegen"
     477                 :            :         InfoBox aBox( Application::GetDefDialogParent(),
     478 [ #  # ][ #  # ]:          0 :                         ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_2 ) );
                 [ #  # ]
     479 [ #  # ][ #  # ]:          0 :         aBox.Execute();
     480                 :            :     }
     481                 :            : 
     482                 :            :     //  aufraeumen
     483                 :            : 
     484         [ +  - ]:          4 :     aRef->DoClose();
     485                 :            : 
     486         [ +  - ]:          4 :     pDoc->SetInLinkUpdate( false );
     487                 :            : 
     488         [ +  - ]:          4 :     if (bCanDo)
     489                 :            :     {
     490                 :            :         //  notify Uno objects (for XRefreshListener)
     491                 :            :         //! also notify Uno objects if file name was changed!
     492         [ +  - ]:          4 :         ScLinkRefreshedHint aHint;
     493         [ +  - ]:          4 :         aHint.SetAreaLink( aDestPos );
     494 [ +  - ][ +  - ]:          4 :         pDoc->BroadcastUno( aHint );
     495                 :            :     }
     496                 :            : 
     497 [ +  - ][ +  - ]:         16 :     return bCanDo;
         [ +  - ][ +  - ]
     498                 :            : }
     499                 :            : 
     500                 :            : 
     501                 :          0 : IMPL_LINK_NOARG(ScAreaLink, RefreshHdl)
     502                 :            : {
     503                 :            :     long nRes = Refresh( aFileName, aFilterName, aSourceArea,
     504                 :          0 :         GetRefreshDelay() ) != 0;
     505                 :          0 :     return nRes;
     506                 :            : }
     507                 :            : 
     508                 :          0 : IMPL_LINK_NOARG(ScAreaLink, AreaEndEditHdl)
     509                 :            : {
     510                 :            :     //  #i76514# can't use link argument to access the dialog,
     511                 :            :     //  because it's the ScLinkedAreaDlg, not AbstractScLinkedAreaDlg
     512                 :            : 
     513 [ #  # ][ #  # ]:          0 :     if ( pImpl->m_pDialog && pImpl->m_pDialog->GetResult() == RET_OK )
                 [ #  # ]
     514                 :            :     {
     515 [ #  # ][ #  # ]:          0 :         aOptions = pImpl->m_pDialog->GetOptions();
                 [ #  # ]
     516                 :          0 :         Refresh( pImpl->m_pDialog->GetURL(), pImpl->m_pDialog->GetFilter(),
     517 [ #  # ][ #  # ]:          0 :                  pImpl->m_pDialog->GetSource(), pImpl->m_pDialog->GetRefresh() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     518                 :            : 
     519                 :            :         //  copy source data from members (set in Refresh) into link name for dialog
     520         [ #  # ]:          0 :         String aNewLinkName;
     521         [ #  # ]:          0 :         sfx2::MakeLnkName( aNewLinkName, NULL, aFileName, aSourceArea, &aFilterName );
     522 [ #  # ][ #  # ]:          0 :         SetName( aNewLinkName );
     523                 :            :     }
     524                 :          0 :     pImpl->m_pDialog = NULL;    // dialog is deleted with parent
     525                 :            : 
     526                 :          0 :     return 0;
     527                 :            : }
     528                 :            : 
     529                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10