LibreOffice Module sc (master) 1
viewfun4.cxx
Go to the documentation of this file.
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 <config_features.h>
21
22#include <memory>
23#include <editeng/eeitem.hxx>
24
25#include <editeng/editobj.hxx>
26#include <editeng/editstat.hxx>
27#include <editeng/editview.hxx>
28#include <editeng/flditem.hxx>
29#include <sot/storage.hxx>
30#include <svx/hlnkitem.hxx>
31#include <editeng/unolingu.hxx>
32
33#include <sfx2/bindings.hxx>
34#include <sfx2/dispatch.hxx>
35#include <sfx2/docfile.hxx>
36#include <sfx2/docfilt.hxx>
37#include <sfx2/fcontnr.hxx>
38#include <svtools/langtab.hxx>
39#include <vcl/graphicfilter.hxx>
40#include <svl/stritem.hxx>
41#include <vcl/transfer.hxx>
42#include <svl/urlbmk.hxx>
44#include <vcl/svapp.hxx>
45#include <vcl/weld.hxx>
47#include <osl/diagnose.h>
48
51
52#include <viewfunc.hxx>
53#include <docsh.hxx>
54#include <document.hxx>
55#include <globstr.hrc>
56#include <global.hxx>
57#include <scresid.hxx>
58#include <undoblk.hxx>
59#include <undocell.hxx>
60#include <formulacell.hxx>
61#include <scmod.hxx>
62#include <spelleng.hxx>
63#include <patattr.hxx>
64#include <tabvwsh.hxx>
65#include <impex.hxx>
66#include <editutil.hxx>
67#include <editable.hxx>
68#include <dociter.hxx>
69#include <reffind.hxx>
70#include <compiler.hxx>
71#include <tokenarray.hxx>
72#include <refupdatecontext.hxx>
73#include <gridwin.hxx>
74#include <refundo.hxx>
75
76using namespace com::sun::star;
77
78void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
79 const css::uno::Reference< css::datatransfer::XTransferable >& rxTransferable )
80{
81 TransferableDataHelper aDataHelper( rxTransferable );
82 if ( aDataHelper.HasFormat( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT ) )
83 {
85
87 ScDocument& rDoc = pDocSh->GetDocument();
88 SCTAB nTab = GetViewData().GetTabNo();
89 const bool bRecord (rDoc.IsUndoEnabled());
90
91 const ScPatternAttr* pPattern = rDoc.GetPattern( nStartCol, nStartRow, nTab );
92 std::optional<ScTabEditEngine> pEngine(std::in_place, *pPattern, rDoc.GetEnginePool(), &rDoc );
93 pEngine->EnableUndo( false );
94
95 vcl::Window* pActWin = GetActiveWin();
96 if (pActWin)
97 {
98 pEngine->SetPaperSize(Size(100000,100000));
100 EditView aEditView( &*pEngine, aWin.get() );
101 aEditView.SetOutputArea(tools::Rectangle(0,0,100000,100000));
102
103 // same method now for clipboard or drag&drop
104 // mba: clipboard always must contain absolute URLs (could be from alien source)
105 aEditView.InsertText( rxTransferable, OUString(), true );
106 }
107
108 sal_Int32 nParCnt = pEngine->GetParagraphCount();
109 if (nParCnt)
110 {
111 SCROW nEndRow = nStartRow + static_cast<SCROW>(nParCnt) - 1;
112 if (nEndRow > rDoc.MaxRow())
113 nEndRow = rDoc.MaxRow();
114
115 ScDocumentUniquePtr pUndoDoc;
116 if (bRecord)
117 {
118 pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
119 pUndoDoc->InitUndo( rDoc, nTab, nTab );
120 rDoc.CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, InsertDeleteFlags::ALL, false, *pUndoDoc );
121 }
122
123 SCROW nRow = nStartRow;
124
125 // Temporarily turn off undo generation for this lot
126 bool bUndoEnabled = rDoc.IsUndoEnabled();
127 rDoc.EnableUndo( false );
128 for( sal_Int32 n = 0; n < nParCnt; n++ )
129 {
130 std::unique_ptr<EditTextObject> pObject(pEngine->CreateTextObject(n));
131 EnterData(nStartCol, nRow, nTab, *pObject, true);
132 if( ++nRow > rDoc.MaxRow() )
133 break;
134 }
135 rDoc.EnableUndo(bUndoEnabled);
136
137 if (bRecord)
138 {
140 pRedoDoc->InitUndo( rDoc, nTab, nTab );
141 rDoc.CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, InsertDeleteFlags::ALL|InsertDeleteFlags::NOCAPTIONS, false, *pRedoDoc );
142
143 ScRange aMarkRange(nStartCol, nStartRow, nTab, nStartCol, nEndRow, nTab);
144 ScMarkData aDestMark(rDoc.GetSheetLimits());
145 aDestMark.SetMarkArea( aMarkRange );
146 pDocSh->GetUndoManager()->AddUndoAction(
147 std::make_unique<ScUndoPaste>( pDocSh, aMarkRange, aDestMark,
148 std::move(pUndoDoc), std::move(pRedoDoc), InsertDeleteFlags::ALL, nullptr));
149 }
150 }
151
152 pEngine.reset();
153
155 }
156 else
157 {
159 ScDocShell* pDocSh = GetViewData().GetDocShell();
160 ScImportExport aImpEx( pDocSh->GetDocument(),
161 ScAddress( nStartCol, nStartRow, GetViewData().GetTabNo() ) );
162
163 OUString aStr;
165 if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::RTF, xStream ) && xStream.is() )
166 // mba: clipboard always must contain absolute URLs (could be from alien source)
167 aImpEx.ImportStream( *xStream, OUString(), SotClipboardFormatId::RTF );
168 else if ( aDataHelper.GetString( SotClipboardFormatId::RTF, aStr ) )
169 aImpEx.ImportString( aStr, SotClipboardFormatId::RTF );
170 else if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::RICHTEXT, xStream ) && xStream.is() )
171 aImpEx.ImportStream( *xStream, OUString(), SotClipboardFormatId::RICHTEXT );
172 else if ( aDataHelper.GetString( SotClipboardFormatId::RICHTEXT, aStr ) )
173 aImpEx.ImportString( aStr, SotClipboardFormatId::RICHTEXT );
174
175 AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row(), true );
176 pDocSh->UpdateOle(GetViewData());
178 }
179}
181{
184 SCTAB nTabCount = rDoc.GetTableCount();
185 bool bRecord = true;
186 if (!rDoc.IsUndoEnabled())
187 bRecord = false;
188
189 ScRange aMarkRange;
190 rMark.MarkToSimple();
191 bool bMulti = rMark.IsMultiMarked();
192 if (bMulti)
193 aMarkRange = rMark.GetMultiMarkArea();
194 else if (rMark.IsMarked())
195 aMarkRange = rMark.GetMarkArea();
196 else
197 {
198 aMarkRange = ScRange( GetViewData().GetCurX(),
199 GetViewData().GetCurY(), GetViewData().GetTabNo() );
200 }
201 ScEditableTester aTester( rDoc, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
202 aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(),rMark );
203 if (!aTester.IsEditable())
204 {
205 ErrorMessage(aTester.GetMessageId());
206 return;
207 }
208
209 ScDocShell* pDocSh = GetViewData().GetDocShell();
210 bool bOk = false;
211
212 ScDocumentUniquePtr pUndoDoc;
213 if (bRecord)
214 {
215 pUndoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
216 SCTAB nTab = aMarkRange.aStart.Tab();
217 pUndoDoc->InitUndo( rDoc, nTab, nTab );
218
219 if ( rMark.GetSelectCount() > 1 )
220 {
221 for (const auto& rTab : rMark)
222 if ( rTab != nTab )
223 pUndoDoc->AddUndoTab( rTab, rTab );
224 }
225 ScRange aCopyRange = aMarkRange;
226 aCopyRange.aStart.SetTab(0);
227 aCopyRange.aEnd.SetTab(nTabCount-1);
228 rDoc.CopyToDocument( aCopyRange, InsertDeleteFlags::ALL, bMulti, *pUndoDoc, &rMark );
229 }
230
231 ScRangeListRef xRanges;
232 GetViewData().GetMultiArea( xRanges );
233 size_t nCount = xRanges->size();
234
235 for (const SCTAB& i : rMark)
236 {
237 for (size_t j = 0; j < nCount; ++j)
238 {
239 ScRange aRange = (*xRanges)[j];
240 aRange.aStart.SetTab(i);
241 aRange.aEnd.SetTab(i);
242 ScCellIterator aIter( rDoc, aRange );
243 for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
244 {
245 if (aIter.getType() != CELLTYPE_FORMULA)
246 continue;
247
248 ScFormulaCell* pCell = aIter.getFormulaCell();
249 ScMatrixMode eMatrixMode = pCell->GetMatrixFlag();
250 if (eMatrixMode == ScMatrixMode::Reference)
251 continue;
252
253 OUString aOld = pCell->GetFormula();
254 sal_Int32 nLen = aOld.getLength();
255 if (eMatrixMode == ScMatrixMode::Formula)
256 {
257 assert(nLen >= 2 && aOld[0] == '{' && aOld[nLen-1] == '}');
258 nLen -= 2;
259 aOld = aOld.copy( 1, nLen);
260 }
261 ScRefFinder aFinder( aOld, aIter.GetPos(), rDoc, rDoc.GetAddressConvention() );
262 aFinder.ToggleRel( 0, nLen );
263 if (aFinder.GetFound())
264 {
265 ScAddress aPos = pCell->aPos;
266 const OUString& aNew = aFinder.GetText();
267 ScCompiler aComp( rDoc, aPos, rDoc.GetGrammar());
268 std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aNew));
269 ScFormulaCell* pNewCell =
270 new ScFormulaCell(
271 rDoc, aPos, *pArr, formula::FormulaGrammar::GRAM_DEFAULT, eMatrixMode);
272
273 rDoc.SetFormulaCell(aPos, pNewCell);
274 bOk = true;
275 }
276 }
277 }
278 }
279 if (bRecord)
280 {
282 SCTAB nTab = aMarkRange.aStart.Tab();
283 pRedoDoc->InitUndo( rDoc, nTab, nTab );
284
285 if ( rMark.GetSelectCount() > 1 )
286 {
287 for (const auto& rTab : rMark)
288 if ( rTab != nTab )
289 pRedoDoc->AddUndoTab( rTab, rTab );
290 }
291 ScRange aCopyRange = aMarkRange;
292 aCopyRange.aStart.SetTab(0);
293 aCopyRange.aEnd.SetTab(nTabCount-1);
294 rDoc.CopyToDocument( aCopyRange, InsertDeleteFlags::ALL, bMulti, *pRedoDoc, &rMark );
295
296 pDocSh->GetUndoManager()->AddUndoAction(
297 std::make_unique<ScUndoRefConversion>( pDocSh,
298 aMarkRange, rMark, std::move(pUndoDoc), std::move(pRedoDoc), bMulti) );
299 }
300
301 pDocSh->PostPaint( aMarkRange, PaintPartFlags::Grid );
302 pDocSh->UpdateOle(GetViewData());
303 pDocSh->SetDocumentModified();
305
306 if (!bOk)
307 ErrorMessage(STR_ERR_NOREF);
308}
309
310// Thesaurus - Undo ok
312{
313 SCCOL nCol;
314 SCROW nRow;
315 SCTAB nTab;
316 ScDocShell* pDocSh = GetViewData().GetDocShell();
317 ScDocument& rDoc = pDocSh->GetDocument();
320 EESpellState eState;
321 EditView* pEditView = nullptr;
322 std::unique_ptr<ESelection> pEditSel;
323 std::unique_ptr<ScEditEngineDefaulter> pThesaurusEngine;
324 bool bIsEditMode = GetViewData().HasEditView(eWhich);
325 bool bRecord = true;
326 if (!rDoc.IsUndoEnabled())
327 bRecord = false;
328 if (bIsEditMode) // edit mode active
329 {
330 GetViewData().GetEditView(eWhich, pEditView, nCol, nRow);
331 pEditSel.reset(new ESelection(pEditView->GetSelection()));
332 SC_MOD()->InputEnterHandler();
333 GetViewData().GetBindings().Update(); // otherwise the Sfx becomes mixed-up...
334 }
335 else
336 {
337 nCol = GetViewData().GetCurX();
338 nRow = GetViewData().GetCurY();
339 }
340 nTab = GetViewData().GetTabNo();
341
342 ScAddress aPos(nCol, nRow, nTab);
343 ScEditableTester aTester( rDoc, nCol, nRow, nCol, nRow, rMark );
344 if (!aTester.IsEditable())
345 {
346 ErrorMessage(aTester.GetMessageId());
347 return;
348 }
349
350 ScCellValue aOldText;
351 aOldText.assign(rDoc, aPos);
352 if (aOldText.getType() != CELLTYPE_STRING && aOldText.getType() != CELLTYPE_EDIT)
353 {
354 ErrorMessage(STR_THESAURUS_NO_STRING);
355 return;
356 }
357
358 uno::Reference<linguistic2::XSpellChecker1> xSpeller = LinguMgr::GetSpellChecker();
359
360 pThesaurusEngine.reset(new ScEditEngineDefaulter(rDoc.GetEnginePool()));
361 pThesaurusEngine->SetEditTextObjectPool( rDoc.GetEditPool() );
362 pThesaurusEngine->SetRefDevice(GetViewData().GetActiveWin()->GetOutDev());
363 pThesaurusEngine->SetSpeller(xSpeller);
364 MakeEditView(pThesaurusEngine.get(), nCol, nRow );
365 SfxItemSet aEditDefaults(pThesaurusEngine->GetEmptyItemSet());
366 const ScPatternAttr* pPattern = rDoc.GetPattern(nCol, nRow, nTab);
367 if (pPattern)
368 {
369 pPattern->FillEditItemSet( &aEditDefaults );
370 pThesaurusEngine->SetDefaults( aEditDefaults );
371 }
372
373 if (aOldText.getType() == CELLTYPE_EDIT)
374 pThesaurusEngine->SetTextCurrentDefaults(*aOldText.getEditText());
375 else
376 pThesaurusEngine->SetTextCurrentDefaults(aOldText.getString(rDoc));
377
378 pEditView = GetViewData().GetEditView(GetViewData().GetActivePart());
379 if (pEditSel)
380 pEditView->SetSelection(*pEditSel);
381 else
382 pEditView->SetSelection(ESelection(0,0,0,0));
383
384 pThesaurusEngine->ClearModifyFlag();
385
386 // language is now in EditEngine attributes -> no longer passed to StartThesaurus
387
388 eState = pEditView->StartThesaurus(GetViewData().GetDialogParent());
389 OSL_ENSURE(eState != EESpellState::NoSpeller, "No SpellChecker");
390
391 if (eState == EESpellState::ErrorFound) // should happen later through Wrapper!
392 {
393 LanguageType eLnge = ScViewUtil::GetEffLanguage( rDoc, ScAddress( nCol, nRow, nTab ) );
394 OUString aErr = SvtLanguageTable::GetLanguageString(eLnge) + ScResId( STR_SPELLING_NO_LANG );
395
396 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(),
397 VclMessageType::Info, VclButtonsType::Ok,
398 aErr));
399 xInfoBox->run();
400 }
401 if (pThesaurusEngine->IsModified())
402 {
403 ScCellValue aNewText;
404
405 if (aOldText.getType() == CELLTYPE_EDIT)
406 {
407 // The cell will own the text object instance.
408 std::unique_ptr<EditTextObject> pText = pThesaurusEngine->CreateTextObject();
409 auto tmp = pText.get();
410 if (rDoc.SetEditText(ScAddress(nCol,nRow,nTab), std::move(pText)))
411 aNewText.set(*tmp);
412 }
413 else
414 {
415 OUString aStr = pThesaurusEngine->GetText();
416 aNewText.set(rDoc.GetSharedStringPool().intern(aStr));
417 rDoc.SetString(nCol, nRow, nTab, aStr);
418 }
419
420 pDocSh->SetDocumentModified();
421 if (bRecord)
422 {
424 std::make_unique<ScUndoThesaurus>(
425 GetViewData().GetDocShell(), nCol, nRow, nTab, aOldText, aNewText));
426 }
427 }
428
429 KillEditView(true);
430 pDocSh->PostPaintGridAll();
431}
432
434{
436 DoSheetConversion( aConvParam );
437}
438
440{
441 SCCOL nCol;
442 SCROW nRow;
443 SCTAB nTab;
444 ScViewData& rViewData = GetViewData();
445 ScDocShell* pDocSh = rViewData.GetDocShell();
446 ScDocument& rDoc = pDocSh->GetDocument();
447 ScMarkData& rMark = rViewData.GetMarkData();
448 ScSplitPos eWhich = rViewData.GetActivePart();
449 EditView* pEditView = nullptr;
450 bool bIsEditMode = rViewData.HasEditView(eWhich);
451 bool bRecord = true;
452 if (!rDoc.IsUndoEnabled())
453 bRecord = false;
454 if (bIsEditMode) // edit mode active
455 {
456 rViewData.GetEditView(eWhich, pEditView, nCol, nRow);
457 SC_MOD()->InputEnterHandler();
458 }
459 else
460 {
461 nCol = rViewData.GetCurX();
462 nRow = rViewData.GetCurY();
463
464 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP);
465 }
466 nTab = rViewData.GetTabNo();
467
468 rMark.MarkToMulti();
469 bool bMarked = rMark.IsMultiMarked();
470 if (bMarked)
471 {
472 ScEditableTester aTester( rDoc, rMark );
473 if (!aTester.IsEditable())
474 {
475 ErrorMessage(aTester.GetMessageId());
476 return;
477 }
478 }
479
480 ScDocumentUniquePtr pUndoDoc;
481 ScDocumentUniquePtr pRedoDoc;
482 if (bRecord)
483 {
484 pUndoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
485 pUndoDoc->InitUndo( rDoc, nTab, nTab );
486 pRedoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
487 pRedoDoc->InitUndo( rDoc, nTab, nTab );
488
489 if ( rMark.GetSelectCount() > 1 )
490 {
491 for (const auto& rTab : rMark)
492 if ( rTab != nTab )
493 {
494 pUndoDoc->AddUndoTab( rTab, rTab );
495 pRedoDoc->AddUndoTab( rTab, rTab );
496 }
497 }
498 }
499
500 // from here no return
501
502 bool bOldEnabled = rDoc.IsIdleEnabled();
503 rDoc.EnableIdle(false); // stop online spelling
504
505 // *** create and init the edit engine *** --------------------------------
506
507 std::unique_ptr<ScConversionEngineBase> pEngine;
508 switch( rConvParam.GetType() )
509 {
511 pEngine.reset(new ScSpellingEngine(
512 rDoc.GetEnginePool(), rViewData, pUndoDoc.get(), pRedoDoc.get(), LinguMgr::GetSpellChecker() ));
513 break;
516 pEngine.reset(new ScTextConversionEngine(
517 rDoc.GetEnginePool(), rViewData, rConvParam, pUndoDoc.get(), pRedoDoc.get() ));
518 break;
519 default:
520 OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" );
521 }
522
523 MakeEditView( pEngine.get(), nCol, nRow );
524 pEngine->SetRefDevice( rViewData.GetActiveWin()->GetOutDev() );
525 // simulate dummy cell:
526 pEditView = rViewData.GetEditView( rViewData.GetActivePart() );
527 rViewData.SetSpellingView( pEditView );
528 tools::Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
529 pEditView->SetOutputArea( aRect );
530 pEngine->SetControlWord( EEControlBits::USECHARATTRIBS );
531 pEngine->EnableUndo( false );
532 pEngine->SetPaperSize( aRect.GetSize() );
533 pEngine->SetTextCurrentDefaults( OUString() );
534
535 // *** do the conversion *** ----------------------------------------------
536
537 pEngine->ClearModifyFlag();
538 pEngine->ConvertAll(GetViewData().GetDialogParent(), *pEditView);
539
540 // *** undo/redo *** ------------------------------------------------------
541
542 if( pEngine->IsAnyModified() )
543 {
544 if (bRecord)
545 {
546 SCCOL nNewCol = rViewData.GetCurX();
547 SCROW nNewRow = rViewData.GetCurY();
549 std::make_unique<ScUndoConversion>(
550 pDocSh, rMark,
551 nCol, nRow, nTab, std::move(pUndoDoc),
552 nNewCol, nNewRow, nTab, std::move(pRedoDoc), rConvParam ) );
553 }
554
556 rDoc.SetAllFormulasDirty(aCxt);
557
558 pDocSh->SetDocumentModified();
559 }
560 else
561 {
562 pUndoDoc.reset();
563 pRedoDoc.reset();
564 }
565
566 // *** final cleanup *** --------------------------------------------------
567
568 rViewData.SetSpellingView( nullptr );
569 KillEditView(true);
570 pEngine.reset();
571 pDocSh->PostPaintGridAll();
572 rViewData.GetViewShell()->UpdateInputHandler();
573 rDoc.EnableIdle(bOldEnabled);
574}
575
576// past from SotClipboardFormatId::FILE items
577// is not called directly from Drop, but asynchronously -> dialogs are allowed
578
579bool ScViewFunc::PasteFile( const Point& rPos, const OUString& rFile, bool bLink )
580{
582 aURL.SetSmartURL( rFile );
583 OUString aStrURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
584
585 // is it a media URL?
586#if HAVE_FEATURE_AVMEDIA
587 if( ::avmedia::MediaWindow::isMediaURL( aStrURL, ""/*TODO?*/ ) )
588 {
589 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aStrURL );
590 return ( nullptr != GetViewData().GetDispatcher().ExecuteList(
591 SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
592 { &aMediaURLItem }) );
593 }
594#endif
595
596 if (!bLink) // for bLink only graphics or URL
597 {
598 // 1. can I open the file?
599 std::shared_ptr<const SfxFilter> pFlt;
600
601 // search only for its own filters, without selection box (as in ScDocumentLoader)
602 SfxFilterMatcher aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
603 SfxMedium aSfxMedium( aStrURL, (StreamMode::READ | StreamMode::SHARE_DENYNONE) );
604 // #i73992# GuessFilter no longer calls UseInteractionHandler.
605 // This is UI, so it can be called here.
606 aSfxMedium.UseInteractionHandler(true);
607 ErrCode nErr = aMatcher.GuessFilter( aSfxMedium, pFlt );
608
609 if ( pFlt && !nErr )
610 {
611 // code stolen from the SFX!
612 SfxDispatcher &rDispatcher = GetViewData().GetDispatcher();
613 SfxStringItem aFileNameItem( SID_FILE_NAME, aStrURL );
614 SfxStringItem aFilterItem( SID_FILTER_NAME, pFlt->GetName() );
615 // #i69524# add target, as in SfxApplication when the Open dialog is used
616 SfxStringItem aTargetItem( SID_TARGETNAME, "_default" );
617
618 // Open Asynchronously, because it can also happen from D&D
619 // and that is not so good for the MAC...
620 return (nullptr != rDispatcher.ExecuteList(SID_OPENDOC,
621 SfxCallMode::ASYNCHRON,
622 { &aFileNameItem, &aFilterItem, &aTargetItem}));
623 }
624 }
625
626 // 2. can the file be inserted using the graphics filter?
627 // (as a link, since the Gallery provides it in this way)
628
629 Graphic aGraphic;
631
632 if (!rGraphicFilter.ImportGraphic(aGraphic, aURL,
634 {
635 if ( bLink )
636 {
637 return PasteGraphic( rPos, aGraphic, aStrURL );
638 }
639 else
640 {
641 // #i76709# if bLink isn't set, pass empty URL/filter, so a non-linked image is inserted
642 return PasteGraphic( rPos, aGraphic, OUString() );
643 }
644 }
645
646 if (bLink) // for bLink everything, which is not graphics, as URL
647 {
648 tools::Rectangle aRect( rPos, Size(0,0) );
649 ScRange aRange = GetViewData().GetDocument().
650 GetRange( GetViewData().GetTabNo(), aRect );
651 SCCOL nPosX = aRange.aStart.Col();
652 SCROW nPosY = aRange.aStart.Row();
653
654 InsertBookmark( aStrURL, aStrURL, nPosX, nPosY );
655 return true;
656 }
657 else
658 {
659 // 3. can the file be inserted as OLE?
660 // also non-storages, for instance sounds (#38282#)
661 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
662
663 //TODO/LATER: what about "bLink"?
664
665 uno::Sequence < beans::PropertyValue > aMedium{ comphelper::makePropertyValue("URL",
666 aStrURL) };
667
669 OUString aName;
670 uno::Reference < embed::XEmbeddedObject > xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
671 if( xObj.is() )
672 return PasteObject( rPos, xObj, nullptr );
673
674 // If an OLE object can't be created, insert a URL button
675
676 GetViewData().GetViewShell()->InsertURLButton( aStrURL, aStrURL, OUString(), &rPos );
677 return true;
678 }
679}
680
682 const css::uno::Reference< css::datatransfer::XTransferable >& rxTransferable,
683 SCCOL nPosX, SCROW nPosY )
684{
685 INetBookmark aBookmark;
686 TransferableDataHelper aDataHelper( rxTransferable );
687 if ( !aDataHelper.GetINetBookmark( nFormatId, aBookmark ) )
688 return false;
689
690 InsertBookmark( aBookmark.GetDescription(), aBookmark.GetURL(), nPosX, nPosY );
691 return true;
692}
693
694void ScViewFunc::InsertBookmark( const OUString& rDescription, const OUString& rURL,
695 SCCOL nPosX, SCROW nPosY, const OUString* pTarget,
696 bool bTryReplace )
697{
698 ScViewData& rViewData = GetViewData();
699 if ( rViewData.HasEditView( rViewData.GetActivePart() ) &&
700 nPosX >= rViewData.GetEditStartCol() && nPosX <= rViewData.GetEditEndCol() &&
701 nPosY >= rViewData.GetEditStartRow() && nPosY <= rViewData.GetEditEndRow() )
702 {
703 // insert into the cell which just got edited
704
705 OUString aTargetFrame;
706 if (pTarget)
707 aTargetFrame = *pTarget;
708 rViewData.GetViewShell()->InsertURLField( rDescription, rURL, aTargetFrame );
709 return;
710 }
711
712 // insert into not edited cell
713
715 SCTAB nTab = GetViewData().GetTabNo();
716 ScAddress aCellPos( nPosX, nPosY, nTab );
717 EditEngine aEngine( rDoc.GetEnginePool() );
718
719 const EditTextObject* pOld = rDoc.GetEditText(aCellPos);
720 if (pOld)
721 aEngine.SetText(*pOld);
722 else
723 {
724 OUString aOld = rDoc.GetInputString(nPosX, nPosY, nTab);
725 if (!aOld.isEmpty())
726 aEngine.SetText(aOld);
727 }
728
729 sal_Int32 nPara = aEngine.GetParagraphCount();
730 if (nPara)
731 --nPara;
732 sal_Int32 nTxtLen = aEngine.GetTextLen(nPara);
733 ESelection aInsSel( nPara, nTxtLen, nPara, nTxtLen );
734
735 if ( bTryReplace && HasBookmarkAtCursor( nullptr ) )
736 {
737 // if called from hyperlink slot and cell contains only a URL,
738 // replace old URL with new one
739
740 aInsSel = ESelection( 0, 0, 0, 1 ); // replace first character (field)
741 }
742
743 SvxURLField aField( rURL, rDescription, SvxURLFormat::AppDefault );
744 if (pTarget)
745 aField.SetTargetFrame(*pTarget);
746 aEngine.QuickInsertField( SvxFieldItem( aField, EE_FEATURE_FIELD ), aInsSel );
747
748 std::unique_ptr<EditTextObject> pData(aEngine.CreateTextObject());
749 EnterData(nPosX, nPosY, nTab, *pData);
750}
751
753{
754 ScAddress aPos( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
756
757 const EditTextObject* pData = rDoc.GetEditText(aPos);
758 if (!pData)
759 return false;
760
761 if (!pData->IsFieldObject())
762 // not a field object.
763 return false;
764
765 const SvxFieldItem* pFieldItem = pData->GetField();
766 if (!pFieldItem)
767 // doesn't have a field item.
768 return false;
769
770 const SvxFieldData* pField = pFieldItem->GetField();
771 if (!pField)
772 // doesn't have a field item data.
773 return false;
774
775 if (pField->GetClassId() != css::text::textfield::Type::URL)
776 // not a URL field.
777 return false;
778
779 if (pContent)
780 {
781 const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
782 pContent->SetName( pURLField->GetRepresentation() );
783 pContent->SetURL( pURLField->GetURL() );
784 pContent->SetTargetFrame( pURLField->GetTargetFrame() );
785 }
786 return true;
787}
788
789/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XInputStream > xStream
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< EditTextObject > CreateTextObject()
void SetText(const OUString &rStr)
sal_Int32 GetParagraphCount() const
void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)
sal_Int32 GetTextLen() const
ESelection GetSelection() const
EESpellState StartThesaurus(weld::Widget *pDialogParent)
void SetOutputArea(const tools::Rectangle &rRect)
void SetSelection(const ESelection &rNewSel)
void InsertText(const OUString &rNew, bool bSelect=false, bool bLOKShowSelect=true)
static GraphicFilter & GetGraphicFilter()
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
const OUString & GetDescription() const
const OUString & GetURL() const
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
Walk through all cells in an area.
Definition: dociter.hxx:206
CellType getType() const
Definition: dociter.hxx:233
ScFormulaCell * getFormulaCell()
Definition: dociter.hxx:236
const ScAddress & GetPos() const
Definition: dociter.hxx:231
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
Definition: compiler.cxx:4691
Parameters for conversion.
Definition: spellparam.hxx:33
ScConversionType GetType() const
Definition: spellparam.hxx:54
void PostPaintGridAll()
Definition: docsh3.cxx:183
void SetDocumentModified()
Definition: docsh.cxx:2982
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void UpdateOle(const ScViewData &rViewData, bool bSnapSize=false)
Definition: docsh6.cxx:152
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2968
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:478
SC_DLLPUBLIC bool SetEditText(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
This method manages the lifecycle of the passed edit text object.
Definition: document.cxx:3422
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:898
SC_DLLPUBLIC ScFormulaCell * SetFormulaCell(const ScAddress &rPos, ScFormulaCell *pCell)
Set formula cell, and transfer its ownership to the document.
Definition: documen2.cxx:1149
bool IsIdleEnabled() const
Definition: document.hxx:2207
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC void EnableUndo(bool bVal)
Definition: document.cxx:6456
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:473
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3391
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: document.cxx:3819
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1010
SC_DLLPUBLIC OUString GetInputString(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bForceSystemLocale=false) const
Definition: document.cxx:3549
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
Definition: document.cxx:2041
void EnableIdle(bool bDo)
Definition: document.hxx:2208
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
Definition: documen2.cxx:601
SC_DLLPUBLIC const EditTextObject * GetEditText(const ScAddress &rPos) const
Definition: document.cxx:3612
bool IsUndoEnabled() const
Definition: document.hxx:1595
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4719
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
bool IsEditable() const
Definition: editable.hxx:84
TranslateId GetMessageId() const
Definition: editable.cxx:152
ScMatrixMode GetMatrixFlag() const
ScAddress aPos
OUString GetFormula(const formula::FormulaGrammar::Grammar=formula::FormulaGrammar::GRAM_DEFAULT, const ScInterpreterContext *pContext=nullptr) const
const ScRange & GetRange() const
Definition: impex.hxx:104
bool ImportString(const OUString &, SotClipboardFormatId)
Definition: impex.cxx:316
bool ImportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:395
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
const ScRange & GetMultiMarkArea() const
Definition: markdata.hxx:84
const ScRange & GetMarkArea() const
Definition: markdata.hxx:83
bool IsMultiMarked() const
Definition: markdata.hxx:81
SCTAB GetSelectCount() const
Definition: markdata.cxx:180
void MarkToMulti()
Definition: markdata.cxx:209
bool IsMarked() const
Definition: markdata.hxx:80
void SetMarkArea(const ScRange &rRange)
Definition: markdata.cxx:92
void MarkToSimple()
Definition: markdata.cxx:222
void FillEditItemSet(SfxItemSet *pEditSet, const SfxItemSet *pCondSet=nullptr) const
Converts all Calc items contained in the own item set to edit engine items and puts them into pEditSe...
Definition: patattr.cxx:868
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
void ToggleRel(sal_Int32 nStartPos, sal_Int32 nEndPos)
Definition: reffind.cxx:235
sal_Int32 GetFound() const
Definition: reffind.hxx:43
const OUString & GetText() const
Definition: reffind.hxx:42
Edit engine for spell checking.
Definition: spelleng.hxx:96
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:690
void InsertURLField(const OUString &rName, const OUString &rURL, const OUString &rTarget)
Definition: tabvwshe.cxx:184
void InsertURLButton(const OUString &rName, const OUString &rURL, const OUString &rTarget, const Point *pInsPos)
Definition: tabvwshg.cxx:42
void AlignToCursor(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, const ScSplitPos *pWhich=nullptr)
Definition: tabview3.cxx:917
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1553
void MakeEditView(ScEditEngineDefaulter *pEngine, SCCOL nCol, SCROW nRow)
Definition: tabview3.cxx:2113
ScViewData & GetViewData()
Definition: tabview.hxx:344
void ShowAllCursors()
Definition: tabview3.cxx:234
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:878
SC_DLLPUBLIC void CellContentChanged()
Definition: tabview3.cxx:513
void KillEditView(bool bNoPaint)
Definition: tabview3.cxx:2196
void HideAllCursors()
Definition: tabview3.cxx:220
Edit engine for text conversion.
Definition: spelleng.hxx:128
void GetMultiArea(ScRangeListRef &rRange) const
Definition: viewdata.cxx:1205
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3140
SCCOL GetEditEndCol() const
Definition: viewdata.hxx:607
SCROW GetEditEndRow() const
Definition: viewdata.hxx:608
void SetSpellingView(EditView *pSpView)
Definition: viewdata.hxx:650
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3146
SCROW GetEditStartRow() const
Definition: viewdata.hxx:606
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
SCCOL GetEditStartCol() const
Definition: viewdata.hxx:605
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3162
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2284
SfxBindings & GetBindings()
Definition: viewdata.cxx:3134
bool HasEditView(ScSplitPos eWhich) const
Definition: viewdata.hxx:582
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
bool PasteGraphic(const Point &rPos, const Graphic &rGraphic, const OUString &rFile)
Definition: viewfun7.cxx:384
void EnterData(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const EditTextObject *pData=nullptr, bool bMatrixExpand=false)
Definition: viewfunc.cxx:384
void DoRefConversion()
Definition: viewfun4.cxx:180
bool HasBookmarkAtCursor(SvxHyperlinkItem *pContent)
Definition: viewfun4.cxx:752
bool PasteBookmark(SotClipboardFormatId nFormatId, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, SCCOL nPosX, SCROW nPosY)
Definition: viewfun4.cxx:681
void PasteRTF(SCCOL nCol, SCROW nStartRow, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable)
Definition: viewfun4.cxx:78
void DoHangulHanjaConversion()
Definition: viewfun4.cxx:433
void DoThesaurus()
Definition: viewfun4.cxx:311
void DoSheetConversion(const ScConversionParam &rParam)
Generic implementation of sheet conversion functions.
Definition: viewfun4.cxx:439
void InsertBookmark(const OUString &rDescription, const OUString &rURL, SCCOL nPosX, SCROW nPosY, const OUString *pTarget=nullptr, bool bTryReplace=false)
Definition: viewfun4.cxx:694
bool AdjustRowHeight(SCROW nStartRow, SCROW nEndRow, bool bApi)
Definition: viewfun2.cxx:193
bool PasteObject(const Point &, const css::uno::Reference< css::embed::XEmbeddedObject > &, const Size *, const Graphic *=nullptr, const OUString &=OUString(), sal_Int64 nAspect=css::embed::Aspects::MSOLE_CONTENT)
Definition: viewfun7.cxx:285
bool PasteFile(const Point &, const OUString &, bool bLink)
Definition: viewfun4.cxx:579
static LanguageType GetEffLanguage(ScDocument &rDoc, const ScAddress &rPos)
Definition: viewutil.cxx:70
void Update(sal_uInt16 nId)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
ErrCode GuessFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
void UseInteractionHandler(bool)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
static OUString GetLanguageString(const LanguageType eType)
virtual sal_Int32 GetClassId() const
const SvxFieldData * GetField() const
void SetName(const OUString &rName)
void SetURL(const OUString &rURL)
void SetTargetFrame(const OUString &rTarget)
const OUString & GetRepresentation() const
void SetTargetFrame(const OUString &rFrm)
const OUString & GetTargetFrame() const
const OUString & GetURL() const
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotTempStream > &rStreamRef) const
bool HasFormat(SotClipboardFormatId nFormat) const
bool GetINetBookmark(SotClipboardFormatId nFormat, INetBookmark &rBmk) const
reference_type * get() const
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
SharedString intern(const OUString &rStr)
constexpr Size GetSize() const
::OutputDevice const * GetOutDev() const
int nCount
URL aURL
virtual OUString GetName() const override
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2720
@ SCDOCMODE_UNDO
Definition: document.hxx:258
EESpellState
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
EmbeddedObjectRef * pObject
SotClipboardFormatId
ScMatrixMode
@ CELLTYPE_EDIT
Definition: global.hxx:277
@ CELLTYPE_STRING
Definition: global.hxx:275
@ CELLTYPE_FORMULA
Definition: global.hxx:276
@ NOCAPTIONS
Sparklines in a cell.
#define GRFILTER_FORMAT_DONTKNOW
OUString aName
sal_Int64 n
#define LANGUAGE_KOREAN
aStr
std::unique_ptr< sal_Int32[]> pData
SfxDispatcher * GetDispatcher()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
#define SC_MOD()
Definition: scmod.hxx:247
@ SC_CONVERSION_CHINESE_TRANSL
Hangul-Hanja converter.
Definition: spellparam.hxx:28
@ SC_CONVERSION_SPELLCHECK
Definition: spellparam.hxx:26
@ SC_CONVERSION_HANGULHANJA
Spell checker.
Definition: spellparam.hxx:27
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:32
OUString getString(const ScDocument &rDoc) const
Definition: cellvalue.cxx:514
void assign(const ScDocument &rDoc, const ScAddress &rPos)
Take cell value from specified position in specified document.
Definition: cellvalue.cxx:359
void set(double fValue)
Definition: cellvalue.cxx:329
CellType getType() const
Definition: cellvalue.cxx:296
EditTextObject * getEditText() const
Definition: cellvalue.hxx:61
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
ScSplitPos
Definition: viewdata.hxx:44
@ SC_FOLLOW_JUMP
Definition: viewdata.hxx:52