xref: /trunk/main/vcl/source/app/unohelp.cxx (revision db7807d9)
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 
55 using namespace ::com::sun::star;
56 using namespace ::rtl;
57 
58 #define STRING( x ) #x ""
59 
60 struct VCLRegServiceInfo
61 {
62 	const sal_Char*		pLibName;
63 	sal_Bool			bHasSUPD;
64 };
65 
66 static VCLRegServiceInfo aVCLComponentsArray[] =
67 {
68 	{"i18n", sal_True},
69     {"i18npool", sal_True},
70 #ifdef UNX
71 #ifdef MACOSX
72 	{"dtransaqua", sal_True},
73 #else
74 	{"dtransX11", sal_True},
75 #endif
76 #endif
77 #if defined(WNT) || defined(OS2)
78 	{"sysdtrans", sal_False},
79 #endif
80 	{"dtrans", sal_False},
81 	{"mcnttype", sal_False},
82 	{"ftransl", sal_False},
83 	{"dnd", sal_False},
84 	{NULL, sal_False}
85 };
86 
87 uno::Reference< lang::XMultiServiceFactory > vcl::unohelper::GetMultiServiceFactory()
88 {
89 	ImplSVData* pSVData = ImplGetSVData();
90 	if ( !pSVData->maAppData.mxMSF.is() )
91 	{
92 		pSVData->maAppData.mxMSF = ::comphelper::getProcessServiceFactory();
93 	}
94 	if ( !pSVData->maAppData.mxMSF.is() )
95 	{
96 		TempFile aTempFile;
97 		OUString aTempFileName;
98 		osl::FileBase::getSystemPathFromFileURL( aTempFile.GetName(), aTempFileName );
99 		pSVData->maAppData.mpMSFTempFileName = new String(aTempFileName);
100 
101         try
102         {
103             pSVData->maAppData.mxMSF = ::cppu::createRegistryServiceFactory( aTempFileName, rtl::OUString(), sal_False );
104             uno::Reference < registry::XImplementationRegistration > xReg(
105                 pSVData->maAppData.mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" )), uno::UNO_QUERY );
106 
107             if( xReg.is() )
108             {
109                 sal_Int32 nCompCount = 0;
110                 while ( aVCLComponentsArray[ nCompCount ].pLibName )
111                 {
112                     OUString aComponentPathString = CreateLibraryName( aVCLComponentsArray[ nCompCount ].pLibName,  aVCLComponentsArray[ nCompCount ].bHasSUPD );
113                     if (aComponentPathString.getLength() )
114                     {
115                         try
116                         {
117                             xReg->registerImplementation(
118                                 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),aComponentPathString, NULL );
119                         }
120                         catch( ::com::sun::star::uno::Exception & )
121                         {
122                         }
123                     }
124                     nCompCount++;
125                 }
126             }
127         }
128         catch( ::com::sun::star::uno::Exception & )
129         {
130             delete pSVData->maAppData.mpMSFTempFileName;
131             pSVData->maAppData.mpMSFTempFileName = NULL;
132         }
133 	}
134 	return pSVData->maAppData.mxMSF;
135 }
136 
137 
138 uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
139 {
140 	uno::Reference < i18n::XBreakIterator > xB;
141 	uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
142 	if ( xMSF.is() )
143 	{
144 		uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) );
145 		if ( xI.is() )
146 		{
147 			uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XBreakIterator >*)0) );
148 			x >>= xB;
149 		}
150 	}
151 	return xB;
152 }
153 
154 uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
155 {
156 	uno::Reference < i18n::XCharacterClassification > xB;
157 	uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
158 	if ( xMSF.is() )
159 	{
160 		uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.CharacterClassification" ) );
161 		if ( xI.is() )
162 		{
163 			uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCharacterClassification >*)0) );
164 			x >>= xB;
165 		}
166 	}
167 	return xB;
168 }
169 
170 uno::Reference < i18n::XCollator > vcl::unohelper::CreateCollator()
171 {
172 	uno::Reference < i18n::XCollator > xB;
173 	uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory();
174 	if ( xMSF.is() )
175 	{
176 		uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) );
177 		if ( xI.is() )
178 		{
179 			uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCollator >*)0) );
180 			x >>= xB;
181 		}
182 	}
183 	return xB;
184 }
185 
186 ::rtl::OUString vcl::unohelper::CreateLibraryName( const sal_Char* pModName, sal_Bool bSUPD )
187 {
188 	// create variable library name suffixes
189 	OUString aDLLSuffix = OUString::createFromAscii( STRING(DLLPOSTFIX) );
190 
191 	OUString aLibName;
192 
193 #if defined( WNT) || defined(OS2)
194 	aLibName = OUString::createFromAscii( pModName );
195 	if ( bSUPD )
196 	{
197 		aLibName += aDLLSuffix;
198 	}
199 	aLibName += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dll" ));
200 #else
201 	aLibName = OUString( RTL_CONSTASCII_USTRINGPARAM( "lib" ));
202 	aLibName += OUString::createFromAscii( pModName );
203 	if ( bSUPD )
204 	{
205 		aLibName += aDLLSuffix;
206 	}
207 #ifdef MACOSX
208 	aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".dylib" ));
209 #else
210 	aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".so" ));
211 #endif
212 #endif
213 
214 	return aLibName;
215 }
216 
217 void vcl::unohelper::NotifyAccessibleStateEventGlobally( const ::com::sun::star::accessibility::AccessibleEventObject& rEventObject )
218 {
219     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XExtendedToolkit > xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY );
220     if ( xExtToolkit.is() )
221     {
222         // Only for focus events
223         sal_Int16 nType = ::com::sun::star::accessibility::AccessibleStateType::INVALID;
224         rEventObject.NewValue >>= nType;
225         if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED )
226             xExtToolkit->fireFocusGained( rEventObject.Source );
227         else
228         {
229             rEventObject.OldValue >>= nType;
230             if ( nType == ::com::sun::star::accessibility::AccessibleStateType::FOCUSED )
231                 xExtToolkit->fireFocusLost( rEventObject.Source );
232         }
233 
234     }
235 }
236