mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 18:00:26 +02:00
TCheckListbox: improve drawing under win32 (disabled state and do all through ThemeServices), saving/loading grayed states
TCheckListBoxEditor: handle grayed states git-svn-id: trunk@13365 -
This commit is contained in:
parent
9f7365c4d8
commit
b9556171fe
@ -68,13 +68,14 @@ var
|
||||
i: integer;
|
||||
begin
|
||||
dstCheck.Items.Clear;
|
||||
dstCheck.Items:=srcCheck.Items;
|
||||
dstCheck.ItemHeight:=srcCheck.ItemHeight;
|
||||
for i := 0 to srcCheck.Items.Count-1 do
|
||||
dstCheck.AllowGrayed := srcCheck.AllowGrayed;
|
||||
dstCheck.Items := srcCheck.Items;
|
||||
dstCheck.ItemHeight := srcCheck.ItemHeight;
|
||||
for i := 0 to srcCheck.Items.Count - 1 do
|
||||
begin
|
||||
if srcCheck.Items[i]<>dstCheck.Items[i] then
|
||||
if srcCheck.Items[i] <> dstCheck.Items[i] then
|
||||
dstCheck.Items[i] := srcCheck.Items[i];
|
||||
dstCheck.Checked[i]:=srcCheck.Checked[i]
|
||||
dstCheck.State[i] := srcCheck.State[i]
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -275,19 +275,14 @@ var
|
||||
ChecksCount: integer;
|
||||
Checks: string;
|
||||
i: Integer;
|
||||
v: Integer;
|
||||
begin
|
||||
ChecksCount := ReadLRSInteger(Stream);
|
||||
if ChecksCount > 0 then
|
||||
begin
|
||||
SetLength(Checks, ChecksCount);
|
||||
Stream.ReadBuffer(Checks[1], ChecksCount);
|
||||
for i:=0 to ChecksCount-1 do
|
||||
begin
|
||||
v := ord(Checks[i+1]);
|
||||
Checked[i] := ((v and 1) > 0);
|
||||
//debugln('TCustomCheckListBox.ReadData Checked[',dbgs(i),']=',dbgs(Checked[i]),' v=',dbgs(v));
|
||||
end;
|
||||
for i := 0 to ChecksCount-1 do
|
||||
State[i] := TCheckBoxState(ord(Checks[i + 1]));
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -296,20 +291,14 @@ var
|
||||
ChecksCount: integer;
|
||||
Checks: string;
|
||||
i: Integer;
|
||||
v: Integer;
|
||||
begin
|
||||
ChecksCount:=Items.Count;
|
||||
ChecksCount := Items.Count;
|
||||
WriteLRSInteger(Stream, ChecksCount);
|
||||
if ChecksCount>0 then
|
||||
if ChecksCount > 0 then
|
||||
begin
|
||||
SetLength(Checks, ChecksCount);
|
||||
for i:=0 to ChecksCount-1 do
|
||||
begin
|
||||
v := 0;
|
||||
if Checked[i] then inc(v, 1);
|
||||
//debugln('TCustomCheckListBox.WriteData Checked[',dbgs(i),']=',dbgs(Checked[i]));
|
||||
Checks[i+1] := chr(v);
|
||||
end;
|
||||
for i := 0 to ChecksCount - 1 do
|
||||
Checks[i+1] := chr(Ord(State[i]));
|
||||
Stream.WriteBuffer(Checks[1], ChecksCount);
|
||||
end;
|
||||
end;
|
||||
|
@ -198,12 +198,18 @@ var
|
||||
end;
|
||||
|
||||
procedure DrawCheckListBoxItem(CheckListBox: TCheckListBox; Data: PDrawItemStruct);
|
||||
const
|
||||
ThemeStateMap: array[TCheckBoxState, Boolean] of TThemedButton =
|
||||
(
|
||||
{cbUnchecked} (tbCheckBoxUncheckedDisabled, tbCheckBoxUncheckedNormal),
|
||||
{cbChecked } (tbCheckBoxCheckedDisabled, tbCheckBoxCheckedNormal),
|
||||
{cbGrayed } (tbCheckBoxMixedDisabled, tbCheckBoxMixedNormal)
|
||||
);
|
||||
var
|
||||
Selected: Boolean;
|
||||
Enabled, Selected: Boolean;
|
||||
lgBrush: LOGBRUSH;
|
||||
Brush: HBRUSH;
|
||||
Rect: Windows.Rect;
|
||||
Flags: Cardinal;
|
||||
Details: TThemedElementDetails;
|
||||
OldColor: COLORREF;
|
||||
OldBackColor: COLORREF;
|
||||
@ -213,9 +219,10 @@ var
|
||||
{$endif}
|
||||
begin
|
||||
Selected := (Data^.itemState AND ODS_SELECTED)>0;
|
||||
Enabled := CheckListBox.Enabled;
|
||||
|
||||
// fill the background
|
||||
if Selected then
|
||||
if Enabled and Selected then
|
||||
lgBrush.lbColor := Windows.GetSysColor(COLOR_HIGHLIGHT)
|
||||
else
|
||||
lgBrush.lbColor := Windows.GetSysColor(COLOR_WINDOW);
|
||||
@ -229,30 +236,19 @@ var
|
||||
InflateRect(Rect, -1, -1);
|
||||
Rect.Right := Rect.Left + Rect.Bottom - Rect.Top;
|
||||
|
||||
if ThemeServices.ThemesEnabled then
|
||||
begin
|
||||
case CheckListBox.State[Data^.ItemID] of
|
||||
cbUnchecked: Details := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal);
|
||||
cbChecked: Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
|
||||
cbGrayed: Details := ThemeServices.GetElementDetails(tbCheckBoxMixedNormal);
|
||||
end;
|
||||
ThemeServices.DrawElement(Data^._HDC, Details, Rect);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Flags := DFCS_BUTTONCHECK;
|
||||
case CheckListBox.State[Data^.ItemID] of
|
||||
cbChecked: Flags := Flags or DFCS_CHECKED;
|
||||
cbGrayed: Flags := Flags or DFCS_INACTIVE;
|
||||
end;
|
||||
Windows.DrawFrameControl(Data^._HDC, Rect, DFC_BUTTON, Flags);
|
||||
end;
|
||||
// draw all through ThemeServices. ThemeServices can decide itself hot to perform actual draw
|
||||
Details := ThemeServices.GetElementDetails(ThemeStateMap[CheckListBox.State[Data^.ItemID], Enabled]);
|
||||
ThemeServices.DrawElement(Data^._HDC, Details, Rect);
|
||||
|
||||
// draw text
|
||||
Rect := Windows.Rect(Data^.rcItem);
|
||||
Rect.Right := Data^.rcItem.Right;
|
||||
Rect.Left := Rect.Bottom-Rect.Top + 5;
|
||||
if Selected then begin
|
||||
if not Enabled then
|
||||
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_GRAYTEXT))
|
||||
else
|
||||
if Selected then
|
||||
begin
|
||||
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_HIGHLIGHTTEXT));
|
||||
OldBackColor := Windows.SetBkColor(Data^._HDC, Windows.GetSysColor(COLOR_HIGHLIGHT));
|
||||
end;
|
||||
@ -273,7 +269,11 @@ var
|
||||
Windows.DrawText(Data^._HDC, PChar(CheckListBox.Items[Data^.ItemID]), -1,
|
||||
Rect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
|
||||
{$endif}
|
||||
if Selected then begin
|
||||
if not Enabled then
|
||||
Windows.SetTextColor(Data^._HDC, OldColor)
|
||||
else
|
||||
if Selected then
|
||||
begin
|
||||
Windows.SetTextColor(Data^._HDC, OldColor);
|
||||
Windows.SetBkColor(Data^._HDC, OldBackColor);
|
||||
end;
|
||||
|
@ -1846,7 +1846,11 @@ begin
|
||||
begin
|
||||
case Details.Part of
|
||||
BP_RADIOBUTTON: ADrawFlags := DFCS_BUTTONRADIO;
|
||||
BP_CHECKBOX: ADrawFlags := DFCS_BUTTONCHECK;
|
||||
BP_CHECKBOX:
|
||||
if IsMixed(Details) then
|
||||
ADrawFlags := DFCS_BUTTON3STATE
|
||||
else
|
||||
ADrawFlags := DFCS_BUTTONCHECK;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1856,7 +1860,7 @@ begin
|
||||
ADrawFlags := ADrawFlags or DFCS_PUSHED else
|
||||
if IsHot(Details) then
|
||||
ADrawFlags := ADrawFlags or DFCS_HOT;
|
||||
if IsChecked(Details) then
|
||||
if IsChecked(Details) or IsMixed(Details) then
|
||||
ADrawFlags := ADrawFlags or DFCS_CHECKED;
|
||||
|
||||
WidgetSet.DrawFrameControl(DC, ARect, DFC_BUTTON, ADrawFlags);
|
||||
|
Loading…
Reference in New Issue
Block a user