1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svl.hxx" 30 31 #include <svl/cjkoptions.hxx> 32 33 #include <svl/languageoptions.hxx> 34 #include <i18npool/lang.h> 35 #include <unotools/configitem.hxx> 36 #include <tools/debug.hxx> 37 #include <com/sun/star/uno/Any.h> 38 #include <com/sun/star/uno/Sequence.hxx> 39 #include <osl/mutex.hxx> 40 #include <rtl/instance.hxx> 41 42 #include <itemholder2.hxx> 43 44 using namespace ::com::sun::star::uno; 45 using namespace ::rtl; 46 47 #define C2U(cChar) OUString::createFromAscii(cChar) 48 #define CFG_READONLY_DEFAULT sal_False 49 /* -----------------------------10.04.01 12:39-------------------------------- 50 51 ---------------------------------------------------------------------------*/ 52 class SvtCJKOptions_Impl : public utl::ConfigItem 53 { 54 sal_Bool bIsLoaded; 55 sal_Bool bCJKFont; 56 sal_Bool bVerticalText; 57 sal_Bool bAsianTypography; 58 sal_Bool bJapaneseFind; 59 sal_Bool bRuby; 60 sal_Bool bChangeCaseMap; 61 sal_Bool bDoubleLines; 62 sal_Bool bEmphasisMarks; 63 sal_Bool bVerticalCallOut; 64 65 sal_Bool bROCJKFont; 66 sal_Bool bROVerticalText; 67 sal_Bool bROAsianTypography; 68 sal_Bool bROJapaneseFind; 69 sal_Bool bRORuby; 70 sal_Bool bROChangeCaseMap; 71 sal_Bool bRODoubleLines; 72 sal_Bool bROEmphasisMarks; 73 sal_Bool bROVerticalCallOut; 74 75 public: 76 SvtCJKOptions_Impl(); 77 ~SvtCJKOptions_Impl(); 78 79 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& rPropertyNames ); 80 virtual void Commit(); 81 void Load(); 82 83 sal_Bool IsLoaded() { return bIsLoaded; } 84 85 sal_Bool IsCJKFontEnabled() const { return bCJKFont; } 86 sal_Bool IsVerticalTextEnabled() const { return bVerticalText; } 87 sal_Bool IsAsianTypographyEnabled() const { return bAsianTypography; } 88 sal_Bool IsJapaneseFindEnabled() const { return bJapaneseFind; } 89 sal_Bool IsRubyEnabled() const { return bRuby; } 90 sal_Bool IsChangeCaseMapEnabled() const { return bChangeCaseMap; } 91 sal_Bool IsDoubleLinesEnabled() const { return bDoubleLines; } 92 sal_Bool IsEmphasisMarksEnabled() const { return bEmphasisMarks; } 93 sal_Bool IsVerticalCallOutEnabled() const { return bVerticalCallOut; } 94 95 sal_Bool IsAnyEnabled() const { 96 return bCJKFont||bVerticalText||bAsianTypography||bJapaneseFind|| 97 bRuby||bChangeCaseMap||bDoubleLines||bEmphasisMarks||bVerticalCallOut; } 98 void SetAll(sal_Bool bSet); 99 sal_Bool IsReadOnly(SvtCJKOptions::EOption eOption) const; 100 }; 101 /*-- 10.04.01 12:41:57--------------------------------------------------- 102 103 -----------------------------------------------------------------------*/ 104 namespace 105 { 106 struct PropertyNames 107 : public rtl::Static< Sequence<OUString>, PropertyNames > {}; 108 } 109 110 SvtCJKOptions_Impl::SvtCJKOptions_Impl() : 111 utl::ConfigItem(C2U("Office.Common/I18N/CJK")), 112 bIsLoaded(sal_False), 113 bCJKFont(sal_True), 114 bVerticalText(sal_True), 115 bAsianTypography(sal_True), 116 bJapaneseFind(sal_True), 117 bRuby(sal_True), 118 bChangeCaseMap(sal_True), 119 bDoubleLines(sal_True), 120 bEmphasisMarks(sal_True), 121 bVerticalCallOut(sal_True), 122 bROCJKFont(CFG_READONLY_DEFAULT), 123 bROVerticalText(CFG_READONLY_DEFAULT), 124 bROAsianTypography(CFG_READONLY_DEFAULT), 125 bROJapaneseFind(CFG_READONLY_DEFAULT), 126 bRORuby(CFG_READONLY_DEFAULT), 127 bROChangeCaseMap(CFG_READONLY_DEFAULT), 128 bRODoubleLines(CFG_READONLY_DEFAULT), 129 bROEmphasisMarks(CFG_READONLY_DEFAULT), 130 bROVerticalCallOut(CFG_READONLY_DEFAULT) 131 { 132 } 133 /*-- 10.04.01 12:41:57--------------------------------------------------- 134 135 -----------------------------------------------------------------------*/ 136 SvtCJKOptions_Impl::~SvtCJKOptions_Impl() 137 { 138 } 139 /* -----------------------------20.04.01 14:34-------------------------------- 140 141 ---------------------------------------------------------------------------*/ 142 void SvtCJKOptions_Impl::SetAll(sal_Bool bSet) 143 { 144 if ( 145 !bROCJKFont && 146 !bROVerticalText && 147 !bROAsianTypography && 148 !bROJapaneseFind && 149 !bRORuby && 150 !bROChangeCaseMap && 151 !bRODoubleLines && 152 !bROEmphasisMarks && 153 !bROVerticalCallOut 154 ) 155 { 156 bCJKFont=bSet; 157 bVerticalText=bSet; 158 bAsianTypography=bSet; 159 bJapaneseFind=bSet; 160 bRuby=bSet; 161 bChangeCaseMap=bSet; 162 bDoubleLines=bSet; 163 bEmphasisMarks=bSet; 164 bVerticalCallOut=bSet; 165 166 SetModified(); 167 Commit(); 168 NotifyListeners(0); 169 } 170 } 171 /*-- 10.04.01 12:41:56--------------------------------------------------- 172 173 -----------------------------------------------------------------------*/ 174 void SvtCJKOptions_Impl::Load() 175 { 176 Sequence<OUString> &rPropertyNames = PropertyNames::get(); 177 if(!rPropertyNames.getLength()) 178 { 179 rPropertyNames.realloc(9); 180 OUString* pNames = rPropertyNames.getArray(); 181 182 pNames[0] = C2U("CJKFont"); 183 pNames[1] = C2U("VerticalText"); 184 pNames[2] = C2U("AsianTypography"); 185 pNames[3] = C2U("JapaneseFind"); 186 pNames[4] = C2U("Ruby"); 187 pNames[5] = C2U("ChangeCaseMap"); 188 pNames[6] = C2U("DoubleLines"); 189 pNames[7] = C2U("EmphasisMarks"); 190 pNames[8] = C2U("VerticalCallOut"); 191 192 EnableNotification( rPropertyNames ); 193 } 194 Sequence< Any > aValues = GetProperties(rPropertyNames); 195 Sequence< sal_Bool > aROStates = GetReadOnlyStates(rPropertyNames); 196 const Any* pValues = aValues.getConstArray(); 197 const sal_Bool* pROStates = aROStates.getConstArray(); 198 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" ); 199 DBG_ASSERT( aROStates.getLength() == rPropertyNames.getLength(), "GetReadOnlyStates failed" ); 200 if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() ) 201 { 202 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ ) 203 { 204 if( pValues[nProp].hasValue() ) 205 { 206 sal_Bool bValue = *(sal_Bool*)pValues[nProp].getValue(); 207 switch ( nProp ) 208 { 209 case 0: { bCJKFont = bValue; bROCJKFont = pROStates[nProp]; } break; 210 case 1: { bVerticalText = bValue; bROVerticalText = pROStates[nProp]; } break; 211 case 2: { bAsianTypography = bValue; bROAsianTypography = pROStates[nProp]; } break; 212 case 3: { bJapaneseFind = bValue; bROJapaneseFind = pROStates[nProp]; } break; 213 case 4: { bRuby = bValue; bRORuby = pROStates[nProp]; } break; 214 case 5: { bChangeCaseMap = bValue; bROChangeCaseMap = pROStates[nProp]; } break; 215 case 6: { bDoubleLines = bValue; bRODoubleLines = pROStates[nProp]; } break; 216 case 7: { bEmphasisMarks = bValue; bROEmphasisMarks = pROStates[nProp]; } break; 217 case 8: { bVerticalCallOut = bValue; bROVerticalCallOut = pROStates[nProp]; } break; 218 } 219 } 220 } 221 } 222 223 SvtSystemLanguageOptions aSystemLocaleSettings; 224 LanguageType eSystemLanguage = aSystemLocaleSettings.GetWin16SystemLanguage(); 225 sal_uInt16 nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage ); 226 227 sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM); 228 if ( !bCJKFont && (( nScriptType & SCRIPTTYPE_ASIAN )|| 229 ((eSystemLanguage != LANGUAGE_SYSTEM) && ( nWinScript & SCRIPTTYPE_ASIAN )))) 230 { 231 SetAll(sal_True); 232 } 233 bIsLoaded = sal_True; 234 } 235 /*-- 10.04.01 12:41:57--------------------------------------------------- 236 237 -----------------------------------------------------------------------*/ 238 void SvtCJKOptions_Impl::Notify( const Sequence< OUString >& ) 239 { 240 Load(); 241 NotifyListeners(0); 242 } 243 /*-- 10.04.01 12:41:57--------------------------------------------------- 244 245 -----------------------------------------------------------------------*/ 246 void SvtCJKOptions_Impl::Commit() 247 { 248 Sequence<OUString> &rPropertyNames = PropertyNames::get(); 249 OUString* pOrgNames = rPropertyNames.getArray(); 250 sal_Int32 nOrgCount = rPropertyNames.getLength(); 251 252 Sequence< OUString > aNames(nOrgCount); 253 Sequence< Any > aValues(nOrgCount); 254 255 OUString* pNames = aNames.getArray(); 256 Any* pValues = aValues.getArray(); 257 sal_Int32 nRealCount = 0; 258 259 const Type& rType = ::getBooleanCppuType(); 260 for(int nProp = 0; nProp < nOrgCount; nProp++) 261 { 262 switch(nProp) 263 { 264 case 0: 265 { 266 if (!bROCJKFont) 267 { 268 pNames[nRealCount] = pOrgNames[nProp]; 269 pValues[nRealCount].setValue(&bCJKFont, rType); 270 ++nRealCount; 271 } 272 } 273 break; 274 275 case 1: 276 { 277 if (!bROVerticalText) 278 { 279 pNames[nRealCount] = pOrgNames[nProp]; 280 pValues[nRealCount].setValue(&bVerticalText, rType); 281 ++nRealCount; 282 } 283 } 284 break; 285 286 case 2: 287 { 288 if (!bROAsianTypography) 289 { 290 pNames[nRealCount] = pOrgNames[nProp]; 291 pValues[nRealCount].setValue(&bAsianTypography, rType); 292 ++nRealCount; 293 } 294 } 295 break; 296 297 case 3: 298 { 299 if (!bROJapaneseFind) 300 { 301 pNames[nRealCount] = pOrgNames[nProp]; 302 pValues[nRealCount].setValue(&bJapaneseFind, rType); 303 ++nRealCount; 304 } 305 } 306 break; 307 308 case 4: 309 { 310 if (!bRORuby) 311 { 312 pNames[nRealCount] = pOrgNames[nProp]; 313 pValues[nRealCount].setValue(&bRuby, rType); 314 ++nRealCount; 315 } 316 } 317 break; 318 319 case 5: 320 { 321 if (!bROChangeCaseMap) 322 { 323 pNames[nRealCount] = pOrgNames[nProp]; 324 pValues[nRealCount].setValue(&bChangeCaseMap, rType); 325 ++nRealCount; 326 } 327 } 328 break; 329 330 case 6: 331 { 332 if (!bRODoubleLines) 333 { 334 pNames[nRealCount] = pOrgNames[nProp]; 335 pValues[nRealCount].setValue(&bDoubleLines, rType); 336 ++nRealCount; 337 } 338 } 339 break; 340 341 case 7: 342 { 343 if (!bROEmphasisMarks) 344 { 345 pNames[nRealCount] = pOrgNames[nProp]; 346 pValues[nRealCount].setValue(&bEmphasisMarks, rType); 347 ++nRealCount; 348 } 349 } 350 break; 351 352 case 8: 353 { 354 if (!bROVerticalCallOut) 355 { 356 pNames[nRealCount] = pOrgNames[nProp]; 357 pValues[nRealCount].setValue(&bVerticalCallOut, rType); 358 ++nRealCount; 359 } 360 } 361 break; 362 } 363 } 364 aNames.realloc(nRealCount); 365 aValues.realloc(nRealCount); 366 PutProperties(aNames, aValues); 367 } 368 /*-- 13.02.2003 12:12--------------------------------------------------- 369 370 -----------------------------------------------------------------------*/ 371 sal_Bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption) const 372 { 373 sal_Bool bReadOnly = CFG_READONLY_DEFAULT; 374 switch(eOption) 375 { 376 case SvtCJKOptions::E_CJKFONT : bReadOnly = bROCJKFont; break; 377 case SvtCJKOptions::E_VERTICALTEXT : bReadOnly = bROVerticalText; break; 378 case SvtCJKOptions::E_ASIANTYPOGRAPHY : bReadOnly = bROAsianTypography; break; 379 case SvtCJKOptions::E_JAPANESEFIND : bReadOnly = bROJapaneseFind; break; 380 case SvtCJKOptions::E_RUBY : bReadOnly = bRORuby; break; 381 case SvtCJKOptions::E_CHANGECASEMAP : bReadOnly = bROChangeCaseMap; break; 382 case SvtCJKOptions::E_DOUBLELINES : bReadOnly = bRODoubleLines; break; 383 case SvtCJKOptions::E_EMPHASISMARKS : bReadOnly = bROEmphasisMarks; break; 384 case SvtCJKOptions::E_VERTICALCALLOUT : bReadOnly = bROVerticalCallOut; break; 385 case SvtCJKOptions::E_ALL : if (bROCJKFont || bROVerticalText || bROAsianTypography || bROJapaneseFind || bRORuby || bROChangeCaseMap || bRODoubleLines || bROEmphasisMarks || bROVerticalCallOut) 386 bReadOnly = sal_True; 387 break; 388 } 389 return bReadOnly; 390 } 391 392 // global ---------------------------------------------------------------- 393 394 static SvtCJKOptions_Impl* pCJKOptions = NULL; 395 static sal_Int32 nCJKRefCount = 0; 396 namespace { struct CJKMutex : public rtl::Static< ::osl::Mutex , CJKMutex >{}; } 397 398 399 // class SvtCJKOptions -------------------------------------------------- 400 401 SvtCJKOptions::SvtCJKOptions(sal_Bool bDontLoad) 402 { 403 // Global access, must be guarded (multithreading) 404 ::osl::MutexGuard aGuard( CJKMutex::get() ); 405 if ( !pCJKOptions ) 406 { 407 pCJKOptions = new SvtCJKOptions_Impl; 408 ItemHolder2::holdConfigItem(E_CJKOPTIONS); 409 } 410 if( !bDontLoad && !pCJKOptions->IsLoaded()) 411 pCJKOptions->Load(); 412 413 ++nCJKRefCount; 414 pImp = pCJKOptions; 415 } 416 417 // ----------------------------------------------------------------------- 418 419 SvtCJKOptions::~SvtCJKOptions() 420 { 421 // Global access, must be guarded (multithreading) 422 ::osl::MutexGuard aGuard( CJKMutex::get() ); 423 if ( !--nCJKRefCount ) 424 DELETEZ( pCJKOptions ); 425 } 426 // ----------------------------------------------------------------------- 427 sal_Bool SvtCJKOptions::IsCJKFontEnabled() const 428 { 429 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 430 return pCJKOptions->IsCJKFontEnabled(); 431 } 432 // ----------------------------------------------------------------------- 433 sal_Bool SvtCJKOptions::IsVerticalTextEnabled() const 434 { 435 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 436 return pCJKOptions->IsVerticalTextEnabled(); 437 } 438 // ----------------------------------------------------------------------- 439 sal_Bool SvtCJKOptions::IsAsianTypographyEnabled() const 440 { 441 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 442 return pCJKOptions->IsAsianTypographyEnabled(); 443 } 444 // ----------------------------------------------------------------------- 445 sal_Bool SvtCJKOptions::IsJapaneseFindEnabled() const 446 { 447 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 448 return pCJKOptions->IsJapaneseFindEnabled(); 449 } 450 // ----------------------------------------------------------------------- 451 sal_Bool SvtCJKOptions::IsRubyEnabled() const 452 { 453 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 454 return pCJKOptions->IsRubyEnabled(); 455 } 456 // ----------------------------------------------------------------------- 457 sal_Bool SvtCJKOptions::IsChangeCaseMapEnabled() const 458 { 459 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 460 return pCJKOptions->IsChangeCaseMapEnabled(); 461 } 462 // ----------------------------------------------------------------------- 463 sal_Bool SvtCJKOptions::IsDoubleLinesEnabled() const 464 { 465 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 466 return pCJKOptions->IsDoubleLinesEnabled(); 467 } 468 // ----------------------------------------------------------------------- 469 sal_Bool SvtCJKOptions::IsEmphasisMarksEnabled() const 470 { 471 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 472 return pCJKOptions->IsEmphasisMarksEnabled(); 473 } 474 // ----------------------------------------------------------------------- 475 sal_Bool SvtCJKOptions::IsVerticalCallOutEnabled() const 476 { 477 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 478 return pCJKOptions->IsVerticalCallOutEnabled(); 479 } 480 /*-- 20.04.01 14:32:04--------------------------------------------------- 481 482 -----------------------------------------------------------------------*/ 483 void SvtCJKOptions::SetAll(sal_Bool bSet) 484 { 485 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 486 pCJKOptions->SetAll(bSet); 487 } 488 /*-- 20.04.01 14:32:06--------------------------------------------------- 489 490 -----------------------------------------------------------------------*/ 491 sal_Bool SvtCJKOptions::IsAnyEnabled() const 492 { 493 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 494 return pCJKOptions->IsAnyEnabled(); 495 } 496 /*-- 13.02.2003 12:11--------------------------------------------------- 497 498 -----------------------------------------------------------------------*/ 499 sal_Bool SvtCJKOptions::IsReadOnly(EOption eOption) const 500 { 501 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); 502 return pCJKOptions->IsReadOnly(eOption); 503 } 504 505