Update ooo320-m1
[ooovba.git] / svtools / source / config / ctloptions.cxx
blob7814e2e7cf22d4c78ec3b4271d3ee9a8a91cfcbd
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: ctloptions.cxx,v $
10 * $Revision: 1.18.140.1 $
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/ctloptions.hxx>
41 #include <svtools/languageoptions.hxx>
42 #include <i18npool/mslangid.hxx>
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 <vos/mutex.hxx>
49 #include <svtools/smplhint.hxx>
50 #include <vcl/svapp.hxx>
51 #include <rtl/instance.hxx>
53 #include <itemholder2.hxx>
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::uno;
58 #define ASCII_STR(s) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
59 #define CFG_READONLY_DEFAULT sal_False
61 // SvtCJKOptions_Impl ----------------------------------------------------------
63 class SvtCTLOptions_Impl : public utl::ConfigItem, public SfxBroadcaster
65 private:
66 sal_Bool m_bIsLoaded;
67 sal_Bool m_bCTLFontEnabled;
68 sal_Bool m_bCTLSequenceChecking;
69 sal_Bool m_bCTLRestricted;
70 sal_Bool m_bCTLTypeAndReplace;
71 SvtCTLOptions::CursorMovement m_eCTLCursorMovement;
72 SvtCTLOptions::TextNumerals m_eCTLTextNumerals;
74 sal_Bool m_bROCTLFontEnabled;
75 sal_Bool m_bROCTLSequenceChecking;
76 sal_Bool m_bROCTLRestricted;
77 sal_Bool m_bROCTLTypeAndReplace;
78 sal_Bool m_bROCTLCursorMovement;
79 sal_Bool m_bROCTLTextNumerals;
81 public:
82 SvtCTLOptions_Impl();
83 ~SvtCTLOptions_Impl();
85 virtual void Notify( const Sequence< rtl::OUString >& _aPropertyNames );
86 virtual void Commit();
87 void Load();
89 sal_Bool IsLoaded() { return m_bIsLoaded; }
90 void SetCTLFontEnabled( sal_Bool _bEnabled );
91 sal_Bool IsCTLFontEnabled() const { return m_bCTLFontEnabled; }
93 void SetCTLSequenceChecking( sal_Bool _bEnabled );
94 sal_Bool IsCTLSequenceChecking() const { return m_bCTLSequenceChecking;}
96 void SetCTLSequenceCheckingRestricted( sal_Bool _bEnable );
97 sal_Bool IsCTLSequenceCheckingRestricted( void ) const { return m_bCTLRestricted; }
99 void SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable );
100 sal_Bool IsCTLSequenceCheckingTypeAndReplace() const { return m_bCTLTypeAndReplace; }
102 void SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement );
103 SvtCTLOptions::CursorMovement
104 GetCTLCursorMovement() const { return m_eCTLCursorMovement; }
106 void SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals );
107 SvtCTLOptions::TextNumerals
108 GetCTLTextNumerals() const { return m_eCTLTextNumerals; }
110 sal_Bool IsReadOnly(SvtCTLOptions::EOption eOption) const;
112 //------------------------------------------------------------------------------
113 namespace
115 struct PropertyNames
116 : public rtl::Static< Sequence< rtl::OUString >, PropertyNames > {};
118 //------------------------------------------------------------------------------
119 sal_Bool SvtCTLOptions_Impl::IsReadOnly(SvtCTLOptions::EOption eOption) const
121 sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
122 switch(eOption)
124 case SvtCTLOptions::E_CTLFONT : bReadOnly = m_bROCTLFontEnabled ; break;
125 case SvtCTLOptions::E_CTLSEQUENCECHECKING : bReadOnly = m_bROCTLSequenceChecking ; break;
126 case SvtCTLOptions::E_CTLCURSORMOVEMENT : bReadOnly = m_bROCTLCursorMovement ; break;
127 case SvtCTLOptions::E_CTLTEXTNUMERALS : bReadOnly = m_bROCTLTextNumerals ; break;
128 case SvtCTLOptions::E_CTLSEQUENCECHECKINGRESTRICTED: bReadOnly = m_bROCTLRestricted ; break;
129 case SvtCTLOptions::E_CTLSEQUENCECHECKINGTYPEANDREPLACE: bReadOnly = m_bROCTLTypeAndReplace; break;
130 default: DBG_ERROR( "SvtCTLOptions_Impl::IsReadOnly() - invalid option" );
132 return bReadOnly;
134 //------------------------------------------------------------------------------
135 SvtCTLOptions_Impl::SvtCTLOptions_Impl() :
137 utl::ConfigItem( ASCII_STR("Office.Common/I18N/CTL") ),
139 m_bIsLoaded ( sal_False ),
140 m_bCTLFontEnabled ( sal_False ),
141 m_bCTLSequenceChecking ( sal_False ),
142 m_bCTLRestricted ( sal_False ),
143 m_eCTLCursorMovement ( SvtCTLOptions::MOVEMENT_LOGICAL ),
144 m_eCTLTextNumerals ( SvtCTLOptions::NUMERALS_ARABIC ),
146 m_bROCTLFontEnabled ( CFG_READONLY_DEFAULT ),
147 m_bROCTLSequenceChecking( CFG_READONLY_DEFAULT ),
148 m_bROCTLRestricted ( CFG_READONLY_DEFAULT ),
149 m_bROCTLCursorMovement ( CFG_READONLY_DEFAULT ),
150 m_bROCTLTextNumerals ( CFG_READONLY_DEFAULT )
153 //------------------------------------------------------------------------------
154 SvtCTLOptions_Impl::~SvtCTLOptions_Impl()
156 if ( IsModified() == sal_True )
157 Commit();
159 // -----------------------------------------------------------------------------
160 void SvtCTLOptions_Impl::Notify( const Sequence< rtl::OUString >& )
162 Load();
163 Broadcast(SfxSimpleHint(SFX_HINT_CTL_SETTINGS_CHANGED));
165 // -----------------------------------------------------------------------------
166 void SvtCTLOptions_Impl::Commit()
168 Sequence< rtl::OUString > &rPropertyNames = PropertyNames::get();
169 rtl::OUString* pOrgNames = rPropertyNames.getArray();
170 sal_Int32 nOrgCount = rPropertyNames.getLength();
172 Sequence< rtl::OUString > aNames( nOrgCount );
173 Sequence< Any > aValues( nOrgCount );
175 rtl::OUString* pNames = aNames.getArray();
176 Any* pValues = aValues.getArray();
177 sal_Int32 nRealCount = 0;
179 const uno::Type& rType = ::getBooleanCppuType();
181 for ( int nProp = 0; nProp < nOrgCount; nProp++ )
183 switch ( nProp )
185 case 0:
187 if (!m_bROCTLFontEnabled)
189 pNames[nRealCount] = pOrgNames[nProp];
190 pValues[nRealCount].setValue( &m_bCTLFontEnabled, rType );
191 ++nRealCount;
194 break;
196 case 1:
198 if (!m_bROCTLSequenceChecking)
200 pNames[nRealCount] = pOrgNames[nProp];
201 pValues[nRealCount].setValue( &m_bCTLSequenceChecking, rType );
202 ++nRealCount;
205 break;
207 case 2:
209 if (!m_bROCTLCursorMovement)
211 pNames[nRealCount] = pOrgNames[nProp];
212 pValues[nRealCount] <<= (sal_Int32)m_eCTLCursorMovement;
213 ++nRealCount;
216 break;
218 case 3:
220 if (!m_bROCTLTextNumerals)
222 pNames[nRealCount] = pOrgNames[nProp];
223 pValues[nRealCount] <<= (sal_Int32)m_eCTLTextNumerals;
224 ++nRealCount;
227 break;
229 case 4:
231 if (!m_bROCTLRestricted)
233 pNames[nRealCount] = pOrgNames[nProp];
234 pValues[nRealCount].setValue( &m_bCTLRestricted, rType );
235 ++nRealCount;
238 break;
239 case 5:
241 if(!m_bROCTLTypeAndReplace)
243 pNames[nRealCount] = pOrgNames[nProp];
244 pValues[nRealCount].setValue( &m_bCTLTypeAndReplace, rType );
245 ++nRealCount;
248 break;
251 aNames.realloc(nRealCount);
252 aValues.realloc(nRealCount);
253 PutProperties( aNames, aValues );
254 //broadcast changes
255 Broadcast(SfxSimpleHint(SFX_HINT_CTL_SETTINGS_CHANGED));
257 // -----------------------------------------------------------------------------
258 void SvtCTLOptions_Impl::Load()
260 Sequence< rtl::OUString >& rPropertyNames = PropertyNames::get();
261 if ( !rPropertyNames.getLength() )
263 rPropertyNames.realloc(6);
264 rtl::OUString* pNames = rPropertyNames.getArray();
265 pNames[0] = ASCII_STR("CTLFont");
266 pNames[1] = ASCII_STR("CTLSequenceChecking");
267 pNames[2] = ASCII_STR("CTLCursorMovement");
268 pNames[3] = ASCII_STR("CTLTextNumerals");
269 pNames[4] = ASCII_STR("CTLSequenceCheckingRestricted");
270 pNames[5] = ASCII_STR("CTLSequenceCheckingTypeAndReplace");
271 EnableNotification( rPropertyNames );
273 Sequence< Any > aValues = GetProperties( rPropertyNames );
274 Sequence< sal_Bool > aROStates = GetReadOnlyStates( rPropertyNames );
275 const Any* pValues = aValues.getConstArray();
276 const sal_Bool* pROStates = aROStates.getConstArray();
277 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
278 DBG_ASSERT( aROStates.getLength() == rPropertyNames.getLength(), "GetReadOnlyStates failed" );
279 if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() )
281 sal_Bool bValue = sal_False;
282 sal_Int32 nValue = 0;
284 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
286 if ( pValues[nProp].hasValue() )
288 if ( pValues[nProp] >>= bValue )
290 switch ( nProp )
292 case 0: { m_bCTLFontEnabled = bValue; m_bROCTLFontEnabled = pROStates[nProp]; } break;
293 case 1: { m_bCTLSequenceChecking = bValue; m_bROCTLSequenceChecking = pROStates[nProp]; } break;
294 case 4: { m_bCTLRestricted = bValue; m_bROCTLRestricted = pROStates[nProp]; } break;
295 case 5: { m_bCTLTypeAndReplace = bValue; m_bROCTLTypeAndReplace = pROStates[nProp]; } break;
298 else if ( pValues[nProp] >>= nValue )
300 switch ( nProp )
302 case 2: { m_eCTLCursorMovement = (SvtCTLOptions::CursorMovement)nValue; m_bROCTLCursorMovement = pROStates[nProp]; } break;
303 case 3: { m_eCTLTextNumerals = (SvtCTLOptions::TextNumerals)nValue; m_bROCTLTextNumerals = pROStates[nProp]; } break;
309 sal_uInt16 nType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM);
310 SvtSystemLanguageOptions aSystemLocaleSettings;
311 LanguageType eSystemLanguage = aSystemLocaleSettings.GetWin16SystemLanguage();
312 sal_uInt16 nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage );
313 if( !m_bCTLFontEnabled && (( nType & SCRIPTTYPE_COMPLEX ) ||
314 ((eSystemLanguage != LANGUAGE_SYSTEM) && ( nWinScript & SCRIPTTYPE_COMPLEX ))) )
316 m_bCTLFontEnabled = sal_True;
317 sal_uInt16 nLanguage = Application::GetSettings().GetLanguage();
318 //enable sequence checking for the appropriate languages
319 m_bCTLSequenceChecking = m_bCTLRestricted = m_bCTLTypeAndReplace =
320 (MsLangId::needsSequenceChecking( nLanguage) ||
321 MsLangId::needsSequenceChecking( eSystemLanguage));
322 Commit();
324 m_bIsLoaded = sal_True;
326 //------------------------------------------------------------------------------
327 void SvtCTLOptions_Impl::SetCTLFontEnabled( sal_Bool _bEnabled )
329 if(!m_bROCTLFontEnabled && m_bCTLFontEnabled != _bEnabled)
331 m_bCTLFontEnabled = _bEnabled;
332 SetModified();
335 //------------------------------------------------------------------------------
336 void SvtCTLOptions_Impl::SetCTLSequenceChecking( sal_Bool _bEnabled )
338 if(!m_bROCTLSequenceChecking && m_bCTLSequenceChecking != _bEnabled)
340 SetModified();
341 m_bCTLSequenceChecking = _bEnabled;
344 //------------------------------------------------------------------------------
345 void SvtCTLOptions_Impl::SetCTLSequenceCheckingRestricted( sal_Bool _bEnabled )
347 if(!m_bROCTLRestricted && m_bCTLRestricted != _bEnabled)
349 SetModified();
350 m_bCTLRestricted = _bEnabled;
353 //------------------------------------------------------------------------------
354 void SvtCTLOptions_Impl::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnabled )
356 if(!m_bROCTLTypeAndReplace && m_bCTLTypeAndReplace != _bEnabled)
358 SetModified();
359 m_bCTLTypeAndReplace = _bEnabled;
362 //------------------------------------------------------------------------------
363 void SvtCTLOptions_Impl::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement )
365 if (!m_bROCTLCursorMovement && m_eCTLCursorMovement != _eMovement )
367 SetModified();
368 m_eCTLCursorMovement = _eMovement;
371 //------------------------------------------------------------------------------
372 void SvtCTLOptions_Impl::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals )
374 if (!m_bROCTLTextNumerals && m_eCTLTextNumerals != _eNumerals )
376 SetModified();
377 m_eCTLTextNumerals = _eNumerals;
380 // global ----------------------------------------------------------------
382 static SvtCTLOptions_Impl* pCTLOptions = NULL;
383 static sal_Int32 nCTLRefCount = 0;
384 namespace { struct CTLMutex : public rtl::Static< osl::Mutex, CTLMutex > {}; }
386 // class SvtCTLOptions --------------------------------------------------
388 SvtCTLOptions::SvtCTLOptions( sal_Bool bDontLoad )
390 // Global access, must be guarded (multithreading)
391 ::osl::MutexGuard aGuard( CTLMutex::get() );
392 if ( !pCTLOptions )
394 pCTLOptions = new SvtCTLOptions_Impl;
395 ItemHolder2::holdConfigItem(E_CTLOPTIONS);
397 if( !bDontLoad && !pCTLOptions->IsLoaded() )
398 pCTLOptions->Load();
400 ++nCTLRefCount;
401 m_pImp = pCTLOptions;
402 StartListening( *m_pImp);
405 // -----------------------------------------------------------------------
407 SvtCTLOptions::~SvtCTLOptions()
409 // Global access, must be guarded (multithreading)
410 ::osl::MutexGuard aGuard( CTLMutex::get() );
412 if ( !--nCTLRefCount )
413 DELETEZ( pCTLOptions );
415 // -----------------------------------------------------------------------------
416 void SvtCTLOptions::SetCTLFontEnabled( sal_Bool _bEnabled )
418 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
419 pCTLOptions->SetCTLFontEnabled( _bEnabled );
421 // -----------------------------------------------------------------------------
422 sal_Bool SvtCTLOptions::IsCTLFontEnabled() const
424 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
425 return pCTLOptions->IsCTLFontEnabled();
427 // -----------------------------------------------------------------------------
428 void SvtCTLOptions::SetCTLSequenceChecking( sal_Bool _bEnabled )
430 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
431 pCTLOptions->SetCTLSequenceChecking(_bEnabled);
433 // -----------------------------------------------------------------------------
434 sal_Bool SvtCTLOptions::IsCTLSequenceChecking() const
436 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
437 return pCTLOptions->IsCTLSequenceChecking();
439 // -----------------------------------------------------------------------------
440 void SvtCTLOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable )
442 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
443 pCTLOptions->SetCTLSequenceCheckingRestricted(_bEnable);
445 // -----------------------------------------------------------------------------
446 sal_Bool SvtCTLOptions::IsCTLSequenceCheckingRestricted( void ) const
448 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
449 return pCTLOptions->IsCTLSequenceCheckingRestricted();
451 // -----------------------------------------------------------------------------
452 void SvtCTLOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable )
454 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
455 pCTLOptions->SetCTLSequenceCheckingTypeAndReplace(_bEnable);
457 // -----------------------------------------------------------------------------
458 sal_Bool SvtCTLOptions::IsCTLSequenceCheckingTypeAndReplace() const
460 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
461 return pCTLOptions->IsCTLSequenceCheckingTypeAndReplace();
463 // -----------------------------------------------------------------------------
464 void SvtCTLOptions::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement )
466 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
467 pCTLOptions->SetCTLCursorMovement( _eMovement );
469 // -----------------------------------------------------------------------------
470 SvtCTLOptions::CursorMovement SvtCTLOptions::GetCTLCursorMovement() const
472 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
473 return pCTLOptions->GetCTLCursorMovement();
475 // -----------------------------------------------------------------------------
476 void SvtCTLOptions::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals )
478 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
479 pCTLOptions->SetCTLTextNumerals( _eNumerals );
481 // -----------------------------------------------------------------------------
482 SvtCTLOptions::TextNumerals SvtCTLOptions::GetCTLTextNumerals() const
484 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
485 return pCTLOptions->GetCTLTextNumerals();
487 // -----------------------------------------------------------------------------
488 sal_Bool SvtCTLOptions::IsReadOnly(EOption eOption) const
490 DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" );
491 return pCTLOptions->IsReadOnly(eOption);
493 /* -----------------30.04.2003 10:40-----------------
495 --------------------------------------------------*/
496 void SvtCTLOptions::Notify( SfxBroadcaster&, const SfxHint& rHint )
498 vos::OGuard aVclGuard( Application::GetSolarMutex() );
499 Broadcast( rHint );
502 // -----------------------------------------------------------------------------