This is an automated email from the ASF dual-hosted git repository.
mseidel pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/trunk by this push:
new d3e5b9da5e Cleanup
d3e5b9da5e is described below
commit d3e5b9da5ecd3a21afd95e21a5fd36807d0753aa
Author: mseidel <[email protected]>
AuthorDate: Mon May 19 17:21:45 2025 +0200
Cleanup
---
main/connectivity/source/commontools/sqlerror.cxx | 476 ++++++------
main/oox/source/ole/olehelper.cxx | 388 +++++-----
main/oox/source/xls/drawingbase.cxx | 406 +++++-----
main/oox/source/xls/excelvbaproject.cxx | 136 ++--
main/slideshow/source/engine/color.cxx | 865 +++++++++++-----------
5 files changed, 1126 insertions(+), 1145 deletions(-)
diff --git a/main/connectivity/source/commontools/sqlerror.cxx
b/main/connectivity/source/commontools/sqlerror.cxx
index d7b25c66c5..105c499736 100644
--- a/main/connectivity/source/commontools/sqlerror.cxx
+++ b/main/connectivity/source/commontools/sqlerror.cxx
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* 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
@@ -7,20 +7,18 @@
* 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
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
-
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
@@ -36,10 +34,8 @@
#include <string.h>
-//........................................................................
namespace connectivity
{
-//........................................................................
/** === begin UNO using === **/
using ::com::sun::star::uno::Reference;
@@ -49,311 +45,311 @@ namespace connectivity
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::makeAny;
- using ::com::sun::star::uno::XInterface;
- using ::com::sun::star::sdbc::SQLException;
- using ::com::sun::star::uno::Type;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::sdbc::SQLException;
+ using ::com::sun::star::uno::Type;
/** === end UNO using === **/
- //using SQLError::ParamValue; // GCC (unxlngi6) does not like this
- namespace
- {
- typedef SQLError::ParamValue ParamValue;
- }
+ //using SQLError::ParamValue; // GCC (unxlngi6) does not like this
+ namespace
+ {
+ typedef SQLError::ParamValue ParamValue;
+ }
//====================================================================
//= SQLError_Impl - declaration
//====================================================================
- class SQLError_Impl
- {
- public:
- SQLError_Impl( const ::comphelper::ComponentContext& _rContext );
- ~SQLError_Impl();
-
- // versions of the public SQLError methods which are just delegated to
this impl-class
- static const ::rtl::OUString& getMessagePrefix();
- ::rtl::OUString getErrorMessage( const ErrorCondition _eCondition,
const ParamValue& _rParamValue1, const ParamValue& _rParamValue2, const
ParamValue& _rParamValue3 );
- ::rtl::OUString getSQLState( const ErrorCondition _eCondition );
- static ErrorCode getErrorCode( const ErrorCondition _eCondition );
- void raiseException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext, const ParamValue& _rParamValue1,
const ParamValue& _rParamValue2, const ParamValue& _rParamValue3 );
- void raiseException( const ErrorCondition _eCondition,
const ParamValue& _rParamValue1, const ParamValue& _rParamValue2, const
ParamValue& _rParamValue3 );
- void raiseTypedException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext, const Type&
_rExceptionType, const ParamValue& _rParamValue1, const ParamValue&
_rParamValue2, const ParamValue& _rParamValue3 );
- SQLException getSQLException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext, const ParamValue& _rParamValue1,
const ParamValue& _rParamValue2, const ParamValue& _rParamValue3 );
-
- private:
- /// returns the basic error message associated with the given error
condition, without any parameter replacements
- ::rtl::OUString
- impl_getErrorMessage( const ErrorCondition& _eCondition );
-
- /// returns the SQLState associated with the given error condition
- ::rtl::OUString
- impl_getSQLState( const ErrorCondition& _eCondition );
-
- /// returns an SQLException describing the given error condition
- SQLException
- impl_buildSQLException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
- const ParamValue& _rParamValue1, const ParamValue&
_rParamValue2, const ParamValue& _rParamValue3 );
-
- /// initializes our resource bundle
- bool impl_initResources();
-
- private:
- ::osl::Mutex m_aMutex;
- ::comphelper::ComponentContext m_aContext;
- ::std::auto_ptr< ::comphelper::OfficeResourceBundle > m_pResources;
- bool
m_bAttemptedInit;
- };
+ class SQLError_Impl
+ {
+ public:
+ SQLError_Impl( const ::comphelper::ComponentContext& _rContext
);
+ ~SQLError_Impl();
+
+ // versions of the public SQLError methods which are just
delegated to this impl-class
+ static const ::rtl::OUString& getMessagePrefix();
+ ::rtl::OUString getErrorMessage( const ErrorCondition
_eCondition, const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 );
+ ::rtl::OUString getSQLState( const ErrorCondition
_eCondition );
+ static ErrorCode getErrorCode( const ErrorCondition
_eCondition );
+ void raiseException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext, const ParamValue&
_rParamValue1, const ParamValue& _rParamValue2, const ParamValue& _rParamValue3
);
+ void raiseException( const ErrorCondition
_eCondition, const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 );
+ void raiseTypedException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext, const Type&
_rExceptionType, const ParamValue& _rParamValue1, const ParamValue&
_rParamValue2, const ParamValue& _rParamValue3 );
+ SQLException getSQLException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext, const ParamValue&
_rParamValue1, const ParamValue& _rParamValue2, const ParamValue& _rParamValue3
);
+
+ private:
+ // returns the basic error message associated with the given
error condition, without any parameter replacements
+ ::rtl::OUString
+ impl_getErrorMessage( const ErrorCondition&
_eCondition );
+
+ // returns the SQLState associated with the given error
condition
+ ::rtl::OUString
+ impl_getSQLState( const ErrorCondition&
_eCondition );
+
+ // returns an SQLException describing the given error condition
+ SQLException
+ impl_buildSQLException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext,
+ const ParamValue& _rParamValue1, const
ParamValue& _rParamValue2, const ParamValue& _rParamValue3 );
+
+ // initializes our resource bundle
+ bool impl_initResources();
+
+ private:
+ ::osl::Mutex
m_aMutex;
+ ::comphelper::ComponentContext
m_aContext;
+ ::std::auto_ptr< ::comphelper::OfficeResourceBundle >
m_pResources;
+ bool
m_bAttemptedInit;
+ };
//====================================================================
//= SQLError_Impl - implementation
//====================================================================
//--------------------------------------------------------------------
- SQLError_Impl::SQLError_Impl( const ::comphelper::ComponentContext&
_rContext )
- :m_aContext( _rContext )
- ,m_pResources( )
- ,m_bAttemptedInit( false )
- {
- }
+ SQLError_Impl::SQLError_Impl( const ::comphelper::ComponentContext&
_rContext )
+ :m_aContext( _rContext )
+ ,m_pResources( )
+ ,m_bAttemptedInit( false )
+ {
+ }
//--------------------------------------------------------------------
- SQLError_Impl::~SQLError_Impl()
- {
- }
+ SQLError_Impl::~SQLError_Impl()
+ {
+ }
//--------------------------------------------------------------------
- const ::rtl::OUString& SQLError_Impl::getMessagePrefix()
- {
- static ::rtl::OUString s_sMessagePrefix( RTL_CONSTASCII_USTRINGPARAM(
"[OOoBase]" ) );
- return s_sMessagePrefix;
- }
+ const ::rtl::OUString& SQLError_Impl::getMessagePrefix()
+ {
+ static ::rtl::OUString s_sMessagePrefix(
RTL_CONSTASCII_USTRINGPARAM( "[OOoBase]" ) );
+ return s_sMessagePrefix;
+ }
//--------------------------------------------------------------------
- namespace
- {
- //................................................................
- /** substitutes a given placeholder in the given message with the
given value
- */
- void lcl_substitutePlaceholder( ::rtl::OUString& _rMessage, const
sal_Char* _pPlaceholder, ParamValue _rParamValue )
- {
- size_t nPlaceholderLen( strlen( _pPlaceholder ) );
- sal_Int32 nIndex = _rMessage.indexOfAsciiL( _pPlaceholder,
nPlaceholderLen );
-
- bool bHasPlaceholder = ( nIndex != -1 );
- bool bWantsPlaceholder = _rParamValue.is();
- OSL_ENSURE( bHasPlaceholder == bWantsPlaceholder,
"lcl_substitutePlaceholder: placeholder where none is expected, or no
placeholder where one is needed!" );
-
- if ( bHasPlaceholder && bWantsPlaceholder )
- _rMessage = _rMessage.replaceAt( nIndex, nPlaceholderLen,
*_rParamValue );
- }
-
- //................................................................
- sal_Int32 lcl_getResourceID( const ErrorCondition _eCondition, bool
_bSQLState )
- {
- return 256
- + 2 * ::sal::static_int_cast< sal_Int32, ErrorCondition >(
_eCondition )
- + ( _bSQLState ? 1 : 0 );
- }
- }
+ namespace
+ {
+
//................................................................
+ /** substitutes a given placeholder in the given message with
the given value
+ */
+ void lcl_substitutePlaceholder( ::rtl::OUString& _rMessage,
const sal_Char* _pPlaceholder, ParamValue _rParamValue )
+ {
+ size_t nPlaceholderLen( strlen( _pPlaceholder ) );
+ sal_Int32 nIndex = _rMessage.indexOfAsciiL(
_pPlaceholder, nPlaceholderLen );
+
+ bool bHasPlaceholder = ( nIndex != -1 );
+ bool bWantsPlaceholder = _rParamValue.is();
+ OSL_ENSURE( bHasPlaceholder == bWantsPlaceholder,
"lcl_substitutePlaceholder: placeholder where none is expected, or no
placeholder where one is needed!" );
+
+ if ( bHasPlaceholder && bWantsPlaceholder )
+ _rMessage = _rMessage.replaceAt( nIndex,
nPlaceholderLen, *_rParamValue );
+ }
+
+
//................................................................
+ sal_Int32 lcl_getResourceID( const ErrorCondition
_eCondition, bool _bSQLState )
+ {
+ return 256
+ + 2 * ::sal::static_int_cast< sal_Int32,
ErrorCondition >( _eCondition )
+ + ( _bSQLState ? 1 : 0 );
+ }
+ }
//--------------------------------------------------------------------
- ::rtl::OUString SQLError_Impl::getErrorMessage( const ErrorCondition
_eCondition, const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 )
- {
- ::rtl::OUString sErrorMessage( impl_getErrorMessage( _eCondition ) );
+ ::rtl::OUString SQLError_Impl::getErrorMessage( const ErrorCondition
_eCondition, const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 )
+ {
+ ::rtl::OUString sErrorMessage( impl_getErrorMessage(
_eCondition ) );
- lcl_substitutePlaceholder( sErrorMessage, "$1$", _rParamValue1 );
- lcl_substitutePlaceholder( sErrorMessage, "$2$", _rParamValue2 );
- lcl_substitutePlaceholder( sErrorMessage, "$3$", _rParamValue3 );
+ lcl_substitutePlaceholder( sErrorMessage, "$1$", _rParamValue1
);
+ lcl_substitutePlaceholder( sErrorMessage, "$2$", _rParamValue2
);
+ lcl_substitutePlaceholder( sErrorMessage, "$3$", _rParamValue3
);
- return sErrorMessage;
- }
+ return sErrorMessage;
+ }
//--------------------------------------------------------------------
- ::rtl::OUString SQLError_Impl::getSQLState( const ErrorCondition
_eCondition )
- {
- return impl_getSQLState( _eCondition );
- }
+ ::rtl::OUString SQLError_Impl::getSQLState( const ErrorCondition
_eCondition )
+ {
+ return impl_getSQLState( _eCondition );
+ }
//--------------------------------------------------------------------
- ErrorCode SQLError_Impl::getErrorCode( const ErrorCondition _eCondition )
- {
- return 0 - ::sal::static_int_cast< ErrorCode, ErrorCondition >(
_eCondition );
- }
+ ErrorCode SQLError_Impl::getErrorCode( const ErrorCondition _eCondition
)
+ {
+ return 0 - ::sal::static_int_cast< ErrorCode, ErrorCondition >(
_eCondition );
+ }
//--------------------------------------------------------------------
- void SQLError_Impl::raiseException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext, const ParamValue& _rParamValue1,
const ParamValue& _rParamValue2, const ParamValue& _rParamValue3 )
- {
- raiseTypedException(
- _eCondition,
- _rxContext,
- ::cppu::UnoType< SQLException >::get(),
- _rParamValue1,
- _rParamValue2,
- _rParamValue3
- );
- }
+ void SQLError_Impl::raiseException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext, const ParamValue& _rParamValue1,
const ParamValue& _rParamValue2, const ParamValue& _rParamValue3 )
+ {
+ raiseTypedException(
+ _eCondition,
+ _rxContext,
+ ::cppu::UnoType< SQLException >::get(),
+ _rParamValue1,
+ _rParamValue2,
+ _rParamValue3
+ );
+ }
//--------------------------------------------------------------------
- void SQLError_Impl::raiseException( const ErrorCondition _eCondition,
const ParamValue& _rParamValue1, const ParamValue& _rParamValue2, const
ParamValue& _rParamValue3 )
- {
- raiseTypedException(
- _eCondition,
- NULL,
- ::cppu::UnoType< SQLException >::get(),
- _rParamValue1,
- _rParamValue2,
- _rParamValue3
- );
- }
+ void SQLError_Impl::raiseException( const ErrorCondition _eCondition,
const ParamValue& _rParamValue1, const ParamValue& _rParamValue2, const
ParamValue& _rParamValue3 )
+ {
+ raiseTypedException(
+ _eCondition,
+ NULL,
+ ::cppu::UnoType< SQLException >::get(),
+ _rParamValue1,
+ _rParamValue2,
+ _rParamValue3
+ );
+ }
//--------------------------------------------------------------------
- void SQLError_Impl::raiseTypedException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
- const Type& _rExceptionType, const ParamValue& _rParamValue1, const
ParamValue& _rParamValue2, const ParamValue& _rParamValue3 )
- {
- if ( !::cppu::UnoType< SQLException >::get().isAssignableFrom(
_rExceptionType ) )
- throw ::std::bad_cast();
+ void SQLError_Impl::raiseTypedException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext,
+ const Type& _rExceptionType, const ParamValue& _rParamValue1,
const ParamValue& _rParamValue2, const ParamValue& _rParamValue3 )
+ {
+ if ( !::cppu::UnoType< SQLException >::get().isAssignableFrom(
_rExceptionType ) )
+ throw ::std::bad_cast();
- // default-construct an exception of the desired type
- Any aException( NULL, _rExceptionType );
+ // default-construct an exception of the desired type
+ Any aException( NULL, _rExceptionType );
- // fill it
- SQLException* pException = static_cast< SQLException* >(
aException.pData );
- *pException = impl_buildSQLException( _eCondition, _rxContext,
_rParamValue1, _rParamValue2, _rParamValue3 );
+ // fill it
+ SQLException* pException = static_cast< SQLException* >(
aException.pData );
+ *pException = impl_buildSQLException( _eCondition, _rxContext,
_rParamValue1, _rParamValue2, _rParamValue3 );
- // throw it
- ::cppu::throwException( aException );
- }
+ // throw it
+ ::cppu::throwException( aException );
+ }
//--------------------------------------------------------------------
- SQLException SQLError_Impl::getSQLException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext,
- const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 )
- {
- return impl_buildSQLException( _eCondition, _rxContext, _rParamValue1,
_rParamValue2, _rParamValue3 );
- }
+ SQLException SQLError_Impl::getSQLException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext,
+ const ParamValue& _rParamValue1, const ParamValue&
_rParamValue2, const ParamValue& _rParamValue3 )
+ {
+ return impl_buildSQLException( _eCondition, _rxContext,
_rParamValue1, _rParamValue2, _rParamValue3 );
+ }
//--------------------------------------------------------------------
- SQLException SQLError_Impl::impl_buildSQLException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext,
- const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 )
- {
- return SQLException(
- getErrorMessage( _eCondition, _rParamValue1, _rParamValue2,
_rParamValue3 ),
- _rxContext,
- getSQLState( _eCondition ),
- getErrorCode( _eCondition ),
- Any()
- );
- }
+ SQLException SQLError_Impl::impl_buildSQLException( const
ErrorCondition _eCondition, const Reference< XInterface >& _rxContext,
+ const ParamValue& _rParamValue1, const ParamValue&
_rParamValue2, const ParamValue& _rParamValue3 )
+ {
+ return SQLException(
+ getErrorMessage( _eCondition, _rParamValue1,
_rParamValue2, _rParamValue3 ),
+ _rxContext,
+ getSQLState( _eCondition ),
+ getErrorCode( _eCondition ),
+ Any()
+ );
+ }
//--------------------------------------------------------------------
- ::rtl::OUString SQLError_Impl::impl_getErrorMessage( const ErrorCondition&
_eCondition )
- {
- ::rtl::OUStringBuffer aMessage;
+ ::rtl::OUString SQLError_Impl::impl_getErrorMessage( const
ErrorCondition& _eCondition )
+ {
+ ::rtl::OUStringBuffer aMessage;
- if ( impl_initResources() )
- {
- ::rtl::OUString sResMessage( m_pResources->loadString(
lcl_getResourceID( _eCondition, false ) ) );
- OSL_ENSURE( sResMessage.getLength(),
"SQLError_Impl::impl_getErrorMessage: illegal error condition, or invalid
resource!" );
- aMessage.append( getMessagePrefix() ).appendAscii( " " ).append(
sResMessage );
- }
+ if ( impl_initResources() )
+ {
+ ::rtl::OUString sResMessage( m_pResources->loadString(
lcl_getResourceID( _eCondition, false ) ) );
+ OSL_ENSURE( sResMessage.getLength(),
"SQLError_Impl::impl_getErrorMessage: illegal error condition, or invalid
resource!" );
+ aMessage.append( getMessagePrefix() ).appendAscii( " "
).append( sResMessage );
+ }
- return aMessage.makeStringAndClear();
- }
+ return aMessage.makeStringAndClear();
+ }
//--------------------------------------------------------------------
- ::rtl::OUString SQLError_Impl::impl_getSQLState( const ErrorCondition&
_eCondition )
- {
- ::rtl::OUString sState;
+ ::rtl::OUString SQLError_Impl::impl_getSQLState( const ErrorCondition&
_eCondition )
+ {
+ ::rtl::OUString sState;
- if ( impl_initResources() )
- {
- sal_Int32 nResourceId( lcl_getResourceID( _eCondition, true ) );
- if ( m_pResources->hasString( nResourceId ) )
- sState = m_pResources->loadString( nResourceId );
- }
+ if ( impl_initResources() )
+ {
+ sal_Int32 nResourceId( lcl_getResourceID( _eCondition,
true ) );
+ if ( m_pResources->hasString( nResourceId ) )
+ sState = m_pResources->loadString( nResourceId
);
+ }
- if ( !sState.getLength() )
- sState = ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM(
"S1000" ) );
+ if ( !sState.getLength() )
+ sState = ::rtl::OUString::intern(
RTL_CONSTASCII_USTRINGPARAM( "S1000" ) );
- return sState;
- }
+ return sState;
+ }
//--------------------------------------------------------------------
- bool SQLError_Impl::impl_initResources()
- {
- if ( m_pResources.get() )
- return true;
- if ( m_bAttemptedInit )
- return false;
+ bool SQLError_Impl::impl_initResources()
+ {
+ if ( m_pResources.get() )
+ return true;
+ if ( m_bAttemptedInit )
+ return false;
- ::osl::MutexGuard aGuard( m_aMutex );
- m_bAttemptedInit = true;
+ ::osl::MutexGuard aGuard( m_aMutex );
+ m_bAttemptedInit = true;
- m_pResources.reset( new ::comphelper::OfficeResourceBundle(
m_aContext.getUNOContext(), "sdberr" ) );
- return m_pResources.get() != NULL;
- }
+ m_pResources.reset( new ::comphelper::OfficeResourceBundle(
m_aContext.getUNOContext(), "sdberr" ) );
+ return m_pResources.get() != NULL;
+ }
//====================================================================
//= SQLError
//====================================================================
//--------------------------------------------------------------------
- SQLError::SQLError( const ::comphelper::ComponentContext& _rContext )
- :m_pImpl( new SQLError_Impl( _rContext ) )
- {
- }
+ SQLError::SQLError( const ::comphelper::ComponentContext& _rContext )
+ :m_pImpl( new SQLError_Impl( _rContext ) )
+ {
+ }
//--------------------------------------------------------------------
- SQLError::~SQLError()
- {
- }
+ SQLError::~SQLError()
+ {
+ }
//--------------------------------------------------------------------
- const ::rtl::OUString& SQLError::getMessagePrefix()
- {
- return SQLError_Impl::getMessagePrefix();
- }
+ const ::rtl::OUString& SQLError::getMessagePrefix()
+ {
+ return SQLError_Impl::getMessagePrefix();
+ }
//--------------------------------------------------------------------
- ::rtl::OUString SQLError::getErrorMessage( const ErrorCondition
_eCondition, const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 ) const
- {
- return m_pImpl->getErrorMessage( _eCondition, _rParamValue1,
_rParamValue2, _rParamValue3 );
- }
+ ::rtl::OUString SQLError::getErrorMessage( const ErrorCondition
_eCondition, const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 ) const
+ {
+ return m_pImpl->getErrorMessage( _eCondition, _rParamValue1,
_rParamValue2, _rParamValue3 );
+ }
//--------------------------------------------------------------------
- ::rtl::OUString SQLError::getSQLState( const ErrorCondition _eCondition )
const
- {
- return m_pImpl->getSQLState( _eCondition );
- }
+ ::rtl::OUString SQLError::getSQLState( const ErrorCondition _eCondition
) const
+ {
+ return m_pImpl->getSQLState( _eCondition );
+ }
//--------------------------------------------------------------------
- ErrorCode SQLError::getErrorCode( const ErrorCondition _eCondition )
- {
- return SQLError_Impl::getErrorCode( _eCondition );
- }
+ ErrorCode SQLError::getErrorCode( const ErrorCondition _eCondition )
+ {
+ return SQLError_Impl::getErrorCode( _eCondition );
+ }
//--------------------------------------------------------------------
- void SQLError::raiseException( const ErrorCondition _eCondition, const
Reference< XInterface >& _rxContext, const ParamValue& _rParamValue1, const
ParamValue& _rParamValue2, const ParamValue& _rParamValue3 ) const
- {
- m_pImpl->raiseException( _eCondition, _rxContext, _rParamValue1,
_rParamValue2, _rParamValue3 );
- }
+ void SQLError::raiseException( const ErrorCondition _eCondition, const
Reference< XInterface >& _rxContext, const ParamValue& _rParamValue1, const
ParamValue& _rParamValue2, const ParamValue& _rParamValue3 ) const
+ {
+ m_pImpl->raiseException( _eCondition, _rxContext,
_rParamValue1, _rParamValue2, _rParamValue3 );
+ }
//--------------------------------------------------------------------
- void SQLError::raiseException( const ErrorCondition _eCondition, const
ParamValue& _rParamValue1, const ParamValue& _rParamValue2, const ParamValue&
_rParamValue3 ) const
- {
- m_pImpl->raiseException( _eCondition, _rParamValue1, _rParamValue2,
_rParamValue3 );
- }
+ void SQLError::raiseException( const ErrorCondition _eCondition, const
ParamValue& _rParamValue1, const ParamValue& _rParamValue2, const ParamValue&
_rParamValue3 ) const
+ {
+ m_pImpl->raiseException( _eCondition, _rParamValue1,
_rParamValue2, _rParamValue3 );
+ }
//--------------------------------------------------------------------
- void SQLError::raiseTypedException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
- const Type& _rExceptionType, const ParamValue& _rParamValue1, const
ParamValue& _rParamValue2, const ParamValue& _rParamValue3 ) const
- {
- m_pImpl->raiseTypedException( _eCondition, _rxContext,
_rExceptionType, _rParamValue1, _rParamValue2, _rParamValue3 );
- }
+ void SQLError::raiseTypedException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
+ const Type& _rExceptionType, const ParamValue& _rParamValue1,
const ParamValue& _rParamValue2, const ParamValue& _rParamValue3 ) const
+ {
+ m_pImpl->raiseTypedException( _eCondition, _rxContext,
_rExceptionType, _rParamValue1, _rParamValue2, _rParamValue3 );
+ }
//--------------------------------------------------------------------
- SQLException SQLError::getSQLException( const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
- const ParamValue& _rParamValue1, const ParamValue& _rParamValue2,
const ParamValue& _rParamValue3 ) const
- {
- return m_pImpl->getSQLException( _eCondition, _rxContext,
_rParamValue1, _rParamValue2, _rParamValue3 );
- }
+ SQLException SQLError::getSQLException( const ErrorCondition
_eCondition, const Reference< XInterface >& _rxContext,
+ const ParamValue& _rParamValue1, const ParamValue&
_rParamValue2, const ParamValue& _rParamValue3 ) const
+ {
+ return m_pImpl->getSQLException( _eCondition, _rxContext,
_rParamValue1, _rParamValue2, _rParamValue3 );
+ }
-//........................................................................
} // namespace connectivity
-//........................................................................
+
+/* vim: set noet sw=4 ts=4: */
diff --git a/main/oox/source/ole/olehelper.cxx
b/main/oox/source/ole/olehelper.cxx
index 11dd69d01d..ff44a92cc3 100644
--- a/main/oox/source/ole/olehelper.cxx
+++ b/main/oox/source/ole/olehelper.cxx
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* 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
@@ -7,20 +7,18 @@
* 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
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
-
#include "oox/ole/olehelper.hxx"
#include <rtl/ustrbuf.hxx>
@@ -31,13 +29,9 @@
namespace oox {
namespace ole {
-// ============================================================================
-
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
-// ============================================================================
-
namespace {
const sal_uInt32 OLE_COLORTYPE_MASK = 0xFF000000;
@@ -53,13 +47,13 @@ const sal_uInt32 OLE_SYSTEMCOLOR_MASK = 0x0000FFFF;
/** Swaps the red and blue component of the passed color. */
inline sal_uInt32 lclSwapRedBlue( sal_uInt32 nColor )
{
- return static_cast< sal_uInt32 >( (nColor & 0xFF00FF00) | ((nColor &
0x0000FF) << 16) | ((nColor & 0xFF0000) >> 16) );
+ return static_cast< sal_uInt32 >( (nColor & 0xFF00FF00) | ((nColor &
0x0000FF) << 16) | ((nColor & 0xFF0000) >> 16) );
}
/** Returns the UNO RGB color from the passed encoded OLE BGR color. */
inline sal_Int32 lclDecodeBgrColor( sal_uInt32 nOleColor )
{
- return static_cast< sal_Int32 >( lclSwapRedBlue( nOleColor ) & 0xFFFFFF );
+ return static_cast< sal_Int32 >( lclSwapRedBlue( nOleColor ) & 0xFFFFFF
);
}
// ----------------------------------------------------------------------------
@@ -70,44 +64,44 @@ const sal_Char* const OLE_GUID_FILEMONIKER =
"{00000303-0000-0000-C000-00000000
const sal_uInt32 OLE_STDPIC_ID = 0x0000746C;
const sal_uInt32 OLE_STDHLINK_VERSION = 2;
-const sal_uInt32 OLE_STDHLINK_HASTARGET = 0x00000001; /// Has hyperlink
moniker.
-const sal_uInt32 OLE_STDHLINK_ABSOLUTE = 0x00000002; /// Absolute path.
-const sal_uInt32 OLE_STDHLINK_HASLOCATION = 0x00000008; /// Has target
location.
-const sal_uInt32 OLE_STDHLINK_HASDISPLAY = 0x00000010; /// Has display
string.
-const sal_uInt32 OLE_STDHLINK_HASGUID = 0x00000020; /// Has
identification GUID.
-const sal_uInt32 OLE_STDHLINK_HASTIME = 0x00000040; /// Has creation
time.
-const sal_uInt32 OLE_STDHLINK_HASFRAME = 0x00000080; /// Has frame.
-const sal_uInt32 OLE_STDHLINK_ASSTRING = 0x00000100; /// Hyperlink as
simple string.
+const sal_uInt32 OLE_STDHLINK_HASTARGET = 0x00000001; // Has hyperlink
moniker.
+const sal_uInt32 OLE_STDHLINK_ABSOLUTE = 0x00000002; // Absolute path.
+const sal_uInt32 OLE_STDHLINK_HASLOCATION = 0x00000008; // Has target
location.
+const sal_uInt32 OLE_STDHLINK_HASDISPLAY = 0x00000010; // Has display
string.
+const sal_uInt32 OLE_STDHLINK_HASGUID = 0x00000020; // Has
identification GUID.
+const sal_uInt32 OLE_STDHLINK_HASTIME = 0x00000040; // Has creation time.
+const sal_uInt32 OLE_STDHLINK_HASFRAME = 0x00000080; // Has frame.
+const sal_uInt32 OLE_STDHLINK_ASSTRING = 0x00000100; // Hyperlink as
simple string.
// ----------------------------------------------------------------------------
template< typename Type >
void lclAppendHex( OUStringBuffer& orBuffer, Type nValue )
{
- const sal_Int32 nWidth = 2 * sizeof( Type );
- static const sal_Unicode spcHexChars[] = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- orBuffer.setLength( orBuffer.getLength() + nWidth );
- for( sal_Int32 nCharIdx = orBuffer.getLength() - 1, nCharEnd = nCharIdx -
nWidth; nCharIdx > nCharEnd; --nCharIdx, nValue >>= 4 )
- orBuffer.setCharAt( nCharIdx, spcHexChars[ nValue & 0xF ] );
+ const sal_Int32 nWidth = 2 * sizeof( Type );
+ static const sal_Unicode spcHexChars[] = { '0', '1', '2', '3', '4',
'5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+ orBuffer.setLength( orBuffer.getLength() + nWidth );
+ for( sal_Int32 nCharIdx = orBuffer.getLength() - 1, nCharEnd = nCharIdx
- nWidth; nCharIdx > nCharEnd; --nCharIdx, nValue >>= 4 )
+ orBuffer.setCharAt( nCharIdx, spcHexChars[ nValue & 0xF ] );
}
OUString lclReadStdHlinkString( BinaryInputStream& rInStrm, bool bUnicode )
{
- OUString aRet;
- sal_Int32 nChars = rInStrm.readInt32();
- if( nChars > 0 )
- {
- sal_Int32 nReadChars = getLimitedValue< sal_Int32, sal_Int32 >(
nChars, 0, SAL_MAX_UINT16 );
- // byte strings are always in ANSI (Windows 1252) encoding
- aRet = bUnicode ? rInStrm.readUnicodeArray( nReadChars, true ) :
rInStrm.readCharArrayUC( nReadChars, RTL_TEXTENCODING_MS_1252, true );
- // strings are NUL terminated, remove trailing NUL and possible other
garbage
- sal_Int32 nNulPos = aRet.indexOf( '\0' );
- if( nNulPos >= 0 )
- aRet = aRet.copy( 0, nNulPos );
- // skip remaining chars
- rInStrm.skip( (bUnicode ? 2 : 1) * (nChars - nReadChars) );
- }
- return aRet;
+ OUString aRet;
+ sal_Int32 nChars = rInStrm.readInt32();
+ if( nChars > 0 )
+ {
+ sal_Int32 nReadChars = getLimitedValue< sal_Int32, sal_Int32 >(
nChars, 0, SAL_MAX_UINT16 );
+ // byte strings are always in ANSI (Windows 1252) encoding
+ aRet = bUnicode ? rInStrm.readUnicodeArray( nReadChars, true )
: rInStrm.readCharArrayUC( nReadChars, RTL_TEXTENCODING_MS_1252, true );
+ // strings are NUL terminated, remove trailing NUL and possible
other garbage
+ sal_Int32 nNulPos = aRet.indexOf( '\0' );
+ if( nNulPos >= 0 )
+ aRet = aRet.copy( 0, nNulPos );
+ // skip remaining chars
+ rInStrm.skip( (bUnicode ? 2 : 1) * (nChars - nReadChars) );
+ }
+ return aRet;
}
} // namespace
@@ -115,195 +109,195 @@ OUString lclReadStdHlinkString( BinaryInputStream&
rInStrm, bool bUnicode )
// ============================================================================
StdFontInfo::StdFontInfo() :
- mnHeight( 0 ),
- mnWeight( OLE_STDFONT_NORMAL ),
- mnCharSet( WINDOWS_CHARSET_ANSI ),
- mnFlags( 0 )
+ mnHeight( 0 ),
+ mnWeight( OLE_STDFONT_NORMAL ),
+ mnCharSet( WINDOWS_CHARSET_ANSI ),
+ mnFlags( 0 )
{
}
StdFontInfo::StdFontInfo( const ::rtl::OUString& rName, sal_uInt32 nHeight,
- sal_uInt16 nWeight, sal_uInt16 nCharSet, sal_uInt8 nFlags ) :
- maName( rName ),
- mnHeight( nHeight ),
- mnWeight( nWeight ),
- mnCharSet( nCharSet ),
- mnFlags( nFlags )
+ sal_uInt16 nWeight, sal_uInt16 nCharSet, sal_uInt8 nFlags ) :
+ maName( rName ),
+ mnHeight( nHeight ),
+ mnWeight( nWeight ),
+ mnCharSet( nCharSet ),
+ mnFlags( nFlags )
{
}
// ============================================================================
/*static*/ sal_Int32 OleHelper::decodeOleColor(
- const GraphicHelper& rGraphicHelper, sal_uInt32 nOleColor, bool
bDefaultColorBgr )
+ const GraphicHelper& rGraphicHelper, sal_uInt32 nOleColor, bool
bDefaultColorBgr )
{
- static const sal_Int32 spnSystemColors[] =
- {
- XML_scrollBar, XML_background, XML_activeCaption,
XML_inactiveCaption,
- XML_menu, XML_window, XML_windowFrame,
XML_menuText,
- XML_windowText, XML_captionText, XML_activeBorder,
XML_inactiveBorder,
- XML_appWorkspace, XML_highlight, XML_highlightText,
XML_btnFace,
- XML_btnShadow, XML_grayText, XML_btnText,
XML_inactiveCaptionText,
- XML_btnHighlight, XML_3dDkShadow, XML_3dLight,
XML_infoText,
- XML_infoBk
- };
-
- switch( nOleColor & OLE_COLORTYPE_MASK )
- {
- case OLE_COLORTYPE_CLIENT:
- return bDefaultColorBgr ? lclDecodeBgrColor( nOleColor ) :
rGraphicHelper.getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
-
- case OLE_COLORTYPE_PALETTE:
- return rGraphicHelper.getPaletteColor( nOleColor &
OLE_PALETTECOLOR_MASK );
-
- case OLE_COLORTYPE_BGR:
- return lclDecodeBgrColor( nOleColor );
-
- case OLE_COLORTYPE_SYSCOLOR:
- return rGraphicHelper.getSystemColor( STATIC_ARRAY_SELECT(
spnSystemColors, nOleColor & OLE_SYSTEMCOLOR_MASK, XML_TOKEN_INVALID ),
API_RGB_WHITE );
- }
- OSL_ENSURE( false, "OleHelper::decodeOleColor - unknown color type" );
- return API_RGB_BLACK;
+ static const sal_Int32 spnSystemColors[] =
+ {
+ XML_scrollBar, XML_background, XML_activeCaption,
XML_inactiveCaption,
+ XML_menu, XML_window, XML_windowFrame,
XML_menuText,
+ XML_windowText, XML_captionText, XML_activeBorder,
XML_inactiveBorder,
+ XML_appWorkspace, XML_highlight, XML_highlightText,
XML_btnFace,
+ XML_btnShadow, XML_grayText, XML_btnText,
XML_inactiveCaptionText,
+ XML_btnHighlight, XML_3dDkShadow, XML_3dLight,
XML_infoText,
+ XML_infoBk
+ };
+
+ switch( nOleColor & OLE_COLORTYPE_MASK )
+ {
+ case OLE_COLORTYPE_CLIENT:
+ return bDefaultColorBgr ? lclDecodeBgrColor( nOleColor
) : rGraphicHelper.getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
+
+ case OLE_COLORTYPE_PALETTE:
+ return rGraphicHelper.getPaletteColor( nOleColor &
OLE_PALETTECOLOR_MASK );
+
+ case OLE_COLORTYPE_BGR:
+ return lclDecodeBgrColor( nOleColor );
+
+ case OLE_COLORTYPE_SYSCOLOR:
+ return rGraphicHelper.getSystemColor(
STATIC_ARRAY_SELECT( spnSystemColors, nOleColor & OLE_SYSTEMCOLOR_MASK,
XML_TOKEN_INVALID ), API_RGB_WHITE );
+ }
+ OSL_ENSURE( false, "OleHelper::decodeOleColor - unknown color type" );
+ return API_RGB_BLACK;
}
/*static*/ sal_uInt32 OleHelper::encodeOleColor( sal_Int32 nRgbColor )
{
- return OLE_COLORTYPE_BGR | lclSwapRedBlue( static_cast< sal_uInt32 >(
nRgbColor & 0xFFFFFF ) );
+ return OLE_COLORTYPE_BGR | lclSwapRedBlue( static_cast< sal_uInt32 >(
nRgbColor & 0xFFFFFF ) );
}
/*static*/ OUString OleHelper::importGuid( BinaryInputStream& rInStrm )
{
- OUStringBuffer aBuffer;
- aBuffer.append( sal_Unicode( '{' ) );
- lclAppendHex( aBuffer, rInStrm.readuInt32() );
- aBuffer.append( sal_Unicode( '-' ) );
- lclAppendHex( aBuffer, rInStrm.readuInt16() );
- aBuffer.append( sal_Unicode( '-' ) );
- lclAppendHex( aBuffer, rInStrm.readuInt16() );
- aBuffer.append( sal_Unicode( '-' ) );
- lclAppendHex( aBuffer, rInStrm.readuInt8() );
- lclAppendHex( aBuffer, rInStrm.readuInt8() );
- aBuffer.append( sal_Unicode( '-' ) );
- for( int nIndex = 0; nIndex < 6; ++nIndex )
- lclAppendHex( aBuffer, rInStrm.readuInt8() );
- aBuffer.append( sal_Unicode( '}' ) );
- return aBuffer.makeStringAndClear();
+ OUStringBuffer aBuffer;
+ aBuffer.append( sal_Unicode( '{' ) );
+ lclAppendHex( aBuffer, rInStrm.readuInt32() );
+ aBuffer.append( sal_Unicode( '-' ) );
+ lclAppendHex( aBuffer, rInStrm.readuInt16() );
+ aBuffer.append( sal_Unicode( '-' ) );
+ lclAppendHex( aBuffer, rInStrm.readuInt16() );
+ aBuffer.append( sal_Unicode( '-' ) );
+ lclAppendHex( aBuffer, rInStrm.readuInt8() );
+ lclAppendHex( aBuffer, rInStrm.readuInt8() );
+ aBuffer.append( sal_Unicode( '-' ) );
+ for( int nIndex = 0; nIndex < 6; ++nIndex )
+ lclAppendHex( aBuffer, rInStrm.readuInt8() );
+ aBuffer.append( sal_Unicode( '}' ) );
+ return aBuffer.makeStringAndClear();
}
/*static*/ bool OleHelper::importStdFont( StdFontInfo& orFontInfo,
BinaryInputStream& rInStrm, bool bWithGuid )
{
- if( bWithGuid )
- {
- bool bIsStdFont = importGuid( rInStrm ).equalsAscii( OLE_GUID_STDFONT
);
- OSL_ENSURE( bIsStdFont, "OleHelper::importStdFont - unexpected header
GUID, expected StdFont" );
- if( !bIsStdFont )
- return false;
- }
-
- sal_uInt8 nVersion, nNameLen;
- rInStrm >> nVersion >> orFontInfo.mnCharSet >> orFontInfo.mnFlags >>
orFontInfo.mnWeight >> orFontInfo.mnHeight >> nNameLen;
- // according to spec the name is ASCII
- orFontInfo.maName = rInStrm.readCharArrayUC( nNameLen,
RTL_TEXTENCODING_ASCII_US );
- OSL_ENSURE( nVersion <= 1, "OleHelper::importStdFont - wrong version" );
- return !rInStrm.isEof() && (nVersion <= 1);
+ if( bWithGuid )
+ {
+ bool bIsStdFont = importGuid( rInStrm ).equalsAscii(
OLE_GUID_STDFONT );
+ OSL_ENSURE( bIsStdFont, "OleHelper::importStdFont - unexpected
header GUID, expected StdFont" );
+ if( !bIsStdFont )
+ return false;
+ }
+
+ sal_uInt8 nVersion, nNameLen;
+ rInStrm >> nVersion >> orFontInfo.mnCharSet >> orFontInfo.mnFlags >>
orFontInfo.mnWeight >> orFontInfo.mnHeight >> nNameLen;
+ // according to spec the name is ASCII
+ orFontInfo.maName = rInStrm.readCharArrayUC( nNameLen,
RTL_TEXTENCODING_ASCII_US );
+ OSL_ENSURE( nVersion <= 1, "OleHelper::importStdFont - wrong version" );
+ return !rInStrm.isEof() && (nVersion <= 1);
}
/*static*/ bool OleHelper::importStdPic( StreamDataSequence& orGraphicData,
BinaryInputStream& rInStrm, bool bWithGuid )
{
- if( bWithGuid )
- {
- bool bIsStdPic = importGuid( rInStrm ).equalsAscii( OLE_GUID_STDPIC );
- OSL_ENSURE( bIsStdPic, "OleHelper::importStdPic - unexpected header
GUID, expected StdPic" );
- if( !bIsStdPic )
- return false;
- }
-
- sal_uInt32 nStdPicId;
- sal_Int32 nBytes;
- rInStrm >> nStdPicId >> nBytes;
- OSL_ENSURE( nStdPicId == OLE_STDPIC_ID, "OleHelper::importStdPic -
unexpected header version" );
- return !rInStrm.isEof() && (nStdPicId == OLE_STDPIC_ID) && (nBytes > 0) &&
(rInStrm.readData( orGraphicData, nBytes ) == nBytes);
+ if( bWithGuid )
+ {
+ bool bIsStdPic = importGuid( rInStrm ).equalsAscii(
OLE_GUID_STDPIC );
+ OSL_ENSURE( bIsStdPic, "OleHelper::importStdPic - unexpected
header GUID, expected StdPic" );
+ if( !bIsStdPic )
+ return false;
+ }
+
+ sal_uInt32 nStdPicId;
+ sal_Int32 nBytes;
+ rInStrm >> nStdPicId >> nBytes;
+ OSL_ENSURE( nStdPicId == OLE_STDPIC_ID, "OleHelper::importStdPic -
unexpected header version" );
+ return !rInStrm.isEof() && (nStdPicId == OLE_STDPIC_ID) && (nBytes > 0)
&& (rInStrm.readData( orGraphicData, nBytes ) == nBytes);
}
/*static*/ bool OleHelper::importStdHlink( StdHlinkInfo& orHlinkInfo,
BinaryInputStream& rInStrm, bool bWithGuid )
{
- if( bWithGuid )
- {
- bool bIsStdHlink = importGuid( rInStrm ).equalsAscii(
OLE_GUID_STDHLINK );
- OSL_ENSURE( bIsStdHlink, "OleHelper::importStdHlink - unexpected
header GUID, expected StdHlink" );
- if( !bIsStdHlink )
- return false;
- }
-
- sal_uInt32 nVersion, nFlags;
- rInStrm >> nVersion >> nFlags;
- OSL_ENSURE( nVersion == OLE_STDHLINK_VERSION, "OleHelper::importStdHlink -
unexpected header version" );
- if( rInStrm.isEof() || (nVersion != OLE_STDHLINK_VERSION) )
- return false;
-
- // display string
- if( getFlag( nFlags, OLE_STDHLINK_HASDISPLAY ) )
- orHlinkInfo.maDisplay = lclReadStdHlinkString( rInStrm, true );
- // frame string
- if( getFlag( nFlags, OLE_STDHLINK_HASFRAME ) )
- orHlinkInfo.maFrame = lclReadStdHlinkString( rInStrm, true );
-
- // target
- if( getFlag( nFlags, OLE_STDHLINK_HASTARGET ) )
- {
- if( getFlag( nFlags, OLE_STDHLINK_ASSTRING ) )
- {
- OSL_ENSURE( getFlag( nFlags, OLE_STDHLINK_ABSOLUTE ),
"OleHelper::importStdHlink - link not absolute" );
- orHlinkInfo.maTarget = lclReadStdHlinkString( rInStrm, true );
- }
- else // hyperlink moniker
- {
- OUString aGuid = importGuid( rInStrm );
- if( aGuid.equalsAscii( OLE_GUID_FILEMONIKER ) )
- {
- // file name, maybe relative and with directory up-count
- sal_Int16 nUpLevels;
- rInStrm >> nUpLevels;
- OSL_ENSURE( (nUpLevels == 0) || !getFlag( nFlags,
OLE_STDHLINK_ABSOLUTE ), "OleHelper::importStdHlink - absolute filename with
upcount" );
- orHlinkInfo.maTarget = lclReadStdHlinkString( rInStrm, false );
- rInStrm.skip( 24 );
- sal_Int32 nBytes = rInStrm.readInt32();
- if( nBytes > 0 )
- {
- sal_Int64 nEndPos = rInStrm.tell() + ::std::max< sal_Int32
>( nBytes, 0 );
- sal_uInt16 nChars = getLimitedValue< sal_uInt16, sal_Int32
>( rInStrm.readInt32() / 2, 0, SAL_MAX_UINT16 );
- rInStrm.skip( 2 ); // key value
- orHlinkInfo.maTarget = rInStrm.readUnicodeArray( nChars );
// NOT null terminated
- rInStrm.seek( nEndPos );
- }
- if( !getFlag( nFlags, OLE_STDHLINK_ABSOLUTE ) )
- for( sal_Int16 nLevel = 0; nLevel < nUpLevels; ++nLevel )
- orHlinkInfo.maTarget = CREATE_OUSTRING( "../" ) +
orHlinkInfo.maTarget;
- }
- else if( aGuid.equalsAscii( OLE_GUID_URLMONIKER ) )
- {
- // URL, maybe relative and with leading '../'
- sal_Int32 nBytes = rInStrm.readInt32();
- sal_Int64 nEndPos = rInStrm.tell() + ::std::max< sal_Int32 >(
nBytes, 0 );
- orHlinkInfo.maTarget = rInStrm.readNulUnicodeArray();
- rInStrm.seek( nEndPos );
- }
- else
- {
- OSL_ENSURE( false, "OleHelper::importStdHlink - unsupported
hyperlink moniker" );
- return false;
- }
- }
- }
-
- // target location
- if( getFlag( nFlags, OLE_STDHLINK_HASLOCATION ) )
- orHlinkInfo.maLocation = lclReadStdHlinkString( rInStrm, true );
-
- return !rInStrm.isEof();
+ if( bWithGuid )
+ {
+ bool bIsStdHlink = importGuid( rInStrm ).equalsAscii(
OLE_GUID_STDHLINK );
+ OSL_ENSURE( bIsStdHlink, "OleHelper::importStdHlink -
unexpected header GUID, expected StdHlink" );
+ if( !bIsStdHlink )
+ return false;
+ }
+
+ sal_uInt32 nVersion, nFlags;
+ rInStrm >> nVersion >> nFlags;
+ OSL_ENSURE( nVersion == OLE_STDHLINK_VERSION,
"OleHelper::importStdHlink - unexpected header version" );
+ if( rInStrm.isEof() || (nVersion != OLE_STDHLINK_VERSION) )
+ return false;
+
+ // display string
+ if( getFlag( nFlags, OLE_STDHLINK_HASDISPLAY ) )
+ orHlinkInfo.maDisplay = lclReadStdHlinkString( rInStrm, true );
+ // frame string
+ if( getFlag( nFlags, OLE_STDHLINK_HASFRAME ) )
+ orHlinkInfo.maFrame = lclReadStdHlinkString( rInStrm, true );
+
+ // target
+ if( getFlag( nFlags, OLE_STDHLINK_HASTARGET ) )
+ {
+ if( getFlag( nFlags, OLE_STDHLINK_ASSTRING ) )
+ {
+ OSL_ENSURE( getFlag( nFlags, OLE_STDHLINK_ABSOLUTE ),
"OleHelper::importStdHlink - link not absolute" );
+ orHlinkInfo.maTarget = lclReadStdHlinkString( rInStrm,
true );
+ }
+ else // hyperlink moniker
+ {
+ OUString aGuid = importGuid( rInStrm );
+ if( aGuid.equalsAscii( OLE_GUID_FILEMONIKER ) )
+ {
+ // file name, maybe relative and with directory
up-count
+ sal_Int16 nUpLevels;
+ rInStrm >> nUpLevels;
+ OSL_ENSURE( (nUpLevels == 0) || !getFlag(
nFlags, OLE_STDHLINK_ABSOLUTE ), "OleHelper::importStdHlink - absolute filename
with upcount" );
+ orHlinkInfo.maTarget = lclReadStdHlinkString(
rInStrm, false );
+ rInStrm.skip( 24 );
+ sal_Int32 nBytes = rInStrm.readInt32();
+ if( nBytes > 0 )
+ {
+ sal_Int64 nEndPos = rInStrm.tell() +
::std::max< sal_Int32 >( nBytes, 0 );
+ sal_uInt16 nChars = getLimitedValue<
sal_uInt16, sal_Int32 >( rInStrm.readInt32() / 2, 0, SAL_MAX_UINT16 );
+ rInStrm.skip( 2 ); // key value
+ orHlinkInfo.maTarget =
rInStrm.readUnicodeArray( nChars ); // NOT null terminated
+ rInStrm.seek( nEndPos );
+ }
+ if( !getFlag( nFlags, OLE_STDHLINK_ABSOLUTE ) )
+ for( sal_Int16 nLevel = 0; nLevel <
nUpLevels; ++nLevel )
+ orHlinkInfo.maTarget =
CREATE_OUSTRING( "../" ) + orHlinkInfo.maTarget;
+ }
+ else if( aGuid.equalsAscii( OLE_GUID_URLMONIKER ) )
+ {
+ // URL, maybe relative and with leading '../'
+ sal_Int32 nBytes = rInStrm.readInt32();
+ sal_Int64 nEndPos = rInStrm.tell() +
::std::max< sal_Int32 >( nBytes, 0 );
+ orHlinkInfo.maTarget =
rInStrm.readNulUnicodeArray();
+ rInStrm.seek( nEndPos );
+ }
+ else
+ {
+ OSL_ENSURE( false, "OleHelper::importStdHlink -
unsupported hyperlink moniker" );
+ return false;
+ }
+ }
+ }
+
+ // target location
+ if( getFlag( nFlags, OLE_STDHLINK_HASLOCATION ) )
+ orHlinkInfo.maLocation = lclReadStdHlinkString( rInStrm, true );
+
+ return !rInStrm.isEof();
}
-// ============================================================================
-
} // namespace ole
} // namespace oox
+
+/* vim: set noet sw=4 ts=4: */
diff --git a/main/oox/source/xls/drawingbase.cxx
b/main/oox/source/xls/drawingbase.cxx
index 0aa1ae7940..f4bdddd2f5 100644
--- a/main/oox/source/xls/drawingbase.cxx
+++ b/main/oox/source/xls/drawingbase.cxx
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* 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
@@ -7,20 +7,18 @@
* 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
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
-
#include "oox/xls/drawingbase.hxx"
#include <com/sun/star/awt/Rectangle.hpp>
@@ -31,39 +29,35 @@
namespace oox {
namespace xls {
-// ============================================================================
-
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::table;
using namespace ::oox::drawingml;
using ::rtl::OUString;
-// ============================================================================
-
namespace {
/** Converts the passed 32-bit integer value from 1/100 mm to EMUs. */
inline sal_Int64 lclHmmToEmu( sal_Int32 nValue )
{
- return (nValue < 0) ? -1 : convertHmmToEmu( nValue );
+ return (nValue < 0) ? -1 : convertHmmToEmu( nValue );
}
/** Converts the passed 64-bit integer value from EMUs to 1/100 mm. */
inline sal_Int32 lclEmuToHmm( sal_Int64 nValue )
{
- return (nValue < 0) ? -1 : convertEmuToHmm( nValue );
+ return (nValue < 0) ? -1 : convertEmuToHmm( nValue );
}
/** Reads the cell anchor model from a BIFF or DFF stream. */
BinaryInputStream& operator>>( BinaryInputStream& rStrm, CellAnchorModel&
rModel )
{
- // all members are given as 16-bit unsigned values
- rModel.mnCol = rStrm.readuInt16();
- rModel.mnColOffset = rStrm.readuInt16();
- rModel.mnRow = rStrm.readuInt16();
- rModel.mnRowOffset = rStrm.readuInt16();
- return rStrm;
+ // all members are given as 16-bit unsigned values
+ rModel.mnCol = rStrm.readuInt16();
+ rModel.mnColOffset = rStrm.readuInt16();
+ rModel.mnRow = rStrm.readuInt16();
+ rModel.mnRowOffset = rStrm.readuInt16();
+ return rStrm;
}
} // namespace
@@ -71,250 +65,250 @@ BinaryInputStream& operator>>( BinaryInputStream& rStrm,
CellAnchorModel& rModel
// ============================================================================
CellAnchorModel::CellAnchorModel() :
- mnCol( -1 ),
- mnRow( -1 ),
- mnColOffset( 0 ),
- mnRowOffset( 0 )
+ mnCol( -1 ),
+ mnRow( -1 ),
+ mnColOffset( 0 ),
+ mnRowOffset( 0 )
{
}
// ----------------------------------------------------------------------------
AnchorClientDataModel::AnchorClientDataModel() :
- mbLocksWithSheet( true ),
- mbPrintsWithSheet( true )
+ mbLocksWithSheet( true ),
+ mbPrintsWithSheet( true )
{
}
// ============================================================================
ShapeAnchor::ShapeAnchor( const WorksheetHelper& rHelper ) :
- WorksheetHelper( rHelper ),
- meAnchorType( ANCHOR_INVALID ),
- meCellAnchorType( CELLANCHOR_EMU ),
- mnEditAs( XML_twoCell )
+ WorksheetHelper( rHelper ),
+ meAnchorType( ANCHOR_INVALID ),
+ meCellAnchorType( CELLANCHOR_EMU ),
+ mnEditAs( XML_twoCell )
{
}
void ShapeAnchor::importAnchor( sal_Int32 nElement, const AttributeList&
rAttribs )
{
- switch( nElement )
- {
- case XDR_TOKEN( absoluteAnchor ):
- meAnchorType = ANCHOR_ABSOLUTE;
- break;
- case XDR_TOKEN( oneCellAnchor ):
- meAnchorType = ANCHOR_ONECELL;
- break;
- case XDR_TOKEN( twoCellAnchor ):
- meAnchorType = ANCHOR_TWOCELL;
- mnEditAs = rAttribs.getToken( XML_editAs, XML_twoCell );
- break;
- default:
- OSL_ENSURE( false, "ShapeAnchor::importAnchor - unexpected
element" );
- }
- meCellAnchorType = CELLANCHOR_EMU;
+ switch( nElement )
+ {
+ case XDR_TOKEN( absoluteAnchor ):
+ meAnchorType = ANCHOR_ABSOLUTE;
+ break;
+ case XDR_TOKEN( oneCellAnchor ):
+ meAnchorType = ANCHOR_ONECELL;
+ break;
+ case XDR_TOKEN( twoCellAnchor ):
+ meAnchorType = ANCHOR_TWOCELL;
+ mnEditAs = rAttribs.getToken( XML_editAs, XML_twoCell );
+ break;
+ default:
+ OSL_ENSURE( false, "ShapeAnchor::importAnchor -
unexpected element" );
+ }
+ meCellAnchorType = CELLANCHOR_EMU;
}
void ShapeAnchor::importPos( const AttributeList& rAttribs )
{
- OSL_ENSURE( meAnchorType == ANCHOR_ABSOLUTE, "ShapeAnchor::importPos -
unexpected 'xdr:pos' element" );
- maPos.X = rAttribs.getHyper( XML_x, 0 );
- maPos.Y = rAttribs.getHyper( XML_y, 0 );
+ OSL_ENSURE( meAnchorType == ANCHOR_ABSOLUTE, "ShapeAnchor::importPos -
unexpected 'xdr:pos' element" );
+ maPos.X = rAttribs.getHyper( XML_x, 0 );
+ maPos.Y = rAttribs.getHyper( XML_y, 0 );
}
void ShapeAnchor::importExt( const AttributeList& rAttribs )
{
- OSL_ENSURE( (meAnchorType == ANCHOR_ABSOLUTE) || (meAnchorType ==
ANCHOR_ONECELL), "ShapeAnchor::importExt - unexpected 'xdr:ext' element" );
- maSize.Width = rAttribs.getHyper( XML_cx, 0 );
- maSize.Height = rAttribs.getHyper( XML_cy, 0 );
+ OSL_ENSURE( (meAnchorType == ANCHOR_ABSOLUTE) || (meAnchorType ==
ANCHOR_ONECELL), "ShapeAnchor::importExt - unexpected 'xdr:ext' element" );
+ maSize.Width = rAttribs.getHyper( XML_cx, 0 );
+ maSize.Height = rAttribs.getHyper( XML_cy, 0 );
}
void ShapeAnchor::importClientData( const AttributeList& rAttribs )
{
- maClientData.mbLocksWithSheet = rAttribs.getBool( XML_fLocksWithSheet,
true );
- maClientData.mbPrintsWithSheet = rAttribs.getBool( XML_fPrintsWithSheet,
true );
+ maClientData.mbLocksWithSheet = rAttribs.getBool( XML_fLocksWithSheet,
true );
+ maClientData.mbPrintsWithSheet = rAttribs.getBool(
XML_fPrintsWithSheet, true );
}
void ShapeAnchor::setCellPos( sal_Int32 nElement, sal_Int32 nParentContext,
const OUString& rValue )
{
- CellAnchorModel* pCellAnchor = 0;
- switch( nParentContext )
- {
- case XDR_TOKEN( from ):
- OSL_ENSURE( (meAnchorType == ANCHOR_ONECELL) || (meAnchorType ==
ANCHOR_TWOCELL), "ShapeAnchor::setCellPos - unexpected 'xdr:from' element" );
- pCellAnchor = &maFrom;
- break;
- case XDR_TOKEN( to ):
- OSL_ENSURE( meAnchorType == ANCHOR_TWOCELL,
"ShapeAnchor::setCellPos - unexpected 'xdr:to' element" );
- pCellAnchor = &maTo;
- break;
- default:
- OSL_ENSURE( false, "ShapeAnchor::setCellPos - unexpected parent
element" );
- }
- if( pCellAnchor ) switch( nElement )
- {
- case XDR_TOKEN( col ): pCellAnchor->mnCol = rValue.toInt32();
break;
- case XDR_TOKEN( row ): pCellAnchor->mnRow = rValue.toInt32();
break;
- case XDR_TOKEN( colOff ): pCellAnchor->mnColOffset =
rValue.toInt64(); break;
- case XDR_TOKEN( rowOff ): pCellAnchor->mnRowOffset =
rValue.toInt64(); break;
- default: OSL_ENSURE( false, "ShapeAnchor::setCellPos - unexpected
element" );
- }
+ CellAnchorModel* pCellAnchor = 0;
+ switch( nParentContext )
+ {
+ case XDR_TOKEN( from ):
+ OSL_ENSURE( (meAnchorType == ANCHOR_ONECELL) ||
(meAnchorType == ANCHOR_TWOCELL), "ShapeAnchor::setCellPos - unexpected
'xdr:from' element" );
+ pCellAnchor = &maFrom;
+ break;
+ case XDR_TOKEN( to ):
+ OSL_ENSURE( meAnchorType == ANCHOR_TWOCELL,
"ShapeAnchor::setCellPos - unexpected 'xdr:to' element" );
+ pCellAnchor = &maTo;
+ break;
+ default:
+ OSL_ENSURE( false, "ShapeAnchor::setCellPos -
unexpected parent element" );
+ }
+ if( pCellAnchor ) switch( nElement )
+ {
+ case XDR_TOKEN( col ): pCellAnchor->mnCol =
rValue.toInt32(); break;
+ case XDR_TOKEN( row ): pCellAnchor->mnRow =
rValue.toInt32(); break;
+ case XDR_TOKEN( colOff ): pCellAnchor->mnColOffset =
rValue.toInt64(); break;
+ case XDR_TOKEN( rowOff ): pCellAnchor->mnRowOffset =
rValue.toInt64(); break;
+ default: OSL_ENSURE( false, "ShapeAnchor::setCellPos -
unexpected element" );
+ }
}
void ShapeAnchor::importVmlAnchor( const OUString& rAnchor )
{
- meAnchorType = ANCHOR_TWOCELL; /// VML uses two-cell anchors only
- meCellAnchorType = CELLANCHOR_PIXEL; /// VML uses screen pixels for
offset values
-
- ::std::vector< OUString > aTokens;
- sal_Int32 nIndex = 0;
- while( nIndex >= 0 )
- aTokens.push_back( rAnchor.getToken( 0, ',', nIndex ).trim() );
-
- OSL_ENSURE( aTokens.size() >= 8, "ShapeAnchor::importVmlAnchor - missing
anchor tokens" );
- if( aTokens.size() >= 8 )
- {
- maFrom.mnCol = aTokens[ 0 ].toInt32();
- maFrom.mnColOffset = aTokens[ 1 ].toInt32();
- maFrom.mnRow = aTokens[ 2 ].toInt32();
- maFrom.mnRowOffset = aTokens[ 3 ].toInt32();
- maTo.mnCol = aTokens[ 4 ].toInt32();
- maTo.mnColOffset = aTokens[ 5 ].toInt32();
- maTo.mnRow = aTokens[ 6 ].toInt32();
- maTo.mnRowOffset = aTokens[ 7 ].toInt32();
- }
+ meAnchorType = ANCHOR_TWOCELL; // VML uses two-cell anchors
only
+ meCellAnchorType = CELLANCHOR_PIXEL; // VML uses screen pixels for
offset values
+
+ ::std::vector< OUString > aTokens;
+ sal_Int32 nIndex = 0;
+ while( nIndex >= 0 )
+ aTokens.push_back( rAnchor.getToken( 0, ',', nIndex ).trim() );
+
+ OSL_ENSURE( aTokens.size() >= 8, "ShapeAnchor::importVmlAnchor -
missing anchor tokens" );
+ if( aTokens.size() >= 8 )
+ {
+ maFrom.mnCol = aTokens[ 0 ].toInt32();
+ maFrom.mnColOffset = aTokens[ 1 ].toInt32();
+ maFrom.mnRow = aTokens[ 2 ].toInt32();
+ maFrom.mnRowOffset = aTokens[ 3 ].toInt32();
+ maTo.mnCol = aTokens[ 4 ].toInt32();
+ maTo.mnColOffset = aTokens[ 5 ].toInt32();
+ maTo.mnRow = aTokens[ 6 ].toInt32();
+ maTo.mnRowOffset = aTokens[ 7 ].toInt32();
+ }
}
void ShapeAnchor::importBiffAnchor( BinaryInputStream& rStrm )
{
- meAnchorType = ANCHOR_TWOCELL; /// BIFF/DFF use two-cell anchors
only
- meCellAnchorType = CELLANCHOR_COLROW; /// BIFF/DFF use fraction of
column/row for offset values
- rStrm >> maFrom >> maTo;
+ meAnchorType = ANCHOR_TWOCELL; // BIFF/DFF use two-cell
anchors only
+ meCellAnchorType = CELLANCHOR_COLROW; // BIFF/DFF use fraction of
column/row for offset values
+ rStrm >> maFrom >> maTo;
}
EmuRectangle ShapeAnchor::calcAnchorRectEmu( const Size& rPageSizeHmm ) const
{
- AddressConverter& rAddrConv = getAddressConverter();
- EmuSize aPageSize( lclHmmToEmu( rPageSizeHmm.Width ), lclHmmToEmu(
rPageSizeHmm.Height ) );
- EmuRectangle aAnchorRect( -1, -1, -1, -1 );
-
- // calculate shape position
- switch( meAnchorType )
- {
- case ANCHOR_ABSOLUTE:
- OSL_ENSURE( maPos.isValid(), "ShapeAnchor::calcAnchorRectEmu -
invalid position" );
- if( maPos.isValid() && (maPos.X < aPageSize.Width) && (maPos.Y <
aPageSize.Height) )
- aAnchorRect.setPos( maPos );
- break;
- case ANCHOR_ONECELL:
- case ANCHOR_TWOCELL:
- OSL_ENSURE( maFrom.isValid(), "ShapeAnchor::calcAnchorRectEmu -
invalid position" );
- if( maFrom.isValid() && rAddrConv.checkCol( maFrom.mnCol, true )
&& rAddrConv.checkRow( maFrom.mnRow, true ) )
- {
- EmuPoint aPoint = calcCellAnchorEmu( maFrom );
- if( (aPoint.X < aPageSize.Width) && (aPoint.Y <
aPageSize.Height) )
- aAnchorRect.setPos( aPoint );
- }
- break;
- case ANCHOR_INVALID:
- OSL_ENSURE( false, "ShapeAnchor::calcAnchorRectEmu - invalid
anchor" );
- break;
- }
-
- // calculate shape size
- if( (aAnchorRect.X >= 0) && (aAnchorRect.Y >= 0) ) switch( meAnchorType )
- {
- case ANCHOR_ABSOLUTE:
- case ANCHOR_ONECELL:
- OSL_ENSURE( maSize.isValid(), "ShapeAnchor::calcAnchorRectEmu -
invalid size" );
- if( maSize.isValid() )
- {
- aAnchorRect.Width = ::std::min< sal_Int64 >( maSize.Width,
aPageSize.Width - aAnchorRect.X );
- aAnchorRect.Height = ::std::min< sal_Int64 >( maSize.Height,
aPageSize.Height - aAnchorRect.Y );
- }
- break;
- case ANCHOR_TWOCELL:
- OSL_ENSURE( maTo.isValid(), "ShapeAnchor::calcAnchorRectEmu -
invalid position" );
- if( maTo.isValid() )
- {
- /* Pass a valid cell address to calcCellAnchorEmu(), otherwise
- nothing useful is returned, even if either row or column
is valid. */
- CellAddress aToCell = rAddrConv.createValidCellAddress(
BinAddress( maTo.mnCol, maTo.mnRow ), getSheetIndex(), true );
- CellAnchorModel aValidTo = maTo;
- aValidTo.mnCol = aToCell.Column;
- aValidTo.mnRow = aToCell.Row;
- EmuPoint aPoint = calcCellAnchorEmu( aValidTo );
- // width (if column index is valid, use the calculated offset,
otherwise stretch to maximum available X position)
- aAnchorRect.Width = aPageSize.Width - aAnchorRect.X;
- if( aToCell.Column == maTo.mnCol )
- aAnchorRect.Width = ::std::min< sal_Int64 >( aPoint.X -
aAnchorRect.X + 1, aAnchorRect.Width );
- // height (if row index is valid, use the calculated offset,
otherwise stretch to maximum available Y position)
- aAnchorRect.Height = aPageSize.Height - aAnchorRect.Y;
- if( aToCell.Row == maTo.mnRow )
- aAnchorRect.Height = ::std::min< sal_Int64 >( aPoint.Y -
aAnchorRect.Y + 1, aAnchorRect.Height );
- }
- break;
- case ANCHOR_INVALID:
- break;
- }
-
- // add 0.75 mm (27,000 EMUs) in X direction to correct display error
- if( aAnchorRect.X >= 0 )
- aAnchorRect.X += 27000;
- // remove 0.25 mm (9,000 EMUs) in Y direction to correct display error
- if( aAnchorRect.Y >= 9000 )
- aAnchorRect.Y -= 9000;
-
- return aAnchorRect;
+ AddressConverter& rAddrConv = getAddressConverter();
+ EmuSize aPageSize( lclHmmToEmu( rPageSizeHmm.Width ), lclHmmToEmu(
rPageSizeHmm.Height ) );
+ EmuRectangle aAnchorRect( -1, -1, -1, -1 );
+
+ // calculate shape position
+ switch( meAnchorType )
+ {
+ case ANCHOR_ABSOLUTE:
+ OSL_ENSURE( maPos.isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid position" );
+ if( maPos.isValid() && (maPos.X < aPageSize.Width) &&
(maPos.Y < aPageSize.Height) )
+ aAnchorRect.setPos( maPos );
+ break;
+ case ANCHOR_ONECELL:
+ case ANCHOR_TWOCELL:
+ OSL_ENSURE( maFrom.isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid position" );
+ if( maFrom.isValid() && rAddrConv.checkCol(
maFrom.mnCol, true ) && rAddrConv.checkRow( maFrom.mnRow, true ) )
+ {
+ EmuPoint aPoint = calcCellAnchorEmu( maFrom );
+ if( (aPoint.X < aPageSize.Width) && (aPoint.Y <
aPageSize.Height) )
+ aAnchorRect.setPos( aPoint );
+ }
+ break;
+ case ANCHOR_INVALID:
+ OSL_ENSURE( false, "ShapeAnchor::calcAnchorRectEmu -
invalid anchor" );
+ break;
+ }
+
+ // calculate shape size
+ if( (aAnchorRect.X >= 0) && (aAnchorRect.Y >= 0) ) switch( meAnchorType
)
+ {
+ case ANCHOR_ABSOLUTE:
+ case ANCHOR_ONECELL:
+ OSL_ENSURE( maSize.isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid size" );
+ if( maSize.isValid() )
+ {
+ aAnchorRect.Width = ::std::min< sal_Int64 >(
maSize.Width, aPageSize.Width - aAnchorRect.X );
+ aAnchorRect.Height = ::std::min< sal_Int64 >(
maSize.Height, aPageSize.Height - aAnchorRect.Y );
+ }
+ break;
+ case ANCHOR_TWOCELL:
+ OSL_ENSURE( maTo.isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid position" );
+ if( maTo.isValid() )
+ {
+ /* Pass a valid cell address to
calcCellAnchorEmu(), otherwise
+ nothing useful is returned, even if
either row or column is valid. */
+ CellAddress aToCell =
rAddrConv.createValidCellAddress( BinAddress( maTo.mnCol, maTo.mnRow ),
getSheetIndex(), true );
+ CellAnchorModel aValidTo = maTo;
+ aValidTo.mnCol = aToCell.Column;
+ aValidTo.mnRow = aToCell.Row;
+ EmuPoint aPoint = calcCellAnchorEmu( aValidTo );
+ // width (if column index is valid, use the
calculated offset, otherwise stretch to maximum available X position)
+ aAnchorRect.Width = aPageSize.Width -
aAnchorRect.X;
+ if( aToCell.Column == maTo.mnCol )
+ aAnchorRect.Width = ::std::min<
sal_Int64 >( aPoint.X - aAnchorRect.X + 1, aAnchorRect.Width );
+ // height (if row index is valid, use the
calculated offset, otherwise stretch to maximum available Y position)
+ aAnchorRect.Height = aPageSize.Height -
aAnchorRect.Y;
+ if( aToCell.Row == maTo.mnRow )
+ aAnchorRect.Height = ::std::min<
sal_Int64 >( aPoint.Y - aAnchorRect.Y + 1, aAnchorRect.Height );
+ }
+ break;
+ case ANCHOR_INVALID:
+ break;
+ }
+
+ // add 0.75 mm (27,000 EMUs) in X direction to correct display error
+ if( aAnchorRect.X >= 0 )
+ aAnchorRect.X += 27000;
+ // remove 0.25 mm (9,000 EMUs) in Y direction to correct display error
+ if( aAnchorRect.Y >= 9000 )
+ aAnchorRect.Y -= 9000;
+
+ return aAnchorRect;
}
Rectangle ShapeAnchor::calcAnchorRectHmm( const Size& rPageSizeHmm ) const
{
- EmuRectangle aAnchorRect = calcAnchorRectEmu( rPageSizeHmm );
- return Rectangle( lclEmuToHmm( aAnchorRect.X ), lclEmuToHmm( aAnchorRect.Y
), lclEmuToHmm( aAnchorRect.Width ), lclEmuToHmm( aAnchorRect.Height ) );
+ EmuRectangle aAnchorRect = calcAnchorRectEmu( rPageSizeHmm );
+ return Rectangle( lclEmuToHmm( aAnchorRect.X ), lclEmuToHmm(
aAnchorRect.Y ), lclEmuToHmm( aAnchorRect.Width ), lclEmuToHmm(
aAnchorRect.Height ) );
}
// private --------------------------------------------------------------------
EmuPoint ShapeAnchor::calcCellAnchorEmu( const CellAnchorModel& rModel ) const
{
- // calculate position of top-left edge of the cell
- Point aPoint = getCellPosition( rModel.mnCol, rModel.mnRow );
- EmuPoint aEmuPoint( lclHmmToEmu( aPoint.X ), lclHmmToEmu( aPoint.Y ) );
-
- // add the offset inside the cell
- switch( meCellAnchorType )
- {
- case CELLANCHOR_EMU:
- aEmuPoint.X += rModel.mnColOffset;
- aEmuPoint.Y += rModel.mnRowOffset;
- break;
-
- case CELLANCHOR_PIXEL:
- {
- const UnitConverter& rUnitConv = getUnitConverter();
- aEmuPoint.X += static_cast< sal_Int64 >( rUnitConv.scaleValue(
static_cast< double >( rModel.mnColOffset ), UNIT_SCREENX, UNIT_EMU ) );
- aEmuPoint.Y += static_cast< sal_Int64 >( rUnitConv.scaleValue(
static_cast< double >( rModel.mnRowOffset ), UNIT_SCREENY, UNIT_EMU ) );
- }
- break;
-
- case CELLANCHOR_COLROW:
- {
- Size aCellSize = getCellSize( rModel.mnCol, rModel.mnRow );
- EmuSize aEmuSize( lclHmmToEmu( aCellSize.Width ), lclHmmToEmu(
aCellSize.Height ) );
- // X offset is given in 1/1024 of column width
- aEmuPoint.X += static_cast< sal_Int64 >( aEmuSize.Width *
getLimitedValue< double >( static_cast< double >( rModel.mnColOffset ) /
1024.0, 0.0, 1.0 ) + 0.5 );
- // Y offset is given in 1/256 of row height
- aEmuPoint.Y += static_cast< sal_Int64 >( aEmuSize.Height *
getLimitedValue< double >( static_cast< double >( rModel.mnRowOffset ) / 256.0,
0.0, 1.0 ) + 0.5 );
- }
- break;
- }
-
- return aEmuPoint;
+ // calculate position of top-left edge of the cell
+ Point aPoint = getCellPosition( rModel.mnCol, rModel.mnRow );
+ EmuPoint aEmuPoint( lclHmmToEmu( aPoint.X ), lclHmmToEmu( aPoint.Y ) );
+
+ // add the offset inside the cell
+ switch( meCellAnchorType )
+ {
+ case CELLANCHOR_EMU:
+ aEmuPoint.X += rModel.mnColOffset;
+ aEmuPoint.Y += rModel.mnRowOffset;
+ break;
+
+ case CELLANCHOR_PIXEL:
+ {
+ const UnitConverter& rUnitConv = getUnitConverter();
+ aEmuPoint.X += static_cast< sal_Int64 >(
rUnitConv.scaleValue( static_cast< double >( rModel.mnColOffset ),
UNIT_SCREENX, UNIT_EMU ) );
+ aEmuPoint.Y += static_cast< sal_Int64 >(
rUnitConv.scaleValue( static_cast< double >( rModel.mnRowOffset ),
UNIT_SCREENY, UNIT_EMU ) );
+ }
+ break;
+
+ case CELLANCHOR_COLROW:
+ {
+ Size aCellSize = getCellSize( rModel.mnCol,
rModel.mnRow );
+ EmuSize aEmuSize( lclHmmToEmu( aCellSize.Width ),
lclHmmToEmu( aCellSize.Height ) );
+ // X offset is given in 1/1024 of column width
+ aEmuPoint.X += static_cast< sal_Int64 >( aEmuSize.Width
* getLimitedValue< double >( static_cast< double >( rModel.mnColOffset ) /
1024.0, 0.0, 1.0 ) + 0.5 );
+ // Y offset is given in 1/256 of row height
+ aEmuPoint.Y += static_cast< sal_Int64 >(
aEmuSize.Height * getLimitedValue< double >( static_cast< double >(
rModel.mnRowOffset ) / 256.0, 0.0, 1.0 ) + 0.5 );
+ }
+ break;
+ }
+
+ return aEmuPoint;
}
-// ============================================================================
-
} // namespace xls
} // namespace oox
+
+/* vim: set noet sw=4 ts=4: */
diff --git a/main/oox/source/xls/excelvbaproject.cxx
b/main/oox/source/xls/excelvbaproject.cxx
index 91073b0582..66206288eb 100644
--- a/main/oox/source/xls/excelvbaproject.cxx
+++ b/main/oox/source/xls/excelvbaproject.cxx
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* 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
@@ -7,20 +7,18 @@
* 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
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
-
#include "oox/xls/excelvbaproject.hxx"
#include <list>
@@ -54,8 +52,8 @@ using ::rtl::OUStringBuffer;
// ============================================================================
ExcelVbaProject::ExcelVbaProject( const Reference< XComponentContext >&
rxContext, const Reference< XSpreadsheetDocument >& rxDocument ) :
- ::oox::ole::VbaProject( rxContext, Reference< XModel >( rxDocument,
UNO_QUERY ), CREATE_OUSTRING( "Calc" ) ),
- mxDocument( rxDocument )
+ ::oox::ole::VbaProject( rxContext, Reference< XModel >( rxDocument,
UNO_QUERY ), CREATE_OUSTRING( "Calc" ) ),
+ mxDocument( rxDocument )
{
}
@@ -65,11 +63,11 @@ namespace {
struct SheetCodeNameInfo
{
- PropertySet maSheetProps; /// Property set of the sheet
without codename.
- OUString maPrefix; /// Prefix for the codename to be
generated.
+ PropertySet maSheetProps; // Property set of the sheet
without codename.
+ OUString maPrefix; // Prefix for the codename to
be generated.
- inline explicit SheetCodeNameInfo( PropertySet& rSheetProps, const
OUString& rPrefix ) :
- maSheetProps( rSheetProps ), maPrefix( rPrefix ) {}
+ inline explicit SheetCodeNameInfo( PropertySet& rSheetProps, const
OUString& rPrefix ) :
+ maSheetProps(
rSheetProps ), maPrefix( rPrefix ) {}
};
typedef ::std::set< OUString > CodeNameSet;
@@ -79,65 +77,67 @@ typedef ::std::list< SheetCodeNameInfo >
SheetCodeNameInfoList;
void ExcelVbaProject::prepareImport()
{
- /* Check if the sheets have imported codenames. Generate new unused
- codenames if not. */
- if( mxDocument.is() ) try
- {
- // collect existing codenames (do not use them when creating new
codenames)
- CodeNameSet aUsedCodeNames;
-
- // collect sheets without codenames
- SheetCodeNameInfoList aCodeNameInfos;
-
- // iterate over all imported sheets
- Reference< XEnumerationAccess > xSheetsEA( mxDocument->getSheets(),
UNO_QUERY_THROW );
- Reference< XEnumeration > xSheetsEnum( xSheetsEA->createEnumeration(),
UNO_SET_THROW );
- // own try/catch for every sheet
- while( xSheetsEnum->hasMoreElements() ) try
- {
- PropertySet aSheetProp( xSheetsEnum->nextElement() );
- OUString aCodeName;
- aSheetProp.getProperty( aCodeName, PROP_CodeName );
- if( aCodeName.getLength() > 0 )
- {
- aUsedCodeNames.insert( aCodeName );
- }
- else
- {
- // TODO: once we have chart sheets we need a switch/case on
sheet type ('SheetNNN' vs. 'ChartNNN')
- aCodeNameInfos.push_back( SheetCodeNameInfo( aSheetProp,
CREATE_OUSTRING( "Sheet" ) ) );
- }
- }
- catch( Exception& )
- {
- }
-
- // create new codenames if sheets do not have one
- for( SheetCodeNameInfoList::iterator aIt = aCodeNameInfos.begin(),
aEnd = aCodeNameInfos.end(); aIt != aEnd; ++aIt )
- {
- // search for an unused codename
- sal_Int32 nCounter = 1;
- OUString aCodeName;
- do
- {
- aCodeName = OUStringBuffer( aIt->maPrefix ).append( nCounter++
).makeStringAndClear();
- }
- while( aUsedCodeNames.count( aCodeName ) > 0 );
- aUsedCodeNames.insert( aCodeName );
-
- // set codename at sheet
- aIt->maSheetProps.setProperty( PROP_CodeName, aCodeName );
-
- // tell base class to create a dummy module
- addDummyModule( aCodeName, ModuleType::DOCUMENT );
- }
- }
- catch( Exception& )
- {
- }
+ /* Check if the sheets have imported codenames. Generate new unused
+ codenames if not. */
+ if( mxDocument.is() ) try
+ {
+ // collect existing codenames (do not use them when creating
new codenames)
+ CodeNameSet aUsedCodeNames;
+
+ // collect sheets without codenames
+ SheetCodeNameInfoList aCodeNameInfos;
+
+ // iterate over all imported sheets
+ Reference< XEnumerationAccess > xSheetsEA(
mxDocument->getSheets(), UNO_QUERY_THROW );
+ Reference< XEnumeration > xSheetsEnum(
xSheetsEA->createEnumeration(), UNO_SET_THROW );
+ // own try/catch for every sheet
+ while( xSheetsEnum->hasMoreElements() ) try
+ {
+ PropertySet aSheetProp( xSheetsEnum->nextElement() );
+ OUString aCodeName;
+ aSheetProp.getProperty( aCodeName, PROP_CodeName );
+ if( aCodeName.getLength() > 0 )
+ {
+ aUsedCodeNames.insert( aCodeName );
+ }
+ else
+ {
+ // TODO: once we have chart sheets we need a
switch/case on sheet type ('SheetNNN' vs. 'ChartNNN')
+ aCodeNameInfos.push_back( SheetCodeNameInfo(
aSheetProp, CREATE_OUSTRING( "Sheet" ) ) );
+ }
+ }
+ catch( Exception& )
+ {
+ }
+
+ // create new codenames if sheets do not have one
+ for( SheetCodeNameInfoList::iterator aIt =
aCodeNameInfos.begin(), aEnd = aCodeNameInfos.end(); aIt != aEnd; ++aIt )
+ {
+ // search for an unused codename
+ sal_Int32 nCounter = 1;
+ OUString aCodeName;
+ do
+ {
+ aCodeName = OUStringBuffer( aIt->maPrefix
).append( nCounter++ ).makeStringAndClear();
+ }
+ while( aUsedCodeNames.count( aCodeName ) > 0 );
+ aUsedCodeNames.insert( aCodeName );
+
+ // set codename at sheet
+ aIt->maSheetProps.setProperty( PROP_CodeName, aCodeName
);
+
+ // tell base class to create a dummy module
+ addDummyModule( aCodeName, ModuleType::DOCUMENT );
+ }
+ }
+ catch( Exception& )
+ {
+ }
}
// ============================================================================
} // namespace xls
} // namespace oox
+
+/* vim: set noet sw=4 ts=4: */
diff --git a/main/slideshow/source/engine/color.cxx
b/main/slideshow/source/engine/color.cxx
index 0ab5cd16a6..feaee4aa01 100644
--- a/main/slideshow/source/engine/color.cxx
+++ b/main/slideshow/source/engine/color.cxx
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* 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
@@ -7,20 +7,18 @@
* 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
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
-
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_slideshow.hxx"
@@ -32,434 +30,433 @@
#include <cmath> // for fmod
#include <algorithm>
-
namespace slideshow
{
- namespace internal
- {
- namespace
- {
- // helper functions
- // ================
-
- double getMagic( double nLuminance, double nSaturation )
- {
- if( nLuminance <= 0.5 )
- return nLuminance*(1.0 + nSaturation);
- else
- return nLuminance + nSaturation - nLuminance*nSaturation;
- }
-
- HSLColor::HSLTriple rgb2hsl( double nRed, double nGreen, double
nBlue )
- {
- // r,g,b in [0,1], h in [0,360] and s,l in [0,1]
- HSLColor::HSLTriple aRes;
-
- const double nMax( ::std::max(nRed,::std::max(nGreen, nBlue))
);
- const double nMin( ::std::min(nRed,::std::min(nGreen, nBlue))
);
-
- const double nDelta( nMax - nMin );
-
- aRes.mnLuminance = (nMax + nMin) / 2.0;
-
- if( ::basegfx::fTools::equalZero( nDelta ) )
- {
- aRes.mnSaturation = 0.0;
-
- // hue undefined (achromatic case)
- aRes.mnHue = 0.0;
- }
- else
- {
- aRes.mnSaturation = aRes.mnLuminance > 0.5 ?
- nDelta/(2.0-nMax-nMin) :
- nDelta/(nMax + nMin);
-
- if( nRed == nMax )
- aRes.mnHue = (nGreen - nBlue)/nDelta;
- else if( nGreen == nMax )
- aRes.mnHue = 2.0 + (nBlue - nRed)/nDelta;
- else if( nBlue == nMax )
- aRes.mnHue = 4.0 + (nRed - nGreen)/nDelta;
-
- aRes.mnHue *= 60.0;
-
- if( aRes.mnHue < 0.0 )
- aRes.mnHue += 360.0;
- }
-
- return aRes;
- }
-
- double hsl2rgbHelper( double nValue1, double nValue2, double nHue )
- {
- // clamp hue to [0,360]
- nHue = fmod( nHue, 360.0 );
-
- // cope with wrap-arounds
- if( nHue < 0.0 )
- nHue += 360.0;
-
- if( nHue < 60.0 )
- return nValue1 + (nValue2 - nValue1)*nHue/60.0;
- else if( nHue < 180.0 )
- return nValue2;
- else if( nHue < 240.0 )
- return nValue1 + (nValue2 - nValue1)*(240.0 - nHue)/60.0;
- else
- return nValue1;
- }
-
- RGBColor::RGBTriple hsl2rgb( double nHue, double nSaturation,
double nLuminance )
- {
- if( ::basegfx::fTools::equalZero( nSaturation ) )
- return RGBColor::RGBTriple(0.0, 0.0, nLuminance );
-
- const double nVal1( getMagic(nLuminance, nSaturation) );
- const double nVal2( 2.0*nLuminance - nVal1 );
-
- RGBColor::RGBTriple aRes;
-
- aRes.mnRed = hsl2rgbHelper( nVal2,
- nVal1,
- nHue + 120.0 );
- aRes.mnGreen = hsl2rgbHelper( nVal2,
- nVal1,
- nHue );
- aRes.mnBlue = hsl2rgbHelper( nVal2,
- nVal1,
- nHue - 120.0 );
-
- return aRes;
- }
-
- /// Truncate range of value to [0,1]
- double truncateRangeStd( double nVal )
- {
- return ::std::max( 0.0,
- ::std::min( 1.0,
- nVal ) );
- }
-
- /// Truncate range of value to [0,360]
- double truncateRangeHue( double nVal )
- {
- return ::std::max( 0.0,
- ::std::min( 360.0,
- nVal ) );
- }
-
- /// convert RGB color to sal_uInt8, truncate range appropriately
before
- sal_uInt8 colorToInt( double nCol )
- {
- return static_cast< sal_uInt8 >(
- ::basegfx::fround( truncateRangeStd( nCol ) * 255.0 ) );
- }
- }
-
-
-
- // HSLColor
- // ===============================================
-
- HSLColor::HSLTriple::HSLTriple() :
- mnHue(),
- mnSaturation(),
- mnLuminance()
- {
- }
-
- HSLColor::HSLTriple::HSLTriple( double nHue, double nSaturation,
double nLuminance ) :
- mnHue( nHue ),
- mnSaturation( nSaturation ),
- mnLuminance( nLuminance )
- {
- }
-
- HSLColor::HSLColor() :
- maHSLTriple( 0.0, 0.0, 0.0 ),
- mnMagicValue( getMagic( maHSLTriple.mnLuminance,
- maHSLTriple.mnSaturation ) )
- {
- }
-
- HSLColor::HSLColor( ::cppcanvas::Color::IntSRGBA nRGBColor ) :
- maHSLTriple( rgb2hsl( ::cppcanvas::getRed( nRGBColor ) / 255.0,
- ::cppcanvas::getGreen( nRGBColor ) / 255.0,
- ::cppcanvas::getBlue( nRGBColor ) / 255.0 )
),
- mnMagicValue( getMagic( maHSLTriple.mnLuminance,
- maHSLTriple.mnSaturation ) )
- {
- }
-
- HSLColor::HSLColor( double nHue, double nSaturation, double nLuminance
) :
- maHSLTriple( nHue, nSaturation, nLuminance ),
- mnMagicValue( getMagic( maHSLTriple.mnLuminance,
- maHSLTriple.mnSaturation ) )
- {
- }
-
- HSLColor::HSLColor( const RGBColor& rColor ) :
- maHSLTriple( rgb2hsl( truncateRangeStd( rColor.getRed() ),
- truncateRangeStd( rColor.getGreen() ),
- truncateRangeStd( rColor.getBlue() ) ) ),
- mnMagicValue( getMagic( maHSLTriple.mnLuminance,
- maHSLTriple.mnSaturation ) )
- {
- }
-
- double HSLColor::getHue() const
- {
- return maHSLTriple.mnHue;
- }
-
- double HSLColor::getSaturation() const
- {
- return maHSLTriple.mnSaturation;
- }
-
- double HSLColor::getLuminance() const
- {
- return maHSLTriple.mnLuminance;
- }
-
- double HSLColor::getRed() const
- {
- if( ::basegfx::fTools::equalZero( getSaturation() ) )
- return getLuminance();
-
- return hsl2rgbHelper( 2.0*getLuminance() - mnMagicValue,
- mnMagicValue,
- getHue() + 120.0 );
- }
-
- double HSLColor::getGreen() const
- {
- if( ::basegfx::fTools::equalZero( getSaturation() ) )
- return getLuminance();
-
- return hsl2rgbHelper( 2.0*getLuminance() - mnMagicValue,
- mnMagicValue,
- getHue() );
- }
-
- double HSLColor::getBlue() const
- {
- if( ::basegfx::fTools::equalZero( getSaturation() ) )
- return getLuminance();
-
- return hsl2rgbHelper( 2.0*getLuminance() - mnMagicValue,
- mnMagicValue,
- getHue() - 120.0 );
- }
-
- RGBColor HSLColor::getRGBColor() const
- {
- RGBColor::RGBTriple aColor( hsl2rgb( getHue(),
- getSaturation(),
- getLuminance() ) );
- return RGBColor( aColor.mnRed, aColor.mnGreen, aColor.mnBlue );
- }
-
- RGBColor::RGBColor(const RGBColor& rLHS)
- {
- maRGBTriple.mnRed = rLHS.getRed();
- maRGBTriple.mnGreen = rLHS.getGreen();
- maRGBTriple.mnBlue = rLHS.getBlue();
- }
-
- RGBColor& RGBColor::operator=( const RGBColor& rLHS ){
-
- maRGBTriple.mnRed = rLHS.getRed();
- maRGBTriple.mnGreen = rLHS.getGreen();
- maRGBTriple.mnBlue = rLHS.getBlue();
- return *this;
- }
-
- HSLColor operator+( const HSLColor& rLHS, const HSLColor& rRHS )
- {
- return HSLColor( rLHS.getHue() + rRHS.getHue(),
- rLHS.getSaturation() + rRHS.getSaturation(),
- rLHS.getLuminance() + rRHS.getLuminance() );
- }
-
- HSLColor operator*( const HSLColor& rLHS, const HSLColor& rRHS )
- {
- return HSLColor( rLHS.getHue() * rRHS.getHue(),
- rLHS.getSaturation() * rRHS.getSaturation(),
- rLHS.getLuminance() * rRHS.getLuminance() );
- }
-
- HSLColor operator*( double nFactor, const HSLColor& rRHS )
- {
- return HSLColor( nFactor * rRHS.getHue(),
- nFactor * rRHS.getSaturation(),
- nFactor * rRHS.getLuminance() );
- }
-
- HSLColor interpolate( const HSLColor& rFrom, const HSLColor& rTo,
double t, bool bCCW )
- {
- const double nFromHue( rFrom.getHue() );
- const double nToHue ( rTo.getHue() );
-
- double nHue=0.0;
-
- if( nFromHue <= nToHue && !bCCW )
- {
- // interpolate hue clockwise. That is, hue starts at
- // high values and ends at low ones. Therefore, we
- // must 'cross' the 360 degrees and start at low
- // values again (imagine the hues to lie on the
- // circle, where values above 360 degrees are mapped
- // back to [0,360)).
- nHue = (1.0-t)*(nFromHue + 360.0) + t*nToHue;
- }
- else if( nFromHue > nToHue && bCCW )
- {
- // interpolate hue counter-clockwise. That is, hue
- // starts at high values and ends at low
- // ones. Therefore, we must 'cross' the 360 degrees
- // and start at low values again (imagine the hues to
- // lie on the circle, where values above 360 degrees
- // are mapped back to [0,360)).
- nHue = (1.0-t)*nFromHue + t*(nToHue + 360.0);
- }
- else
- {
- // interpolate hue counter-clockwise. That is, hue
- // starts at low values and ends at high ones (imagine
- // the hue value as degrees on a circle, with
- // increasing values going counter-clockwise)
- nHue = (1.0-t)*nFromHue + t*nToHue;
- }
-
- return HSLColor( nHue,
- (1.0-t)*rFrom.getSaturation() +
t*rTo.getSaturation(),
- (1.0-t)*rFrom.getLuminance() +
t*rTo.getLuminance() );
- }
-
-
-
- // RGBColor
- // ===============================================
-
-
- RGBColor::RGBTriple::RGBTriple() :
- mnRed(),
- mnGreen(),
- mnBlue()
- {
- }
-
- RGBColor::RGBTriple::RGBTriple( double nRed, double nGreen, double
nBlue ) :
- mnRed( nRed ),
- mnGreen( nGreen ),
- mnBlue( nBlue )
- {
- }
-
- RGBColor::RGBColor() :
- maRGBTriple( 0.0, 0.0, 0.0 )
- {
- }
-
- RGBColor::RGBColor( ::cppcanvas::Color::IntSRGBA nRGBColor ) :
- maRGBTriple( ::cppcanvas::getRed( nRGBColor ) / 255.0,
- ::cppcanvas::getGreen( nRGBColor ) / 255.0,
- ::cppcanvas::getBlue( nRGBColor ) / 255.0 )
- {
- }
-
- RGBColor::RGBColor( double nRed, double nGreen, double nBlue ) :
- maRGBTriple( nRed, nGreen, nBlue )
- {
- }
-
- RGBColor::RGBColor( const HSLColor& rColor ) :
- maRGBTriple( hsl2rgb( truncateRangeHue( rColor.getHue() ),
- truncateRangeStd( rColor.getSaturation() ),
- truncateRangeStd( rColor.getLuminance() ) ) )
- {
- }
-
- double RGBColor::getHue() const
- {
- return rgb2hsl( getRed(),
- getGreen(),
- getBlue() ).mnHue;
- }
-
- double RGBColor::getSaturation() const
- {
- return rgb2hsl( getRed(),
- getGreen(),
- getBlue() ).mnSaturation;
- }
-
- double RGBColor::getLuminance() const
- {
- return rgb2hsl( getRed(),
- getGreen(),
- getBlue() ).mnLuminance;
- }
-
- double RGBColor::getRed() const
- {
- return maRGBTriple.mnRed;
- }
-
- double RGBColor::getGreen() const
- {
- return maRGBTriple.mnGreen;
- }
-
- double RGBColor::getBlue() const
- {
- return maRGBTriple.mnBlue;
- }
-
- HSLColor RGBColor::getHSLColor() const
- {
- HSLColor::HSLTriple aColor( rgb2hsl( getRed(),
- getGreen(),
- getBlue() ) );
- return HSLColor( aColor.mnHue, aColor.mnSaturation,
aColor.mnLuminance );
- }
-
- ::cppcanvas::Color::IntSRGBA RGBColor::getIntegerColor() const
- {
- return ::cppcanvas::makeColor( colorToInt( getRed() ),
- colorToInt( getGreen() ),
- colorToInt( getBlue() ),
- 255 );
- }
-
- RGBColor operator+( const RGBColor& rLHS, const RGBColor& rRHS )
- {
- return RGBColor( rLHS.getRed() + rRHS.getRed(),
- rLHS.getGreen() + rRHS.getGreen(),
- rLHS.getBlue() + rRHS.getBlue() );
- }
-
- RGBColor operator*( const RGBColor& rLHS, const RGBColor& rRHS )
- {
- return RGBColor( rLHS.getRed() * rRHS.getRed(),
- rLHS.getGreen() * rRHS.getGreen(),
- rLHS.getBlue() * rRHS.getBlue() );
- }
-
- RGBColor operator*( double nFactor, const RGBColor& rRHS )
- {
- return RGBColor( nFactor * rRHS.getRed(),
- nFactor * rRHS.getGreen(),
- nFactor * rRHS.getBlue() );
- }
-
- RGBColor interpolate( const RGBColor& rFrom, const RGBColor& rTo,
double t )
- {
- return RGBColor( (1.0-t)*rFrom.getRed() + t*rTo.getRed(),
- (1.0-t)*rFrom.getGreen() + t*rTo.getGreen(),
- (1.0-t)*rFrom.getBlue() + t*rTo.getBlue() );
- }
- }
+ namespace internal
+ {
+ namespace
+ {
+ // helper functions
+ // ================
+
+ double getMagic( double nLuminance, double nSaturation )
+ {
+ if( nLuminance <= 0.5 )
+ return nLuminance*(1.0 + nSaturation);
+ else
+ return nLuminance + nSaturation -
nLuminance*nSaturation;
+ }
+
+ HSLColor::HSLTriple rgb2hsl( double nRed, double
nGreen, double nBlue )
+ {
+ // r,g,b in [0,1], h in [0,360] and s,l in [0,1]
+ HSLColor::HSLTriple aRes;
+
+ const double nMax(
::std::max(nRed,::std::max(nGreen, nBlue)) );
+ const double nMin(
::std::min(nRed,::std::min(nGreen, nBlue)) );
+
+ const double nDelta( nMax - nMin );
+
+ aRes.mnLuminance = (nMax + nMin) / 2.0;
+
+ if( ::basegfx::fTools::equalZero( nDelta ) )
+ {
+ aRes.mnSaturation = 0.0;
+
+ // hue undefined (achromatic case)
+ aRes.mnHue = 0.0;
+ }
+ else
+ {
+ aRes.mnSaturation = aRes.mnLuminance >
0.5 ?
+ nDelta/(2.0-nMax-nMin) :
+ nDelta/(nMax + nMin);
+
+ if( nRed == nMax )
+ aRes.mnHue = (nGreen -
nBlue)/nDelta;
+ else if( nGreen == nMax )
+ aRes.mnHue = 2.0 + (nBlue -
nRed)/nDelta;
+ else if( nBlue == nMax )
+ aRes.mnHue = 4.0 + (nRed -
nGreen)/nDelta;
+
+ aRes.mnHue *= 60.0;
+
+ if( aRes.mnHue < 0.0 )
+ aRes.mnHue += 360.0;
+ }
+
+ return aRes;
+ }
+
+ double hsl2rgbHelper( double nValue1, double nValue2,
double nHue )
+ {
+ // clamp hue to [0,360]
+ nHue = fmod( nHue, 360.0 );
+
+ // cope with wrap-arounds
+ if( nHue < 0.0 )
+ nHue += 360.0;
+
+ if( nHue < 60.0 )
+ return nValue1 + (nValue2 -
nValue1)*nHue/60.0;
+ else if( nHue < 180.0 )
+ return nValue2;
+ else if( nHue < 240.0 )
+ return nValue1 + (nValue2 -
nValue1)*(240.0 - nHue)/60.0;
+ else
+ return nValue1;
+ }
+
+ RGBColor::RGBTriple hsl2rgb( double nHue, double
nSaturation, double nLuminance )
+ {
+ if( ::basegfx::fTools::equalZero( nSaturation )
)
+ return RGBColor::RGBTriple(0.0, 0.0,
nLuminance );
+
+ const double nVal1( getMagic(nLuminance,
nSaturation) );
+ const double nVal2( 2.0*nLuminance - nVal1 );
+
+ RGBColor::RGBTriple aRes;
+
+ aRes.mnRed = hsl2rgbHelper( nVal2,
+
nVal1,
+
nHue + 120.0 );
+ aRes.mnGreen = hsl2rgbHelper( nVal2,
+
nVal1,
+
nHue );
+ aRes.mnBlue = hsl2rgbHelper( nVal2,
+
nVal1,
+
nHue - 120.0 );
+
+ return aRes;
+ }
+
+ // Truncate range of value to [0,1]
+ double truncateRangeStd( double nVal )
+ {
+ return ::std::max( 0.0,
+ ::std::min(
1.0,
+
nVal ) );
+ }
+
+ // Truncate range of value to [0,360]
+ double truncateRangeHue( double nVal )
+ {
+ return ::std::max( 0.0,
+ ::std::min(
360.0,
+
nVal ) );
+ }
+
+ // convert RGB color to sal_uInt8, truncate range
appropriately before
+ sal_uInt8 colorToInt( double nCol )
+ {
+ return static_cast< sal_uInt8 >(
+ ::basegfx::fround( truncateRangeStd(
nCol ) * 255.0 ) );
+ }
+ }
+
+
+ // HSLColor
+ // ===============================================
+
+ HSLColor::HSLTriple::HSLTriple() :
+ mnHue(),
+ mnSaturation(),
+ mnLuminance()
+ {
+ }
+
+ HSLColor::HSLTriple::HSLTriple( double nHue, double
nSaturation, double nLuminance ) :
+ mnHue( nHue ),
+ mnSaturation( nSaturation ),
+ mnLuminance( nLuminance )
+ {
+ }
+
+ HSLColor::HSLColor() :
+ maHSLTriple( 0.0, 0.0, 0.0 ),
+ mnMagicValue( getMagic( maHSLTriple.mnLuminance,
+
maHSLTriple.mnSaturation ) )
+ {
+ }
+
+ HSLColor::HSLColor( ::cppcanvas::Color::IntSRGBA nRGBColor ) :
+ maHSLTriple( rgb2hsl( ::cppcanvas::getRed( nRGBColor )
/ 255.0,
+
::cppcanvas::getGreen( nRGBColor ) / 255.0,
+
::cppcanvas::getBlue( nRGBColor ) / 255.0 ) ),
+ mnMagicValue( getMagic( maHSLTriple.mnLuminance,
+
maHSLTriple.mnSaturation ) )
+ {
+ }
+
+ HSLColor::HSLColor( double nHue, double nSaturation, double
nLuminance ) :
+ maHSLTriple( nHue, nSaturation, nLuminance ),
+ mnMagicValue( getMagic( maHSLTriple.mnLuminance,
+
maHSLTriple.mnSaturation ) )
+ {
+ }
+
+ HSLColor::HSLColor( const RGBColor& rColor ) :
+ maHSLTriple( rgb2hsl( truncateRangeStd( rColor.getRed()
),
+
truncateRangeStd( rColor.getGreen() ),
+
truncateRangeStd( rColor.getBlue() ) ) ),
+ mnMagicValue( getMagic( maHSLTriple.mnLuminance,
+
maHSLTriple.mnSaturation ) )
+ {
+ }
+
+ double HSLColor::getHue() const
+ {
+ return maHSLTriple.mnHue;
+ }
+
+ double HSLColor::getSaturation() const
+ {
+ return maHSLTriple.mnSaturation;
+ }
+
+ double HSLColor::getLuminance() const
+ {
+ return maHSLTriple.mnLuminance;
+ }
+
+ double HSLColor::getRed() const
+ {
+ if( ::basegfx::fTools::equalZero( getSaturation() ) )
+ return getLuminance();
+
+ return hsl2rgbHelper( 2.0*getLuminance() - mnMagicValue,
+ mnMagicValue,
+ getHue() +
120.0 );
+ }
+
+ double HSLColor::getGreen() const
+ {
+ if( ::basegfx::fTools::equalZero( getSaturation() ) )
+ return getLuminance();
+
+ return hsl2rgbHelper( 2.0*getLuminance() - mnMagicValue,
+ mnMagicValue,
+ getHue() );
+ }
+
+ double HSLColor::getBlue() const
+ {
+ if( ::basegfx::fTools::equalZero( getSaturation() ) )
+ return getLuminance();
+
+ return hsl2rgbHelper( 2.0*getLuminance() - mnMagicValue,
+ mnMagicValue,
+ getHue() -
120.0 );
+ }
+
+ RGBColor HSLColor::getRGBColor() const
+ {
+ RGBColor::RGBTriple aColor( hsl2rgb( getHue(),
+
getSaturation(),
+
getLuminance() ) );
+ return RGBColor( aColor.mnRed, aColor.mnGreen,
aColor.mnBlue );
+ }
+
+ RGBColor::RGBColor(const RGBColor& rLHS)
+ {
+ maRGBTriple.mnRed = rLHS.getRed();
+ maRGBTriple.mnGreen = rLHS.getGreen();
+ maRGBTriple.mnBlue = rLHS.getBlue();
+ }
+
+ RGBColor& RGBColor::operator=( const RGBColor& rLHS ){
+
+ maRGBTriple.mnRed = rLHS.getRed();
+ maRGBTriple.mnGreen = rLHS.getGreen();
+ maRGBTriple.mnBlue = rLHS.getBlue();
+ return *this;
+ }
+
+ HSLColor operator+( const HSLColor& rLHS, const HSLColor& rRHS )
+ {
+ return HSLColor( rLHS.getHue() + rRHS.getHue(),
+ rLHS.getSaturation() +
rRHS.getSaturation(),
+ rLHS.getLuminance() +
rRHS.getLuminance() );
+ }
+
+ HSLColor operator*( const HSLColor& rLHS, const HSLColor& rRHS )
+ {
+ return HSLColor( rLHS.getHue() * rRHS.getHue(),
+ rLHS.getSaturation() *
rRHS.getSaturation(),
+ rLHS.getLuminance() *
rRHS.getLuminance() );
+ }
+
+ HSLColor operator*( double nFactor, const HSLColor& rRHS )
+ {
+ return HSLColor( nFactor * rRHS.getHue(),
+ nFactor *
rRHS.getSaturation(),
+ nFactor *
rRHS.getLuminance() );
+ }
+
+ HSLColor interpolate( const HSLColor& rFrom, const HSLColor&
rTo, double t, bool bCCW )
+ {
+ const double nFromHue( rFrom.getHue() );
+ const double nToHue ( rTo.getHue() );
+
+ double nHue=0.0;
+
+ if( nFromHue <= nToHue && !bCCW )
+ {
+ // interpolate hue clockwise. That is, hue
starts at
+ // high values and ends at low ones. Therefore,
we
+ // must 'cross' the 360 degrees and start at low
+ // values again (imagine the hues to lie on the
+ // circle, where values above 360 degrees are
mapped
+ // back to [0,360)).
+ nHue = (1.0-t)*(nFromHue + 360.0) + t*nToHue;
+ }
+ else if( nFromHue > nToHue && bCCW )
+ {
+ // interpolate hue counter-clockwise. That is,
hue
+ // starts at high values and ends at low
+ // ones. Therefore, we must 'cross' the 360
degrees
+ // and start at low values again (imagine the
hues to
+ // lie on the circle, where values above 360
degrees
+ // are mapped back to [0,360)).
+ nHue = (1.0-t)*nFromHue + t*(nToHue + 360.0);
+ }
+ else
+ {
+ // interpolate hue counter-clockwise. That is,
hue
+ // starts at low values and ends at high ones
(imagine
+ // the hue value as degrees on a circle, with
+ // increasing values going counter-clockwise)
+ nHue = (1.0-t)*nFromHue + t*nToHue;
+ }
+
+ return HSLColor( nHue,
+
(1.0-t)*rFrom.getSaturation() + t*rTo.getSaturation(),
+
(1.0-t)*rFrom.getLuminance() + t*rTo.getLuminance() );
+ }
+
+
+ // RGBColor
+ // ===============================================
+
+
+ RGBColor::RGBTriple::RGBTriple() :
+ mnRed(),
+ mnGreen(),
+ mnBlue()
+ {
+ }
+
+ RGBColor::RGBTriple::RGBTriple( double nRed, double nGreen,
double nBlue ) :
+ mnRed( nRed ),
+ mnGreen( nGreen ),
+ mnBlue( nBlue )
+ {
+ }
+
+ RGBColor::RGBColor() :
+ maRGBTriple( 0.0, 0.0, 0.0 )
+ {
+ }
+
+ RGBColor::RGBColor( ::cppcanvas::Color::IntSRGBA nRGBColor ) :
+ maRGBTriple( ::cppcanvas::getRed( nRGBColor ) / 255.0,
+ ::cppcanvas::getGreen(
nRGBColor ) / 255.0,
+ ::cppcanvas::getBlue(
nRGBColor ) / 255.0 )
+ {
+ }
+
+ RGBColor::RGBColor( double nRed, double nGreen, double nBlue ) :
+ maRGBTriple( nRed, nGreen, nBlue )
+ {
+ }
+
+ RGBColor::RGBColor( const HSLColor& rColor ) :
+ maRGBTriple( hsl2rgb( truncateRangeHue( rColor.getHue()
),
+
truncateRangeStd( rColor.getSaturation() ),
+
truncateRangeStd( rColor.getLuminance() ) ) )
+ {
+ }
+
+ double RGBColor::getHue() const
+ {
+ return rgb2hsl( getRed(),
+ getGreen(),
+ getBlue() ).mnHue;
+ }
+
+ double RGBColor::getSaturation() const
+ {
+ return rgb2hsl( getRed(),
+ getGreen(),
+ getBlue()
).mnSaturation;
+ }
+
+ double RGBColor::getLuminance() const
+ {
+ return rgb2hsl( getRed(),
+ getGreen(),
+ getBlue() ).mnLuminance;
+ }
+
+ double RGBColor::getRed() const
+ {
+ return maRGBTriple.mnRed;
+ }
+
+ double RGBColor::getGreen() const
+ {
+ return maRGBTriple.mnGreen;
+ }
+
+ double RGBColor::getBlue() const
+ {
+ return maRGBTriple.mnBlue;
+ }
+
+ HSLColor RGBColor::getHSLColor() const
+ {
+ HSLColor::HSLTriple aColor( rgb2hsl( getRed(),
+
getGreen(),
+
getBlue() ) );
+ return HSLColor( aColor.mnHue, aColor.mnSaturation,
aColor.mnLuminance );
+ }
+
+ ::cppcanvas::Color::IntSRGBA RGBColor::getIntegerColor() const
+ {
+ return ::cppcanvas::makeColor( colorToInt( getRed() ),
+
colorToInt( getGreen() ),
+
colorToInt( getBlue() ),
+
255 );
+ }
+
+ RGBColor operator+( const RGBColor& rLHS, const RGBColor& rRHS )
+ {
+ return RGBColor( rLHS.getRed() + rRHS.getRed(),
+ rLHS.getGreen() +
rRHS.getGreen(),
+ rLHS.getBlue() +
rRHS.getBlue() );
+ }
+
+ RGBColor operator*( const RGBColor& rLHS, const RGBColor& rRHS )
+ {
+ return RGBColor( rLHS.getRed() * rRHS.getRed(),
+ rLHS.getGreen() *
rRHS.getGreen(),
+ rLHS.getBlue() *
rRHS.getBlue() );
+ }
+
+ RGBColor operator*( double nFactor, const RGBColor& rRHS )
+ {
+ return RGBColor( nFactor * rRHS.getRed(),
+ nFactor *
rRHS.getGreen(),
+ nFactor *
rRHS.getBlue() );
+ }
+
+ RGBColor interpolate( const RGBColor& rFrom, const RGBColor&
rTo, double t )
+ {
+ return RGBColor( (1.0-t)*rFrom.getRed() +
t*rTo.getRed(),
+
(1.0-t)*rFrom.getGreen() + t*rTo.getGreen(),
+
(1.0-t)*rFrom.getBlue() + t*rTo.getBlue() );
+ }
+ }
}
+
+/* vim: set noet sw=4 ts=4: */