Переглянути джерело

Add VCL Styles support to TNewCheckListBox items. Todo: checkmarks.

Martijn Laan 2 місяців тому
батько
коміт
54b85543b5
1 змінених файлів з 30 додано та 7 видалено
  1. 30 7
      Components/NewCheckListBox.pas

+ 30 - 7
Components/NewCheckListBox.pas

@@ -205,7 +205,7 @@ procedure Register;
 implementation
 
 uses
-  NewUxTheme.TmSchema, PathFunc, ActiveX, BidiUtils, Types;
+  Themes, NewUxTheme.TmSchema, PathFunc, ActiveX, BidiUtils, Types;
 
 const
   sRadioCantHaveDisabledChildren = 'Radio item cannot have disabled child items';
@@ -720,6 +720,8 @@ const
     (CBS_CHECKEDNORMAL, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDDISABLED),
     (CBS_MIXEDNORMAL, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDDISABLED)
   );
+  FontColorStates: array[Boolean] of TStyleFont = (sfListItemTextDisabled, sfListItemTextNormal);
+  CheckListItemStates: array[Boolean] of TThemedCheckListBox = (tclListItemDisabled, tclListItemNormal);
 var
   SavedClientRect: TRect;
 
@@ -773,18 +775,39 @@ begin
   ItemState := ItemStates[Index];
   UIState := SendMessage(Handle, WM_QUERYUISTATE, 0, 0);
   Disabled := not Enabled or not ItemState.Enabled;
+
+  { Style code below is based on Vcl.StdCtrls' TCustomListBox.CNDrawItem and Vcl.CheckList's
+    TCustomCheckListBox.DrawItem  }
+  var LStyle := StyleServices(Self);
+  if not LStyle.Enabled or LStyle.IsSystemStyle then
+    LStyle := nil;
+
   with Canvas do begin
     if not FWantTabs and (odSelected in State) and Focused then begin
-      Brush.Color := clHighlight;
       NewTextColor := clHighlightText;
-    end
-    else begin
-      Brush.Color := Self.Color;
+      if (LStyle <> nil) and (seClient in StyleElements) then begin
+        Brush.Color := LStyle.GetSystemColor(clHighlight);
+        if seFont in StyleElements then
+          NewTextColor := LStyle.GetStyleFontColor(sfListItemTextSelected);
+      end else
+        Brush.Color := clHighlight;
+    end else begin
       if Disabled then
         NewTextColor := clGrayText
       else
         NewTextColor := Self.Font.Color;
-    end;
+      if (LStyle <> nil) and (seClient in StyleElements) then begin
+        Brush.Color := LStyle.GetStyleColor(scListBox);
+        if seFont in StyleElements then begin
+          NewTextColor := LStyle.GetStyleFontColor(FontColorStates[not Disabled]);
+          const Details = LStyle.GetElementDetails(CheckListItemStates[Enabled]);
+          var LColor: TColor;
+          if LStyle.GetElementColor(Details, ecTextColor, LColor) and (LColor <> clNone) then
+            NewTextColor := LColor;
+        end;
+      end else
+        Brush.Color := Self.Color;
+   end;
     { Draw threads }
     if FShowLines then begin
       Pen.Color := clGrayText;
@@ -897,7 +920,7 @@ begin
       lines are drawn -- and we mustn't draw too many. }
     InternalDrawText(Items[Index], Rect, DrawTextFormat or DT_CALCRECT, False);
     FlipRect(Rect, SavedClientRect, FUseRightToLeft);
-    InternalDrawText(Items[Index], Rect, DrawTextFormat, FWantTabs and Disabled);
+    InternalDrawText(Items[Index], Rect, DrawTextFormat, FWantTabs and Disabled and (LStyle = nil));
     { Draw focus rectangle }
     if FWantTabs and not Disabled and (odSelected in State) and Focused and
       (UIState and UISF_HIDEFOCUS = 0) then