Update ooo320-m1
[ooovba.git] / sw / source / ui / app / docsh.cxx
blob2998a6084393ece2baa4c5870f9e08276500c30a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docsh.cxx,v $
10 * $Revision: 1.79.188.1 $
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_sw.hxx"
34 #include <hintids.hxx>
35 #include <rtl/logfile.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/wrkwin.hxx>
39 #include <vcl/jobset.hxx>
40 #include <tools/urlobj.hxx>
41 #include <svtools/whiter.hxx>
42 #include <svtools/zforlist.hxx>
43 #include <svtools/eitem.hxx>
44 #include <svtools/stritem.hxx>
45 #include <svx/adjitem.hxx>
46 #include <basic/sbx.hxx>
47 #include <svtools/moduleoptions.hxx>
48 #include <sfx2/app.hxx>
49 #include <sfx2/request.hxx>
50 #include <svtools/misccfg.hxx>
51 #include <sfx2/passwd.hxx>
52 #include <sfx2/bindings.hxx>
53 #include <sfx2/docfile.hxx>
54 #include <sfx2/evntconf.hxx>
55 #include <sfx2/docfilt.hxx>
56 #include <sfx2/printer.hxx>
57 #include <svx/linkmgr.hxx>
58 #include <svx/srchitem.hxx>
59 #include <svx/flstitem.hxx>
60 #include <svx/htmlmode.hxx>
61 #include <svx/svxmsbas.hxx>
62 #include <svtools/soerr.hxx>
63 #include <sot/clsids.hxx>
64 #include <basic/basmgr.hxx>
65 #include <basic/sbmod.hxx>
66 //#include <basic/sbjsmod.hxx>
67 #include <swevent.hxx>
68 #include <fmtpdsc.hxx>
69 #include <fmtfsize.hxx>
70 #include <fmtfld.hxx>
71 #include <node.hxx>
72 #include <swwait.hxx>
73 #include <swprtopt.hxx>
74 #include <frmatr.hxx>
75 #include <view.hxx> // fuer die aktuelle Sicht
76 #include <edtwin.hxx>
77 #include <PostItMgr.hxx>
78 #include <postit.hxx>
79 #include <wrtsh.hxx> // Verbindung zur Core
80 #include <docsh.hxx> // Dokumenterzeugung
81 #include <basesh.hxx>
82 #include <viewopt.hxx>
83 #include <wdocsh.hxx>
84 #include <swmodule.hxx>
85 #include <globdoc.hxx>
86 #include <usrpref.hxx>
87 #include <shellio.hxx> // I/O
88 #include <docstyle.hxx>
89 #include <doc.hxx>
90 #include <docstat.hxx>
91 #include <pagedesc.hxx>
92 #include <pview.hxx>
93 #include <mdiexp.hxx>
94 #include <swbaslnk.hxx>
95 #include <srcview.hxx>
96 #include <ndindex.hxx>
97 #include <ndole.hxx>
98 #include <swcli.hxx>
99 #include <txtftn.hxx>
100 #include <ftnidx.hxx>
102 // --> FME 2004-08-05 #i20883# Digital Signatures and Encryption
103 #include <fldbas.hxx>
104 #include <docary.hxx>
105 // <--
106 #include <swerror.h> // Fehlermeldungen
107 #include <helpid.h>
108 #include <cmdid.h>
109 #include <globals.hrc>
110 #include <app.hrc>
111 #include "warnpassword.hxx"
113 #include <cfgid.h>
114 #include <svtools/moduleoptions.hxx>
115 #include <svtools/fltrcfg.hxx>
116 #include <svx/htmlcfg.hxx>
117 #include <sfx2/fcontnr.hxx>
118 #include <sfx2/objface.hxx>
119 #include <comphelper/storagehelper.hxx>
121 #define SwDocShell
122 #include <sfx2/msg.hxx>
123 #include <swslots.hxx>
124 #include <com/sun/star/document/UpdateDocMode.hpp>
126 #include <com/sun/star/document/XDocumentProperties.hpp>
127 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
129 #include <unomid.h>
131 #include <sfx2/Metadatable.hxx>
134 using rtl::OUString;
135 using namespace ::com::sun::star;
136 using namespace ::com::sun::star::uno;
137 using namespace ::com::sun::star::script;
138 using namespace ::com::sun::star::container;
141 SFX_IMPL_INTERFACE( SwDocShell, SfxObjectShell, SW_RES(0) )
143 SFX_CHILDWINDOW_REGISTRATION( SID_HYPERLINK_INSERT );
146 TYPEINIT2(SwDocShell, SfxObjectShell, SfxListener);
148 //-------------------------------------------------------------------------
149 SFX_IMPL_OBJECTFACTORY(SwDocShell, SvGlobalName(SO3_SW_CLASSID), SFXOBJECTSHELL_STD_NORMAL|SFXOBJECTSHELL_HASMENU, "swriter" )
151 /*--------------------------------------------------------------------
152 Beschreibung: Laden vorbereiten
153 --------------------------------------------------------------------*/
156 Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
157 SwCrsrShell *pCrsrShell,
158 SwPaM* pPaM )
160 BOOL bAPICall = FALSE;
161 const SfxPoolItem* pApiItem;
162 const SfxItemSet* pMedSet;
163 if( 0 != ( pMedSet = rMedium.GetItemSet() ) && SFX_ITEM_SET ==
164 pMedSet->GetItemState( FN_API_CALL, TRUE, &pApiItem ) )
165 bAPICall = ((const SfxBoolItem*)pApiItem)->GetValue();
167 const SfxFilter* pFlt = rMedium.GetFilter();
168 if( !pFlt )
170 if(!bAPICall)
172 InfoBox( 0, SW_RESSTR(STR_CANTOPEN)).Execute();
174 return 0;
176 String aFileName( rMedium.GetName() );
177 SwRead pRead = SwReaderWriter::GetReader( pFlt->GetUserData() );
178 if( !pRead )
179 return 0;
181 if( rMedium.IsStorage()
182 ? SW_STORAGE_READER & pRead->GetReaderType()
183 : SW_STREAM_READER & pRead->GetReaderType() )
185 *ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) :
186 pCrsrShell ?
187 new SwReader( rMedium, aFileName, *pCrsrShell->GetCrsr() )
188 : new SwReader( rMedium, aFileName, pDoc );
190 else
191 return 0;
193 // PassWord Checken
194 String aPasswd;
195 if ((*ppRdr)->NeedsPasswd( *pRead ))
197 if(!bAPICall)
199 SfxPasswordDialog* pPasswdDlg =
200 new SfxPasswordDialog( 0 );
201 if(RET_OK == pPasswdDlg->Execute())
202 aPasswd = pPasswdDlg->GetPassword();
204 else
206 const SfxItemSet* pSet = rMedium.GetItemSet();
207 const SfxPoolItem *pPassItem;
208 if(pSet && SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, TRUE, &pPassItem))
209 aPasswd = ((const SfxStringItem *)pPassItem)->GetValue();
212 if (!(*ppRdr)->CheckPasswd( aPasswd, *pRead ))
214 InfoBox( 0, SW_RES(MSG_ERROR_PASSWD)).Execute();
215 delete *ppRdr;
216 return 0;
219 if(rMedium.IsStorage())
221 //SvStorageRef aStor( rMedium.GetStorage() );
222 const SfxItemSet* pSet = rMedium.GetItemSet();
223 const SfxPoolItem *pItem;
224 if(pSet && SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, TRUE, &pItem))
226 DBG_ASSERT(pItem->IsA( TYPE(SfxStringItem) ), "Fehler Parametertype");
227 comphelper::OStorageHelper::SetCommonStoragePassword( rMedium.GetStorage(), ((const SfxStringItem *)pItem)->GetValue() );
229 // Fuer's Dokument-Einfuegen noch die FF-Version, wenn's der
230 // eigene Filter ist.
231 ASSERT( /*pRead != ReadSw3 || */pRead != ReadXML || pFlt->GetVersion(),
232 "Am Filter ist keine FF-Version gesetzt" );
233 //if( (pRead == ReadSw3 || pRead == ReadXML) && pFlt->GetVersion() )
234 // aStor->SetVersion( (long)pFlt->GetVersion() );
236 // #i30171# set the UpdateDocMode at the SwDocShell
237 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
238 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
240 if( pFlt->GetDefaultTemplate().Len() )
241 pRead->SetTemplateName( pFlt->GetDefaultTemplate() );
243 if( pRead == ReadAscii && 0 != rMedium.GetInStream() &&
244 pFlt->GetUserData().EqualsAscii( FILTER_TEXT_DLG ) )
246 SwAsciiOptions aOpt;
247 const SfxItemSet* pSet;
248 const SfxPoolItem* pItem;
249 if( 0 != ( pSet = rMedium.GetItemSet() ) && SFX_ITEM_SET ==
250 pSet->GetItemState( SID_FILE_FILTEROPTIONS, TRUE, &pItem ) )
251 aOpt.ReadUserData( ((const SfxStringItem*)pItem)->GetValue() );
253 if( pRead )
254 pRead->GetReaderOpt().SetASCIIOpts( aOpt );
257 return pRead;
260 /*--------------------------------------------------------------------
261 Beschreibung: Laden
262 --------------------------------------------------------------------*/
264 BOOL SwDocShell::ConvertFrom( SfxMedium& rMedium )
266 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::ConvertFrom" );
268 SwReader* pRdr;
269 SwRead pRead = StartConvertFrom(rMedium, &pRdr);
270 if (!pRead)
271 return FALSE; // #129881# return if no reader is found
272 SotStorageRef pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
274 SwWait aWait( *this, TRUE );
276 // SfxProgress unterdruecken, wenn man Embedded ist
277 SW_MOD()->SetEmbeddedLoadSave(
278 SFX_CREATE_MODE_EMBEDDED == GetCreateMode() );
280 pRdr->GetDoc()->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell));
282 /* #106748# Restore the pool default if reading a saved document. */
283 pDoc->RemoveAllFmtLanguageDependencies();
285 ULONG nErr = pRdr->Read( *pRead );
287 // Evtl. ein altes Doc weg
288 if ( pDoc != pRdr->GetDoc() )
290 if( pDoc )
291 RemoveLink();
292 pDoc = pRdr->GetDoc();
294 AddLink();
296 if ( !mxBasePool.is() )
297 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
300 UpdateFontList();
301 InitDraw();
303 delete pRdr;
305 SW_MOD()->SetEmbeddedLoadSave( FALSE );
307 SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
308 BOOL bOk = !IsError( nErr );
310 // --> OD 2006-11-07 #i59688#
311 // // StartFinishedLoading rufen. Nicht bei asynchronen Filtern!
312 // // Diese muessen das selbst rufen!
313 // if( bOk && !pDoc->IsInLoadAsynchron() )
314 // StartLoadFinishedTimer();
315 if ( bOk && !pDoc->IsInLoadAsynchron() )
317 LoadingFinished();
319 // <--
321 pRead->setSotStorageRef(pStg); // #i45333# save sot storage ref in case of recursive calls
323 return bOk;
326 /*--------------------------------------------------------------------
327 Beschreibung: Sichern des Default-Formats, Stg vorhanden
328 --------------------------------------------------------------------*/
331 BOOL SwDocShell::Save()
333 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::Save" );
334 //#i3370# remove quick help to prevent saving of autocorrection suggestions
335 if(pView)
336 pView->GetEditWin().StopQuickHelp();
337 SwWait aWait( *this, TRUE );
339 CalcLayoutForOLEObjects(); // format for OLE objets
340 // --> OD 2006-03-17 #i62875#
341 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
342 if ( pWrtShell && pDoc &&
343 pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
344 docfunc::AllDrawObjsOnPage( *pDoc ) )
346 pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
348 // <--
350 ULONG nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE;
351 if( SfxObjectShell::Save() )
353 switch( GetCreateMode() )
355 case SFX_CREATE_MODE_INTERNAL:
356 nErr = 0;
357 break;
359 case SFX_CREATE_MODE_ORGANIZER:
361 WriterRef xWrt;
362 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt );
363 xWrt->SetOrganizerMode( TRUE );
364 SwWriter aWrt( *GetMedium(), *pDoc );
365 nErr = aWrt.Write( xWrt );
366 xWrt->SetOrganizerMode( FALSE );
368 break;
370 case SFX_CREATE_MODE_EMBEDDED:
371 // SfxProgress unterdruecken, wenn man Embedded ist
372 SW_MOD()->SetEmbeddedLoadSave( TRUE );
373 // kein break;
375 case SFX_CREATE_MODE_STANDARD:
376 case SFX_CREATE_MODE_PREVIEW:
377 default:
379 if( pDoc->ContainsMSVBasic() )
381 //TODO/MBA: it looks as that this code can be removed!
382 //SvxImportMSVBasic aTmp( *this, pIo->GetStorage() );
383 //aTmp.SaveOrDelMSVBAStorage( FALSE, aEmptyStr );
384 if( SvtFilterOptions::Get()->IsLoadWordBasicStorage() )
385 nVBWarning = SvxImportMSVBasic::
386 GetSaveWarningOfMSVBAStorage( *this );
387 pDoc->SetContainsMSVBasic( FALSE );
390 // TabellenBox Edit beenden!
391 if( pWrtShell )
392 pWrtShell->EndAllTblBoxEdit();
394 WriterRef xWrt;
395 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt );
397 BOOL bLockedView(FALSE);
398 if ( pWrtShell )
400 bLockedView = pWrtShell->IsViewLocked();
401 pWrtShell->LockView( TRUE ); //lock visible section
404 SwWriter aWrt( *GetMedium(), *pDoc );
405 nErr = aWrt.Write( xWrt );
407 if ( pWrtShell )
408 pWrtShell->LockView( bLockedView );
410 break;
412 SW_MOD()->SetEmbeddedLoadSave( FALSE );
414 SetError( nErr ? nErr : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
416 SfxViewFrame* pFrm = pWrtShell ? pWrtShell->GetView().GetViewFrame() : 0;
417 if( pFrm )
419 pFrm->GetBindings().SetState( SfxStringItem( SID_DOC_MODIFIED, ' ' ));
421 return !IsError( nErr );
424 /*--------------------------------------------------------------------
425 Beschreibung: Sichern im Defaultformat
426 --------------------------------------------------------------------*/
429 sal_Bool SwDocShell::SaveAs( SfxMedium& rMedium )
431 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SaveAs" );
433 SwWait aWait( *this, TRUE );
434 //#i3370# remove quick help to prevent saving of autocorrection suggestions
435 if(pView)
436 pView->GetEditWin().StopQuickHelp();
438 //#i91811# mod if we have an active margin window, write back the text
439 if (pView && pView->GetPostItMgr() && pView->GetPostItMgr()->GetActivePostIt())
440 pView->GetPostItMgr()->GetActivePostIt()->UpdateData();
442 if( pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) &&
443 !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS) )
444 RemoveOLEObjects();
447 // Task 75666 - is the Document imported by our Microsoft-Filters?
448 const SfxFilter* pOldFilter = GetMedium()->GetFilter();
449 if( pOldFilter &&
450 ( pOldFilter->GetUserData().EqualsAscii( FILTER_WW8 ) ||
451 pOldFilter->GetUserData().EqualsAscii( "CWW6" ) ||
452 pOldFilter->GetUserData().EqualsAscii( "WW6" ) ||
453 pOldFilter->GetUserData().EqualsAscii( "WW1" ) ))
455 // when saving it in our own fileformat, then remove the template
456 // name from the docinfo.
457 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
458 GetModel(), uno::UNO_QUERY_THROW);
459 uno::Reference<document::XDocumentProperties> xDocProps
460 = xDPS->getDocumentProperties();
461 xDocProps->setTemplateName(::rtl::OUString::createFromAscii(""));
462 xDocProps->setTemplateURL(::rtl::OUString::createFromAscii(""));
463 xDocProps->setTemplateDate(::util::DateTime());
467 CalcLayoutForOLEObjects(); // format for OLE objets
468 // --> OD 2006-03-17 #i62875#
469 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
470 if ( pWrtShell && pDoc &&
471 pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
472 docfunc::AllDrawObjsOnPage( *pDoc ) )
474 pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
476 // <--
478 ULONG nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE;
479 uno::Reference < embed::XStorage > xStor = rMedium.GetOutputStorage();
480 if( SfxObjectShell::SaveAs( rMedium ) )
482 if( GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && !ISA( SwGlobalDocShell ) )
484 // This is to set the correct class id if SaveAs is
485 // called from SwDoc::SplitDoc to save a normal doc as
486 // global doc. In this case, SaveAs is called at a
487 // normal doc shell, therefore, SfxInplaceObject::SaveAs
488 // will set the wrong class id.
489 SvGlobalName aClassName;
490 String aAppName, aLongUserName, aUserName;
491 SfxObjectShellRef xDocSh =
492 new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL );
493 // the global document can not be a template
494 xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), sal_False );
495 xDocSh->DoClose();
499 // TabellenBox Edit beenden!
500 if( pWrtShell )
501 pWrtShell->EndAllTblBoxEdit();
503 // Modified-Flag merken und erhalten ohne den Link zu Callen
504 // (fuer OLE; nach Anweisung von MM)
505 BOOL bIsModified = pDoc->IsModified();
506 SwUndoNoModifiedPosition aOldPos = pDoc->getUndoNoModifiedPosition();
507 Link aOldOLELnk( pDoc->GetOle2Link() );
508 pDoc->SetOle2Link( Link() );
510 // SfxProgress unterdruecken, wenn man Embedded ist
511 SW_MOD()->SetEmbeddedLoadSave(
512 SFX_CREATE_MODE_EMBEDDED == GetCreateMode() );
514 WriterRef xWrt;
515 ::GetXMLWriter( aEmptyStr, rMedium.GetBaseURL( true ), xWrt );
517 BOOL bLockedView(FALSE);
518 if ( pWrtShell )
520 bLockedView = pWrtShell->IsViewLocked();
521 pWrtShell->LockView( TRUE ); //lock visible section
524 SwWriter aWrt( rMedium, *pDoc );
525 nErr = aWrt.Write( xWrt );
527 if ( pWrtShell )
528 pWrtShell->LockView( bLockedView );
530 if( bIsModified )
532 pDoc->SetModified();
533 pDoc->setUndoNoModifiedPosition( aOldPos );
535 pDoc->SetOle2Link( aOldOLELnk );
537 SW_MOD()->SetEmbeddedLoadSave( FALSE );
539 SetError( nErr ? nErr : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
541 return !IsError( nErr );
544 /*--------------------------------------------------------------------
545 Beschreibung: Sichern aller Formate
546 --------------------------------------------------------------------*/
547 SwSrcView* lcl_GetSourceView( SwDocShell* pSh )
549 // sind wir in der SourceView?
550 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( pSh );
551 SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
552 return PTR_CAST( SwSrcView, pViewShell);
555 BOOL SwDocShell::ConvertTo( SfxMedium& rMedium )
557 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::ConvertTo" );
558 const SfxFilter* pFlt = rMedium.GetFilter();
559 if( !pFlt )
560 return FALSE;
562 WriterRef xWriter;
563 SwReaderWriter::GetWriter( pFlt->GetUserData(), rMedium.GetBaseURL( true ), xWriter );
564 if( !xWriter.Is() )
565 { // Der Filter ist nicht vorhanden
566 InfoBox( 0,
567 SW_RESSTR(STR_DLLNOTFOUND) ).Execute();
568 return FALSE;
571 //#i3370# remove quick help to prevent saving of autocorrection suggestions
572 if(pView)
573 pView->GetEditWin().StopQuickHelp();
575 //#i91811# mod if we have an active margin window, write back the text
576 if (pView && pView->GetPostItMgr() && pView->GetPostItMgr()->GetActivePostIt())
577 pView->GetPostItMgr()->GetActivePostIt()->UpdateData();
579 ULONG nVBWarning = 0;
581 if( pDoc->ContainsMSVBasic() )
583 BOOL bSave = pFlt->GetUserData().EqualsAscii( "CWW8" )
584 && SvtFilterOptions::Get()->IsLoadWordBasicStorage();
586 if ( bSave )
588 SvStorageRef xStg = new SotStorage( rMedium.GetOutStream(), FALSE );
589 DBG_ASSERT( !xStg->GetError(), "No storage available for storing VBA macros!" );
590 if ( !xStg->GetError() )
592 SvxImportMSVBasic aTmp( *this, *xStg );
593 nVBWarning = aTmp.SaveOrDelMSVBAStorage( bSave, String::CreateFromAscii("Macros") );
594 xStg->Commit();
595 pDoc->SetContainsMSVBasic( TRUE );
600 // TabellenBox Edit beenden!
601 if( pWrtShell )
602 pWrtShell->EndAllTblBoxEdit();
604 if( pFlt->GetUserData().EqualsAscii( "HTML") )
606 SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
607 if( !pHtmlOpt->IsStarBasic() && pHtmlOpt->IsStarBasicWarning() && HasBasic() )
609 uno::Reference< XLibraryContainer > xLibCont(GetBasicContainer(), UNO_QUERY);
610 uno::Reference< XNameAccess > xLib;
611 Sequence<rtl::OUString> aNames = xLibCont->getElementNames();
612 const rtl::OUString* pNames = aNames.getConstArray();
613 for(sal_Int32 nLib = 0; nLib < aNames.getLength(); nLib++)
615 Any aLib = xLibCont->getByName(pNames[nLib]);
616 aLib >>= xLib;
617 if(xLib.is())
619 Sequence<rtl::OUString> aModNames = xLib->getElementNames();
620 if(aModNames.getLength())
622 SetError(WARN_SWG_HTML_NO_MACROS, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
623 break;
628 UpdateDocInfoForSave();
631 // --> FME 2007-5-7 #i76360# Update document statistics
632 SwDocStat aDocStat( pDoc->GetDocStat() );;
633 pDoc->UpdateDocStat( aDocStat );
634 // <--
635 CalcLayoutForOLEObjects(); // format for OLE objets
636 // --> OD 2006-03-17 #i62875#
637 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
638 if ( pWrtShell && pDoc &&
639 pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
640 docfunc::AllDrawObjsOnPage( *pDoc ) )
642 pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
644 // <--
646 if( xWriter->IsStgWriter() &&
647 ( /*xWriter->IsSw3Writer() ||*/
648 pFlt->GetUserData().EqualsAscii( FILTER_XML ) ||
649 pFlt->GetUserData().EqualsAscii( FILTER_XMLV ) ||
650 pFlt->GetUserData().EqualsAscii( FILTER_XMLVW ) ) )
652 // eigenen Typ ermitteln
653 BYTE nMyType = 0;
654 if( ISA( SwWebDocShell) )
655 nMyType = 1;
656 else if( ISA( SwGlobalDocShell) )
657 nMyType = 2;
659 // gewuenschten Typ ermitteln
660 BYTE nSaveType = 0;
661 ULONG nSaveClipId = pFlt->GetFormat();
662 if( SOT_FORMATSTR_ID_STARWRITERWEB_8 == nSaveClipId ||
663 SOT_FORMATSTR_ID_STARWRITERWEB_60 == nSaveClipId ||
664 SOT_FORMATSTR_ID_STARWRITERWEB_50 == nSaveClipId ||
665 SOT_FORMATSTR_ID_STARWRITERWEB_40 == nSaveClipId )
666 nSaveType = 1;
667 else if( SOT_FORMATSTR_ID_STARWRITERGLOB_8 == nSaveClipId ||
668 SOT_FORMATSTR_ID_STARWRITERGLOB_60 == nSaveClipId ||
669 SOT_FORMATSTR_ID_STARWRITERGLOB_50 == nSaveClipId ||
670 SOT_FORMATSTR_ID_STARWRITERGLOB_40 == nSaveClipId )
671 nSaveType = 2;
673 // Flags am Dokument entsprechend umsetzen
674 BOOL bIsHTMLModeSave = GetDoc()->get(IDocumentSettingAccess::HTML_MODE);
675 BOOL bIsGlobalDocSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT);
676 BOOL bIsGlblDocSaveLinksSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
677 if( nMyType != nSaveType )
679 GetDoc()->set(IDocumentSettingAccess::HTML_MODE, 1 == nSaveType);
680 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, 2 == nSaveType);
681 if( 2 != nSaveType )
682 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
685 // if the target format is storage based, then the output storage must be already created
686 if ( rMedium.IsStorage() )
688 // set MediaType on target storage
689 // (MediaType will be queried during SaveAs)
692 // TODO/MBA: testing
693 uno::Reference < beans::XPropertySet > xSet( rMedium.GetStorage(), uno::UNO_QUERY );
694 if ( xSet.is() )
695 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("MediaType"), uno::makeAny( ::rtl::OUString( SotExchange::GetFormatMimeType( nSaveClipId ) ) ) );
697 catch ( uno::Exception& )
702 // Jetzt das Dokument normal speichern
703 BOOL bRet = SaveAs( rMedium );
705 if( nMyType != nSaveType )
707 GetDoc()->set(IDocumentSettingAccess::HTML_MODE, bIsHTMLModeSave );
708 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, bIsGlobalDocSave);
709 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bIsGlblDocSaveLinksSave);
712 if( bRet && nMyType != nSaveType )
714 SvGlobalName aClassName;
715 String aAppName, aLongUserName, aUserName;
716 SfxObjectShellRef xDocSh;
717 switch( nSaveType )
719 case 0:
720 xDocSh = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
721 break;
722 case 1:
723 xDocSh = new SwWebDocShell( SFX_CREATE_MODE_INTERNAL );
724 break;
725 case 2:
726 xDocSh = new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL );
727 break;
731 return bRet;
734 if( pFlt->GetUserData().EqualsAscii( FILTER_TEXT_DLG ) &&
735 ( pWrtShell || !::lcl_GetSourceView( this ) ))
737 SwAsciiOptions aOpt;
738 String sItemOpt;
739 const SfxItemSet* pSet;
740 const SfxPoolItem* pItem;
741 if( 0 != ( pSet = rMedium.GetItemSet() ) )
743 if( SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS,
744 TRUE, &pItem ) )
745 sItemOpt = ((const SfxStringItem*)pItem)->GetValue();
747 if(sItemOpt.Len())
748 aOpt.ReadUserData( sItemOpt );
750 xWriter->SetAsciiOptions( aOpt );
753 // SfxProgress unterdruecken, wenn man Embedded ist
754 SW_MOD()->SetEmbeddedLoadSave(
755 SFX_CREATE_MODE_EMBEDDED == GetCreateMode());
757 // Kontext aufspannen, um die Anzeige der Selektion zu unterbinden
758 ULONG nErrno;
759 String aFileName( rMedium.GetName() );
761 //Keine View also das ganze Dokument!
762 if ( pWrtShell )
764 SwWait aWait( *this, TRUE );
765 pWrtShell->StartAllAction();
766 pWrtShell->Push();
767 SwWriter aWrt( rMedium, *pWrtShell, TRUE );
768 nErrno = aWrt.Write( xWriter, &aFileName );
769 //JP 16.05.97: falls der SFX uns die View waehrend des speicherns
770 // entzieht
771 if( pWrtShell )
773 pWrtShell->Pop(FALSE);
774 pWrtShell->EndAllAction();
777 else
779 // sind wir in der SourceView?
780 SwSrcView* pSrcView = ::lcl_GetSourceView( this );
781 if( pSrcView )
783 pSrcView->SaveContentTo(rMedium);
784 nErrno = 0;
786 else
788 SwWriter aWrt( rMedium, *pDoc );
789 nErrno = aWrt.Write( xWriter, &aFileName );
793 SW_MOD()->SetEmbeddedLoadSave( FALSE );
794 SetError( nErrno ? nErrno : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
795 if( !rMedium.IsStorage() )
796 rMedium.CloseOutStream();
798 return !IsError( nErrno );
801 /*--------------------------------------------------------------------
802 Beschreibung: Haende weg
803 --------------------------------------------------------------------*/
806 /*--------------------------------------------------------------------
807 Beschreibung: ??? noch nicht zu aktivieren, muss TRUE liefern
808 --------------------------------------------------------------------*/
811 sal_Bool SwDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor )
813 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SaveCompleted" );
814 BOOL bRet = SfxObjectShell::SaveCompleted( xStor );
815 if( bRet )
817 // erst hier entscheiden, ob das Speichern geklappt hat oder nicht
818 if( IsModified() )
819 pDoc->SetModified();
820 else
821 pDoc->ResetModified();
824 if( pOLEChildList )
826 BOOL bResetModified = IsEnableSetModified();
827 if( bResetModified )
828 EnableSetModified( FALSE );
830 uno::Sequence < rtl::OUString > aNames = pOLEChildList->GetObjectNames();
831 for( sal_Int32 n = aNames.getLength(); n; n-- )
833 if ( !pOLEChildList->MoveEmbeddedObject( aNames[n-1], GetEmbeddedObjectContainer() ) )
835 DBG_ERROR( "Copying of objects didn't work!" );
838 //SvPersist* pPersist = this;
839 //SvInfoObjectRef aRef( pInfList->GetObject( --n ));
840 //pPersist->Move( &aRef, aRef->GetStorageName() );
843 DELETEZ( pOLEChildList );
844 if( bResetModified )
845 EnableSetModified( TRUE );
847 return bRet;
850 /*--------------------------------------------------------------------
851 Beschreibung: Draw()-Overload fuer OLE2 (Sfx)
852 --------------------------------------------------------------------*/
854 void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& rSetup,
855 USHORT nAspect )
857 //fix #25341# Draw sollte das Modified nicht beeinflussen
858 BOOL bResetModified;
859 if ( TRUE == (bResetModified = IsEnableSetModified()) )
860 EnableSetModified( FALSE );
862 //sollte am Document ein JobSetup haengen, dann kopieren wir uns diesen,
863 //um nach dem PrtOle2 diesen wieder am Doc zu verankern.
864 //Einen leeren JobSetup setzen wir nicht ein, denn der wuerde nur zu
865 //fragwuerdigem Ergebnis nach teurer Neuformatierung fuehren (Preview!)
866 JobSetup *pOrig = 0;
867 if ( rSetup.GetPrinterName().Len() && ASPECT_THUMBNAIL != nAspect )
869 pOrig = const_cast<JobSetup*>(pDoc->getJobsetup());
870 if( pOrig ) // dann kopieren wir uns den
871 pOrig = new JobSetup( *pOrig );
872 pDoc->setJobsetup( rSetup );
875 Rectangle aRect( nAspect == ASPECT_THUMBNAIL ?
876 GetVisArea( nAspect ) : GetVisArea( ASPECT_CONTENT ) );
878 pDev->Push();
879 pDev->SetFillColor();
880 pDev->SetLineColor();
881 pDev->SetBackground();
882 BOOL bWeb = 0 != PTR_CAST(SwWebDocShell, this);
883 SwPrtOptions aOpts( aEmptyStr );
884 ViewShell::PrtOle2( pDoc, SW_MOD()->GetUsrPref(bWeb), aOpts, pDev, aRect );
885 pDev->Pop();
887 if( pOrig )
889 pDoc->setJobsetup( *pOrig );
890 delete pOrig;
892 if ( bResetModified )
893 EnableSetModified( TRUE );
897 void SwDocShell::SetVisArea( const Rectangle &rRect )
899 Rectangle aRect( rRect );
900 if ( pView )
902 Size aSz( pView->GetDocSz() );
903 aSz.Width() += DOCUMENTBORDER; aSz.Height() += DOCUMENTBORDER;
904 long nMoveX = 0, nMoveY = 0;
905 if ( aRect.Right() > aSz.Width() )
906 nMoveX = aSz.Width() - aRect.Right();
907 if ( aRect.Bottom() > aSz.Height() )
908 nMoveY = aSz.Height() - aRect.Bottom();
909 aRect.Move( nMoveX, nMoveY );
910 nMoveX = aRect.Left() < 0 ? -aRect.Left() : 0;
911 nMoveY = aRect.Top() < 0 ? -aRect.Top() : 0;
912 aRect.Move( nMoveX, nMoveY );
914 //Ruft das SfxInPlaceObject::SetVisArea()!
915 pView->SetVisArea( aRect, TRUE );
917 else
918 SfxObjectShell::SetVisArea( aRect );
922 Rectangle SwDocShell::GetVisArea( USHORT nAspect ) const
924 if ( nAspect == ASPECT_THUMBNAIL )
926 //PreView: VisArea auf die erste Seite einstellen.
927 SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 1 );
928 SwCntntNode* pNd = pDoc->GetNodes().GoNext( &aIdx );
930 const SwRect aPageRect = pNd->FindPageFrmRect( FALSE, 0, FALSE );
931 return aPageRect.SVRect();
933 // Why does this have to be that complicated? I replaced this by the
934 // call of FindPageFrmRect():
936 //PageDesc besorgen, vom ersten Absatz oder den default.
937 const SwFmtPageDesc &rDesc = pNd->GetSwAttrSet().GetPageDesc();
938 const SwPageDesc* pDesc = rDesc.GetPageDesc();
939 if( !pDesc )
940 pDesc = &const_cast<const SwDoc *>(pDoc)->GetPageDesc( 0 );
942 //Das Format wird evtl. von der virtuellen Seitennummer bestimmt.
943 const USHORT nPgNum = rDesc.GetNumOffset();
944 const BOOL bOdd = nPgNum % 2 ? TRUE : FALSE;
945 const SwFrmFmt *pFmt = bOdd ? pDesc->GetRightFmt() : pDesc->GetLeftFmt();
946 if ( !pFmt ) //#40568#
947 pFmt = bOdd ? pDesc->GetLeftFmt() : pDesc->GetRightFmt();
949 if ( pFmt->GetFrmSize().GetWidth() == LONG_MAX )
950 //Jetzt wird es aber Zeit fuer die Initialisierung
951 pDoc->getPrinter( true );
953 const SwFmtFrmSize& rFrmSz = pFmt->GetFrmSize();
954 const Size aSz( rFrmSz.GetWidth(), rFrmSz.GetHeight() );
955 const Point aPt( DOCUMENTBORDER, DOCUMENTBORDER );
956 const Rectangle aRect( aPt, aSz );
957 return aRect;*/
959 return SfxObjectShell::GetVisArea( nAspect );
962 Printer *SwDocShell::GetDocumentPrinter()
964 return pDoc->getPrinter( false );
967 OutputDevice* SwDocShell::GetDocumentRefDev()
969 return pDoc->getReferenceDevice( false );
972 void SwDocShell::OnDocumentPrinterChanged( Printer * pNewPrinter )
974 if ( pNewPrinter )
975 GetDoc()->setJobsetup( pNewPrinter->GetJobSetup() );
976 else
977 GetDoc()->setPrinter( 0, true, true );
980 ULONG SwDocShell::GetMiscStatus() const
982 return SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE;
985 // --> FME 2004-08-05 #i20883# Digital Signatures and Encryption
986 sal_uInt16 SwDocShell::GetHiddenInformationState( sal_uInt16 nStates )
988 // get global state like HIDDENINFORMATION_DOCUMENTVERSIONS
989 sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates );
991 if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES )
993 if ( GetDoc()->GetRedlineTbl().Count() )
994 nState |= HIDDENINFORMATION_RECORDEDCHANGES;
996 if ( nStates & HIDDENINFORMATION_NOTES )
998 ASSERT( GetWrtShell(), "No SwWrtShell, no information" )
999 if ( GetWrtShell() )
1001 SwFieldType* pType = GetWrtShell()->GetFldType( RES_POSTITFLD, aEmptyStr );
1002 SwClientIter aIter( *pType );
1003 SwClient* pFirst = aIter.GoStart();
1004 while( pFirst )
1006 if( static_cast<SwFmtFld*>(pFirst)->GetTxtFld() &&
1007 static_cast<SwFmtFld*>(pFirst)->IsFldInDoc() )
1009 nState |= HIDDENINFORMATION_NOTES;
1010 break;
1012 pFirst = ++aIter;
1017 return nState;
1019 // <--
1022 /*--------------------------------------------------------------------
1023 Beschreibung:
1024 --------------------------------------------------------------------*/
1027 void SwDocShell::GetState(SfxItemSet& rSet)
1029 SfxWhichIter aIter(rSet);
1030 USHORT nWhich = aIter.FirstWhich();
1032 while (nWhich)
1034 switch (nWhich)
1036 // MT: MakroChosser immer enablen, weil Neu moeglich
1037 // case SID_BASICCHOOSER:
1038 // {
1039 // StarBASIC* pBasic = GetBasic();
1040 // StarBASIC* pAppBasic = SFX_APP()->GetBasic();
1041 // if ( !(pBasic->GetModules()->Count() ||
1042 // pAppBasic->GetModules()->Count()) )
1043 // rSet.DisableItem(nWhich);
1044 // }
1045 // break;
1046 case SID_PRINTPREVIEW:
1048 BOOL bDisable = IsInPlaceActive();
1049 if ( !bDisable )
1051 SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this);
1052 while (pTmpFrm) // Preview suchen
1054 if ( PTR_CAST(SwView, pTmpFrm->GetViewShell()) &&
1055 ((SwView*)pTmpFrm->GetViewShell())->GetWrtShell().getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE))
1057 bDisable = TRUE;
1058 break;
1060 pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this);
1063 if ( bDisable )
1064 rSet.DisableItem( SID_PRINTPREVIEW );
1065 else
1067 SfxBoolItem aBool( SID_PRINTPREVIEW, FALSE );
1068 if( PTR_CAST( SwPagePreView, SfxViewShell::Current()) )
1069 aBool.SetValue( TRUE );
1070 rSet.Put( aBool );
1073 break;
1074 case SID_SOURCEVIEW:
1076 SfxViewShell* pCurrView = GetView() ? (SfxViewShell*)GetView()
1077 : SfxViewShell::Current();
1078 BOOL bSourceView = 0 != PTR_CAST(SwSrcView, pCurrView);
1079 rSet.Put(SfxBoolItem(SID_SOURCEVIEW, bSourceView));
1081 break;
1082 case SID_HTML_MODE:
1083 rSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
1084 break;
1086 case FN_ABSTRACT_STARIMPRESS:
1087 case FN_OUTLINE_TO_IMPRESS:
1089 SvtModuleOptions aMOpt;
1090 if ( !aMOpt.IsImpress() )
1091 rSet.DisableItem( nWhich );
1093 /* no break here */
1094 case FN_ABSTRACT_NEWDOC:
1095 case FN_OUTLINE_TO_CLIPBOARD:
1097 if ( !GetDoc()->GetNodes().GetOutLineNds().Count() )
1098 rSet.DisableItem( nWhich );
1100 break;
1101 case SID_BROWSER_MODE:
1102 case FN_PRINT_LAYOUT:
1104 sal_Bool bState = GetDoc()->get(IDocumentSettingAccess::BROWSE_MODE);
1105 if(FN_PRINT_LAYOUT == nWhich)
1106 bState = !bState;
1107 rSet.Put( SfxBoolItem( nWhich, bState));
1109 break;
1111 case FN_NEW_GLOBAL_DOC:
1112 if ( ISA(SwGlobalDocShell) )
1113 rSet.DisableItem( nWhich );
1114 break;
1116 case FN_NEW_HTML_DOC:
1117 if( ISA( SwWebDocShell ) )
1118 rSet.DisableItem( nWhich );
1119 break;
1121 case SID_ATTR_YEAR2000:
1123 const SvNumberFormatter* pFmtr = pDoc->GetNumberFormatter(FALSE);
1124 rSet.Put( SfxUInt16Item( nWhich,
1125 static_cast< sal_uInt16 >(
1126 pFmtr ? pFmtr->GetYear2000()
1127 : SFX_APP()->GetMiscConfig()->GetYear2000() )));
1129 break;
1130 case SID_ATTR_CHAR_FONTLIST:
1132 rSet.Put( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
1134 break;
1136 default: DBG_ASSERT(!this,"Hier darfst Du nicht hinein!");
1139 nWhich = aIter.NextWhich();
1143 /*--------------------------------------------------------------------
1144 Beschreibung: OLE-Hdls
1145 --------------------------------------------------------------------*/
1148 IMPL_LINK( SwDocShell, Ole2ModifiedHdl, void *, p )
1150 // vom Doc wird der Status mitgegeben (siehe doc.cxx)
1151 // Bit 0: -> alter Zustand
1152 // Bit 1: -> neuer Zustand
1153 long nStatus = (long)p;
1154 if( IsEnableSetModified() )
1155 SetModified( (nStatus & 2) ? TRUE : FALSE );
1156 return 0;
1159 /*--------------------------------------------------------------------
1160 Beschreibung: Pool returnen Hier weil virtuelll
1161 --------------------------------------------------------------------*/
1164 SfxStyleSheetBasePool* SwDocShell::GetStyleSheetPool()
1166 return mxBasePool.get();
1170 void SwDocShell::SetView(SwView* pVw)
1172 if ( 0 != (pView = pVw) )
1173 pWrtShell = &pView->GetWrtShell();
1174 else
1175 pWrtShell = 0;
1179 void SwDocShell::PrepareReload()
1181 ::DelAllGrfCacheEntries( pDoc );
1184 // --> OD 2006-11-07 #i59688#
1185 // linked graphics are now loaded on demand.
1186 // Thus, loading of linked graphics no longer needed and necessary for
1187 // the load of document being finished.
1188 void SwDocShell::LoadingFinished()
1190 // --> OD 2007-10-08 #i38810#
1191 // Original fix fails after integration of cws xmlsec11:
1192 // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because
1193 // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and
1194 // enables the document modification again.
1195 // Thus, manuell modify the document, if its modified and its links are updated
1196 // before <FinishedLoading(..)> is called.
1197 const bool bHasDocToStayModified( pDoc->IsModified() && pDoc->LinksUpdated() );
1198 // // --> OD 2005-02-11 #i38810# - disable method <SetModified(..)>, if document
1199 // // has stay in modified state, due to the update of its links during load.
1200 // bool bResetEnableSetModified(false);
1201 // if ( IsEnableSetModified() &&
1202 // pDoc->IsModified() && pDoc->LinksUpdated() )
1203 // {
1204 // EnableSetModified( FALSE );
1205 // bResetEnableSetModified = true;
1206 // }
1207 // <--
1208 FinishedLoading( SFX_LOADED_ALL );
1209 // // --> OD 2005-02-11 #i38810#
1210 // if ( bResetEnableSetModified )
1211 // {
1212 // EnableSetModified( TRUE );
1213 // }
1214 // // <--
1215 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst(this);
1216 if(pVFrame)
1218 SfxViewShell* pShell = pVFrame->GetViewShell();
1219 if(PTR_CAST(SwSrcView, pShell))
1220 ((SwSrcView*)pShell)->Load(this);
1223 // --> OD 2007-10-08 #i38810#
1224 if ( bHasDocToStayModified && !pDoc->IsModified() )
1226 pDoc->SetModified();
1228 // <--
1231 // eine Uebertragung wird abgebrochen (wird aus dem SFX gerufen)
1232 void SwDocShell::CancelTransfers()
1234 // alle Links vom LinkManager Canceln
1235 aFinishedTimer.Stop();
1236 pDoc->GetLinkManager().CancelTransfers();
1237 SfxObjectShell::CancelTransfers();
1240 SwFEShell* SwDocShell::GetFEShell()
1242 return pWrtShell;
1245 void SwDocShell::RemoveOLEObjects()
1247 SwClientIter aIter( *(SwModify*)pDoc->GetDfltGrfFmtColl() );
1248 for( SwCntntNode* pNd = (SwCntntNode*)aIter.First( TYPE( SwCntntNode ) );
1249 pNd; pNd = (SwCntntNode*)aIter.Next() )
1251 SwOLENode* pOLENd = pNd->GetOLENode();
1252 if( pOLENd && ( pOLENd->IsOLEObjectDeleted() ||
1253 pOLENd->IsInGlobalDocSection() ) )
1255 if( !pOLEChildList )
1256 pOLEChildList = new comphelper::EmbeddedObjectContainer;
1258 ::rtl::OUString aObjName = pOLENd->GetOLEObj().GetCurrentPersistName();
1259 GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName, *pOLEChildList );
1264 // When a document is loaded, SwDoc::PrtOLENotify is called to update
1265 // the sizes of math objects. However, for objects that do not have a
1266 // SwFrm at this time, only a flag is set (bIsOLESizeInvalid) and the
1267 // size change takes place later, while calculating the layout in the
1268 // idle handler. If this document is saved now, it is saved with invalid
1269 // sizes. For this reason, the layout has to be calculated before a document is
1270 // saved, but of course only id there are OLE objects with bOLESizeInvalid set.
1271 void SwDocShell::CalcLayoutForOLEObjects()
1273 if( !pWrtShell )
1274 return;
1276 SwClientIter aIter( *(SwModify*)pDoc->GetDfltGrfFmtColl() );
1277 for( SwCntntNode* pNd = (SwCntntNode*)aIter.First( TYPE( SwCntntNode ) );
1278 pNd; pNd = (SwCntntNode*)aIter.Next() )
1280 SwOLENode* pOLENd = pNd->GetOLENode();
1281 if( pOLENd && pOLENd->IsOLESizeInvalid() )
1283 pWrtShell->CalcLayout();
1284 break;
1290 // --> FME 2005-02-25 #i42634# Overwrites SfxObjectShell::UpdateLinks
1291 // This new function is necessary to trigger update of links in docs
1292 // read by the binary filter:
1293 void SwDocShell::UpdateLinks()
1295 GetDoc()->UpdateLinks(TRUE);
1296 // --> FME 2005-07-27 #i50703# Update footnote numbers
1297 SwTxtFtn::SetUniqueSeqRefNo( *GetDoc() );
1298 SwNodeIndex aTmp( GetDoc()->GetNodes() );
1299 GetDoc()->GetFtnIdxs().UpdateFtn( aTmp );
1300 // <--
1303 uno::Reference< frame::XController >
1304 SwDocShell::GetController()
1306 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > aRet;
1307 // --> FME 2007-10-15 #i82346# No view in page preview
1308 if ( GetView() )
1309 // <--
1310 aRet = GetView()->GetController();
1311 return aRet;
1314 /* -----------------------------12.02.01 12:08--------------------------------
1316 ---------------------------------------------------------------------------*/
1317 static const char* pEventNames[] =
1319 "OnPageCountChange",
1320 "OnMailMerge",
1321 "OnMailMergeFinished",
1322 "OnFieldMerge",
1323 "OnFieldMergeFinished",
1324 "OnLayoutFinished"
1327 Sequence< OUString > SwDocShell::GetEventNames()
1329 Sequence< OUString > aRet = SfxObjectShell::GetEventNames();
1330 sal_Int32 nLen = aRet.getLength();
1331 aRet.realloc(nLen + 6);
1332 OUString* pNames = aRet.getArray();
1333 pNames[nLen++] = GetEventName(0);
1334 pNames[nLen++] = GetEventName(1);
1335 pNames[nLen++] = GetEventName(2);
1336 pNames[nLen++] = GetEventName(3);
1337 pNames[nLen++] = GetEventName(4);
1338 pNames[nLen] = GetEventName(5);
1340 return aRet;
1343 static sal_Int32 nEvents=13;
1345 rtl::OUString SwDocShell::GetEventName( sal_Int32 nIndex )
1347 if ( nIndex<nEvents )
1348 return ::rtl::OUString::createFromAscii(pEventNames[nIndex]);
1349 return rtl::OUString();
1352 const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const
1354 return pDoc ? &pDoc->GetXmlIdRegistry() : 0;