GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / config / cjkoptions.cxx
blobd69880aad0ab3767ff42ee6a0117563445aa0168
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svl/cjkoptions.hxx>
23 #include <svl/languageoptions.hxx>
24 #include <i18nlangtag/lang.h>
25 #include <unotools/configitem.hxx>
26 #include <tools/debug.hxx>
27 #include <com/sun/star/uno/Any.h>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <osl/mutex.hxx>
30 #include <rtl/instance.hxx>
32 #include <itemholder2.hxx>
34 using namespace ::com::sun::star::uno;
35 using namespace ::rtl;
37 #define CFG_READONLY_DEFAULT sal_False
39 class SvtCJKOptions_Impl : public utl::ConfigItem
41 sal_Bool bIsLoaded;
42 sal_Bool bCJKFont;
43 sal_Bool bVerticalText;
44 sal_Bool bAsianTypography;
45 sal_Bool bJapaneseFind;
46 sal_Bool bRuby;
47 sal_Bool bChangeCaseMap;
48 sal_Bool bDoubleLines;
49 sal_Bool bEmphasisMarks;
50 sal_Bool bVerticalCallOut;
52 sal_Bool bROCJKFont;
53 sal_Bool bROVerticalText;
54 sal_Bool bROAsianTypography;
55 sal_Bool bROJapaneseFind;
56 sal_Bool bRORuby;
57 sal_Bool bROChangeCaseMap;
58 sal_Bool bRODoubleLines;
59 sal_Bool bROEmphasisMarks;
60 sal_Bool bROVerticalCallOut;
62 public:
63 SvtCJKOptions_Impl();
64 ~SvtCJKOptions_Impl();
66 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& rPropertyNames );
67 virtual void Commit();
68 void Load();
70 sal_Bool IsLoaded() { return bIsLoaded; }
72 sal_Bool IsCJKFontEnabled() const { return bCJKFont; }
73 sal_Bool IsVerticalTextEnabled() const { return bVerticalText; }
74 sal_Bool IsAsianTypographyEnabled() const { return bAsianTypography; }
75 sal_Bool IsJapaneseFindEnabled() const { return bJapaneseFind; }
76 sal_Bool IsRubyEnabled() const { return bRuby; }
77 sal_Bool IsChangeCaseMapEnabled() const { return bChangeCaseMap; }
78 sal_Bool IsDoubleLinesEnabled() const { return bDoubleLines; }
80 sal_Bool IsAnyEnabled() const {
81 return bCJKFont||bVerticalText||bAsianTypography||bJapaneseFind||
82 bRuby||bChangeCaseMap||bDoubleLines||bEmphasisMarks||bVerticalCallOut; }
83 void SetAll(sal_Bool bSet);
84 sal_Bool IsReadOnly(SvtCJKOptions::EOption eOption) const;
87 namespace
89 struct PropertyNames
90 : public rtl::Static< Sequence<OUString>, PropertyNames > {};
93 SvtCJKOptions_Impl::SvtCJKOptions_Impl() :
94 utl::ConfigItem("Office.Common/I18N/CJK"),
95 bIsLoaded(sal_False),
96 bCJKFont(sal_True),
97 bVerticalText(sal_True),
98 bAsianTypography(sal_True),
99 bJapaneseFind(sal_True),
100 bRuby(sal_True),
101 bChangeCaseMap(sal_True),
102 bDoubleLines(sal_True),
103 bEmphasisMarks(sal_True),
104 bVerticalCallOut(sal_True),
105 bROCJKFont(CFG_READONLY_DEFAULT),
106 bROVerticalText(CFG_READONLY_DEFAULT),
107 bROAsianTypography(CFG_READONLY_DEFAULT),
108 bROJapaneseFind(CFG_READONLY_DEFAULT),
109 bRORuby(CFG_READONLY_DEFAULT),
110 bROChangeCaseMap(CFG_READONLY_DEFAULT),
111 bRODoubleLines(CFG_READONLY_DEFAULT),
112 bROEmphasisMarks(CFG_READONLY_DEFAULT),
113 bROVerticalCallOut(CFG_READONLY_DEFAULT)
117 SvtCJKOptions_Impl::~SvtCJKOptions_Impl()
121 void SvtCJKOptions_Impl::SetAll(sal_Bool bSet)
123 if (
124 !bROCJKFont &&
125 !bROVerticalText &&
126 !bROAsianTypography &&
127 !bROJapaneseFind &&
128 !bRORuby &&
129 !bROChangeCaseMap &&
130 !bRODoubleLines &&
131 !bROEmphasisMarks &&
132 !bROVerticalCallOut
135 bCJKFont=bSet;
136 bVerticalText=bSet;
137 bAsianTypography=bSet;
138 bJapaneseFind=bSet;
139 bRuby=bSet;
140 bChangeCaseMap=bSet;
141 bDoubleLines=bSet;
142 bEmphasisMarks=bSet;
143 bVerticalCallOut=bSet;
145 SetModified();
146 Commit();
147 NotifyListeners(0);
151 void SvtCJKOptions_Impl::Load()
153 Sequence<OUString> &rPropertyNames = PropertyNames::get();
154 if(!rPropertyNames.getLength())
156 rPropertyNames.realloc(9);
157 OUString* pNames = rPropertyNames.getArray();
159 pNames[0] = "CJKFont";
160 pNames[1] = "VerticalText";
161 pNames[2] = "AsianTypography";
162 pNames[3] = "JapaneseFind";
163 pNames[4] = "Ruby";
164 pNames[5] = "ChangeCaseMap";
165 pNames[6] = "DoubleLines";
166 pNames[7] = "EmphasisMarks";
167 pNames[8] = "VerticalCallOut";
169 EnableNotification( rPropertyNames );
171 Sequence< Any > aValues = GetProperties(rPropertyNames);
172 Sequence< sal_Bool > aROStates = GetReadOnlyStates(rPropertyNames);
173 const Any* pValues = aValues.getConstArray();
174 const sal_Bool* pROStates = aROStates.getConstArray();
175 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
176 DBG_ASSERT( aROStates.getLength() == rPropertyNames.getLength(), "GetReadOnlyStates failed" );
177 if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() )
179 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
181 if( pValues[nProp].hasValue() )
183 sal_Bool bValue = *(sal_Bool*)pValues[nProp].getValue();
184 switch ( nProp )
186 case 0: { bCJKFont = bValue; bROCJKFont = pROStates[nProp]; } break;
187 case 1: { bVerticalText = bValue; bROVerticalText = pROStates[nProp]; } break;
188 case 2: { bAsianTypography = bValue; bROAsianTypography = pROStates[nProp]; } break;
189 case 3: { bJapaneseFind = bValue; bROJapaneseFind = pROStates[nProp]; } break;
190 case 4: { bRuby = bValue; bRORuby = pROStates[nProp]; } break;
191 case 5: { bChangeCaseMap = bValue; bROChangeCaseMap = pROStates[nProp]; } break;
192 case 6: { bDoubleLines = bValue; bRODoubleLines = pROStates[nProp]; } break;
193 case 7: { bEmphasisMarks = bValue; bROEmphasisMarks = pROStates[nProp]; } break;
194 case 8: { bVerticalCallOut = bValue; bROVerticalCallOut = pROStates[nProp]; } break;
200 if (!bCJKFont)
202 bool bAutoEnableCJK = false;
204 sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM);
205 //system locale is CJK
206 bAutoEnableCJK = (nScriptType & SCRIPTTYPE_ASIAN);
208 if (!bAutoEnableCJK)
210 SvtSystemLanguageOptions aSystemLocaleSettings;
212 //windows secondary system locale is CJK
213 LanguageType eSystemLanguage = aSystemLocaleSettings.GetWin16SystemLanguage();
214 if (eSystemLanguage != LANGUAGE_SYSTEM)
216 sal_uInt16 nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage );
217 bAutoEnableCJK = (nWinScript & SCRIPTTYPE_ASIAN);
220 //CJK keyboard is installed
221 if (!bAutoEnableCJK)
222 bAutoEnableCJK = aSystemLocaleSettings.isCJKKeyboardLayoutInstalled();
225 if (bAutoEnableCJK)
227 SetAll(sal_True);
230 bIsLoaded = sal_True;
233 void SvtCJKOptions_Impl::Notify( const Sequence< OUString >& )
235 Load();
236 NotifyListeners(0);
239 void SvtCJKOptions_Impl::Commit()
241 Sequence<OUString> &rPropertyNames = PropertyNames::get();
242 OUString* pOrgNames = rPropertyNames.getArray();
243 sal_Int32 nOrgCount = rPropertyNames.getLength();
245 Sequence< OUString > aNames(nOrgCount);
246 Sequence< Any > aValues(nOrgCount);
248 OUString* pNames = aNames.getArray();
249 Any* pValues = aValues.getArray();
250 sal_Int32 nRealCount = 0;
252 const Type& rType = ::getBooleanCppuType();
253 for(int nProp = 0; nProp < nOrgCount; nProp++)
255 switch(nProp)
257 case 0:
259 if (!bROCJKFont)
261 pNames[nRealCount] = pOrgNames[nProp];
262 pValues[nRealCount].setValue(&bCJKFont, rType);
263 ++nRealCount;
266 break;
268 case 1:
270 if (!bROVerticalText)
272 pNames[nRealCount] = pOrgNames[nProp];
273 pValues[nRealCount].setValue(&bVerticalText, rType);
274 ++nRealCount;
277 break;
279 case 2:
281 if (!bROAsianTypography)
283 pNames[nRealCount] = pOrgNames[nProp];
284 pValues[nRealCount].setValue(&bAsianTypography, rType);
285 ++nRealCount;
288 break;
290 case 3:
292 if (!bROJapaneseFind)
294 pNames[nRealCount] = pOrgNames[nProp];
295 pValues[nRealCount].setValue(&bJapaneseFind, rType);
296 ++nRealCount;
299 break;
301 case 4:
303 if (!bRORuby)
305 pNames[nRealCount] = pOrgNames[nProp];
306 pValues[nRealCount].setValue(&bRuby, rType);
307 ++nRealCount;
310 break;
312 case 5:
314 if (!bROChangeCaseMap)
316 pNames[nRealCount] = pOrgNames[nProp];
317 pValues[nRealCount].setValue(&bChangeCaseMap, rType);
318 ++nRealCount;
321 break;
323 case 6:
325 if (!bRODoubleLines)
327 pNames[nRealCount] = pOrgNames[nProp];
328 pValues[nRealCount].setValue(&bDoubleLines, rType);
329 ++nRealCount;
332 break;
334 case 7:
336 if (!bROEmphasisMarks)
338 pNames[nRealCount] = pOrgNames[nProp];
339 pValues[nRealCount].setValue(&bEmphasisMarks, rType);
340 ++nRealCount;
343 break;
345 case 8:
347 if (!bROVerticalCallOut)
349 pNames[nRealCount] = pOrgNames[nProp];
350 pValues[nRealCount].setValue(&bVerticalCallOut, rType);
351 ++nRealCount;
354 break;
357 aNames.realloc(nRealCount);
358 aValues.realloc(nRealCount);
359 PutProperties(aNames, aValues);
362 sal_Bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption) const
364 sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
365 switch(eOption)
367 case SvtCJKOptions::E_CJKFONT : bReadOnly = bROCJKFont; break;
368 case SvtCJKOptions::E_VERTICALTEXT : bReadOnly = bROVerticalText; break;
369 case SvtCJKOptions::E_ASIANTYPOGRAPHY : bReadOnly = bROAsianTypography; break;
370 case SvtCJKOptions::E_JAPANESEFIND : bReadOnly = bROJapaneseFind; break;
371 case SvtCJKOptions::E_RUBY : bReadOnly = bRORuby; break;
372 case SvtCJKOptions::E_CHANGECASEMAP : bReadOnly = bROChangeCaseMap; break;
373 case SvtCJKOptions::E_DOUBLELINES : bReadOnly = bRODoubleLines; break;
374 case SvtCJKOptions::E_EMPHASISMARKS : bReadOnly = bROEmphasisMarks; break;
375 case SvtCJKOptions::E_VERTICALCALLOUT : bReadOnly = bROVerticalCallOut; break;
376 case SvtCJKOptions::E_ALL : if (bROCJKFont || bROVerticalText || bROAsianTypography || bROJapaneseFind || bRORuby || bROChangeCaseMap || bRODoubleLines || bROEmphasisMarks || bROVerticalCallOut)
377 bReadOnly = sal_True;
378 break;
380 return bReadOnly;
383 // global ----------------------------------------------------------------
385 static SvtCJKOptions_Impl* pCJKOptions = NULL;
386 static sal_Int32 nCJKRefCount = 0;
387 namespace { struct theCJKOptionsMutex : public rtl::Static< ::osl::Mutex , theCJKOptionsMutex >{}; }
390 // class SvtCJKOptions --------------------------------------------------
392 SvtCJKOptions::SvtCJKOptions(sal_Bool bDontLoad)
394 // Global access, must be guarded (multithreading)
395 ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() );
396 if ( !pCJKOptions )
398 pCJKOptions = new SvtCJKOptions_Impl;
399 ItemHolder2::holdConfigItem(E_CJKOPTIONS);
401 if( !bDontLoad && !pCJKOptions->IsLoaded())
402 pCJKOptions->Load();
404 ++nCJKRefCount;
405 pImp = pCJKOptions;
408 // -----------------------------------------------------------------------
410 SvtCJKOptions::~SvtCJKOptions()
412 // Global access, must be guarded (multithreading)
413 ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() );
414 if ( !--nCJKRefCount )
415 DELETEZ( pCJKOptions );
417 // -----------------------------------------------------------------------
418 sal_Bool SvtCJKOptions::IsCJKFontEnabled() const
420 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
421 return pCJKOptions->IsCJKFontEnabled();
423 // -----------------------------------------------------------------------
424 sal_Bool SvtCJKOptions::IsVerticalTextEnabled() const
426 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
427 return pCJKOptions->IsVerticalTextEnabled();
429 // -----------------------------------------------------------------------
430 sal_Bool SvtCJKOptions::IsAsianTypographyEnabled() const
432 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
433 return pCJKOptions->IsAsianTypographyEnabled();
435 // -----------------------------------------------------------------------
436 sal_Bool SvtCJKOptions::IsJapaneseFindEnabled() const
438 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
439 return pCJKOptions->IsJapaneseFindEnabled();
441 // -----------------------------------------------------------------------
442 sal_Bool SvtCJKOptions::IsRubyEnabled() const
444 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
445 return pCJKOptions->IsRubyEnabled();
447 // -----------------------------------------------------------------------
448 sal_Bool SvtCJKOptions::IsChangeCaseMapEnabled() const
450 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
451 return pCJKOptions->IsChangeCaseMapEnabled();
453 // -----------------------------------------------------------------------
454 sal_Bool SvtCJKOptions::IsDoubleLinesEnabled() const
456 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
457 return pCJKOptions->IsDoubleLinesEnabled();
460 void SvtCJKOptions::SetAll(sal_Bool bSet)
462 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
463 pCJKOptions->SetAll(bSet);
466 sal_Bool SvtCJKOptions::IsAnyEnabled() const
468 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
469 return pCJKOptions->IsAnyEnabled();
472 sal_Bool SvtCJKOptions::IsReadOnly(EOption eOption) const
474 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
475 return pCJKOptions->IsReadOnly(eOption);
478 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */