/********************************************************************* * * _CalcPositions * * Calculates all positions required for drawing or for mouse / touch * evaluation. */ static void _CalcPositions(SCROLLBAR_Obj* pObj, SCROLLBAR_POSITIONS* pPos) { int xSizeArrow, xSize, xSizeMoveable, ThumbSize, NumItems, xSizeThumbArea; WM_HWIN hWin; GUI_RECT r, rSub; int x0, y0; r = pObj->Widget.Win.Rect; x0 = r.x0; y0 = r.y0; pPos->x1 = (pObj->Widget.State & WIDGET_STATE_VERTICAL) ? r.y1 : r.x1; /* Subtract the rectangle of the other scrollbar (if existing and visible) */ if (pObj->Widget.Id == GUI_ID_HSCROLL) { hWin = WM_GetScrollbarV(pObj->Widget.Win.hParent); if (hWin) { WM_GetWindowRectEx(hWin, &rSub); if (r.x1 == rSub.x1) { r.x1 = rSub.x0 -1; } } } if (pObj->Widget.Id == GUI_ID_VSCROLL) { hWin = WM_GetScrollbarH(pObj->Widget.Win.hParent); if (hWin) { WM_GetWindowRectEx(hWin, &rSub); if (r.y1 == rSub.y1) { r.y1 = rSub.y0 -1; } } } /* Convert coordinates of this window */ GUI_MoveRect(&r, -x0, -y0); /* Convert real into virtual coordinates */ _WIDGET__RECT2VRECT(&pObj->Widget, &r); NumItems = pObj->NumItems; xSize = r.x1 - r.x0 + 1; xSizeArrow = _GetArrowSize(pObj); xSizeThumbArea= xSize - 2 * xSizeArrow; /* Number of pixels available for thumb and movement */ ThumbSize = GUI__DivideRound(xSizeThumbArea * pObj->PageSize, NumItems); if (ThumbSize < 4) { ThumbSize = 4; } if (ThumbSize > xSizeThumbArea) { ThumbSize = xSizeThumbArea; } xSizeMoveable = xSizeThumbArea - ThumbSize; pPos->x0_LeftArrow = r.x0; pPos->x1_LeftArrow = xSizeArrow - 1; pPos->x1_RightArrow = xSize - 1; pPos->x0_RightArrow = xSize - xSizeArrow; pPos->x0_Thumb = pPos->x1_LeftArrow + 1+ GUI__DivideRound(xSizeMoveable * pObj->v, NumItems - pObj->PageSize); pPos->x1_Thumb = pPos->x0_Thumb + ThumbSize - 1; pPos->xSizeMoveable = xSizeMoveable; pPos->ThumbSize = ThumbSize; }
/********************************************************************* * * _LISTVIEW_Callback */ static void _LISTVIEW_Callback (WM_MESSAGE *pMsg) { LISTVIEW_Handle hObj; LISTVIEW_Obj* pObj; WM_SCROLL_STATE ScrollState; hObj = pMsg->hWin; /* Let widget handle the standard messages */ if (WIDGET_HandleActive(hObj, pMsg) == 0) { return; } pObj = LISTVIEW_H2P(hObj); switch (pMsg->MsgId) { case WM_NOTIFY_CLIENTCHANGE: case WM_SIZE: LISTVIEW__UpdateScrollParas(hObj, pObj); return; case WM_NOTIFY_PARENT: switch (pMsg->Data.v) { case WM_NOTIFICATION_CHILD_DELETED: /* make sure we do not send any messages to the header child once it has been deleted */ if (pMsg->hWinSrc == pObj->hHeader) { pObj->hHeader = 0; } break; case WM_NOTIFICATION_VALUE_CHANGED: if (pMsg->hWinSrc == WM_GetScrollbarV(hObj)) { WM_GetScrollState(pMsg->hWinSrc, &ScrollState); pObj->ScrollStateV.v = ScrollState.v; LISTVIEW__InvalidateInsideArea(hObj, pObj); _NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED); } else if (pMsg->hWinSrc == WM_GetScrollbarH(hObj)) { WM_GetScrollState(pMsg->hWinSrc, &ScrollState); pObj->ScrollStateH.v = ScrollState.v; LISTVIEW__UpdateScrollParas(hObj, pObj); HEADER_SetScrollPos(pObj->hHeader, pObj->ScrollStateH.v); _NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED); } break; case WM_NOTIFICATION_SCROLLBAR_ADDED: LISTVIEW__UpdateScrollParas(hObj, pObj); break; } return; case WM_PAINT: _Paint(hObj, pObj, pMsg); return; case WM_TOUCH: _OnTouch(hObj, pObj, pMsg); return; /* Important: message handled ! */ case WM_KEY: if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt > 0) { int Key; Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key; if (_AddKey(hObj, Key)) { return; } } break; /* No return here ... WM_DefaultProc needs to be called */ case WM_DELETE: _FreeAttached(pObj); break; /* No return here ... WM_DefaultProc needs to be called */ } WM_DefaultProc(pMsg); }
/********************************************************************* * * _LISTBOX_Callback */ static void _LISTBOX_Callback(WM_MESSAGE*pMsg) { LISTBOX_Handle hObj = pMsg->hWin; LISTBOX_Obj* pObj = LISTBOX_H2P(hObj); WM_SCROLL_STATE ScrollState; /* Let widget handle the standard messages */ if (WIDGET_HandleActive(hObj, pMsg) == 0) { /* Owner needs to be informed about focus change */ if (pMsg->MsgId == WM_SET_FOCUS) { if (pMsg->Data.v == 0) { /* Lost focus ? */ _NotifyOwner(hObj, LISTBOX_NOTIFICATION_LOST_FOCUS); } } return; } switch (pMsg->MsgId) { case WM_NOTIFY_PARENT: switch (pMsg->Data.v) { case WM_NOTIFICATION_VALUE_CHANGED: if (pMsg->hWinSrc == WM_GetScrollbarV(hObj)) { WM_GetScrollState(pMsg->hWinSrc, &ScrollState); pObj->ScrollStateV.v = ScrollState.v; LISTBOX__InvalidateInsideArea(hObj); _NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED); } else if (pMsg->hWinSrc == WM_GetScrollbarH(hObj)) { WM_GetScrollState(pMsg->hWinSrc, &ScrollState); pObj->ScrollStateH.v = ScrollState.v; LISTBOX__InvalidateInsideArea(hObj); _NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED); } break; case WM_NOTIFICATION_SCROLLBAR_ADDED: LISTBOX_UpdateScrollers(hObj); break; } break; case WM_PAINT: _OnPaint(hObj, pObj, pMsg); break; case WM_PID_STATE_CHANGED: { const WM_PID_STATE_CHANGED_INFO* pInfo = (const WM_PID_STATE_CHANGED_INFO*)pMsg->Data.p; if (pInfo->State) { int Sel; Sel = _GetItemFromPos(hObj, pObj, pInfo->x, pInfo->y); if (Sel >= 0) { _ToggleMultiSel(hObj, pObj, Sel); LISTBOX_SetSel(hObj, Sel); } _NotifyOwner(hObj, WM_NOTIFICATION_CLICKED); return; } } break; case WM_TOUCH: _OnTouch(hObj, pMsg); return; #if GUI_SUPPORT_MOUSE case WM_MOUSEOVER: if (_OnMouseOver(hObj, pObj, pMsg) == 0) return; break; #endif case WM_DELETE: _FreeAttached(pObj); break; /* No return here ... WM_DefaultProc needs to be called */ case WM_KEY: if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt > 0) { int Key; Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key; if (LISTBOX_AddKey(hObj, Key)) { return; } } break; case WM_SIZE: LISTBOX_UpdateScrollers(hObj); WM_InvalidateWindow(hObj); break; } WM_DefaultProc(pMsg); }
/********************************************************************* * * LISTVIEW_Callback */ void LISTVIEW_Callback (WM_MESSAGE *pMsg) { LISTVIEW_Handle hObj; LISTVIEW_Obj* pObj; WM_SCROLL_STATE ScrollState; hObj = pMsg->hWin; /* Let widget handle the standard messages */ if (WIDGET_HandleActive(hObj, pMsg) == 0) { return; } pObj = (LISTVIEW_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */ switch (pMsg->MsgId) { case WM_NOTIFY_CLIENTCHANGE: case WM_SIZE: if (pMsg->hWinSrc && (pMsg->hWinSrc == pObj->hHeader)) { LISTVIEW__UpdateScrollParas(hObj, pObj); } return; case WM_NOTIFY_PARENT: switch (pMsg->Data.v) { case WM_NOTIFICATION_CHILD_DELETED: /* make sure we do not send any messages to the header child once it has been deleted */ if (pMsg->hWinSrc == pObj->hHeader) { pObj->hHeader = 0; } break; case WM_NOTIFICATION_VALUE_CHANGED: if (pMsg->hWinSrc == WM_GetScrollbarV(hObj)) { WM_GetScrollState(pMsg->hWinSrc, &ScrollState); pObj->ScrollStateV.v = ScrollState.v; LISTVIEW__InvalidateInsideArea(hObj, pObj); _NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED); } else if (pMsg->hWinSrc == WM_GetScrollbarH(hObj)) { WM_GetScrollState(pMsg->hWinSrc, &ScrollState); pObj->ScrollStateH.v = ScrollState.v; LISTVIEW__UpdateScrollParas(hObj, pObj); HEADER_SetScrollPos(pObj->hHeader, pObj->ScrollStateH.v); _NotifyOwner(hObj, WM_NOTIFICATION_SCROLL_CHANGED); } break; case WM_NOTIFICATION_SCROLLBAR_ADDED: #if WIDGET_USE_PARENT_EFFECT WIDGET_SetEffect(pMsg->hWinSrc, pObj->Widget.pEffect); #endif LISTVIEW__UpdateScrollParas(hObj, pObj); break; case WM_NOTIFICATION_RELEASED: if ((pMsg->hWinSrc == pObj->hHeader) && (pObj->hSort)) { int Column; LISTVIEW_SORT * pSort; LISTVIEW_COLUMN * pColumn; WM_SetFocus(hObj); Column = HEADER_GetSel(pObj->hHeader); if (Column >= 0) { pColumn = (LISTVIEW_COLUMN *)GUI_ARRAY_GetpItem(&pObj->ColumnArray, Column); if (pColumn->fpCompare) { pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(pObj->hSort); if (pSort) { // ReverseSort if (pObj->SortIndex == Column) { pSort->Reverse ^= 1; pObj->ReverseSort = 1; pObj->IsSorted = 0; } else { pSort->Reverse = 0; pObj->SortIndex = Column; pObj->IsPresorted = 0; } /* if (pObj->SortIndex == Column) { pSort->Reverse ^= 1; } else { pSort->Reverse = 0; pObj->SortIndex = Column; } pObj->IsPresorted = 0; */ LISTVIEW__InvalidateInsideArea(hObj, pObj); } } } } break; } return; case WM_PAINT: _Paint(hObj, pObj, pMsg); return; case WM_TOUCH: _OnTouch(hObj, pObj, pMsg); return; /* Important: message handled ! */ case WM_KEY: if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt > 0) { int Key; Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key; if (_AddKey(hObj, pObj, Key)) { return; } } break; /* No return here ... WM_DefaultProc needs to be called */ case WM_DELETE: _FreeAttached(pObj); break; /* No return here ... WM_DefaultProc needs to be called */ } WM_DefaultProc(pMsg); }