Files
libreoffice/cui/source/options/cfgchart.cxx

320 lines
8.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: clarify Option->Language UI option Patch contributed by Herbert Duerr http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117709#: add missing string resource Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172348 cws mba34issues01: #i117716#: fix missing resources my removing unused code Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172345 re-add Crystal, Tango, Oxygen icon theme listings. correct method signature Patch contributed by Jean-Louis 'Hans' Fuchs http://svn.apache.org/viewvc?view=revision&revision=1306725 i#119063 - correct serf integration Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1300521 i#119036 - adapt serf integration -- use transfer-encoding 'chunked' on HTTPS -- switch transfer-encoding between 'chunked' and none on 413 HTTP status code -- refactoring -- improve user experience of certification dialog - only shown once Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1299727 118569: Use whole certification chain for verification. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1295493 serf integration: improve credential input handling Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1294557 warning-free ucb/source/ucp/webdav Patch contributed by Pavel Janik http://svn.apache.org/viewvc?view=revision&revision=1294086 some refactoring to PROPPATCH and PROPFIND requests Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1293281 i#118569: Replace neon with serf Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1292832 http://svn.apache.org/viewvc?view=revision&revision=1292794 remove OS/2 conditionals for now. re-enable webdav unit tests.
2012-10-04 11:25:41 +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 .
*/
2009-10-31 00:36:06 +01:00
#include <com/sun/star/uno/Sequence.hxx>
#include <tools/stream.hxx>
2009-10-31 00:36:06 +01:00
#include "cfgchart.hxx"
#include <dialmgr.hxx>
migrate to boost::gettext * all .ui files go from <interface> to <interface domain="MODULE"> e.g. vcl * all .src files go away and the english source strings folded into the .hrc as NC_("context", "source string") * ResMgr is dropped in favour of std::locale imbued by boost::locale::generator pointed at matching MODULE .mo files * UIConfig translations are folded into the module .mo, so e.g. UIConfig_cui goes from l10n target to normal one, so the res/lang.zips of UI files go away * translation via Translation::get(hrc-define-key, imbued-std::locale) * python can now be translated with its inbuilt gettext support (we keep the name strings.hrc there to keep finding the .hrc file uniform) so magic numbers can go away there * java and starbasic components can be translated via the pre-existing css.resource.StringResourceWithLocation mechanism * en-US res files go away, their strings are now the .hrc keys in the source code * remaining .res files are replaced by .mo files * in .res/.ui-lang-zip files, the old scheme missing translations of strings results in inserting the english original so something can be found, now the standard fallback of using the english original from the source key is used, so partial translations shrink dramatically in size * extract .hrc strings with hrcex which backs onto xgettext -C --add-comments --keyword=NC_:1c,2 --from-code=UTF-8 --no-wrap * extract .ui strings with uiex which backs onto xgettext --add-comments --no-wrap * qtz for gettext translations is generated at runtime as ascii-ified crc32 of content + "|" + msgid * [API CHANGE] remove deprecated binary .res resouce loader related uno apis com::sun::star::resource::OfficeResourceLoader com::sun::star::resource::XResourceBundleLoader com::sun::star::resource::XResourceBundle when translating strings via uno apis com.sun.star.resource.StringResourceWithLocation can continue to be used Change-Id: Ia2594a2672b7301d9c3421fdf31b6cfe7f3f8d0a
2017-06-11 20:56:30 +01:00
#include <strings.hrc>
2009-10-31 00:36:06 +01:00
#define ROW_COLOR_COUNT 12
using namespace com::sun::star;
SvxChartColorTable::SvxChartColorTable()
: nNextElementNumber(0)
{
}
2009-10-31 00:36:06 +01:00
SvxChartColorTable::SvxChartColorTable(const SvxChartColorTable & _rSource)
: m_aColorEntries(_rSource.m_aColorEntries)
, nNextElementNumber(m_aColorEntries.size() + 1)
{
}
2009-10-31 00:36:06 +01:00
// accessors
size_t SvxChartColorTable::size() const
{
return m_aColorEntries.size();
}
const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
{
if ( _nIndex >= m_aColorEntries.size() )
{
SAL_WARN( "cui.options", "SvxChartColorTable::[] invalid index" );
2009-10-31 00:36:06 +01:00
return m_aColorEntries[ 0 ];
}
return m_aColorEntries[ _nIndex ];
}
ColorData SvxChartColorTable::getColorData( size_t _nIndex ) const
{
if ( _nIndex >= m_aColorEntries.size() )
{
SAL_WARN( "cui.options", "SvxChartColorTable::getColorData invalid index" );
2009-10-31 00:36:06 +01:00
return COL_BLACK;
}
return m_aColorEntries[ _nIndex ].GetColor().GetRGBColor();
2009-10-31 00:36:06 +01:00
}
// mutators
void SvxChartColorTable::clear()
{
m_aColorEntries.clear();
nNextElementNumber = 1;
2009-10-31 00:36:06 +01:00
}
void SvxChartColorTable::append( const XColorEntry & _rEntry )
{
m_aColorEntries.push_back( _rEntry );
}
void SvxChartColorTable::remove( size_t _nIndex )
{
if (m_aColorEntries.size() > 0)
m_aColorEntries.erase( m_aColorEntries.begin() + _nIndex);
for (size_t i=0 ; i<m_aColorEntries.size(); i++)
{
m_aColorEntries[ i ].SetName( getDefaultName( i ) );
}
}
2009-10-31 00:36:06 +01:00
void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
{
DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
"SvxChartColorTable::replace invalid index" );
m_aColorEntries[ _nIndex ] = _rEntry;
}
void SvxChartColorTable::useDefault()
{
ColorData aColors[] = {
RGB_COLORDATA( 0x00, 0x45, 0x86 ),
RGB_COLORDATA( 0xff, 0x42, 0x0e ),
RGB_COLORDATA( 0xff, 0xd3, 0x20 ),
RGB_COLORDATA( 0x57, 0x9d, 0x1c ),
RGB_COLORDATA( 0x7e, 0x00, 0x21 ),
RGB_COLORDATA( 0x83, 0xca, 0xff ),
RGB_COLORDATA( 0x31, 0x40, 0x04 ),
RGB_COLORDATA( 0xae, 0xcf, 0x00 ),
RGB_COLORDATA( 0x4b, 0x1f, 0x6f ),
RGB_COLORDATA( 0xff, 0x95, 0x0e ),
RGB_COLORDATA( 0xc5, 0x00, 0x0b ),
RGB_COLORDATA( 0x00, 0x84, 0xd1 )
};
clear();
for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
2009-10-31 00:36:06 +01:00
{
append( XColorEntry( aColors[ i % sizeof( aColors ) ], getDefaultName( i ) ));
2009-10-31 00:36:06 +01:00
}
}
2009-10-31 00:36:06 +01:00
OUString SvxChartColorTable::getDefaultName( size_t _nIndex )
{
OUString aName;
2009-10-31 00:36:06 +01:00
if (sDefaultNamePrefix.getLength() == 0)
{
OUString aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW ) );
sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
if( nPos != -1 )
{
sDefaultNamePrefix = aResName.copy( 0, nPos );
sDefaultNamePostfix = aResName.copy( nPos + sizeof( "$(ROW)" ) - 1 );
}
else
{
sDefaultNamePrefix = aResName;
}
2009-10-31 00:36:06 +01:00
}
aName = sDefaultNamePrefix + OUString::number(_nIndex + 1) + sDefaultNamePostfix;
nNextElementNumber++;
return aName;
2009-10-31 00:36:06 +01:00
}
// comparison
bool SvxChartColorTable::operator==( const SvxChartColorTable & _rOther ) const
{
// note: XColorEntry has no operator ==
bool bEqual = ( m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
2009-10-31 00:36:06 +01:00
if( bEqual )
{
for( size_t i = 0; i < m_aColorEntries.size(); ++i )
{
if( getColorData( i ) != _rOther.getColorData( i ))
{
bEqual = false;
break;
}
}
}
return bEqual;
}
2009-10-31 00:36:06 +01:00
// class SvxChartOptions
2009-10-31 00:36:06 +01:00
SvxChartOptions::SvxChartOptions() :
::utl::ConfigItem( "Office.Chart" ),
mbIsInitialized( false )
2009-10-31 00:36:06 +01:00
{
maPropertyNames.realloc( 1 );
maPropertyNames[ 0 ] = "DefaultColor/Series";
2009-10-31 00:36:06 +01:00
}
SvxChartOptions::~SvxChartOptions()
{
}
const SvxChartColorTable& SvxChartOptions::GetDefaultColors()
{
if ( !mbIsInitialized )
mbIsInitialized = RetrieveOptions();
return maDefColors;
}
void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& aCol )
{
maDefColors = aCol;
SetModified();
}
bool SvxChartOptions::RetrieveOptions()
2009-10-31 00:36:06 +01:00
{
// get sequence containing all properties
uno::Sequence< OUString > aNames = GetPropertyNames();
2009-10-31 00:36:06 +01:00
uno::Sequence< uno::Any > aProperties( aNames.getLength());
aProperties = GetProperties( aNames );
if( aProperties.getLength() == aNames.getLength())
{
// 1. default colors for series
maDefColors.clear();
uno::Sequence< sal_Int64 > aColorSeq;
aProperties[ 0 ] >>= aColorSeq;
sal_Int32 nCount = aColorSeq.getLength();
Color aCol;
// create strings for entry names
OUString aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW ) );
OUString aPrefix, aPostfix, aName;
sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
if( nPos != -1 )
2009-10-31 00:36:06 +01:00
{
aPrefix = aResName.copy( 0, nPos );
sal_Int32 idx = nPos + sizeof( "$(ROW)" ) - 1;
aPostfix = aResName.copy( idx );
2009-10-31 00:36:06 +01:00
}
else
aPrefix = aResName;
// set color values
for( sal_Int32 i=0; i < nCount; i++ )
{
aCol.SetColor( static_cast< ColorData >(aColorSeq[ i ]) );
2009-10-31 00:36:06 +01:00
aName = aPrefix + OUString::number(i + 1) + aPostfix;
2009-10-31 00:36:06 +01:00
maDefColors.append( XColorEntry( aCol, aName ));
}
return true;
2009-10-31 00:36:06 +01:00
}
return false;
2009-10-31 00:36:06 +01:00
}
void SvxChartOptions::ImplCommit()
2009-10-31 00:36:06 +01:00
{
uno::Sequence< OUString > aNames = GetPropertyNames();
2009-10-31 00:36:06 +01:00
uno::Sequence< uno::Any > aValues( aNames.getLength());
if( aValues.getLength() >= 1 )
{
// 1. default colors for series
// convert list to sequence
const size_t nCount = maDefColors.size();
uno::Sequence< sal_Int64 > aColors( nCount );
for( size_t i=0; i < nCount; i++ )
{
ColorData aData = maDefColors.getColorData( i );
aColors[ i ] = aData;
}
aValues[ 0 ] <<= aColors;
}
PutProperties( aNames, aValues );
}
void SvxChartOptions::Notify( const css::uno::Sequence< OUString >& )
2009-10-31 00:36:06 +01:00
{
}
2009-10-31 00:36:06 +01:00
// class SvxChartColorTableItem
2009-10-31 00:36:06 +01:00
SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_, const SvxChartColorTable& aTable ) :
2009-10-31 00:36:06 +01:00
SfxPoolItem( nWhich_ ),
m_aColorTable( aTable )
{
}
SvxChartColorTableItem::SvxChartColorTableItem( const SvxChartColorTableItem& rOther ) :
SfxPoolItem( rOther ),
m_aColorTable( rOther.m_aColorTable )
{
}
2010-12-11 22:45:31 +01:00
SfxPoolItem* SvxChartColorTableItem::Clone( SfxItemPool * ) const
2009-10-31 00:36:06 +01:00
{
return new SvxChartColorTableItem( *this );
}
bool SvxChartColorTableItem::operator==( const SfxPoolItem& rAttr ) const
2009-10-31 00:36:06 +01:00
{
assert(SfxPoolItem::operator==(rAttr));
2009-10-31 00:36:06 +01:00
const SvxChartColorTableItem * rCTItem( dynamic_cast<const SvxChartColorTableItem * >( & rAttr ));
2009-10-31 00:36:06 +01:00
if( rCTItem )
{
return (m_aColorTable == rCTItem->GetColorList());
2009-10-31 00:36:06 +01:00
}
return false;
2009-10-31 00:36:06 +01:00
}
2010-12-11 22:45:31 +01:00
void SvxChartColorTableItem::SetOptions( SvxChartOptions* pOpts ) const
2009-10-31 00:36:06 +01:00
{
if ( pOpts )
pOpts->SetDefaultColors( m_aColorTable );
}
void SvxChartColorTableItem::ReplaceColorByIndex( size_t _nIndex, const XColorEntry & _rEntry )
{
m_aColorTable.replace( _nIndex, _rEntry );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */