Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sw / source / core / text / txtcache.cxx
blobbecdf9169c4270869fa3831aef8296ad7344307a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "txtcache.hxx"
21 #include "txtfrm.hxx"
22 #include "porlay.hxx"
24 /*************************************************************************
26 |* SwTxtLine::SwTxtLine(), ~SwTxtLine()
28 |*************************************************************************/
30 SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
31 SwCacheObj( (void*)pFrm ),
32 pLine( pNew )
36 SwTxtLine::~SwTxtLine()
38 delete pLine;
41 /*************************************************************************
43 |* SwTxtLineAccess::NewObj()
45 |*************************************************************************/
47 SwCacheObj *SwTxtLineAccess::NewObj()
49 return new SwTxtLine( (SwTxtFrm*)pOwner );
52 /*************************************************************************
54 |* SwTxtLineAccess::GetPara()
56 |*************************************************************************/
58 SwParaPortion *SwTxtLineAccess::GetPara()
60 SwTxtLine *pRet;
61 if ( pObj )
62 pRet = (SwTxtLine*)pObj;
63 else
65 pRet = (SwTxtLine*)Get();
66 ((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
68 if ( !pRet->GetPara() )
69 pRet->SetPara( new SwParaPortion );
70 return pRet->GetPara();
74 /*************************************************************************
76 |* SwTxtLineAccess::SwTxtLineAccess()
78 |*************************************************************************/
80 SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
81 SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
85 /*************************************************************************
87 |* SwTxtLineAccess::IsAvailable
89 |*************************************************************************/
91 sal_Bool SwTxtLineAccess::IsAvailable() const
93 if ( pObj )
94 return ((SwTxtLine*)pObj)->GetPara() != 0;
95 return sal_False;
98 /*************************************************************************
100 |* SwTxtFrm::HasPara()
102 |*************************************************************************/
104 sal_Bool SwTxtFrm::_HasPara() const
106 SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
107 Get( this, GetCacheIdx(), sal_False );
108 if ( pTxtLine )
110 if ( pTxtLine->GetPara() )
111 return sal_True;
113 else
114 ((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
116 return sal_False;
119 /*************************************************************************
121 |* SwTxtFrm::GetPara()
123 |*************************************************************************/
125 SwParaPortion *SwTxtFrm::GetPara()
127 if ( GetCacheIdx() != MSHRT_MAX )
128 { SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
129 Get( this, GetCacheIdx(), sal_False );
130 if ( pLine )
131 return pLine->GetPara();
132 else
133 nCacheIdx = MSHRT_MAX;
135 return 0;
139 /*************************************************************************
141 |* SwTxtFrm::ClearPara()
143 |*************************************************************************/
145 void SwTxtFrm::ClearPara()
147 OSL_ENSURE( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
148 if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
150 SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
151 Get( this, GetCacheIdx(), sal_False );
152 if ( pTxtLine )
154 delete pTxtLine->GetPara();
155 pTxtLine->SetPara( 0 );
157 else
158 nCacheIdx = MSHRT_MAX;
162 /*************************************************************************
164 |* SwTxtFrm::SetPara()
166 |*************************************************************************/
168 void SwTxtFrm::SetPara( SwParaPortion *pNew, sal_Bool bDelete )
170 if ( GetCacheIdx() != MSHRT_MAX )
172 // Only change the information, the CacheObj stays there
173 SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
174 Get( this, GetCacheIdx(), sal_False );
175 if ( pTxtLine )
177 if( bDelete )
178 delete pTxtLine->GetPara();
179 pTxtLine->SetPara( pNew );
181 else
183 OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
184 nCacheIdx = MSHRT_MAX;
187 else if ( pNew )
188 { // Insert a new one
189 SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
190 if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
191 nCacheIdx = pTxtLine->GetCachePos();
192 else
194 OSL_FAIL( "+SetPara: InsertCache failed." );
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */