merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / itemholder2.cxx
blob6e0d1876d066099db4603e4dfb0a1ba075918649
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itemholder2.cxx,v $
10 * $Revision: 1.13 $
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_svtools.hxx"
34 #ifdef SVL_DLLIMPLEMENTATION
35 #undef SVL_DLLIMPLEMENTATION
36 #endif
37 #define SVT_DLLIMPLEMENTATION
39 #include "itemholder2.hxx"
41 //-----------------------------------------------
42 // includes
43 #include <comphelper/processfactory.hxx>
44 #include <com/sun/star/lang/XComponent.hpp>
46 #include <svtools/accessibilityoptions.hxx>
47 #include <apearcfg.hxx>
48 #include <svtools/cjkoptions.hxx>
49 #include <svtools/colorcfg.hxx>
50 #include <svtools/ctloptions.hxx>
51 #include <fontsubstconfig.hxx>
52 #include <svtools/helpopt.hxx>
53 #include <svtools/languageoptions.hxx>
54 #include <misccfg.hxx>
55 #include <svtools/printoptions.hxx>
56 #include <svtools/syslocaleoptions.hxx>
57 #include <svtools/undoopt.hxx>
58 #include <svtools/useroptions.hxx>
59 #include <svtools/options.hxx>
60 #include <svtools/miscopt.hxx>
63 #include <tools/debug.hxx>
65 //-----------------------------------------------
66 // namespaces
68 namespace css = ::com::sun::star;
70 //-----------------------------------------------
71 // declarations
73 //-----------------------------------------------
74 ItemHolder2::ItemHolder2()
75 : ItemHolderMutexBase()
77 try
79 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
80 css::uno::Reference< css::lang::XComponent > xCfg(
81 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")),
82 css::uno::UNO_QUERY);
83 if (xCfg.is())
84 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
86 // #i37892 got errorhandling from ConfigManager::GetConfigurationProvider()
87 catch(css::uno::RuntimeException& rREx)
89 throw rREx;
91 #ifdef DBG_UTIL
92 catch(css::uno::Exception& rEx)
94 static sal_Bool bMessage = sal_True;
95 if(bMessage)
97 bMessage = sal_False;
98 ::rtl::OString sMsg("CreateInstance with arguments exception: ");
99 sMsg += ::rtl::OString(rEx.Message.getStr(),
100 rEx.Message.getLength(),
101 RTL_TEXTENCODING_ASCII_US);
102 DBG_ERROR(sMsg.getStr());
105 #else
106 catch(css::uno::Exception&){}
107 #endif
110 //-----------------------------------------------
111 ItemHolder2::~ItemHolder2()
113 impl_releaseAllItems();
116 //-----------------------------------------------
117 void ItemHolder2::holdConfigItem(EItem eItem)
119 static ItemHolder2* pHolder = new ItemHolder2();
120 pHolder->impl_addItem(eItem);
123 //-----------------------------------------------
124 void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
125 throw(css::uno::RuntimeException)
127 impl_releaseAllItems();
130 //-----------------------------------------------
131 void ItemHolder2::impl_addItem(EItem eItem)
133 ::osl::ResettableMutexGuard aLock(m_aLock);
135 TItems::const_iterator pIt;
136 for ( pIt = m_lItems.begin();
137 pIt != m_lItems.end() ;
138 ++pIt )
140 const TItemInfo& rInfo = *pIt;
141 if (rInfo.eItem == eItem)
142 return;
145 TItemInfo aNewItem;
146 aNewItem.eItem = eItem;
147 impl_newItem(aNewItem);
148 if (aNewItem.pItem)
149 m_lItems.push_back(aNewItem);
152 //-----------------------------------------------
153 void ItemHolder2::impl_releaseAllItems()
155 ::osl::ResettableMutexGuard aLock(m_aLock);
157 TItems::iterator pIt;
158 for ( pIt = m_lItems.begin();
159 pIt != m_lItems.end() ;
160 ++pIt )
162 TItemInfo& rInfo = *pIt;
163 impl_deleteItem(rInfo);
165 m_lItems.clear();
168 //-----------------------------------------------
169 void ItemHolder2::impl_newItem(TItemInfo& rItem)
171 switch(rItem.eItem)
173 case E_ACCESSIBILITYOPTIONS :
174 rItem.pItem = new SvtAccessibilityOptions();
175 break;
177 case E_APEARCFG :
178 // no ref count rItem.pItem = new SvtTabAppearanceCfg();
179 break;
181 case E_CJKOPTIONS :
182 rItem.pItem = new SvtCJKOptions();
183 break;
185 case E_COLORCFG :
186 rItem.pItem = new ::svtools::ColorConfig();
187 break;
189 case E_CTLOPTIONS :
190 rItem.pItem = new SvtCTLOptions();
191 break;
193 case E_FONTSUBSTCONFIG :
194 // no ref count rItem.pItem = new SvtFontSubstConfig();
195 break;
197 case E_HELPOPTIONS :
198 rItem.pItem = new SvtHelpOptions();
199 break;
201 case E_LANGUAGEOPTIONS :
202 // capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions();
203 break;
205 case E_MISCCFG :
206 // no ref count rItem.pItem = new SfxMiscCfg();
207 break;
209 case E_PRINTOPTIONS :
210 rItem.pItem = new SvtPrinterOptions();
211 break;
213 case E_PRINTFILEOPTIONS :
214 rItem.pItem = new SvtPrintFileOptions();
215 break;
217 case E_SYSLOCALEOPTIONS :
218 rItem.pItem = new SvtSysLocaleOptions();
219 break;
221 case E_UNDOOPTIONS :
222 rItem.pItem = new SvtUndoOptions();
223 break;
225 case E_USEROPTIONS :
226 rItem.pItem = new SvtUserOptions();
227 break;
228 case E_MISCOPTIONS :
229 rItem.pItem = new SvtMiscOptions();
230 break;
232 default:
233 OSL_ASSERT(false);
234 break;
238 //-----------------------------------------------
239 void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
241 if (rItem.pItem)
243 delete rItem.pItem;
244 rItem.pItem = 0;