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
|
/*
Popup Plus plugin for Miranda IM
Copyright © 2002 Luca Santarelli,
© 2004-2007 Victor Pavlychko
© 2010 MPK
© 2010 Merlin_de
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 "headers.h"
static int ActionsSortFunc(const POPUPACTION *p1, const POPUPACTION *p2)
{
return mir_strcmp(p1->lpzTitle, p2->lpzTitle);
}
static LIST<POPUPACTION> gActions(3, ActionsSortFunc);
// interface
void LoadActions()
{
POPUPACTION actions[] =
{
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_REPLY, 0), LPGEN("General")"/"LPGEN("Quick reply"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_MESS, 0), LPGEN("General")"/"LPGEN("Send message"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_INFO, 0), LPGEN("General")"/"LPGEN("User details"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_MENU, 0), LPGEN("General")"/"LPGEN("Contact menu"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_ADD, 0), LPGEN("General")"/"LPGEN("Add permanently"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_PIN, 0), LPGEN("General")"/"LPGEN("Pin popup"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_CLOSE, 0), LPGEN("General")"/"LPGEN("Dismiss popup"), 0 },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_COPY, 0), LPGEN("General")"/"LPGEN("Copy to clipboard"), 0 },
// remove popup action
#if defined(_DEBUG)
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_POPUP_ON, 0), "Popup Plus/Test action", PAF_ENABLED },
{ sizeof(POPUPACTION), IcoLib_GetIcon(ICO_ACT_CLOSE, 0), "Popup Plus/Second test action", 0 },
{ sizeof(POPUPACTION), Skin_LoadIcon(SKINICON_OTHER_MIRANDA), "Popup Plus/One more action", PAF_ENABLED },
#endif
};
for (int i = 0; i < SIZEOF(actions); ++i)
RegisterAction(&actions[i]);
}
void UnloadActions()
{
for (int i = 0; i < gActions.getCount(); ++i)
delete gActions[i];
gActions.destroy();
}
void RegisterAction(POPUPACTION *action)
{
int index;
if ((index = gActions.getIndex(action)) >= 0) {
DWORD flags = gActions[index]->flags;
*gActions[index] = *action;
gActions[index]->flags = flags;
}
else {
POPUPACTION *actionCopy = new POPUPACTION;
*actionCopy = *action;
actionCopy->flags = db_get_b(NULL, "PopupActions", actionCopy->lpzTitle, actionCopy->flags & PAF_ENABLED) ? PAF_ENABLED : 0;
gActions.insert(actionCopy);
}
}
bool IsActionEnabled(POPUPACTION *action)
{
if (!(action->flags & PAF_ENABLED))
return false;
int index;
if ((index = gActions.getIndex(action)) >= 0)
if (!(gActions[index]->flags & PAF_ENABLED))
return false;
return true;
}
bool IsActionEnabled(char *name)
{
POPUPACTION action = { 0 };
action.flags = PAF_ENABLED;
mir_strcpy(action.lpzTitle, name);
return IsActionEnabled(&action);
}
DWORD MouseOverride(HWND hCombo, int number)
{
DWORD dwItem = 0;
DWORD ItemActive = 0;
if (number < 0 || number > 7)
number = 0;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("No overwrite"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 0);
if (number == 0)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("Send message"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 1);
if (number == 1)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("Quick reply"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 2);
if (number == 2)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("User details"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 3);
if (number == 3)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("Contact menu"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 4);
if (number == 4)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("Dismiss popup"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 5);
if (number == 5)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("Pin popup"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 6);
if (number == 6)
ItemActive = dwItem;
dwItem = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)TranslateT("Copy to clipboard"));
SendMessage(hCombo, CB_SETITEMDATA, dwItem, 7);
if (number == 7)
ItemActive = dwItem;
return ItemActive;
}
// options
void LoadOption_Actions()
{
PopupOptions.actions = db_get_dw(NULL, MODULNAME, "Actions",
ACT_ENABLE | ACT_RIGHTICONS | ACT_DEF_KEEPWND | ACT_DEF_IMONLY |
ACT_DEF_NOGLOBAL | ACT_DEF_MESSAGE | ACT_DEF_DETAILS | ACT_DEF_MENU |
ACT_DEF_ADD | ACT_DEF_DISMISS | ACT_DEF_PIN);
PopupOptions.overrideLeft = db_get_dw(NULL, MODULNAME, "OverrideLeft", 0);
PopupOptions.overrideMiddle = db_get_dw(NULL, MODULNAME, "OverrideMiddle", 0);
PopupOptions.overrideRight = db_get_dw(NULL, MODULNAME, "OverrideRight", 0);
}
static UINT controls[] =
{
IDC_GRP_CUSTOMACTIONS,
IDC_TXT_CUSTOMACTIONS,
IDC_CHK_IMCONTACTSONLY,
IDC_CHK_CONTACTSONLY,
IDC_CHK_DONTCLOSE,
IDC_GRP_SIZEPOSITION,
IDC_CHK_LARGEICONS,
IDC_TXT_POSITION,
IDC_RD_TEXT,
IDC_RD_LEFTICONS,
IDC_RD_RIGHTICONS,
IDC_GRP_ACTIONS,
IDC_ACTIONS,
IDC_GRP_SIZEPOSITION2,
IDC_TXT_POSITION2,
IDC_CB_LEFT,
IDC_TXT_MIDDLE,
IDC_CB_MIDDLE,
IDC_TXT_RIGHT,
IDC_CB_RIGHT
};
INT_PTR CALLBACK DlgProcPopupActions(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static bool windowInitialized = false;
int i;
switch (msg) {
case WM_INITDIALOG:
windowInitialized = false;
TranslateDialogDefault(hwnd);
SendDlgItemMessage(hwnd, IDC_ICO_INFO, STM_SETICON, (WPARAM)IcoLib_GetIcon(ICO_MISC_NOTIFY, 0), 0);
CheckDlgButton(hwnd, IDC_CHK_ENABLEACTIONS, PopupOptions.actions & ACT_ENABLE ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_CHK_IMCONTACTSONLY, PopupOptions.actions & ACT_DEF_IMONLY ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_CHK_CONTACTSONLY, PopupOptions.actions & ACT_DEF_NOGLOBAL ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_CHK_DONTCLOSE, PopupOptions.actions & ACT_DEF_KEEPWND ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_CHK_LARGEICONS, PopupOptions.actions & ACT_LARGE ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_RD_TEXT, PopupOptions.actions & ACT_TEXT ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_RD_LEFTICONS, PopupOptions.actions & ACT_LEFTICONS ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_RD_RIGHTICONS, PopupOptions.actions & ACT_RIGHTICONS ? BST_CHECKED : BST_UNCHECKED);
{
DWORD dwActiveItem = 0;
HWND hCombo = GetDlgItem(hwnd, IDC_CB_LEFT);
dwActiveItem = MouseOverride(hCombo, PopupOptions.overrideLeft);
SendDlgItemMessage(hwnd, IDC_CB_LEFT, CB_SETCURSEL, dwActiveItem, 0);
dwActiveItem = 0;
hCombo = GetDlgItem(hwnd, IDC_CB_MIDDLE);
dwActiveItem = MouseOverride(hCombo, PopupOptions.overrideMiddle);
SendDlgItemMessage(hwnd, IDC_CB_MIDDLE, CB_SETCURSEL, dwActiveItem, 0);
dwActiveItem = 0;
hCombo = GetDlgItem(hwnd, IDC_CB_RIGHT);
dwActiveItem = MouseOverride(hCombo, PopupOptions.overrideRight);
SendDlgItemMessage(hwnd, IDC_CB_RIGHT, CB_SETCURSEL, dwActiveItem, 0);
HWND hwndList = GetDlgItem(hwnd, IDC_ACTIONS);
ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_LABELTIP);
HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 10, 1);
ListView_SetImageList(hwndList, hImgList, LVSIL_SMALL);
LVCOLUMN column = { 0 };
column.mask = LVCF_TEXT | LVCF_WIDTH;
column.pszText = TranslateT("Action");
column.cx = 175;
ListView_InsertColumn(hwndList, 0, &column);
ListView_EnableGroupView(hwndList, TRUE);
LIST<char> groups(1, strcmp);
for (i = 0; i < gActions.getCount(); ++i) {
char szGroup[64];
char *szName = strchr(gActions[i]->lpzTitle, '/');
if (!szName) szName = gActions[i]->lpzTitle;
else ++szName;
mir_strncpy(szGroup, gActions[i]->lpzTitle, szName - gActions[i]->lpzTitle);
int grpId = 0;
if ((grpId = groups.getIndex(szGroup)) < 0) {
LVGROUP group = { 0 };
group.cbSize = sizeof(group);
group.mask = LVGF_HEADER | LVGF_GROUPID;
LPTSTR wszGroup = mir_a2t(szGroup);
group.pszHeader = TranslateTS(wszGroup);
group.cchHeader = (int)mir_tstrlen(wszGroup);
grpId = group.iGroupId = groups.getCount();
ListView_InsertGroup(hwndList, -1, &group);
mir_free(wszGroup);
groups.insert(mir_strdup(szGroup), groups.getCount());
}
LVITEM item = { 0 };
item.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT | LVIF_STATE | LVIF_INDENT;
item.iItem = i;
ptrT tszName(mir_a2t(szName));
item.pszText = TranslateTS(tszName);
item.iImage = ImageList_AddIcon(hImgList, gActions[i]->lchIcon);
item.lParam = i;
item.mask |= LVIF_GROUPID;
item.iGroupId = grpId;
item.iIndent = 0;
ListView_InsertItem(hwndList, &item);
ListView_SetItemState(hwndList, i, (gActions[i]->flags & PAF_ENABLED) ? 0x2000 : 0x1000, LVIS_STATEIMAGEMASK);
}
BOOL enabled = (PopupOptions.actions & ACT_ENABLE) ? TRUE : FALSE;
for (i = 0; i < SIZEOF(controls); ++i)
EnableWindow(GetDlgItem(hwnd, controls[i]), enabled);
}
windowInitialized = true;
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_CHK_ENABLEACTIONS:
PopupOptions.actions &= ~ACT_ENABLE;
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_CHK_ENABLEACTIONS) ? ACT_ENABLE : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
{
BOOL enabled = (PopupOptions.actions & ACT_ENABLE) ? TRUE : FALSE;
for (i = 0; i < SIZEOF(controls); ++i)
EnableWindow(GetDlgItem(hwnd, controls[i]), enabled);
}
break;
case IDC_CHK_IMCONTACTSONLY:
PopupOptions.actions &= ~ACT_DEF_IMONLY;
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_CHK_IMCONTACTSONLY) ? ACT_DEF_IMONLY : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_CHK_CONTACTSONLY:
PopupOptions.actions &= ~ACT_DEF_NOGLOBAL;
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_CHK_CONTACTSONLY) ? ACT_DEF_NOGLOBAL : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_CHK_DONTCLOSE:
PopupOptions.actions &= ~ACT_DEF_KEEPWND;
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_CHK_DONTCLOSE) ? ACT_DEF_KEEPWND : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_CHK_LARGEICONS:
PopupOptions.actions &= ~ACT_LARGE;
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_CHK_LARGEICONS) ? ACT_LARGE : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_RD_TEXT:
PopupOptions.actions &= ~(ACT_TEXT | ACT_LEFTICONS | ACT_RIGHTICONS);
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_CHK_ENABLEACTIONS) ? ACT_TEXT : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_RD_LEFTICONS:
PopupOptions.actions &= ~(ACT_TEXT | ACT_LEFTICONS | ACT_RIGHTICONS);
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_RD_LEFTICONS) ? ACT_LEFTICONS : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_RD_RIGHTICONS:
PopupOptions.actions &= ~(ACT_TEXT | ACT_LEFTICONS | ACT_RIGHTICONS);
PopupOptions.actions |= IsDlgButtonChecked(hwnd, IDC_RD_RIGHTICONS) ? ACT_RIGHTICONS : 0;
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
case IDC_PREVIEW:
PopupPreview();
break;
case IDC_CB_LEFT:
case IDC_CB_MIDDLE:
case IDC_CB_RIGHT:
PopupOptions.overrideLeft = SendDlgItemMessage(hwnd, IDC_CB_LEFT, CB_GETITEMDATA,
SendDlgItemMessage(hwnd, IDC_CB_LEFT, CB_GETCURSEL, 0, 0), 0);
PopupOptions.overrideMiddle = SendDlgItemMessage(hwnd, IDC_CB_MIDDLE, CB_GETITEMDATA,
SendDlgItemMessage(hwnd, IDC_CB_MIDDLE, CB_GETCURSEL, 0, 0), 0);
PopupOptions.overrideRight = SendDlgItemMessage(hwnd, IDC_CB_RIGHT, CB_GETITEMDATA,
SendDlgItemMessage(hwnd, IDC_CB_RIGHT, CB_GETCURSEL, 0, 0), 0);
if (HIWORD(wParam) == CBN_SELCHANGE)
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
}
break;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->idFrom) {
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_RESET:
LoadOption_Actions();
break;
case PSN_APPLY:
db_set_dw(NULL, MODULNAME, "Actions", PopupOptions.actions);
HWND hwndList = GetDlgItem(hwnd, IDC_ACTIONS);
for (i = 0; i < gActions.getCount(); ++i) {
gActions[i]->flags = (ListView_GetItemState(hwndList, i, LVIS_STATEIMAGEMASK) == 0x2000) ? PAF_ENABLED : 0;
db_set_b(NULL, "PopupActions", gActions[i]->lpzTitle, (gActions[i]->flags & PAF_ENABLED) ? 1 : 0);
}
// overrideActions
db_set_dw(NULL, MODULNAME, "OverrideLeft", PopupOptions.overrideLeft);
db_set_dw(NULL, MODULNAME, "OverrideMiddle", PopupOptions.overrideMiddle);
db_set_dw(NULL, MODULNAME, "OverrideRight", PopupOptions.overrideRight);
}
break;
case IDC_ACTIONS:
NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
if (windowInitialized && nmlv && nmlv->hdr.code == LVN_ITEMCHANGED && nmlv->uOldState != 0 && (nmlv->uNewState == 0x1000 || nmlv->uNewState == 0x2000))
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
}
}
return FALSE;
}
|