Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "txtcache.hxx"
30 : : #include "txtfrm.hxx"
31 : : #include "porlay.hxx"
32 : :
33 : : /*************************************************************************
34 : : |*
35 : : |* SwTxtLine::SwTxtLine(), ~SwTxtLine()
36 : : |*
37 : : |*************************************************************************/
38 : :
39 : 3470 : SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
40 : : SwCacheObj( (void*)pFrm ),
41 : 3470 : pLine( pNew )
42 : : {
43 : 3470 : }
44 : :
45 : 3470 : SwTxtLine::~SwTxtLine()
46 : : {
47 [ + + ][ + - ]: 3470 : delete pLine;
48 [ - + ]: 6940 : }
49 : :
50 : : /*************************************************************************
51 : : |*
52 : : |* SwTxtLineAccess::NewObj()
53 : : |*
54 : : |*************************************************************************/
55 : :
56 : 3380 : SwCacheObj *SwTxtLineAccess::NewObj()
57 : : {
58 [ + - ]: 3380 : return new SwTxtLine( (SwTxtFrm*)pOwner );
59 : : }
60 : :
61 : : /*************************************************************************
62 : : |*
63 : : |* SwTxtLineAccess::GetPara()
64 : : |*
65 : : |*************************************************************************/
66 : :
67 : 44733 : SwParaPortion *SwTxtLineAccess::GetPara()
68 : : {
69 : : SwTxtLine *pRet;
70 [ + + ]: 44733 : if ( pObj )
71 : 41353 : pRet = (SwTxtLine*)pObj;
72 : : else
73 : : {
74 : 3380 : pRet = (SwTxtLine*)Get();
75 : 3380 : ((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
76 : : }
77 [ + + ]: 44733 : if ( !pRet->GetPara() )
78 [ + - ]: 4999 : pRet->SetPara( new SwParaPortion );
79 : 44733 : return pRet->GetPara();
80 : : }
81 : :
82 : :
83 : : /*************************************************************************
84 : : |*
85 : : |* SwTxtLineAccess::SwTxtLineAccess()
86 : : |*
87 : : |*************************************************************************/
88 : :
89 : 36099 : SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
90 : 36099 : SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
91 : : {
92 : 36099 : }
93 : :
94 : : /*************************************************************************
95 : : |*
96 : : |* SwTxtLineAccess::IsAvailable
97 : : |*
98 : : |*************************************************************************/
99 : :
100 : 15169 : sal_Bool SwTxtLineAccess::IsAvailable() const
101 : : {
102 [ + + ]: 15169 : if ( pObj )
103 : 11923 : return ((SwTxtLine*)pObj)->GetPara() != 0;
104 : 15169 : return sal_False;
105 : : }
106 : :
107 : : /*************************************************************************
108 : : |*
109 : : |* SwTxtFrm::HasPara()
110 : : |*
111 : : |*************************************************************************/
112 : :
113 : 212387 : sal_Bool SwTxtFrm::_HasPara() const
114 : : {
115 : : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
116 : 212387 : Get( this, GetCacheIdx(), sal_False );
117 [ + - ]: 212387 : if ( pTxtLine )
118 : : {
119 [ + + ]: 212387 : if ( pTxtLine->GetPara() )
120 : 208070 : return sal_True;
121 : : }
122 : : else
123 : 0 : ((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
124 : :
125 : 212387 : return sal_False;
126 : : }
127 : :
128 : : /*************************************************************************
129 : : |*
130 : : |* SwTxtFrm::GetPara()
131 : : |*
132 : : |*************************************************************************/
133 : :
134 : 409665 : SwParaPortion *SwTxtFrm::GetPara()
135 : : {
136 [ + + ]: 409665 : if ( GetCacheIdx() != MSHRT_MAX )
137 : : { SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
138 : 381870 : Get( this, GetCacheIdx(), sal_False );
139 [ + - ]: 381870 : if ( pLine )
140 : 381870 : return pLine->GetPara();
141 : : else
142 : 0 : nCacheIdx = MSHRT_MAX;
143 : : }
144 : 409665 : return 0;
145 : : }
146 : :
147 : :
148 : : /*************************************************************************
149 : : |*
150 : : |* SwTxtFrm::ClearPara()
151 : : |*
152 : : |*************************************************************************/
153 : :
154 : 7011 : void SwTxtFrm::ClearPara()
155 : : {
156 : : OSL_ENSURE( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
157 [ + - ][ + + ]: 7011 : if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
[ + + ]
158 : : {
159 : : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
160 : 5115 : Get( this, GetCacheIdx(), sal_False );
161 [ + - ]: 5115 : if ( pTxtLine )
162 : : {
163 [ + + ]: 5115 : delete pTxtLine->GetPara();
164 : 5115 : pTxtLine->SetPara( 0 );
165 : : }
166 : : else
167 : 0 : nCacheIdx = MSHRT_MAX;
168 : : }
169 : 7011 : }
170 : :
171 : : /*************************************************************************
172 : : |*
173 : : |* SwTxtFrm::SetPara()
174 : : |*
175 : : |*************************************************************************/
176 : :
177 : 228 : void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
178 : : {
179 [ + + ]: 228 : if ( GetCacheIdx() != MSHRT_MAX )
180 : : {
181 : : // Only change the information, the CacheObj stays there
182 : : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
183 : 138 : Get( this, GetCacheIdx(), sal_False );
184 [ + - ]: 138 : if ( pTxtLine )
185 : : {
186 [ + + ]: 138 : if( bDelete )
187 [ + - ]: 136 : delete pTxtLine->GetPara();
188 : 138 : pTxtLine->SetPara( pNew );
189 : : }
190 : : else
191 : : {
192 : : OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
193 : 0 : nCacheIdx = MSHRT_MAX;
194 : : }
195 : : }
196 [ + - ]: 90 : else if ( pNew )
197 : : { // Insert a new one
198 [ + - ]: 90 : SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
199 [ + - ]: 90 : if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
200 : 90 : nCacheIdx = pTxtLine->GetCachePos();
201 : : else
202 : : {
203 : : OSL_FAIL( "+SetPara: InsertCache failed." );
204 : : }
205 : : }
206 : 228 : }
207 : :
208 : :
209 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|