merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / doc / docglbl.cxx
blob1d39e35de21062daaaf0a52df3849c002d37187d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docglbl.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <unotools/tempfile.hxx>
37 #include <svtools/urihelper.hxx>
38 #include <svtools/stritem.hxx>
39 #include <svtools/eitem.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/docfilt.hxx>
43 #include <sfx2/fcontnr.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <sfx2/request.hxx>
46 #include <fmtinfmt.hxx>
47 #include <fmtanchr.hxx>
48 #include <doc.hxx>
49 #include <docary.hxx>
50 #include <pam.hxx>
51 #include <ndtxt.hxx>
52 #ifndef _DOCSH_HXX
53 #include <docsh.hxx>
54 #endif
55 #ifndef _GLOBDOC_HXX
56 #include <globdoc.hxx>
57 #endif
58 #include <shellio.hxx>
59 #include <swundo.hxx> // fuer die UndoIds
60 #include <section.hxx>
61 #include <doctxm.hxx>
62 #include <poolfmt.hxx>
64 #include <com/sun/star/uno/Reference.h>
65 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
66 #include <com/sun/star/document/XDocumentProperties.hpp>
68 using namespace ::com::sun::star;
70 enum SwSplitDocType
72 SPLITDOC_TO_GLOBALDOC,
73 SPLITDOC_TO_HTML
76 BOOL SwDoc::GenerateGlobalDoc( const String& rPath,
77 const SwTxtFmtColl* pSplitColl )
79 return SplitDoc( SPLITDOC_TO_GLOBALDOC, rPath, pSplitColl );
82 //#outline level,add by zhaojianwei
83 BOOL SwDoc::GenerateGlobalDoc( const String& rPath, int nOutlineLevel )
85 return SplitDoc( SPLITDOC_TO_GLOBALDOC, rPath, nOutlineLevel );
87 BOOL SwDoc::GenerateHTMLDoc( const String& rPath, int nOutlineLevel )
89 return SplitDoc( SPLITDOC_TO_HTML, rPath, nOutlineLevel );
91 //<-end,zhaojianwei
93 BOOL SwDoc::GenerateHTMLDoc( const String& rPath,
94 const SwTxtFmtColl* pSplitColl )
96 #ifdef JP_TEST
97 if( !pSplitColl )
99 BYTE nLvl = 1;
100 const SwTxtFmtColls& rFmtColls =*GetTxtFmtColls();
101 for( USHORT n = rFmtColls.Count(); n; )
102 //if( nLvl == rFmtColls[ --n ]->GetOutlineLevel() )//#outline level,zhaojianwei
103 if( nLvl == rFmtColls[ --n ]->GetAttrOutlineLevel() -1 )//<-end,zhaojianwei 0814
105 pSplitColl = rFmtColls[ n ];
106 break;
109 if( !pSplitColl )
110 pSplitColl = GetTxtCollFromPool( RES_POOLCOLL_HEADLINE2 );
112 #endif
114 return SplitDoc( SPLITDOC_TO_HTML, rPath, pSplitColl );
117 BOOL SwDoc::SplitDoc( USHORT eDocType, const String& rPath,
118 const SwTxtFmtColl* pSplitColl )
120 // ueber alle Node der Vorlage Iterieren und dafuer einzelne
121 // Dokumente erzeugen und in diesem gegen
122 // - gelinkte Bereiche (GlobalDoc)
123 // - Links (HTML)
124 // austauschen.
125 // Am Ende wird dieses Doc als GlobalDoc/HTML-Doc gespreichert.
126 if( !pDocShell || !pDocShell->GetMedium() ||
127 ( SPLITDOC_TO_GLOBALDOC == eDocType && get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ) )
128 return FALSE;
130 USHORT nOutl = 0;
131 SwOutlineNodes* pOutlNds = (SwOutlineNodes*)&GetNodes().GetOutLineNds();
132 SwNodePtr pSttNd;
134 if( pSplitColl )
136 // wenn keine OutlineNumerierung ist, dann benutze eigenes Array
137 // und sammel die Nodes zusammen.
138 //if( NO_NUMBERING == pSplitColl->GetOutlineLevel() )//#outline level,zhaojianwei
139 if( pSplitColl->GetAttrOutlineLevel() == 0 )//<-end,zhaojianwei, 0814
141 pOutlNds = new SwOutlineNodes( 8, 8 );
142 SwClientIter aIter( *(SwModify*)pSplitColl );
143 for( SwTxtNode* pTNd = (SwTxtNode*)aIter.First( TYPE( SwTxtNode ));
144 pTNd; pTNd = (SwTxtNode*)aIter.Next() )
145 if( pTNd->GetNodes().IsDocNodes() )
146 pOutlNds->Insert( pTNd );
148 if( !pOutlNds->Count() )
150 delete pOutlNds;
151 return FALSE;
155 else
157 // dann suche die Gliederungs - Vorlage, der 1. Ebene
158 const SwTxtFmtColls& rFmtColls =*GetTxtFmtColls();
159 for( USHORT n = rFmtColls.Count(); n; )
160 //if( !rFmtColls[ --n ]->GetOutlineLevel() )//#outline level,zhaojianwei
161 if ( rFmtColls[ --n ]->GetAttrOutlineLevel() == 1 )//<-end,zhaojianwei
163 pSplitColl = rFmtColls[ n ];
164 break;
167 if( !pSplitColl )
168 return FALSE;
171 const SfxFilter* pFilter;
172 switch( eDocType )
174 case SPLITDOC_TO_HTML:
175 pFilter = SwIoSystem::GetFilterOfFormat( String::CreateFromAscii(
176 RTL_CONSTASCII_STRINGPARAM( "HTML" )));
177 break;
179 default:
180 // case SPLITDOC_TO_GLOBALDOC:
181 pFilter = SwIoSystem::GetFilterOfFormat(
182 String::CreateFromAscii( FILTER_XML ));
183 eDocType = SPLITDOC_TO_GLOBALDOC;
184 break;
187 if( !pFilter )
188 return FALSE;
190 // Undo/Redline aufjedenfall abschalten
191 DoUndo( FALSE );
192 SetRedlineMode_intern( (RedlineMode_t)(GetRedlineMode() & ~nsRedlineMode_t::REDLINE_ON));
194 String sExt( pFilter->GetSuffixes().GetToken(0, ',') );
195 if( !sExt.Len() )
196 sExt.AssignAscii( "sxw" );
197 if( '.' != sExt.GetChar( 0 ) )
198 sExt.Insert( '.', 0 );
200 INetURLObject aEntry(rPath);
201 String sLeading(aEntry.GetBase());
202 aEntry.removeSegment();
203 String sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
204 utl::TempFile aTemp(sLeading,&sExt,&sPath );
205 aTemp.EnableKillingFile();
207 DateTime aTmplDate;
209 Time a2Min( 0 ); a2Min.SetMin( 2 );
210 aTmplDate += a2Min;
214 // alle Ungueltigen ueberspringen
215 while( nOutl < pOutlNds->Count() &&
216 pOutlNds->GetObject( nOutl )->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
217 ++nOutl;
219 do {
220 pSttNd = 0;
222 SwNodePtr pNd;
223 for( ; nOutl < pOutlNds->Count(); ++nOutl )
224 if( ( pNd = pOutlNds->GetObject( nOutl ))->GetTxtNode()->
225 GetTxtColl() == pSplitColl &&
226 !pNd->FindTableNode() )
228 pSttNd = pNd;
229 break;
232 if( pSttNd )
234 SwNodePtr pEndNd = 0;
235 for( ++nOutl; nOutl < pOutlNds->Count(); ++nOutl )
237 pNd = pOutlNds->GetObject( nOutl );
238 SwTxtFmtColl* pTColl = pNd->GetTxtNode()->GetTxtColl();
240 //if( ( pTColl == pSplitColl || //#outline level,zhaojianwei
241 // ( NO_NUMBERING != pSplitColl->GetOutlineLevel() &&
242 // pTColl->GetOutlineLevel() <
243 // pSplitColl->GetOutlineLevel() )) &&
244 // !pNd->FindTableNode() )
245 if( ( pTColl == pSplitColl ||
246 ( pSplitColl->GetAttrOutlineLevel() > 0 &&
247 pTColl->GetAttrOutlineLevel() > 0 &&
248 pTColl->GetAttrOutlineLevel() <
249 pSplitColl->GetAttrOutlineLevel() )) &&
250 !pNd->FindTableNode() ) //<-end,zhaojianwei
252 pEndNd = pNd;
254 break;
257 SwNodeIndex aEndIdx( pEndNd ? *pEndNd
258 : GetNodes().GetEndOfContent() );
260 // die Nodes komplett rausschreiben
261 String sFileName;
262 if( pSttNd->GetIndex() + 1 < aEndIdx.GetIndex() )
264 SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
265 if( xDocSh->DoInitNew( 0 ) )
267 SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
269 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
270 ((SwDocShell*)(&xDocSh))->GetModel(),
271 uno::UNO_QUERY_THROW);
272 uno::Reference<document::XDocumentProperties> xDocProps(
273 xDPS->getDocumentProperties());
274 DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
275 // the GlobalDoc is the template
276 xDocProps->setTemplateName(aEmptyStr);
277 ::util::DateTime uDT(aTmplDate.Get100Sec(),
278 aTmplDate.GetSec(), aTmplDate.GetMin(),
279 aTmplDate.GetHour(), aTmplDate.GetDay(),
280 aTmplDate.GetMonth(), aTmplDate.GetYear());
281 xDocProps->setTemplateDate(uDT);
282 xDocProps->setTemplateURL(rPath);
283 //JP 14.06.99: Set the text of the "split para" as title
284 // from the new doc. Is the current doc has
285 // a title, insert it at begin.
286 String sTitle( xDocProps->getTitle() );
287 if( sTitle.Len() )
288 sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ));
289 sTitle += ((SwTxtNode*)pSttNd)->GetExpandTxt();
290 xDocProps->setTitle( sTitle );
292 // Vorlagen ersetzen
293 pDoc->ReplaceStyles( *this );
295 // KapitelNumerierung uebernehmen
296 if( pOutlineRule )
297 pDoc->SetOutlineNumRule( *pOutlineRule );
299 SwNodeRange aRg( *pSttNd, 0, aEndIdx.GetNode() );
300 SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() );
301 GetNodes()._Copy( aRg, aTmpIdx, FALSE );
303 // den initialen TextNode loeschen
304 SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 );
305 if( aIdx.GetIndex() + 1 !=
306 pDoc->GetNodes().GetEndOfContent().GetIndex() )
307 pDoc->GetNodes().Delete( aIdx, 1 );
309 // alle Flys in dem Bereich
310 CopyFlyInFlyImpl( aRg, 0, aIdx );
313 // und noch alle Bookmarks
314 // ?????
316 utl::TempFile aTempFile2(sLeading,&sExt,&sPath );
317 sFileName = aTempFile2.GetURL();
318 SfxMedium* pTmpMed = new SfxMedium( sFileName,
319 STREAM_STD_READWRITE, TRUE );
320 pTmpMed->SetFilter( pFilter );
322 // fuer den HTML-Filter mussen wir aber ein Layout
323 // haben, damit Textrahmen/Controls/OLE-Objecte korrekt
324 // als Grafik exportiert werden koennen.
325 if( SPLITDOC_TO_HTML == eDocType &&
326 pDoc->GetSpzFrmFmts()->Count() )
328 /* SfxViewFrame* pFrame = */
329 SfxViewFrame::CreateViewFrame( *xDocSh, 0, TRUE );
331 xDocSh->DoSaveAs( *pTmpMed );
332 xDocSh->DoSaveCompleted( pTmpMed );
334 // beim Fehler wird keine FileLinkSection eingefuegt
335 if( xDocSh->GetError() )
336 sFileName.Erase();
338 xDocSh->DoClose();
341 // dann koennen ja die Bereiche eingefuegt werden
342 if( sFileName.Len() )
344 switch( eDocType )
346 case SPLITDOC_TO_HTML:
348 // loesche alle Nodes im Bereich und setze im "Start-
349 // Node" den Link auf das gespeicherte Doc
350 ULONG nNodeDiff = aEndIdx.GetIndex() -
351 pSttNd->GetIndex() - 1;
352 if( nNodeDiff )
354 SwPaM aTmp( *pSttNd, aEndIdx.GetNode(), 1, -1 );
355 aTmp.GetPoint()->nContent.Assign( 0, 0 );
356 aTmp.GetMark()->nContent.Assign( 0, 0 );
357 SwNodeIndex aSIdx( aTmp.GetMark()->nNode );
358 SwNodeIndex aEIdx( aTmp.GetPoint()->nNode );
360 // versuche hinters Ende zu verschieben
361 if( !aTmp.Move( fnMoveForward, fnGoNode ) )
363 // na gut, dann an den Anfang
364 aTmp.Exchange();
365 if( !aTmp.Move( fnMoveBackward, fnGoNode ))
367 ASSERT( FALSE, "kein Node mehr vorhanden" );
370 // Bookmarks usw. verschieben
371 CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), TRUE);
373 // stehen noch FlyFrames rum, loesche auch diese
374 const SwPosition* pAPos;
375 for( USHORT n = 0; n < GetSpzFrmFmts()->Count(); ++n )
377 SwFrmFmt* pFly = (*GetSpzFrmFmts())[n];
378 const SwFmtAnchor* pAnchor = &pFly->GetAnchor();
379 if( ( FLY_AT_CNTNT == pAnchor->GetAnchorId() ||
380 FLY_AUTO_CNTNT == pAnchor->GetAnchorId() ) &&
381 0 != ( pAPos = pAnchor->GetCntntAnchor() ) &&
382 aSIdx <= pAPos->nNode &&
383 pAPos->nNode < aEIdx )
385 DelLayoutFmt( pFly );
386 --n;
390 GetNodes().Delete( aSIdx, nNodeDiff );
393 // dann setze im StartNode noch den Link:
394 SwFmtINetFmt aINet( sFileName , aEmptyStr );
395 SwTxtNode* pTNd = (SwTxtNode*)pSttNd;
396 pTNd->InsertItem( aINet, 0, pTNd->GetTxt().Len() );
398 // wenn der nicht mehr gefunden wird, kann das nur
399 // ein Bug sein!
400 if( !pOutlNds->Seek_Entry( pSttNd, &nOutl ))
401 pSttNd = 0;
402 ++nOutl;
404 break;
406 default:
408 String sNm( INetURLObject( sFileName ).GetName() );
409 SwSection aSect( FILE_LINK_SECTION,
410 GetUniqueSectionName( &sNm ));
411 SwSectionFmt* pFmt = MakeSectionFmt( 0 );
412 aSect.SetLinkFileName(sFileName );
413 aSect.SetProtect();
415 aEndIdx--; // im InsertSection ist Ende inclusive
416 while( aEndIdx.GetNode().IsStartNode() )
417 aEndIdx--;
419 // JP 06.07.99 - Bug 67361 - is any Section ends or
420 // starts in the new sectionrange, they must end or
421 // start before or behind the range!
422 SwSectionNode* pSectNd = pSttNd->FindSectionNode();
423 while( pSectNd && pSectNd->EndOfSectionIndex()
424 <= aEndIdx.GetIndex() )
426 const SwNode* pSectEnd = pSectNd->EndOfSectionNode();
427 if( pSectNd->GetIndex() + 1 ==
428 pSttNd->GetIndex() )
430 BOOL bMvIdx = aEndIdx == *pSectEnd;
431 DelSectionFmt( pSectNd->GetSection().GetFmt() );
432 if( bMvIdx )
433 aEndIdx--;
435 else
437 SwNodeRange aRg( *pSttNd, *pSectEnd );
438 SwNodeIndex aIdx( *pSectEnd, 1 );
439 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
441 pSectNd = pSttNd->FindSectionNode();
444 pSectNd = aEndIdx.GetNode().FindSectionNode();
445 while( pSectNd && pSectNd->GetIndex() >
446 pSttNd->GetIndex() )
448 // #i15712# don't attempt to split sections if
449 // they are fully enclosed in [pSectNd,aEndIdx].
450 if( aEndIdx < pSectNd->EndOfSectionIndex() )
452 SwNodeRange aRg( *pSectNd, 1, aEndIdx, 1 );
453 SwNodeIndex aIdx( *pSectNd );
454 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
457 pSectNd = pSttNd->FindSectionNode();
460 // -> #i26762#
461 // Ensure order of start and end of section is sane.
462 SwNodeIndex aStartIdx(*pSttNd);
464 if (aEndIdx >= aStartIdx)
465 pSectNd = GetNodes().InsertSection
466 (aStartIdx, *pFmt, aSect, &aEndIdx, FALSE );
467 else
468 pSectNd = GetNodes().InsertSection
469 (aEndIdx, *pFmt, aSect, &aStartIdx, FALSE );
470 // <- #i26762#
472 pSectNd->GetSection().CreateLink( CREATE_CONNECT );
474 break;
478 } while( pSttNd );
480 // if( pOutlNds != (SwOutlineNodes*)&GetNodes().GetOutLineNds();
481 if( pOutlNds != &GetNodes().GetOutLineNds() )
482 delete pOutlNds;
484 switch( eDocType )
486 case SPLITDOC_TO_HTML:
487 if( get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
489 // dann alles verbliebenen Bereiche aufheben
490 while( GetSections().Count() )
491 DelSectionFmt( GetSections()[ 0 ] );
493 SfxFilterContainer* pFCntnr = pDocShell->GetFactory().GetFilterContainer();
494 pFilter = pFCntnr->GetFilter4EA( pFilter->GetTypeName(), SFX_FILTER_EXPORT );
496 break;
498 // case SPLITDOC_TO_GLOBALDOC:
499 default:
500 // dann das Globaldoc speichern
501 set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
502 set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
505 // Medium istn't locked after reopen the document. Bug 91462
506 SfxRequest aReq( SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, GetAttrPool() );
507 aReq.AppendItem( SfxStringItem( SID_FILE_NAME, rPath ) );
508 aReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
509 if(pFilter)
510 aReq.AppendItem( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
511 const SfxBoolItem *pRet = (const SfxBoolItem*)pDocShell->ExecuteSlot( aReq );
513 return pRet && pRet->GetValue();
516 //#outline level,add by zhaojianwei
517 BOOL SwDoc::SplitDoc( USHORT eDocType, const String& rPath, int nOutlineLevel )
519 if( !pDocShell || !pDocShell->GetMedium() ||
520 ( SPLITDOC_TO_GLOBALDOC == eDocType && get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ) )
521 return FALSE;
523 USHORT nOutl = 0;
524 SwOutlineNodes* pOutlNds = (SwOutlineNodes*)&GetNodes().GetOutLineNds();
525 SwNodePtr pSttNd;
527 const SfxFilter* pFilter;
528 switch( eDocType )
530 case SPLITDOC_TO_HTML:
531 pFilter = SwIoSystem::GetFilterOfFormat( String::CreateFromAscii(
532 RTL_CONSTASCII_STRINGPARAM( "HTML" )));
533 break;
535 default:
536 // case SPLITDOC_TO_GLOBALDOC:
537 pFilter = SwIoSystem::GetFilterOfFormat(
538 String::CreateFromAscii( FILTER_XML ));
539 eDocType = SPLITDOC_TO_GLOBALDOC;
540 break;
543 if( !pFilter )
544 return FALSE;
546 // Undo/Redline aufjedenfall abschalten
547 DoUndo( FALSE );
548 SetRedlineMode_intern( (RedlineMode_t)(GetRedlineMode() & ~nsRedlineMode_t::REDLINE_ON));
550 String sExt( pFilter->GetSuffixes().GetToken(0, ',') );
551 if( !sExt.Len() )
552 sExt.AssignAscii( "sxw" );
553 if( '.' != sExt.GetChar( 0 ) )
554 sExt.Insert( '.', 0 );
556 INetURLObject aEntry(rPath);
557 String sLeading(aEntry.GetBase());
558 aEntry.removeSegment();
559 String sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
560 utl::TempFile aTemp(sLeading,&sExt,&sPath );
561 aTemp.EnableKillingFile();
563 DateTime aTmplDate;
565 Time a2Min( 0 ); a2Min.SetMin( 2 );
566 aTmplDate += a2Min;
570 // alle Ungueltigen ueberspringen
571 while( nOutl < pOutlNds->Count() &&
572 pOutlNds->GetObject( nOutl )->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
573 ++nOutl;
575 do {
576 pSttNd = 0;
578 SwNodePtr pNd;
579 for( ; nOutl < pOutlNds->Count(); ++nOutl )
580 if( ( pNd = pOutlNds->GetObject( nOutl ))->GetTxtNode()->GetAttrOutlineLevel() == nOutlineLevel &&
581 !pNd->FindTableNode() )
583 pSttNd = pNd;
584 break;
587 if( pSttNd )
589 SwNodePtr pEndNd = 0;
590 for( ++nOutl; nOutl < pOutlNds->Count(); ++nOutl )
592 pNd = pOutlNds->GetObject( nOutl );
594 const int nLevel = pNd->GetTxtNode()->GetAttrOutlineLevel();
596 if( ( 0 < nLevel && nLevel <= nOutlineLevel ) &&
597 !pNd->FindTableNode() )
599 pEndNd = pNd;
601 break;
604 SwNodeIndex aEndIdx( pEndNd ? *pEndNd
605 : GetNodes().GetEndOfContent() );
607 String sFileName;
608 if( pSttNd->GetIndex() + 1 < aEndIdx.GetIndex() )
610 SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
611 if( xDocSh->DoInitNew( 0 ) )
613 SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
615 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
616 ((SwDocShell*)(&xDocSh))->GetModel(),
617 uno::UNO_QUERY_THROW);
618 uno::Reference<document::XDocumentProperties> xDocProps(
619 xDPS->getDocumentProperties());
620 DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
621 // the GlobalDoc is the template
622 xDocProps->setTemplateName(aEmptyStr);
623 ::util::DateTime uDT(aTmplDate.Get100Sec(),
624 aTmplDate.GetSec(), aTmplDate.GetMin(),
625 aTmplDate.GetHour(), aTmplDate.GetDay(),
626 aTmplDate.GetMonth(), aTmplDate.GetYear());
627 xDocProps->setTemplateDate(uDT);
628 xDocProps->setTemplateURL(rPath);
629 //JP 14.06.99: Set the text of the "split para" as title
630 // from the new doc. Is the current doc has
631 // a title, insert it at begin.
632 String sTitle( xDocProps->getTitle() );
633 if( sTitle.Len() )
634 sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ));
635 sTitle += ((SwTxtNode*)pSttNd)->GetExpandTxt();
636 xDocProps->setTitle( sTitle );
638 // Vorlagen ersetzen
639 pDoc->ReplaceStyles( *this );
641 // KapitelNumerierung uebernehmen
642 if( pOutlineRule )
643 pDoc->SetOutlineNumRule( *pOutlineRule );
645 SwNodeRange aRg( *pSttNd, 0, aEndIdx.GetNode() );
646 SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() );
647 GetNodes()._Copy( aRg, aTmpIdx, FALSE );
649 // den initialen TextNode loeschen
650 SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 );
651 if( aIdx.GetIndex() + 1 !=
652 pDoc->GetNodes().GetEndOfContent().GetIndex() )
653 pDoc->GetNodes().Delete( aIdx, 1 );
655 // alle Flys in dem Bereich
656 CopyFlyInFlyImpl( aRg, 0, aIdx );
659 // und noch alle Bookmarks
660 // ?????
662 utl::TempFile aTempFile2(sLeading,&sExt,&sPath );
663 sFileName = aTempFile2.GetURL();
664 SfxMedium* pTmpMed = new SfxMedium( sFileName,
665 STREAM_STD_READWRITE, TRUE );
666 pTmpMed->SetFilter( pFilter );
668 // fuer den HTML-Filter mussen wir aber ein Layout
669 // haben, damit Textrahmen/Controls/OLE-Objecte korrekt
670 // als Grafik exportiert werden koennen.
671 if( SPLITDOC_TO_HTML == eDocType &&
672 pDoc->GetSpzFrmFmts()->Count() )
674 /* SfxViewFrame* pFrame = */
675 SfxViewFrame::CreateViewFrame( *xDocSh, 0, TRUE );
677 xDocSh->DoSaveAs( *pTmpMed );
678 xDocSh->DoSaveCompleted( pTmpMed );
680 // beim Fehler wird keine FileLinkSection eingefuegt
681 if( xDocSh->GetError() )
682 sFileName.Erase();
684 xDocSh->DoClose();
687 // dann koennen ja die Bereiche eingefuegt werden
688 if( sFileName.Len() )
690 switch( eDocType )
692 case SPLITDOC_TO_HTML:
694 // loesche alle Nodes im Bereich und setze im "Start-
695 // Node" den Link auf das gespeicherte Doc
696 ULONG nNodeDiff = aEndIdx.GetIndex() -
697 pSttNd->GetIndex() - 1;
698 if( nNodeDiff )
700 SwPaM aTmp( *pSttNd, aEndIdx.GetNode(), 1, -1 );
701 aTmp.GetPoint()->nContent.Assign( 0, 0 );
702 aTmp.GetMark()->nContent.Assign( 0, 0 );
703 SwNodeIndex aSIdx( aTmp.GetMark()->nNode );
704 SwNodeIndex aEIdx( aTmp.GetPoint()->nNode );
706 // versuche hinters Ende zu verschieben
707 if( !aTmp.Move( fnMoveForward, fnGoNode ) )
709 // na gut, dann an den Anfang
710 aTmp.Exchange();
711 if( !aTmp.Move( fnMoveBackward, fnGoNode ))
713 ASSERT( FALSE, "kein Node mehr vorhanden" );
716 // Bookmarks usw. verschieben
717 CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), TRUE);
719 // stehen noch FlyFrames rum, loesche auch diese
720 const SwPosition* pAPos;
721 for( USHORT n = 0; n < GetSpzFrmFmts()->Count(); ++n )
723 SwFrmFmt* pFly = (*GetSpzFrmFmts())[n];
724 const SwFmtAnchor* pAnchor = &pFly->GetAnchor();
725 if( ( FLY_AT_CNTNT == pAnchor->GetAnchorId() ||
726 FLY_AUTO_CNTNT == pAnchor->GetAnchorId() ) &&
727 0 != ( pAPos = pAnchor->GetCntntAnchor() ) &&
728 aSIdx <= pAPos->nNode &&
729 pAPos->nNode < aEIdx )
731 DelLayoutFmt( pFly );
732 --n;
736 GetNodes().Delete( aSIdx, nNodeDiff );
739 // dann setze im StartNode noch den Link:
740 SwFmtINetFmt aINet( sFileName , aEmptyStr );
741 SwTxtNode* pTNd = (SwTxtNode*)pSttNd;
742 pTNd->InsertItem( aINet, 0, pTNd->GetTxt().Len() );
744 // wenn der nicht mehr gefunden wird, kann das nur
745 // ein Bug sein!
746 if( !pOutlNds->Seek_Entry( pSttNd, &nOutl ))
747 pSttNd = 0;
748 ++nOutl;
750 break;
752 default:
754 String sNm( INetURLObject( sFileName ).GetName() );
755 SwSection aSect( FILE_LINK_SECTION,
756 GetUniqueSectionName( &sNm ));
757 SwSectionFmt* pFmt = MakeSectionFmt( 0 );
758 aSect.SetLinkFileName(sFileName );
759 aSect.SetProtect();
761 aEndIdx--; // im InsertSection ist Ende inclusive
762 while( aEndIdx.GetNode().IsStartNode() )
763 aEndIdx--;
765 // JP 06.07.99 - Bug 67361 - is any Section ends or
766 // starts in the new sectionrange, they must end or
767 // start before or behind the range!
768 SwSectionNode* pSectNd = pSttNd->FindSectionNode();
769 while( pSectNd && pSectNd->EndOfSectionIndex()
770 <= aEndIdx.GetIndex() )
772 const SwNode* pSectEnd = pSectNd->EndOfSectionNode();
773 if( pSectNd->GetIndex() + 1 ==
774 pSttNd->GetIndex() )
776 BOOL bMvIdx = aEndIdx == *pSectEnd;
777 DelSectionFmt( pSectNd->GetSection().GetFmt() );
778 if( bMvIdx )
779 aEndIdx--;
781 else
783 SwNodeRange aRg( *pSttNd, *pSectEnd );
784 SwNodeIndex aIdx( *pSectEnd, 1 );
785 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
787 pSectNd = pSttNd->FindSectionNode();
790 pSectNd = aEndIdx.GetNode().FindSectionNode();
791 while( pSectNd && pSectNd->GetIndex() >
792 pSttNd->GetIndex() )
794 if( aEndIdx < pSectNd->EndOfSectionIndex() )
796 SwNodeRange aRg( *pSectNd, 1, aEndIdx, 1 );
797 SwNodeIndex aIdx( *pSectNd );
798 GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
801 pSectNd = pSttNd->FindSectionNode();
804 SwNodeIndex aStartIdx(*pSttNd);
806 if (aEndIdx >= aStartIdx)
807 pSectNd = GetNodes().InsertSection
808 (aStartIdx, *pFmt, aSect, &aEndIdx, FALSE );
809 else
810 pSectNd = GetNodes().InsertSection
811 (aEndIdx, *pFmt, aSect, &aStartIdx, FALSE );
813 pSectNd->GetSection().CreateLink( CREATE_CONNECT );
815 break;
819 } while( pSttNd );
821 if( pOutlNds != &GetNodes().GetOutLineNds() )
822 delete pOutlNds;
824 switch( eDocType )
826 case SPLITDOC_TO_HTML:
827 if( get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
829 while( GetSections().Count() )
830 DelSectionFmt( GetSections()[ 0 ] );
832 SfxFilterContainer* pFCntnr = pDocShell->GetFactory().GetFilterContainer();
833 pFilter = pFCntnr->GetFilter4EA( pFilter->GetTypeName(), SFX_FILTER_EXPORT );
835 break;
837 // case SPLITDOC_TO_GLOBALDOC:
838 default:
839 set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
840 set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
843 SfxRequest aReq( SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, GetAttrPool() );
844 aReq.AppendItem( SfxStringItem( SID_FILE_NAME, rPath ) );
845 aReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
846 if(pFilter)
847 aReq.AppendItem( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
848 const SfxBoolItem *pRet = (const SfxBoolItem*)pDocShell->ExecuteSlot( aReq );
850 return pRet && pRet->GetValue();
851 }//<-end,zhaojianwei