📄 framewin.c
字号:
* Private routines
*
**********************************************************************
*/
/*********************************************************************
*
* FRAMEWIN_h2p
*/
#if GUI_DEBUG_LEVEL >= GUI_DEBUG_LEVEL_CHECK_ALL
FRAMEWIN_Obj * FRAMEWIN_h2p(FRAMEWIN_Handle h) {
FRAMEWIN_Obj * p = (FRAMEWIN_Obj *)GUI_ALLOC_h2p(h);
if (p) {
if (p->DebugId != FRAMEWIN_ID) {
GUI_DEBUG_ERROROUT("FRAMEWIN.c: Wrong handle type or Object not init'ed");
return 0;
}
}
return p;
}
#endif
/*********************************************************************
*
* FRAMEWIN__CalcTitleHeight
*/
int FRAMEWIN__CalcTitleHeight(FRAMEWIN_Obj* pObj) {
int r = 0;
if (pObj->Widget.State & FRAMEWIN_SF_TITLEVIS) {
r = pObj->Props.TitleHeight;
if (r == 0) {
r = 2 + GUI_GetYSizeOfFont(pObj->Props.pFont);
}
}
return r;
}
/*********************************************************************
*
* FRAMEWIN__CalcPositions
*/
void FRAMEWIN__CalcPositions(FRAMEWIN_Obj* pObj, POSITIONS* pPos) {
WM_HWIN hChild;
WM_Obj* pChild;
int TitleHeight;
int MenuHeight = 0;
int IBorderSize = 0;
int BorderSize;
int xsize, ysize;
int x0, x1, y0;
BorderSize = pObj->Props.BorderSize;
xsize = WM__GetWindowSizeX(&pObj->Widget.Win);
ysize = WM__GetWindowSizeY(&pObj->Widget.Win);
if (pObj->Widget.State & FRAMEWIN_SF_TITLEVIS) {
IBorderSize = pObj->Props.IBorderSize;
}
TitleHeight = FRAMEWIN__CalcTitleHeight(pObj);
if (pObj->hMenu) {
MenuHeight = WM_GetWindowSizeY(pObj->hMenu);
}
pPos->TitleHeight = TitleHeight;
pPos->MenuHeight = MenuHeight;
/* Set object properties accordingly */
pPos->rClient.x0 = BorderSize;
pPos->rClient.x1 = xsize - BorderSize - 1;
pPos->rClient.y0 = BorderSize + IBorderSize + TitleHeight + MenuHeight;
pPos->rClient.y1 = ysize - BorderSize - 1;
/* Calculate title rect */
pPos->rTitleText.x0 = BorderSize;
pPos->rTitleText.x1 = xsize - BorderSize - 1;
pPos->rTitleText.y0 = BorderSize;
pPos->rTitleText.y1 = BorderSize + TitleHeight - 1;
/* Iterate over all children */
for (hChild = pObj->Widget.Win.hFirstChild; hChild; hChild = pChild->hNext) {
pChild = WM_H2P(hChild);
x0 = pChild->Rect.x0 - pObj->Widget.Win.Rect.x0;
x1 = pChild->Rect.x1 - pObj->Widget.Win.Rect.x0;
y0 = pChild->Rect.y0 - pObj->Widget.Win.Rect.y0;
if (y0 == BorderSize) {
if (pChild->Status & WM_SF_ANCHOR_RIGHT) {
if (x0 <= pPos->rTitleText.x1) {
pPos->rTitleText.x1 = x0 - 1;
}
} else {
if (x1 >= pPos->rTitleText.x0) {
pPos->rTitleText.x0 = x1 + 1;
}
}
}
}
}
/*********************************************************************
*
* FRAMEWIN__UpdatePositions
*/
void FRAMEWIN__UpdatePositions(FRAMEWIN_Obj* pObj) {
/* Move client window accordingly */
if (pObj->hClient || pObj->hMenu) {
POSITIONS Pos;
FRAMEWIN__CalcPositions(pObj, &Pos);
if (pObj->hClient) {
WM_MoveChildTo(pObj->hClient, Pos.rClient.x0, Pos.rClient.y0);
WM_SetSize(pObj->hClient,
Pos.rClient.x1 - Pos.rClient.x0 + 1,
Pos.rClient.y1 - Pos.rClient.y0 + 1);
}
if (pObj->hMenu) {
WM_MoveChildTo(pObj->hMenu, Pos.rClient.x0, Pos.rClient.y0 - Pos.MenuHeight);
}
}
}
/*********************************************************************
*
* Exported API routines: Callback
*
**********************************************************************
*/
/*********************************************************************
*
* Framewin Callback
*/
void FRAMEWIN_Callback (WM_MESSAGE *pMsg) {
FRAMEWIN_Handle hWin;
FRAMEWIN_Obj * pObj;
GUI_RECT * pRect;
POSITIONS Pos;
GUI_HOOK * pHook;
hWin = (FRAMEWIN_Handle)(pMsg->hWin);
pObj = (FRAMEWIN_Obj *)GUI_ALLOC_h2p(hWin); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
pRect = (GUI_RECT*)(pMsg->Data.p);
/* Call hook functions */
for (pHook = pObj->pFirstHook; pHook; pHook = pHook->pNext) {
int r;
r = (*pHook->pHookFunc)(pMsg);
if (r) {
return; /* Message handled */
}
}
switch (pMsg->MsgId) {
case WM_HANDLE_DIALOG_STATUS:
if (pMsg->Data.p) { /* set pointer to Dialog status */
pObj->pDialogStatus = (WM_DIALOG_STATUS*)pMsg->Data.p;
} else { /* return pointer to Dialog status */
pMsg->Data.p = pObj->pDialogStatus;
}
return;
case WM_PAINT:
_Paint(pObj);
break;
case WM_TOUCH:
_OnTouch(hWin, pObj, pMsg);
return; /* Return here ... Message handled */
case WM_GET_INSIDE_RECT:
FRAMEWIN__CalcPositions(pObj, &Pos);
*pRect = Pos.rClient;
return; /* Return here ... Message handled */
case WM_GET_CLIENT_WINDOW: /* return handle to client window. For most windows, there is no seperate client window, so it is the same handle */
pMsg->Data.v = (int)pObj->hClient;
return; /* Return here ... Message handled */
case WM_NOTIFY_PARENT:
if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
WM_MESSAGE Msg;
Msg.hWinSrc = hWin;
Msg.Data = pMsg->Data;
Msg.MsgId = WM_NOTIFY_PARENT_REFLECTION;
WM__SendMessage(pMsg->hWinSrc, &Msg);
}
return;
case WM_SET_FOCUS: /* We have received or lost focus */
if (pMsg->Data.v == 1) {
if (WM_IsWindow(pObj->hFocussedChild)) {
WM_SetFocus(pObj->hFocussedChild);
} else {
pObj->hFocussedChild = WM_SetFocusOnNextChild(pObj->hClient);
}
FRAMEWIN_SetActive(hWin, 1);
pMsg->Data.v = 0; /* Focus could be accepted */
} else {
FRAMEWIN_SetActive(hWin, 0);
}
return;
case WM_TOUCH_CHILD:
/* If a child of this framewindow has been touched and the frame window was not active,
the framewindow will receive the focus.
*/
if (!(pObj->Flags & FRAMEWIN_SF_ACTIVE)) {
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_SetFocus(hWin);
}
}
}
break;
case WM_NOTIFY_CHILD_HAS_FOCUS:
_OnChildHasFocus(hWin, pObj, pMsg);
break;
case WM_DELETE:
GUI_DEBUG_LOG("FRAMEWIN: FRAMEWIN_Callback(WM_DELETE)\n");
GUI_ALLOC_FreePtr(&pObj->hText);
break;
}
/* Let widget handle the standard messages */
if (WIDGET_HandleActive(hWin, pMsg) == 0) {
return;
}
WM_DefaultProc(pMsg);
}
/*********************************************************************
*
* Exported API routines: Create
*
**********************************************************************
*/
/*********************************************************************
*
* FRAMEWIN_CreateEx
*/
FRAMEWIN_Handle FRAMEWIN_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
int WinFlags, int ExFlags, int Id, const char* pTitle, WM_CALLBACK* cb)
{
FRAMEWIN_Handle hObj;
/* Create the window */
GUI_LOCK();
WinFlags |= WM_CF_LATE_CLIP; /* Always use late clipping since widget is optimized for it. */
hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags, FRAMEWIN_Callback,
sizeof(FRAMEWIN_Obj) - sizeof(WM_Obj));
if (hObj) {
FRAMEWIN_Obj* pObj;
POSITIONS Pos;
pObj = (FRAMEWIN_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
/* init widget specific variables */
WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE | FRAMEWIN_SF_TITLEVIS);
/* init member variables */
FRAMEWIN_INIT_ID(pObj);
pObj->Props = FRAMEWIN__DefaultProps;
pObj->cb = cb;
pObj->Flags = ExFlags;
pObj->hFocussedChild = 0;
pObj->hMenu = 0;
pObj->pFirstHook = NULL;
FRAMEWIN__CalcPositions(pObj, &Pos);
pObj->hClient = WM_CreateWindowAsChild(Pos.rClient.x0,Pos.rClient.y0,
Pos.rClient.x1 - Pos.rClient.x0 +1,
Pos.rClient.y1 - Pos.rClient.y0 +1,
hObj,
WM_CF_ANCHOR_RIGHT | WM_CF_ANCHOR_LEFT | WM_CF_ANCHOR_TOP | WM_CF_ANCHOR_BOTTOM | WM_CF_SHOW | WM_CF_LATE_CLIP,
FRAMEWIN__cbClient, 0);
/* Normally we disable memory devices for the frame window:
* The frame window does not flicker, and not using memory devices is usually faster.
* You can still use memory by explicitly specifying the flag
*/
if ((WinFlags & (WM_CF_MEMDEV | (WM_CF_MEMDEV_ON_REDRAW))) == 0) {
WM_DisableMemdev(hObj);
}
FRAMEWIN_SetText(hObj, pTitle);
}
GUI_UNLOCK();
return hObj;
}
/*********************************************************************
*
* Exported routines: Set Properties
*
**********************************************************************
*/
/*********************************************************************
*
* FRAMEWIN_SetText
*/
void FRAMEWIN_SetText(FRAMEWIN_Handle hObj, const char* s) {
if (hObj) {
FRAMEWIN_Obj* pObj;
GUI_LOCK();
pObj = FRAMEWIN_H2P(hObj);
if (GUI__SetText(&pObj->hText, s)) {
FRAMEWIN_Invalidate(hObj);
}
GUI_UNLOCK();
}
}
/*********************************************************************
*
* FRAMEWIN_SetTextAlign
*/
void FRAMEWIN_SetTextAlign(FRAMEWIN_Handle hObj, int Align) {
if (hObj) {
FRAMEWIN_Obj* pObj;
GUI_LOCK();
pObj = FRAMEWIN_H2P(hObj);
if (pObj->Props.TextAlign != Align) {
pObj->Props.TextAlign = Align;
FRAMEWIN_Invalidate(hObj);
}
GUI_UNLOCK();
}
}
/*********************************************************************
*
* FRAMEWIN_SetMoveable
*/
void FRAMEWIN_SetMoveable(FRAMEWIN_Handle hObj, int State) {
if (hObj) {
FRAMEWIN_Obj* pObj;
GUI_LOCK();
pObj = FRAMEWIN_H2P(hObj);
if (State) {
pObj->Flags |= FRAMEWIN_CF_MOVEABLE;
} else {
pObj->Flags &= ~FRAMEWIN_CF_MOVEABLE;
}
GUI_UNLOCK();
}
}
/*********************************************************************
*
* FRAMEWIN_SetActive
*/
void FRAMEWIN_SetActive(FRAMEWIN_Handle hObj, int State) {
if (hObj) {
WM_LOCK();
_SetActive(hObj, State);
WM_UNLOCK();
}
}
#else
void WIDGET_FrameWin(void) {} /* avoid empty object files */
#endif /* GUI_WINSUPPORT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -