1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 #include "unotypewrapper.hxx"
27 #include "rtl/ustring.hxx"
28
29
createUnoTypeWrapper(BSTR sTypeName,VARIANT * pVar)30 bool createUnoTypeWrapper(BSTR sTypeName, VARIANT * pVar)
31 {
32 bool ret = false;
33 OSL_ASSERT(sTypeName && pVar);
34 CComObject< UnoTypeWrapper>* pObj;
35 VariantClear(pVar);
36 if( SUCCEEDED( CComObject<UnoTypeWrapper>::CreateInstance( &pObj)))
37 {
38 pObj->AddRef();
39 pVar->vt= VT_DISPATCH;
40 #ifdef __MINGW32__
41 pVar->pdispVal= CComQIPtr<IDispatch, &__uuidof(IDispatch)>(pObj->GetUnknown());
42 #else
43 pVar->pdispVal= CComQIPtr<IDispatch>(pObj->GetUnknown());
44 #endif
45 //now set the value, e.i. the name of the type
46 #ifdef __MINGW32__
47 CComQIPtr<IUnoTypeWrapper, &__uuidof(IUnoTypeWrapper)> spType(pVar->pdispVal);
48 #else
49 CComQIPtr<IUnoTypeWrapper> spType(pVar->pdispVal);
50 #endif
51 OSL_ASSERT(spType);
52 if (SUCCEEDED(spType->put_Name(sTypeName)))
53 {
54 ret = true;
55 }
56 }
57 return ret;
58 }
59
60
createUnoTypeWrapper(const rtl::OUString & sTypeName,VARIANT * pVar)61 bool createUnoTypeWrapper(const rtl::OUString& sTypeName, VARIANT * pVar)
62 {
63 CComBSTR bstr(reinterpret_cast<LPCOLESTR>(sTypeName.getStr()));
64 return createUnoTypeWrapper(bstr, pVar);
65 }
66
UnoTypeWrapper()67 UnoTypeWrapper::UnoTypeWrapper()
68 {
69 }
70
~UnoTypeWrapper()71 UnoTypeWrapper::~UnoTypeWrapper()
72 {
73 }
74
75
76 // UnoTypeWrapper, IDispatch --------------------------------------------
GetTypeInfoCount(UINT *)77 STDMETHODIMP UnoTypeWrapper::GetTypeInfoCount(UINT* /*pctinfo*/)
78 {
79 return E_NOTIMPL;
80 }
81
82 // UnoTypeWrapper, IDispatch --------------------------------------------
GetTypeInfo(UINT,LCID,ITypeInfo **)83 STDMETHODIMP UnoTypeWrapper::GetTypeInfo( UINT /*iTInfo*/,
84 LCID /*lcid*/,
85 ITypeInfo** /*ppTInfo*/)
86 {
87 return E_NOTIMPL;
88 }
89
90 // UnoTypeWrapper, IDispatch --------------------------------------------
GetIDsOfNames(REFIID,LPOLESTR * rgszNames,UINT,LCID,DISPID * rgDispId)91 STDMETHODIMP UnoTypeWrapper::GetIDsOfNames( REFIID /*riid*/,
92 LPOLESTR *rgszNames,
93 UINT /*cNames*/,
94 LCID /*lcid*/,
95 DISPID *rgDispId)
96 {
97 if( !rgDispId)
98 return E_POINTER;
99
100 HRESULT ret= S_OK;
101 CComBSTR name(*rgszNames);
102 name.ToLower();
103
104 if( name == CComBSTR( L"name") )
105 *rgDispId= DISPID_VALUE;
106 else
107 ret= DISP_E_UNKNOWNNAME;
108
109 return ret;
110 }
111
112 // UnoTypeWrapper, IDispatch --------------------------------------------
Invoke(DISPID dispIdMember,REFIID,LCID,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO *,UINT *)113 STDMETHODIMP UnoTypeWrapper::Invoke( DISPID dispIdMember,
114 REFIID /*riid*/,
115 LCID /*lcid*/,
116 WORD wFlags,
117 DISPPARAMS *pDispParams,
118 VARIANT *pVarResult,
119 EXCEPINFO* /*pExcepInfo*/,
120 UINT* /*puArgErr*/)
121 {
122 if (pDispParams == NULL)
123 return DISP_E_EXCEPTION;
124
125 if( pDispParams->cNamedArgs)
126 return DISP_E_NONAMEDARGS;
127
128
129 HRESULT ret= S_OK;
130 switch( dispIdMember)
131 {
132 case DISPID_VALUE: // DISPID_VALUE
133 if (wFlags & DISPATCH_PROPERTYGET)
134 {
135 if (pVarResult == NULL)
136 {
137 ret = E_POINTER;
138 break;
139 }
140 get_Name( & pVarResult->bstrVal);
141 pVarResult->vt = VT_BSTR;
142 }
143 break;
144 default:
145 ret= DISP_E_MEMBERNOTFOUND;
146 break;
147 }
148
149 return ret;
150 }
151
152 // IUnoTypeWrapper-----------------------
put_Name(BSTR val)153 STDMETHODIMP UnoTypeWrapper::put_Name(BSTR val)
154 {
155 Lock();
156 HRESULT hr = S_OK;
157 m_sName = val;
158 Unlock();
159 return hr;
160 }
161
162 // (UnoTypeWrapper-----------------------
get_Name(BSTR * pVal)163 STDMETHODIMP UnoTypeWrapper::get_Name(BSTR *pVal)
164 {
165 Lock();
166 HRESULT hr = S_OK;
167 if( !pVal)
168 return E_POINTER;
169 *pVal = m_sName.Copy();
170 Unlock();
171 return hr;
172 }
173
174
175
176