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