1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontoptions.cxx,v $
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"
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
40 #include <svtools/fontoptions.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <unotools/configitem.hxx>
43 #include <tools/debug.hxx>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
47 #include <rtl/logfile.hxx>
48 #include "itemholder1.hxx"
50 //_________________________________________________________________________________________________________________
52 //_________________________________________________________________________________________________________________
54 using namespace ::utl
;
55 using namespace ::rtl
;
56 using namespace ::osl
;
57 using namespace ::com::sun::star::uno
;
59 //_________________________________________________________________________________________________________________
61 //_________________________________________________________________________________________________________________
63 #define ROOTNODE_FONT OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Font" ))
65 #define PROPERTYNAME_REPLACEMENTTABLE OUString(RTL_CONSTASCII_USTRINGPARAM("Substitution/Replacement" ))
66 #define PROPERTYNAME_FONTHISTORY OUString(RTL_CONSTASCII_USTRINGPARAM("View/History" ))
67 #define PROPERTYNAME_FONTWYSIWYG OUString(RTL_CONSTASCII_USTRINGPARAM("View/ShowFontBoxWYSIWYG" ))
69 #define PROPERTYHANDLE_REPLACEMENTTABLE 0
70 #define PROPERTYHANDLE_FONTHISTORY 1
71 #define PROPERTYHANDLE_FONTWYSIWYG 2
73 #define PROPERTYCOUNT 3
75 //_________________________________________________________________________________________________________________
76 // private declarations!
77 //_________________________________________________________________________________________________________________
79 class SvtFontOptions_Impl
: public ConfigItem
81 //-------------------------------------------------------------------------------------------------------------
83 //-------------------------------------------------------------------------------------------------------------
87 //---------------------------------------------------------------------------------------------------------
88 // constructor / destructor
89 //---------------------------------------------------------------------------------------------------------
91 SvtFontOptions_Impl();
92 ~SvtFontOptions_Impl();
94 //---------------------------------------------------------------------------------------------------------
95 // overloaded methods of baseclass
96 //---------------------------------------------------------------------------------------------------------
98 /*-****************************************************************************************************//**
99 @short called for notify of configmanager
100 @descr These method is called from the ConfigManager before application ends or from the
101 PropertyChangeListener if the sub tree broadcasts changes. You must update your
104 @seealso baseclass ConfigItem
106 @param "seqPropertyNames" is the list of properties which should be updated.
110 *//*-*****************************************************************************************************/
112 virtual void Notify( const Sequence
< OUString
>& seqPropertyNames
);
114 /*-****************************************************************************************************//**
115 @short write changes to configuration
116 @descr These method writes the changed values into the sub tree
117 and should always called in our destructor to guarantee consistency of config data.
119 @seealso baseclass ConfigItem
125 *//*-*****************************************************************************************************/
127 virtual void Commit();
129 //---------------------------------------------------------------------------------------------------------
131 //---------------------------------------------------------------------------------------------------------
133 /*-****************************************************************************************************//**
134 @short access method to get internal values
135 @descr These method give us a chance to regulate acces to ouer internal values.
136 It's not used in the moment - but it's possible for the feature!
144 *//*-*****************************************************************************************************/
146 sal_Bool
IsReplacementTableEnabled ( ) const ;
147 void EnableReplacementTable ( sal_Bool bState
) ;
149 sal_Bool
IsFontHistoryEnabled ( ) const ;
150 void EnableFontHistory ( sal_Bool bState
) ;
152 sal_Bool
IsFontWYSIWYGEnabled ( ) const ;
153 void EnableFontWYSIWYG ( sal_Bool bState
) ;
155 //-------------------------------------------------------------------------------------------------------------
157 //-------------------------------------------------------------------------------------------------------------
161 /*-****************************************************************************************************//**
162 @short return list of key names of ouer configuration management which represent oue module tree
163 @descr These methods return a static const list of key names. We need it to get needed values from our
164 configuration management.
169 @return A list of needed configuration keys is returned.
172 *//*-*****************************************************************************************************/
174 static Sequence
< OUString
> impl_GetPropertyNames();
176 //-------------------------------------------------------------------------------------------------------------
178 //-------------------------------------------------------------------------------------------------------------
182 sal_Bool m_bReplacementTable
;
183 sal_Bool m_bFontHistory
;
184 sal_Bool m_bFontWYSIWYG
;
187 //_________________________________________________________________________________________________________________
189 //_________________________________________________________________________________________________________________
191 //*****************************************************************************************************************
193 //*****************************************************************************************************************
194 SvtFontOptions_Impl::SvtFontOptions_Impl()
195 // Init baseclasses first
196 : ConfigItem ( ROOTNODE_FONT
)
198 , m_bReplacementTable ( sal_False
)
199 , m_bFontHistory ( sal_False
)
200 , m_bFontWYSIWYG ( sal_False
)
202 // Use our static list of configuration keys to get his values.
203 Sequence
< OUString
> seqNames
= impl_GetPropertyNames ( );
204 Sequence
< Any
> seqValues
= GetProperties ( seqNames
);
206 // Safe impossible cases.
207 // We need values from ALL configuration keys.
208 // Follow assignment use order of values in relation to our list of key names!
209 DBG_ASSERT( !(seqNames
.getLength()!=seqValues
.getLength()), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nI miss some values of configuration keys!\n" );
211 // Copy values from list in right order to ouer internal member.
212 sal_Int32 nPropertyCount
= seqValues
.getLength();
213 for( sal_Int32 nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
215 // Safe impossible cases.
216 // Check any for valid value.
217 DBG_ASSERT( !(seqValues
[nProperty
].hasValue()==sal_False
), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nInvalid property value detected!\n" );
220 case PROPERTYHANDLE_REPLACEMENTTABLE
: {
221 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nWho has changed the value type of \"Office.Common\\Font\\Substitution\\Replacement\"?" );
222 seqValues
[nProperty
] >>= m_bReplacementTable
;
225 case PROPERTYHANDLE_FONTHISTORY
: {
226 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nWho has changed the value type of \"Office.Common\\Font\\View\\History\"?" );
227 seqValues
[nProperty
] >>= m_bFontHistory
;
230 case PROPERTYHANDLE_FONTWYSIWYG
: {
231 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nWho has changed the value type of \"Office.Common\\Font\\View\\ShowFontBoxWYSIWYG\"?" );
232 seqValues
[nProperty
] >>= m_bFontWYSIWYG
;
238 // Enable notification mechanism of ouer baseclass.
239 // We need it to get information about changes outside these class on ouer used configuration keys!
240 EnableNotification( seqNames
);
243 //*****************************************************************************************************************
245 //*****************************************************************************************************************
246 SvtFontOptions_Impl::~SvtFontOptions_Impl()
248 // We must save our current values .. if user forget it!
249 if( IsModified() == sal_True
)
255 //*****************************************************************************************************************
257 //*****************************************************************************************************************
258 void SvtFontOptions_Impl::Notify( const Sequence
< OUString
>& seqPropertyNames
)
260 // Use given list of updated properties to get his values from configuration directly!
261 Sequence
< Any
> seqValues
= GetProperties( seqPropertyNames
);
262 // Safe impossible cases.
263 // We need values from ALL notified configuration keys.
264 DBG_ASSERT( !(seqPropertyNames
.getLength()!=seqValues
.getLength()), "SvtFontOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
265 // Step over list of property names and get right value from coreesponding value list to set it on internal members!
266 sal_Int32 nCount
= seqPropertyNames
.getLength();
267 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
269 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_REPLACEMENTTABLE
)
271 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtFontOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Font\\Substitution\\Replacement\"?" );
272 seqValues
[nProperty
] >>= m_bReplacementTable
;
275 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_FONTHISTORY
)
277 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtFontOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Font\\View\\History\"?" );
278 seqValues
[nProperty
] >>= m_bFontHistory
;
281 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_FONTWYSIWYG
)
283 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtFontOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Font\\View\\ShowFontBoxWYSIWYG\"?" );
284 seqValues
[nProperty
] >>= m_bFontWYSIWYG
;
286 #if OSL_DEBUG_LEVEL > 1
287 else DBG_ASSERT( sal_False
, "SvtFontOptions_Impl::Notify()\nUnkown property detected ... I can't handle these!\n" );
292 //*****************************************************************************************************************
294 //*****************************************************************************************************************
295 void SvtFontOptions_Impl::Commit()
297 // Get names of supported properties, create a list for values and copy current values to it.
298 Sequence
< OUString
> seqNames
= impl_GetPropertyNames();
299 sal_Int32 nCount
= seqNames
.getLength();
300 Sequence
< Any
> seqValues ( nCount
);
301 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
305 case PROPERTYHANDLE_REPLACEMENTTABLE
: {
306 seqValues
[nProperty
] <<= m_bReplacementTable
;
309 case PROPERTYHANDLE_FONTHISTORY
: {
310 seqValues
[nProperty
] <<= m_bFontHistory
;
313 case PROPERTYHANDLE_FONTWYSIWYG
: {
314 seqValues
[nProperty
] <<= m_bFontWYSIWYG
;
319 // Set properties in configuration.
320 PutProperties( seqNames
, seqValues
);
323 //*****************************************************************************************************************
325 //*****************************************************************************************************************
326 sal_Bool
SvtFontOptions_Impl::IsReplacementTableEnabled() const
328 return m_bReplacementTable
;
331 //*****************************************************************************************************************
333 //*****************************************************************************************************************
334 void SvtFontOptions_Impl::EnableReplacementTable( sal_Bool bState
)
336 m_bReplacementTable
= bState
;
340 //*****************************************************************************************************************
342 //*****************************************************************************************************************
343 sal_Bool
SvtFontOptions_Impl::IsFontHistoryEnabled() const
345 return m_bFontHistory
;
348 //*****************************************************************************************************************
350 //*****************************************************************************************************************
351 void SvtFontOptions_Impl::EnableFontHistory( sal_Bool bState
)
353 m_bFontHistory
= bState
;
357 //*****************************************************************************************************************
359 //*****************************************************************************************************************
360 sal_Bool
SvtFontOptions_Impl::IsFontWYSIWYGEnabled() const
362 return m_bFontWYSIWYG
;
365 //*****************************************************************************************************************
367 //*****************************************************************************************************************
368 void SvtFontOptions_Impl::EnableFontWYSIWYG( sal_Bool bState
)
370 m_bFontWYSIWYG
= bState
;
374 //*****************************************************************************************************************
376 //*****************************************************************************************************************
377 Sequence
< OUString
> SvtFontOptions_Impl::impl_GetPropertyNames()
379 // Build static list of configuration key names.
380 static const OUString pProperties
[] =
382 PROPERTYNAME_REPLACEMENTTABLE
,
383 PROPERTYNAME_FONTHISTORY
,
384 PROPERTYNAME_FONTWYSIWYG
,
386 // Initialize return sequence with these list ...
387 static const Sequence
< OUString
> seqPropertyNames( pProperties
, PROPERTYCOUNT
);
388 // ... and return it.
389 return seqPropertyNames
;
392 //*****************************************************************************************************************
393 // initialize static member
394 // DON'T DO IT IN YOUR HEADER!
395 // see definition for further informations
396 //*****************************************************************************************************************
397 SvtFontOptions_Impl
* SvtFontOptions::m_pDataContainer
= NULL
;
398 sal_Int32
SvtFontOptions::m_nRefCount
= 0 ;
400 //*****************************************************************************************************************
402 //*****************************************************************************************************************
403 SvtFontOptions::SvtFontOptions()
405 // Global access, must be guarded (multithreading!).
406 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
407 // Increase ouer refcount ...
409 // ... and initialize ouer data container only if it not already exist!
410 if( m_pDataContainer
== NULL
)
412 RTL_LOGFILE_CONTEXT(aLog
, "svtools ( ??? ) ::SvtFontOptions_Impl::ctor()");
413 m_pDataContainer
= new SvtFontOptions_Impl
;
415 ItemHolder1::holdConfigItem(E_FONTOPTIONS
);
419 //*****************************************************************************************************************
421 //*****************************************************************************************************************
422 SvtFontOptions::~SvtFontOptions()
424 // Global access, must be guarded (multithreading!)
425 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
426 // Decrease ouer refcount.
428 // If last instance was deleted ...
429 // we must destroy ouer static data container!
430 if( m_nRefCount
<= 0 )
432 delete m_pDataContainer
;
433 m_pDataContainer
= NULL
;
437 //*****************************************************************************************************************
439 //*****************************************************************************************************************
440 sal_Bool
SvtFontOptions::IsReplacementTableEnabled() const
442 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
443 return m_pDataContainer
->IsReplacementTableEnabled();
446 //*****************************************************************************************************************
448 //*****************************************************************************************************************
449 void SvtFontOptions::EnableReplacementTable( sal_Bool bState
)
451 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
452 m_pDataContainer
->EnableReplacementTable( bState
);
455 //*****************************************************************************************************************
457 //*****************************************************************************************************************
458 sal_Bool
SvtFontOptions::IsFontHistoryEnabled() const
460 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
461 return m_pDataContainer
->IsFontHistoryEnabled();
464 //*****************************************************************************************************************
466 //*****************************************************************************************************************
467 void SvtFontOptions::EnableFontHistory( sal_Bool bState
)
469 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
470 m_pDataContainer
->EnableFontHistory( bState
);
473 //*****************************************************************************************************************
475 //*****************************************************************************************************************
476 sal_Bool
SvtFontOptions::IsFontWYSIWYGEnabled() const
478 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
479 return m_pDataContainer
->IsFontWYSIWYGEnabled();
482 //*****************************************************************************************************************
484 //*****************************************************************************************************************
485 void SvtFontOptions::EnableFontWYSIWYG( sal_Bool bState
)
487 MutexGuard
aGuard( impl_GetOwnStaticMutex() );
488 m_pDataContainer
->EnableFontWYSIWYG( bState
);
491 //*****************************************************************************************************************
493 //*****************************************************************************************************************
494 Mutex
& SvtFontOptions::impl_GetOwnStaticMutex()
496 // Initialize static mutex only for one time!
497 static Mutex
* pMutex
= NULL
;
498 // If these method first called (Mutex not already exist!) ...
501 // ... we must create a new one. Protect follow code with the global mutex -
502 // It must be - we create a static variable!
503 MutexGuard
aGuard( Mutex::getGlobalMutex() );
504 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
507 // Create the new mutex and set it for return on static variable.
512 // Return new created or already existing mutex object.