xref: /aoo42x/main/sfx2/source/explorer/nochaos.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svl/itempool.hxx>
28cdf0e10cSrcweir #include <svl/poolitem.hxx>
29cdf0e10cSrcweir #include <svl/stritem.hxx>
30cdf0e10cSrcweir #include <nochaos.hxx>
31cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #define WID_CHAOS_START 500
35cdf0e10cSrcweir //=========================================================================
36cdf0e10cSrcweir //
37cdf0e10cSrcweir // class CntStaticPoolDefaults_Impl
38cdf0e10cSrcweir //
39cdf0e10cSrcweir //=========================================================================
40cdf0e10cSrcweir 
41cdf0e10cSrcweir class CntItemPool;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir class CntStaticPoolDefaults_Impl
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	sal_uInt32		  m_nItems;
46cdf0e10cSrcweir 	SfxPoolItem** m_ppDefaults;
47cdf0e10cSrcweir 	SfxItemInfo*  m_pItemInfos;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir private:
50cdf0e10cSrcweir 	// Forbidden and not implemented...
51cdf0e10cSrcweir 	CntStaticPoolDefaults_Impl( const CntStaticPoolDefaults_Impl& );
52cdf0e10cSrcweir     CntStaticPoolDefaults_Impl&	operator=( const CntStaticPoolDefaults_Impl& );
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	inline void Insert( SfxPoolItem* pItem, sal_uInt16 nSID, sal_uInt16 nFlags );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir public:
57cdf0e10cSrcweir 	CntStaticPoolDefaults_Impl( CntItemPool* pPool );
58cdf0e10cSrcweir 	~CntStaticPoolDefaults_Impl();
59cdf0e10cSrcweir 
GetDefaults() const60cdf0e10cSrcweir 	SfxPoolItem** 	   GetDefaults() const  { return m_ppDefaults; }
GetItemInfos() const61cdf0e10cSrcweir 	const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; }
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //----------------------------------------------------------------------------
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //=========================================================================
67cdf0e10cSrcweir 
68cdf0e10cSrcweir class CntItemPool: public SfxItemPool
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	static CntItemPool* _pThePool;
71cdf0e10cSrcweir 	sal_uInt16              _nRefs;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir protected:
74cdf0e10cSrcweir 			 CntItemPool();
75cdf0e10cSrcweir 	virtual ~CntItemPool();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir public:
78cdf0e10cSrcweir 	static CntItemPool* Acquire();
79cdf0e10cSrcweir 	static sal_uInt16 		Release();
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //----------------------------------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //----------------------------------------------------------------------------
85cdf0e10cSrcweir // static
GetItemPool()86cdf0e10cSrcweir SfxItemPool* NoChaos::GetItemPool()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	// Get and hold CHAOS item pool.
89cdf0e10cSrcweir 	return CntItemPool::Acquire();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //----------------------------------------------------------------------------
93cdf0e10cSrcweir // static
ReleaseItemPool()94cdf0e10cSrcweir sal_uInt16 NoChaos::ReleaseItemPool()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	// Release CHAOS item pool.
97cdf0e10cSrcweir 	return CntItemPool::Release();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //=========================================================================
101cdf0e10cSrcweir //
102cdf0e10cSrcweir //	CntItemPool implementation
103cdf0e10cSrcweir //
104cdf0e10cSrcweir //=========================================================================
105cdf0e10cSrcweir 
106cdf0e10cSrcweir static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = NULL;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // static member!
109cdf0e10cSrcweir CntItemPool* CntItemPool::_pThePool = NULL;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //-------------------------------------------------------------------------
CntItemPool()112cdf0e10cSrcweir CntItemPool::CntItemPool()
113cdf0e10cSrcweir : SfxItemPool( DEFINE_CONST_UNICODE("chaos"), WID_CHAOS_START, WID_CHAOS_START, NULL ),
114cdf0e10cSrcweir   _nRefs( 0 )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	FreezeIdRanges();
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	// Create static defaults.
121cdf0e10cSrcweir 	pPoolDefs_Impl = new CntStaticPoolDefaults_Impl( this );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	// Set item infos.
124cdf0e10cSrcweir 	SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	// Set static pool default items.
127cdf0e10cSrcweir 	SetDefaults( pPoolDefs_Impl->GetDefaults() );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //-------------------------------------------------------------------------
131cdf0e10cSrcweir //virtual
~CntItemPool()132cdf0e10cSrcweir CntItemPool::~CntItemPool()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	// Release static pool default items.
135cdf0e10cSrcweir 	ReleaseDefaults( sal_False );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //-------------------------------------------------------------------------
139cdf0e10cSrcweir // static
Acquire()140cdf0e10cSrcweir CntItemPool* CntItemPool::Acquire()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	if ( !_pThePool )
143cdf0e10cSrcweir 		_pThePool = new CntItemPool;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	_pThePool->_nRefs++;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	return _pThePool;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir //-------------------------------------------------------------------------
151cdf0e10cSrcweir // static
Release()152cdf0e10cSrcweir sal_uInt16 CntItemPool::Release()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	if ( !_pThePool )
155cdf0e10cSrcweir 		return 0;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	sal_uInt16& nRefs = _pThePool->_nRefs;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	if ( nRefs )
160cdf0e10cSrcweir 		--nRefs;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if ( !nRefs )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		DELETEZ( _pThePool );
165cdf0e10cSrcweir 		DELETEZ( pPoolDefs_Impl );
166cdf0e10cSrcweir 		return 0;
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	return nRefs;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir //=========================================================================
173cdf0e10cSrcweir //
174cdf0e10cSrcweir // CntStaticPoolDefaults_Impl implementation.
175cdf0e10cSrcweir //
176cdf0e10cSrcweir //=========================================================================
177cdf0e10cSrcweir 
Insert(SfxPoolItem * pItem,sal_uInt16 nSID,sal_uInt16 nFlags)178cdf0e10cSrcweir inline void CntStaticPoolDefaults_Impl::Insert(
179cdf0e10cSrcweir 	 	SfxPoolItem* pItem, 		/* Static Pool Default Item */
180cdf0e10cSrcweir      	sal_uInt16 nSID, sal_uInt16 nFlags  /* Item Info */	)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	m_ppDefaults[ nPos ]         = pItem;
185cdf0e10cSrcweir 	m_pItemInfos[ nPos ]._nSID   = nSID;
186cdf0e10cSrcweir 	m_pItemInfos[ nPos ]._nFlags = nFlags;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //-------------------------------------------------------------------------
~CntStaticPoolDefaults_Impl()190cdf0e10cSrcweir CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	for ( sal_uInt32 n = 0; n < m_nItems; ++n )
193cdf0e10cSrcweir 		delete m_ppDefaults[ n ];
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	delete [] m_ppDefaults;
196cdf0e10cSrcweir 	delete [] m_pItemInfos;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //-------------------------------------------------------------------------
CntStaticPoolDefaults_Impl(CntItemPool *)200cdf0e10cSrcweir CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl( CntItemPool* /*pPool*/ )
201cdf0e10cSrcweir : m_nItems( 1 ),
202cdf0e10cSrcweir   m_ppDefaults( new SfxPoolItem* [ m_nItems ] ),
203cdf0e10cSrcweir   m_pItemInfos( new SfxItemInfo  [ m_nItems ] )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     rtl_zeroMemory( m_ppDefaults, sizeof( SfxPoolItem* ) * m_nItems );
206cdf0e10cSrcweir     rtl_zeroMemory( m_pItemInfos, sizeof( SfxItemInfo ) * m_nItems );
207cdf0e10cSrcweir 	Insert(
208cdf0e10cSrcweir 		new	SfxStringItem( WID_CHAOS_START, String() ),
209cdf0e10cSrcweir 		0,
210cdf0e10cSrcweir 		SFX_ITEM_POOLABLE );
211cdf0e10cSrcweir }
212