LibreOffice Module svl (master) 1
itemholder2.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "itemholder2.hxx"
22
23#include <osl/diagnose.h>
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>
30#include <unotools/options.hxx>
31
33{
34 try
35 {
36 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));
39 }
40 catch(const css::uno::RuntimeException&)
41 {
42 throw;
43 }
44#ifdef DBG_UTIL
45 catch(const css::uno::Exception&)
46 {
47 static bool bMessage = true;
48 if(bMessage)
49 {
50 bMessage = false;
51 TOOLS_WARN_EXCEPTION( "svl", "" );
52 }
53 }
54#else
55 catch(css::uno::Exception&){}
56#endif
57}
58
60{
62}
63
65{
66 static rtl::Reference<ItemHolder2> pHolder = new ItemHolder2();
67 pHolder->impl_addItem(eItem);
68}
69
70void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
71{
73}
74
76{
77 std::scoped_lock aLock(m_aLock);
78
79 for ( auto const & rInfo : m_lItems )
80 {
81 if (rInfo.eItem == eItem)
82 return;
83 }
84
85 TItemInfo aNewItem;
86 aNewItem.eItem = eItem;
87 impl_newItem(aNewItem);
88 if (aNewItem.pItem)
89 m_lItems.emplace_back(std::move(aNewItem));
90}
91
93{
94 std::vector< TItemInfo > items;
95 {
96 std::scoped_lock aLock(m_aLock);
97 items.swap(m_lItems);
98 }
99
100 // items will be freed when the block exits
101}
102
104{
105 switch(rItem.eItem)
106 {
107 case EItem::CTLOptions :
108 rItem.pItem.reset( new SvtCTLOptions() );
109 break;
110
111 default:
112 OSL_ASSERT(false);
113 break;
114 }
115}
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void impl_releaseAllItems()
Definition: itemholder2.cxx:92
void impl_addItem(EItem eItem)
Definition: itemholder2.cxx:75
std::vector< TItemInfo > m_lItems
Definition: itemholder2.hxx:34
virtual ~ItemHolder2() override
Definition: itemholder2.cxx:59
static void impl_newItem(TItemInfo &rItem)
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
Definition: itemholder2.cxx:70
std::mutex m_aLock
Definition: itemholder2.hxx:33
static void holdConfigItem(EItem eItem)
Definition: itemholder2.cxx:64
#define TOOLS_WARN_EXCEPTION(area, stream)
EItem
std::unique_ptr< utl::detail::Options > pItem
EItem eItem