merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / itemholder1.cxx
blob9a941e32b7407251062375070fa71b59a97b1aff
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: itemholder1.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 #include "itemholder1.hxx"
36 //-----------------------------------------------
37 // includes
38 #include <comphelper/processfactory.hxx>
39 #include <com/sun/star/lang/XComponent.hpp>
41 #include <svtools/accelcfg.hxx>
42 #include <svtools/addxmltostorageoptions.hxx>
43 #include <cacheoptions.hxx>
44 #include <svtools/cmdoptions.hxx>
45 #include <svtools/compatibility.hxx>
46 #include <svtools/defaultoptions.hxx>
47 #include <svtools/dynamicmenuoptions.hxx>
48 #include <eventcfg.hxx>
49 #include <svtools/extendedsecurityoptions.hxx>
50 #include <fltrcfg.hxx>
51 #include <svtools/fontoptions.hxx>
52 #include <svtools/historyoptions.hxx>
53 #include <svtools/inetoptions.hxx>
54 #include <svtools/internaloptions.hxx>
55 #include <javaoptions.hxx>
56 #include <svtools/lingucfg.hxx>
57 #include <svtools/localisationoptions.hxx>
58 #include <svtools/menuoptions.hxx>
59 #include <svtools/moduleoptions.hxx>
60 #include <svtools/pathoptions.hxx>
61 #include <svtools/printwarningoptions.hxx>
62 #include <regoptions.hxx>
63 #include <svtools/optionsdlg.hxx>
64 #include <svtools/saveopt.hxx>
65 #include <searchopt.hxx>
66 #include <svtools/securityoptions.hxx>
67 #include <svtools/sourceviewconfig.hxx>
68 #include <svtools/startoptions.hxx>
69 #include <svtools/viewoptions.hxx>
70 #include <svtools/workingsetoptions.hxx>
71 #include <xmlaccelcfg.hxx>
72 #include <svtools/options.hxx>
74 //-----------------------------------------------
75 // namespaces
77 namespace css = ::com::sun::star;
79 //-----------------------------------------------
80 // declarations
82 //-----------------------------------------------
83 ItemHolder1::ItemHolder1()
84 : ItemHolderMutexBase()
86 try
88 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
89 css::uno::Reference< css::lang::XComponent > xCfg(
90 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")),
91 css::uno::UNO_QUERY);
92 if (xCfg.is())
93 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
95 // #i37892 got errorhandling from ConfigManager::GetConfigurationProvider()
96 #ifdef DBG_UTIL
97 catch(css::uno::Exception& rEx)
99 static sal_Bool bMessage = sal_True;
100 if(bMessage)
102 bMessage = sal_False;
103 ::rtl::OString sMsg("CreateInstance with arguments exception: ");
104 sMsg += ::rtl::OString(rEx.Message.getStr(),
105 rEx.Message.getLength(),
106 RTL_TEXTENCODING_ASCII_US);
107 OSL_ENSURE(sal_False, sMsg.getStr());
110 #else
111 catch(css::uno::Exception&){}
112 #endif
115 //-----------------------------------------------
116 ItemHolder1::~ItemHolder1()
118 impl_releaseAllItems();
121 //-----------------------------------------------
122 void ItemHolder1::holdConfigItem(EItem eItem)
124 static ItemHolder1* pHolder = new ItemHolder1();
125 pHolder->impl_addItem(eItem);
128 //-----------------------------------------------
129 void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
130 throw(css::uno::RuntimeException)
132 css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
133 impl_releaseAllItems();
136 //-----------------------------------------------
137 void ItemHolder1::impl_addItem(EItem eItem)
139 ::osl::ResettableMutexGuard aLock(m_aLock);
141 TItems::const_iterator pIt;
142 for ( pIt = m_lItems.begin();
143 pIt != m_lItems.end() ;
144 ++pIt )
146 const TItemInfo& rInfo = *pIt;
147 if (rInfo.eItem == eItem)
148 return;
151 TItemInfo aNewItem;
152 aNewItem.eItem = eItem;
153 impl_newItem(aNewItem);
154 if (aNewItem.pItem)
155 m_lItems.push_back(aNewItem);
158 //-----------------------------------------------
159 void ItemHolder1::impl_releaseAllItems()
161 ::osl::ResettableMutexGuard aLock(m_aLock);
163 TItems::iterator pIt;
164 for ( pIt = m_lItems.begin();
165 pIt != m_lItems.end() ;
166 ++pIt )
168 TItemInfo& rInfo = *pIt;
169 impl_deleteItem(rInfo);
171 m_lItems.clear();
174 //-----------------------------------------------
175 void ItemHolder1::impl_newItem(TItemInfo& rItem)
177 switch(rItem.eItem)
179 case E_ACCELCFG :
180 rItem.pItem = new SvtAcceleratorConfiguration();
181 break;
183 case E_ADDXMLTOSTORAGEOPTIONS :
184 rItem.pItem = new SvtAddXMLToStorageOptions();
185 break;
187 case E_CMDOPTIONS :
188 rItem.pItem = new SvtCommandOptions();
189 break;
191 case E_COMPATIBILITY :
192 rItem.pItem = new SvtCompatibilityOptions();
193 break;
195 case E_DEFAULTOPTIONS :
196 rItem.pItem = new SvtDefaultOptions();
197 break;
199 case E_DYNAMICMENUOPTIONS :
200 rItem.pItem = new SvtDynamicMenuOptions();
201 break;
203 case E_EVENTCFG :
204 //rItem.pItem = new GlobalEventConfig();
205 break;
207 case E_EXTENDEDSECURITYOPTIONS :
208 rItem.pItem = new SvtExtendedSecurityOptions();
209 break;
211 case E_FLTRCFG :
212 // no ref count rItem.pItem = new SvtFilterOptions();
213 break;
215 case E_FONTOPTIONS :
216 rItem.pItem = new SvtFontOptions();
217 break;
219 case E_HISTORYOPTIONS :
220 rItem.pItem = new SvtHistoryOptions();
221 break;
223 case E_INETOPTIONS :
224 rItem.pItem = new SvtInetOptions();
225 break;
227 case E_INTERNALOPTIONS :
228 rItem.pItem = new SvtInternalOptions();
229 break;
231 case E_JAVAOPTIONS :
232 // no ref count rItem.pItem = new SvtJavaOptions();
233 break;
235 case E_LINGUCFG :
236 rItem.pItem = new SvtLinguConfig();
237 break;
239 case E_LOCALISATIONOPTIONS :
240 rItem.pItem = new SvtLocalisationOptions();
241 break;
243 case E_MENUOPTIONS :
244 rItem.pItem = new SvtMenuOptions();
245 break;
247 case E_MODULEOPTIONS :
248 rItem.pItem = new SvtModuleOptions();
249 break;
251 case E_OPTIONSDLGOPTIONS :
252 rItem.pItem = new SvtOptionsDialogOptions();
253 break;
255 case E_PATHOPTIONS :
256 rItem.pItem = new SvtPathOptions();
257 break;
259 case E_PRINTWARNINGOPTIONS :
260 rItem.pItem = new SvtPrintWarningOptions();
261 break;
263 case E_REGOPTIONS :
264 // no ref count rItem.pItem = new ::svt::RegOptions();
265 break;
267 case E_SAVEOPTIONS :
268 rItem.pItem = new SvtSaveOptions();
269 break;
271 case E_SEARCHOPT :
272 // no ref count rItem.pItem = new SvtSearchOptions();
273 break;
275 case E_SECURITYOPTIONS :
276 rItem.pItem = new SvtSecurityOptions();
277 break;
279 case E_SOURCEVIEWCONFIG :
280 rItem.pItem = new ::svt::SourceViewConfig();
281 break;
283 case E_STARTOPTIONS :
284 rItem.pItem = new SvtStartOptions();
285 break;
287 case E_VIEWOPTIONS_DIALOG :
288 rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString());
289 break;
291 case E_VIEWOPTIONS_TABDIALOG :
292 rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString());
293 break;
295 case E_VIEWOPTIONS_TABPAGE :
296 rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString());
297 break;
299 case E_VIEWOPTIONS_WINDOW :
300 rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString());
301 break;
303 case E_WORKINGSETOPTIONS :
304 rItem.pItem = new SvtWorkingSetOptions();
305 break;
307 case E_XMLACCELCFG :
308 // ??? TODO
309 break;
310 default:
311 OSL_ASSERT( "unknown item type" );
312 break;
316 //-----------------------------------------------
317 void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
319 if (rItem.pItem)
321 delete rItem.pItem;
322 rItem.pItem = 0;