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