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