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