blob: 2ce499dac1a37735af62e96e555f0a9395f7c058 (
plain)
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
|
unit gfx_popupwindow;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
gfxbase,
fpgfx,
gfx_widget,
gfx_impl;
type
TfpgPopupWindow = class(TfpgWidget)
private
FDontCloseWidget: TfpgWidget;
protected
procedure MsgClose(var msg: TfpgMessageRec); message FPGM_CLOSE;
procedure AdjustWindowStyle; override;
procedure HandleShow; override;
procedure HandleHide; override;
procedure HandleClose; virtual;
public
constructor Create(AOwner: TComponent); override;
procedure ShowAt(AWidget: TfpgWidget; x, y: TfpgCoord);
procedure Close; virtual;
property DontCloseWidget: TfpgWidget read FDontCloseWidget write FDontCloseWidget;
end;
procedure ClosePopups;
function PopupListFirst: TfpgPopupWindow;
function PopupListFind(AWinHandle: TfpgWinHandle): TfpgPopupWindow;
function PopupDontCloseWidget(AWidget: TfpgWidget): boolean;
implementation
type
// Popup window linked list. Maybe we can implemnt it via a TList as well.
PPopupListRec = ^PopupListRec;
PopupListRec = record
Widget: TfpgPopupWindow;
Next: PPopupListRec;
end;
var
uOriginalFocusRoot: TfpgWidget;
uFirstPopup: PPopupListRec;
uLastPopup: PPopupListRec;
// local helper functions
procedure ClosePopups;
begin
while uFirstPopup <> nil do
begin
TfpgPopupWindow(uFirstPopup^.Widget).Close;
end;
end;
procedure PopupListAdd(pw: TfpgPopupWindow);
var
p: PPopupListRec;
begin
if pw = nil then
Exit; //==>
if uFirstPopup = nil then
uOriginalFocusRoot := FocusRootWidget;
FocusRootWidget := pw;
New(p);
p^.Widget := pw;
p^.Next := nil;
if uFirstPopup = nil then
uFirstPopup := p
else
uLastPopup^.Next := p;
uLastPopup := p;
end;
procedure PopupListRemove(pw: TfpgPopupWindow);
var
prevp: PPopupListRec;
p: PPopupListRec;
px: PPopupListRec;
begin
p := uFirstPopup;
prevp := nil;
while p <> nil do
begin
if p^.Widget = pw then
begin
if prevp = nil then
uFirstPopup := p^.Next
else
prevp^.Next := p^.Next;
if uLastPopup = p then
uLastPopup := prevp;
px := p;
p := p^.Next;
Dispose(px);
end
else
begin
prevp := p;
p := p^.Next;
end;
end;
if uLastPopup <> nil then
FocusRootWidget := uLastPopup^.Widget
else
FocusRootWidget := uOriginalFocusRoot;
end;
function PopupListFirst: TfpgPopupWindow;
begin
if uFirstPopup <> nil then
Result := uFirstPopup^.Widget
else
Result := nil;
end;
function PopupListFind(AWinHandle: TfpgWinHandle): TfpgPopupWindow;
var
p: PPopupListRec;
begin
p := uFirstPopup;
while p <> nil do
begin
if p^.Widget.WinHandle = AWinHandle then
begin
Result := p^.Widget;
Exit; //==>
end;
p := p^.Next;
end;
Result := nil;
end;
function PopupDontCloseWidget(AWidget: TfpgWidget): boolean;
var
p: PPopupListRec;
begin
Result := False;
if AWidget = nil then
Exit; //==>
p := uFirstPopup;
while p <> nil do
begin
if p^.Widget.DontCloseWidget = AWidget then
begin
Result := True;
Exit; //==>
end;
p := p^.Next;
end;
end;
{ TfpgPopupWindow }
procedure TfpgPopupWindow.MsgClose(var msg: TfpgMessageRec);
begin
HandleClose;
end;
procedure TfpgPopupWindow.AdjustWindowStyle;
begin
inherited AdjustWindowStyle;
// We could possibly change this later
Exclude(FWindowAttributes, waSizeable);
end;
procedure TfpgPopupWindow.HandleShow;
begin
inherited HandleShow;
CaptureMouse;
end;
procedure TfpgPopupWindow.HandleHide;
begin
ReleaseMouse;
inherited HandleHide;
end;
procedure TfpgPopupWindow.HandleClose;
begin
HandleHide;
end;
constructor TfpgPopupWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
WindowType := wtPopup;
FDontCloseWidget := nil;
Parent := nil;
end;
procedure TfpgPopupWindow.ShowAt(AWidget: TfpgWidget; x, y: TfpgCoord);
var
pt: TPoint;
begin
PopupListAdd(self);
DontCloseWidget := nil;
// translate coordinates
pt := WindowToScreen(AWidget, Point(x, y));
// reposition
Left := pt.X;
Top := pt.Y;
// and show
HandleShow;
end;
procedure TfpgPopupWindow.Close;
begin
HandleHide;
PopupListRemove(self);
end;
initialization
uFirstPopup := nil;
uLastPopup := nil;
end.
|