bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / config / itemholder2.cxx
blob5e46847dc7b572274639bace711c117c22f9b258
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 <svl/cjkoptions.hxx>
29 #include <svl/ctloptions.hxx>
30 #include <svl/languageoptions.hxx>
31 #include <unotools/options.hxx>
33 ItemHolder2::ItemHolder2()
34 : ItemHolderMutexBase()
36 try
38 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
39 css::uno::Reference< css::lang::XComponent > xCfg( css::configuration::theDefaultProvider::get(xContext), css::uno::UNO_QUERY_THROW );
40 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
42 catch(const css::uno::RuntimeException&)
44 throw;
46 #ifdef DBG_UTIL
47 catch(const css::uno::Exception& rEx)
49 static bool bMessage = true;
50 if(bMessage)
52 bMessage = false;
53 OString sMsg("CreateInstance with arguments exception: ");
54 sMsg += OString(rEx.Message.getStr(),
55 rEx.Message.getLength(),
56 RTL_TEXTENCODING_ASCII_US);
57 OSL_FAIL(sMsg.getStr());
60 #else
61 catch(css::uno::Exception&){}
62 #endif
65 ItemHolder2::~ItemHolder2()
67 impl_releaseAllItems();
70 void ItemHolder2::holdConfigItem(EItem eItem)
72 static ItemHolder2* pHolder = new ItemHolder2();
73 pHolder->impl_addItem(eItem);
76 void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
77 throw(css::uno::RuntimeException, std::exception)
79 impl_releaseAllItems();
82 void ItemHolder2::impl_addItem(EItem eItem)
84 ::osl::ResettableMutexGuard aLock(m_aLock);
86 TItems::const_iterator pIt;
87 for ( pIt = m_lItems.begin();
88 pIt != m_lItems.end() ;
89 ++pIt )
91 const TItemInfo& rInfo = *pIt;
92 if (rInfo.eItem == eItem)
93 return;
96 TItemInfo aNewItem;
97 aNewItem.eItem = eItem;
98 impl_newItem(aNewItem);
99 if (aNewItem.pItem)
100 m_lItems.push_back(aNewItem);
103 void ItemHolder2::impl_releaseAllItems()
105 ::osl::ResettableMutexGuard aLock(m_aLock);
107 TItems::iterator pIt;
108 for ( pIt = m_lItems.begin();
109 pIt != m_lItems.end() ;
110 ++pIt )
112 TItemInfo& rInfo = *pIt;
113 impl_deleteItem(rInfo);
115 m_lItems.clear();
118 void ItemHolder2::impl_newItem(TItemInfo& rItem)
120 switch(rItem.eItem)
122 case E_CJKOPTIONS :
123 rItem.pItem = new SvtCJKOptions();
124 break;
126 case E_CTLOPTIONS :
127 rItem.pItem = new SvtCTLOptions();
128 break;
130 case E_LANGUAGEOPTIONS :
131 // capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions();
132 break;
134 default:
135 OSL_ASSERT(false);
136 break;
140 void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
142 if (rItem.pItem)
144 delete rItem.pItem;
145 rItem.pItem = 0;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */