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
|
#include "headers.h"
int addSettingToWatchList(HANDLE hContact, char* module, char* setting)
{
if (WatchListArray.count == WatchListArray.size)
{
WatchListArray.size += 32;
WatchListArray.item = (struct DBsetting*)mir_realloc(WatchListArray.item, sizeof(struct DBsetting)*WatchListArray.size);
}
if (!WatchListArray.item) return 0;
if (setting && db_get(hContact,module, setting, &(WatchListArray.item[WatchListArray.count].dbv))) return 0;
WatchListArray.item[WatchListArray.count].hContact = hContact;
WatchListArray.item[WatchListArray.count].module = mir_tstrdup(module);
if (setting) WatchListArray.item[WatchListArray.count].setting = mir_tstrdup(setting);
else WatchListArray.item[WatchListArray.count].setting = 0;
WatchListArray.item[WatchListArray.count].WatchModule = setting?WATCH_SETTING:WATCH_MODULE;
WatchListArray.count++;
return 1;
}
void freeWatchListItem(int item)
{
if (WatchListArray.item[item].module) mir_free(WatchListArray.item[item].module);
WatchListArray.item[item].module = 0;
if (WatchListArray.item[item].setting) mir_free(WatchListArray.item[item].setting);
WatchListArray.item[item].setting = 0;
db_free(&(WatchListArray.item[item].dbv));
WatchListArray.item[item].hContact = 0;
}
void addwatchtolist(HWND hwnd2list, struct DBsetting *lParam)
{
LVITEM lvItem;
int index;
char data[32], tmp[32];
DBVARIANT *dbv = &(lParam->dbv);
HANDLE hContact = lParam->hContact;
char *module = lParam->module;
char *setting = lParam->setting;
if (!module) return;
lvItem.lParam = (LPARAM)lParam->hContact;
lvItem.mask = LVIF_TEXT|LVIF_PARAM;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
if (!setting || (int)(lParam->setting) == WATCH_MODULE) // add every item in the module and return
{
ModuleSettingLL settinglist;
struct DBsetting dummy;
struct ModSetLinkLinkItem *setting;
if (!EnumSettings(hContact,module,&settinglist)) return;
dummy.hContact = hContact;
dummy.module = mir_tstrdup(module);
setting = settinglist.first;
while (setting)
{
dummy.setting = setting->name;
addwatchtolist(hwnd2list, &dummy);
setting = (struct ModSetLinkLinkItem *)setting->next;
}
mir_free(dummy.module);
FreeModuleSettingLL(&settinglist);
return;
}
db_free(&(lParam->dbv));
if (GetSetting(hContact, module, setting, &(lParam->dbv))) return;
if (!hContact)
lvItem.pszText = "NULL";
else
lvItem.pszText = (char*)GetContactName(hContact, NULL, 1);
index = ListView_InsertItem(hwnd2list,&lvItem);
WCHAR* ptszText = mir_a2u(lvItem.pszText);
ListView_SetItemTextW(hwnd2list, index, 0, ptszText);
mir_free(ptszText);
ListView_SetItemText(hwnd2list,index,1,module);
ListView_SetItemText(hwnd2list,index,2,setting);
switch (dbv->type) {
case DBVT_BLOB:
{
int j;
char *data = NULL;
if (!(data = (char*)mir_realloc(data, 3*(dbv->cpbVal+1)) ))
return;
data[0] = '\0';
for (j=0; j<dbv->cpbVal; j++)
{
char tmp[16];
mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)dbv->pbVal[j]);
strcat(data, tmp);
}
ListView_SetItemText(hwnd2list,index,4,data);
ListView_SetItemText(hwnd2list,index,3,"BLOB");
mir_free(data);
}
break;
case DBVT_BYTE:
mir_snprintf(data, 32, "0x%02X (%s)", dbv->bVal, itoa(dbv->bVal,tmp,10));
ListView_SetItemText(hwnd2list,index,4,data);
ListView_SetItemText(hwnd2list,index,3,"BYTE");
break;
case DBVT_WORD:
mir_snprintf(data, 32, "0x%04X (%s)", dbv->wVal, itoa(dbv->wVal,tmp,10));
ListView_SetItemText(hwnd2list,index,4,data);
ListView_SetItemText(hwnd2list,index,3,"WORD");
break;
case DBVT_DWORD:
mir_snprintf(data, 32, "0x%08X (%s)", dbv->dVal, itoa(dbv->dVal,tmp,10));
ListView_SetItemText(hwnd2list,index,4,data);
ListView_SetItemText(hwnd2list,index,3,"DWORD");
break;
case DBVT_ASCIIZ:
ListView_SetItemText(hwnd2list,index,4,dbv->pszVal);
ListView_SetItemText(hwnd2list,index,3,"STRING");
break;
case DBVT_UTF8:
int length = (int)strlen(dbv->pszVal) + 1;
WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR));
MultiByteToWideChar(CP_UTF8, 0, dbv->pszVal, -1, wc, length);
ListView_SetItemTextW(hwnd2list,index,4,wc);
ListView_SetItemText(hwnd2list,index,3,"UNICODE");
break;
}
}
void PopulateWatchedWindow(HWND hwnd)
{
int i;
ListView_DeleteAllItems(hwnd);
for (i=0;i<WatchListArray.count;i++)
{
addwatchtolist(hwnd, &(WatchListArray.item[i]));
}
}
void freeAllWatches()
{
int i;
for (i=0;i<WatchListArray.count;i++)
{
freeWatchListItem(i);
}
mir_free(WatchListArray.item);
WatchListArray.item = 0;
WatchListArray.count = 0;
}
int WatchDialogResize(HWND hwnd,LPARAM lParam,UTILRESIZECONTROL *urc)
{
switch(urc->wId)
{
case IDC_VARS:
urc->rcItem.top = 0;
urc->rcItem.bottom = urc->dlgNewSize.cy;
urc->rcItem.left = 0;
urc->rcItem.right = urc->dlgNewSize.cx;
return RD_ANCHORY_CUSTOM|RD_ANCHORX_CUSTOM;
}
return RD_ANCHORX_LEFT|RD_ANCHORY_TOP;
}
INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
{
// setup the list...
LVCOLUMN sLC;
sLC.fmt = LVCFMT_LEFT;
ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_VARS), 32|LVS_EX_SUBITEMIMAGES); //LVS_EX_FULLROWSELECT
sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
sLC.pszText = Translate("Contact"); sLC.cx = 80;
ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS),0,&sLC);
sLC.pszText = Translate("Module"); sLC.cx = 80;
ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS),1,&sLC);
sLC.pszText = Translate("Setting"); sLC.cx = 80;
ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS),2,&sLC);
sLC.pszText = Translate("Type"); sLC.cx = 60;
ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS),3,&sLC);
sLC.pszText = Translate("Data"); sLC.cx = 300;
ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS),4,&sLC);
PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS));
TranslateMenu(GetMenu(hwnd));
TranslateMenu(GetSubMenu(GetMenu(hwnd),0));
TranslateDialogDefault(hwnd);
// do the icon
SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(ICO_REGEDIT)));
}
return TRUE;
// for the resize
case WM_GETMINMAXINFO:
{
MINMAXINFO *mmi=(MINMAXINFO*)lParam;
mmi->ptMinTrackSize.x=200;
mmi->ptMinTrackSize.y=90;
return 0;
}
case WM_SIZE:
{
UTILRESIZEDIALOG urd;
ZeroMemory(&urd,sizeof(urd));
urd.cbSize=sizeof(urd);
urd.hInstance=hInst;
urd.hwndDlg=hwnd;
urd.lParam=0;
urd.lpTemplate=MAKEINTRESOURCE(IDD_WATCH_DIAG);
urd.pfnResizer=WatchDialogResize;
CallService(MS_UTILS_RESIZEDIALOG,0,(LPARAM)&urd);
break;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case MENU_REMALL_WATCHES:
freeAllWatches();
ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_VARS));
break;
case MENU_EXIT:
case IDCANCEL:
hwnd2watchedVarsWindow = 0;
DestroyWindow(hwnd);
break;
case MENU_REFRESH:
PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS));
}
break;
case WM_NOTIFY:
switch(LOWORD(wParam))
{
case IDC_VARS:
switch(((NMHDR*)lParam)->code)
{
case NM_DBLCLK:
{
LVHITTESTINFO hti;
LVITEM lvi;
hti.pt=((NMLISTVIEW*)lParam)->ptAction;
if (ListView_SubItemHitTest(GetDlgItem(hwnd,IDC_VARS),&hti) >-1)
{
if (hti.flags&LVHT_ONITEM)
{
lvi.mask = LVIF_PARAM;
lvi.iItem = hti.iItem;
lvi.iSubItem = 0;
if (ListView_GetItem(GetDlgItem(hwnd,IDC_VARS),&lvi))
{
ItemInfo ii;
ii.hContact = (HANDLE)lvi.lParam;
ListView_GetItemText(GetDlgItem(hwnd,IDC_VARS),hti.iItem,1,ii.module,128);
ListView_GetItemText(GetDlgItem(hwnd,IDC_VARS),hti.iItem,2,ii.setting,128);
ii.type = FW_SETTINGNAME;
SendMessage(hwnd2mainWindow,WM_FINDITEM,(WPARAM)&ii,0);
}
}
}
}
break;
}
break;
}
break;
}
return 0;
}
void popupWatchedVar(HANDLE hContact,const char* module,const char* setting)
{
HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT));
char lpzContactName[MAX_CONTACTNAME];
char lpzText[MAX_SECONDLINE];
COLORREF colorBack = db_get_dw(NULL,modname,"PopupColour",RGB(255,0,0));
COLORREF colorText = RGB(0,0,0);
int timeout = db_get_b(NULL,modname,"PopupDelay",3);
if (hContact) {
// contacts nick
char szProto[256];
if (GetValue(hContact,"Protocol","p",szProto,SIZEOF(szProto)))
mir_snprintf(lpzContactName, MAX_SECONDLINE, "%s (%s)", (char*)GetContactName(hContact, szProto, 0), szProto);
else
mir_snprintf(lpzContactName, MAX_SECONDLINE, nick_unknown);
}
else strcpy(lpzContactName,Translate("Settings"));
// 2nd line
DBVARIANT dbv;
if ( GetSetting(hContact, module, setting, &dbv))
return;
switch (dbv.type) {
case DBVT_BYTE:
mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (BYTE) %d"), module, setting, dbv.bVal);
break;
case DBVT_WORD:
mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (WORD) %d"), module, setting, dbv.wVal);
break;
case DBVT_DWORD:
mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (DWORD) 0x%X"), module, setting, dbv.dVal);
break;
case DBVT_ASCIIZ:
mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: \"%s\""), module, setting, dbv.pszVal);
break;
case DBVT_UTF8:
mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value (UTF8): \"%s\""), module, setting, dbv.pszVal);
break;
default:
return;
}
db_free(&dbv);
POPUPDATA ppd = { 0 };
ppd.lchContact = (HANDLE)hContact;
ppd.lchIcon = hIcon;
lstrcpyn(ppd.lpzContactName, lpzContactName,MAX_CONTACTNAME);
lstrcpyn(ppd.lpzText, lpzText,MAX_SECONDLINE);
ppd.colorBack = colorBack;
ppd.colorText = colorText;
ppd.iSeconds = timeout ? timeout : -1;
PUAddPopUp(&ppd);
}
|