Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "txtcache.hxx"
21 : #include "txtfrm.hxx"
22 : #include "porlay.hxx"
23 :
24 : /*************************************************************************
25 : |*
26 : |* SwTxtLine::SwTxtLine(), ~SwTxtLine()
27 : |*
28 : |*************************************************************************/
29 :
30 2422 : SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
31 : SwCacheObj( (void*)pFrm ),
32 2422 : pLine( pNew )
33 : {
34 2422 : }
35 :
36 7266 : SwTxtLine::~SwTxtLine()
37 : {
38 2422 : delete pLine;
39 4844 : }
40 :
41 : /*************************************************************************
42 : |*
43 : |* SwTxtLineAccess::NewObj()
44 : |*
45 : |*************************************************************************/
46 :
47 2353 : SwCacheObj *SwTxtLineAccess::NewObj()
48 : {
49 2353 : return new SwTxtLine( (SwTxtFrm*)pOwner );
50 : }
51 :
52 : /*************************************************************************
53 : |*
54 : |* SwTxtLineAccess::GetPara()
55 : |*
56 : |*************************************************************************/
57 :
58 21707 : SwParaPortion *SwTxtLineAccess::GetPara()
59 : {
60 : SwTxtLine *pRet;
61 21707 : if ( pObj )
62 19354 : pRet = (SwTxtLine*)pObj;
63 : else
64 : {
65 2353 : pRet = (SwTxtLine*)Get();
66 2353 : ((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
67 : }
68 21707 : if ( !pRet->GetPara() )
69 3455 : pRet->SetPara( new SwParaPortion );
70 21707 : return pRet->GetPara();
71 : }
72 :
73 :
74 : /*************************************************************************
75 : |*
76 : |* SwTxtLineAccess::SwTxtLineAccess()
77 : |*
78 : |*************************************************************************/
79 :
80 17887 : SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
81 17887 : SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
82 : {
83 17887 : }
84 :
85 : /*************************************************************************
86 : |*
87 : |* SwTxtLineAccess::IsAvailable
88 : |*
89 : |*************************************************************************/
90 :
91 7851 : sal_Bool SwTxtLineAccess::IsAvailable() const
92 : {
93 7851 : if ( pObj )
94 5561 : return ((SwTxtLine*)pObj)->GetPara() != 0;
95 2290 : return sal_False;
96 : }
97 :
98 : /*************************************************************************
99 : |*
100 : |* SwTxtFrm::HasPara()
101 : |*
102 : |*************************************************************************/
103 :
104 105895 : sal_Bool SwTxtFrm::_HasPara() const
105 : {
106 : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
107 105895 : Get( this, GetCacheIdx(), sal_False );
108 105895 : if ( pTxtLine )
109 : {
110 105895 : if ( pTxtLine->GetPara() )
111 103358 : return sal_True;
112 : }
113 : else
114 0 : ((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
115 :
116 2537 : return sal_False;
117 : }
118 :
119 : /*************************************************************************
120 : |*
121 : |* SwTxtFrm::GetPara()
122 : |*
123 : |*************************************************************************/
124 :
125 207140 : SwParaPortion *SwTxtFrm::GetPara()
126 : {
127 207140 : if ( GetCacheIdx() != MSHRT_MAX )
128 : { SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
129 188558 : Get( this, GetCacheIdx(), sal_False );
130 188558 : if ( pLine )
131 188558 : return pLine->GetPara();
132 : else
133 0 : nCacheIdx = MSHRT_MAX;
134 : }
135 18582 : return 0;
136 : }
137 :
138 :
139 : /*************************************************************************
140 : |*
141 : |* SwTxtFrm::ClearPara()
142 : |*
143 : |*************************************************************************/
144 :
145 5397 : void SwTxtFrm::ClearPara()
146 : {
147 : OSL_ENSURE( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
148 5397 : if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
149 : {
150 : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
151 3607 : Get( this, GetCacheIdx(), sal_False );
152 3607 : if ( pTxtLine )
153 : {
154 3607 : delete pTxtLine->GetPara();
155 3607 : pTxtLine->SetPara( 0 );
156 : }
157 : else
158 0 : nCacheIdx = MSHRT_MAX;
159 : }
160 5397 : }
161 :
162 : /*************************************************************************
163 : |*
164 : |* SwTxtFrm::SetPara()
165 : |*
166 : |*************************************************************************/
167 :
168 173 : void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
169 : {
170 173 : if ( GetCacheIdx() != MSHRT_MAX )
171 : {
172 : // Only change the information, the CacheObj stays there
173 : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
174 104 : Get( this, GetCacheIdx(), sal_False );
175 104 : if ( pTxtLine )
176 : {
177 104 : if( bDelete )
178 96 : delete pTxtLine->GetPara();
179 104 : pTxtLine->SetPara( pNew );
180 : }
181 : else
182 : {
183 : OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
184 0 : nCacheIdx = MSHRT_MAX;
185 : }
186 : }
187 69 : else if ( pNew )
188 : { // Insert a new one
189 69 : SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
190 69 : if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
191 69 : nCacheIdx = pTxtLine->GetCachePos();
192 : else
193 : {
194 : OSL_FAIL( "+SetPara: InsertCache failed." );
195 : }
196 : }
197 272 : }
198 :
199 :
200 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|