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