📄 multipage.c
字号:
LCD_SetColor(0x555555);
GUI_DrawVLine(r.x1 + 1, r.y0, r.y0 + 1);
}
} else {
r.y1 += pObj->Widget.pEffect->EffectSize + 1;
if (pObj->Widget.pEffect->EffectSize > 1) {
LCD_SetColor(GUI_WHITE);
GUI_DrawVLine(r.x0 - 1, r.y1 - 2, r.y1 - 1);
LCD_SetColor(0x555555);
GUI_DrawVLine(r.x1 + 1, r.y1 - 2, r.y1 - 1);
}
}
}
LCD_SetColor(pObj->aBkColor[ColorIndex]);
WIDGET__FillRectEx(&pObj->Widget, &r);
LCD_SetBkColor(pObj->aBkColor[ColorIndex]);
LCD_SetColor(pObj->aTextColor[ColorIndex]);
GUI_DispStringAt(pText, r.x0 + 4, pRect->y0 + 3);
}
/*********************************************************************
*
* Static code, multipage callbacks
*
**********************************************************************
*/
/*********************************************************************
*
* _Paint
*/
static void _Paint(MULTIPAGE_Obj* pObj) {
GUI_RECT rBorder;
/* Draw border of multipage */
_CalcBorderRect(pObj, &rBorder);
WIDGET__EFFECT_DrawUpRect(&pObj->Widget, &rBorder);
/* Draw text items */
if (pObj->Handles.NumItems > 0) {
MULTIPAGE_PAGE* pPage;
GUI_RECT rText, rClip;
int i, w = 0, x0 = 0;
if (pObj->Widget.State & MULTIPAGE_STATE_SCROLLMODE) {
if (pObj->Align & MULTIPAGE_ALIGN_RIGHT) {
x0 = -_GetPagePosX(pObj, pObj->ScrollState);
} else {
x0 = -_GetPagePosX(pObj, pObj->ScrollState);
}
}
_GetTextRect(pObj, &rText);
rClip = rText;
rClip.y0 = rText.y0 - 1;
rClip.y1 = rText.y1 + 1;
WM_SetUserClipRect(&rClip);
GUI_SetFont(pObj->Font);
for (i = 0; i < pObj->Handles.NumItems; i++) {
pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, i);
x0 += w;
w = GUI_GetStringDistX(&pPage->acText) + 10;
_DrawTextItem(pObj, &pPage->acText, i, &rText, x0, w, (pPage->Status & MULTIPAGE_STATE_ENABLED) ? 1 : 0);
}
WM_SetUserClipRect(NULL);
}
}
/*********************************************************************
*
* _ClickedOnMultipage
*/
static int _ClickedOnMultipage(MULTIPAGE_Handle hObj, MULTIPAGE_Obj* pObj, int x, int y) {
GUI_RECT rText;
_GetTextRect(pObj, &rText);
if ((y >= rText.y0) && (y <= rText.y1)) {
if ((pObj->Handles.NumItems > 0) && (x >= rText.x0) && (x <= rText.x1)) {
int i, w = 0, x0 = rText.x0;
/* Check if another page must be selected */
if (pObj->Widget.State & MULTIPAGE_STATE_SCROLLMODE) {
x0 -= _GetPagePosX(pObj, pObj->ScrollState);
}
for (i = 0; i < pObj->Handles.NumItems; i++) {
x0 += w;
w = _GetPageSizeX(pObj, i);
if (x >= x0 && x <= (x0 + w - 1)) {
MULTIPAGE_SelectPage(hObj, i);
WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
return 1;
}
}
}
return 0;
}
return 1;
}
/*********************************************************************
*
* _OnTouch
*/
static void _OnTouch(MULTIPAGE_Handle hObj, MULTIPAGE_Obj* pObj, WM_MESSAGE*pMsg) {
GUI_PID_STATE* pState;
int Notification;
if (pMsg->Data.p) { /* Something happened in our area (pressed or released) */
pState = (GUI_PID_STATE*)pMsg->Data.p;
if (pState->Pressed) {
int x = pState->x;
int y = pState->y;
if (!_ClickedOnMultipage(hObj, pObj, x, y)) {
WM_HWIN hBelow;
x += WM_GetWindowOrgX(hObj);
y += WM_GetWindowOrgY(hObj);
hBelow = WM_Screen2hWinEx(hObj, x, y);
if (hBelow) {
pState->x = x - WM_GetWindowOrgX(hBelow);
pState->y = y - WM_GetWindowOrgY(hBelow);
pMsg->hWin = hBelow;
(*WM_H2P(hBelow)->cb)(pMsg);
}
} else {
WM_BringToTop(hObj);
}
Notification = WM_NOTIFICATION_CLICKED;
} else {
Notification = WM_NOTIFICATION_RELEASED;
}
} else {
Notification = WM_NOTIFICATION_MOVED_OUT;
}
WM_NotifyParent(hObj, Notification);
}
/*********************************************************************
*
* _MoveSel
*
* Purpose:
* Moves the selection into the given direction.
*
* Parameters:
* hObj, pObj - Obvious
* Dir - +1 moves the selection to the next selectable page
* -1 moves the selection to the previous selectable page
*/
static void _MoveSel(MULTIPAGE_Handle hObj, MULTIPAGE_Obj * pObj, int Dir) {
int Sel, NewSel, ScrollPos, NumItems;
SCROLLBAR_Handle hScroll;
hScroll = WM_GetScrollbarH(hObj);
NewSel = ScrollPos = -1;
NumItems = pObj->Handles.NumItems;
for (Sel = pObj->Selection + Dir; (Sel >= 0) && (Sel < NumItems) && (NewSel == -1); Sel += Dir) {
if (_GetEnable(pObj, Sel)) {
NewSel = Sel;
}
}
if (NewSel >= 0) {
MULTIPAGE_SelectPage(hObj, NewSel);
ScrollPos = NewSel;
} else {
ScrollPos = pObj->ScrollState + Dir;
}
if (hScroll) {
if ((ScrollPos >= 0) && (ScrollPos < NumItems)) {
SCROLLBAR_SetValue(hScroll, ScrollPos);
}
}
}
/*********************************************************************
*
* _AddKey
*
* Returns: 1 if Key has been consumed
* 0 else
*/
static int _AddKey(MULTIPAGE_Handle hObj, MULTIPAGE_Obj * pObj, int Key) {
switch (Key) {
case GUI_KEY_PGUP:
_MoveSel(hObj, pObj, -1);
return 1; /* Key has been consumed */
case GUI_KEY_PGDOWN:
_MoveSel(hObj, pObj, +1);
return 1; /* Key has been consumed */
}
return 0; /* Key has NOT been consumed */
}
/*********************************************************************
*
* _Callback
*/
static void _Callback (WM_MESSAGE *pMsg) {
MULTIPAGE_Handle hObj = pMsg->hWin;
MULTIPAGE_Obj* pObj;
int Handled;
WM_LOCK();
pObj = (MULTIPAGE_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
Handled = WIDGET_HandleActive(hObj, pMsg);
switch (pMsg->MsgId) {
case WM_PAINT:
_Paint(pObj);
break;
case WM_TOUCH:
_OnTouch(hObj, pObj, pMsg);
break;
case WM_NOTIFY_PARENT:
if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
if (WM_GetId(pMsg->hWinSrc) == GUI_ID_HSCROLL) {
pObj->ScrollState = SCROLLBAR_GetValue(pMsg->hWinSrc);
WM_InvalidateWindow(hObj);
}
}
break;
case WM_GET_CLIENT_WINDOW:
pMsg->Data.v = (int)pObj->hClient;
break;
case WM_GET_INSIDE_RECT:
_CalcClientRect(pObj, (GUI_RECT*)(pMsg->Data.p));
break;
case WM_WIDGET_SET_EFFECT:
WIDGET_SetEffect(WM_GetScrollbarH(hObj), (WIDGET_EFFECT const *)pMsg->Data.p);
case WM_SIZE:
_UpdatePositions(hObj, pObj);
break;
case WM_DELETE:
GUI_ARRAY_Delete(&pObj->Handles);
/* No break here ... WM_DefaultProc needs to be called */
default:
/* Let widget handle the standard messages */
if (Handled) {
WM_DefaultProc(pMsg);
}
}
WM_UNLOCK();
}
/*********************************************************************
*
* _ClientCallback
*/
static void _ClientCallback(WM_MESSAGE* pMsg) {
WM_HWIN hObj = pMsg->hWin;
WM_HWIN hParent = WM_GetParent(hObj);
MULTIPAGE_Obj* pParent;
WM_LOCK();
pParent = (MULTIPAGE_Obj *)GUI_ALLOC_h2p(hParent); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
switch (pMsg->MsgId) {
case WM_PAINT:
LCD_SetBkColor(pParent->aBkColor[1]);
GUI_Clear();
break;
case WM_TOUCH:
WM_SetFocus(hParent);
WM_BringToTop(hParent);
break;
case WM_GET_CLIENT_WINDOW:
pMsg->Data.v = (int)hObj;
break;
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(hParent, pParent, Key)) {
break;
}
}
/* No break here ... WM_DefaultProc needs to be called */
case WM_GET_INSIDE_RECT:
WM_DefaultProc(pMsg);
}
WM_UNLOCK();
}
/*********************************************************************
*
* Private routines
*
**********************************************************************
*/
/*********************************************************************
*
* MULTIPAGE_h2p
*/
#if GUI_DEBUG_LEVEL >= GUI_DEBUG_LEVEL_CHECK_ALL
MULTIPAGE_Obj * MULTIPAGE_h2p(MULTIPAGE_Handle h) {
MULTIPAGE_Obj * p = (MULTIPAGE_Obj *)GUI_ALLOC_h2p(h);
if (p) {
if (p->DebugId != MULTIPAGE_ID) {
GUI_DEBUG_ERROROUT("MULTIPAGE.c: Wrong handle type or Object not init'ed");
return 0;
}
}
return p;
}
#endif
/*********************************************************************
*
* Exported routines: Create
*
**********************************************************************
*/
/* Note: the parameters to a create function may vary.
Some widgets may have multiple create functions */
/*********************************************************************
*
* MULTIPAGE_CreateEx
*/
MULTIPAGE_Handle MULTIPAGE_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
int WinFlags, int ExFlags, int Id)
{
MULTIPAGE_Handle hObj;
GUI_USE_PARA(ExFlags);
/* Create the window */
hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags | WM_CF_HASTRANS, &_Callback,
sizeof(MULTIPAGE_Obj) - sizeof(WM_Obj));
if (hObj) {
MULTIPAGE_Obj* pObj;
GUI_RECT rClient;
int Flags;
WM_LOCK();
pObj = (MULTIPAGE_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->Handles);
/* init widget specific variables */
WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE);
/* init member variables */
MULTIPAGE_INIT_ID(pObj);
pObj->aBkColor[0] = MULTIPAGE__DefaultBkColor[0];
pObj->aBkColor[1] = MULTIPAGE__DefaultBkColor[1];
pObj->aTextColor[0] = MULTIPAGE__DefaultTextColor[0];
pObj->aTextColor[1] = MULTIPAGE__DefaultTextColor[1];
pObj->Font = MULTIPAGE__pDefaultFont;
pObj->Align = MULTIPAGE__DefaultAlign;
pObj->Selection = 0xffff;
pObj->ScrollState = 0;
pObj->Widget.State = 0;
_CalcClientRect(pObj, &rClient);
Flags = WM_CF_SHOW | WM_CF_ANCHOR_LEFT | WM_CF_ANCHOR_RIGHT | WM_CF_ANCHOR_TOP | WM_CF_ANCHOR_BOTTOM;
pObj->hClient = WM_CreateWindowAsChild(rClient.x0, rClient.y0,
rClient.x1 - rClient.x0 + 1,
rClient.y1 - rClient.y0 + 1,
hObj, Flags, &_ClientCallback, 0);
_UpdatePositions(hObj, pObj);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -