Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / explorer / nochaos.cxx
blob82de6fc93941995c2f3801f1559f07c560d5cba6
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 .
21 #include <svl/itempool.hxx>
22 #include <svl/poolitem.hxx>
23 #include <svl/stritem.hxx>
24 #include <nochaos.hxx>
25 #include <sfx2/sfxuno.hxx>
28 #define WID_CHAOS_START 500
29 //=========================================================================
30 // class CntStaticPoolDefaults_Impl
31 //=========================================================================
33 class CntItemPool;
35 class CntStaticPoolDefaults_Impl
37 sal_uInt32 m_nItems;
38 SfxPoolItem** m_ppDefaults;
39 SfxItemInfo* m_pItemInfos;
41 private:
42 // Forbidden and not implemented...
43 CntStaticPoolDefaults_Impl( const CntStaticPoolDefaults_Impl& );
44 CntStaticPoolDefaults_Impl& operator=( const CntStaticPoolDefaults_Impl& );
46 inline void Insert( SfxPoolItem* pItem, sal_uInt16 nSID, sal_uInt16 nFlags );
48 public:
49 CntStaticPoolDefaults_Impl( CntItemPool* pPool );
50 ~CntStaticPoolDefaults_Impl();
52 SfxPoolItem** GetDefaults() const { return m_ppDefaults; }
53 const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; }
56 //----------------------------------------------------------------------------
58 //=========================================================================
60 class CntItemPool: public SfxItemPool
62 static CntItemPool* _pThePool;
63 sal_uInt16 _nRefs;
65 protected:
66 CntItemPool();
67 virtual ~CntItemPool();
69 public:
70 static CntItemPool* Acquire();
71 static sal_uInt16 Release();
74 //----------------------------------------------------------------------------
76 //----------------------------------------------------------------------------
77 // static
78 SfxItemPool* NoChaos::GetItemPool()
80 // Get and hold CHAOS item pool.
81 return CntItemPool::Acquire();
84 //----------------------------------------------------------------------------
85 // static
86 sal_uInt16 NoChaos::ReleaseItemPool()
88 // Release CHAOS item pool.
89 return CntItemPool::Release();
92 //=========================================================================
93 // CntItemPool implementation
94 //=========================================================================
96 static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = NULL;
98 // static member!
99 CntItemPool* CntItemPool::_pThePool = NULL;
101 //-------------------------------------------------------------------------
102 CntItemPool::CntItemPool()
103 : SfxItemPool( "chaos", WID_CHAOS_START, WID_CHAOS_START, NULL ),
104 _nRefs( 0 )
106 SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );
108 FreezeIdRanges();
110 // Create static defaults.
111 pPoolDefs_Impl = new CntStaticPoolDefaults_Impl( this );
113 // Set item infos.
114 SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
116 // Set static pool default items.
117 SetDefaults( pPoolDefs_Impl->GetDefaults() );
120 //-------------------------------------------------------------------------
121 //virtual
122 CntItemPool::~CntItemPool()
124 // Release static pool default items.
125 ReleaseDefaults( sal_False );
128 //-------------------------------------------------------------------------
129 // static
130 CntItemPool* CntItemPool::Acquire()
132 if ( !_pThePool )
133 _pThePool = new CntItemPool;
135 _pThePool->_nRefs++;
137 return _pThePool;
140 //-------------------------------------------------------------------------
141 // static
142 sal_uInt16 CntItemPool::Release()
144 if ( !_pThePool )
145 return 0;
147 sal_uInt16& nRefs = _pThePool->_nRefs;
149 if ( nRefs )
150 --nRefs;
152 if ( !nRefs )
154 DELETEZ( _pThePool );
155 DELETEZ( pPoolDefs_Impl );
156 return 0;
159 return nRefs;
162 //=========================================================================
163 // CntStaticPoolDefaults_Impl implementation.
164 //=========================================================================
166 inline void CntStaticPoolDefaults_Impl::Insert(
167 SfxPoolItem* pItem, /* Static Pool Default Item */
168 sal_uInt16 nSID, sal_uInt16 nFlags /* Item Info */ )
170 sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
172 m_ppDefaults[ nPos ] = pItem;
173 m_pItemInfos[ nPos ]._nSID = nSID;
174 m_pItemInfos[ nPos ]._nFlags = nFlags;
177 //-------------------------------------------------------------------------
178 CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
180 for ( sal_uInt32 n = 0; n < m_nItems; ++n )
181 delete m_ppDefaults[ n ];
183 delete [] m_ppDefaults;
184 delete [] m_pItemInfos;
187 //-------------------------------------------------------------------------
188 CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl( CntItemPool* /*pPool*/ )
189 : m_nItems( 1 ),
190 m_ppDefaults( new SfxPoolItem* [ m_nItems ] ),
191 m_pItemInfos( new SfxItemInfo [ m_nItems ] )
193 memset( m_ppDefaults, 0, sizeof( SfxPoolItem* ) * m_nItems );
194 memset( m_pItemInfos, 0, sizeof( SfxItemInfo ) * m_nItems );
195 Insert(
196 new SfxStringItem( WID_CHAOS_START, String() ),
198 SFX_ITEM_POOLABLE );
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */