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>
23 #include <o3tl/char16_t2wchar_t.hxx>
25 bool createUnoTypeWrapper(BSTR sTypeName
, VARIANT
* pVar
)
28 assert(sTypeName
&& pVar
);
29 CComObject
< UnoTypeWrapper
>* pObj
;
31 if( SUCCEEDED( CComObject
<UnoTypeWrapper
>::CreateInstance( &pObj
)))
34 pVar
->vt
= VT_DISPATCH
;
35 pVar
->pdispVal
= CComQIPtr
<IDispatch
>(pObj
->GetUnknown());
36 //now set the value, e.i. the name of the type
37 CComQIPtr
<IUnoTypeWrapper
> spType(pVar
->pdispVal
);
39 if (SUCCEEDED(spType
->put_Name(sTypeName
)))
48 bool createUnoTypeWrapper(const OUString
& sTypeName
, VARIANT
* pVar
)
50 CComBSTR
bstr(o3tl::toW(sTypeName
.getStr()));
51 return createUnoTypeWrapper(bstr
, pVar
);
54 UnoTypeWrapper::UnoTypeWrapper()
58 UnoTypeWrapper::~UnoTypeWrapper()
63 // UnoTypeWrapper, IDispatch --------------------------------------------
64 COM_DECLSPEC_NOTHROW STDMETHODIMP
UnoTypeWrapper::GetTypeInfoCount(UINT
* /*pctinfo*/)
69 // UnoTypeWrapper, IDispatch --------------------------------------------
70 COM_DECLSPEC_NOTHROW STDMETHODIMP
UnoTypeWrapper::GetTypeInfo( UINT
/*iTInfo*/,
72 ITypeInfo
** /*ppTInfo*/)
77 // UnoTypeWrapper, IDispatch --------------------------------------------
78 COM_DECLSPEC_NOTHROW STDMETHODIMP
UnoTypeWrapper::GetIDsOfNames( REFIID
/*riid*/,
88 CComBSTR
name(*rgszNames
);
91 if( name
== CComBSTR( L
"name") )
92 *rgDispId
= DISPID_VALUE
;
94 ret
= DISP_E_UNKNOWNNAME
;
99 // UnoTypeWrapper, IDispatch --------------------------------------------
100 COM_DECLSPEC_NOTHROW STDMETHODIMP
UnoTypeWrapper::Invoke( DISPID dispIdMember
,
104 DISPPARAMS
*pDispParams
,
106 EXCEPINFO
* /*pExcepInfo*/,
109 if (pDispParams
== nullptr)
110 return DISP_E_EXCEPTION
;
112 if( pDispParams
->cNamedArgs
)
113 return DISP_E_NONAMEDARGS
;
117 switch( dispIdMember
)
119 case DISPID_VALUE
: // DISPID_VALUE
120 if (wFlags
& DISPATCH_PROPERTYGET
)
122 if (pVarResult
== nullptr)
127 get_Name( & pVarResult
->bstrVal
);
128 pVarResult
->vt
= VT_BSTR
;
132 ret
= DISP_E_MEMBERNOTFOUND
;
139 // IUnoTypeWrapper-----------------------
140 COM_DECLSPEC_NOTHROW STDMETHODIMP
UnoTypeWrapper::put_Name(BSTR val
)
148 // (UnoTypeWrapper-----------------------
149 COM_DECLSPEC_NOTHROW STDMETHODIMP
UnoTypeWrapper::get_Name(BSTR
*pVal
)
154 *pVal
= m_sName
.Copy();
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */