-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbclistbox.pas
181 lines (148 loc) · 4.11 KB
/
bclistbox.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// SPDX-License-Identifier: LGPL-3.0-linking-exception
{******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | mailedivando@gmail.com
(Compatibility with delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
unit BCListBox;
{$I bgracontrols.inc}
interface
uses
Classes, SysUtils, {$IFDEF FPC}LCLType, LResources, {$ENDIF}
Forms, Controls, Graphics, Dialogs, StdCtrls,
{$IFNDEF FPC}Types, BGRAGraphics, GraphType, FPImage, BCBaseCtrls,{$ENDIF}
BGRAVirtualScreen, BGRABitmap, BGRASliceScaling;
type
TBCListBox = class;
TBCPaperPanel = class;
{ TBCPaperPanel }
TBCPaperPanel = class(TBGRAVirtualScreen)
private
FShadow: TBGRASliceScaling;
procedure LoadShadowFromBitmapResource;
protected
procedure BCRedraw(Sender: TObject; ABitmap: TBGRABitmap);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
published
end;
{ TBCListBox }
TBCListBox = class(TListBox)
private
{ Private declarations }
protected
procedure BCDrawItem(Control: TWinControl; Index: integer;
ARect: TRect; State: TOwnerDrawState);
{ Protected declarations }
public
{ Public declarations }
constructor Create(TheOwner: TComponent); override;
published
{ Published declarations }
end;
{ TBCPaperListBox }
TBCPaperListBox = class(TBCPaperPanel)
private
FListBox: TBCListBox;
public
constructor Create(TheOwner: TComponent); override;
published
property ListBox: TBCListBox read FListBox write FListBox;
end;
{$IFDEF FPC}procedure Register;{$ENDIF}
implementation
{$IFDEF FPC}
uses
PropEdits;
{$ENDIF}
{$IFDEF FPC}
procedure Register;
begin
RegisterComponents('BGRA Controls', [TBCListBox]);
RegisterComponents('BGRA Controls', [TBCPaperPanel]);
RegisterComponents('BGRA Controls', [TBCPaperListBox]);
{$IFDEF FPC}//#
RegisterPropertyEditor(TypeInfo(TBCListBox),
TBCPaperListBox, 'ListBox', TClassPropertyEditor);
{$ENDIF}
end;
{$ENDIF}
{ TBCPaperListBox }
constructor TBCPaperListBox.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Self.ChildSizing.ControlsPerLine := 1;
Self.ChildSizing.LeftRightSPacing := 4;
Self.ChildSizing.TopBottomSpacing := 5;
FListBox := TBCListBox.Create(Self);
FListBox.Align := alClient;
FListBox.Parent := Self;
FListBox.SetSubComponent(true);
end;
{ TBCPaperListBox }
procedure TBCPaperPanel.LoadShadowFromBitmapResource;
{$IFDEF FPC}
var
res: TLazarusResourceStream;
{$ENDIF}
begin
{$IFDEF FPC}
res := TLazarusResourceStream.Create('SHADOW', nil);
FShadow := TBGRASliceScaling.Create(res);
FShadow.Margins := Margins(6, 9, 6, 9);
res.Free;
{$ENDIF}
end;
procedure TBCPaperPanel.BCRedraw(Sender: TObject; ABitmap: TBGRABitmap);
begin
FShadow.Draw(ABitmap, 0, 0, ABitmap.Width, ABitmap.Height);
end;
constructor TBCPaperPanel.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
LoadShadowFromBitmapResource;
Self.OnRedraw := BCRedraw;
end;
destructor TBCPaperPanel.Destroy;
begin
inherited Destroy;
FShadow.Free;
end;
{ TBCListBox }
procedure TBCListBox.BCDrawItem(Control: TWinControl; Index: integer;
ARect: TRect; State: TOwnerDrawState);
var
lb: TListBox;
hg: integer;
begin
{$IFDEF FPC}
lb := TListBox(Control);
lb.Canvas.Clipping := False;
if odFocused in State then
lb.Canvas.Brush.Color := $00e4e4e4
else
lb.Canvas.Brush.Color := clWhite;
if odSelected in State then
lb.Canvas.Font.Style := [fsBold];
lb.Canvas.FillRect(ARect);
hg := lb.Canvas.TextHeight(lb.Items[Index]);
lb.Canvas.Font.Color := clBlack;
lb.Canvas.TextOut(ARect.Left + ScaleX(16, 96), ARect.Top +
(lb.ItemHeight - hg) div 2, lb.Items[Index]);
lb.Canvas.Clipping := True;
lb.Canvas.ClipRect := Rect(0, 0, 0, 0);
{$ENDIF}
end;
constructor TBCListBox.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Self.Style := lbOwnerDrawFixed;
Self.OnDrawItem := BCDrawItem;
{$IFDEF FPC}
Self.ItemHeight := ScaleY(48, 96);
{$ENDIF}
Self.BorderStyle := bsNone;
end;
initialization
{$I bcpaperlistbox.lrs}
end.