1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <svl/itempool.hxx>
23 #include <svl/poolitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <nochaos.hxx>
29 #define WID_CHAOS_START 500
36 class CntStaticPoolDefaults_Impl
38 static const sal_uInt32 m_nItems
= 1;
39 std::vector
<SfxPoolItem
*> mvDefaults
;
40 std::unique_ptr
<SfxItemInfo
[]> m_pItemInfos
;
43 inline void Insert( SfxPoolItem
* pItem
);
46 explicit CntStaticPoolDefaults_Impl();
47 ~CntStaticPoolDefaults_Impl();
48 CntStaticPoolDefaults_Impl(const CntStaticPoolDefaults_Impl
&) = delete;
49 CntStaticPoolDefaults_Impl
& operator=(const CntStaticPoolDefaults_Impl
&) = delete;
51 std::vector
<SfxPoolItem
*>* GetDefaults() { return &mvDefaults
; }
52 const SfxItemInfo
* GetItemInfos() const { return m_pItemInfos
.get(); }
56 class CntItemPool
: public SfxItemPool
58 static CntItemPool
* _pThePool
;
63 virtual ~CntItemPool() override
;
66 static CntItemPool
* Acquire();
67 static sal_uInt16
Release();
73 SfxItemPool
* NoChaos::GetItemPool()
75 // Get and hold CHAOS item pool.
76 return CntItemPool::Acquire();
81 sal_uInt16
NoChaos::ReleaseItemPool()
83 // Release CHAOS item pool.
84 return CntItemPool::Release();
88 // CntItemPool implementation
91 static CntStaticPoolDefaults_Impl
* pPoolDefs_Impl
= nullptr;
94 CntItemPool
* CntItemPool::_pThePool
= nullptr;
97 CntItemPool::CntItemPool()
98 : SfxItemPool( "chaos", WID_CHAOS_START
, WID_CHAOS_START
, nullptr ),
103 // Create static defaults.
104 pPoolDefs_Impl
= new CntStaticPoolDefaults_Impl
;
107 SetItemInfos( pPoolDefs_Impl
->GetItemInfos() );
109 // Set static pool default items.
110 SetDefaults( pPoolDefs_Impl
->GetDefaults() );
115 CntItemPool::~CntItemPool()
117 // Release static pool default items.
123 CntItemPool
* CntItemPool::Acquire()
126 _pThePool
= new CntItemPool
;
135 sal_uInt16
CntItemPool::Release()
140 sal_uInt16
& nRefs
= _pThePool
->_nRefs
;
149 delete pPoolDefs_Impl
;
150 pPoolDefs_Impl
= nullptr;
158 // CntStaticPoolDefaults_Impl implementation.
161 inline void CntStaticPoolDefaults_Impl::Insert(
162 SfxPoolItem
* pItem
/* Static Pool Default Item */ )
164 sal_uInt16 nPos
= pItem
->Which() - WID_CHAOS_START
;
166 mvDefaults
[ nPos
] = pItem
;
167 m_pItemInfos
[ nPos
]._nSID
= 0;
168 m_pItemInfos
[ nPos
]._bPoolable
= true;
172 CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
174 for ( sal_uInt32 n
= 0; n
< m_nItems
; ++n
)
175 delete mvDefaults
[ n
];
179 CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl()
180 : mvDefaults( m_nItems
, nullptr ),
181 m_pItemInfos( new SfxItemInfo
[ m_nItems
] )
183 memset( m_pItemInfos
.get(), 0, sizeof( SfxItemInfo
) * m_nItems
);
184 Insert( new SfxStringItem( WID_CHAOS_START
, OUString() ) );
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */