LCL: set Windows listbox itemindex to -1 if nothing is selected. Issue #19893

git-svn-id: trunk@31884 -
This commit is contained in:
juha 2011-08-06 10:00:58 +00:00
parent 7e2778735b
commit 69a63a5af6
3 changed files with 45 additions and 31 deletions

View File

@ -53,21 +53,23 @@ end;
procedure TWin32ListStringList.InitFlags; procedure TWin32ListStringList.InitFlags;
begin begin
FFlagSort := UINT(LBS_SORT); FFlagSort := UINT(LBS_SORT);
FFlagGetText := UINT(LB_GETTEXT); FFlagGetText := UINT(LB_GETTEXT);
FFlagGetTextLen := UINT(LB_GETTEXTLEN); FFlagGetTextLen := UINT(LB_GETTEXTLEN);
FFlagGetCount := UINT(LB_GETCOUNT); FFlagGetCount := UINT(LB_GETCOUNT);
FFlagResetContent := UINT(LB_RESETCONTENT); FFlagResetContent := UINT(LB_RESETCONTENT);
FFlagDeleteString := UINT(LB_DELETESTRING); FFlagDeleteString := UINT(LB_DELETESTRING);
FFlagInsertString := UINT(LB_INSERTSTRING); FFlagInsertString := UINT(LB_INSERTSTRING);
FFlagAddString := UINT(LB_ADDSTRING); FFlagAddString := UINT(LB_ADDSTRING);
FFlagGetItemData := UINT(LB_GETITEMDATA); FFlagGetItemData := UINT(LB_GETITEMDATA);
FFlagSetItemData := UINT(LB_SETITEMDATA); FFlagSetItemData := UINT(LB_SETITEMDATA);
FFlagGetItemIndex := UINT(LB_GETCURSEL); FFlagGetItemIndex := UINT(LB_GETCURSEL);
FFlagSetItemIndex := UINT(LB_SETCURSEL); FFlagSetItemIndex := UINT(LB_SETCURSEL);
FFlagGetSelected := UINT(LB_GETSEL); FFlagGetCaretIndex := UINT(LB_GETCARETINDEX);
FFlagSetSelected := UINT(LB_SETSEL); FFlagSetCaretIndex := UINT(LB_SETCARETINDEX);
FFlagInitStorage := UINT(LB_INITSTORAGE); FFlagGetSelected := UINT(LB_GETSEL);
FFlagSetSelected := UINT(LB_SETSEL);
FFlagInitStorage := UINT(LB_INITSTORAGE);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -244,7 +246,12 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TWin32ListStringList.Insert(Index: Integer; Const S: String); procedure TWin32ListStringList.Insert(Index: Integer; Const S: String);
var
lItemIndex: Integer;
begin begin
if (FFlagGetCaretIndex <> 0) and (GetCount = 0) then
lItemIndex := SendMessage(FWin32List, FFlagGetCaretIndex, 0, 0);
FLastInsertedIndex := Index; FLastInsertedIndex := Index;
if FSorted then if FSorted then
begin begin
@ -268,6 +275,9 @@ begin
Windows.SendMessage(FWin32List, FFlagInsertString, Index, LPARAM(PChar(S))); Windows.SendMessage(FWin32List, FFlagInsertString, Index, LPARAM(PChar(S)));
{$endif} {$endif}
end; end;
if (FFlagSetCaretIndex <> 0) and (GetCount = 1) then
SendMessage(FWin32List, FFlagSetCaretIndex, lItemIndex, 0);
end; end;
procedure TWin32ListStringList.Put(Index: integer; const S: string); procedure TWin32ListStringList.Put(Index: integer; const S: string);
@ -333,21 +343,23 @@ end;
procedure TWin32ComboBoxStringList.InitFlags; procedure TWin32ComboBoxStringList.InitFlags;
begin begin
FFlagSort := UINT(CBS_SORT); FFlagSort := UINT(CBS_SORT);
FFlagGetText := UINT(CB_GETLBTEXT); FFlagGetText := UINT(CB_GETLBTEXT);
FFlagGetTextLen := UINT(CB_GETLBTEXTLEN); FFlagGetTextLen := UINT(CB_GETLBTEXTLEN);
FFlagGetCount := UINT(CB_GETCOUNT); FFlagGetCount := UINT(CB_GETCOUNT);
FFlagResetContent := UINT(CB_RESETCONTENT); FFlagResetContent := UINT(CB_RESETCONTENT);
FFlagDeleteString := UINT(CB_DELETESTRING); FFlagDeleteString := UINT(CB_DELETESTRING);
FFlagInsertString := UINT(CB_INSERTSTRING); FFlagInsertString := UINT(CB_INSERTSTRING);
FFlagAddString := UINT(CB_ADDSTRING); FFlagAddString := UINT(CB_ADDSTRING);
FFlagGetItemData := UINT(CB_GETITEMDATA); FFlagGetItemData := UINT(CB_GETITEMDATA);
FFlagSetItemData := UINT(CB_SETITEMDATA); FFlagSetItemData := UINT(CB_SETITEMDATA);
FFlagGetItemIndex := UINT(CB_GETCURSEL); FFlagGetItemIndex := UINT(CB_GETCURSEL);
FFlagSetItemIndex := UINT(CB_SETCURSEL); FFlagSetItemIndex := UINT(CB_SETCURSEL);
FFlagGetSelected := UINT(0); FFlagGetCaretIndex := UINT(0);
FFlagSetSelected := UINT(0); FFlagSetCaretIndex := UINT(0);
FFlagInitStorage := UINT(CB_INITSTORAGE); FFlagGetSelected := UINT(0);
FFlagSetSelected := UINT(0);
FFlagInitStorage := UINT(CB_INITSTORAGE);
//Get edit and item sizes //Get edit and item sizes
FDropDownCount := TCustomComboBox(FSender).DropDownCount; FDropDownCount := TCustomComboBox(FSender).DropDownCount;
if FDropDownCount = 0 then if FDropDownCount = 0 then

View File

@ -50,6 +50,8 @@ Type
FFlagSetItemData: Cardinal; FFlagSetItemData: Cardinal;
FFlagGetItemIndex: cardinal; FFlagGetItemIndex: cardinal;
FFlagSetItemIndex: cardinal; FFlagSetItemIndex: cardinal;
FFlagGetCaretIndex: cardinal;
FFlagSetCaretIndex: cardinal;
FFlagGetSelected: cardinal; FFlagGetSelected: cardinal;
FFlagsetSelected: cardinal; FFlagsetSelected: cardinal;
FFlagInitStorage: cardinal; FFlagInitStorage: cardinal;

View File

@ -769,8 +769,8 @@ begin
if AIndex >= 0 then if AIndex >= 0 then
begin begin
Windows.SendMessage(Handle, LB_SETSEL, Windows.WParam(true), Windows.LParam(AIndex)); Windows.SendMessage(Handle, LB_SETSEL, Windows.WParam(true), Windows.LParam(AIndex));
Windows.SendMessage(Handle, LB_SETCARETINDEX, Windows.WParam(AIndex), 0);
end; end;
Windows.SendMessage(Handle, LB_SETCARETINDEX, Windows.WParam(AIndex), 0);
end else end else
Windows.SendMessage(Handle, LB_SETCURSEL, Windows.WParam(AIndex), 0); Windows.SendMessage(Handle, LB_SETCURSEL, Windows.WParam(AIndex), 0);
end; end;