Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : : #include <unotools/tempfile.hxx>
31 : : #include <svl/urihelper.hxx>
32 : : #include <svl/stritem.hxx>
33 : : #include <svl/eitem.hxx>
34 : : #include <sfx2/app.hxx>
35 : : #include <sfx2/docfile.hxx>
36 : : #include <sfx2/docfilt.hxx>
37 : : #include <sfx2/fcontnr.hxx>
38 : : #include <sfx2/bindings.hxx>
39 : : #include <sfx2/request.hxx>
40 : : #include <fmtinfmt.hxx>
41 : : #include <fmtanchr.hxx>
42 : : #include <doc.hxx>
43 : : #include <IDocumentUndoRedo.hxx>
44 : : #include <docary.hxx>
45 : : #include <pam.hxx>
46 : : #include <ndtxt.hxx>
47 : : #include <docsh.hxx>
48 : : #include <globdoc.hxx>
49 : : #include <shellio.hxx>
50 : : #include <swundo.hxx> // for the UndoIds
51 : : #include <section.hxx>
52 : : #include <doctxm.hxx>
53 : : #include <poolfmt.hxx>
54 : : #include <switerator.hxx>
55 : : #include <com/sun/star/uno/Reference.h>
56 : : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
57 : : #include <com/sun/star/document/XDocumentProperties.hpp>
58 : :
59 : : using namespace ::com::sun::star;
60 : :
61 : : enum SwSplitDocType
62 : : {
63 : : SPLITDOC_TO_GLOBALDOC,
64 : : SPLITDOC_TO_HTML
65 : : };
66 : :
67 : 0 : sal_Bool SwDoc::GenerateGlobalDoc( const String& rPath,
68 : : const SwTxtFmtColl* pSplitColl )
69 : : {
70 : 0 : return SplitDoc( SPLITDOC_TO_GLOBALDOC, rPath, false, pSplitColl, 0 );
71 : : }
72 : :
73 : 0 : sal_Bool SwDoc::GenerateGlobalDoc( const String& rPath, int nOutlineLevel )
74 : : {
75 : 0 : return SplitDoc( SPLITDOC_TO_GLOBALDOC, rPath, true, 0, nOutlineLevel );
76 : : }
77 : :
78 : 0 : sal_Bool SwDoc::GenerateHTMLDoc( const String& rPath, int nOutlineLevel )
79 : : {
80 : 0 : return SplitDoc( SPLITDOC_TO_HTML, rPath, true, 0, nOutlineLevel );
81 : : }
82 : :
83 : 0 : sal_Bool SwDoc::GenerateHTMLDoc( const String& rPath,
84 : : const SwTxtFmtColl* pSplitColl )
85 : : {
86 : 0 : return SplitDoc( SPLITDOC_TO_HTML, rPath, false, pSplitColl, 0 );
87 : : }
88 : :
89 : : // two helpers for outline mode
90 : 0 : SwNodePtr GetStartNode( SwOutlineNodes* pOutlNds, int nOutlineLevel, sal_uInt16* nOutl )
91 : : {
92 : : SwNodePtr pNd;
93 : :
94 [ # # ]: 0 : for( ; *nOutl < pOutlNds->size(); ++(*nOutl) )
95 [ # # ][ # # ]: 0 : if( ( pNd = (*pOutlNds)[ *nOutl ])->GetTxtNode()->GetAttrOutlineLevel() == nOutlineLevel && !pNd->FindTableNode() )
[ # # ]
96 : : {
97 : 0 : return pNd;
98 : : }
99 : :
100 : 0 : return 0;
101 : : }
102 : :
103 : 0 : SwNodePtr GetEndNode( SwOutlineNodes* pOutlNds, int nOutlineLevel, sal_uInt16* nOutl )
104 : : {
105 : : SwNodePtr pNd;
106 : :
107 [ # # ]: 0 : for( ++(*nOutl); (*nOutl) < pOutlNds->size(); ++(*nOutl) )
108 : : {
109 : 0 : pNd = (*pOutlNds)[ *nOutl ];
110 : :
111 : 0 : const int nLevel = pNd->GetTxtNode()->GetAttrOutlineLevel();
112 : :
113 [ # # # # ]: 0 : if( ( 0 < nLevel && nLevel <= nOutlineLevel ) &&
[ # # ][ # # ]
114 : 0 : !pNd->FindTableNode() )
115 : : {
116 : 0 : return pNd;
117 : : }
118 : : }
119 : 0 : return 0;
120 : : }
121 : :
122 : : // two helpers for collection mode
123 : 0 : SwNodePtr GetStartNode( const SwOutlineNodes* pOutlNds, const SwTxtFmtColl* pSplitColl, sal_uInt16* nOutl )
124 : : {
125 : : SwNodePtr pNd;
126 [ # # ]: 0 : for( ; *nOutl < pOutlNds->size(); ++(*nOutl) )
127 [ # # # # ]: 0 : if( ( pNd = (*pOutlNds)[ *nOutl ])->GetTxtNode()->
[ # # ]
128 : 0 : GetTxtColl() == pSplitColl &&
129 : 0 : !pNd->FindTableNode() )
130 : : {
131 : 0 : return pNd;
132 : : }
133 : 0 : return 0;
134 : : }
135 : :
136 : 0 : SwNodePtr GetEndNode( const SwOutlineNodes* pOutlNds, const SwTxtFmtColl* pSplitColl, sal_uInt16* nOutl )
137 : : {
138 : : SwNodePtr pNd;
139 : :
140 [ # # ]: 0 : for( ++(*nOutl); *nOutl < pOutlNds->size(); ++(*nOutl) )
141 : : {
142 : 0 : pNd = (*pOutlNds)[ *nOutl ];
143 : 0 : SwTxtFmtColl* pTColl = pNd->GetTxtNode()->GetTxtColl();
144 : :
145 [ # # ][ # # : 0 : if( ( pTColl == pSplitColl ||
# # # # #
# # # ]
146 : 0 : ( pSplitColl->GetAttrOutlineLevel() > 0 &&
147 : 0 : pTColl->GetAttrOutlineLevel() > 0 &&
148 : 0 : pTColl->GetAttrOutlineLevel() <
149 : 0 : pSplitColl->GetAttrOutlineLevel() )) &&
150 : 0 : !pNd->FindTableNode() )
151 : : {
152 : 0 : return pNd;
153 : : }
154 : : }
155 : 0 : return 0;
156 : : }
157 : :
158 : 0 : bool SwDoc::SplitDoc( sal_uInt16 eDocType, const String& rPath, bool bOutline, const SwTxtFmtColl* pSplitColl, int nOutlineLevel )
159 : : {
160 : : // Iterate over all the template's Nodes, creating an own
161 : : // document for every single one and replace linked sections (GlobalDoc) for links (HTML).
162 : : // Finally, we save this document as a GlobalDoc/HTMLDoc.
163 [ # # ][ # # ]: 0 : if( !pDocShell || !pDocShell->GetMedium() ||
[ # # ][ # # ]
[ # # ]
164 [ # # ]: 0 : ( SPLITDOC_TO_GLOBALDOC == eDocType && get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ) )
165 : 0 : return false;
166 : :
167 : 0 : sal_uInt16 nOutl = 0;
168 [ # # ][ # # ]: 0 : SwOutlineNodes* pOutlNds = (SwOutlineNodes*)&GetNodes().GetOutLineNds();
169 : : SwNodePtr pStartNd;
170 : :
171 [ # # ]: 0 : if ( !bOutline) {
172 [ # # ]: 0 : if( pSplitColl )
173 : : {
174 : : // If it isn't a OutlineNumbering, then use an own array and collect the Nodes.
175 [ # # ][ # # ]: 0 : if( pSplitColl->GetAttrOutlineLevel() == 0 )//<-end,zhaojianwei, 0814
176 : : {
177 [ # # ][ # # ]: 0 : pOutlNds = new SwOutlineNodes;
178 [ # # ]: 0 : SwIterator<SwTxtNode,SwFmtColl> aIter( *pSplitColl );
179 [ # # ][ # # ]: 0 : for( SwTxtNode* pTNd = aIter.First(); pTNd; pTNd = aIter.Next() )
[ # # ]
180 [ # # ][ # # ]: 0 : if( pTNd->GetNodes().IsDocNodes() )
181 [ # # ][ # # ]: 0 : pOutlNds->insert( pTNd );
182 : :
183 [ # # ]: 0 : if( pOutlNds->empty() )
184 : : {
185 [ # # ]: 0 : delete pOutlNds;
186 : 0 : return false;
187 [ # # ][ # # ]: 0 : }
188 : : }
189 : : }
190 : : else
191 : : {
192 : : // Look for the 1st level OutlineTemplate
193 : 0 : const SwTxtFmtColls& rFmtColls =*GetTxtFmtColls();
194 [ # # ]: 0 : for( sal_uInt16 n = rFmtColls.size(); n; )
195 [ # # ][ # # ]: 0 : if ( rFmtColls[ --n ]->GetAttrOutlineLevel() == 1 )//<-end,zhaojianwei
[ # # ]
196 : : {
197 [ # # ]: 0 : pSplitColl = rFmtColls[ n ];
198 : 0 : break;
199 : : }
200 : :
201 [ # # ]: 0 : if( !pSplitColl )
202 : 0 : return false;
203 : : }
204 : : }
205 : :
206 : : const SfxFilter* pFilter;
207 [ # # ]: 0 : switch( eDocType )
208 : : {
209 : : case SPLITDOC_TO_HTML:
210 [ # # ][ # # ]: 0 : pFilter = SwIoSystem::GetFilterOfFormat(rtl::OUString("HTML"));
[ # # ]
211 : 0 : break;
212 : :
213 : : default:
214 [ # # ][ # # ]: 0 : pFilter = SwIoSystem::GetFilterOfFormat(rtl::OUString(FILTER_XML));
[ # # ]
215 : 0 : eDocType = SPLITDOC_TO_GLOBALDOC;
216 : 0 : break;
217 : : }
218 : :
219 [ # # ]: 0 : if( !pFilter )
220 : 0 : return false;
221 : :
222 : : // Deactivate Undo/Redline in any case
223 [ # # ][ # # ]: 0 : GetIDocumentUndoRedo().DoUndo(false);
224 [ # # ][ # # ]: 0 : SetRedlineMode_intern( (RedlineMode_t)(GetRedlineMode() & ~nsRedlineMode_t::REDLINE_ON));
225 : :
226 [ # # ][ # # ]: 0 : String sExt( pFilter->GetSuffixes().GetToken(0, ',') );
[ # # ]
227 [ # # ]: 0 : if( !sExt.Len() )
228 [ # # ]: 0 : sExt.AssignAscii( "sxw" );
229 [ # # ]: 0 : if( '.' != sExt.GetChar( 0 ) )
230 [ # # ]: 0 : sExt.Insert( '.', 0 );
231 : :
232 [ # # ][ # # ]: 0 : INetURLObject aEntry(rPath);
233 [ # # ][ # # ]: 0 : String sLeading(aEntry.GetBase());
234 [ # # ]: 0 : aEntry.removeSegment();
235 [ # # ][ # # ]: 0 : String sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
236 [ # # ]: 0 : utl::TempFile aTemp(sLeading,&sExt,&sPath );
237 : 0 : aTemp.EnableKillingFile();
238 : :
239 [ # # ]: 0 : DateTime aTmplDate( DateTime::SYSTEM );
240 : : {
241 [ # # ]: 0 : Time a2Min( 0 ); a2Min.SetMin( 2 );
242 [ # # ]: 0 : aTmplDate += a2Min;
243 : : }
244 : :
245 : :
246 : : // Skip all invalid ones
247 [ # # # # ]: 0 : while( nOutl < pOutlNds->size() &&
[ # # ]
248 [ # # ][ # # ]: 0 : (*pOutlNds)[ nOutl ]->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
249 : 0 : ++nOutl;
250 : :
251 [ # # ]: 0 : do {
252 [ # # ]: 0 : if( bOutline )
253 [ # # ]: 0 : pStartNd = GetStartNode( pOutlNds, nOutlineLevel, &nOutl );
254 : : else
255 [ # # ]: 0 : pStartNd = GetStartNode( pOutlNds, pSplitColl, &nOutl );
256 : :
257 [ # # ]: 0 : if( pStartNd )
258 : : {
259 : : SwNodePtr pEndNd;
260 [ # # ]: 0 : if( bOutline )
261 [ # # ]: 0 : pEndNd = GetEndNode( pOutlNds, nOutlineLevel, &nOutl );
262 : : else
263 [ # # ]: 0 : pEndNd = GetEndNode( pOutlNds, pSplitColl, &nOutl );
264 : : SwNodeIndex aEndIdx( pEndNd ? *pEndNd
265 [ # # ][ # # ]: 0 : : GetNodes().GetEndOfContent() );
[ # # ]
266 : :
267 : : // Write out the Nodes completely
268 [ # # ]: 0 : String sFileName;
269 [ # # ]: 0 : if( pStartNd->GetIndex() + 1 < aEndIdx.GetIndex() )
270 : : {
271 [ # # ][ # # ]: 0 : SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
[ # # ]
272 [ # # ][ # # ]: 0 : if( xDocSh->DoInitNew( 0 ) )
273 : : {
274 : 0 : SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
275 : :
276 : : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
277 : 0 : ((SwDocShell*)(&xDocSh))->GetModel(),
278 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW);
279 : : uno::Reference<document::XDocumentProperties> xDocProps(
280 [ # # ][ # # ]: 0 : xDPS->getDocumentProperties());
281 : : OSL_ENSURE(xDocProps.is(), "Doc has no DocumentProperties");
282 : : // the GlobalDoc is the template
283 [ # # ][ # # ]: 0 : xDocProps->setTemplateName(aEmptyStr);
[ # # ]
284 : 0 : ::util::DateTime uDT(aTmplDate.Get100Sec(),
285 : 0 : aTmplDate.GetSec(), aTmplDate.GetMin(),
286 : 0 : aTmplDate.GetHour(), aTmplDate.GetDay(),
287 : 0 : aTmplDate.GetMonth(), aTmplDate.GetYear());
288 [ # # ][ # # ]: 0 : xDocProps->setTemplateDate(uDT);
289 [ # # ][ # # ]: 0 : xDocProps->setTemplateURL(rPath);
[ # # ]
290 : : // Set the new doc's title to the text of the "split para".
291 : : // If the current doc has a title, insert it at the begin.
292 [ # # ][ # # ]: 0 : String sTitle( xDocProps->getTitle() );
[ # # ]
293 [ # # ]: 0 : if( sTitle.Len() )
294 [ # # ]: 0 : sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ));
295 [ # # ][ # # ]: 0 : sTitle += ((SwTxtNode*)pStartNd)->GetExpandTxt();
[ # # ][ # # ]
296 [ # # ][ # # ]: 0 : xDocProps->setTitle( sTitle );
[ # # ]
297 : :
298 : : // Replace template
299 [ # # ]: 0 : pDoc->ReplaceStyles( *this );
300 : :
301 : : // Take over chapter numbering
302 [ # # ]: 0 : if( pOutlineRule )
303 [ # # ]: 0 : pDoc->SetOutlineNumRule( *pOutlineRule );
304 : :
305 [ # # ]: 0 : SwNodeRange aRg( *pStartNd, 0, aEndIdx.GetNode() );
306 [ # # ][ # # ]: 0 : SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() );
307 [ # # ][ # # ]: 0 : GetNodes()._Copy( aRg, aTmpIdx, sal_False );
308 : :
309 : : // Delete the initial TextNode
310 [ # # ][ # # ]: 0 : SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 );
311 [ # # ]: 0 : if( aIdx.GetIndex() + 1 !=
312 [ # # ]: 0 : pDoc->GetNodes().GetEndOfContent().GetIndex() )
313 [ # # ][ # # ]: 0 : pDoc->GetNodes().Delete( aIdx, 1 );
314 : :
315 : : // All Flys in the section
316 [ # # ]: 0 : CopyFlyInFlyImpl( aRg, 0, aIdx );
317 : :
318 : :
319 : : // And what's with all the Bookmarks?
320 : : // ?????
321 : :
322 [ # # ]: 0 : utl::TempFile aTempFile2(sLeading,&sExt,&sPath );
323 [ # # ][ # # ]: 0 : sFileName = aTempFile2.GetURL();
[ # # ]
324 : : SfxMedium* pTmpMed = new SfxMedium( sFileName,
325 [ # # ][ # # ]: 0 : STREAM_STD_READWRITE );
326 [ # # ]: 0 : pTmpMed->SetFilter( pFilter );
327 : :
328 : : // We need to have a Layout for the HTMLFilter, so that
329 : : // TextFrames/Controls/OLE objects can be exported correctly as graphics.
330 [ # # # # ]: 0 : if( SPLITDOC_TO_HTML == eDocType &&
[ # # ]
331 : 0 : !pDoc->GetSpzFrmFmts()->empty() )
332 : : {
333 [ # # ]: 0 : SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
334 : : }
335 [ # # ]: 0 : xDocSh->DoSaveAs( *pTmpMed );
336 [ # # ]: 0 : xDocSh->DoSaveCompleted( pTmpMed );
337 : :
338 : : // do not insert a FileLinkSection in case of error
339 [ # # ][ # # ]: 0 : if( xDocSh->GetError() )
340 [ # # ][ # # ]: 0 : sFileName.Erase();
[ # # ][ # # ]
[ # # ][ # # ]
341 : : }
342 [ # # ][ # # ]: 0 : xDocSh->DoClose();
343 : : }
344 : :
345 : : // We can now insert the section
346 [ # # ]: 0 : if( sFileName.Len() )
347 : : {
348 [ # # ]: 0 : switch( eDocType )
349 : : {
350 : : case SPLITDOC_TO_HTML:
351 : : {
352 : : // Delete all nodes in the section and, in the "start node",
353 : : // set the Link to the saved document.
354 : 0 : sal_uLong nNodeDiff = aEndIdx.GetIndex() -
355 : 0 : pStartNd->GetIndex() - 1;
356 [ # # ]: 0 : if( nNodeDiff )
357 : : {
358 [ # # ]: 0 : SwPaM aTmp( *pStartNd, aEndIdx.GetNode(), 1, -1 );
359 [ # # ]: 0 : aTmp.GetPoint()->nContent.Assign( 0, 0 );
360 [ # # ]: 0 : aTmp.GetMark()->nContent.Assign( 0, 0 );
361 [ # # ]: 0 : SwNodeIndex aSIdx( aTmp.GetMark()->nNode );
362 [ # # ]: 0 : SwNodeIndex aEIdx( aTmp.GetPoint()->nNode );
363 : :
364 : : // Try to move past the end
365 [ # # ][ # # ]: 0 : if( !aTmp.Move( fnMoveForward, fnGoNode ) )
366 : : {
367 : : // well then, back to the beginning
368 : 0 : aTmp.Exchange();
369 [ # # ]: 0 : if( !aTmp.Move( fnMoveBackward, fnGoNode ))
370 : : {
371 : : OSL_FAIL( "no more Nodes!" );
372 : : }
373 : : }
374 : : // Move Bookmarks and so forth
375 [ # # ]: 0 : CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), sal_True);
376 : :
377 : : // If FlyFrames are still around, delete these too
378 [ # # ]: 0 : for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n )
379 : : {
380 : 0 : SwFrmFmt* pFly = (*GetSpzFrmFmts())[n];
381 [ # # ]: 0 : const SwFmtAnchor* pAnchor = &pFly->GetAnchor();
382 : : SwPosition const*const pAPos =
383 [ # # ]: 0 : pAnchor->GetCntntAnchor();
384 [ # # # # : 0 : if (pAPos &&
# # # # #
# ][ # # ]
385 : 0 : ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
386 : 0 : (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
387 : 0 : aSIdx <= pAPos->nNode &&
388 : 0 : pAPos->nNode < aEIdx )
389 : : {
390 [ # # ]: 0 : DelLayoutFmt( pFly );
391 : 0 : --n;
392 : : }
393 : : }
394 : :
395 [ # # ][ # # ]: 0 : GetNodes().Delete( aSIdx, nNodeDiff );
[ # # ][ # # ]
[ # # ]
396 : : }
397 : :
398 : : // set the link in the StartNode
399 [ # # ]: 0 : SwFmtINetFmt aINet( sFileName , aEmptyStr );
400 [ # # ]: 0 : SwTxtNode* pTNd = (SwTxtNode*)pStartNd;
401 [ # # ]: 0 : pTNd->InsertItem( aINet, 0, pTNd->GetTxt().Len() );
402 : :
403 : : // If the link cannot be found anymore,
404 : : // it has to be a bug!
405 [ # # ][ # # ]: 0 : if( !pOutlNds->Seek_Entry( pStartNd, &nOutl ))
406 : 0 : pStartNd = 0;
407 [ # # ]: 0 : ++nOutl;
408 : : }
409 : 0 : break;
410 : :
411 : : default:
412 : : {
413 [ # # ][ # # ]: 0 : String sNm( INetURLObject( sFileName ).GetName() );
[ # # ][ # # ]
[ # # ]
414 : : SwSectionData aSectData( FILE_LINK_SECTION,
415 [ # # ][ # # ]: 0 : GetUniqueSectionName( &sNm ));
[ # # ]
416 [ # # ]: 0 : SwSectionFmt* pFmt = MakeSectionFmt( 0 );
417 [ # # ]: 0 : aSectData.SetLinkFileName(sFileName);
418 : 0 : aSectData.SetProtectFlag(true);
419 : :
420 [ # # ]: 0 : aEndIdx--; // in the InsertSection the end is inclusive
421 [ # # ]: 0 : while( aEndIdx.GetNode().IsStartNode() )
422 [ # # ]: 0 : aEndIdx--;
423 : :
424 : : // If any Section ends or starts in the new sectionrange,
425 : : // they must end or start before or after the range!
426 [ # # ]: 0 : SwSectionNode* pSectNd = pStartNd->FindSectionNode();
427 [ # # ][ # # ]: 0 : while( pSectNd && pSectNd->EndOfSectionIndex()
[ # # ]
428 : 0 : <= aEndIdx.GetIndex() )
429 : : {
430 : 0 : const SwNode* pSectEnd = pSectNd->EndOfSectionNode();
431 [ # # ]: 0 : if( pSectNd->GetIndex() + 1 ==
432 : 0 : pStartNd->GetIndex() )
433 : : {
434 [ # # ][ # # ]: 0 : bool bMvIdx = aEndIdx == *pSectEnd;
435 [ # # ]: 0 : DelSectionFmt( pSectNd->GetSection().GetFmt() );
436 [ # # ]: 0 : if( bMvIdx )
437 [ # # ]: 0 : aEndIdx--;
438 : : }
439 : : else
440 : : {
441 [ # # ][ # # ]: 0 : SwNodeRange aRg( *pStartNd, *pSectEnd );
[ # # ][ # # ]
[ # # ]
442 [ # # ]: 0 : SwNodeIndex aIdx( *pSectEnd, 1 );
443 [ # # ][ # # ]: 0 : GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
[ # # ][ # # ]
[ # # ]
444 : : }
445 [ # # ]: 0 : pSectNd = pStartNd->FindSectionNode();
446 : : }
447 : :
448 [ # # ]: 0 : pSectNd = aEndIdx.GetNode().FindSectionNode();
449 [ # # ][ # # ]: 0 : while( pSectNd && pSectNd->GetIndex() >
[ # # ]
450 : 0 : pStartNd->GetIndex() )
451 : : {
452 : : // #i15712# don't attempt to split sections if
453 : : // they are fully enclosed in [pSectNd,aEndIdx].
454 [ # # ]: 0 : if( aEndIdx < pSectNd->EndOfSectionIndex() )
455 : : {
456 [ # # ][ # # ]: 0 : SwNodeRange aRg( *pSectNd, 1, aEndIdx, 1 );
[ # # ]
457 [ # # ]: 0 : SwNodeIndex aIdx( *pSectNd );
458 [ # # ][ # # ]: 0 : GetNodes()._MoveNodes( aRg, GetNodes(), aIdx );
[ # # ][ # # ]
[ # # ]
459 : : }
460 : :
461 [ # # ]: 0 : pSectNd = pStartNd->FindSectionNode();
462 : : }
463 : :
464 : : // -> #i26762#
465 : : // Ensure order of start and end of section is sane.
466 [ # # ]: 0 : SwNodeIndex aStartIdx(*pStartNd);
467 : :
468 [ # # ]: 0 : if (aEndIdx >= aStartIdx)
469 : : {
470 [ # # ]: 0 : pSectNd = GetNodes().InsertTextSection(aStartIdx,
471 [ # # ]: 0 : *pFmt, aSectData, 0, &aEndIdx, false);
472 : : }
473 : : else
474 : : {
475 [ # # ]: 0 : pSectNd = GetNodes().InsertTextSection(aEndIdx,
476 [ # # ]: 0 : *pFmt, aSectData, 0, &aStartIdx, false);
477 : : }
478 : : // <- #i26762#
479 : :
480 [ # # ][ # # ]: 0 : pSectNd->GetSection().CreateLink( CREATE_CONNECT );
[ # # ][ # # ]
481 : : }
482 : 0 : break;
483 : : }
484 [ # # ][ # # ]: 0 : }
485 : : }
486 : : } while( pStartNd );
487 : :
488 [ # # ][ # # ]: 0 : if( pOutlNds != &GetNodes().GetOutLineNds() )
[ # # ]
489 [ # # ]: 0 : delete pOutlNds;
490 : :
491 [ # # ]: 0 : switch( eDocType )
492 : : {
493 : : case SPLITDOC_TO_HTML:
494 [ # # ][ # # ]: 0 : if( get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
495 : : {
496 : : // save all remaining sections
497 [ # # ]: 0 : while( !GetSections().empty() )
498 [ # # ][ # # ]: 0 : DelSectionFmt( GetSections().front() );
499 : :
500 [ # # ][ # # ]: 0 : SfxFilterContainer* pFCntnr = pDocShell->GetFactory().GetFilterContainer();
501 [ # # ]: 0 : pFilter = pFCntnr->GetFilter4EA( pFilter->GetTypeName(), SFX_FILTER_EXPORT );
502 : : }
503 : 0 : break;
504 : :
505 : : default:
506 : : // save the Globaldoc
507 [ # # ]: 0 : set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
508 [ # # ]: 0 : set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
509 : : }
510 : :
511 : : // The medium isn't locked after reopening the document.
512 [ # # ]: 0 : SfxRequest aReq( SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, GetAttrPool() );
513 [ # # ][ # # ]: 0 : aReq.AppendItem( SfxStringItem( SID_FILE_NAME, rPath ) );
[ # # ]
514 [ # # ][ # # ]: 0 : aReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
[ # # ]
515 [ # # ]: 0 : if(pFilter)
516 [ # # ][ # # ]: 0 : aReq.AppendItem( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
[ # # ]
517 [ # # ]: 0 : const SfxBoolItem *pRet = (const SfxBoolItem*)pDocShell->ExecuteSlot( aReq );
518 : :
519 [ # # ][ # # ]: 0 : return pRet && pRet->GetValue();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
520 : : }
521 : :
522 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|