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 .
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 //=========================================================================
35 class CntStaticPoolDefaults_Impl
38 SfxPoolItem
** m_ppDefaults
;
39 SfxItemInfo
* m_pItemInfos
;
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
);
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
;
67 virtual ~CntItemPool();
70 static CntItemPool
* Acquire();
71 static sal_uInt16
Release();
74 //----------------------------------------------------------------------------
76 //----------------------------------------------------------------------------
78 SfxItemPool
* NoChaos::GetItemPool()
80 // Get and hold CHAOS item pool.
81 return CntItemPool::Acquire();
84 //----------------------------------------------------------------------------
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
;
99 CntItemPool
* CntItemPool::_pThePool
= NULL
;
101 //-------------------------------------------------------------------------
102 CntItemPool::CntItemPool()
103 : SfxItemPool( "chaos", WID_CHAOS_START
, WID_CHAOS_START
, NULL
),
106 SetFileFormatVersion( SOFFICE_FILEFORMAT_50
);
110 // Create static defaults.
111 pPoolDefs_Impl
= new CntStaticPoolDefaults_Impl( this );
114 SetItemInfos( pPoolDefs_Impl
->GetItemInfos() );
116 // Set static pool default items.
117 SetDefaults( pPoolDefs_Impl
->GetDefaults() );
120 //-------------------------------------------------------------------------
122 CntItemPool::~CntItemPool()
124 // Release static pool default items.
125 ReleaseDefaults( sal_False
);
128 //-------------------------------------------------------------------------
130 CntItemPool
* CntItemPool::Acquire()
133 _pThePool
= new CntItemPool
;
140 //-------------------------------------------------------------------------
142 sal_uInt16
CntItemPool::Release()
147 sal_uInt16
& nRefs
= _pThePool
->_nRefs
;
154 DELETEZ( _pThePool
);
155 DELETEZ( pPoolDefs_Impl
);
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*/ )
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
);
196 new SfxStringItem( WID_CHAOS_START
, String() ),
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */