bump product version to 7.6.3.2-android
[LibreOffice.git] / svtools / source / config / itemholder2.cxx
blobc41095247eca2b6adbb719ffbb5a9e35cd760aec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svtools/accessibilityoptions.hxx>
29 #include <svtools/colorcfg.hxx>
30 #include <unotools/options.hxx>
31 #include <svtools/miscopt.hxx>
32 #include <comphelper/diagnose_ex.hxx>
33 #include <rtl/ref.hxx>
35 namespace svtools {
37 ItemHolder2::ItemHolder2()
39 try
41 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
42 css::uno::Reference< css::lang::XComponent > xCfg(
43 css::configuration::theDefaultProvider::get( xContext ),
44 css::uno::UNO_QUERY_THROW );
45 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
47 catch(const css::uno::RuntimeException&)
49 throw;
51 #ifdef DBG_UTIL
52 catch(const css::uno::Exception&)
54 static bool bMessage = true;
55 if(bMessage)
57 bMessage = false;
58 TOOLS_WARN_EXCEPTION( "svtools", "CreateInstance with arguments" );
61 #else
62 catch(css::uno::Exception&){}
63 #endif
67 ItemHolder2::~ItemHolder2()
69 impl_releaseAllItems();
73 void ItemHolder2::holdConfigItem(EItem eItem)
75 static rtl::Reference<ItemHolder2> pHolder = new ItemHolder2();
76 pHolder->impl_addItem(eItem);
80 void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
82 impl_releaseAllItems();
86 void ItemHolder2::impl_addItem(EItem eItem)
88 std::scoped_lock aLock(m_aLock);
90 for ( auto const & rInfo : m_lItems )
92 if (rInfo.eItem == eItem)
93 return;
96 TItemInfo aNewItem;
97 aNewItem.eItem = eItem;
98 impl_newItem(aNewItem);
99 if (aNewItem.pItem)
100 m_lItems.emplace_back(std::move(aNewItem));
104 void ItemHolder2::impl_releaseAllItems()
106 std::vector<TItemInfo> items;
108 std::scoped_lock aLock(m_aLock);
109 items.swap(m_lItems);
112 // items will be freed when the block exits
116 void ItemHolder2::impl_newItem(TItemInfo& rItem)
118 switch(rItem.eItem)
120 case EItem::AccessibilityOptions :
121 rItem.pItem.reset( new SvtAccessibilityOptions() );
122 break;
124 case EItem::ColorConfig :
125 rItem.pItem.reset( new ::svtools::ColorConfig() );
126 break;
128 case EItem::MiscOptions :
129 rItem.pItem.reset( new SvtMiscOptions() );
130 break;
132 default:
133 OSL_ASSERT(false);
134 break;
138 } // namespace svtools
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */