mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-28 22:33:41 +02:00
LCL/CheckListbox: Add new properties HeaderBackgroundColor and HeaderColor and implement them for win32 WS. Issue #39874, patch by Don Siders.
This commit is contained in:
parent
2199a763c6
commit
cf2aa0649b
lcl
@ -36,6 +36,8 @@ type
|
|||||||
TCustomCheckListBox = class(TCustomListBox)
|
TCustomCheckListBox = class(TCustomListBox)
|
||||||
private
|
private
|
||||||
FAllowGrayed: Boolean;
|
FAllowGrayed: Boolean;
|
||||||
|
FHeaderBackgroundColor: TColor;
|
||||||
|
FHeaderColor: TColor;
|
||||||
FItemDataOffset: Integer;
|
FItemDataOffset: Integer;
|
||||||
FOnClickCheck : TNotifyEvent;
|
FOnClickCheck : TNotifyEvent;
|
||||||
FOnItemClick: TCheckListClicked;
|
FOnItemClick: TCheckListClicked;
|
||||||
@ -49,6 +51,8 @@ type
|
|||||||
procedure SendItemHeader(const AIndex: Integer; const AHeader: Boolean);
|
procedure SendItemHeader(const AIndex: Integer; const AHeader: Boolean);
|
||||||
procedure DoChange(var Msg: TLMessage); message LM_CHANGED;
|
procedure DoChange(var Msg: TLMessage); message LM_CHANGED;
|
||||||
procedure SetHeader(AIndex: Integer; const AValue: Boolean);
|
procedure SetHeader(AIndex: Integer; const AValue: Boolean);
|
||||||
|
procedure SetHeaderBackgroundColor(AValue: TColor);
|
||||||
|
procedure SetHeaderColor(AValue: TColor);
|
||||||
procedure SetItemEnabled(AIndex: Integer; const AValue: Boolean);
|
procedure SetItemEnabled(AIndex: Integer; const AValue: Boolean);
|
||||||
procedure SetState(AIndex: Integer; const AValue: TCheckBoxState);
|
procedure SetState(AIndex: Integer; const AValue: TCheckBoxState);
|
||||||
protected
|
protected
|
||||||
@ -75,6 +79,8 @@ type
|
|||||||
property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False;
|
property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False;
|
||||||
property Checked[AIndex: Integer]: Boolean read GetChecked write SetChecked;
|
property Checked[AIndex: Integer]: Boolean read GetChecked write SetChecked;
|
||||||
property Header[AIndex: Integer]: Boolean read GetHeader write SetHeader;
|
property Header[AIndex: Integer]: Boolean read GetHeader write SetHeader;
|
||||||
|
property HeaderBackgroundColor: TColor read FHeaderBackgroundColor write SetHeaderBackgroundColor default clInfoBk;
|
||||||
|
property HeaderColor: TColor read FHeaderColor write SetHeaderColor default clInfoText;
|
||||||
property ItemEnabled[AIndex: Integer]: Boolean read GetItemEnabled write SetItemEnabled;
|
property ItemEnabled[AIndex: Integer]: Boolean read GetItemEnabled write SetItemEnabled;
|
||||||
property State[AIndex: Integer]: TCheckBoxState read GetState write SetState;
|
property State[AIndex: Integer]: TCheckBoxState read GetState write SetState;
|
||||||
property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck;
|
property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck;
|
||||||
@ -100,6 +106,8 @@ type
|
|||||||
property ExtendedSelect;
|
property ExtendedSelect;
|
||||||
property Enabled;
|
property Enabled;
|
||||||
property Font;
|
property Font;
|
||||||
|
property HeaderBackgroundColor;
|
||||||
|
property HeaderColor;
|
||||||
property IntegralHeight;
|
property IntegralHeight;
|
||||||
property Items;
|
property Items;
|
||||||
property ItemHeight;
|
property ItemHeight;
|
||||||
@ -208,6 +216,8 @@ begin
|
|||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FCompStyle := csCheckListBox;
|
FCompStyle := csCheckListBox;
|
||||||
FItemDataOffset := inherited GetCachedDataSize;
|
FItemDataOffset := inherited GetCachedDataSize;
|
||||||
|
FHeaderBackgroundColor := clInfoBk;
|
||||||
|
FHeaderColor := clInfoText;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomCheckListBox.CalculateStandardItemHeight: Integer;
|
function TCustomCheckListBox.CalculateStandardItemHeight: Integer;
|
||||||
@ -367,6 +377,20 @@ begin
|
|||||||
PCachedItemData(GetCachedData(AIndex) + FItemDataOffset)^.Header := AValue;
|
PCachedItemData(GetCachedData(AIndex) + FItemDataOffset)^.Header := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomCheckListBox.SetHeaderBackgroundColor(AValue: TColor);
|
||||||
|
begin
|
||||||
|
if FHeaderBackgroundColor = AValue then Exit;
|
||||||
|
FHeaderBackgroundColor := AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomCheckListBox.SetHeaderColor(AValue: TColor);
|
||||||
|
begin
|
||||||
|
if FHeaderColor = AValue then Exit;
|
||||||
|
FHeaderColor := AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TCustomCheckListBox.WSRegisterClass;
|
class procedure TCustomCheckListBox.WSRegisterClass;
|
||||||
begin
|
begin
|
||||||
inherited WSRegisterClass;
|
inherited WSRegisterClass;
|
||||||
|
@ -192,15 +192,25 @@ class procedure TWin32WSCustomCheckListBox.DefaultWndHandler(
|
|||||||
OldBkMode: Integer;
|
OldBkMode: Integer;
|
||||||
sz: TSize;
|
sz: TSize;
|
||||||
WideBuffer: widestring;
|
WideBuffer: widestring;
|
||||||
|
HdrBg, HdrTxt: TColor;
|
||||||
|
BgBrush: Windows.HBRUSH;
|
||||||
begin
|
begin
|
||||||
Selected := (Data^.itemState and ODS_SELECTED) > 0;
|
Selected := (Data^.itemState and ODS_SELECTED) > 0;
|
||||||
Enabled := CheckListBox.Enabled and CheckListBox.ItemEnabled[Data^.itemID];
|
Enabled := CheckListBox.Enabled and CheckListBox.ItemEnabled[Data^.itemID];
|
||||||
Header := CheckListBox.Header[Data^.itemID];
|
Header := CheckListBox.Header[Data^.itemID];
|
||||||
|
|
||||||
|
if Header then
|
||||||
|
begin
|
||||||
|
HdrBg := CheckListBox.HeaderBackgroundColor;
|
||||||
|
if HdrBg = clDefault then HdrBg := clInfoBk;
|
||||||
|
HdrTxt := CheckListBox.HeaderColor;
|
||||||
|
if HdrTxt = clDefault then HdrTxt := clInfoText;
|
||||||
|
end;
|
||||||
|
|
||||||
ARect := Data^.rcItem;
|
ARect := Data^.rcItem;
|
||||||
TextRect := ARect;
|
TextRect := ARect;
|
||||||
|
|
||||||
// adjust text rectangle for check box items
|
// adjust text rectangle for check box and padding
|
||||||
if not Header then
|
if not Header then
|
||||||
begin
|
begin
|
||||||
if CheckListBox.UseRightToLeftAlignment then
|
if CheckListBox.UseRightToLeftAlignment then
|
||||||
@ -209,9 +219,13 @@ class procedure TWin32WSCustomCheckListBox.DefaultWndHandler(
|
|||||||
TextRect.Left := TextRect.Left + TextRect.Bottom - TextRect.Top + 4;
|
TextRect.Left := TextRect.Left + TextRect.Bottom - TextRect.Top + 4;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// fill the background
|
||||||
if Header then
|
if Header then
|
||||||
// TODO: use TCheckListBox.HeaderBackground when implemented
|
begin
|
||||||
Windows.FillRect(Data^._HDC, ARect, GetSysColorBrush(SysColorToSysColorIndex(clInfoBk)))
|
BgBrush := Windows.CreateSolidBrush(ColorToRGB(HdrBg));
|
||||||
|
Windows.FillRect(Data^._HDC, ARect, BgBrush);
|
||||||
|
Windows.DeleteObject(BgBrush);
|
||||||
|
end
|
||||||
else if Selected then
|
else if Selected then
|
||||||
begin
|
begin
|
||||||
Windows.FillRect(Data^._HDC, Rect(ARect.Left, ARect.Top, TextRect.Left, ARect.Bottom), CheckListBox.Brush.Reference.Handle);
|
Windows.FillRect(Data^._HDC, Rect(ARect.Left, ARect.Top, TextRect.Left, ARect.Bottom), CheckListBox.Brush.Reference.Handle);
|
||||||
@ -249,13 +263,11 @@ class procedure TWin32WSCustomCheckListBox.DefaultWndHandler(
|
|||||||
TextFlags := DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX;
|
TextFlags := DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX;
|
||||||
end;
|
end;
|
||||||
OldBkMode := Windows.SetBkMode(Data^._HDC, TRANSPARENT);
|
OldBkMode := Windows.SetBkMode(Data^._HDC, TRANSPARENT);
|
||||||
if Header then
|
if not Enabled then
|
||||||
// TODO: use TCheckListBox.HeaderColor when implemented
|
|
||||||
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(SysColorToSysColorIndex(clInfoText)))
|
|
||||||
else if not Enabled then
|
|
||||||
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_GRAYTEXT))
|
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_GRAYTEXT))
|
||||||
else
|
else if Header then
|
||||||
if Selected then
|
OldColor := Windows.SetTextColor(Data^._HDC, ColorToRGB(HdrTxt))
|
||||||
|
else if Selected then
|
||||||
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_HIGHLIGHTTEXT))
|
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_HIGHLIGHTTEXT))
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user