xref: /trunk/main/editeng/source/uno/unoipset.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*190118d0SAndrew Rist  * distributed with this work for additional information
6*190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9*190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*190118d0SAndrew Rist  * software distributed under the License is distributed on an
15*190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*190118d0SAndrew Rist  * specific language governing permissions and limitations
18*190118d0SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*190118d0SAndrew Rist  *************************************************************/
21*190118d0SAndrew Rist 
22*190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
27cdf0e10cSrcweir #include <svl/eitem.hxx>
28cdf0e10cSrcweir #include <tools/list.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <svl/itemprop.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <editeng/unoipset.hxx>
33cdf0e10cSrcweir #include <editeng/editids.hrc>
34cdf0e10cSrcweir #include <editeng/editeng.hxx>
35cdf0e10cSrcweir #include <svl/itempool.hxx>
36cdf0e10cSrcweir #include <algorithm>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::rtl;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //----------------------------------------------------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir struct SfxItemPropertyMapEntryHash
44cdf0e10cSrcweir {
operator ()SfxItemPropertyMapEntryHash45cdf0e10cSrcweir     size_t operator()(const SfxItemPropertyMapEntry* pMap) const { return (size_t)pMap; }
46cdf0e10cSrcweir };
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //----------------------------------------------------------------------
49cdf0e10cSrcweir 
50cdf0e10cSrcweir struct SvxIDPropertyCombine
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     sal_uInt16  nWID;
53cdf0e10cSrcweir     uno::Any    aAny;
54cdf0e10cSrcweir };
55cdf0e10cSrcweir 
DECLARE_LIST(SvxIDPropertyCombineList,SvxIDPropertyCombine *)56cdf0e10cSrcweir DECLARE_LIST( SvxIDPropertyCombineList, SvxIDPropertyCombine * )
57cdf0e10cSrcweir 
58cdf0e10cSrcweir SvxItemPropertySet::SvxItemPropertySet( const SfxItemPropertyMapEntry* pMap, SfxItemPool& rItemPool, sal_Bool bConvertTwips )
59cdf0e10cSrcweir :   m_aPropertyMap( pMap ),
60cdf0e10cSrcweir     _pMap(pMap), mbConvertTwips(bConvertTwips), mrItemPool( rItemPool )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     pCombiList = NULL;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //----------------------------------------------------------------------
~SvxItemPropertySet()66cdf0e10cSrcweir SvxItemPropertySet::~SvxItemPropertySet()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     ClearAllUsrAny();
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //----------------------------------------------------------------------
GetUsrAnyForID(sal_uInt16 nWID) const72cdf0e10cSrcweir uno::Any* SvxItemPropertySet::GetUsrAnyForID(sal_uInt16 nWID) const
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     if(pCombiList && pCombiList->Count())
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         SvxIDPropertyCombine* pActual = pCombiList->First();
77cdf0e10cSrcweir         while(pActual)
78cdf0e10cSrcweir         {
79cdf0e10cSrcweir             if(pActual->nWID == nWID)
80cdf0e10cSrcweir                 return &pActual->aAny;
81cdf0e10cSrcweir             pActual = pCombiList->Next();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir     return NULL;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir //----------------------------------------------------------------------
AddUsrAnyForID(const uno::Any & rAny,sal_uInt16 nWID)89cdf0e10cSrcweir void SvxItemPropertySet::AddUsrAnyForID(const uno::Any& rAny, sal_uInt16 nWID)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     if(!pCombiList)
92cdf0e10cSrcweir         pCombiList = new SvxIDPropertyCombineList();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     SvxIDPropertyCombine* pNew = new SvxIDPropertyCombine;
95cdf0e10cSrcweir     pNew->nWID = nWID;
96cdf0e10cSrcweir     pNew->aAny = rAny;
97cdf0e10cSrcweir     pCombiList->Insert(pNew);
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //----------------------------------------------------------------------
101cdf0e10cSrcweir 
ClearAllUsrAny()102cdf0e10cSrcweir void SvxItemPropertySet::ClearAllUsrAny()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     if(pCombiList)
105cdf0e10cSrcweir         delete pCombiList;
106cdf0e10cSrcweir     pCombiList = NULL;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //----------------------------------------------------------------------
110cdf0e10cSrcweir 
SvxUnoCheckForPositiveValue(const uno::Any & rVal)111cdf0e10cSrcweir sal_Bool SvxUnoCheckForPositiveValue( const uno::Any& rVal )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     sal_Bool bConvert = sal_True; // the default is that all metric items must be converted
114cdf0e10cSrcweir     sal_Int32 nValue = 0;
115cdf0e10cSrcweir     if( rVal >>= nValue )
116cdf0e10cSrcweir         bConvert = (nValue > 0);
117cdf0e10cSrcweir     return bConvert;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir //----------------------------------------------------------------------
getPropertyValue(const SfxItemPropertySimpleEntry * pMap,const SfxItemSet & rSet,bool bSearchInParent,bool bDontConvertNegativeValues) const122cdf0e10cSrcweir uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry* pMap, const SfxItemSet& rSet, bool bSearchInParent, bool bDontConvertNegativeValues ) const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     uno::Any aVal;
125cdf0e10cSrcweir     if(!pMap || !pMap->nWID)
126cdf0e10cSrcweir         return aVal;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     const SfxPoolItem* pItem = 0;
129cdf0e10cSrcweir     SfxItemPool* pPool = rSet.GetPool();
130cdf0e10cSrcweir     rSet.GetItemState( pMap->nWID, bSearchInParent, &pItem );
131cdf0e10cSrcweir     if( NULL == pItem && pPool )
132cdf0e10cSrcweir         pItem = &(pPool->GetDefaultItem( pMap->nWID ));
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pMap->nWID) : SFX_MAPUNIT_100TH_MM;
135cdf0e10cSrcweir     sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM);
136cdf0e10cSrcweir     if( eMapUnit == SFX_MAPUNIT_100TH_MM )
137cdf0e10cSrcweir         nMemberId &= (~CONVERT_TWIPS);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     if(pItem)
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         pItem->QueryValue( aVal, nMemberId );
142cdf0e10cSrcweir         if( pMap->nMemberId & SFX_METRIC_ITEM )
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             if( eMapUnit != SFX_MAPUNIT_100TH_MM )
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 if ( !bDontConvertNegativeValues || SvxUnoCheckForPositiveValue( aVal ) )
147cdf0e10cSrcweir                     SvxUnoConvertToMM( eMapUnit, aVal );
148cdf0e10cSrcweir             }
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir         else if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM &&
151cdf0e10cSrcweir               aVal.getValueType() == ::getCppuType((const sal_Int32*)0) )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             // convert typeless SfxEnumItem to enum type
154cdf0e10cSrcweir             sal_Int32 nEnum;
155cdf0e10cSrcweir             aVal >>= nEnum;
156cdf0e10cSrcweir             aVal.setValue( &nEnum, *pMap->pType );
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir     else
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         DBG_ERROR( "No SfxPoolItem found for property!" );
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     return aVal;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir //----------------------------------------------------------------------
setPropertyValue(const SfxItemPropertySimpleEntry * pMap,const uno::Any & rVal,SfxItemSet & rSet,bool bDontConvertNegativeValues) const168cdf0e10cSrcweir void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rVal, SfxItemSet& rSet, bool bDontConvertNegativeValues ) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     if(!pMap || !pMap->nWID)
171cdf0e10cSrcweir         return;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     // item holen
174cdf0e10cSrcweir     const SfxPoolItem* pItem = 0;
175cdf0e10cSrcweir     SfxPoolItem *pNewItem = 0;
176cdf0e10cSrcweir     SfxItemState eState = rSet.GetItemState( pMap->nWID, sal_True, &pItem );
177cdf0e10cSrcweir     SfxItemPool* pPool = rSet.GetPool();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     // UnoAny in item-Wert stecken
180cdf0e10cSrcweir     if(eState < SFX_ITEM_DEFAULT || pItem == NULL)
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         if( pPool == NULL )
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             DBG_ERROR( "No default item and no pool?" );
185cdf0e10cSrcweir             return;
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         pItem = &pPool->GetDefaultItem( pMap->nWID );
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     DBG_ASSERT( pItem, "Got no default for item!" );
192cdf0e10cSrcweir     if( pItem )
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         uno::Any aValue( rVal );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pMap->nWID) : SFX_MAPUNIT_100TH_MM;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         // check for needed metric translation
199cdf0e10cSrcweir         if( (pMap->nMemberId & SFX_METRIC_ITEM) && eMapUnit != SFX_MAPUNIT_100TH_MM )
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             if ( !bDontConvertNegativeValues || SvxUnoCheckForPositiveValue( aValue ) )
202cdf0e10cSrcweir                 SvxUnoConvertFromMM( eMapUnit, aValue );
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         pNewItem = pItem->Clone();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM);
208cdf0e10cSrcweir         if( eMapUnit == SFX_MAPUNIT_100TH_MM )
209cdf0e10cSrcweir             nMemberId &= (~CONVERT_TWIPS);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         if( pNewItem->PutValue( aValue, nMemberId ) )
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             // neues item in itemset setzen
214cdf0e10cSrcweir             rSet.Put( *pNewItem, pMap->nWID );
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir         delete pNewItem;
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir //----------------------------------------------------------------------
getPropertyValue(const SfxItemPropertySimpleEntry * pMap) const221cdf0e10cSrcweir uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry* pMap ) const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     // Schon ein Wert eingetragen? Dann schnell fertig
224cdf0e10cSrcweir     uno::Any* pUsrAny = GetUsrAnyForID(pMap->nWID);
225cdf0e10cSrcweir     if(pUsrAny)
226cdf0e10cSrcweir         return *pUsrAny;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     // Noch kein UsrAny gemerkt, generiere Default-Eintrag und gib
229cdf0e10cSrcweir     // diesen zurueck
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     const SfxMapUnit eMapUnit = mrItemPool.GetMetric((sal_uInt16)pMap->nWID);
232cdf0e10cSrcweir     sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM);
233cdf0e10cSrcweir     if( eMapUnit == SFX_MAPUNIT_100TH_MM )
234cdf0e10cSrcweir         nMemberId &= (~CONVERT_TWIPS);
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     uno::Any aVal;
237cdf0e10cSrcweir     SfxItemSet aSet( mrItemPool, pMap->nWID, pMap->nWID);
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     if( (pMap->nWID < OWN_ATTR_VALUE_START) && (pMap->nWID > OWN_ATTR_VALUE_END ) )
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         // Default aus ItemPool holen
242cdf0e10cSrcweir         if(mrItemPool.IsWhich(pMap->nWID))
243cdf0e10cSrcweir             aSet.Put(mrItemPool.GetDefaultItem(pMap->nWID));
244cdf0e10cSrcweir     }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     if(aSet.Count())
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         const SfxPoolItem* pItem = NULL;
249cdf0e10cSrcweir         SfxItemState eState = aSet.GetItemState( pMap->nWID, sal_True, &pItem );
250cdf0e10cSrcweir         if(eState >= SFX_ITEM_DEFAULT && pItem)
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir             pItem->QueryValue( aVal, nMemberId );
253cdf0e10cSrcweir             ((SvxItemPropertySet*)this)->AddUsrAnyForID(aVal, pMap->nWID);
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     if( pMap->nMemberId & SFX_METRIC_ITEM )
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         // check for needed metric translation
260cdf0e10cSrcweir         if(pMap->nMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
261cdf0e10cSrcweir         {
262cdf0e10cSrcweir             SvxUnoConvertToMM( eMapUnit, aVal );
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM &&
267cdf0e10cSrcweir           aVal.getValueType() == ::getCppuType((const sal_Int32*)0) )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         sal_Int32 nEnum;
270cdf0e10cSrcweir         aVal >>= nEnum;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         aVal.setValue( &nEnum, *pMap->pType );
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     return aVal;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir //----------------------------------------------------------------------
279cdf0e10cSrcweir 
setPropertyValue(const SfxItemPropertySimpleEntry * pMap,const uno::Any & rVal) const280cdf0e10cSrcweir void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rVal ) const
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     uno::Any* pUsrAny = GetUsrAnyForID(pMap->nWID);
283cdf0e10cSrcweir     if(!pUsrAny)
284cdf0e10cSrcweir         ((SvxItemPropertySet*)this)->AddUsrAnyForID(rVal, pMap->nWID);
285cdf0e10cSrcweir     else
286cdf0e10cSrcweir         *pUsrAny = rVal;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir //----------------------------------------------------------------------
290cdf0e10cSrcweir 
getPropertyMapEntry(const OUString & rName) const291cdf0e10cSrcweir const SfxItemPropertySimpleEntry* SvxItemPropertySet::getPropertyMapEntry(const OUString &rName) const
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     return m_aPropertyMap.getByName( rName );
294cdf0e10cSrcweir  }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir //----------------------------------------------------------------------
297cdf0e10cSrcweir 
getPropertySetInfo() const298cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo >  SvxItemPropertySet::getPropertySetInfo() const
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     if( !m_xInfo.is() )
301cdf0e10cSrcweir         m_xInfo = new SfxItemPropertySetInfo( &m_aPropertyMap );
302cdf0e10cSrcweir     return m_xInfo;
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir //----------------------------------------------------------------------
306cdf0e10cSrcweir 
307cdf0e10cSrcweir #ifndef TWIPS_TO_MM
308cdf0e10cSrcweir #define TWIPS_TO_MM(val) ((val * 127 + 36) / 72)
309cdf0e10cSrcweir #endif
310cdf0e10cSrcweir #ifndef MM_TO_TWIPS
311cdf0e10cSrcweir #define MM_TO_TWIPS(val) ((val * 72 + 63) / 127)
312cdf0e10cSrcweir #endif
313cdf0e10cSrcweir 
314cdf0e10cSrcweir /** converts the given any with a metric to 100th/mm if needed */
SvxUnoConvertToMM(const SfxMapUnit eSourceMapUnit,uno::Any & rMetric)315cdf0e10cSrcweir void SvxUnoConvertToMM( const SfxMapUnit eSourceMapUnit, uno::Any & rMetric ) throw()
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     // map the metric of the itempool to 100th mm
318cdf0e10cSrcweir     switch(eSourceMapUnit)
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir         case SFX_MAPUNIT_TWIP :
321cdf0e10cSrcweir         {
322cdf0e10cSrcweir             switch( rMetric.getValueTypeClass() )
323cdf0e10cSrcweir             {
324cdf0e10cSrcweir             case uno::TypeClass_BYTE:
325cdf0e10cSrcweir                 rMetric <<= (sal_Int8)(TWIPS_TO_MM(*(sal_Int8*)rMetric.getValue()));
326cdf0e10cSrcweir                 break;
327cdf0e10cSrcweir             case uno::TypeClass_SHORT:
328cdf0e10cSrcweir                 rMetric <<= (sal_Int16)(TWIPS_TO_MM(*(sal_Int16*)rMetric.getValue()));
329cdf0e10cSrcweir                 break;
330cdf0e10cSrcweir             case uno::TypeClass_UNSIGNED_SHORT:
331cdf0e10cSrcweir                 rMetric <<= (sal_uInt16)(TWIPS_TO_MM(*(sal_uInt16*)rMetric.getValue()));
332cdf0e10cSrcweir                 break;
333cdf0e10cSrcweir             case uno::TypeClass_LONG:
334cdf0e10cSrcweir                 rMetric <<= (sal_Int32)(TWIPS_TO_MM(*(sal_Int32*)rMetric.getValue()));
335cdf0e10cSrcweir                 break;
336cdf0e10cSrcweir             case uno::TypeClass_UNSIGNED_LONG:
337cdf0e10cSrcweir                 rMetric <<= (sal_uInt32)(TWIPS_TO_MM(*(sal_uInt32*)rMetric.getValue()));
338cdf0e10cSrcweir                 break;
339cdf0e10cSrcweir             default:
340cdf0e10cSrcweir                 DBG_ERROR("AW: Missing unit translation to 100th mm!");
341cdf0e10cSrcweir             }
342cdf0e10cSrcweir             break;
343cdf0e10cSrcweir         }
344cdf0e10cSrcweir         default:
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             DBG_ERROR("AW: Missing unit translation to 100th mm!");
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //----------------------------------------------------------------------
352cdf0e10cSrcweir 
353cdf0e10cSrcweir /** converts the given any with a metric from 100th/mm to the given metric if needed */
SvxUnoConvertFromMM(const SfxMapUnit eDestinationMapUnit,uno::Any & rMetric)354cdf0e10cSrcweir void SvxUnoConvertFromMM( const SfxMapUnit eDestinationMapUnit, uno::Any & rMetric ) throw()
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     switch(eDestinationMapUnit)
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir         case SFX_MAPUNIT_TWIP :
359cdf0e10cSrcweir         {
360cdf0e10cSrcweir             switch( rMetric.getValueTypeClass() )
361cdf0e10cSrcweir             {
362cdf0e10cSrcweir                 case uno::TypeClass_BYTE:
363cdf0e10cSrcweir                     rMetric <<= (sal_Int8)(MM_TO_TWIPS(*(sal_Int8*)rMetric.getValue()));
364cdf0e10cSrcweir                     break;
365cdf0e10cSrcweir                 case uno::TypeClass_SHORT:
366cdf0e10cSrcweir                     rMetric <<= (sal_Int16)(MM_TO_TWIPS(*(sal_Int16*)rMetric.getValue()));
367cdf0e10cSrcweir                     break;
368cdf0e10cSrcweir                 case uno::TypeClass_UNSIGNED_SHORT:
369cdf0e10cSrcweir                     rMetric <<= (sal_uInt16)(MM_TO_TWIPS(*(sal_uInt16*)rMetric.getValue()));
370cdf0e10cSrcweir                     break;
371cdf0e10cSrcweir                 case uno::TypeClass_LONG:
372cdf0e10cSrcweir                     rMetric <<= (sal_Int32)(MM_TO_TWIPS(*(sal_Int32*)rMetric.getValue()));
373cdf0e10cSrcweir                     break;
374cdf0e10cSrcweir                 case uno::TypeClass_UNSIGNED_LONG:
375cdf0e10cSrcweir                     rMetric <<= (sal_uInt32)(MM_TO_TWIPS(*(sal_uInt32*)rMetric.getValue()));
376cdf0e10cSrcweir                     break;
377cdf0e10cSrcweir                 default:
378cdf0e10cSrcweir                     DBG_ERROR("AW: Missing unit translation to 100th mm!");
379cdf0e10cSrcweir             }
380cdf0e10cSrcweir             break;
381cdf0e10cSrcweir         }
382cdf0e10cSrcweir         default:
383cdf0e10cSrcweir         {
384cdf0e10cSrcweir             DBG_ERROR("AW: Missing unit translation to PoolMetrics!");
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir }
388