-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Controls.PanelExt.pas
520 lines (484 loc) · 13.3 KB
/
HGM.Controls.PanelExt.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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
unit HGM.Controls.PanelExt;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.Types,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, HGM.Common;
type
TCustomPanelExt = class(TCustomPanel)
private
FOnPanel: Boolean;
FDefaultPaint: Boolean;
FOnMouseDown: TMouseEvent;
FOnMouseMove: TMouseMoveEvent;
FOnMouseUp: TMouseEvent;
FMouseCoord: TPoint;
FMouseState: TShiftState;
FRepaintOnMouseMove: Boolean;
procedure SetDefaultPaint(const Value: Boolean);
procedure SetRepaintOnMouseMove(const Value: Boolean);
public
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
FOnPaint: TNotifyEvent;
procedure FMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure CMMouseEnter(var message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var message: TMessage); message CM_MOUSELEAVE;
procedure CMMouseWheel(var Message: TCMMouseWheel); message WM_MOUSEWHEEL;
procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
procedure Paint; override;
property Canvas;
constructor Create(AOwner: TComponent); override;
property OnPanel: Boolean read FOnPanel;
property MouseCoord: TPoint read FMouseCoord;
property MouseState: TShiftState read FMouseState;
property RepaintOnMouseMove: Boolean read FRepaintOnMouseMove write SetRepaintOnMouseMove;
property DefaultPaint: Boolean read FDefaultPaint write SetDefaultPaint;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
end;
TPanelExt = class(TCustomPanelExt)
published
property Caption;
property DefaultPaint;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnPaint;
property RepaintOnMouseMove default False;
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property Padding;
property ParentBiDiMode;
property ParentBackground;
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowCaption;
property ShowHint;
property TabOrder;
property TabStop;
property Touch;
property VerticalAlignment;
property Visible;
property StyleElements;
property OnAlignInsertBefore;
property OnAlignPosition;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnGetSiteInfo;
property OnMouseActivate;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
end;
TDrawPanel = class(TCustomPanelExt)
public
FOnPaint: TNotifyEvent;
procedure Paint; override;
constructor Create(AOwner: TComponent); override;
published
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
property RepaintOnMouseMove default True;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnPanel;
property DefaultPaint;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property Padding;
property ParentBiDiMode;
property ParentBackground;
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowCaption;
property ShowHint;
property TabOrder;
property TabStop;
property Touch;
property VerticalAlignment;
property Visible;
property StyleElements;
property OnAlignInsertBefore;
property OnAlignPosition;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnGetSiteInfo;
property OnMouseActivate;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
TDragPanel = class(TCustomPanel)
private
FOnMouseDown: TMouseEvent;
procedure FMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); overload;
procedure SetOnMouseDown(const Value: TMouseEvent);
public
procedure DoDrag;
property DockManager;
constructor Create(AOwner: TComponent); override;
published
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Caption;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property Padding;
property ParentBiDiMode;
property ParentBackground;
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowCaption;
property ShowHint;
property TabOrder;
property TabStop;
property Touch;
property VerticalAlignment;
property Visible;
property StyleElements;
property OnAlignInsertBefore;
property OnAlignPosition;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnGetSiteInfo;
property OnMouseActivate;
property OnMouseDown: TMouseEvent read FOnMouseDown write SetOnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
TDecoratePanel = class
private
FAnimate: Boolean;
FOwner: TControl;
FPanel: TPanel;
FOpening: Boolean;
FCancelClose: Boolean;
public
constructor Create(AOwner: TControl; APanel: TPanel; AOpen: Boolean = False);
procedure Close;
procedure CloseDelay(Interval: Integer; FProc: TProc = nil);
procedure Open(Animate: Boolean = True);
procedure UpdateSize;
property Animate: Boolean read FAnimate write FAnimate default True;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents(PackageName, [TPanelExt]);
RegisterComponents(PackageName, [TDrawPanel]);
RegisterComponents(PackageName, [TDragPanel]);
end;
constructor TDrawPanel.Create(AOwner: TComponent);
begin
inherited;
ParentBackground := False;
RepaintOnMouseMove := True;
end;
procedure TDrawPanel.Paint;
begin
if Visible then
if Assigned(FOnPaint) then
FOnPaint(Self);
end;
procedure TCustomPanelExt.Paint;
begin
if Brush.Bitmap <> nil then
Canvas.Draw(0, 0, Brush.Bitmap);
if Assigned(FOnPaint) then
FOnPaint(Self);
end;
procedure TCustomPanelExt.SetDefaultPaint(const Value: Boolean);
begin
FDefaultPaint := Value;
if not (csLoading in ComponentState) then
Paint;
end;
procedure TCustomPanelExt.SetRepaintOnMouseMove(const Value: Boolean);
begin
FRepaintOnMouseMove := Value;
end;
procedure TCustomPanelExt.WMNCPaint(var Message: TMessage);
begin
if FDefaultPaint then
inherited;
if Assigned(FOnPaint) then
FOnPaint(Self);
end;
procedure TCustomPanelExt.CMMouseEnter(var message: TMessage);
begin
FOnPanel := True;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TCustomPanelExt.CMMouseLeave(var message: TMessage);
begin
FOnPanel := False;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
procedure TCustomPanelExt.CMMouseWheel(var Message: TCMMouseWheel);
begin
with Message do
begin
Result := 0;
if DoMouseWheel(ShiftState, WheelDelta, SmallPointToPoint(Pos)) then
Message.Result := 1
else if Parent <> nil then
with TMessage(Message) do
Result := Parent.Perform(CM_MOUSEWHEEL, WParam, LParam);
end;
end;
constructor TCustomPanelExt.Create(AOwner: TComponent);
begin
inherited;
FDefaultPaint := False;
inherited OnMouseMove := FMouseMove;
inherited OnMouseDown := FMouseDown;
inherited OnMouseUp := FMouseUp;
end;
procedure TCustomPanelExt.FMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FMouseState := Shift;
if Assigned(FOnMouseDown) then
FOnMouseDown(Sender, Button, Shift, X, Y);
end;
procedure TCustomPanelExt.FMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
FMouseState := Shift;
FMouseCoord := Point(X, Y);
if Assigned(FOnMouseMove) then
FOnMouseMove(Sender, Shift, X, Y);
if FRepaintOnMouseMove then
Repaint;
end;
procedure TCustomPanelExt.FMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FMouseState := Shift;
if Assigned(FOnMouseUp) then
FOnMouseUp(Sender, Button, Shift, X, Y);
end;
{ TDragPanel }
constructor TDragPanel.Create(AOwner: TComponent);
begin
inherited;
inherited OnMouseDown := FMouseDown;
end;
procedure TDragPanel.DoDrag;
begin
ReleaseCapture;
SendMessage(Self.Parent.Handle, WM_SYSCOMMAND, 61458, 0);
end;
procedure TDragPanel.FMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DoDrag;
if Assigned(FOnMouseDown) then
FOnMouseDown(Sender, Button, Shift, X, Y);
end;
procedure TDragPanel.SetOnMouseDown(const Value: TMouseEvent);
begin
FOnMouseDown := Value;
end;
{ TDecoratePanel }
procedure TDecoratePanel.Close;
var
i: Integer;
begin
for i := 0 to FOwner.ClientHeight div 30 do
begin
FPanel.Top := i * 30;
FOwner.Repaint;
end;
FPanel.Hide;
FOwner.Repaint;
end;
procedure TDecoratePanel.CloseDelay;
begin
TThread.CreateAnonymousThread(
procedure
begin
Sleep(Interval);
if FCancelClose then
TThread.Synchronize(TThread.Current,
procedure
begin
Close;
if Assigned(FProc) then
FProc;
end);
end).Start;
end;
constructor TDecoratePanel.Create(AOwner: TControl; APanel: TPanel; AOpen: Boolean);
begin
FCancelClose := False;
FOwner := AOwner;
FPanel := APanel;
FOpening := False;
FPanel.Left := 0;
FPanel.Top := 0;
FPanel.Hide;
if AOpen then
Open(False);
end;
procedure TDecoratePanel.Open(Animate: Boolean);
begin
UpdateSize;
FCancelClose := True;
FOpening := True;
FPanel.Show;
FPanel.BringToFront;
FPanel.Left := 0;
FPanel.Top := 0;
FOpening := False;
end;
procedure TDecoratePanel.UpdateSize;
begin
if Assigned(FOwner) and Assigned(FPanel) then
begin
FPanel.Width := FOwner.ClientWidth;
FPanel.Height := FOwner.ClientHeight;
end;
end;
end.