2010-10-14 08:27:31 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-07-11 09:51:50 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2006-09-17 13:23:53 +00:00
2009-10-06 07:38:24 +02:00
# include <unotools/fontoptions.hxx>
2000-11-13 08:48:47 +00:00
# include <unotools/configmgr.hxx>
# include <unotools/configitem.hxx>
# include <tools/debug.hxx>
# include <com/sun/star/uno/Any.hxx>
# include <com/sun/star/uno/Sequence.hxx>
2011-04-03 21:34:16 +01:00
# include <rtl/instance.hxx>
2004-11-15 16:19:52 +00:00
# include "itemholder1.hxx"
2014-04-06 18:58:39 +03:00
using namespace : : utl ;
using namespace : : osl ;
using namespace : : com : : sun : : star : : uno ;
2000-11-13 08:48:47 +00:00
2013-03-10 20:44:01 +01:00
# define ROOTNODE_FONT OUString("Office.Common / Font")
2000-11-13 08:48:47 +00:00
2014-12-18 13:38:27 +01:00
# define PROPERTYNAME_REPLACEMENTTABLE "Substitution / Replacement"
# define PROPERTYNAME_FONTHISTORY "View / History"
# define PROPERTYNAME_FONTWYSIWYG "View / ShowFontBoxWYSIWYG"
2000-11-13 08:48:47 +00:00
# define PROPERTYHANDLE_REPLACEMENTTABLE 0
# define PROPERTYHANDLE_FONTHISTORY 1
# define PROPERTYHANDLE_FONTWYSIWYG 2
# define PROPERTYCOUNT 3
class SvtFontOptions_Impl : public ConfigItem
{
public :
SvtFontOptions_Impl ( ) ;
2014-04-01 19:18:35 +02:00
virtual ~ SvtFontOptions_Impl ( ) ;
2000-11-13 08:48:47 +00:00
2014-02-25 22:46:10 +01:00
/*-****************************************************************************************************
2000-11-13 08:48:47 +00:00
@ short called for notify of configmanager
@ descr These method is called from the ConfigManager before application ends or from the
PropertyChangeListener if the sub tree broadcasts changes . You must update your
internal values .
@ seealso baseclass ConfigItem
@ param " seqPropertyNames " is the list of properties which should be updated .
*/ /*-*****************************************************************************************************/
2014-03-26 16:37:00 +01:00
virtual void Notify ( const Sequence < OUString > & seqPropertyNames ) SAL_OVERRIDE ;
2000-11-13 08:48:47 +00:00
2014-02-25 22:46:10 +01:00
/*-****************************************************************************************************
2000-11-13 08:48:47 +00:00
@ short access method to get internal values
2015-02-18 21:58:05 +01:00
@ descr These method give us a chance to regulate access to our internal values .
2000-11-13 08:48:47 +00:00
It ' s not used in the moment - but it ' s possible for the feature !
*/ /*-*****************************************************************************************************/
2014-06-09 10:09:42 +02:00
bool IsFontHistoryEnabled ( ) const { return m_bFontHistory ; }
2014-04-06 18:58:39 +03:00
void EnableFontHistory ( bool bState ) ;
2000-11-13 08:48:47 +00:00
2014-06-09 10:09:42 +02:00
bool IsFontWYSIWYGEnabled ( ) const { return m_bFontWYSIWYG ; }
2014-04-06 18:58:39 +03:00
void EnableFontWYSIWYG ( bool bState ) ;
2000-11-13 08:48:47 +00:00
private :
2015-03-11 16:14:47 +01:00
virtual void ImplCommit ( ) SAL_OVERRIDE ;
2014-02-25 22:46:10 +01:00
/*-****************************************************************************************************
2014-04-06 20:25:20 +03:00
@ short return list of key names of our configuration management which represent oue module tree
2000-11-13 08:48:47 +00:00
@ descr These methods return a static const list of key names . We need it to get needed values from our
configuration management .
@ return A list of needed configuration keys is returned .
*/ /*-*****************************************************************************************************/
static Sequence < OUString > impl_GetPropertyNames ( ) ;
private :
2014-04-06 18:58:39 +03:00
bool m_bReplacementTable ;
bool m_bFontHistory ;
bool m_bFontWYSIWYG ;
2000-11-13 08:48:47 +00:00
} ;
// constructor
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
SvtFontOptions_Impl : : SvtFontOptions_Impl ( )
// Init baseclasses first
: ConfigItem ( ROOTNODE_FONT )
// Init member then.
2014-02-19 12:30:34 +01:00
, m_bReplacementTable ( false )
, m_bFontHistory ( false )
, m_bFontWYSIWYG ( false )
2000-11-13 08:48:47 +00:00
{
// Use our static list of configuration keys to get his values.
Sequence < OUString > seqNames = impl_GetPropertyNames ( ) ;
Sequence < Any > seqValues = GetProperties ( seqNames ) ;
// Safe impossible cases.
// We need values from ALL configuration keys.
// Follow assignment use order of values in relation to our list of key names!
DBG_ASSERT ( ! ( seqNames . getLength ( ) ! = seqValues . getLength ( ) ) , " SvtFontOptions_Impl::SvtFontOptions_Impl() \n I miss some values of configuration keys! \n " ) ;
2014-04-06 20:25:20 +03:00
// Copy values from list in right order to our internal member.
2000-11-13 08:48:47 +00:00
sal_Int32 nPropertyCount = seqValues . getLength ( ) ;
for ( sal_Int32 nProperty = 0 ; nProperty < nPropertyCount ; + + nProperty )
{
// Safe impossible cases.
// Check any for valid value.
2014-01-21 17:47:16 +01:00
DBG_ASSERT ( seqValues [ nProperty ] . hasValue ( ) , " SvtFontOptions_Impl::SvtFontOptions_Impl() \n Invalid property value detected! \n " ) ;
2000-11-13 08:48:47 +00:00
switch ( nProperty )
{
case PROPERTYHANDLE_REPLACEMENTTABLE : {
DBG_ASSERT ( ! ( seqValues [ nProperty ] . getValueTypeClass ( ) ! = TypeClass_BOOLEAN ) , " SvtFontOptions_Impl::SvtFontOptions_Impl() \n Who has changed the value type of \" Office.Common \\ Font \\ Substitution \\ Replacement \" ? " ) ;
seqValues [ nProperty ] > > = m_bReplacementTable ;
}
break ;
case PROPERTYHANDLE_FONTHISTORY : {
DBG_ASSERT ( ! ( seqValues [ nProperty ] . getValueTypeClass ( ) ! = TypeClass_BOOLEAN ) , " SvtFontOptions_Impl::SvtFontOptions_Impl() \n Who has changed the value type of \" Office.Common \\ Font \\ View \\ History \" ? " ) ;
seqValues [ nProperty ] > > = m_bFontHistory ;
}
break ;
case PROPERTYHANDLE_FONTWYSIWYG : {
DBG_ASSERT ( ! ( seqValues [ nProperty ] . getValueTypeClass ( ) ! = TypeClass_BOOLEAN ) , " SvtFontOptions_Impl::SvtFontOptions_Impl() \n Who has changed the value type of \" Office.Common \\ Font \\ View \\ ShowFontBoxWYSIWYG \" ? " ) ;
seqValues [ nProperty ] > > = m_bFontWYSIWYG ;
}
break ;
}
}
2014-04-06 20:25:20 +03:00
// Enable notification mechanism of our baseclass.
// We need it to get information about changes outside these class on our used configuration keys!
2000-11-13 08:48:47 +00:00
EnableNotification ( seqNames ) ;
}
// destructor
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
SvtFontOptions_Impl : : ~ SvtFontOptions_Impl ( )
{
2015-03-11 16:39:24 +01:00
assert ( ! IsModified ( ) ) ; // should have been committed
2000-11-13 08:48:47 +00:00
}
// public method
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
void SvtFontOptions_Impl : : Notify ( const Sequence < OUString > & seqPropertyNames )
{
// Use given list of updated properties to get his values from configuration directly!
Sequence < Any > seqValues = GetProperties ( seqPropertyNames ) ;
// Safe impossible cases.
// We need values from ALL notified configuration keys.
DBG_ASSERT ( ! ( seqPropertyNames . getLength ( ) ! = seqValues . getLength ( ) ) , " SvtFontOptions_Impl::Notify() \n I miss some values of configuration keys! \n " ) ;
// Step over list of property names and get right value from coreesponding value list to set it on internal members!
sal_Int32 nCount = seqPropertyNames . getLength ( ) ;
for ( sal_Int32 nProperty = 0 ; nProperty < nCount ; + + nProperty )
{
if ( seqPropertyNames [ nProperty ] = = PROPERTYNAME_REPLACEMENTTABLE )
{
DBG_ASSERT ( ! ( seqValues [ nProperty ] . getValueTypeClass ( ) ! = TypeClass_BOOLEAN ) , " SvtFontOptions_Impl::Notify() \n Who has changed the value type of \" Office.Common \\ Font \\ Substitution \\ Replacement \" ? " ) ;
seqValues [ nProperty ] > > = m_bReplacementTable ;
}
else
if ( seqPropertyNames [ nProperty ] = = PROPERTYNAME_FONTHISTORY )
{
DBG_ASSERT ( ! ( seqValues [ nProperty ] . getValueTypeClass ( ) ! = TypeClass_BOOLEAN ) , " SvtFontOptions_Impl::Notify() \n Who has changed the value type of \" Office.Common \\ Font \\ View \\ History \" ? " ) ;
seqValues [ nProperty ] > > = m_bFontHistory ;
}
else
if ( seqPropertyNames [ nProperty ] = = PROPERTYNAME_FONTWYSIWYG )
{
DBG_ASSERT ( ! ( seqValues [ nProperty ] . getValueTypeClass ( ) ! = TypeClass_BOOLEAN ) , " SvtFontOptions_Impl::Notify() \n Who has changed the value type of \" Office.Common \\ Font \\ View \\ ShowFontBoxWYSIWYG \" ? " ) ;
seqValues [ nProperty ] > > = m_bFontWYSIWYG ;
}
2003-04-15 16:51:45 +00:00
# if OSL_DEBUG_LEVEL > 1
2013-03-22 22:11:49 +08:00
else DBG_ASSERT ( sal_False , " SvtFontOptions_Impl::Notify() \ nUnknown property detected . . . I can ' t handle these ! \ n " ) ;
2000-11-13 08:48:47 +00:00
# endif
}
}
// public method
2014-02-25 22:46:10 +01:00
2015-03-11 16:14:47 +01:00
void SvtFontOptions_Impl : : ImplCommit ( )
2000-11-13 08:48:47 +00:00
{
// Get names of supported properties, create a list for values and copy current values to it.
Sequence < OUString > seqNames = impl_GetPropertyNames ( ) ;
sal_Int32 nCount = seqNames . getLength ( ) ;
Sequence < Any > seqValues ( nCount ) ;
for ( sal_Int32 nProperty = 0 ; nProperty < nCount ; + + nProperty )
{
switch ( nProperty )
{
case PROPERTYHANDLE_REPLACEMENTTABLE : {
seqValues [ nProperty ] < < = m_bReplacementTable ;
}
break ;
case PROPERTYHANDLE_FONTHISTORY : {
seqValues [ nProperty ] < < = m_bFontHistory ;
}
break ;
case PROPERTYHANDLE_FONTWYSIWYG : {
seqValues [ nProperty ] < < = m_bFontWYSIWYG ;
}
break ;
}
}
// Set properties in configuration.
PutProperties ( seqNames , seqValues ) ;
}
// public method
2014-02-25 22:46:10 +01:00
2014-02-19 12:30:34 +01:00
void SvtFontOptions_Impl : : EnableFontHistory ( bool bState )
2000-11-13 08:48:47 +00:00
{
m_bFontHistory = bState ;
SetModified ( ) ;
}
// public method
2014-02-25 22:46:10 +01:00
2014-02-19 12:30:34 +01:00
void SvtFontOptions_Impl : : EnableFontWYSIWYG ( bool bState )
2000-11-13 08:48:47 +00:00
{
m_bFontWYSIWYG = bState ;
SetModified ( ) ;
}
// private method
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
Sequence < OUString > SvtFontOptions_Impl : : impl_GetPropertyNames ( )
{
2011-06-01 09:23:41 +01:00
// Build list of configuration key names.
const OUString pProperties [ ] =
2000-11-13 08:48:47 +00:00
{
2014-12-18 20:45:06 -05:00
OUString ( PROPERTYNAME_REPLACEMENTTABLE ) ,
OUString ( PROPERTYNAME_FONTHISTORY ) ,
OUString ( PROPERTYNAME_FONTWYSIWYG ) ,
2000-11-13 08:48:47 +00:00
} ;
// Initialize return sequence with these list ...
2011-06-01 09:23:41 +01:00
const Sequence < OUString > seqPropertyNames ( pProperties , PROPERTYCOUNT ) ;
2000-11-13 08:48:47 +00:00
// ... and return it.
return seqPropertyNames ;
}
// initialize static member
// DON'T DO IT IN YOUR HEADER!
2013-04-15 04:49:39 +02:00
// see definition for further information
2014-02-25 22:46:10 +01:00
2014-04-06 18:58:39 +03:00
SvtFontOptions_Impl * SvtFontOptions : : m_pDataContainer = NULL ;
sal_Int32 SvtFontOptions : : m_nRefCount = 0 ;
2000-11-13 08:48:47 +00:00
// constructor
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
SvtFontOptions : : SvtFontOptions ( )
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard ( impl_GetOwnStaticMutex ( ) ) ;
2014-04-06 20:25:20 +03:00
// Increase our refcount ...
2000-11-13 08:48:47 +00:00
+ + m_nRefCount ;
2014-04-06 20:25:20 +03:00
// ... and initialize our data container only if it not already exist!
2000-11-13 08:48:47 +00:00
if ( m_pDataContainer = = NULL )
{
m_pDataContainer = new SvtFontOptions_Impl ;
2004-11-15 16:19:52 +00:00
2005-11-11 07:49:02 +00:00
ItemHolder1 : : holdConfigItem ( E_FONTOPTIONS ) ;
2000-11-13 08:48:47 +00:00
}
}
// destructor
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
SvtFontOptions : : ~ SvtFontOptions ( )
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard ( impl_GetOwnStaticMutex ( ) ) ;
2014-04-06 20:25:20 +03:00
// Decrease our refcount.
2000-11-13 08:48:47 +00:00
- - m_nRefCount ;
// If last instance was deleted ...
2014-04-06 20:25:20 +03:00
// we must destroy our static data container!
2000-11-13 08:48:47 +00:00
if ( m_nRefCount < = 0 )
{
delete m_pDataContainer ;
m_pDataContainer = NULL ;
}
}
// public method
2014-02-25 22:46:10 +01:00
2014-02-19 12:30:34 +01:00
bool SvtFontOptions : : IsFontHistoryEnabled ( ) const
2000-11-13 08:48:47 +00:00
{
MutexGuard aGuard ( impl_GetOwnStaticMutex ( ) ) ;
return m_pDataContainer - > IsFontHistoryEnabled ( ) ;
}
// public method
2014-02-25 22:46:10 +01:00
2014-02-19 12:30:34 +01:00
void SvtFontOptions : : EnableFontHistory ( bool bState )
2000-11-13 08:48:47 +00:00
{
MutexGuard aGuard ( impl_GetOwnStaticMutex ( ) ) ;
m_pDataContainer - > EnableFontHistory ( bState ) ;
}
// public method
2014-02-25 22:46:10 +01:00
2014-02-19 12:30:34 +01:00
bool SvtFontOptions : : IsFontWYSIWYGEnabled ( ) const
2000-11-13 08:48:47 +00:00
{
MutexGuard aGuard ( impl_GetOwnStaticMutex ( ) ) ;
return m_pDataContainer - > IsFontWYSIWYGEnabled ( ) ;
}
// public method
2014-02-25 22:46:10 +01:00
2014-02-19 12:30:34 +01:00
void SvtFontOptions : : EnableFontWYSIWYG ( bool bState )
2000-11-13 08:48:47 +00:00
{
MutexGuard aGuard ( impl_GetOwnStaticMutex ( ) ) ;
m_pDataContainer - > EnableFontWYSIWYG ( bState ) ;
}
2011-04-03 21:34:16 +01:00
namespace
{
class theFontOptionsMutex : public rtl : : Static < osl : : Mutex , theFontOptionsMutex > { } ;
}
2000-11-13 08:48:47 +00:00
// private method
2014-02-25 22:46:10 +01:00
2000-11-13 08:48:47 +00:00
Mutex & SvtFontOptions : : impl_GetOwnStaticMutex ( )
{
2011-04-03 21:34:16 +01:00
return theFontOptionsMutex : : get ( ) ;
2000-11-13 08:48:47 +00:00
}
2010-10-14 08:27:31 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */