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  : maTimer(std::make_unique<AutoTimer>(pDebugName))
116  {
117  maTimer->SetTimeout(1000);
118  maTimer->SetInvokeHandler(LINK(this, SystemDependentDataBuffer, implTimeoutHdl));
119  }
120 
121  virtual ~SystemDependentDataBuffer() override
122  {
123  flushAll();
124  }
125 
126  void startUsage(basegfx::SystemDependentData_SharedPtr& rData) override
127  {
128  ::osl::MutexGuard aGuard(m_aMutex);
129  EntryMap::iterator aFound(maEntries.find(rData));
130 
131  if(aFound == maEntries.end())
132  {
133  if(maTimer && !maTimer->IsActive())
134  {
135  maTimer->Start();
136  }
137 
138  maEntries[rData] = rData->calculateCombinedHoldCyclesInSeconds();
139  }
140  }
141 
142  void endUsage(basegfx::SystemDependentData_SharedPtr& rData) override
143  {
144  ::osl::MutexGuard aGuard(m_aMutex);
145  EntryMap::iterator aFound(maEntries.find(rData));
146 
147  if(aFound != maEntries.end())
148  {
149  maEntries.erase(aFound);
150  }
151  }
152 
153  void touchUsage(basegfx::SystemDependentData_SharedPtr& rData) override
154  {
155  ::osl::MutexGuard aGuard(m_aMutex);
156  EntryMap::iterator aFound(maEntries.find(rData));
157 
158  if(aFound != maEntries.end())
159  {
160  aFound->second = rData->calculateCombinedHoldCyclesInSeconds();
161  }
162  }
163 
164  void flushAll() override
165  {
166  ::osl::MutexGuard aGuard(m_aMutex);
167 
168  if(maTimer)
169  {
170  maTimer->Stop();
171  maTimer.reset();
172  }
173 
174  maEntries.clear();
175  }
176  };
177 
178  IMPL_LINK_NOARG(SystemDependentDataBuffer, implTimeoutHdl, Timer *, void)
179  {
180  ::osl::MutexGuard aGuard(m_aMutex);
181  EntryMap::iterator aIter(maEntries.begin());
182 
183  while(aIter != maEntries.end())
184  {
185  if(aIter->second)
186  {
187  aIter->second--;
188  ++aIter;
189  }
190  else
191  {
192  aIter = maEntries.erase(aIter);
193  }
194  }
195 
196  if (maEntries.empty())
197  maTimer->Stop();
198  }
199 }
200 
202 {
203  static SystemDependentDataBuffer aSystemDependentDataBuffer("vcl SystemDependentDataBuffer aSystemDependentDataBuffer");
204 
205  return aSystemDependentDataBuffer;
206 }
207 
210 {
211  ImplSVData* pSVData = ImplGetSVData();
212  if (pSVData->maFrameData.mpAppWin)
213  return pSVData->maFrameData.mpAppWin;
214  else
216 }
217 
220 {
221  ImplSVData* pSVData = ImplGetSVData();
222 
223  // Double check locking on mpDefaultWin.
224  if ( !pSVData->mpDefaultWin )
225  {
226  SolarMutexGuard aGuard;
227 
228  if (!pSVData->mpDefaultWin && !pSVData->mbDeInit)
229  {
230  try
231  {
232  SAL_INFO( "vcl", "ImplGetDefaultWindow(): No AppWindow" );
233 
235  pSVData->mpDefaultWin->SetText( "VCL ImplGetDefaultWindow" );
236  }
237  catch (const css::uno::Exception&)
238  {
239  TOOLS_WARN_EXCEPTION("vcl", "unable to create Default Window");
240  }
241  }
242  }
243 
244  return pSVData->mpDefaultWin;
245 }
246 
247 const std::locale& ImplGetResLocale()
248 {
249  ImplSVData* pSVData = ImplGetSVData();
251  {
252  pSVData->maResLocale = Translate::Create("vcl");
253  pSVData->mbResLocaleSet = true;
254  }
255  return pSVData->maResLocale;
256 }
257 
258 OUString VclResId(TranslateId aId)
259 {
260  return Translate::get(aId, ImplGetResLocale());
261 }
262 
264 {
265  ImplSVData* pSVData = ImplGetSVData();
266  if( pSVData->maCtrlData.maFieldUnitStrings.empty() )
267  {
268  sal_uInt32 nUnits = SAL_N_ELEMENTS(SV_FUNIT_STRINGS);
269  pSVData->maCtrlData.maFieldUnitStrings.reserve( nUnits );
270  for (sal_uInt32 i = 0; i < nUnits; i++)
271  {
272  std::pair<OUString, FieldUnit> aElement(VclResId(SV_FUNIT_STRINGS[i].first), SV_FUNIT_STRINGS[i].second);
273  pSVData->maCtrlData.maFieldUnitStrings.push_back( aElement );
274  }
275  }
276  return pSVData->maCtrlData.maFieldUnitStrings;
277 }
278 
280 {
281  ImplSVData* pSVData = ImplGetSVData();
282  if( pSVData->maCtrlData.maCleanUnitStrings.empty() )
283  {
284  const FieldUnitStringList& rUnits = ImplGetFieldUnits();
285  size_t nUnits = rUnits.size();
286  pSVData->maCtrlData.maCleanUnitStrings.reserve(nUnits);
287  for (size_t i = 0; i < nUnits; ++i)
288  {
289  OUString aUnit(rUnits[i].first);
290  aUnit = aUnit.replaceAll(" ", "");
291  aUnit = aUnit.toAsciiLowerCase();
292  std::pair<OUString, FieldUnit> aElement(aUnit, rUnits[i].second);
293  pSVData->maCtrlData.maCleanUnitStrings.push_back(aElement);
294  }
295  }
296  return pSVData->maCtrlData.maCleanUnitStrings;
297 }
298 
300 {
301  ImplSVData* pSVData = ImplGetSVData();
302  if ( !pSVData->mpDockingManager )
303  pSVData->mpDockingManager.reset(new DockingManager());
304 
305  return pSVData->mpDockingManager.get();
306 }
307 
309 {
310  ImplSVData* pSVData = ImplGetSVData();
311  if ( !pSVData->mpBlendFrameCache)
312  pSVData->mpBlendFrameCache.reset( new BlendFrameCache() );
313 
314  return pSVData->mpBlendFrameCache.get();
315 }
316 
317 #ifdef _WIN32
318 bool ImplInitAccessBridge()
319 {
320  ImplSVData* pSVData = ImplGetSVData();
321  if( ! pSVData->mxAccessBridge.is() )
322  {
323  css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
324 
325  if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
326  {
327  SAL_INFO("vcl", "Apparently no running AT -> "
328  "not enabling IAccessible2 integration");
329  }
330  else
331  {
332  try {
333  pSVData->mxAccessBridge
334  = css::accessibility::MSAAService::create(xContext);
335  SAL_INFO("vcl", "got IAccessible2 bridge");
336  return true;
337  } catch (css::uno::DeploymentException &) {
339  "vcl",
340  "got no IAccessible2 bridge");
341  return false;
342  }
343  }
344  }
345 
346  return true;
347 }
348 #endif
349 
351 {
353 }
354 
356 {
358  return nullptr;
359 
361 
362  ImplSVData* pSVData = ImplGetSVData();
363  assert(pSVData && pSVData->mpWinData);
364 
365  p->mpFocusWin = pSVData->mpWinData->mpFocusWin;
366  return p;
367 }
368 
370 {
371  delete pData;
372 }
373 
374 void SetSVWinData(ImplSVWinData* pSVWinData)
375 {
377  return;
378 
379  ImplSVData* pSVData = ImplGetSVData();
380  assert(pSVData != nullptr);
381 
382  if (pSVData->mpWinData == pSVWinData)
383  return;
384 
385  // If current one is the static, clean it up to avoid having lingering references.
386  if (pSVData->mpWinData == &private_aImplSVWinData::get())
387  {
388  pSVData->mpWinData->mpFocusWin.reset();
389  }
390 
391  pSVData->mpWinData = pSVWinData;
392  if (pSVData->mpWinData == nullptr)
393  {
394  pSVData->mpWinData = &private_aImplSVWinData::get(); // Never leave it null.
395  }
396 }
397 
399 {
400  mpHelpData = &private_aImplSVHelpData::get();
401  mpWinData = &private_aImplSVWinData::get();
402 }
403 
405 {
407  return nullptr;
408 
409  ImplSVHelpData* pNewData = new ImplSVHelpData;
410 
411  // Set options set globally
412  ImplSVHelpData& aStaticHelpData = private_aImplSVHelpData::get();
413  pNewData->mbContextHelp = aStaticHelpData.mbContextHelp;
414  pNewData->mbExtHelp = aStaticHelpData.mbExtHelp;
415  pNewData->mbExtHelpMode = aStaticHelpData.mbExtHelpMode;
416  pNewData->mbOldBalloonMode = aStaticHelpData.mbOldBalloonMode;
417  pNewData->mbBalloonHelp = aStaticHelpData.mbBalloonHelp;
418  pNewData->mbQuickHelp = aStaticHelpData.mbQuickHelp;
419 
420  return pNewData;
421 }
422 
424 {
426  return;
427 
428  // Change the SVData's help date if necessary
429  if(ImplGetSVData()->mpHelpData == pSVHelpData)
430  {
431  ImplGetSVData()->mpHelpData = &private_aImplSVHelpData::get();
432  }
433 
434  if(pSVHelpData)
435  {
436  ImplDestroyHelpWindow(*pSVHelpData, false);
437  delete pSVHelpData;
438  }
439 }
440 
441 void SetSVHelpData(ImplSVHelpData* pSVHelpData)
442 {
444  return;
445 
446  ImplSVData* pSVData = ImplGetSVData();
447  if (pSVData->mpHelpData == pSVHelpData)
448  return;
449 
450  // If current one is the static, clean it up to avoid having lingering references.
451  if (pSVData->mpHelpData == &private_aImplSVHelpData::get())
452  {
453  pSVData->mpHelpData->mpHelpWin.reset();
454  }
455 
456  pSVData->mpHelpData = pSVHelpData;
457  if (pSVData->mpHelpData == nullptr)
458  {
459  pSVData->mpHelpData = &private_aImplSVHelpData::get(); // Never leave it null.
460  }
461 }
462 
464 {
465  ImplSVData* pSVData = ImplGetSVData();
466  if(pSVData->mpHelpData)
467  {
468  return *pSVData->mpHelpData;
469  }
470  else
471  {
472  return private_aImplSVHelpData::get();
473  }
474 }
475 
482 
483 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImplSVHelpData & ImplGetSVHelpData()
Definition: svdata.cxx:463
ConfigurationHints
VclPtr< HelpTextWindow > mpHelpWin
Definition: svdata.hxx:305
std::unique_ptr< SalSystem > mpSalSystem
Definition: svdata.hxx:392
VclPtr< vcl::Window > mpFocusWin
Definition: svdata.hxx:253
const FieldUnitStringList & ImplGetCleanedFieldUnits()
Definition: svdata.cxx:279
void SetSVWinData(ImplSVWinData *pSVWinData)
Definition: svdata.cxx:374
std::unique_ptr< vcl::SettingsConfigItem > mpSettingsConfigItem
Definition: svdata.hxx:412
css::uno::Reference< css::lang::XComponent > mxAccessBridge
Definition: svdata.hxx:411
~ImplSVData()
Definition: svdata.cxx:476
void DestroySVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:423
ImplSVData()
Definition: svdata.cxx:398
ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:404
BlendFrameCache * ImplGetBlendFrameCache()
Definition: svdata.cxx:308
ImplSVCtrlData maCtrlData
Definition: svdata.hxx:400
bool mbExtHelpMode
Definition: svdata.hxx:298
bool mbResLocaleSet
Definition: svdata.hxx:393
ImplSVHelpData * mpHelpData
Definition: svdata.hxx:401
std::unique_ptr< BlendFrameCache > mpBlendFrameCache
Definition: svdata.hxx:406
basegfx::SystemDependentDataManager & ImplGetSystemDependentDataManager()
Definition: svdata.cxx:201
OUString VclResId(TranslateId aId)
Definition: svdata.cxx:258
#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:219
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:290
bool mbQuickHelp
Definition: svdata.hxx:301
bool mbExtHelp
Definition: svdata.hxx:297
VclPtr< WorkWindow > mpAppWin
Definition: svdata.hxx:245
OUString get(TranslateId sContextAndId, const std::locale &loc)
static void LocaleSettingsChanged(ConfigurationHints nHint)
bool mbContextHelp
Definition: svdata.hxx:296
void reset(reference_type *pBody)
Definition: vclptr.hxx:153
const std::locale & ImplGetResLocale()
Definition: svdata.cxx:247
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: svdata.cxx:350
bool mbBalloonHelp
Definition: svdata.hxx:300
DockingManager * ImplGetDockingManager()
Definition: svdata.cxx:299
bool mbOldBalloonMode
Definition: svdata.hxx:299
void ImplDeInitSVData()
Definition: svdata.cxx:87
ImplSVFrameData maFrameData
Definition: svdata.hxx:398
#define SAL_INFO(area, stream)
void SetSVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:441
virtual void SetText(const OUString &rStr) override
Definition: syswin.cxx:1051
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
bool mbDeInit
Definition: svdata.hxx:391
void DestroySVWinData(ImplSVWinData *pData)
Definition: svdata.cxx:369
void * p
Reference< XComponentContext > getProcessComponentContext()
std::vector< std::pair< OUString, FieldUnit > > FieldUnitStringList
Definition: svdata.hxx:272
IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
Definition: Animation.cxx:278
WinBits const WB_DEFAULTWIN
ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:355
FieldUnitStringList maFieldUnitStrings
Definition: svdata.hxx:289
Definition: timer.hxx:26
std::unique_ptr< DockingManager > mpDockingManager
Definition: svdata.hxx:405
const FieldUnitStringList & ImplGetFieldUnits()
Definition: svdata.cxx:263
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:209
std::locale maResLocale
Definition: svdata.hxx:394
SalInstance * mpDefInst
Definition: svdata.hxx:388
std::unordered_map< int, OUString > maPaperNames
Definition: svdata.hxx:414
void ImplDestroyHelpWindow(bool bUpdateHideTime)
Definition: help.cxx:551
ImplSVWinData * mpWinData
Definition: svdata.hxx:399
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
VclPtr< WorkWindow > mpDefaultWin
Definition: svdata.hxx:390