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 <view.hxx>
26 
27 SwTextLine::SwTextLine( SwTextFrame const *pFrame, std::unique_ptr<SwParaPortion> pNew ) :
28  SwCacheObj( static_cast<void const *>(pFrame) ),
29  pLine( std::move(pNew) )
30 {
31 }
32 
34 {
35 }
36 
38 {
39  return new SwTextLine( static_cast<SwTextFrame const *>(m_pOwner) );
40 }
41 
43 {
44  SwTextLine *pRet;
45  if ( m_pObj )
46  pRet = static_cast<SwTextLine*>(m_pObj);
47  else
48  {
49  pRet = static_cast<SwTextLine*>(Get());
50  const_cast<SwTextFrame *>(static_cast<SwTextFrame const *>(m_pOwner))->SetCacheIdx( pRet->GetCachePos() );
51  }
52  if ( !pRet->GetPara() )
53  pRet->SetPara( new SwParaPortion, true/*bDelete*/ );
54  return pRet->GetPara();
55 }
56 
58  SwCacheAccess( *SwTextFrame::GetTextCache(), pOwn, pOwn->GetCacheIdx() )
59 {
60 }
61 
63 {
64  return m_pObj && static_cast<SwTextLine*>(m_pObj)->GetPara();
65 }
66 
68 {
69  SwTextLine *pTextLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
70  Get( this, GetCacheIdx(), false ));
71  if ( pTextLine )
72  {
73  if ( pTextLine->GetPara() )
74  return true;
75  }
76  else
77  const_cast<SwTextFrame*>(this)->mnCacheIndex = USHRT_MAX;
78 
79  return false;
80 }
81 
83 {
84  if ( GetCacheIdx() != USHRT_MAX )
85  {
86  SwTextLine *pLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
87  Get( this, GetCacheIdx(), false ));
88  if ( pLine )
89  return pLine->GetPara();
90  else
92  }
93  return nullptr;
94 }
95 
97 {
98  OSL_ENSURE( !IsLocked(), "+SwTextFrame::ClearPara: this is locked." );
99  if ( !IsLocked() && GetCacheIdx() != USHRT_MAX )
100  {
101  SwTextLine *pTextLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
102  Get( this, GetCacheIdx(), false ));
103  if ( pTextLine )
104  {
105  pTextLine->SetPara( nullptr, true/*bDelete*/ );
106  }
107  else
109  }
110 }
111 
112 void SwTextFrame::SetPara( SwParaPortion *pNew, bool bDelete )
113 {
114  if ( GetCacheIdx() != USHRT_MAX )
115  {
116  // Only change the information, the CacheObj stays there
117  SwTextLine *pTextLine = static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
118  Get( this, GetCacheIdx(), false ));
119  if ( pTextLine )
120  {
121  pTextLine->SetPara( pNew, bDelete );
122  }
123  else
124  {
125  OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
127  }
128  }
129  else if ( pNew )
130  { // Insert a new one
131  SwTextLine *pTextLine = new SwTextLine( this, std::unique_ptr<SwParaPortion>(pNew) );
132  if ( SwTextFrame::GetTextCache()->Insert( pTextLine ) )
133  mnCacheIndex = pTextLine->GetCachePos();
134  else
135  {
136  OSL_FAIL( "+SetPara: InsertCache failed." );
137  }
138  }
139 }
140 
151 {
152  sal_uInt16 nVisibleShells(0);
153  for (auto pView = SfxViewShell::GetFirst(true, checkSfxViewShell<SwView>);
154  pView != nullptr;
155  pView = SfxViewShell::GetNext(*pView, true, checkSfxViewShell<SwView>))
156  {
157  ++nVisibleShells;
158  }
159 
160  sal_uInt16 const nPreserved(100 * nVisibleShells);
161  SwCache & rCache(*SwTextFrame::GetTextCache());
162  if (rCache.GetCurMax() < nPreserved + 250)
163  {
164  rCache.IncreaseMax(nPreserved + 250 - rCache.GetCurMax());
165  }
166  rCache.SetLRUOfst(nPreserved);
167 }
168 
170 {
172 }
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
sal_uInt16 GetCachePos() const
Definition: swcache.hxx:162
void SetLRUOfst(const sal_uInt16 nOfst)
Definition: swcache.cxx:437
SwCacheObj * m_pObj
Definition: swcache.hxx:193
sal_uInt16 GetCurMax() const
Definition: swcache.hxx:113
SwParaPortion * GetPara()
Definition: txtcache.cxx:42
SwParaPortion * GetPara()
Definition: txtcache.cxx:82
SwParaPortion * GetPara()
Definition: txtcache.hxx:36
const void * m_pOwner
Definition: swcache.hxx:194
Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
Definition: porlay.hxx:229
void SetPara(SwParaPortion *pNew, bool bDelete=true)
Definition: txtcache.cxx:112
void SetPara(SwParaPortion *pNew, bool bDelete)
Definition: txtcache.hxx:39
static SwCache * GetTextCache()
Definition: txtfrm.hxx:597
void ResetLRUOfst()
nOfst determines how many are not to be touched
Definition: swcache.hxx:109
SwCacheObj * Get()
Definition: swcache.hxx:244
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
sal_uInt16 GetCacheIdx() const
Definition: txtfrm.hxx:602
sal_uInt16 mnCacheIndex
Definition: txtfrm.hxx:191
SwTextLineAccess(const SwTextFrame *pOwner)
Definition: txtcache.cxx:57
void IncreaseMax(const sal_uInt16 nAdd)
Definition: swcache.cxx:130
SwSaveSetLRUOfst()
Prevent the SwParaPortions of the visible paragraphs from being deleted; they would just be recreated...
Definition: txtcache.cxx:150
virtual ~SwTextLine() override
Definition: txtcache.cxx:33
bool IsLocked() const
Definition: txtfrm.hxx:505
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
virtual SwCacheObj * NewObj() override
Can be use in NewObj.
Definition: txtcache.cxx:37
SwTextLine(SwTextFrame const *pFrame, std::unique_ptr< SwParaPortion > pNew=nullptr)
Definition: txtcache.cxx:27
void ClearPara()
Removes the Line information from the Cache.
Definition: txtcache.cxx:96
The Cache object base class Users of the Cache must derrive a class from the SwCacheObj and store the...
Definition: swcache.hxx:133
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:259
SVX_DLLPUBLIC MSO_SPT Get(const OUString &)
void SetCacheIdx(const sal_uInt16 nNew)
Definition: txtfrm.hxx:603
Access class for the Cache.
Definition: swcache.hxx:186
bool HasPara_() const
Definition: txtcache.cxx:67
bool IsAvailable() const
Definition: txtcache.cxx:62
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo