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
|
unit iac_chain;
interface
implementation
uses
windows, messages, commctrl,
global, iac_global, mirutils, m_api, inouttext,
dlgshare,lowlevelc,common,dbsettings, wrapper;
{$include i_cnst_chain.inc}
{$resource iac_chain.res}
const
ACF_BYNAME = $00000001; // Address action link by name, not Id
ACF_NOWAIT = $00000002; // Don't wait execution result, continue
ACF_KEEPOLD = $00000004; // Don't change LastResult value
ACF_SAMETHREAD = $00000008; // Execute in same thread with waiting
const
ioNoWait = 'nowait';
ioKeepOld = 'keepold';
ioSameThread = 'samethread';
const
opt_chain = 'chain';
opt_actname = 'actname';
const
NoChainText:PWideChar = 'not defined';
type
tChainAction = class(tBaseAction)
private
id :dword;
actname:pWideChar;
public
constructor Create(uid:dword);
destructor Destroy; override;
function DoAction(var WorkData:tWorkData):LRESULT; override;
procedure Save(node:pointer;fmt:integer); override;
procedure Load(node:pointer;fmt:integer); override;
end;
//----- Support functions -----
//----- Object realization -----
constructor tChainAction.Create(uid:dword);
begin
inherited Create(uid);
id :=0;
actname:=nil;
end;
destructor tChainAction.Destroy;
begin
if (flags and ACF_BYNAME)<>0 then
mFreeMem(actname);
inherited Destroy;
end;
function tChainAction.DoAction(var WorkData:tWorkData):LRESULT;
var
params:tAct_Param;
res:int_ptr;
begin
result:=0;
if (flags and ACF_BYNAME)<>0 then
begin
params.flags:=ACTP_BYNAME;
params.Id :=uint_ptr(actname);
end
else
begin
params.flags:=0;
params.Id :=id;
end;
if (flags and ACF_SAMETHREAD)<>0 then
params.flags:=params.flags or ACTP_SAMETHREAD
else if (flags and ACF_NOWAIT)=0 then
params.flags:=params.flags or ACTP_WAIT;
if (flags and ACF_KEEPOLD)=0 then
params.flags:=params.flags or ACTP_KEEPRESULT;
params.wParam:=WorkData.Parameter;
params.lParam:=WorkData.LastResult;
res:=CallService(MS_ACT_RUNPARAMS,0,tlparam(@params));
if (flags and ACF_KEEPOLD)=0 then
begin
ClearResult(WorkData);
if (flags and ACF_SAMETHREAD)=0 then
begin
WorkData.LastResult:=res;
WorkData.ResultType:=rtInt;
end
else
begin
WorkData.LastResult:=params.lParam;
WorkData.ResultType:=params.lPType;
end;
end;
end;
procedure tChainAction.Load(node:pointer;fmt:integer);
var
section: array [0..127] of AnsiChar;
pc:pAnsiChar;
begin
inherited Load(node,fmt);
case fmt of
0: begin
pc:=StrCopyE(section,pAnsiChar(node));
if (flags and ACF_BYNAME)=0 then
begin
StrCopy(pc,opt_chain); id:=DBReadDWord(0,DBBranch,section);
end
else
begin
StrCopy(pc,opt_actname); actname:=DBReadUnicode(0,DBBranch,section);
end;
end;
100: begin
flags:=flags and not ACF_BYNAME;
pc:=StrCopyE(section,pAnsiChar(node));
StrCopy(pc,'text'); id:=DBReadDWord(0,DBBranch,section);
end;
end;
end;
procedure tChainAction.Save(node:pointer;fmt:integer);
var
section: array [0..127] of AnsiChar;
pc:pAnsiChar;
begin
inherited Save(node,fmt);
case fmt of
0: begin
pc:=StrCopyE(section,pAnsiChar(node));
if (flags and ACF_BYNAME)=0 then
begin
StrCopy(pc,opt_chain); DBWriteDWord(0,DBBranch,section,id);
end
else
begin
StrCopy(pc,opt_actname); DBWriteUnicode(0,DBBranch,section,actname);
end;
end;
13: begin
tTextExport(node).AddTextW('actionname',actname);
tTextExport(node).AddFlag('samethread',(flags or ACF_SAMETHREAD)<>0);
tTextExport(node).AddFlag('nowait' ,(flags or ACF_NOWAIT )<>0);
tTextExport(node).AddFlag('keepold' ,(flags or ACF_KEEPOLD )<>0);
tTextExport(node).AddNewLine();
end;
end;
end;
//----- Dialog realization -----
procedure FillChainList(Dialog:HWND);
var
wnd,list:HWND;
i:integer;
li:LV_ITEMW;
Macro:pMacroRecord;
begin
wnd:=GetDlgItem(Dialog,IDC_MACRO_LIST);
SendMessage(wnd,CB_RESETCONTENT,0,0);
SendMessage(wnd,CB_SETITEMDATA,
SendMessageW(wnd,CB_ADDSTRING,0,lparam(TranslateW(NoChainText))),0);
list:=MacroListWindow;
li.mask :=LVIF_PARAM;
li.iSubItem :=0;
for i:=0 to SendMessage(list,LVM_GETITEMCOUNT,0,0)-1 do
begin
li.iItem:=i;
SendMessageW(list,LVM_GETITEMW,0,tlparam(@li));
Macro:=EditMacroList[loword(li.lParam)];
SendMessage(wnd,CB_SETITEMDATA,
SendMessageW(wnd,CB_ADDSTRING,0,lparam(@(Macro.descr))),Macro.id);
end;
end;
procedure ClearFields(Dialog:HWND);
begin
CheckDlgButton(Dialog,IDC_MACRO_NOWAIT ,BST_UNCHECKED);
CheckDlgButton(Dialog,IDC_MACRO_SAMETHREAD,BST_UNCHECKED);
CheckDlgButton(Dialog,IDC_MACRO_KEEPOLD ,BST_UNCHECKED);
end;
function DlgProc(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
var
tmp:dword;
wnd:HWND;
bb:boolean;
begin
result:=0;
case hMessage of
WM_INITDIALOG: begin
TranslateDialogDefault(Dialog);
FillChainList(Dialog);
end;
WM_ACT_SETVALUE: begin
ClearFields(Dialog);
with tChainAction(lParam) do
begin
if (flags and ACF_BYNAME)<>0 then
SendDlgItemMessageW(Dialog,IDC_MACRO_LIST,CB_SELECTSTRING,twparam(-1),tlparam(actname))
else
CB_SelectData(Dialog,IDC_MACRO_LIST,id);
if (flags and ACF_KEEPOLD)<>0 then
CheckDlgButton(Dialog,IDC_MACRO_KEEPOLD,BST_CHECKED);
if (flags and ACF_SAMETHREAD)<>0 then
begin
bb:=false;
CheckDlgButton(Dialog,IDC_MACRO_SAMETHREAD,BST_CHECKED);
end
else
begin
bb:=true;
if (flags and ACF_NOWAIT)<>0 then
CheckDlgButton(Dialog,IDC_MACRO_NOWAIT,BST_CHECKED);
end;
EnableWindow(GetDlgItem(Dialog,IDC_MACRO_NOWAIT),bb);
end;
end;
WM_ACT_RESET: begin
ClearFields(Dialog);
CheckDlgButton(Dialog,IDC_MACRO_SAMETHREAD,BST_CHECKED);
SendDlgItemMessage(Dialog,IDC_MACRO_LIST,CB_SETCURSEL,0,0);
end;
WM_ACT_SAVE: begin
with tChainAction(lParam) do
begin
id:=CB_GetData(GetDlgItem(Dialog,IDC_MACRO_LIST));
if IsDlgButtonChecked(Dialog,IDC_MACRO_SAMETHREAD)<>BST_UNCHECKED then
flags:=flags or ACF_SAMETHREAD
else if IsDlgButtonChecked(Dialog,IDC_MACRO_NOWAIT)<>BST_UNCHECKED then
flags:=flags or ACF_NOWAIT;
if IsDlgButtonChecked(Dialog,IDC_MACRO_KEEPOLD)<>BST_UNCHECKED then
flags:=flags or ACF_KEEPOLD;
end;
end;
WM_ACT_LISTCHANGE: begin
if wParam=1 then
begin
wnd:=GetDlgItem(Dialog,IDC_MACRO_LIST);
tmp:=CB_GetData(wnd);
FillChainList(Dialog);
CB_SelectData(wnd,tmp);
end;
end;
WM_COMMAND: begin
case wParam shr 16 of
CBN_SELCHANGE: SendMessage(GetParent(GetParent(Dialog)),PSM_CHANGED,0,0);
BN_CLICKED: begin
if loword(wParam)=IDC_MACRO_SAMETHREAD then
begin
EnableWindow(GetDlgItem(Dialog,IDC_MACRO_NOWAIT),
IsDlgButtonChecked(Dialog,IDC_MACRO_SAMETHREAD)=BST_UNCHECKED);
end;
SendMessage(GetParent(GetParent(Dialog)),PSM_CHANGED,0,0);
end;
end;
end;
WM_HELP: begin
result:=1;
end;
end;
// result:=DefWindowProc(Dialog,hMessage,wParam,lParam);
end;
//----- Export/interface functions -----
var
vc:tActModule;
function CreateAction:tBaseAction;
begin
result:=tChainAction.Create(vc.Hash);
end;
function CreateDialog(parent:HWND):HWND;
begin
result:=CreateDialogW(hInstance,'IDD_ACTCHAIN',parent,@DlgProc);
end;
procedure Init;
begin
vc.Next :=ModuleLink;
vc.Name :='Chain';
vc.Dialog :=@CreateDialog;
vc.Create :=@CreateAction;
vc.Icon :='IDI_CHAIN';
vc.Hash :=0;
ModuleLink :=@vc;
end;
begin
Init;
end.
|