LibreOffice Module comphelper (master)  1
lok.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 
10 #include <comphelper/lok.hxx>
12 #include <sal/log.hxx>
13 
14 #include <iostream>
15 #include <map>
16 
18 {
19 
20 static bool g_bActive(false);
21 
22 static bool g_bPartInInvalidation(false);
23 
24 static bool g_bTiledPainting(false);
25 
26 static bool g_bDialogPainting(false);
27 
28 static bool g_bTiledAnnotations(true);
29 
30 static bool g_bRangeHeaders(false);
31 
32 static bool g_bViewIdForVisCursorInvalidation(false);
33 
34 static bool g_bLocalRendering(false);
35 
37 
38 namespace
39 {
40 
41 class LanguageAndLocale
42 {
43 private:
46 
47 public:
48 
49  LanguageAndLocale()
50  : maLanguageTag(LANGUAGE_NONE)
51  , maLocaleLanguageTag(LANGUAGE_NONE)
52  {}
53 
54  const LanguageTag& getLanguage()
55  {
56  return maLanguageTag;
57  }
58 
59  void setLanguage(const LanguageTag& rLanguageTag)
60  {
61  if (maLanguageTag != rLanguageTag)
62  {
63  SAL_INFO("comphelper.lok", "Setting language from " << maLanguageTag.getBcp47() << " to " << rLanguageTag.getBcp47());
64  maLanguageTag = rLanguageTag;
65  }
66  }
67 
68  const LanguageTag& getLocale()
69  {
70  return maLocaleLanguageTag;
71  }
72 
73  void setLocale(const LanguageTag& rLocaleLanguageTag)
74  {
75  if (maLocaleLanguageTag != rLocaleLanguageTag)
76  {
77  SAL_INFO("comphelper.lok", "Setting locale from " << maLanguageTag.getBcp47() << " to " << rLocaleLanguageTag.getBcp47());
78  maLocaleLanguageTag = rLocaleLanguageTag;
79  }
80  }
81 
82 };
83 
84 }
85 
86 static LanguageAndLocale g_aLanguageAndLocale;
87 
89 static double g_fDPIScale(1.0);
90 
91 void setActive(bool bActive)
92 {
93  g_bActive = bActive;
94 }
95 
96 bool isActive()
97 {
98  return g_bActive;
99 }
100 
101 void setPartInInvalidation(bool bPartInInvalidation)
102 {
103  g_bPartInInvalidation = bPartInInvalidation;
104 }
105 
107 {
108  return g_bPartInInvalidation;
109 }
110 
111 void setTiledPainting(bool bTiledPainting)
112 {
113  g_bTiledPainting = bTiledPainting;
114 }
115 
117 {
118  return g_bTiledPainting;
119 }
120 
121 void setDialogPainting(bool bDialogPainting)
122 {
123  g_bDialogPainting = bDialogPainting;
124 }
125 
127 {
128  return g_bDialogPainting;
129 }
130 
131 void setDPIScale(double fDPIScale)
132 {
133  g_fDPIScale = fDPIScale;
134 }
135 
136 double getDPIScale()
137 {
138  return g_fDPIScale;
139 }
140 
141 void setTiledAnnotations(bool bTiledAnnotations)
142 {
143  g_bTiledAnnotations = bTiledAnnotations;
144 }
145 
147 {
148  return g_bTiledAnnotations;
149 }
150 
151 void setRangeHeaders(bool bRangeHeaders)
152 {
153  g_bRangeHeaders = bRangeHeaders;
154 }
155 
156 void setViewIdForVisCursorInvalidation(bool bViewIdForVisCursorInvalidation)
157 {
158  g_bViewIdForVisCursorInvalidation = bViewIdForVisCursorInvalidation;
159 }
160 
162 {
164 }
165 
167 {
168  return g_bRangeHeaders;
169 }
170 
171 void setLocalRendering(bool bLocalRendering)
172 {
173  g_bLocalRendering = bLocalRendering;
174 }
175 
177 {
178  return g_bLocalRendering;
179 }
180 
181 void setCompatFlag(Compat flag) { g_eCompatFlags = static_cast<Compat>(g_eCompatFlags | flag); }
182 
183 bool isCompatFlagSet(Compat flag) { return (g_eCompatFlags & flag) == flag; }
184 
185 void setLocale(const LanguageTag& rLanguageTag)
186 {
187  g_aLanguageAndLocale.setLocale(rLanguageTag);
188 }
189 
191 {
192  const LanguageTag& rLocale = g_aLanguageAndLocale.getLocale();
193  SAL_INFO_IF(rLocale.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Locale not set");
194  return rLocale;
195 }
196 
197 void setLanguageTag(const LanguageTag& rLanguageTag)
198 {
199  g_aLanguageAndLocale.setLanguage(rLanguageTag);
200 }
201 
203 {
204  const LanguageTag& rLanguage = g_aLanguageAndLocale.getLanguage();
205  SAL_INFO_IF(rLanguage.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Language not set");
206  return rLanguage;
207 }
208 
209 bool isWhitelistedLanguage(const OUString& lang)
210 {
211  if (!isActive())
212  return true;
213 
214 #ifdef ANDROID
215  (void) lang;
216  return true;
217 #else
218  static bool bInitialized = false;
219  static std::vector<OUString> aWhitelist;
220  if (!bInitialized)
221  {
222  // coverity[tainted_data] - we trust the contents of this variable
223  const char* pWhitelist = getenv("LOK_WHITELIST_LANGUAGES");
224  if (pWhitelist)
225  {
226  std::stringstream stream(pWhitelist);
227  std::string s;
228 
229  std::cerr << "Whitelisted languages: ";
230  while (getline(stream, s, ' ')) {
231  if (s.length() == 0)
232  continue;
233 
234  std::cerr << s << " ";
235  aWhitelist.emplace_back(OStringToOUString(s.c_str(), RTL_TEXTENCODING_UTF8));
236  }
237  std::cerr << std::endl;
238  }
239 
240  if (aWhitelist.empty())
241  std::cerr << "No language whitelisted, turning off the language support." << std::endl;
242 
243  bInitialized = true;
244  }
245 
246  if (aWhitelist.empty())
247  return false;
248 
249  for (const auto& entry : aWhitelist)
250  {
251  if (lang.startsWith(entry))
252  return true;
253  if (lang.startsWith(entry.replace('_', '-')))
254  return true;
255  }
256 
257  return false;
258 #endif
259 }
260 
261 static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
262 static void *pStatusIndicatorCallbackData(nullptr);
263 
264 void setStatusIndicatorCallback(void (*callback)(void *data, statusIndicatorCallbackType type, int percent), void *data)
265 {
266  pStatusIndicatorCallback = callback;
268 }
269 
271 {
274 }
275 
276 void statusIndicatorSetValue(int percent)
277 {
280 }
281 
283 {
286 }
287 
288 } // namespace
289 
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define LANGUAGE_NONE
static void * pStatusIndicatorCallbackData(nullptr)
bool isWhitelistedLanguage(const OUString &lang)
If the language name should be used for this LOK instance.
Definition: lok.cxx:209
bool isTiledAnnotations()
Check if annotations rendering is turned off.
Definition: lok.cxx:146
LanguageType getLanguageType(bool bResolveSystem=true) const
#define SAL_INFO_IF(condition, area, stream)
void setViewIdForVisCursorInvalidation(bool bViewIdForVisCursorInvalidation)
Set whether clients want viewId in visible cursor invalidation payload.
Definition: lok.cxx:156
const OUString & getBcp47(bool bResolveSystem=true) const
void statusIndicatorFinish()
Definition: lok.cxx:282
LanguageTag maLocaleLanguageTag
Definition: lok.cxx:45
static Compat g_eCompatFlags(Compat::none)
void setTiledPainting(bool bTiledPainting)
Set if we are doing tiled painting.
Definition: lok.cxx:111
static void(* pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr)
Definition: lok.cxx:261
void setDPIScale(double fDPIScale)
Set the DPI scale for rendering for HiDPI displays.
Definition: lok.cxx:131
void setLanguageTag(const LanguageTag &rLanguageTag)
Update the current LOK's language.
Definition: lok.cxx:197
bool isRangeHeaders()
Check if range based header data is enabled.
Definition: lok.cxx:166
bool isCompatFlagSet(Compat flag)
Get compatibility flags.
Definition: lok.cxx:183
static bool g_bTiledPainting(false)
bool isTiledPainting()
Check if we are doing tiled painting.
Definition: lok.cxx:116
bool isDialogPainting()
Check if we are painting the dialog.
Definition: lok.cxx:126
bool isPartInInvalidation()
Check whether clients want a part number in an invalidation payload.
Definition: lok.cxx:106
static LanguageAndLocale g_aLanguageAndLocale
Definition: lok.cxx:86
static bool g_bRangeHeaders(false)
void setRangeHeaders(bool bRangeHeaders)
Set if we want range based header data.
Definition: lok.cxx:151
static bool g_bDialogPainting(false)
void setLocalRendering(bool bLocalRendering)
Shift the coordinates before rendering each bitmap.
Definition: lok.cxx:171
void setStatusIndicatorCallback(void(*callback)(void *data, statusIndicatorCallbackType type, int percent), void *data)
Definition: lok.cxx:264
const LanguageTag & getLanguageTag()
Get the current LOK's language.
Definition: lok.cxx:202
void setDialogPainting(bool bDialogPainting)
Set if we are painting the dialog.
Definition: lok.cxx:121
void statusIndicatorSetValue(int percent)
Definition: lok.cxx:276
static bool g_bLocalRendering(false)
void setCompatFlag(Compat flag)
Set compatibility flags.
Definition: lok.cxx:181
exports com.sun.star.chart2. data
Reference< XOutputStream > stream
const LanguageTag & getLocale()
Get the current LOK's locale.
Definition: lok.cxx:190
bool isViewIdForVisCursorInvalidation()
Check whether clients want viewId in visible cursor invalidation payload.
Definition: lok.cxx:161
static bool g_bViewIdForVisCursorInvalidation(false)
void setTiledAnnotations(bool bTiledAnnotations)
Set if we want no annotations rendering.
Definition: lok.cxx:141
#define SAL_INFO(area, stream)
static bool g_bTiledAnnotations(true)
static double g_fDPIScale(1.0)
Scaling of the cairo canvas painting for hi-dpi.
LanguageTag maLanguageTag
Definition: lok.cxx:44
ResultType type
void setActive(bool bActive)
Definition: lok.cxx:91
void setPartInInvalidation(bool bPartInInvalidation)
Set whether clients want a part number in an invalidation payload.
Definition: lok.cxx:101
static bool g_bActive(false)
double getDPIScale()
Get the DPI scale for rendering for HiDPI displays.
Definition: lok.cxx:136
static bool g_bPartInInvalidation(false)
void setLocale(const LanguageTag &rLanguageTag)
Update the current LOK's locale.
Definition: lok.cxx:185
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo