home *** CD-ROM | disk | FTP | other *** search
- //-----------------------------------------------------------------------------
- // VirtualIntfSink.h - part of the BeeGrid samples
- // Copyright ⌐ 2000,2001 Stinga
- //
- //
- //-----------------------------------------------------------------------------
-
- #include "stdafx.h"
- #include "VirtualIntfSink.h"
-
-
- BEGIN_INTERFACE_MAP(MFCBeeGridVirtualIntfSink, CCmdTarget)
- INTERFACE_PART(MFCBeeGridVirtualIntfSink, BeeGridOLEDB10::IID_IsgGridDataSource, sgGridDataSource)
- END_INTERFACE_MAP()
-
-
- MFCBeeGridVirtualIntfSink::MFCBeeGridVirtualIntfSink()
- {
- CCmdTarget::EnableAutomation();
-
- // Initialize sample data
- m_rowCount = 1000000;
- m_colCount = 3;
- }
-
- MFCBeeGridVirtualIntfSink::~MFCBeeGridVirtualIntfSink()
- {
- }
-
- BeeGridOLEDB10::IsgGridDataSourcePtr MFCBeeGridVirtualIntfSink::GetIsgGridDataSource()
- {
- IUnknownPtr spUnk;
- HRESULT hr = ExternalQueryInterface(&BeeGridOLEDB10::IID_IsgGridDataSource,
- (void**)&spUnk);
-
- BeeGridOLEDB10::IsgGridDataSourcePtr sp;
- if (SUCCEEDED(hr))
- sp = spUnk;
-
- return sp;
- }
-
-
- //-----------------------------------------------------------------------------
- // IUnknown implementation
- //-----------------------------------------------------------------------------
- STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::QueryInterface(
- REFIID riid, void **ppv)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
- return pThis->ExternalQueryInterface(&riid, ppv);
- }
-
- STDMETHODIMP_(ULONG) MFCBeeGridVirtualIntfSink::XsgGridDataSource::AddRef(void)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
- return pThis->ExternalAddRef();
- }
-
- STDMETHODIMP_(ULONG) MFCBeeGridVirtualIntfSink::XsgGridDataSource::Release(void)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
- return pThis->ExternalRelease();
- }
-
-
- //-----------------------------------------------------------------------------
- // IsgGridDataSource implementation
- //-----------------------------------------------------------------------------
- STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::AddRow(long RowIndex,
- long ColCount,
- VARIANT RowData,
- /*[out]*/ VARIANT_BOOL * Cancel)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
-
- // The AddRow function is called by the BeeGrid control when it needs to
- // add a new row to the data source. This function should return VARIANT_TRUE
- // if the new row has been added to the data store.
- //
- // Parameters:
- // RowIndex - not used in this version
- // ColCount - number of elements in the RowData array
- // RowData - array of variants with row data
-
- HRESULT hr = S_OK;
-
- if (Cancel == 0)
- return E_POINTER;
-
- return hr;
- }
-
- STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::DeleteRow(long RowIndex,
- /*[out]*/ VARIANT_BOOL * Cancel)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
-
- // The DeleteRow function is called by the BeeGrid control when it needs
- // to delete a row from the data source. This function should return
- // VARIANT_TRUE if a row has been deleted from to the data store.
- //
- // Parameters:
- // RowIndex - data index of the row to be deleted
-
- HRESULT hr = S_OK;
-
-
- if (Cancel == 0)
- return E_POINTER;
-
- return hr;
- }
-
- STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::GetRowCount(/*[out]*/ long * Res)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
-
- // The GetRowCount function is called by the BeeGrid control when it needs
- // to know exact row count. This function should return current row count.
-
- HRESULT hr = S_OK;
-
- if (Res == 0)
- return E_POINTER;
-
- *Res = pThis->m_rowCount;
-
- return hr;
- }
-
- STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::GetRowData(long RowIndex,
- long ColCount,
- /*[out]*/ VARIANT * RowData)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
-
- // The GetRowData function is called by the BeeGrid control when it
- // needs data from a particular row. This function should initialize
- // RowData parameter with array of variants. Each variant in that
- // array represents data for one row cell.
- //
- // Parameters:
- // RowIndex - index of the requested row
- // ColCount - number of elements in the RowData array
- // RowData - array of variants with row data. This array
- // has ColCount elements and is resized by the
- // caller (BeeGrid control).
-
- HRESULT hr = S_OK;
-
- // Check parameters
- if (RowData == 0)
- return E_POINTER;
- if ((RowData->vt != (VT_ARRAY|VT_VARIANT)) || (RowData->parray == 0))
- return E_INVALIDARG;
- if (ColCount < 0)
- return E_INVALIDARG;
- if ((RowIndex < 0) || (RowIndex >= pThis->m_rowCount))
- return E_INVALIDARG;
-
- SAFEARRAY* sa = RowData->parray;
- hr = ::SafeArrayLock(sa);
- if (SUCCEEDED(hr))
- {
- // Check row array
- if ((sa->cbElements < (unsigned long)ColCount) || (sa->pvData == 0))
- {
- ::SafeArrayUnlock(sa);
- return E_INVALIDARG;
- }
-
- // Get VARIANT array pointer
- VARIANT* pRowData = reinterpret_cast<VARIANT*>(sa->pvData);
-
- ::VariantClear(pRowData + 0);
- ::VariantClear(pRowData + 1);
- ::VariantClear(pRowData + 2);
- ::VariantClear(pRowData + 3);
-
- // Fill row data
- for (long col = 0; col < ColCount; ++col)
- {
- ::VariantClear(pRowData + col);
-
- pRowData[col].vt = VT_I4;
-
- switch (col)
- {
- case 0: pRowData[col].lVal = RowIndex; break;
- case 1: pRowData[col].lVal = RowIndex % 4; break;
- case 2: pRowData[col].lVal = RowIndex % 8; break;
- case 3: pRowData[col].lVal = RowIndex % 32; break;
- }
- }
- }
- ::SafeArrayUnlock(sa);
-
- return hr;
- }
-
- STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::SetRowData(long RowIndex,
- long ColCount,
- VARIANT RowData)
- {
- METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
-
- // The SetRowData function is called by the BeeGrid control when it
- // needs to update row data.
- //
- // Parameters:
- // RowIndex - index of the row that is being updated
- // ColCount - number of elements in the RowData array
- // RowData - array of variants with row data.
-
- HRESULT hr = S_OK;
-
-
- return hr;
- }
-