1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
37 class CntStaticPoolDefaults_Impl
: private boost::noncopyable
40 SfxPoolItem
** m_ppDefaults
;
41 SfxItemInfo
* m_pItemInfos
;
44 inline void Insert( SfxPoolItem
* pItem
, sal_uInt16 nSID
, SfxItemPoolFlags nFlags
);
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
;
65 virtual ~CntItemPool();
68 static CntItemPool
* Acquire();
69 static sal_uInt16
Release();
76 SfxItemPool
* NoChaos::GetItemPool()
78 // Get and hold CHAOS item pool.
79 return CntItemPool::Acquire();
84 sal_uInt16
NoChaos::ReleaseItemPool()
86 // Release CHAOS item pool.
87 return CntItemPool::Release();
91 // CntItemPool implementation
94 static CntStaticPoolDefaults_Impl
* pPoolDefs_Impl
= NULL
;
97 CntItemPool
* CntItemPool::_pThePool
= NULL
;
100 CntItemPool::CntItemPool()
101 : SfxItemPool( "chaos", WID_CHAOS_START
, WID_CHAOS_START
, NULL
),
104 SetFileFormatVersion( SOFFICE_FILEFORMAT_50
);
108 // Create static defaults.
109 pPoolDefs_Impl
= new CntStaticPoolDefaults_Impl( this );
112 SetItemInfos( pPoolDefs_Impl
->GetItemInfos() );
114 // Set static pool default items.
115 SetDefaults( pPoolDefs_Impl
->GetDefaults() );
120 CntItemPool::~CntItemPool()
122 // Release static pool default items.
123 ReleaseDefaults( false );
128 CntItemPool
* CntItemPool::Acquire()
131 _pThePool
= new CntItemPool
;
140 sal_uInt16
CntItemPool::Release()
145 sal_uInt16
& nRefs
= _pThePool
->_nRefs
;
152 DELETEZ( _pThePool
);
153 DELETEZ( pPoolDefs_Impl
);
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*/ )
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
);
194 new SfxStringItem( WID_CHAOS_START
, OUString() ),
196 SfxItemPoolFlags::POOLABLE
);
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */