| 1 | unit ListBoxEx;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 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 |
|
|---|
| 10 | type
|
|---|
| 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 |
|
|---|
| 22 | procedure Register;
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | implementation
|
|---|
| 26 |
|
|---|
| 27 | procedure Register;
|
|---|
| 28 | begin
|
|---|
| 29 | RegisterComponents('C-evo', [TListBoxEx]);
|
|---|
| 30 | end;
|
|---|
| 31 |
|
|---|
| 32 | { TListBoxEx }
|
|---|
| 33 |
|
|---|
| 34 | procedure TListBoxEx.DrawItem(Control: TWinControl; Index: Integer; ARect: TRect;
|
|---|
| 35 | State: TOwnerDrawState);
|
|---|
| 36 | var
|
|---|
| 37 | BackgroundColor: TColor;
|
|---|
| 38 | TextColor: TColor;
|
|---|
| 39 | NewRect: TRect;
|
|---|
| 40 | const
|
|---|
| 41 | Orange = $5F77CB;
|
|---|
| 42 | Blue = $d77800;
|
|---|
| 43 | begin
|
|---|
| 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;
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | constructor TListBoxEx.Create(TheOwner: TComponent);
|
|---|
| 88 | begin
|
|---|
| 89 | inherited;
|
|---|
| 90 | OnDrawItem := DrawItem;
|
|---|
| 91 | Style := TListBoxStyle.lbOwnerDrawVariable;
|
|---|
| 92 | end;
|
|---|
| 93 |
|
|---|
| 94 | end.
|
|---|
| 95 |
|
|---|