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 <cppuhelper/implbase1.hxx>
31 : #include <uno/current_context.hxx>
32 :
33 : #include "vcl/configsettings.hxx"
34 : #include "vcl/svapp.hxx"
35 : #include "vcl/settings.hxx"
36 : #include "vcl/wrkwin.hxx"
37 : #include "vcl/layout.hxx"
38 : #include "vcl/button.hxx"
39 : #include "vcl/dockwin.hxx"
40 : #include "vcl/print.hxx"
41 : #include "vcl/virdev.hxx"
42 : #include "salinst.hxx"
43 : #include "salframe.hxx"
44 : #include "salgdi.hxx"
45 : #include "svdata.hxx"
46 : #include "window.h"
47 : #include "salimestatus.hxx"
48 : #include "salsys.hxx"
49 : #include "svids.hrc"
50 : #include "helpwin.hxx"
51 : #include "../window/scrwnd.hxx"
52 :
53 : #include "com/sun/star/accessibility/MSAAService.hpp"
54 :
55 : #include "officecfg/Office/Common.hxx"
56 :
57 : #include "vcl/opengl/OpenGLContext.hxx"
58 :
59 : using namespace com::sun::star::uno;
60 : using namespace com::sun::star::lang;
61 : using namespace com::sun::star::awt;
62 :
63 : namespace
64 : {
65 : struct private_aImplSVData :
66 : public rtl::Static<ImplSVData, private_aImplSVData> {};
67 : }
68 :
69 306572579 : ImplSVData* ImplGetSVData() {
70 306572579 : return &private_aImplSVData::get();
71 : }
72 :
73 19354 : SalSystem* ImplGetSalSystem()
74 : {
75 19354 : ImplSVData* pSVData = ImplGetSVData();
76 19354 : if( ! pSVData->mpSalSystem )
77 98 : pSVData->mpSalSystem = pSVData->mpDefInst->CreateSalSystem();
78 19354 : return pSVData->mpSalSystem;
79 : }
80 :
81 245 : ImplSVData::ImplSVData()
82 : {
83 : // init global instance data
84 245 : memset( this, 0, sizeof( ImplSVData ) );
85 245 : maHelpData.mbAutoHelpId = true;
86 245 : maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
87 245 : }
88 :
89 490 : ImplSVGDIData::~ImplSVGDIData()
90 : {
91 : // FIXME: deliberately leak any remaining OutputDevice
92 : // until we have their pGraphics reference counted, doing
93 : // any disposes so late in shutdown is rather unsafe.
94 245 : memset( this, 0, sizeof( ImplSVGDIData ) );
95 245 : }
96 :
97 242 : void ImplDeInitSVData()
98 : {
99 242 : ImplSVData* pSVData = ImplGetSVData();
100 :
101 : // delete global instance data
102 242 : if( pSVData->mpSettingsConfigItem )
103 0 : delete pSVData->mpSettingsConfigItem;
104 :
105 242 : if( pSVData->mpDockingManager )
106 210 : delete pSVData->mpDockingManager;
107 :
108 242 : if( pSVData->maCtrlData.mpFieldUnitStrings )
109 39 : delete pSVData->maCtrlData.mpFieldUnitStrings, pSVData->maCtrlData.mpFieldUnitStrings = NULL;
110 242 : if( pSVData->maCtrlData.mpCleanUnitStrings )
111 38 : delete pSVData->maCtrlData.mpCleanUnitStrings, pSVData->maCtrlData.mpCleanUnitStrings = NULL;
112 242 : if( pSVData->mpPaperNames )
113 0 : delete pSVData->mpPaperNames, pSVData->mpPaperNames = NULL;
114 242 : }
115 :
116 450056 : vcl::Window* ImplGetDefaultWindow()
117 : {
118 450056 : ImplSVData* pSVData = ImplGetSVData();
119 450056 : if ( pSVData->maWinData.mpAppWin )
120 13 : return pSVData->maWinData.mpAppWin;
121 :
122 : // First test if we already have a default window.
123 : // Don't only place a single if..else inside solar mutex lockframe
124 : // because then we might have to wait for the solar mutex what is not necessary
125 : // if we already have a default window.
126 :
127 450043 : if ( !pSVData->mpDefaultWin )
128 : {
129 226 : Application::GetSolarMutex().acquire();
130 :
131 : // Test again because the thread who released the solar mutex could have called
132 : // the same method
133 :
134 226 : if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit )
135 : {
136 : DBG_WARNING( "ImplGetDefaultWindow(): No AppWindow" );
137 213 : pSVData->mpDefaultWin = VclPtr<WorkWindow>::Create( nullptr, WB_DEFAULTWIN );
138 213 : pSVData->mpDefaultWin->SetText( OUString( "VCL ImplGetDefaultWindow" ) );
139 :
140 : // Add a reference to the default context so it never gets deleted
141 213 : OpenGLContext* pContext = pSVData->mpDefaultWin->GetGraphics()->GetOpenGLContext();
142 213 : if( pContext )
143 : {
144 : #ifdef DBG_UTIL
145 : pContext->AddRef(NULL);
146 : #else
147 0 : pContext->AddRef();
148 : #endif
149 : }
150 : }
151 226 : Application::GetSolarMutex().release();
152 : }
153 :
154 450043 : return pSVData->mpDefaultWin;
155 : }
156 :
157 6582 : ResMgr* ImplGetResMgr()
158 : {
159 6582 : ImplSVData* pSVData = ImplGetSVData();
160 6582 : if ( !pSVData->mpResMgr )
161 : {
162 107 : LanguageTag aLocale( Application::GetSettings().GetUILanguageTag());
163 107 : pSVData->mpResMgr = ResMgr::SearchCreateResMgr( "vcl", aLocale );
164 :
165 : static bool bMessageOnce = false;
166 107 : if( !pSVData->mpResMgr && ! bMessageOnce )
167 : {
168 0 : bMessageOnce = true;
169 : const char* pMsg =
170 : "Missing vcl resource. This indicates that files vital to localization are missing. "
171 0 : "You might have a corrupt installation.";
172 : SAL_WARN("vcl", "" << pMsg << "\n");
173 0 : ScopedVclPtrInstance< MessageDialog > aBox( nullptr, OUString(pMsg, strlen(pMsg), RTL_TEXTENCODING_ASCII_US) );
174 0 : aBox->Execute();
175 107 : }
176 : }
177 6582 : return pSVData->mpResMgr;
178 : }
179 :
180 0 : ResId VclResId( sal_Int32 nId )
181 : {
182 0 : ResMgr* pMgr = ImplGetResMgr();
183 0 : if( ! pMgr )
184 0 : throw std::bad_alloc();
185 :
186 0 : return ResId( nId, *pMgr );
187 : }
188 :
189 62908 : FieldUnitStringList* ImplGetFieldUnits()
190 : {
191 62908 : ImplSVData* pSVData = ImplGetSVData();
192 62908 : if( ! pSVData->maCtrlData.mpFieldUnitStrings )
193 : {
194 39 : ResMgr* pResMgr = ImplGetResMgr();
195 39 : if( pResMgr )
196 : {
197 39 : ResStringArray aUnits( ResId (SV_FUNIT_STRINGS, *pResMgr) );
198 39 : sal_uInt32 nUnits = aUnits.Count();
199 39 : pSVData->maCtrlData.mpFieldUnitStrings = new FieldUnitStringList();
200 39 : pSVData->maCtrlData.mpFieldUnitStrings->reserve( nUnits );
201 975 : for( sal_uInt32 i = 0; i < nUnits; i++ )
202 : {
203 936 : std::pair< OUString, FieldUnit > aElement( aUnits.GetString(i), static_cast<FieldUnit>(aUnits.GetValue(i)) );
204 936 : pSVData->maCtrlData.mpFieldUnitStrings->push_back( aElement );
205 975 : }
206 : }
207 : }
208 62908 : return pSVData->maCtrlData.mpFieldUnitStrings;
209 : }
210 :
211 30502 : FieldUnitStringList* ImplGetCleanedFieldUnits()
212 : {
213 30502 : ImplSVData* pSVData = ImplGetSVData();
214 30502 : if( ! pSVData->maCtrlData.mpCleanUnitStrings )
215 : {
216 38 : FieldUnitStringList* pUnits = ImplGetFieldUnits();
217 38 : if( pUnits )
218 : {
219 38 : size_t nUnits = pUnits->size();
220 38 : pSVData->maCtrlData.mpCleanUnitStrings = new FieldUnitStringList();
221 38 : pSVData->maCtrlData.mpCleanUnitStrings->reserve( nUnits );
222 950 : for( size_t i = 0; i < nUnits; ++i )
223 : {
224 912 : OUString aUnit( (*pUnits)[i].first );
225 912 : aUnit = comphelper::string::remove(aUnit, ' ');
226 912 : aUnit = aUnit.toAsciiLowerCase();
227 1824 : std::pair< OUString, FieldUnit > aElement( aUnit, (*pUnits)[i].second );
228 912 : pSVData->maCtrlData.mpCleanUnitStrings->push_back( aElement );
229 912 : }
230 : }
231 : }
232 30502 : return pSVData->maCtrlData.mpCleanUnitStrings;
233 : }
234 :
235 4069751 : DockingManager* ImplGetDockingManager()
236 : {
237 4069751 : ImplSVData* pSVData = ImplGetSVData();
238 4069751 : if ( !pSVData->mpDockingManager )
239 212 : pSVData->mpDockingManager = new DockingManager();
240 :
241 4069751 : return pSVData->mpDockingManager;
242 : }
243 :
244 0 : BlendFrameCache* ImplGetBlendFrameCache()
245 : {
246 0 : ImplSVData* pSVData = ImplGetSVData();
247 0 : if ( !pSVData->mpBlendFrameCache)
248 0 : pSVData->mpBlendFrameCache= new BlendFrameCache();
249 :
250 0 : return pSVData->mpBlendFrameCache;
251 : }
252 :
253 : #ifdef _WIN32
254 : bool HasAtHook();
255 : #endif
256 :
257 0 : bool ImplInitAccessBridge()
258 : {
259 0 : ImplSVData* pSVData = ImplGetSVData();
260 0 : if( ! pSVData->mxAccessBridge.is() )
261 : {
262 0 : css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
263 :
264 : #ifdef _WIN32
265 : if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
266 : {
267 : SAL_INFO("vcl", "Apparently no running AT -> "
268 : "not enabling IAccessible2 integration");
269 : }
270 : else
271 : {
272 : try {
273 : pSVData->mxAccessBridge
274 : = css::accessibility::MSAAService::create(xContext);
275 : SAL_INFO("vcl", "got IAccessible2 bridge");
276 : return true;
277 : } catch (css::uno::DeploymentException & e) {
278 : SAL_WARN(
279 : "vcl",
280 : "got no IAccessible2 bridge" << e.Message);
281 : return false;
282 : }
283 : }
284 : #endif
285 : }
286 :
287 0 : return true;
288 : }
289 :
290 0 : vcl::Window* ImplFindWindow( const SalFrame* pFrame, ::Point& rSalFramePos )
291 : {
292 0 : ImplSVData* pSVData = ImplGetSVData();
293 0 : vcl::Window* pFrameWindow = pSVData->maWinData.mpFirstFrame;
294 0 : while ( pFrameWindow )
295 : {
296 0 : if ( pFrameWindow->ImplGetFrame() == pFrame )
297 : {
298 0 : vcl::Window* pWindow = pFrameWindow->ImplFindWindow( rSalFramePos );
299 0 : if ( !pWindow )
300 0 : pWindow = pFrameWindow->ImplGetWindow();
301 0 : rSalFramePos = pWindow->ImplFrameToOutput( rSalFramePos );
302 0 : return pWindow;
303 : }
304 0 : pFrameWindow = pFrameWindow->ImplGetFrameData()->mpNextFrame;
305 : }
306 :
307 0 : return NULL;
308 : }
309 :
310 1 : void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 nHint )
311 : {
312 1 : AllSettings::LocaleSettingsChanged( nHint );
313 802 : }
314 :
315 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|