1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 31 #include <tools/tempfile.hxx> 32 33 #include <osl/file.hxx> 34 35 #include <cppuhelper/servicefactory.hxx> 36 37 #include <vcl/svapp.hxx> 38 #include <vcl/unohelp.hxx> 39 40 #include <svdata.hxx> 41 42 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 43 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 44 #include <comphelper/processfactory.hxx> 45 46 #include <com/sun/star/i18n/XBreakIterator.hpp> 47 #include <com/sun/star/i18n/XCharacterClassification.hpp> 48 #include <com/sun/star/i18n/XCollator.hpp> 49 #include <com/sun/star/awt/XExtendedToolkit.hpp> 50 #include <com/sun/star/accessibility/AccessibleEventObject.hpp> 51 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 52 #include <com/sun/star/registry/XImplementationRegistration.hpp> 53 54 using namespace ::com::sun::star; 55 using namespace ::rtl; 56 57 struct VCLRegServiceInfo 58 { 59 const sal_Char* pLibName; 60 sal_Bool bHasSUPD; 61 }; 62 63 static VCLRegServiceInfo aVCLComponentsArray[] = 64 { 65 {"i18n", sal_True}, 66 {"i18npool", sal_True}, 67 #ifdef UNX 68 #ifdef MACOSX 69 {"dtransaqua", sal_True}, 70 #else 71 {"dtransX11", sal_True}, 72 #endif 73 #endif 74 #if defined(WNT) || defined(OS2) 75 {"sysdtrans", sal_False}, 76 #endif 77 {"dtrans", sal_False}, 78 {"mcnttype", sal_False}, 79 {"ftransl", sal_False}, 80 {"dnd", sal_False}, 81 {NULL, sal_False} 82 }; 83 84 uno::Reference< lang::XMultiServiceFactory > vcl::unohelper::GetMultiServiceFactory() 85 { 86 ImplSVData* pSVData = ImplGetSVData(); 87 if ( !pSVData->maAppData.mxMSF.is() ) 88 { 89 pSVData->maAppData.mxMSF = ::comphelper::getProcessServiceFactory(); 90 } 91 if ( !pSVData->maAppData.mxMSF.is() ) 92 { 93 TempFile aTempFile; 94 OUString aTempFileName; 95 osl::FileBase::getSystemPathFromFileURL( aTempFile.GetName(), aTempFileName ); 96 pSVData->maAppData.mpMSFTempFileName = new String(aTempFileName); 97 98 try 99 { 100 pSVData->maAppData.mxMSF = ::cppu::createRegistryServiceFactory( aTempFileName, rtl::OUString(), sal_False ); 101 uno::Reference < registry::XImplementationRegistration > xReg( 102 pSVData->maAppData.mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" )), uno::UNO_QUERY ); 103 104 if( xReg.is() ) 105 { 106 sal_Int32 nCompCount = 0; 107 while ( aVCLComponentsArray[ nCompCount ].pLibName ) 108 { 109 OUString aComponentPathString = CreateLibraryName( aVCLComponentsArray[ nCompCount ].pLibName, aVCLComponentsArray[ nCompCount ].bHasSUPD ); 110 if (aComponentPathString.getLength() ) 111 { 112 try 113 { 114 xReg->registerImplementation( 115 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),aComponentPathString, NULL ); 116 } 117 catch( ::com::sun::star::uno::Exception & ) 118 { 119 } 120 } 121 nCompCount++; 122 } 123 } 124 } 125 catch( ::com::sun::star::uno::Exception & ) 126 { 127 delete pSVData->maAppData.mpMSFTempFileName; 128 pSVData->maAppData.mpMSFTempFileName = NULL; 129 } 130 } 131 return pSVData->maAppData.mxMSF; 132 } 133 134 135 uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator() 136 { 137 uno::Reference < i18n::XBreakIterator > xB; 138 uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory(); 139 if ( xMSF.is() ) 140 { 141 uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ); 142 if ( xI.is() ) 143 { 144 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XBreakIterator >*)0) ); 145 x >>= xB; 146 } 147 } 148 return xB; 149 } 150 151 uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification() 152 { 153 uno::Reference < i18n::XCharacterClassification > xB; 154 uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory(); 155 if ( xMSF.is() ) 156 { 157 uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.CharacterClassification" ) ); 158 if ( xI.is() ) 159 { 160 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCharacterClassification >*)0) ); 161 x >>= xB; 162 } 163 } 164 return xB; 165 } 166 167 uno::Reference < i18n::XCollator > vcl::unohelper::CreateCollator() 168 { 169 uno::Reference < i18n::XCollator > xB; 170 uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory(); 171 if ( xMSF.is() ) 172 { 173 uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) ); 174 if ( xI.is() ) 175 { 176 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCollator >*)0) ); 177 x >>= xB; 178 } 179 } 180 return xB; 181 } 182 183 ::rtl::OUString vcl::unohelper::CreateLibraryName( const sal_Char* pModName, sal_Bool bSUPD ) 184 { 185 // create variable library name suffixes 186 OUString aDLLSuffix; //= OUString::createFromAscii( STRING(DLLPOSTFIX) ); 187 188 OUString aLibName; 189 190 #if defined( WNT) || defined(OS2) 191 aLibName = OUString::createFromAscii( pModName ); 192 if ( bSUPD ) 193 { 194 aLibName += aDLLSuffix; 195 } 196 aLibName += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dll" )); 197 #else 198 aLibName = OUString( RTL_CONSTASCII_USTRINGPARAM( "lib" )); 199 aLibName += OUString::createFromAscii( pModName ); 200 if ( bSUPD ) 201 { 202 aLibName += aDLLSuffix; 203 } 204 #ifdef MACOSX 205 aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".dylib" )); 206 #else 207 aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".so" )); 208 #endif 209 #endif 210 211 return aLibName; 212 } 213 214 void vcl::unohelper::NotifyAccessibleStateEventGlobally( const ::com::sun::star::accessibility::AccessibleEventObject& rEventObject ) 215 { 216 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XExtendedToolkit > xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY ); 217 if ( xExtToolkit.is() ) 218 { 219 // Only for focus events 220 sal_Int16 nType = ::com::sun::star::accessibility::AccessibleStateType::INVALID; 221 rEventObject.NewValue >>= nType; 222 if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED ) 223 xExtToolkit->fireFocusGained( rEventObject.Source ); 224 else 225 { 226 rEventObject.OldValue >>= nType; 227 if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED ) 228 xExtToolkit->fireFocusLost( rEventObject.Source ); 229 } 230 231 } 232 } 233