1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
24 /*************************************************************************
26 |* SwTxtLine::SwTxtLine(), ~SwTxtLine()
28 |*************************************************************************/
30 SwTxtLine::SwTxtLine( SwTxtFrm
*pFrm
, SwParaPortion
*pNew
) :
31 SwCacheObj( (void*)pFrm
),
36 SwTxtLine::~SwTxtLine()
41 /*************************************************************************
43 |* SwTxtLineAccess::NewObj()
45 |*************************************************************************/
47 SwCacheObj
*SwTxtLineAccess::NewObj()
49 return new SwTxtLine( (SwTxtFrm
*)pOwner
);
52 /*************************************************************************
54 |* SwTxtLineAccess::GetPara()
56 |*************************************************************************/
58 SwParaPortion
*SwTxtLineAccess::GetPara()
62 pRet
= (SwTxtLine
*)pObj
;
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
94 return ((SwTxtLine
*)pObj
)->GetPara() != 0;
98 /*************************************************************************
100 |* SwTxtFrm::HasPara()
102 |*************************************************************************/
104 sal_Bool
SwTxtFrm::_HasPara() const
106 SwTxtLine
*pTxtLine
= (SwTxtLine
*)SwTxtFrm::GetTxtCache()->
107 Get( this, GetCacheIdx(), sal_False
);
110 if ( pTxtLine
->GetPara() )
114 ((SwTxtFrm
*)this)->nCacheIdx
= MSHRT_MAX
;
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
);
131 return pLine
->GetPara();
133 nCacheIdx
= MSHRT_MAX
;
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
);
154 delete pTxtLine
->GetPara();
155 pTxtLine
->SetPara( 0 );
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
);
178 delete pTxtLine
->GetPara();
179 pTxtLine
->SetPara( pNew
);
183 OSL_ENSURE( !pNew
, "+SetPara: Losing SwParaPortion" );
184 nCacheIdx
= MSHRT_MAX
;
188 { // Insert a new one
189 SwTxtLine
*pTxtLine
= new SwTxtLine( this, pNew
);
190 if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine
) )
191 nCacheIdx
= pTxtLine
->GetCachePos();
194 OSL_FAIL( "+SetPara: InsertCache failed." );
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */