forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdsCustomControls.pas
More file actions
303 lines (290 loc) · 8 KB
/
dsCustomControls.pas
File metadata and controls
303 lines (290 loc) · 8 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
unit dsCustomControls;
{$S-,W-,R+,H+,X+}
interface
uses
VCL.Dialogs,
WinAPI.Windows, Forms, Messages, System.Classes, VCL.Controls, VCL.Graphics;
type
TPenSetEvent = procedure(Sender:TObject; Value:TPen; var Co: boolean) of object;
TBrushSetEvent = procedure(Sender:TObject; Value:TBrush; var Co: boolean) of object;
TFontSetEvent = procedure(Sender:TObject; Value:TFont; var Co: boolean) of object;
THitTestEvent = procedure(Sender:TObject; var HitResult:integer) of object;
THackedWinControl = class(TWinControl)
public
procedure PaintControls(DC: HDC; First: TControl);
end;
TGraphControl = class( TCustomTransparentControl )
private
FFocused: boolean;
FCreateNotFired: boolean;
foc, fod, fop, fpc, fbc, ffc, fOnFocus, fOnBlur: TNotifyEvent;
fps: TPenSetEvent;
fbs: TBrushSetEvent;
ffs: TFontSetEvent;
fontps: THitTestEvent;
function FBrush: TBrush;
function FFont: TFont;
function FPen: TPen;
protected
procedure SetBrush(ABrush:TBrush);
procedure SetFont(AFont:TFont);
procedure SetPen(APen:TPen);
procedure ChangeBrush(Sender:TObject);
procedure ChangeFont(Sender:TObject);
procedure ChangePen(Sender:TObject);
procedure SetOnCreate(A:TNotifyEvent);
procedure Paint; override;
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure setFocused(a:boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Anchors;
property Align;
property Canvas;
procedure UnFocus;
property Focused: boolean read FFocused write setFocused;
procedure Repaint; override;
procedure Invalidate; override;
procedure Refresh; reintroduce;
property Brush: TBrush read FBrush write SetBrush;
property Pen: TPen read FPen write SetPen;
property Font: TFont read FFont write SetFont;
property OnBrushChange: TNotifyEvent read fbc write fbc;
property OnBrushSet: TBrushSetEvent read fbs write fbs;
property OnFontChange:TNotifyEvent read ffc write ffc;
property OnFontSet:TFontSetEvent read ffs write ffs;
property OnPenChange: TNotifyEvent read fpc write fpc;
property OnPenSet: TPenSetEvent read fps write fps;
property OnPaint: TNotifyEvent read fop write fop;
property OnHitTest: THitTestEvent read fontps write fontps;
property OnCreate: TNotifyEvent read foc write SetOnCreate;
property OnDestroy: TNotifyEvent read fod write fod;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Constraints;
property ShowHint;
property ParentShowHint;
property Touch;
property Visible;
property AutoSize;
property OnCanResize;
property OnConstrainedResize;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
{OnClick, OnDblClick, OnMouseActivate,
OnMouseEnter ,OnMouseLeave, OnMouseMove,
OnMouseDown, OnMouseUp, OnMouseWheel,
OnGesture, OnDragOver,OnDragDrop,
OnStartDrag, OnStartDock, OnEndDock,
OnEndDrag, OnFocus, OnBlur}
property OnClick;
property OnDblClick;
property OnKeyPress;
property OnKeyUp;
property OnKeyDown;
property OnMouseActivate;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnGesture;
property OnContextPopup;
property OnStartDock;
property OnStartDrag;
property onFocus:TNotifyEvent read FOnFocus write FOnFocus;
property onBlur:TNotifyEvent read FOnBlur write FOnBlur;
end;
implementation
procedure THackedWinControl.PaintControls(DC: HDC; First: TControl);
begin
inherited PaintControls(DC, First);
end;
procedure TGraphControl.Repaint;
begin
Invalidate;
Update;
end;
procedure TGraphControl.Invalidate;
var DC: HDC;
begin
if (Visible or (csDesigning in ComponentState) and
not (csNoDesignVisible in ControlStyle)) and (Parent <> nil) and
Parent.HandleAllocated then
begin
DC := GetDC(Parent.Handle);
try
IntersectClipRect(DC, Left, Top, Left + Width, Top + Height);
THackedWinControl(Parent).PaintControls(DC, Self);
finally
ReleaseDC(Parent.Handle, DC);
end;
end;
end;
procedure TGraphControl.Refresh;
begin
Repaint;
end;
procedure TGraphControl.setFocused(a: Boolean);
begin
if FFocused = a then Exit;
if a then
SetFocus
else
UnFocus;
end;
procedure TGraphControl.UnFocus;
var
Parent: TCustomForm;
begin
Parent := GetParentForm(Self);
if Parent <> nil then
begin
FFocused := False;
Parent.DeFocusControl(Self,False);
end
else
ValidParentForm(Self);
end;
constructor TGraphControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FFocused := False;
Canvas.Brush.Assign(inherited Brush);
(inherited Brush).OnChange := ChangeBrush;
Canvas.Brush.OnChange := ChangeBrush;
(inherited Font).OnChange := ChangeFont;
Canvas.Font.OnChange := ChangeFont;
Canvas.Font.Assign(inherited Font);
Canvas.Pen.OnChange := ChangePen;
ControlStyle := ControlStyle + [csReplicatable];
ParentDoubleBuffered := False;
DoubleBuffered := False;
FCreateNotFired := True;
end;
procedure TGraphControl.WMNCHitTest(var Message: TWMNCHitTest);
var hResult: integer;
begin
hResult := HTCLIENT;
if ((csDesigning in ComponentState) and (Parent <> nil)) or (not Assigned(fontps)) then
Message.Result := HTCLIENT
else
begin
fontps(Self as TObject, hresult);
Message.Result := hresult;
end;
end;
function TGraphControl.FBrush: TBrush;
begin
Result := inherited Brush;
end;
function TGraphControl.FFont: TFont;
begin
Result := inherited Font;
end;
function TGraphControl.FPen: TPen;
begin
Result := Canvas.Pen;
end;
procedure TGraphControl.SetBrush(ABrush:TBrush);
var conti: boolean;
begin
conti := true;
if Assigned(fbs)then
fbs(Self as TObject, ABrush, conti);
if conti and (inherited Brush <> ABrush) then
Begin
(inherited Brush).Assign(ABrush);
Canvas.Brush.Assign(ABrush);
End;
end;
procedure TGraphControl.SetFont(AFont:TFont);
var conti: boolean;
begin
conti := true;
if Assigned(ffs)then
ffs(Self as TObject, AFont, conti);
if conti and (inherited Font <> AFont) then
Begin
(inherited Font).Assign(AFont);
Canvas.Font.Assign(AFont);
End;
end;
procedure TGraphControl.SetPen(APen:TPen);
var conti: boolean;
begin
conti := true;
if Assigned(fps)then
fps(Self as TObject, APen, conti);
if conti and (Canvas.Pen <> APen) then
Canvas.Pen.Assign(APen);
end;
procedure TGraphControl.ChangeBrush(Sender:TObject);
begin
if TBrush(Sender) = Canvas.Brush then
(inherited Brush).Assign(TBrush(Sender))
else
Canvas.Brush.Assign(TBrush(Sender));
if Assigned(fbc) then
fbc(Self as TObject);
end;
procedure TGraphControl.ChangeFont(Sender:TObject);
begin
if TFont(Sender) = Canvas.Font then
(inherited Font).Assign(TFont(Sender))
else
Canvas.Font.Assign(TFont(Sender));
if Assigned(ffc) then
ffc(Self as TObject);
end;
procedure TGraphControl.ChangePen(Sender:TObject);
begin
if Assigned(fpc) then
fpc(Self as TObject);
end;
procedure TGraphControl.SetOnCreate(A:TNotifyEvent);
begin
foc := A;
if FCreateNotFired then
begin
foc(Self as TObject);
FCreateNotFired := False;
end;
end;
procedure TGraphControl.WMSetFocus(var Message: TWMSetFocus);
begin
FFocused := True;
if Assigned(fOnFocus) then
fOnFocus(Self as TObject);
inherited;
end;
procedure TGraphControl.WMKillFocus(var Message: TWMKillFocus);
begin
FFocused := False;
if Assigned(fOnBlur) then
fOnBlur(Self as TObject);
inherited;
end;
procedure TGraphControl.Paint;
begin
if Assigned(fop) then
fop(Self as TObject);
end;
destructor TGraphControl.Destroy;
begin
if Assigned(fod) then
fod(Self as TObject);
inherited Destroy;
end;
end.