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/debug.hxx>
27 #include <tools/resary.hxx>
28 #include <tools/gen.hxx>
29 #include <uno/current_context.hxx>
31 #include <vcl/configsettings.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/settings.hxx>
34 #include <vcl/wrkwin.hxx>
35 #include <vcl/layout.hxx>
36 #include <vcl/button.hxx>
37 #include <vcl/dockwin.hxx>
38 #include <vcl/print.hxx>
39 #include <vcl/virdev.hxx>
40 #include "salinst.hxx"
41 #include "salframe.hxx"
45 #include "salimestatus.hxx"
48 #include "helpwin.hxx"
49 #include "../window/scrwnd.hxx"
51 #include "com/sun/star/accessibility/MSAAService.hpp"
53 #include "officecfg/Office/Common.hxx"
55 #include <config_features.h>
56 #if HAVE_FEATURE_OPENGL
57 #include <vcl/opengl/OpenGLContext.hxx>
60 using namespace com::sun::star::uno
;
61 using namespace com::sun::star::lang
;
62 using namespace com::sun::star::awt
;
66 struct private_aImplSVData
:
67 public rtl::Static
<ImplSVData
, private_aImplSVData
> {};
70 ImplSVData
* ImplGetSVData() {
71 return &private_aImplSVData::get();
74 SalSystem
* ImplGetSalSystem()
76 ImplSVData
* pSVData
= ImplGetSVData();
77 if( ! pSVData
->mpSalSystem
)
78 pSVData
->mpSalSystem
= pSVData
->mpDefInst
->CreateSalSystem();
79 return pSVData
->mpSalSystem
;
82 ImplSVGDIData::~ImplSVGDIData()
84 // FIXME: deliberately leak any remaining OutputDevice
85 // until we have their pGraphics reference counted, doing
86 // any disposes so late in shutdown is rather unsafe.
87 memset( this, 0, sizeof( ImplSVGDIData
) );
90 void ImplDeInitSVData()
92 ImplSVData
* pSVData
= ImplGetSVData();
94 // delete global instance data
95 if( pSVData
->mpSettingsConfigItem
)
97 delete pSVData
->mpSettingsConfigItem
;
98 pSVData
->mpSettingsConfigItem
= nullptr;
101 if( pSVData
->mpDockingManager
)
103 delete pSVData
->mpDockingManager
;
104 pSVData
->mpDockingManager
= nullptr;
107 if( pSVData
->maCtrlData
.mpFieldUnitStrings
)
109 delete pSVData
->maCtrlData
.mpFieldUnitStrings
;
110 pSVData
->maCtrlData
.mpFieldUnitStrings
= nullptr;
112 if( pSVData
->maCtrlData
.mpCleanUnitStrings
)
114 delete pSVData
->maCtrlData
.mpCleanUnitStrings
;
115 pSVData
->maCtrlData
.mpCleanUnitStrings
= nullptr;
117 if( pSVData
->mpPaperNames
)
119 delete pSVData
->mpPaperNames
;
120 pSVData
->mpPaperNames
= nullptr;
124 /// Returns either the application window, or the default GL context window
125 vcl::Window
* ImplGetDefaultWindow()
127 ImplSVData
* pSVData
= ImplGetSVData();
128 if ( pSVData
->maWinData
.mpAppWin
)
129 return pSVData
->maWinData
.mpAppWin
;
131 return ImplGetDefaultContextWindow();
134 /// returns the default window created to hold the persistent VCL GL context.
135 vcl::Window
*ImplGetDefaultContextWindow()
137 ImplSVData
* pSVData
= ImplGetSVData();
139 // Double check locking on mpDefaultWin.
140 if ( !pSVData
->mpDefaultWin
)
142 SolarMutexGuard aGuard
;
144 if ( !pSVData
->mpDefaultWin
&& !pSVData
->mbDeInit
)
146 SAL_INFO( "vcl", "ImplGetDefaultWindow(): No AppWindow" );
147 pSVData
->mpDefaultWin
= VclPtr
<WorkWindow
>::Create( nullptr, WB_DEFAULTWIN
);
148 pSVData
->mpDefaultWin
->SetText( "VCL ImplGetDefaultWindow" );
150 #if HAVE_FEATURE_OPENGL
151 // Add a reference to the default context so it never gets deleted
152 rtl::Reference
<OpenGLContext
> pContext
= pSVData
->mpDefaultWin
->GetGraphics()->GetOpenGLContext();
159 return pSVData
->mpDefaultWin
;
162 ResMgr
* ImplGetResMgr()
164 ImplSVData
* pSVData
= ImplGetSVData();
165 LanguageTag
aLocale(Application::GetSettings().GetUILanguageTag());
166 if (!pSVData
->mpResMgr
|| pSVData
->mpResMgr
->GetLocale() != aLocale
)
168 pSVData
->mpResMgr
.reset(ResMgr::SearchCreateResMgr("vcl", aLocale
));
170 static bool bMessageOnce
= false;
171 if( !pSVData
->mpResMgr
&& ! bMessageOnce
)
175 "Missing vcl resource. This indicates that files vital to localization are missing. "
176 "You might have a corrupt installation.";
177 SAL_WARN("vcl", "" << pMsg
<< "\n");
178 ScopedVclPtrInstance
< MessageDialog
> aBox( nullptr, OUString(pMsg
, strlen(pMsg
), RTL_TEXTENCODING_ASCII_US
) );
182 return pSVData
->mpResMgr
.get();
185 ResId
VclResId( sal_Int32 nId
)
187 ResMgr
* pMgr
= ImplGetResMgr();
189 throw std::bad_alloc();
191 return ResId( nId
, *pMgr
);
194 FieldUnitStringList
* ImplGetFieldUnits()
196 ImplSVData
* pSVData
= ImplGetSVData();
197 if( ! pSVData
->maCtrlData
.mpFieldUnitStrings
)
199 ResMgr
* pResMgr
= ImplGetResMgr();
202 ResStringArray
aUnits( ResId (SV_FUNIT_STRINGS
, *pResMgr
) );
203 sal_uInt32 nUnits
= aUnits
.Count();
204 pSVData
->maCtrlData
.mpFieldUnitStrings
= new FieldUnitStringList();
205 pSVData
->maCtrlData
.mpFieldUnitStrings
->reserve( nUnits
);
206 for( sal_uInt32 i
= 0; i
< nUnits
; i
++ )
208 std::pair
< OUString
, FieldUnit
> aElement( aUnits
.GetString(i
), static_cast<FieldUnit
>(aUnits
.GetValue(i
)) );
209 pSVData
->maCtrlData
.mpFieldUnitStrings
->push_back( aElement
);
213 return pSVData
->maCtrlData
.mpFieldUnitStrings
;
216 FieldUnitStringList
* ImplGetCleanedFieldUnits()
218 ImplSVData
* pSVData
= ImplGetSVData();
219 if( ! pSVData
->maCtrlData
.mpCleanUnitStrings
)
221 FieldUnitStringList
* pUnits
= ImplGetFieldUnits();
224 size_t nUnits
= pUnits
->size();
225 pSVData
->maCtrlData
.mpCleanUnitStrings
= new FieldUnitStringList();
226 pSVData
->maCtrlData
.mpCleanUnitStrings
->reserve( nUnits
);
227 for( size_t i
= 0; i
< nUnits
; ++i
)
229 OUString
aUnit( (*pUnits
)[i
].first
);
230 aUnit
= aUnit
.replaceAll(" ", "");
231 aUnit
= aUnit
.toAsciiLowerCase();
232 std::pair
< OUString
, FieldUnit
> aElement( aUnit
, (*pUnits
)[i
].second
);
233 pSVData
->maCtrlData
.mpCleanUnitStrings
->push_back( aElement
);
237 return pSVData
->maCtrlData
.mpCleanUnitStrings
;
240 DockingManager
* ImplGetDockingManager()
242 ImplSVData
* pSVData
= ImplGetSVData();
243 if ( !pSVData
->mpDockingManager
)
244 pSVData
->mpDockingManager
= new DockingManager();
246 return pSVData
->mpDockingManager
;
249 BlendFrameCache
* ImplGetBlendFrameCache()
251 ImplSVData
* pSVData
= ImplGetSVData();
252 if ( !pSVData
->mpBlendFrameCache
)
253 pSVData
->mpBlendFrameCache
= new BlendFrameCache();
255 return pSVData
->mpBlendFrameCache
;
259 bool ImplInitAccessBridge()
261 ImplSVData
* pSVData
= ImplGetSVData();
262 if( ! pSVData
->mxAccessBridge
.is() )
264 css::uno::Reference
< XComponentContext
> xContext(comphelper::getProcessComponentContext());
266 if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
268 SAL_INFO("vcl", "Apparently no running AT -> "
269 "not enabling IAccessible2 integration");
274 pSVData
->mxAccessBridge
275 = css::accessibility::MSAAService::create(xContext
);
276 SAL_INFO("vcl", "got IAccessible2 bridge");
278 } catch (css::uno::DeploymentException
& e
) {
281 "got no IAccessible2 bridge" << e
.Message
);
291 void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster
*, ConfigurationHints nHint
)
293 AllSettings::LocaleSettingsChanged( nHint
);
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */