LCL: Prevent a design-time crash in TCheckComboBox. Issue #33889, patch from Vojtěch Čihák.

git-svn-id: trunk@58375 -
This commit is contained in:
juha 2018-06-22 12:23:45 +00:00
parent 0141dd2967
commit 5c474d5f12
2 changed files with 29 additions and 25 deletions

View File

@ -284,6 +284,8 @@ type
protected
FCheckHighlight: Boolean;
FCheckSize: TSize;
FDropped: Boolean;
FHilightedIndex: Integer;
FHiLiteLeft: Integer;
FHiLiteRight: Integer;
FNeedMeasure: Boolean;
@ -306,6 +308,7 @@ type
procedure MouseLeave; override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure SetItemHeight(const AValue: Integer); override;
procedure SetItems(const Value: TStrings); override;
procedure Select; override;
public
constructor Create(AOwner: TComponent); override;

View File

@ -550,6 +550,7 @@ end;
procedure TCustomCheckCombo.CloseUp;
begin
FDropped:=False;
if FRejectDropDown then
begin
FRejectDropDown:=False;
@ -661,7 +662,10 @@ begin { do not call inherited ! }
Canvas.Brush.Style:=bsClear;
if (not (odSelected in State) or not aDropped) and not aFocusedEditableMainItemNoDD
then Canvas.Font.Color:=clWindowText
else Canvas.Font.Color:=clHighlightText;
else begin
Canvas.Font.Color:=clHighlightText;
FHilightedIndex:=Index;
end;
if aFocusedEditableMainItemNoDD then
begin
LCLIntf.SetBkColor(Canvas.Handle, ColorToRGB(clBtnFace));
@ -697,12 +701,13 @@ begin
aRect:=Rect(FHiLiteLeft, 0, FHiLiteRight, Height);
FRejectDropDown:=PtInRect(aRect, aCursorPos);
{$ENDIF}
FDropped:=True;
if not FRejectDropDown then
begin
inherited DropDown;
FRejectToggleOnSelect:=False;
end else
if ItemEnabled[ItemIndex] then Toggle(ItemIndex);
if (ItemIndex>=0) and ItemEnabled[ItemIndex] then Toggle(ItemIndex);
end;
procedure TCustomCheckCombo.FontChanged(Sender: TObject);
@ -752,30 +757,20 @@ procedure TCustomCheckCombo.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
VK_RETURN:
begin
if not DroppedDown then
begin
DroppedDown:=True;
Key:=0;
end else
begin
if (ItemIndex>=0) and ItemEnabled[ItemIndex] then
begin
Toggle(ItemIndex);
Key:=0;
DroppedDown:=False;
end;
end;
end;
if FDropped then
if (ItemIndex=FHilightedIndex) and ItemEnabled[ItemIndex] then Toggle(ItemIndex);
VK_SPACE:
begin
if DroppedDown then
if (ItemIndex>=0) and ItemEnabled[ItemIndex] then
begin
if ItemIndex<>FHilightedIndex then
begin
Toggle(ItemIndex);
Key:=0;
if DroppedDown then DroppedDown:=False;
ItemIndex:=FHilightedIndex;
inherited Select;
end;
end;
Toggle(ItemIndex);
DroppedDown:=False;
end;
end;
inherited KeyDown(Key, Shift);
end;
@ -796,7 +791,7 @@ procedure TCustomCheckCombo.MouseMove(Shift: TShiftState; X, Y: Integer);
var aHighlight: Boolean;
begin
inherited MouseMove(Shift, X, Y);
aHighlight:= ((X>FHiLiteLeft) and (X<FHiLiteRight));
aHighlight:=((X>FHiLiteLeft) and (X<FHiLiteRight));
if aHighlight<>FCheckHighlight then
begin
FCheckHighlight:=aHighlight;
@ -815,6 +810,7 @@ begin
if ItemEnabled[ItemIndex] then Toggle(ItemIndex);
FRejectToggleOnSelect:=True;
end;
FDropped:=False;
end;
procedure TCustomCheckCombo.SetItemHeight(const AValue: Integer);
@ -823,6 +819,13 @@ begin
FNeedMeasure:=True;
end;
procedure TCustomCheckCombo.SetItems(const Value: TStrings);
begin
ClearItemStates;
inherited SetItems(Value);
InitItemStates;
end;
procedure TCustomCheckCombo.Toggle(AIndex: Integer);
const caNewStateMap: array [TCheckBoxState, Boolean] of TCheckBoxState =
{ False (AllowGrayed) True }
@ -901,5 +904,3 @@ begin
end;