xref: /aoo41x/main/sw/source/ui/app/docsh2.cxx (revision 79aad27f)
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 <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/frame/XDispatchHelper.hpp>
29 
30 #include <comphelper/processfactory.hxx>
31 
32 #include <hintids.hxx>
33 #include <tools/urlobj.hxx>
34 #include <unotools/tempfile.hxx>
35 #include <vcl/wrkwin.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <svl/lckbitem.hxx>
38 #include <svl/eitem.hxx>
39 #include <svl/zforlist.hxx>
40 #include <svl/zformat.hxx>
41 #include <unotools/pathoptions.hxx>
42 #include <svtools/transfer.hxx>
43 #include <sfx2/dialogs.hrc>
44 #include <sfx2/dinfdlg.hxx>
45 #include <sfx2/request.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/new.hxx>
48 #include <sfx2/filedlghelper.hxx>
49 #include <sfx2/printer.hxx>
50 #include <sfx2/evntconf.hxx>
51 #include <svtools/sfxecode.hxx>
52 #include <sfx2/docfile.hxx>
53 #include <sfx2/docfilt.hxx>
54 #include <svx/svxids.hrc>
55 #include <svx/drawitem.hxx>
56 #include <editeng/svxacorr.hxx>
57 #include <editeng/langitem.hxx>
58 #include <svx/fmshell.hxx>
59 
60 #include <svtools/htmlcfg.hxx>
61 #include <svx/ofaitem.hxx>
62 #include <SwSmartTagMgr.hxx>
63 #include <sfx2/app.hxx>
64 #include <basic/sbstar.hxx>
65 #include <basic/basmgr.hxx>
66 #include <sot/storage.hxx>
67 #include <sot/clsids.hxx>
68 #include <swunodef.hxx>
69 #include <fmtcol.hxx>
70 #include <swevent.hxx>
71 #include <view.hxx> 		// fuer die aktuelle Sicht
72 #include <docsh.hxx>	  	// Dokumenterzeugung
73 #include <wrtsh.hxx>
74 #include <fldbas.hxx>
75 #include <viewopt.hxx>
76 #include <globdoc.hxx>
77 #include <fldwrap.hxx>
78 #include <redlndlg.hxx>
79 #include <docstyle.hxx>
80 #include <doc.hxx>
81 #include <IDocumentUndoRedo.hxx>
82 #include <pagedesc.hxx>
83 #include <shellio.hxx>
84 #include <pview.hxx>
85 #include <srcview.hxx>
86 #include <poolfmt.hxx>
87 #include <usrpref.hxx>
88 #include <wdocsh.hxx>
89 #include <unotxdoc.hxx>
90 #include <acmplwrd.hxx>
91 #include <swmodule.hxx>
92 #include <unobaseclass.hxx>
93 #include <swwait.hxx>
94 #include <swcli.hxx>
95 
96 #include <cmdid.h>
97 #include <globals.h>
98 #include <helpid.h>
99 #include <app.hrc>
100 #include <poolfmt.hrc>
101 #include <globals.hrc>
102 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
103 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
104 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
105 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
106 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
107 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
108 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
109 #ifdef FUTURE_VBA
110 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
111 #include <com/sun/star/script/vba/VBAEventId.hpp>
112 #endif
113 #include <editeng/acorrcfg.hxx>
114 #include <SwStyleNameMapper.hxx>
115 
116 #include <sfx2/fcontnr.hxx>
117 
118 #include "swabstdlg.hxx"
119 #include "dialog.hrc"
120 #include "swabstdlg.hxx"
121 
122 #include <ndtxt.hxx>	//#outline level,add by zhaojianwei
123 
124 using namespace ::com::sun::star::ui::dialogs;
125 using namespace ::com::sun::star::lang;
126 using namespace ::com::sun::star::uno;
127 using namespace ::com::sun::star;
128 using ::rtl::OUString;
129 using namespace ::sfx2;
130 extern sal_Bool FindPhyStyle( SwDoc& , const String& , SfxStyleFamily );
131 
132 /*--------------------------------------------------------------------
133 	Beschreibung:	DocInfo kreieren (virtuell)
134  --------------------------------------------------------------------*/
135 
136 SfxDocumentInfoDialog* SwDocShell::CreateDocumentInfoDialog(
137 								Window *pParent, const SfxItemSet &rSet)
138 {
139 	SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog(pParent, rSet);
140 	//nur mit Statistik, wenn dieses Doc auch angezeigt wird, nicht
141 	//aus dem Doc-Manager
142 	SwDocShell* pDocSh = (SwDocShell*) SfxObjectShell::Current();
143 	if( pDocSh == this )
144 	{
145 		//Nicht fuer SourceView.
146 		SfxViewShell *pVSh = SfxViewShell::Current();
147 		if ( pVSh && !pVSh->ISA(SwSrcView) )
148 		{
149             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
150             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
151 			pDlg->AddTabPage(TP_DOC_STAT, SW_RESSTR(STR_DOC_STAT),pFact->GetTabPageCreatorFunc( TP_DOC_STAT ),0);
152 		}
153 	}
154 	return pDlg;
155 }
156 
157 // Disable "multiple layout"
158 
159 void    SwDocShell::ToggleBrowserMode(sal_Bool bSet, SwView* _pView )
160 {
161 	GetDoc()->set(IDocumentSettingAccess::BROWSE_MODE, bSet );
162 	UpdateFontList();
163     SwView* pTempView = _pView ? _pView : (SwView*)GetView();
164 	if( pTempView )
165 	{
166         pTempView->GetViewFrame()->GetBindings().Invalidate(FN_SHADOWCURSOR);
167         if( !GetDoc()->getPrinter( false ) )
168             pTempView->SetPrinter( GetDoc()->getPrinter( false ), SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP );
169         GetDoc()->CheckDefaultPageFmt();
170 		SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this, sal_False);
171 		do {
172 			if( pTmpFrm != pTempView->GetViewFrame() )
173 			{
174 				pTmpFrm->DoClose();
175 				pTmpFrm = SfxViewFrame::GetFirst(this, sal_False);
176 			}
177 			else
178 				pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this, sal_False);
179 
180 		} while ( pTmpFrm );
181         const SwViewOption& rViewOptions = *pTempView->GetWrtShell().GetViewOptions();
182 		pTempView->GetWrtShell().CheckBrowseView( sal_True );
183 		pTempView->CheckVisArea();
184 		if( bSet )
185         {
186     		const SvxZoomType eType = (SvxZoomType)rViewOptions.GetZoomType();
187             if ( SVX_ZOOM_PERCENT != eType)
188 			    ((SwView*)GetView())->SetZoom( eType );
189         }
190 		pTempView->InvalidateBorder();
191 		pTempView->SetNewWindowAllowed(!bSet);
192 	}
193 }
194 // End of disabled "multiple layout"
195 
196 /// update text fields on document properties changes
197 void SwDocShell::DoFlushDocInfo()
198 {
199 	if ( !pDoc ) return;
200 
201     bool bUnlockView(true);
202     if ( pWrtShell ) {
203         bUnlockView = !pWrtShell->IsViewLocked();
204         pWrtShell->LockView( sal_True );	// lock visible section
205         pWrtShell->StartAllAction();
206     }
207 
208     pDoc->DocInfoChgd();
209 
210     if ( pWrtShell ) {
211         pWrtShell->EndAllAction();
212         if ( bUnlockView ) {
213             pWrtShell->LockView( sal_False );
214         }
215     }
216 }
217 
218 #ifdef FUTURE_VBA
219 void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint )
220 {
221     using namespace com::sun::star::script::vba::VBAEventId;
222     if ( rHint.ISA( SfxEventHint ) )
223     {
224         uno::Sequence< uno::Any > aArgs;
225         sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
226         switch( nEventId )
227         {
228             case SFX_EVENT_CREATEDOC:
229                 xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs );
230             break;
231             case SFX_EVENT_OPENDOC:
232                 xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs );
233             break;
234         }
235     }
236 }
237 #endif
238 
239 /*--------------------------------------------------------------------
240 	Beschreibung: 	Benachrichtigung bei geaenderter DocInfo
241  --------------------------------------------------------------------*/
242 
243 void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
244 {
245 	if( !pDoc )
246 	{
247 //MA: Kommt bei der OLE-Registration vor!
248 //		ASSERT( !this, "DocShell ist nicht richtig initialisiert!" );
249 		return ;
250 	}
251 
252 #ifdef FUTURE_VBA
253     uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor();
254     if( xVbaEvents.is() )
255         lcl_processCompatibleSfxHint( xVbaEvents, rHint );
256 #endif
257 
258 	sal_uInt16 nAction = 0;
259 	if( rHint.ISA(SfxSimpleHint) )
260 	{
261 		// swithc for more actions
262 		switch( ((SfxSimpleHint&) rHint).GetId() )
263 		{
264             case SFX_HINT_TITLECHANGED:
265                 if( GetMedium() )
266                     nAction = 2;
267 			break;
268         }
269 	}
270 	else if( rHint.ISA(SfxEventHint) &&
271         ((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_LOADFINISHED )
272     {
273         // --> OD 2004-12-03 #i38126# - own action id
274         nAction = 3;
275         // <--
276     }
277 
278 	if( nAction )
279 	{
280         sal_Bool bUnlockView = sal_True; //initializing prevents warning
281 		if( pWrtShell )
282 		{
283 			bUnlockView = !pWrtShell->IsViewLocked();
284 			pWrtShell->LockView( sal_True );	//lock visible section
285 			pWrtShell->StartAllAction();
286 		}
287 		switch( nAction )
288 		{
289 		case 2:
290 			pDoc->GetSysFldType( RES_FILENAMEFLD )->UpdateFlds();
291 			break;
292         // --> OD 2004-12-03 #i38126# - own action for event LOADFINISHED
293         // in order to avoid a modified document.
294         // --> OD 2005-02-01 #i41679# - Also for the instance of <SwDoc>
295         // it has to be assured, that it's not modified.
296         // Perform the same as for action id 1, but disable <SetModified>.
297         case 3:
298             {
299                 const bool bResetModified = IsEnableSetModified();
300                 if ( bResetModified )
301                     EnableSetModified( sal_False );
302                 // --> OD 2005-02-01 #i41679#
303                 const bool bIsDocModified = pDoc->IsModified();
304                 // <--
305 
306                 pDoc->DocInfoChgd( );
307 
308                 // --> OD 2005-02-01 #i41679#
309                 if ( !bIsDocModified )
310                     pDoc->ResetModified();
311                 // <--
312                 if ( bResetModified )
313                     EnableSetModified( sal_True );
314             }
315             break;
316         // <--
317 		}
318 
319 		if( pWrtShell )
320 		{
321 			pWrtShell->EndAllAction();
322 			if( bUnlockView )
323 				pWrtShell->LockView( sal_False );
324 		}
325 	}
326 }
327 
328 /*--------------------------------------------------------------------
329 	Beschreibung: 	Benachrichtigung Doc schliessen
330  --------------------------------------------------------------------*/
331 
332 sal_uInt16 SwDocShell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
333 {
334 	sal_uInt16 nRet = SfxObjectShell::PrepareClose( bUI, bForBrowsing );
335 
336 	if( sal_True == nRet ) //Unbedingt auf sal_True abfragen! (RET_NEWTASK)
337 		EndListening( *this );
338 
339 #ifdef FUTURE_VBA
340     if( pDoc && IsInPrepareClose() )
341     {
342         uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor();
343         if( xVbaEvents.is() )
344         {
345             using namespace com::sun::star::script::vba::VBAEventId;
346             uno::Sequence< uno::Any > aArgs;
347             xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs );
348         }
349     }
350 #endif
351 	return nRet;
352 }
353 
354 /*--------------------------------------------------------------------
355 	Beschreibung:	Organizer
356  --------------------------------------------------------------------*/
357 
358 sal_Bool SwDocShell::Insert( SfxObjectShell &rSource,
359 	sal_uInt16	nSourceIdx1,		// SourcePool: oberste Inhaltsebene (Vorlagen/Makros)
360 	sal_uInt16	nSourceIdx2,		// Index in den Inhalt
361 	sal_uInt16	nSourceIdx3,		// Index in die Inhaltsebene
362 	sal_uInt16 &rIdx1,				// und das gleiche fuer den DestinationPool
363 	sal_uInt16 &rIdx2,				//		""
364 	sal_uInt16 &rIdx3,				//		""
365 	sal_uInt16 &rRemovedIdx )		// falls doppelte geloescht werden, Pos zurueck
366 {
367     // --> OD 2005-05-10 #i48949# - actions aren't undoable. Thus, allow no undo
368     // actions
369     // Note: The undo action stack is cleared at the end of this method.
370     ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
371     // <--
372 
373     sal_Bool bRet = sal_False;
374 
375 	if (INDEX_IGNORE == rIdx1 && CONTENT_STYLE == nSourceIdx1)
376 		rIdx1 = CONTENT_STYLE;
377 
378 	if (CONTENT_STYLE == nSourceIdx1 && CONTENT_STYLE == rIdx1)
379 	{
380 		SfxStyleSheetBasePool* pHisPool  = rSource.GetStyleSheetPool();
381 		SwDocStyleSheetPool* pMyPool =
382 			(SwDocStyleSheetPool*)GetStyleSheetPool();
383 
384 		//	wir koennen nicht in uns selbst hin und her moven
385 		if( pHisPool == pMyPool )
386 			return sal_False;
387 
388 		if( INDEX_IGNORE == rIdx2 )
389 			rIdx2 = pMyPool->Count();
390 
391 		// erstmal auf die Such-Maske "positionieren"
392 		pHisPool->First();
393 		SfxStyleSheetBase* pHisSheet = (*pHisPool)[nSourceIdx2];
394 
395 		// wenn so eine Vorlage schon existiert: loeschen!
396 		const String& rOldName = pHisSheet->GetName();
397 		SfxStyleFamily eOldFamily( pHisSheet->GetFamily() );
398 
399 		// dflt. PageDesc und StandardZeichenvorlage nie loeschen !!!
400 		if( ( SFX_STYLE_FAMILY_PAGE == eOldFamily &&
401 			  const_cast<const SwDoc *>(pDoc)->GetPageDesc(0).GetName() ==
402               rOldName ) ||
403 			  ( SFX_STYLE_FAMILY_CHAR == eOldFamily &&
404 				rOldName == *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD -
405 												RES_POOLCOLL_TEXT_BEGIN ] ))
406 			return sal_False;
407 
408 		SfxStyleFamily eMyOldFamily( pMyPool->GetSearchFamily() );
409 		sal_uInt16 nMySrchMask = pMyPool->GetSearchMask();
410 
411 		SfxStyleSheetBase* pExist;
412 		if( ::FindPhyStyle( *pDoc, rOldName, eOldFamily ) )
413 		{
414 			// Bug 20365: nur uebernehmen, wenn das gewuenscht ist!
415 			if( ERRCODE_BUTTON_OK != ErrorHandler::HandleError(
416 				*new MessageInfo( ERRCODE_SFXMSG_STYLEREPLACE, rOldName )) )
417 			{
418 				return sal_False;
419 			}
420 
421 			// Da Replace den aStyleSheet-Member selbst benoetigt, muss
422 			// das Ergebnis vom Find kopiert werden (s.u.))
423 			rtl::Reference< SwDocStyleSheet > xExist( new SwDocStyleSheet(
424 					*(SwDocStyleSheet*)pMyPool->Find( rOldName, eOldFamily ) ) );
425 			pMyPool->Replace( *pHisSheet, *xExist.get() );
426 
427 			// An der Reihenfolge der Vorlagen im Pool aendert sich nichts.
428 			rIdx2 = rIdx1 = INDEX_IGNORE;
429 
430 			GetDoc()->SetModified();
431 
432 			return sal_True;
433 		}
434 
435 		pMyPool->SetSearchMask( eOldFamily, nMySrchMask );
436 
437 		// MIB 18.12.98: SwDocStyleSheetPool::Make liefert einen
438 		// Pointer auf SwDocStyleSheetPool::aStyleSheet zurueck.
439 		// Der gleiche Member von SwDocStyleSheetPool::Find benutzt.
440 		// Deshalb muss hier mit einer Kopie gearbeitet werden.
441 		// Vorsicht: SfxStyleSheetBase::SetFollow ruft seinerseits
442 		// ein SwDocStyleSheetPool::Find auf, do dass es nicht genuegt
443 		// die Find-Aufrufe in dieser Methode zu eleminieren.
444 
445 		rtl::Reference< SwDocStyleSheet > xNewSheet( new SwDocStyleSheet( (SwDocStyleSheet&)pMyPool
446 				->Make(rOldName, eOldFamily, pHisSheet->GetMask() ) ) );
447 		if( SFX_STYLE_FAMILY_PAGE == eOldFamily && rSource.ISA(SwDocShell) )
448 		{
449 			// gesondert behandeln!!
450 			SwPageDesc* pDestDsc = (SwPageDesc*)xNewSheet->GetPageDesc();
451 			SwPageDesc* pCpyDsc = (SwPageDesc*)((SwDocStyleSheet*)pHisSheet)->GetPageDesc();
452 			pDoc->CopyPageDesc( *pCpyDsc, *pDestDsc );
453 		}
454 		else
455 			// die neue Vorlage mit den Attributen fuellen
456 			xNewSheet->SetItemSet( pHisSheet->GetItemSet() );
457 
458 		pMyPool->SetSearchMask( SFX_STYLE_FAMILY_ALL, nMySrchMask );
459 
460 		if(	xNewSheet->IsUserDefined() || xNewSheet->IsUsed() )
461 		{
462 			// Benutzte und Benutzer-definierte Vorlagen werden angezeigt.
463 			// Dshalb muss hier der Index der neuen Vorlage im Pool
464 			// ermittelt werden.
465 			pExist = pMyPool->First();
466 			sal_uInt16 nIdx = 0;
467 			while( pExist )
468 			{
469 				if( pExist->GetName() == rOldName &&
470 				   eOldFamily == pExist->GetFamily() )
471 				{
472 					rIdx2 = nIdx;
473 					break;
474 				}
475 				pExist = pMyPool->Next();
476 				nIdx++;
477 			}
478 		}
479 		else
480 		{
481 			// Andere Vorlagen werden nicht angezeigt.
482 			rIdx1 = rIdx2 = INDEX_IGNORE;
483 		}
484 
485 /*		  pMyPool->Count(); 	  //interne Liste neu fuellen lassen!!!!!
486 
487 		// suchen, um die richige Insert-Position returnen zu koennen
488 		pMyPool->Find( rOldName, SFX_STYLE_FAMILY_ALL, nMySrchMask );
489 		rIdx2 = pMyPool->GetFindPos();*/
490 
491 		// wer bekommt den Neuen als Parent? wer benutzt den Neuen als Follow?
492 		// (immer nur ueber die Instanziierten!!!)
493 		pMyPool->SetSearchMask( eOldFamily, nMySrchMask );
494 		pMyPool->SetOrganizerMode( sal_True );
495 		SfxStyleSheetBase* pTestSheet = pMyPool->First();
496 		while (pTestSheet)
497 		{
498 			if (pTestSheet->GetFamily() == eOldFamily &&
499 				pTestSheet->HasParentSupport()		  &&
500 				pTestSheet->GetParent() == rOldName)
501 			{
502 				pTestSheet->SetParent(rOldName); // Verknuepfung neu aufbauen
503 			}
504 
505 			if (pTestSheet->GetFamily() == eOldFamily &&
506 				pTestSheet->HasFollowSupport()		  &&
507 				pTestSheet->GetFollow() == rOldName)
508 			{
509 				pTestSheet->SetFollow(rOldName); // Verknuepfung neu aufbauen
510 			}
511 
512 			pTestSheet = pMyPool->Next();
513 		}
514 		pMyPool->SetOrganizerMode( SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
515 
516 		// hat der Neue einen Parent? wenn ja, mit gleichem Namen bei uns suchen
517 		if (pHisSheet->HasParentSupport())
518 		{
519 			const String& rParentName = pHisSheet->GetParent();
520 			if (0 != rParentName.Len())
521 			{
522 				SfxStyleSheetBase* pParentOfNew = pMyPool->Find(rParentName,
523 																eOldFamily);
524 				if (pParentOfNew)
525 				{
526 					xNewSheet->SetParent(rParentName);
527 				}
528 				pMyPool->SetSearchMask( eOldFamily, nMySrchMask );
529 			}
530 		}
531 
532 		// hat der Neue einen Follow? wenn ja, mit gleichem Namen bei uns suchen
533 		if (pHisSheet->HasFollowSupport())
534 		{
535 			const String& rFollowName = pHisSheet->GetFollow();
536 			if (0 != rFollowName.Len())
537 			{
538 				SfxStyleSheetBase* pFollowOfNew = pMyPool->Find(rFollowName,
539 																eOldFamily);
540 				if (pFollowOfNew)
541 				{
542 					xNewSheet->SetFollow(rFollowName);
543 				}
544 				pMyPool->SetSearchMask( eOldFamily, nMySrchMask );
545 			}
546 		}
547 
548 		// Bug 27347: alte Einstellung wieder setzen
549 		pMyPool->SetSearchMask( eMyOldFamily, nMySrchMask );
550 
551 		// Model geaendert
552 		ASSERT(pDoc, "Doc fehlt");
553 		GetDoc()->SetModified();
554 
555 		bRet = sal_True;
556 	}
557 	else
558 		bRet = SfxObjectShell::Insert( rSource,
559 					nSourceIdx1,
560 					nSourceIdx2,
561 					nSourceIdx3,
562 					rIdx1,
563 					rIdx2,
564 					rIdx3,
565 					rRemovedIdx);
566 
567     // --> OD 2005-05-10 #i48949# - actions aren't undoable and could have change
568     // the document node array. Thus, clear the undo action stack.
569     if (undoGuard.UndoWasEnabled())
570     {
571         GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
572     }
573     // <--
574 
575     return bRet;
576 }
577 
578 /*--------------------------------------------------------------------
579 	Beschreibung:	Vorlagen Remove
580  --------------------------------------------------------------------*/
581 
582 sal_Bool SwDocShell::Remove(sal_uInt16 nIdx1,		// siehe Insert
583 						sal_uInt16 nIdx2,
584 						sal_uInt16 nIdx3)
585 {
586 	sal_Bool bRet = sal_False;
587 
588 	if (CONTENT_STYLE == nIdx1)
589 	{
590 		SwDocStyleSheetPool* pMyPool = (SwDocStyleSheetPool*)GetStyleSheetPool();
591 
592 		pMyPool->First();		// vorm Zugriff Pool aktualisieren!!
593 		SfxStyleSheetBase* pMySheet = (*pMyPool)[nIdx2];
594 
595 		String aName( pMySheet->GetName() );
596 		SfxStyleFamily eFamily( pMySheet->GetFamily() );
597 
598 		// dflt. PageDesc und StandardZeichenvorlage nie loeschen !!!
599 		if( ( SFX_STYLE_FAMILY_PAGE == eFamily &&
600 			  const_cast<const SwDoc *>(pDoc)->GetPageDesc(0).GetName()
601               == aName ) ||
602 			  ( SFX_STYLE_FAMILY_CHAR == eFamily &&
603 				aName == *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD -
604 												RES_POOLCOLL_TEXT_BEGIN ] ))
605 			return sal_False;
606 
607 		// also loeschen
608 		pMyPool->Remove( pMySheet );
609 
610 		// jetzt noch die Parents/Follows aller Instanziierten korrigieren
611 		pMyPool->SetOrganizerMode( sal_True );
612 		SfxStyleSheetBase* pTestSheet = pMyPool->First();
613 		while (pTestSheet)
614 		{
615 			if (pTestSheet->GetFamily() == eFamily &&
616 				pTestSheet->HasParentSupport()	   &&
617 				pTestSheet->GetParent() == aName)
618 			{
619 				pTestSheet->SetParent( aEmptyStr ); // Verknuepfung aufloesen
620 			}
621 
622 			if (pTestSheet->GetFamily() == eFamily &&
623 				pTestSheet->HasFollowSupport()		  &&
624 				pTestSheet->GetFollow() == aName)
625 			{
626 				pTestSheet->SetFollow( aEmptyStr ); // Verknuepfung aufloesen
627 			}
628 
629 			pTestSheet = pMyPool->Next();
630 		}
631 		pMyPool->SetOrganizerMode( SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
632 
633 		bRet = sal_True;
634 	}
635 	else
636 		bRet = SfxObjectShell::Remove( 	nIdx1,
637 										nIdx2,
638 										nIdx3 );
639 
640 
641 	// Model geaendert
642 	ASSERT(pDoc, "Doc fehlt");
643 	GetDoc()->SetModified();
644 
645 	return bRet;
646 }
647 
648 /*--------------------------------------------------------------------
649 	Beschreibung:
650  --------------------------------------------------------------------*/
651 
652 void SwDocShell::Execute(SfxRequest& rReq)
653 {
654 	const SfxItemSet* pArgs = rReq.GetArgs();
655 	const SfxPoolItem* pItem;
656 	sal_uInt16 nWhich = rReq.GetSlot();
657 	sal_Bool bDone = sal_False;
658 	switch ( nWhich )
659 	{
660         case SID_AUTO_CORRECT_DLG:
661 		{
662 			SvxSwAutoFmtFlags* pAFlags = &SvxAutoCorrCfg::Get()->GetAutoCorrect()->GetSwFlags();
663 			SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords();
664 
665 			sal_Bool bOldLocked = rACW.IsLockWordLstLocked(),
666 				 bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords;
667 
668 			rACW.SetLockWordLstLocked( sal_True );
669 
670 			SvStringsISortDtor aTmpLst;
671 			aTmpLst.Insert( &rACW.GetWordList() );
672 			pAFlags->pAutoCmpltList = &aTmpLst;
673 
674 			SfxApplication* pApp = SFX_APP();
675 			SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SFX_CALLMODE_SYNCHRON, pApp->GetPool());
676             SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG, sal_True );
677 			aAppReq.AppendItem(aSwOptions);
678 
679             // SMARTTAGS
680             pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get();
681 
682 			//pApp->ExecuteSlot(aAppReq);
683 
684             SfxItemSet aSet( pApp->GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS, 0 );
685             aSet.Put( aSwOptions );
686 
687             const SfxPoolItem* pOpenSmartTagOptionsItem = 0;
688             if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS, sal_False, &pOpenSmartTagOptionsItem ) )
689                 aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) );
690 
691 			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
692     	  	SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
693 		  	pDlg->Execute();
694 		  	delete pDlg;
695 
696 			rACW.SetLockWordLstLocked( bOldLocked );
697 
698 			SwEditShell::SetAutoFmtFlags( pAFlags );
699 			rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen );
700 			rACW.SetMaxCount( pAFlags->nAutoCmpltListLen );
701 			if( pAFlags->pAutoCmpltList )  // any changes?
702 			{
703 				rACW.CheckChangedList( aTmpLst );
704 				// clear the temp WordList pointer
705 				pAFlags->pAutoCmpltList = 0;
706 			}
707 			// remove all pointer we never delete the strings
708 			aTmpLst.Remove( (sal_uInt16)0, aTmpLst.Count() );
709 
710 			if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords !=
711 				pAFlags->bAutoCmpltCollectWords )
712 			{
713 				// call on all Docs the idle formatter to start
714 				// the collection of Words
715 				TypeId aType = TYPE(SwDocShell);
716 				for( SwDocShell *pDocSh = (SwDocShell*)SfxObjectShell::GetFirst(&aType);
717 			 		pDocSh;
718 			 		pDocSh = (SwDocShell*)SfxObjectShell::GetNext( *pDocSh, &aType ) )
719 				{
720 					SwDoc* pTmp = pDocSh->GetDoc();
721 					if ( pTmp->GetCurrentViewShell() )	//swmod 071108//swmod 071225
722 						pTmp->InvalidateAutoCompleteFlag();
723 				}
724 			}
725 		}
726 		break;
727 
728 		case SID_PRINTPREVIEW:
729 			{
730 				sal_Bool bSet = sal_False, bFound = sal_False, bOnly = sal_True;
731 				SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this);
732 				SfxViewShell* pViewShell = SfxViewShell::Current();
733                 SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell );
734 				sal_Bool bCurrent = IS_TYPE( SwPagePreView, pViewShell );
735 
736 				while( pTmpFrm ) 	// search PreView
737 				{
738 					if( IS_TYPE( SwView, pTmpFrm->GetViewShell()) )
739 						bOnly = sal_False;
740 					else if( IS_TYPE( SwPagePreView, pTmpFrm->GetViewShell()))
741 					{
742 						pTmpFrm->GetFrame().Appear();
743 						bFound = sal_True;
744 					}
745 					if( bFound && !bOnly )
746 						break;
747 					pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this);
748 				}
749 
750 				if( pArgs && SFX_ITEM_SET ==
751 					pArgs->GetItemState( SID_PRINTPREVIEW, sal_False, &pItem ))
752 					bSet = ((SfxBoolItem*)pItem)->GetValue();
753 				else
754 					bSet = !bCurrent;
755 
756 				sal_uInt16 nSlotId = 0;
757 				if( bSet && !bFound )	// Keine gefunden, daher neue Preview anlegen
758 						nSlotId = SID_VIEWSHELL1;
759 				else if( bFound && !bSet )
760 					nSlotId = bOnly ? SID_VIEWSHELL0 : SID_VIEWSHELL1;
761 
762 				if( nSlotId )
763 				{
764 					//JP 23.8.2001: Bug 91360 - PagePreView in the WebDocShell
765 					//				is found under Id ViewShell2.
766 					if( ISA(SwWebDocShell) && SID_VIEWSHELL1 == nSlotId )
767 						nSlotId = SID_VIEWSHELL2;
768 
769                     if( pCurrView && pCurrView->GetDocShell() == this )
770                         pTmpFrm = pCurrView->GetViewFrame();
771 					else
772 						pTmpFrm = SfxViewFrame::GetFirst( this );
773 
774                     pTmpFrm->GetDispatcher()->Execute( nSlotId, 0, 0, SFX_CALLMODE_ASYNCHRON );
775 				}
776 
777 				rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW, bSet ));
778 			}
779 			break;
780 		case SID_TEMPLATE_LOAD:
781 			{
782 				String aFileName;
783                 static sal_Bool bText = sal_True;
784                 static sal_Bool bFrame = sal_False;
785                 static sal_Bool bPage =  sal_False;
786                 static sal_Bool bNum =   sal_False;
787                 static sal_Bool bMerge = sal_False;
788 				sal_uInt16 nRet = USHRT_MAX;
789 
790                 sal_uInt16 nFlags = bFrame ? SFX_LOAD_FRAME_STYLES : 0;
791                 if(bPage)
792                     nFlags|= SFX_LOAD_PAGE_STYLES;
793                 if(bNum)
794                     nFlags|= SFX_LOAD_NUM_STYLES;
795                 if(!nFlags || bText)
796                     nFlags|= SFX_LOAD_TEXT_STYLES;
797                 if(bMerge)
798                     nFlags|= SFX_MERGE_STYLES;
799 
800                 if ( pArgs )
801                 {
802                     SFX_REQUEST_ARG( rReq, pTemplateItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False );
803                     if ( pTemplateItem )
804                     {
805                         aFileName = pTemplateItem->GetValue();
806                         SFX_REQUEST_ARG( rReq, pFlagsItem, SfxInt32Item, SID_TEMPLATE_LOAD, sal_False );
807                         if ( pFlagsItem )
808                             nFlags = (sal_uInt16) pFlagsItem->GetValue();
809                     }
810                 }
811 
812                 if ( !aFileName.Len() )
813                 {
814                     SvtPathOptions aPathOpt;
815                     SfxNewFileDialog* pNewFileDlg =
816                         new SfxNewFileDialog(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE);
817                     pNewFileDlg->SetTemplateFlags(nFlags);
818 
819                     nRet = pNewFileDlg->Execute();
820                     if(RET_TEMPLATE_LOAD == nRet)
821                     {
822                         FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
823                         uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
824 
825                         xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
826 
827                         SfxObjectFactory &rFact = GetFactory();
828 						SfxFilterMatcher aMatcher( String::CreateFromAscii(rFact.GetShortName()) );
829 						SfxFilterMatcherIter aIter( &aMatcher );
830                         uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
831                         const SfxFilter* pFlt = aIter.First();
832                         while( pFlt )
833                         {
834                             // --> OD #i117339#
835 //                            if( pFlt && pFlt->IsAllowedAsTemplate() )
836                             if( pFlt && pFlt->IsAllowedAsTemplate() &&
837                                 ( pFlt->GetUserData().EqualsAscii("CXML") ||
838                                   pFlt->GetUserData().EqualsAscii("CXMLV") ) )
839                             {
840                                 const String sWild = ((WildCard&)pFlt->GetWildcard()).GetWildCard();
841                                 xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
842                             }
843 							pFlt = aIter.Next();
844                         }
845                         sal_Bool bWeb = 0 != dynamic_cast< SwWebDocShell *>( this );
846                         const SfxFilter *pOwnFlt =
847                                 SwDocShell::Factory().GetFilterContainer()->
848                                 GetFilter4FilterName(String::CreateFromAscii("writer8"));
849 
850                         //#b6439685# make sure the default file format is also available
851                         if(bWeb)
852                         {
853                             const String sWild = ((WildCard&)pOwnFlt->GetWildcard()).GetWildCard();
854                             xFltMgr->appendFilter( pOwnFlt->GetUIName(), sWild );
855                         }
856 
857                         bool bError = false;
858                         //#b6439685# catch expception if wrong filter is selected - should not happen anymore
859                         try
860                         {
861                             xFltMgr->setCurrentFilter( pOwnFlt->GetUIName() );
862                         }
863                         catch( const uno::Exception& )
864                         {
865                             bError = true;
866                         }
867 
868                         if( !bError && ERRCODE_NONE == aDlgHelper.Execute() )
869                         {
870                             aFileName = xFP->getFiles().getConstArray()[0];
871                         }
872                     }
873                     else if( RET_OK == nRet)
874                     {
875                         aFileName = pNewFileDlg->GetTemplateFileName();
876                     }
877 
878                     nFlags = pNewFileDlg->GetTemplateFlags();
879                     rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) );
880                     rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, (long) nFlags ) );
881                     delete pNewFileDlg;
882                 }
883 
884                 if( aFileName.Len() )
885                 {
886                     SwgReaderOption aOpt;
887                     aOpt.SetTxtFmts(    bText = (0 != (nFlags&SFX_LOAD_TEXT_STYLES) ));
888                     aOpt.SetFrmFmts(    bFrame = (0 != (nFlags&SFX_LOAD_FRAME_STYLES)));
889                     aOpt.SetPageDescs(  bPage = (0 != (nFlags&SFX_LOAD_PAGE_STYLES )));
890                     aOpt.SetNumRules(   bNum = (0 != (nFlags&SFX_LOAD_NUM_STYLES  )));
891                     //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge!
892                     bMerge = 0 != (nFlags&SFX_MERGE_STYLES);
893                     aOpt.SetMerge( !bMerge );
894 
895 					SetError( LoadStylesFromFile( aFileName, aOpt, sal_False ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
896                     if ( !GetError() )
897                         rReq.Done();
898                 }
899             }
900 			break;
901 			case SID_SOURCEVIEW:
902 			{
903 				SfxViewShell* pViewShell = GetView()
904 											? (SfxViewShell*)GetView()
905 											: SfxViewShell::Current();
906 				SfxViewFrame*  pViewFrm = pViewShell->GetViewFrame();
907                 SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell );
908 				if(!pSrcView)
909 				{
910                     // 3 possible state:
911                     // 1 - file unsaved -> save as HTML
912                     // 2 - file modified and HTML filter active -> save
913                     // 3 - file saved in non-HTML -> QueryBox to save as HTML
914                     const SfxFilter* pHtmlFlt =
915                                     SwIoSystem::GetFilterOfFormat(
916                                         String::CreateFromAscii("HTML"),
917                                         SwWebDocShell::Factory().GetFilterContainer() );
918                     sal_Bool bLocalHasName = HasName();
919                     if(bLocalHasName)
920                     {
921                         //check for filter type
922                         const SfxFilter* pFlt = GetMedium()->GetFilter();
923                         if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData())
924                         {
925                             QueryBox aQuery(&pViewFrm->GetWindow(), SW_RES(MSG_SAVEAS_HTML_QUERY));
926                             if(RET_YES == aQuery.Execute())
927                                 bLocalHasName = sal_False;
928                             else
929                                 break;
930                         }
931                     }
932                     if(!bLocalHasName)
933 					{
934                         FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
935                         aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() );
936                         aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() );
937 	                    if( ERRCODE_NONE != aDlgHelper.Execute())
938                         {
939                             break;
940                         }
941                         String sPath = aDlgHelper.GetPath();
942                         SfxStringItem aName(SID_FILE_NAME, sPath);
943                         SfxStringItem aFilter(SID_FILTER_NAME, pHtmlFlt->GetName());
944                         const SfxBoolItem* pBool = (const SfxBoolItem*)
945 								pViewFrm->GetDispatcher()->Execute(
946                                         SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, &aName, &aFilter, 0L );
947 						if(!pBool || !pBool->GetValue())
948                             break;
949 					}
950 				}
951 #ifdef DBG_UTIL
952 				{
953                     sal_Bool bWeb = 0 != dynamic_cast<SwWebDocShell*>(this);
954 					DBG_ASSERT(bWeb == sal_True, "SourceView nur in der WebDocShell");
955 				}
956 #endif
957 				// die SourceView ist fuer die SwWebDocShell die 1
958 				sal_uInt16 nSlot = SID_VIEWSHELL1;
959 				sal_Bool bSetModified = sal_False;
960 				SfxPrinter* pSavePrinter = 0;
961 				if( 0 != pSrcView)
962 				{
963                     SfxPrinter* pTemp = GetDoc()->getPrinter( false );
964 					if(pTemp)
965 						pSavePrinter = new SfxPrinter(*pTemp);
966 					bSetModified = IsModified() || pSrcView->IsModified();
967 					if(pSrcView->IsModified()||pSrcView->HasSourceSaved())
968 					{
969 						utl::TempFile aTempFile;
970 						aTempFile.EnableKillingFile();
971 						pSrcView->SaveContent(aTempFile.GetURL());
972 						bDone = sal_True;
973 						SvxMacro aMac(aEmptyStr, aEmptyStr, STARBASIC);
974                         SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC ), aMac, this);
975 						SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC ), aMac, this);
976 						SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC ), 	aMac, this);
977 						SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC ), aMac, this);
978 						ReloadFromHtml(aTempFile.GetURL(), pSrcView);
979 						nSlot = 0;
980 					}
981 					else
982 					{
983 						nSlot = SID_VIEWSHELL0;
984 					}
985 				}
986 /*	 OS 10.04.97 14.20: Im Web-Writer gibt es keinen Unterschied zwischen
987 						Export in den SourceMode und dem Speichern des Docs
988 				else if(IsModified())
989 				{
990 					sal_uInt16 nRet = QueryBox( SFX_APPWINDOW ,SW_RES(MSG_SAVE_HTML_QUERY)).Execute();
991 					if(RET_YES == nRet)
992 					{
993 						S F X _DISPATCHER().Execute(SID_SAVEDOC,
994 									SFX_CALLMODE_SYNCHRON);
995 						// der ReturnValue von SID_SAVEDOC ist etwas schwer verstaendlich
996 						if(IsModified())
997 							nSlot = 0;
998 					}
999 					else if( RET_CANCEL == nRet )
1000 					{
1001 						nSlot = 0;
1002 					}
1003 				}*/
1004 				if(nSlot)
1005 					pViewFrm->GetDispatcher()->Execute(nSlot, SFX_CALLMODE_SYNCHRON);
1006 				if(bSetModified)
1007 					GetDoc()->SetModified();
1008 				if(pSavePrinter)
1009 				{
1010                     GetDoc()->setPrinter( pSavePrinter, true, true);
1011 					//pSavePrinter darf nicht wieder geloescht werden
1012 				}
1013 				pViewFrm->GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW, nSlot == SID_VIEWSHELL2));
1014                 pViewFrm->GetBindings().Invalidate( SID_NEWWINDOW );
1015 				pViewFrm->GetBindings().Invalidate( SID_BROWSER_MODE );
1016 				pViewFrm->GetBindings().Invalidate( FN_PRINT_LAYOUT );
1017 			}
1018 			break;
1019 			case SID_GET_COLORTABLE:
1020 			{
1021 				SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
1022 				XColorTable* pTable = pColItem->GetColorTable();
1023 				rReq.SetReturnValue(OfaPtrItem(SID_GET_COLORTABLE, pTable));
1024 			}
1025 			break;
1026 		case FN_ABSTRACT_STARIMPRESS:
1027 		case FN_ABSTRACT_NEWDOC:
1028 		{
1029             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1030             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
1031 
1032             AbstractSwInsertAbstractDlg* pDlg = pFact->CreateSwInsertAbstractDlg(0, DLG_INSERT_ABSTRACT );
1033             DBG_ASSERT(pDlg, "Dialogdiet fail!");
1034 			if(RET_OK == pDlg->Execute())
1035 			{
1036 				sal_uInt8 nLevel = pDlg->GetLevel();
1037 				sal_uInt8 nPara = pDlg->GetPara();
1038 				SwDoc* pSmryDoc = new SwDoc();
1039 				SfxObjectShellLock xDocSh( new SwDocShell( pSmryDoc, SFX_CREATE_MODE_STANDARD));
1040 				xDocSh->DoInitNew( 0 );
1041 
1042 				sal_Bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
1043 				pDoc->Summary( pSmryDoc, nLevel, nPara, bImpress );
1044 				if( bImpress )
1045 				{
1046 					WriterRef xWrt;
1047                     // mba: looks as if relative URLs don't make sense here
1048                     ::GetRTFWriter( aEmptyStr, String(), xWrt );
1049 					SvMemoryStream *pStrm = new SvMemoryStream();
1050 					pStrm->SetBufferSize( 16348 );
1051 					SwWriter aWrt( *pStrm, *pSmryDoc );
1052 					ErrCode eErr = aWrt.Write( xWrt );
1053 					if( !ERRCODE_TOERROR( eErr ) )
1054 					{
1055                         uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1056                         uno::Reference< frame::XDispatchProvider > xProv(
1057 							xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
1058 						if ( xProv.is() )
1059 						{
1060 							::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( "SendOutlineToImpress" );
1061                             uno::Reference< frame::XDispatchHelper > xHelper(
1062 								xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1063 							if ( xHelper.is() )
1064 							{
1065 								pStrm->Seek( STREAM_SEEK_TO_END );
1066 								*pStrm << '\0';
1067 								pStrm->Seek( STREAM_SEEK_TO_BEGIN );
1068 
1069 								// Transfer ownership of stream to a lockbytes object
1070 								SvLockBytes aLockBytes( pStrm, sal_True );
1071 								SvLockBytesStat aStat;
1072 								if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
1073 								{
1074 									sal_uInt32 nLen = aStat.nSize;
1075 									sal_uLong nRead = 0;
1076                                     uno::Sequence< sal_Int8 > aSeq( nLen );
1077 									aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
1078 
1079                                     uno::Sequence< beans::PropertyValue > aArgs(1);
1080 									aArgs[0].Name = ::rtl::OUString::createFromAscii("RtfOutline");
1081 									aArgs[0].Value <<= aSeq;
1082 									xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aArgs );
1083 								}
1084 							}
1085 						}
1086 					}
1087 					else
1088 						ErrorHandler::HandleError(ErrCode( eErr ));
1089 				}
1090 				else
1091 				{
1092 					// Neues Dokument erzeugen.
1093                     SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, 0 );
1094                     SwView      *pCurrView = (SwView*) pFrame->GetViewShell();
1095 
1096 					// Dokumenttitel setzen
1097 					String aTmp( SW_RES(STR_ABSTRACT_TITLE) );
1098 					aTmp += GetTitle();
1099 					xDocSh->SetTitle( aTmp );
1100                     pCurrView->GetWrtShell().SetNewDoc();
1101 					pFrame->Show();
1102 					pSmryDoc->SetModified();
1103 				}
1104 
1105 			}
1106 			delete pDlg;
1107 		}
1108 		break;
1109 		case FN_OUTLINE_TO_CLIPBOARD:
1110 		case FN_OUTLINE_TO_IMPRESS:
1111 			{
1112 				sal_Bool bEnable = IsEnableSetModified();
1113 				EnableSetModified( sal_False );
1114 				WriterRef xWrt;
1115                 // mba: looks as if relative URLs don't make sense here
1116                 ::GetRTFWriter( 'O', String(), xWrt );
1117 				SvMemoryStream *pStrm = new SvMemoryStream();
1118 				pStrm->SetBufferSize( 16348 );
1119 				SwWriter aWrt( *pStrm, *GetDoc() );
1120 				ErrCode eErr = aWrt.Write( xWrt );
1121 				EnableSetModified( bEnable );
1122 				if( !ERRCODE_TOERROR( eErr ) )
1123 				{
1124 					pStrm->Seek( STREAM_SEEK_TO_END );
1125 					*pStrm << '\0';
1126 					pStrm->Seek( STREAM_SEEK_TO_BEGIN );
1127 					if ( nWhich == FN_OUTLINE_TO_IMPRESS )
1128 					{
1129                         uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1130                         uno::Reference< frame::XDispatchProvider > xProv(
1131 							xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
1132 						if ( xProv.is() )
1133 						{
1134 							::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( "SendOutlineToImpress" );
1135                             uno::Reference< frame::XDispatchHelper > xHelper(
1136 								xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1137 							if ( xHelper.is() )
1138 							{
1139 								pStrm->Seek( STREAM_SEEK_TO_END );
1140 								*pStrm << '\0';
1141 								pStrm->Seek( STREAM_SEEK_TO_BEGIN );
1142 
1143 								// Transfer ownership of stream to a lockbytes object
1144 								SvLockBytes aLockBytes( pStrm, sal_True );
1145 								SvLockBytesStat aStat;
1146 								if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
1147 								{
1148 									sal_uInt32 nLen = aStat.nSize;
1149 									sal_uLong nRead = 0;
1150                                     uno::Sequence< sal_Int8 > aSeq( nLen );
1151 									aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
1152 
1153                                     uno::Sequence< beans::PropertyValue > aArgs(1);
1154 									aArgs[0].Name = ::rtl::OUString::createFromAscii("RtfOutline");
1155 									aArgs[0].Value <<= aSeq;
1156 									xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aArgs );
1157 								}
1158 							}
1159 						}
1160 					}
1161 					else
1162 					{
1163 						TransferDataContainer* pClipCntnr =
1164 													new TransferDataContainer;
1165 						STAR_REFERENCE( datatransfer::XTransferable )
1166 														xRef( pClipCntnr );
1167 
1168 						pClipCntnr->CopyAnyData( FORMAT_RTF, (sal_Char*)
1169                                     pStrm->GetData(), pStrm->GetEndOfData() );
1170 						pClipCntnr->CopyToClipboard(
1171 							GetView()? (Window*)&GetView()->GetEditWin() : 0 );
1172 						delete pStrm;
1173 					}
1174 				}
1175 				else
1176 					ErrorHandler::HandleError(ErrCode( eErr ));
1177 			}
1178 			break;
1179 			case SID_SPELLCHECKER_CHANGED:
1180 				//! sal_False, sal_True, sal_True is on the save side but a probably overdone
1181 				SW_MOD()->CheckSpellChanges(sal_False, sal_True, sal_True, sal_False );
1182 			break;
1183 
1184         case SID_MAIL_PREPAREEXPORT:
1185         {
1186             //pWrtShell is not set in page preview
1187             if(pWrtShell)
1188                 pWrtShell->StartAllAction();
1189             pDoc->UpdateFlds( NULL, false );
1190             pDoc->EmbedAllLinks();
1191             pDoc->RemoveInvisibleContent();
1192             if(pWrtShell)
1193                 pWrtShell->EndAllAction();
1194         }
1195         break;
1196 
1197         case SID_MAIL_EXPORT_FINISHED:
1198         {
1199                 if(pWrtShell)
1200                     pWrtShell->StartAllAction();
1201                 //try to undo the removal of invisible content
1202                 pDoc->RestoreInvisibleContent();
1203                 if(pWrtShell)
1204                     pWrtShell->EndAllAction();
1205         }
1206         break;
1207 		case FN_NEW_HTML_DOC:
1208 		case FN_NEW_GLOBAL_DOC:
1209 			{
1210 				bDone = sal_False;
1211                 sal_Bool bCreateHtml = FN_NEW_HTML_DOC == nWhich;
1212 
1213 				sal_Bool bCreateByOutlineLevel = false;		//#outline level,add by zhaojianwei
1214 				sal_Int32  nTemplateOutlineLevel = 0 ;		//#outline level,add by zhaojianwei
1215 
1216                 String aFileName, aTemplateName;
1217                 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich, sal_False, &pItem ) )
1218                 {
1219                     aFileName = ((const SfxStringItem*)pItem)->GetValue();
1220                     SFX_ITEMSET_ARG( pArgs, pTemplItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False );
1221                     if ( pTemplItem )
1222                         aTemplateName = pTemplItem->GetValue();
1223                 }
1224                 bool bError = false;
1225                 if ( !aFileName.Len() )
1226                 {
1227                     FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, 0 );
1228 
1229                     const sal_Int16 nControlIds[] = {
1230                         CommonFilePickerElementIds::PUSHBUTTON_OK,
1231                         CommonFilePickerElementIds::PUSHBUTTON_CANCEL,
1232                         CommonFilePickerElementIds::LISTBOX_FILTER,
1233                         CommonFilePickerElementIds::CONTROL_FILEVIEW,
1234                         CommonFilePickerElementIds::EDIT_FILEURL,
1235                         ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION,
1236                         ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1237                         0
1238                     };
1239 
1240                     const char* aHTMLHelpIds[] =
1241                     {
1242                          HID_SEND_HTML_CTRL_PUSHBUTTON_OK,
1243                          HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL,
1244                          HID_SEND_HTML_CTRL_LISTBOX_FILTER,
1245                          HID_SEND_HTML_CTRL_CONTROL_FILEVIEW,
1246                          HID_SEND_HTML_CTRL_EDIT_FILEURL,
1247                          HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION,
1248                          HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE,
1249                          ""
1250                     };
1251 
1252                     const char* aMasterHelpIds[] =
1253                     {
1254                          HID_SEND_MASTER_CTRL_PUSHBUTTON_OK,
1255                          HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL,
1256                          HID_SEND_MASTER_CTRL_LISTBOX_FILTER,
1257                          HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW,
1258                          HID_SEND_MASTER_CTRL_EDIT_FILEURL,
1259                          HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION,
1260                          HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE,
1261                          ""
1262                     };
1263 
1264                     const char** pHelpIds = bCreateHtml ? aHTMLHelpIds : aMasterHelpIds;
1265                     aDlgHelper.SetControlHelpIds( nControlIds, pHelpIds );
1266                     uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
1267 
1268                     const SfxFilter* pFlt;
1269                     sal_uInt16 nStrId;
1270 
1271                     if( bCreateHtml )
1272                     {
1273                         // fuer HTML gibts es nur einen Filter!!
1274                         pFlt = SwIoSystem::GetFilterOfFormat(
1275                                 String::CreateFromAscii("HTML"),
1276                                 SwWebDocShell::Factory().GetFilterContainer() );
1277                         nStrId = STR_LOAD_HTML_DOC;
1278                     }
1279                     else
1280                     {
1281                         // Fuer Global-Dokumente bieten wir jetzt auch nur
1282                         // noch den aktuellen an.
1283                         pFlt = SwGlobalDocShell::Factory().GetFilterContainer()->
1284                                     GetFilter4Extension( String::CreateFromAscii("odm")  );
1285                         nStrId = STR_LOAD_GLOBAL_DOC;
1286                     }
1287 
1288                     if( pFlt )
1289                     {
1290                         uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
1291                         const String sWild = ((WildCard&)pFlt->GetWildcard()).GetWildCard();
1292                         xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
1293                         try
1294                         {
1295                             xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
1296                         }
1297                         catch( const uno::Exception& )
1298                         {
1299                             bError = true;
1300                         }
1301                     }
1302                     if(!bError)
1303                     {
1304                         uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY);
1305 
1306 				//#removed by zhaojianwei
1307 
1308         //             const sal_uInt16 nCount = pDoc->GetTxtFmtColls()->Count();
1309         //                Sequence<OUString> aListBoxEntries(nCount);
1310         //                OUString* pEntries = aListBoxEntries.getArray();
1311         //                sal_Int32 nIdx = 0;
1312         //                sal_Int16 nSelect = 0;
1313         //                OUString sStartTemplate;
1314         //                SwTxtFmtColl *pFnd = 0, *pAny = 0;
1315         //                for(sal_uInt16 i = 0; i < nCount; ++i)
1316         //                {
1317         //                    SwTxtFmtColl &rTxtColl =
1318         //                                    *pDoc->GetTxtFmtColls()->GetObject( i );
1319         //                    if( !rTxtColl.IsDefault() && rTxtColl.IsAtDocNodeSet() )
1320         //                    {
1321         //                        //if( MAXLEVEL >= rTxtColl.GetOutlineLevel() && ( !pFnd ||			//#outline level,zhaojianwei
1322 								//if(  rTxtColl.IsAssignedToListLevelOfOutlineStyle()  && ( !pFnd ||	//<-end,zhaojianwei
1323         //                            pFnd->GetAssignedOutlineStyleLevel() > rTxtColl.GetAssignedOutlineStyleLevel() ))
1324         //                        {
1325         //                                nSelect = (sal_Int16)nIdx;
1326         //                                pFnd = &rTxtColl;
1327         //                                sStartTemplate = rTxtColl.GetName();
1328         //                        }
1329         //                        else if( !pAny )
1330         //                            pAny = &rTxtColl;
1331         //                        //pEntries[nIdx++] = rTxtColl.GetName();			//#outline level,remove by zhaojianwei
1332         //                        pEntries[nIdx++] = sStyles + rTxtColl.GetName();	//#outline level,add by zhaojianwei
1333         //                    }
1334         //                }
1335         //                if(!sStartTemplate.getLength() && pAny)
1336         //                    sStartTemplate = pAny->GetName();
1337         //                aListBoxEntries.realloc(nIdx);
1338 				//<-end,zhaojianwei
1339 
1340 
1341 					//#outline level,add by zhaojianwei
1342 					/////////////////////////////////////////////////////////////////////
1343 
1344 						bool	bOutline[MAXLEVEL] = {false};
1345 						const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
1346 						if( rOutlNds.Count() )
1347 						{
1348 							int nLevel;
1349 							for(sal_uInt16 n = 0; n < rOutlNds.Count(); ++n )
1350 								if( ( nLevel = rOutlNds[n]->GetTxtNode()->GetAttrOutlineLevel()) > 0 &&
1351 									! bOutline[nLevel-1] )
1352 								{
1353 									bOutline[nLevel-1] = true;
1354 								}
1355 						}
1356 
1357 						const sal_uInt16 nStyleCount = pDoc->GetTxtFmtColls()->Count();
1358 						Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount);
1359 						OUString* pEntries = aListBoxEntries.getArray();
1360 						sal_Int32	nIdx = 0 ;
1361 
1362 						OUString	sOutline( SW_RESSTR(STR_FDLG_OUTLINE_LEVEL) );
1363 						for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
1364 						{
1365 							if( bOutline[i] )
1366 								pEntries[nIdx++] = sOutline + String::CreateFromInt32( i+1 );
1367 						}
1368 
1369 						OUString	sStyle( SW_RESSTR(STR_FDLG_STYLE) );
1370 						for(sal_uInt16 i = 0; i < nStyleCount; ++i)
1371 						{
1372 							SwTxtFmtColl &rTxtColl =
1373 								*pDoc->GetTxtFmtColls()->GetObject( i );
1374 							if( !rTxtColl.IsDefault() && rTxtColl.IsAtDocNodeSet() )
1375 							{
1376 								pEntries[nIdx++] = sStyle + rTxtColl.GetName();
1377 							}
1378 						}
1379 
1380 						aListBoxEntries.realloc(nIdx);
1381 						sal_Int16 nSelect = 0;
1382  					/////////////////////////////////////////////////////////////////////
1383 					//<-end,zhaojianwei
1384 
1385 						try
1386                         {
1387                             Any aTemplates(&aListBoxEntries, ::getCppuType(&aListBoxEntries));
1388 
1389                             xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1390                                 ListboxControlActions::ADD_ITEMS , aTemplates );
1391                             Any aSelectPos(&nSelect, ::getCppuType(&nSelect));
1392                             xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1393                                 ListboxControlActions::SET_SELECT_ITEM, aSelectPos );
1394                             xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1395                                                     String(SW_RES( STR_FDLG_TEMPLATE_NAME )));
1396                         }
1397                         catch(Exception& )
1398                         {
1399                             DBG_ERROR("control acces failed");
1400                         }
1401 
1402                         xFP->setTitle( SW_RESSTR( nStrId ));
1403                         SvtPathOptions aPathOpt;
1404                         xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
1405                         if( ERRCODE_NONE == aDlgHelper.Execute())
1406                         {
1407                             aFileName = xFP->getFiles().getConstArray()[0];
1408                             Any aTemplateValue = xCtrlAcc->getValue(
1409                                 ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1410                                 ListboxControlActions::GET_SELECTED_ITEM );
1411                             OUString sTmpl;
1412                             aTemplateValue >>= sTmpl;
1413 							//aTemplateName = sTmpl;	//#outline level,removed by zhaojianwei
1414 							//#outline level,add by zhaojianwei
1415 
1416 							sal_Int32 nColonPos = sTmpl.indexOf( sal_Unicode(':') );
1417 							OUString sPrefix = sTmpl.copy( 0L, nColonPos );
1418 							if( sPrefix.equalsAscii("Style"))
1419 							{
1420 								aTemplateName = sTmpl.copy( 7L );	//get string behind "Style: "
1421 							}
1422 							else if( sPrefix.equalsAscii("Outline"))
1423 							{
1424 								nTemplateOutlineLevel =	( sTmpl.copy( 15L )).toInt32();	//get string behind "Outline: Leve  ";
1425 								bCreateByOutlineLevel = true;
1426 							}
1427 							//<-end,zhaojianwei
1428 
1429                             if ( aFileName.Len() )
1430                             {
1431                                 rReq.AppendItem( SfxStringItem( nWhich, aFileName ) );
1432                                 if( aTemplateName.Len() )
1433                                     rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aTemplateName ) );
1434                             }
1435                         }
1436                     }
1437                 }
1438 
1439 				//const SwTxtFmtColl* pSplitColl = 0;		//#outline level,removed by zhaojianwei
1440     //            if ( aTemplateName.Len() )
1441     //                pSplitColl = pDoc->FindTxtFmtCollByName(aTemplateName);
1442 															//<-end,zhaojianwei
1443 				if( aFileName.Len() )
1444 				{
1445 					if( PrepareClose( sal_False ) )
1446 					{
1447 						SwWait aWait( *this, sal_True );
1448 
1449 						//bDone = bCreateHtml			//#outline level,removed by zhaojianwei
1450 						//	? pDoc->GenerateHTMLDoc( aFileName, pSplitColl )
1451 						//	: pDoc->GenerateGlobalDoc( aFileName, pSplitColl );
1452 						if ( bCreateByOutlineLevel )	//add by zhaojianwei
1453 						{
1454 							bDone = bCreateHtml			//#outline level,removed by zhaojianwei
1455 								? pDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel )
1456 								: pDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel );
1457 						}
1458 						else
1459 						{
1460 							const SwTxtFmtColl* pSplitColl = 0;
1461 							if ( aTemplateName.Len() )
1462 								pSplitColl = pDoc->FindTxtFmtCollByName(aTemplateName);
1463 							bDone = bCreateHtml			//#outline level,removed by zhaojianwei
1464 								? pDoc->GenerateHTMLDoc( aFileName, pSplitColl )
1465 								: pDoc->GenerateGlobalDoc( aFileName, pSplitColl );
1466 						}
1467 						//<-end,zhaojianwei
1468 						if( bDone )
1469 						{
1470 							SfxStringItem aName( SID_FILE_NAME, aFileName );
1471 							SfxStringItem aReferer( SID_REFERER, aEmptyStr );
1472                             SfxViewShell* pViewShell = SfxViewShell::GetFirst();
1473                             while(pViewShell)
1474                             {
1475                                 //search for the view that created the call
1476                                 if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher())
1477                                 {
1478                                     SfxFrameItem* pFrameItem = new SfxFrameItem( SID_DOCFRAME,
1479                                                         pViewShell->GetViewFrame() );
1480                                     SfxDispatcher* pDispatch = pViewShell->GetDispatcher();
1481                                     pDispatch->Execute(
1482                                             SID_OPENDOC,
1483                                             SFX_CALLMODE_ASYNCHRON,
1484                                             &aName,
1485                                             &aReferer,
1486                                             pFrameItem, 0L );
1487 
1488                                     delete pFrameItem;
1489                                     break;
1490                                 }
1491                                 pViewShell = SfxViewShell::GetNext(*pViewShell);
1492                             }
1493                         }
1494 					}
1495 					if( !bDone && !rReq.IsAPI() )
1496 					{
1497 						InfoBox( 0, SW_RESSTR( STR_CANTCREATE )).Execute();
1498 					}
1499 				}
1500 			}
1501 			rReq.SetReturnValue(SfxBoolItem( nWhich, bDone ));
1502 			if (bDone)
1503 				rReq.Done();
1504 			else
1505 				rReq.Ignore();
1506 			break;
1507 
1508 		case SID_ATTR_YEAR2000:
1509 			if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich , sal_False, &pItem ))
1510 			{
1511 				DBG_ASSERT(pItem->ISA(SfxUInt16Item), "falsches Item");
1512 				sal_uInt16 nYear2K = ((SfxUInt16Item*)pItem)->GetValue();
1513 				//ueber Views iterieren und den State an den FormShells setzen
1514 
1515 				SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this );
1516 				SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
1517                 SwView* pCurrView = dynamic_cast< SwView* >( pViewShell );
1518                 while(pCurrView)
1519 				{
1520                     FmFormShell* pFormShell = pCurrView->GetFormShell();
1521 					if(pFormShell)
1522 						pFormShell->SetY2KState(nYear2K);
1523 					pVFrame = SfxViewFrame::GetNext( *pVFrame, this );
1524 					pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
1525                     pCurrView = dynamic_cast<SwView*>( pViewShell );
1526 				}
1527 				pDoc->GetNumberFormatter(sal_True)->SetYear2000(nYear2K);
1528 			}
1529 		break;
1530 
1531 		default: DBG_ERROR("falscher Dispatcher");
1532 	}
1533 }
1534 
1535 
1536 /*--------------------------------------------------------------------
1537 	Beschreibung:
1538  --------------------------------------------------------------------*/
1539 
1540 long SwDocShell::DdeGetData( const String& rItem, const String& rMimeType,
1541                                 uno::Any & rValue )
1542 {
1543 	return pDoc->GetData( rItem, rMimeType, rValue );
1544 }
1545 
1546 
1547 /*--------------------------------------------------------------------
1548 	Beschreibung:
1549  --------------------------------------------------------------------*/
1550 
1551 long SwDocShell::DdeSetData( const String& rItem, const String& rMimeType,
1552                             const uno::Any & rValue )
1553 {
1554 	return pDoc->SetData( rItem, rMimeType, rValue );
1555 }
1556 
1557 
1558 /*--------------------------------------------------------------------
1559 	Beschreibung:
1560  --------------------------------------------------------------------*/
1561 
1562 ::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const String& rItem )
1563 {
1564 	return pDoc->CreateLinkSource( rItem );
1565 }
1566 
1567 /*--------------------------------------------------------------------
1568 	Beschreibung:
1569  --------------------------------------------------------------------*/
1570 
1571 void SwDocShell::FillClass( SvGlobalName * pClassName,
1572 								   sal_uInt32 * pClipFormat,
1573 								   String * /*pAppName*/,
1574 								   String * pLongUserName,
1575                                    String * pUserName,
1576                                    sal_Int32 nVersion,
1577                                    sal_Bool bTemplate /* = sal_False */) const
1578 {
1579 	if (nVersion == SOFFICE_FILEFORMAT_60)
1580 	{
1581 		*pClassName		= SvGlobalName( SO3_SW_CLASSID_60 );
1582 		*pClipFormat	= SOT_FORMATSTR_ID_STARWRITER_60;
1583 		*pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE);
1584 	}
1585 	else if (nVersion == SOFFICE_FILEFORMAT_8)
1586 	{
1587 		*pClassName		= SvGlobalName( SO3_SW_CLASSID_60 );
1588         *pClipFormat	= bTemplate ? SOT_FORMATSTR_ID_STARWRITER_8_TEMPLATE : SOT_FORMATSTR_ID_STARWRITER_8;
1589 		*pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE);
1590 	}
1591 
1592 	*pUserName = SW_RESSTR(STR_HUMAN_SWDOC_NAME);
1593 }
1594 
1595 
1596 /*--------------------------------------------------------------------
1597 	Beschreibung:
1598  --------------------------------------------------------------------*/
1599 
1600 void SwDocShell::SetModified( sal_Bool bSet )
1601 {
1602     SfxObjectShell::SetModified( bSet );
1603 	if( IsEnableSetModified())
1604 	{
1605 		 if (!pDoc->IsInCallModified() )
1606 		 {
1607 			EnableSetModified( sal_False );
1608 			if( bSet )
1609 			{
1610 				sal_Bool bOld = pDoc->IsModified();
1611 				pDoc->SetModified();
1612 				if( !bOld )
1613                 {
1614                     pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1615                 }
1616 			}
1617 			else
1618 				pDoc->ResetModified();
1619 
1620 			EnableSetModified( sal_True );
1621 		 }
1622 
1623 		UpdateChildWindows();
1624 		Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED));
1625 	}
1626 }
1627 
1628 /*--------------------------------------------------------------------
1629 	Beschreibung:
1630  --------------------------------------------------------------------*/
1631 
1632 void SwDocShell::UpdateChildWindows()
1633 {
1634 	// Flddlg ggf neu initialisieren (z.B. fuer TYP_SETVAR)
1635 	if(!GetView())
1636 		return;
1637 	SfxViewFrame* pVFrame = GetView()->GetViewFrame();
1638 	SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame->
1639 			GetChildWindow( SwFldDlgWrapper::GetChildWindowId() );
1640 	if( pWrp )
1641 		pWrp->ReInitDlg( this );
1642 
1643 	// RedlineDlg ggf neu initialisieren
1644 	SwRedlineAcceptChild *pRed = (SwRedlineAcceptChild*)pVFrame->
1645 			GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() );
1646 	if( pRed )
1647 		pRed->ReInitDlg( this );
1648 }
1649 
1650 /*--------------------------------------------------------------------
1651 	Beschreibung:
1652  --------------------------------------------------------------------*/
1653 // --> OD 2005-08-02 #i48748#
1654 class SwReloadFromHtmlReader : public SwReader
1655 {
1656     public:
1657         SwReloadFromHtmlReader( SfxMedium& _rTmpMedium,
1658                                 const String& _rFilename,
1659                                 SwDoc* _pDoc )
1660             : SwReader( _rTmpMedium, _rFilename, _pDoc )
1661         {
1662             SetBaseURL( _rFilename );
1663         }
1664 };
1665 // <--
1666 void SwDocShell::ReloadFromHtml( const String& rStreamName, SwSrcView* pSrcView )
1667 {
1668 	sal_Bool bModified = IsModified();
1669 
1670 	// MIB 23.6.97: Die HTTP-Header-Felder muessen geloescht werden,
1671 	// sonst gibt es welche aus Meta-Tags hinter doppelt und dreifach.
1672 	ClearHeaderAttributesForSourceViewHack();
1673 
1674 	// MIB 24.07.97: Das Dokument-Basic muss auch noch d'ran glauben ...
1675 	SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
1676 	//#59620# HasBasic() zeigt an, dass es schon einen BasicManager an der DocShell
1677 	//			gibt. Der wurde im HTML-Import immer angelegt, wenn Macros im Quelltext
1678 	//			vorhanden sind.
1679 	if( pHtmlOptions && pHtmlOptions->IsStarBasic() && HasBasic())
1680 	{
1681 		BasicManager *pBasicMan = GetBasicManager();
1682 		if( pBasicMan && (pBasicMan != SFX_APP()->GetBasicManager()) )
1683 		{
1684 			sal_uInt16 nLibCount = pBasicMan->GetLibCount();
1685 			while( nLibCount )
1686 			{
1687 				StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount );
1688 				if( pBasic )
1689 				{
1690 					// Die IDE benachrichtigen
1691                     SfxUsrAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( GetModel() ) );
1692                     String aLibName( pBasic->GetName() );
1693                     SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
1694 					pSrcView->GetViewFrame()->GetDispatcher()->Execute(
1695 											SID_BASICIDE_LIBREMOVED,
1696 											SFX_CALLMODE_SYNCHRON,
1697 											&aShellItem, &aLibNameItem, 0L );
1698 
1699 					// Aus der Standard-Lib werden nur die Module geloescht
1700 					if( nLibCount )
1701 						pBasicMan->RemoveLib( nLibCount, sal_True );
1702 					else
1703 						pBasic->Clear();
1704 				}
1705 			}
1706 
1707 			ASSERT( pBasicMan->GetLibCount() <= 1,
1708 					"Loschen des Basics hat nicht geklappt" );
1709 		}
1710 	}
1711     sal_Bool bWasBrowseMode = pDoc->get(IDocumentSettingAccess::BROWSE_MODE);
1712 	RemoveLink();
1713 
1714 	//jetzt muss auch das UNO-Model ueber das neue Doc informiert werden #51535#
1715 	uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY);
1716 	text::XTextDocument* pxDoc = xDoc.get();
1717 	((SwXTextDocument*)pxDoc)->InitNewDoc();
1718 
1719 	AddLink();
1720 	//#116402# update font list when new document is created
1721 	UpdateFontList();
1722 	pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bWasBrowseMode);
1723 	pSrcView->SetPool(&GetPool());
1724 
1725 
1726 	const String& rMedname = GetMedium()->GetName();
1727 
1728 	// fix #51032#: Die HTML-Vorlage muss noch gesetzt werden
1729 	SetHTMLTemplate( *GetDoc() );	//Styles aus HTML.vor
1730 
1731 	SfxViewShell* pViewShell = GetView() ? (SfxViewShell*)GetView()
1732 										 : SfxViewShell::Current();
1733 	SfxViewFrame*  pViewFrm = pViewShell->GetViewFrame();
1734 	pViewFrm->GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_SYNCHRON );
1735 
1736 	SubInitNew();
1737 
1738 	SfxMedium aMed( rStreamName, STREAM_READ, sal_False );
1739     // --> OD 2005-08-01 #i48748# - use class <SwReloadFromHtmlReader>, because
1740     // the base URL has to be set to the filename of the document <rMedname>
1741     // and not to the base URL of the temporary file <aMed> in order to get
1742     // the URLs of the linked graphics correctly resolved.
1743     SwReloadFromHtmlReader aReader( aMed, rMedname, pDoc );
1744     // <--
1745     aReader.Read( *ReadHTML );
1746 
1747     const SwView* pCurrView = GetView();
1748     //in print layout the first page(s) may have been formatted as a mix of browse
1749     //and print layout
1750     if(!bWasBrowseMode && pCurrView)
1751     {
1752         SwWrtShell& rWrtSh = pCurrView->GetWrtShell();
1753         if( rWrtSh.GetLayout())
1754             rWrtSh.CheckBrowseView( sal_True );
1755     }
1756 
1757 
1758 	// MIB 23.6.97: Die HTTP-Header-Attribute wieder in die DokInfo
1759 	// uebernehmen. Die Base-URL ist hier egal, da TLX zum absolutieren die
1760 	// vom Dokument nimmt.
1761 	SetHeaderAttributesForSourceViewHack();
1762 
1763 	if(bModified && !IsReadOnly())
1764 		SetModified();
1765 	else
1766 		pDoc->ResetModified();
1767 }
1768 
1769 sal_uLong SwDocShell::LoadStylesFromFile( const String& rURL,
1770 					SwgReaderOption& rOpt, sal_Bool bUnoCall )
1771 {
1772 	sal_uLong nErr = 0;
1773 
1774 	// Create a URL from filename
1775 	INetURLObject aURLObj( rURL );
1776 	String sURL( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
1777 
1778 	// Filter bestimmen:
1779 //  const SfxFilter* pFlt = SwIoSystem::GetFileFilter( rURL, aEmptyStr );
1780     String sFactory(String::CreateFromAscii(SwDocShell::Factory().GetShortName()));
1781     SfxFilterMatcher aMatcher( sFactory );
1782 
1783 	//#b6445961#  search for filter in WebDocShell, too
1784     SfxMedium aMed( rURL, STREAM_STD_READ, sal_False );
1785     const SfxFilter* pFlt = 0;
1786     aMatcher.DetectFilter( aMed, &pFlt, sal_False, sal_False );
1787     if(!pFlt)
1788     {
1789         String sWebFactory(String::CreateFromAscii(SwWebDocShell::Factory().GetShortName()));
1790         SfxFilterMatcher aWebMatcher( sWebFactory );
1791         aWebMatcher.DetectFilter( aMed, &pFlt, sal_False, sal_False );
1792     }
1793     // --> OD #i117339# - trigger import only for own formats
1794 //    if( aMed.IsStorage() )
1795     bool bImport( false );
1796     {
1797         if ( aMed.IsStorage() )
1798         {
1799             // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat()
1800             // does not work correct (e.g., MS Word 2007 XML Template),
1801             // use workaround provided by MAV.
1802             uno::Reference< embed::XStorage > xStorage = aMed.GetStorage();
1803             if ( xStorage.is() )
1804             {
1805                 // use <try-catch> on retrieving <MediaType> in order to check,
1806                 // if the storage is one of our own ones.
1807                 try
1808                 {
1809                     uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW );
1810                     const ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
1811                     xProps->getPropertyValue( aMediaTypePropName );
1812                     bImport = true;
1813                 }
1814                 catch( const uno::Exception& )
1815                 {
1816                     bImport = false;
1817                 }
1818             }
1819         }
1820     }
1821     if ( bImport )
1822     // <--
1823 	{
1824         DBG_ASSERT((pFlt ? pFlt->GetVersion() : 0) >= SOFFICE_FILEFORMAT_60, "which file version?");
1825         SwRead pRead =  ReadXML;
1826         SwReader* pReader = 0;
1827         SwPaM* pPam = 0;
1828 		// the SW3IO - Reader need the pam/wrtshell, because only then he
1829 		// insert the styles!
1830 		if( bUnoCall )
1831 		{
1832 			SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfContent(), -1 );
1833 			pPam = new SwPaM( aIdx );
1834 			pReader = new SwReader( aMed, rURL, *pPam );
1835 		}
1836 		else
1837         {
1838 			pReader = new SwReader( aMed, rURL, *pWrtShell->GetCrsr() );
1839         }
1840 
1841 		pRead->GetReaderOpt().SetTxtFmts( rOpt.IsTxtFmts() );
1842 		pRead->GetReaderOpt().SetFrmFmts( rOpt.IsFrmFmts() );
1843 		pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() );
1844 		pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() );
1845 		pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() );
1846 
1847         if( bUnoCall )
1848 		{
1849 			UnoActionContext aAction( pDoc );
1850 			nErr = pReader->Read( *pRead );
1851 		}
1852 		else
1853 		{
1854 			pWrtShell->StartAllAction();
1855 			nErr = pReader->Read( *pRead );
1856 			pWrtShell->EndAllAction();
1857 		}
1858         delete pPam;
1859         delete pReader;
1860 	}
1861 
1862     return nErr;
1863 }
1864 
1865 /*--------------------------------------------------------------------
1866     Get a client for an embedded object if possible.
1867  --------------------------------------------------------------------*/
1868 SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef )
1869 {
1870     SfxInPlaceClient* pResult = NULL;
1871 
1872     SwWrtShell* pShell = GetWrtShell();
1873     if ( pShell )
1874     {
1875         pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), (Window*)&pShell->GetView().GetEditWin() );
1876         if ( !pResult )
1877             pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef );
1878     }
1879 
1880     return pResult;
1881 }
1882 
1883