diff options
-rw-r--r-- | svx/source/unodraw/unoipset.cxx | 177 | ||||
-rw-r--r-- | svx/source/unodraw/unopool.cxx | 66 |
2 files changed, 137 insertions, 106 deletions
diff --git a/svx/source/unodraw/unoipset.cxx b/svx/source/unodraw/unoipset.cxx index 0b1675bd3ac1..9e97d8375188 100644 --- a/svx/source/unodraw/unoipset.cxx +++ b/svx/source/unodraw/unoipset.cxx @@ -2,9 +2,9 @@ * * $RCSfile: unoipset.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: cl $ $Date: 2001-06-29 09:41:25 $ + * last change: $Author: cl $ $Date: 2001-07-11 13:51:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,6 +75,7 @@ #include "deflt3d.hxx" #include "unoshprp.hxx" #include "editeng.hxx" +#include "unoapi.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -138,23 +139,6 @@ void SvxItemPropertySet::AddUsrAnyForID(const uno::Any& rAny, sal_uInt16 nWID) } //---------------------------------------------------------------------- -//-/void SvxItemPropertySet::Generate3DAttrDefaultItem(sal_uInt16 nWID, SfxItemSet& rSet) -//-/{ -//-/ SfxItemSet aSet( *rSet.GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END); -//-/ E3dDefaultAttributes a3DDefaultAttr; -//-/ a3DDefaultAttr.TakeDefaultValues(aSet); -//-/ const SfxPoolItem* pItem = 0; -//-/ SfxPoolItem *pNewItem = 0; -//-/ SfxItemState eState = aSet.GetItemState( nWID, sal_True, &pItem ); -//-/ if(eState >= SFX_ITEM_DEFAULT && pItem) -//-/ { -//-/ pNewItem = pItem->Clone(); -//-/ rSet.Put( *pNewItem, nWID ); -//-/ delete pNewItem; -//-/ } -//-/} - -//---------------------------------------------------------------------- void SvxItemPropertySet::ObtainSettingsFromPropertySet(SvxItemPropertySet& rPropSet, SfxItemSet& rSet, Reference< beans::XPropertySet > xSet ) { @@ -192,18 +176,8 @@ void SvxItemPropertySet::ObtainSettingsFromPropertySet(SvxItemPropertySet& rProp } else { - // Eintrag sicherstellen in ItemSet -//-/ if(pDst->nWID >= SID_ATTR_3D_START && pDst->nWID <= SID_ATTR_3D_END) -//-/ { -//-/ // 3D-Attribut, eigenen Default -//-/ Generate3DAttrDefaultItem(pDst->nWID, rSet); -//-/ } -//-/ else -//-/ { - // Default aus ItemPool holen - if(rSet.GetPool()->IsWhich(pDst->nWID)) - rSet.Put(rSet.GetPool()->GetDefaultItem(pDst->nWID)); -//-/ } + if(rSet.GetPool()->IsWhich(pDst->nWID)) + rSet.Put(rSet.GetPool()->GetDefaultItem(pDst->nWID)); // setzen setPropertyValue(pDst, *pUsrAny, rSet); @@ -227,24 +201,30 @@ uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertyMap* pMap, c // item holen const SfxPoolItem* pItem = 0; + SfxItemPool* pPool = rSet.GetPool(); SfxItemState eState = rSet.GetItemState( pMap->nWID, sal_True, &pItem ); - if( NULL == pItem ) + if( NULL == pItem && pPool ) { - SfxItemPool* pPool = rSet.GetPool(); - if( pPool ) - { - pItem = &(pPool->GetDefaultItem( pMap->nWID )); - } + pItem = &(pPool->GetDefaultItem( pMap->nWID )); } // item-Wert als UnoAny zurueckgeben if(pItem) { - pItem->QueryValue( aVal, pMap->nMemberId ); + pItem->QueryValue( aVal, pMap->nMemberId & (~SFX_METRIC_ITEM) ); - // allgemeine SfxEnumItem Values in konkrete wandeln - if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM && + if( pMap->nMemberId & SFX_METRIC_ITEM ) + { + // check for needed metric translation + const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((USHORT)pMap->nWID) : SFX_MAPUNIT_100TH_MM; + if(pMap->nMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM) + { + SvxUnoConvertToMM( eMapUnit, aVal ); + } + } + // convert typeless SfxEnumItem to enum type + else if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM && aVal.getValueType() == ::getCppuType((const sal_Int32*)0) ) { sal_Int32 nEnum; @@ -271,11 +251,11 @@ void SvxItemPropertySet::setPropertyValue( const SfxItemPropertyMap* pMap, const const SfxPoolItem* pItem = 0; SfxPoolItem *pNewItem = 0; SfxItemState eState = rSet.GetItemState( pMap->nWID, sal_True, &pItem ); + SfxItemPool* pPool = rSet.GetPool(); // UnoAny in item-Wert stecken if(eState < SFX_ITEM_DEFAULT || pItem == NULL) { - SfxItemPool* pPool = rSet.GetPool(); if( pPool == NULL ) { DBG_ERROR( "No default item and no pool?" ); @@ -288,8 +268,20 @@ void SvxItemPropertySet::setPropertyValue( const SfxItemPropertyMap* pMap, const DBG_ASSERT( pItem, "Got no default for item!" ); if( pItem ) { + uno::Any aValue( rVal ); + + if( pMap->nMemberId & SFX_METRIC_ITEM ) + { + // check for needed metric translation + const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((USHORT)pMap->nWID) : SFX_MAPUNIT_100TH_MM; + if(pMap->nMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM) + { + SvxUnoConvertFromMM( eMapUnit, aValue ); + } + } + pNewItem = pItem->Clone(); - if( pNewItem->PutValue( rVal, pMap->nMemberId ) ) + if( pNewItem->PutValue( aValue, pMap->nMemberId & (~SFX_METRIC_ITEM) ) ) { // neues item in itemset setzen rSet.Put( *pNewItem, pMap->nWID ); @@ -312,7 +304,6 @@ uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertyMap* pMap ) { // ItemPool generieren ((SvxItemPropertySet*)this)->pItemPool = new SdrItemPool; - // pItemPool->SetDefaultMetric(...eScaleUnit...); // Der Outliner hat keinen eigenen Pool, deshalb den der EditEngine SfxItemPool* pOutlPool=EditEngine::CreatePool(); // OutlinerPool als SecondaryPool des SdrPool @@ -321,12 +312,7 @@ uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertyMap* pMap ) uno::Any aVal; SfxItemSet aSet( *pItemPool, pMap->nWID, pMap->nWID); -//-/ if(pMap->nWID >= SID_ATTR_3D_START && pMap->nWID <= SID_ATTR_3D_END) -//-/ { -//-/ // 3D-Attribut, eigenen Default generieren -//-/ ((SvxItemPropertySet*)this)->Generate3DAttrDefaultItem(pMap->nWID, aSet); -//-/ } -//-/ else + if( (pMap->nWID < OWN_ATTR_VALUE_START) && (pMap->nWID > OWN_ATTR_VALUE_END ) ) { // Default aus ItemPool holen @@ -345,6 +331,16 @@ uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertyMap* pMap ) } } + if( pMap->nMemberId & SFX_METRIC_ITEM ) + { + // check for needed metric translation + const SfxMapUnit eMapUnit = pItemPool ? pItemPool->GetMetric((USHORT)pMap->nWID) : SFX_MAPUNIT_100TH_MM; + if(pMap->nMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM) + { + SvxUnoConvertToMM( eMapUnit, aVal ); + } + } + if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM && aVal.getValueType() == ::getCppuType((const sal_Int32*)0) ) { @@ -382,3 +378,86 @@ Reference< ::com::sun::star::beans::XPropertySetInfo > SvxItemPropertySet::getP Reference< ::com::sun::star::beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( _pMap )); return aRef; } + +//---------------------------------------------------------------------- + +#ifndef TWIPS_TO_MM +#define TWIPS_TO_MM(val) ((val * 127 + 36) / 72) +#endif +#ifndef MM_TO_TWIPS +#define MM_TO_TWIPS(val) ((val * 72 + 63) / 127) +#endif + +/** converts the given any with a metric to 100th/mm if needed */ +void SvxUnoConvertToMM( const SfxMapUnit eSourceMapUnit, com::sun::star::uno::Any & rMetric ) throw() +{ + // map the metric of the itempool to 100th mm + switch(eSourceMapUnit) + { + case SFX_MAPUNIT_TWIP : + { + switch( rMetric.getValueTypeClass() ) + { + case uno::TypeClass_BYTE: + rMetric <<= (sal_Int8)(TWIPS_TO_MM(*(sal_Int8*)rMetric.getValue())); + break; + case uno::TypeClass_SHORT: + rMetric <<= (sal_Int16)(TWIPS_TO_MM(*(sal_Int16*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_SHORT: + rMetric <<= (sal_uInt16)(TWIPS_TO_MM(*(sal_uInt16*)rMetric.getValue())); + break; + case uno::TypeClass_LONG: + rMetric <<= (sal_Int32)(TWIPS_TO_MM(*(sal_Int32*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_LONG: + rMetric <<= (sal_uInt32)(TWIPS_TO_MM(*(sal_uInt32*)rMetric.getValue())); + break; + default: + DBG_ERROR("AW: Missing unit translation to 100th mm!"); + } + break; + } + default: + { + DBG_ERROR("AW: Missing unit translation to 100th mm!"); + } + } +} + +//---------------------------------------------------------------------- + +/** converts the given any with a metric from 100th/mm to the given metric if needed */ +void SvxUnoConvertFromMM( const SfxMapUnit eDestinationMapUnit, com::sun::star::uno::Any & rMetric ) throw() +{ + switch(eDestinationMapUnit) + { + case SFX_MAPUNIT_TWIP : + { + switch( rMetric.getValueTypeClass() ) + { + case uno::TypeClass_BYTE: + rMetric <<= (sal_Int8)(MM_TO_TWIPS(*(sal_Int8*)rMetric.getValue())); + break; + case uno::TypeClass_SHORT: + rMetric <<= (sal_Int16)(MM_TO_TWIPS(*(sal_Int16*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_SHORT: + rMetric <<= (sal_uInt16)(MM_TO_TWIPS(*(sal_uInt16*)rMetric.getValue())); + break; + case uno::TypeClass_LONG: + rMetric <<= (sal_Int32)(MM_TO_TWIPS(*(sal_Int32*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_LONG: + rMetric <<= (sal_uInt32)(MM_TO_TWIPS(*(sal_uInt32*)rMetric.getValue())); + break; + default: + DBG_ERROR("AW: Missing unit translation to 100th mm!"); + } + } + default: + { + DBG_ERROR("AW: Missing unit translation to PoolMetrics!"); + } + } +} diff --git a/svx/source/unodraw/unopool.cxx b/svx/source/unodraw/unopool.cxx index 238651e6b9f5..6b6f60e2747f 100644 --- a/svx/source/unodraw/unopool.cxx +++ b/svx/source/unodraw/unopool.cxx @@ -2,9 +2,9 @@ * * $RCSfile: unopool.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: cl $ $Date: 2001-05-30 15:10:45 $ + * last change: $Author: cl $ $Date: 2001-07-11 13:51:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -113,6 +113,8 @@ #include "editeng.hxx" #endif +#include "unoapi.hxx" + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -177,7 +179,7 @@ void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEn break; } default: - pPool->GetDefaultItem( (USHORT)pEntry->mnHandle ).QueryValue( rValue, pEntry->mnMemberId ); + pPool->GetDefaultItem( (USHORT)pEntry->mnHandle ).QueryValue( rValue, pEntry->mnMemberId & (~SFX_METRIC_ITEM) ); } @@ -185,42 +187,10 @@ void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEn const SfxMapUnit eMapUnit = pPool->GetMetric((USHORT)pEntry->mnHandle); if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM) { - // map the metric of the itempool to 100th mm - switch(eMapUnit) - { - case SFX_MAPUNIT_TWIP : - { - switch( rValue.getValueTypeClass() ) - { - case uno::TypeClass_BYTE: - rValue <<= (sal_Int8)(TWIPS_TO_MM(*(sal_Int8*)rValue.getValue())); - break; - case uno::TypeClass_SHORT: - rValue <<= (sal_Int16)(TWIPS_TO_MM(*(sal_Int16*)rValue.getValue())); - break; - case uno::TypeClass_UNSIGNED_SHORT: - rValue <<= (sal_uInt16)(TWIPS_TO_MM(*(sal_uInt16*)rValue.getValue())); - break; - case uno::TypeClass_LONG: - rValue <<= (sal_Int32)(TWIPS_TO_MM(*(sal_Int32*)rValue.getValue())); - break; - case uno::TypeClass_UNSIGNED_LONG: - rValue <<= (sal_uInt32)(TWIPS_TO_MM(*(sal_uInt32*)rValue.getValue())); - break; - default: - DBG_ERROR("AW: Missing unit translation to 100th mm!"); - } - break; - } - default: - { - DBG_ERROR("AW: Missing unit translation to 100th mm!"); - } - } + SvxUnoConvertToMM( eMapUnit, rValue ); } - // convert int32 to correct enum type if needed - if ( pEntry->mpType->getTypeClass() == TypeClass_ENUM && rValue.getValueType() == ::getCppuType((const sal_Int32*)0) ) + else if ( pEntry->mpType->getTypeClass() == TypeClass_ENUM && rValue.getValueType() == ::getCppuType((const sal_Int32*)0) ) { sal_Int32 nEnum; rValue >>= nEnum; @@ -237,25 +207,7 @@ void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEn const SfxMapUnit eMapUnit = pPool->GetMetric((USHORT)pEntry->mnHandle); if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM) { - switch(eMapUnit) - { - case SFX_MAPUNIT_TWIP : - { - if( aValue.getValueType() == ::getCppuType(( const sal_Int32 *)0)) - aValue <<= (sal_Int32)(MM_TO_TWIPS(*(sal_Int32*)aValue.getValue())); - else if( aValue.getValueType() == ::getCppuType(( const sal_uInt32*)0)) - aValue <<= (sal_uInt32)(MM_TO_TWIPS(*(sal_uInt32*)aValue.getValue())); - else if( aValue.getValueType() == ::getCppuType(( const sal_uInt16*)0)) - aValue <<= (sal_uInt16)(MM_TO_TWIPS(*(sal_uInt16*)aValue.getValue())); - else - DBG_ERROR("AW: Missing unit translation to PoolMetrics!"); - break; - } - default: - { - DBG_ERROR("AW: Missing unit translation to PoolMetrics!"); - } - } + SvxUnoConvertFromMM( eMapUnit, aValue ); } const sal_uInt16 nWhich = (sal_uInt16)pEntry->mnHandle; @@ -283,7 +235,7 @@ void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEn default: SfxPoolItem* pNewItem = pPool->GetDefaultItem( nWhich ).Clone(); - if( !pNewItem->PutValue( aValue, pEntry->mnMemberId ) ) + if( !pNewItem->PutValue( aValue, pEntry->mnMemberId & (~SFX_METRIC_ITEM) ) ) throw IllegalArgumentException(); pPool->SetPoolDefaultItem( *pNewItem ); |