Update ooo320-m1
[ooovba.git] / sfx2 / source / explorer / nochaos.cxx
bloba5f69a2e9cd6e5797781dee3990b36701be4c21e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nochaos.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include <svtools/itempool.hxx>
35 #include <svtools/poolitem.hxx>
36 #include <svtools/stritem.hxx>
37 #include <nochaos.hxx>
38 #include <sfx2/sfxuno.hxx>
41 #define WID_CHAOS_START 500
42 //=========================================================================
44 // class CntStaticPoolDefaults_Impl
46 //=========================================================================
48 class CntItemPool;
50 class CntStaticPoolDefaults_Impl
52 sal_uInt32 m_nItems;
53 SfxPoolItem** m_ppDefaults;
54 SfxItemInfo* m_pItemInfos;
56 private:
57 // Forbidden and not implemented...
58 CntStaticPoolDefaults_Impl( const CntStaticPoolDefaults_Impl& );
59 CntStaticPoolDefaults_Impl& operator=( const CntStaticPoolDefaults_Impl& );
61 inline void Insert( SfxPoolItem* pItem, sal_uInt16 nSID, sal_uInt16 nFlags );
63 public:
64 CntStaticPoolDefaults_Impl( CntItemPool* pPool );
65 ~CntStaticPoolDefaults_Impl();
67 SfxPoolItem** GetDefaults() const { return m_ppDefaults; }
68 const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; }
71 //----------------------------------------------------------------------------
73 //=========================================================================
75 class CntItemPool: public SfxItemPool
77 static CntItemPool* _pThePool;
78 USHORT _nRefs;
80 protected:
81 CntItemPool();
82 virtual ~CntItemPool();
84 public:
85 static CntItemPool* Acquire();
86 static USHORT Release();
89 //----------------------------------------------------------------------------
91 //----------------------------------------------------------------------------
92 // static
93 SfxItemPool* NoChaos::GetItemPool()
95 // Get and hold CHAOS item pool.
96 return CntItemPool::Acquire();
99 //----------------------------------------------------------------------------
100 // static
101 USHORT NoChaos::ReleaseItemPool()
103 // Release CHAOS item pool.
104 return CntItemPool::Release();
107 //=========================================================================
109 // CntItemPool implementation
111 //=========================================================================
113 static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = NULL;
115 // static member!
116 CntItemPool* CntItemPool::_pThePool = NULL;
118 //-------------------------------------------------------------------------
119 CntItemPool::CntItemPool()
120 : SfxItemPool( DEFINE_CONST_UNICODE("chaos"), WID_CHAOS_START, WID_CHAOS_START, NULL ),
121 _nRefs( 0 )
123 SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );
125 FreezeIdRanges();
127 // Create static defaults.
128 pPoolDefs_Impl = new CntStaticPoolDefaults_Impl( this );
130 // Set item infos.
131 SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
133 // Set static pool default items.
134 SetDefaults( pPoolDefs_Impl->GetDefaults() );
137 //-------------------------------------------------------------------------
138 //virtual
139 CntItemPool::~CntItemPool()
141 // Release static pool default items.
142 ReleaseDefaults( sal_False );
145 //-------------------------------------------------------------------------
146 // static
147 CntItemPool* CntItemPool::Acquire()
149 if ( !_pThePool )
150 _pThePool = new CntItemPool;
152 _pThePool->_nRefs++;
154 return _pThePool;
157 //-------------------------------------------------------------------------
158 // static
159 sal_uInt16 CntItemPool::Release()
161 if ( !_pThePool )
162 return 0;
164 sal_uInt16& nRefs = _pThePool->_nRefs;
166 if ( nRefs )
167 --nRefs;
169 if ( !nRefs )
171 DELETEZ( _pThePool );
172 DELETEZ( pPoolDefs_Impl );
173 return 0;
176 return nRefs;
179 //=========================================================================
181 // CntStaticPoolDefaults_Impl implementation.
183 //=========================================================================
185 inline void CntStaticPoolDefaults_Impl::Insert(
186 SfxPoolItem* pItem, /* Static Pool Default Item */
187 sal_uInt16 nSID, sal_uInt16 nFlags /* Item Info */ )
189 sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
191 m_ppDefaults[ nPos ] = pItem;
192 m_pItemInfos[ nPos ]._nSID = nSID;
193 m_pItemInfos[ nPos ]._nFlags = nFlags;
196 //-------------------------------------------------------------------------
197 CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
199 for ( sal_uInt32 n = 0; n < m_nItems; ++n )
200 delete m_ppDefaults[ n ];
202 delete [] m_ppDefaults;
203 delete [] m_pItemInfos;
206 //-------------------------------------------------------------------------
207 CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl( CntItemPool* /*pPool*/ )
208 : m_nItems( 1 ),
209 m_ppDefaults( new SfxPoolItem* [ m_nItems ] ),
210 m_pItemInfos( new SfxItemInfo [ m_nItems ] )
212 rtl_zeroMemory( m_ppDefaults, sizeof( SfxPoolItem* ) * m_nItems );
213 rtl_zeroMemory( m_pItemInfos, sizeof( SfxItemInfo ) * m_nItems );
214 Insert(
215 new SfxStringItem( WID_CHAOS_START, String() ),
217 SFX_ITEM_POOLABLE );