merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / ole / unotypewrapper.cxx
blobda2cc93349eb4af39e3ece6d2459a9a718703af6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "unotypewrapper.hxx"
31 #include "rtl/ustring.hxx"
34 bool createUnoTypeWrapper(BSTR sTypeName, VARIANT * pVar)
36 bool ret = false;
37 OSL_ASSERT(sTypeName && pVar);
38 CComObject< UnoTypeWrapper>* pObj;
39 VariantClear(pVar);
40 if( SUCCEEDED( CComObject<UnoTypeWrapper>::CreateInstance( &pObj)))
42 pObj->AddRef();
43 pVar->vt= VT_DISPATCH;
44 #ifdef __MINGW32__
45 pVar->pdispVal= CComQIPtr<IDispatch, &__uuidof(IDispatch)>(pObj->GetUnknown());
46 #else
47 pVar->pdispVal= CComQIPtr<IDispatch>(pObj->GetUnknown());
48 #endif
49 //now set the value, e.i. the name of the type
50 #ifdef __MINGW32__
51 CComQIPtr<IUnoTypeWrapper, &__uuidof(IUnoTypeWrapper)> spType(pVar->pdispVal);
52 #else
53 CComQIPtr<IUnoTypeWrapper> spType(pVar->pdispVal);
54 #endif
55 OSL_ASSERT(spType);
56 if (SUCCEEDED(spType->put_Name(sTypeName)))
58 ret = true;
61 return ret;
65 bool createUnoTypeWrapper(const rtl::OUString& sTypeName, VARIANT * pVar)
67 CComBSTR bstr(reinterpret_cast<LPCOLESTR>(sTypeName.getStr()));
68 return createUnoTypeWrapper(bstr, pVar);
71 UnoTypeWrapper::UnoTypeWrapper()
75 UnoTypeWrapper::~UnoTypeWrapper()
80 // UnoTypeWrapper, IDispatch --------------------------------------------
81 STDMETHODIMP UnoTypeWrapper::GetTypeInfoCount(UINT* /*pctinfo*/)
83 return E_NOTIMPL;
86 // UnoTypeWrapper, IDispatch --------------------------------------------
87 STDMETHODIMP UnoTypeWrapper::GetTypeInfo( UINT /*iTInfo*/,
88 LCID /*lcid*/,
89 ITypeInfo** /*ppTInfo*/)
91 return E_NOTIMPL;
94 // UnoTypeWrapper, IDispatch --------------------------------------------
95 STDMETHODIMP UnoTypeWrapper::GetIDsOfNames( REFIID /*riid*/,
96 LPOLESTR *rgszNames,
97 UINT /*cNames*/,
98 LCID /*lcid*/,
99 DISPID *rgDispId)
101 if( !rgDispId)
102 return E_POINTER;
104 HRESULT ret= S_OK;
105 CComBSTR name(*rgszNames);
106 name.ToLower();
108 if( name == CComBSTR( L"name") )
109 *rgDispId= DISPID_VALUE;
110 else
111 ret= DISP_E_UNKNOWNNAME;
113 return ret;
116 // UnoTypeWrapper, IDispatch --------------------------------------------
117 STDMETHODIMP UnoTypeWrapper::Invoke( DISPID dispIdMember,
118 REFIID /*riid*/,
119 LCID /*lcid*/,
120 WORD wFlags,
121 DISPPARAMS *pDispParams,
122 VARIANT *pVarResult,
123 EXCEPINFO* /*pExcepInfo*/,
124 UINT* /*puArgErr*/)
126 if (pDispParams == NULL)
127 return DISP_E_EXCEPTION;
129 if( pDispParams->cNamedArgs)
130 return DISP_E_NONAMEDARGS;
133 HRESULT ret= S_OK;
134 switch( dispIdMember)
136 case DISPID_VALUE: // DISPID_VALUE
137 if (wFlags & DISPATCH_PROPERTYGET)
139 if (pVarResult == NULL)
141 ret = E_POINTER;
142 break;
144 get_Name( & pVarResult->bstrVal);
145 pVarResult->vt = VT_BSTR;
147 break;
148 default:
149 ret= DISP_E_MEMBERNOTFOUND;
150 break;
153 return ret;
156 // IUnoTypeWrapper-----------------------
157 STDMETHODIMP UnoTypeWrapper::put_Name(BSTR val)
159 Lock();
160 HRESULT hr = S_OK;
161 m_sName = val;
162 Unlock();
163 return hr;
166 // (UnoTypeWrapper-----------------------
167 STDMETHODIMP UnoTypeWrapper::get_Name(BSTR *pVal)
169 Lock();
170 HRESULT hr = S_OK;
171 if( !pVal)
172 return E_POINTER;
173 *pVal = m_sName.Copy();
174 Unlock();
175 return hr;