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