LibreOffice Module sw (master) 1
txtcache.cxx
Go to the documentation of this file.
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#include <sfx2/viewsh.hxx>
25#include <osl/diagnose.h>
26#include <view.hxx>
27
28SwTextLine::SwTextLine( SwTextFrame const *pFrame, std::unique_ptr<SwParaPortion> pNew ) :
29 SwCacheObj( static_cast<void const *>(pFrame) ),
30 m_pLine( std::move(pNew) )
31{
32}
33
35{
36}
37
39{
40 // note: SwTextFrame lives longer than its SwTextLine, see ~SwTextFrame
41 assert(m_pOwner);
42 const_cast<SwTextFrame *>(static_cast<SwTextFrame const *>(m_pOwner))->SetCacheIdx(GetCachePos());
43}
44
46{
47 return new SwTextLine( static_cast<SwTextFrame const *>(m_pOwner) );
48}
49
51{
52 SwTextLine *pRet;
53 if ( m_pObj )
54 pRet = static_cast<SwTextLine*>(m_pObj);
55 else
56 {
57 pRet = static_cast<SwTextLine*>(Get(false));
58 const_cast<SwTextFrame *>(static_cast<SwTextFrame const *>(m_pOwner))->SetCacheIdx( pRet->GetCachePos() );
59 }
60 if ( !pRet->GetPara() )
61 pRet->SetPara( new SwParaPortion, true/*bDelete*/ );
62 return pRet->GetPara();
63}
64
66 SwCacheAccess( *SwTextFrame::GetTextCache(), pOwn, pOwn->GetCacheIdx() )
67{
68}
69
71{
72 return m_pObj && static_cast<SwTextLine*>(m_pObj)->GetPara();
73}
74
76{
77 SwTextLine *pTextLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
78 Get( this, GetCacheIdx(), false ));
79 if ( pTextLine )
80 {
81 if ( pTextLine->GetPara() )
82 return true;
83 }
84 else
85 const_cast<SwTextFrame*>(this)->mnCacheIndex = USHRT_MAX;
86
87 return false;
88}
89
91{
92 if ( GetCacheIdx() != USHRT_MAX )
93 {
94 SwTextLine *pLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
95 Get( this, GetCacheIdx(), false ));
96 if ( pLine )
97 return pLine->GetPara();
98 else
99 mnCacheIndex = USHRT_MAX;
100 }
101 return nullptr;
102}
103
105{
106 OSL_ENSURE( !IsLocked(), "+SwTextFrame::ClearPara: this is locked." );
107 if ( !IsLocked() && GetCacheIdx() != USHRT_MAX )
108 {
109 SwTextLine *pTextLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
110 Get( this, GetCacheIdx(), false ));
111 if ( pTextLine )
112 {
113 pTextLine->SetPara( nullptr, true/*bDelete*/ );
114 }
115 else
116 mnCacheIndex = USHRT_MAX;
117 }
118}
119
121{
122 if (GetCacheIdx() != USHRT_MAX)
123 {
125 SetCacheIdx(USHRT_MAX);
126 }
127}
128
129void SwTextFrame::SetPara( SwParaPortion *pNew, bool bDelete )
130{
131 if ( GetCacheIdx() != USHRT_MAX )
132 {
133 // Only change the information, the CacheObj stays there
134 SwTextLine *pTextLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
135 Get( this, GetCacheIdx(), false ));
136 if ( pTextLine )
137 {
138 pTextLine->SetPara( pNew, bDelete );
139 }
140 else
141 {
142 OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
143 mnCacheIndex = USHRT_MAX;
144 }
145 }
146 else if ( pNew )
147 { // Insert a new one
148 SwTextLine *pTextLine = new SwTextLine( this, std::unique_ptr<SwParaPortion>(pNew) );
149 if (SwTextFrame::GetTextCache()->Insert(pTextLine, false))
150 mnCacheIndex = pTextLine->GetCachePos();
151 else
152 {
153 OSL_FAIL( "+SetPara: InsertCache failed." );
154 }
155 }
156}
157
168{
169 sal_uInt16 nVisibleShells(0);
170 for (auto pView = SfxViewShell::GetFirst(true, checkSfxViewShell<SwView>);
171 pView != nullptr;
172 pView = SfxViewShell::GetNext(*pView, true, checkSfxViewShell<SwView>))
173 {
174 // Apparently we are not interested here what document pView is for, but only in the
175 // total number of shells in the process?
176 ++nVisibleShells;
177 }
178
179 sal_uInt16 const nPreserved(100 * nVisibleShells);
181 if (rCache.GetCurMax() < nPreserved + 250)
182 {
183 rCache.IncreaseMax(nPreserved + 250 - rCache.GetCurMax());
184 }
185 rCache.SetLRUOfst(nPreserved);
186}
187
189{
191}
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
Access class for the Cache.
Definition: swcache.hxx:198
const void * m_pOwner
Definition: swcache.hxx:205
SwCacheObj * m_pObj
Definition: swcache.hxx:204
SwCacheObj * Get(bool isDuplicateOwnerAllowed)
Definition: swcache.hxx:259
The Cache object base class Users of the Cache must derive a class from the SwCacheObj and store thei...
Definition: swcache.hxx:137
const void * m_pOwner
Definition: swcache.hxx:163
sal_uInt16 GetCachePos() const
Definition: swcache.hxx:173
void Delete(const void *pOwner, sal_uInt16 nIndex)
Definition: swcache.cxx:322
void ResetLRUOfst()
Definition: swcache.hxx:112
sal_uInt16 GetCurMax() const
Definition: swcache.hxx:116
void IncreaseMax(const sal_uInt16 nAdd)
Definition: swcache.cxx:128
void SetLRUOfst(const sal_uInt16 nOfst)
Mark some entries as "do not delete".
Definition: swcache.cxx:439
Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
Definition: porlay.hxx:251
SwSaveSetLRUOfst()
Prevent the SwParaPortions of the visible paragraphs from being deleted; they would just be recreated...
Definition: txtcache.cxx:167
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:165
bool HasPara_() const
Definition: txtcache.cxx:75
void ClearPara()
Removes the Line information from the Cache but retains the entry itself.
Definition: txtcache.cxx:104
void SetPara(SwParaPortion *pNew, bool bDelete=true)
Definition: txtcache.cxx:129
void SetCacheIdx(const sal_uInt16 nNew)
Definition: txtfrm.hxx:620
SwParaPortion * GetPara()
Definition: txtcache.cxx:90
bool IsLocked() const
Definition: txtfrm.hxx:523
static SwCache * s_pTextCache
SwLineLayout cache: the lines are not actually owned by the SwTextFrame but by this SwCache,...
Definition: txtfrm.hxx:177
static SwCache * GetTextCache()
Definition: txtfrm.hxx:614
sal_uInt16 mnCacheIndex
Definition: txtfrm.hxx:206
sal_uInt16 GetCacheIdx() const
Definition: txtfrm.hxx:619
void RemoveFromCache()
Removes this frame completely from the Cache.
Definition: txtcache.cxx:120
virtual SwCacheObj * NewObj() override
Can be use in NewObj.
Definition: txtcache.cxx:45
SwTextLineAccess(const SwTextFrame *pOwner)
Definition: txtcache.cxx:65
bool IsAvailable() const
Definition: txtcache.cxx:70
SwParaPortion * GetPara()
Definition: txtcache.cxx:50
SwParaPortion * GetPara()
Definition: txtcache.hxx:38
SwTextLine(SwTextFrame const *pFrame, std::unique_ptr< SwParaPortion > pNew=nullptr)
Definition: txtcache.cxx:28
virtual void UpdateCachePos() override
Definition: txtcache.cxx:38
virtual ~SwTextLine() override
Definition: txtcache.cxx:34
void SetPara(SwParaPortion *pNew, bool bDelete)
Definition: txtcache.hxx:41
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)