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