📄 eblistview.c
字号:
pSrc->pszText = (char *) malloc (strlen (pDest->pszText) + 1);
strcpy (pSrc->pszText, pDest->pszText);
}
else
pSrc->pszText = NULL;
}
if (pDest->pszText != NULL)
free (pDest->pszText);
pDest->pszText = p1;
return 0;
}
static PEBITEMDATA sGetItemFromList (int nItemSeq, PEBLSTVWDATA pLVInternalData)
{
PEBITEMDATA p1;
int nPosition;
if ((nItemSeq < 1) || (nItemSeq > pLVInternalData->nRows))
return NULL;
nPosition = nItemSeq;
p1 = pLVInternalData->pItemHead;
while (nPosition != 1)
{
nPosition = nPosition - 1;
p1 = p1->pNext;
}
return p1;
}
static int sGetSubItemWidth (int nCols, PEBLSTVWDATA pLVInternalData)
{
PEBLSTHDR p;
int nPosition;
nPosition = nCols;
if ((nCols < 1) || (nCols > pLVInternalData->nCols))
{
return -1;
}
p = pLVInternalData->pLstHead;
while (nPosition != 1)
{
nPosition--;
p = p->pNext;
}
return p->width;
}
static int sGetSubItemX (int nCols, PEBLSTVWDATA pLVInternalData)
{
PEBLSTHDR p;
int nPosition;
nPosition = nCols;
if ((nCols < 1) || (nCols > pLVInternalData->nCols))
{
return -1;
}
p = pLVInternalData->pLstHead;
while (nPosition != 1)
{
nPosition--;
p = p->pNext;
}
return p->x;
}
static int sGetItemWidth (PEBLSTVWDATA pLVInternalData)
{
PEBLSTHDR p;
int width;
p = pLVInternalData->pLstHead;
width = 0;
while (p != NULL)
{
width += p->width;
p = p->pNext;
}
return width;
}
static int sGetFrontSubItemsWidth (int end, PEBLSTVWDATA pLVInternalData)
{
PEBLSTHDR p;
int nPosition;
int width;
nPosition = end;
if ((end < 1) || (end > pLVInternalData->nCols))
return -1;
p = pLVInternalData->pLstHead;
width = 0;
while (nPosition != 1)
{
width += p->width;
nPosition--;
p = p->pNext;
}
return width;
}
static int sAddOffsetToSubItem (PEBLSTHDR p, int offset)
{
p->width += offset;
return 0;
}
static int sAddOffsetToTailSubItem (int nCols, int offset, PEBLSTVWDATA pLVInternalData)
{
PEBLSTHDR p;
int nPosition;
nPosition = nCols;
if ((nCols < 1) || (nCols > pLVInternalData->nCols))
return -1;
p = pLVInternalData->pLstHead;
while (nPosition != 1)
{
nPosition--;
p = p->pNext;
}
while (p != NULL)
{
p->x += offset;
p = p->pNext;
}
return 0;
}
static int sSortItemByCol (unsigned int nCols, SORTTYPE sort, PEBLSTVWDATA pLVInternalData)
{
PEBCMPITEMSTRUCT *p1;
int j;
int i;
PEBITEMDATA p2 = NULL;
PEBSUBITEMDATA p3 = NULL;
PEBITEMDATA *p4;
PEBITEMDATA p5;
if ((nCols > pLVInternalData->nCols) || (nCols < 1))
return -1;
if (pLVInternalData->nRows < 1)
return 0;
p1 = (PEBCMPITEMSTRUCT *) malloc (sizeof (char *) * pLVInternalData->nRows);
p2 = pLVInternalData->pItemHead;
j = 0;
while (p2 != NULL)
{
int nPosition;
nPosition = nCols;
p3 = p2->pSubItemHead;
while (nPosition != 1)
{
nPosition--;
p3 = p3->pNext;
}
p1[j] = (PEBCMPITEMSTRUCT) malloc (sizeof (EBCMPITEMSTRUCT));
if (p3->pszText != NULL)
{
p1[j]->pszText = (char *) malloc (strlen (p3->pszText) + 1);
strcpy (p1[j]->pszText, p3->pszText);
}
else
p1[j]->pszText = NULL;
p1[j]->nItemSeq = j + 1;
}
p2 = p2->pNext;
j++;
/********************************************sort item***************************************************************/
for (i = 0; i < pLVInternalData->nRows - 1; i++)
{
for (j = i + 1; j < pLVInternalData->nRows; j++)
{
if (sort == HISORTED)
{
if (sCmpInfo (p1[i]->pszText, p1[j]->pszText) < 0)
sCmpStructExchange (p1[i], p1[j]);
}
else if (sCmpInfo (p1[i]->pszText, p1[j]->pszText) > 0)
{
sCmpStructExchange (p1[i], p1[j]);
}
}
}
/*********************************************sort item***************************************************************/
/***********************************************rearrange item list****************************************************/
p4 = (PEBITEMDATA *) malloc (sizeof (PEBITEMDATA) * pLVInternalData->nRows);
for (i = 0; i < pLVInternalData->nRows; i++)
{
p5 = sGetItemFromList (p1[i]->nItemSeq, pLVInternalData);
p4[i] = p5;
}
for (i = 0; i < pLVInternalData->nRows - 1; i++)
{
p4[i]->pNext = p4[i + 1];
}
pLVInternalData->pItemHead = p4[0];
p4[pLVInternalData->nRows - 1]->pNext = NULL;
free (p4);
/***********************************************rearrange item list****************************************************/
for (i = 0; i < pLVInternalData->nRows; i++)
{
if (p1[i]->pszText != NULL)
free (p1[i]->pszText);
free (p1[i]);
}
free (p1);
return 0;
}
/********************************************** List internals data **********************************************/
/********************************************** List Report **********************************************/
static int lstSetVScrollInfo (PEBLSTVWDATA pLVInternalData)
{
SCROLLINFO si;
RECT rect;
GetClientRect (pLVInternalData->hWnd, &rect);
if ((rect.bottom - rect.top - pLVInternalData->nHeadHeight) >
((pLVInternalData->nRows - 1) * pLVInternalData->nItemHeight))
{
SetScrollPos (pLVInternalData->hWnd, SB_VERT, 0);
EnableScrollBar (pLVInternalData->hWnd, SB_VERT, FALSE);
ShowScrollBar (pLVInternalData->hWnd, SB_VERT, FALSE);
return 0;
}
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMax = pLVInternalData->nRows * pLVInternalData->nItemHeight;
si.nMin = 0;
si.nPage = rect.bottom - rect.top - pLVInternalData->nHeadHeight;
si.nPos = pLVInternalData->nOriginalY;
SetScrollInfo (pLVInternalData->hWnd, SB_VERT, &si, TRUE);
EnableScrollBar (pLVInternalData->hWnd, SB_VERT, TRUE);
ShowScrollBar (pLVInternalData->hWnd, SB_VERT, TRUE);
return 0;
}
static int lstSetHScrollInfo (PEBLSTVWDATA pLVInternalData)
{
SCROLLINFO si;
RECT rect;
GetClientRect (pLVInternalData->hWnd, &rect);
if ((rect.right - rect.left) > (sGetItemWidth (pLVInternalData)))
{
SetScrollPos (pLVInternalData->hWnd, SB_HORZ, 0);
EnableScrollBar (pLVInternalData->hWnd, SB_HORZ, FALSE);
ShowScrollBar (pLVInternalData->hWnd, SB_HORZ, FALSE);
return 0;
}
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMax = sGetItemWidth (pLVInternalData);
si.nMin = 0;
si.nPage = rect.right - rect.left;
si.nPos = pLVInternalData->nOriginalX;
SetScrollInfo (pLVInternalData->hWnd, SB_HORZ, &si, TRUE);
EnableScrollBar (pLVInternalData->hWnd, SB_HORZ, TRUE);
ShowScrollBar (pLVInternalData->hWnd, SB_HORZ, TRUE);
return 0;
}
static int isInListViewHead (int mouseX, int mouseY, PEBLSTHDR * pRet,
PEBLSTVWDATA pLVInternalData)
{
int nPosition = 0;
PEBLSTHDR p1 = NULL;
p1 = pLVInternalData->pLstHead;
while (p1 != NULL)
{
nPosition++;
if ((mouseX > p1->x - pLVInternalData->nOriginalX + 1)
&& (mouseX < (p1->x + p1->width - pLVInternalData->nOriginalX - 1))
&& (mouseY > 0) && (mouseY < pLVInternalData->nHeadHeight))
break;
p1 = p1->pNext;
}
*pRet = NULL;
if ((nPosition > pLVInternalData->nCols) || (nPosition == 0))
return -1;
else
{
*pRet = p1;
if (p1 != NULL)
return nPosition;
else
return -1;
}
}
static int isInLVHeadBorder (int mouseX, int mouseY, PEBLSTHDR * pRet,
PEBLSTVWDATA pLVInternalData)
{
int nPosition = 0;
PEBLSTHDR p1 = NULL;
p1 = pLVInternalData->pLstHead;
while (p1 != NULL)
{
nPosition++;
if ((mouseX >= (p1->x + p1->width - pLVInternalData->nOriginalX - 1))
&& (mouseX <= (p1->x + p1->width - pLVInternalData->nOriginalX + 1))
&& (mouseY >= 0) && (mouseY <= pLVInternalData->nHeadHeight))
break;
p1 = p1->pNext;
}
*pRet = NULL;
if ((nPosition > pLVInternalData->nCols) || (nPosition == 0))
return -1;
else
{
*pRet = p1;
if (p1 != NULL)
return nPosition;
else
return -1;
}
}
static int isInLVItem (int mouseX, int mouseY, PEBITEMDATA * pRet, PEBLSTVWDATA pLVInternalData)
{
int ret, j;
PEBITEMDATA p1;
//因为列表框的行的宽度和列表框等同,所以这里不用判断mouseX是否在列表框内,因为如果鼠标的横坐标
//不在列表框内,列表框就接收不到MOUSEMOVE的消息
if ((mouseY < pLVInternalData->nHeadHeight))
return -1;
ret=(mouseY+pLVInternalData->nOriginalY-pLVInternalData->nHeadHeight)/pLVInternalData->nItemHeight;
if((mouseY+ pLVInternalData->nOriginalY -pLVInternalData->nHeadHeight) > ((ret+1)*pLVInternalData->nItemHeight-pLVInternalData->nItemGap) &&
(mouseY+ pLVInternalData->nOriginalY -pLVInternalData->nHeadHeight) < (ret+1)*pLVInternalData->nItemHeight)
{
return -1;
}
ret++;
*pRet = NULL;
p1 = pLVInternalData->pItemHead;
j = 0;
while ((p1 != NULL) && (j < ret))
{
*pRet = p1;
p1 = p1->pNext;
j++;
}
if (ret > j)
return -1;
return ret;
}
static void sDrawText (HDC hdc, int x, int y, int width, int height, const char *pszText)
{
RECT rect;
SIZE size;
rect.left = x + 2;
rect.top = y + 2;
rect.right = x + width;
rect.bottom = y + height;
if (pszText != NULL)
{
GetTextExtent (hdc, pszText, -1, &size);
if (width > size.cx)
{
DrawText (hdc, pszText, -1, &rect, DT_SINGLELINE | DT_LEFT |DT_VCENTER);
}
else
{
DrawText (hdc, pszText, -1, &rect, DT_SINGLELINE | DT_LEFT |DT_VCENTER);
}
}
}
static void
sDrawTextToSubItem (HWND hwnd,HDC hdc, PEBSUBITEMDATA psubitem,int nRows, int nCols,
PEBITEMDATA pItem, PEBLSTVWDATA pLVInternalData)
{
int nOldBrushColor;
int x;
int y,dy;
int temp1,temp3, temp2 = 0,temp4;
int fit_char;
int *pos_char, *dx_char;
SIZE size;
int i;
RECT rect, rect1;
DWORD dwStyle = GetWindowStyle (hwnd);
UINT uFormat;
y =(nRows - 1) * pLVInternalData->nItemHeight - pLVInternalData->nOriginalY;
x = sGetSubItemX (nCols, pLVInternalData) - pLVInternalData->nOriginalX;
switch(psubitem->mask)
{
case ELV_BITMAP:
{
if(!pLVInternalData->nBKImage)
break;
if(dwStyle &ELVS_TYPE3STATE)
{
if (!pItem->bSelected)
{
if(!pItem->bMouseOver)
{
dy = (pLVInternalData->nItemHeight - ((PBITMAP*)(psubitem->iImage))[0]->bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,
0,0,((PBITMAP*)(psubitem->iImage))[0]);
}
else
{
dy = (pLVInternalData->nItemHeight - ((PBITMAP*)(psubitem->iImage))[1]->bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,
0,0,((PBITMAP*)(psubitem->iImage))[1]);
}
}
else
{
dy = (pLVInternalData->nItemHeight - ((PBITMAP*)(psubitem->iImage))[2]->bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,0,0,
((PBITMAP*)(psubitem->iImage))[2]);
}
}
else
{
if (!pItem->bSelected)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -