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 : typedef ::std::pair< OUString, OUString > FilterDesc;
73 :
74 : namespace
75 : {
76 :
77 0 : OUString lcl_GetExtensionsList ( ::std::vector< FilterDesc > const& rFilterDescList )
78 : {
79 0 : OUString aExtensions;
80 0 : ::std::vector< FilterDesc >::const_iterator aIter( rFilterDescList.begin() );
81 :
82 0 : while (aIter != rFilterDescList.end())
83 : {
84 0 : OUString sWildcard = (*aIter).second;
85 :
86 0 : if ( aExtensions.indexOf( sWildcard ) == -1 )
87 : {
88 0 : if ( !aExtensions.isEmpty() )
89 0 : aExtensions += ";";
90 0 : aExtensions += sWildcard;
91 : }
92 :
93 0 : ++aIter;
94 0 : }
95 :
96 0 : return aExtensions;
97 : }
98 :
99 0 : void lcl_AddFilter ( ::std::vector< FilterDesc >& rFilterDescList,
100 : const SfxFilter *pFilter )
101 : {
102 0 : if (pFilter)
103 0 : rFilterDescList.push_back( ::std::make_pair( pFilter->GetUIName(), pFilter->GetDefaultExtension() ) );
104 0 : }
105 :
106 : }
107 :
108 : namespace sd {
109 :
110 0 : TYPEINIT1( FuInsertFile, FuPoor );
111 :
112 0 : FuInsertFile::FuInsertFile (
113 : ViewShell* pViewSh,
114 : ::sd::Window* pWin,
115 : ::sd::View* pView,
116 : SdDrawDocument* pDoc,
117 : SfxRequest& rReq)
118 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
119 : {
120 0 : }
121 :
122 0 : rtl::Reference<FuPoor> FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
123 : {
124 0 : rtl::Reference<FuPoor> xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
125 0 : xFunc->DoExecute(rReq);
126 0 : return xFunc;
127 : }
128 :
129 0 : void FuInsertFile::DoExecute( SfxRequest& rReq )
130 : {
131 0 : SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
132 0 : ::std::vector< FilterDesc > aFilterVector;
133 0 : ::std::vector< OUString > aOtherFilterVector;
134 0 : const SfxItemSet* pArgs = rReq.GetArgs ();
135 :
136 0 : FuInsertFile::GetSupportedFilterVector( aOtherFilterVector );
137 :
138 0 : if (!pArgs)
139 : {
140 : sfx2::FileDialogHelper aFileDialog(
141 : ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
142 0 : SFXWB_INSERT );
143 0 : Reference< XFilePicker > xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
144 0 : Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
145 0 : OUString aOwnCont;
146 0 : OUString aOtherCont;
147 :
148 0 : aFileDialog.SetTitle( SD_RESSTR(STR_DLG_INSERT_PAGES_FROM_FILE) );
149 :
150 0 : if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
151 : {
152 0 : aOwnCont = "simpress";
153 0 : aOtherCont = "sdraw";
154 : }
155 : else
156 : {
157 0 : aOtherCont = "simpress";
158 0 : aOwnCont = "sdraw" ;
159 : }
160 :
161 0 : SfxFilterMatcher aMatch( aOwnCont );
162 :
163 0 : if( xFilterManager.is() )
164 : {
165 : // Get filter for current format
166 : try
167 : {
168 : // Get main filter
169 0 : const SfxFilter* pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
170 0 : lcl_AddFilter( aFilterVector, pFilter );
171 :
172 : // get template filter
173 0 : if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
174 0 : pFilter = DrawDocShell::Factory().GetTemplateFilter();
175 : else
176 0 : pFilter = GraphicDocShell::Factory().GetTemplateFilter();
177 0 : lcl_AddFilter( aFilterVector, pFilter );
178 :
179 : // get cross filter
180 0 : pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
181 0 : lcl_AddFilter( aFilterVector, pFilter );
182 :
183 : // get Powerpoint filter
184 0 : OUString aExt = ".ppt";
185 0 : pFilter = aMatch.GetFilter4Extension( aExt );
186 0 : lcl_AddFilter( aFilterVector, pFilter );
187 :
188 : // Get other draw/impress filters
189 0 : pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
190 0 : lcl_AddFilter( aFilterVector, pFilter );
191 :
192 0 : pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::TEMPLATEPATH );
193 0 : lcl_AddFilter( aFilterVector, pFilter );
194 :
195 0 : pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
196 0 : lcl_AddFilter( aFilterVector, pFilter );
197 :
198 0 : pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::TEMPLATEPATH );
199 0 : lcl_AddFilter( aFilterVector, pFilter );
200 :
201 0 : pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
202 0 : lcl_AddFilter( aFilterVector, pFilter );
203 :
204 0 : pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::TEMPLATEPATH );
205 0 : lcl_AddFilter( aFilterVector, pFilter );
206 :
207 : // add additional supported filters
208 0 : ::std::vector< OUString >::const_iterator aOtherIter( aOtherFilterVector.begin() );
209 :
210 0 : while( aOtherIter != aOtherFilterVector.end() )
211 : {
212 0 : if( ( pFilter = rMatcher.GetFilter4Mime( *aOtherIter ) ) != NULL )
213 0 : lcl_AddFilter( aFilterVector, pFilter );
214 :
215 0 : ++aOtherIter;
216 : }
217 :
218 : // set default-filter (<All>)
219 0 : OUString aAllSpec( SD_RESSTR( STR_ALL_FILES ) );
220 0 : OUString aExtensions = lcl_GetExtensionsList( aFilterVector );
221 0 : OUString aGUIName = aAllSpec + " (" + aExtensions + ")";
222 :
223 0 : xFilterManager->appendFilter( aGUIName, aExtensions );
224 0 : xFilterManager->setCurrentFilter( aAllSpec );
225 :
226 : // add filters to filter manager finally
227 0 : ::std::vector< ::std::pair < OUString, OUString > >::const_iterator aIter( aFilterVector.begin() );
228 :
229 0 : while( aIter != aFilterVector.end() )
230 : {
231 0 : xFilterManager->appendFilter( (*aIter).first, (*aIter).second );
232 0 : ++aIter;
233 0 : }
234 :
235 : }
236 0 : catch (const IllegalArgumentException&)
237 : {
238 : }
239 : }
240 :
241 0 : if( aFileDialog.Execute() != ERRCODE_NONE )
242 0 : return;
243 : else
244 : {
245 0 : aFilterName = aFileDialog.GetCurrentFilter();
246 0 : aFile = aFileDialog.GetPath();
247 0 : }
248 : }
249 : else
250 : {
251 0 : SFX_REQUEST_ARG (rReq, pFileName, SfxStringItem, ID_VAL_DUMMY0, false);
252 0 : SFX_REQUEST_ARG (rReq, pFilterName, SfxStringItem, ID_VAL_DUMMY1, false);
253 :
254 0 : aFile = pFileName->GetValue ();
255 :
256 0 : if( pFilterName )
257 0 : aFilterName = pFilterName->GetValue ();
258 : }
259 :
260 0 : mpDocSh->SetWaitCursor( true );
261 :
262 0 : SfxMedium* pMedium = new SfxMedium( aFile, StreamMode::READ | StreamMode::NOCREATE );
263 0 : const SfxFilter* pFilter = NULL;
264 :
265 0 : SfxGetpApp()->GetFilterMatcher().GuessFilter( *pMedium, &pFilter, SfxFilterFlags::IMPORT, SFX_FILTER_NOTINSTALLED | SfxFilterFlags::EXECUTABLE );
266 :
267 0 : bool bDrawMode = mpViewShell && mpViewShell->ISA(DrawViewShell);
268 0 : bool bInserted = false;
269 :
270 0 : if( pFilter )
271 : {
272 0 : pMedium->SetFilter( pFilter );
273 0 : aFilterName = pFilter->GetFilterName();
274 :
275 0 : if( pMedium->IsStorage() || ( pMedium->GetInStream() && SotStorage::IsStorageFile( pMedium->GetInStream() ) ) )
276 : {
277 0 : if ( pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument" ||
278 0 : pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument" )
279 : {
280 : // Draw, Impress or PowerPoint document
281 : // the ownership of the Medium is transferred
282 0 : if( bDrawMode )
283 0 : InsSDDinDrMode( pMedium );
284 : else
285 0 : InsSDDinOlMode( pMedium );
286 :
287 : // don't delete Medium here, ownership of pMedium has changed in this case
288 0 : bInserted = true;
289 : }
290 : }
291 : else
292 : {
293 0 : bool bFound = ( ::std::find( aOtherFilterVector.begin(), aOtherFilterVector.end(), pFilter->GetMimeType() ) != aOtherFilterVector.end() );
294 0 : if( !bFound &&
295 0 : ( aFilterName.indexOf( "Text" ) != -1 ||
296 0 : aFilterName.indexOf( "Rich" ) != -1 ||
297 0 : aFilterName.indexOf( "RTF" ) != -1 ||
298 0 : aFilterName.indexOf( "HTML" ) != -1 ) )
299 : {
300 0 : bFound = true;
301 : }
302 :
303 0 : if( bFound )
304 : {
305 0 : if( bDrawMode )
306 0 : InsTextOrRTFinDrMode(pMedium);
307 : else
308 0 : InsTextOrRTFinOlMode(pMedium);
309 :
310 0 : bInserted = true;
311 0 : delete pMedium;
312 : }
313 : }
314 : }
315 :
316 0 : mpDocSh->SetWaitCursor( false );
317 :
318 0 : if( !bInserted )
319 : {
320 0 : ScopedVclPtrInstance< MessageDialog > aErrorBox(mpWindow, SD_RESSTR( STR_READ_DATA_ERROR));
321 0 : aErrorBox->Execute();
322 0 : delete pMedium;
323 0 : }
324 : }
325 :
326 0 : bool FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
327 : {
328 0 : bool bOK = false;
329 :
330 0 : mpDocSh->SetWaitCursor( false );
331 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
332 0 : boost::scoped_ptr<AbstractSdInsertPagesObjsDlg> pDlg(pFact ? pFact->CreateSdInsertPagesObjsDlg( NULL, mpDoc, pMedium, aFile ) : 0);
333 :
334 0 : if( !pDlg )
335 0 : return false;
336 :
337 : /* Maybe a QueryBox is opened ("update links?"), therefore the dialog
338 : becomes the current DefModalDialogParent */
339 0 : vcl::Window* pDefParent = Application::GetDefDialogParent();
340 0 : Application::SetDefDialogParent(pDlg->GetWindow());
341 :
342 0 : sal_uInt16 nRet = pDlg->Execute();
343 :
344 0 : Application::SetDefDialogParent(pDefParent);
345 :
346 0 : mpDocSh->SetWaitCursor( true );
347 :
348 0 : if( nRet == RET_OK )
349 : {
350 : /* list with page names (if NULL, then all pages)
351 : First, insert pages */
352 0 : std::vector<OUString> aBookmarkList = pDlg->GetList( 1 ); // pages
353 0 : bool bLink = pDlg->IsLink();
354 0 : bool bReplace = false;
355 0 : SdPage* pPage = NULL;
356 0 : ::sd::View* pView = mpViewShell ? mpViewShell->GetView() : NULL;
357 :
358 0 : if (pView)
359 : {
360 0 : if (pView->ISA(OutlineView))
361 : {
362 0 : pPage = static_cast<OutlineView*>(pView)->GetActualPage();
363 : }
364 : else
365 : {
366 0 : pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
367 : }
368 : }
369 :
370 0 : sal_uInt16 nPos = 0xFFFF;
371 :
372 0 : if (pPage && !pPage->IsMasterPage())
373 : {
374 0 : if (pPage->GetPageKind() == PK_STANDARD)
375 : {
376 0 : nPos = pPage->GetPageNum() + 2;
377 : }
378 0 : else if (pPage->GetPageKind() == PK_NOTES)
379 : {
380 0 : nPos = pPage->GetPageNum() + 1;
381 : }
382 : }
383 :
384 : bool bNameOK;
385 0 : std::vector<OUString> aExchangeList;
386 0 : std::vector<OUString> aObjectBookmarkList = pDlg->GetList( 2 ); // objects
387 :
388 : /* if pBookmarkList is NULL, we insert selected pages, and/or selected
389 : objects or everything. */
390 0 : if( !aBookmarkList.empty() || aObjectBookmarkList.empty() )
391 : {
392 : /* To ensure that all page names are unique, we check the ones we
393 : want to insert and insert them into a substitution list if
394 : necessary.
395 : bNameOK is sal_False if the user has canceled. */
396 0 : bNameOK = mpView->GetExchangeList( aExchangeList, aBookmarkList, 0 );
397 :
398 0 : if( bNameOK )
399 : bOK = mpDoc->InsertBookmarkAsPage( aBookmarkList, &aExchangeList,
400 : bLink, bReplace, nPos,
401 0 : false, NULL, true, true, false );
402 :
403 0 : aBookmarkList.clear();
404 0 : aExchangeList.clear();
405 : }
406 :
407 : // to ensure ... (see above)
408 0 : bNameOK = mpView->GetExchangeList( aExchangeList, aObjectBookmarkList, 1 );
409 :
410 0 : if( bNameOK )
411 : bOK = mpDoc->InsertBookmarkAsObject( aObjectBookmarkList, aExchangeList,
412 0 : bLink, NULL, NULL);
413 :
414 0 : if( pDlg->IsRemoveUnnessesaryMasterPages() )
415 0 : mpDoc->RemoveUnnecessaryMasterPages();
416 : }
417 :
418 0 : return bOK;
419 : }
420 :
421 0 : void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
422 : {
423 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
424 0 : boost::scoped_ptr<AbstractSdInsertPagesObjsDlg> pDlg(pFact ? pFact->CreateSdInsertPagesObjsDlg(NULL, mpDoc, NULL, aFile ) : 0);
425 0 : if( !pDlg )
426 0 : return;
427 :
428 0 : mpDocSh->SetWaitCursor( false );
429 :
430 0 : sal_uInt16 nRet = pDlg->Execute();
431 0 : mpDocSh->SetWaitCursor( true );
432 :
433 0 : if( nRet == RET_OK )
434 : {
435 : // selected file format: text, RTF or HTML (default is text)
436 0 : sal_uInt16 nFormat = EE_FORMAT_TEXT;
437 :
438 0 : if( aFilterName.indexOf( "Rich") != -1 )
439 0 : nFormat = EE_FORMAT_RTF;
440 0 : else if( aFilterName.indexOf( "HTML" ) != -1 )
441 0 : nFormat = EE_FORMAT_HTML;
442 :
443 : /* create our own outline since:
444 : - it is possible that the document outliner is actually used in the
445 : structuring mode
446 : - the draw outliner of the drawing engine has to draw something in
447 : between
448 : - the global outliner could be used in SdPage::CreatePresObj */
449 0 : boost::scoped_ptr<SdrOutliner> pOutliner(new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT ));
450 :
451 : // set reference device
452 0 : pOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
453 :
454 0 : SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
455 0 : aLayoutName = pPage->GetLayoutName();
456 0 : sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
457 0 : if( nIndex != -1 )
458 0 : aLayoutName = aLayoutName.copy(0, nIndex);
459 :
460 0 : pOutliner->SetPaperSize(pPage->GetSize());
461 :
462 0 : SvStream* pStream = pMedium->GetInStream();
463 : assert(pStream && "No InStream!");
464 0 : pStream->Seek( 0 );
465 :
466 0 : sal_uLong nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
467 :
468 0 : if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
469 : {
470 0 : ScopedVclPtrInstance< MessageDialog > aErrorBox(mpWindow, SD_RESSTR(STR_READ_DATA_ERROR));
471 0 : aErrorBox->Execute();
472 : }
473 : else
474 : {
475 : // is it a master page?
476 0 : if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EM_MASTERPAGE &&
477 0 : !pPage->IsMasterPage())
478 : {
479 0 : pPage = static_cast<SdPage*>(&(pPage->TRG_GetMasterPage()));
480 : }
481 :
482 : assert(pPage && "page not found");
483 :
484 : // if editing is going on right now, let it flow into this text object
485 0 : OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
486 0 : if( pOutlinerView )
487 : {
488 0 : SdrObject* pObj = mpView->GetTextEditObject();
489 0 : if( pObj &&
490 0 : pObj->GetObjInventor() == SdrInventor &&
491 0 : pObj->GetObjIdentifier() == OBJ_TITLETEXT &&
492 0 : pOutliner->GetParagraphCount() > 1 )
493 : {
494 : // in title objects, only one paragraph is allowed
495 0 : while ( pOutliner->GetParagraphCount() > 1 )
496 : {
497 0 : Paragraph* pPara = pOutliner->GetParagraph( 0 );
498 0 : sal_uLong nLen = pOutliner->GetText( pPara, 1 ).getLength();
499 0 : pOutliner->QuickDelete( ESelection( 0, nLen, 1, 0 ) );
500 0 : pOutliner->QuickInsertLineBreak( ESelection( 0, nLen, 0, nLen ) );
501 : }
502 : }
503 : }
504 :
505 0 : OutlinerParaObject* pOPO = pOutliner->CreateParaObject();
506 :
507 0 : if (pOutlinerView)
508 : {
509 0 : pOutlinerView->InsertText(*pOPO);
510 0 : delete pOPO;
511 : }
512 : else
513 : {
514 0 : SdrRectObj* pTO = new SdrRectObj(OBJ_TEXT);
515 0 : pTO->SetOutlinerParaObject(pOPO);
516 :
517 0 : const bool bUndo = mpView->IsUndoEnabled();
518 0 : if( bUndo )
519 0 : mpView->BegUndo(SD_RESSTR(STR_UNDO_INSERT_TEXTFRAME));
520 0 : pPage->InsertObject(pTO);
521 :
522 : /* can be bigger as the maximal allowed size:
523 : limit object size if necessary */
524 0 : Size aSize(pOutliner->CalcTextSize());
525 0 : Size aMaxSize = mpDoc->GetMaxObjSize();
526 0 : aSize.Height() = std::min(aSize.Height(), aMaxSize.Height());
527 0 : aSize.Width() = std::min(aSize.Width(), aMaxSize.Width());
528 0 : aSize = mpWindow->LogicToPixel(aSize);
529 :
530 : // put it at the center of the window
531 0 : Size aTemp(mpWindow->GetOutputSizePixel());
532 0 : Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
533 0 : aPos.X() -= aSize.Width() / 2;
534 0 : aPos.Y() -= aSize.Height() / 2;
535 0 : aSize = mpWindow->PixelToLogic(aSize);
536 0 : aPos = mpWindow->PixelToLogic(aPos);
537 0 : pTO->SetLogicRect(Rectangle(aPos, aSize));
538 :
539 0 : if (pDlg->IsLink())
540 : {
541 0 : pTO->SetTextLink(aFile, aFilterName, osl_getThreadTextEncoding() );
542 : }
543 :
544 0 : if( bUndo )
545 : {
546 0 : mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
547 0 : mpView->EndUndo();
548 : }
549 : }
550 0 : }
551 0 : }
552 : }
553 :
554 0 : void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
555 : {
556 : // selected file format: text, RTF or HTML (default is text)
557 0 : sal_uInt16 nFormat = EE_FORMAT_TEXT;
558 :
559 0 : if( aFilterName.indexOf( "Rich") != -1 )
560 0 : nFormat = EE_FORMAT_RTF;
561 0 : else if( aFilterName.indexOf( "HTML" ) != -1 )
562 0 : nFormat = EE_FORMAT_HTML;
563 :
564 0 : ::Outliner& rDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
565 :
566 0 : std::vector<Paragraph*> aSelList;
567 0 : rDocliner.GetView(0)->CreateSelectionList(aSelList);
568 :
569 0 : Paragraph* pPara = aSelList.empty() ? NULL : *(aSelList.begin());
570 :
571 : // what should we insert?
572 0 : while (pPara && !Outliner::HasParaFlag(pPara, ParaFlag::ISPAGE))
573 0 : pPara = rDocliner.GetParent(pPara);
574 :
575 0 : sal_Int32 nTargetPos = rDocliner.GetAbsPos(pPara) + 1;
576 :
577 : // apply layout of predecessor page
578 0 : sal_uInt16 nPage = 0;
579 0 : pPara = rDocliner.GetParagraph( rDocliner.GetAbsPos( pPara ) - 1 );
580 0 : while (pPara)
581 : {
582 0 : sal_Int32 nPos = rDocliner.GetAbsPos( pPara );
583 0 : if ( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
584 0 : nPage++;
585 0 : pPara = rDocliner.GetParagraph( nPos - 1 );
586 : }
587 0 : SdPage* pPage = mpDoc->GetSdPage(nPage, PK_STANDARD);
588 0 : aLayoutName = pPage->GetLayoutName();
589 0 : sal_Int32 nIndex = aLayoutName.indexOf(SD_LT_SEPARATOR);
590 0 : if( nIndex != -1 )
591 0 : aLayoutName = aLayoutName.copy(0, nIndex);
592 :
593 : /* create our own outline since:
594 : - it is possible that the document outliner is actually used in the
595 : structuring mode
596 : - the draw outliner of the drawing engine has to draw something in
597 : between
598 : - the global outliner could be used in SdPage::CreatePresObj */
599 0 : boost::scoped_ptr< ::Outliner> pOutliner(new ::Outliner( &mpDoc->GetItemPool(), OUTLINERMODE_OUTLINEOBJECT ));
600 0 : pOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
601 :
602 : // set reference device
603 0 : pOutliner->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
604 0 : pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
605 :
606 0 : SvStream* pStream = pMedium->GetInStream();
607 : DBG_ASSERT( pStream, "No InStream!" );
608 0 : pStream->Seek( 0 );
609 :
610 0 : sal_uLong nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
611 :
612 0 : if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
613 : {
614 0 : ScopedVclPtrInstance< MessageDialog > aErrorBox(mpWindow, 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( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
628 0 : nNewPages++;
629 0 : pPara = pOutliner->GetParagraph( ++nPos );
630 : }
631 :
632 0 : mpDocSh->SetWaitCursor( false );
633 :
634 0 : boost::scoped_ptr<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 : rDocliner.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 : rDocliner.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 = static_cast<SfxStyleSheet*>( pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() ) );
661 0 : rDocliner.SetStyleSheet( nTargetPos, pOutlStyle );
662 : }
663 :
664 0 : if( Outliner::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 : rDocliner.GetUndoManager().LeaveListAction();
677 :
678 0 : pProgress.reset();
679 :
680 0 : mpDocSh->SetWaitCursor( true );
681 0 : }
682 0 : }
683 :
684 0 : bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
685 : {
686 0 : OutlineView* pOlView = static_cast<OutlineView*>(mpView);
687 :
688 : // transfer Outliner content to SdDrawDocument
689 0 : pOlView->PrepareClose();
690 :
691 : // einlesen wie im Zeichenmodus
692 0 : if (InsSDDinDrMode(pMedium))
693 : {
694 0 : ::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
695 :
696 : // cut notification links temporarily
697 0 : Link<> aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
698 0 : pOutliner->SetParaInsertedHdl( Link<>(NULL, NULL));
699 0 : Link<> aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
700 0 : pOutliner->SetParaRemovingHdl( Link<>(NULL, NULL));
701 0 : Link<> aOldDepthChangedHdl = pOutliner->GetDepthChangedHdl();
702 0 : pOutliner->SetDepthChangedHdl( Link<>(NULL, NULL));
703 0 : Link<> aOldBeginMovingHdl = pOutliner->GetBeginMovingHdl();
704 0 : pOutliner->SetBeginMovingHdl( Link<>(NULL, NULL));
705 0 : Link<> aOldEndMovingHdl = pOutliner->GetEndMovingHdl();
706 0 : pOutliner->SetEndMovingHdl( Link<>(NULL, NULL));
707 :
708 0 : Link<> aOldStatusEventHdl = pOutliner->GetStatusEventHdl();
709 0 : pOutliner->SetStatusEventHdl(Link<>(NULL, NULL));
710 :
711 0 : pOutliner->Clear();
712 0 : pOlView->FillOutliner();
713 :
714 : // set links again
715 0 : pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
716 0 : pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
717 0 : pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
718 0 : pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
719 0 : pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
720 0 : pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
721 :
722 0 : return true;
723 : }
724 : else
725 0 : return false;
726 : }
727 :
728 0 : void FuInsertFile::GetSupportedFilterVector( ::std::vector< OUString >& rFilterVector )
729 : {
730 0 : SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
731 0 : const SfxFilter* pSearchFilter = NULL;
732 :
733 0 : rFilterVector.clear();
734 :
735 0 : if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/plain" )) != NULL )
736 0 : rFilterVector.push_back( pSearchFilter->GetMimeType() );
737 :
738 0 : if( ( pSearchFilter = rMatcher.GetFilter4Mime( "application/rtf" ) ) != NULL )
739 0 : rFilterVector.push_back( pSearchFilter->GetMimeType() );
740 :
741 0 : if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/html" ) ) != NULL )
742 0 : rFilterVector.push_back( pSearchFilter->GetMimeType() );
743 0 : }
744 :
745 66 : } // end of namespace sd
746 :
747 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|