procedure TATCheckedComboBox.ListWndProc(
var Message: TMessage);
var
nItemHeight, nTopIndex, nIndex: Integer;
rcItem,rcClient: TRect;
pt : TPoint;
begin
case Message.Msg
of
LB_GETCURSEL :
// this is for to not draw the selected in the text area
begin
Message.result := -1;
exit;
end;
//--------------------------------------------------------------------------------------
// This code prevents automatic scrolling when mouse leaves to dropdown window
WM_MOUSEMOVE,
WM_TIMER:
begin
GetWindowRect(FListHandle, rcClient);
if not PtInRect(rcClient, Mouse.CursorPos)
then
begin
Message.Result := -1;
Exit;
end;
end;
//--------------------------------------------------------------------------------------
WM_CHAR:
// pressing space toggles the checked
begin
if (TWMKey(
Message).CharCode = VK_SPACE)
then
begin
// Get the current selection
nIndex := CallWindowProcA(FDefListProc, FListHandle, LB_GETCURSEL,
Message.wParam,
Message.lParam);
SendMessage(FListHandle, LB_GETITEMRECT, nIndex, LongInt(@rcItem));
InvalidateRect(FListHandle, @rcItem, FALSE);
SetCheck(nIndex,
not IsChecked(nIndex));
SendMessage(WM_COMMAND,
handle, CBN_SELCHANGE,
handle);
Message.result := 0;
exit;
end
end;
WM_LBUTTONDOWN:
begin
Windows.GetClientRect(FListHandle, rcClient);
pt.x := TWMMouse(
Message).XPos;
//LOWORD(Message.lParam);
pt.y := TWMMouse(
Message).YPos;
//HIWORD(Message.lParam);
if (PtInRect(rcClient, pt))
then
begin
nItemHeight := SendMessage(FListHandle, LB_GETITEMHEIGHT, 0, 0);
nTopIndex := SendMessage(FListHandle, LB_GETTOPINDEX, 0, 0);
// Compute which index to check/uncheck
nIndex := trunc(nTopIndex + pt.y / nItemHeight);
SendMessage(FListHandle, LB_GETITEMRECT, nIndex, LongInt(@rcItem));
if (PtInRect(rcItem, pt))
then
begin
InvalidateRect(FListHandle, @rcItem, FALSE);
SetCheck(nIndex,
not IsChecked(nIndex));
SendMessage(WM_COMMAND,
handle, CBN_SELCHANGE,
handle);
end
end
end;
WM_LBUTTONUP:
begin
Message.result := 0;
exit;
end;
end;
ComboWndProc(
Message, FListHandle, FDefListProc);
end;