1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: edglbldc.cxx,v $
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"
41 #include <swundo.hxx> // fuer die UndoIds
42 #include <section.hxx>
44 #include <edglbldc.hxx>
47 SV_IMPL_OP_PTRARR_SORT( SwGlblDocContents
, SwGlblDocContentPtr
)
49 BOOL
SwEditShell::IsGlobalDoc() const
51 return getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
);
54 void SwEditShell::SetGlblDocSaveLinks( BOOL bFlag
)
56 getIDocumentSettingAccess()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS
, bFlag
);
57 if( !GetDoc()->IsModified() ) // Bug 57028
58 GetDoc()->SetUndoNoResetModified();
59 GetDoc()->SetModified();
62 BOOL
SwEditShell::IsGlblDocSaveLinks() const
64 return getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS
);
67 USHORT
SwEditShell::GetGlobalDocContent( SwGlblDocContents
& rArr
) const
70 rArr
.DeleteAndDestroy( 0, rArr
.Count() );
72 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) )
75 // dann alle gelinkten Bereiche auf der obersten Ebene
76 SwDoc
* pMyDoc
= GetDoc();
77 const SwSectionFmts
& rSectFmts
= pMyDoc
->GetSections();
80 for( n
= rSectFmts
.Count(); n
; )
82 const SwSection
* pSect
= rSectFmts
[ --n
]->GetGlobalDocSection();
85 SwGlblDocContentPtr pNew
;
86 switch( pSect
->GetType() )
88 case TOX_HEADER_SECTION
: break; // ignore
89 case TOX_CONTENT_SECTION
:
90 ASSERT( pSect
->ISA( SwTOXBaseSection
), "keine TOXBaseSection!" );
91 pNew
= new SwGlblDocContent( (SwTOXBaseSection
*)pSect
);
95 pNew
= new SwGlblDocContent( pSect
);
98 if( !rArr
.Insert( pNew
) )
103 // und als letztes die Dummies (sonstiger Text) einfuegen
105 ULONG nSttIdx
= pMyDoc
->GetNodes().GetEndOfExtras().GetIndex() + 2;
106 for( n
= 0; n
< rArr
.Count(); ++n
)
108 const SwGlblDocContent
& rNew
= *rArr
[ n
];
109 // suche von StartPos bis rNew.DocPos nach einem Content Node.
110 // Existiert dieser, so muss ein DummyEintrag eingefuegt werden.
111 for( ; nSttIdx
< rNew
.GetDocPos(); ++nSttIdx
)
112 if( ( pNd
= pMyDoc
->GetNodes()[ nSttIdx
])->IsCntntNode()
113 || pNd
->IsSectionNode() || pNd
->IsTableNode() )
115 SwGlblDocContentPtr pNew
= new SwGlblDocContent( nSttIdx
);
116 if( !rArr
.Insert( pNew
) )
119 ++n
; // auf die naechste Position
123 // StartPosition aufs Ende setzen
124 nSttIdx
= pMyDoc
->GetNodes()[ rNew
.GetDocPos() ]->EndOfSectionIndex();
128 // sollte man das Ende auch noch setzen??
131 ULONG nNdEnd
= pMyDoc
->GetNodes().GetEndOfContent().GetIndex();
132 for( ; nSttIdx
< nNdEnd
; ++nSttIdx
)
133 if( ( pNd
= pMyDoc
->GetNodes()[ nSttIdx
])->IsCntntNode()
134 || pNd
->IsSectionNode() || pNd
->IsTableNode() )
136 SwGlblDocContentPtr pNew
= new SwGlblDocContent( nSttIdx
);
137 if( !rArr
.Insert( pNew
) )
144 SwGlblDocContentPtr pNew
= new SwGlblDocContent(
145 pMyDoc
->GetNodes().GetEndOfExtras().GetIndex() + 2 );
151 BOOL
SwEditShell::InsertGlobalDocContent( const SwGlblDocContent
& rInsPos
,
152 const SwSection
& rNew
)
154 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) )
157 SET_CURR_SHELL( this );
160 SwPaM
* pCrsr
= GetCrsr();
161 if( pCrsr
->GetNext() != pCrsr
|| IsTableMode() )
164 SwPosition
& rPos
= *pCrsr
->GetPoint();
165 rPos
.nNode
= rInsPos
.GetDocPos();
167 BOOL bEndUndo
= FALSE
;
168 SwDoc
* pMyDoc
= GetDoc();
169 SwTxtNode
* pTxtNd
= pMyDoc
->GetNodes()[ rPos
.nNode
]->GetTxtNode();
171 rPos
.nContent
.Assign( pTxtNd
, 0 );
175 pMyDoc
->StartUndo( UNDO_START
, NULL
);
177 pMyDoc
->AppendTxtNode( rPos
);
181 InsertSection( rNew
);
184 pMyDoc
->EndUndo( UNDO_END
, NULL
);
190 BOOL
SwEditShell::InsertGlobalDocContent( const SwGlblDocContent
& rInsPos
,
191 const SwTOXBase
& rTOX
)
193 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) )
196 SET_CURR_SHELL( this );
199 SwPaM
* pCrsr
= GetCrsr();
200 if( pCrsr
->GetNext() != pCrsr
|| IsTableMode() )
203 SwPosition
& rPos
= *pCrsr
->GetPoint();
204 rPos
.nNode
= rInsPos
.GetDocPos();
206 BOOL bEndUndo
= FALSE
;
207 SwDoc
* pMyDoc
= GetDoc();
208 SwTxtNode
* pTxtNd
= rPos
.nNode
.GetNode().GetTxtNode();
209 if( pTxtNd
&& pTxtNd
->GetTxt().Len() && rPos
.nNode
.GetIndex() + 1 !=
210 pMyDoc
->GetNodes().GetEndOfContent().GetIndex() )
211 rPos
.nContent
.Assign( pTxtNd
, 0 );
215 pMyDoc
->StartUndo( UNDO_START
, NULL
);
217 pMyDoc
->AppendTxtNode( rPos
);
220 InsertTableOf( rTOX
);
223 pMyDoc
->EndUndo( UNDO_END
, NULL
);
229 BOOL
SwEditShell::InsertGlobalDocContent( const SwGlblDocContent
& rInsPos
)
231 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) )
234 SET_CURR_SHELL( this );
237 SwPaM
* pCrsr
= GetCrsr();
238 if( pCrsr
->GetNext() != pCrsr
|| IsTableMode() )
241 SwPosition
& rPos
= *pCrsr
->GetPoint();
242 rPos
.nNode
= rInsPos
.GetDocPos() - 1;
243 rPos
.nContent
.Assign( 0, 0 );
245 SwDoc
* pMyDoc
= GetDoc();
246 pMyDoc
->AppendTxtNode( rPos
);
251 BOOL
SwEditShell::DeleteGlobalDocContent( const SwGlblDocContents
& rArr
,
254 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) )
257 SET_CURR_SHELL( this );
259 StartUndo( UNDO_START
);
261 SwPaM
* pCrsr
= GetCrsr();
262 if( pCrsr
->GetNext() != pCrsr
|| IsTableMode() )
265 SwPosition
& rPos
= *pCrsr
->GetPoint();
267 SwDoc
* pMyDoc
= GetDoc();
268 const SwGlblDocContent
& rDelPos
= *rArr
[ nDelPos
];
269 ULONG nDelIdx
= rDelPos
.GetDocPos();
270 if( 1 == rArr
.Count() )
272 // ein Node muss aber da bleiben!
273 rPos
.nNode
= nDelIdx
- 1;
274 rPos
.nContent
.Assign( 0, 0 );
276 pMyDoc
->AppendTxtNode( rPos
);
280 switch( rDelPos
.GetType() )
282 case GLBLDOC_UNKNOWN
:
284 rPos
.nNode
= nDelIdx
;
286 if( ++nDelPos
< rArr
.Count() )
287 rPos
.nNode
= rArr
[ nDelPos
]->GetDocPos();
289 rPos
.nNode
= pMyDoc
->GetNodes().GetEndOfContent();
291 if( !pMyDoc
->DelFullPara( *pCrsr
) )
296 case GLBLDOC_TOXBASE
:
298 SwTOXBaseSection
* pTOX
= (SwTOXBaseSection
*)rDelPos
.GetTOX();
299 pMyDoc
->DeleteTOX( *pTOX
, TRUE
);
303 case GLBLDOC_SECTION
:
305 SwSectionFmt
* pSectFmt
= (SwSectionFmt
*)rDelPos
.GetSection()->GetFmt();
306 pMyDoc
->DelSectionFmt( pSectFmt
, TRUE
);
316 BOOL
SwEditShell::MoveGlobalDocContent( const SwGlblDocContents
& rArr
,
317 USHORT nFromPos
, USHORT nToPos
,
320 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) ||
321 nFromPos
>= rArr
.Count() || nToPos
> rArr
.Count() ||
322 nInsPos
> rArr
.Count() || nFromPos
>= nToPos
||
323 ( nFromPos
<= nInsPos
&& nInsPos
<= nToPos
) )
326 SET_CURR_SHELL( this );
329 SwPaM
* pCrsr
= GetCrsr();
330 if( pCrsr
->GetNext() != pCrsr
|| IsTableMode() )
333 SwDoc
* pMyDoc
= GetDoc();
334 SwNodeRange
aRg( pMyDoc
->GetNodes(), rArr
[ nFromPos
]->GetDocPos() );
335 if( nToPos
< rArr
.Count() )
336 aRg
.aEnd
= rArr
[ nToPos
]->GetDocPos();
338 aRg
.aEnd
= pMyDoc
->GetNodes().GetEndOfContent();
340 SwNodeIndex
aInsPos( pMyDoc
->GetNodes() );
341 if( nInsPos
< rArr
.Count() )
342 aInsPos
= rArr
[ nInsPos
]->GetDocPos();
344 aInsPos
= pMyDoc
->GetNodes().GetEndOfContent();
346 BOOL bRet
= pMyDoc
->Move( aRg
, aInsPos
,
347 IDocumentContentOperations::SwMoveFlags(IDocumentContentOperations::DOC_MOVEALLFLYS
|IDocumentContentOperations::DOC_CREATEUNDOOBJ
));
353 BOOL
SwEditShell::GotoGlobalDocContent( const SwGlblDocContent
& rPos
)
355 if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT
) )
358 SET_CURR_SHELL( this );
361 SwPaM
* pCrsr
= GetCrsr();
362 if( pCrsr
->GetNext() != pCrsr
|| IsTableMode() )
365 SwPosition
& rCrsrPos
= *pCrsr
->GetPoint();
366 rCrsrPos
.nNode
= rPos
.GetDocPos();
368 SwDoc
* pMyDoc
= GetDoc();
369 SwCntntNode
* pCNd
= pMyDoc
->GetNodes()[ rCrsrPos
.nNode
]->GetCntntNode();
371 pCNd
= pMyDoc
->GetNodes().GoNext( &rCrsrPos
.nNode
);
373 rCrsrPos
.nContent
.Assign( pCNd
, 0 );
379 SwGlblDocContent::SwGlblDocContent( ULONG nPos
)
381 eType
= GLBLDOC_UNKNOWN
;
386 SwGlblDocContent::SwGlblDocContent( const SwTOXBaseSection
* pTOX
)
388 eType
= GLBLDOC_TOXBASE
;
391 const SwSectionNode
* pSectNd
= pTOX
->GetFmt()->GetSectionNode();
392 nDocPos
= pSectNd
? pSectNd
->GetIndex() : 0;
395 SwGlblDocContent::SwGlblDocContent( const SwSection
* pSect
)
397 eType
= GLBLDOC_SECTION
;
400 const SwSectionNode
* pSectNd
= pSect
->GetFmt()->GetSectionNode();
401 nDocPos
= pSectNd
? pSectNd
->GetIndex() : 0;