Get the style color and number just once
[LibreOffice.git] / sd / source / ui / func / fuinsfil.cxx
blob630ea14ae3aaf7920e69c554be1b381f14f54cb4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <fuinsfil.hxx>
21 #include <vcl/svapp.hxx>
22 #include <sfx2/progress.hxx>
23 #include <editeng/outliner.hxx>
24 #include <editeng/outlobj.hxx>
25 #include <editeng/editeng.hxx>
26 #include <editeng/editund2.hxx>
27 #include <svl/stritem.hxx>
28 #include <sfx2/request.hxx>
29 #include <sfx2/app.hxx>
30 #include <vcl/weld.hxx>
31 #include <svx/svdorect.hxx>
32 #include <svx/svdundo.hxx>
33 #include <svx/svdoutl.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include <sot/formats.hxx>
36 #include <sfx2/docfile.hxx>
37 #include <sfx2/docfilt.hxx>
38 #include <sfx2/fcontnr.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <svx/svxids.hrc>
41 #include <tools/debug.hxx>
42 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
43 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
44 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
45 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
47 #include <sdresid.hxx>
48 #include <drawdoc.hxx>
49 #include <Window.hxx>
50 #include <View.hxx>
51 #include <strings.hrc>
52 #include <sdmod.hxx>
53 #include <sdpage.hxx>
54 #include <ViewShellBase.hxx>
55 #include <DrawViewShell.hxx>
56 #include <OutlineView.hxx>
57 #include <DrawDocShell.hxx>
58 #include <GraphicDocShell.hxx>
59 #include <app.hrc>
60 #include <Outliner.hxx>
61 #include <sdabstdlg.hxx>
62 #include <memory>
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::ui::dialogs;
67 using namespace ::com::sun::star;
69 typedef ::std::pair< OUString, OUString > FilterDesc;
71 namespace
74 OUString lcl_GetExtensionsList ( ::std::vector< FilterDesc > const& rFilterDescList )
76 OUStringBuffer aExtensions;
78 for (const auto& rFilterDesc : rFilterDescList)
80 OUString sWildcard = rFilterDesc.second;
82 if ( aExtensions.indexOf( sWildcard ) == -1 )
84 if ( !aExtensions.isEmpty() )
85 aExtensions.append(";");
86 aExtensions.append(sWildcard);
91 return aExtensions.makeStringAndClear();
94 void lcl_AddFilter ( ::std::vector< FilterDesc >& rFilterDescList,
95 const std::shared_ptr<const SfxFilter>& pFilter )
97 if (pFilter)
98 rFilterDescList.emplace_back( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
103 namespace sd {
106 FuInsertFile::FuInsertFile (
107 ViewShell* pViewSh,
108 ::sd::Window* pWin,
109 ::sd::View* pView,
110 SdDrawDocument* pDoc,
111 SfxRequest& rReq)
112 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
116 rtl::Reference<FuPoor> FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
118 rtl::Reference<FuPoor> xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
119 xFunc->DoExecute(rReq);
120 return xFunc;
123 void FuInsertFile::DoExecute( SfxRequest& rReq )
125 SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
126 ::std::vector< FilterDesc > aFilterVector;
127 ::std::vector< OUString > aOtherFilterVector;
128 const SfxItemSet* pArgs = rReq.GetArgs ();
130 FuInsertFile::GetSupportedFilterVector( aOtherFilterVector );
132 if (!pArgs)
134 sfx2::FileDialogHelper aFileDialog(
135 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
136 FileDialogFlags::Insert, mpWindow ? mpWindow->GetFrameWeld() : nullptr);
137 aFileDialog.SetContext(sfx2::FileDialogHelper::DrawImpressInsertFile);
138 Reference< XFilePicker > xFilePicker( aFileDialog.GetFilePicker() );
139 Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
140 OUString aOwnCont;
141 OUString aOtherCont;
143 aFileDialog.SetTitle( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE) );
145 if( mpDoc->GetDocumentType() == DocumentType::Impress )
147 aOwnCont = "simpress";
148 aOtherCont = "sdraw";
150 else
152 aOtherCont = "simpress";
153 aOwnCont = "sdraw" ;
156 SfxFilterMatcher aMatch( aOwnCont );
158 if( xFilterManager.is() )
160 // Get filter for current format
163 // Get main filter
164 std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
165 lcl_AddFilter( aFilterVector, pFilter );
167 // get template filter
168 if( mpDoc->GetDocumentType() == DocumentType::Impress )
169 pFilter = DrawDocShell::Factory().GetTemplateFilter();
170 else
171 pFilter = GraphicDocShell::Factory().GetTemplateFilter();
172 lcl_AddFilter( aFilterVector, pFilter );
174 // get cross filter
175 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
176 lcl_AddFilter( aFilterVector, pFilter );
178 // get Powerpoint filter
179 pFilter = aMatch.GetFilter4Extension( u".ppt"_ustr );
180 lcl_AddFilter( aFilterVector, pFilter );
182 // Get other draw/impress filters
183 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
184 lcl_AddFilter( aFilterVector, pFilter );
186 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::TEMPLATEPATH );
187 lcl_AddFilter( aFilterVector, pFilter );
189 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
190 lcl_AddFilter( aFilterVector, pFilter );
192 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::TEMPLATEPATH );
193 lcl_AddFilter( aFilterVector, pFilter );
195 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
196 lcl_AddFilter( aFilterVector, pFilter );
198 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::TEMPLATEPATH );
199 lcl_AddFilter( aFilterVector, pFilter );
201 // add additional supported filters
202 for( const auto& rOtherFilter : aOtherFilterVector )
204 if( ( pFilter = rMatcher.GetFilter4Mime( rOtherFilter ) ) != nullptr )
205 lcl_AddFilter( aFilterVector, pFilter );
208 // set "All supported formats" as the default filter
209 OUString aAllSpec( SdResId( STR_ALL_SUPPORTED_FORMATS ) );
210 OUString aExtensions = lcl_GetExtensionsList( aFilterVector );
211 OUString aGUIName = aAllSpec + " (" + aExtensions + ")";
213 xFilterManager->appendFilter( aGUIName, aExtensions );
214 xFilterManager->setCurrentFilter( aAllSpec );
216 // append individual filters
217 for( const auto& rFilter : aFilterVector )
219 xFilterManager->appendFilter( rFilter.first, rFilter.second );
222 // end with "All files" as fallback
223 xFilterManager->appendFilter( SdResId( STR_ALL_FILES ), u"*.*"_ustr );
225 catch (const IllegalArgumentException&)
230 if( aFileDialog.Execute() != ERRCODE_NONE )
231 return;
232 else
234 aFilterName = aFileDialog.GetCurrentFilter();
235 aFile = aFileDialog.GetPath();
238 else
240 const SfxStringItem* pFileName = rReq.GetArg<SfxStringItem>(ID_VAL_DUMMY0);
241 assert(pFileName && "must be present");
242 aFile = pFileName->GetValue();
243 if (const SfxStringItem* pFilterName = rReq.GetArg<SfxStringItem>(ID_VAL_DUMMY1))
244 aFilterName = pFilterName->GetValue();
247 mpDocSh->SetWaitCursor( true );
249 std::unique_ptr<SfxMedium> xMedium(new SfxMedium(aFile, StreamMode::READ | StreamMode::NOCREATE));
250 std::shared_ptr<const SfxFilter> pFilter;
252 SfxGetpApp()->GetFilterMatcher().GuessFilter(*xMedium, pFilter);
254 bool bDrawMode = dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr;
255 bool bInserted = false;
257 if( pFilter )
259 xMedium->SetFilter( pFilter );
260 aFilterName = pFilter->GetFilterName();
262 if( xMedium->IsStorage() || ( xMedium->GetInStream() && SotStorage::IsStorageFile( xMedium->GetInStream() ) ) )
264 if ( pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument" ||
265 pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument" )
267 // Draw, Impress or PowerPoint document
268 // the ownership of the Medium is transferred
269 if( bDrawMode )
270 InsSDDinDrMode(xMedium.release());
271 else
272 InsSDDinOlMode(xMedium.release());
274 // ownership of pMedium has changed in this case
275 bInserted = true;
278 else
280 bool bFound = ( ::std::find( aOtherFilterVector.begin(), aOtherFilterVector.end(), pFilter->GetMimeType() ) != aOtherFilterVector.end() );
281 if( !bFound &&
282 ( aFilterName.indexOf( "Text" ) != -1 ||
283 aFilterName.indexOf( "Rich" ) != -1 ||
284 aFilterName.indexOf( "RTF" ) != -1 ||
285 aFilterName.indexOf( "HTML" ) != -1 ) )
287 bFound = true;
290 if( bFound )
292 if( bDrawMode )
293 InsTextOrRTFinDrMode(xMedium.get());
294 else
295 InsTextOrRTFinOlMode(xMedium.get());
297 bInserted = true;
298 xMedium.reset();
303 mpDocSh->SetWaitCursor( false );
305 if( !bInserted )
307 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(mpWindow->GetFrameWeld(),
308 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
309 xErrorBox->run();
313 bool FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
315 bool bOK = false;
317 mpDocSh->SetWaitCursor( false );
318 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
319 weld::Window* pParent = mpViewShell ? mpViewShell->GetFrameWeld() : nullptr;
320 ScopedVclPtr<AbstractSdInsertPagesObjsDlg> pDlg( pFact->CreateSdInsertPagesObjsDlg(pParent, mpDoc, pMedium, aFile) );
322 sal_uInt16 nRet = pDlg->Execute();
324 mpDocSh->SetWaitCursor( true );
326 if( nRet == RET_OK )
328 /* list with page names (if NULL, then all pages)
329 First, insert pages */
330 std::vector<OUString> aBookmarkList = pDlg->GetList( 1 ); // pages
331 bool bLink = pDlg->IsLink();
332 SdPage* pPage = nullptr;
333 ::sd::View* pView = mpViewShell ? mpViewShell->GetView() : nullptr;
335 if (pView)
337 if( auto pOutlineView = dynamic_cast<OutlineView *>( pView ))
339 pPage = pOutlineView->GetActualPage();
341 else
343 pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
347 sal_uInt16 nPos = 0xFFFF;
349 if (pPage && !pPage->IsMasterPage())
351 if (pPage->GetPageKind() == PageKind::Standard)
353 nPos = pPage->GetPageNum() + 2;
355 else if (pPage->GetPageKind() == PageKind::Notes)
357 nPos = pPage->GetPageNum() + 1;
361 bool bNameOK;
362 std::vector<OUString> aExchangeList;
363 std::vector<OUString> aObjectBookmarkList = pDlg->GetList( 2 ); // objects
365 /* if pBookmarkList is NULL, we insert selected pages, and/or selected
366 objects or everything. */
367 if( !aBookmarkList.empty() || aObjectBookmarkList.empty() )
369 /* To ensure that all page names are unique, we check the ones we
370 want to insert and insert them into a substitution list if
371 necessary.
372 bNameOK is sal_False if the user has canceled. */
373 bNameOK = mpView->GetExchangeList( aExchangeList, aBookmarkList, 0 );
375 if( bNameOK )
376 bOK = mpDoc->InsertBookmarkAsPage( aBookmarkList, &aExchangeList,
377 bLink, false/*bReplace*/, nPos,
378 false, nullptr, true, true, false );
380 aBookmarkList.clear();
381 aExchangeList.clear();
384 // to ensure ... (see above)
385 bNameOK = mpView->GetExchangeList( aExchangeList, aObjectBookmarkList, 1 );
387 if( bNameOK )
388 bOK = mpDoc->InsertBookmarkAsObject( aObjectBookmarkList, aExchangeList,
389 nullptr, nullptr, false );
391 if( pDlg->IsRemoveUnnecessaryMasterPages() )
392 mpDoc->RemoveUnnecessaryMasterPages();
395 return bOK;
398 void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
400 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
401 ScopedVclPtr<AbstractSdInsertPagesObjsDlg> pDlg( pFact->CreateSdInsertPagesObjsDlg(mpViewShell->GetFrameWeld(), mpDoc, nullptr, aFile) );
403 mpDocSh->SetWaitCursor( false );
405 sal_uInt16 nRet = pDlg->Execute();
406 mpDocSh->SetWaitCursor( true );
408 if( nRet != RET_OK )
409 return;
411 // selected file format: text, RTF or HTML (default is text)
412 EETextFormat nFormat = EETextFormat::Text;
414 if( aFilterName.indexOf( "Rich") != -1 )
415 nFormat = EETextFormat::Rtf;
416 else if( aFilterName.indexOf( "HTML" ) != -1 )
417 nFormat = EETextFormat::Html;
419 /* create our own outline since:
420 - it is possible that the document outliner is actually used in the
421 structuring mode
422 - the draw outliner of the drawing engine has to draw something in
423 between
424 - the global outliner could be used in SdPage::CreatePresObj */
425 SdOutliner aOutliner( mpDoc, OutlinerMode::TextObject );
427 // set reference device
428 aOutliner.SetRefDevice(SdModule::get()->GetVirtualRefDevice());
430 SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
431 aLayoutName = pPage->GetLayoutName();
432 sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
433 if( nIndex != -1 )
434 aLayoutName = aLayoutName.copy(0, nIndex);
436 aOutliner.SetPaperSize(pPage->GetSize());
438 SvStream* pStream = pMedium->GetInStream();
439 assert(pStream && "No InStream!");
440 pStream->Seek( 0 );
442 ErrCode nErr = aOutliner.Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
444 if (nErr || !aOutliner.GetEditEngine().HasText())
446 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(mpWindow->GetFrameWeld(),
447 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
448 xErrorBox->run();
450 else
452 // is it a master page?
453 if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EditMode::MasterPage &&
454 !pPage->IsMasterPage())
456 pPage = static_cast<SdPage*>(&(pPage->TRG_GetMasterPage()));
459 assert(pPage && "page not found");
461 // if editing is going on right now, let it flow into this text object
462 OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
463 if( pOutlinerView )
465 SdrObject* pObj = mpView->GetTextEditObject();
466 if( pObj &&
467 pObj->GetObjInventor() == SdrInventor::Default &&
468 pObj->GetObjIdentifier() == SdrObjKind::TitleText &&
469 aOutliner.GetParagraphCount() > 1 )
471 // in title objects, only one paragraph is allowed
472 while ( aOutliner.GetParagraphCount() > 1 )
474 Paragraph* pPara = aOutliner.GetParagraph( 0 );
475 sal_uLong nLen = aOutliner.GetText( pPara ).getLength();
476 aOutliner.QuickInsertLineBreak(ESelection(0, nLen, 1, 0));
481 std::optional<OutlinerParaObject> pOPO = aOutliner.CreateParaObject();
483 if (pOutlinerView)
485 pOutlinerView->InsertText(*pOPO);
487 else
489 rtl::Reference<SdrRectObj> pTO = new SdrRectObj(
490 mpView->getSdrModelFromSdrView(),
491 SdrObjKind::Text);
492 pTO->SetOutlinerParaObject(std::move(pOPO));
494 const bool bUndo = mpView->IsUndoEnabled();
495 if( bUndo )
496 mpView->BegUndo(SdResId(STR_UNDO_INSERT_TEXTFRAME));
497 pPage->InsertObject(pTO.get());
499 /* can be bigger as the maximal allowed size:
500 limit object size if necessary */
501 Size aSize(aOutliner.CalcTextSize());
502 Size aMaxSize = mpDoc->GetMaxObjSize();
503 aSize.setHeight( std::min(aSize.Height(), aMaxSize.Height()) );
504 aSize.setWidth( std::min(aSize.Width(), aMaxSize.Width()) );
505 aSize = mpWindow->LogicToPixel(aSize);
507 // put it at the center of the window
508 Size aTemp(mpWindow->GetOutputSizePixel());
509 Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
510 aPos.AdjustX( -(aSize.Width() / 2) );
511 aPos.AdjustY( -(aSize.Height() / 2) );
512 aSize = mpWindow->PixelToLogic(aSize);
513 aPos = mpWindow->PixelToLogic(aPos);
514 pTO->SetLogicRect(::tools::Rectangle(aPos, aSize));
516 if (pDlg->IsLink())
518 pTO->SetTextLink(aFile, aFilterName );
521 if( bUndo )
523 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
524 mpView->EndUndo();
530 void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
532 // selected file format: text, RTF or HTML (default is text)
533 EETextFormat nFormat = EETextFormat::Text;
535 if( aFilterName.indexOf( "Rich") != -1 )
536 nFormat = EETextFormat::Rtf;
537 else if( aFilterName.indexOf( "HTML" ) != -1 )
538 nFormat = EETextFormat::Html;
540 ::Outliner& rDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
542 std::vector<Paragraph*> aSelList;
543 rDocliner.GetView(0)->CreateSelectionList(aSelList);
545 Paragraph* pPara = aSelList.empty() ? nullptr : *(aSelList.begin());
547 // what should we insert?
548 while (pPara && !Outliner::HasParaFlag(pPara, ParaFlag::ISPAGE))
549 pPara = rDocliner.GetParent(pPara);
551 sal_Int32 nTargetPos = rDocliner.GetAbsPos(pPara) + 1;
553 // apply layout of predecessor page
554 sal_uInt16 nPage = 0;
555 pPara = rDocliner.GetParagraph( rDocliner.GetAbsPos( pPara ) - 1 );
556 while (pPara)
558 sal_Int32 nPos = rDocliner.GetAbsPos( pPara );
559 if ( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
560 nPage++;
561 pPara = rDocliner.GetParagraph( nPos - 1 );
563 SdPage* pPage = mpDoc->GetSdPage(nPage, PageKind::Standard);
564 aLayoutName = pPage->GetLayoutName();
565 sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
566 if( nIndex != -1 )
567 aLayoutName = aLayoutName.copy(0, nIndex);
569 /* create our own outline since:
570 - it is possible that the document outliner is actually used in the
571 structuring mode
572 - the draw outliner of the drawing engine has to draw something in
573 between
574 - the global outliner could be used in SdPage::CreatePresObj */
575 ::Outliner aOutliner( &mpDoc->GetItemPool(), OutlinerMode::OutlineObject );
576 aOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
578 // set reference device
579 aOutliner.SetRefDevice(SdModule::get()->GetVirtualRefDevice());
580 aOutliner.SetPaperSize(Size(0x7fffffff, 0x7fffffff));
582 SvStream* pStream = pMedium->GetInStream();
583 assert(pStream && "No InStream!");
584 pStream->Seek( 0 );
586 ErrCode nErr = aOutliner.Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
588 if (nErr || !aOutliner.GetEditEngine().HasText())
590 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(mpWindow->GetFrameWeld(),
591 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
592 xErrorBox->run();
594 else
596 sal_Int32 nParaCount = aOutliner.GetParagraphCount();
598 // for progress bar: number of level-0-paragraphs
599 sal_uInt16 nNewPages = 0;
600 pPara = aOutliner.GetParagraph( 0 );
601 while (pPara)
603 sal_Int32 nPos = aOutliner.GetAbsPos( pPara );
604 if( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
605 nNewPages++;
606 pPara = aOutliner.GetParagraph( ++nPos );
609 mpDocSh->SetWaitCursor( false );
611 std::optional<SfxProgress> pProgress( std::in_place, mpDocSh, SdResId(STR_CREATE_PAGES), nNewPages);
612 pProgress->SetState( 0, 100 );
614 nNewPages = 0;
616 ViewShellId nViewShellId = mpViewShell ? mpViewShell->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
617 rDocliner.GetUndoManager().EnterListAction(
618 SdResId(STR_UNDO_INSERT_FILE), OUString(), 0, nViewShellId );
620 sal_Int32 nSourcePos = 0;
621 SfxStyleSheet* pStyleSheet = pPage->GetStyleSheetForPresObj( PresObjKind::Outline );
622 Paragraph* pSourcePara = aOutliner.GetParagraph( 0 );
623 while (pSourcePara)
625 sal_Int32 nPos = aOutliner.GetAbsPos( pSourcePara );
626 sal_Int16 nDepth = aOutliner.GetDepth( nPos );
628 // only take the last paragraph if it is filled
629 if (nSourcePos < nParaCount - 1 ||
630 !aOutliner.GetText(pSourcePara).isEmpty())
632 rDocliner.Insert( aOutliner.GetText(pSourcePara), nTargetPos, nDepth );
633 OUString aStyleSheetName( pStyleSheet->GetName() );
634 aStyleSheetName = aStyleSheetName.subView( 0, aStyleSheetName.getLength()-1 ) +
635 OUString::number( nDepth <= 0 ? 1 : nDepth+1 );
636 SfxStyleSheetBasePool* pStylePool = mpDoc->GetStyleSheetPool();
637 SfxStyleSheet* pOutlStyle = static_cast<SfxStyleSheet*>( pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() ) );
638 rDocliner.SetStyleSheet( nTargetPos, pOutlStyle );
641 if( Outliner::HasParaFlag( pSourcePara, ParaFlag::ISPAGE ) )
643 nNewPages++;
644 pProgress->SetState( nNewPages );
647 pSourcePara = aOutliner.GetParagraph( ++nPos );
648 nTargetPos++;
649 nSourcePos++;
652 rDocliner.GetUndoManager().LeaveListAction();
654 pProgress.reset();
656 mpDocSh->SetWaitCursor( true );
660 bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
662 OutlineView* pOlView = static_cast<OutlineView*>(mpView);
664 // transfer Outliner content to SdDrawDocument
665 pOlView->PrepareClose();
667 // read in like in the character mode
668 if (InsSDDinDrMode(pMedium))
670 ::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
672 // cut notification links temporarily
673 Link<Outliner::ParagraphHdlParam,void> aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
674 pOutliner->SetParaInsertedHdl( Link<Outliner::ParagraphHdlParam,void>());
675 Link<Outliner::ParagraphHdlParam,void> aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
676 pOutliner->SetParaRemovingHdl( Link<Outliner::ParagraphHdlParam,void>());
677 Link<Outliner::DepthChangeHdlParam,void> aOldDepthChangedHdl = pOutliner->GetDepthChangedHdl();
678 pOutliner->SetDepthChangedHdl( Link<::Outliner::DepthChangeHdlParam,void>());
679 Link<::Outliner*,void> aOldBeginMovingHdl = pOutliner->GetBeginMovingHdl();
680 pOutliner->SetBeginMovingHdl( Link<::Outliner*,void>());
681 Link<::Outliner*,void> aOldEndMovingHdl = pOutliner->GetEndMovingHdl();
682 pOutliner->SetEndMovingHdl( Link<::Outliner*,void>());
684 Link<EditStatus&,void> aOldStatusEventHdl = pOutliner->GetStatusEventHdl();
685 pOutliner->SetStatusEventHdl(Link<EditStatus&,void>());
687 pOutliner->Clear();
688 pOlView->FillOutliner();
690 // set links again
691 pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
692 pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
693 pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
694 pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
695 pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
696 pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
698 return true;
700 else
701 return false;
704 void FuInsertFile::GetSupportedFilterVector( ::std::vector< OUString >& rFilterVector )
706 SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
707 std::shared_ptr<const SfxFilter> pSearchFilter;
709 rFilterVector.clear();
711 if( ( pSearchFilter = rMatcher.GetFilter4Mime( u"text/plain"_ustr )) != nullptr )
712 rFilterVector.push_back( pSearchFilter->GetMimeType() );
714 if( ( pSearchFilter = rMatcher.GetFilter4Mime( u"application/rtf"_ustr ) ) != nullptr )
715 rFilterVector.push_back( pSearchFilter->GetMimeType() );
717 if( ( pSearchFilter = rMatcher.GetFilter4Mime( u"text/html"_ustr ) ) != nullptr )
718 rFilterVector.push_back( pSearchFilter->GetMimeType() );
721 } // end of namespace sd
723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */