📄 supergridctrl.cpp
字号:
}
SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText);
}
void CSuperGridCtrl::DeleteAll()
{
POSITION pos = m_RootItems.GetHeadPosition();
while(pos!=NULL)
{
CTreeItem * pRoot = (CTreeItem*)m_RootItems.GetNext(pos);
if(pRoot!=NULL)
DeleteItemEx(pRoot, 0);
}
}
POSITION CSuperGridCtrl::GetRootHeadPosition() const
{
return m_RootItems.GetHeadPosition();
}
POSITION CSuperGridCtrl::GetRootTailPosition() const
{
return m_RootItems.GetTailPosition();
}
CSuperGridCtrl::CTreeItem* CSuperGridCtrl::GetNextRoot(POSITION& pos) const
{
return (CTreeItem*)m_RootItems.GetNext(pos);
}
CSuperGridCtrl::CTreeItem* CSuperGridCtrl::GetPrevRoot(POSITION& pos) const
{
return (CTreeItem*)m_RootItems.GetNext(pos);
}
POSITION CSuperGridCtrl::GetHeadPosition(CTreeItem* pItem) const
{
return pItem->m_listChild.GetHeadPosition();
}
CSuperGridCtrl::CTreeItem* CSuperGridCtrl::GetNextChild(CTreeItem *pItem, POSITION& pos) const
{
return (CTreeItem*)pItem->m_listChild.GetNext(pos);
}
CSuperGridCtrl::CTreeItem* CSuperGridCtrl::GetPrevChild(CTreeItem *pItem, POSITION& pos) const
{
return (CTreeItem*)pItem->m_listChild.GetPrev(pos);
}
POSITION CSuperGridCtrl::GetTailPosition(CTreeItem *pItem) const
{
return pItem->m_listChild.GetTailPosition();
}
void CSuperGridCtrl::AddTail(CTreeItem *pParent, CTreeItem *pChild)
{
pParent->m_listChild.AddTail(pChild);
}
inline int StrComp(const CString* pElement1, const CString* pElement2)
{
return pElement1->Compare(*pElement2);
}
int CSuperGridCtrl::CompareChildren(const void* p1, const void* p2)
{
CTreeItem * pChild1 = *(CTreeItem**)p1;
CTreeItem * pChild2 = *((CTreeItem**)p2);
CItemInfo *pItem1=(*pChild1).m_lpNodeInfo;
CItemInfo *pItem2=(*pChild2).m_lpNodeInfo;
return StrComp(&(pItem1->GetItemText()), &(pItem2->GetItemText()));
}
void CSuperGridCtrl::Sort(CTreeItem* pParent, BOOL bSortChildren)
{
const int nChildren = NumChildren(pParent);
if (nChildren > 1)
{
CTreeItem** ppSortArray = new CTreeItem*[nChildren];
// Fill in array with pointers to our children.
POSITION pos = pParent->m_listChild.GetHeadPosition();
for (int i=0; pos; i++)
{
ASSERT(i < nChildren);
ppSortArray[i] = (CTreeItem*)pParent->m_listChild.GetAt(pos);
pParent->m_listChild.GetNext(pos);
}
qsort(ppSortArray, nChildren, sizeof(CTreeItem*), CompareChildren);
// reorg children with new sorted list
pos = pParent->m_listChild.GetHeadPosition();
for (i=0; pos; i++)
{
ASSERT(i < nChildren);
pParent->m_listChild.SetAt(pos, ppSortArray[i]);
pParent->m_listChild.GetNext(pos);
}
delete [] ppSortArray;
}
if(bSortChildren)
{
POSITION pos = pParent->m_listChild.GetHeadPosition();
while (pos)
{
CTreeItem *pChild = (CTreeItem*)pParent->m_listChild.GetNext(pos);
Sort(pChild, TRUE);
}
}
}
int CSuperGridCtrl::NumChildren(const CTreeItem *pItem) const
{
return pItem->m_listChild.GetCount();
}
BOOL CSuperGridCtrl::ItemHasChildren(const CTreeItem* pItem) const
{
BOOL bChildren = pItem->m_listChild.GetCount() != 0;
//see if we have a flag
int nFlag = pItem->m_bSetChildFlag;
if(nFlag!=-1)
return 1;
else
return bChildren;
}
void CSuperGridCtrl::SetChildrenFlag(CTreeItem *pItem, int nFlag) const
{
pItem->m_bSetChildFlag = nFlag;
}
BOOL CSuperGridCtrl::IsCollapsed(const CTreeItem* pItem) const
{
return pItem->m_bHideChildren;//e.g not visible
}
void CSuperGridCtrl::Hide(CTreeItem* pItem, BOOL bFlag)
{
pItem->m_bHideChildren=bFlag;
}
int CSuperGridCtrl::GetIndent(const CTreeItem* pItem) const
{
return pItem->m_nIndent;
}
void CSuperGridCtrl::SetIndent(CTreeItem *pItem, int iIndent)
{
pItem->m_nIndent = iIndent;
}
int CSuperGridCtrl::GetCurIndex(const CTreeItem *pItem) const
{
return pItem->m_nIndex;
}
void CSuperGridCtrl::SetCurIndex(CTreeItem* pItem, int nIndex)
{
pItem->m_nIndex = nIndex;
}
void CSuperGridCtrl::SetParentItem(CTreeItem*pItem, CTreeItem* pParent)
{
pItem->m_pParent=pParent;
}
CSuperGridCtrl::CTreeItem* CSuperGridCtrl::GetParentItem(const CTreeItem* pItem)
{
return pItem->m_pParent;
};
CItemInfo* CSuperGridCtrl::GetData(const CTreeItem* pItem)
{
return pItem->m_lpNodeInfo;
}
void CSuperGridCtrl::UpdateData(CTreeItem* pItem, CItemInfo* lpInfo)
{
pItem->m_lpNodeInfo = lpInfo;
}
//overrides
CItemInfo* CSuperGridCtrl::CopyData(CItemInfo* lpSrc)
{
ASSERT(FALSE);//debug
return NULL; //release
}
//default implementation for setting icons
int CSuperGridCtrl::GetIcon(const CTreeItem* pItem)
{
return 0;//just take the first item in CImageList ..what ever that is
}
void CSuperGridCtrl::OnControlLButtonDown(UINT nFlags, CPoint point, LVHITTESTINFO& ht)
{
if(ht.iSubItem==0)
{
CRect rcItem;
GetItemRect(ht.iItem, rcItem, LVIR_LABEL);
DWORD dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL|ES_LEFT;
// CEdit *pEdit = new CListEditCtrl(ht.iItem, ht.iSubItem, GetItemText(ht.iItem, ht.iSubItem));
// pEdit->Create(dwStyle, rcItem, this, 0x1233);
}
// else
// EditLabelEx(ht.iItem, ht.iSubItem);
}
COLORREF CSuperGridCtrl::GetCellRGB()
{
return RGB(192,0,0);
}
BOOL CSuperGridCtrl::OnVKMultiply(CTreeItem *pItem, int nIndex)
{
return 1;
}
BOOL CSuperGridCtrl::OnVkSubTract(CTreeItem *pItem, int nIndex)
{
return 1;
}
BOOL CSuperGridCtrl::OnVKAdd(CTreeItem *pItem, int nIndex)
{
return 1;
}
BOOL CSuperGridCtrl::OnDeleteItem(CTreeItem* pItem, int nIndex)
{
return 1;
}
BOOL CSuperGridCtrl::OnItemExpanding(CTreeItem *pItem, int iItem)
{
return 1;
}
BOOL CSuperGridCtrl::OnItemExpanded(CTreeItem* pItem, int iItem)
{
return 1;
}
BOOL CSuperGridCtrl::OnCollapsing(CTreeItem *pItem)
{
return 1;
}
BOOL CSuperGridCtrl::OnItemCollapsed(CTreeItem *pItem)
{
return 1;
}
BOOL CSuperGridCtrl::OnItemLButtonDown(LVHITTESTINFO& ht)
{
return 1;
}
BOOL CSuperGridCtrl::OnVkReturn(void)
{
return 0;
}
void CSuperGridCtrl::OnSysColorChange()
{
CListCtrl::OnSysColorChange();
//nop nothing yet
}
UINT CSuperGridCtrl::_GetCount(CTreeItem* pItem, UINT& nCount)
{
POSITION pos = pItem->m_listChild.GetHeadPosition();
while (pos)
{
CTreeItem *pChild = (CTreeItem*)pItem->m_listChild.GetNext(pos);
nCount = _GetCount(pChild, nCount);
nCount++;
}
return nCount;
}
UINT CSuperGridCtrl::GetCount(void)
{
UINT nCount=0;
POSITION pos = m_RootItems.GetHeadPosition();
while(pos!=NULL)
{
CTreeItem * pRoot = (CTreeItem*)m_RootItems.GetNext(pos);
UINT _nCount=0;
nCount += _GetCount(pRoot, _nCount) + 1;
}
return nCount;
}
CSuperGridCtrl::CTreeItem* CSuperGridCtrl::GetTreeItem(int nIndex /*nIndex must be valid of course*/ )
{
return reinterpret_cast<CTreeItem*>(GetItemData(nIndex));
}
int CSuperGridCtrl::GetSelectedItem(void) const
{
return GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
}
//////////////////////////////////////////////////////////////////////////
//
// not much but ...
//
//////////////////////////////////////////////////////////////////////////
CSuperGridCtrl::CTreeItem::~CTreeItem()
{
// delete child nodes
POSITION pos = m_listChild.GetHeadPosition();
while (pos != NULL)
{
CTreeItem* pItem = (CTreeItem*)m_listChild.GetNext(pos);
if(pItem!=NULL)
{
if(pItem->m_lpNodeInfo!=NULL)
delete pItem->m_lpNodeInfo;
delete pItem;
}
}
m_listChild.RemoveAll();
}
void CSuperGridCtrl::DrawProgressBar(CDC* pDC, int iItem, int iSubItem)
{
ASSERT(pDC);
CRect rect;
BOOL bRC = CListCtrl::GetSubItemRect(iItem, iSubItem, LVIR_LABEL, rect);
// GetProgressRect(id, rect, false);
//First, fill area outside progress bar with background color
{
CRect outrect;
GetSubItemRect(iItem, iSubItem, LVIR_BOUNDS, outrect);
// GetTextRect(id, outrect);
pDC->SaveDC();
pDC->ExcludeClipRect(&rect);
FillSolidRect(pDC, outrect, RGB(0,0,0));
pDC->RestoreDC(-1);
}
// if(id.m_edge != 0)
{
// draw border
pDC->DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
}
// GetProgressRect(id, rect, true);
// fill interior with background color
FillSolidRect(pDC, rect, RGB(128,0,0)); //id.m_progressBar.m_fillColor==DEFAULTCOLOR));
// if (id.m_value > 0)
{
// draw progress bar and text
// rect.right = rect.left + GetBarSize(id, rect);
COLORREF fill = ::GetSysColor(COLOR_GRAYTEXT);
FillSolidRect(pDC, rect, fill);
}
}
//Custom draw
/*void CSuperGridCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// *pResult = 0; return;
// If this is the beginning of the control's paint cycle, request
// notifications for each item.
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
// This is the pre-paint stage for an item. We need to make another
// request to be notified during the post-paint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;;
}
else if ( (CDDS_ITEMPREPAINT| CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
DrawProgressBar(pDC, static_cast<int> (pLVCD->nmcd.dwItemSpec), pLVCD->iSubItem);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
}*/
//////////////////////////////////////////////////////////////////////////
//
// Simple class CRectangle for the + - sign,
//
//////////////////////////////////////////////////////////////////////////
CRectangle::CRectangle(CSuperGridCtrl* pCtrl, CDC* pDC, int iIndent, const CRect& rcBounds)
{
m_pDC=pDC;
int nHalfImage = (pCtrl->m_cxImage >> 1);
int nBottomDown = rcBounds.top + nHalfImage + ((rcBounds.Height() - pCtrl->m_cyImage) >> 1);
m_right_bottom.cx = (pCtrl->m_cxImage>>1)+2+1;
m_right_bottom.cy = (pCtrl->m_cyImage>>1)+2+1;
m_left = rcBounds.left + iIndent * pCtrl->m_cxImage - nHalfImage;
m_top = nBottomDown - (m_right_bottom.cy >> 1);
m_left_top.x = m_left - (m_right_bottom.cx >> 1);
m_left_top.y = m_top;
m_topdown = nBottomDown;
}
void CRectangle::DrawRectangle(CSuperGridCtrl* pCtrl)
{
//erase bkgrnd
CRect rc(m_left_top, m_right_bottom);
m_pDC->FillRect(rc, &pCtrl->m_brushErase);
//draw rectangle
CPen* pPenRectangle = m_pDC->SelectObject(&pCtrl->m_psRectangle);
m_pDC->Rectangle(rc);
m_pDC->SelectObject(pPenRectangle);
}
CRectangle::~CRectangle()
{
}
BOOL CRectangle::HitTest(CPoint pt)
{
CRect rc = GetHitTestRect();
return rc.PtInRect(pt);
}
void CRectangle::DrawPlus(void)
{
m_pDC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -