/********************************************************************* * * _CalcClientRect * * Calculates the rect of the client area. */ static void _CalcClientRect(MULTIPAGE_Obj* pObj, GUI_RECT* pRect) { WIDGET__GetInsideRect(&pObj->Widget, pRect); if (pObj->Align & MULTIPAGE_ALIGN_BOTTOM) { pRect->y1 -= GUI_GetYSizeOfFont(pObj->Font) + 6; } else { pRect->y0 += GUI_GetYSizeOfFont(pObj->Font) + 6; } }
/********************************************************************* * * EDIT_GetCursorPixelPos */ void EDIT_GetCursorPixelPos(EDIT_Handle hObj, int * pxPos, int * pyPos) { if (hObj) { int NumChars; EDIT_Obj * pObj; const char GUI_UNI_PTR * pText; GUI_RECT rInside, rText; WM_LOCK(); pObj = EDIT_H2P(hObj); if (pObj->hpText) { GUI_SetFont(pObj->Props.pFont); WIDGET__GetInsideRect(&pObj->Widget, &rInside); pText = (const char*) GUI_ALLOC_h2p(pObj->hpText); NumChars = GUI__GetNumChars(pText); rInside.x0 += pObj->Props.Border + EDIT_XOFF; rInside.x1 -= pObj->Props.Border + EDIT_XOFF; GUI__CalcTextRect(pText, &rInside, &rText, pObj->Props.Align); rText.x0 += GUI__GetCursorPosX(pText, pObj->CursorPos, NumChars); *pxPos = rText.x0; *pyPos = rText.y0; } WM_UNLOCK(); } }
/********************************************************************* * * WIDGET_HandleActive */ int WIDGET_HandleActive(WM_HWIN hObj, WM_MESSAGE* pMsg) { WM_MESSAGE Msg; WIDGET* pWidget = WIDGET_H2P(hObj); switch (pMsg->MsgId) { case WM_GET_ID: pMsg->Data.v = pWidget->Id; return 0; /* Message handled -> Return */ case WM_SET_FOCUS: if (pMsg->Data.v == 1) { WIDGET_SetState(hObj, pWidget->State | WIDGET_STATE_FOCUS); } else { WIDGET_SetState(hObj, pWidget->State & ~WIDGET_STATE_FOCUS); } Msg.MsgId = WM_NOTIFY_CHILD_HAS_FOCUS; Msg.Data.v = pMsg->Data.v; WM_SendToParent(hObj, &Msg); return 0; case WM_GET_HAS_FOCUS: pMsg->Data.v = pWidget->State & WIDGET_STATE_FOCUS; return 0; /* Message handled */ case WM_SET_ENABLE: if (pMsg->Data.v) { WIDGET_OrState(hObj, WIDGET_STATE_ENABLED); } else { WIDGET_AndState(hObj, WIDGET_STATE_ENABLED); } case WM_GET_ACCEPT_FOCUS: pMsg->Data.v = (pWidget->State & WIDGET_STATE_FOCUSSABLE) ? 1 : 0; /* Can handle focus */ return 0; /* Message handled */ case WM_GET_INSIDE_RECT: WIDGET__GetInsideRect(pWidget, (GUI_RECT*)pMsg->Data.p); return 0; /* Message handled */ } return 1; /* Message NOT handled */ }
/********************************************************************* * * _Paint */ static void _Paint(EDIT_Obj* pObj) { int PixelLen, xSize, ySize, xPosText = 0, xPosCursor = 0, yPosText = 0, yPosCursor = 0, XSizeCursor, YSizeCursor; int IsEnabled; GUI_RECT rClient, rWindow; char * s; s = (char*) WM_HMEM2Ptr(pObj->hpText); GUI_DEBUG_LOG("BUTTON: _Paint(..)\n"); if (pObj->Border) { GUI_SetBkColor(pObj->aBkColor[0]); GUI_Clear(); } IsEnabled = WIDGET__IsEnabled(&pObj->Widget); /* Set clipping rectangle */ WIDGET__GetInsideRect(&pObj->Widget, &rWindow); WM_SetUserClipRect(&rWindow); /* Calculate size */ GUI_GetClientRect(&rClient); xSize = rClient.x1 - rClient.x0 + 1; ySize = rClient.y1 - rClient.y0 + 1; /* Draw background */ GUI_SetBkColor (pObj->aBkColor[IsEnabled]); GUI_SetColor (pObj->aTextColor[0]); GUI_Clear(); /* Calculate length */ GUI_SetFont (pObj->pFont); PixelLen = GUI_GetStringDistX(s); /* Calculate size of cursor */ YSizeCursor = GUI_GetFontDistY(); if (pObj->EditMode == GUI_EDIT_MODE_INSERT) { if (pObj->XSizeCursor != 0) { XSizeCursor = pObj->XSizeCursor; } else { XSizeCursor = GUI_GetCharDistX(' '); } } else { if (pObj->CursorPos < (int)strlen(s)) { XSizeCursor = GUI_GetCharDistX(*(s + pObj->CursorPos)); } else { XSizeCursor = pObj->XSizeCursor; } } /* Calculate X-pos */ switch (pObj->Align & GUI_TA_HORIZONTAL) { case GUI_TA_CENTER: xPosCursor = (xSize - PixelLen + 1) / 2; xPosText = xSize / 2; break; case GUI_TA_LEFT: xPosCursor = pObj->Border + EDIT_XOFF; xPosText = pObj->Border + EDIT_XOFF; break; case GUI_TA_RIGHT: xPosCursor = xSize - (pObj->Border + EDIT_XOFF) - PixelLen; xPosText = xSize - (pObj->Border + EDIT_XOFF); break; } /* Calculate Y-pos */ switch (pObj->Align & GUI_TA_VERTICAL) { case GUI_TA_TOP: yPosCursor = 0; yPosText = 0; break; case GUI_TA_BOTTOM: yPosCursor = ySize - YSizeCursor; yPosText = ySize; break; case GUI_TA_VCENTER: yPosCursor = (ySize - YSizeCursor + 1) / 2; yPosText = ySize / 2; break; } /* Display text */ GUI_SetTextAlign(pObj->Align); GUI_DispStringAt(s, xPosText, yPosText); /* Display cursor */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { int i; for (i = 0; i != pObj->CursorPos; i++) { xPosCursor += GUI_GetCharDistX(*(s + i)); } GUI_InvertRect(xPosCursor, yPosCursor, xPosCursor + XSizeCursor - 1, yPosCursor + YSizeCursor - 1); } WM_SetUserClipRect(NULL); /* Draw the 3D effect (if configured) */ WIDGET__EFFECT_DrawDown(&pObj->Widget); }
/********************************************************************* * * WIDGET_HandleActive */ int WIDGET_HandleActive(WM_HWIN hObj, WM_MESSAGE* pMsg) { int Diff, Notification; WIDGET* pWidget = WIDGET_H2P(hObj); switch (pMsg->MsgId) { case WM_WIDGET_SET_EFFECT: Diff = pWidget->pEffect->EffectSize; pWidget->pEffect = (const WIDGET_EFFECT*)pMsg->Data.p; Diff -= pWidget->pEffect->EffectSize; _UpdateChildPostions(hObj, Diff); WM_InvalidateWindow(hObj); return 0; /* Message handled -> Return */ case WM_GET_ID: pMsg->Data.v = pWidget->Id; return 0; /* Message handled -> Return */ case WM_PID_STATE_CHANGED: if (pWidget->State & WIDGET_STATE_FOCUSSABLE) { const WM_PID_STATE_CHANGED_INFO * pInfo = (const WM_PID_STATE_CHANGED_INFO*)pMsg->Data.p; if (pInfo->State) { WM_SetFocus(hObj); } } break; case WM_TOUCH_CHILD: /* A descendent (child) has been touched or released. If it has been touched, we need to get to top. */ { const WM_MESSAGE * pMsgOrg; const GUI_PID_STATE * pState; pMsgOrg = (const WM_MESSAGE*)pMsg->Data.p; /* The original touch message */ pState = (const GUI_PID_STATE*)pMsgOrg->Data.p; if (pState) { /* Message may not have a valid pointer (moved out) ! */ if (pState->Pressed) { WM_BringToTop(hObj); return 0; /* Message handled -> Return */ } } } break; case WM_SET_ID: pWidget->Id = pMsg->Data.v; return 0; /* Message handled -> Return */ case WM_SET_FOCUS: if (pMsg->Data.v == 1) { WIDGET_SetState(hObj, pWidget->State | WIDGET_STATE_FOCUS); Notification = WM_NOTIFICATION_GOT_FOCUS; } else { WIDGET_SetState(hObj, pWidget->State & ~WIDGET_STATE_FOCUS); Notification = WM_NOTIFICATION_LOST_FOCUS; } WM_NotifyParent(hObj, Notification); pMsg->Data.v = 0; /* Focus change accepted */ return 0; case WM_GET_ACCEPT_FOCUS: pMsg->Data.v = (pWidget->State & WIDGET_STATE_FOCUSSABLE) ? 1 : 0; /* Can handle focus */ return 0; /* Message handled */ case WM_GET_INSIDE_RECT: WIDGET__GetInsideRect(pWidget, (GUI_RECT*)pMsg->Data.p); return 0; /* Message handled */ } return 1; /* Message NOT handled */ }
/********************************************************************* * * _Paint */ static void _Paint(EDIT_Obj* pObj, EDIT_Handle hObj) { GUI_RECT rFillRect, rInside, rText, rInvert; const char GUI_UNI_PTR * pText = NULL; int IsEnabled, CursorWidth = 0; IsEnabled = WM__IsEnabled(hObj); /* Set colors and font */ LCD_SetBkColor(pObj->Props.aBkColor[IsEnabled]); LCD_SetColor(pObj->Props.aTextColor[0]); GUI_SetFont(pObj->Props.pFont); /* Calculate size */ WIDGET__GetInsideRect(&pObj->Widget, &rFillRect); if (pObj->hpText) { pText = (const char*) GUI_ALLOC_h2p(pObj->hpText); } rInside = rFillRect; rInside.x0 += pObj->Props.Border + EDIT_XOFF; rInside.x1 -= pObj->Props.Border + EDIT_XOFF; GUI__CalcTextRect(pText, &rInside, &rText, pObj->Props.Align); /* Calculate position and size of cursor */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { int NumChars; CursorWidth = ((pObj->XSizeCursor > 0) ? (pObj->XSizeCursor) : (1)); NumChars = GUI__GetNumChars(pText); if (pText) { U16 Char; int i, IsRTL = 0; if ((pObj->EditMode != GUI_EDIT_MODE_INSERT) || (pObj->SelSize)) { if (pObj->CursorPos < NumChars) { if (pObj->SelSize) { CursorWidth = 0; for (i = pObj->CursorPos; i < (int)(pObj->CursorPos + pObj->SelSize); i++) { Char = GUI__GetCursorCharacter(pText, i, NumChars, 0); CursorWidth += GUI_GetCharDistX(Char); } if (!CursorWidth) { CursorWidth = 1; } } else { Char = GUI__GetCursorCharacter(pText, pObj->CursorPos, NumChars, &IsRTL); CursorWidth = GUI_GetCharDistX(Char); } } } rInvert = rText; if (IsRTL) { rInvert.x0 -= CursorWidth; } rInvert.x0 += GUI__GetCursorPosX(pText, pObj->CursorPos, NumChars); } } /* WM loop */ WM_ITERATE_START(NULL) { /* Set clipping rectangle */ WM_SetUserClipRect(&rFillRect); /* Display text */ WIDGET__FillStringInRect(pText, &rFillRect, &rInside, &rText); /* Display cursor if needed */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { GUI_InvertRect(rInvert.x0, rInvert.y0, rInvert.x0 + CursorWidth - 1, rInvert.y1); } WM_SetUserClipRect(NULL); /* Draw the 3D effect (if configured) */ WIDGET__EFFECT_DrawDown(&pObj->Widget); } WM_ITERATE_END(); }