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