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