窗口链
链表
struct WM_Obj {
GUI_RECT Rect; /* Outer dimensions of window */
GUI_RECT InvalidRect; /* Invalid rectangle */
WM_CALLBACK* cb; /* Ptr to notification callback */
WM_HWIN hNextLin; /* Next window in linear list */ 窗口链表
WM_HWIN hParent;
WM_HWIN hFirstChild; //窗口二叉树 的第一个子窗口
WM_HWIN hNext;//第一个子窗口的右兄弟
U16 Status; /* Some status flags */
};
添加窗口链表函数
static void _AddToLinList (WM_HWIN hNew) {
WM_Obj* pFirst;
WM_Obj* pNew;
if (WM__FirstWin) {
pFirst = WM_H2P(WM__FirstWin);
pNew = WM_H2P(hNew);
pNew->hNextLin = pFirst->hNextLin;
pFirst->hNextLin = hNew;
} else {
WM__FirstWin = hNew;
}
}
添加窗口二叉树 链表
void WM__InsertWindowIntoList(WM_HWIN hWin, WM_HWIN hParent) {
int OnTop;
WM_HWIN hi;
WM_Obj * pWin;
WM_Obj * pParent;
WM_Obj * pi;
if (hParent) {
pWin = WM_H2P(hWin);
pWin->hNext = 0;
pWin->hParent = hParent;
pParent = WM_H2P(hParent);
OnTop = pWin->Status & WM_CF_STAYONTOP;
hi = pParent->hFirstChild;
/* Put it at beginning of the list if there is no child */
if (hi == 0) { /* No child yet ... Makes things easy ! */
pParent->hFirstChild = hWin;
return; /* Early out ... We are done */
}
/* Put it at beginning of the list if first child is a TOP window and new one is not */
pi = WM_H2P(hi);
if (!OnTop) {
if (pi->Status & WM_SF_STAYONTOP) {
pWin->hNext = hi;
pParent->hFirstChild = hWin;
return; /* Early out ... We are done */
}
}
/* Put it at the end of the list or before the last non "STAY-ON-TOP" child */
do {
WM_Obj* pNext;
WM_HWIN hNext;
if ((hNext = pi->hNext) == 0) { /* End of sibling list ? */
pi->hNext = hWin; /* Then modify this last element to point to new one and we are done */
break;
}
pNext = WM_H2P(hNext);
if (!OnTop) {
if (pNext->Status & WM_SF_STAYONTOP) {
pi->hNext = hWin;
pWin->hNext = hNext;
break;
}
}
pi = pNext;
} while (1);
#if WM_SUPPORT_NOTIFY_VIS_CHANGED
WM__NotifyVisChanged(hWin, &pWin->Rect);
#endif
}
}
兄弟窗口的排序 z 序
Z序的排列主要参考两点
(1)越最新创建的窗口,Z序越大
(2)同类窗口下WM_CF_STAYONTOP Z序大
二叉树Z序