merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / cjkoptions.cxx
blob0419e5ec7c6d5b4f6e11cffd30c45e860811461c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cjkoptions.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #ifdef SVL_DLLIMPLEMENTATION
35 #undef SVL_DLLIMPLEMENTATION
36 #endif
37 #define SVT_DLLIMPLEMENTATION
39 #include <svtools/cjkoptions.hxx>
41 #include <svtools/languageoptions.hxx>
42 #include <i18npool/lang.h>
43 #include <unotools/configitem.hxx>
44 #include <tools/debug.hxx>
45 #include <com/sun/star/uno/Any.h>
46 #include <com/sun/star/uno/Sequence.hxx>
47 #include <osl/mutex.hxx>
48 #include <rtl/instance.hxx>
50 #include <itemholder2.hxx>
52 using namespace ::com::sun::star::uno;
53 using namespace ::rtl;
55 #define C2U(cChar) OUString::createFromAscii(cChar)
56 #define CFG_READONLY_DEFAULT sal_False
57 /* -----------------------------10.04.01 12:39--------------------------------
59 ---------------------------------------------------------------------------*/
60 class SvtCJKOptions_Impl : public utl::ConfigItem
62 sal_Bool bIsLoaded;
63 sal_Bool bCJKFont;
64 sal_Bool bVerticalText;
65 sal_Bool bAsianTypography;
66 sal_Bool bJapaneseFind;
67 sal_Bool bRuby;
68 sal_Bool bChangeCaseMap;
69 sal_Bool bDoubleLines;
70 sal_Bool bEmphasisMarks;
71 sal_Bool bVerticalCallOut;
73 sal_Bool bROCJKFont;
74 sal_Bool bROVerticalText;
75 sal_Bool bROAsianTypography;
76 sal_Bool bROJapaneseFind;
77 sal_Bool bRORuby;
78 sal_Bool bROChangeCaseMap;
79 sal_Bool bRODoubleLines;
80 sal_Bool bROEmphasisMarks;
81 sal_Bool bROVerticalCallOut;
83 public:
84 SvtCJKOptions_Impl();
85 ~SvtCJKOptions_Impl();
87 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& rPropertyNames );
88 virtual void Commit();
89 void Load();
91 sal_Bool IsLoaded() { return bIsLoaded; }
93 sal_Bool IsCJKFontEnabled() const { return bCJKFont; }
94 sal_Bool IsVerticalTextEnabled() const { return bVerticalText; }
95 sal_Bool IsAsianTypographyEnabled() const { return bAsianTypography; }
96 sal_Bool IsJapaneseFindEnabled() const { return bJapaneseFind; }
97 sal_Bool IsRubyEnabled() const { return bRuby; }
98 sal_Bool IsChangeCaseMapEnabled() const { return bChangeCaseMap; }
99 sal_Bool IsDoubleLinesEnabled() const { return bDoubleLines; }
100 sal_Bool IsEmphasisMarksEnabled() const { return bEmphasisMarks; }
101 sal_Bool IsVerticalCallOutEnabled() const { return bVerticalCallOut; }
103 sal_Bool IsAnyEnabled() const {
104 return bCJKFont||bVerticalText||bAsianTypography||bJapaneseFind||
105 bRuby||bChangeCaseMap||bDoubleLines||bEmphasisMarks||bVerticalCallOut; }
106 void SetAll(sal_Bool bSet);
107 sal_Bool IsReadOnly(SvtCJKOptions::EOption eOption) const;
109 /*-- 10.04.01 12:41:57---------------------------------------------------
111 -----------------------------------------------------------------------*/
112 namespace
114 struct PropertyNames
115 : public rtl::Static< Sequence<OUString>, PropertyNames > {};
118 SvtCJKOptions_Impl::SvtCJKOptions_Impl() :
119 utl::ConfigItem(C2U("Office.Common/I18N/CJK")),
120 bIsLoaded(sal_False),
121 bCJKFont(sal_True),
122 bVerticalText(sal_True),
123 bAsianTypography(sal_True),
124 bJapaneseFind(sal_True),
125 bRuby(sal_True),
126 bChangeCaseMap(sal_True),
127 bDoubleLines(sal_True),
128 bEmphasisMarks(sal_True),
129 bVerticalCallOut(sal_True),
130 bROCJKFont(CFG_READONLY_DEFAULT),
131 bROVerticalText(CFG_READONLY_DEFAULT),
132 bROAsianTypography(CFG_READONLY_DEFAULT),
133 bROJapaneseFind(CFG_READONLY_DEFAULT),
134 bRORuby(CFG_READONLY_DEFAULT),
135 bROChangeCaseMap(CFG_READONLY_DEFAULT),
136 bRODoubleLines(CFG_READONLY_DEFAULT),
137 bROEmphasisMarks(CFG_READONLY_DEFAULT),
138 bROVerticalCallOut(CFG_READONLY_DEFAULT)
141 /*-- 10.04.01 12:41:57---------------------------------------------------
143 -----------------------------------------------------------------------*/
144 SvtCJKOptions_Impl::~SvtCJKOptions_Impl()
147 /* -----------------------------20.04.01 14:34--------------------------------
149 ---------------------------------------------------------------------------*/
150 void SvtCJKOptions_Impl::SetAll(sal_Bool bSet)
152 if (
153 !bROCJKFont &&
154 !bROVerticalText &&
155 !bROAsianTypography &&
156 !bROJapaneseFind &&
157 !bRORuby &&
158 !bROChangeCaseMap &&
159 !bRODoubleLines &&
160 !bROEmphasisMarks &&
161 !bROVerticalCallOut
164 bCJKFont=bSet;
165 bVerticalText=bSet;
166 bAsianTypography=bSet;
167 bJapaneseFind=bSet;
168 bRuby=bSet;
169 bChangeCaseMap=bSet;
170 bDoubleLines=bSet;
171 bEmphasisMarks=bSet;
172 bVerticalCallOut=bSet;
174 SetModified();
175 Commit();
178 /*-- 10.04.01 12:41:56---------------------------------------------------
180 -----------------------------------------------------------------------*/
181 void SvtCJKOptions_Impl::Load()
183 Sequence<OUString> &rPropertyNames = PropertyNames::get();
184 if(!rPropertyNames.getLength())
186 rPropertyNames.realloc(9);
187 OUString* pNames = rPropertyNames.getArray();
189 pNames[0] = C2U("CJKFont");
190 pNames[1] = C2U("VerticalText");
191 pNames[2] = C2U("AsianTypography");
192 pNames[3] = C2U("JapaneseFind");
193 pNames[4] = C2U("Ruby");
194 pNames[5] = C2U("ChangeCaseMap");
195 pNames[6] = C2U("DoubleLines");
196 pNames[7] = C2U("EmphasisMarks");
197 pNames[8] = C2U("VerticalCallOut");
199 EnableNotification( rPropertyNames );
201 Sequence< Any > aValues = GetProperties(rPropertyNames);
202 Sequence< sal_Bool > aROStates = GetReadOnlyStates(rPropertyNames);
203 const Any* pValues = aValues.getConstArray();
204 const sal_Bool* pROStates = aROStates.getConstArray();
205 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
206 DBG_ASSERT( aROStates.getLength() == rPropertyNames.getLength(), "GetReadOnlyStates failed" );
207 if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() )
209 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
211 if( pValues[nProp].hasValue() )
213 sal_Bool bValue = *(sal_Bool*)pValues[nProp].getValue();
214 switch ( nProp )
216 case 0: { bCJKFont = bValue; bROCJKFont = pROStates[nProp]; } break;
217 case 1: { bVerticalText = bValue; bROVerticalText = pROStates[nProp]; } break;
218 case 2: { bAsianTypography = bValue; bROAsianTypography = pROStates[nProp]; } break;
219 case 3: { bJapaneseFind = bValue; bROJapaneseFind = pROStates[nProp]; } break;
220 case 4: { bRuby = bValue; bRORuby = pROStates[nProp]; } break;
221 case 5: { bChangeCaseMap = bValue; bROChangeCaseMap = pROStates[nProp]; } break;
222 case 6: { bDoubleLines = bValue; bRODoubleLines = pROStates[nProp]; } break;
223 case 7: { bEmphasisMarks = bValue; bROEmphasisMarks = pROStates[nProp]; } break;
224 case 8: { bVerticalCallOut = bValue; bROVerticalCallOut = pROStates[nProp]; } break;
230 SvtSystemLanguageOptions aSystemLocaleSettings;
231 LanguageType eSystemLanguage = aSystemLocaleSettings.GetWin16SystemLanguage();
232 sal_uInt16 nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage );
234 sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM);
235 if ( !bCJKFont && (( nScriptType & SCRIPTTYPE_ASIAN )||
236 ((eSystemLanguage != LANGUAGE_SYSTEM) && ( nWinScript & SCRIPTTYPE_ASIAN ))))
238 SetAll(sal_True);
240 bIsLoaded = sal_True;
242 /*-- 10.04.01 12:41:57---------------------------------------------------
244 -----------------------------------------------------------------------*/
245 void SvtCJKOptions_Impl::Notify( const Sequence< OUString >& )
247 Load();
249 /*-- 10.04.01 12:41:57---------------------------------------------------
251 -----------------------------------------------------------------------*/
252 void SvtCJKOptions_Impl::Commit()
254 Sequence<OUString> &rPropertyNames = PropertyNames::get();
255 OUString* pOrgNames = rPropertyNames.getArray();
256 sal_Int32 nOrgCount = rPropertyNames.getLength();
258 Sequence< OUString > aNames(nOrgCount);
259 Sequence< Any > aValues(nOrgCount);
261 OUString* pNames = aNames.getArray();
262 Any* pValues = aValues.getArray();
263 sal_Int32 nRealCount = 0;
265 const Type& rType = ::getBooleanCppuType();
266 for(int nProp = 0; nProp < nOrgCount; nProp++)
268 switch(nProp)
270 case 0:
272 if (!bROCJKFont)
274 pNames[nRealCount] = pOrgNames[nProp];
275 pValues[nRealCount].setValue(&bCJKFont, rType);
276 ++nRealCount;
279 break;
281 case 1:
283 if (!bROVerticalText)
285 pNames[nRealCount] = pOrgNames[nProp];
286 pValues[nRealCount].setValue(&bVerticalText, rType);
287 ++nRealCount;
290 break;
292 case 2:
294 if (!bROAsianTypography)
296 pNames[nRealCount] = pOrgNames[nProp];
297 pValues[nRealCount].setValue(&bAsianTypography, rType);
298 ++nRealCount;
301 break;
303 case 3:
305 if (!bROJapaneseFind)
307 pNames[nRealCount] = pOrgNames[nProp];
308 pValues[nRealCount].setValue(&bJapaneseFind, rType);
309 ++nRealCount;
312 break;
314 case 4:
316 if (!bRORuby)
318 pNames[nRealCount] = pOrgNames[nProp];
319 pValues[nRealCount].setValue(&bRuby, rType);
320 ++nRealCount;
323 break;
325 case 5:
327 if (!bROChangeCaseMap)
329 pNames[nRealCount] = pOrgNames[nProp];
330 pValues[nRealCount].setValue(&bChangeCaseMap, rType);
331 ++nRealCount;
334 break;
336 case 6:
338 if (!bRODoubleLines)
340 pNames[nRealCount] = pOrgNames[nProp];
341 pValues[nRealCount].setValue(&bDoubleLines, rType);
342 ++nRealCount;
345 break;
347 case 7:
349 if (!bROEmphasisMarks)
351 pNames[nRealCount] = pOrgNames[nProp];
352 pValues[nRealCount].setValue(&bEmphasisMarks, rType);
353 ++nRealCount;
356 break;
358 case 8:
360 if (!bROVerticalCallOut)
362 pNames[nRealCount] = pOrgNames[nProp];
363 pValues[nRealCount].setValue(&bVerticalCallOut, rType);
364 ++nRealCount;
367 break;
370 aNames.realloc(nRealCount);
371 aValues.realloc(nRealCount);
372 PutProperties(aNames, aValues);
374 /*-- 13.02.2003 12:12---------------------------------------------------
376 -----------------------------------------------------------------------*/
377 sal_Bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption) const
379 sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
380 switch(eOption)
382 case SvtCJKOptions::E_CJKFONT : bReadOnly = bROCJKFont; break;
383 case SvtCJKOptions::E_VERTICALTEXT : bReadOnly = bROVerticalText; break;
384 case SvtCJKOptions::E_ASIANTYPOGRAPHY : bReadOnly = bROAsianTypography; break;
385 case SvtCJKOptions::E_JAPANESEFIND : bReadOnly = bROJapaneseFind; break;
386 case SvtCJKOptions::E_RUBY : bReadOnly = bRORuby; break;
387 case SvtCJKOptions::E_CHANGECASEMAP : bReadOnly = bROChangeCaseMap; break;
388 case SvtCJKOptions::E_DOUBLELINES : bReadOnly = bRODoubleLines; break;
389 case SvtCJKOptions::E_EMPHASISMARKS : bReadOnly = bROEmphasisMarks; break;
390 case SvtCJKOptions::E_VERTICALCALLOUT : bReadOnly = bROVerticalCallOut; break;
391 case SvtCJKOptions::E_ALL : if (bROCJKFont || bROVerticalText || bROAsianTypography || bROJapaneseFind || bRORuby || bROChangeCaseMap || bRODoubleLines || bROEmphasisMarks || bROVerticalCallOut)
392 bReadOnly = sal_True;
393 break;
395 return bReadOnly;
398 // global ----------------------------------------------------------------
400 static SvtCJKOptions_Impl* pCJKOptions = NULL;
401 static sal_Int32 nCJKRefCount = 0;
402 namespace { struct CJKMutex : public rtl::Static< ::osl::Mutex , CJKMutex >{}; }
405 // class SvtCJKOptions --------------------------------------------------
407 SvtCJKOptions::SvtCJKOptions(sal_Bool bDontLoad)
409 // Global access, must be guarded (multithreading)
410 ::osl::MutexGuard aGuard( CJKMutex::get() );
411 if ( !pCJKOptions )
413 pCJKOptions = new SvtCJKOptions_Impl;
414 ItemHolder2::holdConfigItem(E_CJKOPTIONS);
416 if( !bDontLoad && !pCJKOptions->IsLoaded())
417 pCJKOptions->Load();
419 ++nCJKRefCount;
420 pImp = pCJKOptions;
423 // -----------------------------------------------------------------------
425 SvtCJKOptions::~SvtCJKOptions()
427 // Global access, must be guarded (multithreading)
428 ::osl::MutexGuard aGuard( CJKMutex::get() );
429 if ( !--nCJKRefCount )
430 DELETEZ( pCJKOptions );
432 // -----------------------------------------------------------------------
433 sal_Bool SvtCJKOptions::IsCJKFontEnabled() const
435 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
436 return pCJKOptions->IsCJKFontEnabled();
438 // -----------------------------------------------------------------------
439 sal_Bool SvtCJKOptions::IsVerticalTextEnabled() const
441 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
442 return pCJKOptions->IsVerticalTextEnabled();
444 // -----------------------------------------------------------------------
445 sal_Bool SvtCJKOptions::IsAsianTypographyEnabled() const
447 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
448 return pCJKOptions->IsAsianTypographyEnabled();
450 // -----------------------------------------------------------------------
451 sal_Bool SvtCJKOptions::IsJapaneseFindEnabled() const
453 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
454 return pCJKOptions->IsJapaneseFindEnabled();
456 // -----------------------------------------------------------------------
457 sal_Bool SvtCJKOptions::IsRubyEnabled() const
459 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
460 return pCJKOptions->IsRubyEnabled();
462 // -----------------------------------------------------------------------
463 sal_Bool SvtCJKOptions::IsChangeCaseMapEnabled() const
465 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
466 return pCJKOptions->IsChangeCaseMapEnabled();
468 // -----------------------------------------------------------------------
469 sal_Bool SvtCJKOptions::IsDoubleLinesEnabled() const
471 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
472 return pCJKOptions->IsDoubleLinesEnabled();
474 // -----------------------------------------------------------------------
475 sal_Bool SvtCJKOptions::IsEmphasisMarksEnabled() const
477 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
478 return pCJKOptions->IsEmphasisMarksEnabled();
480 // -----------------------------------------------------------------------
481 sal_Bool SvtCJKOptions::IsVerticalCallOutEnabled() const
483 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
484 return pCJKOptions->IsVerticalCallOutEnabled();
486 /*-- 20.04.01 14:32:04---------------------------------------------------
488 -----------------------------------------------------------------------*/
489 void SvtCJKOptions::SetAll(sal_Bool bSet)
491 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
492 pCJKOptions->SetAll(bSet);
494 /*-- 20.04.01 14:32:06---------------------------------------------------
496 -----------------------------------------------------------------------*/
497 sal_Bool SvtCJKOptions::IsAnyEnabled() const
499 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
500 return pCJKOptions->IsAnyEnabled();
502 /*-- 13.02.2003 12:11---------------------------------------------------
504 -----------------------------------------------------------------------*/
505 sal_Bool SvtCJKOptions::IsReadOnly(EOption eOption) const
507 DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded");
508 return pCJKOptions->IsReadOnly(eOption);