Skip to content

Commit

Permalink
Merge pull request #11 from xiaoweihan/master
Browse files Browse the repository at this point in the history
合并代码
  • Loading branch information
vbtang authored Jun 24, 2017
2 parents da6c892 + c9a468a commit 4790252
Show file tree
Hide file tree
Showing 18 changed files with 736 additions and 57 deletions.
224 changes: 217 additions & 7 deletions Src/Edislab/Edislab Pro/CustomGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
#include "Msg.h"
//默认增加列的宽度
const int DEFAULT_COLUMN_WIDTH = 20;
//默认的初始行数
const int DEFAULT_ROW_NUM = 60;
IMPLEMENT_DYNCREATE(CCustomGrid, CBCGPGridCtrl)
CCustomGrid::CCustomGrid():m_nDisplayVitrualRows(60),
m_pCallBack(nullptr)
CCustomGrid::CCustomGrid():
m_pCallBack(nullptr),
m_nDisplayRows(DEFAULT_ROW_NUM)
{
m_HeaderInfoArray.clear();
}
Expand Down Expand Up @@ -60,15 +63,18 @@ int CCustomGrid::OnCreate(LPCREATESTRUCT lpCreateStruct)
SetEditFirstClick(FALSE);
SetWholeRowSel(TRUE);
m_ColumnsEx.EnableAutoSize(TRUE);
CreateHeaderInfo();
CreateColumnInfo();

if (nullptr != m_pCallBack)
{
EnableVirtualMode(m_pCallBack,(LPARAM)this);
SetVirtualRows(m_nDisplayVitrualRows);
SetVirtualRows(m_nDisplayRows);
}
else
{
CreateRowInfo();
}

CreateHeaderInfo();
CreateColumnInfo();
AdjustLayout();
return 0;
}
Expand Down Expand Up @@ -144,7 +150,16 @@ void CCustomGrid::DynamicSetHeaderInfoArray(const std::vector<COLUMN_GROUP_INFO>
//重新设置列
CreateHeaderInfo();
CreateColumnInfo();
m_CachedItems.CleanUpCache();

if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
else
{
CreateRowInfo();
}

AdjustLayout();
}

Expand Down Expand Up @@ -188,6 +203,16 @@ void CCustomGrid::AddHeaderInfo(const COLUMN_GROUP_INFO& HeaderInfo)
//重新设置列
CreateHeaderInfo();
CreateColumnInfo();

if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
else
{
CreateRowInfo();
}

AdjustLayout();
}

Expand Down Expand Up @@ -236,6 +261,16 @@ void CCustomGrid::RemoveHeaderInfo(const CString& strHeaderName)
//重新设置列
CreateHeaderInfo();
CreateColumnInfo();

if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
else
{
CreateRowInfo();
}

AdjustLayout();
}

Expand Down Expand Up @@ -301,6 +336,16 @@ void CCustomGrid::RemoveColumn(const CString& strColumnName)
m_ColumnsEx.DeleteAllColumns();
CreateHeaderInfo();
CreateColumnInfo();

if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
else
{
CreateRowInfo();
}

AdjustLayout();
}

Expand Down Expand Up @@ -373,6 +418,15 @@ void CCustomGrid::AddColumnInfo(const CString& strHeaderName,const CString& strC
CreateHeaderInfo();
CreateColumnInfo();

if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
else
{
CreateRowInfo();
}

AdjustLayout();
}

Expand Down Expand Up @@ -473,6 +527,66 @@ void CCustomGrid::GetHeaderInfo(std::vector<COLUMN_GROUP_INFO>& HeaderInfoArray)
HeaderInfoArray.assign(m_HeaderInfoArray.begin(),m_HeaderInfoArray.end());
}

/*******************************************************************
*函数名称:SetDisplayRow
*功能描述:设置显示列
*输入参数:
*输出参数:
*返回值:
*作者:xiaowei.han
*日期:2017/06/17 22:55:33
*******************************************************************/
void CCustomGrid::SetDisplayRow(int nRow)
{
int nTotalRowNum = GetRowCount();

if (TRUE == IsVirtualMode())
{
if (nRow > nTotalRowNum)
{
SetVirtualRows(nRow);
}
}
else
{
if (nRow > nTotalRowNum)
{
for (int i = 0; i < (nRow - nTotalRowNum); ++i)
{
CBCGPGridRow* pRow = CreateRow(GetColumnCount());
if (nullptr != pRow)
{
AddRow(pRow,FALSE);
}
}
}

}

m_nDisplayRows = (std::max)(m_nDisplayRows,nRow);

AdjustLayout();
}

/*******************************************************************
*函数名称:刷新Grid
*功能描述:
*输入参数:
*输出参数:
*返回值:
*作者:xiaowei.han
*日期:2017/06/17 22:44:48
*******************************************************************/
void CCustomGrid::Refresh(void)
{
//清空缓存
if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
AdjustLayout();
}

