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