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