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 <sal/log.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <com/sun/star/configuration/theDefaultProvider.hpp>
29 #include <svl/cjkoptions.hxx>
30 #include <svl/ctloptions.hxx>
31 #include <svl/languageoptions.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <unotools/options.hxx>
35 ItemHolder2::ItemHolder2()
36 : ItemHolderMutexBase()
40 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
41 css::uno::Reference
< css::lang::XComponent
> xCfg( css::configuration::theDefaultProvider::get(xContext
), css::uno::UNO_QUERY_THROW
);
42 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
44 catch(const css::uno::RuntimeException
&)
49 catch(const css::uno::Exception
&)
51 static bool bMessage
= true;
55 css::uno::Any
ex( cppu::getCaughtException() );
56 SAL_WARN( "svl", "CreateInstance with arguments exception: " << exceptionToString(ex
));
60 catch(css::uno::Exception
&){}
64 ItemHolder2::~ItemHolder2()
66 impl_releaseAllItems();
69 void ItemHolder2::holdConfigItem(EItem eItem
)
71 static ItemHolder2
* pHolder
= new ItemHolder2();
72 pHolder
->impl_addItem(eItem
);
75 void SAL_CALL
ItemHolder2::disposing(const css::lang::EventObject
&)
77 impl_releaseAllItems();
80 void ItemHolder2::impl_addItem(EItem eItem
)
82 osl::MutexGuard
aLock(m_aLock
);
84 for ( auto const & rInfo
: m_lItems
)
86 if (rInfo
.eItem
== eItem
)
91 aNewItem
.eItem
= eItem
;
92 impl_newItem(aNewItem
);
94 m_lItems
.emplace_back(std::move(aNewItem
));
97 void ItemHolder2::impl_releaseAllItems()
99 std::vector
< TItemInfo
> items
;
101 ::osl::MutexGuard
aLock(m_aLock
);
102 items
.swap(m_lItems
);
105 // items will be freed when the block exits
108 void ItemHolder2::impl_newItem(TItemInfo
& rItem
)
112 case EItem::CJKOptions
:
113 rItem
.pItem
.reset( new SvtCJKOptions() );
116 case EItem::CTLOptions
:
117 rItem
.pItem
.reset( new SvtCTLOptions() );
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */