1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svl.hxx" 26 #include <com/sun/star/uno/Any.hxx> 27 #include <com/sun/star/uno/Sequence.hxx> 28 #include <com/sun/star/script/XTypeConverter.hpp> 29 30 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31 32 #include <comphelper/processfactory.hxx> 33 34 #include <svl/globalnameitem.hxx> 35 36 // STATIC DATA ----------------------------------------------------------- 37 38 39 // ----------------------------------------------------------------------- 40 41 TYPEINIT1_AUTOFACTORY(SfxGlobalNameItem, SfxPoolItem); 42 43 // ----------------------------------------------------------------------- 44 45 SfxGlobalNameItem::SfxGlobalNameItem() 46 { 47 } 48 49 // ----------------------------------------------------------------------- 50 51 SfxGlobalNameItem::SfxGlobalNameItem( sal_uInt16 nW, const SvGlobalName& rName ) 52 : SfxPoolItem( nW ), 53 m_aName( rName ) 54 { 55 } 56 57 // ----------------------------------------------------------------------- 58 59 SfxGlobalNameItem::~SfxGlobalNameItem() 60 { 61 } 62 63 // ----------------------------------------------------------------------- 64 65 int SfxGlobalNameItem::operator==( const SfxPoolItem& rItem ) const 66 { 67 return ((SfxGlobalNameItem&)rItem).m_aName == m_aName; 68 } 69 70 // ----------------------------------------------------------------------- 71 72 SfxPoolItem* SfxGlobalNameItem::Clone(SfxItemPool *) const 73 { 74 return new SfxGlobalNameItem( *this ); 75 } 76 77 //---------------------------------------------------------------------------- 78 // virtual 79 sal_Bool SfxGlobalNameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) 80 { 81 com::sun::star::uno::Reference < com::sun::star::script::XTypeConverter > xConverter 82 ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), 83 com::sun::star::uno::UNO_QUERY ); 84 com::sun::star::uno::Sequence< sal_Int8 > aSeq; 85 com::sun::star::uno::Any aNew; 86 87 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const com::sun::star::uno::Sequence < sal_Int8 >*)0) ); } 88 catch (com::sun::star::uno::Exception&) {} 89 aNew >>= aSeq; 90 if ( aSeq.getLength() == 16 ) 91 { 92 m_aName.MakeFromMemory( (void*) aSeq.getConstArray() ); 93 return sal_True; 94 } 95 96 DBG_ERROR( "SfxGlobalNameItem::PutValue - Wrong type!" ); 97 return sal_False; 98 } 99 100 //---------------------------------------------------------------------------- 101 // virtual 102 sal_Bool SfxGlobalNameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const 103 { 104 com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); 105 void* pData = ( void* ) &m_aName.GetCLSID(); 106 memcpy( aSeq.getArray(), pData, 16 ); 107 rVal <<= aSeq; 108 return sal_True; 109 } 110 111