LibreOffice Module vcl (master) 1
svdata.cxx
Go to the documentation of this file.
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
22#include <comphelper/lok.hxx>
25#include <unotools/resmgr.hxx>
26#include <sal/log.hxx>
27
28#include <configsettings.hxx>
29#include <vcl/QueueInfo.hxx>
30#include <vcl/cvtgrf.hxx>
31#include <vcl/dockwin.hxx>
32#include <vcl/fieldvalues.hxx>
33#include <vcl/menu.hxx>
34#include <vcl/print.hxx>
35#include <vcl/settings.hxx>
36#include <vcl/svapp.hxx>
37#include <vcl/virdev.hxx>
38#include <vcl/wrkwin.hxx>
39#include <vcl/uitest/logger.hxx>
40#include <salframe.hxx>
41#include <scrwnd.hxx>
42#include <helpwin.hxx>
44#include <salinst.hxx>
45#include <salgdi.hxx>
46#include <svdata.hxx>
47#include <salsys.hxx>
48#include <windowdev.hxx>
49#include <units.hrc>
50#include <print.h>
51
52#include <com/sun/star/accessibility/MSAAService.hpp>
53
54#include <config_features.h>
56#include <mutex>
57
58using namespace com::sun::star::uno;
59using namespace com::sun::star::lang;
60using namespace com::sun::star::awt;
61
62namespace
63{
64 struct private_aImplSVData :
65 public rtl::Static<ImplSVData, private_aImplSVData> {};
67 struct private_aImplSVHelpData :
68 public rtl::Static<ImplSVHelpData, private_aImplSVHelpData> {};
69
71 struct private_aImplSVWinData :
72 public rtl::Static<ImplSVWinData, private_aImplSVWinData> {};
73
74}
75
77 return &private_aImplSVData::get();
78}
79
81{
82 ImplSVData* pSVData = ImplGetSVData();
83 if( ! pSVData->mpSalSystem )
84 pSVData->mpSalSystem.reset( pSVData->mpDefInst->CreateSalSystem() );
85 return pSVData->mpSalSystem.get();
86}
87
89{
90 ImplSVData* pSVData = ImplGetSVData();
91
92 // delete global instance data
93 pSVData->mpSettingsConfigItem.reset();
94
95 pSVData->mpDockingManager.reset();
96
97 pSVData->maCtrlData.maFieldUnitStrings.clear();
98 pSVData->maCtrlData.maCleanUnitStrings.clear();
99 pSVData->maPaperNames.clear();
100}
101
102namespace
103{
104 typedef ::std::map< basegfx::SystemDependentData_SharedPtr, sal_uInt32 > EntryMap;
105
106 class SystemDependentDataBuffer final : public basegfx::SystemDependentDataManager
107 {
108 private:
109 std::mutex m_aMutex;
110 std::unique_ptr<AutoTimer> maTimer;
111 EntryMap maEntries;
112
113 DECL_LINK(implTimeoutHdl, Timer *, void);
114
115 public:
116 SystemDependentDataBuffer(const char* pDebugName)
117 : maTimer(std::make_unique<AutoTimer>(pDebugName))
118 {
119 maTimer->SetTimeout(1000);
120 maTimer->SetInvokeHandler(LINK(this, SystemDependentDataBuffer, implTimeoutHdl));
121 }
122
123 virtual ~SystemDependentDataBuffer() override
124 {
125 flushAll();
126 }
127
129 {
130 std::unique_lock aGuard(m_aMutex);
131 EntryMap::iterator aFound(maEntries.find(rData));
132
133 if(aFound == maEntries.end())
134 {
135 if(maTimer && !maTimer->IsActive())
136 {
137 maTimer->Start();
138 }
139
140 maEntries[rData] = rData->calculateCombinedHoldCyclesInSeconds();
141 }
142 }
143
145 {
146 std::unique_lock aGuard(m_aMutex);
147 EntryMap::iterator aFound(maEntries.find(rData));
148
149 if(aFound != maEntries.end())
150 {
151 maEntries.erase(aFound);
152 }
153 }
154
156 {
157 std::unique_lock aGuard(m_aMutex);
158 EntryMap::iterator aFound(maEntries.find(rData));
159
160 if(aFound != maEntries.end())
161 {
162 aFound->second = rData->calculateCombinedHoldCyclesInSeconds();
163 }
164 }
165
166 void flushAll() override
167 {
168 std::unique_lock aGuard(m_aMutex);
169
170 if(maTimer)
171 {
172 maTimer->Stop();
173 maTimer.reset();
174 }
175
176 maEntries.clear();
177 }
178 };
179
180 IMPL_LINK_NOARG(SystemDependentDataBuffer, implTimeoutHdl, Timer *, void)
181 {
182 std::unique_lock aGuard(m_aMutex);
183 EntryMap::iterator aIter(maEntries.begin());
184
185 while(aIter != maEntries.end())
186 {
187 if(aIter->second)
188 {
189 aIter->second--;
190 ++aIter;
191 }
192 else
193 {
194 aIter = maEntries.erase(aIter);
195 }
196 }
197
198 if (maEntries.empty())
199 maTimer->Stop();
200 }
201}
202
204{
205 static SystemDependentDataBuffer aSystemDependentDataBuffer("vcl SystemDependentDataBuffer aSystemDependentDataBuffer");
206
207 return aSystemDependentDataBuffer;
208}
209
212{
213 ImplSVData* pSVData = ImplGetSVData();
214 if (pSVData->maFrameData.mpAppWin)
215 return pSVData->maFrameData.mpAppWin;
216 else
218}
219
222{
223 ImplSVData* pSVData = ImplGetSVData();
224
225 // Double check locking on mpDefaultWin.
226 if ( !pSVData->mpDefaultWin )
227 {
228 SolarMutexGuard aGuard;
229
230 if (!pSVData->mpDefaultWin && !pSVData->mbDeInit)
231 {
232 try
233 {
234 SAL_INFO( "vcl", "ImplGetDefaultWindow(): No AppWindow" );
235
237 pSVData->mpDefaultWin->SetText( "VCL ImplGetDefaultWindow" );
238 }
239 catch (const css::uno::Exception&)
240 {
241 TOOLS_WARN_EXCEPTION("vcl", "unable to create Default Window");
242 }
243 }
244 }
245
246 return pSVData->mpDefaultWin;
247}
248
249const std::locale& ImplGetResLocale()
250{
251 ImplSVData* pSVData = ImplGetSVData();
253 {
254 pSVData->maResLocale = Translate::Create("vcl");
255 pSVData->mbResLocaleSet = true;
256 }
257 return pSVData->maResLocale;
258}
259
261{
262 return Translate::get(aId, ImplGetResLocale());
263}
264
266{
267 ImplSVData* pSVData = ImplGetSVData();
268 if( pSVData->maCtrlData.maFieldUnitStrings.empty() )
269 {
270 sal_uInt32 nUnits = SAL_N_ELEMENTS(SV_FUNIT_STRINGS);
271 pSVData->maCtrlData.maFieldUnitStrings.reserve( nUnits );
272 for (sal_uInt32 i = 0; i < nUnits; i++)
273 {
274 std::pair<OUString, FieldUnit> aElement(VclResId(SV_FUNIT_STRINGS[i].first), SV_FUNIT_STRINGS[i].second);
275 pSVData->maCtrlData.maFieldUnitStrings.push_back( aElement );
276 }
277 }
278 return pSVData->maCtrlData.maFieldUnitStrings;
279}
280
281namespace vcl
282{
283 FieldUnit EnglishStringToMetric(std::string_view rEnglishMetricString)
284 {
285 sal_uInt32 nUnits = SAL_N_ELEMENTS(SV_FUNIT_STRINGS);
286 for (sal_uInt32 i = 0; i < nUnits; ++i)
287 {
288 if (rEnglishMetricString == SV_FUNIT_STRINGS[i].first.mpId)
289 return SV_FUNIT_STRINGS[i].second;
290 }
291 return FieldUnit::NONE;
292 }
293}
294
296{
297 ImplSVData* pSVData = ImplGetSVData();
298 if( pSVData->maCtrlData.maCleanUnitStrings.empty() )
299 {
300 const FieldUnitStringList& rUnits = ImplGetFieldUnits();
301 size_t nUnits = rUnits.size();
302 pSVData->maCtrlData.maCleanUnitStrings.reserve(nUnits);
303 for (size_t i = 0; i < nUnits; ++i)
304 {
305 OUString aUnit(rUnits[i].first);
306 aUnit = aUnit.replaceAll(" ", "");
307 aUnit = aUnit.toAsciiLowerCase();
308 std::pair<OUString, FieldUnit> aElement(aUnit, rUnits[i].second);
309 pSVData->maCtrlData.maCleanUnitStrings.push_back(aElement);
310 }
311 }
312 return pSVData->maCtrlData.maCleanUnitStrings;
313}
314
316{
317 ImplSVData* pSVData = ImplGetSVData();
318 if ( !pSVData->mpDockingManager )
319 pSVData->mpDockingManager.reset(new DockingManager());
320
321 return pSVData->mpDockingManager.get();
322}
323
325{
326 ImplSVData* pSVData = ImplGetSVData();
327 if ( !pSVData->mpBlendFrameCache)
328 pSVData->mpBlendFrameCache.reset( new BlendFrameCache() );
329
330 return pSVData->mpBlendFrameCache.get();
331}
332
333#ifdef _WIN32
334bool ImplInitAccessBridge()
335{
336 ImplSVData* pSVData = ImplGetSVData();
337 if( ! pSVData->mxAccessBridge.is() )
338 {
339 css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
340
341 if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
342 {
343 SAL_INFO("vcl", "Apparently no running AT -> "
344 "not enabling IAccessible2 integration");
345 }
346 else
347 {
348 try {
349 pSVData->mxAccessBridge
350 = css::accessibility::MSAAService::create(xContext);
351 SAL_INFO("vcl", "got IAccessible2 bridge");
352 return true;
353 } catch (css::uno::DeploymentException &) {
355 "vcl",
356 "got no IAccessible2 bridge");
357 return false;
358 }
359 }
360 }
361
362 return true;
363}
364#endif
365
367{
369}
370
372{
374 return nullptr;
375
377
378 ImplSVData* pSVData = ImplGetSVData();
379 assert(pSVData && pSVData->mpWinData);
380
381 p->mpFocusWin = pSVData->mpWinData->mpFocusWin;
382 return p;
383}
384
386{
387 delete pData;
388}
389
391{
393 return;
394
395 ImplSVData* pSVData = ImplGetSVData();
396 assert(pSVData != nullptr);
397
398 if (pSVData->mpWinData == pSVWinData)
399 return;
400
401 // If current one is the static, clean it up to avoid having lingering references.
402 if (pSVData->mpWinData == &private_aImplSVWinData::get())
403 {
404 pSVData->mpWinData->mpFocusWin.reset();
405 }
406
407 pSVData->mpWinData = pSVWinData;
408 if (pSVData->mpWinData == nullptr)
409 {
410 pSVData->mpWinData = &private_aImplSVWinData::get(); // Never leave it null.
411 }
412}
413
415{
416 mpHelpData = &private_aImplSVHelpData::get();
417 mpWinData = &private_aImplSVWinData::get();
418}
419
421{
423 return nullptr;
424
425 ImplSVHelpData* pNewData = new ImplSVHelpData;
426
427 // Set options set globally
428 ImplSVHelpData& aStaticHelpData = private_aImplSVHelpData::get();
429 pNewData->mbContextHelp = aStaticHelpData.mbContextHelp;
430 pNewData->mbExtHelp = aStaticHelpData.mbExtHelp;
431 pNewData->mbExtHelpMode = aStaticHelpData.mbExtHelpMode;
432 pNewData->mbOldBalloonMode = aStaticHelpData.mbOldBalloonMode;
433 pNewData->mbBalloonHelp = aStaticHelpData.mbBalloonHelp;
434 pNewData->mbQuickHelp = aStaticHelpData.mbQuickHelp;
435
436 return pNewData;
437}
438
440{
442 return;
443
444 // Change the SVData's help date if necessary
445 if(ImplGetSVData()->mpHelpData == pSVHelpData)
446 {
447 ImplGetSVData()->mpHelpData = &private_aImplSVHelpData::get();
448 }
449
450 if(pSVHelpData)
451 {
452 ImplDestroyHelpWindow(*pSVHelpData, false);
453 delete pSVHelpData;
454 }
455}
456
458{
460 return;
461
462 ImplSVData* pSVData = ImplGetSVData();
463 if (pSVData->mpHelpData == pSVHelpData)
464 return;
465
466 // If current one is the static, clean it up to avoid having lingering references.
467 if (pSVData->mpHelpData == &private_aImplSVHelpData::get())
468 {
469 pSVData->mpHelpData->mpHelpWin.reset();
470 }
471
472 pSVData->mpHelpData = pSVHelpData;
473 if (pSVData->mpHelpData == nullptr)
474 {
475 pSVData->mpHelpData = &private_aImplSVHelpData::get(); // Never leave it null.
476 }
477}
478
480{
481 ImplSVData* pSVData = ImplGetSVData();
482 if(pSVData->mpHelpData)
483 {
484 return *pSVData->mpHelpData;
485 }
486 else
487 {
488 return private_aImplSVHelpData::get();
489 }
490}
491
493
495{
496 m_bUseSystemLoop = getenv("SAL_USE_SYSTEM_LOOP") != nullptr;
497 SAL_WARN_IF(m_bUseSystemLoop, "vcl.schedule", "Overriding to run LO on system event loop!");
498}
499
505
506/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
Definition: Animation.cxx:283
static SAL_DLLPRIVATE void LocaleSettingsChanged(ConfigurationHints nHint)
An auto-timer is a multi-shot timer re-emitting itself at interval until destroyed or stopped.
Definition: timer.hxx:67
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: svdata.cxx:366
virtual SalSystem * CreateSalSystem()=0
virtual void SetText(const OUString &rStr) override
Definition: syswin.cxx:1051
Definition: timer.hxx:27
void reset(reference_type *pBody)
Definition: vclptr.hxx:153
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
virtual void endUsage(basegfx::SystemDependentData_SharedPtr &rData)=0
virtual void startUsage(basegfx::SystemDependentData_SharedPtr &rData)=0
virtual void touchUsage(basegfx::SystemDependentData_SharedPtr &rData)=0
#define TOOLS_WARN_EXCEPTION(area, stream)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
FieldUnit
void ImplDestroyHelpWindow(bool bUpdateHideTime)
Definition: help.cxx:550
std::mutex m_aMutex
void * p
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
#define SAL_N_ELEMENTS(arr)
std::unique_ptr< sal_Int32[]> pData
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
Reference< XComponentContext > getProcessComponentContext()
int i
constexpr OUStringLiteral first
FieldUnit EnglishStringToMetric(std::string_view rEnglishMetricString)
Definition: svdata.cxx:283
ConfigurationHints
bool m_bUseSystemLoop
Definition: svdata.hxx:163
FieldUnitStringList maCleanUnitStrings
Definition: svdata.hxx:292
FieldUnitStringList maFieldUnitStrings
Definition: svdata.hxx:291
ImplSVCtrlData maCtrlData
Definition: svdata.hxx:404
bool mbDeInit
Definition: svdata.hxx:395
ImplSVFrameData maFrameData
Definition: svdata.hxx:402
bool mbResLocaleSet
Definition: svdata.hxx:397
~ImplSVData()
Definition: svdata.cxx:492
SalInstance * mpDefInst
Definition: svdata.hxx:392
std::unique_ptr< DockingManager > mpDockingManager
Definition: svdata.hxx:409
std::unique_ptr< BlendFrameCache > mpBlendFrameCache
Definition: svdata.hxx:410
ImplSVHelpData * mpHelpData
Definition: svdata.hxx:405
ImplSVData()
Definition: svdata.cxx:414
css::uno::Reference< css::lang::XComponent > mxAccessBridge
Definition: svdata.hxx:415
VclPtr< WorkWindow > mpDefaultWin
Definition: svdata.hxx:394
ImplSVWinData * mpWinData
Definition: svdata.hxx:403
std::locale maResLocale
Definition: svdata.hxx:398
std::unique_ptr< SalSystem > mpSalSystem
Definition: svdata.hxx:396
std::unique_ptr< vcl::SettingsConfigItem > mpSettingsConfigItem
Definition: svdata.hxx:416
std::unordered_map< int, OUString > maPaperNames
Definition: svdata.hxx:418
VclPtr< WorkWindow > mpAppWin
Definition: svdata.hxx:247
VclPtr< HelpTextWindow > mpHelpWin
Definition: svdata.hxx:307
bool mbOldBalloonMode
Definition: svdata.hxx:301
bool mbExtHelpMode
Definition: svdata.hxx:300
bool mbBalloonHelp
Definition: svdata.hxx:302
bool mbQuickHelp
Definition: svdata.hxx:303
bool mbContextHelp
Definition: svdata.hxx:298
bool mbExtHelp
Definition: svdata.hxx:299
VclPtr< vcl::Window > mpFocusWin
Definition: svdata.hxx:255
ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:371
SalSystem * ImplGetSalSystem()
Definition: svdata.cxx:80
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:76
void DestroySVWinData(ImplSVWinData *pData)
Definition: svdata.cxx:385
void ImplDeInitSVData()
Definition: svdata.cxx:88
void DestroySVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:439
const std::locale & ImplGetResLocale()
Definition: svdata.cxx:249
vcl::Window * ImplGetDefaultWindow()
Returns either the application window, or the default GL context window.
Definition: svdata.cxx:211
BlendFrameCache * ImplGetBlendFrameCache()
Definition: svdata.cxx:324
ImplSVHelpData & ImplGetSVHelpData()
Definition: svdata.cxx:479
void SetSVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:457
void SetSVWinData(ImplSVWinData *pSVWinData)
Definition: svdata.cxx:390
const FieldUnitStringList & ImplGetFieldUnits()
Definition: svdata.cxx:265
DockingManager * ImplGetDockingManager()
Definition: svdata.cxx:315
OUString VclResId(TranslateId aId)
Definition: svdata.cxx:260
ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:420
const FieldUnitStringList & ImplGetCleanedFieldUnits()
Definition: svdata.cxx:295
vcl::Window * ImplGetDefaultContextWindow()
returns the default window created to hold the persistent VCL GL context.
Definition: svdata.cxx:221
basegfx::SystemDependentDataManager & ImplGetSystemDependentDataManager()
Definition: svdata.cxx:203
std::vector< std::pair< OUString, FieldUnit > > FieldUnitStringList
Definition: svdata.hxx:274
WinBits const WB_DEFAULTWIN
Definition: wintypes.hxx:174