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
|
/*
Weather Protocol plugin for Miranda IM
Copyright (c) 2012 Miranda NG team
Copyright (c) 2006-2009 Boris Krasnovskiy All Rights Reserved
Copyright (c) 2002-2006 Calvin Che
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; version 2
of the License.
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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#define MS_TOOLTIP_SHOWTIP "mToolTip/ShowTip"
#define MS_TOOLTIP_HIDETIP "mToolTip/HideTip"
static MWindowList hMwinWindowList;
static HANDLE hFontHook;
HGENMENU hMwinMenu;
typedef struct
{
MCONTACT hContact;
HWND hAvt;
BOOL haveAvatar;
} MWinDataType;
#define WM_REDRAWWIN (WM_USER + 17369)
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
MWinDataType *data = (MWinDataType*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
switch (msg) {
case WM_CREATE:
data = (MWinDataType*)mir_calloc(sizeof(MWinDataType));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data);
data->hContact = (DWORD_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams;
data->hAvt = CreateWindow(AVATAR_CONTROL_CLASS, TEXT(""), WS_CHILD,
0, 0, opt.AvatarSize, opt.AvatarSize, hwnd, nullptr, g_plugin.getInst(), nullptr);
if (data->hAvt) SendMessage(data->hAvt, AVATAR_SETCONTACT, 0, (LPARAM)data->hContact);
break;
case WM_DESTROY:
mir_free(data);
break;
case WM_CONTEXTMENU:
{
POINT pt;
GetCursorPos(&pt);
HMENU hMenu = Menu_BuildContactMenu(data->hContact);
TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwnd, nullptr);
DestroyMenu(hMenu);
}
break;
case WM_MOUSEMOVE:
{
TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.hwndTrack = hwnd;
tme.dwFlags = TME_QUERY;
TrackMouseEvent(&tme);
if (tme.dwFlags == 0) {
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.hwndTrack = hwnd;
tme.dwHoverTime = CallService(MS_CLC_GETINFOTIPHOVERTIME, 0, 0);
TrackMouseEvent(&tme);
}
}
break;
case WM_MOUSEHOVER:
{
POINT pt;
CLCINFOTIP ti = { 0 };
GetCursorPos(&pt);
GetWindowRect(hwnd, &ti.rcItem);
ti.cbSize = sizeof(ti);
ti.hItem = (HANDLE)data->hContact;
ti.ptCursor = pt;
ti.isTreeFocused = 1;
CallService(MS_TOOLTIP_SHOWTIP, 0, (LPARAM)&ti);
}
break;
case WM_LBUTTONDBLCLK:
BriefInfo(data->hContact, 0);
break;
case WM_COMMAND: //Needed by the contact's context menu
if (Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, data->hContact))
break;
return FALSE;
case WM_MEASUREITEM: //Needed by the contact's context menu
return Menu_MeasureItem(lParam);
case WM_DRAWITEM: //Needed by the contact's context menu
return Menu_DrawItem(lParam);
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == NM_AVATAR_CHANGED) {
BOOL newava = CallService(MS_AV_GETAVATARBITMAP, data->hContact, 0) != 0;
if (newava != data->haveAvatar) {
LONG_PTR style = GetWindowLongPtr(data->hAvt, GWL_STYLE);
data->haveAvatar = newava;
SetWindowLongPtr(data->hAvt, GWL_STYLE, newava ? (style | WS_VISIBLE) : (style & ~WS_VISIBLE));
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE);
}
}
break;
case WM_REDRAWWIN:
if (data->hAvt != nullptr) MoveWindow(data->hAvt, 0, 0, opt.AvatarSize, opt.AvatarSize, TRUE);
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
break;
case WM_PAINT:
{
RECT r, rc;
if (GetUpdateRect(hwnd, &r, FALSE)) {
int picSize = opt.AvatarSize;
HICON hIcon = nullptr;
if (!data->haveAvatar) {
int statusIcon = g_plugin.getWord(data->hContact, "Status");
picSize = GetSystemMetrics(SM_CXICON);
hIcon = Skin_LoadProtoIcon(MODULENAME, statusIcon, true);
if ((INT_PTR)hIcon == CALLSERVICE_NOTFOUND) {
picSize = GetSystemMetrics(SM_CXSMICON);
hIcon = Skin_LoadProtoIcon(MODULENAME, statusIcon);
}
}
LOGFONT lfnt, lfnt1;
COLORREF clr = g_plugin.getDword("ColorMwinFrame", GetSysColor(COLOR_3DFACE));
COLORREF fntc = Font_GetW(_A2W(MODULENAME), LPGENW("Frame Font"), &lfnt);
COLORREF fntc1 = Font_GetW(_A2W(MODULENAME), LPGENW("Frame Title Font"), &lfnt1);
ptrW tszInfo(db_get_wsa(data->hContact, WEATHERCONDITION, "WeatherInfo"));
GetClientRect(hwnd, &rc);
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
if (ServiceExists(MS_SKIN_DRAWGLYPH)) {
SKINDRAWREQUEST rq;
memset(&rq, 0, sizeof(rq));
rq.hDC = hdc;
rq.rcDestRect = rc;
rq.rcClipRect = rc;
mir_strcpy(rq.szObjectID, "Main,ID=WeatherFrame");
CallService(MS_SKIN_DRAWGLYPH, (WPARAM)&rq, 0);
}
if (clr != 0xFFFFFFFF) {
HBRUSH hBkgBrush = CreateSolidBrush(clr);
FillRect(hdc, &rc, hBkgBrush);
DeleteObject(hBkgBrush);
}
if (!data->haveAvatar)
DrawIconEx(hdc, 1, 1, hIcon, 0, 0, 0, nullptr, DI_NORMAL);
SetBkMode(hdc, TRANSPARENT);
HFONT hfnt = CreateFontIndirect(&lfnt1);
HFONT hfntold = (HFONT)SelectObject(hdc, hfnt);
wchar_t *nick = Clist_GetContactDisplayName(data->hContact);
SIZE fontSize;
GetTextExtentPoint32(hdc, L"|", 1, &fontSize);
rc.top += 1;
rc.left += picSize + fontSize.cx;
SetTextColor(hdc, fntc1);
DrawText(hdc, nick, -1, &rc, DT_LEFT | DT_EXPANDTABS);
rc.top += fontSize.cy;
SelectObject(hdc, hfntold);
DeleteObject(hfnt);
if (tszInfo) {
HFONT hFont = CreateFontIndirect(&lfnt);
HFONT hFontOld = (HFONT)SelectObject(hdc, hFont);
SetTextColor(hdc, fntc);
DrawText(hdc, tszInfo, -1, &rc, DT_LEFT | DT_EXPANDTABS);
SelectObject(hdc, hFontOld);
DeleteObject(hFont);
}
EndPaint(hwnd, &ps);
IcoLib_ReleaseIcon(hIcon);
}
break;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return(TRUE);
}
static void addWindow(MCONTACT hContact)
{
DBVARIANT dbv;
if (g_plugin.getWString(hContact, "Nick", &dbv))
return;
wchar_t winname[512];
mir_snwprintf(winname, L"Weather: %s", dbv.pwszVal);
db_free(&dbv);
HWND hWnd = CreateWindow(L"WeatherFrame", L"", WS_CHILD | WS_VISIBLE,
0, 0, 10, 10, g_clistApi.hwndContactList, nullptr, g_plugin.getInst(), (void*)hContact);
WindowList_Add(hMwinWindowList, hWnd, hContact);
CLISTFrame Frame = { 0 };
Frame.szName.w = winname;
Frame.hIcon = g_plugin.getIcon(IDI_ICON);
Frame.cbSize = sizeof(Frame);
Frame.hWnd = hWnd;
Frame.align = alBottom;
Frame.Flags = F_VISIBLE | F_NOBORDER | F_UNICODE;
Frame.height = 32;
int frameID = g_plugin.addFrame(&Frame);
g_plugin.setDword(hContact, "mwin", frameID);
Contact_Hide(hContact);
}
void removeWindow(MCONTACT hContact)
{
DWORD frameId = g_plugin.getDword(hContact, "mwin");
WindowList_Remove(hMwinWindowList, WindowList_Find(hMwinWindowList, hContact));
CallService(MS_CLIST_FRAMES_REMOVEFRAME, frameId, 0);
g_plugin.setDword(hContact, "mwin", 0);
Contact_Hide(hContact, false);
}
void UpdateMwinData(MCONTACT hContact)
{
HWND hwnd = WindowList_Find(hMwinWindowList, hContact);
if (hwnd != nullptr)
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
}
INT_PTR Mwin_MenuClicked(WPARAM wParam, LPARAM)
{
BOOL addwnd = WindowList_Find(hMwinWindowList, wParam) == nullptr;
if (addwnd)
addWindow(wParam);
else
removeWindow(wParam);
return 0;
}
int BuildContactMenu(WPARAM wparam, LPARAM)
{
int flags = g_plugin.getDword(wparam, "mwin") ? CMIF_CHECKED : 0;
Menu_ModifyItem(hMwinMenu, nullptr, INVALID_HANDLE_VALUE, flags);
return 0;
}
int RedrawFrame(WPARAM, LPARAM)
{
WindowList_Broadcast(hMwinWindowList, WM_REDRAWWIN, 0, 0);
return 0;
}
void InitMwin(void)
{
if (!ServiceExists(MS_CLIST_FRAMES_ADDFRAME))
return;
hMwinWindowList = WindowList_Create();
WNDCLASS wndclass;
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = wndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = g_plugin.getInst();
wndclass.hIcon = nullptr;
wndclass.hCursor = LoadCursor(nullptr, IDC_ARROW);
wndclass.hbrBackground = nullptr; //(HBRUSH)(COLOR_3DFACE+1);
wndclass.lpszMenuName = nullptr;
wndclass.lpszClassName = L"WeatherFrame";
RegisterClass(&wndclass);
ColourIDW colourid = {};
mir_strcpy(colourid.dbSettingsGroup, MODULENAME);
mir_strcpy(colourid.setting, "ColorMwinFrame");
mir_wstrcpy(colourid.name, LPGENW("Frame Background"));
mir_wstrcpy(colourid.group, _A2W(MODULENAME));
colourid.defcolour = GetSysColor(COLOR_3DFACE);
g_plugin.addColor(&colourid);
FontIDW fontid = {};
fontid.flags = FIDF_ALLOWREREGISTER | FIDF_DEFAULTVALID;
mir_strcpy(fontid.dbSettingsGroup, MODULENAME);
mir_wstrcpy(fontid.group, _A2W(MODULENAME));
mir_wstrcpy(fontid.name, LPGENW("Frame Font"));
mir_strcpy(fontid.setting, "fnt0");
HDC hdc = GetDC(nullptr);
fontid.deffontsettings.size = -13;
ReleaseDC(nullptr, hdc);
fontid.deffontsettings.charset = DEFAULT_CHARSET;
mir_wstrcpy(fontid.deffontsettings.szFace, L"Verdana");
mir_wstrcpy(fontid.backgroundGroup, _A2W(MODULENAME));
mir_wstrcpy(fontid.backgroundName, LPGENW("Frame Background"));
g_plugin.addFont(&fontid);
fontid.deffontsettings.style = DBFONTF_BOLD;
mir_wstrcpy(fontid.name, LPGENW("Frame Title Font"));
mir_strcpy(fontid.setting, "fnt1");
g_plugin.addFont(&fontid);
for (auto &hContact : Contacts(MODULENAME))
if (g_plugin.getDword(hContact, "mwin"))
addWindow(hContact);
hFontHook = HookEvent(ME_FONT_RELOAD, RedrawFrame);
}
void DestroyMwin(void)
{
for (auto &hContact : Contacts(MODULENAME)) {
DWORD frameId = g_plugin.getDword(hContact, "mwin");
if (frameId)
CallService(MS_CLIST_FRAMES_REMOVEFRAME, frameId, 0);
}
UnregisterClass(L"WeatherFrame", g_plugin.getInst());
WindowList_Destroy(hMwinWindowList);
UnhookEvent(hFontHook);
}
|