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 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
26 :
27 : #include <svl/cjkoptions.hxx>
28 : #include <svl/ctloptions.hxx>
29 : #include <svl/languageoptions.hxx>
30 : #include <unotools/options.hxx>
31 :
32 : #include <tools/debug.hxx>
33 :
34 128 : ItemHolder2::ItemHolder2()
35 128 : : ItemHolderMutexBase()
36 : {
37 : try
38 : {
39 128 : css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
40 256 : css::uno::Reference< css::lang::XComponent > xCfg( css::configuration::theDefaultProvider::get(xContext), css::uno::UNO_QUERY_THROW );
41 256 : xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
42 : }
43 0 : catch(const css::uno::RuntimeException&)
44 : {
45 0 : throw;
46 : }
47 : #ifdef DBG_UTIL
48 : catch(const css::uno::Exception& rEx)
49 : {
50 : static bool bMessage = true;
51 : if(bMessage)
52 : {
53 : bMessage = false;
54 : OString sMsg("CreateInstance with arguments exception: ");
55 : sMsg += OString(rEx.Message.getStr(),
56 : rEx.Message.getLength(),
57 : RTL_TEXTENCODING_ASCII_US);
58 : OSL_FAIL(sMsg.getStr());
59 : }
60 : }
61 : #else
62 0 : catch(css::uno::Exception&){}
63 : #endif
64 128 : }
65 :
66 381 : ItemHolder2::~ItemHolder2()
67 : {
68 127 : impl_releaseAllItems();
69 254 : }
70 :
71 218 : void ItemHolder2::holdConfigItem(EItem eItem)
72 : {
73 218 : static ItemHolder2* pHolder = new ItemHolder2();
74 218 : pHolder->impl_addItem(eItem);
75 218 : }
76 :
77 127 : void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
78 : throw(css::uno::RuntimeException, std::exception)
79 : {
80 127 : impl_releaseAllItems();
81 127 : }
82 :
83 218 : void ItemHolder2::impl_addItem(EItem eItem)
84 : {
85 218 : ::osl::ResettableMutexGuard aLock(m_aLock);
86 :
87 218 : TItems::const_iterator pIt;
88 924 : for ( pIt = m_lItems.begin();
89 616 : pIt != m_lItems.end() ;
90 : ++pIt )
91 : {
92 90 : const TItemInfo& rInfo = *pIt;
93 90 : if (rInfo.eItem == eItem)
94 218 : return;
95 : }
96 :
97 218 : TItemInfo aNewItem;
98 218 : aNewItem.eItem = eItem;
99 218 : impl_newItem(aNewItem);
100 218 : if (aNewItem.pItem)
101 218 : m_lItems.push_back(aNewItem);
102 : }
103 :
104 254 : void ItemHolder2::impl_releaseAllItems()
105 : {
106 254 : ::osl::ResettableMutexGuard aLock(m_aLock);
107 :
108 254 : TItems::iterator pIt;
109 1413 : for ( pIt = m_lItems.begin();
110 942 : pIt != m_lItems.end() ;
111 : ++pIt )
112 : {
113 217 : TItemInfo& rInfo = *pIt;
114 217 : impl_deleteItem(rInfo);
115 : }
116 254 : m_lItems.clear();
117 254 : }
118 :
119 218 : void ItemHolder2::impl_newItem(TItemInfo& rItem)
120 : {
121 218 : switch(rItem.eItem)
122 : {
123 : case E_CJKOPTIONS :
124 90 : rItem.pItem = new SvtCJKOptions();
125 90 : break;
126 :
127 : case E_CTLOPTIONS :
128 128 : rItem.pItem = new SvtCTLOptions();
129 128 : break;
130 :
131 : case E_LANGUAGEOPTIONS :
132 : // capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions();
133 0 : break;
134 :
135 : default:
136 : OSL_ASSERT(false);
137 0 : break;
138 : }
139 218 : }
140 :
141 217 : void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
142 : {
143 217 : if (rItem.pItem)
144 : {
145 217 : delete rItem.pItem;
146 217 : rItem.pItem = 0;
147 : }
148 217 : }
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|