xref: /aoo42x/main/sw/source/core/text/txtcache.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 
33 #include "errhdl.hxx"
34 
35 #include "txtcache.hxx"
36 #include "txtfrm.hxx"
37 #include "porlay.hxx"
38 
39 /*************************************************************************
40 |*
41 |*	SwTxtLine::SwTxtLine(), ~SwTxtLine()
42 |*
43 |*	Ersterstellung		MA 16. Mar. 94
44 |*	Letzte Aenderung	MA 16. Mar. 94
45 |*
46 |*************************************************************************/
47 
48 SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
49 	SwCacheObj( (void*)pFrm ),
50 	pLine( pNew )
51 {
52 }
53 
54 SwTxtLine::~SwTxtLine()
55 {
56 	delete pLine;
57 }
58 
59 /*************************************************************************
60 |*
61 |*	SwTxtLineAccess::NewObj()
62 |*
63 |*	Ersterstellung		MA 16. Mar. 94
64 |*	Letzte Aenderung	MA 16. Mar. 94
65 |*
66 |*************************************************************************/
67 
68 SwCacheObj *SwTxtLineAccess::NewObj()
69 {
70 	return new SwTxtLine( (SwTxtFrm*)pOwner );
71 }
72 
73 /*************************************************************************
74 |*
75 |*	SwTxtLineAccess::GetPara()
76 |*
77 |*	Ersterstellung		MA 16. Mar. 94
78 |*	Letzte Aenderung	MA 16. Mar. 94
79 |*
80 |*************************************************************************/
81 
82 SwParaPortion *SwTxtLineAccess::GetPara()
83 {
84 	SwTxtLine *pRet;
85 	if ( pObj )
86 		pRet = (SwTxtLine*)pObj;
87 	else
88 	{
89 		pRet = (SwTxtLine*)Get();
90 		((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
91 	}
92 	if ( !pRet->GetPara() )
93 		pRet->SetPara( new SwParaPortion );
94 	return pRet->GetPara();
95 }
96 
97 
98 /*************************************************************************
99 |*
100 |*	SwTxtLineAccess::SwTxtLineAccess()
101 |*
102 |*	Ersterstellung		MA 16. Mar. 94
103 |*	Letzte Aenderung	MA 16. Mar. 94
104 |*
105 |*************************************************************************/
106 
107 SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
108     SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
109 {
110 }
111 
112 /*************************************************************************
113 |*
114 |*	SwTxtLineAccess::IsAvailable
115 |*
116 |*	Ersterstellung		MA 23. Mar. 94
117 |*	Letzte Aenderung	MA 23. Mar. 94
118 |*
119 |*************************************************************************/
120 
121 sal_Bool SwTxtLineAccess::IsAvailable() const
122 {
123 	if ( pObj )
124 		return ((SwTxtLine*)pObj)->GetPara() != 0;
125 	return sal_False;
126 }
127 
128 /*************************************************************************
129 |*
130 |*	SwTxtFrm::HasPara()
131 |*
132 |*	Ersterstellung		MA 16. Mar. 94
133 |*	Letzte Aenderung	MA 22. Aug. 94
134 |*
135 |*************************************************************************/
136 
137 sal_Bool SwTxtFrm::_HasPara() const
138 {
139 	SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
140 											Get( this, GetCacheIdx(), sal_False );
141 	if ( pTxtLine )
142 	{
143 		if ( pTxtLine->GetPara() )
144 			return sal_True;
145 	}
146 	else
147 		((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
148 
149 	return sal_False;
150 }
151 
152 /*************************************************************************
153 |*
154 |*	SwTxtFrm::GetPara()
155 |*
156 |*	Ersterstellung		MA 16. Mar. 94
157 |*	Letzte Aenderung	MA 22. Aug. 94
158 |*
159 |*************************************************************************/
160 
161 SwParaPortion *SwTxtFrm::GetPara()
162 {
163 	if ( GetCacheIdx() != MSHRT_MAX )
164 	{	SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
165 										Get( this, GetCacheIdx(), sal_False );
166 		if ( pLine )
167 			return pLine->GetPara();
168 		else
169 			nCacheIdx = MSHRT_MAX;
170 	}
171 	return 0;
172 }
173 
174 
175 /*************************************************************************
176 |*
177 |*	SwTxtFrm::ClearPara()
178 |*
179 |*	Ersterstellung		MA 16. Mar. 94
180 |*	Letzte Aenderung	MA 22. Aug. 94
181 |*
182 |*************************************************************************/
183 
184 void SwTxtFrm::ClearPara()
185 {
186 	ASSERT( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
187 	if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
188 	{
189 		SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
190 										Get( this, GetCacheIdx(), sal_False );
191 		if ( pTxtLine )
192 		{
193 			delete pTxtLine->GetPara();
194 			pTxtLine->SetPara( 0 );
195 		}
196 		else
197 			nCacheIdx = MSHRT_MAX;
198 	}
199 }
200 
201 /*************************************************************************
202 |*
203 |*	SwTxtFrm::SetPara()
204 |*
205 |*	Ersterstellung		MA 16. Mar. 94
206 |*	Letzte Aenderung	MA 22. Aug. 94
207 |*
208 |*************************************************************************/
209 
210 void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
211 {
212 	if ( GetCacheIdx() != MSHRT_MAX )
213 	{
214 		//Nur die Information Auswechseln, das CacheObj bleibt stehen.
215 		SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
216 										Get( this, GetCacheIdx(), sal_False );
217 		if ( pTxtLine )
218 		{
219 			if( bDelete )
220 				delete pTxtLine->GetPara();
221 			pTxtLine->SetPara( pNew );
222 		}
223 		else
224 		{
225 			ASSERT( !pNew, "+SetPara: Losing SwParaPortion" );
226 			nCacheIdx = MSHRT_MAX;
227 		}
228 	}
229 	else if ( pNew )
230 	{	//Einen neuen einfuegen.
231 		SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
232 		if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
233 			nCacheIdx = pTxtLine->GetCachePos();
234 		else
235 		{
236 			ASSERT( sal_False, "+SetPara: InsertCache failed." );
237 		}
238 	}
239 }
240 
241 
242