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 <sot/storage.hxx>
28 #include <svx/hlnkitem.hxx>
29 #include <editeng/langitem.hxx>
30 #include <svx/svxerr.hxx>
31 #include <editeng/unolingu.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/fcontnr.hxx>
37 #include <svtools/langtab.hxx>
38 #include <vcl/graphicfilter.hxx>
39 #include <svl/stritem.hxx>
40 #include <svtools/transfer.hxx>
41 #include <svl/urlbmk.hxx>
42 #include <svl/sharedstringpool.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <avmedia/mediawindow.hxx>
46 #include <comphelper/storagehelper.hxx>
47 #include <comphelper/processfactory.hxx>
49 #include "viewfunc.hxx"
51 #include "document.hxx"
52 #include "docpool.hxx"
53 #include "globstr.hrc"
55 #include "undoblk.hxx"
56 #include "undocell.hxx"
57 #include "formulacell.hxx"
59 #include "spelleng.hxx"
60 #include "patattr.hxx"
62 #include "tabvwsh.hxx"
64 #include "editutil.hxx"
65 #include "editable.hxx"
66 #include "dociter.hxx"
67 #include "reffind.hxx"
68 #include "compiler.hxx"
69 #include "tokenarray.hxx"
70 #include <refupdatecontext.hxx>
71 #include <gridwin.hxx>
73 #include <boost/scoped_ptr.hpp>
75 using namespace com::sun::star
;
77 // STATIC DATA -----------------------------------------------------------
79 bool bPasteIsDrop
= false;
81 void ScViewFunc::PasteRTF( SCCOL nStartCol
, SCROW nStartRow
,
82 const ::com::sun::star::uno::Reference
<
83 ::com::sun::star::datatransfer::XTransferable
>& rxTransferable
)
85 TransferableDataHelper
aDataHelper( rxTransferable
);
86 if ( aDataHelper
.HasFormat( SotClipboardFormatId::EDITENGINE
) )
90 ScDocShell
* pDocSh
= GetViewData().GetDocShell();
91 ScDocument
& rDoc
= pDocSh
->GetDocument();
92 SCTAB nTab
= GetViewData().GetTabNo();
93 const bool bRecord (rDoc
.IsUndoEnabled());
95 const ScPatternAttr
* pPattern
= rDoc
.GetPattern( nStartCol
, nStartRow
, nTab
);
96 boost::scoped_ptr
<ScTabEditEngine
> pEngine(new ScTabEditEngine( *pPattern
, rDoc
.GetEnginePool() ));
97 pEngine
->EnableUndo( false );
99 vcl::Window
* pActWin
= GetActiveWin();
102 pEngine
->SetPaperSize(Size(100000,100000));
103 ScopedVclPtrInstance
< vcl::Window
> aWin( pActWin
);
104 EditView
aEditView( pEngine
.get(), aWin
.get() );
105 aEditView
.SetOutputArea(Rectangle(0,0,100000,100000));
107 // same method now for clipboard or drag&drop
108 // mba: clipboard always must contain absolute URLs (could be from alien source)
109 aEditView
.InsertText( rxTransferable
, OUString(), true );
112 sal_Int32 nParCnt
= pEngine
->GetParagraphCount();
115 SCROW nEndRow
= nStartRow
+ static_cast<SCROW
>(nParCnt
) - 1;
116 if (nEndRow
> MAXROW
)
119 ScDocument
* pUndoDoc
= NULL
;
122 pUndoDoc
= new ScDocument( SCDOCMODE_UNDO
);
123 pUndoDoc
->InitUndo( &rDoc
, nTab
, nTab
);
124 rDoc
.CopyToDocument( nStartCol
,nStartRow
,nTab
, nStartCol
,nEndRow
,nTab
, IDF_ALL
, false, pUndoDoc
);
127 SCROW nRow
= nStartRow
;
129 // Temporarily turn off undo generation for this lot
130 bool bUndoEnabled
= rDoc
.IsUndoEnabled();
131 rDoc
.EnableUndo( false );
132 for( sal_Int32 n
= 0; n
< nParCnt
; n
++ )
134 boost::scoped_ptr
<EditTextObject
> pObject(pEngine
->CreateTextObject(n
));
135 EnterData(nStartCol
, nRow
, nTab
, *pObject
, true);
136 if( ++nRow
> MAXROW
)
139 rDoc
.EnableUndo(bUndoEnabled
);
143 ScDocument
* pRedoDoc
= new ScDocument( SCDOCMODE_UNDO
);
144 pRedoDoc
->InitUndo( &rDoc
, nTab
, nTab
);
145 rDoc
.CopyToDocument( nStartCol
,nStartRow
,nTab
, nStartCol
,nEndRow
,nTab
, IDF_ALL
|IDF_NOCAPTIONS
, false, pRedoDoc
);
147 ScRange
aMarkRange(nStartCol
, nStartRow
, nTab
, nStartCol
, nEndRow
, nTab
);
148 ScMarkData aDestMark
;
149 aDestMark
.SetMarkArea( aMarkRange
);
150 pDocSh
->GetUndoManager()->AddUndoAction(
151 new ScUndoPaste( pDocSh
, aMarkRange
, aDestMark
,
152 pUndoDoc
, pRedoDoc
, IDF_ALL
, NULL
));
163 ScDocShell
* pDocSh
= GetViewData().GetDocShell();
164 ScImportExport
aImpEx( &pDocSh
->GetDocument(),
165 ScAddress( nStartCol
, nStartRow
, GetViewData().GetTabNo() ) );
168 tools::SvRef
<SotStorageStream
> xStream
;
169 if ( aDataHelper
.GetSotStorageStream( SotClipboardFormatId::RTF
, xStream
) && xStream
.Is() )
170 // mba: clipboard always must contain absolute URLs (could be from alien source)
171 aImpEx
.ImportStream( *xStream
, OUString(), SotClipboardFormatId::RTF
);
172 else if ( aDataHelper
.GetString( SotClipboardFormatId::RTF
, aStr
) )
173 aImpEx
.ImportString( aStr
, SotClipboardFormatId::RTF
);
175 AdjustRowHeight( nStartRow
, aImpEx
.GetRange().aEnd
.Row() );
176 pDocSh
->UpdateOle(&GetViewData());
180 void ScViewFunc::DoRefConversion( bool bRecord
)
182 ScDocument
* pDoc
= GetViewData().GetDocument();
183 ScMarkData
& rMark
= GetViewData().GetMarkData();
184 SCTAB nTabCount
= pDoc
->GetTableCount();
185 if (bRecord
&& !pDoc
->IsUndoEnabled())
189 rMark
.MarkToSimple();
190 bool bMulti
= rMark
.IsMultiMarked();
192 rMark
.GetMultiMarkArea( aMarkRange
);
193 else if (rMark
.IsMarked())
194 rMark
.GetMarkArea( aMarkRange
);
197 aMarkRange
= ScRange( GetViewData().GetCurX(),
198 GetViewData().GetCurY(), GetViewData().GetTabNo() );
200 ScEditableTester
aTester( pDoc
, aMarkRange
.aStart
.Col(), aMarkRange
.aStart
.Row(),
201 aMarkRange
.aEnd
.Col(), aMarkRange
.aEnd
.Row(),rMark
);
202 if (!aTester
.IsEditable())
204 ErrorMessage(aTester
.GetMessageId());
208 ScDocShell
* pDocSh
= GetViewData().GetDocShell();
211 ScDocument
* pUndoDoc
= NULL
;
214 pUndoDoc
= new ScDocument( SCDOCMODE_UNDO
);
215 SCTAB nTab
= aMarkRange
.aStart
.Tab();
216 pUndoDoc
->InitUndo( pDoc
, nTab
, nTab
);
218 if ( rMark
.GetSelectCount() > 1 )
220 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
221 for (; itr
!= itrEnd
; ++itr
)
223 pUndoDoc
->AddUndoTab( *itr
, *itr
);
225 ScRange aCopyRange
= aMarkRange
;
226 aCopyRange
.aStart
.SetTab(0);
227 aCopyRange
.aEnd
.SetTab(nTabCount
-1);
228 pDoc
->CopyToDocument( aCopyRange
, IDF_ALL
, bMulti
, pUndoDoc
, &rMark
);
231 ScRangeListRef xRanges
;
232 GetViewData().GetMultiArea( xRanges
);
233 size_t nCount
= xRanges
->size();
235 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
236 for (; itr
!= itrEnd
; ++itr
)
239 for (size_t j
= 0; j
< nCount
; ++j
)
241 ScRange aRange
= *(*xRanges
)[j
];
242 aRange
.aStart
.SetTab(i
);
243 aRange
.aEnd
.SetTab(i
);
244 ScCellIterator
aIter( pDoc
, aRange
);
245 for (bool bHas
= aIter
.first(); bHas
; bHas
= aIter
.next())
247 if (aIter
.getType() != CELLTYPE_FORMULA
)
250 ScFormulaCell
* pCell
= aIter
.getFormulaCell();
252 pCell
->GetFormula(aOld
);
253 sal_Int32 nLen
= aOld
.getLength();
254 ScRefFinder
aFinder( aOld
, aIter
.GetPos(), pDoc
, pDoc
->GetAddressConvention() );
255 aFinder
.ToggleRel( 0, nLen
);
256 if (aFinder
.GetFound())
258 ScAddress aPos
= pCell
->aPos
;
259 OUString aNew
= aFinder
.GetText();
260 ScCompiler
aComp( pDoc
, aPos
);
261 aComp
.SetGrammar(pDoc
->GetGrammar());
262 boost::scoped_ptr
<ScTokenArray
> pArr(aComp
.CompileString(aNew
));
263 ScFormulaCell
* pNewCell
=
265 pDoc
, aPos
, *pArr
, formula::FormulaGrammar::GRAM_DEFAULT
, MM_NONE
);
267 pDoc
->SetFormulaCell(aPos
, pNewCell
);
275 ScDocument
* pRedoDoc
= new ScDocument( SCDOCMODE_UNDO
);
276 SCTAB nTab
= aMarkRange
.aStart
.Tab();
277 pRedoDoc
->InitUndo( pDoc
, nTab
, nTab
);
279 if ( rMark
.GetSelectCount() > 1 )
282 for (; itr
!= itrEnd
; ++itr
)
284 pRedoDoc
->AddUndoTab( *itr
, *itr
);
286 ScRange aCopyRange
= aMarkRange
;
287 aCopyRange
.aStart
.SetTab(0);
288 aCopyRange
.aEnd
.SetTab(nTabCount
-1);
289 pDoc
->CopyToDocument( aCopyRange
, IDF_ALL
, bMulti
, pRedoDoc
, &rMark
);
291 pDocSh
->GetUndoManager()->AddUndoAction(
292 new ScUndoRefConversion( pDocSh
,
293 aMarkRange
, rMark
, pUndoDoc
, pRedoDoc
, bMulti
, IDF_ALL
) );
296 pDocSh
->PostPaint( aMarkRange
, PAINT_GRID
);
297 pDocSh
->UpdateOle(&GetViewData());
298 pDocSh
->SetDocumentModified();
299 CellContentChanged();
302 ErrorMessage(STR_ERR_NOREF
);
304 // Thesaurus - Undo ok
305 void ScViewFunc::DoThesaurus( bool bRecord
)
310 ScDocShell
* pDocSh
= GetViewData().GetDocShell();
311 ScDocument
& rDoc
= pDocSh
->GetDocument();
312 ScMarkData
& rMark
= GetViewData().GetMarkData();
313 ScSplitPos eWhich
= GetViewData().GetActivePart();
315 EditView
* pEditView
= NULL
;
316 boost::scoped_ptr
<ESelection
> pEditSel
;
317 boost::scoped_ptr
<ScEditEngineDefaulter
> pThesaurusEngine
;
318 bool bIsEditMode
= GetViewData().HasEditView(eWhich
);
319 if (bRecord
&& !rDoc
.IsUndoEnabled())
321 if (bIsEditMode
) // Edit-Mode aktiv
323 GetViewData().GetEditView(eWhich
, pEditView
, nCol
, nRow
);
324 pEditSel
.reset(new ESelection(pEditView
->GetSelection()));
325 SC_MOD()->InputEnterHandler();
326 GetViewData().GetBindings().Update(); // sonst kommt der Sfx durcheinander...
330 nCol
= GetViewData().GetCurX();
331 nRow
= GetViewData().GetCurY();
333 nTab
= GetViewData().GetTabNo();
335 ScAddress
aPos(nCol
, nRow
, nTab
);
336 ScEditableTester
aTester( &rDoc
, nCol
, nRow
, nCol
, nRow
, rMark
);
337 if (!aTester
.IsEditable())
339 ErrorMessage(aTester
.GetMessageId());
343 ScCellValue aOldText
;
344 aOldText
.assign(rDoc
, aPos
);
345 if (aOldText
.meType
!= CELLTYPE_STRING
&& aOldText
.meType
!= CELLTYPE_EDIT
)
347 ErrorMessage(STR_THESAURUS_NO_STRING
);
351 uno::Reference
<linguistic2::XSpellChecker1
> xSpeller
= LinguMgr::GetSpellChecker();
353 pThesaurusEngine
.reset(new ScEditEngineDefaulter(rDoc
.GetEnginePool()));
354 pThesaurusEngine
->SetEditTextObjectPool( rDoc
.GetEditPool() );
355 pThesaurusEngine
->SetRefDevice(GetViewData().GetActiveWin());
356 pThesaurusEngine
->SetSpeller(xSpeller
);
357 MakeEditView(pThesaurusEngine
.get(), nCol
, nRow
);
358 const ScPatternAttr
* pPattern
= NULL
;
359 boost::scoped_ptr
<SfxItemSet
> pEditDefaults(
360 new SfxItemSet(pThesaurusEngine
->GetEmptyItemSet()));
361 pPattern
= rDoc
.GetPattern(nCol
, nRow
, nTab
);
364 pPattern
->FillEditItemSet( pEditDefaults
.get() );
365 pThesaurusEngine
->SetDefaults( *pEditDefaults
);
368 if (aOldText
.meType
== CELLTYPE_EDIT
)
369 pThesaurusEngine
->SetText(*aOldText
.mpEditText
);
371 pThesaurusEngine
->SetText(aOldText
.getString(&rDoc
));
373 pEditView
= GetViewData().GetEditView(GetViewData().GetActivePart());
375 pEditView
->SetSelection(*pEditSel
);
377 pEditView
->SetSelection(ESelection(0,0,0,0));
379 pThesaurusEngine
->ClearModifyFlag();
381 // language is now in EditEngine attributes -> no longer passed to StartThesaurus
383 eState
= pEditView
->StartThesaurus();
384 OSL_ENSURE(eState
!= EE_SPELL_NOSPELLER
, "No SpellChecker");
386 if (eState
== EE_SPELL_ERRORFOUND
) // sollte spaeter durch Wrapper geschehen!
388 LanguageType eLnge
= ScViewUtil::GetEffLanguage( &rDoc
, ScAddress( nCol
, nRow
, nTab
) );
389 OUString aErr
= SvtLanguageTable::GetLanguageString(eLnge
);
390 aErr
+= ScGlobal::GetRscString( STR_SPELLING_NO_LANG
);
391 ScopedVclPtrInstance
< InfoBox
> aBox( GetViewData().GetDialogParent(), aErr
);
394 if (pThesaurusEngine
->IsModified())
396 ScCellValue aNewText
;
398 if (aOldText
.meType
== CELLTYPE_EDIT
)
400 // The cell will own the text object instance.
401 EditTextObject
* pText
= pThesaurusEngine
->CreateTextObject();
402 if (rDoc
.SetEditText(ScAddress(nCol
,nRow
,nTab
), pText
))
403 aNewText
.set(*pText
);
407 OUString aStr
= pThesaurusEngine
->GetText();
408 aNewText
.set(rDoc
.GetSharedStringPool().intern(aStr
));
409 rDoc
.SetString(nCol
, nRow
, nTab
, aStr
);
412 pDocSh
->SetDocumentModified();
415 GetViewData().GetDocShell()->GetUndoManager()->AddUndoAction(
417 GetViewData().GetDocShell(), nCol
, nRow
, nTab
, aOldText
, aNewText
));
422 pDocSh
->PostPaintGridAll();
425 void ScViewFunc::DoHangulHanjaConversion( bool bRecord
)
427 ScConversionParam
aConvParam( SC_CONVERSION_HANGULHANJA
, LANGUAGE_KOREAN
, 0, true );
428 DoSheetConversion( aConvParam
, bRecord
);
431 void ScViewFunc::DoSheetConversion( const ScConversionParam
& rConvParam
, bool bRecord
)
436 ScViewData
& rViewData
= GetViewData();
437 ScDocShell
* pDocSh
= rViewData
.GetDocShell();
438 ScDocument
& rDoc
= pDocSh
->GetDocument();
439 ScMarkData
& rMark
= rViewData
.GetMarkData();
440 ScSplitPos eWhich
= rViewData
.GetActivePart();
441 EditView
* pEditView
= NULL
;
442 bool bIsEditMode
= rViewData
.HasEditView(eWhich
);
443 if (bRecord
&& !rDoc
.IsUndoEnabled())
445 if (bIsEditMode
) // Edit-Mode aktiv
447 rViewData
.GetEditView(eWhich
, pEditView
, nCol
, nRow
);
448 SC_MOD()->InputEnterHandler();
452 nCol
= rViewData
.GetCurX();
453 nRow
= rViewData
.GetCurY();
455 AlignToCursor( nCol
, nRow
, SC_FOLLOW_JUMP
);
457 nTab
= rViewData
.GetTabNo();
460 bool bMarked
= rMark
.IsMultiMarked();
463 ScEditableTester
aTester( &rDoc
, rMark
);
464 if (!aTester
.IsEditable())
466 ErrorMessage(aTester
.GetMessageId());
471 ScDocument
* pUndoDoc
= NULL
;
472 ScDocument
* pRedoDoc
= NULL
;
475 pUndoDoc
= new ScDocument( SCDOCMODE_UNDO
);
476 pUndoDoc
->InitUndo( &rDoc
, nTab
, nTab
);
477 pRedoDoc
= new ScDocument( SCDOCMODE_UNDO
);
478 pRedoDoc
->InitUndo( &rDoc
, nTab
, nTab
);
480 if ( rMark
.GetSelectCount() > 1 )
482 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
483 for (; itr
!= itrEnd
; ++itr
)
486 pUndoDoc
->AddUndoTab( *itr
, *itr
);
487 pRedoDoc
->AddUndoTab( *itr
, *itr
);
492 // ab hier kein return mehr
494 bool bOldEnabled
= rDoc
.IsIdleEnabled();
495 rDoc
.EnableIdle(false); // stop online spelling
497 // *** create and init the edit engine *** --------------------------------
499 boost::scoped_ptr
<ScConversionEngineBase
> pEngine
;
500 switch( rConvParam
.GetType() )
502 case SC_CONVERSION_SPELLCHECK
:
503 pEngine
.reset(new ScSpellingEngine(
504 rDoc
.GetEnginePool(), rViewData
, pUndoDoc
, pRedoDoc
, LinguMgr::GetSpellChecker() ));
506 case SC_CONVERSION_HANGULHANJA
:
507 case SC_CONVERSION_CHINESE_TRANSL
:
508 pEngine
.reset(new ScTextConversionEngine(
509 rDoc
.GetEnginePool(), rViewData
, rConvParam
, pUndoDoc
, pRedoDoc
));
512 OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" );
515 MakeEditView( pEngine
.get(), nCol
, nRow
);
516 pEngine
->SetRefDevice( rViewData
.GetActiveWin() );
517 // dummy Zelle simulieren:
518 pEditView
= rViewData
.GetEditView( rViewData
.GetActivePart() );
519 rViewData
.SetSpellingView( pEditView
);
520 Rectangle
aRect( Point( 0, 0 ), Point( 0, 0 ) );
521 pEditView
->SetOutputArea( aRect
);
522 pEngine
->SetControlWord( EEControlBits::USECHARATTRIBS
);
523 pEngine
->EnableUndo( false );
524 pEngine
->SetPaperSize( aRect
.GetSize() );
525 pEngine
->SetText( EMPTY_OUSTRING
);
527 // *** do the conversion *** ----------------------------------------------
529 pEngine
->ClearModifyFlag();
530 pEngine
->ConvertAll( *pEditView
);
532 // *** undo/redo *** ------------------------------------------------------
534 if( pEngine
->IsAnyModified() )
538 SCCOL nNewCol
= rViewData
.GetCurX();
539 SCROW nNewRow
= rViewData
.GetCurY();
540 rViewData
.GetDocShell()->GetUndoManager()->AddUndoAction(
541 new ScUndoConversion(
543 nCol
, nRow
, nTab
, pUndoDoc
,
544 nNewCol
, nNewRow
, nTab
, pRedoDoc
, rConvParam
) );
547 sc::SetFormulaDirtyContext aCxt
;
548 rDoc
.SetAllFormulasDirty(aCxt
);
550 pDocSh
->SetDocumentModified();
558 // *** final cleanup *** --------------------------------------------------
560 rViewData
.SetSpellingView( NULL
);
563 pDocSh
->PostPaintGridAll();
564 rViewData
.GetViewShell()->UpdateInputHandler();
565 rDoc
.EnableIdle(bOldEnabled
);
568 // Pasten von SotClipboardFormatId::FILE-Items
569 // wird nicht direkt aus Drop aufgerufen, sondern asynchron -> Dialoge sind erlaubt
571 bool ScViewFunc::PasteFile( const Point
& rPos
, const OUString
& rFile
, bool bLink
)
574 aURL
.SetSmartURL( rFile
);
575 OUString aStrURL
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
577 // is it a media URL?
578 if( ::avmedia::MediaWindow::isMediaURL( aStrURL
, ""/*TODO?*/ ) )
580 const SfxStringItem
aMediaURLItem( SID_INSERT_AVMEDIA
, aStrURL
);
581 return ( 0 != GetViewData().GetDispatcher().Execute(
582 SID_INSERT_AVMEDIA
, SfxCallMode::SYNCHRON
,
583 &aMediaURLItem
, 0L ) );
586 if (!bLink
) // bei bLink nur Grafik oder URL
588 // 1. Kann ich die Datei oeffnen?
589 const SfxFilter
* pFlt
= NULL
;
591 // nur nach eigenen Filtern suchen, ohne Auswahlbox (wie in ScDocumentLoader)
592 SfxFilterMatcher
aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
593 SfxMedium
aSfxMedium( aStrURL
, (StreamMode::READ
| StreamMode::SHARE_DENYNONE
) );
594 // #i73992# GuessFilter no longer calls UseInteractionHandler.
595 // This is UI, so it can be called here.
596 aSfxMedium
.UseInteractionHandler(true);
597 ErrCode nErr
= aMatcher
.GuessFilter( aSfxMedium
, &pFlt
);
601 // Code aus dem SFX geklaut!
602 SfxDispatcher
&rDispatcher
= GetViewData().GetDispatcher();
603 SfxStringItem
aFileNameItem( SID_FILE_NAME
, aStrURL
);
604 SfxStringItem
aFilterItem( SID_FILTER_NAME
, pFlt
->GetName() );
605 // #i69524# add target, as in SfxApplication when the Open dialog is used
606 SfxStringItem
aTargetItem( SID_TARGETNAME
, OUString("_default") );
608 // Asynchron oeffnen, kann naemlich auch aus D&D heraus passieren
609 // und das bekommt dem MAC nicht so gut ...
610 return ( 0 != rDispatcher
.Execute( SID_OPENDOC
,
611 SfxCallMode::ASYNCHRON
, &aFileNameItem
, &aFilterItem
, &aTargetItem
, 0L) );
615 // 2. Kann die Datei ueber die Grafik-Filter eingefuegt werden?
616 // (als Link, weil Gallery das so anbietet)
618 sal_uInt16 nFilterFormat
;
620 GraphicFilter
& rGraphicFilter
= GraphicFilter::GetGraphicFilter();
622 if (!rGraphicFilter
.ImportGraphic(aGraphic
, aURL
,
623 GRFILTER_FORMAT_DONTKNOW
, &nFilterFormat
))
627 OUString aFltName
= rGraphicFilter
.GetImportFormatName(nFilterFormat
);
628 return PasteGraphic( rPos
, aGraphic
, aStrURL
, aFltName
);
632 // #i76709# if bLink isn't set, pass empty URL/filter, so a non-linked image is inserted
633 return PasteGraphic( rPos
, aGraphic
, EMPTY_OUSTRING
, EMPTY_OUSTRING
);
637 if (bLink
) // bei bLink alles, was nicht Grafik ist, als URL
639 Rectangle
aRect( rPos
, Size(0,0) );
640 ScRange aRange
= GetViewData().GetDocument()->
641 GetRange( GetViewData().GetTabNo(), aRect
);
642 SCCOL nPosX
= aRange
.aStart
.Col();
643 SCROW nPosY
= aRange
.aStart
.Row();
645 InsertBookmark( aStrURL
, aStrURL
, nPosX
, nPosY
);
650 // 3. Kann die Datei als OLE eingefuegt werden?
651 // auch nicht-Storages, z.B. Sounds (#38282#)
652 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
654 //TODO/LATER: what about "bLink"?
656 uno::Sequence
< beans::PropertyValue
> aMedium(1);
657 aMedium
[0].Name
= "URL";
658 aMedium
[0].Value
<<= OUString( aStrURL
);
660 comphelper::EmbeddedObjectContainer
aCnt( xStorage
);
662 uno::Reference
< embed::XEmbeddedObject
> xObj
= aCnt
.InsertEmbeddedObject( aMedium
, aName
);
664 return PasteObject( rPos
, xObj
);
666 // If an OLE object can't be created, insert a URL button
668 GetViewData().GetViewShell()->InsertURLButton( aStrURL
, aStrURL
, EMPTY_OUSTRING
, &rPos
);
673 bool ScViewFunc::PasteBookmark( SotClipboardFormatId nFormatId
,
674 const ::com::sun::star::uno::Reference
<
675 ::com::sun::star::datatransfer::XTransferable
>& rxTransferable
,
676 SCCOL nPosX
, SCROW nPosY
)
678 INetBookmark aBookmark
;
679 TransferableDataHelper
aDataHelper( rxTransferable
);
680 if ( !aDataHelper
.GetINetBookmark( nFormatId
, aBookmark
) )
683 InsertBookmark( aBookmark
.GetDescription(), aBookmark
.GetURL(), nPosX
, nPosY
);
687 void ScViewFunc::InsertBookmark( const OUString
& rDescription
, const OUString
& rURL
,
688 SCCOL nPosX
, SCROW nPosY
, const OUString
* pTarget
,
691 ScViewData
& rViewData
= GetViewData();
692 if ( rViewData
.HasEditView( rViewData
.GetActivePart() ) &&
693 nPosX
>= rViewData
.GetEditStartCol() && nPosX
<= rViewData
.GetEditEndCol() &&
694 nPosY
>= rViewData
.GetEditStartRow() && nPosY
<= rViewData
.GetEditEndRow() )
696 // in die gerade editierte Zelle einfuegen
698 OUString aTargetFrame
;
700 aTargetFrame
= *pTarget
;
701 rViewData
.GetViewShell()->InsertURLField( rDescription
, rURL
, aTargetFrame
);
705 // in nicht editierte Zelle einfuegen
707 ScDocument
* pDoc
= GetViewData().GetDocument();
708 SCTAB nTab
= GetViewData().GetTabNo();
709 ScAddress
aCellPos( nPosX
, nPosY
, nTab
);
710 EditEngine
aEngine( pDoc
->GetEnginePool() );
712 const EditTextObject
* pOld
= pDoc
->GetEditText(aCellPos
);
714 aEngine
.SetText(*pOld
);
718 pDoc
->GetInputString(nPosX
, nPosY
, nTab
, aOld
);
720 aEngine
.SetText(aOld
);
723 sal_Int32 nPara
= aEngine
.GetParagraphCount();
726 sal_Int32 nTxtLen
= aEngine
.GetTextLen(nPara
);
727 ESelection
aInsSel( nPara
, nTxtLen
, nPara
, nTxtLen
);
729 if ( bTryReplace
&& HasBookmarkAtCursor( NULL
) )
731 // if called from hyperlink slot and cell contains only a URL,
732 // replace old URL with new one
734 aInsSel
= ESelection( 0, 0, 0, 1 ); // replace first character (field)
737 SvxURLField
aField( rURL
, rDescription
, SVXURLFORMAT_APPDEFAULT
);
739 aField
.SetTargetFrame(*pTarget
);
740 aEngine
.QuickInsertField( SvxFieldItem( aField
, EE_FEATURE_FIELD
), aInsSel
);
742 boost::scoped_ptr
<EditTextObject
> pData(aEngine
.CreateTextObject());
743 EnterData(nPosX
, nPosY
, nTab
, *pData
);
746 bool ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem
* pContent
)
748 ScAddress
aPos( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
749 ScDocument
& rDoc
= GetViewData().GetDocShell()->GetDocument();
751 const EditTextObject
* pData
= rDoc
.GetEditText(aPos
);
755 if (!pData
->IsFieldObject())
756 // not a field object.
759 const SvxFieldItem
* pFieldItem
= pData
->GetField();
761 // doesn't have a field item.
764 const SvxFieldData
* pField
= pFieldItem
->GetField();
766 // doesn't have a field item data.
769 if (pField
->GetClassId() != com::sun::star::text::textfield::Type::URL
)
775 const SvxURLField
* pURLField
= static_cast<const SvxURLField
*>(pField
);
776 pContent
->SetName( pURLField
->GetRepresentation() );
777 pContent
->SetURL( pURLField
->GetURL() );
778 pContent
->SetTargetFrame( pURLField
->GetTargetFrame() );
783 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */