merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / text / txtcache.cxx
blob79d87f681131d6febaddbc0a35caf63e6bf69f64
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: txtcache.cxx,v $
10 * $Revision: 1.9 $
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"
38 #include "txtcache.hxx"
39 #include "txtfrm.hxx"
40 #include "porlay.hxx"
42 /*************************************************************************
44 |* SwTxtLine::SwTxtLine(), ~SwTxtLine()
46 |* Ersterstellung MA 16. Mar. 94
47 |* Letzte Aenderung MA 16. Mar. 94
49 |*************************************************************************/
51 SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
52 SwCacheObj( (void*)pFrm ),
53 pLine( pNew )
57 SwTxtLine::~SwTxtLine()
59 delete pLine;
62 /*************************************************************************
64 |* SwTxtLineAccess::NewObj()
66 |* Ersterstellung MA 16. Mar. 94
67 |* Letzte Aenderung MA 16. Mar. 94
69 |*************************************************************************/
71 SwCacheObj *SwTxtLineAccess::NewObj()
73 return new SwTxtLine( (SwTxtFrm*)pOwner );
76 /*************************************************************************
78 |* SwTxtLineAccess::GetPara()
80 |* Ersterstellung MA 16. Mar. 94
81 |* Letzte Aenderung MA 16. Mar. 94
83 |*************************************************************************/
85 SwParaPortion *SwTxtLineAccess::GetPara()
87 SwTxtLine *pRet;
88 if ( pObj )
89 pRet = (SwTxtLine*)pObj;
90 else
92 pRet = (SwTxtLine*)Get();
93 ((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
95 if ( !pRet->GetPara() )
96 pRet->SetPara( new SwParaPortion );
97 return pRet->GetPara();
101 /*************************************************************************
103 |* SwTxtLineAccess::SwTxtLineAccess()
105 |* Ersterstellung MA 16. Mar. 94
106 |* Letzte Aenderung MA 16. Mar. 94
108 |*************************************************************************/
110 SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
111 SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
115 /*************************************************************************
117 |* SwTxtLineAccess::IsAvailable
119 |* Ersterstellung MA 23. Mar. 94
120 |* Letzte Aenderung MA 23. Mar. 94
122 |*************************************************************************/
124 sal_Bool SwTxtLineAccess::IsAvailable() const
126 if ( pObj )
127 return ((SwTxtLine*)pObj)->GetPara() != 0;
128 return sal_False;
131 /*************************************************************************
133 |* SwTxtFrm::HasPara()
135 |* Ersterstellung MA 16. Mar. 94
136 |* Letzte Aenderung MA 22. Aug. 94
138 |*************************************************************************/
140 sal_Bool SwTxtFrm::_HasPara() const
142 SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
143 Get( this, GetCacheIdx(), sal_False );
144 if ( pTxtLine )
146 if ( pTxtLine->GetPara() )
147 return sal_True;
149 else
150 ((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
152 return sal_False;
155 /*************************************************************************
157 |* SwTxtFrm::GetPara()
159 |* Ersterstellung MA 16. Mar. 94
160 |* Letzte Aenderung MA 22. Aug. 94
162 |*************************************************************************/
164 SwParaPortion *SwTxtFrm::GetPara()
166 if ( GetCacheIdx() != MSHRT_MAX )
167 { SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
168 Get( this, GetCacheIdx(), sal_False );
169 if ( pLine )
170 return pLine->GetPara();
171 else
172 nCacheIdx = MSHRT_MAX;
174 return 0;
178 /*************************************************************************
180 |* SwTxtFrm::ClearPara()
182 |* Ersterstellung MA 16. Mar. 94
183 |* Letzte Aenderung MA 22. Aug. 94
185 |*************************************************************************/
187 void SwTxtFrm::ClearPara()
189 ASSERT( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
190 if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
192 SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
193 Get( this, GetCacheIdx(), sal_False );
194 if ( pTxtLine )
196 delete pTxtLine->GetPara();
197 pTxtLine->SetPara( 0 );
199 else
200 nCacheIdx = MSHRT_MAX;
204 /*************************************************************************
206 |* SwTxtFrm::SetPara()
208 |* Ersterstellung MA 16. Mar. 94
209 |* Letzte Aenderung MA 22. Aug. 94
211 |*************************************************************************/
213 void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
215 if ( GetCacheIdx() != MSHRT_MAX )
217 //Nur die Information Auswechseln, das CacheObj bleibt stehen.
218 SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
219 Get( this, GetCacheIdx(), sal_False );
220 if ( pTxtLine )
222 if( bDelete )
223 delete pTxtLine->GetPara();
224 pTxtLine->SetPara( pNew );
226 else
228 ASSERT( !pNew, "+SetPara: Losing SwParaPortion" );
229 nCacheIdx = MSHRT_MAX;
232 else if ( pNew )
233 { //Einen neuen einfuegen.
234 SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
235 if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
236 nCacheIdx = pTxtLine->GetCachePos();
237 else
239 ASSERT( sal_False, "+SetPara: InsertCache failed." );