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