xref: /aoo42x/main/sw/source/ui/app/docsh.cxx (revision efeef26f)
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 void SwDocShell::SetView(SwView* pVw)
1129 {
1130 	if ( 0 != (pView = pVw) )
1131 		pWrtShell = &pView->GetWrtShell();
1132 	else
1133 		pWrtShell = 0;
1134 }
1135 
1136 
1137 void SwDocShell::PrepareReload()
1138 {
1139 	::DelAllGrfCacheEntries( pDoc );
1140 }
1141 
1142 // --> OD 2006-11-07 #i59688#
1143 // linked graphics are now loaded on demand.
1144 // Thus, loading of linked graphics no longer needed and necessary for
1145 // the load of document being finished.
1146 void SwDocShell::LoadingFinished()
1147 {
1148     // --> OD 2007-10-08 #i38810#
1149     // Original fix fails after integration of cws xmlsec11:
1150     // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because
1151     // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and
1152     // enables the document modification again.
1153     // Thus, manuell modify the document, if its modified and its links are updated
1154     // before <FinishedLoading(..)> is called.
1155     const bool bHasDocToStayModified( pDoc->IsModified() && pDoc->LinksUpdated() );
1156 //    // --> OD 2005-02-11 #i38810# - disable method <SetModified(..)>, if document
1157 //    // has stay in modified state, due to the update of its links during load.
1158 //    bool bResetEnableSetModified(false);
1159 //    if ( IsEnableSetModified() &&
1160 //         pDoc->IsModified() && pDoc->LinksUpdated() )
1161 //    {
1162 //        EnableSetModified( sal_False );
1163 //        bResetEnableSetModified = true;
1164 //    }
1165     // <--
1166     FinishedLoading( SFX_LOADED_ALL );
1167 //    // --> OD 2005-02-11 #i38810#
1168 //    if ( bResetEnableSetModified )
1169 //    {
1170 //        EnableSetModified( sal_True );
1171 //    }
1172 //    // <--
1173 	SfxViewFrame* pVFrame = SfxViewFrame::GetFirst(this);
1174 	if(pVFrame)
1175 	{
1176 		SfxViewShell* pShell = pVFrame->GetViewShell();
1177 		if(PTR_CAST(SwSrcView, pShell))
1178 			((SwSrcView*)pShell)->Load(this);
1179 	}
1180 
1181     // --> OD 2007-10-08 #i38810#
1182     if ( bHasDocToStayModified && !pDoc->IsModified() )
1183     {
1184         pDoc->SetModified();
1185     }
1186     // <--
1187 }
1188 
1189 // eine Uebertragung wird abgebrochen (wird aus dem SFX gerufen)
1190 void SwDocShell::CancelTransfers()
1191 {
1192 	// alle Links vom LinkManager Canceln
1193 	aFinishedTimer.Stop();
1194 	pDoc->GetLinkManager().CancelTransfers();
1195 	SfxObjectShell::CancelTransfers();
1196 }
1197 
1198 SwFEShell* SwDocShell::GetFEShell()
1199 {
1200 	return pWrtShell;
1201 }
1202 
1203 void SwDocShell::RemoveOLEObjects()
1204 {
1205 	SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
1206 	for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
1207 	{
1208 		SwOLENode* pOLENd = pNd->GetOLENode();
1209 		if( pOLENd && ( pOLENd->IsOLEObjectDeleted() ||
1210 						pOLENd->IsInGlobalDocSection() ) )
1211 		{
1212             if( !pOLEChildList )
1213                 pOLEChildList = new comphelper::EmbeddedObjectContainer;
1214 
1215             ::rtl::OUString aObjName = pOLENd->GetOLEObj().GetCurrentPersistName();
1216             GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName, *pOLEChildList );
1217 		}
1218     }
1219 }
1220 
1221 // When a document is loaded, SwDoc::PrtOLENotify is called to update
1222 // the sizes of math objects. However, for objects that do not have a
1223 // SwFrm at this time, only a flag is set (bIsOLESizeInvalid) and the
1224 // size change takes place later, while calculating the layout in the
1225 // idle handler. If this document is saved now, it is saved with invalid
1226 // sizes. For this reason, the layout has to be calculated before a document is
1227 // saved, but of course only id there are OLE objects with bOLESizeInvalid set.
1228 void SwDocShell::CalcLayoutForOLEObjects()
1229 {
1230 	if( !pWrtShell )
1231 		return;
1232 
1233 	SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
1234 	for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
1235 	{
1236 		SwOLENode* pOLENd = pNd->GetOLENode();
1237 		if( pOLENd && pOLENd->IsOLESizeInvalid() )
1238 		{
1239 			pWrtShell->CalcLayout();
1240 			break;
1241 		}
1242 	}
1243 }
1244 
1245 
1246 // --> FME 2005-02-25 #i42634# Overwrites SfxObjectShell::UpdateLinks
1247 // This new function is necessary to trigger update of links in docs
1248 // read by the binary filter:
1249 void SwDocShell::UpdateLinks()
1250 {
1251     GetDoc()->UpdateLinks(sal_True);
1252     // --> FME 2005-07-27 #i50703# Update footnote numbers
1253     SwTxtFtn::SetUniqueSeqRefNo( *GetDoc() );
1254     SwNodeIndex aTmp( GetDoc()->GetNodes() );
1255     GetDoc()->GetFtnIdxs().UpdateFtn( aTmp );
1256     // <--
1257 }
1258 
1259 uno::Reference< frame::XController >
1260                                 SwDocShell::GetController()
1261 {
1262     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > aRet;
1263     // --> FME 2007-10-15 #i82346# No view in page preview
1264     if ( GetView() )
1265     // <--
1266         aRet = GetView()->GetController();
1267     return aRet;
1268 }
1269 
1270 /* -----------------------------12.02.01 12:08--------------------------------
1271 
1272  ---------------------------------------------------------------------------*/
1273 static const char* pEventNames[] =
1274 {
1275 	"OnPageCountChange",
1276 	"OnMailMerge",
1277 	"OnMailMergeFinished",
1278 	"OnFieldMerge",
1279 	"OnFieldMergeFinished",
1280 	"OnLayoutFinished"
1281 };
1282 
1283 Sequence< OUString >	SwDocShell::GetEventNames()
1284 {
1285 	Sequence< OUString > aRet = SfxObjectShell::GetEventNames();
1286 	sal_Int32 nLen = aRet.getLength();
1287 	aRet.realloc(nLen + 6);
1288 	OUString* pNames = aRet.getArray();
1289     pNames[nLen++] = GetEventName(0);
1290     pNames[nLen++] = GetEventName(1);
1291     pNames[nLen++] = GetEventName(2);
1292     pNames[nLen++] = GetEventName(3);
1293     pNames[nLen++] = GetEventName(4);
1294     pNames[nLen]   = GetEventName(5);
1295 
1296 	return aRet;
1297 }
1298 
1299 static sal_Int32 nEvents=13;
1300 
1301 rtl::OUString SwDocShell::GetEventName( sal_Int32 nIndex )
1302 {
1303 	if ( nIndex<nEvents )
1304 		return ::rtl::OUString::createFromAscii(pEventNames[nIndex]);
1305 	return rtl::OUString();
1306 }
1307 
1308 const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const
1309 {
1310     return pDoc ? &pDoc->GetXmlIdRegistry() : 0;
1311 }
1312 
1313 
1314 bool SwDocShell::IsChangeRecording() const
1315 {
1316     return (pWrtShell->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON) != 0;
1317 }
1318 
1319 
1320 bool SwDocShell::HasChangeRecordProtection() const
1321 {
1322     return pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0;
1323 }
1324 
1325 
1326 void SwDocShell::SetChangeRecording( bool bActivate )
1327 {
1328     sal_uInt16 nOn = bActivate ? nsRedlineMode_t::REDLINE_ON : 0;
1329     sal_uInt16 nMode = pWrtShell->GetRedlineMode();
1330     pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn);
1331 }
1332 
1333 
1334 bool SwDocShell::SetProtectionPassword( const String &rNewPassword )
1335 {
1336     const SfxAllItemSet aSet( GetPool() );
1337     const SfxItemSet*   pArgs = &aSet;
1338     const SfxPoolItem*  pItem = NULL;
1339 
1340     IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
1341     Sequence< sal_Int8 > aPasswd = pIDRA->GetRedlinePassword();
1342     if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem )
1343         && ((SfxBoolItem*)pItem)->GetValue() == (aPasswd.getLength() > 0))
1344         return false;
1345 
1346     bool bRes = false;
1347 
1348     if (rNewPassword.Len())
1349     {
1350         // when password protection is applied change tracking must always be active
1351         SetChangeRecording( true );
1352 
1353         Sequence< sal_Int8 > aNewPasswd;
1354         SvPasswordHelper::GetHashPassword( aNewPasswd, rNewPassword );
1355         pIDRA->SetRedlinePassword( aNewPasswd );
1356         bRes = true;
1357     }
1358     else
1359     {
1360         pIDRA->SetRedlinePassword( Sequence< sal_Int8 >() );
1361         bRes = true;
1362     }
1363 
1364     return bRes;
1365 }
1366 
1367 
1368 bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash )
1369 {
1370     bool bRes = false;
1371 
1372     const SfxAllItemSet aSet( GetPool() );
1373     const SfxItemSet*   pArgs = &aSet;
1374     const SfxPoolItem*  pItem = NULL;
1375 
1376     IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
1377     Sequence< sal_Int8 > aPasswdHash( pIDRA->GetRedlinePassword() );
1378     if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem )
1379         && ((SfxBoolItem*)pItem)->GetValue() == (aPasswdHash.getLength() != 0))
1380         return false;
1381     rPasswordHash = aPasswdHash;
1382     bRes = true;
1383 
1384     return bRes;
1385 }
1386 
1387 
1388