/src/libreoffice/sfx2/source/explorer/nochaos.cxx
Line | Count | Source |
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 <sal/config.h> |
21 | | |
22 | | #include <svl/itempool.hxx> |
23 | | #include <svl/poolitem.hxx> |
24 | | #include <svl/stritem.hxx> |
25 | | #include <nochaos.hxx> |
26 | | #include <memory> |
27 | | |
28 | | |
29 | | #define WID_CHAOS_START TypedWhichId<SfxStringItem>(500) |
30 | | |
31 | | |
32 | | namespace { |
33 | | class CntItemPool: public SfxItemPool |
34 | | { |
35 | | static CntItemPool* _pThePool; |
36 | | sal_uInt16 _nRefs; |
37 | | |
38 | | protected: |
39 | | CntItemPool(); |
40 | | virtual ~CntItemPool() override; |
41 | | |
42 | | public: |
43 | | static CntItemPool* Acquire(); |
44 | | static sal_uInt16 Release(); |
45 | | }; |
46 | | |
47 | | } |
48 | | |
49 | | // static |
50 | | SfxItemPool* NoChaos::GetItemPool() |
51 | 27 | { |
52 | | // Get and hold CHAOS item pool. |
53 | 27 | return CntItemPool::Acquire(); |
54 | 27 | } |
55 | | |
56 | | |
57 | | // static |
58 | | sal_uInt16 NoChaos::ReleaseItemPool() |
59 | 0 | { |
60 | | // Release CHAOS item pool. |
61 | 0 | return CntItemPool::Release(); |
62 | 0 | } |
63 | | |
64 | | |
65 | | // CntItemPool implementation |
66 | | static ItemInfoPackage& getItemInfoPackageNoChaos() |
67 | 27 | { |
68 | 27 | class ItemInfoPackageNoChaos : public ItemInfoPackage |
69 | 27 | { |
70 | 27 | typedef std::array<ItemInfoStatic, 1> ItemInfoArrayNoChaos; |
71 | 27 | ItemInfoArrayNoChaos maItemInfos {{ |
72 | | // m_nWhich, m_pItem, m_nSlotID, m_nItemInfoFlags |
73 | 27 | { WID_CHAOS_START, new SfxStringItem(WID_CHAOS_START, OUString()), 0, SFX_ITEMINFOFLAG_NONE } |
74 | 27 | }}; |
75 | | |
76 | 27 | virtual const ItemInfoStatic& getItemInfoStatic(size_t nIndex) const override { return maItemInfos[nIndex]; } |
77 | | |
78 | 27 | public: |
79 | 135 | virtual size_t size() const override { return maItemInfos.size(); } |
80 | 27 | virtual const ItemInfo& getItemInfo(size_t nIndex, SfxItemPool& /*rPool*/) override { return maItemInfos[nIndex]; } |
81 | 27 | }; |
82 | | |
83 | 27 | static std::unique_ptr<ItemInfoPackageNoChaos> g_aItemInfoPackageNoChaos; |
84 | 27 | if (!g_aItemInfoPackageNoChaos) |
85 | 27 | g_aItemInfoPackageNoChaos.reset(new ItemInfoPackageNoChaos); |
86 | 27 | return *g_aItemInfoPackageNoChaos; |
87 | 27 | } |
88 | | |
89 | | |
90 | | // static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = nullptr; |
91 | | |
92 | | // static member! |
93 | | CntItemPool* CntItemPool::_pThePool = nullptr; |
94 | | |
95 | | CntItemPool::CntItemPool() |
96 | 27 | : SfxItemPool(u"chaos"_ustr) |
97 | 27 | , _nRefs(0) |
98 | 27 | { |
99 | 27 | registerItemInfoPackage(getItemInfoPackageNoChaos()); |
100 | 27 | } |
101 | | |
102 | | |
103 | | //virtual |
104 | | CntItemPool::~CntItemPool() |
105 | | { |
106 | | } |
107 | | |
108 | | |
109 | | // static |
110 | | CntItemPool* CntItemPool::Acquire() |
111 | 27 | { |
112 | 27 | if ( !_pThePool ) |
113 | 27 | _pThePool = new CntItemPool; |
114 | | |
115 | 27 | _pThePool->_nRefs++; |
116 | | |
117 | 27 | return _pThePool; |
118 | 27 | } |
119 | | |
120 | | |
121 | | // static |
122 | | sal_uInt16 CntItemPool::Release() |
123 | 0 | { |
124 | 0 | if ( !_pThePool ) |
125 | 0 | return 0; |
126 | | |
127 | 0 | sal_uInt16& nRefs = _pThePool->_nRefs; |
128 | |
|
129 | 0 | if ( nRefs ) |
130 | 0 | --nRefs; |
131 | |
|
132 | 0 | if ( !nRefs ) |
133 | 0 | { |
134 | 0 | delete _pThePool; |
135 | 0 | _pThePool = nullptr; |
136 | 0 | return 0; |
137 | 0 | } |
138 | | |
139 | 0 | return nRefs; |
140 | 0 | } |
141 | | |
142 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |