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>
27 #include <rtl/ref.hxx>
28 #include <svl/ctloptions.hxx>
29 #include <comphelper/diagnose_ex.hxx>
30 #include <unotools/options.hxx>
32 ItemHolder2::ItemHolder2()
36 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
= ::comphelper::getProcessComponentContext();
37 css::uno::Reference
< css::lang::XComponent
> xCfg( css::configuration::theDefaultProvider::get(xContext
), css::uno::UNO_QUERY_THROW
);
38 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
40 catch(const css::uno::RuntimeException
&)
45 catch(const css::uno::Exception
&)
47 static bool bMessage
= true;
51 TOOLS_WARN_EXCEPTION( "svl", "" );
55 catch(css::uno::Exception
&){}
59 ItemHolder2::~ItemHolder2()
61 impl_releaseAllItems();
64 void ItemHolder2::holdConfigItem(EItem eItem
)
66 static rtl::Reference
<ItemHolder2
> pHolder
= new ItemHolder2();
67 pHolder
->impl_addItem(eItem
);
70 void SAL_CALL
ItemHolder2::disposing(const css::lang::EventObject
&)
72 impl_releaseAllItems();
75 void ItemHolder2::impl_addItem(EItem eItem
)
77 std::scoped_lock
aLock(m_aLock
);
79 for ( auto const & rInfo
: m_lItems
)
81 if (rInfo
.eItem
== eItem
)
86 aNewItem
.eItem
= eItem
;
87 impl_newItem(aNewItem
);
89 m_lItems
.emplace_back(std::move(aNewItem
));
92 void ItemHolder2::impl_releaseAllItems()
94 std::vector
< TItemInfo
> items
;
96 std::scoped_lock
aLock(m_aLock
);
100 // items will be freed when the block exits
103 void ItemHolder2::impl_newItem(TItemInfo
& rItem
)
107 case EItem::CTLOptions
:
108 rItem
.pItem
.reset( new SvtCTLOptions() );
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */