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