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 <svl/languageoptions.hxx>
23 #include <i18nlangtag/lang.h>
24 #include <unotools/configitem.hxx>
25 #include <tools/solar.h>
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() SAL_OVERRIDE
;
64 virtual ~SvtCJKOptions_Impl();
66 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
>& rPropertyNames
) SAL_OVERRIDE
;
69 bool IsLoaded() { return bIsLoaded
; }
71 bool IsCJKFontEnabled() const { return bCJKFont
; }
72 bool IsVerticalTextEnabled() const { return bVerticalText
; }
73 bool IsAsianTypographyEnabled() const { return bAsianTypography
; }
74 bool IsJapaneseFindEnabled() const { return bJapaneseFind
; }
75 bool IsRubyEnabled() const { return bRuby
; }
76 bool IsChangeCaseMapEnabled() const { return bChangeCaseMap
; }
77 bool IsDoubleLinesEnabled() const { return bDoubleLines
; }
79 bool IsAnyEnabled() const {
80 return bCJKFont
||bVerticalText
||bAsianTypography
||bJapaneseFind
||
81 bRuby
||bChangeCaseMap
||bDoubleLines
||bEmphasisMarks
||bVerticalCallOut
; }
82 void SetAll(bool bSet
);
83 bool IsReadOnly(SvtCJKOptions::EOption eOption
) const;
89 : public rtl::Static
< Sequence
<OUString
>, PropertyNames
> {};
92 SvtCJKOptions_Impl::SvtCJKOptions_Impl() :
93 utl::ConfigItem("Office.Common/I18N/CJK"),
97 bAsianTypography(true),
100 bChangeCaseMap(true),
102 bEmphasisMarks(true),
103 bVerticalCallOut(true),
104 bROCJKFont(CFG_READONLY_DEFAULT
),
105 bROVerticalText(CFG_READONLY_DEFAULT
),
106 bROAsianTypography(CFG_READONLY_DEFAULT
),
107 bROJapaneseFind(CFG_READONLY_DEFAULT
),
108 bRORuby(CFG_READONLY_DEFAULT
),
109 bROChangeCaseMap(CFG_READONLY_DEFAULT
),
110 bRODoubleLines(CFG_READONLY_DEFAULT
),
111 bROEmphasisMarks(CFG_READONLY_DEFAULT
),
112 bROVerticalCallOut(CFG_READONLY_DEFAULT
)
116 SvtCJKOptions_Impl::~SvtCJKOptions_Impl()
120 void SvtCJKOptions_Impl::SetAll(bool bSet
)
125 !bROAsianTypography
&&
136 bAsianTypography
=bSet
;
142 bVerticalCallOut
=bSet
;
150 void SvtCJKOptions_Impl::Load()
152 Sequence
<OUString
> &rPropertyNames
= PropertyNames::get();
153 if(!rPropertyNames
.getLength())
155 rPropertyNames
.realloc(9);
156 OUString
* pNames
= rPropertyNames
.getArray();
158 pNames
[0] = "CJKFont";
159 pNames
[1] = "VerticalText";
160 pNames
[2] = "AsianTypography";
161 pNames
[3] = "JapaneseFind";
163 pNames
[5] = "ChangeCaseMap";
164 pNames
[6] = "DoubleLines";
165 pNames
[7] = "EmphasisMarks";
166 pNames
[8] = "VerticalCallOut";
168 EnableNotification( rPropertyNames
);
170 Sequence
< Any
> aValues
= GetProperties(rPropertyNames
);
171 Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates(rPropertyNames
);
172 const Any
* pValues
= aValues
.getConstArray();
173 const sal_Bool
* pROStates
= aROStates
.getConstArray();
174 assert(aValues
.getLength() == rPropertyNames
.getLength() && "GetProperties failed");
175 assert(aROStates
.getLength() == rPropertyNames
.getLength() && "GetReadOnlyStates failed");
176 if ( aValues
.getLength() == rPropertyNames
.getLength() && aROStates
.getLength() == rPropertyNames
.getLength() )
178 for ( int nProp
= 0; nProp
< rPropertyNames
.getLength(); nProp
++ )
180 if( pValues
[nProp
].hasValue() )
182 bool bValue
= *static_cast<sal_Bool
const *>(pValues
[nProp
].getValue());
185 case 0: { bCJKFont
= bValue
; bROCJKFont
= pROStates
[nProp
]; } break;
186 case 1: { bVerticalText
= bValue
; bROVerticalText
= pROStates
[nProp
]; } break;
187 case 2: { bAsianTypography
= bValue
; bROAsianTypography
= pROStates
[nProp
]; } break;
188 case 3: { bJapaneseFind
= bValue
; bROJapaneseFind
= pROStates
[nProp
]; } break;
189 case 4: { bRuby
= bValue
; bRORuby
= pROStates
[nProp
]; } break;
190 case 5: { bChangeCaseMap
= bValue
; bROChangeCaseMap
= pROStates
[nProp
]; } break;
191 case 6: { bDoubleLines
= bValue
; bRODoubleLines
= pROStates
[nProp
]; } break;
192 case 7: { bEmphasisMarks
= bValue
; bROEmphasisMarks
= pROStates
[nProp
]; } break;
193 case 8: { bVerticalCallOut
= bValue
; bROVerticalCallOut
= pROStates
[nProp
]; } break;
201 SvtScriptType nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM
);
202 //system locale is CJK
203 bool bAutoEnableCJK
= bool(nScriptType
& SvtScriptType::ASIAN
);
207 SvtSystemLanguageOptions aSystemLocaleSettings
;
209 //windows secondary system locale is CJK
210 LanguageType eSystemLanguage
= aSystemLocaleSettings
.GetWin16SystemLanguage();
211 if (eSystemLanguage
!= LANGUAGE_SYSTEM
)
213 SvtScriptType nWinScript
= SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage
);
214 bAutoEnableCJK
= bool(nWinScript
& SvtScriptType::ASIAN
);
217 //CJK keyboard is installed
219 bAutoEnableCJK
= aSystemLocaleSettings
.isCJKKeyboardLayoutInstalled();
230 void SvtCJKOptions_Impl::Notify( const Sequence
< OUString
>& )
236 void SvtCJKOptions_Impl::ImplCommit()
238 Sequence
<OUString
> &rPropertyNames
= PropertyNames::get();
239 OUString
* pOrgNames
= rPropertyNames
.getArray();
240 sal_Int32 nOrgCount
= rPropertyNames
.getLength();
242 Sequence
< OUString
> aNames(nOrgCount
);
243 Sequence
< Any
> aValues(nOrgCount
);
245 OUString
* pNames
= aNames
.getArray();
246 Any
* pValues
= aValues
.getArray();
247 sal_Int32 nRealCount
= 0;
249 const Type
& rType
= cppu::UnoType
<bool>::get();
250 for(int nProp
= 0; nProp
< nOrgCount
; nProp
++)
258 pNames
[nRealCount
] = pOrgNames
[nProp
];
259 pValues
[nRealCount
].setValue(&bCJKFont
, rType
);
267 if (!bROVerticalText
)
269 pNames
[nRealCount
] = pOrgNames
[nProp
];
270 pValues
[nRealCount
].setValue(&bVerticalText
, rType
);
278 if (!bROAsianTypography
)
280 pNames
[nRealCount
] = pOrgNames
[nProp
];
281 pValues
[nRealCount
].setValue(&bAsianTypography
, rType
);
289 if (!bROJapaneseFind
)
291 pNames
[nRealCount
] = pOrgNames
[nProp
];
292 pValues
[nRealCount
].setValue(&bJapaneseFind
, rType
);
302 pNames
[nRealCount
] = pOrgNames
[nProp
];
303 pValues
[nRealCount
].setValue(&bRuby
, rType
);
311 if (!bROChangeCaseMap
)
313 pNames
[nRealCount
] = pOrgNames
[nProp
];
314 pValues
[nRealCount
].setValue(&bChangeCaseMap
, rType
);
324 pNames
[nRealCount
] = pOrgNames
[nProp
];
325 pValues
[nRealCount
].setValue(&bDoubleLines
, rType
);
333 if (!bROEmphasisMarks
)
335 pNames
[nRealCount
] = pOrgNames
[nProp
];
336 pValues
[nRealCount
].setValue(&bEmphasisMarks
, rType
);
344 if (!bROVerticalCallOut
)
346 pNames
[nRealCount
] = pOrgNames
[nProp
];
347 pValues
[nRealCount
].setValue(&bVerticalCallOut
, rType
);
354 aNames
.realloc(nRealCount
);
355 aValues
.realloc(nRealCount
);
356 PutProperties(aNames
, aValues
);
359 bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption
) const
361 bool bReadOnly
= CFG_READONLY_DEFAULT
;
364 case SvtCJKOptions::E_CJKFONT
: bReadOnly
= bROCJKFont
; break;
365 case SvtCJKOptions::E_VERTICALTEXT
: bReadOnly
= bROVerticalText
; break;
366 case SvtCJKOptions::E_ASIANTYPOGRAPHY
: bReadOnly
= bROAsianTypography
; break;
367 case SvtCJKOptions::E_JAPANESEFIND
: bReadOnly
= bROJapaneseFind
; break;
368 case SvtCJKOptions::E_RUBY
: bReadOnly
= bRORuby
; break;
369 case SvtCJKOptions::E_CHANGECASEMAP
: bReadOnly
= bROChangeCaseMap
; break;
370 case SvtCJKOptions::E_DOUBLELINES
: bReadOnly
= bRODoubleLines
; break;
371 case SvtCJKOptions::E_EMPHASISMARKS
: bReadOnly
= bROEmphasisMarks
; break;
372 case SvtCJKOptions::E_VERTICALCALLOUT
: bReadOnly
= bROVerticalCallOut
; break;
373 case SvtCJKOptions::E_ALL
: if (bROCJKFont
|| bROVerticalText
|| bROAsianTypography
|| bROJapaneseFind
|| bRORuby
|| bROChangeCaseMap
|| bRODoubleLines
|| bROEmphasisMarks
|| bROVerticalCallOut
)
382 static SvtCJKOptions_Impl
* pCJKOptions
= NULL
;
383 static sal_Int32 nCJKRefCount
= 0;
384 namespace { struct theCJKOptionsMutex
: public rtl::Static
< ::osl::Mutex
, theCJKOptionsMutex
>{}; }
386 SvtCJKOptions::SvtCJKOptions(bool bDontLoad
)
388 // Global access, must be guarded (multithreading)
389 ::osl::MutexGuard
aGuard( theCJKOptionsMutex::get() );
392 pCJKOptions
= new SvtCJKOptions_Impl
;
393 ItemHolder2::holdConfigItem(E_CJKOPTIONS
);
395 if( !bDontLoad
&& !pCJKOptions
->IsLoaded())
404 SvtCJKOptions::~SvtCJKOptions()
406 // Global access, must be guarded (multithreading)
407 ::osl::MutexGuard
aGuard( theCJKOptionsMutex::get() );
408 if ( !--nCJKRefCount
)
409 DELETEZ( pCJKOptions
);
412 bool SvtCJKOptions::IsCJKFontEnabled() const
414 assert(pCJKOptions
->IsLoaded());
415 return pCJKOptions
->IsCJKFontEnabled();
418 bool SvtCJKOptions::IsVerticalTextEnabled() const
420 assert(pCJKOptions
->IsLoaded());
421 return pCJKOptions
->IsVerticalTextEnabled();
424 bool SvtCJKOptions::IsAsianTypographyEnabled() const
426 assert(pCJKOptions
->IsLoaded());
427 return pCJKOptions
->IsAsianTypographyEnabled();
430 bool SvtCJKOptions::IsJapaneseFindEnabled() const
432 assert(pCJKOptions
->IsLoaded());
433 return pCJKOptions
->IsJapaneseFindEnabled();
436 bool SvtCJKOptions::IsRubyEnabled() const
438 assert(pCJKOptions
->IsLoaded());
439 return pCJKOptions
->IsRubyEnabled();
442 bool SvtCJKOptions::IsChangeCaseMapEnabled() const
444 assert(pCJKOptions
->IsLoaded());
445 return pCJKOptions
->IsChangeCaseMapEnabled();
448 bool SvtCJKOptions::IsDoubleLinesEnabled() const
450 assert(pCJKOptions
->IsLoaded());
451 return pCJKOptions
->IsDoubleLinesEnabled();
454 void SvtCJKOptions::SetAll(bool bSet
)
456 assert(pCJKOptions
->IsLoaded());
457 pCJKOptions
->SetAll(bSet
);
460 bool SvtCJKOptions::IsAnyEnabled() const
462 assert(pCJKOptions
->IsLoaded());
463 return pCJKOptions
->IsAnyEnabled();
466 bool SvtCJKOptions::IsReadOnly(EOption eOption
) const
468 assert(pCJKOptions
->IsLoaded());
469 return pCJKOptions
->IsReadOnly(eOption
);
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */