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 586 : SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
31 : SwCacheObj( (void*)pFrm ),
32 586 : pLine( pNew )
33 : {
34 586 : }
35 :
36 1758 : SwTxtLine::~SwTxtLine()
37 : {
38 586 : delete pLine;
39 1172 : }
40 :
41 : /*************************************************************************
42 : |*
43 : |* SwTxtLineAccess::NewObj()
44 : |*
45 : |*************************************************************************/
46 :
47 556 : SwCacheObj *SwTxtLineAccess::NewObj()
48 : {
49 556 : return new SwTxtLine( (SwTxtFrm*)pOwner );
50 : }
51 :
52 : /*************************************************************************
53 : |*
54 : |* SwTxtLineAccess::GetPara()
55 : |*
56 : |*************************************************************************/
57 :
58 1764 : SwParaPortion *SwTxtLineAccess::GetPara()
59 : {
60 : SwTxtLine *pRet;
61 1764 : if ( pObj )
62 1208 : pRet = (SwTxtLine*)pObj;
63 : else
64 : {
65 556 : pRet = (SwTxtLine*)Get();
66 556 : ((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
67 : }
68 1764 : if ( !pRet->GetPara() )
69 632 : pRet->SetPara( new SwParaPortion );
70 1764 : return pRet->GetPara();
71 : }
72 :
73 :
74 : /*************************************************************************
75 : |*
76 : |* SwTxtLineAccess::SwTxtLineAccess()
77 : |*
78 : |*************************************************************************/
79 :
80 1771 : SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
81 1771 : SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
82 : {
83 1771 : }
84 :
85 : /*************************************************************************
86 : |*
87 : |* SwTxtLineAccess::IsAvailable
88 : |*
89 : |*************************************************************************/
90 :
91 784 : sal_Bool SwTxtLineAccess::IsAvailable() const
92 : {
93 784 : if ( pObj )
94 229 : return ((SwTxtLine*)pObj)->GetPara() != 0;
95 555 : return sal_False;
96 : }
97 :
98 : /*************************************************************************
99 : |*
100 : |* SwTxtFrm::HasPara()
101 : |*
102 : |*************************************************************************/
103 :
104 8467 : sal_Bool SwTxtFrm::_HasPara() const
105 : {
106 : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
107 8467 : Get( this, GetCacheIdx(), sal_False );
108 8467 : if ( pTxtLine )
109 : {
110 8467 : if ( pTxtLine->GetPara() )
111 8376 : return sal_True;
112 : }
113 : else
114 0 : ((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
115 :
116 91 : return sal_False;
117 : }
118 :
119 : /*************************************************************************
120 : |*
121 : |* SwTxtFrm::GetPara()
122 : |*
123 : |*************************************************************************/
124 :
125 15874 : SwParaPortion *SwTxtFrm::GetPara()
126 : {
127 15874 : if ( GetCacheIdx() != MSHRT_MAX )
128 : { SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
129 13677 : Get( this, GetCacheIdx(), sal_False );
130 13677 : if ( pLine )
131 13677 : return pLine->GetPara();
132 : else
133 0 : nCacheIdx = MSHRT_MAX;
134 : }
135 2197 : return 0;
136 : }
137 :
138 :
139 : /*************************************************************************
140 : |*
141 : |* SwTxtFrm::ClearPara()
142 : |*
143 : |*************************************************************************/
144 :
145 330 : void SwTxtFrm::ClearPara()
146 : {
147 : OSL_ENSURE( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
148 330 : if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
149 : {
150 : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
151 256 : Get( this, GetCacheIdx(), sal_False );
152 256 : if ( pTxtLine )
153 : {
154 256 : delete pTxtLine->GetPara();
155 256 : pTxtLine->SetPara( 0 );
156 : }
157 : else
158 0 : nCacheIdx = MSHRT_MAX;
159 : }
160 330 : }
161 :
162 : /*************************************************************************
163 : |*
164 : |* SwTxtFrm::SetPara()
165 : |*
166 : |*************************************************************************/
167 :
168 60 : void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
169 : {
170 60 : if ( GetCacheIdx() != MSHRT_MAX )
171 : {
172 : // Only change the information, the CacheObj stays there
173 : SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
174 30 : Get( this, GetCacheIdx(), sal_False );
175 30 : if ( pTxtLine )
176 : {
177 30 : if( bDelete )
178 30 : delete pTxtLine->GetPara();
179 30 : pTxtLine->SetPara( pNew );
180 : }
181 : else
182 : {
183 : OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
184 0 : nCacheIdx = MSHRT_MAX;
185 : }
186 : }
187 30 : else if ( pNew )
188 : { // Insert a new one
189 30 : SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
190 30 : if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
191 30 : nCacheIdx = pTxtLine->GetCachePos();
192 : else
193 : {
194 : OSL_FAIL( "+SetPara: InsertCache failed." );
195 : }
196 : }
197 60 : }
198 :
199 :
200 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|