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