bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / ole / unotypewrapper.cxx
blobdd6364b76633c17f2979ff7a582a0d6489834114
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>
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 #ifdef __MINGW32__
36 pVar->pdispVal= CComQIPtr<IDispatch, &__uuidof(IDispatch)>(pObj->GetUnknown());
37 #else
38 pVar->pdispVal= CComQIPtr<IDispatch>(pObj->GetUnknown());
39 #endif
40 //now set the value, e.i. the name of the type
41 #ifdef __MINGW32__
42 CComQIPtr<IUnoTypeWrapper, &__uuidof(IUnoTypeWrapper)> spType(pVar->pdispVal);
43 #else
44 CComQIPtr<IUnoTypeWrapper> spType(pVar->pdispVal);
45 #endif
46 OSL_ASSERT(spType);
47 if (SUCCEEDED(spType->put_Name(sTypeName)))
49 ret = true;
52 return ret;
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*/)
74 return E_NOTIMPL;
77 // UnoTypeWrapper, IDispatch --------------------------------------------
78 STDMETHODIMP UnoTypeWrapper::GetTypeInfo( UINT /*iTInfo*/,
79 LCID /*lcid*/,
80 ITypeInfo** /*ppTInfo*/)
82 return E_NOTIMPL;
85 // UnoTypeWrapper, IDispatch --------------------------------------------
86 STDMETHODIMP UnoTypeWrapper::GetIDsOfNames( REFIID /*riid*/,
87 LPOLESTR *rgszNames,
88 UINT /*cNames*/,
89 LCID /*lcid*/,
90 DISPID *rgDispId)
92 if( !rgDispId)
93 return E_POINTER;
95 HRESULT ret= S_OK;
96 CComBSTR name(*rgszNames);
97 name.ToLower();
99 if( name == CComBSTR( L"name") )
100 *rgDispId= DISPID_VALUE;
101 else
102 ret= DISP_E_UNKNOWNNAME;
104 return ret;
107 // UnoTypeWrapper, IDispatch --------------------------------------------
108 STDMETHODIMP UnoTypeWrapper::Invoke( DISPID dispIdMember,
109 REFIID /*riid*/,
110 LCID /*lcid*/,
111 WORD wFlags,
112 DISPPARAMS *pDispParams,
113 VARIANT *pVarResult,
114 EXCEPINFO* /*pExcepInfo*/,
115 UINT* /*puArgErr*/)
117 if (pDispParams == NULL)
118 return DISP_E_EXCEPTION;
120 if( pDispParams->cNamedArgs)
121 return DISP_E_NONAMEDARGS;
124 HRESULT ret= S_OK;
125 switch( dispIdMember)
127 case DISPID_VALUE: // DISPID_VALUE
128 if (wFlags & DISPATCH_PROPERTYGET)
130 if (pVarResult == NULL)
132 ret = E_POINTER;
133 break;
135 get_Name( & pVarResult->bstrVal);
136 pVarResult->vt = VT_BSTR;
138 break;
139 default:
140 ret= DISP_E_MEMBERNOTFOUND;
141 break;
144 return ret;
147 // IUnoTypeWrapper-----------------------
148 STDMETHODIMP UnoTypeWrapper::put_Name(BSTR val)
150 Lock();
151 HRESULT hr = S_OK;
152 m_sName = val;
153 Unlock();
154 return hr;
157 // (UnoTypeWrapper-----------------------
158 STDMETHODIMP UnoTypeWrapper::get_Name(BSTR *pVal)
160 Lock();
161 HRESULT hr = S_OK;
162 if( !pVal)
163 return E_POINTER;
164 *pVal = m_sName.Copy();
165 Unlock();
166 return hr;
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */