xref: /aoo41x/main/sd/source/ui/func/fuinsfil.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "fuinsfil.hxx"
32 #include <vcl/wrkwin.hxx>
33 #include <sfx2/progress.hxx>
34 #include <editeng/outliner.hxx>
35 #ifndef _EDITENG_HXX
36 #include <editeng/editeng.hxx>
37 #endif
38 #include <svl/stritem.hxx>
39 #include <sfx2/request.hxx>
40 #include <sfx2/app.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <sfx2/printer.hxx>
43 #include <svx/svdorect.hxx>
44 #include <svx/svdundo.hxx>
45 #include <svx/svdoutl.hxx>
46 #include <sfx2/filedlghelper.hxx>
47 #include <sot/formats.hxx>
48 #include <svl/urihelper.hxx>
49 #include <editeng/forbiddencharacterstable.hxx>
50 #include <tools/urlobj.hxx>
51 #include <sfx2/docfile.hxx>
52 #include <sfx2/docfilt.hxx>
53 #include <sfx2/fcontnr.hxx>
54 #include <svx/svdpagv.hxx>
55 #include <svx/dialogs.hrc>
56 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
57 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
58 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
59 
60 #include "sdresid.hxx"
61 #include "drawdoc.hxx"
62 #include "Window.hxx"
63 #include "View.hxx"
64 #include "strings.hrc"
65 #include "stlpool.hxx"
66 #include "glob.hrc"
67 #include "sdpage.hxx"
68 #include "strmname.h"
69 #include "strings.hrc"
70 #include "DrawViewShell.hxx"
71 #include "OutlineViewShell.hxx"
72 #include "DrawDocShell.hxx"
73 #include "GraphicDocShell.hxx"
74 #include "app.hrc"
75 #include "unmovss.hxx"
76 #include "Outliner.hxx"
77 #include "sdabstdlg.hxx"
78 
79 using ::rtl::OUString;
80 using namespace ::com::sun::star::lang;
81 using namespace ::com::sun::star::uno;
82 using namespace ::com::sun::star::ui::dialogs;
83 using namespace ::com::sun::star;
84 
85 namespace sd {
86 
87 TYPEINIT1( FuInsertFile, FuPoor );
88 
89 #define POOL_BUFFER_SIZE		(sal_uInt16)32768
90 #define BASIC_BUFFER_SIZE		(sal_uInt16)8192
91 #define DOCUMENT_BUFFER_SIZE	(sal_uInt16)32768
92 
93 /*************************************************************************
94 |*
95 |* Konstruktor
96 |*
97 \************************************************************************/
98 
99 FuInsertFile::FuInsertFile (
100     ViewShell*    pViewSh,
101     ::sd::Window*	   pWin,
102     ::sd::View*		   pView,
103     SdDrawDocument* pDoc,
104     SfxRequest&	   rReq)
105     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
106 {
107 }
108 
109 FunctionReference FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
110 {
111 	FunctionReference xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
112 	xFunc->DoExecute(rReq);
113 	return xFunc;
114 }
115 
116 void FuInsertFile::DoExecute( SfxRequest& rReq )
117 {
118 	SfxFilterMatcher&       rMatcher = SFX_APP()->GetFilterMatcher();
119     ::std::vector< String > aFilterVector;
120 	const SfxItemSet*       pArgs = rReq.GetArgs ();
121 
122     FuInsertFile::GetSupportedFilterVector( aFilterVector );
123 
124     if (!pArgs)
125 	{
126         sfx2::FileDialogHelper      aFileDialog( WB_OPEN | SFXWB_INSERT | WB_STDMODAL );
127 		Reference< XFilePicker >    xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
128 		Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
129         String aOwnCont;
130         String aOtherCont;
131 		const SfxFilter*	        pFilter = NULL;
132 
133 		aFileDialog.SetTitle( String( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE ) ) );
134 
135 		if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
136         {
137             aOwnCont = String( RTL_CONSTASCII_USTRINGPARAM( "simpress" ) );
138             aOtherCont = String( RTL_CONSTASCII_USTRINGPARAM( "sdraw" ) ) ;
139         }
140 		else
141         {
142             aOtherCont = String( RTL_CONSTASCII_USTRINGPARAM( "simpress" ) );
143             aOwnCont = String( RTL_CONSTASCII_USTRINGPARAM( "sdraw" ) ) ;
144         }
145 
146         SfxFilterMatcher aMatch( aOwnCont );
147 
148 		if( xFilterManager.is() )
149 		{
150     		// Get filter for current format
151 			try
152 			{
153         		String  aExt;
154             	String  aAllSpec( SdResId( STR_ALL_FILES ) );
155 
156 				xFilterManager->appendFilter( aAllSpec, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.*" ) ) );
157 				xFilterManager->setCurrentFilter( aAllSpec ); // set default-filter (<All>)
158 
159 				// Get main filter
160                 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
161 				if( pFilter )
162 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
163 
164                 // get cross filter
165                 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
166 				if( pFilter )
167                 {
168                     pFilter = aMatch.GetFilter4Extension( pFilter->GetDefaultExtension() );
169                     if ( pFilter )
170                         xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
171                 }
172 
173                 // get femplate filter
174                 if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
175                     pFilter = DrawDocShell::Factory().GetTemplateFilter();
176                 else
177                     pFilter = GraphicDocShell::Factory().GetTemplateFilter();
178 				if( pFilter )
179 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
180 
181                 // get Powerpoint filter
182                 aExt = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( ".ppt" ) );
183 				pFilter = aMatch.GetFilter4Extension( aExt );
184 				if( pFilter )
185 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
186 
187                 // Get other draw/impress filters
188                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
189 				if( pFilter )
190 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
191 
192                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_TEMPLATEPATH );
193 				if( pFilter )
194 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
195 
196                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
197 				if( pFilter )
198 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
199 
200                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_TEMPLATEPATH  );
201 				if( pFilter )
202 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
203 
204                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
205 				if( pFilter )
206 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
207 
208             	pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_TEMPLATEPATH );
209 				if( pFilter )
210 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
211 
212                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
213 				if( pFilter )
214 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
215 
216             	pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_TEMPLATEPATH  );
217 				if( pFilter )
218 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
219 
220                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
221 				if( pFilter )
222 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
223 
224             	pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_TEMPLATEPATH  );
225 				if( pFilter )
226 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
227 
228                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
229 				if( pFilter )
230 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
231 
232             	pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_TEMPLATEPATH  );
233 				if( pFilter )
234 					xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
235 
236                 // add additional supported filters
237                 ::std::vector< String >::const_iterator aIter( aFilterVector.begin() );
238 
239                 while( aIter != aFilterVector.end() )
240                 {
241                     if( ( pFilter = rMatcher.GetFilter4Mime( *aIter ) ) != NULL )
242     		            xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
243 
244                     ++aIter;
245                 }
246 			}
247 			catch(IllegalArgumentException)
248 			{
249 			}
250 		}
251 
252 		if( aFileDialog.Execute() != ERRCODE_NONE )
253 			return;
254 		else
255 		{
256 			aFilterName = aFileDialog.GetCurrentFilter();
257 			aFile = aFileDialog.GetPath();
258 		}
259 	}
260 	else
261 	{
262 		SFX_REQUEST_ARG (rReq, pFileName, SfxStringItem, ID_VAL_DUMMY0, sal_False);
263 		SFX_REQUEST_ARG (rReq, pFilterName, SfxStringItem, ID_VAL_DUMMY1, sal_False);
264 
265 		aFile = pFileName->GetValue ();
266 
267 		if( pFilterName )
268 			aFilterName = pFilterName->GetValue ();
269 	}
270 
271 	mpDocSh->SetWaitCursor( sal_True );
272 
273 	SfxMedium*			pMedium = new SfxMedium( aFile, STREAM_READ | STREAM_NOCREATE, sal_False );
274 	const SfxFilter*	pFilter = NULL;
275 
276 	SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium, &pFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
277 
278 	sal_Bool				bDrawMode = mpViewShell && mpViewShell->ISA(DrawViewShell);
279     sal_Bool                bInserted = sal_False;
280 
281 	if( pFilter )
282     {
283 		pMedium->SetFilter( pFilter );
284         aFilterName = pFilter->GetFilterName();
285 
286         if( pMedium->IsStorage() || ( pMedium->GetInStream() && SotStorage::IsStorageFile( pMedium->GetInStream() ) ) )
287         {
288             if ( pFilter->GetServiceName().EqualsAscii( "com.sun.star.presentation.PresentationDocument" ) ||
289                  pFilter->GetServiceName().EqualsAscii( "com.sun.star.drawing.DrawingDocument" ) )
290             {
291                 // Draw, Impress or PowerPoint document
292                 // the ownership of the Medium is transferred
293                 if( bDrawMode )
294                     InsSDDinDrMode( pMedium );
295                 else
296                     InsSDDinOlMode( pMedium );
297 
298                 // don't delete Medium here, ownership of pMedium has changed in this case
299                 bInserted = sal_True;
300             }
301         }
302         else
303         {
304             sal_Bool bFound = ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFilter->GetMimeType() ) != aFilterVector.end() );
305             if( !bFound &&
306                 ( aFilterName.SearchAscii( "Text" ) != STRING_NOTFOUND ||
307                 aFilterName.SearchAscii( "Rich" ) != STRING_NOTFOUND ||
308                 aFilterName.SearchAscii( "RTF" )  != STRING_NOTFOUND ||
309                 aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND ) )
310             {
311                 bFound = sal_True;
312             }
313 
314             if( bFound )
315             {
316                 if( bDrawMode )
317                     InsTextOrRTFinDrMode(pMedium);
318                 else
319                     InsTextOrRTFinOlMode(pMedium);
320 
321                 bInserted = sal_True;
322                 delete pMedium;
323             }
324         }
325     }
326 
327 	mpDocSh->SetWaitCursor( sal_False );
328 
329     if( !bInserted )
330     {
331         ErrorBox aErrorBox( mpWindow, WB_OK, String( SdResId( STR_READ_DATA_ERROR ) ) );
332 		aErrorBox.Execute();
333         delete pMedium;
334     }
335 }
336 
337 // -----------------------------------------------------------------------------
338 
339 sal_Bool FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
340 {
341 	sal_Bool bOK = sal_False;
342 
343 	// Liste mit Seitennamen (wenn NULL, dann alle Seiten)
344 	List* pBookmarkList = NULL;
345 
346 	mpDocSh->SetWaitCursor( sal_False );
347     SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
348 	AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg( NULL, mpDoc, pMedium, aFile ) : 0;
349 
350 	if( !pDlg )
351 		return sal_False;
352 
353 	// Ev. wird eine QueryBox geoeffnet ("Links aktualisieren?"),
354 	// daher wird der Dialog der aktuelle DefModalDialogParent
355 	::Window* pDefParent = GetpApp()->GetDefDialogParent();
356     GetpApp()->SetDefDialogParent(pDlg->GetWindow());
357 
358 	sal_uInt16 nRet = pDlg->Execute();
359 
360 	GetpApp()->SetDefDialogParent(pDefParent);
361 
362 	mpDocSh->SetWaitCursor( sal_True );
363 
364 	if( nRet == RET_OK )
365 	{
366 		// Zuerst Seiten einfuegen
367 		pBookmarkList = pDlg->GetList( 1 ); // Seiten
368 		sal_Bool bLink = pDlg->IsLink();
369 		sal_Bool bReplace = sal_False;
370 		SdPage* pPage = NULL;
371 		::sd::View* pView = mpViewShell->GetView();
372 
373 		if (pView->ISA(OutlineView))
374 		{
375 			pPage = static_cast<OutlineView*>(pView)->GetActualPage();
376 		}
377 		else
378 		{
379 			pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
380 		}
381 
382 		sal_uInt16 nPos = 0xFFFF;
383 
384 		if (pPage && !pPage->IsMasterPage())
385 		{
386 			if (pPage->GetPageKind() == PK_STANDARD)
387 			{
388 				nPos = pPage->GetPageNum() + 2;
389 			}
390 			else if (pPage->GetPageKind() == PK_NOTES)
391 			{
392 				nPos = pPage->GetPageNum() + 1;
393 			}
394 		}
395 
396 		sal_Bool  bNameOK;
397 		List* pObjectBookmarkList = pDlg->GetList( 2 ); // Objekte
398 		List* pExchangeList = NULL;
399 
400 		// Es werden ausgewaehlte Seiten und/oder ausgewaehlte Objekte oder
401 		// alles eingefuegt, wenn pBookmarkList NULL ist!
402 		if( pBookmarkList || !pObjectBookmarkList )
403 		{
404 			// Um zu gewaehrleisten, dass alle Seitennamen eindeutig sind, werden
405 			// die einzufuegenden geprueft und gegebenenfalls in einer Ersatzliste
406 			// aufgenommen
407 			// bNameOK == sal_False -> Benutzer hat abgebrochen
408 			bNameOK = mpView->GetExchangeList( pExchangeList, pBookmarkList, 0 );
409 
410 			if( bNameOK )
411 				bOK = mpDoc->InsertBookmarkAsPage( pBookmarkList, pExchangeList,
412 									bLink, bReplace, nPos,
413 									sal_False, NULL, sal_True, sal_True, sal_False );
414 
415 			// Loeschen der BookmarkList
416 			if( pBookmarkList )
417 			{
418 				String* pString = (String*) pBookmarkList->First();
419 				while( pString )
420 				{
421 					delete pString;
422 					pString = (String*) pBookmarkList->Next();
423 				}
424 				delete pBookmarkList;
425 				pBookmarkList = NULL;
426 			}
427 			// Loeschen der ExchangeList
428 			if( pExchangeList )
429 			{
430 				String* pString = (String*) pExchangeList->First();
431 				while( pString )
432 				{
433 					delete pString;
434 					pString = (String*) pExchangeList->Next();
435 				}
436 				delete pExchangeList;
437 				pExchangeList = NULL;
438 			}
439 		}
440 		// Dann Objekte einfuegen
441 		//pBookmarkList = pDlg->GetList( 2 ); // Objekte
442 		pBookmarkList = pObjectBookmarkList;
443 
444 		// Um zu gewaehrleisten... (s.o.)
445 		bNameOK = mpView->GetExchangeList( pExchangeList, pBookmarkList, 1 );
446 
447 		if( bNameOK )
448 			bOK = mpDoc->InsertBookmarkAsObject( pBookmarkList, pExchangeList,
449 								bLink, NULL, NULL);
450 
451 		// Loeschen der BookmarkList
452 		if( pBookmarkList )
453 		{
454 			String* pString = (String*) pBookmarkList->First();
455 			while( pString )
456 			{
457 				delete pString;
458 				pString = (String*) pBookmarkList->Next();
459 			}
460 			delete pBookmarkList;
461 			pBookmarkList = NULL;
462 		}
463 		// Loeschen der ExchangeList
464 		if( pExchangeList )
465 		{
466 			String* pString = (String*) pExchangeList->First();
467 			while( pString )
468 			{
469 				delete pString;
470 				pString = (String*) pExchangeList->Next();
471 			}
472 			delete pExchangeList;
473 			pExchangeList = NULL;
474 		}
475 
476 		if( pDlg->IsRemoveUnnessesaryMasterPages() )
477 			mpDoc->RemoveUnnecessaryMasterPages();
478 	}
479 
480 	delete pDlg;
481 
482 	return (bOK);
483 }
484 
485 // -----------------------------------------------------------------------------
486 
487 void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
488 {
489 	SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
490 	AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg(NULL, mpDoc, NULL, aFile ) : 0;
491 	if( !pDlg )
492 		return;
493 
494 	mpDocSh->SetWaitCursor( sal_False );
495 
496 	sal_uInt16 nRet = pDlg->Execute();
497 	mpDocSh->SetWaitCursor( sal_True );
498 
499 	if( nRet == RET_OK )
500 	{
501 		// gewaehltes Dateiformat: Text oder RTF oder HTML (Default ist Text)
502 		sal_uInt16 nFormat = EE_FORMAT_TEXT;
503 
504 		if( aFilterName.SearchAscii( "Rich") != STRING_NOTFOUND )
505 			nFormat = EE_FORMAT_RTF;
506 		else if( aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND )
507 			nFormat = EE_FORMAT_HTML;
508 
509 		// einen eigenen Outliner erzeugen, denn:
510 		// der Dokument-Outliner koennte gerade vom Gliederungsmodus
511 		// benutzt werden;
512 		// der Draw-Outliner der Drawing Engine koennte zwischendurch
513 		// was zeichnen muessen;
514 		// der globale Outliner koennte in SdPage::CreatePresObj
515 		// benutzt werden
516 //		SfxItemPool* pPool = mpDoc->GetDrawOutliner().GetEmptyItemSet().GetPool();
517 		SdrOutliner* pOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
518 //		pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)mpDoc->GetStyleSheetPool());
519 //		pOutliner->SetEditTextObjectPool(pPool);
520 //		pOutliner->SetForbiddenCharsTable( mpDoc->GetForbiddenCharsTable() );
521 
522 		// Referenz-Device setzen
523 		pOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
524 
525 		SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
526 		aLayoutName = pPage->GetLayoutName();
527 		aLayoutName.Erase(aLayoutName.SearchAscii(SD_LT_SEPARATOR));
528 
529 		pOutliner->SetPaperSize(pPage->GetSize());
530 
531 		SvStream* pStream = pMedium->GetInStream();
532 		DBG_ASSERT( pStream, "Kein InStream!" );
533 		pStream->Seek( 0 );
534 
535         sal_uLong nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
536 
537 		if (nErr || !pOutliner->GetEditEngine().GetText().Len())
538 		{
539 			ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
540 					  String(SdResId(STR_READ_DATA_ERROR)));
541 			aErrorBox.Execute();
542 		}
543 		else
544 		{
545 			// ist es eine Masterpage?
546 			if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EM_MASTERPAGE &&
547 				!pPage->IsMasterPage())
548 			{
549 				pPage = (SdPage*)(&(pPage->TRG_GetMasterPage()));
550 			}
551 
552 			DBG_ASSERT(pPage, "Seite nicht gefunden");
553 
554 			// wenn gerade editiert wird, in dieses Textobjekt einfliessen lassen
555 			OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
556 			if( pOutlinerView )
557 			{
558 				SdrObject* pObj = mpView->GetTextEditObject();
559 				if( pObj &&
560 					pObj->GetObjInventor()   == SdrInventor &&
561 					pObj->GetObjIdentifier() == OBJ_TITLETEXT &&
562 					pOutliner->GetParagraphCount() > 1 )
563 				{
564 					// In Titelobjekten darf nur ein Absatz vorhanden sein
565 					while ( pOutliner->GetParagraphCount() > 1 )
566 					{
567 						Paragraph* pPara = pOutliner->GetParagraph( 0 );
568 						sal_uLong nLen = pOutliner->GetText( pPara, 1 ).Len();
569 						pOutliner->QuickDelete( ESelection( 0, (sal_uInt16) nLen, 1, 0 ) );
570 						pOutliner->QuickInsertLineBreak( ESelection( 0, (sal_uInt16) nLen, 0, (sal_uInt16) nLen ) );
571 					}
572 				}
573 			}
574 
575 			OutlinerParaObject* pOPO = pOutliner->CreateParaObject();
576 
577 			if (pOutlinerView)
578 			{
579 				pOutlinerView->InsertText(*pOPO);
580 			}
581 			else
582 			{
583 				SdrRectObj* pTO = new SdrRectObj(OBJ_TEXT);
584 				pTO->SetOutlinerParaObject(pOPO);
585 
586 				const bool bUndo = mpView->IsUndoEnabled();
587 				if( bUndo )
588 					mpView->BegUndo(String(SdResId(STR_UNDO_INSERT_TEXTFRAME)));
589 				pPage->InsertObject(pTO);
590 
591 				// koennte groesser sein als die max. erlaubte Groesse:
592 				// falls noetig, die Objektgroesse begrenzen
593 				Size aSize(pOutliner->CalcTextSize());
594 				Size aMaxSize = mpDoc->GetMaxObjSize();
595 				aSize.Height() = Min(aSize.Height(), aMaxSize.Height());
596 				aSize.Width()  = Min(aSize.Width(), aMaxSize.Width());
597 				aSize = mpWindow->LogicToPixel(aSize);
598 
599 				// in der Mitte des Fensters absetzen
600 				Size aTemp(mpWindow->GetOutputSizePixel());
601 				Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
602 				aPos.X() -= aSize.Width() / 2;
603 				aPos.Y() -= aSize.Height() / 2;
604 				aSize = mpWindow->PixelToLogic(aSize);
605 				aPos = mpWindow->PixelToLogic(aPos);
606 				pTO->SetLogicRect(Rectangle(aPos, aSize));
607 
608 				if (pDlg->IsLink())
609 				{
610 					pTO->SetTextLink(aFile, aFilterName, gsl_getSystemTextEncoding() );
611 				}
612 
613 				if( bUndo )
614 				{
615 					mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
616 					mpView->EndUndo();
617 				}
618 			}
619 		}
620 		delete pOutliner;
621 	}
622 
623 	delete pDlg;
624 }
625 
626 // -----------------------------------------------------------------------------
627 
628 void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
629 {
630 	// gewaehltes Dateiformat: Text oder RTF oder HTML (Default ist Text)
631 	sal_uInt16 nFormat = EE_FORMAT_TEXT;
632 
633 	if( aFilterName.SearchAscii( "Rich") != STRING_NOTFOUND )
634 		nFormat = EE_FORMAT_RTF;
635 	else if( aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND )
636 		nFormat = EE_FORMAT_HTML;
637 
638 	::Outliner*	   pDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
639 	List*		   pList	 = pDocliner->GetView(0)->CreateSelectionList();
640 	Paragraph*	   pPara	 = (Paragraph*)pList->First();
641 
642 	// wo soll eingefuegt werden?
643 	while( !pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
644 	{
645 		pPara = pDocliner->GetParent(pPara);
646 	}
647 	sal_uLong nTargetPos = pDocliner->GetAbsPos(pPara) + 1;
648 
649 	// Layout der Vorgaengerseite uebernehmen
650 	sal_uInt16 nPage = 0;
651 	pPara = pDocliner->GetParagraph( pDocliner->GetAbsPos( pPara ) - 1 );
652 	while (pPara)
653 	{
654 		sal_uLong nPos = pDocliner->GetAbsPos( pPara );
655 		if ( pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
656 			nPage++;
657 		pPara = pDocliner->GetParagraph( nPos - 1 );
658 	}
659 	SdPage* pPage = mpDoc->GetSdPage(nPage, PK_STANDARD);
660 	aLayoutName = pPage->GetLayoutName();
661 	aLayoutName.Erase(aLayoutName.SearchAscii(SD_LT_SEPARATOR));
662 
663 	// einen eigenen Outliner erzeugen, denn:
664 	// der Dokument-Outliner koennte gerade vom Gliederungsmodus
665 	// benutzt werden;
666 	// der Draw-Outliner der Drawing Engine koennte zwischendurch
667 	// was zeichnen muessen;
668 	// der globale Outliner koennte in SdPage::CreatePresObj
669 	// benutzt werden
670 	::Outliner* pOutliner = new ::Outliner( &mpDoc->GetItemPool(), OUTLINERMODE_OUTLINEOBJECT );
671 	pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)mpDoc->GetStyleSheetPool());
672 
673 	// Referenz-Device setzen
674 	pOutliner->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
675 	pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
676 
677 	SvStream* pStream = pMedium->GetInStream();
678 	DBG_ASSERT( pStream, "Kein InStream!" );
679 	pStream->Seek( 0 );
680 
681     sal_uLong nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
682 
683 	if (nErr || !pOutliner->GetEditEngine().GetText().Len())
684 	{
685 		ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
686 				  String(SdResId(STR_READ_DATA_ERROR)));
687 		aErrorBox.Execute();
688 	}
689 	else
690 	{
691 		sal_uLong nParaCount = pOutliner->GetParagraphCount();
692 
693 		// fuer Fortschrittsanzeige: Anzahl der Ebene-0-Absaetze
694 		sal_uInt16 nNewPages = 0;
695 		pPara = pOutliner->GetParagraph( 0 );
696 		while (pPara)
697 		{
698 			sal_uLong nPos = pOutliner->GetAbsPos( pPara );
699 			if( pOutliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
700 				nNewPages++;
701 			pPara = pOutliner->GetParagraph( ++nPos );
702 		}
703 
704 		mpDocSh->SetWaitCursor( sal_False );
705 
706 		SfxProgress* pProgress = new SfxProgress( mpDocSh, String( SdResId(STR_CREATE_PAGES)), nNewPages);
707 		if( pProgress )
708 			pProgress->SetState( 0, 100 );
709 
710 		nNewPages = 0;
711 
712 		pDocliner->GetUndoManager().EnterListAction(
713 									String(SdResId(STR_UNDO_INSERT_FILE)), String() );
714 
715 		sal_uLong nSourcePos = 0;
716 		SfxStyleSheet* pStyleSheet = pPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
717 		Paragraph* pSourcePara = pOutliner->GetParagraph( 0 );
718 		while (pSourcePara)
719 		{
720 			sal_uLong nPos = pOutliner->GetAbsPos( pSourcePara );
721 			sal_Int16 nDepth = pOutliner->GetDepth( (sal_uInt16) nPos );
722 
723 			// den letzte Absatz nur uebernehmen, wenn er gefuellt ist
724 			if (nSourcePos < nParaCount - 1 ||
725 				pOutliner->GetText(pSourcePara).Len() > 0)
726 			{
727 				pDocliner->Insert( pOutliner->GetText(pSourcePara), nTargetPos, nDepth );
728 				String aStyleSheetName( pStyleSheet->GetName() );
729 				aStyleSheetName.Erase( aStyleSheetName.Len()-1, 1 );
730 				aStyleSheetName += String::CreateFromInt32( nDepth <= 0 ? 1 : nDepth+1 );
731 				SfxStyleSheetBasePool* pStylePool = mpDoc->GetStyleSheetPool();
732 				SfxStyleSheet* pOutlStyle = (SfxStyleSheet*) pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() );
733 				pDocliner->SetStyleSheet( nTargetPos, pOutlStyle );
734 			}
735 
736 			if( pDocliner->HasParaFlag( pSourcePara, PARAFLAG_ISPAGE ) )
737 			{
738 				nNewPages++;
739 				if( pProgress )
740 					pProgress->SetState( nNewPages );
741 			}
742 
743 			pSourcePara = pOutliner->GetParagraph( ++nPos );
744 			nTargetPos++;
745 			nSourcePos++;
746 		}
747 
748 		pDocliner->GetUndoManager().LeaveListAction();
749 
750 		if( pProgress )
751 			delete pProgress;
752 
753 		mpDocSh->SetWaitCursor( sal_True );
754 	}
755 
756 	delete pOutliner;
757 }
758 
759 // -----------------------------------------------------------------------------
760 
761 sal_Bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
762 {
763 	OutlineView* pOlView = static_cast<OutlineView*>(mpView);
764 
765 	// Outliner-Inhalte ins SdDrawDocument uebertragen
766 	pOlView->PrepareClose();
767 
768 	// einlesen wie im Zeichenmodus
769 	if (InsSDDinDrMode(pMedium))
770 	{
771 		::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
772 
773 		// Benachrichtigungs-Links temporaer trennen
774 		Link aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
775 		pOutliner->SetParaInsertedHdl( Link(NULL, NULL));
776 		Link aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
777 		pOutliner->SetParaRemovingHdl( Link(NULL, NULL));
778 		Link aOldDepthChangedHdl	  = pOutliner->GetDepthChangedHdl();
779 		pOutliner->SetDepthChangedHdl( Link(NULL, NULL));
780 		Link aOldBeginMovingHdl 	  = pOutliner->GetBeginMovingHdl();
781 		pOutliner->SetBeginMovingHdl( Link(NULL, NULL));
782 		Link aOldEndMovingHdl		  = pOutliner->GetEndMovingHdl();
783 		pOutliner->SetEndMovingHdl( Link(NULL, NULL));
784 
785 		Link aOldStatusEventHdl 	  = pOutliner->GetStatusEventHdl();
786 		pOutliner->SetStatusEventHdl(Link(NULL, NULL));
787 
788 		pOutliner->Clear();
789 		pOlView->FillOutliner();
790 
791 		// Links wieder setzen
792 		pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
793 		pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
794 		pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
795 		pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
796 		pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
797 		pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
798 
799         return sal_True;
800 	}
801     else
802         return sal_False;
803 }
804 
805 // -----------------------------------------------------------------------------
806 
807 void FuInsertFile::GetSupportedFilterVector( ::std::vector< String >& rFilterVector )
808 {
809 	SfxFilterMatcher&   rMatcher = SFX_APP()->GetFilterMatcher();
810     const SfxFilter*    pSearchFilter = NULL;
811 
812     rFilterVector.clear();
813 
814 	if( ( pSearchFilter = rMatcher.GetFilter4Mime( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "text/plain" ) ) ) ) != NULL )
815         rFilterVector.push_back( pSearchFilter->GetMimeType() );
816 
817 	if( ( pSearchFilter = rMatcher.GetFilter4Mime( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "application/rtf" ) ) ) ) != NULL )
818         rFilterVector.push_back( pSearchFilter->GetMimeType() );
819 
820 	if( ( pSearchFilter = rMatcher.GetFilter4Mime( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "text/html" ) ) ) ) != NULL )
821         rFilterVector.push_back( pSearchFilter->GetMimeType() );
822 }
823 
824 } // end of namespace sd
825