Update ooo320-m1
[ooovba.git] / sc / source / ui / view / viewfun4.cxx
blobf33bc74aea5d4f8ce893d2c3e2b988c146936d52
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewfun4.cxx,v $
10 * $Revision: 1.39.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
41 #include <svx/editobj.hxx>
42 #include <svx/editstat.hxx>
43 #include <svx/editview.hxx>
44 #include <svx/flditem.hxx>
45 #include <svx/hlnkitem.hxx>
46 #include <svx/langitem.hxx>
47 #include <svx/svxerr.hxx>
48 #include <svx/impgrf.hxx>
49 #include <svx/unolingu.hxx>
51 #include <sfx2/bindings.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <sfx2/docfile.hxx>
54 #include <sfx2/fcontnr.hxx>
55 #include <svtools/langtab.hxx>
56 #include <svtools/filter.hxx>
57 #include <svtools/stritem.hxx>
58 #include <svtools/transfer.hxx>
59 #include <svtools/urlbmk.hxx>
60 #include <vcl/msgbox.hxx>
61 #include <avmedia/mediawindow.hxx>
63 #include <comphelper/storagehelper.hxx>
64 #include <comphelper/processfactory.hxx>
66 #include "viewfunc.hxx"
67 #include "docsh.hxx"
68 #include "docsh.hxx"
69 #include "document.hxx"
70 #include "docpool.hxx"
71 #include "globstr.hrc"
72 #include "global.hxx"
73 #include "undoblk.hxx"
74 #include "undocell.hxx"
75 #include "cell.hxx"
76 #include "scmod.hxx"
77 #include "spelleng.hxx"
78 #include "patattr.hxx"
79 #include "sc.hrc"
80 #include "tabvwsh.hxx"
81 #include "impex.hxx"
82 #include "editutil.hxx"
83 #include "editable.hxx"
84 #include "dociter.hxx"
85 #include "reffind.hxx"
86 #include "compiler.hxx"
88 using namespace com::sun::star;
90 // STATIC DATA -----------------------------------------------------------
92 BOOL bPasteIsDrop = FALSE;
94 //==================================================================
96 void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
97 const ::com::sun::star::uno::Reference<
98 ::com::sun::star::datatransfer::XTransferable >& rxTransferable )
100 TransferableDataHelper aDataHelper( rxTransferable );
101 if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_EDITENGINE ) )
103 HideAllCursors();
105 ScDocument* pUndoDoc = NULL;
107 ScDocShell* pDocSh = GetViewData()->GetDocShell();
108 ScDocument* pDoc = pDocSh->GetDocument();
109 SCTAB nTab = GetViewData()->GetTabNo();
110 const BOOL bRecord (pDoc->IsUndoEnabled());
112 const ScPatternAttr* pPattern = pDoc->GetPattern( nStartCol, nStartRow, nTab );
113 ScTabEditEngine* pEngine = new ScTabEditEngine( *pPattern, pDoc->GetEnginePool() );
114 pEngine->EnableUndo( FALSE );
116 Window* pActWin = GetActiveWin();
117 if (pActWin)
119 pEngine->SetPaperSize(Size(100000,100000));
120 Window aWin( pActWin );
121 EditView aEditView( pEngine, &aWin );
122 aEditView.SetOutputArea(Rectangle(0,0,100000,100000));
124 // same method now for clipboard or drag&drop
125 // mba: clipboard always must contain absolute URLs (could be from alien source)
126 aEditView.InsertText( rxTransferable, String(), TRUE );
129 ULONG nParCnt = pEngine->GetParagraphCount();
130 if (nParCnt)
132 SCROW nEndRow = nStartRow + static_cast<SCROW>(nParCnt) - 1;
133 if (nEndRow > MAXROW)
134 nEndRow = MAXROW;
136 if (bRecord)
138 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
139 pUndoDoc->InitUndo( pDoc, nTab, nTab );
140 pDoc->CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, IDF_ALL, FALSE, pUndoDoc );
143 SCROW nRow = nStartRow;
144 for( USHORT n = 0; n < nParCnt; n++ )
146 EditTextObject* pObject = pEngine->CreateTextObject( n );
147 EnterData( nStartCol, nRow, nTab, pObject, FALSE, TRUE );
148 // kein Undo, auf einfache Strings testen
149 delete pObject;
150 if( ++nRow > MAXROW )
151 break;
154 if (bRecord)
156 ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
157 pRedoDoc->InitUndo( pDoc, nTab, nTab );
158 pDoc->CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, IDF_ALL|IDF_NOCAPTIONS, FALSE, pRedoDoc );
160 ScMarkData aDestMark;
161 aDestMark.SelectOneTable( nTab );
162 pDocSh->GetUndoManager()->AddUndoAction(
163 new ScUndoPaste( pDocSh, nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab,
164 aDestMark,
165 pUndoDoc, pRedoDoc, IDF_ALL, NULL,NULL,NULL,NULL ) );
169 delete pEngine;
171 ShowAllCursors();
173 else
175 HideAllCursors();
176 ScDocShell* pDocSh = GetViewData()->GetDocShell();
177 ScImportExport aImpEx( pDocSh->GetDocument(),
178 ScAddress( nStartCol, nStartRow, GetViewData()->GetTabNo() ) );
180 ::rtl::OUString aStr;
181 SotStorageStreamRef xStream;
182 if ( aDataHelper.GetSotStorageStream( SOT_FORMAT_RTF, xStream ) && xStream.Is() )
183 // mba: clipboard always must contain absolute URLs (could be from alien source)
184 aImpEx.ImportStream( *xStream, String(), SOT_FORMAT_RTF );
185 else if ( aDataHelper.GetString( SOT_FORMAT_RTF, aStr ) )
186 aImpEx.ImportString( aStr, SOT_FORMAT_RTF );
188 AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row() );
189 pDocSh->UpdateOle(GetViewData());
190 ShowAllCursors();
193 void ScViewFunc::DoRefConversion( BOOL bRecord )
195 ScDocument* pDoc = GetViewData()->GetDocument();
196 ScMarkData& rMark = GetViewData()->GetMarkData();
197 SCTAB nTabCount = pDoc->GetTableCount();
198 if (bRecord && !pDoc->IsUndoEnabled())
199 bRecord = FALSE;
201 ScRange aMarkRange;
202 rMark.MarkToSimple();
203 BOOL bMulti = rMark.IsMultiMarked();
204 if (bMulti)
205 rMark.GetMultiMarkArea( aMarkRange );
206 else if (rMark.IsMarked())
207 rMark.GetMarkArea( aMarkRange );
208 else
210 aMarkRange = ScRange( GetViewData()->GetCurX(),
211 GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
213 ScEditableTester aTester( pDoc, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
214 aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(),rMark );
215 if (!aTester.IsEditable())
217 ErrorMessage(aTester.GetMessageId());
218 return;
221 ScDocShell* pDocSh = GetViewData()->GetDocShell();
222 BOOL bOk = FALSE;
224 ScDocument* pUndoDoc = NULL;
225 if (bRecord)
227 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
228 SCTAB nTab = aMarkRange.aStart.Tab();
229 pUndoDoc->InitUndo( pDoc, nTab, nTab );
231 if ( rMark.GetSelectCount() > 1 )
233 for (SCTAB i=0; i<nTabCount; i++)
234 if ( rMark.GetTableSelect(i) && i != nTab )
235 pUndoDoc->AddUndoTab( i, i );
237 ScRange aCopyRange = aMarkRange;
238 aCopyRange.aStart.SetTab(0);
239 aCopyRange.aEnd.SetTab(nTabCount-1);
240 pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pUndoDoc, &rMark );
243 ScRangeListRef xRanges;
244 GetViewData()->GetMultiArea( xRanges );
245 ULONG nCount = xRanges->Count();
247 for (SCTAB i=0; i<nTabCount; i++)
249 if (rMark.GetTableSelect(i))
251 for (ULONG j=0; j<nCount; j++)
253 ScRange aRange = *xRanges->GetObject(j);
254 aRange.aStart.SetTab(i);
255 aRange.aEnd.SetTab(i);
256 ScCellIterator aIter( pDoc, aRange );
257 ScBaseCell* pCell = aIter.GetFirst();
258 while ( pCell )
260 if (pCell->GetCellType() == CELLTYPE_FORMULA)
262 String aOld;
263 ((ScFormulaCell*)pCell)->GetFormula(aOld);
264 xub_StrLen nLen = aOld.Len();
265 ScRefFinder aFinder( aOld, pDoc );
266 aFinder.ToggleRel( 0, nLen );
267 if (aFinder.GetFound())
269 ScAddress aPos = ((ScFormulaCell*)pCell)->aPos;
270 String aNew = aFinder.GetText();
271 ScCompiler aComp( pDoc, aPos);
272 aComp.SetGrammar(pDoc->GetGrammar());
273 ScTokenArray* pArr = aComp.CompileString( aNew );
274 ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos,
275 pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE );
276 pDoc->PutCell( aPos, pNewCell );
277 bOk = TRUE;
280 pCell = aIter.GetNext();
285 if (bRecord)
287 ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
288 SCTAB nTab = aMarkRange.aStart.Tab();
289 pRedoDoc->InitUndo( pDoc, nTab, nTab );
291 if ( rMark.GetSelectCount() > 1 )
293 for (SCTAB i=0; i<nTabCount; i++)
294 if ( rMark.GetTableSelect(i) && i != nTab )
295 pRedoDoc->AddUndoTab( i, i );
297 ScRange aCopyRange = aMarkRange;
298 aCopyRange.aStart.SetTab(0);
299 aCopyRange.aEnd.SetTab(nTabCount-1);
300 pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pRedoDoc, &rMark );
302 pDocSh->GetUndoManager()->AddUndoAction(
303 new ScUndoRefConversion( pDocSh,
304 aMarkRange, rMark, pUndoDoc, pRedoDoc, bMulti, IDF_ALL) );
307 pDocSh->PostPaint( aMarkRange, PAINT_GRID );
308 pDocSh->UpdateOle(GetViewData());
309 pDocSh->SetDocumentModified();
310 CellContentChanged();
312 if (!bOk)
313 ErrorMessage(STR_ERR_NOREF);
315 // Thesaurus - Undo ok
316 void ScViewFunc::DoThesaurus( BOOL bRecord )
318 SCCOL nCol;
319 SCROW nRow;
320 SCTAB nTab;
321 ScDocShell* pDocSh = GetViewData()->GetDocShell();
322 ScDocument* pDoc = pDocSh->GetDocument();
323 ScMarkData& rMark = GetViewData()->GetMarkData();
324 ScSplitPos eWhich = GetViewData()->GetActivePart();
325 CellType eCellType;
326 EESpellState eState;
327 String sOldText, sNewString;
328 EditTextObject* pOldTObj = NULL;
329 const EditTextObject* pTObject = NULL;
330 ScBaseCell* pCell = NULL;
331 EditView* pEditView = NULL;
332 ESelection* pEditSel = NULL;
333 ScEditEngineDefaulter* pThesaurusEngine;
334 BOOL bIsEditMode = GetViewData()->HasEditView(eWhich);
335 if (bRecord && !pDoc->IsUndoEnabled())
336 bRecord = FALSE;
337 if (bIsEditMode) // Edit-Mode aktiv
339 GetViewData()->GetEditView(eWhich, pEditView, nCol, nRow);
340 pEditSel = new ESelection(pEditView->GetSelection());
341 SC_MOD()->InputEnterHandler();
342 GetViewData()->GetBindings().Update(); // sonst kommt der Sfx durcheinander...
344 else
346 nCol = GetViewData()->GetCurX();
347 nRow = GetViewData()->GetCurY();
349 nTab = GetViewData()->GetTabNo();
351 ScEditableTester aTester( pDoc, nCol, nRow, nCol, nRow, rMark );
352 if (!aTester.IsEditable())
354 ErrorMessage(aTester.GetMessageId());
355 delete pEditSel;
356 return;
358 pDoc->GetCellType(nCol, nRow, nTab, eCellType);
359 if (eCellType != CELLTYPE_STRING && eCellType != CELLTYPE_EDIT)
361 ErrorMessage(STR_THESAURUS_NO_STRING);
362 return;
365 com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1>
366 xSpeller = LinguMgr::GetSpellChecker();
367 //! if (...) // thesaurus not available
368 //! {
369 //! ErrorMessage(STR_EXPORT_ASCII_WARNING);
370 //! delete pEditSel;
371 //! return;
372 //! }
374 pThesaurusEngine = new ScEditEngineDefaulter( pDoc->GetEnginePool() );
375 pThesaurusEngine->SetEditTextObjectPool( pDoc->GetEditPool() );
376 pThesaurusEngine->SetRefDevice(GetViewData()->GetActiveWin());
377 pThesaurusEngine->SetSpeller(xSpeller);
378 MakeEditView(pThesaurusEngine, nCol, nRow );
379 const ScPatternAttr* pPattern = NULL;
380 SfxItemSet* pEditDefaults = new SfxItemSet(pThesaurusEngine->GetEmptyItemSet());
381 pPattern = pDoc->GetPattern(nCol, nRow, nTab);
382 if (pPattern )
384 pPattern->FillEditItemSet( pEditDefaults );
385 pThesaurusEngine->SetDefaults( *pEditDefaults );
388 if (eCellType == CELLTYPE_STRING)
390 pDoc->GetString(nCol, nRow, nTab, sOldText);
391 pThesaurusEngine->SetText(sOldText);
393 else if (eCellType == CELLTYPE_EDIT)
395 pDoc->GetCell(nCol, nRow, nTab, pCell);
396 if (pCell)
398 ((ScEditCell*) pCell)->GetData(pTObject);
399 pOldTObj = pTObject->Clone();
400 if (pTObject)
401 pThesaurusEngine->SetText(*pTObject);
404 else
406 DBG_ERROR("DoThesaurus: Keine String oder Editzelle");
408 pEditView = GetViewData()->GetEditView(GetViewData()->GetActivePart());;
409 if (pEditSel)
410 pEditView->SetSelection(*pEditSel);
411 else
412 pEditView->SetSelection(ESelection(0,0,0,0));
414 pThesaurusEngine->ClearModifyFlag();
416 // language is now in EditEngine attributes -> no longer passed to StartThesaurus
418 eState = pEditView->StartThesaurus();
419 DBG_ASSERT(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
421 if (eState == EE_SPELL_ERRORFOUND) // sollte spaeter durch Wrapper geschehen!
423 LanguageType eLnge = ScViewUtil::GetEffLanguage( pDoc, ScAddress( nCol, nRow, nTab ) );
424 SvtLanguageTable aLangTab;
425 String aErr = aLangTab.GetString(eLnge);
426 aErr += ScGlobal::GetRscString( STR_SPELLING_NO_LANG );
427 InfoBox aBox( GetViewData()->GetDialogParent(), aErr );
428 aBox.Execute();
430 if (pThesaurusEngine->IsModified())
432 EditTextObject* pNewTObj = NULL;
433 if (pCell && pTObject)
435 pNewTObj = pThesaurusEngine->CreateTextObject();
436 pCell = new ScEditCell( pNewTObj, pDoc,
437 pThesaurusEngine->GetEditTextObjectPool() );
438 pDoc->PutCell( nCol, nRow, nTab, pCell );
440 else
442 sNewString = pThesaurusEngine->GetText();
443 pDoc->SetString(nCol, nRow, nTab, sNewString);
445 // erack! it's broadcasted
446 // pDoc->SetDirty();
447 pDocSh->SetDocumentModified();
448 if (bRecord)
450 GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
451 new ScUndoThesaurus( GetViewData()->GetDocShell(),
452 nCol, nRow, nTab,
453 sOldText, pOldTObj, sNewString, pNewTObj));
455 delete pNewTObj;
457 KillEditView(TRUE);
458 delete pEditDefaults;
459 delete pThesaurusEngine;
460 delete pOldTObj;
461 delete pEditSel;
462 pDocSh->PostPaintGridAll();
465 //UNUSED2008-05 // Spelling Checker - Undo ok
466 //UNUSED2008-05 void ScViewFunc::DoSpellingChecker( BOOL bRecord )
467 //UNUSED2008-05 {
468 //UNUSED2008-05 DoSheetConversion( ScConversionParam( SC_CONVERSION_SPELLCHECK ), bRecord );
469 //UNUSED2008-05 }
471 void ScViewFunc::DoHangulHanjaConversion( BOOL bRecord )
473 ScConversionParam aConvParam( SC_CONVERSION_HANGULHANJA, LANGUAGE_KOREAN, 0, true );
474 DoSheetConversion( aConvParam, bRecord );
477 void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, BOOL bRecord )
479 SCCOL nCol;
480 SCROW nRow;
481 SCTAB nTab;
482 ScViewData& rViewData = *GetViewData();
483 ScDocShell* pDocSh = rViewData.GetDocShell();
484 ScDocument* pDoc = pDocSh->GetDocument();
485 ScMarkData& rMark = rViewData.GetMarkData();
486 ScSplitPos eWhich = rViewData.GetActivePart();
487 EditView* pEditView = NULL;
488 ESelection* pEditSel = NULL;
489 BOOL bIsEditMode = rViewData.HasEditView(eWhich);
490 if (bRecord && !pDoc->IsUndoEnabled())
491 bRecord = FALSE;
492 if (bIsEditMode) // Edit-Mode aktiv
494 rViewData.GetEditView(eWhich, pEditView, nCol, nRow);
495 pEditSel = new ESelection(pEditView->GetSelection());
496 SC_MOD()->InputEnterHandler();
498 else
500 nCol = rViewData.GetCurX();
501 nRow = rViewData.GetCurY();
503 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP);
505 nTab = rViewData.GetTabNo();
507 rMark.MarkToMulti();
508 BOOL bMarked = rMark.IsMultiMarked();
509 if (bMarked)
511 ScEditableTester aTester( pDoc, rMark );
512 if (!aTester.IsEditable())
514 ErrorMessage(aTester.GetMessageId());
515 delete pEditSel;
516 return;
520 ScDocument* pUndoDoc = NULL;
521 ScDocument* pRedoDoc = NULL;
522 if (bRecord)
524 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
525 pUndoDoc->InitUndo( pDoc, nTab, nTab );
526 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
527 pRedoDoc->InitUndo( pDoc, nTab, nTab );
529 if ( rMark.GetSelectCount() > 1 )
531 SCTAB nTabCount = pDoc->GetTableCount();
532 for (SCTAB i=0; i<nTabCount; i++)
533 if ( rMark.GetTableSelect(i) && i != nTab )
535 pUndoDoc->AddUndoTab( i, i );
536 pRedoDoc->AddUndoTab( i, i );
541 // ab hier kein return mehr
543 BOOL bOldDis = pDoc->IsIdleDisabled();
544 pDoc->DisableIdle( TRUE ); // #42726# stop online spelling
546 // *** create and init the edit engine *** --------------------------------
548 ScConversionEngineBase* pEngine = NULL;
549 switch( rConvParam.GetType() )
551 case SC_CONVERSION_SPELLCHECK:
552 pEngine = new ScSpellingEngine(
553 pDoc->GetEnginePool(), rViewData, pUndoDoc, pRedoDoc, LinguMgr::GetSpellChecker() );
554 break;
555 case SC_CONVERSION_HANGULHANJA:
556 case SC_CONVERSION_CHINESE_TRANSL:
557 pEngine = new ScTextConversionEngine(
558 pDoc->GetEnginePool(), rViewData, rConvParam, pUndoDoc, pRedoDoc );
559 break;
560 default:
561 DBG_ERRORFILE( "ScViewFunc::DoSheetConversion - unknown conversion type" );
564 MakeEditView( pEngine, nCol, nRow );
565 pEngine->SetRefDevice( rViewData.GetActiveWin() );
566 // dummy Zelle simulieren:
567 pEditView = rViewData.GetEditView( rViewData.GetActivePart() );
568 rViewData.SetSpellingView( pEditView );
569 Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
570 pEditView->SetOutputArea( aRect );
571 pEngine->SetControlWord( EE_CNTRL_USECHARATTRIBS );
572 pEngine->EnableUndo( FALSE );
573 pEngine->SetPaperSize( aRect.GetSize() );
574 pEngine->SetText( EMPTY_STRING );
576 // *** do the conversion *** ----------------------------------------------
578 pEngine->ClearModifyFlag();
579 pEngine->ConvertAll( *pEditView );
581 // *** undo/redo *** ------------------------------------------------------
583 if( pEngine->IsAnyModified() )
585 if (bRecord)
587 SCCOL nNewCol = rViewData.GetCurX();
588 SCROW nNewRow = rViewData.GetCurY();
589 rViewData.GetDocShell()->GetUndoManager()->AddUndoAction(
590 new ScUndoConversion(
591 pDocSh, rMark,
592 nCol, nRow, nTab, pUndoDoc,
593 nNewCol, nNewRow, nTab, pRedoDoc, rConvParam ) );
595 pDoc->SetDirty();
596 pDocSh->SetDocumentModified();
598 else
600 delete pUndoDoc;
601 delete pRedoDoc;
604 // *** final cleanup *** --------------------------------------------------
606 rViewData.SetSpellingView( NULL );
607 KillEditView(TRUE);
608 delete pEngine;
609 delete pEditSel;
610 pDocSh->PostPaintGridAll();
611 rViewData.GetViewShell()->UpdateInputHandler();
612 pDoc->DisableIdle(bOldDis);
616 //UNUSED2008-05 IMPL_LINK_INLINE_START( ScViewFunc, SpellError, void *, nLang )
617 //UNUSED2008-05 {
618 //UNUSED2008-05 SvtLanguageTable aLangTab;
619 //UNUSED2008-05 String aErr = aLangTab.GetString((LanguageType) (ULONG) nLang);
620 //UNUSED2008-05 ErrorHandler::HandleError(*new StringErrorInfo(
621 //UNUSED2008-05 ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS, aErr) );
622 //UNUSED2008-05
623 //UNUSED2008-05 return 0;
624 //UNUSED2008-05 }
625 //UNUSED2008-05 IMPL_LINK_INLINE_END( ScViewFunc, SpellError, void *, nLang )
627 // Pasten von FORMAT_FILE-Items
628 // wird nicht direkt aus Drop aufgerufen, sondern asynchron -> Dialoge sind erlaubt
630 BOOL ScViewFunc::PasteFile( const Point& rPos, const String& rFile, BOOL bLink )
632 INetURLObject aURL;
633 aURL.SetSmartURL( rFile );
634 String aStrURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
636 // is it a media URL?
637 if( ::avmedia::MediaWindow::isMediaURL( aStrURL ) )
639 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aStrURL );
640 return BOOL( 0 != GetViewData()->GetDispatcher().Execute(
641 SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON,
642 &aMediaURLItem, 0L ) );
645 if (!bLink) // bei bLink nur Grafik oder URL
647 // 1. Kann ich die Datei oeffnen?
648 const SfxFilter* pFlt = NULL;
650 // nur nach eigenen Filtern suchen, ohne Auswahlbox (wie in ScDocumentLoader)
651 SfxFilterMatcher aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
652 SfxMedium aSfxMedium( aStrURL, (STREAM_READ | STREAM_SHARE_DENYNONE), FALSE );
653 // #i73992# GuessFilter no longer calls UseInteractionHandler.
654 // This is UI, so it can be called here.
655 aSfxMedium.UseInteractionHandler(TRUE);
656 ErrCode nErr = aMatcher.GuessFilter( aSfxMedium, &pFlt );
658 if ( pFlt && !nErr )
660 // Code aus dem SFX geklaut!
661 SfxDispatcher &rDispatcher = GetViewData()->GetDispatcher();
662 SfxStringItem aFileNameItem( SID_FILE_NAME, aStrURL );
663 SfxStringItem aFilterItem( SID_FILTER_NAME, pFlt->GetName() );
664 // #i69524# add target, as in SfxApplication when the Open dialog is used
665 SfxStringItem aTargetItem( SID_TARGETNAME, String::CreateFromAscii("_default") );
667 // Asynchron oeffnen, kann naemlich auch aus D&D heraus passieren
668 // und das bekommt dem MAC nicht so gut ...
669 return BOOL( 0 != rDispatcher.Execute( SID_OPENDOC,
670 SFX_CALLMODE_ASYNCHRON, &aFileNameItem, &aFilterItem, &aTargetItem, 0L) );
674 // 2. Kann die Datei ueber die Grafik-Filter eingefuegt werden?
675 // (als Link, weil Gallery das so anbietet)
677 USHORT nFilterFormat;
678 Graphic aGraphic;
679 GraphicFilter* pGraphicFilter = ::GetGrfFilter();
681 // GraphicProgress aGraphicProgress(&aGraphicFilter);
683 if (!pGraphicFilter->ImportGraphic(aGraphic, aURL,
684 GRFILTER_FORMAT_DONTKNOW, &nFilterFormat ))
686 if ( bLink )
688 String aFltName = pGraphicFilter->GetImportFormatName(nFilterFormat);
689 return PasteGraphic( rPos, aGraphic, aStrURL, aFltName );
691 else
693 // #i76709# if bLink isn't set, pass empty URL/filter, so a non-linked image is inserted
694 return PasteGraphic( rPos, aGraphic, EMPTY_STRING, EMPTY_STRING );
698 if (bLink) // bei bLink alles, was nicht Grafik ist, als URL
700 Rectangle aRect( rPos, Size(0,0) );
701 ScRange aRange = GetViewData()->GetDocument()->
702 GetRange( GetViewData()->GetTabNo(), aRect );
703 SCCOL nPosX = aRange.aStart.Col();
704 SCROW nPosY = aRange.aStart.Row();
706 InsertBookmark( aStrURL, aStrURL, nPosX, nPosY );
707 return TRUE;
709 else
711 // 3. Kann die Datei als OLE eingefuegt werden?
712 // auch nicht-Storages, z.B. Sounds (#38282#)
713 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
715 //TODO/LATER: what about "bLink"?
717 uno::Sequence < beans::PropertyValue > aMedium(1);
718 aMedium[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
719 aMedium[0].Value <<= ::rtl::OUString( aStrURL );
721 comphelper::EmbeddedObjectContainer aCnt( xStorage );
722 ::rtl::OUString aName;
723 uno::Reference < embed::XEmbeddedObject > xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
724 if( xObj.is() )
725 return PasteObject( rPos, xObj );
727 // #105851# If an OLE object can't be created, insert a URL button
729 GetViewData()->GetViewShell()->InsertURLButton( aStrURL, aStrURL, EMPTY_STRING, &rPos );
730 return TRUE;
734 BOOL ScViewFunc::PasteBookmark( ULONG nFormatId,
735 const ::com::sun::star::uno::Reference<
736 ::com::sun::star::datatransfer::XTransferable >& rxTransferable,
737 SCCOL nPosX, SCROW nPosY )
739 INetBookmark aBookmark;
740 TransferableDataHelper aDataHelper( rxTransferable );
741 if ( !aDataHelper.GetINetBookmark( nFormatId, aBookmark ) )
742 return FALSE;
744 InsertBookmark( aBookmark.GetDescription(), aBookmark.GetURL(), nPosX, nPosY );
745 return TRUE;
748 void ScViewFunc::InsertBookmark( const String& rDescription, const String& rURL,
749 SCCOL nPosX, SCROW nPosY, const String* pTarget,
750 BOOL bTryReplace )
752 ScViewData* pViewData = GetViewData();
753 if ( pViewData->HasEditView( pViewData->GetActivePart() ) &&
754 nPosX >= pViewData->GetEditStartCol() && nPosX <= pViewData->GetEditEndCol() &&
755 nPosY >= pViewData->GetEditStartRow() && nPosY <= pViewData->GetEditEndRow() )
757 // in die gerade editierte Zelle einfuegen
759 String aTargetFrame;
760 if (pTarget)
761 aTargetFrame = *pTarget;
762 pViewData->GetViewShell()->InsertURLField( rDescription, rURL, aTargetFrame );
763 return;
766 // in nicht editierte Zelle einfuegen
768 ScDocument* pDoc = GetViewData()->GetDocument();
769 SCTAB nTab = GetViewData()->GetTabNo();
770 ScAddress aCellPos( nPosX, nPosY, nTab );
771 ScBaseCell* pCell = pDoc->GetCell( aCellPos );
772 EditEngine aEngine( pDoc->GetEnginePool() );
773 if (pCell)
775 if (pCell->GetCellType() == CELLTYPE_EDIT)
777 const EditTextObject* pOld = ((ScEditCell*)pCell)->GetData();
778 if (pOld)
779 aEngine.SetText(*pOld);
781 else
783 String aOld;
784 pDoc->GetInputString( nPosX, nPosY, nTab, aOld );
785 if (aOld.Len())
786 aEngine.SetText(aOld);
790 USHORT nPara = aEngine.GetParagraphCount();
791 if (nPara)
792 --nPara;
793 xub_StrLen nTxtLen = aEngine.GetTextLen(nPara);
794 ESelection aInsSel( nPara, nTxtLen, nPara, nTxtLen );
796 if ( bTryReplace && HasBookmarkAtCursor( NULL ) )
798 // if called from hyperlink slot and cell contains only a URL,
799 // replace old URL with new one
801 aInsSel = ESelection( 0, 0, 0, 1 ); // replace first character (field)
804 SvxURLField aField( rURL, rDescription, SVXURLFORMAT_APPDEFAULT );
805 if (pTarget)
806 aField.SetTargetFrame(*pTarget);
807 aEngine.QuickInsertField( SvxFieldItem( aField, EE_FEATURE_FIELD ), aInsSel );
809 EditTextObject* pData = aEngine.CreateTextObject();
810 EnterData( nPosX, nPosY, nTab, pData );
811 delete pData;
814 BOOL ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem* pContent )
816 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
817 ScDocument* pDoc = GetViewData()->GetDocShell()->GetDocument();
819 ScBaseCell* pCell = pDoc->GetCell( aPos );
820 if ( pCell && pCell->GetCellType() == CELLTYPE_EDIT )
822 const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
823 if (pData)
825 BOOL bField = pData->IsFieldObject();
826 if (bField)
828 const SvxFieldItem* pFieldItem = pData->GetField();
829 if (pFieldItem)
831 const SvxFieldData* pField = pFieldItem->GetField();
832 if ( pField && pField->ISA(SvxURLField) )
834 if (pContent)
836 const SvxURLField* pURLField = (const SvxURLField*)pField;
837 pContent->SetName( pURLField->GetRepresentation() );
838 pContent->SetURL( pURLField->GetURL() );
839 pContent->SetTargetFrame( pURLField->GetTargetFrame() );
841 return TRUE;
847 return FALSE;