-
Notifications
You must be signed in to change notification settings - Fork 8
/
TUPopupMenu.pas
132 lines (114 loc) · 3.37 KB
/
TUPopupMenu.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
unit TUPopupMenu;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UCL.Form, UCL.ThemeManager,
Vcl.Menus, Vcl.StdCtrls, UCL.ScrollBox, Vcl.ExtCtrls, UCL.ListButton, UCL.Colors;
type
TPopupMode = (pmStandard, pmCustom);
TPopupMenu = class (Vcl.Menus.TPopupMenu)
private
FPopupForm: TUForm;
FPopupMode: TPopupMode;
FPopupCount: Integer;
FMonitor: TMonitor;
public
constructor Create(AOwner: TComponent); override;
procedure Popup(X,Y: Integer); override;
property PopupForm: TUForm read FPopupForm write FPopupForm;
property PopupMode: TPopupMode read FPopupMode write FPopupMode;
property PopupCount: Integer read FPopupCount write FPopupCount;
end;
type
// TMenuItem = class(Vcl.Menus.TMenuItem)
// end;
TPopupForm = class(TUForm)
UScrollBox1: TUScrollBox;
private
{ Private declarations }
FPopupForm: TUForm;
FPopupMenu: TPopupMenu;
FPopupCount: Integer;
procedure WMActivate(var AMessage: TWMActivate); message WM_ACTIVATE;
public
{ Public declarations }
constructor Create(AOwner: TComponent; APopupForm: TUForm;
APopupMenu: TPopupMenu; APopupCount: Integer); reintroduce;
end;
var
PopupForm: TPopupForm;
implementation
{$R *.dfm}
{ TPopupMenu }
constructor TPopupMenu.Create(AOwner: TComponent);
begin
Inherited;
FPopupMode := pmStandard;
FPopupCount := 5;
end;
procedure TPopupMenu.Popup(X, Y: Integer);
var
I: Integer;
AForm: TPopupForm;
AItem: TUListButton;
begin
case FPopupMode of
pmCustom:
begin
AForm := TPopupForm.Create(nil, FPopupForm, Self, FPopupCount);
with AForm do
begin
FMonitor := Screen.MonitorFromWindow(GetParentHandle);
Top := Y;
Left := X;
Width := 180;
Height := 200;
if FMonitor.Top > Top then
Top := FMonitor.Top;
if FMonitor.Left > Left then
Left := FMonitor.Left;
if FMonitor.BoundsRect.Bottom < (Top+Height) then
Top := FMonitor.BoundsRect.Bottom - Height;
if FMonitor.BoundsRect.Right < (Left+Width) then
Left := FMonitor.BoundsRect.Right - Width;
BorderIcons := [];
DoubleBuffered := True;
FormStyle := fsStayOnTop;
BorderStyle := bsDialog;
ThemeManager.ThemeType := ttDark;
Show;
for I := Items.Count - 1 downto 0 do
begin
AItem := TUListButton.Create(nil);
with AItem do
begin
Align := alTop;
Detail := '';
ImageIndex := I;
FontIcon := '';
Caption := Items[I].Caption;
Parent := AForm.UScrollBox1;
end;
end;
end;
end;
pmStandard: inherited;
end;
end;
{ TPopupForm }
constructor TPopupForm.Create(AOwner: TComponent; APopupForm: TUForm;
APopupMenu: TPopupMenu; APopupCount: Integer);
begin
inherited Create(AOwner);
FPopupForm := APopupForm;
FPopupMenu := APopupMenu;
FPopupCount := APopupCount;
end;
procedure TPopupForm.WMActivate(var AMessage: TWMActivate);
begin
SendMessage(FPopupForm.Handle, WM_NCACTIVATE, 1, 0);
Inherited;
if AMessage.Active = WA_INACTIVE then
Release;
end;
end.