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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
/*
* A plugin for Miranda IM which displays web page text in a window Copyright
* (C) 2005 Vincent Joyce.
*
* Miranda IM: the free icq client for MS Windows Copyright (C) 2000-2
* Richard Hughes, Roland Rabien & Tristan Van de Vreede
*
* 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 "stdafx.h"
#include "webview.h"
char* WndClass = "WEBWnd";
WNDCLASSEX wincl;
MSG messages;
DWORD winheight;
int StartUpDelay = 0;
DWORD Xposition, Yposition;
DWORD BackgoundClr, TextClr;
DWORD WindowHeight, WindowWidth;
UINT_PTR timerId;
UINT_PTR Countdown;
LOGFONT lf;
HFONT h_font;
HWND ContactHwnd;
HINSTANCE hInst;
HMENU hMenu;
int bpStatus;
HANDLE hMenuItem1;
HANDLE hMenuItemCountdown;
/*****************************************************************************/
void ChangeMenuItem1()
{
/*
* Enable or Disable auto updates
*/
CLISTMENUITEM mi = { sizeof(mi) };
mi.flags = CMIM_NAME | CMIM_ICON | CMIF_TCHAR;
mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SITE));
if (!db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))
mi.ptszName = LPGENT("Auto Update Enabled");
else
mi.ptszName = LPGENT("Auto Update Disabled");
CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuItem1, (LPARAM)&mi);
}
/*****************************************************************************/
void ChangeMenuItemCountdown()
{
/*
* countdown
*/
CLISTMENUITEM mi = { sizeof(mi) };
mi.flags = CMIM_NAME | CMIM_ICON | CMIF_TCHAR | CMIF_KEEPUNTRANSLATED;
mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_UPDATEALL));
TCHAR countername[100];
mir_sntprintf(countername,SIZEOF(countername), TranslateT("%d Minutes to Update"), db_get_dw(NULL, MODULENAME, COUNTDOWN_KEY, 0));
mi.ptszName = countername;
CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuItemCountdown, (LPARAM)&mi);
}
/*****************************************************************************/
static int CALLBACK EnumFontsProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
{
if (!IsWindow((HWND) lParam))
return FALSE;
if (SendMessage((HWND) lParam, CB_FINDSTRINGEXACT, -1, (LPARAM) lpelfe->elfLogFont.lfFaceName) == CB_ERR)
SendMessage((HWND) lParam, CB_ADDSTRING, 0, (LPARAM) lpelfe->elfLogFont.lfFaceName);
return TRUE;
}
void FillFontListThread(void *param)
{
HDC hdc = GetDC((HWND)param);
LOGFONT lf = {0};
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfFaceName[0] = 0;
lf.lfPitchAndFamily = 0;
EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC) EnumFontsProc, (LPARAM) GetDlgItem((HWND)param, IDC_TYPEFACE), 0);
ReleaseDC((HWND)param, hdc);
}
/*****************************************************************************/
void TxtclrLoop()
{
for (HANDLE hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) {
HWND hwndDlg = WindowList_Find(hWindowList, hContact);
SetDlgItemText(hwndDlg, IDC_DATA, _T(""));
InvalidateRect(hwndDlg, NULL, 1);
}
}
/*****************************************************************************/
void BGclrLoop()
{
for (HANDLE hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) {
HWND hwndDlg = (WindowList_Find(hWindowList, hContact));
SetDlgItemText(hwndDlg, IDC_DATA, _T(""));
SendMessage(GetDlgItem(hwndDlg, IDC_DATA), EM_SETBKGNDCOLOR, 0, BackgoundClr);
InvalidateRect(hwndDlg, NULL, 1);
}
}
/*****************************************************************************/
void StartUpdate(void *dummy)
{
StartUpDelay = 1;
Sleep(((db_get_dw(NULL, MODULENAME, START_DELAY_KEY, 0)) * SECOND));
for (HANDLE hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME))
GetData(hContact);
StartUpDelay = 0;
}
/*****************************************************************************/
void ContactLoop(void *dummy)
{
if (StartUpDelay == 0) {
for (HANDLE hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) {
GetData(hContact);
Sleep(10); // avoid 100% CPU
}
}
WAlertPopup(NULL, TranslateT("All Webview sites have been updated."));
}
/*****************************************************************************/
INT_PTR MarkAllReadMenuCommand(WPARAM wParam, LPARAM lParam)
{
ChangeContactStatus(1);
return 0;
}
/*****************************************************************************/
void InitialiseGlobals(void)
{
Xposition = db_get_dw(NULL, MODULENAME, Xpos_WIN_KEY, 0);
Yposition = db_get_dw(NULL, MODULENAME, Ypos_WIN_KEY, 0);
if (Yposition == -32000)
Yposition = 100;
if (Xposition == -32000)
Xposition = 100;
BackgoundClr = db_get_dw(NULL, MODULENAME, BG_COLOR_KEY, Def_color_bg);
TextClr = db_get_dw(NULL, MODULENAME, TXT_COLOR_KEY, Def_color_txt);
WindowHeight = db_get_dw(NULL, MODULENAME, WIN_HEIGHT_KEY, Def_win_height);
WindowWidth = db_get_dw(NULL, MODULENAME, WIN_WIDTH_KEY, Def_win_width);
}
/*****************************************************************************/
int Doubleclick(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
char *szProto = GetContactProto(hContact);
if ( lstrcmpA(MODULENAME, szProto))
return 0;
if ( db_get_b(hContact, MODULENAME, DBLE_WIN_KEY, 1)) {
ptrT url( db_get_tsa(hContact, MODULENAME, "URL"));
CallService(MS_UTILS_OPENURL, OUF_TCHAR, (WPARAM)url);
db_set_w(hContact, MODULENAME, "Status", ID_STATUS_ONLINE);
}
if ( db_get_b(hContact, MODULENAME, DBLE_WIN_KEY, 1)) {
HWND hwndDlg = WindowList_Find(hWindowList, hContact);
if (hwndDlg) {
SetForegroundWindow(hwndDlg);
SetFocus(hwndDlg);
}
else {
hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DISPLAY_DATA), NULL, DlgProcDisplayData, (LPARAM) hContact);
HWND hTopmost = db_get_b(hContact, MODULENAME, ON_TOP_KEY, 0) ? HWND_TOPMOST : HWND_NOTOPMOST;
SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)));
if ( db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))
SetWindowPos(hwndDlg, hTopmost,
db_get_dw(hContact, MODULENAME, "WVx", 100), // Xposition,
db_get_dw(hContact, MODULENAME, "WVy", 100), // Yposition,
db_get_dw(hContact, MODULENAME, "WVwidth", 412), // WindowWidth,
db_get_dw(hContact, MODULENAME, "WVheight", 350), 0); // WindowHeight,
else
SetWindowPos(hwndDlg, HWND_TOPMOST, Xposition, Yposition, WindowWidth, WindowHeight, 0);
}
ShowWindow(hwndDlg, SW_SHOW);
SetActiveWindow(hwndDlg);
if ( db_get_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, 0)) {
if ( db_get_b(hContact, MODULENAME, ENABLE_ALERTS_KEY, 0))
mir_forkthread(ReadFromFile, hContact);
else
mir_forkthread(GetData, hContact);
db_set_w(hContact, MODULENAME, "Status", ID_STATUS_ONLINE);
}
}
return 1;
}
/*****************************************************************************/
int SendToRichEdit(HWND hWindow, char *truncated, COLORREF rgbText, COLORREF rgbBack)
{
DBVARIANT dbv;
DWORD bold = 0;
DWORD italic = 0;
DWORD underline = 0;
int len = GetWindowTextLength(GetDlgItem(hWindow, IDC_DATA));
SetDlgItemText(hWindow, IDC_DATA, _T(""));
CHARFORMAT2 cfFM;
ZeroMemory(&cfFM, sizeof(cfFM));
cfFM.cbSize = sizeof(CHARFORMAT2);
cfFM.dwMask = CFM_COLOR | CFM_CHARSET | CFM_FACE | ENM_LINK | ENM_MOUSEEVENTS | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_SIZE;
if ( db_get_b(NULL, MODULENAME, FONT_BOLD_KEY, 0))
bold = CFE_BOLD;
if ( db_get_b(NULL, MODULENAME, FONT_ITALIC_KEY, 0))
italic = CFE_ITALIC;
if ( db_get_b(NULL, MODULENAME, FONT_UNDERLINE_KEY, 0))
underline = CFE_UNDERLINE;
cfFM.dwEffects = bold | italic | underline;
if (!db_get_ts(NULL, MODULENAME, FONT_FACE_KEY, &dbv)) {
lstrcpy(cfFM.szFaceName, dbv.ptszVal);
db_free(&dbv);
}
else lstrcpy(cfFM.szFaceName, Def_font_face);
HDC hDC = GetDC(hWindow);
cfFM.yHeight = (BYTE)MulDiv(abs(lf.lfHeight), 120, GetDeviceCaps(GetDC(hWindow), LOGPIXELSY)) * (db_get_b(NULL, MODULENAME, FONT_SIZE_KEY, 14));
ReleaseDC(hWindow, hDC);
cfFM.bCharSet = db_get_b(NULL, MODULENAME, FONT_SCRIPT_KEY, 0);
cfFM.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
cfFM.crTextColor = rgbText;
cfFM.crBackColor = rgbBack;
SendDlgItemMessage(hWindow, IDC_DATA, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) & cfFM);
SendDlgItemMessage(hWindow, IDC_DATA, EM_SETSEL, 0, -1);
SendDlgItemMessageA(hWindow, IDC_DATA, EM_REPLACESEL, FALSE, (LPARAM)truncated);
SendDlgItemMessage(hWindow, IDC_DATA, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cfFM);
return 1;
}
/*****************************************************************************/
void CALLBACK timerfunc(HWND, UINT, UINT_PTR, DWORD)
{
db_set_b(NULL, MODULENAME, HAS_CRASHED_KEY, 0);
if (!(db_get_b(NULL, MODULENAME, OFFLINE_STATUS, 1)))
if (!(db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0)))
mir_forkthread(ContactLoop, NULL);
db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, 0);
}
/*****************************************************************************/
void CALLBACK Countdownfunc(HWND, UINT, UINT_PTR, DWORD)
{
DWORD timetemp = db_get_dw(NULL, MODULENAME, COUNTDOWN_KEY, 100);
if(timetemp <= 0) {
timetemp = db_get_dw(NULL, MODULENAME, REFRESH_KEY, TIME);
db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, timetemp);
}
db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, timetemp-1);
ChangeMenuItemCountdown();
}
/*****************************************************************************/
static int OptInitialise(WPARAM wParam, LPARAM lParam)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.hInstance = hInst;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT);
odp.ptszGroup = LPGENT("Network");
odp.ptszTitle = _T(MODULENAME);
odp.pfnDlgProc = DlgProcOpt;
odp.flags = ODPF_BOLDGROUPS|ODPF_TCHAR;
Options_AddPage(wParam, &odp);
// if popup service exists
if ((ServiceExists(MS_POPUP_ADDPOPUP))) {
odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUP);
odp.ptszGroup = LPGENT("Popups");
odp.pfnDlgProc = DlgPopUpOpts;
Options_AddPage(wParam, &odp);
}
return 0;
}
/*****************************************************************************/
void FontSettings(void)
{
lf.lfHeight = 16;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = 0;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
lstrcpy(lf.lfFaceName, Def_font_face);
}
/*****************************************************************************/
int ModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_OPT_INITIALISE, OptInitialise);
hHookDisplayDataAlert = CreateHookableEvent(ME_DISPLAYDATA_ALERT);
HookEvent(ME_DISPLAYDATA_ALERT, DataWndAlertCommand);
hHookAlertPopup = CreateHookableEvent(ME_POPUP_ALERT);
HookEvent(ME_POPUP_ALERT, PopupAlert);
hHookErrorPopup = CreateHookableEvent(ME_POPUP_ERROR);
HookEvent(ME_POPUP_ERROR, ErrorMsgs);
hHookAlertOSD = CreateHookableEvent(ME_OSD_ALERT);
HookEvent(ME_OSD_ALERT, OSDAlert);
FontSettings();
h_font = CreateFontIndirect(&lf);
// get data on startup
if ( db_get_b(NULL, MODULENAME, UPDATE_ONSTART_KEY, 0))
mir_forkthread(StartUpdate, NULL);
return 0;
}
/*****************************************************************************/
INT_PTR DataWndMenuCommand(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
HWND hwndDlg = WindowList_Find(hWindowList, hContact);
if (hwndDlg != NULL) {
DestroyWindow(hwndDlg);
return 0;
}
HWND hTopmost = db_get_b(hContact, MODULENAME, ON_TOP_KEY, 0) ? HWND_TOPMOST : HWND_NOTOPMOST;
hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DISPLAY_DATA), NULL, DlgProcDisplayData, (LPARAM) hContact);
SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadImage(hInst, MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0));
if ( db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))
SetWindowPos(hwndDlg, hTopmost,
db_get_dw(hContact, MODULENAME, "WVx", 100), // Xposition,
db_get_dw(hContact, MODULENAME, "WVy", 100), // Yposition,
db_get_dw(hContact, MODULENAME, "WVwidth", 100), // WindowWidth,
db_get_dw(hContact, MODULENAME, "WVheight", 100), 0); // WindowHeight,
else
SetWindowPos(hwndDlg, HWND_TOPMOST, Xposition, Yposition, WindowWidth, WindowHeight, 0);
ShowWindow(hwndDlg, SW_SHOW);
SetActiveWindow(hwndDlg);
if ( db_get_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, 0)) {
if ( db_get_b(hContact, MODULENAME, ENABLE_ALERTS_KEY, 0))
mir_forkthread(ReadFromFile, hContact);
else
mir_forkthread(GetData, hContact);
db_set_w(hContact, MODULENAME, "Status", ID_STATUS_ONLINE);
}
return 0;
}
/*****************************************************************************/
INT_PTR UpdateAllMenuCommand(WPARAM wParam, LPARAM lParam)
{
mir_forkthread(ContactLoop, NULL);
return 0;
}
/*****************************************************************************/
INT_PTR AutoUpdateMCmd(WPARAM wParam, LPARAM lParam)
{
if (db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))
db_set_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0);
else
db_set_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 1);
ChangeMenuItem1();
return 0;
}
/*****************************************************************************/
INT_PTR AddContactMenuCommand(WPARAM, LPARAM)
{
db_set_s(NULL, "FindAdd", "LastSearched", MODULENAME);
CallService(MS_FINDADD_FINDADD, 0, 0);
return 0;
}
/*****************************************************************************/
int OnTopMenuCommand(WPARAM wParam, LPARAM lParam, HANDLE singlecontact)
{
int ontop = 0;
int done = 0;
if (((db_get_b(singlecontact, MODULENAME, ON_TOP_KEY, 0))) && done == 0)
{
db_set_b(singlecontact, MODULENAME, ON_TOP_KEY, 0);
ontop = 0;
done = 1;
}
if ((!(db_get_b(singlecontact, MODULENAME, ON_TOP_KEY, 0))) && done == 0)
{
db_set_b(singlecontact, MODULENAME, ON_TOP_KEY, 1);
ontop = 1;
done = 1;
}
return 0;
}
/*****************************************************************************/
INT_PTR WebsiteMenuCommand(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
ptrT url( db_get_tsa(hContact, MODULENAME, "URL"));
if (url)
CallService(MS_UTILS_OPENURL, OUF_TCHAR, (LPARAM)url);
db_set_w(hContact, MODULENAME, "Status", ID_STATUS_ONLINE);
return 0;
}
/*****************************************************************************/
int UpdateMenuCommand(WPARAM wParam, LPARAM lParam, HANDLE singlecontact)
{
mir_forkthread(GetData, singlecontact);
return 0;
}
/*****************************************************************************/
int ContactMenuItemUpdateData(WPARAM wParam, LPARAM lParam)
{
UpdateMenuCommand(wParam, lParam, (HANDLE)wParam);
return 0;
}
/*****************************************************************************/
INT_PTR CntOptionsMenuCommand(WPARAM wParam, LPARAM)
{
HWND hwndDlg = WindowList_Find(hWindowList, (HANDLE)wParam);
if (hwndDlg) {
DestroyWindow(hwndDlg);
return 0;
}
hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONTACT_OPT), NULL, DlgProcContactOpt, (LPARAM) wParam);
ShowWindow(hwndDlg, SW_SHOW);
SetActiveWindow(hwndDlg);
return 0;
}
/*****************************************************************************/
INT_PTR CntAlertMenuCommand(WPARAM wParam, LPARAM)
{
HWND hwndDlg = WindowList_Find(hWindowList, (HANDLE) wParam);
if (hwndDlg) {
DestroyWindow(hwndDlg);
return 0;
}
hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ALRT_OPT), NULL, DlgProcAlertOpt, (LPARAM) wParam);
ShowWindow(hwndDlg, SW_SHOW);
SetActiveWindow(hwndDlg);
return 0;
}
/*****************************************************************************/
INT_PTR CountdownMenuCommand(WPARAM wParam, LPARAM lParam)
{
return 0;
}
|