Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <string.h>
21 : #include <boost/ptr_container/ptr_vector.hpp>
22 :
23 : #include <comphelper/processfactory.hxx>
24 : #include <comphelper/string.hxx>
25 : #include <osl/mutex.hxx>
26 : #include <rtl/process.h>
27 : #include <tools/debug.hxx>
28 : #include <tools/resary.hxx>
29 : #include <tools/gen.hxx>
30 : #include <unotools/fontcfg.hxx>
31 : #include <cppuhelper/implbase1.hxx>
32 : #include <uno/current_context.hxx>
33 :
34 : #include "vcl/configsettings.hxx"
35 : #include "vcl/svapp.hxx"
36 : #include "vcl/wrkwin.hxx"
37 : #include "vcl/msgbox.hxx"
38 : #include "vcl/button.hxx" // for Button::GetStandardText
39 : #include "vcl/dockwin.hxx" // for DockingManager
40 : #include "salinst.hxx"
41 : #include "salframe.hxx"
42 : #include "svdata.hxx"
43 : #include "window.h"
44 : #include "salimestatus.hxx"
45 : #include "salsys.hxx"
46 : #include "svids.hrc"
47 :
48 : #include "com/sun/star/accessibility/AccessBridge.hpp"
49 : #include "com/sun/star/awt/XExtendedToolkit.hpp"
50 : #include "com/sun/star/java/JavaNotConfiguredException.hpp"
51 : #include "com/sun/star/java/JavaVMCreationFailureException.hpp"
52 : #include "com/sun/star/java/MissingJavaRuntimeException.hpp"
53 : #include "com/sun/star/java/JavaDisabledException.hpp"
54 :
55 : #include <stdio.h>
56 :
57 : using namespace com::sun::star::uno;
58 : using namespace com::sun::star::lang;
59 : using namespace com::sun::star::awt;
60 :
61 : // =======================================================================
62 :
63 : namespace
64 : {
65 : struct private_aImplSVData :
66 : public rtl::Static<ImplSVData, private_aImplSVData> {};
67 : }
68 :
69 : // static SV-Data
70 : ImplSVData* pImplSVData = NULL;
71 :
72 6886 : SalSystem* ImplGetSalSystem()
73 : {
74 6886 : ImplSVData* pSVData = ImplGetSVData();
75 6886 : if( ! pSVData->mpSalSystem )
76 55 : pSVData->mpSalSystem = pSVData->mpDefInst->CreateSalSystem();
77 6886 : return pSVData->mpSalSystem;
78 : }
79 :
80 :
81 0 : static OUString ReplaceJavaErrorMessages( const OUString& rString )
82 : {
83 : return rString.replaceAll("%OK", Button::GetStandardText(BUTTON_OK)).
84 : replaceAll("%IGNORE", Button::GetStandardText(BUTTON_IGNORE)).
85 0 : replaceAll("%CANCEL", Button::GetStandardText(BUTTON_CANCEL));
86 : }
87 :
88 : // =======================================================================
89 :
90 151 : void ImplInitSVData()
91 : {
92 151 : pImplSVData = &private_aImplSVData::get();
93 :
94 : // init global instance data
95 151 : memset( pImplSVData, 0, sizeof( ImplSVData ) );
96 151 : pImplSVData->maHelpData.mbAutoHelpId = sal_True;
97 151 : pImplSVData->maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
98 :
99 : // mark default layout border as unitialized
100 151 : pImplSVData->maAppData.mnDefaultLayoutBorder = -1;
101 151 : }
102 :
103 : // -----------------------------------------------------------------------
104 :
105 94 : void ImplDeInitSVData()
106 : {
107 94 : ImplSVData* pSVData = ImplGetSVData();
108 :
109 : // delete global instance data
110 94 : if( pSVData->mpSettingsConfigItem )
111 0 : delete pSVData->mpSettingsConfigItem;
112 :
113 94 : if( pSVData->mpDockingManager )
114 87 : delete pSVData->mpDockingManager;
115 :
116 94 : if( pSVData->maGDIData.mpDefaultFontConfiguration )
117 0 : delete pSVData->maGDIData.mpDefaultFontConfiguration;
118 94 : if( pSVData->maGDIData.mpFontSubstConfiguration )
119 0 : delete pSVData->maGDIData.mpFontSubstConfiguration;
120 :
121 94 : if( pSVData->maCtrlData.mpFieldUnitStrings )
122 29 : delete pSVData->maCtrlData.mpFieldUnitStrings, pSVData->maCtrlData.mpFieldUnitStrings = NULL;
123 94 : if( pSVData->maCtrlData.mpCleanUnitStrings )
124 29 : delete pSVData->maCtrlData.mpCleanUnitStrings, pSVData->maCtrlData.mpCleanUnitStrings = NULL;
125 94 : if( pSVData->mpPaperNames )
126 0 : delete pSVData->mpPaperNames, pSVData->mpPaperNames = NULL;
127 94 : }
128 :
129 : // -----------------------------------------------------------------------
130 :
131 94 : void ImplDestroySVData()
132 : {
133 94 : pImplSVData = NULL;
134 94 : }
135 :
136 : // -----------------------------------------------------------------------
137 :
138 105912 : Window* ImplGetDefaultWindow()
139 : {
140 105912 : ImplSVData* pSVData = ImplGetSVData();
141 105912 : if ( pSVData->maWinData.mpAppWin )
142 0 : return pSVData->maWinData.mpAppWin;
143 :
144 : // First test if we already have a default window.
145 : // Don't only place a single if..else inside solar mutex lockframe
146 : // because then we might have to wait for the solar mutex what is not necessary
147 : // if we already have a default window.
148 :
149 105912 : if ( !pSVData->mpDefaultWin )
150 : {
151 130 : Application::GetSolarMutex().acquire();
152 :
153 : // Test again because the thread who released the solar mutex could have called
154 : // the same method
155 :
156 130 : if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit )
157 : {
158 : DBG_WARNING( "ImplGetDefaultWindow(): No AppWindow" );
159 130 : pSVData->mpDefaultWin = new WorkWindow( 0, WB_DEFAULTWIN );
160 130 : pSVData->mpDefaultWin->SetText( OUString( "VCL ImplGetDefaultWindow" ) );
161 : }
162 130 : Application::GetSolarMutex().release();
163 : }
164 :
165 105912 : return pSVData->mpDefaultWin;
166 : }
167 :
168 : // -----------------------------------------------------------------------
169 :
170 : #define VCL_CREATERESMGR_NAME( Name ) #Name
171 :
172 3177 : ResMgr* ImplGetResMgr()
173 : {
174 3177 : ImplSVData* pSVData = ImplGetSVData();
175 3177 : if ( !pSVData->mpResMgr )
176 : {
177 113 : LanguageTag aLocale( Application::GetSettings().GetUILanguageTag());
178 113 : pSVData->mpResMgr = ResMgr::SearchCreateResMgr( VCL_CREATERESMGR_NAME( vcl ), aLocale );
179 :
180 : static bool bMessageOnce = false;
181 113 : if( !pSVData->mpResMgr && ! bMessageOnce )
182 : {
183 0 : bMessageOnce = true;
184 : const char* pMsg =
185 : "Missing vcl resource. This indicates that files vital to localization are missing. "
186 0 : "You might have a corrupt installation.";
187 0 : fprintf( stderr, "%s\n", pMsg );
188 0 : ErrorBox aBox( NULL, WB_OK | WB_DEF_OK, OUString( pMsg, strlen( pMsg ), RTL_TEXTENCODING_ASCII_US ) );
189 0 : aBox.Execute();
190 113 : }
191 : }
192 3177 : return pSVData->mpResMgr;
193 : }
194 :
195 0 : ResId VclResId( sal_Int32 nId )
196 : {
197 0 : ResMgr* pMgr = ImplGetResMgr();
198 0 : if( ! pMgr )
199 0 : throw std::bad_alloc();
200 :
201 0 : return ResId( nId, *pMgr );
202 : }
203 :
204 20860 : FieldUnitStringList* ImplGetFieldUnits()
205 : {
206 20860 : ImplSVData* pSVData = ImplGetSVData();
207 20860 : if( ! pSVData->maCtrlData.mpFieldUnitStrings )
208 : {
209 29 : ResMgr* pResMgr = ImplGetResMgr();
210 29 : if( pResMgr )
211 : {
212 29 : ResStringArray aUnits( ResId (SV_FUNIT_STRINGS, *pResMgr) );
213 29 : sal_uInt32 nUnits = aUnits.Count();
214 29 : pSVData->maCtrlData.mpFieldUnitStrings = new FieldUnitStringList();
215 29 : pSVData->maCtrlData.mpFieldUnitStrings->reserve( nUnits );
216 609 : for( sal_uInt32 i = 0; i < nUnits; i++ )
217 : {
218 580 : std::pair< String, FieldUnit > aElement( aUnits.GetString(i), static_cast<FieldUnit>(aUnits.GetValue(i)) );
219 580 : pSVData->maCtrlData.mpFieldUnitStrings->push_back( aElement );
220 609 : }
221 : }
222 : }
223 20860 : return pSVData->maCtrlData.mpFieldUnitStrings;
224 : }
225 :
226 4015 : FieldUnitStringList* ImplGetCleanedFieldUnits()
227 : {
228 4015 : ImplSVData* pSVData = ImplGetSVData();
229 4015 : if( ! pSVData->maCtrlData.mpCleanUnitStrings )
230 : {
231 29 : FieldUnitStringList* pUnits = ImplGetFieldUnits();
232 29 : if( pUnits )
233 : {
234 29 : size_t nUnits = pUnits->size();
235 29 : pSVData->maCtrlData.mpCleanUnitStrings = new FieldUnitStringList();
236 29 : pSVData->maCtrlData.mpCleanUnitStrings->reserve( nUnits );
237 609 : for( size_t i = 0; i < nUnits; ++i )
238 : {
239 580 : OUString aUnit( (*pUnits)[i].first );
240 580 : aUnit = comphelper::string::remove(aUnit, ' ');
241 580 : aUnit = aUnit.toAsciiLowerCase();
242 1160 : std::pair< String, FieldUnit > aElement( aUnit, (*pUnits)[i].second );
243 580 : pSVData->maCtrlData.mpCleanUnitStrings->push_back( aElement );
244 580 : }
245 : }
246 : }
247 4015 : return pSVData->maCtrlData.mpCleanUnitStrings;
248 : }
249 :
250 1632556 : DockingManager* ImplGetDockingManager()
251 : {
252 1632556 : ImplSVData* pSVData = ImplGetSVData();
253 1632556 : if ( !pSVData->mpDockingManager )
254 116 : pSVData->mpDockingManager = new DockingManager();
255 :
256 1632556 : return pSVData->mpDockingManager;
257 : }
258 :
259 130 : BlendFrameCache* ImplGetBlendFrameCache()
260 : {
261 130 : ImplSVData* pSVData = ImplGetSVData();
262 130 : if ( !pSVData->mpBlendFrameCache)
263 7 : pSVData->mpBlendFrameCache= new BlendFrameCache();
264 :
265 130 : return pSVData->mpBlendFrameCache;
266 : }
267 :
268 0 : class AccessBridgeCurrentContext: public cppu::WeakImplHelper1< com::sun::star::uno::XCurrentContext >
269 : {
270 : public:
271 0 : AccessBridgeCurrentContext(
272 : const com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > &context ) :
273 0 : m_prevContext( context ) {}
274 :
275 : // XCurrentContext
276 : virtual com::sun::star::uno::Any SAL_CALL getValueByName( const OUString& Name )
277 : throw (com::sun::star::uno::RuntimeException);
278 : private:
279 : com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > m_prevContext;
280 : };
281 :
282 0 : com::sun::star::uno::Any AccessBridgeCurrentContext::getValueByName( const OUString & Name )
283 : throw (com::sun::star::uno::RuntimeException)
284 : {
285 0 : com::sun::star::uno::Any ret;
286 0 : if ( Name == "java-vm.interaction-handler" )
287 : {
288 : // Currently, for accessbility no interaction handler shall be offered.
289 : // There may be introduced later on a handler using native toolkits
290 : // jbu->obr: Instantiate here your interaction handler
291 : }
292 0 : else if( m_prevContext.is() )
293 : {
294 0 : ret = m_prevContext->getValueByName( Name );
295 : }
296 0 : return ret;
297 : }
298 :
299 :
300 0 : bool ImplInitAccessBridge(bool bAllowCancel, bool &rCancelled)
301 : {
302 0 : rCancelled = false;
303 :
304 0 : bool bErrorMessage = true;
305 :
306 : // Note:
307 : // if bAllowCancel is sal_True we were called from application startup
308 : // where we will disable any Java errorboxes and show our own accessibility dialog if Java throws an exception
309 : // if bAllowCancel is sal_False we were called from Tools->Options
310 : // where we will see Java errorboxes, se we do not show our dialogs in addition to Java's
311 :
312 : try
313 : {
314 : // No error messages when env var is set ..
315 0 : static const char* pEnv = getenv("SAL_ACCESSIBILITY_ENABLED" );
316 0 : if( pEnv && *pEnv )
317 : {
318 0 : bErrorMessage = false;
319 : }
320 :
321 0 : ImplSVData* pSVData = ImplGetSVData();
322 0 : if( ! pSVData->mxAccessBridge.is() )
323 : {
324 0 : css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
325 :
326 : css::uno::Reference< XExtendedToolkit > xToolkit =
327 0 : css::uno::Reference< XExtendedToolkit >(Application::GetVCLToolkit(), UNO_QUERY);
328 :
329 : // Disable default java error messages on startup, because they were probably unreadable
330 : // for a disabled user. Use native message boxes which are accessible without java support.
331 : // No need to do this when activated by Tools-Options dialog ..
332 0 : if( bAllowCancel )
333 : {
334 : // customize the java-not-available-interaction-handler entry within the
335 : // current context when called at startup.
336 : com::sun::star::uno::ContextLayer layer(
337 0 : new AccessBridgeCurrentContext( com::sun::star::uno::getCurrentContext() ) );
338 :
339 : pSVData->mxAccessBridge
340 0 : = css::accessibility::AccessBridge::createWithToolkit(
341 0 : xContext, xToolkit);
342 : }
343 : else
344 : {
345 : pSVData->mxAccessBridge
346 0 : = css::accessibility::AccessBridge::createWithToolkit(
347 0 : xContext, xToolkit);
348 0 : }
349 : }
350 :
351 0 : return true;
352 : }
353 0 : catch (const ::com::sun::star::java::JavaNotConfiguredException&)
354 : {
355 0 : ResMgr *pResMgr = ImplGetResMgr();
356 0 : if( bErrorMessage && bAllowCancel && pResMgr )
357 : {
358 0 : OUString aTitle(ResId(SV_ACCESSERROR_JAVA_NOT_CONFIGURED, *pResMgr).toString());
359 0 : OUStringBuffer aMessage((ResId(SV_ACCESSERROR_JAVA_MSG, *pResMgr)).toString());
360 :
361 0 : aMessage.append(' ').append(ResId(SV_ACCESSERROR_OK_CANCEL_MSG, *pResMgr).toString());
362 :
363 0 : int ret = ImplGetSalSystem()->ShowNativeMessageBox(
364 : aTitle,
365 : ReplaceJavaErrorMessages(aMessage.makeStringAndClear()),
366 : SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL,
367 0 : SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, true);
368 :
369 : // Do not change the setting in case the user chooses to cancel
370 0 : if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL == ret )
371 0 : rCancelled = true;
372 : }
373 :
374 0 : return false;
375 : }
376 0 : catch (const ::com::sun::star::java::JavaVMCreationFailureException&)
377 : {
378 0 : ResMgr *pResMgr = ImplGetResMgr();
379 0 : if( bErrorMessage && bAllowCancel && pResMgr )
380 : {
381 0 : OUString aTitle(ResId(SV_ACCESSERROR_FAULTY_JAVA, *pResMgr).toString());
382 0 : OUStringBuffer aMessage(ResId(SV_ACCESSERROR_JAVA_MSG, *pResMgr).toString());
383 :
384 0 : aMessage.append(' ').append(ResId(SV_ACCESSERROR_OK_CANCEL_MSG, *pResMgr).toString());
385 :
386 0 : int ret = ImplGetSalSystem()->ShowNativeMessageBox(
387 : aTitle,
388 : ReplaceJavaErrorMessages(aMessage.makeStringAndClear()),
389 : SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL,
390 0 : SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, true);
391 :
392 : // Do not change the setting in case the user chooses to cancel
393 0 : if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL == ret )
394 0 : rCancelled = true;
395 : }
396 :
397 0 : return false;
398 : }
399 0 : catch (const ::com::sun::star::java::MissingJavaRuntimeException&)
400 : {
401 0 : ResMgr *pResMgr = ImplGetResMgr();
402 0 : if( bErrorMessage && bAllowCancel && pResMgr )
403 : {
404 0 : OUString aTitle(ResId(SV_ACCESSERROR_MISSING_JAVA, *pResMgr).toString());
405 0 : OUStringBuffer aMessage(ResId(SV_ACCESSERROR_JAVA_MSG, *pResMgr).toString());
406 :
407 0 : aMessage.append(' ').append(ResId(SV_ACCESSERROR_OK_CANCEL_MSG, *pResMgr).toString());
408 :
409 0 : int ret = ImplGetSalSystem()->ShowNativeMessageBox(
410 : aTitle,
411 : ReplaceJavaErrorMessages(aMessage.makeStringAndClear()),
412 : SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL,
413 0 : SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, true);
414 :
415 : // Do not change the setting in case the user chooses to cancel
416 0 : if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL == ret )
417 0 : rCancelled = true;
418 : }
419 :
420 0 : return false;
421 : }
422 0 : catch (const ::com::sun::star::java::JavaDisabledException&)
423 : {
424 0 : ResMgr *pResMgr = ImplGetResMgr();
425 0 : if( bErrorMessage && bAllowCancel && pResMgr )
426 : {
427 0 : OUString aTitle(ResId(SV_ACCESSERROR_JAVA_DISABLED, *pResMgr).toString());
428 0 : OUStringBuffer aMessage(ResId(SV_ACCESSERROR_JAVA_MSG, *pResMgr).toString());
429 :
430 0 : aMessage.append(' ').append(ResId(SV_ACCESSERROR_OK_CANCEL_MSG, *pResMgr).toString());
431 :
432 0 : int ret = ImplGetSalSystem()->ShowNativeMessageBox(
433 : aTitle,
434 : ReplaceJavaErrorMessages(aMessage.makeStringAndClear()),
435 : SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL,
436 0 : SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, true);
437 :
438 : // Do not change the setting in case the user chooses to cancel
439 0 : if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL == ret )
440 0 : rCancelled = true;
441 : }
442 :
443 0 : return false;
444 : }
445 0 : catch (const ::com::sun::star::uno::RuntimeException& e)
446 : {
447 0 : ResMgr *pResMgr = ImplGetResMgr();
448 0 : if( bErrorMessage && pResMgr )
449 : {
450 0 : OUString aTitle;
451 0 : OUStringBuffer aMessage(ResId(SV_ACCESSERROR_BRIDGE_MSG, *pResMgr).toString());
452 :
453 0 : if( e.Message.startsWith("ClassNotFound") )
454 : {
455 0 : aTitle = ResId(SV_ACCESSERROR_MISSING_BRIDGE, *pResMgr).toString();
456 : }
457 0 : else if( e.Message.startsWith("NoSuchMethod") )
458 : {
459 0 : aTitle = ResId(SV_ACCESSERROR_WRONG_VERSION, *pResMgr).toString();
460 : }
461 :
462 0 : if (!aTitle.isEmpty())
463 : {
464 0 : if( bAllowCancel )
465 : {
466 : // Something went wrong initializing the Java AccessBridge (on Windows) during the
467 : // startup. Since the office will be probably unusable for a disabled user, we offer
468 : // to terminate directly.
469 0 : aMessage.append(' ').append(ResId(SV_ACCESSERROR_OK_CANCEL_MSG, *pResMgr).toString());
470 :
471 0 : int ret = ImplGetSalSystem()->ShowNativeMessageBox(
472 : aTitle,
473 : ReplaceJavaErrorMessages(aMessage.makeStringAndClear()),
474 : SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL,
475 0 : SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, true);
476 :
477 : // Do not change the setting in case the user chooses to cancel
478 0 : if( SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL == ret )
479 0 : rCancelled = sal_True;
480 : }
481 : else
482 : {
483 : // The user tried to activate accessibility support using Tools-Options dialog,
484 : // so we don't offer to terminate here !
485 0 : ImplGetSalSystem()->ShowNativeMessageBox(
486 : aTitle,
487 : ReplaceJavaErrorMessages(aMessage.makeStringAndClear()),
488 : SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK,
489 0 : SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK, true);
490 : }
491 0 : }
492 : }
493 :
494 0 : return false;
495 : }
496 0 : catch (...)
497 : {
498 0 : return false;
499 : }
500 : }
501 :
502 : // -----------------------------------------------------------------------
503 :
504 0 : Window* ImplFindWindow( const SalFrame* pFrame, ::Point& rSalFramePos )
505 : {
506 0 : ImplSVData* pSVData = ImplGetSVData();
507 0 : Window* pFrameWindow = pSVData->maWinData.mpFirstFrame;
508 0 : while ( pFrameWindow )
509 : {
510 0 : if ( pFrameWindow->ImplGetFrame() == pFrame )
511 : {
512 0 : Window* pWindow = pFrameWindow->ImplFindWindow( rSalFramePos );
513 0 : if ( !pWindow )
514 0 : pWindow = pFrameWindow->ImplGetWindow();
515 0 : rSalFramePos = pWindow->ImplFrameToOutput( rSalFramePos );
516 0 : return pWindow;
517 : }
518 0 : pFrameWindow = pFrameWindow->ImplGetFrameData()->mpNextFrame;
519 : }
520 :
521 0 : return NULL;
522 : }
523 :
524 1 : void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 nHint )
525 : {
526 1 : AllSettings::LocaleSettingsChanged( nHint );
527 466 : }
528 :
529 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|