1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svl.hxx" 30 #include <com/sun/star/uno/Any.hxx> 31 #include <com/sun/star/uno/Sequence.hxx> 32 #include <com/sun/star/script/XTypeConverter.hpp> 33 34 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35 36 #include <comphelper/processfactory.hxx> 37 38 #include <svl/globalnameitem.hxx> 39 40 // STATIC DATA ----------------------------------------------------------- 41 42 43 // ----------------------------------------------------------------------- 44 45 TYPEINIT1_AUTOFACTORY(SfxGlobalNameItem, SfxPoolItem); 46 47 // ----------------------------------------------------------------------- 48 49 SfxGlobalNameItem::SfxGlobalNameItem() 50 { 51 } 52 53 // ----------------------------------------------------------------------- 54 55 SfxGlobalNameItem::SfxGlobalNameItem( sal_uInt16 nW, const SvGlobalName& rName ) 56 : SfxPoolItem( nW ), 57 m_aName( rName ) 58 { 59 } 60 61 // ----------------------------------------------------------------------- 62 63 SfxGlobalNameItem::~SfxGlobalNameItem() 64 { 65 } 66 67 // ----------------------------------------------------------------------- 68 69 int SfxGlobalNameItem::operator==( const SfxPoolItem& rItem ) const 70 { 71 return ((SfxGlobalNameItem&)rItem).m_aName == m_aName; 72 } 73 74 // ----------------------------------------------------------------------- 75 76 SfxPoolItem* SfxGlobalNameItem::Clone(SfxItemPool *) const 77 { 78 return new SfxGlobalNameItem( *this ); 79 } 80 81 //---------------------------------------------------------------------------- 82 // virtual 83 sal_Bool SfxGlobalNameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) 84 { 85 com::sun::star::uno::Reference < com::sun::star::script::XTypeConverter > xConverter 86 ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), 87 com::sun::star::uno::UNO_QUERY ); 88 com::sun::star::uno::Sequence< sal_Int8 > aSeq; 89 com::sun::star::uno::Any aNew; 90 91 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const com::sun::star::uno::Sequence < sal_Int8 >*)0) ); } 92 catch (com::sun::star::uno::Exception&) {} 93 aNew >>= aSeq; 94 if ( aSeq.getLength() == 16 ) 95 { 96 m_aName.MakeFromMemory( (void*) aSeq.getConstArray() ); 97 return sal_True; 98 } 99 100 DBG_ERROR( "SfxGlobalNameItem::PutValue - Wrong type!" ); 101 return sal_False; 102 } 103 104 //---------------------------------------------------------------------------- 105 // virtual 106 sal_Bool SfxGlobalNameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const 107 { 108 com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); 109 void* pData = ( void* ) &m_aName.GetCLSID(); 110 memcpy( aSeq.getArray(), pData, 16 ); 111 rVal <<= aSeq; 112 return sal_True; 113 } 114 115