1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unohelp.cxx,v $
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>
44 #include <com/sun/star/i18n/XCharacterClassification.hpp>
46 #ifndef _COM_SUN_STAR_UTIL_XCOLLATOR_HPP_
47 #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>
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
;
76 static VCLRegServiceInfo aVCLComponentsArray
[] =
79 {"i18npool", sal_True
},
82 {"dtransaqua", sal_True
},
84 {"dtransX11", sal_True
},
87 #if defined(WNT) || defined(OS2)
88 {"sysdtrans", sal_False
},
90 {"dtrans", sal_False
},
91 {"mcnttype", sal_False
},
92 {"ftransl", 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() )
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
);
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
& )
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();
154 uno::Reference
< uno::XInterface
> xI
= xMSF
->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) );
157 uno::Any x
= xI
->queryInterface( ::getCppuType((const uno::Reference
< i18n::XBreakIterator
>*)0) );
164 uno::Reference
< i18n::XCharacterClassification
> vcl::unohelper::CreateCharacterClassification()
166 uno::Reference
< i18n::XCharacterClassification
> xB
;
167 uno::Reference
< lang::XMultiServiceFactory
> xMSF
= GetMultiServiceFactory();
170 uno::Reference
< uno::XInterface
> xI
= xMSF
->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.CharacterClassification" ) );
173 uno::Any x
= xI
->queryInterface( ::getCppuType((const uno::Reference
< i18n::XCharacterClassification
>*)0) );
180 uno::Reference
< i18n::XCollator
> vcl::unohelper::CreateCollator()
182 uno::Reference
< i18n::XCollator
> xB
;
183 uno::Reference
< lang::XMultiServiceFactory
> xMSF
= GetMultiServiceFactory();
186 uno::Reference
< uno::XInterface
> xI
= xMSF
->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) );
189 uno::Any x
= xI
->queryInterface( ::getCppuType((const uno::Reference
< i18n::XCollator
>*)0) );
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
) );
203 #if defined( WNT) || defined(OS2)
204 aLibName
= OUString::createFromAscii( pModName
);
207 aLibName
+= aDLLSuffix
;
209 aLibName
+= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dll" ));
211 aLibName
= OUString( RTL_CONSTASCII_USTRINGPARAM( "lib" ));
212 aLibName
+= OUString::createFromAscii( pModName
);
215 aLibName
+= aDLLSuffix
;
218 aLibName
+= OUString( RTL_CONSTASCII_USTRINGPARAM( ".dylib" ));
220 aLibName
+= OUString( RTL_CONSTASCII_USTRINGPARAM( ".so" ));
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
);
239 rEventObject
.OldValue
>>= nType
;
240 if ( nType
== ::com::sun::star::accessibility::AccessibleStateType::FOCUSED
)
241 xExtToolkit
->fireFocusLost( rEventObject
.Source
);