xref: /trunk/main/sw/source/core/doc/docglbl.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <unotools/tempfile.hxx>
30cdf0e10cSrcweir #include <svl/urihelper.hxx>
31cdf0e10cSrcweir #include <svl/stritem.hxx>
32cdf0e10cSrcweir #include <svl/eitem.hxx>
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir #include <sfx2/docfile.hxx>
35cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
36cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
37cdf0e10cSrcweir #include <sfx2/bindings.hxx>
38cdf0e10cSrcweir #include <sfx2/request.hxx>
39cdf0e10cSrcweir #include <fmtinfmt.hxx>
40cdf0e10cSrcweir #include <fmtanchr.hxx>
41cdf0e10cSrcweir #include <doc.hxx>
42cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
43cdf0e10cSrcweir #include <docary.hxx>
44cdf0e10cSrcweir #include <pam.hxx>
45cdf0e10cSrcweir #include <ndtxt.hxx>
46cdf0e10cSrcweir #include <docsh.hxx>
47cdf0e10cSrcweir #include <globdoc.hxx>
48cdf0e10cSrcweir #include <shellio.hxx>
49cdf0e10cSrcweir #include <swundo.hxx>       // fuer die UndoIds
50cdf0e10cSrcweir #include <section.hxx>
51cdf0e10cSrcweir #include <doctxm.hxx>
52cdf0e10cSrcweir #include <poolfmt.hxx>
53cdf0e10cSrcweir #include <switerator.hxx>
54cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
55cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
56cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir using namespace ::com::sun::star;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir enum SwSplitDocType
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     SPLITDOC_TO_GLOBALDOC,
63cdf0e10cSrcweir     SPLITDOC_TO_HTML
64cdf0e10cSrcweir };
65cdf0e10cSrcweir 
GenerateGlobalDoc(const String & rPath,const SwTxtFmtColl * pSplitColl)66cdf0e10cSrcweir sal_Bool SwDoc::GenerateGlobalDoc( const String& rPath,
67cdf0e10cSrcweir                                 const SwTxtFmtColl* pSplitColl )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     return SplitDoc( SPLITDOC_TO_GLOBALDOC, rPath, pSplitColl );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //#outline level,add by zhaojianwei
GenerateGlobalDoc(const String & rPath,int nOutlineLevel)73cdf0e10cSrcweir sal_Bool SwDoc::GenerateGlobalDoc( const String& rPath, int nOutlineLevel )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     return SplitDoc( SPLITDOC_TO_GLOBALDOC, rPath, nOutlineLevel );
76cdf0e10cSrcweir }
GenerateHTMLDoc(const String & rPath,int nOutlineLevel)77cdf0e10cSrcweir sal_Bool SwDoc::GenerateHTMLDoc( const String& rPath, int nOutlineLevel )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     return SplitDoc( SPLITDOC_TO_HTML, rPath, nOutlineLevel );
80cdf0e10cSrcweir }
81cdf0e10cSrcweir //<-end,zhaojianwei
82cdf0e10cSrcweir 
GenerateHTMLDoc(const String & rPath,const SwTxtFmtColl * pSplitColl)83cdf0e10cSrcweir sal_Bool SwDoc::GenerateHTMLDoc( const String& rPath,
84cdf0e10cSrcweir                                 const SwTxtFmtColl* pSplitColl )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir #ifdef JP_TEST
87cdf0e10cSrcweir     if( !pSplitColl )
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         sal_uInt8 nLvl = 1;
90cdf0e10cSrcweir         const SwTxtFmtColls& rFmtColls =*GetTxtFmtColls();
91cdf0e10cSrcweir         for( sal_uInt16 n = rFmtColls.Count(); n; )
92cdf0e10cSrcweir             //if( nLvl == rFmtColls[ --n ]->GetOutlineLevel() )//#outline level,zhaojianwei
93cdf0e10cSrcweir             if( nLvl == rFmtColls[ --n ]->GetAttrOutlineLevel() -1 )//<-end,zhaojianwei 0814
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 pSplitColl = rFmtColls[ n ];
96cdf0e10cSrcweir                 break;
97cdf0e10cSrcweir             }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         if( !pSplitColl )
100cdf0e10cSrcweir             pSplitColl = GetTxtCollFromPool( RES_POOLCOLL_HEADLINE2 );
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir #endif
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     return SplitDoc( SPLITDOC_TO_HTML, rPath, pSplitColl );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
SplitDoc(sal_uInt16 eDocType,const String & rPath,const SwTxtFmtColl * pSplitColl)107cdf0e10cSrcweir sal_Bool SwDoc::SplitDoc( sal_uInt16 eDocType, const String& rPath,
108cdf0e10cSrcweir                         const SwTxtFmtColl* pSplitColl )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     // ueber alle Node der Vorlage Iterieren und dafuer einzelne
111cdf0e10cSrcweir     // Dokumente erzeugen und in diesem gegen
112cdf0e10cSrcweir     // - gelinkte Bereiche (GlobalDoc)
113cdf0e10cSrcweir     // - Links (HTML)
114cdf0e10cSrcweir     // austauschen.
115cdf0e10cSrcweir     // Am Ende wird dieses Doc als GlobalDoc/HTML-Doc gespreichert.
116cdf0e10cSrcweir     if( !pDocShell || !pDocShell->GetMedium() ||
117cdf0e10cSrcweir         ( SPLITDOC_TO_GLOBALDOC == eDocType && get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ) )
118cdf0e10cSrcweir         return sal_False;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     sal_uInt16 nOutl = 0;
121cdf0e10cSrcweir     SwOutlineNodes* pOutlNds = (SwOutlineNodes*)&GetNodes().GetOutLineNds();
122cdf0e10cSrcweir     SwNodePtr pSttNd;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     if( pSplitColl )
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         // wenn keine OutlineNumerierung ist, dann benutze eigenes Array
127cdf0e10cSrcweir         // und sammel die Nodes zusammen.
128*28f5a95aSOliver-Rainer Wittmann         if( pSplitColl->GetAttrOutlineLevel() == 0 )
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir             pOutlNds = new SwOutlineNodes( 8, 8 );
131cdf0e10cSrcweir             SwIterator<SwTxtNode,SwFmtColl> aIter( *pSplitColl );
132cdf0e10cSrcweir             for( SwTxtNode* pTNd = aIter.First(); pTNd; pTNd = aIter.Next() )
133cdf0e10cSrcweir                 if( pTNd->GetNodes().IsDocNodes() )
134cdf0e10cSrcweir                     pOutlNds->Insert( pTNd );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             if( !pOutlNds->Count() )
137cdf0e10cSrcweir             {
138cdf0e10cSrcweir                 delete pOutlNds;
139cdf0e10cSrcweir                 return sal_False;
140cdf0e10cSrcweir             }
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir     else
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         // dann suche die Gliederungs - Vorlage, der 1. Ebene
146cdf0e10cSrcweir         const SwTxtFmtColls& rFmtColls =*GetTxtFmtColls();
147cdf0e10cSrcweir         for( sal_uInt16 n = rFmtColls.Count(); n; )
148cdf0e10cSrcweir             //if( !rFmtColls[ --n ]->GetOutlineLevel() )//#outline level,zhaojianwei
149cdf0e10cSrcweir             if ( rFmtColls[ --n ]->GetAttrOutlineLevel() == 1 )//<-end,zhaojianwei
150cdf0e10cSrcweir             {
151cdf0e10cSrcweir                 pSplitColl = rFmtColls[ n ];
152cdf0e10cSrcweir                 break;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         if( !pSplitColl )
156cdf0e10cSrcweir             return sal_False;
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     const SfxFilter* pFilter;
160cdf0e10cSrcweir     switch( eDocType )
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir     case SPLITDOC_TO_HTML:
163cdf0e10cSrcweir         pFilter = SwIoSystem::GetFilterOfFormat( String::CreateFromAscii(
164cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "HTML" )));
165cdf0e10cSrcweir         break;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     default:
168cdf0e10cSrcweir //  case SPLITDOC_TO_GLOBALDOC:
169cdf0e10cSrcweir         pFilter = SwIoSystem::GetFilterOfFormat(
170cdf0e10cSrcweir                                     String::CreateFromAscii( FILTER_XML ));
171cdf0e10cSrcweir         eDocType = SPLITDOC_TO_GLOBALDOC;
172cdf0e10cSrcweir         break;
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     if( !pFilter )
176cdf0e10cSrcweir         return sal_False;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     // Undo/Redline aufjedenfall abschalten
179cdf0e10cSrcweir     GetIDocumentUndoRedo().DoUndo(false);
180cdf0e10cSrcweir     SetRedlineMode_intern( (RedlineMode_t)(GetRedlineMode() & ~nsRedlineMode_t::REDLINE_ON));
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     String sExt( pFilter->GetSuffixes().GetToken(0, ',') );
183cdf0e10cSrcweir     if( !sExt.Len() )
184cdf0e10cSrcweir         sExt.AssignAscii( "sxw" );
185cdf0e10cSrcweir     if( '.' != sExt.GetChar( 0 ) )
186cdf0e10cSrcweir         sExt.Insert( '.', 0 );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     INetURLObject aEntry(rPath);
189cdf0e10cSrcweir     String sLeading(aEntry.GetBase());
190cdf0e10cSrcweir     aEntry.removeSegment();
191cdf0e10cSrcweir     String sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
192cdf0e10cSrcweir     utl::TempFile aTemp(sLeading,&sExt,&sPath );
193cdf0e10cSrcweir     aTemp.EnableKillingFile();
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     DateTime aTmplDate;
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         Time a2Min( 0 ); a2Min.SetMin( 2 );
198cdf0e10cSrcweir         aTmplDate += a2Min;
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     // alle Ungueltigen ueberspringen
203cdf0e10cSrcweir     while( nOutl < pOutlNds->Count() &&
204cdf0e10cSrcweir         pOutlNds->GetObject( nOutl )->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
205cdf0e10cSrcweir         ++nOutl;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     do {
208cdf0e10cSrcweir         pSttNd = 0;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         SwNodePtr pNd;
211cdf0e10cSrcweir         for( ; nOutl < pOutlNds->Count(); ++nOutl )
212cdf0e10cSrcweir             if( ( pNd = pOutlNds->GetObject( nOutl ))->GetTxtNode()->
213cdf0e10cSrcweir                     GetTxtColl() == pSplitColl &&
214cdf0e10cSrcweir                 !pNd->FindTableNode() )
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 pSttNd = pNd;
217cdf0e10cSrcweir                 break;
218cdf0e10cSrcweir             }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         if( pSttNd )
221cdf0e10cSrcweir         {
222cdf0e10cSrcweir             SwNodePtr pEndNd = 0;
223cdf0e10cSrcweir             for( ++nOutl; nOutl < pOutlNds->Count(); ++nOutl )
224cdf0e10cSrcweir             {
225cdf0e10cSrcweir                 pNd = pOutlNds->GetObject( nOutl );
226cdf0e10cSrcweir                 SwTxtFmtColl* pTColl = pNd->GetTxtNode()->GetTxtColl();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir                 //if( ( pTColl == pSplitColl ||     //#outline level,zhaojianwei
229cdf0e10cSrcweir                 //  (   NO_NUMBERING != pSplitColl->GetOutlineLevel() &&
230cdf0e10cSrcweir                 //      pTColl->GetOutlineLevel() <
231cdf0e10cSrcweir                 //      pSplitColl->GetOutlineLevel() )) &&
232cdf0e10cSrcweir                 //  !pNd->FindTableNode() )
233cdf0e10cSrcweir                 if( ( pTColl == pSplitColl ||
234cdf0e10cSrcweir                     (   pSplitColl->GetAttrOutlineLevel() > 0 &&
235cdf0e10cSrcweir                         pTColl->GetAttrOutlineLevel() > 0     &&
236cdf0e10cSrcweir                         pTColl->GetAttrOutlineLevel() <
237cdf0e10cSrcweir                         pSplitColl->GetAttrOutlineLevel() )) &&
238cdf0e10cSrcweir                     !pNd->FindTableNode() )         //<-end,zhaojianwei
239cdf0e10cSrcweir                 {
240cdf0e10cSrcweir                     pEndNd = pNd;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir                     break;
243cdf0e10cSrcweir                 }
244cdf0e10cSrcweir             }
245cdf0e10cSrcweir             SwNodeIndex aEndIdx( pEndNd ? *pEndNd
246cdf0e10cSrcweir                                         : GetNodes().GetEndOfContent() );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             // die Nodes komplett rausschreiben
249cdf0e10cSrcweir             String sFileName;
250cdf0e10cSrcweir             if( pSttNd->GetIndex() + 1 < aEndIdx.GetIndex() )
251cdf0e10cSrcweir             {
252cdf0e10cSrcweir                 SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
253cdf0e10cSrcweir                 if( xDocSh->DoInitNew( 0 ) )
254cdf0e10cSrcweir                 {
255cdf0e10cSrcweir                     SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir                     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
258cdf0e10cSrcweir                         ((SwDocShell*)(&xDocSh))->GetModel(),
259cdf0e10cSrcweir                         uno::UNO_QUERY_THROW);
260cdf0e10cSrcweir                     uno::Reference<document::XDocumentProperties> xDocProps(
261cdf0e10cSrcweir                         xDPS->getDocumentProperties());
262cdf0e10cSrcweir                     DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
263cdf0e10cSrcweir                     // the GlobalDoc is the template
264cdf0e10cSrcweir                     xDocProps->setTemplateName(aEmptyStr);
265cdf0e10cSrcweir                     ::util::DateTime uDT(aTmplDate.Get100Sec(),
266cdf0e10cSrcweir                         aTmplDate.GetSec(), aTmplDate.GetMin(),
267cdf0e10cSrcweir                         aTmplDate.GetHour(), aTmplDate.GetDay(),
268cdf0e10cSrcweir                         aTmplDate.GetMonth(), aTmplDate.GetYear());
269cdf0e10cSrcweir                     xDocProps->setTemplateDate(uDT);
270cdf0e10cSrcweir                     xDocProps->setTemplateURL(rPath);
271cdf0e10cSrcweir                     //JP 14.06.99: Set the text of the "split para" as title
272cdf0e10cSrcweir                     //              from the new doc. Is the current doc has
273cdf0e10cSrcweir                     //              a title, insert it at begin.
274cdf0e10cSrcweir                     String sTitle( xDocProps->getTitle() );
275cdf0e10cSrcweir                     if( sTitle.Len() )
276cdf0e10cSrcweir                         sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ));
277cdf0e10cSrcweir                     sTitle += ((SwTxtNode*)pSttNd)->GetExpandTxt();
278cdf0e10cSrcweir                     xDocProps->setTitle( sTitle );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir                     // Vorlagen ersetzen
281cdf0e10cSrcweir                     pDoc->ReplaceStyles( *this );
282cdf0e10cSrcweir 
283cdf0e10cSrcweir                     // KapitelNumerierung uebernehmen
284cdf0e10cSrcweir                     if( pOutlineRule )
285cdf0e10cSrcweir                         pDoc->SetOutlineNumRule( *pOutlineRule );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir                     SwNodeRange aRg( *pSttNd, 0, aEndIdx.GetNode() );
288cdf0e10cSrcweir                     SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() );
289cdf0e10cSrcweir                     GetNodes()._Copy( aRg, aTmpIdx, sal_False );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir                     // den initialen TextNode loeschen
292cdf0e10cSrcweir                     SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 );
293cdf0e10cSrcweir                     if( aIdx.GetIndex() + 1 !=
294cdf0e10cSrcweir                         pDoc->GetNodes().GetEndOfContent().GetIndex() )
295cdf0e10cSrcweir                         pDoc->GetNodes().Delete( aIdx, 1 );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir                     // alle Flys in dem Bereich
298cdf0e10cSrcweir                     CopyFlyInFlyImpl( aRg, 0, aIdx );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 
301cdf0e10cSrcweir                     // und noch alle Bookmarks
302cdf0e10cSrcweir                     // ?????
303cdf0e10cSrcweir 
304cdf0e10cSrcweir                     utl::TempFile aTempFile2(sLeading,&sExt,&sPath );
305cdf0e10cSrcweir                     sFileName = aTempFile2.GetURL();
306cdf0e10cSrcweir                     SfxMedium* pTmpMed = new SfxMedium( sFileName,
307cdf0e10cSrcweir                                                 STREAM_STD_READWRITE, sal_True );
308cdf0e10cSrcweir                     pTmpMed->SetFilter( pFilter );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir                     // fuer den HTML-Filter mussen wir aber ein Layout
311cdf0e10cSrcweir                     // haben, damit Textrahmen/Controls/OLE-Objecte korrekt
312cdf0e10cSrcweir                     // als Grafik exportiert werden koennen.
313cdf0e10cSrcweir                     if( SPLITDOC_TO_HTML == eDocType &&
314cdf0e10cSrcweir                         pDoc->GetSpzFrmFmts()->Count() )
315cdf0e10cSrcweir                     {
316cdf0e10cSrcweir                         /* SfxViewFrame* pFrame = */
317cdf0e10cSrcweir                             SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
318cdf0e10cSrcweir                     }
319cdf0e10cSrcweir                     xDocSh->DoSaveAs( *pTmpMed );
320cdf0e10cSrcweir                     xDocSh->DoSaveCompleted( pTmpMed );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir                     // beim Fehler wird keine FileLinkSection eingefuegt
323cdf0e10cSrcweir                     if( xDocSh->GetError() )
324cdf0e10cSrcweir                         sFileName.Erase();
325cdf0e10cSrcweir                 }
326cdf0e10cSrcweir                 xDocSh->DoClose();
327cdf0e10cSrcweir             }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir             // dann koennen ja die Bereiche eingefuegt werden
330cdf0e10cSrcweir             if( sFileName.Len() )
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 switch( eDocType )
333cdf0e10cSrcweir                 {
334cdf0e10cSrcweir                 case SPLITDOC_TO_HTML:
335cdf0e10cSrcweir                     {
336cdf0e10cSrcweir                         // loesche alle Nodes im Bereich und setze im "Start-
337cdf0e10cSrcweir                         // Node" den Link auf das gespeicherte Doc
338cdf0e10cSrcweir                         sal_uLong nNodeDiff = aEndIdx.GetIndex() -
339cdf0e10cSrcweir                                             pSttNd->GetIndex() - 1;
340cdf0e10cSrcweir                         if( nNodeDiff )
341cdf0e10cSrcweir                         {
342cdf0e10cSrcweir                             SwPaM aTmp( *pSttNd, aEndIdx.GetNode(), 1, -1 );
343cdf0e10cSrcweir                             aTmp.GetPoint()->nContent.Assign( 0, 0 );
344cdf0e10cSrcweir                             aTmp.GetMark()->nContent.Assign( 0, 0 );
345cdf0e10cSrcweir                             SwNodeIndex aSIdx( aTmp.GetMark()->nNode );
346cdf0e10cSrcweir                             SwNodeIndex aEIdx( aTmp.GetPoint()->nNode );
347cdf0e10cSrcweir 
348cdf0e10cSrcweir                             // versuche hinters Ende zu verschieben
349cdf0e10cSrcweir                             if( !aTmp.Move( fnMoveForward, fnGoNode ) )
350cdf0e10cSrcweir                             {
351cdf0e10cSrcweir                                 // na gut, dann an den Anfang
352cdf0e10cSrcweir                                 aTmp.Exchange();
353cdf0e10cSrcweir                                 if( !aTmp.Move( fnMoveBackward, fnGoNode ))
354cdf0e10cSrcweir                                 {
355cdf0e10cSrcweir                                     ASSERT( sal_False, "kein Node mehr vorhanden" );
356cdf0e10cSrcweir                                 }
357cdf0e10cSrcweir                             }
358cdf0e10cSrcweir                                 // Bookmarks usw. verschieben
359cdf0e10cSrcweir                             CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), sal_True);
360cdf0e10cSrcweir 
361cdf0e10cSrcweir                             // stehen noch FlyFrames rum, loesche auch diese
362cdf0e10cSrcweir                             for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->Count(); ++n )
363cdf0e10cSrcweir                             {
364cdf0e10cSrcweir                                 SwFrmFmt* pFly = (*GetSpzFrmFmts())[n];
365cdf0e10cSrcweir                                 const SwFmtAnchor* pAnchor = &pFly->GetAnchor();
366cdf0e10cSrcweir                                 SwPosition const*const pAPos =
367cdf0e10cSrcweir                                     pAnchor->GetCntntAnchor();
368cdf0e10cSrcweir                                 if (pAPos &&
369cdf0e10cSrcweir                                     ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
370cdf0e10cSrcweir                                      (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
371cdf0e10cSrcweir                                     aSIdx <= pAPos->nNode &&
372cdf0e10cSrcweir                                     pAPos->nNode < aEIdx )
373cdf0e10cSrcweir                                 {
374cdf0e10cSrcweir                                     DelLayoutFmt( pFly );
375cdf0e10cSrcweir                                     --n;
376cdf0e10cSrcweir                                 }
377cdf0e10cSrcweir                             }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir                             GetNodes().Delete( aSIdx, nNodeDiff );
380cdf0e10cSrcweir                         }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir                         // dann setze im StartNode noch den Link:
383cdf0e10cSrcweir                         SwFmtINetFmt aINet( sFileName , aEmptyStr );
384cdf0e10cSrcweir                         SwTxtNode* pTNd = (SwTxtNode*)pSttNd;
385cdf0e10cSrcweir                         pTNd->InsertItem( aINet, 0, pTNd->GetTxt().Len() );
386cdf0e10cSrcweir 
387cdf0e10cSrcweir                         // wenn der nicht mehr gefunden wird, kann das nur
388cdf0e10cSrcweir                         // ein Bug sein!
389cdf0e10cSrcweir                         if( !pOutlNds->Seek_Entry( pSttNd, &nOutl ))
390cdf0e10cSrcweir                             pSttNd = 0;
391cdf0e10cSrcweir                         ++nOutl;
392cdf0e10cSrcweir                     }
393cdf0e10cSrcweir                     break;
394cdf0e10cSrcweir 
395cdf0e10cSrcweir                 default:
396cdf0e10cSrcweir                     {
397cdf0e10cSrcweir                         String sNm( INetURLObject( sFileName ).GetName() );
398cdf0e10cSrcweir                         SwSectionData aSectData( FILE_LINK_SECTION,
399cdf0e10cSrcweir                                         GetUniqueSectionName( &sNm ));
400cdf0e10cSrcweir                         SwSectionFmt* pFmt = MakeSectionFmt( 0 );
401cdf0e10cSrcweir                         aSectData.SetLinkFileName(sFileName);
402cdf0e10cSrcweir                         aSectData.SetProtectFlag(true);
403cdf0e10cSrcweir 
404cdf0e10cSrcweir                         aEndIdx--;  // im InsertSection ist Ende inclusive
405cdf0e10cSrcweir                         while( aEndIdx.GetNode().IsStartNode() )
406cdf0e10cSrcweir                             aEndIdx--;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir                         // JP 06.07.99 - Bug 67361 - is any Section ends or
409cdf0e10cSrcweir                         // starts in the new sectionrange, they must end or
410cdf0e10cSrcweir                         // start before or behind the range!
411cdf0e10cSrcweir                         SwSectionNode* pSectNd = pSttNd->FindSectionNode();
412cdf0e10cSrcweir                         while( pSectNd && pSectNd->EndOfSectionIndex()
413cdf0e10cSrcweir                                 <= aEndIdx.GetIndex() )
414cdf0e10cSrcweir                         {
415cdf0e10cSrcweir                             const SwNode* pSectEnd = pSectNd->EndOfSectionNode();
416cdf0e10cSrcweir                             if( pSectNd->GetIndex() + 1 ==
417cdf0e10cSrcweir                                     pSttNd->GetIndex() )
418cdf0e10cSrcweir                             {
419cdf0e10cSrcweir                                 sal_Bool bMvIdx = aEndIdx == *pSectEnd;
420cdf0e10cSrcweir                                 DelSectionFmt( pSectNd->GetSection().GetFmt() );
421cdf0e10cSrcweir                                 if( bMvIdx )
422cdf0e10cSrcweir                                     aEndIdx--;
423cdf0e10cSrcweir                             }
424cdf0e10cSrcweir                             else
425cdf0e10cSrcweir                             {
426cdf0e10cSrcweir                                 SwNodeRange aRg( *pSttNd, *pSectEnd );
427cdf0e10cSrcweir                                 SwNodeIndex aIdx( *pSectEnd, 1 );
428cdf0e10cSrcweir                                 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
429cdf0e10cSrcweir                             }
430cdf0e10cSrcweir                             pSectNd = pSttNd->FindSectionNode();
431cdf0e10cSrcweir                         }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir                         pSectNd = aEndIdx.GetNode().FindSectionNode();
434cdf0e10cSrcweir                         while( pSectNd && pSectNd->GetIndex() >
435cdf0e10cSrcweir                                 pSttNd->GetIndex() )
436cdf0e10cSrcweir                         {
437cdf0e10cSrcweir                             // #i15712# don't attempt to split sections if
438cdf0e10cSrcweir                             // they are fully enclosed in [pSectNd,aEndIdx].
439cdf0e10cSrcweir                             if( aEndIdx < pSectNd->EndOfSectionIndex() )
440cdf0e10cSrcweir                             {
441cdf0e10cSrcweir                                 SwNodeRange aRg( *pSectNd, 1, aEndIdx, 1 );
442cdf0e10cSrcweir                                 SwNodeIndex aIdx( *pSectNd );
443cdf0e10cSrcweir                                 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
444cdf0e10cSrcweir                             }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir                             pSectNd = pSttNd->FindSectionNode();
447cdf0e10cSrcweir                         }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir                         // -> #i26762#
450cdf0e10cSrcweir                         // Ensure order of start and end of section is sane.
451cdf0e10cSrcweir                         SwNodeIndex aStartIdx(*pSttNd);
452cdf0e10cSrcweir 
453cdf0e10cSrcweir                         if (aEndIdx >= aStartIdx)
454cdf0e10cSrcweir                         {
455cdf0e10cSrcweir                             pSectNd = GetNodes().InsertTextSection(aStartIdx,
456cdf0e10cSrcweir                                 *pFmt, aSectData, 0, &aEndIdx, false);
457cdf0e10cSrcweir                         }
458cdf0e10cSrcweir                         else
459cdf0e10cSrcweir                         {
460cdf0e10cSrcweir                             pSectNd = GetNodes().InsertTextSection(aEndIdx,
461cdf0e10cSrcweir                                 *pFmt, aSectData, 0, &aStartIdx, false);
462cdf0e10cSrcweir                         }
463cdf0e10cSrcweir                         // <- #i26762#
464cdf0e10cSrcweir 
465cdf0e10cSrcweir                         pSectNd->GetSection().CreateLink( CREATE_CONNECT );
466cdf0e10cSrcweir                     }
467cdf0e10cSrcweir                     break;
468cdf0e10cSrcweir                 }
469cdf0e10cSrcweir             }
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir     } while( pSttNd );
472cdf0e10cSrcweir 
473cdf0e10cSrcweir //  if( pOutlNds != (SwOutlineNodes*)&GetNodes().GetOutLineNds();
474cdf0e10cSrcweir     if( pOutlNds != &GetNodes().GetOutLineNds() )
475cdf0e10cSrcweir         delete pOutlNds;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     switch( eDocType )
478cdf0e10cSrcweir     {
479cdf0e10cSrcweir     case SPLITDOC_TO_HTML:
480cdf0e10cSrcweir         if( get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
481cdf0e10cSrcweir         {
482cdf0e10cSrcweir             // dann alles verbliebenen Bereiche aufheben
483cdf0e10cSrcweir             while( GetSections().Count() )
484cdf0e10cSrcweir                 DelSectionFmt( GetSections()[ 0 ] );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir             SfxFilterContainer* pFCntnr = pDocShell->GetFactory().GetFilterContainer();
487cdf0e10cSrcweir             pFilter = pFCntnr->GetFilter4EA( pFilter->GetTypeName(), SFX_FILTER_EXPORT );
488cdf0e10cSrcweir         }
489cdf0e10cSrcweir         break;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir //  case SPLITDOC_TO_GLOBALDOC:
492cdf0e10cSrcweir     default:
493cdf0e10cSrcweir         // dann das Globaldoc speichern
494cdf0e10cSrcweir         set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
495cdf0e10cSrcweir         set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
496cdf0e10cSrcweir     }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     //              Medium istn't locked after reopen the document. Bug 91462
499cdf0e10cSrcweir     SfxRequest aReq( SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, GetAttrPool() );
500cdf0e10cSrcweir     aReq.AppendItem( SfxStringItem( SID_FILE_NAME, rPath ) );
501cdf0e10cSrcweir     aReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
502cdf0e10cSrcweir     if(pFilter)
503cdf0e10cSrcweir         aReq.AppendItem( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
504cdf0e10cSrcweir     const SfxBoolItem *pRet = (const SfxBoolItem*)pDocShell->ExecuteSlot( aReq );
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     return pRet && pRet->GetValue();
507cdf0e10cSrcweir }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir //#outline level,add by zhaojianwei
SplitDoc(sal_uInt16 eDocType,const String & rPath,int nOutlineLevel)510cdf0e10cSrcweir sal_Bool SwDoc::SplitDoc( sal_uInt16 eDocType, const String& rPath, int nOutlineLevel )
511cdf0e10cSrcweir {
512cdf0e10cSrcweir     if( !pDocShell || !pDocShell->GetMedium() ||
513cdf0e10cSrcweir         ( SPLITDOC_TO_GLOBALDOC == eDocType && get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ) )
514cdf0e10cSrcweir         return sal_False;
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     sal_uInt16 nOutl = 0;
517cdf0e10cSrcweir     SwOutlineNodes* pOutlNds = (SwOutlineNodes*)&GetNodes().GetOutLineNds();
518cdf0e10cSrcweir     SwNodePtr pSttNd;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     const SfxFilter* pFilter;
521cdf0e10cSrcweir     switch( eDocType )
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir     case SPLITDOC_TO_HTML:
524cdf0e10cSrcweir         pFilter = SwIoSystem::GetFilterOfFormat( String::CreateFromAscii(
525cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "HTML" )));
526cdf0e10cSrcweir         break;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     default:
529cdf0e10cSrcweir //  case SPLITDOC_TO_GLOBALDOC:
530cdf0e10cSrcweir         pFilter = SwIoSystem::GetFilterOfFormat(
531cdf0e10cSrcweir                                     String::CreateFromAscii( FILTER_XML ));
532cdf0e10cSrcweir         eDocType = SPLITDOC_TO_GLOBALDOC;
533cdf0e10cSrcweir         break;
534cdf0e10cSrcweir     }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir     if( !pFilter )
537cdf0e10cSrcweir         return sal_False;
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     // Undo/Redline aufjedenfall abschalten
540cdf0e10cSrcweir     GetIDocumentUndoRedo().DoUndo(false);
541cdf0e10cSrcweir     SetRedlineMode_intern( (RedlineMode_t)(GetRedlineMode() & ~nsRedlineMode_t::REDLINE_ON));
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     String sExt( pFilter->GetSuffixes().GetToken(0, ',') );
544cdf0e10cSrcweir     if( !sExt.Len() )
545cdf0e10cSrcweir         sExt.AssignAscii( "sxw" );
546cdf0e10cSrcweir     if( '.' != sExt.GetChar( 0 ) )
547cdf0e10cSrcweir         sExt.Insert( '.', 0 );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     INetURLObject aEntry(rPath);
550cdf0e10cSrcweir     String sLeading(aEntry.GetBase());
551cdf0e10cSrcweir     aEntry.removeSegment();
552cdf0e10cSrcweir     String sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
553cdf0e10cSrcweir     utl::TempFile aTemp(sLeading,&sExt,&sPath );
554cdf0e10cSrcweir     aTemp.EnableKillingFile();
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     DateTime aTmplDate;
557cdf0e10cSrcweir     {
558cdf0e10cSrcweir         Time a2Min( 0 ); a2Min.SetMin( 2 );
559cdf0e10cSrcweir         aTmplDate += a2Min;
560cdf0e10cSrcweir     }
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 
563cdf0e10cSrcweir     // alle Ungueltigen ueberspringen
564cdf0e10cSrcweir     while( nOutl < pOutlNds->Count() &&
565cdf0e10cSrcweir         pOutlNds->GetObject( nOutl )->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
566cdf0e10cSrcweir         ++nOutl;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     do {
569cdf0e10cSrcweir         pSttNd = 0;
570cdf0e10cSrcweir 
571cdf0e10cSrcweir         SwNodePtr pNd;
572cdf0e10cSrcweir         for( ; nOutl < pOutlNds->Count(); ++nOutl )
573cdf0e10cSrcweir             if( ( pNd = pOutlNds->GetObject( nOutl ))->GetTxtNode()->GetAttrOutlineLevel() == nOutlineLevel &&
574cdf0e10cSrcweir                 !pNd->FindTableNode() )
575cdf0e10cSrcweir             {
576cdf0e10cSrcweir                 pSttNd = pNd;
577cdf0e10cSrcweir                 break;
578cdf0e10cSrcweir             }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir         if( pSttNd )
581cdf0e10cSrcweir         {
582cdf0e10cSrcweir             SwNodePtr pEndNd = 0;
583cdf0e10cSrcweir             for( ++nOutl; nOutl < pOutlNds->Count(); ++nOutl )
584cdf0e10cSrcweir             {
585cdf0e10cSrcweir                 pNd = pOutlNds->GetObject( nOutl );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir                 const int nLevel = pNd->GetTxtNode()->GetAttrOutlineLevel();
588cdf0e10cSrcweir 
589cdf0e10cSrcweir                 if( ( 0 < nLevel && nLevel <= nOutlineLevel ) &&
590cdf0e10cSrcweir                     !pNd->FindTableNode() )
591cdf0e10cSrcweir                 {
592cdf0e10cSrcweir                     pEndNd = pNd;
593cdf0e10cSrcweir 
594cdf0e10cSrcweir                     break;
595cdf0e10cSrcweir                 }
596cdf0e10cSrcweir             }
597cdf0e10cSrcweir             SwNodeIndex aEndIdx( pEndNd ? *pEndNd
598cdf0e10cSrcweir                                         : GetNodes().GetEndOfContent() );
599cdf0e10cSrcweir 
600cdf0e10cSrcweir             String sFileName;
601cdf0e10cSrcweir             if( pSttNd->GetIndex() + 1 < aEndIdx.GetIndex() )
602cdf0e10cSrcweir             {
603cdf0e10cSrcweir                 SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
604cdf0e10cSrcweir                 if( xDocSh->DoInitNew( 0 ) )
605cdf0e10cSrcweir                 {
606cdf0e10cSrcweir                     SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
607cdf0e10cSrcweir 
608cdf0e10cSrcweir                     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
609cdf0e10cSrcweir                         ((SwDocShell*)(&xDocSh))->GetModel(),
610cdf0e10cSrcweir                         uno::UNO_QUERY_THROW);
611cdf0e10cSrcweir                     uno::Reference<document::XDocumentProperties> xDocProps(
612cdf0e10cSrcweir                         xDPS->getDocumentProperties());
613cdf0e10cSrcweir                     DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
614cdf0e10cSrcweir                     // the GlobalDoc is the template
615cdf0e10cSrcweir                     xDocProps->setTemplateName(aEmptyStr);
616cdf0e10cSrcweir                     ::util::DateTime uDT(aTmplDate.Get100Sec(),
617cdf0e10cSrcweir                         aTmplDate.GetSec(), aTmplDate.GetMin(),
618cdf0e10cSrcweir                         aTmplDate.GetHour(), aTmplDate.GetDay(),
619cdf0e10cSrcweir                         aTmplDate.GetMonth(), aTmplDate.GetYear());
620cdf0e10cSrcweir                     xDocProps->setTemplateDate(uDT);
621cdf0e10cSrcweir                     xDocProps->setTemplateURL(rPath);
622cdf0e10cSrcweir                     //JP 14.06.99: Set the text of the "split para" as title
623cdf0e10cSrcweir                     //              from the new doc. Is the current doc has
624cdf0e10cSrcweir                     //              a title, insert it at begin.
625cdf0e10cSrcweir                     String sTitle( xDocProps->getTitle() );
626cdf0e10cSrcweir                     if( sTitle.Len() )
627cdf0e10cSrcweir                         sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ));
628cdf0e10cSrcweir                     sTitle += ((SwTxtNode*)pSttNd)->GetExpandTxt();
629cdf0e10cSrcweir                     xDocProps->setTitle( sTitle );
630cdf0e10cSrcweir 
631cdf0e10cSrcweir                     // Vorlagen ersetzen
632cdf0e10cSrcweir                     pDoc->ReplaceStyles( *this );
633cdf0e10cSrcweir 
634cdf0e10cSrcweir                     // KapitelNumerierung uebernehmen
635cdf0e10cSrcweir                     if( pOutlineRule )
636cdf0e10cSrcweir                         pDoc->SetOutlineNumRule( *pOutlineRule );
637cdf0e10cSrcweir 
638cdf0e10cSrcweir                     SwNodeRange aRg( *pSttNd, 0, aEndIdx.GetNode() );
639cdf0e10cSrcweir                     SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() );
640cdf0e10cSrcweir                     GetNodes()._Copy( aRg, aTmpIdx, sal_False );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir                     // den initialen TextNode loeschen
643cdf0e10cSrcweir                     SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 );
644cdf0e10cSrcweir                     if( aIdx.GetIndex() + 1 !=
645cdf0e10cSrcweir                         pDoc->GetNodes().GetEndOfContent().GetIndex() )
646cdf0e10cSrcweir                         pDoc->GetNodes().Delete( aIdx, 1 );
647cdf0e10cSrcweir 
648cdf0e10cSrcweir                     // alle Flys in dem Bereich
649cdf0e10cSrcweir                     CopyFlyInFlyImpl( aRg, 0, aIdx );
650cdf0e10cSrcweir 
651cdf0e10cSrcweir 
652cdf0e10cSrcweir                     // und noch alle Bookmarks
653cdf0e10cSrcweir                     // ?????
654cdf0e10cSrcweir 
655cdf0e10cSrcweir                     utl::TempFile aTempFile2(sLeading,&sExt,&sPath );
656cdf0e10cSrcweir                     sFileName = aTempFile2.GetURL();
657cdf0e10cSrcweir                     SfxMedium* pTmpMed = new SfxMedium( sFileName,
658cdf0e10cSrcweir                                                 STREAM_STD_READWRITE, sal_True );
659cdf0e10cSrcweir                     pTmpMed->SetFilter( pFilter );
660cdf0e10cSrcweir 
661cdf0e10cSrcweir                     // fuer den HTML-Filter mussen wir aber ein Layout
662cdf0e10cSrcweir                     // haben, damit Textrahmen/Controls/OLE-Objecte korrekt
663cdf0e10cSrcweir                     // als Grafik exportiert werden koennen.
664cdf0e10cSrcweir                     if( SPLITDOC_TO_HTML == eDocType &&
665cdf0e10cSrcweir                         pDoc->GetSpzFrmFmts()->Count() )
666cdf0e10cSrcweir                     {
667cdf0e10cSrcweir                         /* SfxViewFrame* pFrame = */
668cdf0e10cSrcweir                             SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
669cdf0e10cSrcweir                     }
670cdf0e10cSrcweir                     xDocSh->DoSaveAs( *pTmpMed );
671cdf0e10cSrcweir                     xDocSh->DoSaveCompleted( pTmpMed );
672cdf0e10cSrcweir 
673cdf0e10cSrcweir                     // beim Fehler wird keine FileLinkSection eingefuegt
674cdf0e10cSrcweir                     if( xDocSh->GetError() )
675cdf0e10cSrcweir                         sFileName.Erase();
676cdf0e10cSrcweir                 }
677cdf0e10cSrcweir                 xDocSh->DoClose();
678cdf0e10cSrcweir             }
679cdf0e10cSrcweir 
680cdf0e10cSrcweir             // dann koennen ja die Bereiche eingefuegt werden
681cdf0e10cSrcweir             if( sFileName.Len() )
682cdf0e10cSrcweir             {
683cdf0e10cSrcweir                 switch( eDocType )
684cdf0e10cSrcweir                 {
685cdf0e10cSrcweir                 case SPLITDOC_TO_HTML:
686cdf0e10cSrcweir                     {
687cdf0e10cSrcweir                         // loesche alle Nodes im Bereich und setze im "Start-
688cdf0e10cSrcweir                         // Node" den Link auf das gespeicherte Doc
689cdf0e10cSrcweir                         sal_uLong nNodeDiff = aEndIdx.GetIndex() -
690cdf0e10cSrcweir                                             pSttNd->GetIndex() - 1;
691cdf0e10cSrcweir                         if( nNodeDiff )
692cdf0e10cSrcweir                         {
693cdf0e10cSrcweir                             SwPaM aTmp( *pSttNd, aEndIdx.GetNode(), 1, -1 );
694cdf0e10cSrcweir                             aTmp.GetPoint()->nContent.Assign( 0, 0 );
695cdf0e10cSrcweir                             aTmp.GetMark()->nContent.Assign( 0, 0 );
696cdf0e10cSrcweir                             SwNodeIndex aSIdx( aTmp.GetMark()->nNode );
697cdf0e10cSrcweir                             SwNodeIndex aEIdx( aTmp.GetPoint()->nNode );
698cdf0e10cSrcweir 
699cdf0e10cSrcweir                             // versuche hinters Ende zu verschieben
700cdf0e10cSrcweir                             if( !aTmp.Move( fnMoveForward, fnGoNode ) )
701cdf0e10cSrcweir                             {
702cdf0e10cSrcweir                                 // na gut, dann an den Anfang
703cdf0e10cSrcweir                                 aTmp.Exchange();
704cdf0e10cSrcweir                                 if( !aTmp.Move( fnMoveBackward, fnGoNode ))
705cdf0e10cSrcweir                                 {
706cdf0e10cSrcweir                                     ASSERT( sal_False, "kein Node mehr vorhanden" );
707cdf0e10cSrcweir                                 }
708cdf0e10cSrcweir                             }
709cdf0e10cSrcweir                                 // Bookmarks usw. verschieben
710cdf0e10cSrcweir                             CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), sal_True);
711cdf0e10cSrcweir 
712cdf0e10cSrcweir                             // stehen noch FlyFrames rum, loesche auch diese
713cdf0e10cSrcweir                             for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->Count(); ++n )
714cdf0e10cSrcweir                             {
715cdf0e10cSrcweir                                 SwFrmFmt* pFly = (*GetSpzFrmFmts())[n];
716cdf0e10cSrcweir                                 const SwFmtAnchor* pAnchor = &pFly->GetAnchor();
717cdf0e10cSrcweir                                 SwPosition const*const pAPos =
718cdf0e10cSrcweir                                     pAnchor->GetCntntAnchor();
719cdf0e10cSrcweir                                 if (pAPos &&
720cdf0e10cSrcweir                                     ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
721cdf0e10cSrcweir                                      (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
722cdf0e10cSrcweir                                     aSIdx <= pAPos->nNode &&
723cdf0e10cSrcweir                                     pAPos->nNode < aEIdx )
724cdf0e10cSrcweir                                 {
725cdf0e10cSrcweir                                     DelLayoutFmt( pFly );
726cdf0e10cSrcweir                                     --n;
727cdf0e10cSrcweir                                 }
728cdf0e10cSrcweir                             }
729cdf0e10cSrcweir 
730cdf0e10cSrcweir                             GetNodes().Delete( aSIdx, nNodeDiff );
731cdf0e10cSrcweir                         }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir                         // dann setze im StartNode noch den Link:
734cdf0e10cSrcweir                         SwFmtINetFmt aINet( sFileName , aEmptyStr );
735cdf0e10cSrcweir                         SwTxtNode* pTNd = (SwTxtNode*)pSttNd;
736cdf0e10cSrcweir                         pTNd->InsertItem( aINet, 0, pTNd->GetTxt().Len() );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir                         // wenn der nicht mehr gefunden wird, kann das nur
739cdf0e10cSrcweir                         // ein Bug sein!
740cdf0e10cSrcweir                         if( !pOutlNds->Seek_Entry( pSttNd, &nOutl ))
741cdf0e10cSrcweir                             pSttNd = 0;
742cdf0e10cSrcweir                         ++nOutl;
743cdf0e10cSrcweir                     }
744cdf0e10cSrcweir                     break;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir                 default:
747cdf0e10cSrcweir                     {
748cdf0e10cSrcweir                         String sNm( INetURLObject( sFileName ).GetName() );
749cdf0e10cSrcweir                         SwSectionData aSectData( FILE_LINK_SECTION,
750cdf0e10cSrcweir                                         GetUniqueSectionName( &sNm ));
751cdf0e10cSrcweir                         SwSectionFmt* pFmt = MakeSectionFmt( 0 );
752cdf0e10cSrcweir                         aSectData.SetLinkFileName(sFileName);
753cdf0e10cSrcweir                         aSectData.SetProtectFlag(true);
754cdf0e10cSrcweir 
755cdf0e10cSrcweir                         aEndIdx--;  // im InsertSection ist Ende inclusive
756cdf0e10cSrcweir                         while( aEndIdx.GetNode().IsStartNode() )
757cdf0e10cSrcweir                             aEndIdx--;
758cdf0e10cSrcweir 
759cdf0e10cSrcweir                         // JP 06.07.99 - Bug 67361 - is any Section ends or
760cdf0e10cSrcweir                         // starts in the new sectionrange, they must end or
761cdf0e10cSrcweir                         // start before or behind the range!
762cdf0e10cSrcweir                         SwSectionNode* pSectNd = pSttNd->FindSectionNode();
763cdf0e10cSrcweir                         while( pSectNd && pSectNd->EndOfSectionIndex()
764cdf0e10cSrcweir                                 <= aEndIdx.GetIndex() )
765cdf0e10cSrcweir                         {
766cdf0e10cSrcweir                             const SwNode* pSectEnd = pSectNd->EndOfSectionNode();
767cdf0e10cSrcweir                             if( pSectNd->GetIndex() + 1 ==
768cdf0e10cSrcweir                                     pSttNd->GetIndex() )
769cdf0e10cSrcweir                             {
770cdf0e10cSrcweir                                 sal_Bool bMvIdx = aEndIdx == *pSectEnd;
771cdf0e10cSrcweir                                 DelSectionFmt( pSectNd->GetSection().GetFmt() );
772cdf0e10cSrcweir                                 if( bMvIdx )
773cdf0e10cSrcweir                                     aEndIdx--;
774cdf0e10cSrcweir                             }
775cdf0e10cSrcweir                             else
776cdf0e10cSrcweir                             {
777cdf0e10cSrcweir                                 SwNodeRange aRg( *pSttNd, *pSectEnd );
778cdf0e10cSrcweir                                 SwNodeIndex aIdx( *pSectEnd, 1 );
779cdf0e10cSrcweir                                 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
780cdf0e10cSrcweir                             }
781cdf0e10cSrcweir                             pSectNd = pSttNd->FindSectionNode();
782cdf0e10cSrcweir                         }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir                         pSectNd = aEndIdx.GetNode().FindSectionNode();
785cdf0e10cSrcweir                         while( pSectNd && pSectNd->GetIndex() >
786cdf0e10cSrcweir                                 pSttNd->GetIndex() )
787cdf0e10cSrcweir                         {
788cdf0e10cSrcweir                             if( aEndIdx < pSectNd->EndOfSectionIndex() )
789cdf0e10cSrcweir                             {
790cdf0e10cSrcweir                                 SwNodeRange aRg( *pSectNd, 1, aEndIdx, 1 );
791cdf0e10cSrcweir                                 SwNodeIndex aIdx( *pSectNd );
792cdf0e10cSrcweir                                 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
793cdf0e10cSrcweir                             }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir                             pSectNd = pSttNd->FindSectionNode();
796cdf0e10cSrcweir                         }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir                         SwNodeIndex aStartIdx(*pSttNd);
799cdf0e10cSrcweir 
800cdf0e10cSrcweir                         if (aEndIdx >= aStartIdx)
801cdf0e10cSrcweir                         {
802cdf0e10cSrcweir                             pSectNd = GetNodes().InsertTextSection(aStartIdx,
803cdf0e10cSrcweir                                 *pFmt, aSectData, 0, &aEndIdx, false);
804cdf0e10cSrcweir                         }
805cdf0e10cSrcweir                         else
806cdf0e10cSrcweir                         {
807cdf0e10cSrcweir                             pSectNd = GetNodes().InsertTextSection(aEndIdx,
808cdf0e10cSrcweir                                 *pFmt, aSectData, 0, &aStartIdx, false);
809cdf0e10cSrcweir                         }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir                         pSectNd->GetSection().CreateLink( CREATE_CONNECT );
812cdf0e10cSrcweir                     }
813cdf0e10cSrcweir                     break;
814cdf0e10cSrcweir                 }
815cdf0e10cSrcweir             }
816cdf0e10cSrcweir         }
817cdf0e10cSrcweir     } while( pSttNd );
818cdf0e10cSrcweir 
819cdf0e10cSrcweir     if( pOutlNds != &GetNodes().GetOutLineNds() )
820cdf0e10cSrcweir         delete pOutlNds;
821cdf0e10cSrcweir 
822cdf0e10cSrcweir     switch( eDocType )
823cdf0e10cSrcweir     {
824cdf0e10cSrcweir     case SPLITDOC_TO_HTML:
825cdf0e10cSrcweir         if( get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
826cdf0e10cSrcweir         {
827cdf0e10cSrcweir             while( GetSections().Count() )
828cdf0e10cSrcweir                 DelSectionFmt( GetSections()[ 0 ] );
829cdf0e10cSrcweir 
830cdf0e10cSrcweir             SfxFilterContainer* pFCntnr = pDocShell->GetFactory().GetFilterContainer();
831cdf0e10cSrcweir             pFilter = pFCntnr->GetFilter4EA( pFilter->GetTypeName(), SFX_FILTER_EXPORT );
832cdf0e10cSrcweir         }
833cdf0e10cSrcweir         break;
834cdf0e10cSrcweir 
835cdf0e10cSrcweir //  case SPLITDOC_TO_GLOBALDOC:
836cdf0e10cSrcweir     default:
837cdf0e10cSrcweir         set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
838cdf0e10cSrcweir         set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
839cdf0e10cSrcweir     }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     SfxRequest aReq( SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, GetAttrPool() );
842cdf0e10cSrcweir     aReq.AppendItem( SfxStringItem( SID_FILE_NAME, rPath ) );
843cdf0e10cSrcweir     aReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
844cdf0e10cSrcweir     if(pFilter)
845cdf0e10cSrcweir         aReq.AppendItem( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
846cdf0e10cSrcweir     const SfxBoolItem *pRet = (const SfxBoolItem*)pDocShell->ExecuteSlot( aReq );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir     return pRet && pRet->GetValue();
849cdf0e10cSrcweir }//<-end,zhaojianwei
850