?? ghswatchcursor.cpp
字號:
// GHSwatchCursor.cpp : Implementation of CGHSwatchCursor
#include "stdafx.h"
#include "GHSwatchCursor.h"
#include ".\ghswatchcursor.h"
#include "SwatchData.h"
// CGHSwatchCursor
void NextCursor(std::list<CSwatchData*>::iterator& pos);
void DummyNextCursor(std::list<CSwatchData*>::iterator& pos);
//Advance the position of the cursor by one and return the Row object at that position
STDMETHODIMP CGHSwatchCursor::NextRow(IGHRow** row)
{
ATLASSERT(m_pGHSwatch!=NULL);
if(row==NULL)
return E_POINTER;
m_mfNextFunc(m_Cursor); //Next cursor
m_mfNextFunc=NextCursor;
if (IsEOF()) //At the end
{
*row=NULL;
return S_OK;
}
HRESULT hr;
if (m_bRecycling) //Recycling Cursor
{
ATLASSERT(m_pRecyclingRow!=NULL);
hr=m_pRecyclingRow->Initial(*m_Cursor);
hr=m_pRecyclingRow->QueryInterface(IID_IGHRow,(void**)row);
}
else //UnRecycling cursor, create a new IGHRow
{
CComObject<CGHRow> *pGHRow;
hr=CComObject<CGHRow>::CreateInstance(&pGHRow);
if(FAILED(hr))
return hr;
hr=pGHRow->InitialOnce(m_pGHSwatch,m_bReadOnly);
hr=pGHRow->Initial(*m_Cursor);
hr=pGHRow->QueryInterface(IID_IGHRow,(void**)row);
}
return hr;
}
//Insert a new row into the Swatch using the values of the input row before current cursor
//
STDMETHODIMP CGHSwatchCursor::InsertRow(IGHRow* row)
{
ATLASSERT(!m_bReadOnly); //Use read-only cursor to modify
/*if (m_bReadOnly)
return E_UNEXPECTED;*/
if(row==NULL)
return E_POINTER;
//CComPtr<IUnknown> cpUnknown;
//HRESULT hr;
//hr=row->QueryInterface(IID_IUnknown,(void**)&cpUnknown);
//
//if(S_OK==hr)
//{
// //
// //DO NOT use the _ATL_DEBUG_INTERFACES pre-compiler macro,
// //'cause it's use the thunk IUnknown
// CComObject<CGHRow> *pRow=(CComObject<CGHRow> *)cpUnknown.p;
// ATLASSERT(pRow);
// CSwatchData* pSwatchData;
// if (pRow->m_bRequireDelete)
// {
// pSwatchData=pRow->Detch();
// }
// else
// {
// }
// m_Cursor=m_pGHSwatch->m_listSwatch.insert(m_Cursor,pSwatchData);
//
// //Initial input row to the reference of Swatch
// pRow->InitialOnce(m_pGHSwatch,m_bReadOnly);
// pRow->Initial(pSwatchData);
//
//}
//
//return hr;
LONG lSize;
m_pGHSwatch->get_FieldCount(&lSize); //m_cpIndexs->get_Count(&lSize);
CSwatchData* pSwatchData=new CSwatchData(lSize);
FLOAT fValue;
for (LONG i=0;i<lSize;i++)
{
row->get_Value(i,&fValue);
pSwatchData->set_Value(i,fValue);
}
m_pGHSwatch->m_listSwatch.insert(m_Cursor,pSwatchData);
return S_OK;
}
//Delete the existing Row in the swatch corresponding to the current position of the cursor,
//and set the cursor to next available position
STDMETHODIMP CGHSwatchCursor::DeleteRow()
{
ATLASSERT(!IsEOF()); //At the end
ATLASSERT(!m_bReadOnly); //Use read-only cursor to modify
delete *m_Cursor;
m_Cursor=m_pGHSwatch->m_listSwatch.erase(m_Cursor);
m_mfNextFunc=DummyNextCursor;
return S_OK;
}
STDMETHODIMP CGHSwatchCursor::Flush(void)
{
return S_OK;
}
//Called by CGHSwatch::Update or CGHSwatch::Search after create a CComobject<CGHSwatchCursor>,use this to initial
HRESULT CGHSwatchCursor::Initial(CComObject<CGHSwatch>* pGHSwatch,
BOOL bReadOnly /* = TRUE */,BOOL bRecyling/* =TRUE */)
{
if(NULL==pGHSwatch)
return E_POINTER;
//Add a reference of IGHSwatch,avoid the below situation:
//IGHSwatch has released,but the cursor is still alive
if (m_pGHSwatch)
m_pGHSwatch->Release();
m_pGHSwatch=pGHSwatch;
m_pGHSwatch->AddRef();
//Initial the cursor at the begin
Reset();
m_bReadOnly=bReadOnly;
m_bRecycling=bRecyling;
HRESULT hr=S_OK;
if (m_bRecycling&&m_pRecyclingRow==NULL) //Create Recycling IGHRow
{
hr=CComObject<CGHRow>::CreateInstance(&m_pRecyclingRow);
if (hr==S_OK)
{
m_pRecyclingRow->AddRef();
m_pRecyclingRow->InitialOnce(pGHSwatch,bReadOnly);
}
}
return hr;
}
//Reset the cursor to the begin
STDMETHODIMP CGHSwatchCursor::Reset(void)
{
m_mfNextFunc=DummyNextCursor;
m_Cursor=m_pGHSwatch->m_listSwatch.begin();
return S_OK;
}
BOOL CGHSwatchCursor::IsEOF()
{
return m_Cursor==m_pGHSwatch->m_listSwatch.end();
}
void NextCursor(std::list<CSwatchData*>::iterator& pos)
{
++pos;
}
void DummyNextCursor(std::list<CSwatchData*>::iterator& pos)
{
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -