1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nochaos.cxx,v $
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 //=========================================================================
50 class CntStaticPoolDefaults_Impl
53 SfxPoolItem
** m_ppDefaults
;
54 SfxItemInfo
* m_pItemInfos
;
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
);
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
;
82 virtual ~CntItemPool();
85 static CntItemPool
* Acquire();
86 static USHORT
Release();
89 //----------------------------------------------------------------------------
91 //----------------------------------------------------------------------------
93 SfxItemPool
* NoChaos::GetItemPool()
95 // Get and hold CHAOS item pool.
96 return CntItemPool::Acquire();
99 //----------------------------------------------------------------------------
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
;
116 CntItemPool
* CntItemPool::_pThePool
= NULL
;
118 //-------------------------------------------------------------------------
119 CntItemPool::CntItemPool()
120 : SfxItemPool( DEFINE_CONST_UNICODE("chaos"), WID_CHAOS_START
, WID_CHAOS_START
, NULL
),
123 SetFileFormatVersion( SOFFICE_FILEFORMAT_50
);
127 // Create static defaults.
128 pPoolDefs_Impl
= new CntStaticPoolDefaults_Impl( this );
131 SetItemInfos( pPoolDefs_Impl
->GetItemInfos() );
133 // Set static pool default items.
134 SetDefaults( pPoolDefs_Impl
->GetDefaults() );
137 //-------------------------------------------------------------------------
139 CntItemPool::~CntItemPool()
141 // Release static pool default items.
142 ReleaseDefaults( sal_False
);
145 //-------------------------------------------------------------------------
147 CntItemPool
* CntItemPool::Acquire()
150 _pThePool
= new CntItemPool
;
157 //-------------------------------------------------------------------------
159 sal_uInt16
CntItemPool::Release()
164 sal_uInt16
& nRefs
= _pThePool
->_nRefs
;
171 DELETEZ( _pThePool
);
172 DELETEZ( pPoolDefs_Impl
);
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*/ )
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
);
215 new SfxStringItem( WID_CHAOS_START
, String() ),