-
Notifications
You must be signed in to change notification settings - Fork 7
/
KOLMHTooltip_implem.inc
437 lines (372 loc) · 8.95 KB
/
KOLMHTooltip_implem.inc
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
// part of KOLMHToolTip -- interface_part.
// Moved to separate inc-file still Delphi20XX does not allow compile
// in DEBUG mode.
const
Dummy1 = 1;
TTDT_AUTOMATIC = 0;
TTDT_RESHOW = 1;
TTDT_AUTOPOP = 2;
TTDT_INITIAL = 3;
function NewMHToolTip(AParent: PControl): PMHToolTip;
const
CS_DROPSHADOW = $00020000;
begin
DoInitCommonControls(ICC_BAR_CLASSES);
New(Result, Create);
Result.fHandle := CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, '', 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, AParent.GetWindowHandle, 0, HInstance, nil);
end;
function TMHToolTip.GetDelay(const Index: Integer): Integer;
begin
Result := SendMessage(fHandle, TTM_GETDELAYTIME, Index, 0);
end;
procedure TMHToolTip.SetDelay(const Index, Value: Integer);
begin
SendMessage(handle, TTM_SETDELAYTIME, Index, MAKELONG(Value, 0));
end;
function TMHToolTip.GetColor(const Index: Integer): TColor;
begin
Result := SendMessage(handle, TTM_GETTIPBKCOLOR + Index, 0, 0);
end;
procedure TMHToolTip.SetColor(const Index: Integer; const Value: TColor);
begin
SendMessage(handle, TTM_SETTIPBKCOLOR + Index, Value, 0);
end;
function TMHToolTip.GetMaxWidth: Integer;
begin
Result := SendMessage(fHandle, TTM_GETMAXTIPWIDTH, 0, 0);
end;
procedure TMHToolTip.SetMaxWidth(const Value: Integer);
begin
SendMessage(fHandle, TTM_SETMAXTIPWIDTH, 0, Value);
end;
function TMHToolTip.GetMargin: TRect;
begin
SendMessage(fHandle, TTM_GETMARGIN, 0, DWord(@Result));
end;
procedure TMHToolTip.SetMargin(const Value: TRect);
begin
SendMessage(fHandle, TTM_SETMARGIN, 0, DWord(@Value));
end;
function TMHToolTip.GetActivate: Boolean;
begin
// ??????
Result := False;
end;
procedure TMHToolTip.SetActivate(const Value: Boolean);
begin
SendMessage(fHandle, TTM_ACTIVATE, DWord(Value), 0);
end;
procedure TMHToolTip.Pop;
begin
SendMessage(fHandle, TTM_POP, 0, 0);
end;
procedure TMHToolTip.Popup;
begin
SendMessage(fHandle, $0422 {TTM_POPUP}, 0, 0);
end;
procedure TMHToolTip.Update;
begin
inherited; // ???
SendMessage(fHandle, TTM_UPDATE, 0, 0);
end;
function NewHint(A: PControl): PMHHint;
begin
New(Result, Create);
with Result^ do
begin
Parent := A;
ToolTip := nil; // ???
HasTool := False; // ???
end;
A.Add2AutoFree(Result);
end;
function NewManager: PMHToolTipManager;
begin
New(Result, Create);
end;
{ TMHHint }
function TMHHint.GetDelay(const Index: Integer): Integer;
begin
// CreateToolTip;
Result := 0;
if Assigned(ToolTip) then
Result := ToolTip.GetDelay(Index);
end;
function TMHHint.GetFI: TFI;
begin
/// !!! DANGER-WITH !!!
with Result, ToolTip^ do
begin
FE := FE + [eTextColor];
Colors[1] := TextColor;
FE := FE + [eBkColor];
Colors[0] := BkColor;
FE := FE + [eAPDelay];
Delays[TTDT_AUTOPOP] := AutoPopDelay;
FE := FE + [eRDelay];
Delays[TTDT_RESHOW] := ReshowDelay;
FE := FE + [eIDelay];
Delays[TTDT_INITIAL] := InitialDelay;
end;
end;
procedure TMHHint.ReConnect(FI: TFI);
var
TMP: PMHToolTip;
begin
with GetManager^ do
begin
TMP := FindNeed(FI);
if not Assigned(TMP) then
TMP := CreateNeed(FI);
if Assigned(ToolTip) and HasTool then
MoveTool(TMP);
ToolTip := TMP;
end;
end;
procedure TMHHint.MoveTool(T1: PMHToolTip);
var
TI: TToolInfo;
TextL: array[0..255] of KOLChar;
begin
if T1 = ToolTip then
Exit;
with TI do
begin
cbSize := SizeOf(TI);
hWnd := Parent.GetWindowHandle;
uId := Parent.GetWindowHandle;
lpszText := @TextL[0];
end;
SendMessage(ToolTip.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
SendMessage(ToolTip.handle, TTM_DELTOOL, 0, DWORD(@TI));
ToolTip.Count := ToolTip.Count - 1;
SendMessage(T1.handle, TTM_ADDTOOL, 0, DWORD(@TI));
T1.Count := T1.Count - 1;
HasTool := True;
end;
procedure TMHHint.SetColor(const Index: Integer; const Value: TColor);
var
FI: TFI;
begin
if Assigned(ToolTip) then
begin
if ToolTip.Count + Byte(not HasTool) = 1 then
begin
ToolTip.SetColor(Index, Value);
Exit;
end;
FI := GetFI;
end;
case Index of
0: FI.FE := FI.FE + [eBkColor];
1: FI.FE := FI.FE + [eTextColor];
end;
FI.Colors[Index] := Value;
ReConnect(FI);
end;
function TMHHint.GetColor(const Index: Integer): TColor;
begin
Result := 0;
if Assigned(ToolTip) then
Result := ToolTip.GetColor(Index);
end;
procedure TMHHint.SetDelay(const Index, Value: Integer);
var
FI: TFI;
begin
if Assigned(ToolTip) then
begin
if ToolTip.Count + Byte(not HasTool) = 1 then
begin
ToolTip.SetDelay(Index, Value);
Exit;
end;
FI := GetFI;
end;
case Index of
TTDT_AUTOPOP: FI.FE := FI.FE + [eAPDelay]; // Spec
TTDT_INITIAL: FI.FE := FI.FE + [eIDelay]; // Spec
TTDT_RESHOW: FI.FE := FI.FE + [eRDelay]; // Spec
end; //case
FI.Delays[Index] := Value; //Spec
ReConnect(FI);
end;
procedure TMHHint.SetText(Value: KOLString);
var
TI: TToolInfo;
begin
ProcBegin(TI);
with TI do
begin
uFlags := TTF_SUBCLASS or TTF_IDISHWND; // Spec
lpszText := PKOLChar(Value); // Spec
end;
procEnd(TI);
if HasTool then
begin
TI.lpszText := PKOLChar(Value);
SendMessage(ToolTip.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
end;
end;
{ TMHToolTipManager }
function TMHToolTipManager.AddTip: Integer;
begin
SetLength(TTT, Length(TTT) + 1);
TTT[Length(TTT) - 1] := NewMHToolTip(Applet);
Result := Length(TTT) - 1;
end;
function TMHToolTipManager.FindNeed(FI: TFI): PMHToolTip;
var
i: Integer;
begin
Result := nil;
for i := 0 to length(TTT) - 1 do
begin
if ((eTextColor in FI.FE) and (not (FI.Colors[1] = TTT[i].TextColor))) or
((eBkColor in FI.FE) and (not (FI.Colors[0] = TTT[i].BkColor))) or
((eAPDelay in FI.FE) and (not (FI.Delays[TTDT_AUTOPOP] = TTT[i].AutoPopDelay))) or
((eIDelay in FI.FE) and (not (FI.Delays[TTDT_INITIAL] = TTT[i].InitialDelay))) or
((eRDelay in FI.FE) and (not (FI.Delays[TTDT_RESHOW] = TTT[i].ReshowDelay))) then
Continue;
Result := TTT[i];
Break;
end;
end;
function TMHToolTipManager.CreateNeed(FI: TFI): PMHToolTip;
begin
Setlength(TTT, length(TTT) + 1);
TTT[length(TTT) - 1] := NewMHToolTip(Applet);
with TTT[length(TTT) - 1]^ do
begin
if (eTextColor in FI.FE) then
TextColor := FI.Colors[1];
if (eBkColor in FI.FE) then
BkColor := FI.Colors[0];
if (eAPDelay in FI.FE) then
AutoPopDelay := FI.Delays[TTDT_AUTOPOP];
if (eIDelay in FI.FE) then
InitialDelay := FI.Delays[TTDT_INITIAL];
if (eRDelay in FI.FE) then
ReshowDelay := FI.Delays[TTDT_RESHOW];
end;
Result := TTT[length(TTT) - 1];
end;
procedure TMHHint.ProcBegin(var TI: TToolInfo);
begin
CreateToolTip;
with TI do
begin
cbSize := SizeOf(TI);
hWnd := Parent.GetWindowHandle;
uId := Parent.GetWindowHandle;
hInst := 0;
end;
end;
procedure TMHHint.ProcEnd(var TI: TToolInfo);
var
TextLine: array[0..255] of KOLChar;
begin
if not HasTool then
begin
SendMessage(ToolTip.handle, TTM_ADDTOOL, 0, DWORD(@TI));
HasTool := True;
ToolTip.Count := ToolTip.Count + 1;
end
else
begin
with TI do
begin
lpszText := @TextLine[0];
end;
SendMessage(ToolTip.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
end;
end;
destructor TMHToolTipManager.Destroy;
var
i: Integer;
begin
for i := 0 to Length(TTT) - 1 do
TTT[i].Free;
SetLength(TTT, 0);
inherited;
end;
procedure TMHHint.Pop;
begin
if Assigned(ToolTip) and (HasTool) then
begin // ^^^^^^^^^^^^ ???
// CreateToolTip;
ToolTip.Pop;
end;
end;
procedure TMHHint.Popup;
begin
if Assigned(ToolTip) and (HasTool) then
begin // ^^^^^^^^^^^^ ???
// CreateToolTip;
ToolTip.Popup;
end;
end;
destructor TMHHint.Destroy;
var
TI: TToolInfo;
i: integer;
begin
with TI do
begin
cbSize := SizeOf(TI);
hWnd := Parent.GetWindowHandle;
uId := Parent.GetWindowHandle;
end;
SendMessage(ToolTip.handle, TTM_DELTOOL, 0, DWORD(@TI));
ToolTip.Count := ToolTip.Count - 1;
if ToolTip.Count <= 0 then begin
i:=Length(Manager.TTT);
if i > 1 then begin
Manager.TTT[i - 1].Free;
SetLength(Manager.TTT, i - 1);
end
else
Free_And_Nil(Manager);
end;
inherited;
end;
destructor TMHToolTip.Destroy;
begin
inherited;
end;
procedure TMHHint.CreateToolTip;
begin
if not Assigned(ToolTip) then
begin
if Length(GetManager.TTT) = 0 then
GetManager.AddTip;
ToolTip := GetManager.TTT[0];
end;
end;
function TMHHint.GetText: KOLString;
var
TI: TToolInfo;
TextL: array[0..255] of KOLChar;
begin
if Assigned(ToolTip) and (HasTool) then
begin
// !!!
with TI do
begin
// ????
// FillChar(TI, SizeOf(TI), 0);
cbSize := SizeOf(TI);
hWnd := Parent.GetWindowHandle;
uId := Parent.GetWindowHandle;
lpszText := @TextL[0];
end;
SendMessage(ToolTip.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
Result := TextL; //TI.lpszText;// := PChar(Value);
end;
end;
function TMHHint.GetManager: PMHToolTipManager;
begin
if Manager=nil then
Manager:=NewManager;
Result:=Manager;
end;