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 : :
30 : : #include <doc.hxx>
31 : : #include <IDocumentUndoRedo.hxx>
32 : : #include <editsh.hxx>
33 : : #include <pam.hxx>
34 : : #include <ndtxt.hxx>
35 : : #include <docary.hxx>
36 : : #include <swwait.hxx>
37 : : #include <swundo.hxx> // fuer die UndoIds
38 : : #include <section.hxx>
39 : : #include <doctxm.hxx>
40 : : #include <edglbldc.hxx>
41 : :
42 : :
43 : 0 : sal_Bool SwEditShell::IsGlobalDoc() const
44 : : {
45 : 0 : return getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT);
46 : : }
47 : :
48 : 0 : void SwEditShell::SetGlblDocSaveLinks( sal_Bool bFlag )
49 : : {
50 : 0 : getIDocumentSettingAccess()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bFlag);
51 [ # # ]: 0 : if( !GetDoc()->IsModified() ) // Bug 57028
52 : : {
53 : 0 : GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
54 : : }
55 : 0 : GetDoc()->SetModified();
56 : 0 : }
57 : :
58 : 0 : sal_Bool SwEditShell::IsGlblDocSaveLinks() const
59 : : {
60 : 0 : return getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
61 : : }
62 : :
63 : 0 : sal_uInt16 SwEditShell::GetGlobalDocContent( SwGlblDocContents& rArr ) const
64 : : {
65 : 0 : rArr.DeleteAndDestroyAll();
66 : :
67 [ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
68 : 0 : return 0;
69 : :
70 : : // dann alle gelinkten Bereiche auf der obersten Ebene
71 : 0 : SwDoc* pMyDoc = GetDoc();
72 : 0 : const SwSectionFmts& rSectFmts = pMyDoc->GetSections();
73 : : sal_uInt16 n;
74 : :
75 [ # # ]: 0 : for( n = rSectFmts.size(); n; )
76 : : {
77 : 0 : const SwSection* pSect = rSectFmts[ --n ]->GetGlobalDocSection();
78 [ # # ]: 0 : if( pSect )
79 : : {
80 : : SwGlblDocContent* pNew;
81 [ # # # ]: 0 : switch( pSect->GetType() )
82 : : {
83 : 0 : case TOX_HEADER_SECTION: break; // ignore
84 : : case TOX_CONTENT_SECTION:
85 : : OSL_ENSURE( pSect->ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
86 [ # # ][ # # ]: 0 : pNew = new SwGlblDocContent( (SwTOXBaseSection*)pSect );
[ # # ]
87 : 0 : break;
88 : :
89 : : default:
90 [ # # ][ # # ]: 0 : pNew = new SwGlblDocContent( pSect );
91 : 0 : break;
92 : : }
93 [ # # ][ # # ]: 0 : if( !rArr.insert( pNew ).second )
94 : 0 : delete pNew;
95 : : }
96 : : }
97 : :
98 : : // und als letztes die Dummies (sonstiger Text) einfuegen
99 : : SwNode* pNd;
100 : 0 : sal_uLong nSttIdx = pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2;
101 [ # # ]: 0 : for( n = 0; n < rArr.size(); ++n )
102 : : {
103 : 0 : const SwGlblDocContent& rNew = *rArr[ n ];
104 : : // suche von StartPos bis rNew.DocPos nach einem Content Node.
105 : : // Existiert dieser, so muss ein DummyEintrag eingefuegt werden.
106 [ # # ]: 0 : for( ; nSttIdx < rNew.GetDocPos(); ++nSttIdx )
107 [ # # # # : 0 : if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsCntntNode()
# # ][ # # ]
108 : 0 : || pNd->IsSectionNode() || pNd->IsTableNode() )
109 : : {
110 [ # # ]: 0 : SwGlblDocContent* pNew = new SwGlblDocContent( nSttIdx );
111 [ # # ][ # # ]: 0 : if( !rArr.insert( pNew ).second )
112 : 0 : delete pNew;
113 : : else
114 : 0 : ++n; // auf die naechste Position
115 : : break;
116 : : }
117 : :
118 : : // StartPosition aufs Ende setzen
119 : 0 : nSttIdx = pMyDoc->GetNodes()[ rNew.GetDocPos() ]->EndOfSectionIndex();
120 : 0 : ++nSttIdx;
121 : : }
122 : :
123 : : // sollte man das Ende auch noch setzen??
124 [ # # ]: 0 : if( !rArr.empty() )
125 : : {
126 : 0 : sal_uLong nNdEnd = pMyDoc->GetNodes().GetEndOfContent().GetIndex();
127 [ # # ]: 0 : for( ; nSttIdx < nNdEnd; ++nSttIdx )
128 [ # # # # : 0 : if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsCntntNode()
# # ][ # # ]
129 : 0 : || pNd->IsSectionNode() || pNd->IsTableNode() )
130 : : {
131 [ # # ]: 0 : SwGlblDocContent* pNew = new SwGlblDocContent( nSttIdx );
132 [ # # ][ # # ]: 0 : if( !rArr.insert( pNew ).second )
133 : 0 : delete pNew;
134 : : break;
135 : : }
136 : : }
137 : : else
138 : : {
139 : : SwGlblDocContent* pNew = new SwGlblDocContent(
140 [ # # ][ # # ]: 0 : pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2 );
141 [ # # ]: 0 : rArr.insert( pNew );
142 : : }
143 : 0 : return rArr.size();
144 : : }
145 : :
146 : 0 : sal_Bool SwEditShell::InsertGlobalDocContent( const SwGlblDocContent& rInsPos,
147 : : SwSectionData & rNew)
148 : : {
149 [ # # ][ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
[ # # ]
150 : 0 : return sal_False;
151 : :
152 [ # # ]: 0 : SET_CURR_SHELL( this );
153 [ # # ]: 0 : StartAllAction();
154 : :
155 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
156 [ # # ][ # # ]: 0 : if( pCrsr->GetNext() != pCrsr || IsTableMode() )
[ # # ]
157 [ # # ]: 0 : ClearMark();
158 : :
159 : 0 : SwPosition& rPos = *pCrsr->GetPoint();
160 [ # # ]: 0 : rPos.nNode = rInsPos.GetDocPos();
161 : :
162 : 0 : sal_Bool bEndUndo = sal_False;
163 : 0 : SwDoc* pMyDoc = GetDoc();
164 : 0 : SwTxtNode *const pTxtNd = rPos.nNode.GetNode().GetTxtNode();
165 [ # # ]: 0 : if( pTxtNd )
166 [ # # ][ # # ]: 0 : rPos.nContent.Assign( pTxtNd, 0 );
167 : : else
168 : : {
169 : 0 : bEndUndo = sal_True;
170 [ # # ][ # # ]: 0 : pMyDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
171 [ # # ]: 0 : rPos.nNode--;
172 [ # # ]: 0 : pMyDoc->AppendTxtNode( rPos );
173 [ # # ]: 0 : pCrsr->SetMark();
174 : : }
175 : :
176 [ # # ]: 0 : InsertSection( rNew );
177 : :
178 [ # # ]: 0 : if( bEndUndo )
179 : : {
180 [ # # ][ # # ]: 0 : pMyDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
181 : : }
182 [ # # ]: 0 : EndAllAction();
183 : :
184 [ # # ]: 0 : return sal_True;
185 : : }
186 : :
187 : 0 : sal_Bool SwEditShell::InsertGlobalDocContent( const SwGlblDocContent& rInsPos,
188 : : const SwTOXBase& rTOX )
189 : : {
190 [ # # ][ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
[ # # ]
191 : 0 : return sal_False;
192 : :
193 [ # # ]: 0 : SET_CURR_SHELL( this );
194 [ # # ]: 0 : StartAllAction();
195 : :
196 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
197 [ # # ][ # # ]: 0 : if( pCrsr->GetNext() != pCrsr || IsTableMode() )
[ # # ]
198 [ # # ]: 0 : ClearMark();
199 : :
200 : 0 : SwPosition& rPos = *pCrsr->GetPoint();
201 [ # # ]: 0 : rPos.nNode = rInsPos.GetDocPos();
202 : :
203 : 0 : sal_Bool bEndUndo = sal_False;
204 : 0 : SwDoc* pMyDoc = GetDoc();
205 : 0 : SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
206 [ # # ][ # # ]: 0 : if( pTxtNd && pTxtNd->GetTxt().Len() && rPos.nNode.GetIndex() + 1 !=
[ # # ][ # # ]
207 [ # # ]: 0 : pMyDoc->GetNodes().GetEndOfContent().GetIndex() )
208 [ # # ][ # # ]: 0 : rPos.nContent.Assign( pTxtNd, 0 );
209 : : else
210 : : {
211 : 0 : bEndUndo = sal_True;
212 [ # # ][ # # ]: 0 : pMyDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
213 [ # # ]: 0 : rPos.nNode--;
214 [ # # ]: 0 : pMyDoc->AppendTxtNode( rPos );
215 : : }
216 : :
217 [ # # ]: 0 : InsertTableOf( rTOX );
218 : :
219 [ # # ]: 0 : if( bEndUndo )
220 : : {
221 [ # # ][ # # ]: 0 : pMyDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
222 : : }
223 [ # # ]: 0 : EndAllAction();
224 : :
225 [ # # ]: 0 : return sal_True;
226 : : }
227 : :
228 : 0 : sal_Bool SwEditShell::InsertGlobalDocContent( const SwGlblDocContent& rInsPos )
229 : : {
230 [ # # ][ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
[ # # ]
231 : 0 : return sal_False;
232 : :
233 [ # # ]: 0 : SET_CURR_SHELL( this );
234 [ # # ]: 0 : StartAllAction();
235 : :
236 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
237 [ # # ][ # # ]: 0 : if( pCrsr->GetNext() != pCrsr || IsTableMode() )
[ # # ]
238 [ # # ]: 0 : ClearMark();
239 : :
240 : 0 : SwPosition& rPos = *pCrsr->GetPoint();
241 [ # # ]: 0 : rPos.nNode = rInsPos.GetDocPos() - 1;
242 [ # # ]: 0 : rPos.nContent.Assign( 0, 0 );
243 : :
244 : 0 : SwDoc* pMyDoc = GetDoc();
245 [ # # ]: 0 : pMyDoc->AppendTxtNode( rPos );
246 [ # # ]: 0 : EndAllAction();
247 [ # # ]: 0 : return sal_True;
248 : : }
249 : :
250 : 0 : sal_Bool SwEditShell::DeleteGlobalDocContent( const SwGlblDocContents& rArr ,
251 : : sal_uInt16 nDelPos )
252 : : {
253 [ # # ][ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
[ # # ]
254 : 0 : return sal_False;
255 : :
256 [ # # ]: 0 : SET_CURR_SHELL( this );
257 [ # # ]: 0 : StartAllAction();
258 [ # # ]: 0 : StartUndo( UNDO_START );
259 : :
260 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
261 [ # # ][ # # ]: 0 : if( pCrsr->GetNext() != pCrsr || IsTableMode() )
[ # # ]
262 [ # # ]: 0 : ClearMark();
263 : :
264 : 0 : SwPosition& rPos = *pCrsr->GetPoint();
265 : :
266 : 0 : SwDoc* pMyDoc = GetDoc();
267 [ # # ]: 0 : const SwGlblDocContent& rDelPos = *rArr[ nDelPos ];
268 : 0 : sal_uLong nDelIdx = rDelPos.GetDocPos();
269 [ # # ]: 0 : if( 1 == rArr.size() )
270 : : {
271 : : // ein Node muss aber da bleiben!
272 [ # # ]: 0 : rPos.nNode = nDelIdx - 1;
273 [ # # ]: 0 : rPos.nContent.Assign( 0, 0 );
274 : :
275 [ # # ]: 0 : pMyDoc->AppendTxtNode( rPos );
276 : 0 : ++nDelIdx;
277 : : }
278 : :
279 [ # # # # ]: 0 : switch( rDelPos.GetType() )
280 : : {
281 : : case GLBLDOC_UNKNOWN:
282 : : {
283 [ # # ]: 0 : rPos.nNode = nDelIdx;
284 [ # # ]: 0 : pCrsr->SetMark();
285 [ # # ]: 0 : if( ++nDelPos < rArr.size() )
286 [ # # ][ # # ]: 0 : rPos.nNode = rArr[ nDelPos ]->GetDocPos();
287 : : else
288 [ # # ][ # # ]: 0 : rPos.nNode = pMyDoc->GetNodes().GetEndOfContent();
289 [ # # ]: 0 : rPos.nNode--;
290 [ # # ][ # # ]: 0 : if( !pMyDoc->DelFullPara( *pCrsr ) )
291 [ # # ]: 0 : Delete();
292 : : }
293 : 0 : break;
294 : :
295 : : case GLBLDOC_TOXBASE:
296 : : {
297 : 0 : SwTOXBaseSection* pTOX = (SwTOXBaseSection*)rDelPos.GetTOX();
298 [ # # ]: 0 : pMyDoc->DeleteTOX( *pTOX, sal_True );
299 : : }
300 : 0 : break;
301 : :
302 : : case GLBLDOC_SECTION:
303 : : {
304 : 0 : SwSectionFmt* pSectFmt = (SwSectionFmt*)rDelPos.GetSection()->GetFmt();
305 [ # # ]: 0 : pMyDoc->DelSectionFmt( pSectFmt, sal_True );
306 : : }
307 : 0 : break;
308 : : }
309 : :
310 [ # # ]: 0 : EndUndo( UNDO_END );
311 [ # # ]: 0 : EndAllAction();
312 [ # # ]: 0 : return sal_True;
313 : : }
314 : :
315 : 0 : sal_Bool SwEditShell::MoveGlobalDocContent( const SwGlblDocContents& rArr ,
316 : : sal_uInt16 nFromPos, sal_uInt16 nToPos,
317 : : sal_uInt16 nInsPos )
318 : : {
319 [ # # ][ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ||
[ # # # #
# # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
320 : 0 : nFromPos >= rArr.size() || nToPos > rArr.size() ||
321 : 0 : nInsPos > rArr.size() || nFromPos >= nToPos ||
322 : : ( nFromPos <= nInsPos && nInsPos <= nToPos ) )
323 : 0 : return sal_False;
324 : :
325 [ # # ]: 0 : SET_CURR_SHELL( this );
326 [ # # ]: 0 : StartAllAction();
327 : :
328 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
329 [ # # ][ # # ]: 0 : if( pCrsr->GetNext() != pCrsr || IsTableMode() )
[ # # ]
330 [ # # ]: 0 : ClearMark();
331 : :
332 : 0 : SwDoc* pMyDoc = GetDoc();
333 [ # # ][ # # ]: 0 : SwNodeRange aRg( pMyDoc->GetNodes(), rArr[ nFromPos ]->GetDocPos() );
[ # # ]
334 [ # # ]: 0 : if( nToPos < rArr.size() )
335 [ # # ][ # # ]: 0 : aRg.aEnd = rArr[ nToPos ]->GetDocPos();
336 : : else
337 [ # # ][ # # ]: 0 : aRg.aEnd = pMyDoc->GetNodes().GetEndOfContent();
338 : :
339 [ # # ][ # # ]: 0 : SwNodeIndex aInsPos( pMyDoc->GetNodes() );
340 [ # # ]: 0 : if( nInsPos < rArr.size() )
341 [ # # ][ # # ]: 0 : aInsPos = rArr[ nInsPos ]->GetDocPos();
342 : : else
343 [ # # ][ # # ]: 0 : aInsPos = pMyDoc->GetNodes().GetEndOfContent();
344 : :
345 : : bool bRet = pMyDoc->MoveNodeRange( aRg, aInsPos,
346 : : static_cast<IDocumentContentOperations::SwMoveFlags>(
347 : : IDocumentContentOperations::DOC_MOVEALLFLYS
348 [ # # ]: 0 : | IDocumentContentOperations::DOC_CREATEUNDOOBJ ));
349 : :
350 [ # # ]: 0 : EndAllAction();
351 [ # # ][ # # ]: 0 : return bRet;
[ # # ]
352 : : }
353 : :
354 : 0 : sal_Bool SwEditShell::GotoGlobalDocContent( const SwGlblDocContent& rPos )
355 : : {
356 [ # # ][ # # ]: 0 : if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
[ # # ]
357 : 0 : return sal_False;
358 : :
359 [ # # ]: 0 : SET_CURR_SHELL( this );
360 [ # # ]: 0 : SttCrsrMove();
361 : :
362 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
363 [ # # ][ # # ]: 0 : if( pCrsr->GetNext() != pCrsr || IsTableMode() )
[ # # ]
364 [ # # ]: 0 : ClearMark();
365 : :
366 : 0 : SwPosition& rCrsrPos = *pCrsr->GetPoint();
367 [ # # ]: 0 : rCrsrPos.nNode = rPos.GetDocPos();
368 : :
369 : 0 : SwDoc* pMyDoc = GetDoc();
370 : 0 : SwCntntNode * pCNd = rCrsrPos.nNode.GetNode().GetCntntNode();
371 [ # # ]: 0 : if( !pCNd )
372 [ # # ][ # # ]: 0 : pCNd = pMyDoc->GetNodes().GoNext( &rCrsrPos.nNode );
373 : :
374 [ # # ][ # # ]: 0 : rCrsrPos.nContent.Assign( pCNd, 0 );
375 : :
376 [ # # ]: 0 : EndCrsrMove();
377 [ # # ]: 0 : return sal_True;
378 : : }
379 : :
380 : 0 : SwGlblDocContent::SwGlblDocContent( sal_uLong nPos )
381 : : {
382 : 0 : eType = GLBLDOC_UNKNOWN;
383 : 0 : PTR.pTOX = 0;
384 : 0 : nDocPos = nPos;
385 : 0 : }
386 : :
387 : 0 : SwGlblDocContent::SwGlblDocContent( const SwTOXBaseSection* pTOX )
388 : : {
389 : 0 : eType = GLBLDOC_TOXBASE;
390 : 0 : PTR.pTOX = pTOX;
391 : :
392 : 0 : const SwSectionNode* pSectNd = pTOX->GetFmt()->GetSectionNode();
393 [ # # ]: 0 : nDocPos = pSectNd ? pSectNd->GetIndex() : 0;
394 : 0 : }
395 : :
396 : 0 : SwGlblDocContent::SwGlblDocContent( const SwSection* pSect )
397 : : {
398 : 0 : eType = GLBLDOC_SECTION;
399 : 0 : PTR.pSect = pSect;
400 : :
401 : 0 : const SwSectionNode* pSectNd = pSect->GetFmt()->GetSectionNode();
402 [ # # ]: 0 : nDocPos = pSectNd ? pSectNd->GetIndex() : 0;
403 : 0 : }
404 : :
405 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|