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