LibreOffice Module svx (master)  1
svdoutlinercache.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 <svdoutlinercache.hxx>
21 #include <svx/svdoutl.hxx>
22 #include <svx/svdmodel.hxx>
23 #include <svx/svdetc.hxx>
24 
26 : mpModel( pModel ),
27  maModeOutline(),
28  maModeText(),
29  maActiveOutliners()
30 {
31 }
32 
33 std::unique_ptr<SdrOutliner> SdrOutlinerCache::createOutliner( OutlinerMode nOutlinerMode )
34 {
35  std::unique_ptr<SdrOutliner> pOutliner;
36 
37  if( (OutlinerMode::OutlineObject == nOutlinerMode) && !maModeOutline.empty() )
38  {
39  pOutliner = std::move(maModeOutline.back());
40  maModeOutline.pop_back();
41  }
42  else if( (OutlinerMode::TextObject == nOutlinerMode) && !maModeText.empty() )
43  {
44  pOutliner = std::move(maModeText.back());
45  maModeText.pop_back();
46  }
47  else
48  {
49  pOutliner = SdrMakeOutliner(nOutlinerMode, *mpModel);
50  Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
51  pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
52  maActiveOutliners.insert(pOutliner.get());
53  }
54 
55  return pOutliner;
56 }
57 
59 {
60 }
61 
62 void SdrOutlinerCache::disposeOutliner( std::unique_ptr<SdrOutliner> pOutliner )
63 {
64  if( pOutliner )
65  {
66  OutlinerMode nOutlMode = pOutliner->GetOutlinerMode();
67 
68  if( OutlinerMode::OutlineObject == nOutlMode )
69  {
70  pOutliner->Clear();
71  pOutliner->SetVertical( false );
72 
73  // Deregister on outliner, might be reused from outliner cache
74  pOutliner->SetNotifyHdl( Link<EENotify&,void>() );
75  maModeOutline.emplace_back(std::move(pOutliner));
76  }
77  else if( OutlinerMode::TextObject == nOutlMode )
78  {
79  pOutliner->Clear();
80  pOutliner->SetVertical( false );
81 
82  // Deregister on outliner, might be reused from outliner cache
83  pOutliner->SetNotifyHdl( Link<EENotify&,void>() );
84  maModeText.emplace_back(std::move(pOutliner));
85  }
86  else
87  {
88  maActiveOutliners.erase(pOutliner.get());
89  }
90  }
91 }
92 
93 std::vector< SdrOutliner* > SdrOutlinerCache::GetActiveOutliners() const
94 {
95  return std::vector< SdrOutliner* >(maActiveOutliners.begin(), maActiveOutliners.end());
96 }
97 
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrOutliner & GetDrawOutliner(const SdrTextObj *pObj=nullptr) const
Definition: svdmodel.cxx:707
OutlinerMode
std::vector< std::unique_ptr< SdrOutliner > > maModeText
void disposeOutliner(std::unique_ptr< SdrOutliner > pOutliner)
std::unique_ptr< SdrOutliner > createOutliner(OutlinerMode nOutlinerMode)
void SetCalcFieldValueHdl(const Link< EditFieldInfo *, void > &rLink)
const_iterator end() const
std::vector< SdrOutliner * > GetActiveOutliners() const
const_iterator begin() const
std::vector< std::unique_ptr< SdrOutliner > > maModeOutline
SdrOutlinerCache(SdrModel *pModel)
o3tl::sorted_vector< SdrOutliner * > maActiveOutliners
std::unique_ptr< SdrOutliner > SdrMakeOutliner(OutlinerMode nOutlinerMode, SdrModel &rModel)
Create an Outliner with the engine-global default settings on the heap.
Definition: svdetc.cxx:338
const Link< EditFieldInfo *, void > & GetCalcFieldValueHdl() const
std::pair< const_iterator, bool > insert(Value &&x)
size_type erase(const Value &x)