merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / func / fuinsfil.cxx
blob7cc08608322e4a7200be485bf680a5c29cad2968
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuinsfil.cxx,v $
10 * $Revision: 1.43 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "fuinsfil.hxx"
35 #include <vcl/wrkwin.hxx>
36 #include <sfx2/progress.hxx>
37 #include <svx/outliner.hxx>
38 #ifndef _EDITENG_HXX
39 #include <svx/editeng.hxx>
40 #endif
41 #include <svtools/stritem.hxx>
42 #include <sfx2/request.hxx>
43 #include <sfx2/app.hxx>
44 #include <vcl/msgbox.hxx>
45 #include <sfx2/printer.hxx>
46 #include <svx/svdorect.hxx>
47 #include <svx/svdundo.hxx>
48 #include <svx/svdoutl.hxx>
49 #include <sfx2/filedlghelper.hxx>
50 #include <sot/formats.hxx>
51 #include <svtools/urihelper.hxx>
52 #include <svx/forbiddencharacterstable.hxx>
53 #include <tools/urlobj.hxx>
54 #include <sfx2/docfile.hxx>
55 #include <sfx2/docfilt.hxx>
56 #include <sfx2/fcontnr.hxx>
57 #include <svx/svdpagv.hxx>
58 #include <svx/dialogs.hrc>
59 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
60 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
61 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
63 #include "sdresid.hxx"
64 #include "drawdoc.hxx"
65 #include "Window.hxx"
66 #include "View.hxx"
67 #include "strings.hrc"
68 #include "stlpool.hxx"
69 #include "glob.hrc"
70 #include "sdpage.hxx"
71 #include "strmname.h"
72 #include "strings.hrc"
73 #include "DrawViewShell.hxx"
74 #include "OutlineViewShell.hxx"
75 #include "DrawDocShell.hxx"
76 #include "GraphicDocShell.hxx"
77 #include "app.hrc"
78 #include "unmovss.hxx"
79 #include "Outliner.hxx"
80 #include "sdabstdlg.hxx"
82 using ::rtl::OUString;
83 using namespace ::com::sun::star::lang;
84 using namespace ::com::sun::star::uno;
85 using namespace ::com::sun::star::ui::dialogs;
86 using namespace ::com::sun::star;
88 namespace sd {
90 TYPEINIT1( FuInsertFile, FuPoor );
92 #define POOL_BUFFER_SIZE (USHORT)32768
93 #define BASIC_BUFFER_SIZE (USHORT)8192
94 #define DOCUMENT_BUFFER_SIZE (USHORT)32768
96 /*************************************************************************
98 |* Konstruktor
100 \************************************************************************/
102 FuInsertFile::FuInsertFile (
103 ViewShell* pViewSh,
104 ::sd::Window* pWin,
105 ::sd::View* pView,
106 SdDrawDocument* pDoc,
107 SfxRequest& rReq)
108 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
112 FunctionReference FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
114 FunctionReference xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
115 xFunc->DoExecute(rReq);
116 return xFunc;
119 void FuInsertFile::DoExecute( SfxRequest& rReq )
121 SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
122 ::std::vector< String > aFilterVector;
123 const SfxItemSet* pArgs = rReq.GetArgs ();
125 FuInsertFile::GetSupportedFilterVector( aFilterVector );
127 if (!pArgs)
129 sfx2::FileDialogHelper aFileDialog( WB_OPEN | SFXWB_INSERT | WB_STDMODAL );
130 Reference< XFilePicker > xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
131 Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
132 String aOwnCont;
133 String aOtherCont;
134 const SfxFilter* pFilter = NULL;
136 aFileDialog.SetTitle( String( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE ) ) );
138 if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
140 aOwnCont = String( RTL_CONSTASCII_USTRINGPARAM( "simpress" ) );
141 aOtherCont = String( RTL_CONSTASCII_USTRINGPARAM( "sdraw" ) ) ;
143 else
145 aOtherCont = String( RTL_CONSTASCII_USTRINGPARAM( "simpress" ) );
146 aOwnCont = String( RTL_CONSTASCII_USTRINGPARAM( "sdraw" ) ) ;
149 SfxFilterMatcher aMatch( aOwnCont );
151 if( xFilterManager.is() )
153 // Get filter for current format
156 String aExt;
157 String aAllSpec( SdResId( STR_ALL_FILES ) );
159 xFilterManager->appendFilter( aAllSpec, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.*" ) ) );
160 xFilterManager->setCurrentFilter( aAllSpec ); // set default-filter (<All>)
162 // Get main filter
163 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
164 if( pFilter )
165 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
167 // get cross filter
168 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
169 if( pFilter )
171 pFilter = aMatch.GetFilter4Extension( pFilter->GetDefaultExtension() );
172 if ( pFilter )
173 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
176 // get femplate filter
177 if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
178 pFilter = DrawDocShell::Factory().GetTemplateFilter();
179 else
180 pFilter = GraphicDocShell::Factory().GetTemplateFilter();
181 if( pFilter )
182 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
184 // get Powerpoint filter
185 aExt = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( ".ppt" ) );
186 pFilter = aMatch.GetFilter4Extension( aExt );
187 if( pFilter )
188 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
190 // Get other draw/impress filters
191 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
192 if( pFilter )
193 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
195 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_TEMPLATEPATH );
196 if( pFilter )
197 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
199 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
200 if( pFilter )
201 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
203 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_TEMPLATEPATH );
204 if( pFilter )
205 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
207 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
208 if( pFilter )
209 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
211 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_TEMPLATEPATH );
212 if( pFilter )
213 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
215 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
216 if( pFilter )
217 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
219 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_TEMPLATEPATH );
220 if( pFilter )
221 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
223 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
224 if( pFilter )
225 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
227 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_TEMPLATEPATH );
228 if( pFilter )
229 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
231 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
232 if( pFilter )
233 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
235 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_TEMPLATEPATH );
236 if( pFilter )
237 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
239 // add additional supported filters
240 ::std::vector< String >::const_iterator aIter( aFilterVector.begin() );
242 while( aIter != aFilterVector.end() )
244 if( ( pFilter = rMatcher.GetFilter4Mime( *aIter ) ) != NULL )
245 xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
247 ++aIter;
250 catch(IllegalArgumentException)
255 if( aFileDialog.Execute() != ERRCODE_NONE )
256 return;
257 else
259 aFilterName = aFileDialog.GetCurrentFilter();
260 aFile = aFileDialog.GetPath();
263 else
265 SFX_REQUEST_ARG (rReq, pFileName, SfxStringItem, ID_VAL_DUMMY0, FALSE);
266 SFX_REQUEST_ARG (rReq, pFilterName, SfxStringItem, ID_VAL_DUMMY1, FALSE);
268 aFile = pFileName->GetValue ();
270 if( pFilterName )
271 aFilterName = pFilterName->GetValue ();
274 mpDocSh->SetWaitCursor( TRUE );
276 SfxMedium* pMedium = new SfxMedium( aFile, STREAM_READ | STREAM_NOCREATE, FALSE );
277 const SfxFilter* pFilter = NULL;
279 SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium, &pFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
281 BOOL bDrawMode = mpViewShell && mpViewShell->ISA(DrawViewShell);
282 BOOL bInserted = FALSE;
284 if( pFilter )
286 pMedium->SetFilter( pFilter );
287 aFilterName = pFilter->GetFilterName();
289 if( pMedium->IsStorage() || ( pMedium->GetInStream() && SotStorage::IsStorageFile( pMedium->GetInStream() ) ) )
291 if ( pFilter->GetServiceName().EqualsAscii( "com.sun.star.presentation.PresentationDocument" ) ||
292 pFilter->GetServiceName().EqualsAscii( "com.sun.star.drawing.DrawingDocument" ) )
294 // Draw, Impress or PowerPoint document
295 // the ownership of the Medium is transferred
296 if( bDrawMode )
297 InsSDDinDrMode( pMedium );
298 else
299 InsSDDinOlMode( pMedium );
301 // don't delete Medium here, ownership of pMedium has changed in this case
302 bInserted = TRUE;
305 else
307 BOOL bFound = ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFilter->GetMimeType() ) != aFilterVector.end() );
308 if( !bFound &&
309 ( aFilterName.SearchAscii( "Text" ) != STRING_NOTFOUND ||
310 aFilterName.SearchAscii( "Rich" ) != STRING_NOTFOUND ||
311 aFilterName.SearchAscii( "RTF" ) != STRING_NOTFOUND ||
312 aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND ) )
314 bFound = TRUE;
317 if( bFound )
319 if( bDrawMode )
320 InsTextOrRTFinDrMode(pMedium);
321 else
322 InsTextOrRTFinOlMode(pMedium);
324 bInserted = TRUE;
325 delete pMedium;
330 mpDocSh->SetWaitCursor( FALSE );
332 if( !bInserted )
334 ErrorBox aErrorBox( mpWindow, WB_OK, String( SdResId( STR_READ_DATA_ERROR ) ) );
335 aErrorBox.Execute();
336 delete pMedium;
340 // -----------------------------------------------------------------------------
342 BOOL FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
344 BOOL bOK = FALSE;
346 // Liste mit Seitennamen (wenn NULL, dann alle Seiten)
347 List* pBookmarkList = NULL;
349 mpDocSh->SetWaitCursor( FALSE );
350 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
351 AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg( NULL, mpDoc, pMedium, aFile ) : 0;
353 if( !pDlg )
354 return FALSE;
356 // Ev. wird eine QueryBox geoeffnet ("Links aktualisieren?"),
357 // daher wird der Dialog der aktuelle DefModalDialogParent
358 ::Window* pDefParent = GetpApp()->GetDefDialogParent();
359 GetpApp()->SetDefDialogParent(pDlg->GetWindow());
361 USHORT nRet = pDlg->Execute();
363 GetpApp()->SetDefDialogParent(pDefParent);
365 mpDocSh->SetWaitCursor( TRUE );
367 if( nRet == RET_OK )
369 // Zuerst Seiten einfuegen
370 pBookmarkList = pDlg->GetList( 1 ); // Seiten
371 BOOL bLink = pDlg->IsLink();
372 BOOL bReplace = FALSE;
373 SdPage* pPage = NULL;
374 ::sd::View* pView = mpViewShell->GetView();
376 if (pView->ISA(OutlineView))
378 pPage = static_cast<OutlineView*>(pView)->GetActualPage();
380 else
382 pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
385 USHORT nPos = 0xFFFF;
387 if (pPage && !pPage->IsMasterPage())
389 if (pPage->GetPageKind() == PK_STANDARD)
391 nPos = pPage->GetPageNum() + 2;
393 else if (pPage->GetPageKind() == PK_NOTES)
395 nPos = pPage->GetPageNum() + 1;
399 BOOL bNameOK;
400 List* pObjectBookmarkList = pDlg->GetList( 2 ); // Objekte
401 List* pExchangeList = NULL;
403 // Es werden ausgewaehlte Seiten und/oder ausgewaehlte Objekte oder
404 // alles eingefuegt, wenn pBookmarkList NULL ist!
405 if( pBookmarkList || !pObjectBookmarkList )
407 // Um zu gewaehrleisten, dass alle Seitennamen eindeutig sind, werden
408 // die einzufuegenden geprueft und gegebenenfalls in einer Ersatzliste
409 // aufgenommen
410 // bNameOK == FALSE -> Benutzer hat abgebrochen
411 bNameOK = mpView->GetExchangeList( pExchangeList, pBookmarkList, 0 );
413 if( bNameOK )
414 bOK = mpDoc->InsertBookmarkAsPage( pBookmarkList, pExchangeList,
415 bLink, bReplace, nPos,
416 FALSE, NULL, TRUE, TRUE, FALSE );
418 // Loeschen der BookmarkList
419 if( pBookmarkList )
421 String* pString = (String*) pBookmarkList->First();
422 while( pString )
424 delete pString;
425 pString = (String*) pBookmarkList->Next();
427 delete pBookmarkList;
428 pBookmarkList = NULL;
430 // Loeschen der ExchangeList
431 if( pExchangeList )
433 String* pString = (String*) pExchangeList->First();
434 while( pString )
436 delete pString;
437 pString = (String*) pExchangeList->Next();
439 delete pExchangeList;
440 pExchangeList = NULL;
443 // Dann Objekte einfuegen
444 //pBookmarkList = pDlg->GetList( 2 ); // Objekte
445 pBookmarkList = pObjectBookmarkList;
447 // Um zu gewaehrleisten... (s.o.)
448 bNameOK = mpView->GetExchangeList( pExchangeList, pBookmarkList, 1 );
450 if( bNameOK )
451 bOK = mpDoc->InsertBookmarkAsObject( pBookmarkList, pExchangeList,
452 bLink, NULL, NULL);
454 // Loeschen der BookmarkList
455 if( pBookmarkList )
457 String* pString = (String*) pBookmarkList->First();
458 while( pString )
460 delete pString;
461 pString = (String*) pBookmarkList->Next();
463 delete pBookmarkList;
464 pBookmarkList = NULL;
466 // Loeschen der ExchangeList
467 if( pExchangeList )
469 String* pString = (String*) pExchangeList->First();
470 while( pString )
472 delete pString;
473 pString = (String*) pExchangeList->Next();
475 delete pExchangeList;
476 pExchangeList = NULL;
479 if( pDlg->IsRemoveUnnessesaryMasterPages() )
480 mpDoc->RemoveUnnecessaryMasterPages();
483 delete pDlg;
485 return (bOK);
488 // -----------------------------------------------------------------------------
490 void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
492 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
493 AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg(NULL, mpDoc, NULL, aFile ) : 0;
494 if( !pDlg )
495 return;
497 mpDocSh->SetWaitCursor( FALSE );
499 USHORT nRet = pDlg->Execute();
500 mpDocSh->SetWaitCursor( TRUE );
502 if( nRet == RET_OK )
504 // gewaehltes Dateiformat: Text oder RTF oder HTML (Default ist Text)
505 USHORT nFormat = EE_FORMAT_TEXT;
507 if( aFilterName.SearchAscii( "Rich") != STRING_NOTFOUND )
508 nFormat = EE_FORMAT_RTF;
509 else if( aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND )
510 nFormat = EE_FORMAT_HTML;
512 // einen eigenen Outliner erzeugen, denn:
513 // der Dokument-Outliner koennte gerade vom Gliederungsmodus
514 // benutzt werden;
515 // der Draw-Outliner der Drawing Engine koennte zwischendurch
516 // was zeichnen muessen;
517 // der globale Outliner koennte in SdPage::CreatePresObj
518 // benutzt werden
519 // SfxItemPool* pPool = mpDoc->GetDrawOutliner().GetEmptyItemSet().GetPool();
520 SdrOutliner* pOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
521 // pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)mpDoc->GetStyleSheetPool());
522 // pOutliner->SetEditTextObjectPool(pPool);
523 // pOutliner->SetForbiddenCharsTable( mpDoc->GetForbiddenCharsTable() );
525 // Referenz-Device setzen
526 pOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
528 SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
529 aLayoutName = pPage->GetLayoutName();
530 aLayoutName.Erase(aLayoutName.SearchAscii(SD_LT_SEPARATOR));
532 pOutliner->SetPaperSize(pPage->GetSize());
534 SvStream* pStream = pMedium->GetInStream();
535 DBG_ASSERT( pStream, "Kein InStream!" );
536 pStream->Seek( 0 );
538 ULONG nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
540 if (nErr || !pOutliner->GetEditEngine().GetText().Len())
542 ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
543 String(SdResId(STR_READ_DATA_ERROR)));
544 aErrorBox.Execute();
546 else
548 // ist es eine Masterpage?
549 if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EM_MASTERPAGE &&
550 !pPage->IsMasterPage())
552 pPage = (SdPage*)(&(pPage->TRG_GetMasterPage()));
555 DBG_ASSERT(pPage, "Seite nicht gefunden");
557 // wenn gerade editiert wird, in dieses Textobjekt einfliessen lassen
558 OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
559 if( pOutlinerView )
561 SdrObject* pObj = mpView->GetTextEditObject();
562 if( pObj &&
563 pObj->GetObjInventor() == SdrInventor &&
564 pObj->GetObjIdentifier() == OBJ_TITLETEXT &&
565 pOutliner->GetParagraphCount() > 1 )
567 // In Titelobjekten darf nur ein Absatz vorhanden sein
568 while ( pOutliner->GetParagraphCount() > 1 )
570 Paragraph* pPara = pOutliner->GetParagraph( 0 );
571 ULONG nLen = pOutliner->GetText( pPara, 1 ).Len();
572 pOutliner->QuickDelete( ESelection( 0, (USHORT) nLen, 1, 0 ) );
573 pOutliner->QuickInsertLineBreak( ESelection( 0, (USHORT) nLen, 0, (USHORT) nLen ) );
578 OutlinerParaObject* pOPO = pOutliner->CreateParaObject();
580 if (pOutlinerView)
582 pOutlinerView->InsertText(*pOPO);
584 else
586 SdrRectObj* pTO = new SdrRectObj(OBJ_TEXT);
587 pTO->SetOutlinerParaObject(pOPO);
589 const bool bUndo = mpView->IsUndoEnabled();
590 if( bUndo )
591 mpView->BegUndo(String(SdResId(STR_UNDO_INSERT_TEXTFRAME)));
592 pPage->InsertObject(pTO);
594 // koennte groesser sein als die max. erlaubte Groesse:
595 // falls noetig, die Objektgroesse begrenzen
596 Size aSize(pOutliner->CalcTextSize());
597 Size aMaxSize = mpDoc->GetMaxObjSize();
598 aSize.Height() = Min(aSize.Height(), aMaxSize.Height());
599 aSize.Width() = Min(aSize.Width(), aMaxSize.Width());
600 aSize = mpWindow->LogicToPixel(aSize);
602 // in der Mitte des Fensters absetzen
603 Size aTemp(mpWindow->GetOutputSizePixel());
604 Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
605 aPos.X() -= aSize.Width() / 2;
606 aPos.Y() -= aSize.Height() / 2;
607 aSize = mpWindow->PixelToLogic(aSize);
608 aPos = mpWindow->PixelToLogic(aPos);
609 pTO->SetLogicRect(Rectangle(aPos, aSize));
611 if (pDlg->IsLink())
613 pTO->SetTextLink(aFile, aFilterName, gsl_getSystemTextEncoding() );
616 if( bUndo )
618 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
619 mpView->EndUndo();
623 delete pOutliner;
626 delete pDlg;
629 // -----------------------------------------------------------------------------
631 void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
633 // gewaehltes Dateiformat: Text oder RTF oder HTML (Default ist Text)
634 USHORT nFormat = EE_FORMAT_TEXT;
636 if( aFilterName.SearchAscii( "Rich") != STRING_NOTFOUND )
637 nFormat = EE_FORMAT_RTF;
638 else if( aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND )
639 nFormat = EE_FORMAT_HTML;
641 ::Outliner* pDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
642 List* pList = pDocliner->GetView(0)->CreateSelectionList();
643 Paragraph* pPara = (Paragraph*)pList->First();
645 // wo soll eingefuegt werden?
646 while( !pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
648 pPara = pDocliner->GetParent(pPara);
650 ULONG nTargetPos = pDocliner->GetAbsPos(pPara) + 1;
652 // Layout der Vorgaengerseite uebernehmen
653 USHORT nPage = 0;
654 pPara = pDocliner->GetParagraph( pDocliner->GetAbsPos( pPara ) - 1 );
655 while (pPara)
657 ULONG nPos = pDocliner->GetAbsPos( pPara );
658 if ( pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
659 nPage++;
660 pPara = pDocliner->GetParagraph( nPos - 1 );
662 SdPage* pPage = mpDoc->GetSdPage(nPage, PK_STANDARD);
663 aLayoutName = pPage->GetLayoutName();
664 aLayoutName.Erase(aLayoutName.SearchAscii(SD_LT_SEPARATOR));
666 // einen eigenen Outliner erzeugen, denn:
667 // der Dokument-Outliner koennte gerade vom Gliederungsmodus
668 // benutzt werden;
669 // der Draw-Outliner der Drawing Engine koennte zwischendurch
670 // was zeichnen muessen;
671 // der globale Outliner koennte in SdPage::CreatePresObj
672 // benutzt werden
673 ::Outliner* pOutliner = new ::Outliner( &mpDoc->GetItemPool(), OUTLINERMODE_OUTLINEOBJECT );
674 pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)mpDoc->GetStyleSheetPool());
676 // Referenz-Device setzen
677 pOutliner->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
678 pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
680 SvStream* pStream = pMedium->GetInStream();
681 DBG_ASSERT( pStream, "Kein InStream!" );
682 pStream->Seek( 0 );
684 ULONG nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
686 if (nErr || !pOutliner->GetEditEngine().GetText().Len())
688 ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
689 String(SdResId(STR_READ_DATA_ERROR)));
690 aErrorBox.Execute();
692 else
694 ULONG nParaCount = pOutliner->GetParagraphCount();
696 // fuer Fortschrittsanzeige: Anzahl der Ebene-0-Absaetze
697 USHORT nNewPages = 0;
698 pPara = pOutliner->GetParagraph( 0 );
699 while (pPara)
701 ULONG nPos = pOutliner->GetAbsPos( pPara );
702 if( pOutliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
703 nNewPages++;
704 pPara = pOutliner->GetParagraph( ++nPos );
707 mpDocSh->SetWaitCursor( FALSE );
709 SfxProgress* pProgress = new SfxProgress( mpDocSh, String( SdResId(STR_CREATE_PAGES)), nNewPages);
710 if( pProgress )
711 pProgress->SetState( 0, 100 );
713 nNewPages = 0;
715 pDocliner->GetUndoManager().EnterListAction(
716 String(SdResId(STR_UNDO_INSERT_FILE)), String() );
718 ULONG nSourcePos = 0;
719 SfxStyleSheet* pStyleSheet = pPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
720 Paragraph* pSourcePara = pOutliner->GetParagraph( 0 );
721 while (pSourcePara)
723 ULONG nPos = pOutliner->GetAbsPos( pSourcePara );
724 sal_Int16 nDepth = pOutliner->GetDepth( (USHORT) nPos );
726 // den letzte Absatz nur uebernehmen, wenn er gefuellt ist
727 if (nSourcePos < nParaCount - 1 ||
728 pOutliner->GetText(pSourcePara).Len() > 0)
730 pDocliner->Insert( pOutliner->GetText(pSourcePara), nTargetPos, nDepth );
731 String aStyleSheetName( pStyleSheet->GetName() );
732 aStyleSheetName.Erase( aStyleSheetName.Len()-1, 1 );
733 aStyleSheetName += String::CreateFromInt32( nDepth <= 0 ? 1 : nDepth+1 );
734 SfxStyleSheetBasePool* pStylePool = mpDoc->GetStyleSheetPool();
735 SfxStyleSheet* pOutlStyle = (SfxStyleSheet*) pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() );
736 pDocliner->SetStyleSheet( nTargetPos, pOutlStyle );
739 if( pDocliner->HasParaFlag( pSourcePara, PARAFLAG_ISPAGE ) )
741 nNewPages++;
742 if( pProgress )
743 pProgress->SetState( nNewPages );
746 pSourcePara = pOutliner->GetParagraph( ++nPos );
747 nTargetPos++;
748 nSourcePos++;
751 pDocliner->GetUndoManager().LeaveListAction();
753 if( pProgress )
754 delete pProgress;
756 mpDocSh->SetWaitCursor( TRUE );
759 delete pOutliner;
762 // -----------------------------------------------------------------------------
764 BOOL FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
766 OutlineView* pOlView = static_cast<OutlineView*>(mpView);
768 // Outliner-Inhalte ins SdDrawDocument uebertragen
769 pOlView->PrepareClose();
771 // einlesen wie im Zeichenmodus
772 if (InsSDDinDrMode(pMedium))
774 ::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
776 // Benachrichtigungs-Links temporaer trennen
777 Link aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
778 pOutliner->SetParaInsertedHdl( Link(NULL, NULL));
779 Link aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
780 pOutliner->SetParaRemovingHdl( Link(NULL, NULL));
781 Link aOldDepthChangedHdl = pOutliner->GetDepthChangedHdl();
782 pOutliner->SetDepthChangedHdl( Link(NULL, NULL));
783 Link aOldBeginMovingHdl = pOutliner->GetBeginMovingHdl();
784 pOutliner->SetBeginMovingHdl( Link(NULL, NULL));
785 Link aOldEndMovingHdl = pOutliner->GetEndMovingHdl();
786 pOutliner->SetEndMovingHdl( Link(NULL, NULL));
788 Link aOldStatusEventHdl = pOutliner->GetStatusEventHdl();
789 pOutliner->SetStatusEventHdl(Link(NULL, NULL));
791 pOutliner->Clear();
792 pOlView->FillOutliner();
794 // Links wieder setzen
795 pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
796 pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
797 pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
798 pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
799 pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
800 pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
802 return TRUE;
804 else
805 return FALSE;
808 // -----------------------------------------------------------------------------
810 void FuInsertFile::GetSupportedFilterVector( ::std::vector< String >& rFilterVector )
812 SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
813 const SfxFilter* pSearchFilter = NULL;
815 rFilterVector.clear();
817 if( ( pSearchFilter = rMatcher.GetFilter4Mime( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "text/plain" ) ) ) ) != NULL )
818 rFilterVector.push_back( pSearchFilter->GetMimeType() );
820 if( ( pSearchFilter = rMatcher.GetFilter4Mime( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "application/rtf" ) ) ) ) != NULL )
821 rFilterVector.push_back( pSearchFilter->GetMimeType() );
823 if( ( pSearchFilter = rMatcher.GetFilter4Mime( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "text/html" ) ) ) ) != NULL )
824 rFilterVector.push_back( pSearchFilter->GetMimeType() );
827 } // end of namespace sd