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
|
/////////////////////////////////////////////////////////////////////////////////////////
// Miranda NG: the free IM client for Microsoft* Windows*
//
// Copyright (C) 2012-23 Miranda NG team,
// Copyright (c) 2000-09 Miranda ICQ/IM project,
// all portions of this codebase are copyrighted to the people
// listed in contributors.txt.
//
// 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.
//
// part of tabSRMM messaging plugin for Miranda.
//
// (C) 2005-2010 by silvercircle _at_ gmail _dot_ com and contributors
//
// Helper functions for the group chat module.
#include "stdafx.h"
char szIndicators[] = { 0, '+', '%', '@', '!', '*' };
static void __stdcall ShowRoomFromPopup(void *pi)
{
SESSION_INFO *si = (SESSION_INFO*)pi;
ShowRoom(nullptr, si);
}
static void __stdcall Chat_DismissPopup(void *pi)
{
SESSION_INFO *si = (SESSION_INFO*)pi;
if (si->hContact)
if (Clist_GetEvent(si->hContact, 0))
Clist_RemoveEvent(si->hContact, GC_FAKE_EVENT);
if (si->pDlg && si->pDlg->timerFlash.Stop())
FlashWindow(si->pDlg->GetHwnd(), FALSE);
}
static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SESSION_INFO *si = (SESSION_INFO*)PUGetPluginData(hWnd);
switch (message) {
case WM_COMMAND:
if (HIWORD(wParam) == STN_CLICKED) {
if (si) {
if (NEN::ActionLeft & MASK_OPEN)
CallFunctionAsync(ShowRoomFromPopup, si);
else
CallFunctionAsync(Chat_DismissPopup, si);
PUDeletePopup(hWnd);
}
return TRUE;
}
break;
case WM_CONTEXTMENU:
if (si && si->hContact) {
if (NEN::ActionRight & MASK_OPEN)
CallFunctionAsync(ShowRoomFromPopup, si);
else
CallFunctionAsync(Chat_DismissPopup, si);
PUDeletePopup(hWnd);
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, wchar_t*, COLORREF crBkg, const wchar_t* fmt, ...)
{
POPUPDATAW pd;
va_list marker;
static wchar_t szBuf[4 * 1024];
if (!fmt || mir_wstrlen(fmt) == 0 || mir_wstrlen(fmt) > 2000)
return 0;
va_start(marker, fmt);
mir_vsnwprintf(szBuf, _countof(szBuf), fmt, marker);
va_end(marker);
pd.lchContact = hContact;
if (hIcon)
pd.lchIcon = hIcon;
else
pd.lchIcon = LoadIconEx("window");
PROTOACCOUNT *pa = Proto_GetAccount(pszProtoName);
mir_snwprintf(pd.lpwzContactName, L"%s - %s", (pa == nullptr) ? _A2T(pszProtoName).get() : pa->tszAccountName, Clist_GetContactDisplayName(hContact));
wcsncpy_s(pd.lpwzText, TranslateW(szBuf), _TRUNCATE);
pd.iSeconds = g_Settings.iPopupTimeout;
if (g_Settings.iPopupStyle == 2) {
pd.colorBack = 0;
pd.colorText = 0;
}
else if (g_Settings.iPopupStyle == 3) {
pd.colorBack = g_Settings.crPUBkgColour;
pd.colorText = g_Settings.crPUTextColour;
}
else {
pd.colorBack = g_Settings.crLogBackground;
pd.colorText = crBkg;
}
pd.PluginWindowProc = PopupDlgProc;
pd.PluginData = si;
return (INT_PTR)PUAddPopupW(&pd);
}
BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce)
{
int iEvent = gce->iType;
if (si == nullptr || !(iEvent & si->iPopupFlags))
return true;
CMsgDialog *dat = si->pDlg;
TContainerData *pContainer = dat ? dat->m_pContainer : nullptr;
wchar_t *bbStart, *bbEnd;
if (g_plugin.bBBCodeInPopups) {
bbStart = L"[b]";
bbEnd = L"[/b]";
}
else bbStart = bbEnd = L"";
if (!NEN::bMucPopups) // no popups at all. Period
return 0;
// check the status mode against the status mask
char *szProto = dat ? dat->m_szProto : si->pszModule;
if (szProto != nullptr) {
int dwStatus = Proto_GetStatus(szProto);
if (dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE)
return 0;
}
if (dat && pContainer != nullptr) { // message window is open, need to check the container config if we want to see a popup nonetheless
if (NEN::bWindowCheck) { // no popups at all for open windows... no exceptions
if (!g_plugin.bHideOnClose)
return 0;
if (pContainer->m_bHidden)
goto passed;
return 0;
}
if (pContainer->cfg.flags.m_bDontReport && IsIconic(pContainer->m_hwnd)) // in tray counts as "minimised"
goto passed;
if (pContainer->cfg.flags.m_bDontReportUnfocused) {
if (!IsIconic(pContainer->m_hwnd) && !pContainer->IsActive())
goto passed;
}
if (pContainer->cfg.flags.m_bAlwaysReportInactive) {
if (pContainer->cfg.flags.m_bDontReportFocused)
goto passed;
if (pContainer->m_hwndActive == si->pDlg->GetHwnd())
return 0;
goto passed;
}
return 0;
}
passed:
int iNewEvent = iEvent;
COLORREF clr = 0;
if ((iNewEvent & GC_EVENT_HIGHLIGHT)) {
clr = g_chatApi.aFonts[16].color;
iNewEvent &= ~GC_EVENT_HIGHLIGHT;
}
if (iNewEvent == GC_EVENT_MESSAGE) {
ShowPopup(si->hContact, si, g_chatApi.getIcon(GC_EVENT_MESSAGE), si->pszModule, si->ptszName, clr ? clr : g_chatApi.aFonts[9].color,
L"%s%s:%s %s", bbStart, gce->pszNick.w, bbEnd, g_chatApi.RemoveFormatting(gce->pszText.w));
}
else oldDoPopup(si, gce);
return TRUE;
}
BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix)
{
if (gce == nullptr || si == nullptr || gce->bIsMe || si->iType == GCW_SERVER)
return FALSE;
CMsgDialog *dat = si->pDlg;
int iMuteMode = db_get_b(si->hContact, "SRMM", "MuteMode", CHATMODE_NORMAL);
int iEvent = gce->iType;
bool bInactive = (dat) ? !dat->IsActive() : true;
bool bActiveTab = false;
bool bMustFlash = false;
bool bMustAutoswitch = false;
bool bFlagUnread = false;
if (bHighlight) {
gce->iType |= GC_EVENT_HIGHLIGHT;
if (Contact::IsHidden(si->hContact) != 0)
Contact::Hide(si->hContact, false);
if (bInactive) {
bFlagUnread = true;
g_chatApi.DoTrayIcon(si, gce);
}
if (dat || NEN::bMucPopups)
if (iMuteMode != CHATMODE_MUTE)
DoPopup(si, gce);
if (Chat::bFlashWindowHighlight && bInactive)
bMustFlash = true;
bMustAutoswitch = true;
if (g_plugin.bCreateWindowOnHighlight && dat == nullptr) {
Clist_ContactDoubleClicked(si->hContact);
bActiveTab = true;
bInactive = bMustAutoswitch = bMustFlash = false;
}
if (dat && g_plugin.bAnnoyingHighlight && bInactive && dat->m_pContainer->m_hwnd != GetForegroundWindow()) {
bActiveTab = true;
bInactive = bMustAutoswitch = bMustFlash = false;
dat->ActivateTab();
}
}
else {
// do blinking icons in tray
if (bInactive || !g_Settings.bTrayIconInactiveOnly) {
g_chatApi.DoTrayIcon(si, gce);
if (iEvent == GC_EVENT_MESSAGE)
bFlagUnread = true;
}
// stupid thing to not create multiple popups for a QUIT event for instance
if (bManyFix == 0) {
// do popups
if (dat || NEN::bMucPopups)
if (iMuteMode != CHATMODE_MUTE)
DoPopup(si, gce);
// do sounds and flashing
if (iEvent == GC_EVENT_MESSAGE) {
if (bInactive && !(si->wState & STATE_TALK)) {
si->wState |= STATE_TALK;
db_set_w(si->hContact, si->pszModule, "ApparentMode", ID_STATUS_OFFLINE);
}
}
}
if (iEvent == GC_EVENT_MESSAGE) {
bMustAutoswitch = true;
if (Chat::bFlashWindow)
bMustFlash = true;
}
}
if (dat && bFlagUnread) {
dat->m_dwUnread++;
if (dat->m_pWnd)
dat->m_pWnd->Invalidate();
}
if (iMuteMode != CHATMODE_MUTE) {
auto sound = si->getSoundName(gce->iType);
if (dat) {
bInactive = dat->m_pContainer->m_hwnd != GetForegroundWindow();
bActiveTab = (dat->m_pContainer->m_hwndActive == dat->GetHwnd());
if (sound && dat->m_pContainer->MustPlaySound(dat))
Skin_PlaySound(sound);
}
else if (sound)
Skin_PlaySound(sound);
}
// dialog event processing
if (dat) {
HICON hIconHighlight = g_chatApi.getIcon(GC_EVENT_HIGHLIGHT), hIconMessage = g_chatApi.getIcon(GC_EVENT_MESSAGE);
HICON hNotifyIcon = (bManyFix && !bInactive) ? 0 : g_chatApi.getIcon(gce->iType);
BOOL bForcedIcon = (hNotifyIcon == hIconHighlight || hNotifyIcon == hIconMessage);
if ((gce->iType & si->iTrayFlags) || bForcedIcon) {
if (!bActiveTab) {
if (hNotifyIcon == hIconHighlight)
dat->m_iFlashIcon = hNotifyIcon;
else {
if (dat->m_iFlashIcon != hIconHighlight && dat->m_iFlashIcon != hIconMessage)
dat->m_iFlashIcon = hNotifyIcon;
}
dat->m_bCanFlashTab = TRUE;
dat->timerFlash.Start(TIMEOUT_FLASHWND);
}
}
if (dat->m_pWnd) {
dat->m_pWnd->updateIcon(hNotifyIcon);
dat->m_pWnd->setOverlayIcon(hNotifyIcon, true);
}
// autoswitch tab..
if (bMustAutoswitch) {
if ((IsIconic(dat->m_pContainer->m_hwnd)) && !IsZoomed(dat->m_pContainer->m_hwnd) && g_plugin.bAutoSwitchTabs && dat->m_pContainer->m_hwndActive != dat->GetHwnd()) {
int iItem = GetTabIndexFromHWND(dat->m_pContainer->m_hwndTabs, dat->GetHwnd());
if (iItem >= 0) {
TabCtrl_SetCurSel(dat->m_pContainer->m_hwndTabs, iItem);
ShowWindow(dat->m_pContainer->m_hwndActive, SW_HIDE);
dat->m_pContainer->m_hwndActive = dat->GetHwnd();
dat->m_pContainer->UpdateTitle(dat->m_hContact);
dat->m_pContainer->cfg.flags.m_bDeferredTabSelect = true;
}
}
}
// flash window if it is not focused
if (bMustFlash && bInactive)
if (!dat->m_pContainer->cfg.flags.m_bNoFlash)
dat->m_pContainer->FlashContainer(1, 0);
if (hNotifyIcon && bInactive && ((gce->iType & si->iTrayFlags) || bForcedIcon)) {
if (bMustFlash)
dat->m_hTabIcon = hNotifyIcon;
else if (dat->m_iFlashIcon) {
dat->m_hTabIcon = dat->m_iFlashIcon;
TCITEM item = {};
item.mask = TCIF_IMAGE;
item.iImage = 0;
TabCtrl_SetItem(GetParent(dat->GetHwnd()), dat->m_iTabID, &item);
}
HICON hIcon = (HICON)SendMessage(dat->m_pContainer->m_hwnd, WM_GETICON, ICON_BIG, 0);
if (hNotifyIcon == hIconHighlight || (hIcon != hIconMessage && hIcon != hIconHighlight)) {
dat->m_pContainer->SetIcon(dat, hNotifyIcon);
dat->m_pContainer->cfg.flags.m_bNeedsUpdateTitle = true;
}
}
if (bMustFlash && bInactive)
AddUnreadContact(dat->m_hContact);
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
char GetIndicator(SESSION_INFO *si, LPCTSTR ptszNick, int *iNickIndex)
{
if (iNickIndex)
*iNickIndex = 0;
for (auto &ui : si->getUserList()) {
if (!mir_wstrcmp(ui->pszNick, ptszNick)) {
STATUSINFO *ti = g_chatApi.TM_FindStatus(si->pStatuses, g_chatApi.TM_WordToString(si->pStatuses, ui->Status));
if (ti) {
if (iNickIndex)
*iNickIndex = ti->iIconIndex; // color table's index is not zero-based
return szIndicators[ti->iIconIndex];
}
break;
}
}
return 0;
}
bool IsHighlighted(SESSION_INFO *si, GCEVENT *gce)
{
if (!g_Settings.bHighlightEnabled || !gce || gce->bIsMe)
return false;
GCEVENT evTmp = *gce;
int dwMask = 0;
if (gce->pszText.w != nullptr)
dwMask |= CMUCHighlight::MATCH_TEXT;
if (gce->pszNick.w != nullptr) {
dwMask |= CMUCHighlight::MATCH_NICKNAME;
if (si && g_Settings.bLogClassicIndicators) {
size_t len = mir_wstrlen(gce->pszNick.w) + 1;
wchar_t *tmp = (wchar_t*)_alloca(sizeof(wchar_t)*(len + 1));
*tmp = GetIndicator(si, gce->pszNick.w, nullptr);
mir_wstrcpy(tmp + 1, gce->pszNick.w);
evTmp.pszNick.w = tmp;
}
}
return g_Settings.Highlight->match(&evTmp, si, dwMask);
}
|