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 "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/MSAAService.hpp"
49 :
50 : #include "officecfg/Office/Common.hxx"
51 :
52 : #include <stdio.h>
53 :
54 : using namespace com::sun::star::uno;
55 : using namespace com::sun::star::lang;
56 : using namespace com::sun::star::awt;
57 :
58 : namespace
59 : {
60 : struct private_aImplSVData :
61 : public rtl::Static<ImplSVData, private_aImplSVData> {};
62 : }
63 :
64 : // static SV-Data
65 : ImplSVData* pImplSVData = NULL;
66 :
67 33684 : SalSystem* ImplGetSalSystem()
68 : {
69 33684 : ImplSVData* pSVData = ImplGetSVData();
70 33684 : if( ! pSVData->mpSalSystem )
71 142 : pSVData->mpSalSystem = pSVData->mpDefInst->CreateSalSystem();
72 33684 : return pSVData->mpSalSystem;
73 : }
74 :
75 373 : void ImplInitSVData()
76 : {
77 373 : pImplSVData = &private_aImplSVData::get();
78 :
79 : // init global instance data
80 373 : memset( pImplSVData, 0, sizeof( ImplSVData ) );
81 373 : pImplSVData->maHelpData.mbAutoHelpId = true;
82 373 : pImplSVData->maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
83 :
84 : // mark default layout border as unitialized
85 373 : pImplSVData->maAppData.mnDefaultLayoutBorder = -1;
86 373 : }
87 :
88 367 : void ImplDeInitSVData()
89 : {
90 367 : ImplSVData* pSVData = ImplGetSVData();
91 :
92 : // delete global instance data
93 367 : if( pSVData->mpSettingsConfigItem )
94 0 : delete pSVData->mpSettingsConfigItem;
95 :
96 367 : if( pSVData->mpDockingManager )
97 310 : delete pSVData->mpDockingManager;
98 :
99 367 : if( pSVData->maCtrlData.mpFieldUnitStrings )
100 56 : delete pSVData->maCtrlData.mpFieldUnitStrings, pSVData->maCtrlData.mpFieldUnitStrings = NULL;
101 367 : if( pSVData->maCtrlData.mpCleanUnitStrings )
102 56 : delete pSVData->maCtrlData.mpCleanUnitStrings, pSVData->maCtrlData.mpCleanUnitStrings = NULL;
103 367 : if( pSVData->mpPaperNames )
104 0 : delete pSVData->mpPaperNames, pSVData->mpPaperNames = NULL;
105 367 : }
106 :
107 367 : void ImplDestroySVData()
108 : {
109 367 : pImplSVData = NULL;
110 367 : }
111 :
112 648474 : vcl::Window* ImplGetDefaultWindow()
113 : {
114 648474 : ImplSVData* pSVData = ImplGetSVData();
115 648474 : if ( pSVData->maWinData.mpAppWin )
116 0 : return pSVData->maWinData.mpAppWin;
117 :
118 : // First test if we already have a default window.
119 : // Don't only place a single if..else inside solar mutex lockframe
120 : // because then we might have to wait for the solar mutex what is not necessary
121 : // if we already have a default window.
122 :
123 648474 : if ( !pSVData->mpDefaultWin )
124 : {
125 314 : Application::GetSolarMutex().acquire();
126 :
127 : // Test again because the thread who released the solar mutex could have called
128 : // the same method
129 :
130 314 : if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit )
131 : {
132 : DBG_WARNING( "ImplGetDefaultWindow(): No AppWindow" );
133 314 : pSVData->mpDefaultWin = new WorkWindow( 0, WB_DEFAULTWIN );
134 314 : pSVData->mpDefaultWin->SetText( OUString( "VCL ImplGetDefaultWindow" ) );
135 : }
136 314 : Application::GetSolarMutex().release();
137 : }
138 :
139 648474 : return pSVData->mpDefaultWin;
140 : }
141 :
142 13408 : ResMgr* ImplGetResMgr()
143 : {
144 13408 : ImplSVData* pSVData = ImplGetSVData();
145 13408 : if ( !pSVData->mpResMgr )
146 : {
147 266 : LanguageTag aLocale( Application::GetSettings().GetUILanguageTag());
148 266 : pSVData->mpResMgr = ResMgr::SearchCreateResMgr( "vcl", aLocale );
149 :
150 : static bool bMessageOnce = false;
151 266 : if( !pSVData->mpResMgr && ! bMessageOnce )
152 : {
153 0 : bMessageOnce = true;
154 : const char* pMsg =
155 : "Missing vcl resource. This indicates that files vital to localization are missing. "
156 0 : "You might have a corrupt installation.";
157 0 : fprintf( stderr, "%s\n", pMsg );
158 0 : MessageDialog aBox(NULL, OUString(pMsg, strlen(pMsg), RTL_TEXTENCODING_ASCII_US));
159 0 : aBox.Execute();
160 266 : }
161 : }
162 13408 : return pSVData->mpResMgr;
163 : }
164 :
165 0 : ResId VclResId( sal_Int32 nId )
166 : {
167 0 : ResMgr* pMgr = ImplGetResMgr();
168 0 : if( ! pMgr )
169 0 : throw std::bad_alloc();
170 :
171 0 : return ResId( nId, *pMgr );
172 : }
173 :
174 90046 : FieldUnitStringList* ImplGetFieldUnits()
175 : {
176 90046 : ImplSVData* pSVData = ImplGetSVData();
177 90046 : if( ! pSVData->maCtrlData.mpFieldUnitStrings )
178 : {
179 56 : ResMgr* pResMgr = ImplGetResMgr();
180 56 : if( pResMgr )
181 : {
182 56 : ResStringArray aUnits( ResId (SV_FUNIT_STRINGS, *pResMgr) );
183 56 : sal_uInt32 nUnits = aUnits.Count();
184 56 : pSVData->maCtrlData.mpFieldUnitStrings = new FieldUnitStringList();
185 56 : pSVData->maCtrlData.mpFieldUnitStrings->reserve( nUnits );
186 1400 : for( sal_uInt32 i = 0; i < nUnits; i++ )
187 : {
188 1344 : std::pair< OUString, FieldUnit > aElement( aUnits.GetString(i), static_cast<FieldUnit>(aUnits.GetValue(i)) );
189 1344 : pSVData->maCtrlData.mpFieldUnitStrings->push_back( aElement );
190 1400 : }
191 : }
192 : }
193 90046 : return pSVData->maCtrlData.mpFieldUnitStrings;
194 : }
195 :
196 42012 : FieldUnitStringList* ImplGetCleanedFieldUnits()
197 : {
198 42012 : ImplSVData* pSVData = ImplGetSVData();
199 42012 : if( ! pSVData->maCtrlData.mpCleanUnitStrings )
200 : {
201 56 : FieldUnitStringList* pUnits = ImplGetFieldUnits();
202 56 : if( pUnits )
203 : {
204 56 : size_t nUnits = pUnits->size();
205 56 : pSVData->maCtrlData.mpCleanUnitStrings = new FieldUnitStringList();
206 56 : pSVData->maCtrlData.mpCleanUnitStrings->reserve( nUnits );
207 1400 : for( size_t i = 0; i < nUnits; ++i )
208 : {
209 1344 : OUString aUnit( (*pUnits)[i].first );
210 1344 : aUnit = comphelper::string::remove(aUnit, ' ');
211 1344 : aUnit = aUnit.toAsciiLowerCase();
212 2688 : std::pair< OUString, FieldUnit > aElement( aUnit, (*pUnits)[i].second );
213 1344 : pSVData->maCtrlData.mpCleanUnitStrings->push_back( aElement );
214 1344 : }
215 : }
216 : }
217 42012 : return pSVData->maCtrlData.mpCleanUnitStrings;
218 : }
219 :
220 7177963 : DockingManager* ImplGetDockingManager()
221 : {
222 7177963 : ImplSVData* pSVData = ImplGetSVData();
223 7177963 : if ( !pSVData->mpDockingManager )
224 314 : pSVData->mpDockingManager = new DockingManager();
225 :
226 7177963 : return pSVData->mpDockingManager;
227 : }
228 :
229 115 : BlendFrameCache* ImplGetBlendFrameCache()
230 : {
231 115 : ImplSVData* pSVData = ImplGetSVData();
232 115 : if ( !pSVData->mpBlendFrameCache)
233 15 : pSVData->mpBlendFrameCache= new BlendFrameCache();
234 :
235 115 : return pSVData->mpBlendFrameCache;
236 : }
237 :
238 : #ifdef _WIN32
239 : bool HasAtHook();
240 : #endif
241 :
242 0 : bool ImplInitAccessBridge()
243 : {
244 0 : ImplSVData* pSVData = ImplGetSVData();
245 0 : if( ! pSVData->mxAccessBridge.is() )
246 : {
247 0 : css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
248 :
249 : #ifdef _WIN32
250 : if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
251 : {
252 : SAL_INFO("vcl", "Apparently no running AT -> "
253 : "not enabling IAccessible2 integration");
254 : }
255 : else
256 : {
257 : try {
258 : pSVData->mxAccessBridge
259 : = css::accessibility::MSAAService::create(xContext);
260 : SAL_INFO("vcl", "got IAccessible2 bridge");
261 : return true;
262 : } catch (css::uno::DeploymentException & e) {
263 : SAL_WARN(
264 : "vcl",
265 : "got no IAccessible2 bridge" << e.Message);
266 : return false;
267 : }
268 : }
269 : #endif
270 : }
271 :
272 0 : return true;
273 : }
274 :
275 0 : vcl::Window* ImplFindWindow( const SalFrame* pFrame, ::Point& rSalFramePos )
276 : {
277 0 : ImplSVData* pSVData = ImplGetSVData();
278 0 : vcl::Window* pFrameWindow = pSVData->maWinData.mpFirstFrame;
279 0 : while ( pFrameWindow )
280 : {
281 0 : if ( pFrameWindow->ImplGetFrame() == pFrame )
282 : {
283 0 : vcl::Window* pWindow = pFrameWindow->ImplFindWindow( rSalFramePos );
284 0 : if ( !pWindow )
285 0 : pWindow = pFrameWindow->ImplGetWindow();
286 0 : rSalFramePos = pWindow->ImplFrameToOutput( rSalFramePos );
287 0 : return pWindow;
288 : }
289 0 : pFrameWindow = pFrameWindow->ImplGetFrameData()->mpNextFrame;
290 : }
291 :
292 0 : return NULL;
293 : }
294 :
295 2 : void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 nHint )
296 : {
297 2 : AllSettings::LocaleSettingsChanged( nHint );
298 1235 : }
299 :
300 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|