bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / fuinsfil.cxx
blob81a8da28fd646e3ba9be1a1b5f24465538d906f7
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 <com/sun/star/ui/dialogs/XFilterManager.hpp>
41 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
42 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
44 #include <sdresid.hxx>
45 #include <drawdoc.hxx>
46 #include <Window.hxx>
47 #include <View.hxx>
48 #include <strings.hrc>
49 #include <sdmod.hxx>
50 #include <sdpage.hxx>
51 #include <ViewShellBase.hxx>
52 #include <DrawViewShell.hxx>
53 #include <OutlineView.hxx>
54 #include <DrawDocShell.hxx>
55 #include <GraphicDocShell.hxx>
56 #include <app.hrc>
57 #include <Outliner.hxx>
58 #include <sdabstdlg.hxx>
59 #include <memory>
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::ui::dialogs;
64 using namespace ::com::sun::star;
66 typedef ::std::pair< OUString, OUString > FilterDesc;
68 namespace
71 OUString lcl_GetExtensionsList ( ::std::vector< FilterDesc > const& rFilterDescList )
73 OUStringBuffer aExtensions;
75 for (const auto& rFilterDesc : rFilterDescList)
77 OUString sWildcard = rFilterDesc.second;
79 if ( aExtensions.indexOf( sWildcard ) == -1 )
81 if ( !aExtensions.isEmpty() )
82 aExtensions.append(";");
83 aExtensions.append(sWildcard);
88 return aExtensions.makeStringAndClear();
91 void lcl_AddFilter ( ::std::vector< FilterDesc >& rFilterDescList,
92 const std::shared_ptr<const SfxFilter>& pFilter )
94 if (pFilter)
95 rFilterDescList.emplace_back( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
100 namespace sd {
103 FuInsertFile::FuInsertFile (
104 ViewShell* pViewSh,
105 ::sd::Window* pWin,
106 ::sd::View* pView,
107 SdDrawDocument* pDoc,
108 SfxRequest& rReq)
109 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
113 rtl::Reference<FuPoor> FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
115 rtl::Reference<FuPoor> xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
116 xFunc->DoExecute(rReq);
117 return xFunc;
120 void FuInsertFile::DoExecute( SfxRequest& rReq )
122 SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
123 ::std::vector< FilterDesc > aFilterVector;
124 ::std::vector< OUString > aOtherFilterVector;
125 const SfxItemSet* pArgs = rReq.GetArgs ();
127 FuInsertFile::GetSupportedFilterVector( aOtherFilterVector );
129 if (!pArgs)
131 sfx2::FileDialogHelper aFileDialog(
132 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
133 FileDialogFlags::Insert, mpWindow ? mpWindow->GetFrameWeld() : nullptr);
134 Reference< XFilePicker > xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
135 Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
136 OUString aOwnCont;
137 OUString aOtherCont;
139 aFileDialog.SetTitle( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE) );
141 if( mpDoc->GetDocumentType() == DocumentType::Impress )
143 aOwnCont = "simpress";
144 aOtherCont = "sdraw";
146 else
148 aOtherCont = "simpress";
149 aOwnCont = "sdraw" ;
152 SfxFilterMatcher aMatch( aOwnCont );
154 if( xFilterManager.is() )
156 // Get filter for current format
159 // Get main filter
160 std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
161 lcl_AddFilter( aFilterVector, pFilter );
163 // get template filter
164 if( mpDoc->GetDocumentType() == DocumentType::Impress )
165 pFilter = DrawDocShell::Factory().GetTemplateFilter();
166 else
167 pFilter = GraphicDocShell::Factory().GetTemplateFilter();
168 lcl_AddFilter( aFilterVector, pFilter );
170 // get cross filter
171 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
172 lcl_AddFilter( aFilterVector, pFilter );
174 // get Powerpoint filter
175 OUString aExt = ".ppt";
176 pFilter = aMatch.GetFilter4Extension( aExt );
177 lcl_AddFilter( aFilterVector, pFilter );
179 // Get other draw/impress filters
180 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
181 lcl_AddFilter( aFilterVector, pFilter );
183 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::TEMPLATEPATH );
184 lcl_AddFilter( aFilterVector, pFilter );
186 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
187 lcl_AddFilter( aFilterVector, pFilter );
189 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::TEMPLATEPATH );
190 lcl_AddFilter( aFilterVector, pFilter );
192 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
193 lcl_AddFilter( aFilterVector, pFilter );
195 pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::TEMPLATEPATH );
196 lcl_AddFilter( aFilterVector, pFilter );
198 // add additional supported filters
199 for( const auto& rOtherFilter : aOtherFilterVector )
201 if( ( pFilter = rMatcher.GetFilter4Mime( rOtherFilter ) ) != nullptr )
202 lcl_AddFilter( aFilterVector, pFilter );
205 // set "All supported formats" as the default filter
206 OUString aAllSpec( SdResId( STR_ALL_SUPPORTED_FORMATS ) );
207 OUString aExtensions = lcl_GetExtensionsList( aFilterVector );
208 OUString aGUIName = aAllSpec + " (" + aExtensions + ")";
210 xFilterManager->appendFilter( aGUIName, aExtensions );
211 xFilterManager->setCurrentFilter( aAllSpec );
213 // append individual filters
214 for( const auto& rFilter : aFilterVector )
216 xFilterManager->appendFilter( rFilter.first, rFilter.second );
219 // end with "All files" as fallback
220 xFilterManager->appendFilter( SdResId( STR_ALL_FILES ), "*.*" );
222 catch (const IllegalArgumentException&)
227 if( aFileDialog.Execute() != ERRCODE_NONE )
228 return;
229 else
231 aFilterName = aFileDialog.GetCurrentFilter();
232 aFile = aFileDialog.GetPath();
235 else
237 const SfxStringItem* pFileName = rReq.GetArg<SfxStringItem>(ID_VAL_DUMMY0);
238 const SfxStringItem* pFilterName = rReq.GetArg<SfxStringItem>(ID_VAL_DUMMY1);
240 aFile = pFileName->GetValue ();
242 if( pFilterName )
243 aFilterName = pFilterName->GetValue ();
246 mpDocSh->SetWaitCursor( true );
248 std::unique_ptr<SfxMedium> xMedium(new SfxMedium(aFile, StreamMode::READ | StreamMode::NOCREATE));
249 std::shared_ptr<const SfxFilter> pFilter;
251 SfxGetpApp()->GetFilterMatcher().GuessFilter(*xMedium, pFilter);
253 bool bDrawMode = dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr;
254 bool bInserted = false;
256 if( pFilter )
258 xMedium->SetFilter( pFilter );
259 aFilterName = pFilter->GetFilterName();
261 if( xMedium->IsStorage() || ( xMedium->GetInStream() && SotStorage::IsStorageFile( xMedium->GetInStream() ) ) )
263 if ( pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument" ||
264 pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument" )
266 // Draw, Impress or PowerPoint document
267 // the ownership of the Medium is transferred
268 if( bDrawMode )
269 InsSDDinDrMode(xMedium.release());
270 else
271 InsSDDinOlMode(xMedium.release());
273 // ownership of pMedium has changed in this case
274 bInserted = true;
277 else
279 bool bFound = ( ::std::find( aOtherFilterVector.begin(), aOtherFilterVector.end(), pFilter->GetMimeType() ) != aOtherFilterVector.end() );
280 if( !bFound &&
281 ( aFilterName.indexOf( "Text" ) != -1 ||
282 aFilterName.indexOf( "Rich" ) != -1 ||
283 aFilterName.indexOf( "RTF" ) != -1 ||
284 aFilterName.indexOf( "HTML" ) != -1 ) )
286 bFound = true;
289 if( bFound )
291 if( bDrawMode )
292 InsTextOrRTFinDrMode(xMedium.get());
293 else
294 InsTextOrRTFinOlMode(xMedium.get());
296 bInserted = true;
297 xMedium.reset();
302 mpDocSh->SetWaitCursor( false );
304 if( !bInserted )
306 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(mpWindow->GetFrameWeld(),
307 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
308 xErrorBox->run();
312 bool FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
314 bool bOK = false;
316 mpDocSh->SetWaitCursor( false );
317 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
318 weld::Window* pParent = mpViewShell ? mpViewShell->GetFrameWeld() : nullptr;
319 ScopedVclPtr<AbstractSdInsertPagesObjsDlg> pDlg( pFact->CreateSdInsertPagesObjsDlg(pParent, mpDoc, pMedium, aFile) );
321 sal_uInt16 nRet = pDlg->Execute();
323 mpDocSh->SetWaitCursor( true );
325 if( nRet == RET_OK )
327 /* list with page names (if NULL, then all pages)
328 First, insert pages */
329 std::vector<OUString> aBookmarkList = pDlg->GetList( 1 ); // pages
330 bool bLink = pDlg->IsLink();
331 SdPage* pPage = nullptr;
332 ::sd::View* pView = mpViewShell ? mpViewShell->GetView() : nullptr;
334 if (pView)
336 if( dynamic_cast< const OutlineView *>( pView ) != nullptr)
338 pPage = static_cast<OutlineView*>(pView)->GetActualPage();
340 else
342 pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
346 sal_uInt16 nPos = 0xFFFF;
348 if (pPage && !pPage->IsMasterPage())
350 if (pPage->GetPageKind() == PageKind::Standard)
352 nPos = pPage->GetPageNum() + 2;
354 else if (pPage->GetPageKind() == PageKind::Notes)
356 nPos = pPage->GetPageNum() + 1;
360 bool bNameOK;
361 std::vector<OUString> aExchangeList;
362 std::vector<OUString> aObjectBookmarkList = pDlg->GetList( 2 ); // objects
364 /* if pBookmarkList is NULL, we insert selected pages, and/or selected
365 objects or everything. */
366 if( !aBookmarkList.empty() || aObjectBookmarkList.empty() )
368 /* To ensure that all page names are unique, we check the ones we
369 want to insert and insert them into a substitution list if
370 necessary.
371 bNameOK is sal_False if the user has canceled. */
372 bNameOK = mpView->GetExchangeList( aExchangeList, aBookmarkList, 0 );
374 if( bNameOK )
375 bOK = mpDoc->InsertBookmarkAsPage( aBookmarkList, &aExchangeList,
376 bLink, false/*bReplace*/, nPos,
377 false, nullptr, true, true, false );
379 aBookmarkList.clear();
380 aExchangeList.clear();
383 // to ensure ... (see above)
384 bNameOK = mpView->GetExchangeList( aExchangeList, aObjectBookmarkList, 1 );
386 if( bNameOK )
387 bOK = mpDoc->InsertBookmarkAsObject( aObjectBookmarkList, aExchangeList,
388 nullptr, nullptr, false );
390 if( pDlg->IsRemoveUnnessesaryMasterPages() )
391 mpDoc->RemoveUnnecessaryMasterPages();
394 return bOK;
397 void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
399 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
400 ScopedVclPtr<AbstractSdInsertPagesObjsDlg> pDlg( pFact->CreateSdInsertPagesObjsDlg(mpViewShell->GetFrameWeld(), mpDoc, nullptr, aFile) );
402 mpDocSh->SetWaitCursor( false );
404 sal_uInt16 nRet = pDlg->Execute();
405 mpDocSh->SetWaitCursor( true );
407 if( nRet != RET_OK )
408 return;
410 // selected file format: text, RTF or HTML (default is text)
411 EETextFormat nFormat = EETextFormat::Text;
413 if( aFilterName.indexOf( "Rich") != -1 )
414 nFormat = EETextFormat::Rtf;
415 else if( aFilterName.indexOf( "HTML" ) != -1 )
416 nFormat = EETextFormat::Html;
418 /* create our own outline since:
419 - it is possible that the document outliner is actually used in the
420 structuring mode
421 - the draw outliner of the drawing engine has to draw something in
422 between
423 - the global outliner could be used in SdPage::CreatePresObj */
424 std::unique_ptr<SdrOutliner> pOutliner(new SdOutliner( mpDoc, OutlinerMode::TextObject ));
426 // set reference device
427 pOutliner->SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
429 SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
430 aLayoutName = pPage->GetLayoutName();
431 sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
432 if( nIndex != -1 )
433 aLayoutName = aLayoutName.copy(0, nIndex);
435 pOutliner->SetPaperSize(pPage->GetSize());
437 SvStream* pStream = pMedium->GetInStream();
438 assert(pStream && "No InStream!");
439 pStream->Seek( 0 );
441 ErrCode nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
443 if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
445 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(mpWindow->GetFrameWeld(),
446 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
447 xErrorBox->run();
449 else
451 // is it a master page?
452 if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EditMode::MasterPage &&
453 !pPage->IsMasterPage())
455 pPage = static_cast<SdPage*>(&(pPage->TRG_GetMasterPage()));
458 assert(pPage && "page not found");
460 // if editing is going on right now, let it flow into this text object
461 OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
462 if( pOutlinerView )
464 SdrObject* pObj = mpView->GetTextEditObject();
465 if( pObj &&
466 pObj->GetObjInventor() == SdrInventor::Default &&
467 pObj->GetObjIdentifier() == OBJ_TITLETEXT &&
468 pOutliner->GetParagraphCount() > 1 )
470 // in title objects, only one paragraph is allowed
471 while ( pOutliner->GetParagraphCount() > 1 )
473 Paragraph* pPara = pOutliner->GetParagraph( 0 );
474 sal_uLong nLen = pOutliner->GetText( pPara ).getLength();
475 pOutliner->QuickDelete( ESelection( 0, nLen, 1, 0 ) );
476 pOutliner->QuickInsertLineBreak( ESelection( 0, nLen, 0, nLen ) );
481 std::unique_ptr<OutlinerParaObject> pOPO = pOutliner->CreateParaObject();
483 if (pOutlinerView)
485 pOutlinerView->InsertText(*pOPO);
487 else
489 SdrRectObj* pTO = new SdrRectObj(
490 mpView->getSdrModelFromSdrView(),
491 OBJ_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);
499 /* can be bigger as the maximal allowed size:
500 limit object size if necessary */
501 Size aSize(pOutliner->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 std::unique_ptr< ::Outliner> pOutliner(new ::Outliner( &mpDoc->GetItemPool(), OutlinerMode::OutlineObject ));
576 pOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
578 // set reference device
579 pOutliner->SetRefDevice(SD_MOD()->GetVirtualRefDevice());
580 pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
582 SvStream* pStream = pMedium->GetInStream();
583 DBG_ASSERT( pStream, "No InStream!" );
584 pStream->Seek( 0 );
586 ErrCode nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
588 if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
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 = pOutliner->GetParagraphCount();
598 // for progress bar: number of level-0-paragraphs
599 sal_uInt16 nNewPages = 0;
600 pPara = pOutliner->GetParagraph( 0 );
601 while (pPara)
603 sal_Int32 nPos = pOutliner->GetAbsPos( pPara );
604 if( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
605 nNewPages++;
606 pPara = pOutliner->GetParagraph( ++nPos );
609 mpDocSh->SetWaitCursor( false );
611 std::unique_ptr<SfxProgress> pProgress(new SfxProgress( 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( PRESOBJ_OUTLINE );
622 Paragraph* pSourcePara = pOutliner->GetParagraph( 0 );
623 while (pSourcePara)
625 sal_Int32 nPos = pOutliner->GetAbsPos( pSourcePara );
626 sal_Int16 nDepth = pOutliner->GetDepth( nPos );
628 // only take the last paragraph if it is filled
629 if (nSourcePos < nParaCount - 1 ||
630 !pOutliner->GetText(pSourcePara).isEmpty())
632 rDocliner.Insert( pOutliner->GetText(pSourcePara), nTargetPos, nDepth );
633 OUString aStyleSheetName( pStyleSheet->GetName() );
634 aStyleSheetName = aStyleSheetName.copy( 0, aStyleSheetName.getLength()-1 );
635 aStyleSheetName += 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 = pOutliner->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( "text/plain" )) != nullptr )
712 rFilterVector.push_back( pSearchFilter->GetMimeType() );
714 if( ( pSearchFilter = rMatcher.GetFilter4Mime( "application/rtf" ) ) != nullptr )
715 rFilterVector.push_back( pSearchFilter->GetMimeType() );
717 if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/html" ) ) != nullptr )
718 rFilterVector.push_back( pSearchFilter->GetMimeType() );
721 } // end of namespace sd
723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */