Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / svdraw / svdoutlinercache.cxx
blob78746639e1c803491ac3f41ef2f2c5317ff48b05
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 <svdoutlinercache.hxx>
21 #include <svx/svdoutl.hxx>
22 #include <svx/svdmodel.hxx>
23 #include <svx/svdetc.hxx>
25 SdrOutlinerCache::SdrOutlinerCache( SdrModel* pModel )
26 : mpModel( pModel ),
27 maModeOutline(),
28 maModeText(),
29 maActiveOutliners()
33 std::unique_ptr<SdrOutliner> SdrOutlinerCache::createOutliner( OutlinerMode nOutlinerMode )
35 std::unique_ptr<SdrOutliner> pOutliner;
37 if( (OutlinerMode::OutlineObject == nOutlinerMode) && !maModeOutline.empty() )
39 pOutliner = std::move(maModeOutline.back());
40 maModeOutline.pop_back();
42 else if( (OutlinerMode::TextObject == nOutlinerMode) && !maModeText.empty() )
44 pOutliner = std::move(maModeText.back());
45 maModeText.pop_back();
47 else
49 pOutliner = SdrMakeOutliner(nOutlinerMode, *mpModel);
50 Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
51 pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
52 maActiveOutliners.insert(pOutliner.get());
55 return pOutliner;
58 SdrOutlinerCache::~SdrOutlinerCache()
62 void SdrOutlinerCache::disposeOutliner( std::unique_ptr<SdrOutliner> pOutliner )
64 if( !pOutliner )
65 return;
67 OutlinerMode nOutlMode = pOutliner->GetOutlinerMode();
69 if( OutlinerMode::OutlineObject == nOutlMode )
71 pOutliner->Clear();
72 pOutliner->SetVertical( false );
74 // Deregister on outliner, might be reused from outliner cache
75 pOutliner->SetNotifyHdl( Link<EENotify&,void>() );
76 maModeOutline.emplace_back(std::move(pOutliner));
78 else if( OutlinerMode::TextObject == nOutlMode )
80 pOutliner->Clear();
81 pOutliner->SetVertical( false );
83 // Deregister on outliner, might be reused from outliner cache
84 pOutliner->SetNotifyHdl( Link<EENotify&,void>() );
85 maModeText.emplace_back(std::move(pOutliner));
87 else
89 maActiveOutliners.erase(pOutliner.get());
93 std::vector< SdrOutliner* > SdrOutlinerCache::GetActiveOutliners() const
95 return std::vector< SdrOutliner* >(maActiveOutliners.begin(), maActiveOutliners.end());
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */