update dev300-m58
[ooovba.git] / vcl / source / app / unohelp.cxx
blob541c2d1b36fcdae94469ac22e09e8a76efe7b984
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unohelp.cxx,v $
10 * $Revision: 1.38 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
36 #include <vcl/unohelp.hxx>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <comphelper/processfactory.hxx>
41 #ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
42 #include <com/sun/star/i18n/XBreakIterator.hpp>
43 #endif
44 #include <com/sun/star/i18n/XCharacterClassification.hpp>
46 #ifndef _COM_SUN_STAR_UTIL_XCOLLATOR_HPP_
47 #include <com/sun/star/i18n/XCollator.hpp>
48 #endif
49 #include <com/sun/star/awt/XExtendedToolkit.hpp>
50 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
51 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
54 #include <com/sun/star/registry/XImplementationRegistration.hpp>
56 #include <cppuhelper/servicefactory.hxx>
58 #include <tools/tempfile.hxx>
59 #include <osl/file.hxx>
61 #include <vcl/svdata.hxx>
62 #include <vcl/svapp.hxx>
64 using namespace ::com::sun::star;
65 using namespace ::rtl;
67 #define DOSTRING( x ) #x
68 #define STRING( x ) DOSTRING( x )
70 struct VCLRegServiceInfo
72 const sal_Char* pLibName;
73 sal_Bool bHasSUPD;
76 static VCLRegServiceInfo aVCLComponentsArray[] =
78 {"i18n", sal_True},
79 {"i18npool", sal_True},
80 #ifdef UNX
81 #ifdef MACOSX
82 {"dtransaqua", sal_True},
83 #else
84 {"dtransX11", sal_True},
85 #endif
86 #endif
87 #if defined(WNT) || defined(OS2)
88 {"sysdtrans", sal_False},
89 #endif
90 {"dtrans", sal_False},
91 {"mcnttype", sal_False},
92 {"ftransl", sal_False},
93 {"dnd", sal_False},
94 {NULL, sal_False}
97 uno::Reference< lang::XMultiServiceFactory > vcl::unohelper::GetMultiServiceFactory()
99 ImplSVData* pSVData = ImplGetSVData();
100 if ( !pSVData->maAppData.mxMSF.is() )
102 pSVData->maAppData.mxMSF = ::comphelper::getProcessServiceFactory();
104 if ( !pSVData->maAppData.mxMSF.is() )
106 TempFile aTempFile;
107 OUString aTempFileName;
108 osl::FileBase::getSystemPathFromFileURL( aTempFile.GetName(), aTempFileName );
109 pSVData->maAppData.mpMSFTempFileName = new String(aTempFileName);
113 pSVData->maAppData.mxMSF = ::cppu::createRegistryServiceFactory( aTempFileName, rtl::OUString(), sal_False );
114 uno::Reference < registry::XImplementationRegistration > xReg(
115 pSVData->maAppData.mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" )), uno::UNO_QUERY );
117 if( xReg.is() )
119 sal_Int32 nCompCount = 0;
120 while ( aVCLComponentsArray[ nCompCount ].pLibName )
122 OUString aComponentPathString = CreateLibraryName( aVCLComponentsArray[ nCompCount ].pLibName, aVCLComponentsArray[ nCompCount ].bHasSUPD );
123 if (aComponentPathString.getLength() )
127 xReg->registerImplementation(
128 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),aComponentPathString, NULL );
130 catch( ::com::sun::star::uno::Exception & )
134 nCompCount++;
138 catch( ::com::sun::star::uno::Exception & )
140 delete pSVData->maAppData.mpMSFTempFileName;
141 pSVData->maAppData.mpMSFTempFileName = NULL;
144 return pSVData->maAppData.mxMSF;
148 uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
150 uno::Reference < i18n::XBreakIterator > xB;
151 uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
152 if ( xMSF.is() )
154 uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) );
155 if ( xI.is() )
157 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XBreakIterator >*)0) );
158 x >>= xB;
161 return xB;
164 uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
166 uno::Reference < i18n::XCharacterClassification > xB;
167 uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
168 if ( xMSF.is() )
170 uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.CharacterClassification" ) );
171 if ( xI.is() )
173 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCharacterClassification >*)0) );
174 x >>= xB;
177 return xB;
180 uno::Reference < i18n::XCollator > vcl::unohelper::CreateCollator()
182 uno::Reference < i18n::XCollator > xB;
183 uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
184 if ( xMSF.is() )
186 uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) );
187 if ( xI.is() )
189 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCollator >*)0) );
190 x >>= xB;
193 return xB;
196 ::rtl::OUString vcl::unohelper::CreateLibraryName( const sal_Char* pModName, BOOL bSUPD )
198 // create variable library name suffixes
199 OUString aDLLSuffix = OUString::createFromAscii( STRING(DLLPOSTFIX) );
201 OUString aLibName;
203 #if defined( WNT) || defined(OS2)
204 aLibName = OUString::createFromAscii( pModName );
205 if ( bSUPD )
207 aLibName += aDLLSuffix;
209 aLibName += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dll" ));
210 #else
211 aLibName = OUString( RTL_CONSTASCII_USTRINGPARAM( "lib" ));
212 aLibName += OUString::createFromAscii( pModName );
213 if ( bSUPD )
215 aLibName += aDLLSuffix;
217 #ifdef MACOSX
218 aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".dylib" ));
219 #else
220 aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".so" ));
221 #endif
222 #endif
224 return aLibName;
227 void vcl::unohelper::NotifyAccessibleStateEventGlobally( const ::com::sun::star::accessibility::AccessibleEventObject& rEventObject )
229 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XExtendedToolkit > xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY );
230 if ( xExtToolkit.is() )
232 // Only for focus events
233 sal_Int16 nType = ::com::sun::star::accessibility::AccessibleStateType::INVALID;
234 rEventObject.NewValue >>= nType;
235 if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED )
236 xExtToolkit->fireFocusGained( rEventObject.Source );
237 else
239 rEventObject.OldValue >>= nType;
240 if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED )
241 xExtToolkit->fireFocusLost( rEventObject.Source );