xref: /trunk/main/sw/source/core/text/txtcache.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 
29 #include "errhdl.hxx"
30 
31 #include "txtcache.hxx"
32 #include "txtfrm.hxx"
33 #include "porlay.hxx"
34 
35 /*************************************************************************
36 |*
37 |*	SwTxtLine::SwTxtLine(), ~SwTxtLine()
38 |*
39 |*	Ersterstellung		MA 16. Mar. 94
40 |*	Letzte Aenderung	MA 16. Mar. 94
41 |*
42 |*************************************************************************/
43 
SwTxtLine(SwTxtFrm * pFrm,SwParaPortion * pNew)44 SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
45 	SwCacheObj( (void*)pFrm ),
46 	pLine( pNew )
47 {
48 }
49 
~SwTxtLine()50 SwTxtLine::~SwTxtLine()
51 {
52 	delete pLine;
53 }
54 
55 /*************************************************************************
56 |*
57 |*	SwTxtLineAccess::NewObj()
58 |*
59 |*	Ersterstellung		MA 16. Mar. 94
60 |*	Letzte Aenderung	MA 16. Mar. 94
61 |*
62 |*************************************************************************/
63 
NewObj()64 SwCacheObj *SwTxtLineAccess::NewObj()
65 {
66 	return new SwTxtLine( (SwTxtFrm*)pOwner );
67 }
68 
69 /*************************************************************************
70 |*
71 |*	SwTxtLineAccess::GetPara()
72 |*
73 |*	Ersterstellung		MA 16. Mar. 94
74 |*	Letzte Aenderung	MA 16. Mar. 94
75 |*
76 |*************************************************************************/
77 
GetPara()78 SwParaPortion *SwTxtLineAccess::GetPara()
79 {
80 	SwTxtLine *pRet;
81 	if ( pObj )
82 		pRet = (SwTxtLine*)pObj;
83 	else
84 	{
85 		pRet = (SwTxtLine*)Get();
86 		((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
87 	}
88 	if ( !pRet->GetPara() )
89 		pRet->SetPara( new SwParaPortion );
90 	return pRet->GetPara();
91 }
92 
93 
94 /*************************************************************************
95 |*
96 |*	SwTxtLineAccess::SwTxtLineAccess()
97 |*
98 |*	Ersterstellung		MA 16. Mar. 94
99 |*	Letzte Aenderung	MA 16. Mar. 94
100 |*
101 |*************************************************************************/
102 
SwTxtLineAccess(const SwTxtFrm * pOwn)103 SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
104     SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
105 {
106 }
107 
108 /*************************************************************************
109 |*
110 |*	SwTxtLineAccess::IsAvailable
111 |*
112 |*	Ersterstellung		MA 23. Mar. 94
113 |*	Letzte Aenderung	MA 23. Mar. 94
114 |*
115 |*************************************************************************/
116 
IsAvailable() const117 sal_Bool SwTxtLineAccess::IsAvailable() const
118 {
119 	if ( pObj )
120 		return ((SwTxtLine*)pObj)->GetPara() != 0;
121 	return sal_False;
122 }
123 
124 /*************************************************************************
125 |*
126 |*	SwTxtFrm::HasPara()
127 |*
128 |*	Ersterstellung		MA 16. Mar. 94
129 |*	Letzte Aenderung	MA 22. Aug. 94
130 |*
131 |*************************************************************************/
132 
_HasPara() const133 sal_Bool SwTxtFrm::_HasPara() const
134 {
135 	SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
136 											Get( this, GetCacheIdx(), sal_False );
137 	if ( pTxtLine )
138 	{
139 		if ( pTxtLine->GetPara() )
140 			return sal_True;
141 	}
142 	else
143 		((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
144 
145 	return sal_False;
146 }
147 
148 /*************************************************************************
149 |*
150 |*	SwTxtFrm::GetPara()
151 |*
152 |*	Ersterstellung		MA 16. Mar. 94
153 |*	Letzte Aenderung	MA 22. Aug. 94
154 |*
155 |*************************************************************************/
156 
GetPara()157 SwParaPortion *SwTxtFrm::GetPara()
158 {
159 	if ( GetCacheIdx() != MSHRT_MAX )
160 	{	SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
161 										Get( this, GetCacheIdx(), sal_False );
162 		if ( pLine )
163 			return pLine->GetPara();
164 		else
165 			nCacheIdx = MSHRT_MAX;
166 	}
167 	return 0;
168 }
169 
170 
171 /*************************************************************************
172 |*
173 |*	SwTxtFrm::ClearPara()
174 |*
175 |*	Ersterstellung		MA 16. Mar. 94
176 |*	Letzte Aenderung	MA 22. Aug. 94
177 |*
178 |*************************************************************************/
179 
ClearPara()180 void SwTxtFrm::ClearPara()
181 {
182 	ASSERT( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
183 	if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
184 	{
185 		SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
186 										Get( this, GetCacheIdx(), sal_False );
187 		if ( pTxtLine )
188 		{
189 			delete pTxtLine->GetPara();
190 			pTxtLine->SetPara( 0 );
191 		}
192 		else
193 			nCacheIdx = MSHRT_MAX;
194 	}
195 }
196 
197 /*************************************************************************
198 |*
199 |*	SwTxtFrm::SetPara()
200 |*
201 |*	Ersterstellung		MA 16. Mar. 94
202 |*	Letzte Aenderung	MA 22. Aug. 94
203 |*
204 |*************************************************************************/
205 
SetPara(SwParaPortion * pNew,sal_Bool bDelete)206 void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
207 {
208 	if ( GetCacheIdx() != MSHRT_MAX )
209 	{
210 		//Nur die Information Auswechseln, das CacheObj bleibt stehen.
211 		SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
212 										Get( this, GetCacheIdx(), sal_False );
213 		if ( pTxtLine )
214 		{
215 			if( bDelete )
216 				delete pTxtLine->GetPara();
217 			pTxtLine->SetPara( pNew );
218 		}
219 		else
220 		{
221 			ASSERT( !pNew, "+SetPara: Losing SwParaPortion" );
222 			nCacheIdx = MSHRT_MAX;
223 		}
224 	}
225 	else if ( pNew )
226 	{	//Einen neuen einfuegen.
227 		SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
228 		if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
229 			nCacheIdx = pTxtLine->GetCachePos();
230 		else
231 		{
232 			ASSERT( sal_False, "+SetPara: InsertCache failed." );
233 		}
234 	}
235 }
236 
237 
238