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 <tools/diagnose_ex.h>
32 #include <unotools/options.hxx>
34 ItemHolder2::ItemHolder2()
35 : ItemHolderMutexBase()
39 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
40 css::uno::Reference
< css::lang::XComponent
> xCfg( css::configuration::theDefaultProvider::get(xContext
), css::uno::UNO_QUERY_THROW
);
41 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
43 catch(const css::uno::RuntimeException
&)
48 catch(const css::uno::Exception
&)
50 static bool bMessage
= true;
54 TOOLS_WARN_EXCEPTION( "svl", "" );
58 catch(css::uno::Exception
&){}
62 ItemHolder2::~ItemHolder2()
64 impl_releaseAllItems();
67 void ItemHolder2::holdConfigItem(EItem eItem
)
69 static ItemHolder2
* pHolder
= new ItemHolder2();
70 pHolder
->impl_addItem(eItem
);
73 void SAL_CALL
ItemHolder2::disposing(const css::lang::EventObject
&)
75 impl_releaseAllItems();
78 void ItemHolder2::impl_addItem(EItem eItem
)
80 osl::MutexGuard
aLock(m_aLock
);
82 for ( auto const & rInfo
: m_lItems
)
84 if (rInfo
.eItem
== eItem
)
89 aNewItem
.eItem
= eItem
;
90 impl_newItem(aNewItem
);
92 m_lItems
.emplace_back(std::move(aNewItem
));
95 void ItemHolder2::impl_releaseAllItems()
97 std::vector
< TItemInfo
> items
;
99 ::osl::MutexGuard
aLock(m_aLock
);
100 items
.swap(m_lItems
);
103 // items will be freed when the block exits
106 void ItemHolder2::impl_newItem(TItemInfo
& rItem
)
110 case EItem::CJKOptions
:
111 rItem
.pItem
.reset( new SvtCJKOptions() );
114 case EItem::CTLOptions
:
115 rItem
.pItem
.reset( new SvtCTLOptions() );
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */