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