crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / svtools / source / config / itemholder2.cxx
blobf7eb8b808739b9dca9e2dc8ade8f447dc2875ab0
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/colorcfg.hxx>
29 #include <unotools/options.hxx>
30 #include <svtools/miscopt.hxx>
31 #include <comphelper/diagnose_ex.hxx>
32 #include <rtl/ref.hxx>
34 namespace svtools {
36 ItemHolder2::ItemHolder2()
38 try
40 const css::uno::Reference< css::uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
41 css::uno::Reference< css::lang::XComponent > xCfg(
42 css::configuration::theDefaultProvider::get( xContext ),
43 css::uno::UNO_QUERY_THROW );
44 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
46 catch(const css::uno::RuntimeException&)
48 throw;
50 #ifdef DBG_UTIL
51 catch(const css::uno::Exception&)
53 static bool bMessage = true;
54 if(bMessage)
56 bMessage = false;
57 TOOLS_WARN_EXCEPTION( "svtools", "CreateInstance with arguments" );
60 #else
61 catch(css::uno::Exception&){}
62 #endif
66 ItemHolder2::~ItemHolder2()
68 impl_releaseAllItems();
72 void ItemHolder2::holdConfigItem(EItem eItem)
74 static rtl::Reference<ItemHolder2> pHolder = new ItemHolder2();
75 pHolder->impl_addItem(eItem);
79 void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
81 impl_releaseAllItems();
85 void ItemHolder2::impl_addItem(EItem eItem)
87 std::scoped_lock aLock(m_aLock);
89 for ( auto const & rInfo : m_lItems )
91 if (rInfo.eItem == eItem)
92 return;
95 TItemInfo aNewItem;
96 aNewItem.eItem = eItem;
97 impl_newItem(aNewItem);
98 if (aNewItem.pItem)
99 m_lItems.emplace_back(std::move(aNewItem));
103 void ItemHolder2::impl_releaseAllItems()
105 std::vector<TItemInfo> items;
107 std::scoped_lock aLock(m_aLock);
108 items.swap(m_lItems);
111 // items will be freed when the block exits
115 void ItemHolder2::impl_newItem(TItemInfo& rItem)
117 switch(rItem.eItem)
119 case EItem::ColorConfig :
120 rItem.pItem.reset( new ::svtools::ColorConfig() );
121 break;
123 case EItem::MiscOptions :
124 rItem.pItem.reset( new SvtMiscOptions() );
125 break;
127 default:
128 OSL_ASSERT(false);
129 break;
133 } // namespace svtools
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */