Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "itemholder2.hxx"
22 : :
23 : : #include <comphelper/processfactory.hxx>
24 : : #include <com/sun/star/lang/XComponent.hpp>
25 : :
26 : : #include <svl/cjkoptions.hxx>
27 : : #include <svl/ctloptions.hxx>
28 : : #include <svl/languageoptions.hxx>
29 : : #include <unotools/options.hxx>
30 : :
31 : : #include <tools/debug.hxx>
32 : :
33 : : //-----------------------------------------------
34 : : // namespaces
35 : :
36 : : namespace css = ::com::sun::star;
37 : :
38 : :
39 : : //-----------------------------------------------
40 : 230 : ItemHolder2::ItemHolder2()
41 [ + - ][ + - ]: 230 : : ItemHolderMutexBase()
42 : : {
43 : : try
44 : : {
45 [ + - ]: 230 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
46 : : css::uno::Reference< css::lang::XComponent > xCfg(
47 [ + - ]: 230 : xSMGR->createInstance(::rtl::OUString("com.sun.star.configuration.ConfigurationProvider")),
48 [ + - ][ + - ]: 230 : css::uno::UNO_QUERY);
49 [ + - ]: 230 : if (xCfg.is())
50 [ + - ][ + - ]: 230 : xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
[ + - ]
51 : : }
52 [ # # # ]: 0 : catch(const css::uno::RuntimeException&)
53 : : {
54 : 0 : throw;
55 : : }
56 : : #ifdef DBG_UTIL
57 : : catch(const css::uno::Exception& rEx)
58 : : {
59 : : static sal_Bool bMessage = sal_True;
60 : : if(bMessage)
61 : : {
62 : : bMessage = sal_False;
63 : : ::rtl::OString sMsg("CreateInstance with arguments exception: ");
64 : : sMsg += ::rtl::OString(rEx.Message.getStr(),
65 : : rEx.Message.getLength(),
66 : : RTL_TEXTENCODING_ASCII_US);
67 : : OSL_FAIL(sMsg.getStr());
68 : : }
69 : : }
70 : : #else
71 [ # # ]: 0 : catch(css::uno::Exception&){}
72 : : #endif
73 : 230 : }
74 : :
75 : : //-----------------------------------------------
76 [ + - ]: 230 : ItemHolder2::~ItemHolder2()
77 : : {
78 [ + - ]: 230 : impl_releaseAllItems();
79 [ - + ]: 460 : }
80 : :
81 : : //-----------------------------------------------
82 : 391 : void ItemHolder2::holdConfigItem(EItem eItem)
83 : : {
84 [ + + ][ + - ]: 391 : static ItemHolder2* pHolder = new ItemHolder2();
[ + - ][ # # ]
85 : 391 : pHolder->impl_addItem(eItem);
86 : 391 : }
87 : :
88 : : //-----------------------------------------------
89 : 230 : void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
90 : : throw(css::uno::RuntimeException)
91 : : {
92 : 230 : impl_releaseAllItems();
93 : 230 : }
94 : :
95 : : //-----------------------------------------------
96 : 391 : void ItemHolder2::impl_addItem(EItem eItem)
97 : : {
98 [ + - ]: 391 : ::osl::ResettableMutexGuard aLock(m_aLock);
99 : :
100 : 391 : TItems::const_iterator pIt;
101 [ + - ][ + - ]: 1104 : for ( pIt = m_lItems.begin();
[ + + ]
102 : 552 : pIt != m_lItems.end() ;
103 : : ++pIt )
104 : : {
105 : 161 : const TItemInfo& rInfo = *pIt;
106 [ - + ]: 161 : if (rInfo.eItem == eItem)
107 : 391 : return;
108 : : }
109 : :
110 : 391 : TItemInfo aNewItem;
111 : 391 : aNewItem.eItem = eItem;
112 [ + - ]: 391 : impl_newItem(aNewItem);
113 [ + - ]: 391 : if (aNewItem.pItem)
114 [ + - ][ + - ]: 391 : m_lItems.push_back(aNewItem);
[ + - ]
115 : : }
116 : :
117 : : //-----------------------------------------------
118 : 460 : void ItemHolder2::impl_releaseAllItems()
119 : : {
120 [ + - ]: 460 : ::osl::ResettableMutexGuard aLock(m_aLock);
121 : :
122 : 460 : TItems::iterator pIt;
123 [ + - ][ + + ]: 1702 : for ( pIt = m_lItems.begin();
124 : 851 : pIt != m_lItems.end() ;
125 : : ++pIt )
126 : : {
127 : 391 : TItemInfo& rInfo = *pIt;
128 [ + - ]: 391 : impl_deleteItem(rInfo);
129 : : }
130 [ + - ]: 460 : m_lItems.clear();
131 : 460 : }
132 : :
133 : : //-----------------------------------------------
134 : 391 : void ItemHolder2::impl_newItem(TItemInfo& rItem)
135 : : {
136 [ + + - - ]: 391 : switch(rItem.eItem)
137 : : {
138 : : case E_CJKOPTIONS :
139 [ + - ]: 161 : rItem.pItem = new SvtCJKOptions();
140 : 161 : break;
141 : :
142 : : case E_CTLOPTIONS :
143 [ + - ]: 230 : rItem.pItem = new SvtCTLOptions();
144 : 230 : break;
145 : :
146 : : case E_LANGUAGEOPTIONS :
147 : : // capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions();
148 : 0 : break;
149 : :
150 : : default:
151 : : OSL_ASSERT(false);
152 : 0 : break;
153 : : }
154 : 391 : }
155 : :
156 : : //-----------------------------------------------
157 : 391 : void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
158 : : {
159 [ + - ]: 391 : if (rItem.pItem)
160 : : {
161 [ + - ]: 391 : delete rItem.pItem;
162 : 391 : rItem.pItem = 0;
163 : : }
164 : 391 : }
165 : :
166 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|