source: trunk/Packages/CevoComponents/ListBoxEx.pas

Last change on this file was 573, checked in by chronos, 6 months ago
  • Fixed: White lines visible in scaled TListBoxEx component on mouse move over list items.
File size: 2.1 KB
Line 
1unit ListBoxEx;
2
3interface
4
5uses
6 Classes, SysUtils, LCLType,
7 {$IFDEF DPI}Dpi.Graphics, Dpi.Controls, Dpi.StdCtrls, Dpi.Forms, Dpi.Common, System.UITypes{$ELSE}
8 Graphics, Controls, StdCtrls, Forms{$ENDIF};
9
10type
11
12 { TListBoxEx }
13
14 TListBoxEx = class(TListBox)
15 protected
16 procedure DrawItem(Control: TWinControl; Index: Integer; ARect: TRect;
17 State: TOwnerDrawState); virtual;
18 public
19 constructor Create(TheOwner: TComponent); override;
20 end;
21
22procedure Register;
23
24
25implementation
26
27procedure Register;
28begin
29 RegisterComponents('C-evo', [TListBoxEx]);
30end;
31
32{ TListBoxEx }
33
34procedure TListBoxEx.DrawItem(Control: TWinControl; Index: Integer; ARect: TRect;
35 State: TOwnerDrawState);
36var
37 BackgroundColor: TColor;
38 TextColor: TColor;
39 NewRect: TRect;
40const
41 Orange = $5F77CB;
42 Blue = $d77800;
43begin
44 {$IFDEF UNIX}
45 // Clear blank area under the items
46 if Index = 0 then begin
47 Canvas.Brush.Color := Color;
48 Canvas.Brush.Style := TBrushStyle.bsSolid;
49 Canvas.FillRect(0, 0, Width, Height);
50 end;
51 {$ENDIF}
52
53 if odSelected in State then begin
54 BackgroundColor := Blue;
55 TextColor := clWhite;
56 end else begin
57 BackgroundColor := clBlack;
58 TextColor := Orange;
59 end;
60
61 NewRect := Rect(ARect.Left, ARect.Top, ARect.Right + 1, ARect.Bottom + 1);
62
63 Canvas.Brush.Color := Color;
64 Canvas.Brush.Style := TBrushStyle.bsSolid;
65 Canvas.FillRect(NewRect);
66
67 Canvas.Font.Assign(Font);
68 Canvas.Font.Color := TextColor;
69
70 NewRect := Rect(NewRect.Left + 2, NewRect.Top + 1, NewRect.Right - 2, NewRect.Bottom - 2);
71
72 Canvas.Brush.Color := BackgroundColor;
73 Canvas.Brush.Style := TBrushStyle.bsSolid;
74 Canvas.FillRect(NewRect);
75
76 Canvas.TextRect(NewRect, NewRect.Left + 2, NewRect.Top +
77 (NewRect.Height - Canvas.TextHeight(Items[Index])) div 2,
78 Items[Index], Canvas.TextStyle);
79 if odSelected in State then begin
80 Canvas.Pen.Color := Orange;
81 Canvas.Pen.Style := TPenStyle.psDot;
82 Canvas.Brush.Style := TBrushStyle.bsClear;
83 Canvas.Rectangle(NewRect);
84 end;
85end;
86
87constructor TListBoxEx.Create(TheOwner: TComponent);
88begin
89 inherited;
90 OnDrawItem := DrawItem;
91 Style := TListBoxStyle.lbOwnerDrawVariable;
92end;
93
94end.
95
Note: See TracBrowser for help on using the repository browser.