LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - viewfun4.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 420 0.2 %
Date: 2013-07-09 Functions: 2 11 18.2 %
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 "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : 
      23             : #include <editeng/editobj.hxx>
      24             : #include <editeng/editstat.hxx>
      25             : #include <editeng/editview.hxx>
      26             : #include <editeng/flditem.hxx>
      27             : #include <svx/hlnkitem.hxx>
      28             : #include <editeng/langitem.hxx>
      29             : #include <svx/svxerr.hxx>
      30             : #include <editeng/unolingu.hxx>
      31             : 
      32             : #include <sfx2/bindings.hxx>
      33             : #include <sfx2/dispatch.hxx>
      34             : #include <sfx2/docfile.hxx>
      35             : #include <sfx2/fcontnr.hxx>
      36             : #include <svtools/langtab.hxx>
      37             : #include <vcl/graphicfilter.hxx>
      38             : #include <svl/stritem.hxx>
      39             : #include <svtools/transfer.hxx>
      40             : #include <svl/urlbmk.hxx>
      41             : #include <vcl/msgbox.hxx>
      42             : #include <avmedia/mediawindow.hxx>
      43             : 
      44             : #include <comphelper/storagehelper.hxx>
      45             : #include <comphelper/processfactory.hxx>
      46             : 
      47             : #include "viewfunc.hxx"
      48             : #include "docsh.hxx"
      49             : #include "document.hxx"
      50             : #include "docpool.hxx"
      51             : #include "globstr.hrc"
      52             : #include "global.hxx"
      53             : #include "undoblk.hxx"
      54             : #include "undocell.hxx"
      55             : #include "formulacell.hxx"
      56             : #include "scmod.hxx"
      57             : #include "spelleng.hxx"
      58             : #include "patattr.hxx"
      59             : #include "sc.hrc"
      60             : #include "tabvwsh.hxx"
      61             : #include "impex.hxx"
      62             : #include "editutil.hxx"
      63             : #include "editable.hxx"
      64             : #include "dociter.hxx"
      65             : #include "reffind.hxx"
      66             : #include "compiler.hxx"
      67             : 
      68             : #include <boost/scoped_ptr.hpp>
      69             : 
      70             : using namespace com::sun::star;
      71             : 
      72             : // STATIC DATA -----------------------------------------------------------
      73             : 
      74             : sal_Bool bPasteIsDrop = false;
      75             : 
      76             : //==================================================================
      77             : 
      78           0 : void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
      79             :                                 const ::com::sun::star::uno::Reference<
      80             :                                     ::com::sun::star::datatransfer::XTransferable >& rxTransferable )
      81             : {
      82           0 :     TransferableDataHelper aDataHelper( rxTransferable );
      83           0 :     if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_EDITENGINE ) )
      84             :     {
      85           0 :         HideAllCursors();
      86             : 
      87             : 
      88           0 :         ScDocShell* pDocSh = GetViewData()->GetDocShell();
      89           0 :         ScDocument* pDoc = pDocSh->GetDocument();
      90           0 :         SCTAB nTab = GetViewData()->GetTabNo();
      91           0 :         const sal_Bool bRecord (pDoc->IsUndoEnabled());
      92             : 
      93           0 :         const ScPatternAttr* pPattern = pDoc->GetPattern( nStartCol, nStartRow, nTab );
      94           0 :         ScTabEditEngine* pEngine = new ScTabEditEngine( *pPattern, pDoc->GetEnginePool() );
      95           0 :         pEngine->EnableUndo( false );
      96             : 
      97           0 :         Window* pActWin = GetActiveWin();
      98           0 :         if (pActWin)
      99             :         {
     100           0 :             pEngine->SetPaperSize(Size(100000,100000));
     101           0 :             Window aWin( pActWin );
     102           0 :             EditView aEditView( pEngine, &aWin );
     103           0 :             aEditView.SetOutputArea(Rectangle(0,0,100000,100000));
     104             : 
     105             :             // same method now for clipboard or drag&drop
     106             :             // mba: clipboard always must contain absolute URLs (could be from alien source)
     107           0 :             aEditView.InsertText( rxTransferable, String(), sal_True );
     108             :         }
     109             : 
     110           0 :         sal_Int32 nParCnt = pEngine->GetParagraphCount();
     111           0 :         if (nParCnt)
     112             :         {
     113           0 :             SCROW nEndRow = nStartRow + static_cast<SCROW>(nParCnt) - 1;
     114           0 :             if (nEndRow > MAXROW)
     115           0 :                 nEndRow = MAXROW;
     116             : 
     117           0 :             ScDocument* pUndoDoc = NULL;
     118           0 :             if (bRecord)
     119             :             {
     120           0 :                 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
     121           0 :                 pUndoDoc->InitUndo( pDoc, nTab, nTab );
     122           0 :                 pDoc->CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, IDF_ALL, false, pUndoDoc );
     123             :             }
     124             : 
     125           0 :             SCROW nRow = nStartRow;
     126             : 
     127             :             // Temporarily turn off undo generation for this lot
     128           0 :             bool bUndoEnabled = pDoc->IsUndoEnabled();
     129           0 :             pDoc->EnableUndo( false );
     130           0 :             for( sal_Int32 n = 0; n < nParCnt; n++ )
     131             :             {
     132           0 :                 boost::scoped_ptr<EditTextObject> pObject(pEngine->CreateTextObject(n));
     133           0 :                 EnterData(nStartCol, nRow, nTab, *pObject, true);
     134           0 :                 if( ++nRow > MAXROW )
     135           0 :                     break;
     136           0 :             }
     137           0 :             pDoc->EnableUndo(bUndoEnabled);
     138             : 
     139           0 :             if (bRecord)
     140             :             {
     141           0 :                 ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
     142           0 :                 pRedoDoc->InitUndo( pDoc, nTab, nTab );
     143           0 :                 pDoc->CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, IDF_ALL|IDF_NOCAPTIONS, false, pRedoDoc );
     144             : 
     145           0 :                 ScMarkData aDestMark;
     146           0 :                 aDestMark.SelectOneTable( nTab );
     147           0 :                 pDocSh->GetUndoManager()->AddUndoAction(
     148             :                     new ScUndoPaste(
     149             :                         pDocSh, ScRange(nStartCol, nStartRow, nTab, nStartCol, nEndRow, nTab),
     150           0 :                         aDestMark, pUndoDoc, pRedoDoc, IDF_ALL, NULL));
     151             :             }
     152             :         }
     153             : 
     154           0 :         delete pEngine;
     155             : 
     156           0 :         ShowAllCursors();
     157             :     }
     158             :     else
     159             :     {
     160           0 :         HideAllCursors();
     161           0 :         ScDocShell* pDocSh = GetViewData()->GetDocShell();
     162             :         ScImportExport aImpEx( pDocSh->GetDocument(),
     163           0 :             ScAddress( nStartCol, nStartRow, GetViewData()->GetTabNo() ) );
     164             : 
     165           0 :         OUString aStr;
     166           0 :         SotStorageStreamRef xStream;
     167           0 :         if ( aDataHelper.GetSotStorageStream( SOT_FORMAT_RTF, xStream ) && xStream.Is() )
     168             :             // mba: clipboard always must contain absolute URLs (could be from alien source)
     169           0 :             aImpEx.ImportStream( *xStream, String(), SOT_FORMAT_RTF );
     170           0 :         else if ( aDataHelper.GetString( SOT_FORMAT_RTF, aStr ) )
     171           0 :             aImpEx.ImportString( aStr, SOT_FORMAT_RTF );
     172             : 
     173           0 :         AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row() );
     174           0 :         pDocSh->UpdateOle(GetViewData());
     175           0 :         ShowAllCursors();
     176           0 :     }
     177           0 : }
     178           0 : void ScViewFunc::DoRefConversion( sal_Bool bRecord )
     179             : {
     180           0 :     ScDocument* pDoc = GetViewData()->GetDocument();
     181           0 :     ScMarkData& rMark = GetViewData()->GetMarkData();
     182           0 :     SCTAB nTabCount = pDoc->GetTableCount();
     183           0 :     if (bRecord && !pDoc->IsUndoEnabled())
     184           0 :         bRecord = false;
     185             : 
     186           0 :     ScRange aMarkRange;
     187           0 :     rMark.MarkToSimple();
     188           0 :     sal_Bool bMulti = rMark.IsMultiMarked();
     189           0 :     if (bMulti)
     190           0 :         rMark.GetMultiMarkArea( aMarkRange );
     191           0 :     else if (rMark.IsMarked())
     192           0 :         rMark.GetMarkArea( aMarkRange );
     193             :     else
     194             :     {
     195           0 :         aMarkRange = ScRange( GetViewData()->GetCurX(),
     196           0 :             GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
     197             :     }
     198           0 :     ScEditableTester aTester( pDoc, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
     199           0 :                             aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(),rMark );
     200           0 :     if (!aTester.IsEditable())
     201             :     {
     202           0 :         ErrorMessage(aTester.GetMessageId());
     203           0 :         return;
     204             :     }
     205             : 
     206           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     207           0 :     sal_Bool bOk = false;
     208             : 
     209           0 :     ScDocument* pUndoDoc = NULL;
     210           0 :     if (bRecord)
     211             :     {
     212           0 :         pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
     213           0 :         SCTAB nTab = aMarkRange.aStart.Tab();
     214           0 :         pUndoDoc->InitUndo( pDoc, nTab, nTab );
     215             : 
     216           0 :         if ( rMark.GetSelectCount() > 1 )
     217             :         {
     218           0 :             ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
     219           0 :             for (; itr != itrEnd; ++itr)
     220           0 :                 if ( *itr != nTab )
     221           0 :                     pUndoDoc->AddUndoTab( *itr, *itr );
     222             :         }
     223           0 :         ScRange aCopyRange = aMarkRange;
     224           0 :         aCopyRange.aStart.SetTab(0);
     225           0 :         aCopyRange.aEnd.SetTab(nTabCount-1);
     226           0 :         pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pUndoDoc, &rMark );
     227             :     }
     228             : 
     229           0 :     ScRangeListRef xRanges;
     230           0 :     GetViewData()->GetMultiArea( xRanges );
     231           0 :     size_t nCount = xRanges->size();
     232             : 
     233           0 :     ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
     234           0 :     for (; itr != itrEnd; ++itr)
     235             :     {
     236           0 :         SCTAB i = *itr;
     237           0 :         for (size_t j = 0; j < nCount; ++j)
     238             :         {
     239           0 :             ScRange aRange = *(*xRanges)[j];
     240           0 :             aRange.aStart.SetTab(i);
     241           0 :             aRange.aEnd.SetTab(i);
     242           0 :             ScCellIterator aIter( pDoc, aRange );
     243           0 :             for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
     244             :             {
     245           0 :                 if (aIter.getType() != CELLTYPE_FORMULA)
     246           0 :                     continue;
     247             : 
     248           0 :                 ScFormulaCell* pCell = aIter.getFormulaCell();
     249           0 :                 OUString aOld;
     250           0 :                 pCell->GetFormula(aOld);
     251           0 :                 sal_Int32 nLen = aOld.getLength();
     252           0 :                 ScRefFinder aFinder( aOld, aIter.GetPos(), pDoc, pDoc->GetAddressConvention() );
     253           0 :                 aFinder.ToggleRel( 0, nLen );
     254           0 :                 if (aFinder.GetFound())
     255             :                 {
     256           0 :                     ScAddress aPos = pCell->aPos;
     257           0 :                     String aNew = aFinder.GetText();
     258           0 :                     ScCompiler aComp( pDoc, aPos);
     259           0 :                     aComp.SetGrammar(pDoc->GetGrammar());
     260           0 :                     ScTokenArray* pArr = aComp.CompileString( aNew );
     261             :                     ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos,
     262           0 :                                                 pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE );
     263           0 :                     pDoc->SetFormulaCell(aPos, pNewCell);
     264           0 :                     bOk = true;
     265             :                 }
     266           0 :             }
     267           0 :         }
     268             :     }
     269           0 :     if (bRecord)
     270             :     {
     271           0 :         ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
     272           0 :         SCTAB nTab = aMarkRange.aStart.Tab();
     273           0 :         pRedoDoc->InitUndo( pDoc, nTab, nTab );
     274             : 
     275           0 :         if ( rMark.GetSelectCount() > 1 )
     276             :         {
     277           0 :             itr = rMark.begin();
     278           0 :             for (; itr != itrEnd; ++itr)
     279           0 :                 if ( *itr != nTab )
     280           0 :                     pRedoDoc->AddUndoTab( *itr, *itr );
     281             :         }
     282           0 :         ScRange aCopyRange = aMarkRange;
     283           0 :         aCopyRange.aStart.SetTab(0);
     284           0 :         aCopyRange.aEnd.SetTab(nTabCount-1);
     285           0 :         pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pRedoDoc, &rMark );
     286             : 
     287           0 :         pDocSh->GetUndoManager()->AddUndoAction(
     288             :             new ScUndoRefConversion( pDocSh,
     289           0 :                                     aMarkRange, rMark, pUndoDoc, pRedoDoc, bMulti, IDF_ALL) );
     290             :     }
     291             : 
     292           0 :     pDocSh->PostPaint( aMarkRange, PAINT_GRID );
     293           0 :     pDocSh->UpdateOle(GetViewData());
     294           0 :     pDocSh->SetDocumentModified();
     295           0 :     CellContentChanged();
     296             : 
     297           0 :     if (!bOk)
     298           0 :         ErrorMessage(STR_ERR_NOREF);
     299             : }
     300             : //  Thesaurus - Undo ok
     301           0 : void ScViewFunc::DoThesaurus( sal_Bool bRecord )
     302             : {
     303             :     SCCOL nCol;
     304             :     SCROW nRow;
     305             :     SCTAB nTab;
     306           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     307           0 :     ScDocument* pDoc = pDocSh->GetDocument();
     308           0 :     ScMarkData& rMark = GetViewData()->GetMarkData();
     309           0 :     ScSplitPos eWhich = GetViewData()->GetActivePart();
     310             :     EESpellState eState;
     311           0 :     String sOldText, sNewString;
     312           0 :     EditTextObject* pOldTObj = NULL;
     313           0 :     const EditTextObject* pTObject = NULL;
     314           0 :     EditView* pEditView = NULL;
     315           0 :     boost::scoped_ptr<ESelection> pEditSel;
     316             :     ScEditEngineDefaulter* pThesaurusEngine;
     317           0 :     sal_Bool bIsEditMode = GetViewData()->HasEditView(eWhich);
     318           0 :     if (bRecord && !pDoc->IsUndoEnabled())
     319           0 :         bRecord = false;
     320           0 :     if (bIsEditMode)                                            // Edit-Mode aktiv
     321             :     {
     322           0 :         GetViewData()->GetEditView(eWhich, pEditView, nCol, nRow);
     323           0 :         pEditSel.reset(new ESelection(pEditView->GetSelection()));
     324           0 :         SC_MOD()->InputEnterHandler();
     325           0 :         GetViewData()->GetBindings().Update();          // sonst kommt der Sfx durcheinander...
     326             :     }
     327             :     else
     328             :     {
     329           0 :         nCol = GetViewData()->GetCurX();
     330           0 :         nRow = GetViewData()->GetCurY();
     331             :     }
     332           0 :     nTab = GetViewData()->GetTabNo();
     333             : 
     334           0 :     ScAddress aPos(nCol, nRow, nTab);
     335           0 :     ScEditableTester aTester( pDoc, nCol, nRow, nCol, nRow, rMark );
     336           0 :     if (!aTester.IsEditable())
     337             :     {
     338           0 :         ErrorMessage(aTester.GetMessageId());
     339           0 :         return;
     340             :     }
     341             : 
     342           0 :     CellType eCellType = pDoc->GetCellType(aPos);
     343           0 :     if (eCellType != CELLTYPE_STRING && eCellType != CELLTYPE_EDIT)
     344             :     {
     345           0 :         ErrorMessage(STR_THESAURUS_NO_STRING);
     346           0 :         return;
     347             :     }
     348             : 
     349           0 :     uno::Reference<linguistic2::XSpellChecker1> xSpeller = LinguMgr::GetSpellChecker();
     350             : 
     351           0 :     pThesaurusEngine = new ScEditEngineDefaulter( pDoc->GetEnginePool() );
     352           0 :     pThesaurusEngine->SetEditTextObjectPool( pDoc->GetEditPool() );
     353           0 :     pThesaurusEngine->SetRefDevice(GetViewData()->GetActiveWin());
     354           0 :     pThesaurusEngine->SetSpeller(xSpeller);
     355           0 :     MakeEditView(pThesaurusEngine, nCol, nRow );
     356           0 :     const ScPatternAttr* pPattern = NULL;
     357           0 :     SfxItemSet* pEditDefaults = new SfxItemSet(pThesaurusEngine->GetEmptyItemSet());
     358           0 :     pPattern = pDoc->GetPattern(nCol, nRow, nTab);
     359           0 :     if (pPattern)
     360             :     {
     361           0 :         pPattern->FillEditItemSet( pEditDefaults );
     362           0 :         pThesaurusEngine->SetDefaults( *pEditDefaults );
     363             :     }
     364             : 
     365           0 :     if (eCellType == CELLTYPE_STRING)
     366             :     {
     367           0 :         sOldText = pDoc->GetString(aPos);
     368           0 :         pThesaurusEngine->SetText(sOldText);
     369             :     }
     370           0 :     else if (eCellType == CELLTYPE_EDIT)
     371             :     {
     372           0 :         pTObject = pDoc->GetEditText(aPos);
     373           0 :         if (pTObject)
     374             :         {
     375           0 :             pOldTObj = pTObject->Clone();
     376           0 :             pThesaurusEngine->SetText(*pTObject);
     377             :         }
     378             :     }
     379             :     else
     380             :     {
     381             :         OSL_FAIL("DoThesaurus: Keine String oder Editzelle");
     382             :     }
     383           0 :     pEditView = GetViewData()->GetEditView(GetViewData()->GetActivePart());
     384           0 :     if (pEditSel)
     385           0 :         pEditView->SetSelection(*pEditSel);
     386             :     else
     387           0 :         pEditView->SetSelection(ESelection(0,0,0,0));
     388             : 
     389           0 :     pThesaurusEngine->ClearModifyFlag();
     390             : 
     391             :     //  language is now in EditEngine attributes -> no longer passed to StartThesaurus
     392             : 
     393           0 :     eState = pEditView->StartThesaurus();
     394             :     OSL_ENSURE(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
     395             : 
     396           0 :     if (eState == EE_SPELL_ERRORFOUND)              // sollte spaeter durch Wrapper geschehen!
     397             :     {
     398           0 :         LanguageType eLnge = ScViewUtil::GetEffLanguage( pDoc, ScAddress( nCol, nRow, nTab ) );
     399           0 :         SvtLanguageTable aLangTab;
     400           0 :         String aErr = aLangTab.GetString(eLnge);
     401           0 :         aErr += ScGlobal::GetRscString( STR_SPELLING_NO_LANG );
     402           0 :         InfoBox aBox( GetViewData()->GetDialogParent(), aErr );
     403           0 :         aBox.Execute();
     404             :     }
     405           0 :     if (pThesaurusEngine->IsModified())
     406             :     {
     407           0 :         EditTextObject* pNewTObj = NULL;
     408           0 :         if (pTObject)
     409             :         {
     410             :             // The cell will own the text object instance.
     411             :             pDoc->SetEditText(
     412           0 :                 ScAddress(nCol,nRow,nTab), pThesaurusEngine->CreateTextObject());
     413             :         }
     414             :         else
     415             :         {
     416           0 :             sNewString = pThesaurusEngine->GetText();
     417           0 :             pDoc->SetString(nCol, nRow, nTab, sNewString);
     418             :         }
     419             : // erack! it's broadcasted
     420             : //      pDoc->SetDirty();
     421           0 :         pDocSh->SetDocumentModified();
     422           0 :         if (bRecord)
     423             :         {
     424           0 :             GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
     425           0 :                 new ScUndoThesaurus( GetViewData()->GetDocShell(),
     426             :                                      nCol, nRow, nTab,
     427           0 :                                      sOldText, pOldTObj, sNewString, pNewTObj));
     428             :         }
     429           0 :         delete pNewTObj;
     430             :     }
     431           0 :     KillEditView(sal_True);
     432           0 :     delete pEditDefaults;
     433           0 :     delete pThesaurusEngine;
     434           0 :     delete pOldTObj;
     435           0 :     pDocSh->PostPaintGridAll();
     436             : }
     437             : 
     438           0 : void ScViewFunc::DoHangulHanjaConversion( sal_Bool bRecord )
     439             : {
     440           0 :     ScConversionParam aConvParam( SC_CONVERSION_HANGULHANJA, LANGUAGE_KOREAN, 0, true );
     441           0 :     DoSheetConversion( aConvParam, bRecord );
     442           0 : }
     443             : 
     444           0 : void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, sal_Bool bRecord )
     445             : {
     446             :     SCCOL nCol;
     447             :     SCROW nRow;
     448             :     SCTAB nTab;
     449           0 :     ScViewData& rViewData = *GetViewData();
     450           0 :     ScDocShell* pDocSh = rViewData.GetDocShell();
     451           0 :     ScDocument* pDoc = pDocSh->GetDocument();
     452           0 :     ScMarkData& rMark = rViewData.GetMarkData();
     453           0 :     ScSplitPos eWhich = rViewData.GetActivePart();
     454           0 :     EditView* pEditView = NULL;
     455           0 :     sal_Bool bIsEditMode = rViewData.HasEditView(eWhich);
     456           0 :     if (bRecord && !pDoc->IsUndoEnabled())
     457           0 :         bRecord = false;
     458           0 :     if (bIsEditMode)                                            // Edit-Mode aktiv
     459             :     {
     460           0 :         rViewData.GetEditView(eWhich, pEditView, nCol, nRow);
     461           0 :         SC_MOD()->InputEnterHandler();
     462             :     }
     463             :     else
     464             :     {
     465           0 :         nCol = rViewData.GetCurX();
     466           0 :         nRow = rViewData.GetCurY();
     467             : 
     468           0 :         AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP);
     469             :     }
     470           0 :     nTab = rViewData.GetTabNo();
     471             : 
     472           0 :     rMark.MarkToMulti();
     473           0 :     sal_Bool bMarked = rMark.IsMultiMarked();
     474           0 :     if (bMarked)
     475             :     {
     476           0 :         ScEditableTester aTester( pDoc, rMark );
     477           0 :         if (!aTester.IsEditable())
     478             :         {
     479           0 :             ErrorMessage(aTester.GetMessageId());
     480           0 :             return;
     481             :         }
     482             :     }
     483             : 
     484           0 :     ScDocument* pUndoDoc = NULL;
     485           0 :     ScDocument* pRedoDoc = NULL;
     486           0 :     if (bRecord)
     487             :     {
     488           0 :         pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
     489           0 :         pUndoDoc->InitUndo( pDoc, nTab, nTab );
     490           0 :         pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
     491           0 :         pRedoDoc->InitUndo( pDoc, nTab, nTab );
     492             : 
     493           0 :         if ( rMark.GetSelectCount() > 1 )
     494             :         {
     495           0 :             ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
     496           0 :             for (; itr != itrEnd; ++itr)
     497           0 :                 if ( *itr != nTab )
     498             :                 {
     499           0 :                     pUndoDoc->AddUndoTab( *itr, *itr );
     500           0 :                     pRedoDoc->AddUndoTab( *itr, *itr );
     501             :                 }
     502             :         }
     503             :     }
     504             : 
     505             :     //  ab hier kein return mehr
     506             : 
     507           0 :     bool bOldEnabled = pDoc->IsIdleEnabled();
     508           0 :     pDoc->EnableIdle(false);   // stop online spelling
     509             : 
     510             :     // *** create and init the edit engine *** --------------------------------
     511             : 
     512           0 :     ScConversionEngineBase* pEngine = NULL;
     513           0 :     switch( rConvParam.GetType() )
     514             :     {
     515             :         case SC_CONVERSION_SPELLCHECK:
     516             :             pEngine = new ScSpellingEngine(
     517           0 :                 pDoc->GetEnginePool(), rViewData, pUndoDoc, pRedoDoc, LinguMgr::GetSpellChecker() );
     518           0 :         break;
     519             :         case SC_CONVERSION_HANGULHANJA:
     520             :         case SC_CONVERSION_CHINESE_TRANSL:
     521             :             pEngine = new ScTextConversionEngine(
     522           0 :                 pDoc->GetEnginePool(), rViewData, rConvParam, pUndoDoc, pRedoDoc );
     523           0 :         break;
     524             :         default:
     525             :             OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" );
     526             :     }
     527             : 
     528           0 :     MakeEditView( pEngine, nCol, nRow );
     529           0 :     pEngine->SetRefDevice( rViewData.GetActiveWin() );
     530             :                                         // dummy Zelle simulieren:
     531           0 :     pEditView = rViewData.GetEditView( rViewData.GetActivePart() );
     532           0 :     rViewData.SetSpellingView( pEditView );
     533           0 :     Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
     534           0 :     pEditView->SetOutputArea( aRect );
     535           0 :     pEngine->SetControlWord( EE_CNTRL_USECHARATTRIBS );
     536           0 :     pEngine->EnableUndo( false );
     537           0 :     pEngine->SetPaperSize( aRect.GetSize() );
     538           0 :     pEngine->SetText( EMPTY_STRING );
     539             : 
     540             :     // *** do the conversion *** ----------------------------------------------
     541             : 
     542           0 :     pEngine->ClearModifyFlag();
     543           0 :     pEngine->ConvertAll( *pEditView );
     544             : 
     545             :     // *** undo/redo *** ------------------------------------------------------
     546             : 
     547           0 :     if( pEngine->IsAnyModified() )
     548             :     {
     549           0 :         if (bRecord)
     550             :         {
     551           0 :             SCCOL nNewCol = rViewData.GetCurX();
     552           0 :             SCROW nNewRow = rViewData.GetCurY();
     553           0 :             rViewData.GetDocShell()->GetUndoManager()->AddUndoAction(
     554             :                 new ScUndoConversion(
     555             :                         pDocSh, rMark,
     556             :                         nCol, nRow, nTab, pUndoDoc,
     557           0 :                         nNewCol, nNewRow, nTab, pRedoDoc, rConvParam ) );
     558             :         }
     559           0 :         pDoc->SetDirty();
     560           0 :         pDocSh->SetDocumentModified();
     561             :     }
     562             :     else
     563             :     {
     564           0 :         delete pUndoDoc;
     565           0 :         delete pRedoDoc;
     566             :     }
     567             : 
     568             :     // *** final cleanup *** --------------------------------------------------
     569             : 
     570           0 :     rViewData.SetSpellingView( NULL );
     571           0 :     KillEditView(sal_True);
     572           0 :     delete pEngine;
     573           0 :     pDocSh->PostPaintGridAll();
     574           0 :     rViewData.GetViewShell()->UpdateInputHandler();
     575           0 :     pDoc->EnableIdle(bOldEnabled);
     576             : }
     577             : 
     578             : // Pasten von FORMAT_FILE-Items
     579             : //  wird nicht direkt aus Drop aufgerufen, sondern asynchron -> Dialoge sind erlaubt
     580             : 
     581           0 : sal_Bool ScViewFunc::PasteFile( const Point& rPos, const String& rFile, sal_Bool bLink )
     582             : {
     583           0 :     INetURLObject aURL;
     584           0 :     aURL.SetSmartURL( rFile );
     585           0 :     String aStrURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
     586             : 
     587             :     // is it a media URL?
     588           0 :     if( ::avmedia::MediaWindow::isMediaURL( aStrURL ) )
     589             :     {
     590           0 :         const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aStrURL );
     591           0 :         return sal_Bool( 0 != GetViewData()->GetDispatcher().Execute(
     592             :                                 SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON,
     593           0 :                                 &aMediaURLItem, 0L ) );
     594             :     }
     595             : 
     596           0 :     if (!bLink)     // bei bLink nur Grafik oder URL
     597             :     {
     598             :         // 1. Kann ich die Datei oeffnen?
     599           0 :         const SfxFilter* pFlt = NULL;
     600             : 
     601             :         // nur nach eigenen Filtern suchen, ohne Auswahlbox (wie in ScDocumentLoader)
     602           0 :         SfxFilterMatcher aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
     603           0 :         SfxMedium aSfxMedium( aStrURL, (STREAM_READ | STREAM_SHARE_DENYNONE) );
     604             :         // #i73992# GuessFilter no longer calls UseInteractionHandler.
     605             :         // This is UI, so it can be called here.
     606           0 :         aSfxMedium.UseInteractionHandler(sal_True);
     607           0 :         ErrCode nErr = aMatcher.GuessFilter( aSfxMedium, &pFlt );
     608             : 
     609           0 :         if ( pFlt && !nErr )
     610             :         {
     611             :             // Code aus dem SFX geklaut!
     612           0 :             SfxDispatcher &rDispatcher = GetViewData()->GetDispatcher();
     613           0 :             SfxStringItem aFileNameItem( SID_FILE_NAME, aStrURL );
     614           0 :             SfxStringItem aFilterItem( SID_FILTER_NAME, pFlt->GetName() );
     615             :             // #i69524# add target, as in SfxApplication when the Open dialog is used
     616           0 :             SfxStringItem aTargetItem( SID_TARGETNAME, OUString("_default") );
     617             : 
     618             :             // Asynchron oeffnen, kann naemlich auch aus D&D heraus passieren
     619             :             // und das bekommt dem MAC nicht so gut ...
     620           0 :             return sal_Bool( 0 != rDispatcher.Execute( SID_OPENDOC,
     621           0 :                                     SFX_CALLMODE_ASYNCHRON, &aFileNameItem, &aFilterItem, &aTargetItem, 0L) );
     622           0 :         }
     623             :     }
     624             : 
     625             :     // 2. Kann die Datei ueber die Grafik-Filter eingefuegt werden?
     626             :     // (als Link, weil Gallery das so anbietet)
     627             : 
     628             :     sal_uInt16 nFilterFormat;
     629           0 :     Graphic aGraphic;
     630           0 :     GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
     631             : 
     632             : 
     633           0 :     if (!rGraphicFilter.ImportGraphic(aGraphic, aURL,
     634           0 :             GRFILTER_FORMAT_DONTKNOW, &nFilterFormat ))
     635             :     {
     636           0 :         if ( bLink )
     637             :         {
     638           0 :             String aFltName = rGraphicFilter.GetImportFormatName(nFilterFormat);
     639           0 :             return PasteGraphic( rPos, aGraphic, aStrURL, aFltName );
     640             :         }
     641             :         else
     642             :         {
     643             :             // #i76709# if bLink isn't set, pass empty URL/filter, so a non-linked image is inserted
     644           0 :             return PasteGraphic( rPos, aGraphic, EMPTY_STRING, EMPTY_STRING );
     645             :         }
     646             :     }
     647             : 
     648           0 :     if (bLink)                      // bei bLink alles, was nicht Grafik ist, als URL
     649             :     {
     650           0 :         Rectangle aRect( rPos, Size(0,0) );
     651             :         ScRange aRange = GetViewData()->GetDocument()->
     652           0 :                             GetRange( GetViewData()->GetTabNo(), aRect );
     653           0 :         SCCOL nPosX = aRange.aStart.Col();
     654           0 :         SCROW nPosY = aRange.aStart.Row();
     655             : 
     656           0 :         InsertBookmark( aStrURL, aStrURL, nPosX, nPosY );
     657           0 :         return sal_True;
     658             :     }
     659             :     else
     660             :     {
     661             :         // 3. Kann die Datei als OLE eingefuegt werden?
     662             :         // auch nicht-Storages, z.B. Sounds (#38282#)
     663           0 :         uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
     664             : 
     665             :         //TODO/LATER: what about "bLink"?
     666             : 
     667           0 :         uno::Sequence < beans::PropertyValue > aMedium(1);
     668           0 :         aMedium[0].Name = OUString( "URL" );
     669           0 :         aMedium[0].Value <<= OUString( aStrURL );
     670             : 
     671           0 :         comphelper::EmbeddedObjectContainer aCnt( xStorage );
     672           0 :         OUString aName;
     673           0 :         uno::Reference < embed::XEmbeddedObject > xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
     674           0 :         if( xObj.is() )
     675           0 :             return PasteObject( rPos, xObj );
     676             : 
     677             :         // If an OLE object can't be created, insert a URL button
     678             : 
     679           0 :         GetViewData()->GetViewShell()->InsertURLButton( aStrURL, aStrURL, EMPTY_STRING, &rPos );
     680           0 :         return sal_True;
     681           0 :     }
     682             : }
     683             : 
     684           0 : sal_Bool ScViewFunc::PasteBookmark( sal_uLong nFormatId,
     685             :                                 const ::com::sun::star::uno::Reference<
     686             :                                     ::com::sun::star::datatransfer::XTransferable >& rxTransferable,
     687             :                                 SCCOL nPosX, SCROW nPosY )
     688             : {
     689           0 :     INetBookmark aBookmark;
     690           0 :     TransferableDataHelper aDataHelper( rxTransferable );
     691           0 :     if ( !aDataHelper.GetINetBookmark( nFormatId, aBookmark ) )
     692           0 :         return false;
     693             : 
     694           0 :     InsertBookmark( aBookmark.GetDescription(), aBookmark.GetURL(), nPosX, nPosY );
     695           0 :     return sal_True;
     696             : }
     697             : 
     698           0 : void ScViewFunc::InsertBookmark( const String& rDescription, const String& rURL,
     699             :                                     SCCOL nPosX, SCROW nPosY, const String* pTarget,
     700             :                                     sal_Bool bTryReplace )
     701             : {
     702           0 :     ScViewData* pViewData = GetViewData();
     703           0 :     if ( pViewData->HasEditView( pViewData->GetActivePart() ) &&
     704           0 :             nPosX >= pViewData->GetEditStartCol() && nPosX <= pViewData->GetEditEndCol() &&
     705           0 :             nPosY >= pViewData->GetEditStartRow() && nPosY <= pViewData->GetEditEndRow() )
     706             :     {
     707             :         //  in die gerade editierte Zelle einfuegen
     708             : 
     709           0 :         String aTargetFrame;
     710           0 :         if (pTarget)
     711           0 :             aTargetFrame = *pTarget;
     712           0 :         pViewData->GetViewShell()->InsertURLField( rDescription, rURL, aTargetFrame );
     713           0 :         return;
     714             :     }
     715             : 
     716             :     //  in nicht editierte Zelle einfuegen
     717             : 
     718           0 :     ScDocument* pDoc = GetViewData()->GetDocument();
     719           0 :     SCTAB nTab = GetViewData()->GetTabNo();
     720           0 :     ScAddress aCellPos( nPosX, nPosY, nTab );
     721           0 :     EditEngine aEngine( pDoc->GetEnginePool() );
     722             : 
     723           0 :     const EditTextObject* pOld = pDoc->GetEditText(aCellPos);
     724           0 :     if (pOld)
     725           0 :         aEngine.SetText(*pOld);
     726             :     else
     727             :     {
     728           0 :         OUString aOld;
     729           0 :         pDoc->GetInputString(nPosX, nPosY, nTab, aOld);
     730           0 :         if (!aOld.isEmpty())
     731           0 :             aEngine.SetText(aOld);
     732             :     }
     733             : 
     734           0 :     sal_Int32 nPara = aEngine.GetParagraphCount();
     735           0 :     if (nPara)
     736           0 :         --nPara;
     737           0 :     xub_StrLen nTxtLen = aEngine.GetTextLen(nPara);
     738           0 :     ESelection aInsSel( nPara, nTxtLen, nPara, nTxtLen );
     739             : 
     740           0 :     if ( bTryReplace && HasBookmarkAtCursor( NULL ) )
     741             :     {
     742             :         //  if called from hyperlink slot and cell contains only a URL,
     743             :         //  replace old URL with new one
     744             : 
     745           0 :         aInsSel = ESelection( 0, 0, 0, 1 );     // replace first character (field)
     746             :     }
     747             : 
     748           0 :     SvxURLField aField( rURL, rDescription, SVXURLFORMAT_APPDEFAULT );
     749           0 :     if (pTarget)
     750           0 :         aField.SetTargetFrame(*pTarget);
     751           0 :     aEngine.QuickInsertField( SvxFieldItem( aField, EE_FEATURE_FIELD ), aInsSel );
     752             : 
     753           0 :     boost::scoped_ptr<EditTextObject> pData(aEngine.CreateTextObject());
     754           0 :     EnterData(nPosX, nPosY, nTab, *pData);
     755             : }
     756             : 
     757           0 : bool ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem* pContent )
     758             : {
     759           0 :     ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
     760           0 :     ScDocument* pDoc = GetViewData()->GetDocShell()->GetDocument();
     761             : 
     762           0 :     const EditTextObject* pData = pDoc->GetEditText(aPos);
     763           0 :     if (!pData)
     764           0 :         return false;
     765             : 
     766           0 :     if (!pData->IsFieldObject())
     767             :         // not a field object.
     768           0 :         return false;
     769             : 
     770           0 :     const SvxFieldItem* pFieldItem = pData->GetField();
     771           0 :     if (!pFieldItem)
     772             :         // doesn't have a field item.
     773           0 :         return false;
     774             : 
     775           0 :     const SvxFieldData* pField = pFieldItem->GetField();
     776           0 :     if (!pField)
     777             :         // doesn't have a field item data.
     778           0 :         return false;
     779             : 
     780           0 :     if (pField->GetClassId() != com::sun::star::text::textfield::Type::URL)
     781             :         // not a URL field.
     782           0 :         return false;
     783             : 
     784           0 :     if (pContent)
     785             :     {
     786           0 :         const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
     787           0 :         pContent->SetName( pURLField->GetRepresentation() );
     788           0 :         pContent->SetURL( pURLField->GetURL() );
     789           0 :         pContent->SetTargetFrame( pURLField->GetTargetFrame() );
     790             :     }
     791           0 :     return true;
     792          93 : }
     793             : 
     794             : 
     795             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10