2002-08-30 08:53:22 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* $RCSfile: sourceviewconfig.cxx,v $
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-11-11 07:54:14 +00:00
|
|
|
* $Revision: 1.4 $
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-11-11 07:54:14 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2005-11-11 08:54:14 $
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2005-09-08 13:46:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
#ifndef _SVTOOLS_SOURCEVIEWCONFIG_HXX
|
|
|
|
#include <sourceviewconfig.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _UTL_CONFIGITEM_HXX_
|
|
|
|
#include <unotools/configitem.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
2004-06-25 16:25:12 +00:00
|
|
|
#ifndef INCLUDED_RTL_INSTANCE_HXX
|
|
|
|
#include <rtl/instance.hxx>
|
|
|
|
#endif
|
2002-08-30 08:53:22 +00:00
|
|
|
#ifndef _SFXSMPLHINT_HXX
|
|
|
|
#include "smplhint.hxx"
|
|
|
|
#endif
|
|
|
|
|
2005-11-11 07:54:14 +00:00
|
|
|
#include <itemholder1.hxx>
|
|
|
|
|
2002-08-30 08:53:22 +00:00
|
|
|
using namespace utl;
|
|
|
|
using namespace rtl;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
namespace svt
|
|
|
|
{
|
|
|
|
class SourceViewConfig_Impl : public utl::ConfigItem, public SfxBroadcaster
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
OUString m_sFontName;
|
|
|
|
sal_Int16 m_nFontHeight;
|
|
|
|
sal_Bool m_bProportionalFontOnly;
|
|
|
|
|
|
|
|
void Load();
|
|
|
|
|
|
|
|
static Sequence< OUString > GetPropertyNames();
|
|
|
|
|
|
|
|
public:
|
|
|
|
SourceViewConfig_Impl();
|
|
|
|
~SourceViewConfig_Impl();
|
|
|
|
|
|
|
|
virtual void Notify( const Sequence< rtl::OUString >& aPropertyNames );
|
|
|
|
virtual void Commit();
|
|
|
|
|
|
|
|
const rtl::OUString& GetFontName() const
|
|
|
|
{return m_sFontName;}
|
|
|
|
void SetFontName(const rtl::OUString& rName)
|
|
|
|
{
|
|
|
|
if(rName != m_sFontName)
|
|
|
|
{
|
|
|
|
m_sFontName = rName;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int16 GetFontHeight() const
|
|
|
|
{return m_nFontHeight;}
|
|
|
|
void SetFontHeight(sal_Int16 nHeight)
|
|
|
|
{
|
|
|
|
if(m_nFontHeight != nHeight)
|
|
|
|
{
|
|
|
|
m_nFontHeight = nHeight;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool IsShowProportionalFontsOnly() const
|
|
|
|
{return m_bProportionalFontOnly;}
|
|
|
|
void SetShowProportionalFontsOnly(sal_Bool bSet)
|
|
|
|
{
|
|
|
|
if(m_bProportionalFontOnly != bSet)
|
|
|
|
{
|
|
|
|
m_bProportionalFontOnly = bSet;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// initialization of static members --------------------------------------
|
|
|
|
SourceViewConfig_Impl* SourceViewConfig::m_pImplConfig = 0;
|
|
|
|
sal_Int32 SourceViewConfig::m_nRefCount = 0;
|
2004-06-25 16:25:12 +00:00
|
|
|
namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
|
2002-08-30 08:53:22 +00:00
|
|
|
/* -----------------------------28.08.2002 16:45------------------------------
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
SourceViewConfig_Impl::SourceViewConfig_Impl() :
|
|
|
|
ConfigItem(OUString::createFromAscii("Office.Common/Font/SourceViewFont")),
|
|
|
|
m_nFontHeight(12),
|
|
|
|
m_bProportionalFontOnly(sal_False)
|
|
|
|
{
|
|
|
|
Load();
|
|
|
|
}
|
|
|
|
/* -----------------------------28.08.2002 16:45------------------------------
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
SourceViewConfig_Impl::~SourceViewConfig_Impl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* -----------------------------28.08.2002 16:25------------------------------
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
Sequence< OUString > SourceViewConfig_Impl::GetPropertyNames()
|
|
|
|
{
|
|
|
|
//this list needs exactly to mach the enum PropertyNameIndex
|
|
|
|
static const char* aPropNames[] =
|
|
|
|
{
|
|
|
|
"FontName" // 0
|
|
|
|
,"FontHeight" // 1
|
|
|
|
,"NonProportionalFontsOnly" // 2
|
|
|
|
};
|
|
|
|
const int nCount = sizeof( aPropNames ) / sizeof( const char* );
|
|
|
|
Sequence< OUString > aNames( nCount );
|
|
|
|
OUString* pNames = aNames.getArray();
|
|
|
|
for ( int i = 0; i < nCount; i++ )
|
|
|
|
pNames[i] = OUString::createFromAscii( aPropNames[i] );
|
|
|
|
|
|
|
|
return aNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-- 28.08.2002 16:37:59---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig_Impl::Load()
|
|
|
|
{
|
|
|
|
Sequence< OUString > aNames = GetPropertyNames();
|
|
|
|
Sequence< Any > aValues = GetProperties( aNames );
|
|
|
|
EnableNotification( aNames );
|
|
|
|
const Any* pValues = aValues.getConstArray();
|
|
|
|
DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
|
|
|
|
if ( aValues.getLength() == aNames.getLength() )
|
|
|
|
{
|
|
|
|
for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
|
|
|
|
{
|
|
|
|
if ( pValues[nProp].hasValue() )
|
|
|
|
{
|
|
|
|
switch( nProp )
|
|
|
|
{
|
|
|
|
case 0: pValues[nProp] >>= m_sFontName; break;
|
|
|
|
case 1: pValues[nProp] >>= m_nFontHeight; break;
|
|
|
|
case 2: pValues[nProp] >>= m_bProportionalFontOnly; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:38:00---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig_Impl::Notify( const Sequence< OUString >& aPropertyNames )
|
|
|
|
{
|
|
|
|
Load();
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:38:00---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig_Impl::Commit()
|
|
|
|
{
|
|
|
|
ClearModified();
|
|
|
|
Sequence< OUString > aNames = GetPropertyNames();
|
|
|
|
OUString* pNames = aNames.getArray();
|
|
|
|
Sequence< Any > aValues( aNames.getLength() );
|
|
|
|
Any* pValues = aValues.getArray();
|
|
|
|
for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
|
|
|
|
{
|
|
|
|
switch( nProp )
|
|
|
|
{
|
|
|
|
case 0: pValues[nProp] <<= m_sFontName; break;
|
|
|
|
case 1: pValues[nProp] <<= m_nFontHeight; break;
|
|
|
|
case 2: pValues[nProp] <<= m_bProportionalFontOnly; break;
|
|
|
|
default:
|
|
|
|
DBG_ERRORFILE( "invalid index to save a user token" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PutProperties( aNames, aValues );
|
|
|
|
|
|
|
|
//notify SfxListener
|
|
|
|
{
|
|
|
|
SfxSimpleHint aHint = SfxSimpleHint( SFX_HINT_DATACHANGED );
|
|
|
|
Broadcast(aHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:19---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
SourceViewConfig::SourceViewConfig()
|
|
|
|
{
|
|
|
|
{
|
2004-06-25 16:25:12 +00:00
|
|
|
::osl::MutexGuard aGuard( lclMutex::get() );
|
2002-08-30 08:53:22 +00:00
|
|
|
if(!m_pImplConfig)
|
2005-11-11 07:54:14 +00:00
|
|
|
{
|
2002-08-30 08:53:22 +00:00
|
|
|
m_pImplConfig = new SourceViewConfig_Impl;
|
2005-11-11 07:54:14 +00:00
|
|
|
ItemHolder1::holdConfigItem(E_SOURCEVIEWCONFIG);
|
|
|
|
}
|
|
|
|
|
2002-08-30 08:53:22 +00:00
|
|
|
++m_nRefCount;
|
|
|
|
}
|
|
|
|
StartListening( *m_pImplConfig, TRUE );
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:19---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
SourceViewConfig::~SourceViewConfig()
|
|
|
|
{
|
|
|
|
EndListening( *m_pImplConfig, TRUE );
|
2004-06-25 16:25:12 +00:00
|
|
|
::osl::MutexGuard aGuard( lclMutex::get() );
|
2002-08-30 08:53:22 +00:00
|
|
|
if( !--m_nRefCount )
|
|
|
|
{
|
|
|
|
if( m_pImplConfig->IsModified() )
|
|
|
|
m_pImplConfig->Commit();
|
|
|
|
DELETEZ( m_pImplConfig );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:19---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
const OUString& SourceViewConfig::GetFontName() const
|
|
|
|
{
|
|
|
|
return m_pImplConfig->GetFontName();
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:20---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig::SetFontName(const OUString& rName)
|
|
|
|
{
|
|
|
|
m_pImplConfig->SetFontName(rName);
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:20---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
sal_Int16 SourceViewConfig::GetFontHeight() const
|
|
|
|
{
|
|
|
|
return m_pImplConfig->GetFontHeight();
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:20---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig::SetFontHeight(sal_Int16 nHeight)
|
|
|
|
{
|
|
|
|
m_pImplConfig->SetFontHeight(nHeight);
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:20---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
sal_Bool SourceViewConfig::IsShowProportionalFontsOnly() const
|
|
|
|
{
|
|
|
|
return m_pImplConfig->IsShowProportionalFontsOnly();
|
|
|
|
}
|
|
|
|
/*-- 28.08.2002 16:32:20---------------------------------------------------
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig::SetShowProportionalFontsOnly(sal_Bool bSet)
|
|
|
|
{
|
|
|
|
m_pImplConfig->SetShowProportionalFontsOnly(bSet);
|
|
|
|
}
|
|
|
|
/* -----------------------------30.08.2002 10:40------------------------------
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
void SourceViewConfig::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
|
|
|
|
{
|
|
|
|
Broadcast( rHint );
|
|
|
|
}
|
|
|
|
}//namespace svt
|