Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / explorer / nochaos.cxx
blobb8b81f8abce3938ab64fe772e78cf311d8fc02dd
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 <sal/config.h>
22 #include <boost/noncopyable.hpp>
23 #include <svl/itempool.hxx>
24 #include <svl/poolitem.hxx>
25 #include <svl/stritem.hxx>
26 #include <nochaos.hxx>
27 #include <sfx2/sfxuno.hxx>
30 #define WID_CHAOS_START 500
32 // class CntStaticPoolDefaults_Impl
35 class CntItemPool;
37 class CntStaticPoolDefaults_Impl: private boost::noncopyable
39 sal_uInt32 m_nItems;
40 SfxPoolItem** m_ppDefaults;
41 SfxItemInfo* m_pItemInfos;
43 private:
44 inline void Insert( SfxPoolItem* pItem, sal_uInt16 nSID, SfxItemPoolFlags nFlags );
46 public:
47 CntStaticPoolDefaults_Impl( CntItemPool* pPool );
48 ~CntStaticPoolDefaults_Impl();
50 SfxPoolItem** GetDefaults() const { return m_ppDefaults; }
51 const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; }
58 class CntItemPool: public SfxItemPool
60 static CntItemPool* _pThePool;
61 sal_uInt16 _nRefs;
63 protected:
64 CntItemPool();
65 virtual ~CntItemPool();
67 public:
68 static CntItemPool* Acquire();
69 static sal_uInt16 Release();
75 // static
76 SfxItemPool* NoChaos::GetItemPool()
78 // Get and hold CHAOS item pool.
79 return CntItemPool::Acquire();
83 // static
84 sal_uInt16 NoChaos::ReleaseItemPool()
86 // Release CHAOS item pool.
87 return CntItemPool::Release();
91 // CntItemPool implementation
94 static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = NULL;
96 // static member!
97 CntItemPool* CntItemPool::_pThePool = NULL;
100 CntItemPool::CntItemPool()
101 : SfxItemPool( "chaos", WID_CHAOS_START, WID_CHAOS_START, NULL ),
102 _nRefs( 0 )
104 SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );
106 FreezeIdRanges();
108 // Create static defaults.
109 pPoolDefs_Impl = new CntStaticPoolDefaults_Impl( this );
111 // Set item infos.
112 SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
114 // Set static pool default items.
115 SetDefaults( pPoolDefs_Impl->GetDefaults() );
119 //virtual
120 CntItemPool::~CntItemPool()
122 // Release static pool default items.
123 ReleaseDefaults( false );
127 // static
128 CntItemPool* CntItemPool::Acquire()
130 if ( !_pThePool )
131 _pThePool = new CntItemPool;
133 _pThePool->_nRefs++;
135 return _pThePool;
139 // static
140 sal_uInt16 CntItemPool::Release()
142 if ( !_pThePool )
143 return 0;
145 sal_uInt16& nRefs = _pThePool->_nRefs;
147 if ( nRefs )
148 --nRefs;
150 if ( !nRefs )
152 DELETEZ( _pThePool );
153 DELETEZ( pPoolDefs_Impl );
154 return 0;
157 return nRefs;
161 // CntStaticPoolDefaults_Impl implementation.
164 inline void CntStaticPoolDefaults_Impl::Insert(
165 SfxPoolItem* pItem, /* Static Pool Default Item */
166 sal_uInt16 nSID, SfxItemPoolFlags nFlags /* Item Info */ )
168 sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
170 m_ppDefaults[ nPos ] = pItem;
171 m_pItemInfos[ nPos ]._nSID = nSID;
172 m_pItemInfos[ nPos ]._nFlags = nFlags;
176 CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
178 for ( sal_uInt32 n = 0; n < m_nItems; ++n )
179 delete m_ppDefaults[ n ];
181 delete [] m_ppDefaults;
182 delete [] m_pItemInfos;
186 CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl( CntItemPool* /*pPool*/ )
187 : m_nItems( 1 ),
188 m_ppDefaults( new SfxPoolItem* [ m_nItems ] ),
189 m_pItemInfos( new SfxItemInfo [ m_nItems ] )
191 memset( m_ppDefaults, 0, sizeof( SfxPoolItem* ) * m_nItems );
192 memset( m_pItemInfos, 0, sizeof( SfxItemInfo ) * m_nItems );
193 Insert(
194 new SfxStringItem( WID_CHAOS_START, OUString() ),
196 SfxItemPoolFlags::POOLABLE );
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */