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/dockwin.hxx>
31 #include <vcl/menu.hxx>
32 #include <vcl/print.hxx>
33 #include <vcl/settings.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/virdev.hxx>
36 #include <vcl/wrkwin.hxx>
37 #include <vcl/uitest/logger.hxx>
38 #include <salframe.hxx>
39 #include <scrwnd.hxx>
40 #include <helpwin.hxx>
41 #include <vcl/toolkit/dialog.hxx>
42 #include <salinst.hxx>
43 #include <salgdi.hxx>
44 #include <svdata.hxx>
45 #include <salsys.hxx>
46 #include <units.hrc>
47 #include <print.h>
48 
49 #include <com/sun/star/accessibility/MSAAService.hpp>
50 
51 #include <config_features.h>
52 #if HAVE_FEATURE_OPENGL
54 #endif
56 #include <cppuhelper/basemutex.hxx>
57 
58 using namespace com::sun::star::uno;
59 using namespace com::sun::star::lang;
60 using namespace com::sun::star::awt;
61 
62 namespace
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 
102 namespace
103 {
104  typedef ::std::map< basegfx::SystemDependentData_SharedPtr, sal_uInt32 > EntryMap;
105 
106  class SystemDependentDataBuffer final : public basegfx::SystemDependentDataManager, protected cppu::BaseMutex
107  {
108  private:
109  std::unique_ptr<AutoTimer> maTimer;
110  EntryMap maEntries;
111 
112  DECL_LINK(implTimeoutHdl, Timer *, void);
113 
114  public:
115  SystemDependentDataBuffer(const char* pDebugName)
116  : basegfx::SystemDependentDataManager(),
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 
128  void startUsage(basegfx::SystemDependentData_SharedPtr& rData) override
129  {
130  ::osl::MutexGuard 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 
144  void endUsage(basegfx::SystemDependentData_SharedPtr& rData) override
145  {
146  ::osl::MutexGuard aGuard(m_aMutex);
147  EntryMap::iterator aFound(maEntries.find(rData));
148 
149  if(aFound != maEntries.end())
150  {
151  maEntries.erase(aFound);
152  }
153  }
154 
155  void touchUsage(basegfx::SystemDependentData_SharedPtr& rData) override
156  {
157  ::osl::MutexGuard 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  ::osl::MutexGuard 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  ::osl::MutexGuard 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 #if HAVE_FEATURE_OPENGL
240  // Add a reference to the default context so it never gets deleted
242  if( pContext.is() )
243  pContext->acquire();
244 #endif
245  }
246  catch (const css::uno::Exception&)
247  {
248  TOOLS_WARN_EXCEPTION("vcl", "unable to create Default Window");
249  }
250  }
251  }
252 
253  return pSVData->mpDefaultWin;
254 }
255 
256 const std::locale& ImplGetResLocale()
257 {
258  ImplSVData* pSVData = ImplGetSVData();
260  {
261  pSVData->maResLocale = Translate::Create("vcl");
262  pSVData->mbResLocaleSet = true;
263  }
264  return pSVData->maResLocale;
265 }
266 
267 OUString VclResId(const char* pId)
268 {
269  return Translate::get(pId, ImplGetResLocale());
270 }
271 
273 {
274  ImplSVData* pSVData = ImplGetSVData();
275  if( pSVData->maCtrlData.maFieldUnitStrings.empty() )
276  {
277  sal_uInt32 nUnits = SAL_N_ELEMENTS(SV_FUNIT_STRINGS);
278  pSVData->maCtrlData.maFieldUnitStrings.reserve( nUnits );
279  for (sal_uInt32 i = 0; i < nUnits; i++)
280  {
281  std::pair<OUString, FieldUnit> aElement(VclResId(SV_FUNIT_STRINGS[i].first), SV_FUNIT_STRINGS[i].second);
282  pSVData->maCtrlData.maFieldUnitStrings.push_back( aElement );
283  }
284  }
285  return pSVData->maCtrlData.maFieldUnitStrings;
286 }
287 
289 {
290  ImplSVData* pSVData = ImplGetSVData();
291  if( pSVData->maCtrlData.maCleanUnitStrings.empty() )
292  {
293  const FieldUnitStringList& rUnits = ImplGetFieldUnits();
294  size_t nUnits = rUnits.size();
295  pSVData->maCtrlData.maCleanUnitStrings.reserve(nUnits);
296  for (size_t i = 0; i < nUnits; ++i)
297  {
298  OUString aUnit(rUnits[i].first);
299  aUnit = aUnit.replaceAll(" ", "");
300  aUnit = aUnit.toAsciiLowerCase();
301  std::pair<OUString, FieldUnit> aElement(aUnit, rUnits[i].second);
302  pSVData->maCtrlData.maCleanUnitStrings.push_back(aElement);
303  }
304  }
305  return pSVData->maCtrlData.maCleanUnitStrings;
306 }
307 
309 {
310  ImplSVData* pSVData = ImplGetSVData();
311  if ( !pSVData->mpDockingManager )
312  pSVData->mpDockingManager.reset(new DockingManager());
313 
314  return pSVData->mpDockingManager.get();
315 }
316 
318 {
319  ImplSVData* pSVData = ImplGetSVData();
320  if ( !pSVData->mpBlendFrameCache)
321  pSVData->mpBlendFrameCache.reset( new BlendFrameCache() );
322 
323  return pSVData->mpBlendFrameCache.get();
324 }
325 
326 #ifdef _WIN32
327 bool ImplInitAccessBridge()
328 {
329  ImplSVData* pSVData = ImplGetSVData();
330  if( ! pSVData->mxAccessBridge.is() )
331  {
332  css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
333 
334  if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
335  {
336  SAL_INFO("vcl", "Apparently no running AT -> "
337  "not enabling IAccessible2 integration");
338  }
339  else
340  {
341  try {
342  pSVData->mxAccessBridge
343  = css::accessibility::MSAAService::create(xContext);
344  SAL_INFO("vcl", "got IAccessible2 bridge");
345  return true;
346  } catch (css::uno::DeploymentException &) {
348  "vcl",
349  "got no IAccessible2 bridge");
350  return false;
351  }
352  }
353  }
354 
355  return true;
356 }
357 #endif
358 
360 {
362 }
363 
365 {
367  return nullptr;
368 
370 
371  ImplSVData* pSVData = ImplGetSVData();
372  assert(pSVData && pSVData->mpWinData);
373 
374  p->mpFocusWin = pSVData->mpWinData->mpFocusWin;
375  return p;
376 }
377 
379 {
380  delete pData;
381 }
382 
383 void SetSVWinData(ImplSVWinData* pSVWinData)
384 {
386  return;
387 
388  ImplSVData* pSVData = ImplGetSVData();
389  assert(pSVData != nullptr);
390 
391  if (pSVData->mpWinData == pSVWinData)
392  return;
393 
394  // If current one is the static, clean it up to avoid having lingering references.
395  if (pSVData->mpWinData == &private_aImplSVWinData::get())
396  {
397  pSVData->mpWinData->mpFocusWin.reset();
398  }
399 
400  pSVData->mpWinData = pSVWinData;
401  if (pSVData->mpWinData == nullptr)
402  {
403  pSVData->mpWinData = &private_aImplSVWinData::get(); // Never leave it null.
404  }
405 }
406 
408 {
409  mpHelpData = &private_aImplSVHelpData::get();
410  mpWinData = &private_aImplSVWinData::get();
411 }
412 
414 {
416  return nullptr;
417 
418  ImplSVHelpData* pNewData = new ImplSVHelpData;
419 
420  // Set options set globally
421  ImplSVHelpData& aStaticHelpData = private_aImplSVHelpData::get();
422  pNewData->mbContextHelp = aStaticHelpData.mbContextHelp;
423  pNewData->mbExtHelp = aStaticHelpData.mbExtHelp;
424  pNewData->mbExtHelpMode = aStaticHelpData.mbExtHelpMode;
425  pNewData->mbOldBalloonMode = aStaticHelpData.mbOldBalloonMode;
426  pNewData->mbBalloonHelp = aStaticHelpData.mbBalloonHelp;
427  pNewData->mbQuickHelp = aStaticHelpData.mbQuickHelp;
428 
429  return pNewData;
430 }
431 
433 {
435  return;
436 
437  // Change the SVData's help date if necessary
438  if(ImplGetSVData()->mpHelpData == pSVHelpData)
439  {
440  ImplGetSVData()->mpHelpData = &private_aImplSVHelpData::get();
441  }
442 
443  if(pSVHelpData)
444  {
445  ImplDestroyHelpWindow(*pSVHelpData, false);
446  delete pSVHelpData;
447  }
448 }
449 
450 void SetSVHelpData(ImplSVHelpData* pSVHelpData)
451 {
453  return;
454 
455  ImplSVData* pSVData = ImplGetSVData();
456  if (pSVData->mpHelpData == pSVHelpData)
457  return;
458 
459  // If current one is the static, clean it up to avoid having lingering references.
460  if (pSVData->mpHelpData == &private_aImplSVHelpData::get())
461  {
462  pSVData->mpHelpData->mpHelpWin.reset();
463  }
464 
465  pSVData->mpHelpData = pSVHelpData;
466  if (pSVData->mpHelpData == nullptr)
467  {
468  pSVData->mpHelpData = &private_aImplSVHelpData::get(); // Never leave it null.
469  }
470 }
471 
473 {
474  ImplSVData* pSVData = ImplGetSVData();
475  if(pSVData->mpHelpData)
476  {
477  return *pSVData->mpHelpData;
478  }
479  else
480  {
481  return private_aImplSVHelpData::get();
482  }
483 }
484 
491 
492 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImplSVHelpData & ImplGetSVHelpData()
Definition: svdata.cxx:472
ConfigurationHints
VclPtr< HelpTextWindow > mpHelpWin
Definition: svdata.hxx:299
std::unique_ptr< SalSystem > mpSalSystem
Definition: svdata.hxx:385
VclPtr< vcl::Window > mpFocusWin
Definition: svdata.hxx:247
rtl::Reference< OpenGLContext > GetOpenGLContext() const
Check that our mpImpl is OpenGL and return the context, otherwise NULL.
const FieldUnitStringList & ImplGetCleanedFieldUnits()
Definition: svdata.cxx:288
void SetSVWinData(ImplSVWinData *pSVWinData)
Definition: svdata.cxx:383
std::unique_ptr< vcl::SettingsConfigItem > mpSettingsConfigItem
Definition: svdata.hxx:408
css::uno::Reference< css::lang::XComponent > mxAccessBridge
Definition: svdata.hxx:407
~ImplSVData()
Definition: svdata.cxx:485
void DestroySVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:432
ImplSVData()
Definition: svdata.cxx:407
ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:413
BlendFrameCache * ImplGetBlendFrameCache()
Definition: svdata.cxx:317
ImplSVCtrlData maCtrlData
Definition: svdata.hxx:396
bool mbExtHelpMode
Definition: svdata.hxx:292
bool mbResLocaleSet
Definition: svdata.hxx:389
std::locale Create(const char *pPrefixName, const LanguageTag &rLocale)
ImplSVHelpData * mpHelpData
Definition: svdata.hxx:397
std::unique_ptr< BlendFrameCache > mpBlendFrameCache
Definition: svdata.hxx:402
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
basegfx::SystemDependentDataManager & ImplGetSystemDependentDataManager()
Definition: svdata.cxx:203
#define SAL_N_ELEMENTS(arr)
vcl::Window * ImplGetDefaultContextWindow()
returns the default window created to hold the persistent VCL GL context.
Definition: svdata.cxx:221
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:76
An auto-timer is a multi-shot timer re-emitting itself at interval until destroyed or stopped...
Definition: timer.hxx:72
SalSystem * ImplGetSalSystem()
Definition: svdata.cxx:80
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual SalSystem * CreateSalSystem()=0
int i
FieldUnitStringList maCleanUnitStrings
Definition: svdata.hxx:284
bool mbQuickHelp
Definition: svdata.hxx:295
bool mbExtHelp
Definition: svdata.hxx:291
VclPtr< WorkWindow > mpAppWin
Definition: svdata.hxx:239
static void LocaleSettingsChanged(ConfigurationHints nHint)
bool mbContextHelp
Definition: svdata.hxx:290
void reset(reference_type *pBody)
Definition: vclptr.hxx:153
const std::locale & ImplGetResLocale()
Definition: svdata.cxx:256
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: svdata.cxx:359
bool mbBalloonHelp
Definition: svdata.hxx:294
DockingManager * ImplGetDockingManager()
Definition: svdata.cxx:308
bool mbOldBalloonMode
Definition: svdata.hxx:293
void ImplDeInitSVData()
Definition: svdata.cxx:88
ImplSVFrameData maFrameData
Definition: svdata.hxx:394
#define SAL_INFO(area, stream)
void SetSVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:450
virtual void SetText(const OUString &rStr) override
Definition: syswin.cxx:1103
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
bool mbDeInit
Definition: svdata.hxx:384
SalGraphics const * GetGraphics() const
Get the graphic context that the output device uses to draw on.
Definition: outdev.cxx:198
void DestroySVWinData(ImplSVWinData *pData)
Definition: svdata.cxx:378
void * p
Reference< XComponentContext > getProcessComponentContext()
std::vector< std::pair< OUString, FieldUnit > > FieldUnitStringList
Definition: svdata.hxx:266
IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
Definition: Animation.cxx:276
WinBits const WB_DEFAULTWIN
ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:364
FieldUnitStringList maFieldUnitStrings
Definition: svdata.hxx:283
OUString VclResId(const char *pId)
Definition: svdata.cxx:267
Definition: timer.hxx:26
std::unique_ptr< DockingManager > mpDockingManager
Definition: svdata.hxx:401
OUString get(const char *pContextAndId, const std::locale &loc)
const FieldUnitStringList & ImplGetFieldUnits()
Definition: svdata.cxx:272
osl::Mutex m_aMutex
Definition: dtranscomp.cxx:61
vcl::Window * ImplGetDefaultWindow()
Returns either the application window, or the default GL context window.
Definition: svdata.cxx:211
std::locale maResLocale
Definition: svdata.hxx:390
SalInstance * mpDefInst
Definition: svdata.hxx:381
std::unordered_map< int, OUString > maPaperNames
Definition: svdata.hxx:410
void ImplDestroyHelpWindow(bool bUpdateHideTime)
Definition: help.cxx:552
const char first[]
ImplSVWinData * mpWinData
Definition: svdata.hxx:395
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
VclPtr< WorkWindow > mpDefaultWin
Definition: svdata.hxx:383