LibreOffice Module svtools (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
29#include <svtools/colorcfg.hxx>
30#include <unotools/options.hxx>
31#include <svtools/miscopt.hxx>
33#include <rtl/ref.hxx>
34
35namespace svtools {
36
38{
39 try
40 {
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));
46 }
47 catch(const css::uno::RuntimeException&)
48 {
49 throw;
50 }
51#ifdef DBG_UTIL
52 catch(const css::uno::Exception&)
53 {
54 static bool bMessage = true;
55 if(bMessage)
56 {
57 bMessage = false;
58 TOOLS_WARN_EXCEPTION( "svtools", "CreateInstance with arguments" );
59 }
60 }
61#else
62 catch(css::uno::Exception&){}
63#endif
64}
65
66
68{
70}
71
72
74{
75 static rtl::Reference<ItemHolder2> pHolder = new ItemHolder2();
76 pHolder->impl_addItem(eItem);
77}
78
79
80void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
81{
83}
84
85
87{
88 std::scoped_lock aLock(m_aLock);
89
90 for ( auto const & rInfo : m_lItems )
91 {
92 if (rInfo.eItem == eItem)
93 return;
94 }
95
96 TItemInfo aNewItem;
97 aNewItem.eItem = eItem;
98 impl_newItem(aNewItem);
99 if (aNewItem.pItem)
100 m_lItems.emplace_back(std::move(aNewItem));
101}
102
103
105{
106 std::vector<TItemInfo> items;
107 {
108 std::scoped_lock aLock(m_aLock);
109 items.swap(m_lItems);
110 }
111
112 // items will be freed when the block exits
113}
114
115
117{
118 switch(rItem.eItem)
119 {
120 case EItem::AccessibilityOptions :
121 rItem.pItem.reset( new SvtAccessibilityOptions() );
122 break;
123
124 case EItem::ColorConfig :
125 rItem.pItem.reset( new ::svtools::ColorConfig() );
126 break;
127
128 case EItem::MiscOptions :
129 rItem.pItem.reset( new SvtMiscOptions() );
130 break;
131
132 default:
133 OSL_ASSERT(false);
134 break;
135 }
136}
137
138} // namespace svtools
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void impl_addItem(EItem eItem)
Definition: itemholder2.cxx:86
virtual ~ItemHolder2() override
Definition: itemholder2.cxx:67
std::vector< TItemInfo > m_lItems
Definition: itemholder2.hxx:36
static void impl_newItem(TItemInfo &rItem)
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
Definition: itemholder2.cxx:80
static void holdConfigItem(EItem eItem)
Definition: itemholder2.cxx:73
#define TOOLS_WARN_EXCEPTION(area, stream)
EItem
std::unique_ptr< utl::detail::Options > pItem
EItem eItem