LibreOffice Module extensions (master) 1
unotypewrapper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "unotypewrapper.hxx"
21#include <rtl/ustring.hxx>
22#include <osl/diagnose.h>
24
25bool createUnoTypeWrapper(BSTR sTypeName, VARIANT * pVar)
26{
27 bool ret = false;
28 OSL_ASSERT(sTypeName && pVar);
29 CComObject< UnoTypeWrapper>* pObj;
30 VariantClear(pVar);
31 if( SUCCEEDED( CComObject<UnoTypeWrapper>::CreateInstance( &pObj)))
32 {
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)))
40 {
41 ret = true;
42 }
43 }
44 return ret;
45}
46
47
48bool createUnoTypeWrapper(const OUString& sTypeName, VARIANT * pVar)
49{
50 CComBSTR bstr(o3tl::toW(sTypeName.getStr()));
51 return createUnoTypeWrapper(bstr, pVar);
52}
53
55{
56}
57
59{
60}
61
62
63// UnoTypeWrapper, IDispatch --------------------------------------------
64COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::GetTypeInfoCount(UINT* /*pctinfo*/)
65{
66 return E_NOTIMPL;
67}
68
69// UnoTypeWrapper, IDispatch --------------------------------------------
70COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::GetTypeInfo( UINT /*iTInfo*/,
71 LCID /*lcid*/,
72 ITypeInfo** /*ppTInfo*/)
73{
74 return E_NOTIMPL;
75}
76
77// UnoTypeWrapper, IDispatch --------------------------------------------
78COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::GetIDsOfNames( REFIID /*riid*/,
79 LPOLESTR *rgszNames,
80 UINT /*cNames*/,
81 LCID /*lcid*/,
82 DISPID *rgDispId)
83{
84 if( !rgDispId)
85 return E_POINTER;
86
87 HRESULT ret= S_OK;
88 CComBSTR name(*rgszNames);
89 name.ToLower();
90
91 if( name == CComBSTR( L"name") )
92 *rgDispId= DISPID_VALUE;
93 else
94 ret= DISP_E_UNKNOWNNAME;
95
96 return ret;
97}
98
99// UnoTypeWrapper, IDispatch --------------------------------------------
100COM_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*/)
108{
109 if (pDispParams == nullptr)
110 return DISP_E_EXCEPTION;
111
112 if( pDispParams->cNamedArgs)
113 return DISP_E_NONAMEDARGS;
114
115
116 HRESULT ret= S_OK;
117 switch( dispIdMember)
118 {
119 case DISPID_VALUE: // DISPID_VALUE
120 if (wFlags & DISPATCH_PROPERTYGET)
121 {
122 if (pVarResult == nullptr)
123 {
124 ret = E_POINTER;
125 break;
126 }
127 get_Name( & pVarResult->bstrVal);
128 pVarResult->vt = VT_BSTR;
129 }
130 break;
131 default:
132 ret= DISP_E_MEMBERNOTFOUND;
133 break;
134 }
135
136 return ret;
137}
138
139// IUnoTypeWrapper-----------------------
140COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::put_Name(BSTR val)
141{
142 Lock();
143 m_sName = val;
144 Unlock();
145 return S_OK;
146}
147
148// (UnoTypeWrapper-----------------------
149COM_DECLSPEC_NOTHROW STDMETHODIMP UnoTypeWrapper::get_Name(BSTR *pVal)
150{
151 Lock();
152 if( !pVal)
153 return E_POINTER;
154 *pVal = m_sName.Copy();
155 Unlock();
156 return S_OK;
157}
158
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHOD() put_Name(BSTR val) override
STDMETHOD() GetTypeInfoCount(UINT *pctinfo) override
STDMETHOD() GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override
STDMETHOD() Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override
virtual ~UnoTypeWrapper()
STDMETHOD() get_Name(BSTR *pVal) override
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override
const char * name
unsigned short WORD
#define VT_BSTR
bool createUnoTypeWrapper(BSTR sTypeName, VARIANT *pVar)