EDIT_Handle EDIT_CreateAsChild (int x0, int y0, int xsize, int ysize, WM_HWIN hParent, int Id, int Flags, int MaxLen) { EDIT_Handle hObj; if (MaxLen == 0) { MaxLen = 8; } /* Alloc memory for obj */ WM_LOCK(); hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WM_CF_SHOW | Flags, EDIT__Callback, sizeof(EDIT_Obj)-sizeof(WM_Obj)); if (hObj) { EDIT_Obj* pObj = (EDIT_Obj*)WM_HMEM2Ptr(hObj); /* init widget specific variables */ WIDGET__Init(&pObj->Widget, WIDGET_STATE_FOCUSSABLE | WIDGET_STATE_ENABLED); pObj->Widget.Id = Id; /* init member variables */ INIT_ID(pObj); pObj->pFont = _pDefaultFont; pObj->aBkColor[0] = EDIT_BKCOLOR0_DEFAULT; pObj->aBkColor[1] = EDIT_BKCOLOR1_DEFAULT; pObj->aTextColor[0] = EDIT_TEXTCOLOR0_DEFAULT; pObj->aTextColor[1] = EDIT_TEXTCOLOR1_DEFAULT; pObj->Align = _DefaultAlign; pObj->Border = _DefaultBorder; pObj->XSizeCursor = 1; pObj->MaxLen = MaxLen; if ((pObj->hpText = WM_ALLOC(MaxLen+1)) ==0) { GUI_DEBUG_ERROROUT("EDIT_Create failed to alloc buffer"); EDIT_Delete(hObj); hObj =0; } } WM_UNLOCK(); return hObj; }
void PROGBAR_SetText(PROGBAR_Handle hObj, const char* s) { PROGBAR_Obj* pObj; WM_HMEM hMem; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); _FreeText(hObj); hMem = WM_ALLOC((int)strlen(s)+1); strcpy((char *) WM_HMEM2Ptr(hMem), s); pObj->hpText = hMem; Invalidate(hObj); WM_UNLOCK(); } }
void EDIT_SetMaxLen(EDIT_Handle hObj, int MaxLen) { EDIT_Obj* pObj; WM_HMEM hpText; if (hObj) { WM_LOCK(); pObj = EDIT_H2P(hObj); if ((hpText = WM_ALLOC(MaxLen+1)) ==0) { GUI_DEBUG_ERROROUT("EDIT_SetMaxLen failed to alloc buffer"); } else { WM_FREEPTR(&pObj->hpText); pObj->hpText = hpText; pObj->MaxLen = MaxLen; } EDIT_Invalidate(hObj); WM_UNLOCK(); } }
void BUTTON_SetText(BUTTON_Handle hObj, const char* s) { WM_LOCK(); if (hObj) { BUTTON_Obj* pObj = BUTTON_H2P(hObj); BUTTON_ASSERT_IS_VALID_PTR(pObj); WM_FREEPTR(&pObj->hpText); { WM_HMEM hMem = WM_ALLOC(strlen(s)+1); if (hMem) { strcpy((char *) WM_HMEM2Ptr(hMem), s); } pObj->hpText = hMem; } BUTTON_Invalidate(hObj); } else { GUI_DEBUG_WARN("BUTTON_SetText: Invalid handle"); } WM_UNLOCK(); }
TERMINAL_Handle TERMINAL_CreateAsChild( int x0, int y0, int xsize, int ysize, WM_HWIN hWinParent, int MaxLen, int Flags) { TERMINAL_Handle hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hWinParent, Flags, _TERMINAL_Callback, sizeof(TERMINAL_Obj)-sizeof(WM_Obj)); if (hObj) { TERMINAL_Obj* pObj = TERMINAL_H2P(hObj); pObj->hpText = WM_ALLOC(MaxLen+1); /* init member variables */ if (pObj->hpText ==0) { GUI_DEBUG_ERROROUT("TERMINAL_Create failed to alloc buffer"); TERMINAL_Delete(hObj); hObj =0; } pObj->MaxLen = MaxLen; } else { GUI_DEBUG_ERROROUT_IF(hObj==0, "TERMINAL_Create failed") } return hObj; }
WM_HWIN WM_CreateWindowAsChild( int x0, int y0, int width, int height ,WM_HWIN hWinParent ,U16 Style ,WM_CALLBACK* cb ,int NumExtraBytes) { WM_Obj* pWin; WM_HWIN hWin; WM_LOCK(); Style |= WM__CreateFlags; /* Get Parent info */ if (!hWinParent) { if (WM__NumWindows) { hWinParent = WM_HBKWIN; } } if (hWinParent) { GUI_RECT Rect; WM_MESSAGE Msg; Msg.MsgId = WM_GETCLIENTRECT_ABS; Msg.Data.p = &Rect; WM_SendMessage(hWinParent, &Msg); x0 += Rect.x0; y0 += Rect.y0; if (width==0) width = Rect.x1-Rect.x0+1; if (height==0) height = Rect.y1-Rect.y0+1; } if ((hWin = (WM_HWIN) WM_ALLOC(NumExtraBytes+sizeof(WM_Obj))) == 0) { GUI_DEBUG_ERROROUT("WM_CreateWindow: No memory to create window"); } else { WM__NumWindows++; pWin = WM_H2P(hWin); memset (pWin, 0, sizeof(WM_Obj)); /* erase this data structure The explicit zero-init is no longer needed since the entire data structure is already zeroed. The advantage is that it reduces program size. */ pWin->Rect.x0 = x0; pWin->Rect.y0 = y0; pWin->Rect.x1 = x0+width-1; pWin->Rect.y1 = y0+height-1; pWin->Status = WM_SF_INUSE; /* Mark window as in use */ pWin->cb = cb; /* Add to linked lists */ pWin->hParent = hWinParent; _AddChild(hWinParent, hWin, Style & WM_CF_STAYONTOP); _AddToLinList(hWin); /* Put Window on top (or bottom) of windows stack */ if (Style & WM_CF_ACTIVATE /*| (cb==NULL)*/) { WM_SelectWindow(hWin); /* This is not needed if callbacks are being used, but it does not cost a lot and makes life easier ... */ } /* Mark client area as invalid */ WM__SendMsgNoData(hWin, WM_CREATE); /* Handle the Style flags, one at a time */ if (Style & WM_CF_SHOW) { WM_ShowWindow(hWin); } /* Hide if parent is not visible */ if (hWinParent) { WM_Obj* pWinParent = WM_H2P(hWinParent); if (!(pWinParent->Status & WM_SF_ISVIS)) { WM_HideWindow(hWin); } } /* Copy the flags which can simply be accepted */ pWin->Status |= (Style & (WM_SF_MEMDEV|WM_SF_STAYONTOP|WM_SF_HASTRANS)); } WM_UNLOCK(); return hWin; }