Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / ole / unotypewrapper.cxx
blob2824e8ef7b27ed04e4e4bbeb9eb5867546fc821e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
27 bool ret = false;
28 OSL_ASSERT(sTypeName && pVar);
29 CComObject< UnoTypeWrapper>* pObj;
30 VariantClear(pVar);
31 if( SUCCEEDED( CComObject<UnoTypeWrapper>::CreateInstance( &pObj)))
33 pObj->AddRef();
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);
38 OSL_ASSERT(spType);
39 if (SUCCEEDED(spType->put_Name(sTypeName)))
41 ret = true;
44 return ret;
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*/)
66 return E_NOTIMPL;
69 // UnoTypeWrapper, IDispatch --------------------------------------------
70 COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::GetTypeInfo( UINT /*iTInfo*/,
71 LCID /*lcid*/,
72 ITypeInfo** /*ppTInfo*/)
74 return E_NOTIMPL;
77 // UnoTypeWrapper, IDispatch --------------------------------------------
78 COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::GetIDsOfNames( REFIID /*riid*/,
79 LPOLESTR *rgszNames,
80 UINT /*cNames*/,
81 LCID /*lcid*/,
82 DISPID *rgDispId)
84 if( !rgDispId)
85 return E_POINTER;
87 HRESULT ret= S_OK;
88 CComBSTR name(*rgszNames);
89 name.ToLower();
91 if( name == CComBSTR( L"name") )
92 *rgDispId= DISPID_VALUE;
93 else
94 ret= DISP_E_UNKNOWNNAME;
96 return ret;
99 // UnoTypeWrapper, IDispatch --------------------------------------------
100 COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::Invoke( DISPID dispIdMember,
101 REFIID /*riid*/,
102 LCID /*lcid*/,
103 WORD wFlags,
104 DISPPARAMS *pDispParams,
105 VARIANT *pVarResult,
106 EXCEPINFO* /*pExcepInfo*/,
107 UINT* /*puArgErr*/)
109 if (pDispParams == nullptr)
110 return DISP_E_EXCEPTION;
112 if( pDispParams->cNamedArgs)
113 return DISP_E_NONAMEDARGS;
116 HRESULT ret= S_OK;
117 switch( dispIdMember)
119 case DISPID_VALUE: // DISPID_VALUE
120 if (wFlags & DISPATCH_PROPERTYGET)
122 if (pVarResult == nullptr)
124 ret = E_POINTER;
125 break;
127 get_Name( & pVarResult->bstrVal);
128 pVarResult->vt = VT_BSTR;
130 break;
131 default:
132 ret= DISP_E_MEMBERNOTFOUND;
133 break;
136 return ret;
139 // IUnoTypeWrapper-----------------------
140 COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::put_Name(BSTR val)
142 Lock();
143 m_sName = val;
144 Unlock();
145 return S_OK;
148 // (UnoTypeWrapper-----------------------
149 COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::get_Name(BSTR *pVal)
151 Lock();
152 if( !pVal)
153 return E_POINTER;
154 *pVal = m_sName.Copy();
155 Unlock();
156 return S_OK;
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */