1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "fuinsfil.hxx"
22 #include <vcl/wrkwin.hxx>
23 #include <sfx2/progress.hxx>
24 #include <editeng/outliner.hxx>
25 #include <editeng/outlobj.hxx>
26 #include <editeng/editeng.hxx>
27 #include <svl/stritem.hxx>
28 #include <sfx2/request.hxx>
29 #include <sfx2/app.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <sfx2/printer.hxx>
32 #include <svx/svdorect.hxx>
33 #include <svx/svdundo.hxx>
34 #include <svx/svdoutl.hxx>
35 #include <sfx2/filedlghelper.hxx>
36 #include <sot/formats.hxx>
37 #include <svl/urihelper.hxx>
38 #include <editeng/forbiddencharacterstable.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/docfilt.hxx>
41 #include <sfx2/fcontnr.hxx>
42 #include <svx/svdpagv.hxx>
43 #include <svx/dialogs.hrc>
44 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
45 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
46 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
47 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49 #include "sdresid.hxx"
50 #include "drawdoc.hxx"
53 #include "strings.hrc"
54 #include "stlpool.hxx"
58 #include "DrawViewShell.hxx"
59 #include "OutlineViewShell.hxx"
60 #include "DrawDocShell.hxx"
61 #include "GraphicDocShell.hxx"
63 #include "unmovss.hxx"
64 #include "Outliner.hxx"
65 #include "sdabstdlg.hxx"
67 using namespace ::com::sun::star::lang
;
68 using namespace ::com::sun::star::uno
;
69 using namespace ::com::sun::star::ui::dialogs
;
70 using namespace ::com::sun::star
;
74 TYPEINIT1( FuInsertFile
, FuPoor
);
77 FuInsertFile::FuInsertFile (
83 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
87 FunctionReference
FuInsertFile::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
89 FunctionReference
xFunc( new FuInsertFile( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
90 xFunc
->DoExecute(rReq
);
94 void FuInsertFile::DoExecute( SfxRequest
& rReq
)
96 SfxFilterMatcher
& rMatcher
= SFX_APP()->GetFilterMatcher();
97 ::std::vector
< OUString
> aFilterVector
;
98 const SfxItemSet
* pArgs
= rReq
.GetArgs ();
100 FuInsertFile::GetSupportedFilterVector( aFilterVector
);
104 sfx2::FileDialogHelper
aFileDialog(
105 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
107 Reference
< XFilePicker
> xFilePicker( aFileDialog
.GetFilePicker(), UNO_QUERY
);
108 Reference
< XFilterManager
> xFilterManager( xFilePicker
, UNO_QUERY
);
111 const SfxFilter
* pFilter
= NULL
;
113 aFileDialog
.SetTitle( String( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE
) ) );
115 if( mpDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
)
117 aOwnCont
= "simpress";
118 aOtherCont
= "sdraw";
122 aOtherCont
= "simpress";
126 SfxFilterMatcher
aMatch( aOwnCont
);
128 if( xFilterManager
.is() )
130 // Get filter for current format
134 String
aAllSpec( SdResId( STR_ALL_FILES
) );
136 xFilterManager
->appendFilter( aAllSpec
, OUString("*.*") );
137 xFilterManager
->setCurrentFilter( aAllSpec
); // set default-filter (<All>)
140 pFilter
= SfxFilter::GetDefaultFilterFromFactory( aOwnCont
);
142 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
145 pFilter
= SfxFilter::GetDefaultFilterFromFactory( aOtherCont
);
148 pFilter
= aMatch
.GetFilter4Extension( pFilter
->GetDefaultExtension() );
150 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
153 // get femplate filter
154 if( mpDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
)
155 pFilter
= DrawDocShell::Factory().GetTemplateFilter();
157 pFilter
= GraphicDocShell::Factory().GetTemplateFilter();
159 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
161 // get Powerpoint filter
162 aExt
= OUString(".ppt");
163 pFilter
= aMatch
.GetFilter4Extension( aExt
);
165 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
167 // Get other draw/impress filters
168 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60
, SFX_FILTER_IMPORT
, SFX_FILTER_TEMPLATEPATH
);
170 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
172 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60
, SFX_FILTER_TEMPLATEPATH
);
174 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
176 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60
, SFX_FILTER_IMPORT
, SFX_FILTER_TEMPLATEPATH
);
178 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
180 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60
, SFX_FILTER_TEMPLATEPATH
);
182 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
184 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50
, SFX_FILTER_IMPORT
, SFX_FILTER_TEMPLATEPATH
);
186 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
188 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50
, SFX_FILTER_TEMPLATEPATH
);
190 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
192 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50
, SFX_FILTER_IMPORT
, SFX_FILTER_TEMPLATEPATH
);
194 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
196 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50
, SFX_FILTER_TEMPLATEPATH
);
198 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
200 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40
, SFX_FILTER_IMPORT
, SFX_FILTER_TEMPLATEPATH
);
202 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
204 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40
, SFX_FILTER_TEMPLATEPATH
);
206 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
208 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW
, SFX_FILTER_IMPORT
, SFX_FILTER_TEMPLATEPATH
);
210 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
212 pFilter
= aMatch
.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW
, SFX_FILTER_TEMPLATEPATH
);
214 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
216 // add additional supported filters
217 ::std::vector
< OUString
>::const_iterator
aIter( aFilterVector
.begin() );
219 while( aIter
!= aFilterVector
.end() )
221 if( ( pFilter
= rMatcher
.GetFilter4Mime( *aIter
) ) != NULL
)
222 xFilterManager
->appendFilter( pFilter
->GetUIName(), pFilter
->GetDefaultExtension() );
227 catch (const IllegalArgumentException
&)
232 if( aFileDialog
.Execute() != ERRCODE_NONE
)
236 aFilterName
= aFileDialog
.GetCurrentFilter();
237 aFile
= aFileDialog
.GetPath();
242 SFX_REQUEST_ARG (rReq
, pFileName
, SfxStringItem
, ID_VAL_DUMMY0
, sal_False
);
243 SFX_REQUEST_ARG (rReq
, pFilterName
, SfxStringItem
, ID_VAL_DUMMY1
, sal_False
);
245 aFile
= pFileName
->GetValue ();
248 aFilterName
= pFilterName
->GetValue ();
251 mpDocSh
->SetWaitCursor( sal_True
);
253 SfxMedium
* pMedium
= new SfxMedium( aFile
, STREAM_READ
| STREAM_NOCREATE
);
254 const SfxFilter
* pFilter
= NULL
;
256 SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium
, &pFilter
, SFX_FILTER_IMPORT
, SFX_FILTER_NOTINSTALLED
| SFX_FILTER_EXECUTABLE
);
258 sal_Bool bDrawMode
= mpViewShell
&& mpViewShell
->ISA(DrawViewShell
);
259 sal_Bool bInserted
= sal_False
;
263 pMedium
->SetFilter( pFilter
);
264 aFilterName
= pFilter
->GetFilterName();
266 if( pMedium
->IsStorage() || ( pMedium
->GetInStream() && SotStorage::IsStorageFile( pMedium
->GetInStream() ) ) )
268 if ( pFilter
->GetServiceName() == "com.sun.star.presentation.PresentationDocument" ||
269 pFilter
->GetServiceName() == "com.sun.star.drawing.DrawingDocument" )
271 // Draw, Impress or PowerPoint document
272 // the ownership of the Medium is transferred
274 InsSDDinDrMode( pMedium
);
276 InsSDDinOlMode( pMedium
);
278 // don't delete Medium here, ownership of pMedium has changed in this case
279 bInserted
= sal_True
;
284 sal_Bool bFound
= ( ::std::find( aFilterVector
.begin(), aFilterVector
.end(), pFilter
->GetMimeType() ) != aFilterVector
.end() );
286 ( aFilterName
.SearchAscii( "Text" ) != STRING_NOTFOUND
||
287 aFilterName
.SearchAscii( "Rich" ) != STRING_NOTFOUND
||
288 aFilterName
.SearchAscii( "RTF" ) != STRING_NOTFOUND
||
289 aFilterName
.SearchAscii( "HTML" ) != STRING_NOTFOUND
) )
297 InsTextOrRTFinDrMode(pMedium
);
299 InsTextOrRTFinOlMode(pMedium
);
301 bInserted
= sal_True
;
307 mpDocSh
->SetWaitCursor( sal_False
);
311 ErrorBox
aErrorBox( mpWindow
, WB_OK
, String( SdResId( STR_READ_DATA_ERROR
) ) );
317 // -----------------------------------------------------------------------------
319 sal_Bool
FuInsertFile::InsSDDinDrMode(SfxMedium
* pMedium
)
321 sal_Bool bOK
= sal_False
;
323 mpDocSh
->SetWaitCursor( sal_False
);
324 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
325 AbstractSdInsertPagesObjsDlg
* pDlg
= pFact
? pFact
->CreateSdInsertPagesObjsDlg( NULL
, mpDoc
, pMedium
, aFile
) : 0;
330 /* Maybe a QueryBox is opened ("update links?"), therefore the dialog
331 becomes the current DefModalDialogParent */
332 ::Window
* pDefParent
= GetpApp()->GetDefDialogParent();
333 GetpApp()->SetDefDialogParent(pDlg
->GetWindow());
335 sal_uInt16 nRet
= pDlg
->Execute();
337 GetpApp()->SetDefDialogParent(pDefParent
);
339 mpDocSh
->SetWaitCursor( sal_True
);
343 /* list with page names (if NULL, then all pages)
344 First, insert pages */
345 std::vector
<OUString
> aBookmarkList
= pDlg
->GetList( 1 ); // pages
346 sal_Bool bLink
= pDlg
->IsLink();
347 sal_Bool bReplace
= sal_False
;
348 SdPage
* pPage
= NULL
;
349 ::sd::View
* pView
= mpViewShell
->GetView();
351 if (pView
->ISA(OutlineView
))
353 pPage
= static_cast<OutlineView
*>(pView
)->GetActualPage();
357 pPage
= static_cast<SdPage
*>(pView
->GetSdrPageView()->GetPage());
360 sal_uInt16 nPos
= 0xFFFF;
362 if (pPage
&& !pPage
->IsMasterPage())
364 if (pPage
->GetPageKind() == PK_STANDARD
)
366 nPos
= pPage
->GetPageNum() + 2;
368 else if (pPage
->GetPageKind() == PK_NOTES
)
370 nPos
= pPage
->GetPageNum() + 1;
375 std::vector
<OUString
> aExchangeList
;
376 std::vector
<OUString
> aObjectBookmarkList
= pDlg
->GetList( 2 ); // objects
378 /* if pBookmarkList is NULL, we insert selected pages, and/or selected
379 objects or everything. */
380 if( !aBookmarkList
.empty() || aObjectBookmarkList
.empty() )
382 /* To ensure that all page names are unique, we check the ones we
383 want to insert and insert them into a substitution list if
385 bNameOK is sal_False if the user has canceled. */
386 bNameOK
= mpView
->GetExchangeList( aExchangeList
, aBookmarkList
, 0 );
389 bOK
= mpDoc
->InsertBookmarkAsPage( aBookmarkList
, &aExchangeList
,
390 bLink
, bReplace
, nPos
,
391 sal_False
, NULL
, sal_True
, sal_True
, sal_False
);
393 aBookmarkList
.clear();
394 aExchangeList
.clear();
397 // to ensure ... (see above)
398 bNameOK
= mpView
->GetExchangeList( aExchangeList
, aObjectBookmarkList
, 1 );
401 bOK
= mpDoc
->InsertBookmarkAsObject( aObjectBookmarkList
, aExchangeList
,
404 if( pDlg
->IsRemoveUnnessesaryMasterPages() )
405 mpDoc
->RemoveUnnecessaryMasterPages();
413 // -----------------------------------------------------------------------------
415 void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium
* pMedium
)
417 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
418 AbstractSdInsertPagesObjsDlg
* pDlg
= pFact
? pFact
->CreateSdInsertPagesObjsDlg(NULL
, mpDoc
, NULL
, aFile
) : 0;
422 mpDocSh
->SetWaitCursor( sal_False
);
424 sal_uInt16 nRet
= pDlg
->Execute();
425 mpDocSh
->SetWaitCursor( sal_True
);
429 // selected file format: text, RTF or HTML (default is text)
430 sal_uInt16 nFormat
= EE_FORMAT_TEXT
;
432 if( aFilterName
.SearchAscii( "Rich") != STRING_NOTFOUND
)
433 nFormat
= EE_FORMAT_RTF
;
434 else if( aFilterName
.SearchAscii( "HTML" ) != STRING_NOTFOUND
)
435 nFormat
= EE_FORMAT_HTML
;
437 /* create our own outline since:
438 - it is possible that the document outliner is actually used in the
440 - the draw outliner of the drawing engine has to draw something in
442 - the global outliner could be used in SdPage::CreatePresObj */
443 SdrOutliner
* pOutliner
= new ::sd::Outliner( mpDoc
, OUTLINERMODE_TEXTOBJECT
);
445 // set reference device
446 pOutliner
->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh
) );
448 SdPage
* pPage
= static_cast<DrawViewShell
*>(mpViewShell
)->GetActualPage();
449 aLayoutName
= pPage
->GetLayoutName();
450 aLayoutName
.Erase(aLayoutName
.SearchAscii(SD_LT_SEPARATOR
));
452 pOutliner
->SetPaperSize(pPage
->GetSize());
454 SvStream
* pStream
= pMedium
->GetInStream();
455 DBG_ASSERT( pStream
, "No InStream!" );
458 sal_uLong nErr
= pOutliner
->Read( *pStream
, pMedium
->GetBaseURL(), nFormat
, mpDocSh
->GetHeaderAttributes() );
460 if (nErr
|| pOutliner
->GetEditEngine().GetText().isEmpty())
462 ErrorBox
aErrorBox( mpWindow
, (WinBits
)WB_OK
,
463 String(SdResId(STR_READ_DATA_ERROR
)));
468 // is it a master page?
469 if (static_cast<DrawViewShell
*>(mpViewShell
)->GetEditMode() == EM_MASTERPAGE
&&
470 !pPage
->IsMasterPage())
472 pPage
= (SdPage
*)(&(pPage
->TRG_GetMasterPage()));
475 DBG_ASSERT(pPage
, "page not found");
477 // if editing is going on right now, let it flow into this text object
478 OutlinerView
* pOutlinerView
= mpView
->GetTextEditOutlinerView();
481 SdrObject
* pObj
= mpView
->GetTextEditObject();
483 pObj
->GetObjInventor() == SdrInventor
&&
484 pObj
->GetObjIdentifier() == OBJ_TITLETEXT
&&
485 pOutliner
->GetParagraphCount() > 1 )
487 // in title objects, only one paragraph is allowed
488 while ( pOutliner
->GetParagraphCount() > 1 )
490 Paragraph
* pPara
= pOutliner
->GetParagraph( 0 );
491 sal_uLong nLen
= pOutliner
->GetText( pPara
, 1 ).Len();
492 pOutliner
->QuickDelete( ESelection( 0, (sal_uInt16
) nLen
, 1, 0 ) );
493 pOutliner
->QuickInsertLineBreak( ESelection( 0, (sal_uInt16
) nLen
, 0, (sal_uInt16
) nLen
) );
498 OutlinerParaObject
* pOPO
= pOutliner
->CreateParaObject();
502 pOutlinerView
->InsertText(*pOPO
);
507 SdrRectObj
* pTO
= new SdrRectObj(OBJ_TEXT
);
508 pTO
->SetOutlinerParaObject(pOPO
);
510 const bool bUndo
= mpView
->IsUndoEnabled();
512 mpView
->BegUndo(String(SdResId(STR_UNDO_INSERT_TEXTFRAME
)));
513 pPage
->InsertObject(pTO
);
515 /* can be bigger as the maximal allowed size:
516 limit object size if necessary */
517 Size
aSize(pOutliner
->CalcTextSize());
518 Size aMaxSize
= mpDoc
->GetMaxObjSize();
519 aSize
.Height() = std::min(aSize
.Height(), aMaxSize
.Height());
520 aSize
.Width() = std::min(aSize
.Width(), aMaxSize
.Width());
521 aSize
= mpWindow
->LogicToPixel(aSize
);
523 // put it at the center of the window
524 Size
aTemp(mpWindow
->GetOutputSizePixel());
525 Point
aPos(aTemp
.Width() / 2, aTemp
.Height() / 2);
526 aPos
.X() -= aSize
.Width() / 2;
527 aPos
.Y() -= aSize
.Height() / 2;
528 aSize
= mpWindow
->PixelToLogic(aSize
);
529 aPos
= mpWindow
->PixelToLogic(aPos
);
530 pTO
->SetLogicRect(Rectangle(aPos
, aSize
));
534 pTO
->SetTextLink(aFile
, aFilterName
, osl_getThreadTextEncoding() );
539 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoInsertObject(*pTO
));
550 // -----------------------------------------------------------------------------
552 void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium
* pMedium
)
554 // selected file format: text, RTF or HTML (default is text)
555 sal_uInt16 nFormat
= EE_FORMAT_TEXT
;
557 if( aFilterName
.SearchAscii( "Rich") != STRING_NOTFOUND
)
558 nFormat
= EE_FORMAT_RTF
;
559 else if( aFilterName
.SearchAscii( "HTML" ) != STRING_NOTFOUND
)
560 nFormat
= EE_FORMAT_HTML
;
562 ::Outliner
* pDocliner
= static_cast<OutlineView
*>(mpView
)->GetOutliner();
564 std::vector
<Paragraph
*> aSelList
;
565 pDocliner
->GetView(0)->CreateSelectionList(aSelList
);
567 Paragraph
* pPara
= aSelList
.empty() ? NULL
: *(aSelList
.begin());
569 // what should we insert?
570 while( !pDocliner
->HasParaFlag( pPara
, PARAFLAG_ISPAGE
) )
571 pPara
= pDocliner
->GetParent(pPara
);
573 sal_Int32 nTargetPos
= pDocliner
->GetAbsPos(pPara
) + 1;
575 // apply layout of predecessor page
576 sal_uInt16 nPage
= 0;
577 pPara
= pDocliner
->GetParagraph( pDocliner
->GetAbsPos( pPara
) - 1 );
580 sal_Int32 nPos
= pDocliner
->GetAbsPos( pPara
);
581 if ( pDocliner
->HasParaFlag( pPara
, PARAFLAG_ISPAGE
) )
583 pPara
= pDocliner
->GetParagraph( nPos
- 1 );
585 SdPage
* pPage
= mpDoc
->GetSdPage(nPage
, PK_STANDARD
);
586 aLayoutName
= pPage
->GetLayoutName();
587 aLayoutName
.Erase(aLayoutName
.SearchAscii(SD_LT_SEPARATOR
));
589 /* create our own outline since:
590 - it is possible that the document outliner is actually used in the
592 - the draw outliner of the drawing engine has to draw something in
594 - the global outliner could be used in SdPage::CreatePresObj */
595 ::Outliner
* pOutliner
= new ::Outliner( &mpDoc
->GetItemPool(), OUTLINERMODE_OUTLINEOBJECT
);
596 pOutliner
->SetStyleSheetPool((SfxStyleSheetPool
*)mpDoc
->GetStyleSheetPool());
598 // set reference device
599 pOutliner
->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh
));
600 pOutliner
->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
602 SvStream
* pStream
= pMedium
->GetInStream();
603 DBG_ASSERT( pStream
, "No InStream!" );
606 sal_uLong nErr
= pOutliner
->Read(*pStream
, pMedium
->GetBaseURL(), nFormat
, mpDocSh
->GetHeaderAttributes());
608 if (nErr
|| pOutliner
->GetEditEngine().GetText().isEmpty())
610 ErrorBox
aErrorBox( mpWindow
, (WinBits
)WB_OK
,
611 String(SdResId(STR_READ_DATA_ERROR
)));
616 sal_Int32 nParaCount
= pOutliner
->GetParagraphCount();
618 // for progress bar: number of level-0-paragraphs
619 sal_uInt16 nNewPages
= 0;
620 pPara
= pOutliner
->GetParagraph( 0 );
623 sal_Int32 nPos
= pOutliner
->GetAbsPos( pPara
);
624 if( pOutliner
->HasParaFlag( pPara
, PARAFLAG_ISPAGE
) )
626 pPara
= pOutliner
->GetParagraph( ++nPos
);
629 mpDocSh
->SetWaitCursor( sal_False
);
631 SfxProgress
* pProgress
= new SfxProgress( mpDocSh
, String( SdResId(STR_CREATE_PAGES
)), nNewPages
);
633 pProgress
->SetState( 0, 100 );
637 pDocliner
->GetUndoManager().EnterListAction(
638 String(SdResId(STR_UNDO_INSERT_FILE
)), String() );
640 sal_Int32 nSourcePos
= 0;
641 SfxStyleSheet
* pStyleSheet
= pPage
->GetStyleSheetForPresObj( PRESOBJ_OUTLINE
);
642 Paragraph
* pSourcePara
= pOutliner
->GetParagraph( 0 );
645 sal_Int32 nPos
= pOutliner
->GetAbsPos( pSourcePara
);
646 sal_Int16 nDepth
= pOutliner
->GetDepth( nPos
);
648 // only take the last paragraph if it is filled
649 if (nSourcePos
< nParaCount
- 1 ||
650 pOutliner
->GetText(pSourcePara
).Len() > 0)
652 pDocliner
->Insert( pOutliner
->GetText(pSourcePara
), nTargetPos
, nDepth
);
653 String
aStyleSheetName( pStyleSheet
->GetName() );
654 aStyleSheetName
.Erase( aStyleSheetName
.Len()-1, 1 );
655 aStyleSheetName
+= OUString::number( nDepth
<= 0 ? 1 : nDepth
+1 );
656 SfxStyleSheetBasePool
* pStylePool
= mpDoc
->GetStyleSheetPool();
657 SfxStyleSheet
* pOutlStyle
= (SfxStyleSheet
*) pStylePool
->Find( aStyleSheetName
, pStyleSheet
->GetFamily() );
658 pDocliner
->SetStyleSheet( nTargetPos
, pOutlStyle
);
661 if( pDocliner
->HasParaFlag( pSourcePara
, PARAFLAG_ISPAGE
) )
665 pProgress
->SetState( nNewPages
);
668 pSourcePara
= pOutliner
->GetParagraph( ++nPos
);
673 pDocliner
->GetUndoManager().LeaveListAction();
678 mpDocSh
->SetWaitCursor( sal_True
);
684 // -----------------------------------------------------------------------------
686 sal_Bool
FuInsertFile::InsSDDinOlMode(SfxMedium
* pMedium
)
688 OutlineView
* pOlView
= static_cast<OutlineView
*>(mpView
);
690 // transfer Outliner content to SdDrawDocument
691 pOlView
->PrepareClose();
693 // einlesen wie im Zeichenmodus
694 if (InsSDDinDrMode(pMedium
))
696 ::Outliner
* pOutliner
= pOlView
->GetViewByWindow(mpWindow
)->GetOutliner();
698 // cut notification links temporarily
699 Link aOldParagraphInsertedHdl
= pOutliner
->GetParaInsertedHdl();
700 pOutliner
->SetParaInsertedHdl( Link(NULL
, NULL
));
701 Link aOldParagraphRemovingHdl
= pOutliner
->GetParaRemovingHdl();
702 pOutliner
->SetParaRemovingHdl( Link(NULL
, NULL
));
703 Link aOldDepthChangedHdl
= pOutliner
->GetDepthChangedHdl();
704 pOutliner
->SetDepthChangedHdl( Link(NULL
, NULL
));
705 Link aOldBeginMovingHdl
= pOutliner
->GetBeginMovingHdl();
706 pOutliner
->SetBeginMovingHdl( Link(NULL
, NULL
));
707 Link aOldEndMovingHdl
= pOutliner
->GetEndMovingHdl();
708 pOutliner
->SetEndMovingHdl( Link(NULL
, NULL
));
710 Link aOldStatusEventHdl
= pOutliner
->GetStatusEventHdl();
711 pOutliner
->SetStatusEventHdl(Link(NULL
, NULL
));
714 pOlView
->FillOutliner();
717 pOutliner
->SetParaInsertedHdl(aOldParagraphInsertedHdl
);
718 pOutliner
->SetParaRemovingHdl(aOldParagraphRemovingHdl
);
719 pOutliner
->SetDepthChangedHdl(aOldDepthChangedHdl
);
720 pOutliner
->SetBeginMovingHdl(aOldBeginMovingHdl
);
721 pOutliner
->SetEndMovingHdl(aOldEndMovingHdl
);
722 pOutliner
->SetStatusEventHdl(aOldStatusEventHdl
);
730 // -----------------------------------------------------------------------------
732 void FuInsertFile::GetSupportedFilterVector( ::std::vector
< OUString
>& rFilterVector
)
734 SfxFilterMatcher
& rMatcher
= SFX_APP()->GetFilterMatcher();
735 const SfxFilter
* pSearchFilter
= NULL
;
737 rFilterVector
.clear();
739 if( ( pSearchFilter
= rMatcher
.GetFilter4Mime( "text/plain" )) != NULL
)
740 rFilterVector
.push_back( pSearchFilter
->GetMimeType() );
742 if( ( pSearchFilter
= rMatcher
.GetFilter4Mime( "application/rtf" ) ) != NULL
)
743 rFilterVector
.push_back( pSearchFilter
->GetMimeType() );
745 if( ( pSearchFilter
= rMatcher
.GetFilter4Mime( "text/html" ) ) != NULL
)
746 rFilterVector
.push_back( pSearchFilter
->GetMimeType() );
749 } // end of namespace sd
751 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */