1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <comphelper/processfactory.hxx>
23 #include <comphelper/string.hxx>
24 #include <osl/mutex.hxx>
25 #include <rtl/process.h>
26 #include <tools/resary.hxx>
27 #include <tools/gen.hxx>
28 #include <uno/current_context.hxx>
30 #include <vcl/button.hxx>
31 #include <vcl/configsettings.hxx>
32 #include <vcl/dockwin.hxx>
33 #include <vcl/layout.hxx>
34 #include <vcl/menu.hxx>
35 #include <vcl/print.hxx>
36 #include <vcl/settings.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/virdev.hxx>
39 #include <vcl/wrkwin.hxx>
41 #include <helpwin.hxx>
42 #include <vcl/dialog.hxx>
43 #include "salinst.hxx"
44 #include "salframe.hxx"
48 #include "salimestatus.hxx"
52 #include "com/sun/star/accessibility/MSAAService.hpp"
54 #include "officecfg/Office/Common.hxx"
56 #include <config_features.h>
57 #if HAVE_FEATURE_OPENGL
58 #include <vcl/opengl/OpenGLContext.hxx>
61 using namespace com::sun::star::uno
;
62 using namespace com::sun::star::lang
;
63 using namespace com::sun::star::awt
;
67 struct private_aImplSVData
:
68 public rtl::Static
<ImplSVData
, private_aImplSVData
> {};
71 ImplSVData
* ImplGetSVData() {
72 return &private_aImplSVData::get();
75 SalSystem
* ImplGetSalSystem()
77 ImplSVData
* pSVData
= ImplGetSVData();
78 if( ! pSVData
->mpSalSystem
)
79 pSVData
->mpSalSystem
= pSVData
->mpDefInst
->CreateSalSystem();
80 return pSVData
->mpSalSystem
;
83 void ImplDeInitSVData()
85 ImplSVData
* pSVData
= ImplGetSVData();
87 // delete global instance data
88 if( pSVData
->mpSettingsConfigItem
)
90 delete pSVData
->mpSettingsConfigItem
;
91 pSVData
->mpSettingsConfigItem
= nullptr;
94 if( pSVData
->mpDockingManager
)
96 delete pSVData
->mpDockingManager
;
97 pSVData
->mpDockingManager
= nullptr;
100 if( pSVData
->maCtrlData
.mpFieldUnitStrings
)
102 delete pSVData
->maCtrlData
.mpFieldUnitStrings
;
103 pSVData
->maCtrlData
.mpFieldUnitStrings
= nullptr;
105 if( pSVData
->maCtrlData
.mpCleanUnitStrings
)
107 delete pSVData
->maCtrlData
.mpCleanUnitStrings
;
108 pSVData
->maCtrlData
.mpCleanUnitStrings
= nullptr;
110 if( pSVData
->mpPaperNames
)
112 delete pSVData
->mpPaperNames
;
113 pSVData
->mpPaperNames
= nullptr;
117 /// Returns either the application window, or the default GL context window
118 vcl::Window
* ImplGetDefaultWindow()
120 ImplSVData
* pSVData
= ImplGetSVData();
121 if ( pSVData
->maWinData
.mpAppWin
)
122 return pSVData
->maWinData
.mpAppWin
;
124 return ImplGetDefaultContextWindow();
127 /// returns the default window created to hold the persistent VCL GL context.
128 vcl::Window
*ImplGetDefaultContextWindow()
130 ImplSVData
* pSVData
= ImplGetSVData();
132 // Double check locking on mpDefaultWin.
133 if ( !pSVData
->mpDefaultWin
)
135 SolarMutexGuard aGuard
;
137 if (!pSVData
->mpDefaultWin
&& !pSVData
->mbDeInit
)
141 SAL_INFO( "vcl", "ImplGetDefaultWindow(): No AppWindow" );
143 pSVData
->mpDefaultWin
= VclPtr
<WorkWindow
>::Create( nullptr, WB_DEFAULTWIN
);
144 pSVData
->mpDefaultWin
->SetText( "VCL ImplGetDefaultWindow" );
146 #if HAVE_FEATURE_OPENGL
147 // Add a reference to the default context so it never gets deleted
148 rtl::Reference
<OpenGLContext
> pContext
= pSVData
->mpDefaultWin
->GetGraphics()->GetOpenGLContext();
153 catch (const css::uno::Exception
& e
)
155 SAL_WARN("vcl", "unable to create Default Window: " << e
.Message
);
160 return pSVData
->mpDefaultWin
;
163 ResMgr
* ImplGetResMgr()
165 ImplSVData
* pSVData
= ImplGetSVData();
166 if ( !pSVData
->mpResMgr
)
168 LanguageTag
aLocale( Application::GetSettings().GetUILanguageTag());
169 pSVData
->mpResMgr
= ResMgr::SearchCreateResMgr( "vcl", aLocale
);
171 static bool bMessageOnce
= false;
172 if( !pSVData
->mpResMgr
&& ! bMessageOnce
)
176 "Missing vcl resource. This indicates that files vital to localization are missing. "
177 "You might have a corrupt installation.";
178 SAL_WARN("vcl", "" << pMsg
);
179 ScopedVclPtrInstance
< MessageDialog
> aBox( nullptr, pMsg
);
183 return pSVData
->mpResMgr
;
186 ResId
VclResId( sal_Int32 nId
)
188 ResMgr
* pMgr
= ImplGetResMgr();
190 throw std::bad_alloc();
192 return ResId( nId
, *pMgr
);
195 FieldUnitStringList
* ImplGetFieldUnits()
197 ImplSVData
* pSVData
= ImplGetSVData();
198 if( ! pSVData
->maCtrlData
.mpFieldUnitStrings
)
200 ResMgr
* pResMgr
= ImplGetResMgr();
203 ResStringArray
aUnits( ResId (SV_FUNIT_STRINGS
, *pResMgr
) );
204 sal_uInt32 nUnits
= aUnits
.Count();
205 pSVData
->maCtrlData
.mpFieldUnitStrings
= new FieldUnitStringList
;
206 pSVData
->maCtrlData
.mpFieldUnitStrings
->reserve( nUnits
);
207 for( sal_uInt32 i
= 0; i
< nUnits
; i
++ )
209 std::pair
< OUString
, FieldUnit
> aElement( aUnits
.GetString(i
), static_cast<FieldUnit
>(aUnits
.GetValue(i
)) );
210 pSVData
->maCtrlData
.mpFieldUnitStrings
->push_back( aElement
);
214 return pSVData
->maCtrlData
.mpFieldUnitStrings
;
217 FieldUnitStringList
* ImplGetCleanedFieldUnits()
219 ImplSVData
* pSVData
= ImplGetSVData();
220 if( ! pSVData
->maCtrlData
.mpCleanUnitStrings
)
222 FieldUnitStringList
* pUnits
= ImplGetFieldUnits();
225 size_t nUnits
= pUnits
->size();
226 pSVData
->maCtrlData
.mpCleanUnitStrings
= new FieldUnitStringList
;
227 pSVData
->maCtrlData
.mpCleanUnitStrings
->reserve( nUnits
);
228 for( size_t i
= 0; i
< nUnits
; ++i
)
230 OUString
aUnit( (*pUnits
)[i
].first
);
231 aUnit
= aUnit
.replaceAll(" ", "");
232 aUnit
= aUnit
.toAsciiLowerCase();
233 std::pair
< OUString
, FieldUnit
> aElement( aUnit
, (*pUnits
)[i
].second
);
234 pSVData
->maCtrlData
.mpCleanUnitStrings
->push_back( aElement
);
238 return pSVData
->maCtrlData
.mpCleanUnitStrings
;
241 DockingManager
* ImplGetDockingManager()
243 ImplSVData
* pSVData
= ImplGetSVData();
244 if ( !pSVData
->mpDockingManager
)
245 pSVData
->mpDockingManager
= new DockingManager();
247 return pSVData
->mpDockingManager
;
250 BlendFrameCache
* ImplGetBlendFrameCache()
252 ImplSVData
* pSVData
= ImplGetSVData();
253 if ( !pSVData
->mpBlendFrameCache
)
254 pSVData
->mpBlendFrameCache
= new BlendFrameCache();
256 return pSVData
->mpBlendFrameCache
;
260 bool ImplInitAccessBridge()
262 ImplSVData
* pSVData
= ImplGetSVData();
263 if( ! pSVData
->mxAccessBridge
.is() )
265 css::uno::Reference
< XComponentContext
> xContext(comphelper::getProcessComponentContext());
267 if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
269 SAL_INFO("vcl", "Apparently no running AT -> "
270 "not enabling IAccessible2 integration");
275 pSVData
->mxAccessBridge
276 = css::accessibility::MSAAService::create(xContext
);
277 SAL_INFO("vcl", "got IAccessible2 bridge");
279 } catch (css::uno::DeploymentException
& e
) {
282 "got no IAccessible2 bridge" << e
.Message
);
292 void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster
*, ConfigurationHints nHint
)
294 AllSettings::LocaleSettingsChanged( nHint
);
298 ImplSVData::~ImplSVData() {}
299 ImplSVAppData::~ImplSVAppData() {}
300 ImplSVGDIData::~ImplSVGDIData() {}
301 ImplSVWinData::~ImplSVWinData() {}
302 ImplSVHelpData::~ImplSVHelpData() {}
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */