Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "fuinsfil.hxx"
22 : #include <vcl/wrkwin.hxx>
23 : #include <sfx2/progress.hxx>
24 : #include <editeng/outliner.hxx>
25 : #include <editeng/outlobj.hxx>
26 : #include <editeng/editeng.hxx>
27 : #include <svl/stritem.hxx>
28 : #include <sfx2/request.hxx>
29 : #include <sfx2/app.hxx>
30 : #include <vcl/msgbox.hxx>
31 : #include <sfx2/printer.hxx>
32 : #include <svx/svdorect.hxx>
33 : #include <svx/svdundo.hxx>
34 : #include <svx/svdoutl.hxx>
35 : #include <sfx2/filedlghelper.hxx>
36 : #include <sot/formats.hxx>
37 : #include <svl/urihelper.hxx>
38 : #include <editeng/forbiddencharacterstable.hxx>
39 : #include <sfx2/docfile.hxx>
40 : #include <sfx2/docfilt.hxx>
41 : #include <sfx2/fcontnr.hxx>
42 : #include <svx/svdpagv.hxx>
43 : #include <svx/dialogs.hrc>
44 : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
45 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
46 : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
47 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
48 :
49 : #include "sdresid.hxx"
50 : #include "drawdoc.hxx"
51 : #include "Window.hxx"
52 : #include "View.hxx"
53 : #include "strings.hrc"
54 : #include "stlpool.hxx"
55 : #include "glob.hrc"
56 : #include "sdpage.hxx"
57 : #include "strmname.h"
58 : #include "DrawViewShell.hxx"
59 : #include "OutlineViewShell.hxx"
60 : #include "DrawDocShell.hxx"
61 : #include "GraphicDocShell.hxx"
62 : #include "app.hrc"
63 : #include "unmovss.hxx"
64 : #include "Outliner.hxx"
65 : #include "sdabstdlg.hxx"
66 :
67 : using namespace ::com::sun::star::lang;
68 : using namespace ::com::sun::star::uno;
69 : using namespace ::com::sun::star::ui::dialogs;
70 : using namespace ::com::sun::star;
71 :
72 : namespace sd {
73 :
74 0 : TYPEINIT1( FuInsertFile, FuPoor );
75 :
76 :
77 0 : FuInsertFile::FuInsertFile (
78 : ViewShell* pViewSh,
79 : ::sd::Window* pWin,
80 : ::sd::View* pView,
81 : SdDrawDocument* pDoc,
82 : SfxRequest& rReq)
83 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
84 : {
85 0 : }
86 :
87 0 : rtl::Reference<FuPoor> FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
88 : {
89 0 : rtl::Reference<FuPoor> xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
90 0 : xFunc->DoExecute(rReq);
91 0 : return xFunc;
92 : }
93 :
94 0 : void FuInsertFile::DoExecute( SfxRequest& rReq )
95 : {
96 0 : SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
97 0 : ::std::vector< OUString > aFilterVector;
98 0 : const SfxItemSet* pArgs = rReq.GetArgs ();
99 :
100 0 : FuInsertFile::GetSupportedFilterVector( aFilterVector );
101 :
102 0 : if (!pArgs)
103 : {
104 : sfx2::FileDialogHelper aFileDialog(
105 : ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
106 0 : SFXWB_INSERT );
107 0 : Reference< XFilePicker > xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
108 0 : Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
109 0 : OUString aOwnCont;
110 0 : OUString aOtherCont;
111 0 : const SfxFilter* pFilter = NULL;
112 :
113 0 : aFileDialog.SetTitle( SD_RESSTR(STR_DLG_INSERT_PAGES_FROM_FILE) );
114 :
115 0 : if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
116 : {
117 0 : aOwnCont = "simpress";
118 0 : aOtherCont = "sdraw";
119 : }
120 : else
121 : {
122 0 : aOtherCont = "simpress";
123 0 : aOwnCont = "sdraw" ;
124 : }
125 :
126 0 : SfxFilterMatcher aMatch( aOwnCont );
127 :
128 0 : if( xFilterManager.is() )
129 : {
130 : // Get filter for current format
131 : try
132 : {
133 0 : OUString aAllSpec( SD_RESSTR( STR_ALL_FILES ) );
134 :
135 0 : xFilterManager->appendFilter( aAllSpec, OUString("*.*") );
136 0 : xFilterManager->setCurrentFilter( aAllSpec ); // set default-filter (<All>)
137 :
138 : // Get main filter
139 0 : pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
140 0 : if( pFilter )
141 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
142 :
143 : // get cross filter
144 0 : pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
145 0 : if( pFilter )
146 : {
147 0 : pFilter = aMatch.GetFilter4Extension( pFilter->GetDefaultExtension() );
148 0 : if ( pFilter )
149 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
150 : }
151 :
152 : // get template filter
153 0 : if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
154 0 : pFilter = DrawDocShell::Factory().GetTemplateFilter();
155 : else
156 0 : pFilter = GraphicDocShell::Factory().GetTemplateFilter();
157 0 : if( pFilter )
158 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
159 :
160 : // get Powerpoint filter
161 0 : OUString aExt = ".ppt";
162 0 : pFilter = aMatch.GetFilter4Extension( aExt );
163 0 : if( pFilter )
164 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
165 :
166 : // Get other draw/impress filters
167 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
168 0 : if( pFilter )
169 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
170 :
171 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_TEMPLATEPATH );
172 0 : if( pFilter )
173 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
174 :
175 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
176 0 : if( pFilter )
177 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
178 :
179 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_TEMPLATEPATH );
180 0 : if( pFilter )
181 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
182 :
183 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
184 0 : if( pFilter )
185 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
186 :
187 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_TEMPLATEPATH );
188 0 : if( pFilter )
189 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
190 :
191 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
192 0 : if( pFilter )
193 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
194 :
195 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_TEMPLATEPATH );
196 0 : if( pFilter )
197 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
198 :
199 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
200 0 : if( pFilter )
201 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
202 :
203 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_TEMPLATEPATH );
204 0 : if( pFilter )
205 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
206 :
207 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
208 0 : if( pFilter )
209 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
210 :
211 0 : pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_TEMPLATEPATH );
212 0 : if( pFilter )
213 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
214 :
215 : // add additional supported filters
216 0 : ::std::vector< OUString >::const_iterator aIter( aFilterVector.begin() );
217 :
218 0 : while( aIter != aFilterVector.end() )
219 : {
220 0 : if( ( pFilter = rMatcher.GetFilter4Mime( *aIter ) ) != NULL )
221 0 : xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
222 :
223 0 : ++aIter;
224 0 : }
225 : }
226 0 : catch (const IllegalArgumentException&)
227 : {
228 : }
229 : }
230 :
231 0 : if( aFileDialog.Execute() != ERRCODE_NONE )
232 0 : return;
233 : else
234 : {
235 0 : aFilterName = aFileDialog.GetCurrentFilter();
236 0 : aFile = aFileDialog.GetPath();
237 0 : }
238 : }
239 : else
240 : {
241 0 : SFX_REQUEST_ARG (rReq, pFileName, SfxStringItem, ID_VAL_DUMMY0, false);
242 0 : SFX_REQUEST_ARG (rReq, pFilterName, SfxStringItem, ID_VAL_DUMMY1, false);
243 :
244 0 : aFile = pFileName->GetValue ();
245 :
246 0 : if( pFilterName )
247 0 : aFilterName = pFilterName->GetValue ();
248 : }
249 :
250 0 : mpDocSh->SetWaitCursor( true );
251 :
252 0 : SfxMedium* pMedium = new SfxMedium( aFile, STREAM_READ | STREAM_NOCREATE );
253 0 : const SfxFilter* pFilter = NULL;
254 :
255 0 : SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium, &pFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
256 :
257 0 : sal_Bool bDrawMode = mpViewShell && mpViewShell->ISA(DrawViewShell);
258 0 : sal_Bool bInserted = sal_False;
259 :
260 0 : if( pFilter )
261 : {
262 0 : pMedium->SetFilter( pFilter );
263 0 : aFilterName = pFilter->GetFilterName();
264 :
265 0 : if( pMedium->IsStorage() || ( pMedium->GetInStream() && SotStorage::IsStorageFile( pMedium->GetInStream() ) ) )
266 : {
267 0 : if ( pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument" ||
268 0 : pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument" )
269 : {
270 : // Draw, Impress or PowerPoint document
271 : // the ownership of the Medium is transferred
272 0 : if( bDrawMode )
273 0 : InsSDDinDrMode( pMedium );
274 : else
275 0 : InsSDDinOlMode( pMedium );
276 :
277 : // don't delete Medium here, ownership of pMedium has changed in this case
278 0 : bInserted = sal_True;
279 : }
280 : }
281 : else
282 : {
283 0 : sal_Bool bFound = ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFilter->GetMimeType() ) != aFilterVector.end() );
284 0 : if( !bFound &&
285 0 : ( aFilterName.indexOf( "Text" ) != -1 ||
286 0 : aFilterName.indexOf( "Rich" ) != -1 ||
287 0 : aFilterName.indexOf( "RTF" ) != -1 ||
288 0 : aFilterName.indexOf( "HTML" ) != -1 ) )
289 : {
290 0 : bFound = sal_True;
291 : }
292 :
293 0 : if( bFound )
294 : {
295 0 : if( bDrawMode )
296 0 : InsTextOrRTFinDrMode(pMedium);
297 : else
298 0 : InsTextOrRTFinOlMode(pMedium);
299 :
300 0 : bInserted = sal_True;
301 0 : delete pMedium;
302 : }
303 : }
304 : }
305 :
306 0 : mpDocSh->SetWaitCursor( false );
307 :
308 0 : if( !bInserted )
309 : {
310 0 : ErrorBox aErrorBox( mpWindow, WB_OK, SD_RESSTR( STR_READ_DATA_ERROR ) );
311 0 : aErrorBox.Execute();
312 0 : delete pMedium;
313 0 : }
314 : }
315 :
316 :
317 :
318 0 : sal_Bool FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
319 : {
320 0 : sal_Bool bOK = sal_False;
321 :
322 0 : mpDocSh->SetWaitCursor( false );
323 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
324 0 : AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg( NULL, mpDoc, pMedium, aFile ) : 0;
325 :
326 0 : if( !pDlg )
327 0 : return sal_False;
328 :
329 : /* Maybe a QueryBox is opened ("update links?"), therefore the dialog
330 : becomes the current DefModalDialogParent */
331 0 : ::Window* pDefParent = GetpApp()->GetDefDialogParent();
332 0 : GetpApp()->SetDefDialogParent(pDlg->GetWindow());
333 :
334 0 : sal_uInt16 nRet = pDlg->Execute();
335 :
336 0 : GetpApp()->SetDefDialogParent(pDefParent);
337 :
338 0 : mpDocSh->SetWaitCursor( true );
339 :
340 0 : if( nRet == RET_OK )
341 : {
342 : /* list with page names (if NULL, then all pages)
343 : First, insert pages */
344 0 : std::vector<OUString> aBookmarkList = pDlg->GetList( 1 ); // pages
345 0 : sal_Bool bLink = pDlg->IsLink();
346 0 : sal_Bool bReplace = sal_False;
347 0 : SdPage* pPage = NULL;
348 0 : ::sd::View* pView = mpViewShell->GetView();
349 :
350 0 : if (pView->ISA(OutlineView))
351 : {
352 0 : pPage = static_cast<OutlineView*>(pView)->GetActualPage();
353 : }
354 : else
355 : {
356 0 : pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
357 : }
358 :
359 0 : sal_uInt16 nPos = 0xFFFF;
360 :
361 0 : if (pPage && !pPage->IsMasterPage())
362 : {
363 0 : if (pPage->GetPageKind() == PK_STANDARD)
364 : {
365 0 : nPos = pPage->GetPageNum() + 2;
366 : }
367 0 : else if (pPage->GetPageKind() == PK_NOTES)
368 : {
369 0 : nPos = pPage->GetPageNum() + 1;
370 : }
371 : }
372 :
373 : sal_Bool bNameOK;
374 0 : std::vector<OUString> aExchangeList;
375 0 : std::vector<OUString> aObjectBookmarkList = pDlg->GetList( 2 ); // objects
376 :
377 : /* if pBookmarkList is NULL, we insert selected pages, and/or selected
378 : objects or everything. */
379 0 : if( !aBookmarkList.empty() || aObjectBookmarkList.empty() )
380 : {
381 : /* To ensure that all page names are unique, we check the ones we
382 : want to insert and insert them into a substitution list if
383 : necessary.
384 : bNameOK is sal_False if the user has canceled. */
385 0 : bNameOK = mpView->GetExchangeList( aExchangeList, aBookmarkList, 0 );
386 :
387 0 : if( bNameOK )
388 : bOK = mpDoc->InsertBookmarkAsPage( aBookmarkList, &aExchangeList,
389 : bLink, bReplace, nPos,
390 0 : sal_False, NULL, sal_True, sal_True, sal_False );
391 :
392 0 : aBookmarkList.clear();
393 0 : aExchangeList.clear();
394 : }
395 :
396 : // to ensure ... (see above)
397 0 : bNameOK = mpView->GetExchangeList( aExchangeList, aObjectBookmarkList, 1 );
398 :
399 0 : if( bNameOK )
400 : bOK = mpDoc->InsertBookmarkAsObject( aObjectBookmarkList, aExchangeList,
401 0 : bLink, NULL, NULL);
402 :
403 0 : if( pDlg->IsRemoveUnnessesaryMasterPages() )
404 0 : mpDoc->RemoveUnnecessaryMasterPages();
405 : }
406 :
407 0 : delete pDlg;
408 :
409 0 : return (bOK);
410 : }
411 :
412 :
413 :
414 0 : void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
415 : {
416 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
417 0 : AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg(NULL, mpDoc, NULL, aFile ) : 0;
418 0 : if( !pDlg )
419 0 : return;
420 :
421 0 : mpDocSh->SetWaitCursor( false );
422 :
423 0 : sal_uInt16 nRet = pDlg->Execute();
424 0 : mpDocSh->SetWaitCursor( true );
425 :
426 0 : if( nRet == RET_OK )
427 : {
428 : // selected file format: text, RTF or HTML (default is text)
429 0 : sal_uInt16 nFormat = EE_FORMAT_TEXT;
430 :
431 0 : if( aFilterName.indexOf( "Rich") != -1 )
432 0 : nFormat = EE_FORMAT_RTF;
433 0 : else if( aFilterName.indexOf( "HTML" ) != -1 )
434 0 : nFormat = EE_FORMAT_HTML;
435 :
436 : /* create our own outline since:
437 : - it is possible that the document outliner is actually used in the
438 : structuring mode
439 : - the draw outliner of the drawing engine has to draw something in
440 : between
441 : - the global outliner could be used in SdPage::CreatePresObj */
442 0 : SdrOutliner* pOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
443 :
444 : // set reference device
445 0 : pOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
446 :
447 0 : SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
448 0 : aLayoutName = pPage->GetLayoutName();
449 0 : sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
450 0 : if( nIndex != -1 )
451 0 : aLayoutName = aLayoutName.copy(0, nIndex);
452 :
453 0 : pOutliner->SetPaperSize(pPage->GetSize());
454 :
455 0 : SvStream* pStream = pMedium->GetInStream();
456 : DBG_ASSERT( pStream, "No InStream!" );
457 0 : pStream->Seek( 0 );
458 :
459 0 : sal_uLong nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
460 :
461 0 : if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
462 : {
463 : ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
464 0 : SD_RESSTR(STR_READ_DATA_ERROR));
465 0 : aErrorBox.Execute();
466 : }
467 : else
468 : {
469 : // is it a master page?
470 0 : if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EM_MASTERPAGE &&
471 0 : !pPage->IsMasterPage())
472 : {
473 0 : pPage = (SdPage*)(&(pPage->TRG_GetMasterPage()));
474 : }
475 :
476 : DBG_ASSERT(pPage, "page not found");
477 :
478 : // if editing is going on right now, let it flow into this text object
479 0 : OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
480 0 : if( pOutlinerView )
481 : {
482 0 : SdrObject* pObj = mpView->GetTextEditObject();
483 0 : if( pObj &&
484 0 : pObj->GetObjInventor() == SdrInventor &&
485 0 : pObj->GetObjIdentifier() == OBJ_TITLETEXT &&
486 0 : pOutliner->GetParagraphCount() > 1 )
487 : {
488 : // in title objects, only one paragraph is allowed
489 0 : while ( pOutliner->GetParagraphCount() > 1 )
490 : {
491 0 : Paragraph* pPara = pOutliner->GetParagraph( 0 );
492 0 : sal_uLong nLen = pOutliner->GetText( pPara, 1 ).getLength();
493 0 : pOutliner->QuickDelete( ESelection( 0, (sal_uInt16) nLen, 1, 0 ) );
494 0 : pOutliner->QuickInsertLineBreak( ESelection( 0, (sal_uInt16) nLen, 0, (sal_uInt16) nLen ) );
495 : }
496 : }
497 : }
498 :
499 0 : OutlinerParaObject* pOPO = pOutliner->CreateParaObject();
500 :
501 0 : if (pOutlinerView)
502 : {
503 0 : pOutlinerView->InsertText(*pOPO);
504 0 : delete pOPO;
505 : }
506 : else
507 : {
508 0 : SdrRectObj* pTO = new SdrRectObj(OBJ_TEXT);
509 0 : pTO->SetOutlinerParaObject(pOPO);
510 :
511 0 : const bool bUndo = mpView->IsUndoEnabled();
512 0 : if( bUndo )
513 0 : mpView->BegUndo(SD_RESSTR(STR_UNDO_INSERT_TEXTFRAME));
514 0 : pPage->InsertObject(pTO);
515 :
516 : /* can be bigger as the maximal allowed size:
517 : limit object size if necessary */
518 0 : Size aSize(pOutliner->CalcTextSize());
519 0 : Size aMaxSize = mpDoc->GetMaxObjSize();
520 0 : aSize.Height() = std::min(aSize.Height(), aMaxSize.Height());
521 0 : aSize.Width() = std::min(aSize.Width(), aMaxSize.Width());
522 0 : aSize = mpWindow->LogicToPixel(aSize);
523 :
524 : // put it at the center of the window
525 0 : Size aTemp(mpWindow->GetOutputSizePixel());
526 0 : Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
527 0 : aPos.X() -= aSize.Width() / 2;
528 0 : aPos.Y() -= aSize.Height() / 2;
529 0 : aSize = mpWindow->PixelToLogic(aSize);
530 0 : aPos = mpWindow->PixelToLogic(aPos);
531 0 : pTO->SetLogicRect(Rectangle(aPos, aSize));
532 :
533 0 : if (pDlg->IsLink())
534 : {
535 0 : pTO->SetTextLink(aFile, aFilterName, osl_getThreadTextEncoding() );
536 : }
537 :
538 0 : if( bUndo )
539 : {
540 0 : mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
541 0 : mpView->EndUndo();
542 : }
543 : }
544 : }
545 0 : delete pOutliner;
546 : }
547 :
548 0 : delete pDlg;
549 : }
550 :
551 :
552 :
553 0 : void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
554 : {
555 : // selected file format: text, RTF or HTML (default is text)
556 0 : sal_uInt16 nFormat = EE_FORMAT_TEXT;
557 :
558 0 : if( aFilterName.indexOf( "Rich") != -1 )
559 0 : nFormat = EE_FORMAT_RTF;
560 0 : else if( aFilterName.indexOf( "HTML" ) != -1 )
561 0 : nFormat = EE_FORMAT_HTML;
562 :
563 0 : ::Outliner* pDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
564 :
565 0 : std::vector<Paragraph*> aSelList;
566 0 : pDocliner->GetView(0)->CreateSelectionList(aSelList);
567 :
568 0 : Paragraph* pPara = aSelList.empty() ? NULL : *(aSelList.begin());
569 :
570 : // what should we insert?
571 0 : while( !pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
572 0 : pPara = pDocliner->GetParent(pPara);
573 :
574 0 : sal_Int32 nTargetPos = pDocliner->GetAbsPos(pPara) + 1;
575 :
576 : // apply layout of predecessor page
577 0 : sal_uInt16 nPage = 0;
578 0 : pPara = pDocliner->GetParagraph( pDocliner->GetAbsPos( pPara ) - 1 );
579 0 : while (pPara)
580 : {
581 0 : sal_Int32 nPos = pDocliner->GetAbsPos( pPara );
582 0 : if ( pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
583 0 : nPage++;
584 0 : pPara = pDocliner->GetParagraph( nPos - 1 );
585 : }
586 0 : SdPage* pPage = mpDoc->GetSdPage(nPage, PK_STANDARD);
587 0 : aLayoutName = pPage->GetLayoutName();
588 0 : sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
589 0 : if( nIndex != -1 )
590 0 : aLayoutName = aLayoutName.copy(0, nIndex);
591 :
592 : /* create our own outline since:
593 : - it is possible that the document outliner is actually used in the
594 : structuring mode
595 : - the draw outliner of the drawing engine has to draw something in
596 : between
597 : - the global outliner could be used in SdPage::CreatePresObj */
598 0 : ::Outliner* pOutliner = new ::Outliner( &mpDoc->GetItemPool(), OUTLINERMODE_OUTLINEOBJECT );
599 0 : pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)mpDoc->GetStyleSheetPool());
600 :
601 : // set reference device
602 0 : pOutliner->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
603 0 : pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
604 :
605 0 : SvStream* pStream = pMedium->GetInStream();
606 : DBG_ASSERT( pStream, "No InStream!" );
607 0 : pStream->Seek( 0 );
608 :
609 0 : sal_uLong nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
610 :
611 0 : if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
612 : {
613 : ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
614 0 : SD_RESSTR(STR_READ_DATA_ERROR));
615 0 : aErrorBox.Execute();
616 : }
617 : else
618 : {
619 0 : sal_Int32 nParaCount = pOutliner->GetParagraphCount();
620 :
621 : // for progress bar: number of level-0-paragraphs
622 0 : sal_uInt16 nNewPages = 0;
623 0 : pPara = pOutliner->GetParagraph( 0 );
624 0 : while (pPara)
625 : {
626 0 : sal_Int32 nPos = pOutliner->GetAbsPos( pPara );
627 0 : if( pOutliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
628 0 : nNewPages++;
629 0 : pPara = pOutliner->GetParagraph( ++nPos );
630 : }
631 :
632 0 : mpDocSh->SetWaitCursor( false );
633 :
634 0 : SfxProgress* pProgress = new SfxProgress( mpDocSh, SD_RESSTR(STR_CREATE_PAGES), nNewPages);
635 0 : if( pProgress )
636 0 : pProgress->SetState( 0, 100 );
637 :
638 0 : nNewPages = 0;
639 :
640 0 : pDocliner->GetUndoManager().EnterListAction(
641 0 : SD_RESSTR(STR_UNDO_INSERT_FILE), OUString() );
642 :
643 0 : sal_Int32 nSourcePos = 0;
644 0 : SfxStyleSheet* pStyleSheet = pPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
645 0 : Paragraph* pSourcePara = pOutliner->GetParagraph( 0 );
646 0 : while (pSourcePara)
647 : {
648 0 : sal_Int32 nPos = pOutliner->GetAbsPos( pSourcePara );
649 0 : sal_Int16 nDepth = pOutliner->GetDepth( nPos );
650 :
651 : // only take the last paragraph if it is filled
652 0 : if (nSourcePos < nParaCount - 1 ||
653 0 : !pOutliner->GetText(pSourcePara).isEmpty())
654 : {
655 0 : pDocliner->Insert( pOutliner->GetText(pSourcePara), nTargetPos, nDepth );
656 0 : OUString aStyleSheetName( pStyleSheet->GetName() );
657 0 : aStyleSheetName = aStyleSheetName.copy( 0, aStyleSheetName.getLength()-1 );
658 0 : aStyleSheetName += OUString::number( nDepth <= 0 ? 1 : nDepth+1 );
659 0 : SfxStyleSheetBasePool* pStylePool = mpDoc->GetStyleSheetPool();
660 0 : SfxStyleSheet* pOutlStyle = (SfxStyleSheet*) pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() );
661 0 : pDocliner->SetStyleSheet( nTargetPos, pOutlStyle );
662 : }
663 :
664 0 : if( pDocliner->HasParaFlag( pSourcePara, PARAFLAG_ISPAGE ) )
665 : {
666 0 : nNewPages++;
667 0 : if( pProgress )
668 0 : pProgress->SetState( nNewPages );
669 : }
670 :
671 0 : pSourcePara = pOutliner->GetParagraph( ++nPos );
672 0 : nTargetPos++;
673 0 : nSourcePos++;
674 : }
675 :
676 0 : pDocliner->GetUndoManager().LeaveListAction();
677 :
678 0 : if( pProgress )
679 0 : delete pProgress;
680 :
681 0 : mpDocSh->SetWaitCursor( true );
682 : }
683 :
684 0 : delete pOutliner;
685 0 : }
686 :
687 :
688 :
689 0 : sal_Bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
690 : {
691 0 : OutlineView* pOlView = static_cast<OutlineView*>(mpView);
692 :
693 : // transfer Outliner content to SdDrawDocument
694 0 : pOlView->PrepareClose();
695 :
696 : // einlesen wie im Zeichenmodus
697 0 : if (InsSDDinDrMode(pMedium))
698 : {
699 0 : ::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
700 :
701 : // cut notification links temporarily
702 0 : Link aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
703 0 : pOutliner->SetParaInsertedHdl( Link(NULL, NULL));
704 0 : Link aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
705 0 : pOutliner->SetParaRemovingHdl( Link(NULL, NULL));
706 0 : Link aOldDepthChangedHdl = pOutliner->GetDepthChangedHdl();
707 0 : pOutliner->SetDepthChangedHdl( Link(NULL, NULL));
708 0 : Link aOldBeginMovingHdl = pOutliner->GetBeginMovingHdl();
709 0 : pOutliner->SetBeginMovingHdl( Link(NULL, NULL));
710 0 : Link aOldEndMovingHdl = pOutliner->GetEndMovingHdl();
711 0 : pOutliner->SetEndMovingHdl( Link(NULL, NULL));
712 :
713 0 : Link aOldStatusEventHdl = pOutliner->GetStatusEventHdl();
714 0 : pOutliner->SetStatusEventHdl(Link(NULL, NULL));
715 :
716 0 : pOutliner->Clear();
717 0 : pOlView->FillOutliner();
718 :
719 : // set links again
720 0 : pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
721 0 : pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
722 0 : pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
723 0 : pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
724 0 : pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
725 0 : pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
726 :
727 0 : return sal_True;
728 : }
729 : else
730 0 : return sal_False;
731 : }
732 :
733 :
734 :
735 0 : void FuInsertFile::GetSupportedFilterVector( ::std::vector< OUString >& rFilterVector )
736 : {
737 0 : SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
738 0 : const SfxFilter* pSearchFilter = NULL;
739 :
740 0 : rFilterVector.clear();
741 :
742 0 : if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/plain" )) != NULL )
743 0 : rFilterVector.push_back( pSearchFilter->GetMimeType() );
744 :
745 0 : if( ( pSearchFilter = rMatcher.GetFilter4Mime( "application/rtf" ) ) != NULL )
746 0 : rFilterVector.push_back( pSearchFilter->GetMimeType() );
747 :
748 0 : if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/html" ) ) != NULL )
749 0 : rFilterVector.push_back( pSearchFilter->GetMimeType() );
750 0 : }
751 :
752 0 : } // end of namespace sd
753 :
754 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|