-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMaxLogic.BalloonDefaultImageList.pas
More file actions
112 lines (92 loc) · 2.51 KB
/
Copy pathMaxLogic.BalloonDefaultImageList.pas
File metadata and controls
112 lines (92 loc) · 2.51 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
unit MaxLogic.BalloonDefaultImageList;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.ImageList, Vcl.ImgList;
type
TImageListForBalloonForm = class(TForm)
ImageList1: TImageList;
private
class var fInstance: TImageListForBalloonForm;
private
fOrgOnFormChange: TNotifyEvent;
procedure init;
procedure myOnFormChange(sender: Tobject);
procedure processForm(f: TForm);
public
destructor Destroy; override;
class function Instance: TImageListForBalloonForm; static;
public const
imgInfo = 0; // never change
imgWarning = 1;
end;
// just a marker to be added to the forms that we did already processed, this will help us to not check all the components each time again and again
TIsAdjustedMarker = class(Tcomponent)
end;
implementation
{$R *.dfm}
{ TImageListForBalloonForm }
destructor TImageListForBalloonForm.Destroy;
begin
try
if assigned(screen) then
screen.OnActiveFormChange := fOrgOnFormChange;
except
// do nothing
end;
inherited;
end;
procedure TImageListForBalloonForm.init;
begin
fOrgOnFormChange := screen.OnActiveFormChange;
screen.OnActiveFormChange := myOnFormChange;
if screen.ActiveForm <> nil then
processForm(screen.ActiveForm);
end;
class function TImageListForBalloonForm.Instance: TImageListForBalloonForm;
begin
if fInstance = nil then
begin
fInstance := TImageListForBalloonForm.create(application);
fInstance.init;
end;
result := fInstance;
end;
procedure TImageListForBalloonForm.myOnFormChange(sender: Tobject);
begin
try
if sender <> nil then
if sender is TForm then
processForm(sender as TForm);
finally
if assigned(fOrgOnFormChange) then
fOrgOnFormChange(sender);
end;
end;
procedure TImageListForBalloonForm.processForm(f: TForm);
var
x: Integer;
c: Tcomponent;
b: TBalloonHint;
begin
// find balloon hints or the marker
for x := f.ComponentCount - 1 to 0 do
begin
c := f.Components[x];
if c is TIsAdjustedMarker then
exit; // we have been here already
if c is TBalloonHint then
begin
b := c as TBalloonHint;
if b.Images = nil then
begin
b.Images := self.ImageList1;
b.ImageIndex := 0;
end;
end;
end;
// set the marker so we do not scan this form again
// Note: it will be destroyed with the form, so there is no need to hold a reference to it
TIsAdjustedMarker.create(f);
end;
end.