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