xref: /aoo41x/main/svl/source/config/itemholder2.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #include "itemholder2.hxx"
32 
33 //-----------------------------------------------
34 // includes
35 #include <comphelper/processfactory.hxx>
36 #include <com/sun/star/lang/XComponent.hpp>
37 
38 #include <svl/cjkoptions.hxx>
39 #include <svl/ctloptions.hxx>
40 #include <svl/languageoptions.hxx>
41 #include <unotools/options.hxx>
42 
43 #include <tools/debug.hxx>
44 
45 //-----------------------------------------------
46 // namespaces
47 
48 namespace css = ::com::sun::star;
49 
50 //-----------------------------------------------
51 // declarations
52 
53 //-----------------------------------------------
54 ItemHolder2::ItemHolder2()
55     : ItemHolderMutexBase()
56 {
57     try
58     {
59         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
60         css::uno::Reference< css::lang::XComponent > xCfg(
61             xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")),
62             css::uno::UNO_QUERY);
63         if (xCfg.is())
64             xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
65     }
66 // #i37892  got errorhandling from   ConfigManager::GetConfigurationProvider()
67     catch(css::uno::RuntimeException& rREx)
68     {
69         throw rREx;
70     }
71 #ifdef DBG_UTIL
72     catch(css::uno::Exception& rEx)
73 	{
74         static sal_Bool bMessage = sal_True;
75         if(bMessage)
76         {
77             bMessage = sal_False;
78             ::rtl::OString sMsg("CreateInstance with arguments exception: ");
79             sMsg += ::rtl::OString(rEx.Message.getStr(),
80                         rEx.Message.getLength(),
81                         RTL_TEXTENCODING_ASCII_US);
82             DBG_ERROR(sMsg.getStr());
83         }
84 	}
85 #else
86 	catch(css::uno::Exception&){}
87 #endif
88 }
89 
90 //-----------------------------------------------
91 ItemHolder2::~ItemHolder2()
92 {
93     impl_releaseAllItems();
94 }
95 
96 //-----------------------------------------------
97 void ItemHolder2::holdConfigItem(EItem eItem)
98 {
99     static ItemHolder2* pHolder = new ItemHolder2();
100     pHolder->impl_addItem(eItem);
101 }
102 
103 //-----------------------------------------------
104 void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
105     throw(css::uno::RuntimeException)
106 {
107     impl_releaseAllItems();
108 }
109 
110 //-----------------------------------------------
111 void ItemHolder2::impl_addItem(EItem eItem)
112 {
113     ::osl::ResettableMutexGuard aLock(m_aLock);
114 
115     TItems::const_iterator pIt;
116     for (  pIt  = m_lItems.begin();
117            pIt != m_lItems.end()  ;
118          ++pIt                    )
119     {
120         const TItemInfo& rInfo = *pIt;
121         if (rInfo.eItem == eItem)
122             return;
123     }
124 
125     TItemInfo aNewItem;
126     aNewItem.eItem = eItem;
127     impl_newItem(aNewItem);
128     if (aNewItem.pItem)
129         m_lItems.push_back(aNewItem);
130 }
131 
132 //-----------------------------------------------
133 void ItemHolder2::impl_releaseAllItems()
134 {
135     ::osl::ResettableMutexGuard aLock(m_aLock);
136 
137     TItems::iterator pIt;
138     for (  pIt  = m_lItems.begin();
139            pIt != m_lItems.end()  ;
140          ++pIt                    )
141     {
142         TItemInfo& rInfo = *pIt;
143         impl_deleteItem(rInfo);
144     }
145     m_lItems.clear();
146 }
147 
148 //-----------------------------------------------
149 void ItemHolder2::impl_newItem(TItemInfo& rItem)
150 {
151     switch(rItem.eItem)
152     {
153         case E_CJKOPTIONS :
154             rItem.pItem = new SvtCJKOptions();
155             break;
156 
157         case E_CTLOPTIONS :
158             rItem.pItem = new SvtCTLOptions();
159             break;
160 
161         case E_LANGUAGEOPTIONS :
162 // capsulate CTL and CJL options !            rItem.pItem = new SvtLanguageOptions();
163             break;
164 
165         default:
166             OSL_ASSERT(false);
167             break;
168     }
169 }
170 
171 //-----------------------------------------------
172 void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
173 {
174     if (rItem.pItem)
175     {
176         delete rItem.pItem;
177         rItem.pItem = 0;
178     }
179 }
180