📄 listedit.c
字号:
char str[LISTEDIT_EDIT_MAXLEN]="\0";
int Align;
LCD_SetBkColor(pObj->Props.aBkColor[3]);
LCD_SetColor(pObj->Props.aTextColor[3]);
Align = *((int*)GUI_ARRAY_GetpItem(&pObj->AlignArray, pObj->ColSel));
memcpy(str,pObj->CurString,strlen(pObj->CurString));
{
int tmpx=0,i=0;
for(i=pObj->ScrollStateH.v;i<pObj->ColSel;i++)
{
tmpx+=HEADER_GetItemWidth(pObj->hHeader,i);
}
rect.x0 = tmpx;
rect.x1 = tmpx+HEADER_GetItemWidth(pObj->hHeader,pObj->ColSel);
rect.y0 = (pObj->RowSel-pObj->ScrollStateV.v)*LISTEDIT__GetRowDistY(pObj)+HEADER_GetHeight(pObj->hHeader);
rect.y1 = rect.y0+LISTEDIT__GetRowDistY(pObj);
if(firstflag)
memset(str,0,LISTEDIT_EDIT_MAXLEN);
//else
{
if(Key == 'h')
memset(str,0,LISTEDIT_EDIT_MAXLEN);
else
{
if(Key == GUI_KEY_BACKSPACE)
{
if(strlen(str))
str[strlen(str)-1]='\0';
}
else
strcat(str,&((char)Key));
}
}
memset(pObj->CurString,0,LISTEDIT_EDIT_MAXLEN);
memcpy(pObj->CurString,str,strlen(str));
//LISTEDIT__InvalidateRow(hObj,pObj,pObj->RowSel);
LISTEDIT__InvalidateCol(hObj,pObj,pObj->ColSel);
}
firstflag=0;
}break;
}
return 0; /* Key has NOT been consumed */
}
/*********************************************************************
*
* _LISTEDIT_Callback
*/
static void _LISTEDIT_Callback (WM_MESSAGE *pMsg) {
LISTEDIT_Handle hObj;
LISTEDIT_Obj* pObj;
WM_SCROLL_STATE ScrollState;
hObj = pMsg->hWin;
/* Let widget handle the standard messages */
if (WIDGET_HandleActive(hObj, pMsg) == 0) {
return;
}
pObj = LISTEDIT_H2P(hObj);
switch (pMsg->MsgId) {
case WM_NOTIFY_CLIENTCHANGE:
case WM_SIZE:
LISTEDIT__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;
LISTEDIT__InvalidateInsideArea(hObj, pObj);
_NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED);
}
else if (pMsg->hWinSrc == WM_GetScrollbarH(hObj))
{
int i=0,hHeaderPos=0;
WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
pObj->ScrollStateH.v = ScrollState.v;
//LISTEDIT__InvalidateInsideArea(hObj, pObj);
LISTEDIT__UpdateScrollParas(hObj, pObj);
for(i=0;i<pObj->ScrollStateH.v;i++)
{
hHeaderPos+=HEADER_GetItemWidth(pObj->hHeader,i);
}
//HEADER_SetScrollPos(pObj->hHeader, pObj->ScrollStateH.v);
HEADER_SetScrollPos(pObj->hHeader, hHeaderPos);
_NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED);
}
break;
case WM_NOTIFICATION_SCROLLBAR_ADDED:
LISTEDIT__UpdateScrollParas(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, 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 */
/*********************************************************************
*
* LISTEDIT_CreateEx
*/
LISTEDIT_Handle LISTEDIT_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
int WinFlags, int ExFlags, int Id)
{
LISTEDIT_Handle hObj;
GUI_USE_PARA(ExFlags);
/* 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, &_LISTEDIT_Callback,
sizeof(LISTEDIT_Obj) - sizeof(WM_Obj));
if (hObj) {
LISTEDIT_Obj* pObj;
WM_LOCK();
pObj = LISTEDIT_H2P(hObj);
/* Init sub-classes */
GUI_ARRAY_CREATE(&pObj->RowArray);
GUI_ARRAY_CREATE(&pObj->AlignArray);
/* Init widget specific variables */
WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE);
/* Init member variables */
LISTEDIT_INIT_ID(pObj);
pObj->Props = LISTEDIT_DefaultProps;
pObj->ShowGrid = 0;
pObj->RowDistY = 0;
pObj->RowSel = 0;
pObj->ColSel = 0;
pObj->LBorder = 1;
pObj->RBorder = 1;
memset(pObj->CurString ,0,30);
pObj->hHeader = HEADER_CreateEx(0, 0, 0, 0, hObj, WM_CF_SHOW, 0, 0);
LISTEDIT__UpdateScrollParas(hObj, pObj);
WM_UNLOCK();
} else {
GUI_DEBUG_ERROROUT_IF(hObj==0, "LISTEDIT_Create failed")
}
return hObj;
}
/*********************************************************************
*
* Exported routines: Member functions
*
**********************************************************************
*/
/*********************************************************************
*
* LISTEDIT_IncRowSel
*/
void LISTEDIT_IncRowSel(LISTEDIT_Handle hObj) {
int Sel = LISTEDIT_GetRowSel(hObj);
LISTEDIT_SetRowSel(hObj, Sel + 1);
}
/*********************************************************************
*
* LISTEDIT_DecRowSel
*/
void LISTEDIT_DecRowSel(LISTEDIT_Handle hObj) {
int Sel = LISTEDIT_GetRowSel(hObj);
if (Sel) {
LISTEDIT_SetRowSel(hObj, Sel - 1);
}
}
/*********************************************************************
*
* LISTEDIT_IncColSel
*/
void LISTEDIT_IncColSel(LISTEDIT_Handle hObj) {
int Sel = LISTEDIT_GetColSel(hObj);
LISTEDIT_SetColSel(hObj, Sel + 1);
}
/*********************************************************************
*
* LISTEDIT_DecColSel
*/
void LISTEDIT_DecColSel(LISTEDIT_Handle hObj) {
int Sel = LISTEDIT_GetColSel(hObj);
if (Sel>-1) {
LISTEDIT_SetColSel(hObj, Sel - 1);
}
}
/*********************************************************************
*
* LISTEDIT_AddColumn
*/
void LISTEDIT_AddColumn(LISTEDIT_Handle hObj, int Width, const char * s, int Align) {
if (hObj) {
LISTEDIT_Obj* pObj;
unsigned NumRows;
WM_LOCK();
pObj = LISTEDIT_H2P(hObj);
HEADER_AddItem(pObj->hHeader, Width, s, Align); /* Modify header */
GUI_ARRAY_AddItem(&pObj->AlignArray, &Align, sizeof(int));
NumRows = LISTEDIT_GetNumRows(hObj);
if (NumRows) {
GUI_ARRAY* pRow;
unsigned i;
for (i = 0; i < NumRows; i++) {
pRow = (GUI_ARRAY*) GUI_ARRAY_GetpItem(&pObj->RowArray, i);
GUI_ARRAY_AddItem(pRow, NULL, sizeof(LISTEDIT_ITEM) + 1);
}
}
LISTEDIT__UpdateScrollParas(hObj, pObj);
LISTEDIT__InvalidateInsideArea(hObj, pObj);
WM_UNLOCK();
}
}
/*********************************************************************
*
* LISTEDIT_AddRow
*/
void LISTEDIT_AddRow(LISTEDIT_Handle hObj, const GUI_ConstString* ppText) {
if (hObj) {
LISTEDIT_Obj* pObj;
int NumRows;
WM_LOCK();
pObj = LISTEDIT_H2P(hObj);
NumRows = GUI_ARRAY_GetNumItems(&pObj->RowArray);
/* Create GUI_ARRAY for the new row */
if (GUI_ARRAY_AddItem(&pObj->RowArray, NULL, sizeof(GUI_ARRAY)) == 0) {
int i, NumColumns, NumBytes;
GUI_ARRAY* pRow;
const char* s;
GUI_ARRAY_CREATE((GUI_ARRAY *)GUI_ARRAY_GetpItem(&pObj->RowArray, NumRows)); /* For higher debug levels only */
/* Add columns for the new row */
NumColumns = HEADER_GetNumItems(pObj->hHeader);
for (i = 0; i < NumColumns; i++) {
LISTEDIT_ITEM * pItem;
pRow = (GUI_ARRAY *)GUI_ARRAY_GetpItem(&pObj->RowArray, NumRows);
s = (ppText) ? *ppText++ : 0;
if (s == 0) {
ppText = 0;
}
NumBytes = GUI__strlen(s) + 1; /* 0 if no string is specified (s == NULL) */
GUI_ARRAY_AddItem(pRow, NULL, sizeof(LISTEDIT_ITEM) + NumBytes);
pItem = (LISTEDIT_ITEM *)GUI_ARRAY_GetpItem(pRow, i);
if (NumBytes > 1) {
strcpy(pItem->acText, s);
}
}
LISTEDIT__UpdateScrollParas(hObj, pObj);
LISTEDIT__InvalidateRow(hObj, pObj, NumRows);
}
else
{
Uart_Printf("GUI_ARRAY AddItem Err!\n");
}
WM_UNLOCK();
}
}
/*********************************************************************
*
* LISTEDIT_InsertRow
Write by fzz 20060228
*********************************************************************/
void LISTEDIT_InsertRow(LISTEDIT_Handle hObj, int Index,const GUI_ConstString* ppText)
{
if (hObj && ppText)
{
LISTEDIT_Obj* pObj;
unsigned int NumRows;
WM_LOCK();
pObj = LISTEDIT_H2P(hObj);
NumRows = GUI_ARRAY_GetNumItems(&pObj->RowArray);
if (Index < NumRows)
{
WM_HMEM hItem;
hItem = GUI_ARRAY_InsertItem(&pObj->RowArray, Index, sizeof(GUI_ARRAY));
if (hItem)
{
int i, NumColumns, NumBytes;
GUI_ARRAY* pRow;
const char* s;
GUI_ARRAY_CREATE((GUI_ARRAY *)GUI_ARRAY_GetpItem(&pObj->RowArray, NumRows)); // For higher debug levels only
// Add columns for the new row
NumColumns = HEADER_GetNumItems(pObj->hHeader);
for (i = 0; i < NumColumns; i++)
{
LISTEDIT_ITEM * pItem;
pRow = (GUI_ARRAY *)GUI_ARRAY_GetpItem(&pObj->RowArray, Index);
s = (ppText) ? *ppText++ : 0;
if (s == 0)
{
ppText = 0;
}
NumBytes = GUI__strlen(s) + 1; /* 0 if no string is specified (s == NULL) */
GUI_ARRAY_AddItem(pRow, NULL, sizeof(LISTEDIT_ITEM) + NumBytes);
pItem = (LISTEDIT_ITEM *)GUI_ARRAY_GetpItem(pRow, i);
if (NumBytes > 1)
{
strcpy(pItem->acText, s);
}
}
LISTEDIT__UpdateScrollParas(hObj, pObj);
LISTEDIT__InvalidateRow(hObj, pObj, NumRows);
}
}
else
{
LISTEDIT_AddRow(hObj,ppText);
}
WM_UNLOCK();
}
}
#else
void LISTEDIT_C(void);
void LISTEDIT_C(void) {}
#endif /* #if GUI_WINSUPPORT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -