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