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 <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/apearcfg.hxx>
30 #include <svtools/menuoptions.hxx>
31 #include <svtools/colorcfg.hxx>
32 #include <svtools/fontsubstconfig.hxx>
33 #include <svtools/helpopt.hxx>
34 #include <svtools/printoptions.hxx>
35 #include <unotools/options.hxx>
36 #include <svtools/miscopt.hxx>
40 ItemHolder2::ItemHolder2()
41 : ItemHolderMutexBase()
45 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
46 css::uno::Reference
< css::lang::XComponent
> xCfg(
47 css::configuration::theDefaultProvider::get( xContext
),
48 css::uno::UNO_QUERY_THROW
);
49 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
51 catch(const css::uno::RuntimeException
&)
56 catch(const css::uno::Exception
& rEx
)
58 static bool bMessage
= true;
62 OString
sMsg("CreateInstance with arguments exception: ");
63 sMsg
+= OString(rEx
.Message
.getStr(),
64 rEx
.Message
.getLength(),
65 RTL_TEXTENCODING_ASCII_US
);
66 OSL_FAIL(sMsg
.getStr());
70 catch(css::uno::Exception
&){}
75 ItemHolder2::~ItemHolder2()
77 impl_releaseAllItems();
81 void ItemHolder2::holdConfigItem(EItem eItem
)
83 static ItemHolder2
* pHolder
= new ItemHolder2();
84 pHolder
->impl_addItem(eItem
);
88 void SAL_CALL
ItemHolder2::disposing(const css::lang::EventObject
&)
89 throw(css::uno::RuntimeException
, std::exception
)
91 impl_releaseAllItems();
95 void ItemHolder2::impl_addItem(EItem eItem
)
97 ::osl::ResettableMutexGuard
aLock(m_aLock
);
99 TItems::const_iterator pIt
;
100 for ( pIt
= m_lItems
.begin();
101 pIt
!= m_lItems
.end() ;
104 const TItemInfo
& rInfo
= *pIt
;
105 if (rInfo
.eItem
== eItem
)
110 aNewItem
.eItem
= eItem
;
111 impl_newItem(aNewItem
);
113 m_lItems
.push_back(aNewItem
);
117 void ItemHolder2::impl_releaseAllItems()
119 ::osl::ResettableMutexGuard
aLock(m_aLock
);
121 TItems::iterator pIt
;
122 for ( pIt
= m_lItems
.begin();
123 pIt
!= m_lItems
.end() ;
126 TItemInfo
& rInfo
= *pIt
;
127 impl_deleteItem(rInfo
);
133 void ItemHolder2::impl_newItem(TItemInfo
& rItem
)
137 case E_ACCESSIBILITYOPTIONS
:
138 rItem
.pItem
= new SvtAccessibilityOptions();
142 // no ref count rItem.pItem = new SvtTabAppearanceCfg();
146 rItem
.pItem
= new ::svtools::ColorConfig();
149 case E_FONTSUBSTCONFIG
:
150 // no ref count rItem.pItem = new SvtFontSubstConfig();
154 rItem
.pItem
= new SvtHelpOptions();
158 rItem
.pItem
= new SvtMenuOptions();
161 case E_PRINTOPTIONS
:
162 rItem
.pItem
= new SvtPrinterOptions();
165 case E_PRINTFILEOPTIONS
:
166 rItem
.pItem
= new SvtPrintFileOptions();
170 rItem
.pItem
= new SvtMiscOptions();
180 void ItemHolder2::impl_deleteItem(TItemInfo
& rItem
)
189 } // namespace svtools
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */