2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2002-08-30 08:53:22 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 19:03:56 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2008-04-10 19:03:56 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2008-04-10 19:03:56 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2008-04-10 19:03:56 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2008-04-10 19:03:56 +00:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
2008-04-10 19:03:56 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2002-08-30 08:53:22 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 13:29:56 +00:00
|
|
|
|
2009-10-06 07:38:24 +02:00
|
|
|
#include <unotools/sourceviewconfig.hxx>
|
2002-08-30 08:53:22 +00:00
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|
|
|
#include <unotools/configitem.hxx>
|
|
|
|
#include <tools/debug.hxx>
|
2004-06-25 16:25:12 +00:00
|
|
|
#include <rtl/instance.hxx>
|
2002-08-30 08:53:22 +00:00
|
|
|
|
2005-11-11 07:54:14 +00:00
|
|
|
#include <itemholder1.hxx>
|
|
|
|
|
2002-08-30 08:53:22 +00:00
|
|
|
using namespace utl;
|
|
|
|
using namespace com::sun::star::uno;
|
2011-02-27 18:47:31 +01:00
|
|
|
|
|
|
|
using ::rtl::OUString;
|
|
|
|
|
2009-10-06 07:38:24 +02:00
|
|
|
namespace utl
|
2002-08-30 08:53:22 +00:00
|
|
|
{
|
2009-10-06 07:38:24 +02:00
|
|
|
class SourceViewConfig_Impl : public utl::ConfigItem
|
2002-08-30 08:53:22 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
SourceViewConfig_Impl::SourceViewConfig_Impl() :
|
2010-11-22 22:54:33 +01:00
|
|
|
ConfigItem(OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Font/SourceViewFont"))),
|
2002-08-30 08:53:22 +00:00
|
|
|
m_nFontHeight(12),
|
|
|
|
m_bProportionalFontOnly(sal_False)
|
|
|
|
{
|
|
|
|
Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceViewConfig_Impl::~SourceViewConfig_Impl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 19:48:40 +00:00
|
|
|
void SourceViewConfig_Impl::Notify( const Sequence< OUString >& )
|
2002-08-30 08:53:22 +00:00
|
|
|
{
|
|
|
|
Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SourceViewConfig_Impl::Commit()
|
|
|
|
{
|
|
|
|
ClearModified();
|
|
|
|
Sequence< OUString > aNames = GetPropertyNames();
|
|
|
|
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:
|
2012-01-16 18:03:17 +01:00
|
|
|
SAL_WARN( "unotools.config", "invalid index to save a user token" );
|
2002-08-30 08:53:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
PutProperties( aNames, aValues );
|
|
|
|
|
2009-10-16 00:05:16 +02:00
|
|
|
NotifyListeners(0);
|
2002-08-30 08:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2009-10-06 07:38:24 +02:00
|
|
|
|
|
|
|
m_pImplConfig->AddListener( this );
|
2002-08-30 08:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceViewConfig::~SourceViewConfig()
|
|
|
|
{
|
2009-10-06 07:38:24 +02:00
|
|
|
m_pImplConfig->RemoveListener( this );
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const OUString& SourceViewConfig::GetFontName() const
|
|
|
|
{
|
|
|
|
return m_pImplConfig->GetFontName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SourceViewConfig::SetFontName(const OUString& rName)
|
|
|
|
{
|
|
|
|
m_pImplConfig->SetFontName(rName);
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int16 SourceViewConfig::GetFontHeight() const
|
|
|
|
{
|
|
|
|
return m_pImplConfig->GetFontHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SourceViewConfig::SetFontHeight(sal_Int16 nHeight)
|
|
|
|
{
|
|
|
|
m_pImplConfig->SetFontHeight(nHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SourceViewConfig::IsShowProportionalFontsOnly() const
|
|
|
|
{
|
|
|
|
return m_pImplConfig->IsShowProportionalFontsOnly();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SourceViewConfig::SetShowProportionalFontsOnly(sal_Bool bSet)
|
|
|
|
{
|
|
|
|
m_pImplConfig->SetShowProportionalFontsOnly(bSet);
|
|
|
|
}
|
|
|
|
}
|
2009-10-06 07:38:24 +02:00
|
|
|
// namespace utl
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|