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