1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "unotypewrapper.hxx"
21 #include "rtl/ustring.hxx"
22 #include <osl/diagnose.h>
25 bool createUnoTypeWrapper(BSTR sTypeName
, VARIANT
* pVar
)
28 OSL_ASSERT(sTypeName
&& pVar
);
29 CComObject
< UnoTypeWrapper
>* pObj
;
31 if( SUCCEEDED( CComObject
<UnoTypeWrapper
>::CreateInstance( &pObj
)))
34 pVar
->vt
= VT_DISPATCH
;
36 pVar
->pdispVal
= CComQIPtr
<IDispatch
, &__uuidof(IDispatch
)>(pObj
->GetUnknown());
38 pVar
->pdispVal
= CComQIPtr
<IDispatch
>(pObj
->GetUnknown());
40 //now set the value, e.i. the name of the type
42 CComQIPtr
<IUnoTypeWrapper
, &__uuidof(IUnoTypeWrapper
)> spType(pVar
->pdispVal
);
44 CComQIPtr
<IUnoTypeWrapper
> spType(pVar
->pdispVal
);
47 if (SUCCEEDED(spType
->put_Name(sTypeName
)))
56 bool createUnoTypeWrapper(const OUString
& sTypeName
, VARIANT
* pVar
)
58 CComBSTR
bstr(reinterpret_cast<LPCOLESTR
>(sTypeName
.getStr()));
59 return createUnoTypeWrapper(bstr
, pVar
);
62 UnoTypeWrapper::UnoTypeWrapper()
66 UnoTypeWrapper::~UnoTypeWrapper()
71 // UnoTypeWrapper, IDispatch --------------------------------------------
72 STDMETHODIMP
UnoTypeWrapper::GetTypeInfoCount(UINT
* /*pctinfo*/)
77 // UnoTypeWrapper, IDispatch --------------------------------------------
78 STDMETHODIMP
UnoTypeWrapper::GetTypeInfo( UINT
/*iTInfo*/,
80 ITypeInfo
** /*ppTInfo*/)
85 // UnoTypeWrapper, IDispatch --------------------------------------------
86 STDMETHODIMP
UnoTypeWrapper::GetIDsOfNames( REFIID
/*riid*/,
96 CComBSTR
name(*rgszNames
);
99 if( name
== CComBSTR( L
"name") )
100 *rgDispId
= DISPID_VALUE
;
102 ret
= DISP_E_UNKNOWNNAME
;
107 // UnoTypeWrapper, IDispatch --------------------------------------------
108 STDMETHODIMP
UnoTypeWrapper::Invoke( DISPID dispIdMember
,
112 DISPPARAMS
*pDispParams
,
114 EXCEPINFO
* /*pExcepInfo*/,
117 if (pDispParams
== NULL
)
118 return DISP_E_EXCEPTION
;
120 if( pDispParams
->cNamedArgs
)
121 return DISP_E_NONAMEDARGS
;
125 switch( dispIdMember
)
127 case DISPID_VALUE
: // DISPID_VALUE
128 if (wFlags
& DISPATCH_PROPERTYGET
)
130 if (pVarResult
== NULL
)
135 get_Name( & pVarResult
->bstrVal
);
136 pVarResult
->vt
= VT_BSTR
;
140 ret
= DISP_E_MEMBERNOTFOUND
;
147 // IUnoTypeWrapper-----------------------
148 STDMETHODIMP
UnoTypeWrapper::put_Name(BSTR val
)
157 // (UnoTypeWrapper-----------------------
158 STDMETHODIMP
UnoTypeWrapper::get_Name(BSTR
*pVal
)
164 *pVal
= m_sName
.Copy();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */