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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <string.h>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <osl/mutex.hxx>
#include <rtl/process.h>
#include <tools/debug.hxx>
#include <tools/resary.hxx>
#include <tools/gen.hxx>
#include <uno/current_context.hxx>
#include <vcl/configsettings.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/layout.hxx>
#include <vcl/button.hxx>
#include <vcl/dockwin.hxx>
#include <vcl/print.hxx>
#include <vcl/virdev.hxx>
#include "salinst.hxx"
#include "salframe.hxx"
#include "salgdi.hxx"
#include "svdata.hxx"
#include "window.h"
#include "salimestatus.hxx"
#include "salsys.hxx"
#include "svids.hrc"
#include "helpwin.hxx"
#include "../window/scrwnd.hxx"
#include "com/sun/star/accessibility/MSAAService.hpp"
#include "officecfg/Office/Common.hxx"
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>
#endif
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::awt;
namespace
{
struct private_aImplSVData :
public rtl::Static<ImplSVData, private_aImplSVData> {};
}
ImplSVData* ImplGetSVData() {
return &private_aImplSVData::get();
}
SalSystem* ImplGetSalSystem()
{
ImplSVData* pSVData = ImplGetSVData();
if( ! pSVData->mpSalSystem )
pSVData->mpSalSystem = pSVData->mpDefInst->CreateSalSystem();
return pSVData->mpSalSystem;
}
ImplSVData::ImplSVData()
{
// init global instance data
memset( this, 0, sizeof( ImplSVData ) );
maHelpData.mbAutoHelpId = true;
maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
maNWFData.mbEnableAccel = true;
maNWFData.mbAutoAccel = false;
}
ImplSVGDIData::~ImplSVGDIData()
{
// FIXME: deliberately leak any remaining OutputDevice
// until we have their pGraphics reference counted, doing
// any disposes so late in shutdown is rather unsafe.
memset( this, 0, sizeof( ImplSVGDIData ) );
}
void ImplDeInitSVData()
{
ImplSVData* pSVData = ImplGetSVData();
// delete global instance data
if( pSVData->mpSettingsConfigItem )
{
delete pSVData->mpSettingsConfigItem;
pSVData->mpSettingsConfigItem = nullptr;
}
if( pSVData->mpDockingManager )
{
delete pSVData->mpDockingManager;
pSVData->mpDockingManager = nullptr;
}
if( pSVData->maCtrlData.mpFieldUnitStrings )
{
delete pSVData->maCtrlData.mpFieldUnitStrings;
pSVData->maCtrlData.mpFieldUnitStrings = nullptr;
}
if( pSVData->maCtrlData.mpCleanUnitStrings )
{
delete pSVData->maCtrlData.mpCleanUnitStrings;
pSVData->maCtrlData.mpCleanUnitStrings = nullptr;
}
if( pSVData->mpPaperNames )
{
delete pSVData->mpPaperNames;
pSVData->mpPaperNames = nullptr;
}
}
/// Returns either the application window, or the default GL context window
vcl::Window* ImplGetDefaultWindow()
{
ImplSVData* pSVData = ImplGetSVData();
if ( pSVData->maWinData.mpAppWin )
return pSVData->maWinData.mpAppWin;
else
return ImplGetDefaultContextWindow();
}
/// returns the default window created to hold the persistent VCL GL context.
vcl::Window *ImplGetDefaultContextWindow()
{
ImplSVData* pSVData = ImplGetSVData();
// Double check locking on mpDefaultWin.
if ( !pSVData->mpDefaultWin )
{
SolarMutexGuard aGuard;
if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit )
{
SAL_INFO( "vcl", "ImplGetDefaultWindow(): No AppWindow" );
pSVData->mpDefaultWin = VclPtr<WorkWindow>::Create( nullptr, WB_DEFAULTWIN );
pSVData->mpDefaultWin->SetText( "VCL ImplGetDefaultWindow" );
#if HAVE_FEATURE_OPENGL
// Add a reference to the default context so it never gets deleted
rtl::Reference<OpenGLContext> pContext = pSVData->mpDefaultWin->GetGraphics()->GetOpenGLContext();
if( pContext.is() )
pContext->acquire();
#endif
}
}
return pSVData->mpDefaultWin;
}
ResMgr* ImplGetResMgr()
{
ImplSVData* pSVData = ImplGetSVData();
if ( !pSVData->mpResMgr )
{
LanguageTag aLocale( Application::GetSettings().GetUILanguageTag());
pSVData->mpResMgr = ResMgr::SearchCreateResMgr( "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.";
SAL_WARN("vcl", "" << pMsg << "\n");
ScopedVclPtrInstance< MessageDialog > aBox( nullptr, 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< OUString, 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 )
{
OUString aUnit( (*pUnits)[i].first );
aUnit = comphelper::string::remove(aUnit, ' ');
aUnit = aUnit.toAsciiLowerCase();
std::pair< OUString, 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;
}
BlendFrameCache* ImplGetBlendFrameCache()
{
ImplSVData* pSVData = ImplGetSVData();
if ( !pSVData->mpBlendFrameCache)
pSVData->mpBlendFrameCache= new BlendFrameCache();
return pSVData->mpBlendFrameCache;
}
#ifdef _WIN32
bool HasAtHook();
#endif
#ifdef _WIN32
bool ImplInitAccessBridge()
{
ImplSVData* pSVData = ImplGetSVData();
if( ! pSVData->mxAccessBridge.is() )
{
css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
{
SAL_INFO("vcl", "Apparently no running AT -> "
"not enabling IAccessible2 integration");
}
else
{
try {
pSVData->mxAccessBridge
= css::accessibility::MSAAService::create(xContext);
SAL_INFO("vcl", "got IAccessible2 bridge");
return true;
} catch (css::uno::DeploymentException & e) {
SAL_WARN(
"vcl",
"got no IAccessible2 bridge" << e.Message);
return false;
}
}
}
return true;
}
#endif
void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 nHint )
{
AllSettings::LocaleSettingsChanged( nHint );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|