xref: /aoo41x/main/sw/source/ui/app/docsh.cxx (revision ad54a8fd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <hintids.hxx>
28 #include <rtl/logfile.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/wrkwin.hxx>
32 #include <vcl/jobset.hxx>
33 #include <tools/urlobj.hxx>
34 #include <svl/whiter.hxx>
35 #include <svl/zforlist.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/stritem.hxx>
38 #include <svl/PasswordHelper.hxx>
39 #include <editeng/adjitem.hxx>
40 #include <basic/sbx.hxx>
41 #include <unotools/moduleoptions.hxx>
42 #include <unotools/misccfg.hxx>
43 #include <sfx2/request.hxx>
44 #include <sfx2/passwd.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/docfile.hxx>
47 #include <sfx2/evntconf.hxx>
48 #include <sfx2/docfilt.hxx>
49 #include <sfx2/printer.hxx>
50 #include <sfx2/linkmgr.hxx>
51 #include <svl/srchitem.hxx>
52 #include <editeng/flstitem.hxx>
53 #include <svx/htmlmode.hxx>
54 #include <svtools/soerr.hxx>
55 #include <sot/clsids.hxx>
56 #include <basic/basmgr.hxx>
57 #include <basic/sbmod.hxx>
58 #include <swevent.hxx>
59 #include <fmtpdsc.hxx>
60 #include <fmtfsize.hxx>
61 #include <fmtfld.hxx>
62 #include <node.hxx>
63 #include <swwait.hxx>
64 #include <printdata.hxx>
65 #include <frmatr.hxx>
66 #include <view.hxx> 		// fuer die aktuelle Sicht
67 #include <edtwin.hxx>
68 #include <PostItMgr.hxx>
69 #include <wrtsh.hxx>		// Verbindung zur Core
70 #include <docsh.hxx>	  	// Dokumenterzeugung
71 #include <basesh.hxx>
72 #include <viewopt.hxx>
73 #include <wdocsh.hxx>
74 #include <swmodule.hxx>
75 #include <globdoc.hxx>
76 #include <usrpref.hxx>
77 #include <shellio.hxx> 		// I/O
78 #include <docstyle.hxx>
79 #include <doc.hxx>
80 #include <IDocumentUndoRedo.hxx>
81 #include <docstat.hxx>
82 #include <pagedesc.hxx>
83 #include <pview.hxx>
84 #include <mdiexp.hxx>
85 #include <swbaslnk.hxx>
86 #include <srcview.hxx>
87 #include <ndindex.hxx>
88 #include <ndole.hxx>
89 #include <swcli.hxx>
90 #include <txtftn.hxx>
91 #include <ftnidx.hxx>
92 #include <fldbas.hxx>
93 #include <docary.hxx>
94 #include <swerror.h>		// Fehlermeldungen
95 #include <helpid.h>
96 #include <cmdid.h>
97 #include <globals.hrc>
98 #include <app.hrc>
99 
100 #include <cfgid.h>
101 #include <unotools/moduleoptions.hxx>
102 #include <unotools/fltrcfg.hxx>
103 #include <svtools/htmlcfg.hxx>
104 #include <sfx2/fcontnr.hxx>
105 #include <sfx2/objface.hxx>
106 #include <comphelper/storagehelper.hxx>
107 
108 #define SwDocShell
109 #include <sfx2/msg.hxx>
110 #include <swslots.hxx>
111 #include <com/sun/star/document/UpdateDocMode.hpp>
112 
113 #include <com/sun/star/document/XDocumentProperties.hpp>
114 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
115 
116 #include <unomid.h>
117 
118 #include <sfx2/Metadatable.hxx>
119 #include <switerator.hxx>
120 
121 using rtl::OUString;
122 using namespace ::com::sun::star;
123 using namespace ::com::sun::star::uno;
124 using namespace ::com::sun::star::script;
125 using namespace ::com::sun::star::container;
126 
127 
128 SFX_IMPL_INTERFACE( SwDocShell, SfxObjectShell, SW_RES(0) )
129 {
130 	SFX_CHILDWINDOW_REGISTRATION( SID_HYPERLINK_INSERT );
131 }
132 
133 TYPEINIT2(SwDocShell, SfxObjectShell, SfxListener);
134 
135 //-------------------------------------------------------------------------
136 SFX_IMPL_OBJECTFACTORY(SwDocShell, SvGlobalName(SO3_SW_CLASSID), SFXOBJECTSHELL_STD_NORMAL|SFXOBJECTSHELL_HASMENU, "swriter"  )
137 
138 /*--------------------------------------------------------------------
139 	Beschreibung: Laden vorbereiten
140  --------------------------------------------------------------------*/
141 
142 
143 Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
144 									SwCrsrShell *pCrsrShell,
145 									SwPaM* pPaM )
146 {
147 	sal_Bool bAPICall = sal_False;
148 	const SfxPoolItem* pApiItem;
149 	const SfxItemSet* pMedSet;
150 	if( 0 != ( pMedSet = rMedium.GetItemSet() ) && SFX_ITEM_SET ==
151 			pMedSet->GetItemState( FN_API_CALL, sal_True, &pApiItem ) )
152 			bAPICall = ((const SfxBoolItem*)pApiItem)->GetValue();
153 
154 	const SfxFilter* pFlt = rMedium.GetFilter();
155 	if( !pFlt )
156 	{
157 		if(!bAPICall)
158 		{
159 			InfoBox( 0, SW_RESSTR(STR_CANTOPEN)).Execute();
160 		}
161 		return 0;
162 	}
163 	String aFileName( rMedium.GetName() );
164 	SwRead pRead = SwReaderWriter::GetReader( pFlt->GetUserData() );
165 	if( !pRead )
166 		return 0;
167 
168 	if( rMedium.IsStorage()
169 		? SW_STORAGE_READER & pRead->GetReaderType()
170 		: SW_STREAM_READER & pRead->GetReaderType() )
171 	{
172 		*ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) :
173 			pCrsrShell ?
174 				new SwReader( rMedium, aFileName, *pCrsrShell->GetCrsr() )
175 					: new SwReader( rMedium, aFileName, pDoc );
176 	}
177 	else
178 		return 0;
179 
180 	// PassWord Checken
181 	String aPasswd;
182 	if ((*ppRdr)->NeedsPasswd( *pRead ))
183 	{
184 		if(!bAPICall)
185 		{
186 			SfxPasswordDialog* pPasswdDlg =
187 					new SfxPasswordDialog( 0 );
188 				if(RET_OK == pPasswdDlg->Execute())
189 					aPasswd = pPasswdDlg->GetPassword();
190 		}
191 		else
192 		{
193 			const SfxItemSet* pSet = rMedium.GetItemSet();
194 			const SfxPoolItem *pPassItem;
195 			if(pSet && SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pPassItem))
196 				aPasswd = ((const SfxStringItem *)pPassItem)->GetValue();
197 		}
198 
199 		if (!(*ppRdr)->CheckPasswd( aPasswd, *pRead ))
200 		{
201 			InfoBox( 0, SW_RES(MSG_ERROR_PASSWD)).Execute();
202 				delete *ppRdr;
203 			return 0;
204 		}
205 	}
206 
207     // #i30171# set the UpdateDocMode at the SwDocShell
208     SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
209     nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
210 
211 	if( pFlt->GetDefaultTemplate().Len() )
212 		pRead->SetTemplateName( pFlt->GetDefaultTemplate() );
213 
214 	if( pRead == ReadAscii && 0 != rMedium.GetInStream() &&
215 		pFlt->GetUserData().EqualsAscii( FILTER_TEXT_DLG ) )
216 	{
217 		SwAsciiOptions aOpt;
218 		const SfxItemSet* pSet;
219 		const SfxPoolItem* pItem;
220 		if( 0 != ( pSet = rMedium.GetItemSet() ) && SFX_ITEM_SET ==
221 			pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
222 			aOpt.ReadUserData( ((const SfxStringItem*)pItem)->GetValue() );
223 
224 		if( pRead )
225 			pRead->GetReaderOpt().SetASCIIOpts( aOpt );
226 	}
227 
228 	return pRead;
229 }
230 
231 /*--------------------------------------------------------------------
232 	Beschreibung: Laden
233  --------------------------------------------------------------------*/
234 
235 sal_Bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
236 {
237 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::ConvertFrom" );
238 
239 	SwReader* pRdr;
240 	SwRead pRead = StartConvertFrom(rMedium, &pRdr);
241 	if (!pRead)
242 	  return sal_False; // #129881# return if no reader is found
243 	SotStorageRef pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
244 
245 	SwWait aWait( *this, sal_True );
246 
247 		// SfxProgress unterdruecken, wenn man Embedded ist
248 	SW_MOD()->SetEmbeddedLoadSave(
249 							SFX_CREATE_MODE_EMBEDDED == GetCreateMode() );
250 
251 	pRdr->GetDoc()->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell));
252 
253     /* #106748# Restore the pool default if reading a saved document. */
254     pDoc->RemoveAllFmtLanguageDependencies();
255 
256 	sal_uLong nErr = pRdr->Read( *pRead );
257 
258 	// Evtl. ein altes Doc weg
259 	if ( pDoc != pRdr->GetDoc() )
260 	{
261 		if( pDoc )
262 			RemoveLink();
263 		pDoc = pRdr->GetDoc();
264 
265         AddLink();
266 
267         if ( !mxBasePool.is() )
268 			mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
269     }
270 
271     UpdateFontList();
272 	InitDraw();
273 
274 	delete pRdr;
275 
276 	SW_MOD()->SetEmbeddedLoadSave( sal_False );
277 
278 	SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
279 	sal_Bool bOk = !IsError( nErr );
280 
281     // --> OD 2006-11-07 #i59688#
282 //    // StartFinishedLoading rufen. Nicht bei asynchronen Filtern!
283 //    // Diese muessen das selbst rufen!
284 //    if( bOk && !pDoc->IsInLoadAsynchron() )
285 //        StartLoadFinishedTimer();
286     if ( bOk && !pDoc->IsInLoadAsynchron() )
287     {
288         LoadingFinished();
289     }
290     // <--
291 
292 	pRead->setSotStorageRef(pStg); // #i45333# save sot storage ref in case of recursive calls
293 
294 	return bOk;
295 }
296 
297 /*--------------------------------------------------------------------
298 	Beschreibung: Sichern des Default-Formats, Stg vorhanden
299  --------------------------------------------------------------------*/
300 
301 
302 sal_Bool SwDocShell::Save()
303 {
304 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Save" );
305     //#i3370# remove quick help to prevent saving of autocorrection suggestions
306     if(pView)
307         pView->GetEditWin().StopQuickHelp();
308     SwWait aWait( *this, sal_True );
309 
310 	CalcLayoutForOLEObjects();	// format for OLE objets
311     // --> OD 2006-03-17 #i62875#
312     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
313     if ( pWrtShell && pDoc &&
314          pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
315          docfunc::AllDrawObjsOnPage( *pDoc ) )
316     {
317         pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
318     }
319     // <--
320 
321 	sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE;
322     if( SfxObjectShell::Save() )
323 	{
324 		switch( GetCreateMode() )
325 		{
326 		case SFX_CREATE_MODE_INTERNAL:
327 			nErr = 0;
328 			break;
329 
330 		case SFX_CREATE_MODE_ORGANIZER:
331 			{
332 				WriterRef xWrt;
333                 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt );
334 				xWrt->SetOrganizerMode( sal_True );
335                 SwWriter aWrt( *GetMedium(), *pDoc );
336 				nErr = aWrt.Write( xWrt );
337 				xWrt->SetOrganizerMode( sal_False );
338 			}
339 			break;
340 
341 		case SFX_CREATE_MODE_EMBEDDED:
342 			// SfxProgress unterdruecken, wenn man Embedded ist
343 			SW_MOD()->SetEmbeddedLoadSave( sal_True );
344 			// kein break;
345 
346 		case SFX_CREATE_MODE_STANDARD:
347 		case SFX_CREATE_MODE_PREVIEW:
348 		default:
349 			{
350 				if( pDoc->ContainsMSVBasic() )
351 				{
352                     //TODO/MBA: it looks as that this code can be removed!
353                     //SvxImportMSVBasic aTmp( *this, pIo->GetStorage() );
354                     //aTmp.SaveOrDelMSVBAStorage( sal_False, aEmptyStr );
355 					if( SvtFilterOptions::Get()->IsLoadWordBasicStorage() )
356 						nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) (*this) );
357 					pDoc->SetContainsMSVBasic( sal_False );
358                 }
359 
360 				// TabellenBox Edit beenden!
361 				if( pWrtShell )
362 					pWrtShell->EndAllTblBoxEdit();
363 
364 				WriterRef xWrt;
365                 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt );
366 
367                 sal_Bool bLockedView(sal_False);
368                 if ( pWrtShell )
369                 {
370                     bLockedView = pWrtShell->IsViewLocked();
371                     pWrtShell->LockView( sal_True );    //lock visible section
372                 }
373 
374                 SwWriter aWrt( *GetMedium(), *pDoc );
375 				nErr = aWrt.Write( xWrt );
376 
377                 if ( pWrtShell )
378                     pWrtShell->LockView( bLockedView );
379 			}
380 			break;
381 		}
382 		SW_MOD()->SetEmbeddedLoadSave( sal_False );
383 	}
384 	SetError( nErr ? nErr : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
385 
386 	SfxViewFrame* pFrm = pWrtShell ? pWrtShell->GetView().GetViewFrame() : 0;
387 	if( pFrm )
388 	{
389 		pFrm->GetBindings().SetState( SfxStringItem( SID_DOC_MODIFIED, ' ' ));
390 	}
391 	return !IsError( nErr );
392 }
393 
394 /*--------------------------------------------------------------------
395 	Beschreibung: Sichern im Defaultformat
396  --------------------------------------------------------------------*/
397 
398 
399 sal_Bool SwDocShell::SaveAs( SfxMedium& rMedium )
400 {
401 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SaveAs" );
402 
403 	SwWait aWait( *this, sal_True );
404     //#i3370# remove quick help to prevent saving of autocorrection suggestions
405     if(pView)
406         pView->GetEditWin().StopQuickHelp();
407 
408 	//#i91811# mod if we have an active margin window, write back the text
409     if ( pView &&
410          pView->GetPostItMgr() &&
411          pView->GetPostItMgr()->HasActiveSidebarWin() )
412     {
413         pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
414     }
415 
416 	if( pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) &&
417         !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS) )
418 		RemoveOLEObjects();
419 
420 	{
421 		// Task 75666 - is the Document imported by our Microsoft-Filters?
422 		const SfxFilter* pOldFilter = GetMedium()->GetFilter();
423 		if( pOldFilter &&
424 			( pOldFilter->GetUserData().EqualsAscii( FILTER_WW8 ) ||
425 			  pOldFilter->GetUserData().EqualsAscii( "CWW6" ) ||
426 			  pOldFilter->GetUserData().EqualsAscii( "WW6" ) ||
427 			  pOldFilter->GetUserData().EqualsAscii( "WW1" ) ))
428 		{
429 			// when saving it in our own fileformat, then remove the template
430 			// name from the docinfo.
431             uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
432                 GetModel(), uno::UNO_QUERY_THROW);
433             uno::Reference<document::XDocumentProperties> xDocProps
434                 = xDPS->getDocumentProperties();
435             xDocProps->setTemplateName(::rtl::OUString::createFromAscii(""));
436             xDocProps->setTemplateURL(::rtl::OUString::createFromAscii(""));
437             xDocProps->setTemplateDate(::util::DateTime());
438 		}
439 	}
440 
441 	CalcLayoutForOLEObjects();	// format for OLE objets
442     // --> OD 2006-03-17 #i62875#
443     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
444     if ( pWrtShell && pDoc &&
445          pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
446          docfunc::AllDrawObjsOnPage( *pDoc ) )
447     {
448         pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
449     }
450     // <--
451 
452 	sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE;
453     uno::Reference < embed::XStorage > xStor = rMedium.GetOutputStorage();
454     if( SfxObjectShell::SaveAs( rMedium ) )
455 	{
456 		if( GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && !ISA( SwGlobalDocShell ) )
457 		{
458 			// This is to set the correct class id if SaveAs is
459 			// called from SwDoc::SplitDoc to save a normal doc as
460 			// global doc. In this case, SaveAs is called at a
461 			// normal doc shell, therefore, SfxInplaceObject::SaveAs
462 			// will set the wrong class id.
463 			SvGlobalName aClassName;
464 			String aAppName, aLongUserName, aUserName;
465 
466             // The document is closed explicitly, but using SfxObjectShellLock is still more correct here
467 			SfxObjectShellLock xDocSh =
468 				new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL );
469 			// the global document can not be a template
470             xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), sal_False );
471             xDocSh->DoClose();
472 		}
473 
474         if( pDoc->ContainsMSVBasic() )
475         {
476             //TODO/MBA: it looks as that this code can be removed!
477             //SvxImportMSVBasic aTmp( *this, pIo->GetStorage() );
478             //aTmp.SaveOrDelMSVBAStorage( sal_False, aEmptyStr );
479             if( SvtFilterOptions::Get()->IsLoadWordBasicStorage() )
480                 nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) *this );
481             pDoc->SetContainsMSVBasic( sal_False );
482         }
483 
484 		// TabellenBox Edit beenden!
485 		if( pWrtShell )
486 			pWrtShell->EndAllTblBoxEdit();
487 
488 		// Modified-Flag merken und erhalten ohne den Link zu Callen
489 		// (fuer OLE; nach Anweisung von MM)
490 		sal_Bool bIsModified = pDoc->IsModified();
491         pDoc->GetIDocumentUndoRedo().LockUndoNoModifiedPosition();
492 		Link aOldOLELnk( pDoc->GetOle2Link() );
493 		pDoc->SetOle2Link( Link() );
494 
495 			// SfxProgress unterdruecken, wenn man Embedded ist
496 		SW_MOD()->SetEmbeddedLoadSave(
497 							SFX_CREATE_MODE_EMBEDDED == GetCreateMode() );
498 
499 		WriterRef xWrt;
500         ::GetXMLWriter( aEmptyStr, rMedium.GetBaseURL( true ), xWrt );
501 
502         sal_Bool bLockedView(sal_False);
503         if ( pWrtShell )
504         {
505             bLockedView = pWrtShell->IsViewLocked();
506             pWrtShell->LockView( sal_True );    //lock visible section
507         }
508 
509         SwWriter aWrt( rMedium, *pDoc );
510 		nErr = aWrt.Write( xWrt );
511 
512         if ( pWrtShell )
513             pWrtShell->LockView( bLockedView );
514 
515 		if( bIsModified )
516         {
517 			pDoc->SetModified();
518             pDoc->GetIDocumentUndoRedo().UnLockUndoNoModifiedPosition();
519         }
520 		pDoc->SetOle2Link( aOldOLELnk );
521 
522 		SW_MOD()->SetEmbeddedLoadSave( sal_False );
523 	}
524 	SetError( nErr ? nErr : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
525 
526 	return !IsError( nErr );
527 }
528 
529 /*--------------------------------------------------------------------
530 	Beschreibung: Sichern aller Formate
531  --------------------------------------------------------------------*/
532 SwSrcView* lcl_GetSourceView( SwDocShell* pSh )
533 {
534 	// sind wir in der SourceView?
535 	SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( pSh );
536 	SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
537 	return PTR_CAST( SwSrcView, pViewShell);
538 }
539 
540 sal_Bool SwDocShell::ConvertTo( SfxMedium& rMedium )
541 {
542 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::ConvertTo" );
543 	const SfxFilter* pFlt = rMedium.GetFilter();
544 	if( !pFlt )
545 		return sal_False;
546 
547 	WriterRef xWriter;
548 	SwReaderWriter::GetWriter( pFlt->GetUserData(), rMedium.GetBaseURL( true ), xWriter );
549 	if( !xWriter.Is() )
550 	{ 	// Der Filter ist nicht vorhanden
551 		InfoBox( 0,
552 				 SW_RESSTR(STR_DLLNOTFOUND) ).Execute();
553 		return sal_False;
554 	}
555 
556     //#i3370# remove quick help to prevent saving of autocorrection suggestions
557     if(pView)
558         pView->GetEditWin().StopQuickHelp();
559 
560 	//#i91811# mod if we have an active margin window, write back the text
561     if ( pView &&
562          pView->GetPostItMgr() &&
563          pView->GetPostItMgr()->HasActiveSidebarWin() )
564     {
565         pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
566     }
567 
568     sal_uLong nVBWarning = 0;
569 
570     if( pDoc->ContainsMSVBasic() )
571 	{
572 		sal_Bool bSave = pFlt->GetUserData().EqualsAscii( "CWW8" )
573 			 && SvtFilterOptions::Get()->IsLoadWordBasicStorage();
574 
575         if ( bSave )
576         {
577             SvStorageRef xStg = new SotStorage( rMedium.GetOutStream(), sal_False );
578             DBG_ASSERT( !xStg->GetError(), "No storage available for storing VBA macros!" );
579             if ( !xStg->GetError() )
580             {
581                 nVBWarning = SaveOrDelMSVBAStorage( (SfxObjectShell&) *this, *xStg, bSave, String::CreateFromAscii("Macros") );
582                 xStg->Commit();
583                 pDoc->SetContainsMSVBasic( sal_True );
584             }
585         }
586     }
587 
588 	// TabellenBox Edit beenden!
589 	if( pWrtShell )
590 		pWrtShell->EndAllTblBoxEdit();
591 
592 	if( pFlt->GetUserData().EqualsAscii( "HTML") )
593 	{
594 		SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
595         if( !pHtmlOpt->IsStarBasic() && pHtmlOpt->IsStarBasicWarning() && HasBasic() )
596 		{
597             uno::Reference< XLibraryContainer > xLibCont(GetBasicContainer(), UNO_QUERY);
598             uno::Reference< XNameAccess > xLib;
599             Sequence<rtl::OUString> aNames = xLibCont->getElementNames();
600             const rtl::OUString* pNames = aNames.getConstArray();
601             for(sal_Int32 nLib = 0; nLib < aNames.getLength(); nLib++)
602             {
603                 Any aLib = xLibCont->getByName(pNames[nLib]);
604                 aLib >>= xLib;
605                 if(xLib.is())
606                 {
607                     Sequence<rtl::OUString> aModNames = xLib->getElementNames();
608                     if(aModNames.getLength())
609                     {
610                         SetError(WARN_SWG_HTML_NO_MACROS, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
611                         break;
612                     }
613                 }
614             }
615         }
616 		UpdateDocInfoForSave();
617 	}
618 
619     // --> FME 2007-5-7 #i76360# Update document statistics
620     SwDocStat aDocStat( pDoc->GetDocStat() );;
621     pDoc->UpdateDocStat( aDocStat );
622     // <--
623 	CalcLayoutForOLEObjects();	// format for OLE objets
624     // --> OD 2006-03-17 #i62875#
625     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
626     if ( pWrtShell && pDoc &&
627          pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
628          docfunc::AllDrawObjsOnPage( *pDoc ) )
629     {
630         pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
631     }
632     // <--
633 
634 	if( xWriter->IsStgWriter() &&
635         ( /*xWriter->IsSw3Writer() ||*/
636 		  pFlt->GetUserData().EqualsAscii( FILTER_XML ) ||
637 	 	  pFlt->GetUserData().EqualsAscii( FILTER_XMLV ) ||
638 	 	  pFlt->GetUserData().EqualsAscii( FILTER_XMLVW ) ) )
639 	{
640 		// eigenen Typ ermitteln
641 		sal_uInt8 nMyType = 0;
642 		if( ISA( SwWebDocShell) )
643 			nMyType = 1;
644 		else if( ISA( SwGlobalDocShell) )
645 			nMyType = 2;
646 
647 		// gewuenschten Typ ermitteln
648 		sal_uInt8 nSaveType = 0;
649 		sal_uLong nSaveClipId = pFlt->GetFormat();
650 		if( SOT_FORMATSTR_ID_STARWRITERWEB_8 == nSaveClipId ||
651 			SOT_FORMATSTR_ID_STARWRITERWEB_60 == nSaveClipId ||
652 			SOT_FORMATSTR_ID_STARWRITERWEB_50 == nSaveClipId ||
653 			SOT_FORMATSTR_ID_STARWRITERWEB_40 == nSaveClipId )
654 			nSaveType = 1;
655 		else if( SOT_FORMATSTR_ID_STARWRITERGLOB_8 == nSaveClipId ||
656 				 SOT_FORMATSTR_ID_STARWRITERGLOB_60 == nSaveClipId ||
657 				 SOT_FORMATSTR_ID_STARWRITERGLOB_50 == nSaveClipId ||
658 				 SOT_FORMATSTR_ID_STARWRITERGLOB_40 == nSaveClipId )
659 			nSaveType = 2;
660 
661 		// Flags am Dokument entsprechend umsetzen
662 		sal_Bool bIsHTMLModeSave = GetDoc()->get(IDocumentSettingAccess::HTML_MODE);
663 		sal_Bool bIsGlobalDocSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT);
664 		sal_Bool bIsGlblDocSaveLinksSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
665 		if( nMyType != nSaveType )
666 		{
667 			GetDoc()->set(IDocumentSettingAccess::HTML_MODE, 1 == nSaveType);
668 			GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, 2 == nSaveType);
669 			if( 2 != nSaveType )
670 				GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
671 		}
672 
673 		// if the target format is storage based, then the output storage must be already created
674         if ( rMedium.IsStorage() )
675         {
676             // set MediaType on target storage
677             // (MediaType will be queried during SaveAs)
678             try
679             {
680                 // TODO/MBA: testing
681                 uno::Reference < beans::XPropertySet > xSet( rMedium.GetStorage(), uno::UNO_QUERY );
682                 if ( xSet.is() )
683                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("MediaType"), uno::makeAny( ::rtl::OUString( SotExchange::GetFormatMimeType( nSaveClipId ) ) ) );
684             }
685             catch ( uno::Exception& )
686             {
687             }
688         }
689 
690 		// Jetzt das Dokument normal speichern
691         sal_Bool bRet = SaveAs( rMedium );
692 
693 		if( nMyType != nSaveType )
694 		{
695 			GetDoc()->set(IDocumentSettingAccess::HTML_MODE, bIsHTMLModeSave );
696 			GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, bIsGlobalDocSave);
697 			GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bIsGlblDocSaveLinksSave);
698 		}
699 
700 		return bRet;
701 	}
702 
703 	if( pFlt->GetUserData().EqualsAscii( FILTER_TEXT_DLG ) &&
704 		( pWrtShell || !::lcl_GetSourceView( this ) ))
705 	{
706 		SwAsciiOptions aOpt;
707 		String sItemOpt;
708 		const SfxItemSet* pSet;
709 		const SfxPoolItem* pItem;
710 		if( 0 != ( pSet = rMedium.GetItemSet() ) )
711 		{
712 			if( SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS,
713 													sal_True, &pItem ) )
714 				sItemOpt = ((const SfxStringItem*)pItem)->GetValue();
715 		}
716         if(sItemOpt.Len())
717             aOpt.ReadUserData( sItemOpt );
718 
719 		xWriter->SetAsciiOptions( aOpt );
720 	}
721 
722 		// SfxProgress unterdruecken, wenn man Embedded ist
723 	SW_MOD()->SetEmbeddedLoadSave(
724 							SFX_CREATE_MODE_EMBEDDED == GetCreateMode());
725 
726 	// Kontext aufspannen, um die Anzeige der Selektion zu unterbinden
727 	sal_uLong nErrno;
728 	String aFileName( rMedium.GetName() );
729 
730 	//Keine View also das ganze Dokument!
731 	if ( pWrtShell )
732 	{
733 		SwWait aWait( *this, sal_True );
734         // --> OD 2009-12-31 #i106906#
735         const sal_Bool bFormerLockView = pWrtShell->IsViewLocked();
736         pWrtShell->LockView( sal_True );
737         // <--
738 		pWrtShell->StartAllAction();
739 		pWrtShell->Push();
740 		SwWriter aWrt( rMedium, *pWrtShell, sal_True );
741         nErrno = aWrt.Write( xWriter, &aFileName );
742 		//JP 16.05.97: falls der SFX uns die View waehrend des speicherns
743 		//				entzieht
744 		if( pWrtShell )
745 		{
746 			pWrtShell->Pop(sal_False);
747 			pWrtShell->EndAllAction();
748             // --> OD 2009-12-31 #i106906#
749             pWrtShell->LockView( bFormerLockView );
750             // <--
751 		}
752 	}
753 	else
754 	{
755 		// sind wir in der SourceView?
756 		SwSrcView* pSrcView = ::lcl_GetSourceView( this );
757 		if( pSrcView )
758 		{
759 			pSrcView->SaveContentTo(rMedium);
760 			nErrno = 0;
761 		}
762 		else
763 		{
764 			SwWriter aWrt( rMedium, *pDoc );
765 			nErrno = aWrt.Write( xWriter, &aFileName );
766 		}
767 	}
768 
769 	SW_MOD()->SetEmbeddedLoadSave( sal_False );
770 	SetError( nErrno ? nErrno : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
771 	if( !rMedium.IsStorage() )
772 		rMedium.CloseOutStream();
773 
774 	return !IsError( nErrno );
775 }
776 
777 /*--------------------------------------------------------------------
778 	Beschreibung:	Haende weg
779  --------------------------------------------------------------------*/
780 
781 
782 /*--------------------------------------------------------------------
783 	Beschreibung: ??? noch nicht zu aktivieren, muss sal_True liefern
784  --------------------------------------------------------------------*/
785 
786 
787 sal_Bool SwDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor  )
788 {
789 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SaveCompleted" );
790     sal_Bool bRet = SfxObjectShell::SaveCompleted( xStor );
791 	if( bRet )
792 	{
793 		// erst hier entscheiden, ob das Speichern geklappt hat oder nicht
794 		if( IsModified() )
795 			pDoc->SetModified();
796 		else
797 			pDoc->ResetModified();
798 	}
799 
800     if( pOLEChildList )
801 	{
802 		sal_Bool bResetModified = IsEnableSetModified();
803 		if( bResetModified )
804 			EnableSetModified( sal_False );
805 
806         uno::Sequence < rtl::OUString > aNames = pOLEChildList->GetObjectNames();
807         for( sal_Int32 n = aNames.getLength(); n; n-- )
808 		{
809             if ( !pOLEChildList->MoveEmbeddedObject( aNames[n-1], GetEmbeddedObjectContainer() ) )
810             {
811                 DBG_ERROR( "Copying of objects didn't work!" );
812             }
813 
814             //SvPersist* pPersist = this;
815             //SvInfoObjectRef aRef( pInfList->GetObject( --n ));
816             //pPersist->Move( &aRef, aRef->GetStorageName() );
817 		}
818 
819         DELETEZ( pOLEChildList );
820 		if( bResetModified )
821 			EnableSetModified( sal_True );
822     }
823 	return bRet;
824 }
825 
826 /*--------------------------------------------------------------------
827 	Beschreibung: Draw()-Overload fuer OLE2 (Sfx)
828  --------------------------------------------------------------------*/
829 
830 void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& rSetup,
831 							   sal_uInt16 nAspect )
832 {
833 	//fix #25341# Draw sollte das Modified nicht beeinflussen
834 	sal_Bool bResetModified;
835 	if ( sal_True == (bResetModified = IsEnableSetModified()) )
836 		EnableSetModified( sal_False );
837 
838 	//sollte am Document ein JobSetup haengen, dann kopieren wir uns diesen,
839 	//um nach dem PrtOle2 diesen wieder am Doc zu verankern.
840 	//Einen leeren JobSetup setzen wir nicht ein, denn der wuerde nur zu
841 	//fragwuerdigem Ergebnis nach teurer Neuformatierung fuehren (Preview!)
842 	JobSetup *pOrig = 0;
843 	if ( rSetup.GetPrinterName().Len() && ASPECT_THUMBNAIL != nAspect )
844 	{
845         pOrig = const_cast<JobSetup*>(pDoc->getJobsetup());
846 		if( pOrig )			// dann kopieren wir uns den
847 			pOrig = new JobSetup( *pOrig );
848         pDoc->setJobsetup( rSetup );
849 	}
850 
851 	Rectangle aRect( nAspect == ASPECT_THUMBNAIL ?
852             GetVisArea( nAspect ) : GetVisArea( ASPECT_CONTENT ) );
853 
854 	pDev->Push();
855 	pDev->SetFillColor();
856 	pDev->SetLineColor();
857 	pDev->SetBackground();
858 	sal_Bool bWeb = 0 != PTR_CAST(SwWebDocShell, this);
859     SwPrintData aOpts;
860     ViewShell::PrtOle2( pDoc, SW_MOD()->GetUsrPref(bWeb), aOpts, pDev, aRect );
861 	pDev->Pop();
862 
863 	if( pOrig )
864 	{
865         pDoc->setJobsetup( *pOrig );
866 		delete pOrig;
867 	}
868 	if ( bResetModified )
869 		EnableSetModified( sal_True );
870 }
871 
872 
873 void SwDocShell::SetVisArea( const Rectangle &rRect )
874 {
875 	Rectangle aRect( rRect );
876 	if ( pView )
877 	{
878 		Size aSz( pView->GetDocSz() );
879 		aSz.Width() += DOCUMENTBORDER; aSz.Height() += DOCUMENTBORDER;
880 		long nMoveX = 0, nMoveY = 0;
881 		if ( aRect.Right() > aSz.Width() )
882 			nMoveX = aSz.Width() - aRect.Right();
883 		if ( aRect.Bottom() > aSz.Height() )
884 			nMoveY = aSz.Height() - aRect.Bottom();
885 		aRect.Move( nMoveX, nMoveY );
886 		nMoveX = aRect.Left() < 0 ? -aRect.Left() : 0;
887 		nMoveY = aRect.Top()  < 0 ? -aRect.Top()  : 0;
888 		aRect.Move( nMoveX, nMoveY );
889 
890 		//Ruft das SfxInPlaceObject::SetVisArea()!
891 		pView->SetVisArea( aRect, sal_True );
892 	}
893 	else
894         SfxObjectShell::SetVisArea( aRect );
895 }
896 
897 
898 Rectangle SwDocShell::GetVisArea( sal_uInt16 nAspect ) const
899 {
900 	if ( nAspect == ASPECT_THUMBNAIL )
901 	{
902 		//PreView: VisArea auf die erste Seite einstellen.
903     	SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 1 );
904 		SwCntntNode* pNd = pDoc->GetNodes().GoNext( &aIdx );
905 
906         const SwRect aPageRect = pNd->FindPageFrmRect( sal_False, 0, sal_False );
907         return aPageRect.SVRect();
908 	}
909     return SfxObjectShell::GetVisArea( nAspect );
910 }
911 
912 Printer *SwDocShell::GetDocumentPrinter()
913 {
914     return pDoc->getPrinter( false );
915 }
916 
917 OutputDevice* SwDocShell::GetDocumentRefDev()
918 {
919     return pDoc->getReferenceDevice( false );
920 }
921 
922 void SwDocShell::OnDocumentPrinterChanged( Printer * pNewPrinter )
923 {
924 	if ( pNewPrinter )
925         GetDoc()->setJobsetup( pNewPrinter->GetJobSetup() );
926 	else
927         GetDoc()->setPrinter( 0, true, true );
928 }
929 
930 sal_uLong SwDocShell::GetMiscStatus() const
931 {
932     return SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE;
933 }
934 
935 // --> FME 2004-08-05 #i20883# Digital Signatures and Encryption
936 sal_uInt16 SwDocShell::GetHiddenInformationState( sal_uInt16 nStates )
937 {
938 	// get global state like HIDDENINFORMATION_DOCUMENTVERSIONS
939     sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates );
940 
941     if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES )
942     {
943         if ( GetDoc()->GetRedlineTbl().Count() )
944             nState |= HIDDENINFORMATION_RECORDEDCHANGES;
945     }
946     if ( nStates & HIDDENINFORMATION_NOTES )
947     {
948         ASSERT( GetWrtShell(), "No SwWrtShell, no information" )
949         if ( GetWrtShell() )
950         {
951             SwFieldType* pType = GetWrtShell()->GetFldType( RES_POSTITFLD, aEmptyStr );
952             SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
953             SwFmtFld* pFirst = aIter.First();
954             while( pFirst )
955             {
956                 if( pFirst->GetTxtFld() && pFirst->IsFldInDoc() )
957                 {
958                     nState |= HIDDENINFORMATION_NOTES;
959                     break;
960                 }
961                 pFirst = aIter.Next();
962             }
963         }
964     }
965 
966     return nState;
967 }
968 // <--
969 
970 
971 /*--------------------------------------------------------------------
972 	Beschreibung:
973  --------------------------------------------------------------------*/
974 
975 
976 void SwDocShell::GetState(SfxItemSet& rSet)
977 {
978 	SfxWhichIter aIter(rSet);
979 	sal_uInt16 	nWhich 	= aIter.FirstWhich();
980 
981 	while (nWhich)
982 	{
983 		switch (nWhich)
984 		{
985 		case SID_PRINTPREVIEW:
986 		{
987 			sal_Bool bDisable = IsInPlaceActive();
988             // Disable "multiple layout"
989 			if ( !bDisable )
990 			{
991 				SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this);
992 				while (pTmpFrm)		// Preview suchen
993 				{
994 					if ( PTR_CAST(SwView, pTmpFrm->GetViewShell()) &&
995                          ((SwView*)pTmpFrm->GetViewShell())->GetWrtShell().GetViewOptions()->getBrowseMode() )
996 					{
997 						bDisable = sal_True;
998 						break;
999 					}
1000 					pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this);
1001 				}
1002 			}
1003             // End of disabled "multiple layout"
1004 			if ( bDisable )
1005 				rSet.DisableItem( SID_PRINTPREVIEW );
1006 			else
1007 			{
1008 				SfxBoolItem aBool( SID_PRINTPREVIEW, sal_False );
1009 				if( PTR_CAST( SwPagePreView, SfxViewShell::Current()) )
1010 					aBool.SetValue( sal_True );
1011 				rSet.Put( aBool );
1012 			}
1013 		}
1014 		break;
1015 		case SID_SOURCEVIEW:
1016 		{
1017             SfxViewShell* pCurrView = GetView() ? (SfxViewShell*)GetView()
1018 										: SfxViewShell::Current();
1019             sal_Bool bSourceView = 0 != PTR_CAST(SwSrcView, pCurrView);
1020 			rSet.Put(SfxBoolItem(SID_SOURCEVIEW, bSourceView));
1021 		}
1022 		break;
1023 		case SID_HTML_MODE:
1024 			rSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
1025 		break;
1026 
1027 		case FN_ABSTRACT_STARIMPRESS:
1028 		case FN_OUTLINE_TO_IMPRESS:
1029 			{
1030 				SvtModuleOptions aMOpt;
1031 				if ( !aMOpt.IsImpress() )
1032 					rSet.DisableItem( nWhich );
1033 			}
1034 			/* no break here */
1035 		case FN_ABSTRACT_NEWDOC:
1036 		case FN_OUTLINE_TO_CLIPBOARD:
1037 			{
1038 				if ( !GetDoc()->GetNodes().GetOutLineNds().Count() )
1039 					rSet.DisableItem( nWhich );
1040 			}
1041 			break;
1042         case SID_BROWSER_MODE:
1043         case FN_PRINT_LAYOUT:
1044 			{
1045                 sal_Bool bState = GetDoc()->get(IDocumentSettingAccess::BROWSE_MODE);
1046                 if(FN_PRINT_LAYOUT == nWhich)
1047                     bState = !bState;
1048                 rSet.Put( SfxBoolItem( nWhich, bState));
1049 			}
1050 			break;
1051 
1052 		case FN_NEW_GLOBAL_DOC:
1053 			if ( ISA(SwGlobalDocShell) )
1054 				rSet.DisableItem( nWhich );
1055 			break;
1056 
1057 		case FN_NEW_HTML_DOC:
1058 			if( ISA( SwWebDocShell ) )
1059 				rSet.DisableItem( nWhich );
1060 			break;
1061 
1062 		case SID_ATTR_YEAR2000:
1063 			{
1064 				const SvNumberFormatter* pFmtr = pDoc->GetNumberFormatter(sal_False);
1065 				rSet.Put( SfxUInt16Item( nWhich,
1066                         static_cast< sal_uInt16 >(
1067 						pFmtr ? pFmtr->GetYear2000()
1068                               : ::utl::MiscCfg().GetYear2000() )));
1069 			}
1070 			break;
1071         case SID_ATTR_CHAR_FONTLIST:
1072         {
1073             rSet.Put( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
1074         }
1075         break;
1076         case SID_MAIL_PREPAREEXPORT:
1077         {
1078             //check if linked content or possibly hidden content is available
1079             //pDoc->UpdateFlds( NULL, false );
1080             sfx2::LinkManager& rLnkMgr = pDoc->GetLinkManager();
1081             const ::sfx2::SvBaseLinks& rLnks = rLnkMgr.GetLinks();
1082             sal_Bool bRet = sal_False;
1083             if( rLnks.Count() )
1084                 bRet = sal_True;
1085             else
1086             {
1087                 //sections with hidden flag, hidden character attribute, hidden paragraph/text or conditional text fields
1088                 bRet = pDoc->HasInvisibleContent();
1089             }
1090             rSet.Put( SfxBoolItem( nWhich, bRet ) );
1091         }
1092         break;
1093 
1094 		default: DBG_ASSERT(!this,"Hier darfst Du nicht hinein!");
1095 
1096 		}
1097 		nWhich = aIter.NextWhich();
1098 	}
1099 }
1100 
1101 /*--------------------------------------------------------------------
1102 	Beschreibung:	OLE-Hdls
1103  --------------------------------------------------------------------*/
1104 
1105 
1106 IMPL_LINK( SwDocShell, Ole2ModifiedHdl, void *, p )
1107 {
1108 	// vom Doc wird der Status mitgegeben (siehe doc.cxx)
1109 	// 	Bit 0:	-> alter Zustand
1110 	//	Bit 1: 	-> neuer Zustand
1111 	long nStatus = (long)p;
1112 	if( IsEnableSetModified() )
1113 		SetModified( (nStatus & 2) ? sal_True : sal_False );
1114 	return 0;
1115 }
1116 
1117 /*--------------------------------------------------------------------
1118 	Beschreibung:	Pool returnen Hier weil virtuelll
1119  --------------------------------------------------------------------*/
1120 
1121 
1122 SfxStyleSheetBasePool*	SwDocShell::GetStyleSheetPool()
1123 {
1124 	return mxBasePool.get();
1125 }
1126 
1127 
1128 #include <unotxdoc.hxx>
1129 
1130 void SwDocShell::SetView(SwView* pVw)
1131 {
1132     bool bChanged(false);
1133 
1134     if(0 != (pView = pVw))
1135     {
1136         pWrtShell = &pView->GetWrtShell();
1137         bChanged = true;
1138     }
1139     else
1140     {
1141         pWrtShell = 0;
1142         bChanged = true;
1143     }
1144 
1145     if(bChanged)
1146     {
1147         // #121125# SwXTextDocument may hold references to the ViewShell, so inform
1148         // it about changes to allow to react on it. This happens e.g. when printing
1149         // and/or PDF export (SwViewOptionAdjust_Impl holds a reference to the view
1150         // and needs to be destroyed)
1151         uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
1152         ((SwXTextDocument*)xDoc.get())->ReactOnViewShellChange();
1153     }
1154 }
1155 
1156 
1157 void SwDocShell::PrepareReload()
1158 {
1159 	::DelAllGrfCacheEntries( pDoc );
1160 }
1161 
1162 // --> OD 2006-11-07 #i59688#
1163 // linked graphics are now loaded on demand.
1164 // Thus, loading of linked graphics no longer needed and necessary for
1165 // the load of document being finished.
1166 void SwDocShell::LoadingFinished()
1167 {
1168     // --> OD 2007-10-08 #i38810#
1169     // Original fix fails after integration of cws xmlsec11:
1170     // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because
1171     // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and
1172     // enables the document modification again.
1173     // Thus, manuell modify the document, if its modified and its links are updated
1174     // before <FinishedLoading(..)> is called.
1175     const bool bHasDocToStayModified( pDoc->IsModified() && pDoc->LinksUpdated() );
1176 //    // --> OD 2005-02-11 #i38810# - disable method <SetModified(..)>, if document
1177 //    // has stay in modified state, due to the update of its links during load.
1178 //    bool bResetEnableSetModified(false);
1179 //    if ( IsEnableSetModified() &&
1180 //         pDoc->IsModified() && pDoc->LinksUpdated() )
1181 //    {
1182 //        EnableSetModified( sal_False );
1183 //        bResetEnableSetModified = true;
1184 //    }
1185     // <--
1186     FinishedLoading( SFX_LOADED_ALL );
1187 //    // --> OD 2005-02-11 #i38810#
1188 //    if ( bResetEnableSetModified )
1189 //    {
1190 //        EnableSetModified( sal_True );
1191 //    }
1192 //    // <--
1193 	SfxViewFrame* pVFrame = SfxViewFrame::GetFirst(this);
1194 	if(pVFrame)
1195 	{
1196 		SfxViewShell* pShell = pVFrame->GetViewShell();
1197 		if(PTR_CAST(SwSrcView, pShell))
1198 			((SwSrcView*)pShell)->Load(this);
1199 	}
1200 
1201     // --> OD 2007-10-08 #i38810#
1202     if ( bHasDocToStayModified && !pDoc->IsModified() )
1203     {
1204         pDoc->SetModified();
1205     }
1206     // <--
1207 }
1208 
1209 // eine Uebertragung wird abgebrochen (wird aus dem SFX gerufen)
1210 void SwDocShell::CancelTransfers()
1211 {
1212 	// alle Links vom LinkManager Canceln
1213 	aFinishedTimer.Stop();
1214 	pDoc->GetLinkManager().CancelTransfers();
1215 	SfxObjectShell::CancelTransfers();
1216 }
1217 
1218 SwFEShell* SwDocShell::GetFEShell()
1219 {
1220 	return pWrtShell;
1221 }
1222 
1223 void SwDocShell::RemoveOLEObjects()
1224 {
1225 	SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
1226 	for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
1227 	{
1228 		SwOLENode* pOLENd = pNd->GetOLENode();
1229 		if( pOLENd && ( pOLENd->IsOLEObjectDeleted() ||
1230 						pOLENd->IsInGlobalDocSection() ) )
1231 		{
1232             if( !pOLEChildList )
1233                 pOLEChildList = new comphelper::EmbeddedObjectContainer;
1234 
1235             ::rtl::OUString aObjName = pOLENd->GetOLEObj().GetCurrentPersistName();
1236             GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName, *pOLEChildList );
1237 		}
1238     }
1239 }
1240 
1241 // When a document is loaded, SwDoc::PrtOLENotify is called to update
1242 // the sizes of math objects. However, for objects that do not have a
1243 // SwFrm at this time, only a flag is set (bIsOLESizeInvalid) and the
1244 // size change takes place later, while calculating the layout in the
1245 // idle handler. If this document is saved now, it is saved with invalid
1246 // sizes. For this reason, the layout has to be calculated before a document is
1247 // saved, but of course only id there are OLE objects with bOLESizeInvalid set.
1248 void SwDocShell::CalcLayoutForOLEObjects()
1249 {
1250 	if( !pWrtShell )
1251 		return;
1252 
1253 	SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
1254 	for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
1255 	{
1256 		SwOLENode* pOLENd = pNd->GetOLENode();
1257 		if( pOLENd && pOLENd->IsOLESizeInvalid() )
1258 		{
1259 			pWrtShell->CalcLayout();
1260 			break;
1261 		}
1262 	}
1263 }
1264 
1265 
1266 // --> FME 2005-02-25 #i42634# Overwrites SfxObjectShell::UpdateLinks
1267 // This new function is necessary to trigger update of links in docs
1268 // read by the binary filter:
1269 void SwDocShell::UpdateLinks()
1270 {
1271     GetDoc()->UpdateLinks(sal_True);
1272     // --> FME 2005-07-27 #i50703# Update footnote numbers
1273     SwTxtFtn::SetUniqueSeqRefNo( *GetDoc() );
1274     SwNodeIndex aTmp( GetDoc()->GetNodes() );
1275     GetDoc()->GetFtnIdxs().UpdateFtn( aTmp );
1276     // <--
1277 }
1278 
1279 uno::Reference< frame::XController >
1280                                 SwDocShell::GetController()
1281 {
1282     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > aRet;
1283     // --> FME 2007-10-15 #i82346# No view in page preview
1284     if ( GetView() )
1285     // <--
1286         aRet = GetView()->GetController();
1287     return aRet;
1288 }
1289 
1290 /* -----------------------------12.02.01 12:08--------------------------------
1291 
1292  ---------------------------------------------------------------------------*/
1293 static const char* s_EventNames[] =
1294 {
1295 	"OnPageCountChange",
1296 	"OnMailMerge",
1297 	"OnMailMergeFinished",
1298 	"OnFieldMerge",
1299 	"OnFieldMergeFinished",
1300 	"OnLayoutFinished"
1301 };
1302 static sal_Int32 const s_nEvents(sizeof(s_EventNames)/sizeof(s_EventNames[0]));
1303 
1304 Sequence< OUString >	SwDocShell::GetEventNames()
1305 {
1306 	Sequence< OUString > aRet = SfxObjectShell::GetEventNames();
1307 	sal_Int32 nLen = aRet.getLength();
1308 	aRet.realloc(nLen + 6);
1309 	OUString* pNames = aRet.getArray();
1310     pNames[nLen++] = GetEventName(0);
1311     pNames[nLen++] = GetEventName(1);
1312     pNames[nLen++] = GetEventName(2);
1313     pNames[nLen++] = GetEventName(3);
1314     pNames[nLen++] = GetEventName(4);
1315     pNames[nLen]   = GetEventName(5);
1316 
1317 	return aRet;
1318 }
1319 
1320 rtl::OUString SwDocShell::GetEventName( sal_Int32 nIndex )
1321 {
1322     if (nIndex < s_nEvents)
1323     {
1324         return ::rtl::OUString::createFromAscii(s_EventNames[nIndex]);
1325     }
1326 	return rtl::OUString();
1327 }
1328 
1329 const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const
1330 {
1331     return pDoc ? &pDoc->GetXmlIdRegistry() : 0;
1332 }
1333 
1334 
1335 bool SwDocShell::IsChangeRecording() const
1336 {
1337     return (pWrtShell->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON) != 0;
1338 }
1339 
1340 
1341 bool SwDocShell::HasChangeRecordProtection() const
1342 {
1343     return pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0;
1344 }
1345 
1346 
1347 void SwDocShell::SetChangeRecording( bool bActivate )
1348 {
1349     sal_uInt16 nOn = bActivate ? nsRedlineMode_t::REDLINE_ON : 0;
1350     sal_uInt16 nMode = pWrtShell->GetRedlineMode();
1351     pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn);
1352 }
1353 
1354 
1355 bool SwDocShell::SetProtectionPassword( const String &rNewPassword )
1356 {
1357     const SfxAllItemSet aSet( GetPool() );
1358     const SfxItemSet*   pArgs = &aSet;
1359     const SfxPoolItem*  pItem = NULL;
1360 
1361     IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
1362     Sequence< sal_Int8 > aPasswd = pIDRA->GetRedlinePassword();
1363     if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem )
1364         && ((SfxBoolItem*)pItem)->GetValue() == (aPasswd.getLength() > 0))
1365         return false;
1366 
1367     bool bRes = false;
1368 
1369     if (rNewPassword.Len())
1370     {
1371         // when password protection is applied change tracking must always be active
1372         SetChangeRecording( true );
1373 
1374         Sequence< sal_Int8 > aNewPasswd;
1375         SvPasswordHelper::GetHashPassword( aNewPasswd, rNewPassword );
1376         pIDRA->SetRedlinePassword( aNewPasswd );
1377         bRes = true;
1378     }
1379     else
1380     {
1381         pIDRA->SetRedlinePassword( Sequence< sal_Int8 >() );
1382         bRes = true;
1383     }
1384 
1385     return bRes;
1386 }
1387 
1388 
1389 bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash )
1390 {
1391     bool bRes = false;
1392 
1393     const SfxAllItemSet aSet( GetPool() );
1394     const SfxItemSet*   pArgs = &aSet;
1395     const SfxPoolItem*  pItem = NULL;
1396 
1397     IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
1398     Sequence< sal_Int8 > aPasswdHash( pIDRA->GetRedlinePassword() );
1399     if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem )
1400         && ((SfxBoolItem*)pItem)->GetValue() == (aPasswdHash.getLength() != 0))
1401         return false;
1402     rPasswordHash = aPasswdHash;
1403     bRes = true;
1404 
1405     return bRes;
1406 }
1407 
1408 
1409