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