Bump version to 5.0-14
[LibreOffice.git] / svtools / source / config / itemholder2.cxx
blobea3b6c866c53efbeed8d60f1b8f7844fb25e2733
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 <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>
38 namespace svtools {
40 ItemHolder2::ItemHolder2()
41 : ItemHolderMutexBase()
43 try
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&)
53 throw;
55 #ifdef DBG_UTIL
56 catch(const css::uno::Exception& rEx)
58 static bool bMessage = true;
59 if(bMessage)
61 bMessage = false;
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());
69 #else
70 catch(css::uno::Exception&){}
71 #endif
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() ;
102 ++pIt )
104 const TItemInfo& rInfo = *pIt;
105 if (rInfo.eItem == eItem)
106 return;
109 TItemInfo aNewItem;
110 aNewItem.eItem = eItem;
111 impl_newItem(aNewItem);
112 if (aNewItem.pItem)
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() ;
124 ++pIt )
126 TItemInfo& rInfo = *pIt;
127 impl_deleteItem(rInfo);
129 m_lItems.clear();
133 void ItemHolder2::impl_newItem(TItemInfo& rItem)
135 switch(rItem.eItem)
137 case E_ACCESSIBILITYOPTIONS :
138 rItem.pItem = new SvtAccessibilityOptions();
139 break;
141 case E_APEARCFG :
142 // no ref count rItem.pItem = new SvtTabAppearanceCfg();
143 break;
145 case E_COLORCFG :
146 rItem.pItem = new ::svtools::ColorConfig();
147 break;
149 case E_FONTSUBSTCONFIG :
150 // no ref count rItem.pItem = new SvtFontSubstConfig();
151 break;
153 case E_HELPOPTIONS :
154 rItem.pItem = new SvtHelpOptions();
155 break;
157 case E_MENUOPTIONS :
158 rItem.pItem = new SvtMenuOptions();
159 break;
161 case E_PRINTOPTIONS :
162 rItem.pItem = new SvtPrinterOptions();
163 break;
165 case E_PRINTFILEOPTIONS :
166 rItem.pItem = new SvtPrintFileOptions();
167 break;
169 case E_MISCOPTIONS :
170 rItem.pItem = new SvtMiscOptions();
171 break;
173 default:
174 OSL_ASSERT(false);
175 break;
180 void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
182 if (rItem.pItem)
184 delete rItem.pItem;
185 rItem.pItem = 0;
189 } // namespace svtools
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */