// SuperGridCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "SuperGrid.h"
#include "SuperGridCtrl.h"
#include "ListEditCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSuperGridCtrl
CSuperGridCtrl::CSuperGridCtrl()
{
m_cxImage = m_cyImage = m_bIsDragging = m_CurSubItem = 0;
m_nDragTarget=m_nDragItem = -1;
m_psTreeLine.CreatePen(PS_SOLID, 1, RGB(192,192,192));
m_psRectangle.CreatePen(PS_SOLID, 1, RGB(198,198,198));
m_psPlusMinus.CreatePen(PS_SOLID, 1, RGB(0,0,0));
m_brushErase.CreateSolidBrush(RGB(255,255,255));
m_himl = NULL;
}
CSuperGridCtrl::~CSuperGridCtrl()
{
m_psPlusMinus.DeleteObject();
m_psRectangle.DeleteObject();
m_psTreeLine.DeleteObject();
m_brushErase.DeleteObject();
while(m_RootItems.GetCount())
{
CTreeItem * root = (CTreeItem*)m_RootItems.RemoveHead();
if(root!=NULL && GetData(root) != NULL)
delete GetData(root);
delete root;
}
m_RootItems.RemoveAll();
}
BEGIN_MESSAGE_MAP(CSuperGridCtrl, CListCtrl)
//{{AFX_MSG_MAP(CSuperGridCtrl)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, OnEndlabeledit)
ON_WM_CREATE()
ON_WM_HSCROLL()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
ON_WM_VSCROLL()
ON_WM_LBUTTONUP()
ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBegindrag)
ON_WM_MEASUREITEM_REFLECT()
ON_WM_DRAWITEM_REFLECT()
ON_WM_SYSCOLORCHANGE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSuperGridCtrl message handlers
BOOL CSuperGridCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= LVS_REPORT | LVS_SINGLESEL | LVS_SHAREIMAGELISTS | LVS_OWNERDRAWFIXED | LVS_SHOWSELALWAYS;
return CListCtrl::PreCreateWindow(cs);
}
int CSuperGridCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
#define OFFSET_FIRST 2
#define OFFSET_OTHER 6
void CSuperGridCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (lpDrawItemStruct->CtlType != ODT_LISTVIEW)
return;
if(lpDrawItemStruct->itemAction == ODA_DRAWENTIRE)
{
if(m_himl==NULL)
{
m_himl = (HIMAGELIST)::SendMessage(m_hWnd, LVM_GETIMAGELIST, (WPARAM)(int)(LVSIL_SMALL), 0L);
if(m_himl==NULL)
return;
}
LV_ITEM lvi;
static _TCHAR szBuff[MAX_PATH];
LPCTSTR pszText;
int nItem = lpDrawItemStruct->itemID;
CRect rcItem(lpDrawItemStruct->rcItem);
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_INDENT | LVIF_PARAM;
lvi.iItem = nItem;
lvi.iSubItem =0;
lvi.pszText = szBuff;
lvi.cchTextMax = sizeof(szBuff);
lvi.stateMask = 0xFFFF;
GetItem(&lvi);
CTreeItem *pSelItem = (CTreeItem*)lpDrawItemStruct->itemData;
CRect rcLabel;
GetItemRect(nItem, rcLabel, LVIR_LABEL);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
ASSERT(pDC);
CRect rcClipBox;
pDC->GetClipBox(rcClipBox);
COLORREF crBackground, crText;
if (lpDrawItemStruct->itemState & ODS_SELECTED)
{
// Set the text background and foreground colors
crBackground = GetSysColor (COLOR_HIGHLIGHT);
crText = GetSysColor (COLOR_HIGHLIGHTTEXT);
}
else
{
// Set the text background and foreground colors to the standard window
// colors
crBackground = GetSysColor (COLOR_WINDOW);
crText = GetSysColor (COLOR_WINDOWTEXT);
}
//Get current Icon, you have overridden this I hope :-)
int iImage = GetIcon(pSelItem);
if(iImage!=-1)
{
if(lvi.iImage!=iImage)
{
LV_ITEM lvItem;
lvItem.mask = LVIF_IMAGE;
lvItem.iImage = iImage;
lvItem.iItem = nItem;
lvItem.iSubItem = 0;
SetItem(&lvItem);
lvi.iImage = iImage;
}
}
CRect rc;
GetItemRect(nItem, rc, LVIR_BOUNDS);
CRect rcIcon;
GetItemRect(nItem, rcIcon, LVIR_ICON);
//Draw Current image
int nOffset = (rcItem.Height() - m_cyImage)/2;
int nY = rcItem.bottom - m_cyImage - nOffset;
int nWidth = m_cxImage;//def icon size
//do not draw icon out side 1.st column.
int iTryIndent = GetIndent(pSelItem) * m_cxImage + m_cxImage;
if(rc.left + iTryIndent > GetColumnWidth(0)-2/*looks better -2*/)
nWidth = (rc.left + iTryIndent) - GetColumnWidth(0);
UINT uiFlags = ILD_TRANSPARENT;
if( GetItemState(nItem, LVIF_STATE) & LVIS_DROPHILITED)//if dragging show a SelectDropTarget alike effect :)
uiFlags |= ILD_BLEND50;
if((nWidth=m_cxImage-nWidth) >-1)//calc width of icon
{
// /*
ImageList_DrawEx(m_himl, lvi.iImage, pDC->m_hDC,
rc.left + (GetIndent(pSelItem) * m_cxImage),
nY,
nWidth,
m_cyImage,
CLR_DEFAULT,
CLR_DEFAULT,
uiFlags);
// */
DrawTreeItem(pDC, pSelItem, nItem, rc);
}
//Draw selection bar (erase old selection too)
pDC->SetBkColor(crBackground);
CRect rcClip = lpDrawItemStruct->rcItem;
rcClip.left += GetIndent(pSelItem) * m_cxImage + m_cxImage + 2;
if(rcClip.left > GetColumnWidth(0))
rcClip.left = GetColumnWidth(0);
//fill background color
ExtTextOut(pDC->GetSafeHdc(), 0, 0, ETO_OPAQUE, rcClip, NULL, 0, NULL);
//draw color in first col if any
rcClip.right = rcLabel.right;
CItemInfo *pItemInfo = GetData(pSelItem);
COLORREF clf = pItemInfo->GetItemClr();
if(clf!=-1)
{
CBrush br(clf);
pDC->FillRect(rcClip, &br);
}
//draw selection rect in 1.st col if selected
if ((lpDrawItemStruct->itemState & ODS_SELECTED) && (m_CurSubItem==0))
{
CBrush br(GetCellRGB());
pDC->FillRect(rcClip,&br);
pDC->DrawFocusRect(rcClip);
}
//if checkbox style
UINT nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK;
if (nStateImageMask)
{
int nImage = (nStateImageMask>>12) - 1;
CImageList *pImageList = GetImageList(LVSIL_STATE);
if (pImageList)
{
int cxIcon,cyIcon=0;
ImageList_GetIconSize(pImageList->m_hImageList, &cxIcon, &cyIcon);
if(rc.left + (GetIndent(pSelItem) * m_cxImage) + m_cxImage + cxIcon < GetColumnWidth(0))
pImageList->Draw(pDC, nImage,CPoint(rc.left + (GetIndent(pSelItem) * m_cxImage) + cxIcon, nY), ILD_TRANSPARENT);
}
}
//draw 1. item
GetItemRect(nItem, rcItem, LVIR_LABEL);
pszText = MakeShortString(pDC, szBuff, rcItem.right - rcItem.left, 2*OFFSET_FIRST);
rcLabel = rcItem;
rcLabel.left+=OFFSET_FIRST;
rcLabel.right-=OFFSET_FIRST;
pDC->SetBkColor (crBackground);
pDC->SetTextColor (crText);
pDC->DrawText(pszText,-1, rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_EXTERNALLEADING);
//draw subitems..
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH;
for(int nColumn=1; GetColumn(nColumn, &lvc); nColumn++)
{
rcItem.left=rcItem.right;
rcItem.right+=lvc.cx;
if (rcItem.left < rcClipBox.right && rcItem.right > rcClipBox.left && rcItem.right > rcItem.left)
{
//support for colors in each cell
COLORREF clf = pItemInfo->GetBkColor(nColumn-1);
if(clf!=-1)
{
CBrush br(clf);
pDC->FillRect(rcItem, &br);
}
int nRetLen = GetItemText(nItem, nColumn, szBuff, sizeof(szBuff));
if(nRetLen==0)
pszText=NULL;
else
pszText=MakeShortString(pDC,szBuff,rcItem.right-rcItem.left,2*OFFSET_OTHER);
UINT nJustify=DT_LEFT;
if(pszText==szBuff)
{
switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
{
case LVCFMT_RIGHT:
nJustify=DT_RIGHT;
break;
case LVCFMT_CENTER:
nJustify=DT_CENTER;
break;
default:
break;
}
}
rcLabel=rcItem;
rcLabel.left+=OFFSET_OTHER;
rcLabel.right-=OFFSET_OTHER;
if (lpDrawItemStruct->itemState & ODS_SELECTED && !m_bIs
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
复选框树控件.rar (38个子文件)
复选框树控件(1)
mainfrm.h 2KB
stdafx.h 1KB
testtreedlg.h 1KB
mainfrm.cpp 2KB
MySuperGrid.h 3KB
SuperGrid.opt 53KB
supervw.h 2KB
SuperGrid.aps 49KB
SuperGrid.rc 13KB
supervw.cpp 4KB
www.pudn.com.txt 218B
supergriddoc.h 1KB
SuperGrid.dsp 5KB
supergrid.cpp 4KB
resource.h 1KB
testtreedlg.cpp 2KB
supergrid.h 1KB
supergridctrl.cpp 57KB
supergridctrl.h 16KB
res
toolbar.bmp 1KB
folders.bmp 758B
supergrid.rc2 401B
supergriddoc.ico 1KB
supergrid.ico 1KB
Release
SuperGrid.exe 88KB
ComboInListView.h 2KB
SuperGrid.plg 2KB
ComboInListView.cpp 3KB
listeditctrl.cpp 3KB
SuperGrid.dsw 753B
SuperGrid.ncb 105KB
MySuperGrid.cpp 24KB
supergriddoc.cpp 2KB
newitem.h 1KB
newitem.cpp 1KB
listeditctrl.h 1KB
Debug
SuperGrid.bsc 3.59MB
stdafx.cpp 207B
共 38 条
- 1
资源评论
fanxbl957
- 粉丝: 2646
- 资源: 1184
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功