/*******************************************************************
*函数名称:GetColumnGroupDisplayInfo
*功能描述:获取显示信息
Expand Down Expand Up @@ -586,6 +700,90 @@ void CCustomGrid::SetColumnGroupDisplayInfo(const std::vector<SHOW_COLUMN_GROUP_
AdjustLayout();
}

/*******************************************************************
*函数名称:SetColumnData
*功能描述:设置列数据
*输入参数:
*输出参数:
*返回值:
*作者:xiaowei.han
*日期:2017/06/17 22:19:28
*******************************************************************/
void CCustomGrid::SetColumnData(int nRowIndex,int nColumnIndex,float fData)
{
//不支持
if (TRUE == IsVirtualMode())
{
return;
}

if (NULL == GetSafeHwnd())
{
return;
}
int nTotalRowNum = GetTotalRowCount();
//参数合法性判断
if (nRowIndex < 0 && nRowIndex >= nTotalRowNum)
{
return;
}
int nTotalColumnNum = GetColumnCount();
//列数不相等
if (nColumnIndex < 0 || nColumnIndex >= nTotalColumnNum)
{
return;
}

//获取指定的行指针
CBCGPGridRow* pRow = GetRow(nRowIndex);
if (nullptr != pRow)
{
CBCGPGridItem* pItem = pRow->GetItem(nColumnIndex);
if (nullptr != pItem)
{
pItem->SetValue(fData,FALSE);
}
}
}

/*******************************************************************
*函数名称:InsertRow
*功能描述:插入一行
*输入参数:
*输出参数:
*返回值:
*作者:xiaowei.han
*日期:2017/06/17 23:14:05
*******************************************************************/
void CCustomGrid::InsertRow(int nRow,bool bBefore /*= true*/)
{
CBCGPGridRow* pInsertRow = CreateRow(GetColumnCount());
if (nullptr == pInsertRow)
{
return;
}
if (bBefore)
{
InsertRowBefore(nRow,pInsertRow,FALSE);
}
else
{
InsertRowAfter(nRow,pInsertRow,FALSE);
}

m_nDisplayRows += 1;
AdjustLayout();
}

bool CCustomGrid::IsVirtualGrid(void)
{
if (TRUE == IsVirtualMode())
{
return true;
}
return false;
}

void CCustomGrid::CreateColumnInfo(void)
{

Expand All @@ -606,6 +804,18 @@ void CCustomGrid::CreateColumnInfo(void)

}

void CCustomGrid::CreateRowInfo(void)
{
for (int i = 0; i < m_nDisplayRows; ++i)
{
CBCGPGridRow* pRow = CreateRow(GetColumnCount());
if (nullptr != pRow)
{
AddRow(pRow,FALSE);
}
}
}

void CCustomGrid::CreateHeaderInfo(void)
{
if (m_HeaderInfoArray.empty())
Expand Down
33 changes: 16 additions & 17 deletions Src/Edislab/Edislab Pro/CustomGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,37 @@ class CCustomGrid : public CBCGPGridCtrl
{
m_pCallBack = pCallBack;
}

//设置虚行数
void SetDisplayVirtualRows(int nVirtualRows)
//设置初始显示的行数
void SetInitDisplayRow(int nRows)
{
m_nDisplayVitrualRows = nVirtualRows;
}

//刷新虚表显示
void Refresh(void)
{
//清空缓存
if (TRUE == IsVirtualMode())
{
m_CachedItems.CleanUpCache();
}
AdjustLayout();
m_nDisplayRows = nRows;
}

//设置行数
void SetDisplayRow(int nRow);
//刷新Grid显示
void Refresh(void);
//获取列分组的显示信息
void GetColumnGroupDisplayInfo(std::vector<SHOW_COLUMN_GROUP_INFO>& DisplayArray);
//设置分组的显示信息
void SetColumnGroupDisplayInfo(const std::vector<SHOW_COLUMN_GROUP_INFO>& DisplayArray);

//设置数据(用于非虚表模式下)
void SetColumnData(int nRowIndex,int nColumnIndex,float fData);
//插入一行
void InsertRow(int nRow,bool bBefore = true);
//是否是虚表模式
bool IsVirtualGrid(void);
private:
//创建列信息
void CreateHeaderInfo(void);
//创建列信息
void CreateColumnInfo(void);
//创建所有行信息
void CreateRowInfo(void);
protected:
std::vector<COLUMN_GROUP_INFO> m_HeaderInfoArray;
BCGPGRID_CALLBACK m_pCallBack;
int m_nDisplayVitrualRows;
int m_nDisplayRows;
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnTimer(UINT_PTR nIDEvent);
Expand Down
36 changes: 36 additions & 0 deletions Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "StdAfx.h"
#include "CustomTreeCtrl.h"
#include "Msg.h"
IMPLEMENT_DYNAMIC(CCustomTreeCtrl, CBCGPTreeCtrlEx)

CCustomTreeCtrl::CCustomTreeCtrl(void)
{
}


CCustomTreeCtrl::~CCustomTreeCtrl(void)
{
}

BEGIN_MESSAGE_MAP(CCustomTreeCtrl, CBCGPTreeCtrlEx)
ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

void CCustomTreeCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值

HTREEITEM hDBClikeItem = HitTest(point);

if (NULL != hDBClikeItem)
{
CWnd* pWnd = GetParent();

if (nullptr != pWnd)
{
pWnd->PostMessage(WM_NOTIFY_TREE_CTRL_DBCLICK,(WPARAM)hDBClikeItem,0);
}
}

CBCGPTreeCtrlEx::OnLButtonDblClk(nFlags, point);
}
Loading

0 comments on commit 4790252

Please sign in to comment.