xref: /aoo41x/main/vcl/source/app/unohelp.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/tempfile.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/file.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <vcl/unohelp.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <svdata.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
43cdf0e10cSrcweir #include <com/sun/star/i18n/XCharacterClassification.hpp>
44cdf0e10cSrcweir #include <com/sun/star/i18n/XCollator.hpp>
45cdf0e10cSrcweir #include <com/sun/star/awt/XExtendedToolkit.hpp>
46cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
47cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
48cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir using namespace ::rtl;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir struct VCLRegServiceInfo
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	const sal_Char*		pLibName;
56cdf0e10cSrcweir 	sal_Bool			bHasSUPD;
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir static VCLRegServiceInfo aVCLComponentsArray[] =
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	{"i18n", sal_True},
62cdf0e10cSrcweir     {"i18npool", sal_True},
63cdf0e10cSrcweir #ifdef UNX
64cdf0e10cSrcweir #ifdef MACOSX
65cdf0e10cSrcweir 	{"dtransaqua", sal_True},
66cdf0e10cSrcweir #else
67cdf0e10cSrcweir 	{"dtransX11", sal_True},
68cdf0e10cSrcweir #endif
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir #if defined(WNT) || defined(OS2)
71cdf0e10cSrcweir 	{"sysdtrans", sal_False},
72cdf0e10cSrcweir #endif
73cdf0e10cSrcweir 	{"dtrans", sal_False},
74cdf0e10cSrcweir 	{"mcnttype", sal_False},
75cdf0e10cSrcweir 	{"ftransl", sal_False},
76cdf0e10cSrcweir 	{"dnd", sal_False},
77cdf0e10cSrcweir 	{NULL, sal_False}
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
GetMultiServiceFactory()80cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > vcl::unohelper::GetMultiServiceFactory()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	ImplSVData* pSVData = ImplGetSVData();
83cdf0e10cSrcweir 	if ( !pSVData->maAppData.mxMSF.is() )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		pSVData->maAppData.mxMSF = ::comphelper::getProcessServiceFactory();
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 	if ( !pSVData->maAppData.mxMSF.is() )
88cdf0e10cSrcweir 	{
89cdf0e10cSrcweir 		TempFile aTempFile;
90cdf0e10cSrcweir 		OUString aTempFileName;
91cdf0e10cSrcweir 		osl::FileBase::getSystemPathFromFileURL( aTempFile.GetName(), aTempFileName );
92cdf0e10cSrcweir 		pSVData->maAppData.mpMSFTempFileName = new String(aTempFileName);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         try
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             pSVData->maAppData.mxMSF = ::cppu::createRegistryServiceFactory( aTempFileName, rtl::OUString(), sal_False );
97cdf0e10cSrcweir             uno::Reference < registry::XImplementationRegistration > xReg(
98cdf0e10cSrcweir                 pSVData->maAppData.mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" )), uno::UNO_QUERY );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             if( xReg.is() )
101cdf0e10cSrcweir             {
102cdf0e10cSrcweir                 sal_Int32 nCompCount = 0;
103cdf0e10cSrcweir                 while ( aVCLComponentsArray[ nCompCount ].pLibName )
104cdf0e10cSrcweir                 {
105cdf0e10cSrcweir                     OUString aComponentPathString = CreateLibraryName( aVCLComponentsArray[ nCompCount ].pLibName,  aVCLComponentsArray[ nCompCount ].bHasSUPD );
106cdf0e10cSrcweir                     if (aComponentPathString.getLength() )
107cdf0e10cSrcweir                     {
108cdf0e10cSrcweir                         try
109cdf0e10cSrcweir                         {
110cdf0e10cSrcweir                             xReg->registerImplementation(
111cdf0e10cSrcweir                                 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),aComponentPathString, NULL );
112cdf0e10cSrcweir                         }
113cdf0e10cSrcweir                         catch( ::com::sun::star::uno::Exception & )
114cdf0e10cSrcweir                         {
115cdf0e10cSrcweir                         }
116cdf0e10cSrcweir                     }
117cdf0e10cSrcweir                     nCompCount++;
118cdf0e10cSrcweir                 }
119cdf0e10cSrcweir             }
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         catch( ::com::sun::star::uno::Exception & )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             delete pSVData->maAppData.mpMSFTempFileName;
124cdf0e10cSrcweir             pSVData->maAppData.mpMSFTempFileName = NULL;
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 	return pSVData->maAppData.mxMSF;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
CreateBreakIterator()131cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	uno::Reference < i18n::XBreakIterator > xB;
134cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
135cdf0e10cSrcweir 	if ( xMSF.is() )
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) );
138cdf0e10cSrcweir 		if ( xI.is() )
139cdf0e10cSrcweir 		{
140cdf0e10cSrcweir 			uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XBreakIterator >*)0) );
141cdf0e10cSrcweir 			x >>= xB;
142cdf0e10cSrcweir 		}
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir 	return xB;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
CreateCharacterClassification()147cdf0e10cSrcweir uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	uno::Reference < i18n::XCharacterClassification > xB;
150cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
151cdf0e10cSrcweir 	if ( xMSF.is() )
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.CharacterClassification" ) );
154cdf0e10cSrcweir 		if ( xI.is() )
155cdf0e10cSrcweir 		{
156cdf0e10cSrcweir 			uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCharacterClassification >*)0) );
157cdf0e10cSrcweir 			x >>= xB;
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 	return xB;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
CreateCollator()163cdf0e10cSrcweir uno::Reference < i18n::XCollator > vcl::unohelper::CreateCollator()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	uno::Reference < i18n::XCollator > xB;
166cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
167cdf0e10cSrcweir 	if ( xMSF.is() )
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) );
170cdf0e10cSrcweir 		if ( xI.is() )
171cdf0e10cSrcweir 		{
172cdf0e10cSrcweir 			uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCollator >*)0) );
173cdf0e10cSrcweir 			x >>= xB;
174cdf0e10cSrcweir 		}
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 	return xB;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
CreateLibraryName(const sal_Char * pModName,sal_Bool bSUPD)179cdf0e10cSrcweir ::rtl::OUString vcl::unohelper::CreateLibraryName( const sal_Char* pModName, sal_Bool bSUPD )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	// create variable library name suffixes
182885b220bSHerbert Dürr 	OUString aDLLSuffix; //= OUString::createFromAscii( STRING(DLLPOSTFIX) );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	OUString aLibName;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir #if defined( WNT) || defined(OS2)
187cdf0e10cSrcweir 	aLibName = OUString::createFromAscii( pModName );
188cdf0e10cSrcweir 	if ( bSUPD )
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		aLibName += aDLLSuffix;
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir 	aLibName += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dll" ));
193cdf0e10cSrcweir #else
194cdf0e10cSrcweir 	aLibName = OUString( RTL_CONSTASCII_USTRINGPARAM( "lib" ));
195cdf0e10cSrcweir 	aLibName += OUString::createFromAscii( pModName );
196cdf0e10cSrcweir 	if ( bSUPD )
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		aLibName += aDLLSuffix;
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir #ifdef MACOSX
201cdf0e10cSrcweir 	aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".dylib" ));
202cdf0e10cSrcweir #else
203cdf0e10cSrcweir 	aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".so" ));
204cdf0e10cSrcweir #endif
205cdf0e10cSrcweir #endif
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	return aLibName;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
NotifyAccessibleStateEventGlobally(const::com::sun::star::accessibility::AccessibleEventObject & rEventObject)210cdf0e10cSrcweir void vcl::unohelper::NotifyAccessibleStateEventGlobally( const ::com::sun::star::accessibility::AccessibleEventObject& rEventObject )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XExtendedToolkit > xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY );
213cdf0e10cSrcweir     if ( xExtToolkit.is() )
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         // Only for focus events
216cdf0e10cSrcweir         sal_Int16 nType = ::com::sun::star::accessibility::AccessibleStateType::INVALID;
217cdf0e10cSrcweir         rEventObject.NewValue >>= nType;
218cdf0e10cSrcweir         if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED )
219cdf0e10cSrcweir             xExtToolkit->fireFocusGained( rEventObject.Source );
220cdf0e10cSrcweir         else
221cdf0e10cSrcweir         {
222cdf0e10cSrcweir             rEventObject.OldValue >>= nType;
223cdf0e10cSrcweir             if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED )
224cdf0e10cSrcweir                 xExtToolkit->fireFocusLost( rEventObject.Source );
225cdf0e10cSrcweir         }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir }
229