1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
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>
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>
44 #include <comphelper/storagehelper.hxx>
45 #include <comphelper/processfactory.hxx>
47 #include "viewfunc.hxx"
49 #include "document.hxx"
50 #include "docpool.hxx"
51 #include "globstr.hrc"
53 #include "undoblk.hxx"
54 #include "undocell.hxx"
55 #include "formulacell.hxx"
57 #include "spelleng.hxx"
58 #include "patattr.hxx"
60 #include "tabvwsh.hxx"
62 #include "editutil.hxx"
63 #include "editable.hxx"
64 #include "dociter.hxx"
65 #include "reffind.hxx"
66 #include "compiler.hxx"
67 #include "tokenarray.hxx"
69 #include <boost/scoped_ptr.hpp>
71 using namespace com::sun::star
;
73 // STATIC DATA -----------------------------------------------------------
75 sal_Bool bPasteIsDrop
= false;
77 //==================================================================
79 void ScViewFunc::PasteRTF( SCCOL nStartCol
, SCROW nStartRow
,
80 const ::com::sun::star::uno::Reference
<
81 ::com::sun::star::datatransfer::XTransferable
>& rxTransferable
)
83 TransferableDataHelper
aDataHelper( rxTransferable
);
84 if ( aDataHelper
.HasFormat( SOT_FORMATSTR_ID_EDITENGINE
) )
89 ScDocShell
* pDocSh
= GetViewData()->GetDocShell();
90 ScDocument
* pDoc
= pDocSh
->GetDocument();
91 SCTAB nTab
= GetViewData()->GetTabNo();
92 const sal_Bool
bRecord (pDoc
->IsUndoEnabled());
94 const ScPatternAttr
* pPattern
= pDoc
->GetPattern( nStartCol
, nStartRow
, nTab
);
95 ScTabEditEngine
* pEngine
= new ScTabEditEngine( *pPattern
, pDoc
->GetEnginePool() );
96 pEngine
->EnableUndo( false );
98 Window
* pActWin
= GetActiveWin();
101 pEngine
->SetPaperSize(Size(100000,100000));
102 Window
aWin( pActWin
);
103 EditView
aEditView( pEngine
, &aWin
);
104 aEditView
.SetOutputArea(Rectangle(0,0,100000,100000));
106 // same method now for clipboard or drag&drop
107 // mba: clipboard always must contain absolute URLs (could be from alien source)
108 aEditView
.InsertText( rxTransferable
, OUString(), sal_True
);
111 sal_Int32 nParCnt
= pEngine
->GetParagraphCount();
114 SCROW nEndRow
= nStartRow
+ static_cast<SCROW
>(nParCnt
) - 1;
115 if (nEndRow
> MAXROW
)
118 ScDocument
* pUndoDoc
= NULL
;
121 pUndoDoc
= new ScDocument( SCDOCMODE_UNDO
);
122 pUndoDoc
->InitUndo( pDoc
, nTab
, nTab
);
123 pDoc
->CopyToDocument( nStartCol
,nStartRow
,nTab
, nStartCol
,nEndRow
,nTab
, IDF_ALL
, false, pUndoDoc
);
126 SCROW nRow
= nStartRow
;
128 // Temporarily turn off undo generation for this lot
129 bool bUndoEnabled
= pDoc
->IsUndoEnabled();
130 pDoc
->EnableUndo( false );
131 for( sal_Int32 n
= 0; n
< nParCnt
; n
++ )
133 boost::scoped_ptr
<EditTextObject
> pObject(pEngine
->CreateTextObject(n
));
134 EnterData(nStartCol
, nRow
, nTab
, *pObject
, true);
135 if( ++nRow
> MAXROW
)
138 pDoc
->EnableUndo(bUndoEnabled
);
142 ScDocument
* pRedoDoc
= new ScDocument( SCDOCMODE_UNDO
);
143 pRedoDoc
->InitUndo( pDoc
, nTab
, nTab
);
144 pDoc
->CopyToDocument( nStartCol
,nStartRow
,nTab
, nStartCol
,nEndRow
,nTab
, IDF_ALL
|IDF_NOCAPTIONS
, false, pRedoDoc
);
146 ScRange
aMarkRange(nStartCol
, nStartRow
, nTab
, nStartCol
, nEndRow
, nTab
);
147 ScMarkData aDestMark
;
148 aDestMark
.SetMarkArea( aMarkRange
);
149 pDocSh
->GetUndoManager()->AddUndoAction(
150 new ScUndoPaste( pDocSh
, aMarkRange
, aDestMark
,
151 pUndoDoc
, pRedoDoc
, IDF_ALL
, NULL
));
162 ScDocShell
* pDocSh
= GetViewData()->GetDocShell();
163 ScImportExport
aImpEx( pDocSh
->GetDocument(),
164 ScAddress( nStartCol
, nStartRow
, GetViewData()->GetTabNo() ) );
167 SotStorageStreamRef xStream
;
168 if ( aDataHelper
.GetSotStorageStream( SOT_FORMAT_RTF
, xStream
) && xStream
.Is() )
169 // mba: clipboard always must contain absolute URLs (could be from alien source)
170 aImpEx
.ImportStream( *xStream
, OUString(), SOT_FORMAT_RTF
);
171 else if ( aDataHelper
.GetString( SOT_FORMAT_RTF
, aStr
) )
172 aImpEx
.ImportString( aStr
, SOT_FORMAT_RTF
);
174 AdjustRowHeight( nStartRow
, aImpEx
.GetRange().aEnd
.Row() );
175 pDocSh
->UpdateOle(GetViewData());
179 void ScViewFunc::DoRefConversion( sal_Bool bRecord
)
181 ScDocument
* pDoc
= GetViewData()->GetDocument();
182 ScMarkData
& rMark
= GetViewData()->GetMarkData();
183 SCTAB nTabCount
= pDoc
->GetTableCount();
184 if (bRecord
&& !pDoc
->IsUndoEnabled())
188 rMark
.MarkToSimple();
189 sal_Bool bMulti
= rMark
.IsMultiMarked();
191 rMark
.GetMultiMarkArea( aMarkRange
);
192 else if (rMark
.IsMarked())
193 rMark
.GetMarkArea( aMarkRange
);
196 aMarkRange
= ScRange( GetViewData()->GetCurX(),
197 GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
199 ScEditableTester
aTester( pDoc
, aMarkRange
.aStart
.Col(), aMarkRange
.aStart
.Row(),
200 aMarkRange
.aEnd
.Col(), aMarkRange
.aEnd
.Row(),rMark
);
201 if (!aTester
.IsEditable())
203 ErrorMessage(aTester
.GetMessageId());
207 ScDocShell
* pDocSh
= GetViewData()->GetDocShell();
208 sal_Bool bOk
= false;
210 ScDocument
* pUndoDoc
= NULL
;
213 pUndoDoc
= new ScDocument( SCDOCMODE_UNDO
);
214 SCTAB nTab
= aMarkRange
.aStart
.Tab();
215 pUndoDoc
->InitUndo( pDoc
, nTab
, nTab
);
217 if ( rMark
.GetSelectCount() > 1 )
219 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
220 for (; itr
!= itrEnd
; ++itr
)
222 pUndoDoc
->AddUndoTab( *itr
, *itr
);
224 ScRange aCopyRange
= aMarkRange
;
225 aCopyRange
.aStart
.SetTab(0);
226 aCopyRange
.aEnd
.SetTab(nTabCount
-1);
227 pDoc
->CopyToDocument( aCopyRange
, IDF_ALL
, bMulti
, pUndoDoc
, &rMark
);
230 ScRangeListRef xRanges
;
231 GetViewData()->GetMultiArea( xRanges
);
232 size_t nCount
= xRanges
->size();
234 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
235 for (; itr
!= itrEnd
; ++itr
)
238 for (size_t j
= 0; j
< nCount
; ++j
)
240 ScRange aRange
= *(*xRanges
)[j
];
241 aRange
.aStart
.SetTab(i
);
242 aRange
.aEnd
.SetTab(i
);
243 ScCellIterator
aIter( pDoc
, aRange
);
244 for (bool bHas
= aIter
.first(); bHas
; bHas
= aIter
.next())
246 if (aIter
.getType() != CELLTYPE_FORMULA
)
249 ScFormulaCell
* pCell
= aIter
.getFormulaCell();
251 pCell
->GetFormula(aOld
);
252 sal_Int32 nLen
= aOld
.getLength();
253 ScRefFinder
aFinder( aOld
, aIter
.GetPos(), pDoc
, pDoc
->GetAddressConvention() );
254 aFinder
.ToggleRel( 0, nLen
);
255 if (aFinder
.GetFound())
257 ScAddress aPos
= pCell
->aPos
;
258 OUString aNew
= aFinder
.GetText();
259 ScCompiler
aComp( pDoc
, aPos
);
260 aComp
.SetGrammar(pDoc
->GetGrammar());
261 boost::scoped_ptr
<ScTokenArray
> pArr(aComp
.CompileString(aNew
));
262 ScFormulaCell
* pNewCell
=
264 pDoc
, aPos
, *pArr
, formula::FormulaGrammar::GRAM_DEFAULT
, MM_NONE
);
266 pDoc
->SetFormulaCell(aPos
, pNewCell
);
274 ScDocument
* pRedoDoc
= new ScDocument( SCDOCMODE_UNDO
);
275 SCTAB nTab
= aMarkRange
.aStart
.Tab();
276 pRedoDoc
->InitUndo( pDoc
, nTab
, nTab
);
278 if ( rMark
.GetSelectCount() > 1 )
281 for (; itr
!= itrEnd
; ++itr
)
283 pRedoDoc
->AddUndoTab( *itr
, *itr
);
285 ScRange aCopyRange
= aMarkRange
;
286 aCopyRange
.aStart
.SetTab(0);
287 aCopyRange
.aEnd
.SetTab(nTabCount
-1);
288 pDoc
->CopyToDocument( aCopyRange
, IDF_ALL
, bMulti
, pRedoDoc
, &rMark
);
290 pDocSh
->GetUndoManager()->AddUndoAction(
291 new ScUndoRefConversion( pDocSh
,
292 aMarkRange
, rMark
, pUndoDoc
, pRedoDoc
, bMulti
, IDF_ALL
) );
295 pDocSh
->PostPaint( aMarkRange
, PAINT_GRID
);
296 pDocSh
->UpdateOle(GetViewData());
297 pDocSh
->SetDocumentModified();
298 CellContentChanged();
301 ErrorMessage(STR_ERR_NOREF
);
303 // Thesaurus - Undo ok
304 void ScViewFunc::DoThesaurus( sal_Bool bRecord
)
309 ScDocShell
* pDocSh
= GetViewData()->GetDocShell();
310 ScDocument
* pDoc
= pDocSh
->GetDocument();
311 ScMarkData
& rMark
= GetViewData()->GetMarkData();
312 ScSplitPos eWhich
= GetViewData()->GetActivePart();
314 OUString sOldText
, sNewString
;
315 EditTextObject
* pOldTObj
= NULL
;
316 const EditTextObject
* pTObject
= NULL
;
317 EditView
* pEditView
= NULL
;
318 boost::scoped_ptr
<ESelection
> pEditSel
;
319 ScEditEngineDefaulter
* pThesaurusEngine
;
320 sal_Bool bIsEditMode
= GetViewData()->HasEditView(eWhich
);
321 if (bRecord
&& !pDoc
->IsUndoEnabled())
323 if (bIsEditMode
) // Edit-Mode aktiv
325 GetViewData()->GetEditView(eWhich
, pEditView
, nCol
, nRow
);
326 pEditSel
.reset(new ESelection(pEditView
->GetSelection()));
327 SC_MOD()->InputEnterHandler();
328 GetViewData()->GetBindings().Update(); // sonst kommt der Sfx durcheinander...
332 nCol
= GetViewData()->GetCurX();
333 nRow
= GetViewData()->GetCurY();
335 nTab
= GetViewData()->GetTabNo();
337 ScAddress
aPos(nCol
, nRow
, nTab
);
338 ScEditableTester
aTester( pDoc
, nCol
, nRow
, nCol
, nRow
, rMark
);
339 if (!aTester
.IsEditable())
341 ErrorMessage(aTester
.GetMessageId());
345 CellType eCellType
= pDoc
->GetCellType(aPos
);
346 if (eCellType
!= CELLTYPE_STRING
&& eCellType
!= CELLTYPE_EDIT
)
348 ErrorMessage(STR_THESAURUS_NO_STRING
);
352 uno::Reference
<linguistic2::XSpellChecker1
> xSpeller
= LinguMgr::GetSpellChecker();
354 pThesaurusEngine
= new ScEditEngineDefaulter( pDoc
->GetEnginePool() );
355 pThesaurusEngine
->SetEditTextObjectPool( pDoc
->GetEditPool() );
356 pThesaurusEngine
->SetRefDevice(GetViewData()->GetActiveWin());
357 pThesaurusEngine
->SetSpeller(xSpeller
);
358 MakeEditView(pThesaurusEngine
, nCol
, nRow
);
359 const ScPatternAttr
* pPattern
= NULL
;
360 SfxItemSet
* pEditDefaults
= new SfxItemSet(pThesaurusEngine
->GetEmptyItemSet());
361 pPattern
= pDoc
->GetPattern(nCol
, nRow
, nTab
);
364 pPattern
->FillEditItemSet( pEditDefaults
);
365 pThesaurusEngine
->SetDefaults( *pEditDefaults
);
368 if (eCellType
== CELLTYPE_STRING
)
370 sOldText
= pDoc
->GetString(aPos
);
371 pThesaurusEngine
->SetText(sOldText
);
373 else if (eCellType
== CELLTYPE_EDIT
)
375 pTObject
= pDoc
->GetEditText(aPos
);
378 pOldTObj
= pTObject
->Clone();
379 pThesaurusEngine
->SetText(*pTObject
);
384 OSL_FAIL("DoThesaurus: Keine String oder Editzelle");
386 pEditView
= GetViewData()->GetEditView(GetViewData()->GetActivePart());
388 pEditView
->SetSelection(*pEditSel
);
390 pEditView
->SetSelection(ESelection(0,0,0,0));
392 pThesaurusEngine
->ClearModifyFlag();
394 // language is now in EditEngine attributes -> no longer passed to StartThesaurus
396 eState
= pEditView
->StartThesaurus();
397 OSL_ENSURE(eState
!= EE_SPELL_NOSPELLER
, "No SpellChecker");
399 if (eState
== EE_SPELL_ERRORFOUND
) // sollte spaeter durch Wrapper geschehen!
401 LanguageType eLnge
= ScViewUtil::GetEffLanguage( pDoc
, ScAddress( nCol
, nRow
, nTab
) );
402 SvtLanguageTable aLangTab
;
403 OUString aErr
= aLangTab
.GetString(eLnge
);
404 aErr
+= ScGlobal::GetRscString( STR_SPELLING_NO_LANG
);
405 InfoBox
aBox( GetViewData()->GetDialogParent(), aErr
);
408 if (pThesaurusEngine
->IsModified())
410 EditTextObject
* pNewTObj
= NULL
;
413 // The cell will own the text object instance.
415 ScAddress(nCol
,nRow
,nTab
), pThesaurusEngine
->CreateTextObject());
419 sNewString
= pThesaurusEngine
->GetText();
420 pDoc
->SetString(nCol
, nRow
, nTab
, sNewString
);
422 // erack! it's broadcasted
424 pDocSh
->SetDocumentModified();
427 GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
428 new ScUndoThesaurus( GetViewData()->GetDocShell(),
430 sOldText
, pOldTObj
, sNewString
, pNewTObj
));
434 KillEditView(sal_True
);
435 delete pEditDefaults
;
436 delete pThesaurusEngine
;
438 pDocSh
->PostPaintGridAll();
441 void ScViewFunc::DoHangulHanjaConversion( sal_Bool bRecord
)
443 ScConversionParam
aConvParam( SC_CONVERSION_HANGULHANJA
, LANGUAGE_KOREAN
, 0, true );
444 DoSheetConversion( aConvParam
, bRecord
);
447 void ScViewFunc::DoSheetConversion( const ScConversionParam
& rConvParam
, sal_Bool bRecord
)
452 ScViewData
& rViewData
= *GetViewData();
453 ScDocShell
* pDocSh
= rViewData
.GetDocShell();
454 ScDocument
* pDoc
= pDocSh
->GetDocument();
455 ScMarkData
& rMark
= rViewData
.GetMarkData();
456 ScSplitPos eWhich
= rViewData
.GetActivePart();
457 EditView
* pEditView
= NULL
;
458 sal_Bool bIsEditMode
= rViewData
.HasEditView(eWhich
);
459 if (bRecord
&& !pDoc
->IsUndoEnabled())
461 if (bIsEditMode
) // Edit-Mode aktiv
463 rViewData
.GetEditView(eWhich
, pEditView
, nCol
, nRow
);
464 SC_MOD()->InputEnterHandler();
468 nCol
= rViewData
.GetCurX();
469 nRow
= rViewData
.GetCurY();
471 AlignToCursor( nCol
, nRow
, SC_FOLLOW_JUMP
);
473 nTab
= rViewData
.GetTabNo();
476 sal_Bool bMarked
= rMark
.IsMultiMarked();
479 ScEditableTester
aTester( pDoc
, rMark
);
480 if (!aTester
.IsEditable())
482 ErrorMessage(aTester
.GetMessageId());
487 ScDocument
* pUndoDoc
= NULL
;
488 ScDocument
* pRedoDoc
= NULL
;
491 pUndoDoc
= new ScDocument( SCDOCMODE_UNDO
);
492 pUndoDoc
->InitUndo( pDoc
, nTab
, nTab
);
493 pRedoDoc
= new ScDocument( SCDOCMODE_UNDO
);
494 pRedoDoc
->InitUndo( pDoc
, nTab
, nTab
);
496 if ( rMark
.GetSelectCount() > 1 )
498 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
499 for (; itr
!= itrEnd
; ++itr
)
502 pUndoDoc
->AddUndoTab( *itr
, *itr
);
503 pRedoDoc
->AddUndoTab( *itr
, *itr
);
508 // ab hier kein return mehr
510 bool bOldEnabled
= pDoc
->IsIdleEnabled();
511 pDoc
->EnableIdle(false); // stop online spelling
513 // *** create and init the edit engine *** --------------------------------
515 ScConversionEngineBase
* pEngine
= NULL
;
516 switch( rConvParam
.GetType() )
518 case SC_CONVERSION_SPELLCHECK
:
519 pEngine
= new ScSpellingEngine(
520 pDoc
->GetEnginePool(), rViewData
, pUndoDoc
, pRedoDoc
, LinguMgr::GetSpellChecker() );
522 case SC_CONVERSION_HANGULHANJA
:
523 case SC_CONVERSION_CHINESE_TRANSL
:
524 pEngine
= new ScTextConversionEngine(
525 pDoc
->GetEnginePool(), rViewData
, rConvParam
, pUndoDoc
, pRedoDoc
);
528 OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" );
531 MakeEditView( pEngine
, nCol
, nRow
);
532 pEngine
->SetRefDevice( rViewData
.GetActiveWin() );
533 // dummy Zelle simulieren:
534 pEditView
= rViewData
.GetEditView( rViewData
.GetActivePart() );
535 rViewData
.SetSpellingView( pEditView
);
536 Rectangle
aRect( Point( 0, 0 ), Point( 0, 0 ) );
537 pEditView
->SetOutputArea( aRect
);
538 pEngine
->SetControlWord( EE_CNTRL_USECHARATTRIBS
);
539 pEngine
->EnableUndo( false );
540 pEngine
->SetPaperSize( aRect
.GetSize() );
541 pEngine
->SetText( EMPTY_OUSTRING
);
543 // *** do the conversion *** ----------------------------------------------
545 pEngine
->ClearModifyFlag();
546 pEngine
->ConvertAll( *pEditView
);
548 // *** undo/redo *** ------------------------------------------------------
550 if( pEngine
->IsAnyModified() )
554 SCCOL nNewCol
= rViewData
.GetCurX();
555 SCROW nNewRow
= rViewData
.GetCurY();
556 rViewData
.GetDocShell()->GetUndoManager()->AddUndoAction(
557 new ScUndoConversion(
559 nCol
, nRow
, nTab
, pUndoDoc
,
560 nNewCol
, nNewRow
, nTab
, pRedoDoc
, rConvParam
) );
563 pDocSh
->SetDocumentModified();
571 // *** final cleanup *** --------------------------------------------------
573 rViewData
.SetSpellingView( NULL
);
574 KillEditView(sal_True
);
576 pDocSh
->PostPaintGridAll();
577 rViewData
.GetViewShell()->UpdateInputHandler();
578 pDoc
->EnableIdle(bOldEnabled
);
581 // Pasten von FORMAT_FILE-Items
582 // wird nicht direkt aus Drop aufgerufen, sondern asynchron -> Dialoge sind erlaubt
584 sal_Bool
ScViewFunc::PasteFile( const Point
& rPos
, const OUString
& rFile
, sal_Bool bLink
)
587 aURL
.SetSmartURL( rFile
);
588 OUString aStrURL
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
590 // is it a media URL?
591 if( ::avmedia::MediaWindow::isMediaURL( aStrURL
, ""/*TODO?*/ ) )
593 const SfxStringItem
aMediaURLItem( SID_INSERT_AVMEDIA
, aStrURL
);
594 return sal_Bool( 0 != GetViewData()->GetDispatcher().Execute(
595 SID_INSERT_AVMEDIA
, SFX_CALLMODE_SYNCHRON
,
596 &aMediaURLItem
, 0L ) );
599 if (!bLink
) // bei bLink nur Grafik oder URL
601 // 1. Kann ich die Datei oeffnen?
602 const SfxFilter
* pFlt
= NULL
;
604 // nur nach eigenen Filtern suchen, ohne Auswahlbox (wie in ScDocumentLoader)
605 SfxFilterMatcher
aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
606 SfxMedium
aSfxMedium( aStrURL
, (STREAM_READ
| STREAM_SHARE_DENYNONE
) );
607 // #i73992# GuessFilter no longer calls UseInteractionHandler.
608 // This is UI, so it can be called here.
609 aSfxMedium
.UseInteractionHandler(sal_True
);
610 ErrCode nErr
= aMatcher
.GuessFilter( aSfxMedium
, &pFlt
);
614 // Code aus dem SFX geklaut!
615 SfxDispatcher
&rDispatcher
= GetViewData()->GetDispatcher();
616 SfxStringItem
aFileNameItem( SID_FILE_NAME
, aStrURL
);
617 SfxStringItem
aFilterItem( SID_FILTER_NAME
, pFlt
->GetName() );
618 // #i69524# add target, as in SfxApplication when the Open dialog is used
619 SfxStringItem
aTargetItem( SID_TARGETNAME
, OUString("_default") );
621 // Asynchron oeffnen, kann naemlich auch aus D&D heraus passieren
622 // und das bekommt dem MAC nicht so gut ...
623 return sal_Bool( 0 != rDispatcher
.Execute( SID_OPENDOC
,
624 SFX_CALLMODE_ASYNCHRON
, &aFileNameItem
, &aFilterItem
, &aTargetItem
, 0L) );
628 // 2. Kann die Datei ueber die Grafik-Filter eingefuegt werden?
629 // (als Link, weil Gallery das so anbietet)
631 sal_uInt16 nFilterFormat
;
633 GraphicFilter
& rGraphicFilter
= GraphicFilter::GetGraphicFilter();
636 if (!rGraphicFilter
.ImportGraphic(aGraphic
, aURL
,
637 GRFILTER_FORMAT_DONTKNOW
, &nFilterFormat
))
641 OUString aFltName
= rGraphicFilter
.GetImportFormatName(nFilterFormat
);
642 return PasteGraphic( rPos
, aGraphic
, aStrURL
, aFltName
);
646 // #i76709# if bLink isn't set, pass empty URL/filter, so a non-linked image is inserted
647 return PasteGraphic( rPos
, aGraphic
, EMPTY_OUSTRING
, EMPTY_OUSTRING
);
651 if (bLink
) // bei bLink alles, was nicht Grafik ist, als URL
653 Rectangle
aRect( rPos
, Size(0,0) );
654 ScRange aRange
= GetViewData()->GetDocument()->
655 GetRange( GetViewData()->GetTabNo(), aRect
);
656 SCCOL nPosX
= aRange
.aStart
.Col();
657 SCROW nPosY
= aRange
.aStart
.Row();
659 InsertBookmark( aStrURL
, aStrURL
, nPosX
, nPosY
);
664 // 3. Kann die Datei als OLE eingefuegt werden?
665 // auch nicht-Storages, z.B. Sounds (#38282#)
666 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
668 //TODO/LATER: what about "bLink"?
670 uno::Sequence
< beans::PropertyValue
> aMedium(1);
671 aMedium
[0].Name
= "URL";
672 aMedium
[0].Value
<<= OUString( aStrURL
);
674 comphelper::EmbeddedObjectContainer
aCnt( xStorage
);
676 uno::Reference
< embed::XEmbeddedObject
> xObj
= aCnt
.InsertEmbeddedObject( aMedium
, aName
);
678 return PasteObject( rPos
, xObj
);
680 // If an OLE object can't be created, insert a URL button
682 GetViewData()->GetViewShell()->InsertURLButton( aStrURL
, aStrURL
, EMPTY_OUSTRING
, &rPos
);
687 sal_Bool
ScViewFunc::PasteBookmark( sal_uLong nFormatId
,
688 const ::com::sun::star::uno::Reference
<
689 ::com::sun::star::datatransfer::XTransferable
>& rxTransferable
,
690 SCCOL nPosX
, SCROW nPosY
)
692 INetBookmark aBookmark
;
693 TransferableDataHelper
aDataHelper( rxTransferable
);
694 if ( !aDataHelper
.GetINetBookmark( nFormatId
, aBookmark
) )
697 InsertBookmark( aBookmark
.GetDescription(), aBookmark
.GetURL(), nPosX
, nPosY
);
701 void ScViewFunc::InsertBookmark( const OUString
& rDescription
, const OUString
& rURL
,
702 SCCOL nPosX
, SCROW nPosY
, const OUString
* pTarget
,
703 sal_Bool bTryReplace
)
705 ScViewData
* pViewData
= GetViewData();
706 if ( pViewData
->HasEditView( pViewData
->GetActivePart() ) &&
707 nPosX
>= pViewData
->GetEditStartCol() && nPosX
<= pViewData
->GetEditEndCol() &&
708 nPosY
>= pViewData
->GetEditStartRow() && nPosY
<= pViewData
->GetEditEndRow() )
710 // in die gerade editierte Zelle einfuegen
712 OUString aTargetFrame
;
714 aTargetFrame
= *pTarget
;
715 pViewData
->GetViewShell()->InsertURLField( rDescription
, rURL
, aTargetFrame
);
719 // in nicht editierte Zelle einfuegen
721 ScDocument
* pDoc
= GetViewData()->GetDocument();
722 SCTAB nTab
= GetViewData()->GetTabNo();
723 ScAddress
aCellPos( nPosX
, nPosY
, nTab
);
724 EditEngine
aEngine( pDoc
->GetEnginePool() );
726 const EditTextObject
* pOld
= pDoc
->GetEditText(aCellPos
);
728 aEngine
.SetText(*pOld
);
732 pDoc
->GetInputString(nPosX
, nPosY
, nTab
, aOld
);
734 aEngine
.SetText(aOld
);
737 sal_Int32 nPara
= aEngine
.GetParagraphCount();
740 xub_StrLen nTxtLen
= aEngine
.GetTextLen(nPara
);
741 ESelection
aInsSel( nPara
, nTxtLen
, nPara
, nTxtLen
);
743 if ( bTryReplace
&& HasBookmarkAtCursor( NULL
) )
745 // if called from hyperlink slot and cell contains only a URL,
746 // replace old URL with new one
748 aInsSel
= ESelection( 0, 0, 0, 1 ); // replace first character (field)
751 SvxURLField
aField( rURL
, rDescription
, SVXURLFORMAT_APPDEFAULT
);
753 aField
.SetTargetFrame(*pTarget
);
754 aEngine
.QuickInsertField( SvxFieldItem( aField
, EE_FEATURE_FIELD
), aInsSel
);
756 boost::scoped_ptr
<EditTextObject
> pData(aEngine
.CreateTextObject());
757 EnterData(nPosX
, nPosY
, nTab
, *pData
);
760 bool ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem
* pContent
)
762 ScAddress
aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
763 ScDocument
* pDoc
= GetViewData()->GetDocShell()->GetDocument();
765 const EditTextObject
* pData
= pDoc
->GetEditText(aPos
);
769 if (!pData
->IsFieldObject())
770 // not a field object.
773 const SvxFieldItem
* pFieldItem
= pData
->GetField();
775 // doesn't have a field item.
778 const SvxFieldData
* pField
= pFieldItem
->GetField();
780 // doesn't have a field item data.
783 if (pField
->GetClassId() != com::sun::star::text::textfield::Type::URL
)
789 const SvxURLField
* pURLField
= static_cast<const SvxURLField
*>(pField
);
790 pContent
->SetName( pURLField
->GetRepresentation() );
791 pContent
->SetURL( pURLField
->GetURL() );
792 pContent
->SetTargetFrame( pURLField
->GetTargetFrame() );
798 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */