home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Basic / GridOne / setup.EXE / VIRTUALINTFSINK.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-09  |  7.0 KB  |  221 lines

  1. //-----------------------------------------------------------------------------
  2. // VirtualIntfSink.h - part of the BeeGrid samples
  3. // Copyright ⌐ 2000,2001 Stinga
  4. // 
  5. //
  6. //-----------------------------------------------------------------------------
  7.  
  8. #include "stdafx.h"
  9. #include "VirtualIntfSink.h"
  10.  
  11.  
  12. BEGIN_INTERFACE_MAP(MFCBeeGridVirtualIntfSink, CCmdTarget)
  13.  INTERFACE_PART(MFCBeeGridVirtualIntfSink, BeeGridOLEDB10::IID_IsgGridDataSource, sgGridDataSource)
  14. END_INTERFACE_MAP() 
  15.  
  16.  
  17. MFCBeeGridVirtualIntfSink::MFCBeeGridVirtualIntfSink()
  18. {
  19.    CCmdTarget::EnableAutomation();
  20.  
  21.    // Initialize sample data 
  22.    m_rowCount = 1000000;
  23.    m_colCount = 3;
  24. }
  25.  
  26. MFCBeeGridVirtualIntfSink::~MFCBeeGridVirtualIntfSink()
  27. {
  28. }
  29.  
  30. BeeGridOLEDB10::IsgGridDataSourcePtr MFCBeeGridVirtualIntfSink::GetIsgGridDataSource()
  31. {
  32.    IUnknownPtr spUnk;
  33.    HRESULT hr = ExternalQueryInterface(&BeeGridOLEDB10::IID_IsgGridDataSource, 
  34.                                       (void**)&spUnk);
  35.  
  36.    BeeGridOLEDB10::IsgGridDataSourcePtr sp;
  37.    if (SUCCEEDED(hr))
  38.       sp = spUnk;
  39.  
  40.    return sp;
  41. }
  42.  
  43.  
  44. //-----------------------------------------------------------------------------
  45. // IUnknown implementation
  46. //-----------------------------------------------------------------------------
  47. STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::QueryInterface(
  48.                                                            REFIID riid, void **ppv)
  49. {
  50.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  51.    return pThis->ExternalQueryInterface(&riid, ppv);
  52. }
  53.  
  54. STDMETHODIMP_(ULONG) MFCBeeGridVirtualIntfSink::XsgGridDataSource::AddRef(void)
  55. {
  56.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  57.    return pThis->ExternalAddRef();
  58. }
  59.  
  60. STDMETHODIMP_(ULONG) MFCBeeGridVirtualIntfSink::XsgGridDataSource::Release(void)
  61. {
  62.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  63.    return pThis->ExternalRelease();
  64.  
  65.  
  66. //-----------------------------------------------------------------------------
  67. // IsgGridDataSource implementation
  68. //-----------------------------------------------------------------------------
  69. STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::AddRow(long RowIndex, 
  70.                                                            long ColCount, 
  71.                                                            VARIANT RowData, 
  72.                                                            /*[out]*/ VARIANT_BOOL * Cancel)
  73. {
  74.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  75.  
  76.    // The AddRow function is called by the BeeGrid control when it needs to
  77.    // add a new row to the data source. This function should return VARIANT_TRUE
  78.    // if the new row has been added to the data store.
  79.    //
  80.    // Parameters:
  81.    //    RowIndex - not used in this version
  82.    //    ColCount - number of elements in the RowData array
  83.    //    RowData  - array of variants with row data
  84.  
  85.    HRESULT hr = S_OK;
  86.  
  87.    if (Cancel == 0)
  88.       return E_POINTER;
  89.  
  90.    return hr;
  91. }
  92.  
  93. STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::DeleteRow(long RowIndex, 
  94.                                                            /*[out]*/ VARIANT_BOOL * Cancel)
  95. {
  96.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  97.  
  98.    // The DeleteRow function is called by the BeeGrid control when it needs
  99.    // to delete a row from the data source. This function should return 
  100.    // VARIANT_TRUE if a row has been deleted from to the data store.
  101.    //
  102.    // Parameters:
  103.    //    RowIndex - data index of the row to be deleted
  104.  
  105.    HRESULT hr = S_OK;
  106.  
  107.  
  108.    if (Cancel == 0)
  109.       return E_POINTER;
  110.  
  111.    return hr;
  112. }
  113.  
  114. STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::GetRowCount(/*[out]*/ long * Res)
  115. {
  116.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  117.  
  118.    // The GetRowCount function is called by the BeeGrid control when it needs
  119.    // to know exact row count. This function should return current row count.
  120.  
  121.    HRESULT hr = S_OK;
  122.  
  123.    if (Res == 0)
  124.       return E_POINTER;
  125.  
  126.    *Res = pThis->m_rowCount;
  127.  
  128.    return hr;
  129. }
  130.  
  131. STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::GetRowData(long RowIndex, 
  132.                                                                       long ColCount, 
  133.                                                                       /*[out]*/ VARIANT * RowData)
  134. {
  135.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  136.  
  137.    // The GetRowData function is called by the BeeGrid control when it
  138.    // needs data from a particular row. This function should initialize
  139.    // RowData parameter with array of variants. Each variant in that
  140.    // array represents data for one row cell.
  141.    //
  142.    // Parameters:
  143.    //    RowIndex - index of the requested row
  144.    //    ColCount - number of elements in the RowData array
  145.    //    RowData  - array of variants with row data. This array
  146.    //               has ColCount elements and is resized by the
  147.    //               caller (BeeGrid control).
  148.  
  149.    HRESULT hr = S_OK;
  150.  
  151.    // Check parameters
  152.    if (RowData == 0)
  153.       return E_POINTER;
  154.    if ((RowData->vt != (VT_ARRAY|VT_VARIANT)) || (RowData->parray == 0))
  155.       return E_INVALIDARG;
  156.    if (ColCount < 0)
  157.       return E_INVALIDARG;
  158.    if ((RowIndex < 0) || (RowIndex >= pThis->m_rowCount))
  159.       return E_INVALIDARG;
  160.  
  161.    SAFEARRAY* sa = RowData->parray;
  162.    hr = ::SafeArrayLock(sa);
  163.    if (SUCCEEDED(hr))
  164.    {
  165.       // Check row array
  166.       if ((sa->cbElements < (unsigned long)ColCount) || (sa->pvData == 0))
  167.       {
  168.          ::SafeArrayUnlock(sa);
  169.          return E_INVALIDARG;
  170.       }
  171.  
  172.       // Get VARIANT array pointer
  173.       VARIANT* pRowData = reinterpret_cast<VARIANT*>(sa->pvData);
  174.  
  175.       ::VariantClear(pRowData + 0);
  176.       ::VariantClear(pRowData + 1);
  177.       ::VariantClear(pRowData + 2);
  178.       ::VariantClear(pRowData + 3);
  179.  
  180.       // Fill row data
  181.       for (long col = 0; col < ColCount; ++col)
  182.       {
  183.          ::VariantClear(pRowData + col);
  184.  
  185.          pRowData[col].vt = VT_I4;
  186.  
  187.          switch (col)
  188.          {
  189.             case 0: pRowData[col].lVal = RowIndex; break;
  190.             case 1: pRowData[col].lVal = RowIndex % 4; break;
  191.             case 2: pRowData[col].lVal = RowIndex % 8; break;
  192.             case 3: pRowData[col].lVal = RowIndex % 32; break;
  193.          }
  194.       }
  195.    }
  196.    ::SafeArrayUnlock(sa);
  197.  
  198.    return hr;
  199. }
  200.  
  201. STDMETHODIMP MFCBeeGridVirtualIntfSink::XsgGridDataSource::SetRowData(long RowIndex, 
  202.                                                                       long ColCount, 
  203.                                                                       VARIANT RowData)
  204. {
  205.    METHOD_PROLOGUE(MFCBeeGridVirtualIntfSink, sgGridDataSource);
  206.  
  207.    // The SetRowData function is called by the BeeGrid control when it
  208.    // needs to update row data.
  209.    //
  210.    // Parameters:
  211.    //    RowIndex - index of the row that is being updated
  212.    //    ColCount - number of elements in the RowData array
  213.    //    RowData  - array of variants with row data.
  214.  
  215.    HRESULT hr = S_OK;
  216.  
  217.  
  218.    return hr;
  219. }
  220.