LCL: Add ColorRectWidth property to TCustomColorBox. Issue #24761, patch from Michael Fuchs

git-svn-id: trunk@42131 -
This commit is contained in:
juha 2013-07-18 13:04:41 +00:00
parent 4aecd50e0f
commit ccd509acfc

View File

@ -40,6 +40,7 @@ type
TCustomColorBox = class(TCustomComboBox) TCustomColorBox = class(TCustomComboBox)
private private
FColorRectWidth: Integer;
FDefaultColorColor: TColor; FDefaultColorColor: TColor;
FNoneColorColor: TColor; FNoneColorColor: TColor;
FOnGetColors: TGetColorsEvent; FOnGetColors: TGetColorsEvent;
@ -48,6 +49,7 @@ type
function GetColor(Index : Integer): TColor; function GetColor(Index : Integer): TColor;
function GetColorName(Index: Integer): string; function GetColorName(Index: Integer): string;
function GetSelected: TColor; function GetSelected: TColor;
procedure SetColorRectWidth(AValue: Integer);
procedure SetDefaultColorColor(const AValue: TColor); procedure SetDefaultColorColor(const AValue: TColor);
procedure SetNoneColorColor(const AValue: TColor); procedure SetNoneColorColor(const AValue: TColor);
procedure SetSelected(Value: TColor); procedure SetSelected(Value: TColor);
@ -64,7 +66,7 @@ type
function PickCustomColor: Boolean; virtual; function PickCustomColor: Boolean; virtual;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
property ColorRectWidth: Integer read FColorRectWidth write SetColorRectWidth default 14;
property Style: TColorBoxStyle read FStyle write SetStyle property Style: TColorBoxStyle read FStyle write SetStyle
default [cbStandardColors, cbExtendedColors, cbSystemColors]; default [cbStandardColors, cbExtendedColors, cbSystemColors];
property Colors[Index: Integer]: TColor read GetColor; property Colors[Index: Integer]: TColor read GetColor;
@ -79,6 +81,7 @@ type
TColorBox = class(TCustomColorBox) TColorBox = class(TCustomColorBox)
published published
property ColorRectWidth;
property DefaultColorColor; property DefaultColorColor;
property NoneColorColor; property NoneColorColor;
property Selected; property Selected;
@ -353,6 +356,7 @@ begin
inherited Style := csOwnerDrawFixed; inherited Style := csOwnerDrawFixed;
inherited ReadOnly := True; inherited ReadOnly := True;
FColorRectWidth := 14;
FStyle := [cbStandardColors, cbExtendedColors, cbSystemColors]; FStyle := [cbStandardColors, cbExtendedColors, cbSystemColors];
FNoneColorColor := clBlack; FNoneColorColor := clBlack;
FDefaultColorColor := clBlack; FDefaultColorColor := clBlack;
@ -388,6 +392,13 @@ begin
Result := FSelected; Result := FSelected;
end; end;
procedure TCustomColorBox.SetColorRectWidth(AValue: Integer);
begin
if FColorRectWidth = AValue then Exit;
FColorRectWidth := AValue;
Invalidate;
end;
procedure TCustomColorBox.SetDefaultColorColor(const AValue: TColor); procedure TCustomColorBox.SetDefaultColorColor(const AValue: TColor);
begin begin
if FDefaultColorColor <> AValue then if FDefaultColorColor <> AValue then
@ -540,7 +551,7 @@ begin
r.top := Rect.top + 3; r.top := Rect.top + 3;
r.bottom := Rect.bottom - 3; r.bottom := Rect.bottom - 3;
r.left := Rect.left + 3; r.left := Rect.left + 3;
r.right := r.left + 14; r.right := r.left + FColorRectWidth;
Exclude(State, odPainted); Exclude(State, odPainted);
with Canvas do with Canvas do
@ -567,7 +578,7 @@ begin
Pen.Color := PenColor; Pen.Color := PenColor;
end; end;
r := Rect; r := Rect;
r.left := r.left + 20; r.left := r.left + FColorRectWidth + 4;
inherited DrawItem(Index, BidiFlipRect(r, Rect, UseRightToLeftAlignment), State); inherited DrawItem(Index, BidiFlipRect(r, Rect, UseRightToLeftAlignment), State);
end; end;