📄 listview.c
字号:
return 1; /* Key has been consumed */
case GUI_KEY_UP:
LISTVIEW__MoveSel(hObj, pObj, -1);
return 1; /* Key has been consumed */
case GUI_KEY_PGUP:
_OnPage(hObj, pObj, -1);
return 1; /* Key has been consumed */
case GUI_KEY_HOME:
LISTVIEW__SetSel(hObj, pObj, 0);
return 1; /* Key has been consumed */
case GUI_KEY_END:
LISTVIEW__SetSel(hObj, pObj, LISTVIEW__GetNumRows(pObj) - 1);
return 1; /* Key has been consumed */
case GUI_KEY_RIGHT:
if (WM_SetScrollValue(&pObj->ScrollStateH, pObj->ScrollStateH.v + pObj->Props.ScrollStepH)) {
LISTVIEW__UpdateScrollPos(hObj, pObj);
LISTVIEW__InvalidateInsideArea(hObj, pObj);
}
return 1; /* Key has been consumed */
case GUI_KEY_LEFT:
if (WM_SetScrollValue(&pObj->ScrollStateH, pObj->ScrollStateH.v - pObj->Props.ScrollStepH)) {
LISTVIEW__UpdateScrollPos(hObj, pObj);
LISTVIEW__InvalidateInsideArea(hObj, pObj);
}
return 1; /* Key has been consumed */
}
return 0; /* Key has NOT been consumed */
}
/*********************************************************************
*
* Private routines
*
**********************************************************************
*/
/*********************************************************************
*
* LISTVIEW_h2p
*/
#if GUI_DEBUG_LEVEL >= GUI_DEBUG_LEVEL_CHECK_ALL
LISTVIEW_Obj * LISTVIEW_h2p(LISTVIEW_Handle h) {
LISTVIEW_Obj * p = (LISTVIEW_Obj *)GUI_ALLOC_h2p(h);
if (p) {
if (p->DebugId != LISTVIEW_ID) {
GUI_DEBUG_ERROROUT("LISTVIEW.c: Wrong handle type or Object not init'ed");
return 0;
}
}
return p;
}
#endif
/*********************************************************************
*
* Exported routines: Create
*
**********************************************************************
*/
/*********************************************************************
*
* LISTVIEW_Callback
*/
void LISTVIEW_Callback (WM_MESSAGE *pMsg) {
LISTVIEW_Handle hObj;
LISTVIEW_Obj* pObj;
WM_SCROLL_STATE ScrollState;
hObj = pMsg->hWin;
/* Let widget handle the standard messages */
if (WIDGET_HandleActive(hObj, pMsg) == 0) {
return;
}
pObj = (LISTVIEW_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
switch (pMsg->MsgId) {
case WM_NOTIFY_CLIENTCHANGE:
case WM_SIZE:
if (pMsg->hWinSrc && (pMsg->hWinSrc == pObj->hHeader)) {
LISTVIEW__UpdateScrollParas(hObj, pObj);
}
return;
case WM_NOTIFY_PARENT:
switch (pMsg->Data.v) {
case WM_NOTIFICATION_CHILD_DELETED:
/* make sure we do not send any messages to the header child once it has been deleted */
if (pMsg->hWinSrc == pObj->hHeader) {
pObj->hHeader = 0;
}
break;
case WM_NOTIFICATION_VALUE_CHANGED:
if (pMsg->hWinSrc == WM_GetScrollbarV(hObj)) {
WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
pObj->ScrollStateV.v = ScrollState.v;
LISTVIEW__InvalidateInsideArea(hObj, pObj);
_NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED);
} else if (pMsg->hWinSrc == WM_GetScrollbarH(hObj)) {
WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
pObj->ScrollStateH.v = ScrollState.v;
LISTVIEW__UpdateScrollParas(hObj, pObj);
HEADER_SetScrollPos(pObj->hHeader, pObj->ScrollStateH.v);
_NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED);
}
break;
case WM_NOTIFICATION_SCROLLBAR_ADDED:
#if WIDGET_USE_PARENT_EFFECT
WIDGET_SetEffect(pMsg->hWinSrc, pObj->Widget.pEffect);
#endif
LISTVIEW__UpdateScrollParas(hObj, pObj);
break;
case WM_NOTIFICATION_RELEASED:
if ((pMsg->hWinSrc == pObj->hHeader) && (pObj->hSort)) {
int Column;
LISTVIEW_SORT * pSort;
LISTVIEW_COLUMN * pColumn;
WM_SetFocus(hObj);
Column = HEADER_GetSel(pObj->hHeader);
if (Column >= 0) {
pColumn = (LISTVIEW_COLUMN *)GUI_ARRAY_GetpItem(&pObj->ColumnArray, Column);
if (pColumn->fpCompare) {
pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(pObj->hSort);
if (pSort) {
// ReverseSort
if (pObj->SortIndex == Column) {
pSort->Reverse ^= 1;
pObj->ReverseSort = 1;
pObj->IsSorted = 0;
} else {
pSort->Reverse = 0;
pObj->SortIndex = Column;
pObj->IsPresorted = 0;
}
/*
if (pObj->SortIndex == Column) {
pSort->Reverse ^= 1;
} else {
pSort->Reverse = 0;
pObj->SortIndex = Column;
}
pObj->IsPresorted = 0;
*/
LISTVIEW__InvalidateInsideArea(hObj, pObj);
}
}
}
}
break;
}
return;
case WM_PAINT:
_Paint(hObj, pObj, pMsg);
return;
case WM_TOUCH:
_OnTouch(hObj, pObj, pMsg);
return; /* Important: message handled ! */
case WM_KEY:
if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt > 0) {
int Key;
Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key;
if (_AddKey(hObj, pObj, Key)) {
return;
}
}
break; /* No return here ... WM_DefaultProc needs to be called */
case WM_DELETE:
_FreeAttached(pObj);
break; /* No return here ... WM_DefaultProc needs to be called */
}
WM_DefaultProc(pMsg);
}
/*********************************************************************
*
* Exported routines: Create
*
**********************************************************************
*/
/* Note: the parameters to a create function may vary.
Some widgets may have multiple create functions */
/*********************************************************************
*
* LISTVIEW_CreateEx
*/
LISTVIEW_Handle LISTVIEW_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
int WinFlags, int ExFlags, int Id)
{
LISTVIEW_Handle hObj;
GUI_USE_PARA(ExFlags);
WM_LOCK();
/* Create the window */
if ((xsize == 0) && (ysize == 0) && (x0 == 0) && (y0 == 0)) {
GUI_RECT Rect;
WM_GetClientRectEx(hParent, &Rect);
xsize = Rect.x1 - Rect.x0 + 1;
ysize = Rect.y1 - Rect.y0 + 1;
}
hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags, &LISTVIEW_Callback,
sizeof(LISTVIEW_Obj) - sizeof(WM_Obj));
if (hObj) {
LISTVIEW_Obj* pObj;
pObj = (LISTVIEW_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
/* Init sub-classes */
GUI_ARRAY_CREATE(&pObj->RowArray);
GUI_ARRAY_CREATE(&pObj->ColumnArray);
/* Init widget specific variables */
WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE);
/* Init member variables */
LISTVIEW_INIT_ID(pObj);
pObj->Props = LISTVIEW_DefaultProps;
pObj->ShowGrid = 0;
pObj->RowDistY = 0;
pObj->Sel = -1;
pObj->LBorder = 1;
pObj->RBorder = 1;
pObj->hHeader = HEADER_CreateEx(0, 0, 0, 0, hObj, WM_CF_SHOW, 0, 0);
LISTVIEW__UpdateScrollParas(hObj, pObj);
} else {
GUI_DEBUG_ERROROUT_IF(hObj==0, "LISTVIEW_Create failed")
}
WM_UNLOCK();
return hObj;
}
/*********************************************************************
*
* Exported routines: Member functions
*
**********************************************************************
*/
/*********************************************************************
*
* LISTVIEW_IncSel
*/
void LISTVIEW_IncSel(LISTVIEW_Handle hObj) {
if (hObj) {
LISTVIEW_Obj* pObj;
WM_LOCK();
pObj = LISTVIEW_H2P(hObj);
LISTVIEW__MoveSel(hObj, pObj, 1);
WM_UNLOCK();
}
}
/*********************************************************************
*
* LISTVIEW_DecSel
*/
void LISTVIEW_DecSel(LISTVIEW_Handle hObj) {
if (hObj) {
LISTVIEW_Obj* pObj;
WM_LOCK();
pObj = LISTVIEW_H2P(hObj);
LISTVIEW__MoveSel(hObj, pObj, -1);
WM_UNLOCK();
}
}
/*********************************************************************
*
* LISTVIEW_AddColumn
*/
int LISTVIEW_AddColumn(LISTVIEW_Handle hObj, int Width, const char * s, int Align) {
int r = 0;
if (hObj) {
LISTVIEW_Obj* pObj;
LISTVIEW_COLUMN Column = {0};
unsigned NumRows;
WM_LOCK();
pObj = LISTVIEW_H2P(hObj);
HEADER_AddItem(pObj->hHeader, Width, s, Align);
Column.Align = Align;
GUI_ARRAY_AddItem(&pObj->ColumnArray, &Column, sizeof(LISTVIEW_COLUMN));
pObj = LISTVIEW_H2P(hObj); /* Restore after allocating memory */
NumRows = LISTVIEW__GetNumRows(pObj);
if (NumRows) {
LISTVIEW_ROW* pRow;
unsigned i;
for (i = 0; i < NumRows; i++) {
pRow = (LISTVIEW_ROW*) GUI_ARRAY_GetpItem(&pObj->RowArray, i);
if (GUI_ARRAY_AddItem(&pRow->CellArray, NULL, sizeof(LISTVIEW_CELL))) {
r = 1;
break;
}
pObj = LISTVIEW_H2P(hObj); /* Restore after allocating memory */
}
}
LISTVIEW__UpdateScrollParas(hObj, pObj);
LISTVIEW__InvalidateInsideArea(hObj, pObj);
WM_UNLOCK();
}
return r;
}
/*********************************************************************
*
* LISTVIEW_AddRow
*/
int LISTVIEW_AddRow(LISTVIEW_Handle hObj, const GUI_ConstString* ppText) {
int r = 0;
if (hObj) {
LISTVIEW_Obj* pObj;
WM_LOCK();
pObj = LISTVIEW_H2P(hObj);
/* Add row item to the GUI_ARRAY */
if (GUI_ARRAY_AddItem(&pObj->RowArray, NULL, sizeof(LISTVIEW_ROW)) == 0) {
LISTVIEW_ROW* pRow;
int i, RowIndex, NumColumns, NumBytes;
const char* s;
pObj = LISTVIEW_H2P(hObj); /* Restore after allocating memory */
RowIndex = LISTVIEW__GetNumRows(pObj) - 1;
NumColumns = LISTVIEW__GetNumColumns(pObj);
pRow = (LISTVIEW_ROW*) GUI_ARRAY_GetpItem(&pObj->RowArray, RowIndex);
GUI_ARRAY_CREATE(&pRow->CellArray);
/* Add columns for the new row */
for (i = 0; i < NumColumns; i++) {
LISTVIEW_CELL* pCell;
s = (ppText) ? *ppText++ : 0;
if (s == 0) {
ppText = 0;
}
NumBytes = GUI__strlen(s) + 1; /* 0 if no string is specified (s == NULL) */
if (GUI_ARRAY_AddItem(&pRow->CellArray, NULL, sizeof(LISTVIEW_CELL) + NumBytes)) {
r = 1;
break;
}
pObj = LISTVIEW_H2P(hObj); /* Restore after allocating memory */
pRow = (LISTVIEW_ROW*) GUI_ARRAY_GetpItem(&pObj->RowArray, RowIndex); /* Restore after allocating memory */
pCell = (LISTVIEW_CELL*) GUI_ARRAY_GetpItem(&pRow->CellArray, i);
if (NumBytes > 1) {
strcpy(pCell->acText, s);
}
}
pObj->IsSorted = 0;
LISTVIEW__UpdateScrollParas(hObj, pObj);
if (pObj->hSort && (pObj->SortIndex >= 0)) {
LISTVIEW__InvalidateInsideArea(hObj, pObj);
} else {
LISTVIEW__InvalidateRow(hObj, pObj, RowIndex);
}
} else {
r = 1;
}
WM_UNLOCK();
}
return r;
}
#else
void LISTVIEW_C(void);
void LISTVIEW_C(void) {}
#endif /* #if GUI_WINSUPPORT */
/*************************** End of file ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -