Update ooo320-m1
[ooovba.git] / extensions / source / ole / unotypewrapper.cxx
blob36b25882f11a170750b7a483bb714241872c78bf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unotypewrapper.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "unotypewrapper.hxx"
34 #include "rtl/ustring.hxx"
37 bool createUnoTypeWrapper(BSTR sTypeName, VARIANT * pVar)
39 bool ret = false;
40 OSL_ASSERT(sTypeName && pVar);
41 CComObject< UnoTypeWrapper>* pObj;
42 VariantClear(pVar);
43 if( SUCCEEDED( CComObject<UnoTypeWrapper>::CreateInstance( &pObj)))
45 pObj->AddRef();
46 pVar->vt= VT_DISPATCH;
47 #ifdef __MINGW32__
48 pVar->pdispVal= CComQIPtr<IDispatch, &__uuidof(IDispatch)>(pObj->GetUnknown());
49 #else
50 pVar->pdispVal= CComQIPtr<IDispatch>(pObj->GetUnknown());
51 #endif
52 //now set the value, e.i. the name of the type
53 #ifdef __MINGW32__
54 CComQIPtr<IUnoTypeWrapper, &__uuidof(IUnoTypeWrapper)> spType(pVar->pdispVal);
55 #else
56 CComQIPtr<IUnoTypeWrapper> spType(pVar->pdispVal);
57 #endif
58 OSL_ASSERT(spType);
59 if (SUCCEEDED(spType->put_Name(sTypeName)))
61 ret = true;
64 return ret;
68 bool createUnoTypeWrapper(const rtl::OUString& sTypeName, VARIANT * pVar)
70 CComBSTR bstr(reinterpret_cast<LPCOLESTR>(sTypeName.getStr()));
71 return createUnoTypeWrapper(bstr, pVar);
74 UnoTypeWrapper::UnoTypeWrapper()
78 UnoTypeWrapper::~UnoTypeWrapper()
83 // UnoTypeWrapper, IDispatch --------------------------------------------
84 STDMETHODIMP UnoTypeWrapper::GetTypeInfoCount(UINT* /*pctinfo*/)
86 return E_NOTIMPL;
89 // UnoTypeWrapper, IDispatch --------------------------------------------
90 STDMETHODIMP UnoTypeWrapper::GetTypeInfo( UINT /*iTInfo*/,
91 LCID /*lcid*/,
92 ITypeInfo** /*ppTInfo*/)
94 return E_NOTIMPL;
97 // UnoTypeWrapper, IDispatch --------------------------------------------
98 STDMETHODIMP UnoTypeWrapper::GetIDsOfNames( REFIID /*riid*/,
99 LPOLESTR *rgszNames,
100 UINT /*cNames*/,
101 LCID /*lcid*/,
102 DISPID *rgDispId)
104 if( !rgDispId)
105 return E_POINTER;
107 HRESULT ret= S_OK;
108 CComBSTR name(*rgszNames);
109 name.ToLower();
111 if( name == CComBSTR( L"name") )
112 *rgDispId= DISPID_VALUE;
113 else
114 ret= DISP_E_UNKNOWNNAME;
116 return ret;
119 // UnoTypeWrapper, IDispatch --------------------------------------------
120 STDMETHODIMP UnoTypeWrapper::Invoke( DISPID dispIdMember,
121 REFIID /*riid*/,
122 LCID /*lcid*/,
123 WORD wFlags,
124 DISPPARAMS *pDispParams,
125 VARIANT *pVarResult,
126 EXCEPINFO* /*pExcepInfo*/,
127 UINT* /*puArgErr*/)
129 if (pDispParams == NULL)
130 return DISP_E_EXCEPTION;
132 if( pDispParams->cNamedArgs)
133 return DISP_E_NONAMEDARGS;
136 HRESULT ret= S_OK;
137 switch( dispIdMember)
139 case DISPID_VALUE: // DISPID_VALUE
140 if (wFlags & DISPATCH_PROPERTYGET)
142 if (pVarResult == NULL)
144 ret = E_POINTER;
145 break;
147 get_Name( & pVarResult->bstrVal);
148 pVarResult->vt = VT_BSTR;
150 break;
151 default:
152 ret= DISP_E_MEMBERNOTFOUND;
153 break;
156 return ret;
159 // IUnoTypeWrapper-----------------------
160 STDMETHODIMP UnoTypeWrapper::put_Name(BSTR val)
162 Lock();
163 HRESULT hr = S_OK;
164 m_sName = val;
165 Unlock();
166 return hr;
169 // (UnoTypeWrapper-----------------------
170 STDMETHODIMP UnoTypeWrapper::get_Name(BSTR *pVal)
172 Lock();
173 HRESULT hr = S_OK;
174 if( !pVal)
175 return E_POINTER;
176 *pVal = m_sName.Copy();
177 Unlock();
178 return hr;