1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "itemholder2.hxx"
23 #include <osl/diagnose.h>
24 #include <comphelper/processfactory.hxx>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/configuration/theDefaultProvider.hpp>
28 #include <svl/cjkoptions.hxx>
29 #include <svl/ctloptions.hxx>
30 #include <svl/languageoptions.hxx>
31 #include <unotools/options.hxx>
33 ItemHolder2::ItemHolder2()
34 : ItemHolderMutexBase()
38 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
39 css::uno::Reference
< css::lang::XComponent
> xCfg( css::configuration::theDefaultProvider::get(xContext
), css::uno::UNO_QUERY_THROW
);
40 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
42 catch(const css::uno::RuntimeException
&)
47 catch(const css::uno::Exception
& rEx
)
49 static bool bMessage
= true;
53 OString
sMsg("CreateInstance with arguments exception: ");
54 sMsg
+= OString(rEx
.Message
.getStr(),
55 rEx
.Message
.getLength(),
56 RTL_TEXTENCODING_ASCII_US
);
57 OSL_FAIL(sMsg
.getStr());
61 catch(css::uno::Exception
&){}
65 ItemHolder2::~ItemHolder2()
67 impl_releaseAllItems();
70 void ItemHolder2::holdConfigItem(EItem eItem
)
72 static ItemHolder2
* pHolder
= new ItemHolder2();
73 pHolder
->impl_addItem(eItem
);
76 void SAL_CALL
ItemHolder2::disposing(const css::lang::EventObject
&)
77 throw(css::uno::RuntimeException
, std::exception
)
79 impl_releaseAllItems();
82 void ItemHolder2::impl_addItem(EItem eItem
)
84 ::osl::ResettableMutexGuard
aLock(m_aLock
);
86 TItems::const_iterator pIt
;
87 for ( pIt
= m_lItems
.begin();
88 pIt
!= m_lItems
.end() ;
91 const TItemInfo
& rInfo
= *pIt
;
92 if (rInfo
.eItem
== eItem
)
97 aNewItem
.eItem
= eItem
;
98 impl_newItem(aNewItem
);
100 m_lItems
.push_back(aNewItem
);
103 void ItemHolder2::impl_releaseAllItems()
105 ::osl::ResettableMutexGuard
aLock(m_aLock
);
107 TItems::iterator pIt
;
108 for ( pIt
= m_lItems
.begin();
109 pIt
!= m_lItems
.end() ;
112 TItemInfo
& rInfo
= *pIt
;
113 impl_deleteItem(rInfo
);
118 void ItemHolder2::impl_newItem(TItemInfo
& rItem
)
123 rItem
.pItem
= new SvtCJKOptions();
127 rItem
.pItem
= new SvtCTLOptions();
130 case E_LANGUAGEOPTIONS
:
131 // capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions();
140 void ItemHolder2::impl_deleteItem(TItemInfo
& rItem
)
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */