merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items / globalnameitem.cxx
blobf3aff6f1ef12ac2070cf6ecb602529bad4732268
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: globalnameitem.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <com/sun/star/script/XTypeConverter.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <comphelper/processfactory.hxx>
41 #include <svtools/globalnameitem.hxx>
43 // STATIC DATA -----------------------------------------------------------
46 // -----------------------------------------------------------------------
48 TYPEINIT1_AUTOFACTORY(SfxGlobalNameItem, SfxPoolItem);
50 // -----------------------------------------------------------------------
52 SfxGlobalNameItem::SfxGlobalNameItem()
56 // -----------------------------------------------------------------------
58 SfxGlobalNameItem::SfxGlobalNameItem( USHORT nW, const SvGlobalName& rName )
59 : SfxPoolItem( nW ),
60 m_aName( rName )
64 // -----------------------------------------------------------------------
66 SfxGlobalNameItem::~SfxGlobalNameItem()
70 // -----------------------------------------------------------------------
72 int SfxGlobalNameItem::operator==( const SfxPoolItem& rItem ) const
74 return ((SfxGlobalNameItem&)rItem).m_aName == m_aName;
77 // -----------------------------------------------------------------------
79 SfxPoolItem* SfxGlobalNameItem::Clone(SfxItemPool *) const
81 return new SfxGlobalNameItem( *this );
84 //----------------------------------------------------------------------------
85 // virtual
86 BOOL SfxGlobalNameItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE )
88 com::sun::star::uno::Reference < com::sun::star::script::XTypeConverter > xConverter
89 ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")),
90 com::sun::star::uno::UNO_QUERY );
91 com::sun::star::uno::Sequence< sal_Int8 > aSeq;
92 com::sun::star::uno::Any aNew;
94 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const com::sun::star::uno::Sequence < sal_Int8 >*)0) ); }
95 catch (com::sun::star::uno::Exception&) {}
96 aNew >>= aSeq;
97 if ( aSeq.getLength() == 16 )
99 m_aName.MakeFromMemory( (void*) aSeq.getConstArray() );
100 return TRUE;
103 DBG_ERROR( "SfxGlobalNameItem::PutValue - Wrong type!" );
104 return FALSE;
107 //----------------------------------------------------------------------------
108 // virtual
109 BOOL SfxGlobalNameItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const
111 com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 );
112 void* pData = ( void* ) &m_aName.GetCLSID();
113 memcpy( aSeq.getArray(), pData, 16 );
114 rVal <<= aSeq;
115 return TRUE;