merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / docnode / ndindex.cxx
blob8e7c933b99f57695648f4534dde5dcb78369a5e6
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: ndindex.cxx,v $
10 * $Revision: 1.5 $
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"
36 #include "errhdl.hxx" // fuers ASSERT
37 #include "error.h" // fuers ASSERT
38 #include "ndindex.hxx"
40 #ifndef PRODUCT
41 int SwNodeIndex::nSerial = 0;
42 #endif
45 SwNodeRange::SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
46 : aStart( rS ), aEnd( rE )
49 SwNodeRange::SwNodeRange( const SwNodeRange &rRange )
50 : aStart( rRange.aStart ), aEnd( rRange.aEnd )
53 SwNodeRange::SwNodeRange( SwNodes& rNds, ULONG nSttIdx, ULONG nEndIdx )
54 : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx )
58 SwNodeRange::SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
59 const SwNodeIndex& rE, long nEndDiff )
60 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff )
63 SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff,
64 const SwNode& rE, long nEndDiff )
65 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff )
69 SwNodeIndex::SwNodeIndex( SwNodes& rNds, ULONG nIdx )
70 : pNd( rNds[ nIdx ] ), pNext( 0 ), pPrev( 0 )
72 rNds.RegisterIndex( *this );
74 #ifndef PRODUCT
75 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version
76 #endif
80 SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
81 : pNext( 0 ), pPrev( 0 )
83 if( nDiff )
84 pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
85 else
86 pNd = rIdx.pNd;
88 pNd->GetNodes().RegisterIndex( *this );
89 #ifndef PRODUCT
90 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version
91 #endif
95 SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
96 : pNext( 0 ), pPrev( 0 )
98 if( nDiff )
99 pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
100 else
101 pNd = (SwNode*)&rNd;
103 pNd->GetNodes().RegisterIndex( *this );
104 #ifndef PRODUCT
105 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version
106 #endif
110 void SwNodeIndex::Remove()
112 pNd->GetNodes().DeRegisterIndex( *this );
115 SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
117 if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
119 pNd->GetNodes().DeRegisterIndex( *this );
120 pNd = rIdx.pNd;
121 pNd->GetNodes().RegisterIndex( *this );
123 else
124 pNd = rIdx.pNd;
125 return *this;
128 SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
130 if( &pNd->GetNodes() != &rNd.GetNodes() )
132 pNd->GetNodes().DeRegisterIndex( *this );
133 pNd = (SwNode*)&rNd;
134 pNd->GetNodes().RegisterIndex( *this );
136 else
137 pNd = (SwNode*)&rNd;
138 return *this;
141 SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, ULONG nIdx )
143 if( &pNd->GetNodes() != &rNds )
145 pNd->GetNodes().DeRegisterIndex( *this );
146 pNd = rNds[ nIdx ];
147 pNd->GetNodes().RegisterIndex( *this );
149 else
150 pNd = rNds[ nIdx ];
151 return *this;
154 SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
156 if( &pNd->GetNodes() != &rNd.GetNodes() )
158 pNd->GetNodes().DeRegisterIndex( *this );
159 pNd = (SwNode*)&rNd;
160 pNd->GetNodes().RegisterIndex( *this );
162 else
163 pNd = (SwNode*)&rNd;
165 if( nOffset )
166 pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
168 return *this;