1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <svl/cjkoptions.hxx>
22 #include <o3tl/any.hxx>
23 #include <svl/languageoptions.hxx>
24 #include <i18nlangtag/lang.h>
25 #include <unotools/configitem.hxx>
26 #include <com/sun/star/uno/Any.h>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <osl/mutex.hxx>
29 #include <rtl/instance.hxx>
31 #include "itemholder2.hxx"
33 using namespace ::com::sun::star::uno
;
35 #define CFG_READONLY_DEFAULT false
37 class SvtCJKOptions_Impl
: public utl::ConfigItem
42 bool bAsianTypography
;
48 bool bVerticalCallOut
;
52 bool bROAsianTypography
;
55 bool bROChangeCaseMap
;
57 bool bROEmphasisMarks
;
58 bool bROVerticalCallOut
;
60 virtual void ImplCommit() override
;
65 virtual void Notify( const css::uno::Sequence
< OUString
>& rPropertyNames
) override
;
68 bool IsLoaded() const { return bIsLoaded
; }
70 bool IsCJKFontEnabled() const { return bCJKFont
; }
71 bool IsVerticalTextEnabled() const { return bVerticalText
; }
72 bool IsAsianTypographyEnabled() const { return bAsianTypography
; }
73 bool IsJapaneseFindEnabled() const { return bJapaneseFind
; }
74 bool IsRubyEnabled() const { return bRuby
; }
75 bool IsChangeCaseMapEnabled() const { return bChangeCaseMap
; }
76 bool IsDoubleLinesEnabled() const { return bDoubleLines
; }
78 bool IsAnyEnabled() const {
79 return bCJKFont
||bVerticalText
||bAsianTypography
||bJapaneseFind
||
80 bRuby
||bChangeCaseMap
||bDoubleLines
||bEmphasisMarks
||bVerticalCallOut
; }
81 void SetAll(bool bSet
);
82 bool IsReadOnly(SvtCJKOptions::EOption eOption
) const;
88 : public rtl::Static
< Sequence
<OUString
>, PropertyNames
> {};
91 SvtCJKOptions_Impl::SvtCJKOptions_Impl() :
92 utl::ConfigItem("Office.Common/I18N/CJK"),
96 bAsianTypography(true),
101 bEmphasisMarks(true),
102 bVerticalCallOut(true),
103 bROCJKFont(CFG_READONLY_DEFAULT
),
104 bROVerticalText(CFG_READONLY_DEFAULT
),
105 bROAsianTypography(CFG_READONLY_DEFAULT
),
106 bROJapaneseFind(CFG_READONLY_DEFAULT
),
107 bRORuby(CFG_READONLY_DEFAULT
),
108 bROChangeCaseMap(CFG_READONLY_DEFAULT
),
109 bRODoubleLines(CFG_READONLY_DEFAULT
),
110 bROEmphasisMarks(CFG_READONLY_DEFAULT
),
111 bROVerticalCallOut(CFG_READONLY_DEFAULT
)
115 void SvtCJKOptions_Impl::SetAll(bool bSet
)
120 bROAsianTypography
||
132 bAsianTypography
=bSet
;
138 bVerticalCallOut
=bSet
;
142 NotifyListeners(ConfigurationHints::NONE
);
145 void SvtCJKOptions_Impl::Load()
147 Sequence
<OUString
> &rPropertyNames
= PropertyNames::get();
148 if(!rPropertyNames
.hasElements())
150 rPropertyNames
.realloc(9);
151 OUString
* pNames
= rPropertyNames
.getArray();
153 pNames
[0] = "CJKFont";
154 pNames
[1] = "VerticalText";
155 pNames
[2] = "AsianTypography";
156 pNames
[3] = "JapaneseFind";
158 pNames
[5] = "ChangeCaseMap";
159 pNames
[6] = "DoubleLines";
160 pNames
[7] = "EmphasisMarks";
161 pNames
[8] = "VerticalCallOut";
163 EnableNotification( rPropertyNames
);
165 Sequence
< Any
> aValues
= GetProperties(rPropertyNames
);
166 Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates(rPropertyNames
);
167 const Any
* pValues
= aValues
.getConstArray();
168 const sal_Bool
* pROStates
= aROStates
.getConstArray();
169 assert(aValues
.getLength() == rPropertyNames
.getLength() && "GetProperties failed");
170 assert(aROStates
.getLength() == rPropertyNames
.getLength() && "GetReadOnlyStates failed");
171 if ( aValues
.getLength() == rPropertyNames
.getLength() && aROStates
.getLength() == rPropertyNames
.getLength() )
173 for ( int nProp
= 0; nProp
< rPropertyNames
.getLength(); nProp
++ )
175 if( pValues
[nProp
].hasValue() )
177 bool bValue
= *o3tl::doAccess
<bool>(pValues
[nProp
]);
180 case 0: { bCJKFont
= bValue
; bROCJKFont
= pROStates
[nProp
]; } break;
181 case 1: { bVerticalText
= bValue
; bROVerticalText
= pROStates
[nProp
]; } break;
182 case 2: { bAsianTypography
= bValue
; bROAsianTypography
= pROStates
[nProp
]; } break;
183 case 3: { bJapaneseFind
= bValue
; bROJapaneseFind
= pROStates
[nProp
]; } break;
184 case 4: { bRuby
= bValue
; bRORuby
= pROStates
[nProp
]; } break;
185 case 5: { bChangeCaseMap
= bValue
; bROChangeCaseMap
= pROStates
[nProp
]; } break;
186 case 6: { bDoubleLines
= bValue
; bRODoubleLines
= pROStates
[nProp
]; } break;
187 case 7: { bEmphasisMarks
= bValue
; bROEmphasisMarks
= pROStates
[nProp
]; } break;
188 case 8: { bVerticalCallOut
= bValue
; bROVerticalCallOut
= pROStates
[nProp
]; } break;
196 SvtScriptType nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM
);
197 //system locale is CJK
198 bool bAutoEnableCJK
= bool(nScriptType
& SvtScriptType::ASIAN
);
202 SvtSystemLanguageOptions aSystemLocaleSettings
;
204 //windows secondary system locale is CJK
205 LanguageType eSystemLanguage
= aSystemLocaleSettings
.GetWin16SystemLanguage();
206 if (eSystemLanguage
!= LANGUAGE_SYSTEM
)
208 SvtScriptType nWinScript
= SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage
);
209 bAutoEnableCJK
= bool(nWinScript
& SvtScriptType::ASIAN
);
212 //CJK keyboard is installed
214 bAutoEnableCJK
= aSystemLocaleSettings
.isCJKKeyboardLayoutInstalled();
225 void SvtCJKOptions_Impl::Notify( const Sequence
< OUString
>& )
228 NotifyListeners(ConfigurationHints::NONE
);
231 void SvtCJKOptions_Impl::ImplCommit()
233 Sequence
<OUString
> &rPropertyNames
= PropertyNames::get();
234 OUString
* pOrgNames
= rPropertyNames
.getArray();
235 sal_Int32 nOrgCount
= rPropertyNames
.getLength();
237 Sequence
< OUString
> aNames(nOrgCount
);
238 Sequence
< Any
> aValues(nOrgCount
);
240 OUString
* pNames
= aNames
.getArray();
241 Any
* pValues
= aValues
.getArray();
242 sal_Int32 nRealCount
= 0;
244 for(int nProp
= 0; nProp
< nOrgCount
; nProp
++)
252 pNames
[nRealCount
] = pOrgNames
[nProp
];
253 pValues
[nRealCount
] <<= bCJKFont
;
261 if (!bROVerticalText
)
263 pNames
[nRealCount
] = pOrgNames
[nProp
];
264 pValues
[nRealCount
] <<= bVerticalText
;
272 if (!bROAsianTypography
)
274 pNames
[nRealCount
] = pOrgNames
[nProp
];
275 pValues
[nRealCount
] <<= bAsianTypography
;
283 if (!bROJapaneseFind
)
285 pNames
[nRealCount
] = pOrgNames
[nProp
];
286 pValues
[nRealCount
] <<= bJapaneseFind
;
296 pNames
[nRealCount
] = pOrgNames
[nProp
];
297 pValues
[nRealCount
] <<= bRuby
;
305 if (!bROChangeCaseMap
)
307 pNames
[nRealCount
] = pOrgNames
[nProp
];
308 pValues
[nRealCount
] <<= bChangeCaseMap
;
318 pNames
[nRealCount
] = pOrgNames
[nProp
];
319 pValues
[nRealCount
] <<= bDoubleLines
;
327 if (!bROEmphasisMarks
)
329 pNames
[nRealCount
] = pOrgNames
[nProp
];
330 pValues
[nRealCount
] <<= bEmphasisMarks
;
338 if (!bROVerticalCallOut
)
340 pNames
[nRealCount
] = pOrgNames
[nProp
];
341 pValues
[nRealCount
] <<= bVerticalCallOut
;
348 aNames
.realloc(nRealCount
);
349 aValues
.realloc(nRealCount
);
350 PutProperties(aNames
, aValues
);
353 bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption
) const
355 bool bReadOnly
= CFG_READONLY_DEFAULT
;
358 case SvtCJKOptions::E_CJKFONT
: bReadOnly
= bROCJKFont
; break;
359 case SvtCJKOptions::E_VERTICALTEXT
: bReadOnly
= bROVerticalText
; break;
360 case SvtCJKOptions::E_ASIANTYPOGRAPHY
: bReadOnly
= bROAsianTypography
; break;
361 case SvtCJKOptions::E_JAPANESEFIND
: bReadOnly
= bROJapaneseFind
; break;
362 case SvtCJKOptions::E_RUBY
: bReadOnly
= bRORuby
; break;
363 case SvtCJKOptions::E_CHANGECASEMAP
: bReadOnly
= bROChangeCaseMap
; break;
364 case SvtCJKOptions::E_DOUBLELINES
: bReadOnly
= bRODoubleLines
; break;
365 case SvtCJKOptions::E_EMPHASISMARKS
: bReadOnly
= bROEmphasisMarks
; break;
366 case SvtCJKOptions::E_VERTICALCALLOUT
: bReadOnly
= bROVerticalCallOut
; break;
367 case SvtCJKOptions::E_ALL
: if (bROCJKFont
|| bROVerticalText
|| bROAsianTypography
|| bROJapaneseFind
|| bRORuby
|| bROChangeCaseMap
|| bRODoubleLines
|| bROEmphasisMarks
|| bROVerticalCallOut
)
377 std::weak_ptr
<SvtCJKOptions_Impl
> g_pCJKOptions
;
379 struct theCJKOptionsMutex
: public rtl::Static
< ::osl::Mutex
, theCJKOptionsMutex
>{};
382 SvtCJKOptions::SvtCJKOptions(bool bDontLoad
)
384 // Global access, must be guarded (multithreading)
385 ::osl::MutexGuard
aGuard( theCJKOptionsMutex::get() );
386 pImpl
= g_pCJKOptions
.lock();
389 pImpl
= std::make_shared
<SvtCJKOptions_Impl
>();
390 g_pCJKOptions
= pImpl
;
391 ItemHolder2::holdConfigItem(EItem::CJKOptions
);
394 if( !bDontLoad
&& !pImpl
->IsLoaded())
399 SvtCJKOptions::~SvtCJKOptions()
401 // Global access, must be guarded (multithreading)
402 ::osl::MutexGuard
aGuard( theCJKOptionsMutex::get() );
404 // pImpl needs to be cleared before the mutex is dropped
408 bool SvtCJKOptions::IsCJKFontEnabled() const
410 assert(pImpl
->IsLoaded());
411 return pImpl
->IsCJKFontEnabled();
414 bool SvtCJKOptions::IsVerticalTextEnabled() const
416 assert(pImpl
->IsLoaded());
417 return pImpl
->IsVerticalTextEnabled();
420 bool SvtCJKOptions::IsAsianTypographyEnabled() const
422 assert(pImpl
->IsLoaded());
423 return pImpl
->IsAsianTypographyEnabled();
426 bool SvtCJKOptions::IsJapaneseFindEnabled() const
428 assert(pImpl
->IsLoaded());
429 return pImpl
->IsJapaneseFindEnabled();
432 bool SvtCJKOptions::IsRubyEnabled() const
434 assert(pImpl
->IsLoaded());
435 return pImpl
->IsRubyEnabled();
438 bool SvtCJKOptions::IsChangeCaseMapEnabled() const
440 assert(pImpl
->IsLoaded());
441 return pImpl
->IsChangeCaseMapEnabled();
444 bool SvtCJKOptions::IsDoubleLinesEnabled() const
446 assert(pImpl
->IsLoaded());
447 return pImpl
->IsDoubleLinesEnabled();
450 void SvtCJKOptions::SetAll(bool bSet
)
452 assert(pImpl
->IsLoaded());
456 bool SvtCJKOptions::IsAnyEnabled() const
458 assert(pImpl
->IsLoaded());
459 return pImpl
->IsAnyEnabled();
462 bool SvtCJKOptions::IsReadOnly(EOption eOption
) const
464 assert(pImpl
->IsLoaded());
465 return pImpl
->IsReadOnly(eOption
);
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */