/********************************************************************* * * WM_IsEnabled */ int WM_IsEnabled(WM_HWIN hObj) { int r = 0; if (hObj) { WM_LOCK(); r = WM__IsEnabled(hObj); WM_UNLOCK(); } return r; }
/********************************************************************* * * _OnKey */ static void _OnKey(CHECKBOX_Handle hObj, CHECKBOX_Obj * pObj, WM_MESSAGE * pMsg) { WM_KEY_INFO * pKeyInfo; if (WM__IsEnabled(hObj)) { pKeyInfo = (WM_KEY_INFO *)(pMsg->Data.p); if (pKeyInfo->PressedCnt > 0) { switch (pKeyInfo->Key) { case GUI_KEY_SPACE: CHECKBOX_SetState(hObj, (pObj->CurrentState + 1) % pObj->NumStates); break; /* Send to parent by not doing anything */ } } } }
/********************************************************************* * * EDIT_Callback */ void EDIT_Callback (WM_MESSAGE * pMsg) { int IsEnabled; EDIT_Handle hObj; EDIT_Obj* pObj; hObj = (EDIT_Handle) pMsg->hWin; pObj = (EDIT_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */ IsEnabled = WM__IsEnabled(hObj); /* Let widget handle the standard messages */ if (WIDGET_HandleActive(hObj, pMsg) == 0) { return; } switch (pMsg->MsgId) { case WM_TOUCH: _OnTouch(hObj, pObj, pMsg); break; case WM_PAINT: GUI_DEBUG_LOG("EDIT: _Callback(WM_PAINT)\n"); _Paint(pObj, hObj); return; case WM_DELETE: GUI_DEBUG_LOG("EDIT: _Callback(WM_DELETE)\n"); _Delete(pObj); break; /* No return here ... WM_DefaultProc needs to be called */ case WM_KEY: if (IsEnabled) { if ( ((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0) { int Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key; switch (Key) { case GUI_KEY_ENTER: case GUI_KEY_ESCAPE: case GUI_KEY_TAB: case GUI_KEY_BACKTAB: break; /* Send to parent by not doing anything */ default: EDIT_AddKey(hObj, Key); return; } } } break; } WM_DefaultProc(pMsg); }
/********************************************************************* * * _Paint */ static void _Paint(BUTTON_Obj* pObj, BUTTON_Handle hObj) { const char* s = NULL; unsigned int Index; int State, PressedState, ColorIndex; GUI_RECT rClient, rInside; State = pObj->Widget.State; PressedState = (State & BUTTON_STATE_PRESSED) ? 1 : 0; ColorIndex = (WM__IsEnabled(hObj)) ? PressedState : 2; GUI_SetFont(pObj->Props.pFont); GUI_DEBUG_LOG("BUTTON: Paint(..)\n"); if (pObj->hpText) { s = (const char*) GUI_ALLOC_h2p(pObj->hpText); } GUI_GetClientRect(&rClient); /* Start drawing */ rInside = rClient; /* Draw the 3D effect (if configured) */ #if BUTTON_USE_3D { int EffectSize; if ((PressedState) == 0) { pObj->Widget.pEffect->pfDrawUp(); /* _WIDGET_EFFECT_3D_DrawUp(); */ EffectSize = pObj->Widget.pEffect->EffectSize; } else { LCD_SetColor(0x000000); GUI_DrawRect(rClient.y0, rClient.x0, rClient.x1, rClient.y1); EffectSize = 1; } GUI__ReduceRect(&rInside, &rInside, EffectSize); } #endif /* Draw background */ LCD_SetBkColor (pObj->Props.aBkColor[ColorIndex]); LCD_SetColor (pObj->Props.aTextColor[ColorIndex]); WM_SetUserClipRect(&rInside); GUI_Clear(); /* Draw bitmap. If we have only one, we will use it. If we have to we will use the second one (Index 1) for the pressed state */ if (ColorIndex < 2) { Index = (pObj->ahDrawObj[BUTTON_BI_PRESSED] && PressedState) ? BUTTON_BI_PRESSED : BUTTON_BI_UNPRESSED; } else { Index = pObj->ahDrawObj[BUTTON_BI_DISABLED] ? BUTTON_BI_DISABLED : BUTTON_BI_UNPRESSED; } GUI_DRAW__Draw(pObj->ahDrawObj[Index], 0, 0); /* Draw the actual button (background and text) */ { GUI_RECT r; r = rInside; #if BUTTON_USE_3D if (PressedState) { GUI_MoveRect(&r, BUTTON_3D_MOVE_X,BUTTON_3D_MOVE_Y); } #endif GUI_SetTextMode(GUI_TM_TRANS); GUI_DispStringInRect(s, &r, pObj->Props.Align); } /* Draw focus */ if (State & BUTTON_STATE_FOCUS) { LCD_SetColor(pObj->Props.FocusColor); GUI_DrawFocusRect(&rClient, 2); } WM_SetUserClipRect(NULL); }
/********************************************************************* * * _OnPaint * * Purpose: * Paints the RADIO button. * The button can actually consist of multiple buttons (NumItems). * The focus rectangle will be drawn on top of the text if any text is set, * otherwise around the entire buttons. */ static void _OnPaint(RADIO_Handle hObj, RADIO_Obj* pObj) { const GUI_BITMAP* pBmRadio; const GUI_BITMAP* pBmCheck; const char* pText; GUI_FONTINFO FontInfo; GUI_RECT Rect, r, rFocus = {0}; int i, y, HasFocus, FontDistY; U8 SpaceAbove, CHeight, FocusBorder; /* Init some data */ WIDGET__GetClientRect(&pObj->Widget, &rFocus); HasFocus = (pObj->Widget.State & WIDGET_STATE_FOCUS) ? 1 : 0; pBmRadio = pObj->apBmRadio[WM__IsEnabled(hObj)]; pBmCheck = pObj->pBmCheck; rFocus.x1 = pBmRadio->XSize + RADIO_BORDER * 2 - 1; rFocus.y1 = pObj->Height + ((pObj->NumItems - 1) * pObj->Spacing) - 1; /* Select font and text color */ LCD_SetColor(pObj->TextColor); GUI_SetFont(pObj->pFont); GUI_SetTextMode(GUI_TM_TRANS); /* Get font infos */ GUI_GetFontInfo(pObj->pFont, &FontInfo); FontDistY = GUI_GetFontDistY(); CHeight = FontInfo.CHeight; SpaceAbove = FontInfo.Baseline - CHeight; Rect.x0 = pBmRadio->XSize + RADIO_BORDER * 2 + 2; Rect.y0 = (CHeight <= pObj->Height) ? ((pObj->Height - CHeight) / 2) : 0; Rect.y1 = Rect.y0 + CHeight - 1; FocusBorder = (FontDistY <= 12) ? 2 : 3; if (Rect.y0 < FocusBorder) { FocusBorder = Rect.y0; } /* Clear inside ... Just in case */ /* Fill with parents background color */ #if WM_SUPPORT_TRANSPARENCY if (!WM_GetHasTrans(hObj)) #endif { if (pObj->BkColor != GUI_INVALID_COLOR) { LCD_SetBkColor(pObj->BkColor); } else { LCD_SetBkColor(RADIO_DEFAULT_BKCOLOR); } GUI_Clear(); } /* Iterate over all items */ for (i = 0; i < pObj->NumItems; i++) { y = i * pObj->Spacing; /* Draw the radio button bitmap */ GUI_DrawBitmap(pBmRadio, RADIO_BORDER, RADIO_BORDER + y); /* Draw the check bitmap */ if (pObj->Sel == i) { GUI_DrawBitmap(pBmCheck, RADIO_BORDER + (pBmRadio->XSize - pBmCheck->XSize) / 2, RADIO_BORDER + ((pBmRadio->YSize - pBmCheck->YSize) / 2) + y); } /* Draw text if available */ pText = (const char*)GUI_ARRAY_GetpItem(&pObj->TextArray, i); if (pText) { if (*pText) { r = Rect; r.x1 = r.x0 + GUI_GetStringDistX(pText) - 2; GUI_MoveRect(&r, 0, y); GUI_DispStringAt(pText, r.x0, r.y0 - SpaceAbove); /* Calculate focus rect */ if (HasFocus && (pObj->Sel == i)) { _ResizeRect(&rFocus, &r, FocusBorder); } } } } /* Draw the focus rect */ if (HasFocus) { LCD_SetColor(GUI_BLACK); WIDGET__DrawFocusRect(&pObj->Widget, &rFocus, 0); } }
/********************************************************************* * * _Paint */ static void _Paint(CHECKBOX_Obj* pObj, CHECKBOX_Handle hObj) { GUI_RECT RectBox = {0}; int ColorIndex, EffectSize, Index; EffectSize = pObj->Widget.pEffect->EffectSize; ColorIndex = WM__IsEnabled(hObj); /* Clear inside ... Just in case */ /* Fill with parents background color */ #if WM_SUPPORT_TRANSPARENCY if (!WM_GetHasTrans(hObj)) #endif { if (pObj->Props.BkColor == GUI_INVALID_COLOR) { LCD_SetBkColor(WIDGET__GetBkColor(hObj)); } else { LCD_SetBkColor(pObj->Props.BkColor); } GUI_Clear(); } /* Get size from bitmap */ RectBox.x1 = pObj->Props.apBm[CHECKBOX_BI_ACTIV]->XSize - 1 + 2 * EffectSize; RectBox.y1 = pObj->Props.apBm[CHECKBOX_BI_ACTIV]->YSize - 1 + 2 * EffectSize; WM_SetUserClipRect(&RectBox); /* Clear inside ... Just in case */ LCD_SetBkColor(pObj->Props.aBkColorBox[ColorIndex]); GUI_Clear(); Index = pObj->CurrentState * 2 + ColorIndex; if (pObj->Props.apBm[Index]) { GUI_DrawBitmap(pObj->Props.apBm[Index], EffectSize, EffectSize); } /* Draw the effect arround the box */ WIDGET__EFFECT_DrawDownRect(&pObj->Widget, &RectBox); WM_SetUserClipRect(NULL); /* Draw text if needed */ if (pObj->hpText) { const char * s; GUI_RECT RectText; /* Draw the text */ s = (const char *) GUI_ALLOC_h2p(pObj->hpText); WM_GetClientRect(&RectText); RectText.x0 += RectBox.x1 + 1 + pObj->Props.Spacing; GUI_SetTextMode(GUI_TM_TRANS); LCD_SetColor(pObj->Props.TextColor); GUI_SetFont(pObj->Props.pFont); GUI_DispStringInRect(s, &RectText, pObj->Props.Align); /* Draw focus rectangle */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { int xSizeText = GUI_GetStringDistX(s); int ySizeText = GUI_GetFontSizeY(); GUI_RECT RectFocus = RectText; switch (pObj->Props.Align & ~(GUI_TA_HORIZONTAL)) { case GUI_TA_VCENTER: RectFocus.y0 = (RectText.y1 - ySizeText + 1) / 2; break; case GUI_TA_BOTTOM: RectFocus.y0 = RectText.y1 - ySizeText; break; } switch (pObj->Props.Align & ~(GUI_TA_VERTICAL)) { case GUI_TA_HCENTER: RectFocus.x0 += ((RectText.x1 - RectText.x0) - xSizeText) / 2; break; case GUI_TA_RIGHT: RectFocus.x0 += (RectText.x1 - RectText.x0) - xSizeText; break; } RectFocus.x1 = RectFocus.x0 + xSizeText - 1; RectFocus.y1 = RectFocus.y0 + ySizeText - 1; LCD_SetColor(pObj->Props.FocusColor); GUI_DrawFocusRect(&RectFocus, -1); } } }
/********************************************************************* * * _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(); }