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 <vcl/configsettings.hxx>
29 #include <vcl/dockwin.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/print.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/virdev.hxx>
35 #include <vcl/wrkwin.hxx>
36 #include <vcl/uitest/logger.hxx>
37 #include <salframe.hxx>
38 #include <scrwnd.hxx>
39 #include <helpwin.hxx>
40 #include <vcl/dialog.hxx>
41 #include <salinst.hxx>
42 #include <salgdi.hxx>
43 #include <svdata.hxx>
44 #include <salsys.hxx>
45 #include <units.hrc>
46 #include <print.h>
47 
48 #include <com/sun/star/accessibility/MSAAService.hpp>
49 
50 #include <config_features.h>
51 #if HAVE_FEATURE_OPENGL
53 #endif
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 #if HAVE_FEATURE_OPENGL
239  // Add a reference to the default context so it never gets deleted
241  if( pContext.is() )
242  pContext->acquire();
243 #endif
244  }
245  catch (const css::uno::Exception&)
246  {
247  TOOLS_WARN_EXCEPTION("vcl", "unable to create Default Window");
248  }
249  }
250  }
251 
252  return pSVData->mpDefaultWin;
253 }
254 
255 const std::locale& ImplGetResLocale()
256 {
257  ImplSVData* pSVData = ImplGetSVData();
259  {
260  pSVData->maResLocale = Translate::Create("vcl");
261  pSVData->mbResLocaleSet = true;
262  }
263  return pSVData->maResLocale;
264 }
265 
266 OUString VclResId(const char* pId)
267 {
268  return Translate::get(pId, ImplGetResLocale());
269 }
270 
272 {
273  ImplSVData* pSVData = ImplGetSVData();
274  if( pSVData->maCtrlData.maFieldUnitStrings.empty() )
275  {
276  sal_uInt32 nUnits = SAL_N_ELEMENTS(SV_FUNIT_STRINGS);
277  pSVData->maCtrlData.maFieldUnitStrings.reserve( nUnits );
278  for (sal_uInt32 i = 0; i < nUnits; i++)
279  {
280  std::pair<OUString, FieldUnit> aElement(VclResId(SV_FUNIT_STRINGS[i].first), SV_FUNIT_STRINGS[i].second);
281  pSVData->maCtrlData.maFieldUnitStrings.push_back( aElement );
282  }
283  }
284  return pSVData->maCtrlData.maFieldUnitStrings;
285 }
286 
288 {
289  ImplSVData* pSVData = ImplGetSVData();
290  if( pSVData->maCtrlData.maCleanUnitStrings.empty() )
291  {
292  const FieldUnitStringList& rUnits = ImplGetFieldUnits();
293  size_t nUnits = rUnits.size();
294  pSVData->maCtrlData.maCleanUnitStrings.reserve(nUnits);
295  for (size_t i = 0; i < nUnits; ++i)
296  {
297  OUString aUnit(rUnits[i].first);
298  aUnit = aUnit.replaceAll(" ", "");
299  aUnit = aUnit.toAsciiLowerCase();
300  std::pair<OUString, FieldUnit> aElement(aUnit, rUnits[i].second);
301  pSVData->maCtrlData.maCleanUnitStrings.push_back(aElement);
302  }
303  }
304  return pSVData->maCtrlData.maCleanUnitStrings;
305 }
306 
308 {
309  ImplSVData* pSVData = ImplGetSVData();
310  if ( !pSVData->mpDockingManager )
311  pSVData->mpDockingManager.reset(new DockingManager());
312 
313  return pSVData->mpDockingManager.get();
314 }
315 
317 {
318  ImplSVData* pSVData = ImplGetSVData();
319  if ( !pSVData->mpBlendFrameCache)
320  pSVData->mpBlendFrameCache.reset( new BlendFrameCache() );
321 
322  return pSVData->mpBlendFrameCache.get();
323 }
324 
325 #ifdef _WIN32
326 bool ImplInitAccessBridge()
327 {
328  ImplSVData* pSVData = ImplGetSVData();
329  if( ! pSVData->mxAccessBridge.is() )
330  {
331  css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
332 
333  if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
334  {
335  SAL_INFO("vcl", "Apparently no running AT -> "
336  "not enabling IAccessible2 integration");
337  }
338  else
339  {
340  try {
341  pSVData->mxAccessBridge
342  = css::accessibility::MSAAService::create(xContext);
343  SAL_INFO("vcl", "got IAccessible2 bridge");
344  return true;
345  } catch (css::uno::DeploymentException &) {
347  "vcl",
348  "got no IAccessible2 bridge");
349  return false;
350  }
351  }
352  }
353 
354  return true;
355 }
356 #endif
357 
359 {
361 }
362 
364 {
366  return nullptr;
367 
369 
370  ImplSVData* pSVData = ImplGetSVData();
371  assert(pSVData && pSVData->mpWinData);
372 
373  p->mpFocusWin = pSVData->mpWinData->mpFocusWin;
374  return p;
375 }
376 
378 {
379  delete pData;
380 }
381 
382 void SetSVWinData(ImplSVWinData* pSVWinData)
383 {
385  return;
386 
387  ImplSVData* pSVData = ImplGetSVData();
388  assert(pSVData != nullptr);
389 
390  if (pSVData->mpWinData != pSVWinData)
391  {
392  // If current one is the static, clean it up to avoid having lingering references.
393  if (pSVData->mpWinData == &private_aImplSVWinData::get())
394  {
395  pSVData->mpWinData->mpFocusWin.reset();
396  }
397 
398  pSVData->mpWinData = pSVWinData;
399  if (pSVData->mpWinData == nullptr)
400  {
401  pSVData->mpWinData = &private_aImplSVWinData::get(); // Never leave it null.
402  }
403  }
404 }
405 
407 {
408  mpHelpData = &private_aImplSVHelpData::get();
409  mpWinData = &private_aImplSVWinData::get();
410 }
411 
413 {
415  return nullptr;
416 
417  ImplSVHelpData* pNewData = new ImplSVHelpData;
418 
419  // Set options set globally
420  ImplSVHelpData& aStaticHelpData = private_aImplSVHelpData::get();
421  pNewData->mbContextHelp = aStaticHelpData.mbContextHelp;
422  pNewData->mbExtHelp = aStaticHelpData.mbExtHelp;
423  pNewData->mbExtHelpMode = aStaticHelpData.mbExtHelpMode;
424  pNewData->mbOldBalloonMode = aStaticHelpData.mbOldBalloonMode;
425  pNewData->mbBalloonHelp = aStaticHelpData.mbBalloonHelp;
426  pNewData->mbQuickHelp = aStaticHelpData.mbQuickHelp;
427 
428  return pNewData;
429 }
430 
432 {
434  return;
435 
436  // Change the SVData's help date if necessary
437  if(ImplGetSVData()->mpHelpData == pSVHelpData)
438  {
439  ImplGetSVData()->mpHelpData = &private_aImplSVHelpData::get();
440  }
441 
442  if(pSVHelpData)
443  {
444  ImplDestroyHelpWindow(*pSVHelpData, false);
445  delete pSVHelpData;
446  }
447 }
448 
449 void SetSVHelpData(ImplSVHelpData* pSVHelpData)
450 {
452  return;
453 
454  ImplSVData* pSVData = ImplGetSVData();
455  if (pSVData->mpHelpData != pSVHelpData)
456  {
457  // If current one is the static, clean it up to avoid having lingering references.
458  if (pSVData->mpHelpData == &private_aImplSVHelpData::get())
459  {
460  pSVData->mpHelpData->mpHelpWin.reset();
461  }
462 
463  pSVData->mpHelpData = pSVHelpData;
464  if (pSVData->mpHelpData == nullptr)
465  {
466  pSVData->mpHelpData = &private_aImplSVHelpData::get(); // Never leave it null.
467  }
468  }
469 }
470 
472 {
473  ImplSVData* pSVData = ImplGetSVData();
474  if(pSVData->mpHelpData)
475  {
476  return *pSVData->mpHelpData;
477  }
478  else
479  {
480  return private_aImplSVHelpData::get();
481  }
482 }
483 
490 
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImplSVHelpData & ImplGetSVHelpData()
Definition: svdata.cxx:471
ConfigurationHints
VclPtr< HelpTextWindow > mpHelpWin
Definition: svdata.hxx:262
std::unique_ptr< SalSystem > mpSalSystem
Definition: svdata.hxx:348
VclPtr< vcl::Window > mpFocusWin
Definition: svdata.hxx:210
rtl::Reference< OpenGLContext > GetOpenGLContext() const
Check that our mpImpl is OpenGL and return the context, otherwise NULL.
const FieldUnitStringList & ImplGetCleanedFieldUnits()
Definition: svdata.cxx:287
void SetSVWinData(ImplSVWinData *pSVWinData)
Definition: svdata.cxx:382
std::unique_ptr< vcl::SettingsConfigItem > mpSettingsConfigItem
Definition: svdata.hxx:371
css::uno::Reference< css::lang::XComponent > mxAccessBridge
Definition: svdata.hxx:370
~ImplSVData()
Definition: svdata.cxx:484
void DestroySVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:431
ImplSVData()
Definition: svdata.cxx:406
ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:412
BlendFrameCache * ImplGetBlendFrameCache()
Definition: svdata.cxx:316
ImplSVCtrlData maCtrlData
Definition: svdata.hxx:359
bool mbExtHelpMode
Definition: svdata.hxx:255
bool mbResLocaleSet
Definition: svdata.hxx:352
std::locale Create(const char *pPrefixName, const LanguageTag &rLocale)
ImplSVHelpData * mpHelpData
Definition: svdata.hxx:360
std::unique_ptr< BlendFrameCache > mpBlendFrameCache
Definition: svdata.hxx:365
basegfx::SystemDependentDataManager & ImplGetSystemDependentDataManager()
Definition: svdata.cxx:202
#define SAL_N_ELEMENTS(arr)
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:72
SalSystem * ImplGetSalSystem()
Definition: svdata.cxx:79
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual SalSystem * CreateSalSystem()=0
FieldUnitStringList maCleanUnitStrings
Definition: svdata.hxx:247
bool mbQuickHelp
Definition: svdata.hxx:258
bool mbExtHelp
Definition: svdata.hxx:254
int i
VclPtr< WorkWindow > mpAppWin
Definition: svdata.hxx:202
static void LocaleSettingsChanged(ConfigurationHints nHint)
bool mbContextHelp
Definition: svdata.hxx:253
void reset(reference_type *pBody)
Definition: vclptr.hxx:153
const std::locale & ImplGetResLocale()
Definition: svdata.cxx:255
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: svdata.cxx:358
bool mbBalloonHelp
Definition: svdata.hxx:257
DockingManager * ImplGetDockingManager()
Definition: svdata.cxx:307
bool mbOldBalloonMode
Definition: svdata.hxx:256
void ImplDeInitSVData()
Definition: svdata.cxx:87
ImplSVFrameData maFrameData
Definition: svdata.hxx:357
#define SAL_INFO(area, stream)
void SetSVHelpData(ImplSVHelpData *pSVHelpData)
Definition: svdata.cxx:449
virtual void SetText(const OUString &rStr) override
Definition: syswin.cxx:1101
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
bool mbDeInit
Definition: svdata.hxx:347
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:377
void * p
Reference< XComponentContext > getProcessComponentContext()
std::vector< std::pair< OUString, FieldUnit > > FieldUnitStringList
Definition: svdata.hxx:229
IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
Definition: Animation.cxx:276
WinBits const WB_DEFAULTWIN
ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:363
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
FieldUnitStringList maFieldUnitStrings
Definition: svdata.hxx:246
OUString VclResId(const char *pId)
Definition: svdata.cxx:266
Definition: timer.hxx:26
std::unique_ptr< DockingManager > mpDockingManager
Definition: svdata.hxx:364
OUString get(const char *pContextAndId, const std::locale &loc)
const FieldUnitStringList & ImplGetFieldUnits()
Definition: svdata.cxx:271
osl::Mutex m_aMutex
Definition: dtranscomp.cxx:57
vcl::Window * ImplGetDefaultWindow()
Returns either the application window, or the default GL context window.
Definition: svdata.cxx:210
std::locale maResLocale
Definition: svdata.hxx:353
SalInstance * mpDefInst
Definition: svdata.hxx:344
std::unordered_map< int, OUString > maPaperNames
Definition: svdata.hxx:373
void ImplDestroyHelpWindow(bool bUpdateHideTime)
Definition: help.cxx:557
ImplSVWinData * mpWinData
Definition: svdata.hxx:358
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
VclPtr< WorkWindow > mpDefaultWin
Definition: svdata.hxx:346