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
|
/*
Miranda Scripting Plugin for Miranda-IM
Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mbot.h"
#include "helpers.h"
#include "functions.h"
#include "dialogs.h"
extern CSyncList g_dlist;
LPCSTR DlgGetCtrlClass(long type)
{
const static char* classes[]={
WC_STATIC,//1
WC_BUTTON,//2
WC_EDIT,//3
WC_COMBOBOX,//4
WC_IPADDRESS,//5
WC_LISTVIEW,//6
PROGRESS_CLASS,//7
WC_TREEVIEW,//8
};
type &= 0x7FffFFff;
if(type > (sizeof(classes) / sizeof(char*))){
return "STATIC";
}else{
return classes[type-1];
}
}
VOID DlgFree(sDialog* dlg)
{
if(dlg){
while(dlg->lNum)
{
//DestroyWindow(dlg->table[dlg->lNum-1]->hWnd);
my_memfree(dlg->table[dlg->lNum-1]);
dlg->table[dlg->lNum-1] = NULL;
dlg->lNum--;
}
my_memfree(dlg);
//memset(dlg,0xAA,sizeof(sDialog));
}
}
BOOL CALLBACK DlgStdInProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
SetWindowLong(hDlg,GWL_USERDATA,(LONG)lParam);
sStdInDlg* sin = (sStdInDlg*)lParam;
if(!sin){
EndDialog(hDlg,IDCANCEL);
return (TRUE);
}
SetWindowText(hDlg,(sin->title)?(sin->title):("Enter some data"));
SetDlgItemText(hDlg,IDC_GS_INFO,(sin->info)?(sin->info):("Please enter some data:"));
if(sin->flags & sStdInDlg::NUMBER_ONLY){
SetWindowLong(GetDlgItem(hDlg,IDC_GS_EDIT),GWL_STYLE,ES_NUMBER);
}
if(sin->flags & sStdInDlg::NO_CANCEL){
ShowWindow(GetDlgItem(hDlg,IDCANCEL),SW_HIDE);
}
if(sin->def){
SetDlgItemText(hDlg,IDC_GS_EDIT,sin->def);
}
return (TRUE);
}
case WM_COMMAND:
{
UINT uid = LOWORD(wParam);
UINT ncode = HIWORD(wParam);
sStdInDlg* sin = (sStdInDlg*)GetWindowLong(hDlg,GWL_USERDATA);
if(uid == IDOK)
{
//do checking
ncode = GetDlgItemText(hDlg,IDC_GS_EDIT,sin->buffer,sizeof(sin->buffer)-1);
if(!ncode && (sin->flags & sStdInDlg::MUST_FILL)){
MessageBox(hDlg,"You must type in some data!",sin->title,MB_ICONWARNING);
break;
}
EndDialog(hDlg,IDOK);
}else if(uid == IDCANCEL){
if(sin->flags & sStdInDlg::MUST_FILL){
MessageBox(hDlg,"You must type in some data!",sin->title,MB_ICONWARNING);
break;
}else{
EndDialog(hDlg,IDCANCEL);
}
}
}
break;
default:
return (FALSE);
}
return (TRUE);
}
BOOL CALLBACK DlgProcedure(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
sDialog* dlg = (sDialog*)GetWindowLong(hDlg,GWL_USERDATA);
PHPR res;
if((uMsg != WM_INITDIALOG && uMsg != (WM_USER + 2)) && (!dlg || (dlg->hDlg != hDlg) || (dlg->lDepth > 0) || !(dlg->lFlags))){
return (FALSE);
}
if(dlg){dlg->lDepth++;}
switch(uMsg)
{
case WM_INITDIALOG:
SetWindowLong(hDlg,GWL_USERDATA,lParam);
dlg = (sDialog*)lParam;
sman_inc(dlg->php);
return (TRUE);
case (WM_USER + 2):
{
RECT rc;
RECT drc;
HWND hButton;
//move the OK & CANCEL buttons
GetClientRect(hDlg,&drc);
hButton = GetDlgItem(hDlg,IDCANCEL);
GetClientRect(hButton,&rc);
SetWindowPos(hButton,NULL,drc.right - 10 - 2*(rc.right - rc.left),drc.bottom - 5 - (rc.bottom - rc.top),
0,0,SWP_NOZORDER | SWP_NOSIZE);
hButton = GetDlgItem(hDlg,IDOK);
GetClientRect(hButton,&rc);
SetWindowPos(hButton,NULL,drc.right - 5 - (rc.right - rc.left),
drc.bottom - 5 - (rc.bottom - rc.top),0,0,SWP_NOZORDER | SWP_NOSIZE);
}
break;
case (WM_USER + 3):
DestroyWindow(hDlg);
sman_dec(dlg->php);
DlgFree(dlg);
SetWindowLong(hDlg,GWL_USERDATA,0);
return (TRUE);
case WM_CLOSE:
wParam = IDCANCEL;
lParam = (LPARAM)GetDlgItem(dlg->hDlg,IDCANCEL);
case WM_COMMAND:
{
UINT uid = LOWORD(wParam);
UINT ncode = HIWORD(wParam);
if((uid == IDOK || uid == IDCANCEL) && ncode == BN_CLICKED)
{
mb_event mbe={MBT_DIALOG,wParam,lParam,0};
mbe.php = dlg->php;
mbe.t3 = MBE_DIALOGCB;
mbe.p3 = (void*)dlg;
res = (PHPR)MBMultiParam(mbe.php,dlg->pszCallback,&mbe,"lll",(uid==IDOK),dlg->param,0);
if(res == PHPR_BREAK || res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
break;
}
else if(uid >= 1000 && uid < (dlg->lNum + 1000))
{
sDlgControl* dc = dlg->table[uid - 1000];
ULONG tmp = GetTickCount();
if(((uid == dlg->lid) && (tmp - dlg->ltc < 250)) || dc->pszCallback[0]=='\0'){
break;
}
mb_event mbe={MBT_DIALOG,wParam,lParam,0};
mbe.php = dlg->php;
mbe.t3 = MBE_DIALOGCB;
mbe.p3 = (void*)dlg;
mbe.lFlags = MBOT_FLAG_NOOUTPUT;
if(dc->type == 2 && ncode==BN_CLICKED){//button
res = (PHPR)MBMultiParam(dlg->php,dc->pszCallback,&mbe,"ll",uid,dc->param);
if(res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
}
else if(dc->type == 4 && ncode == CBN_SELENDOK)
{
res = (PHPR)MBMultiParam(dlg->php,dc->pszCallback,&mbe,"ll",uid,dc->param);
if(res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
}
else if(*dlg->pszWmCommand)
{
res = (PHPR)MBMultiParam(dlg->php,dlg->pszWmCommand,&mbe,"llll",uid,dc->param,wParam,lParam);
if(res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
}
dlg->lid = uid;
dlg->ltc = GetTickCount();
}
break;
}
break;
case WM_NOTIFY:
if(wParam >= 1000 && (wParam < (dlg->lNum + 1000)) &&
(((LPNMHDR)lParam)->code == NM_RCLICK || ((LPNMHDR)lParam)->code == NM_CLICK))
{
LVITEM lvi = {0};
sDlgControl* dc = dlg->table[wParam - 1000];
if(!dc || dc->type != 6 || !(*dc->pszCallback))break;
mb_event mbe={MBT_DIALOG,wParam,lParam,0};
mbe.php = dlg->php;
mbe.t3 = MBE_DIALOGCB;
mbe.p3 = (void*)dlg;
mbe.lFlags = MBOT_FLAG_NOOUTPUT;
res = (PHPR)MBMultiParam(dlg->php,dc->pszCallback,&mbe,"llll",wParam,dc->param,
((LPNMLISTVIEW)lParam)->iItem,
((LPNMHDR)lParam)->code == NM_RCLICK);
if(res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
}
else if(*dlg->pszWmNotify && ((LPNMHDR)lParam)->idFrom >= 1000)
{
mb_event mbe={MBT_DIALOG,wParam,lParam,0};
mbe.php = dlg->php;
mbe.t3 = MBE_DIALOGCB;
mbe.p3 = (void*)dlg;
mbe.lFlags = MBOT_FLAG_NOOUTPUT;
res = (PHPR)MBMultiParam(dlg->php,dlg->pszWmNotify,&mbe,"llll",((LPNMHDR)lParam)->idFrom,
dlg->param,wParam,lParam);
if(res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
}
break;
case WM_TIMER:
{
if(*dlg->pszWmTimer){
mb_event mbe={MBT_DIALOG,wParam,lParam,0};
mbe.php = dlg->php;
mbe.t3 = MBE_DIALOGCB;
mbe.p3 = (void*)dlg;
mbe.lFlags = MBOT_FLAG_NOOUTPUT;
res = (PHPR)MBMultiParam(dlg->php,dlg->pszWmTimer,&mbe,"llll",wParam,
dlg->param,wParam,lParam);
if(res == PHPR_END){
PostMessage(hDlg,WM_USER + 3,0,0);
}
}
}break;
case WM_DESTROY:
sman_dec(dlg->php);
DlgFree(dlg);
SetWindowLong(hDlg,GWL_USERDATA,0);
return (TRUE);
default:
dlg->lDepth--;
return (FALSE);
};
dlg->lDepth--;
return (TRUE);
}
|