lcl: fix TColorBox bug introduced in #0014552

git-svn-id: trunk@21639 -
This commit is contained in:
paul 2009-09-09 22:52:48 +00:00
parent 382a314889
commit 49fffeed25

View File

@ -59,6 +59,7 @@ type
procedure SetSelected(Value: TColor); procedure SetSelected(Value: TColor);
procedure SetStyle(const AValue: TColorBoxStyle); reintroduce; procedure SetStyle(const AValue: TColorBoxStyle); reintroduce;
procedure ColorProc(const s: AnsiString); procedure ColorProc(const s: AnsiString);
procedure UpdateCombo;
protected protected
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override; procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
procedure SetColorList; procedure SetColorList;
@ -428,35 +429,12 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomColorBox.SetSelected(Value: TColor); procedure TCustomColorBox.SetSelected(Value: TColor);
var
c: integer;
begin begin
if Selected = Value then if Selected = Value then
Exit; Exit;
if HandleAllocated then FSelected := Value;
begin UpdateCombo;
FSelected := Value;
for c := Ord(cbCustomColor in Style) to Items.Count - 1 do
begin
if Colors[c] = Value then
begin
ItemIndex := c;
inherited Change;
Exit;
end;
end;
if cbCustomColor in Style then
begin
Items.Objects[0] := TObject(PtrInt(Value));
ItemIndex := 0;
invalidate;
end
else
ItemIndex := -1;
end
else
FSelected := Value;
inherited Change; inherited Change;
end; end;
@ -507,6 +485,31 @@ begin
end; end;
end; end;
procedure TCustomColorBox.UpdateCombo;
var
c: integer;
begin
if HandleAllocated then
begin
for c := Ord(cbCustomColor in Style) to Items.Count - 1 do
begin
if Colors[c] = FSelected then
begin
ItemIndex := c;
Exit;
end;
end;
if cbCustomColor in Style then
begin
Items.Objects[0] := TObject(PtrInt(FSelected));
ItemIndex := 0;
Invalidate;
end
else
ItemIndex := -1;
end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCustomColorBox.DrawItem Method: TCustomColorBox.DrawItem
Params: Index, Rect, State Params: Index, Rect, State
@ -599,7 +602,7 @@ end;
procedure TCustomColorBox.InitializeWnd; procedure TCustomColorBox.InitializeWnd;
begin begin
inherited InitializeWnd; inherited InitializeWnd;
Selected := FSelected; UpdateCombo;
end; end;
procedure TCustomColorBox.DoGetColors; procedure TCustomColorBox.DoGetColors;