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 <tools/solar.h>
23 #include <svl/itempool.hxx>
24 #include <svl/poolitem.hxx>
25 #include <svl/stritem.hxx>
26 #include <nochaos.hxx>
30 #define WID_CHAOS_START 500
37 class CntStaticPoolDefaults_Impl
39 static const sal_uInt32 m_nItems
= 1;
40 std::vector
<SfxPoolItem
*> mvDefaults
;
41 std::unique_ptr
<SfxItemInfo
[]> m_pItemInfos
;
44 inline void Insert( SfxPoolItem
* pItem
);
47 explicit CntStaticPoolDefaults_Impl();
48 ~CntStaticPoolDefaults_Impl();
49 CntStaticPoolDefaults_Impl(const CntStaticPoolDefaults_Impl
&) = delete;
50 CntStaticPoolDefaults_Impl
& operator=(const CntStaticPoolDefaults_Impl
&) = delete;
52 std::vector
<SfxPoolItem
*>* GetDefaults() { return &mvDefaults
; }
53 const SfxItemInfo
* GetItemInfos() const { return m_pItemInfos
.get(); }
57 class CntItemPool
: public SfxItemPool
59 static CntItemPool
* _pThePool
;
64 virtual ~CntItemPool() override
;
67 static CntItemPool
* Acquire();
68 static sal_uInt16
Release();
74 SfxItemPool
* NoChaos::GetItemPool()
76 // Get and hold CHAOS item pool.
77 return CntItemPool::Acquire();
82 sal_uInt16
NoChaos::ReleaseItemPool()
84 // Release CHAOS item pool.
85 return CntItemPool::Release();
89 // CntItemPool implementation
92 static CntStaticPoolDefaults_Impl
* pPoolDefs_Impl
= nullptr;
95 CntItemPool
* CntItemPool::_pThePool
= nullptr;
98 CntItemPool::CntItemPool()
99 : SfxItemPool( "chaos", WID_CHAOS_START
, WID_CHAOS_START
, nullptr ),
104 // Create static defaults.
105 pPoolDefs_Impl
= new CntStaticPoolDefaults_Impl
;
108 SetItemInfos( pPoolDefs_Impl
->GetItemInfos() );
110 // Set static pool default items.
111 SetDefaults( pPoolDefs_Impl
->GetDefaults() );
116 CntItemPool::~CntItemPool()
118 // Release static pool default items.
124 CntItemPool
* CntItemPool::Acquire()
127 _pThePool
= new CntItemPool
;
136 sal_uInt16
CntItemPool::Release()
141 sal_uInt16
& nRefs
= _pThePool
->_nRefs
;
150 delete pPoolDefs_Impl
;
151 pPoolDefs_Impl
= nullptr;
159 // CntStaticPoolDefaults_Impl implementation.
162 inline void CntStaticPoolDefaults_Impl::Insert(
163 SfxPoolItem
* pItem
/* Static Pool Default Item */ )
165 sal_uInt16 nPos
= pItem
->Which() - WID_CHAOS_START
;
167 mvDefaults
[ nPos
] = pItem
;
168 m_pItemInfos
[ nPos
]._nSID
= 0;
169 m_pItemInfos
[ nPos
]._bPoolable
= true;
173 CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
175 for ( sal_uInt32 n
= 0; n
< m_nItems
; ++n
)
176 delete mvDefaults
[ n
];
180 CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl()
181 : mvDefaults( m_nItems
, nullptr ),
182 m_pItemInfos( new SfxItemInfo
[ m_nItems
] )
184 memset( m_pItemInfos
.get(), 0, sizeof( SfxItemInfo
) * m_nItems
);
185 Insert( new SfxStringItem( WID_CHAOS_START
, OUString() ) );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */