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