bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / func / fuinsfil.cxx
blob932a942986e3011145bfa8d441a7c91dfbc96f8e
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 <svl/stritem.hxx>
27 #include <sfx2/request.hxx>
28 #include <sfx2/app.hxx>
29 #include <vcl/weld.hxx>
30 #include <svx/svdorect.hxx>
31 #include <svx/svdundo.hxx>
32 #include <svx/svdoutl.hxx>
33 #include <sfx2/filedlghelper.hxx>
34 #include <sot/formats.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/docfilt.hxx>
37 #include <sfx2/fcontnr.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <svx/svxids.hrc>
40 #include <tools/debug.hxx>
41 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
42 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
43 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
45 #include <sdresid.hxx>
46 #include <drawdoc.hxx>
47 #include <Window.hxx>
48 #include <View.hxx>
49 #include <strings.hrc>
50 #include <sdmod.hxx>
51 #include <sdpage.hxx>
52 #include <ViewShellBase.hxx>
53 #include <DrawViewShell.hxx>
54 #include <OutlineView.hxx>
55 #include <DrawDocShell.hxx>
56 #include <GraphicDocShell.hxx>
57 #include <app.hrc>
58 #include <Outliner.hxx>
59 #include <sdabstdlg.hxx>
60 #include <memory>
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::ui::dialogs;
65 using namespace ::com::sun::star;
67 typedef ::std::pair< OUString, OUString > FilterDesc;
69 namespace
72 OUString lcl_GetExtensionsList ( ::std::vector< FilterDesc > const& rFilterDescList )
74 OUStringBuffer aExtensions;
76 for (const auto& rFilterDesc : rFilterDescList)
78 OUString sWildcard = rFilterDesc.second;
80 if ( aExtensions.indexOf( sWildcard ) == -1 )
82 if ( !aExtensions.isEmpty() )
83 aExtensions.append(";");
84 aExtensions.append(sWildcard);
89 return aExtensions.makeStringAndClear();
92 void lcl_AddFilter ( ::std::vector< FilterDesc >& rFilterDescList,
93 const std::shared_ptr<const SfxFilter>& pFilter )
95 if (pFilter)
96 rFilterDescList.emplace_back( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
101 namespace sd {
104 FuInsertFile::FuInsertFile (
105 ViewShell* pViewSh,
106 ::sd::Window* pWin,
107 ::sd::View* pView,
108 SdDrawDocument* pDoc,
109 SfxRequest& rReq)
110 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
114 rtl::Reference<FuPoor> FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
116 rtl::Reference<FuPoor> xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
117 xFunc->DoExecute(rReq);
118 return xFunc;
121 void FuInsertFile::DoExecute( SfxRequest& rReq )
123 SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
124 ::std::vector< FilterDesc > aFilterVector;
125 ::std::vector< OUString > aOtherFilterVector;
126 const SfxItemSet* pArgs = rReq.GetArgs ();
128 FuInsertFile::GetSupportedFilterVector( aOtherFilterVector );
130 if (!pArgs)
132 sfx2::FileDialogHelper aFileDialog(
133 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
134 FileDialogFlags::Insert, mpWindow ? mpWindow->GetFrameWeld() : nullptr);
135 Reference< XFilePicker > xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
136 Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
137 OUString aOwnCont;
138 OUString aOtherCont;
140 aFileDialog.SetTitle( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE) );
142 if( mpDoc->GetDocumentType() == DocumentType::Impress )
144 aOwnCont = "simpress";
145 aOtherCont = "sdraw";
147 else
149 aOtherCont = "simpress";
150 aOwnCont = "sdraw" ;
153 SfxFilterMatcher aMatch( aOwnCont );
155 if( xFilterManager.is() )
157 // Get filter for current format
160 // Get main filter
161 std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
162 lcl_AddFilter( aFilterVector, pFilter );
164 // get template filter
165 if( mpDoc->GetDocumentType() == DocumentType::Impress )
166 pFilter = DrawDocShell::Factory().GetTemplateFilter();
167 else
168 pFilter = GraphicDocShell::Factory().GetTemplateFilter();
169 lcl_AddFilter( aFilterVector, pFilter );
171 // get cross filter
172 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
173 lcl_AddFilter( aFilterVector, pFilter );
175 // get Powerpoint filter
176 OUString aExt = ".ppt";
177 pFilter = aMatch.GetFilter4Extension( aExt );
178 lcl_AddFilter( aFilterVector, pFilter );
180 // Get other draw/impress filters
181 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
182 lcl_AddFilter( aFilterVector, pFilter );
184 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::TEMPLATEPATH );
185 lcl_AddFilter( aFilterVector, pFilter );
187 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
188 lcl_AddFilter( aFilterVector, pFilter );
190 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::TEMPLATEPATH );
191 lcl_AddFilter( aFilterVector, pFilter );
193 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
194 lcl_AddFilter( aFilterVector, pFilter );
196 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::TEMPLATEPATH );
197 lcl_AddFilter( aFilterVector, pFilter );
199 // add additional supported filters
200 for( const auto& rOtherFilter : aOtherFilterVector )
202 if( ( pFilter = rMatcher.GetFilter4Mime( rOtherFilter ) ) != nullptr )
203 lcl_AddFilter( aFilterVector, pFilter );
206 // set "All supported formats" as the default filter
207 OUString aAllSpec( SdResId( STR_ALL_SUPPORTED_FORMATS ) );
208 OUString aExtensions = lcl_GetExtensionsList( aFilterVector );
209 OUString aGUIName = aAllSpec + " (" + aExtensions + ")";
211 xFilterManager->appendFilter( aGUIName, aExtensions );
212 xFilterManager->setCurrentFilter( aAllSpec );
214 // append individual filters
215 for( const auto& rFilter : aFilterVector )
217 xFilterManager->appendFilter( rFilter.first, rFilter.second );
220 // end with "All files" as fallback
221 xFilterManager->appendFilter( SdResId( STR_ALL_FILES ), "*.*" );
223 catch (const IllegalArgumentException&)
228 if( aFileDialog.Execute() != ERRCODE_NONE )
229 return;
230 else
232 aFilterName = aFileDialog.GetCurrentFilter();
233 aFile = aFileDialog.GetPath();
236 else
238 const SfxStringItem* pFileName = rReq.GetArg<SfxStringItem>(ID_VAL_DUMMY0);
239 const SfxStringItem* pFilterName = rReq.GetArg<SfxStringItem>(ID_VAL_DUMMY1);
241 aFile = pFileName->GetValue ();
243 if( pFilterName )
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( dynamic_cast< const OutlineView *>( pView ) != nullptr)
339 pPage = static_cast<OutlineView*>(pView)->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->IsRemoveUnnessesaryMasterPages() )
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 std::unique_ptr<SdrOutliner> pOutliner(new SdOutliner( mpDoc, OutlinerMode::TextObject ));
427 // set reference device
428 pOutliner->SetRefDevice( SD_MOD()->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 pOutliner->SetPaperSize(pPage->GetSize());
438 SvStream* pStream = pMedium->GetInStream();
439 assert(pStream && "No InStream!");
440 pStream->Seek( 0 );
442 ErrCode nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
444 if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
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() == OBJ_TITLETEXT &&
469 pOutliner->GetParagraphCount() > 1 )
471 // in title objects, only one paragraph is allowed
472 while ( pOutliner->GetParagraphCount() > 1 )
474 Paragraph* pPara = pOutliner->GetParagraph( 0 );
475 sal_uLong nLen = pOutliner->GetText( pPara ).getLength();
476 pOutliner->QuickDelete( ESelection( 0, nLen, 1, 0 ) );
477 pOutliner->QuickInsertLineBreak( ESelection( 0, nLen, 0, nLen ) );
482 std::unique_ptr<OutlinerParaObject> pOPO = pOutliner->CreateParaObject();
484 if (pOutlinerView)
486 pOutlinerView->InsertText(*pOPO);
488 else
490 SdrRectObj* pTO = new SdrRectObj(
491 mpView->getSdrModelFromSdrView(),
492 OBJ_TEXT);
493 pTO->SetOutlinerParaObject(std::move(pOPO));
495 const bool bUndo = mpView->IsUndoEnabled();
496 if( bUndo )
497 mpView->BegUndo(SdResId(STR_UNDO_INSERT_TEXTFRAME));
498 pPage->InsertObject(pTO);
500 /* can be bigger as the maximal allowed size:
501 limit object size if necessary */
502 Size aSize(pOutliner->CalcTextSize());
503 Size aMaxSize = mpDoc->GetMaxObjSize();
504 aSize.setHeight( std::min(aSize.Height(), aMaxSize.Height()) );
505 aSize.setWidth( std::min(aSize.Width(), aMaxSize.Width()) );
506 aSize = mpWindow->LogicToPixel(aSize);
508 // put it at the center of the window
509 Size aTemp(mpWindow->GetOutputSizePixel());
510 Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
511 aPos.AdjustX( -(aSize.Width() / 2) );
512 aPos.AdjustY( -(aSize.Height() / 2) );
513 aSize = mpWindow->PixelToLogic(aSize);
514 aPos = mpWindow->PixelToLogic(aPos);
515 pTO->SetLogicRect(::tools::Rectangle(aPos, aSize));
517 if (pDlg->IsLink())
519 pTO->SetTextLink(aFile, aFilterName );
522 if( bUndo )
524 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
525 mpView->EndUndo();
531 void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
533 // selected file format: text, RTF or HTML (default is text)
534 EETextFormat nFormat = EETextFormat::Text;
536 if( aFilterName.indexOf( "Rich") != -1 )
537 nFormat = EETextFormat::Rtf;
538 else if( aFilterName.indexOf( "HTML" ) != -1 )
539 nFormat = EETextFormat::Html;
541 ::Outliner& rDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
543 std::vector<Paragraph*> aSelList;
544 rDocliner.GetView(0)->CreateSelectionList(aSelList);
546 Paragraph* pPara = aSelList.empty() ? nullptr : *(aSelList.begin());
548 // what should we insert?
549 while (pPara && !Outliner::HasParaFlag(pPara, ParaFlag::ISPAGE))
550 pPara = rDocliner.GetParent(pPara);
552 sal_Int32 nTargetPos = rDocliner.GetAbsPos(pPara) + 1;
554 // apply layout of predecessor page
555 sal_uInt16 nPage = 0;
556 pPara = rDocliner.GetParagraph( rDocliner.GetAbsPos( pPara ) - 1 );
557 while (pPara)
559 sal_Int32 nPos = rDocliner.GetAbsPos( pPara );
560 if ( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
561 nPage++;
562 pPara = rDocliner.GetParagraph( nPos - 1 );
564 SdPage* pPage = mpDoc->GetSdPage(nPage, PageKind::Standard);
565 aLayoutName = pPage->GetLayoutName();
566 sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
567 if( nIndex != -1 )
568 aLayoutName = aLayoutName.copy(0, nIndex);
570 /* create our own outline since:
571 - it is possible that the document outliner is actually used in the
572 structuring mode
573 - the draw outliner of the drawing engine has to draw something in
574 between
575 - the global outliner could be used in SdPage::CreatePresObj */
576 std::unique_ptr< ::Outliner> pOutliner(new ::Outliner( &mpDoc->GetItemPool(), OutlinerMode::OutlineObject ));
577 pOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
579 // set reference device
580 pOutliner->SetRefDevice(SD_MOD()->GetVirtualRefDevice());
581 pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
583 SvStream* pStream = pMedium->GetInStream();
584 DBG_ASSERT( pStream, "No InStream!" );
585 pStream->Seek( 0 );
587 ErrCode nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
589 if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
591 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(mpWindow->GetFrameWeld(),
592 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
593 xErrorBox->run();
595 else
597 sal_Int32 nParaCount = pOutliner->GetParagraphCount();
599 // for progress bar: number of level-0-paragraphs
600 sal_uInt16 nNewPages = 0;
601 pPara = pOutliner->GetParagraph( 0 );
602 while (pPara)
604 sal_Int32 nPos = pOutliner->GetAbsPos( pPara );
605 if( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
606 nNewPages++;
607 pPara = pOutliner->GetParagraph( ++nPos );
610 mpDocSh->SetWaitCursor( false );
612 std::unique_ptr<SfxProgress> pProgress(new SfxProgress( mpDocSh, SdResId(STR_CREATE_PAGES), nNewPages));
613 pProgress->SetState( 0, 100 );
615 nNewPages = 0;
617 ViewShellId nViewShellId = mpViewShell ? mpViewShell->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
618 rDocliner.GetUndoManager().EnterListAction(
619 SdResId(STR_UNDO_INSERT_FILE), OUString(), 0, nViewShellId );
621 sal_Int32 nSourcePos = 0;
622 SfxStyleSheet* pStyleSheet = pPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
623 Paragraph* pSourcePara = pOutliner->GetParagraph( 0 );
624 while (pSourcePara)
626 sal_Int32 nPos = pOutliner->GetAbsPos( pSourcePara );
627 sal_Int16 nDepth = pOutliner->GetDepth( nPos );
629 // only take the last paragraph if it is filled
630 if (nSourcePos < nParaCount - 1 ||
631 !pOutliner->GetText(pSourcePara).isEmpty())
633 rDocliner.Insert( pOutliner->GetText(pSourcePara), nTargetPos, nDepth );
634 OUString aStyleSheetName( pStyleSheet->GetName() );
635 aStyleSheetName = aStyleSheetName.copy( 0, aStyleSheetName.getLength()-1 ) +
636 OUString::number( nDepth <= 0 ? 1 : nDepth+1 );
637 SfxStyleSheetBasePool* pStylePool = mpDoc->GetStyleSheetPool();
638 SfxStyleSheet* pOutlStyle = static_cast<SfxStyleSheet*>( pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() ) );
639 rDocliner.SetStyleSheet( nTargetPos, pOutlStyle );
642 if( Outliner::HasParaFlag( pSourcePara, ParaFlag::ISPAGE ) )
644 nNewPages++;
645 pProgress->SetState( nNewPages );
648 pSourcePara = pOutliner->GetParagraph( ++nPos );
649 nTargetPos++;
650 nSourcePos++;
653 rDocliner.GetUndoManager().LeaveListAction();
655 pProgress.reset();
657 mpDocSh->SetWaitCursor( true );
661 bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
663 OutlineView* pOlView = static_cast<OutlineView*>(mpView);
665 // transfer Outliner content to SdDrawDocument
666 pOlView->PrepareClose();
668 // read in like in the character mode
669 if (InsSDDinDrMode(pMedium))
671 ::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
673 // cut notification links temporarily
674 Link<Outliner::ParagraphHdlParam,void> aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
675 pOutliner->SetParaInsertedHdl( Link<Outliner::ParagraphHdlParam,void>());
676 Link<Outliner::ParagraphHdlParam,void> aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
677 pOutliner->SetParaRemovingHdl( Link<Outliner::ParagraphHdlParam,void>());
678 Link<Outliner::DepthChangeHdlParam,void> aOldDepthChangedHdl = pOutliner->GetDepthChangedHdl();
679 pOutliner->SetDepthChangedHdl( Link<::Outliner::DepthChangeHdlParam,void>());
680 Link<::Outliner*,void> aOldBeginMovingHdl = pOutliner->GetBeginMovingHdl();
681 pOutliner->SetBeginMovingHdl( Link<::Outliner*,void>());
682 Link<::Outliner*,void> aOldEndMovingHdl = pOutliner->GetEndMovingHdl();
683 pOutliner->SetEndMovingHdl( Link<::Outliner*,void>());
685 Link<EditStatus&,void> aOldStatusEventHdl = pOutliner->GetStatusEventHdl();
686 pOutliner->SetStatusEventHdl(Link<EditStatus&,void>());
688 pOutliner->Clear();
689 pOlView->FillOutliner();
691 // set links again
692 pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
693 pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
694 pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
695 pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
696 pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
697 pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
699 return true;
701 else
702 return false;
705 void FuInsertFile::GetSupportedFilterVector( ::std::vector< OUString >& rFilterVector )
707 SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
708 std::shared_ptr<const SfxFilter> pSearchFilter;
710 rFilterVector.clear();
712 if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/plain" )) != nullptr )
713 rFilterVector.push_back( pSearchFilter->GetMimeType() );
715 if( ( pSearchFilter = rMatcher.GetFilter4Mime( "application/rtf" ) ) != nullptr )
716 rFilterVector.push_back( pSearchFilter->GetMimeType() );
718 if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/html" ) ) != nullptr )
719 rFilterVector.push_back( pSearchFilter->GetMimeType() );
722 } // end of namespace sd
724 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */