1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "itemholder2.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //-----------------------------------------------
30cdf0e10cSrcweir // includes
31cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
32cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <svtools/accessibilityoptions.hxx>
35cdf0e10cSrcweir #include <svtools/apearcfg.hxx>
36cdf0e10cSrcweir #include <svtools/menuoptions.hxx>
37cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
38cdf0e10cSrcweir #include <svtools/fontsubstconfig.hxx>
39cdf0e10cSrcweir #include <svtools/helpopt.hxx>
40cdf0e10cSrcweir #include <svtools/printoptions.hxx>
41cdf0e10cSrcweir #include <unotools/options.hxx>
42cdf0e10cSrcweir #include <svtools/miscopt.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <tools/debug.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //-----------------------------------------------
48cdf0e10cSrcweir // namespaces
49cdf0e10cSrcweir 
50cdf0e10cSrcweir namespace css = ::com::sun::star;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //-----------------------------------------------
53cdf0e10cSrcweir // declarations
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //-----------------------------------------------
ItemHolder2()56cdf0e10cSrcweir ItemHolder2::ItemHolder2()
57cdf0e10cSrcweir     : ItemHolderMutexBase()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     try
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
62cdf0e10cSrcweir         css::uno::Reference< css::lang::XComponent > xCfg(
63cdf0e10cSrcweir             xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")),
64cdf0e10cSrcweir             css::uno::UNO_QUERY);
65cdf0e10cSrcweir         if (xCfg.is())
66cdf0e10cSrcweir             xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir // #i37892  got errorhandling from   ConfigManager::GetConfigurationProvider()
69cdf0e10cSrcweir     catch(css::uno::RuntimeException& rREx)
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         throw rREx;
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir #ifdef DBG_UTIL
74cdf0e10cSrcweir     catch(css::uno::Exception& rEx)
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir         static sal_Bool bMessage = sal_True;
77cdf0e10cSrcweir         if(bMessage)
78cdf0e10cSrcweir         {
79cdf0e10cSrcweir             bMessage = sal_False;
80cdf0e10cSrcweir             ::rtl::OString sMsg("CreateInstance with arguments exception: ");
81cdf0e10cSrcweir             sMsg += ::rtl::OString(rEx.Message.getStr(),
82cdf0e10cSrcweir                         rEx.Message.getLength(),
83cdf0e10cSrcweir                         RTL_TEXTENCODING_ASCII_US);
84cdf0e10cSrcweir             DBG_ERROR(sMsg.getStr());
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir #else
88cdf0e10cSrcweir 	catch(css::uno::Exception&){}
89cdf0e10cSrcweir #endif
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //-----------------------------------------------
~ItemHolder2()93cdf0e10cSrcweir ItemHolder2::~ItemHolder2()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     impl_releaseAllItems();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir //-----------------------------------------------
holdConfigItem(EItem eItem)99cdf0e10cSrcweir void ItemHolder2::holdConfigItem(EItem eItem)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     static ItemHolder2* pHolder = new ItemHolder2();
102cdf0e10cSrcweir     pHolder->impl_addItem(eItem);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir //-----------------------------------------------
disposing(const css::lang::EventObject &)106cdf0e10cSrcweir void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
107cdf0e10cSrcweir     throw(css::uno::RuntimeException)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     impl_releaseAllItems();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //-----------------------------------------------
impl_addItem(EItem eItem)113cdf0e10cSrcweir void ItemHolder2::impl_addItem(EItem eItem)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aLock);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     TItems::const_iterator pIt;
118cdf0e10cSrcweir     for (  pIt  = m_lItems.begin();
119cdf0e10cSrcweir            pIt != m_lItems.end()  ;
120cdf0e10cSrcweir          ++pIt                    )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         const TItemInfo& rInfo = *pIt;
123cdf0e10cSrcweir         if (rInfo.eItem == eItem)
124cdf0e10cSrcweir             return;
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     TItemInfo aNewItem;
128cdf0e10cSrcweir     aNewItem.eItem = eItem;
129cdf0e10cSrcweir     impl_newItem(aNewItem);
130cdf0e10cSrcweir     if (aNewItem.pItem)
131cdf0e10cSrcweir         m_lItems.push_back(aNewItem);
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir //-----------------------------------------------
impl_releaseAllItems()135cdf0e10cSrcweir void ItemHolder2::impl_releaseAllItems()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aLock);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     TItems::iterator pIt;
140cdf0e10cSrcweir     for (  pIt  = m_lItems.begin();
141cdf0e10cSrcweir            pIt != m_lItems.end()  ;
142cdf0e10cSrcweir          ++pIt                    )
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         TItemInfo& rInfo = *pIt;
145cdf0e10cSrcweir         impl_deleteItem(rInfo);
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir     m_lItems.clear();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir //-----------------------------------------------
impl_newItem(TItemInfo & rItem)151cdf0e10cSrcweir void ItemHolder2::impl_newItem(TItemInfo& rItem)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     switch(rItem.eItem)
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir         case E_ACCESSIBILITYOPTIONS :
156cdf0e10cSrcweir             rItem.pItem = new SvtAccessibilityOptions();
157cdf0e10cSrcweir             break;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         case E_APEARCFG :
160cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtTabAppearanceCfg();
161cdf0e10cSrcweir             break;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         case E_COLORCFG :
164cdf0e10cSrcweir             rItem.pItem = new ::svtools::ColorConfig();
165cdf0e10cSrcweir             break;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         case E_FONTSUBSTCONFIG :
168cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtFontSubstConfig();
169cdf0e10cSrcweir             break;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         case E_HELPOPTIONS :
172cdf0e10cSrcweir             rItem.pItem = new SvtHelpOptions();
173cdf0e10cSrcweir             break;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         case E_MENUOPTIONS :
176cdf0e10cSrcweir             rItem.pItem = new SvtMenuOptions();
177cdf0e10cSrcweir             break;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         case E_PRINTOPTIONS :
180cdf0e10cSrcweir             rItem.pItem = new SvtPrinterOptions();
181cdf0e10cSrcweir             break;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir         case E_PRINTFILEOPTIONS :
184cdf0e10cSrcweir             rItem.pItem = new SvtPrintFileOptions();
185cdf0e10cSrcweir             break;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         case E_MISCOPTIONS :
188cdf0e10cSrcweir             rItem.pItem = new SvtMiscOptions();
189cdf0e10cSrcweir             break;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         default:
192cdf0e10cSrcweir             OSL_ASSERT(false);
193cdf0e10cSrcweir             break;
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir //-----------------------------------------------
impl_deleteItem(TItemInfo & rItem)198cdf0e10cSrcweir void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     if (rItem.pItem)
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         delete rItem.pItem;
203cdf0e10cSrcweir         rItem.pItem = 0;
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir }
206