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> {};
65 }
66 
68  return &private_aImplSVData::get();
69 }
70 
72 {
73  ImplSVData* pSVData = ImplGetSVData();
74  if( ! pSVData->mpSalSystem )
75  pSVData->mpSalSystem.reset( pSVData->mpDefInst->CreateSalSystem() );
76  return pSVData->mpSalSystem.get();
77 }
78 
80 {
81  ImplSVData* pSVData = ImplGetSVData();
82 
83  // delete global instance data
84  pSVData->mpSettingsConfigItem.reset();
85 
86  pSVData->mpDockingManager.reset();
87 
88  pSVData->maCtrlData.maFieldUnitStrings.clear();
89  pSVData->maCtrlData.maCleanUnitStrings.clear();
90  pSVData->maPaperNames.clear();
91 }
92 
93 namespace
94 {
95  typedef ::std::map< basegfx::SystemDependentData_SharedPtr, sal_uInt32 > EntryMap;
96 
97  class SystemDependentDataBuffer final : public basegfx::SystemDependentDataManager, protected cppu::BaseMutex
98  {
99  private:
100  std::unique_ptr<AutoTimer> maTimer;
101  EntryMap maEntries;
102 
103  DECL_LINK(implTimeoutHdl, Timer *, void);
104 
105  public:
106  SystemDependentDataBuffer(const sal_Char* pDebugName)
107  : basegfx::SystemDependentDataManager(),
108  maTimer(std::make_unique<AutoTimer>(pDebugName))
109  {
110  maTimer->SetTimeout(1000);
111  maTimer->SetInvokeHandler(LINK(this, SystemDependentDataBuffer, implTimeoutHdl));
112  }
113 
114  virtual ~SystemDependentDataBuffer() override
115  {
116  flushAll();
117  }
118 
119  void startUsage(basegfx::SystemDependentData_SharedPtr& rData) override
120  {
121  ::osl::MutexGuard aGuard(m_aMutex);
122  EntryMap::iterator aFound(maEntries.find(rData));
123 
124  if(aFound == maEntries.end())
125  {
126  if(maTimer && !maTimer->IsActive())
127  {
128  maTimer->Start();
129  }
130 
131  maEntries[rData] = rData->calculateCombinedHoldCyclesInSeconds();
132  }
133  }
134 
135  void endUsage(basegfx::SystemDependentData_SharedPtr& rData) override
136  {
137  ::osl::MutexGuard aGuard(m_aMutex);
138  EntryMap::iterator aFound(maEntries.find(rData));
139 
140  if(aFound != maEntries.end())
141  {
142  maEntries.erase(aFound);
143  }
144  }
145 
146  void touchUsage(basegfx::SystemDependentData_SharedPtr& rData) override
147  {
148  ::osl::MutexGuard aGuard(m_aMutex);
149  EntryMap::iterator aFound(maEntries.find(rData));
150 
151  if(aFound != maEntries.end())
152  {
153  aFound->second = rData->calculateCombinedHoldCyclesInSeconds();
154  }
155  }
156 
157  void flushAll() override
158  {
159  ::osl::MutexGuard aGuard(m_aMutex);
160 
161  if(maTimer)
162  {
163  maTimer->Stop();
164  maTimer.reset();
165  }
166 
167  maEntries.clear();
168  }
169  };
170 
171  IMPL_LINK_NOARG(SystemDependentDataBuffer, implTimeoutHdl, Timer *, void)
172  {
173  ::osl::MutexGuard aGuard(m_aMutex);
174  EntryMap::iterator aIter(maEntries.begin());
175 
176  while(aIter != maEntries.end())
177  {
178  if(aIter->second)
179  {
180  aIter->second--;
181  ++aIter;
182  }
183  else
184  {
185  aIter = maEntries.erase(aIter);
186  }
187  }
188 
189  if (maEntries.empty())
190  maTimer->Stop();
191  }
192 }
193 
195 {
196  static SystemDependentDataBuffer aSystemDependentDataBuffer("vcl SystemDependentDataBuffer aSystemDependentDataBuffer");
197 
198  return aSystemDependentDataBuffer;
199 }
200 
203 {
204  ImplSVData* pSVData = ImplGetSVData();
205  if ( pSVData->maWinData.mpAppWin )
206  return pSVData->maWinData.mpAppWin;
207  else
209 }
210 
213 {
214  ImplSVData* pSVData = ImplGetSVData();
215 
216  // Double check locking on mpDefaultWin.
217  if ( !pSVData->mpDefaultWin )
218  {
219  SolarMutexGuard aGuard;
220 
221  if (!pSVData->mpDefaultWin && !pSVData->mbDeInit)
222  {
223  try
224  {
225  SAL_INFO( "vcl", "ImplGetDefaultWindow(): No AppWindow" );
226 
228  pSVData->mpDefaultWin->SetText( "VCL ImplGetDefaultWindow" );
229 
230 #if HAVE_FEATURE_OPENGL
231  // Add a reference to the default context so it never gets deleted
233  if( pContext.is() )
234  pContext->acquire();
235 #endif
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(const char* pId)
259 {
260  return Translate::get(pId, 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 
355 
361 
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ConfigurationHints
std::unique_ptr< SalSystem > mpSalSystem
Definition: svdata.hxx:340
rtl::Reference< OpenGLContext > GetOpenGLContext() const
Check that our mpImpl is OpenGL and return the context, otherwise NULL.
const FieldUnitStringList & ImplGetCleanedFieldUnits()
Definition: svdata.cxx:279
std::unique_ptr< vcl::SettingsConfigItem > mpSettingsConfigItem
Definition: svdata.hxx:362
std::locale Create(const sal_Char *pPrefixName, const LanguageTag &rLocale)
css::uno::Reference< css::lang::XComponent > mxAccessBridge
Definition: svdata.hxx:361
~ImplSVData()
Definition: svdata.cxx:356
BlendFrameCache * ImplGetBlendFrameCache()
Definition: svdata.cxx:308
ImplSVCtrlData maCtrlData
Definition: svdata.hxx:350
bool mbResLocaleSet
Definition: svdata.hxx:344
std::unique_ptr< BlendFrameCache > mpBlendFrameCache
Definition: svdata.hxx:356
char sal_Char
VclPtr< WorkWindow > mpAppWin
Definition: svdata.hxx:199
basegfx::SystemDependentDataManager & ImplGetSystemDependentDataManager()
Definition: svdata.cxx:194
#define SAL_N_ELEMENTS(arr)
vcl::Window * ImplGetDefaultContextWindow()
returns the default window created to hold the persistent VCL GL context.
Definition: svdata.cxx:212
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:67
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:71
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual SalSystem * CreateSalSystem()=0
FieldUnitStringList maCleanUnitStrings
Definition: svdata.hxx:240
int i
static void LocaleSettingsChanged(ConfigurationHints nHint)
ImplSVWinData maWinData
Definition: svdata.hxx:349
const std::locale & ImplGetResLocale()
Definition: svdata.cxx:247
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: svdata.cxx:350
DockingManager * ImplGetDockingManager()
Definition: svdata.cxx:299
void ImplDeInitSVData()
Definition: svdata.cxx:79
#define SAL_INFO(area, stream)
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:339
SalGraphics const * GetGraphics() const
Get the graphic context that the output device uses to draw on.
Definition: outdev.cxx:198
Reference< XComponentContext > getProcessComponentContext()
std::vector< std::pair< OUString, FieldUnit > > FieldUnitStringList
Definition: svdata.hxx:222
IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
Definition: Animation.cxx:280
WinBits const WB_DEFAULTWIN
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
FieldUnitStringList maFieldUnitStrings
Definition: svdata.hxx:239
OUString VclResId(const char *pId)
Definition: svdata.cxx:258
Definition: timer.hxx:26
std::unique_ptr< DockingManager > mpDockingManager
Definition: svdata.hxx:355
OUString get(const char *pContextAndId, const std::locale &loc)
const FieldUnitStringList & ImplGetFieldUnits()
Definition: svdata.cxx:263
vcl::Window * ImplGetDefaultWindow()
Returns either the application window, or the default GL context window.
Definition: svdata.cxx:202
std::locale maResLocale
Definition: svdata.hxx:345
SalInstance * mpDefInst
Definition: svdata.hxx:336
std::unordered_map< int, OUString > maPaperNames
Definition: svdata.hxx:364
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
VclPtr< WorkWindow > mpDefaultWin
Definition: svdata.hxx:338