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