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 <comphelper/processfactory.hxx>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <svtools/accessibilityoptions.hxx>
28 #include <svtools/apearcfg.hxx>
29 #include <svtools/menuoptions.hxx>
30 #include <svtools/colorcfg.hxx>
31 #include <svtools/fontsubstconfig.hxx>
32 #include <svtools/helpopt.hxx>
33 #include <svtools/printoptions.hxx>
34 #include <unotools/options.hxx>
35 #include <svtools/miscopt.hxx>
38 #include <tools/debug.hxx>
41 //-----------------------------------------------
42 ItemHolder2::ItemHolder2()
43 : ItemHolderMutexBase()
47 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
48 css::uno::Reference
< css::lang::XComponent
> xCfg(
49 css::configuration::theDefaultProvider::get( xContext
),
50 css::uno::UNO_QUERY_THROW
);
51 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
53 catch(const css::uno::RuntimeException
&)
58 catch(const css::uno::Exception
& rEx
)
60 static sal_Bool bMessage
= sal_True
;
64 OString
sMsg("CreateInstance with arguments exception: ");
65 sMsg
+= OString(rEx
.Message
.getStr(),
66 rEx
.Message
.getLength(),
67 RTL_TEXTENCODING_ASCII_US
);
68 OSL_FAIL(sMsg
.getStr());
72 catch(css::uno::Exception
&){}
76 //-----------------------------------------------
77 ItemHolder2::~ItemHolder2()
79 impl_releaseAllItems();
82 //-----------------------------------------------
83 void ItemHolder2::holdConfigItem(EItem eItem
)
85 static ItemHolder2
* pHolder
= new ItemHolder2();
86 pHolder
->impl_addItem(eItem
);
89 //-----------------------------------------------
90 void SAL_CALL
ItemHolder2::disposing(const css::lang::EventObject
&)
91 throw(css::uno::RuntimeException
)
93 impl_releaseAllItems();
96 //-----------------------------------------------
97 void ItemHolder2::impl_addItem(EItem eItem
)
99 ::osl::ResettableMutexGuard
aLock(m_aLock
);
101 TItems::const_iterator pIt
;
102 for ( pIt
= m_lItems
.begin();
103 pIt
!= m_lItems
.end() ;
106 const TItemInfo
& rInfo
= *pIt
;
107 if (rInfo
.eItem
== eItem
)
112 aNewItem
.eItem
= eItem
;
113 impl_newItem(aNewItem
);
115 m_lItems
.push_back(aNewItem
);
118 //-----------------------------------------------
119 void ItemHolder2::impl_releaseAllItems()
121 ::osl::ResettableMutexGuard
aLock(m_aLock
);
123 TItems::iterator pIt
;
124 for ( pIt
= m_lItems
.begin();
125 pIt
!= m_lItems
.end() ;
128 TItemInfo
& rInfo
= *pIt
;
129 impl_deleteItem(rInfo
);
134 //-----------------------------------------------
135 void ItemHolder2::impl_newItem(TItemInfo
& rItem
)
139 case E_ACCESSIBILITYOPTIONS
:
140 rItem
.pItem
= new SvtAccessibilityOptions();
144 // no ref count rItem.pItem = new SvtTabAppearanceCfg();
148 rItem
.pItem
= new ::svtools::ColorConfig();
151 case E_FONTSUBSTCONFIG
:
152 // no ref count rItem.pItem = new SvtFontSubstConfig();
156 rItem
.pItem
= new SvtHelpOptions();
160 rItem
.pItem
= new SvtMenuOptions();
163 case E_PRINTOPTIONS
:
164 rItem
.pItem
= new SvtPrinterOptions();
167 case E_PRINTFILEOPTIONS
:
168 rItem
.pItem
= new SvtPrintFileOptions();
172 rItem
.pItem
= new SvtMiscOptions();
181 //-----------------------------------------------
182 void ItemHolder2::impl_deleteItem(TItemInfo
& rItem
)
191 } // namespace svtools
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */