1*40df464eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*40df464eSAndrew Rist * distributed with this work for additional information 6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance 9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*40df464eSAndrew Rist * software distributed under the License is distributed on an 15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the 17*40df464eSAndrew Rist * specific language governing permissions and limitations 18*40df464eSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*40df464eSAndrew Rist *************************************************************/ 21*40df464eSAndrew Rist 22*40df464eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "itemholder2.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir //----------------------------------------------- 30cdf0e10cSrcweir // includes 31cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 32cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <svl/cjkoptions.hxx> 35cdf0e10cSrcweir #include <svl/ctloptions.hxx> 36cdf0e10cSrcweir #include <svl/languageoptions.hxx> 37cdf0e10cSrcweir #include <unotools/options.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <tools/debug.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //----------------------------------------------- 42cdf0e10cSrcweir // namespaces 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace css = ::com::sun::star; 45cdf0e10cSrcweir 46cdf0e10cSrcweir //----------------------------------------------- 47cdf0e10cSrcweir // declarations 48cdf0e10cSrcweir 49cdf0e10cSrcweir //----------------------------------------------- ItemHolder2()50cdf0e10cSrcweirItemHolder2::ItemHolder2() 51cdf0e10cSrcweir : ItemHolderMutexBase() 52cdf0e10cSrcweir { 53cdf0e10cSrcweir try 54cdf0e10cSrcweir { 55cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 56cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > xCfg( 57cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), 58cdf0e10cSrcweir css::uno::UNO_QUERY); 59cdf0e10cSrcweir if (xCfg.is()) 60cdf0e10cSrcweir xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir // #i37892 got errorhandling from ConfigManager::GetConfigurationProvider() 63cdf0e10cSrcweir catch(css::uno::RuntimeException& rREx) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir throw rREx; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir #ifdef DBG_UTIL 68cdf0e10cSrcweir catch(css::uno::Exception& rEx) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir static sal_Bool bMessage = sal_True; 71cdf0e10cSrcweir if(bMessage) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir bMessage = sal_False; 74cdf0e10cSrcweir ::rtl::OString sMsg("CreateInstance with arguments exception: "); 75cdf0e10cSrcweir sMsg += ::rtl::OString(rEx.Message.getStr(), 76cdf0e10cSrcweir rEx.Message.getLength(), 77cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US); 78cdf0e10cSrcweir DBG_ERROR(sMsg.getStr()); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir } 81cdf0e10cSrcweir #else 82cdf0e10cSrcweir catch(css::uno::Exception&){} 83cdf0e10cSrcweir #endif 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir //----------------------------------------------- ~ItemHolder2()87cdf0e10cSrcweirItemHolder2::~ItemHolder2() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir impl_releaseAllItems(); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir //----------------------------------------------- holdConfigItem(EItem eItem)93cdf0e10cSrcweirvoid ItemHolder2::holdConfigItem(EItem eItem) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir static ItemHolder2* pHolder = new ItemHolder2(); 96cdf0e10cSrcweir pHolder->impl_addItem(eItem); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //----------------------------------------------- disposing(const css::lang::EventObject &)100cdf0e10cSrcweirvoid SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&) 101cdf0e10cSrcweir throw(css::uno::RuntimeException) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir impl_releaseAllItems(); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir //----------------------------------------------- impl_addItem(EItem eItem)107cdf0e10cSrcweirvoid ItemHolder2::impl_addItem(EItem eItem) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock); 110cdf0e10cSrcweir 111cdf0e10cSrcweir TItems::const_iterator pIt; 112cdf0e10cSrcweir for ( pIt = m_lItems.begin(); 113cdf0e10cSrcweir pIt != m_lItems.end() ; 114cdf0e10cSrcweir ++pIt ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir const TItemInfo& rInfo = *pIt; 117cdf0e10cSrcweir if (rInfo.eItem == eItem) 118cdf0e10cSrcweir return; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir TItemInfo aNewItem; 122cdf0e10cSrcweir aNewItem.eItem = eItem; 123cdf0e10cSrcweir impl_newItem(aNewItem); 124cdf0e10cSrcweir if (aNewItem.pItem) 125cdf0e10cSrcweir m_lItems.push_back(aNewItem); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir //----------------------------------------------- impl_releaseAllItems()129cdf0e10cSrcweirvoid ItemHolder2::impl_releaseAllItems() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock); 132cdf0e10cSrcweir 133cdf0e10cSrcweir TItems::iterator pIt; 134cdf0e10cSrcweir for ( pIt = m_lItems.begin(); 135cdf0e10cSrcweir pIt != m_lItems.end() ; 136cdf0e10cSrcweir ++pIt ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir TItemInfo& rInfo = *pIt; 139cdf0e10cSrcweir impl_deleteItem(rInfo); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir m_lItems.clear(); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir //----------------------------------------------- impl_newItem(TItemInfo & rItem)145cdf0e10cSrcweirvoid ItemHolder2::impl_newItem(TItemInfo& rItem) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir switch(rItem.eItem) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir case E_CJKOPTIONS : 150cdf0e10cSrcweir rItem.pItem = new SvtCJKOptions(); 151cdf0e10cSrcweir break; 152cdf0e10cSrcweir 153cdf0e10cSrcweir case E_CTLOPTIONS : 154cdf0e10cSrcweir rItem.pItem = new SvtCTLOptions(); 155cdf0e10cSrcweir break; 156cdf0e10cSrcweir 157cdf0e10cSrcweir case E_LANGUAGEOPTIONS : 158cdf0e10cSrcweir // capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions(); 159cdf0e10cSrcweir break; 160cdf0e10cSrcweir 161cdf0e10cSrcweir default: 162cdf0e10cSrcweir OSL_ASSERT(false); 163cdf0e10cSrcweir break; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir //----------------------------------------------- impl_deleteItem(TItemInfo & rItem)168cdf0e10cSrcweirvoid ItemHolder2::impl_deleteItem(TItemInfo& rItem) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if (rItem.pItem) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir delete rItem.pItem; 173cdf0e10cSrcweir rItem.pItem = 0; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176