merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / activex / main / SODispatchInterceptor.cpp
blob30b164079dbda957b3d56b256224cca94b1cca96
1 // SODispatchInterceptor.cpp : Implementation of CHelpApp and DLL registration.
3 #include "stdio.h"
4 #include "stdafx2.h"
5 #include "so_activex.h"
6 #include "SOActiveX.h"
7 #include "SODispatchInterceptor.h"
8 #include "com_uno_helper.h"
10 /////////////////////////////////////////////////////////////////////////////
13 STDMETHODIMP SODispatchInterceptor::InterfaceSupportsErrorInfo(REFIID riid)
15 static const IID* arr[] =
17 &IID_ISODispatchInterceptor,
20 for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
22 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
23 if (InlineIsEqualGUID(*arr[i],riid))
24 #else
25 if (::ATL::InlineIsEqualGUID(*arr[i],riid))
26 #endif
27 return S_OK;
29 return S_FALSE;
32 STDMETHODIMP SODispatchInterceptor::queryDispatch( IDispatch FAR* aURL,
33 BSTR aTargetFrameName,
34 long nSearchFlags,
35 IDispatch FAR* FAR* retVal )
37 if ( !aURL || !retVal ) return E_FAIL;
39 CComVariant aTargetUrl;
40 OLECHAR* sURLMemberName = L"Complete";
41 DISPID nURLID;
42 HRESULT hr = aURL->GetIDsOfNames( IID_NULL, &sURLMemberName, 1, LOCALE_USER_DEFAULT, &nURLID );
43 if( !SUCCEEDED( hr ) ) return hr;
45 hr = CComDispatchDriver::GetProperty( aURL, nURLID, &aTargetUrl );
46 if( !SUCCEEDED( hr ) ) return hr;
48 if( aTargetUrl.vt != VT_BSTR ) return E_FAIL;
50 USES_CONVERSION;
51 if( !strncmp( OLE2T( aTargetUrl.bstrVal ), ".uno:OpenHyperlink", 18 ) )
53 CComQIPtr< IDispatch, &IID_IDispatch > pIDisp( this );
54 if( pIDisp )
56 this->AddRef();
57 *retVal = pIDisp;
60 else
62 if( !m_xSlave )
64 *retVal = NULL;
65 return S_OK;
68 CComVariant aResult;
69 CComVariant aArgs[3];
70 aArgs[0] = CComVariant( nSearchFlags );
71 aArgs[1] = CComVariant( aTargetFrameName );
72 aArgs[2] = CComVariant( aURL );
74 hr = ExecuteFunc( m_xSlave, L"queryDispatch", aArgs, 3, &aResult );
75 if( !SUCCEEDED( hr ) || aResult.vt != VT_DISPATCH || aResult.pdispVal == NULL )
77 *retVal = NULL;
78 return S_OK;
81 *retVal = aResult.pdispVal;
83 CComQIPtr< IUnknown, &IID_IUnknown > pIUnk( *retVal );
84 if( pIUnk )
85 (*retVal)->AddRef();
88 return S_OK;
91 STDMETHODIMP SODispatchInterceptor::queryDispatches( SAFEARRAY FAR* aDescripts, SAFEARRAY FAR* FAR* retVal)
93 if ( !aDescripts || !retVal || SafeArrayGetDim( aDescripts ) != 1 )
94 return E_FAIL;
96 long nLB, nUB;
98 HRESULT hr = SafeArrayGetLBound( aDescripts, 1, &nLB );
99 if( !SUCCEEDED( hr ) ) return hr;
101 hr = SafeArrayGetUBound( aDescripts, 1, &nUB );
102 if( !SUCCEEDED( hr ) ) return hr;
103 if( nUB < nLB ) return E_FAIL;
105 *retVal = SafeArrayCreateVector( VT_DISPATCH, 0, nUB - nLB );
107 for ( long ind = nLB; ind <= nUB; ind ++ )
109 CComPtr<IDispatch> pElem;
110 SafeArrayGetElement( aDescripts, &ind, pElem );
111 if( pElem )
113 OLECHAR* pMemberNames[3] = { L"FeatureURL", L"FrameName", L"SearchFlags" };
114 CComVariant pValues[3];
115 hr = GetPropertiesFromIDisp( pElem, pMemberNames, pValues, 3 );
116 if( !SUCCEEDED( hr ) ) return hr;
117 if( pValues[0].vt != VT_DISPATCH || pValues[0].pdispVal == NULL
118 || pValues[1].vt != VT_BSTR || pValues[2].vt != VT_I4 )
119 return E_FAIL;
121 CComPtr<IDispatch> aRes;
122 hr = queryDispatch( pValues[0].pdispVal, pValues[1].bstrVal, pValues[2].lVal, &aRes );
123 SafeArrayPutElement( *retVal, &ind, aRes );
127 return S_OK;
131 STDMETHODIMP SODispatchInterceptor::dispatch( IDispatch FAR* aURL, SAFEARRAY FAR* aArgs)
133 // get url from aURL
134 OLECHAR* pUrlName = L"Complete";
135 CComVariant pValue;
136 HRESULT hr = GetPropertiesFromIDisp( aURL, &pUrlName, &pValue, 1 );
137 if( !SUCCEEDED( hr ) ) return hr;
138 if( pValue.vt != VT_BSTR || pValue.bstrVal == NULL )
139 return E_FAIL;
141 USES_CONVERSION;
142 if( !strncmp( OLE2T( pValue.bstrVal ), ".uno:OpenHyperlink", 18 ) )
144 long nLB = 0, nUB = 0;
145 // long nDim = SafeArrayGetDim( aArgs );
147 hr = SafeArrayGetLBound( aArgs, 1, &nLB );
148 if( !SUCCEEDED( hr ) ) return hr;
150 hr = SafeArrayGetUBound( aArgs, 1, &nUB );
151 if( !SUCCEEDED( hr ) ) return hr;
152 if( nUB < nLB ) return E_FAIL;
154 for ( long ind = nLB; ind <= nUB; ind ++ )
156 CComVariant pVarElem;
157 SafeArrayGetElement( aArgs, &ind, &pVarElem );
158 if( pVarElem.vt == VT_DISPATCH && pVarElem.pdispVal != NULL )
160 OLECHAR* pMemberNames[2] = { L"Name", L"Value" };
161 CComVariant pValues[2];
162 hr = GetPropertiesFromIDisp( pVarElem.pdispVal, pMemberNames, pValues, 2 );
163 if( !SUCCEEDED( hr ) ) return hr;
165 if( pValues[0].vt == VT_BSTR && pValues[1].vt == VT_BSTR )
167 USES_CONVERSION;
168 if( !strncmp( OLE2T( pValues[0].bstrVal ), "URL", 3 ) )
170 EnterCriticalSection( &mMutex );
171 if( m_xParentControl )
173 // call GetUrl to the browser instance
174 m_xParentControl->GetURL( pValues[1].bstrVal, L"_self" );
176 LeaveCriticalSection( &mMutex );
178 break;
185 return S_OK;
188 STDMETHODIMP SODispatchInterceptor::addStatusListener( IDispatch FAR* /*xControl*/, IDispatch FAR* /*aURL*/)
190 // not implemented
191 return S_OK;
194 STDMETHODIMP SODispatchInterceptor::removeStatusListener( IDispatch FAR* /*xControl*/, IDispatch FAR* /*aURL*/)
196 // not implemented
197 return S_OK;
200 STDMETHODIMP SODispatchInterceptor::getInterceptedURLs( SAFEARRAY FAR* FAR* pVal )
202 *pVal = SafeArrayCreateVector( VT_BSTR, 0, 3 );
204 if( !*pVal )
205 return E_FAIL;
207 long ix = 0;
208 CComBSTR aPattern( OLESTR( "ftp://*" ) );
209 SafeArrayPutElement( *pVal, &ix, aPattern );
211 ix = 1;
212 aPattern = CComBSTR( OLESTR( "http://*" ) );
213 SafeArrayPutElement( *pVal, &ix, aPattern );
215 ix = 2;
216 aPattern = CComBSTR( OLESTR( "file://*" ) );
217 SafeArrayPutElement( *pVal, &ix, aPattern );
219 return S_OK;