GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / config / itemholder2.cxx
blob856125f4a8d2c6496bd37092647f99413fa4397e
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 <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>
40 namespace svtools {
41 //-----------------------------------------------
42 ItemHolder2::ItemHolder2()
43 : ItemHolderMutexBase()
45 try
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&)
55 throw;
57 #ifdef DBG_UTIL
58 catch(const css::uno::Exception& rEx)
60 static sal_Bool bMessage = sal_True;
61 if(bMessage)
63 bMessage = sal_False;
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());
71 #else
72 catch(css::uno::Exception&){}
73 #endif
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() ;
104 ++pIt )
106 const TItemInfo& rInfo = *pIt;
107 if (rInfo.eItem == eItem)
108 return;
111 TItemInfo aNewItem;
112 aNewItem.eItem = eItem;
113 impl_newItem(aNewItem);
114 if (aNewItem.pItem)
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() ;
126 ++pIt )
128 TItemInfo& rInfo = *pIt;
129 impl_deleteItem(rInfo);
131 m_lItems.clear();
134 //-----------------------------------------------
135 void ItemHolder2::impl_newItem(TItemInfo& rItem)
137 switch(rItem.eItem)
139 case E_ACCESSIBILITYOPTIONS :
140 rItem.pItem = new SvtAccessibilityOptions();
141 break;
143 case E_APEARCFG :
144 // no ref count rItem.pItem = new SvtTabAppearanceCfg();
145 break;
147 case E_COLORCFG :
148 rItem.pItem = new ::svtools::ColorConfig();
149 break;
151 case E_FONTSUBSTCONFIG :
152 // no ref count rItem.pItem = new SvtFontSubstConfig();
153 break;
155 case E_HELPOPTIONS :
156 rItem.pItem = new SvtHelpOptions();
157 break;
159 case E_MENUOPTIONS :
160 rItem.pItem = new SvtMenuOptions();
161 break;
163 case E_PRINTOPTIONS :
164 rItem.pItem = new SvtPrinterOptions();
165 break;
167 case E_PRINTFILEOPTIONS :
168 rItem.pItem = new SvtPrintFileOptions();
169 break;
171 case E_MISCOPTIONS :
172 rItem.pItem = new SvtMiscOptions();
173 break;
175 default:
176 OSL_ASSERT(false);
177 break;
181 //-----------------------------------------------
182 void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
184 if (rItem.pItem)
186 delete rItem.pItem;
187 rItem.pItem = 0;
191 } // namespace svtools
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */