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: svdata.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"
38 #include <vcl/salinst.hxx>
39 #include <vcl/salframe.hxx>
41 #ifndef _VOS_MUTEX_HXX
42 #include <vos/mutex.hxx>
45 #include <osl/process.h>
46 #include <osl/file.hxx>
47 #include <uno/current_context.hxx>
48 #include <cppuhelper/implbase1.hxx>
49 #include <tools/debug.hxx>
50 #include <vcl/fontcfg.hxx>
51 #include <vcl/configsettings.hxx>
52 #include <vcl/svdata.hxx>
53 #include <vcl/window.h>
54 #include <vcl/svapp.hxx>
55 #include <vcl/wrkwin.hxx>
56 #include <vcl/msgbox.hxx>
57 #include <vcl/unohelp.hxx>
58 #include <vcl/button.hxx> // for Button::GetStandardText
59 #include <vcl/dockwin.hxx> // for DockingManager
60 #include <vcl/salimestatus.hxx>
61 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
62 #include <com/sun/star/awt/XExtendedToolkit.hpp>
63 #include <com/sun/star/java/JavaNotConfiguredException.hpp>
64 #include <com/sun/star/java/JavaVMCreationFailureException.hpp>
65 #include <com/sun/star/java/MissingJavaRuntimeException.hpp>
66 #include <com/sun/star/java/JavaDisabledException.hpp>
68 #include <com/sun/star/lang/XComponent.hpp>
71 #include <vcl/salsys.hxx>
72 #include <vcl/svids.hrc>
73 #include <rtl/instance.hxx>
75 using namespace com::sun::star::uno
;
76 using namespace com::sun::star::lang
;
77 using namespace com::sun::star::awt
;
80 // =======================================================================
84 struct private_aImplSVData
:
85 public rtl::Static
<ImplSVData
, private_aImplSVData
> {};
89 ImplSVData
* pImplSVData
= NULL
;
91 SalSystem
* ImplGetSalSystem()
93 ImplSVData
* pSVData
= ImplGetSVData();
94 if( ! pSVData
->mpSalSystem
)
95 pSVData
->mpSalSystem
= pSVData
->mpDefInst
->CreateSalSystem();
96 return pSVData
->mpSalSystem
;
100 static String
& ReplaceJavaErrorMessages( String
& rString
)
102 rString
.SearchAndReplaceAllAscii( "%OK", Button::GetStandardText( BUTTON_OK
) );
103 rString
.SearchAndReplaceAllAscii( "%IGNORE", Button::GetStandardText( BUTTON_IGNORE
) );
104 rString
.SearchAndReplaceAllAscii( "%CANCEL", Button::GetStandardText( BUTTON_CANCEL
) );
109 // =======================================================================
111 void ImplInitSVData()
113 pImplSVData
= &private_aImplSVData::get();
115 // init global instance data
116 memset( pImplSVData
, 0, sizeof( ImplSVData
) );
117 pImplSVData
->maHelpData
.mbAutoHelpId
= sal_True
;
118 pImplSVData
->maHelpData
.mbAutoHelpId
= sal_True
;
119 pImplSVData
->maNWFData
.maMenuBarHighlightTextColor
= Color( COL_TRANSPARENT
);
121 // find out whether we are running in the testtool
122 // in this case we need some special workarounds
123 sal_uInt32 nArgs
= osl_getCommandArgCount();
124 for( sal_uInt32 i
= 0; i
< nArgs
; i
++ )
127 osl_getCommandArg( i
, &aArg
.pData
);
128 if( aArg
.equalsAscii( "-enableautomation" ) )
130 pImplSVData
->mbIsTestTool
= true;
136 // -----------------------------------------------------------------------
138 void ImplDeInitSVData()
140 ImplSVData
* pSVData
= ImplGetSVData();
142 // delete global instance data
143 if( pSVData
->mpSettingsConfigItem
)
144 delete pSVData
->mpSettingsConfigItem
;
146 if( pSVData
->mpDockingManager
)
147 delete pSVData
->mpDockingManager
;
149 if( pSVData
->maGDIData
.mpDefaultFontConfiguration
)
150 delete pSVData
->maGDIData
.mpDefaultFontConfiguration
;
151 if( pSVData
->maGDIData
.mpFontSubstConfiguration
)
152 delete pSVData
->maGDIData
.mpFontSubstConfiguration
;
154 if ( pSVData
->maAppData
.mpMSFTempFileName
)
156 if ( pSVData
->maAppData
.mxMSF
.is() )
158 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
> xComp( pSVData
->maAppData
.mxMSF
, ::com::sun::star::uno::UNO_QUERY
);
160 pSVData
->maAppData
.mxMSF
= NULL
;
163 ::rtl::OUString aFileUrl
;
164 ::osl::File::getFileURLFromSystemPath( *pSVData
->maAppData
.mpMSFTempFileName
, aFileUrl
);
165 osl::File::remove( aFileUrl
);
166 delete pSVData
->maAppData
.mpMSFTempFileName
;
167 pSVData
->maAppData
.mpMSFTempFileName
= NULL
;
171 // -----------------------------------------------------------------------
173 void ImplDestroySVData()
178 // -----------------------------------------------------------------------
180 Window
* ImplGetDefaultWindow()
182 ImplSVData
* pSVData
= ImplGetSVData();
183 if ( pSVData
->maWinData
.mpAppWin
)
184 return pSVData
->maWinData
.mpAppWin
;
186 // First test if we already have a default window.
187 // Don't only place a single if..else inside solar mutex lockframe
188 // because then we might have to wait for the solar mutex what is not neccessary
189 // if we already have a default window.
191 if ( !pSVData
->mpDefaultWin
)
193 Application::GetSolarMutex().acquire();
195 // Test again because the thread who released the solar mutex could have called
198 if ( !pSVData
->mpDefaultWin
&& !pSVData
->mbDeInit
)
200 DBG_WARNING( "ImplGetDefaultWindow(): No AppWindow" );
201 pSVData
->mpDefaultWin
= new WorkWindow( 0, WB_DEFAULTWIN
);
202 pSVData
->mpDefaultWin
->SetText( OUString( RTL_CONSTASCII_USTRINGPARAM( "VCL ImplGetDefaultWindow" ) ) );
204 Application::GetSolarMutex().release();
207 return pSVData
->mpDefaultWin
;
210 // -----------------------------------------------------------------------
212 #define VCL_CREATERESMGR_NAME( Name ) #Name
214 ResMgr
* ImplGetResMgr()
216 ImplSVData
* pSVData
= ImplGetSVData();
217 if ( !pSVData
->mpResMgr
)
219 ::com::sun::star::lang::Locale aLocale
= Application::GetSettings().GetUILocale();
220 pSVData
->mpResMgr
= ResMgr::SearchCreateResMgr( VCL_CREATERESMGR_NAME( vcl
), aLocale
);
222 static bool bMessageOnce
= false;
223 if( !pSVData
->mpResMgr
&& ! bMessageOnce
)
227 "Missing vcl resource. This indicates that files vital to localization are missing. "
228 "You might have a corrupt installation.";
229 fprintf( stderr
, "%s\n", pMsg
);
230 ErrorBox
aBox( NULL
, WB_OK
| WB_DEF_OK
, rtl::OUString( pMsg
, strlen( pMsg
), RTL_TEXTENCODING_ASCII_US
) );
234 return pSVData
->mpResMgr
;
237 DockingManager
* ImplGetDockingManager()
239 ImplSVData
* pSVData
= ImplGetSVData();
240 if ( !pSVData
->mpDockingManager
)
241 pSVData
->mpDockingManager
= new DockingManager();
243 return pSVData
->mpDockingManager
;
246 class AccessBridgeCurrentContext
: public cppu::WeakImplHelper1
< com::sun::star::uno::XCurrentContext
>
249 AccessBridgeCurrentContext(
250 const com::sun::star::uno::Reference
< com::sun::star::uno::XCurrentContext
> &context
) :
251 m_prevContext( context
) {}
254 virtual com::sun::star::uno::Any SAL_CALL
getValueByName( const rtl::OUString
& Name
)
255 throw (com::sun::star::uno::RuntimeException
);
257 com::sun::star::uno::Reference
< com::sun::star::uno::XCurrentContext
> m_prevContext
;
260 com::sun::star::uno::Any
AccessBridgeCurrentContext::getValueByName( const rtl::OUString
& Name
)
261 throw (com::sun::star::uno::RuntimeException
)
263 com::sun::star::uno::Any ret
;
264 if( Name
.equalsAscii( "java-vm.interaction-handler" ) )
266 // Currently, for accessbility no interaction handler shall be offered.
267 // There may be introduced later on a handler using native toolkits
268 // jbu->obr: Instantiate here your interaction handler
270 else if( m_prevContext
.is() )
272 ret
= m_prevContext
->getValueByName( Name
);
278 bool ImplInitAccessBridge(BOOL bAllowCancel
, BOOL
&rCancelled
)
282 bool bErrorMessage
= true;
285 // if bAllowCancel is TRUE we were called from application startup
286 // where we will disable any Java errorboxes and show our own accessibility dialog if Java throws an exception
287 // if bAllowCancel is FALSE we were called from Tools->Options
288 // where we will see Java errorboxes, se we do not show our dialogs in addition to Java's
292 bool bSuccess
= true;
294 // No error messages when env var is set ..
295 static const char* pEnv
= getenv("SAL_ACCESSIBILITY_ENABLED" );
298 bErrorMessage
= false;
301 ImplSVData
* pSVData
= ImplGetSVData();
302 if( ! pSVData
->mxAccessBridge
.is() )
304 Reference
< XMultiServiceFactory
> xFactory(vcl::unohelper::GetMultiServiceFactory());
308 Reference
< XExtendedToolkit
> xToolkit
=
309 Reference
< XExtendedToolkit
>(Application::GetVCLToolkit(), UNO_QUERY
);
311 Sequence
< Any
> arguments(1);
312 arguments
[0] = makeAny(xToolkit
);
314 // Disable default java error messages on startup, because they were probably unreadable
315 // for a disabled user. Use native message boxes which are accessible without java support.
316 // No need to do this when activated by Tools-Options dialog ..
319 // customize the java-not-available-interaction-handler entry within the
320 // current context when called at startup.
321 com::sun::star::uno::ContextLayer
layer(
322 new AccessBridgeCurrentContext( com::sun::star::uno::getCurrentContext() ) );
324 pSVData
->mxAccessBridge
= xFactory
->createInstanceWithArguments(
325 OUString::createFromAscii( "com.sun.star.accessibility.AccessBridge" ),
331 pSVData
->mxAccessBridge
= xFactory
->createInstanceWithArguments(
332 OUString::createFromAscii( "com.sun.star.accessibility.AccessBridge" ),
337 if( !pSVData
->mxAccessBridge
.is() )
345 catch(::com::sun::star::java::JavaNotConfiguredException e
)
347 ResMgr
*pResMgr
= ImplGetResMgr();
348 if( bErrorMessage
&& bAllowCancel
&& pResMgr
)
350 String
aTitle(ResId(SV_ACCESSERROR_JAVA_NOT_CONFIGURED
, *pResMgr
));
351 String
aMessage(ResId(SV_ACCESSERROR_JAVA_MSG
, *pResMgr
));
353 aMessage
+= String(" ", 1, RTL_TEXTENCODING_ASCII_US
);
354 aMessage
+= String(ResId(SV_ACCESSERROR_OK_CANCEL_MSG
, *pResMgr
));
356 int ret
= ImplGetSalSystem()->ShowNativeMessageBox(
358 ReplaceJavaErrorMessages(aMessage
),
359 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
,
360 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
);
362 // Do not change the setting in case the user chooses to cancel
363 if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
== ret
)
370 catch(::com::sun::star::java::JavaVMCreationFailureException e
)
372 ResMgr
*pResMgr
= ImplGetResMgr();
373 if( bErrorMessage
&& bAllowCancel
&& pResMgr
)
375 String
aTitle(ResId(SV_ACCESSERROR_FAULTY_JAVA
, *pResMgr
));
376 String
aMessage(ResId(SV_ACCESSERROR_JAVA_MSG
, *pResMgr
));
378 aMessage
+= String(" ", 1, RTL_TEXTENCODING_ASCII_US
);
379 aMessage
+= String(ResId(SV_ACCESSERROR_OK_CANCEL_MSG
, *pResMgr
));
381 int ret
= ImplGetSalSystem()->ShowNativeMessageBox(
383 ReplaceJavaErrorMessages(aMessage
),
384 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
,
385 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
);
387 // Do not change the setting in case the user chooses to cancel
388 if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
== ret
)
395 catch(::com::sun::star::java::MissingJavaRuntimeException e
)
397 ResMgr
*pResMgr
= ImplGetResMgr();
398 if( bErrorMessage
&& bAllowCancel
&& pResMgr
)
400 String
aTitle(ResId(SV_ACCESSERROR_MISSING_JAVA
, *pResMgr
));
401 String
aMessage(ResId(SV_ACCESSERROR_JAVA_MSG
, *pResMgr
));
403 aMessage
+= String(" ", 1, RTL_TEXTENCODING_ASCII_US
);
404 aMessage
+= String(ResId(SV_ACCESSERROR_OK_CANCEL_MSG
, *pResMgr
));
406 int ret
= ImplGetSalSystem()->ShowNativeMessageBox(
408 ReplaceJavaErrorMessages(aMessage
),
409 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
,
410 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
);
412 // Do not change the setting in case the user chooses to cancel
413 if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
== ret
)
420 catch(::com::sun::star::java::JavaDisabledException e
)
422 ResMgr
*pResMgr
= ImplGetResMgr();
423 if( bErrorMessage
&& bAllowCancel
&& pResMgr
)
425 String
aTitle(ResId(SV_ACCESSERROR_JAVA_DISABLED
, *pResMgr
));
426 String
aMessage(ResId(SV_ACCESSERROR_JAVA_MSG
, *pResMgr
));
428 aMessage
+= String(" ", 1, RTL_TEXTENCODING_ASCII_US
);
429 aMessage
+= String(ResId(SV_ACCESSERROR_OK_CANCEL_MSG
, *pResMgr
));
431 int ret
= ImplGetSalSystem()->ShowNativeMessageBox(
433 ReplaceJavaErrorMessages(aMessage
),
434 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
,
435 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
);
437 // Do not change the setting in case the user chooses to cancel
438 if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
== ret
)
446 catch(::com::sun::star::uno::RuntimeException e
)
448 ResMgr
*pResMgr
= ImplGetResMgr();
449 if( bErrorMessage
&& pResMgr
)
452 String
aMessage(ResId(SV_ACCESSERROR_BRIDGE_MSG
, *pResMgr
));
454 if( 0 == e
.Message
.compareTo(::rtl::OUString::createFromAscii("ClassNotFound"), 13) )
456 aTitle
= String(ResId(SV_ACCESSERROR_MISSING_BRIDGE
, *pResMgr
));
458 else if( 0 == e
.Message
.compareTo(::rtl::OUString::createFromAscii("NoSuchMethod"), 12) )
460 aTitle
= String(ResId(SV_ACCESSERROR_WRONG_VERSION
, *pResMgr
));
463 if( aTitle
.Len() != 0 )
467 // Something went wrong initializing the Java AccessBridge (on Windows) during the
468 // startup. Since the office will be probably unusable for a disabled user, we offer
469 // to terminate directly.
470 aMessage
+= String(" ", 1, RTL_TEXTENCODING_ASCII_US
);
471 aMessage
+= String(ResId(SV_ACCESSERROR_OK_CANCEL_MSG
, *pResMgr
));
473 int ret
= ImplGetSalSystem()->ShowNativeMessageBox(
475 ReplaceJavaErrorMessages(aMessage
),
476 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
,
477 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
);
479 // Do not change the setting in case the user chooses to cancel
480 if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
== ret
)
485 // The user tried to activate accessibility support using Tools-Options dialog,
486 // so we don't offer to terminate here !
487 ImplGetSalSystem()->ShowNativeMessageBox(
489 ReplaceJavaErrorMessages(aMessage
),
490 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK
,
491 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK
);
505 // -----------------------------------------------------------------------
507 Window
* ImplFindWindow( const SalFrame
* pFrame
, Point
& rSalFramePos
)
509 ImplSVData
* pSVData
= ImplGetSVData();
510 Window
* pFrameWindow
= pSVData
->maWinData
.mpFirstFrame
;
511 while ( pFrameWindow
)
513 if ( pFrameWindow
->ImplGetFrame() == pFrame
)
515 Window
* pWindow
= pFrameWindow
->ImplFindWindow( rSalFramePos
);
517 pWindow
= pFrameWindow
->ImplGetWindow();
518 rSalFramePos
= pWindow
->ImplFrameToOutput( rSalFramePos
);
521 pFrameWindow
= pFrameWindow
->ImplGetFrameData()->mpNextFrame
;