-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathamScript.Host.AlertWindow.pas
More file actions
128 lines (108 loc) · 3.14 KB
/
amScript.Host.AlertWindow.pas
File metadata and controls
128 lines (108 loc) · 3.14 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
unit amScript.Host.AlertWindow;
(*
* Copyright © 2012 Anders Melander
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*)
interface
uses
Classes,
dxAlertWindow,
amScript.Host.API;
type
TScriptAlertWindow = class(TInterfacedObject, IScriptHostAlertWindow)
private
FAlertWindow: TdxAlertWindow;
FEventSink: IScriptHostAlertEventSink;
FData: pointer;
protected
// IScriptHostAlertWindow
procedure SetEventSink(const EventSink: IScriptHostAlertEventSink; Data: pointer);
procedure Close;
function GetData: pointer;
public
constructor Create(AAlertWindow: TdxAlertWindow);
destructor Destroy; override;
procedure AlertClicked;
procedure AlertClosed;
class function AddAlertMessage(AlertWindowManager: TdxAlertWindowManager; const ACaption, AMessage: string; AImageIndex, ATimeout: integer): IScriptHostAlertWindow;
end;
implementation
class function TScriptAlertWindow.AddAlertMessage(AlertWindowManager: TdxAlertWindowManager; const ACaption, AMessage: string; AImageIndex, ATimeout: integer): IScriptHostAlertWindow;
var
AlertWindow: TdxAlertWindow;
Intf: IUnknown;
begin
while (AlertWindowManager.Count > 0) do
AlertWindowManager.Close(AlertWindowManager.Items[0]);
AlertWindow := AlertWindowManager.Show(ACaption, AMessage, AImageIndex);
if (ATimeout > 0) then
AlertWindow.OptionsBehavior.DisplayTime := ATimeout;
// Create reference counted wrapper for event dispatch to an IScriptHostAlertEventSink interface
Result := TScriptAlertWindow.Create(AlertWindow);
// Save interface reference in Tag
Intf := Result;
AlertWindow.Tag := NativeInt(Intf);
pointer(Intf) := nil;
end;
procedure TScriptAlertWindow.AlertClicked;
begin
// Notify event sink that alert was clicked
if (FEventSink <> nil) then
FEventSink.AlertClicked(Self);
end;
procedure TScriptAlertWindow.AlertClosed;
var
Intf: IUnknown;
begin
// Notify event sink that alert was closed
if (FEventSink <> nil) then
FEventSink.AlertClosed(Self);
// Disconnect us from alert window
if (FAlertWindow <> nil) then
begin
// Clear interface reference in Tag
pointer(Intf) := pointer(FAlertWindow.Tag);
FAlertWindow.Tag := 0;
// This should destroy us
Intf := nil;
end;
end;
procedure TScriptAlertWindow.Close;
begin
// Close alert window
if (FAlertWindow <> nil) then
begin
FAlertWindow.Close;
FAlertWindow := nil;
FEventSink := nil;
end;
end;
constructor TScriptAlertWindow.Create(AAlertWindow: TdxAlertWindow);
begin
inherited Create;
FAlertWindow := AAlertWindow;
end;
destructor TScriptAlertWindow.Destroy;
begin
FEventSink := nil;
if (FAlertWindow <> nil) then
begin
FAlertWindow.Tag := 0;
FAlertWindow := nil;
end;
inherited;
end;
function TScriptAlertWindow.GetData: pointer;
begin
Result := FData;
end;
procedure TScriptAlertWindow.SetEventSink(const EventSink: IScriptHostAlertEventSink; Data: pointer);
begin
// Connect event sink
FEventSink := EventSink;
FData := Data;
end;
end.