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
|
#include "stdafx.h"
static int hMenuObject;
static HANDLE hEventPreBuildMenu;
static HGENMENU hmiHistory, hmiCopy, hmiSaveAs, hmiDownload;
HMENU NSMenu_Build(ItemData *item)
{
if (item->m_bOfflineFile) {
Menu_ModifyItem(hmiCopy, (item->m_bOfflineDownloaded) ? TranslateT("Copy file name") : TranslateT("Copy URL"));
Menu_ShowItem(hmiSaveAs, true);
Menu_ShowItem(hmiDownload, !item->m_bOfflineDownloaded);
}
else {
Menu_ShowItem(hmiSaveAs, false);
Menu_ShowItem(hmiDownload, false);
}
NotifyEventHooks(hEventPreBuildMenu, item->hContact, (LPARAM)&item->dbe);
HMENU hMenu = CreatePopupMenu();
Menu_Build(hMenu, hMenuObject);
return hMenu;
}
bool NSMenu_Process(int iCommand, NewstoryListData *data)
{
return Menu_ProcessCommandById(iCommand, LPARAM(data)) != 0;
}
static INT_PTR NSMenuHelper(WPARAM wParam, LPARAM lParam)
{
auto *pData = (NewstoryListData *)lParam;
switch (wParam) {
case 1:
SendMessage(pData->hwnd, NSM_COPY, 0, 0);
break;
case 2:
pData->BeginEditItem(pData->caret, false);
break;
case 3:
pData->DeleteItems();
break;
case 4:
SendMessage(pData->hwnd, NSM_SELECTITEMS, 0, pData->totalCount - 1);
break;
case 5:
SendMessage(pData->hwnd, NSM_DOWNLOAD, 0, OFD_SAVEAS | OFD_RUN);
break;
case 6:
SendMessage(pData->hwnd, NSM_DOWNLOAD, 0, OFD_DOWNLOAD);
break;
default:
if (auto *pDlg = pData->pMsgDlg) {
PostMessage(pDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0);
Chat_DoEventHook(pDlg->getChat(), GC_USER_LOGMENU, nullptr, nullptr, wParam);
}
}
return 0;
}
static INT_PTR NSMenuAddService(WPARAM wParam, LPARAM lParam)
{
auto *pmi = (TMO_MenuItem *)wParam;
if (pmi == nullptr)
return 0;
auto *mmep = (NSMenuExecParam *)mir_calloc(sizeof(NSMenuExecParam));
if (mmep == nullptr)
return 0;
// we need just one parametr.
mmep->szServiceName = mir_strdup(pmi->pszService);
mmep->iParam = lParam;
HGENMENU hNewItem = Menu_AddItem(hMenuObject, pmi, mmep);
char buf[1024];
mir_snprintf(buf, "%s/%s", pmi->pszService, pmi->name.a);
Menu_ConfigureItem(hNewItem, MCI_OPT_UNIQUENAME, buf);
return (INT_PTR)hNewItem;
}
static INT_PTR NSMenuExecService(WPARAM wParam, LPARAM lParam)
{
if (auto *pParam = (NSMenuExecParam *)wParam)
CallService(pParam->szServiceName, pParam->iParam, lParam);
return 0;
}
static INT_PTR NSMenuFreeOwnerData(WPARAM, LPARAM lParam)
{
if (auto *param = (NSMenuExecParam *)lParam) {
mir_free(param->szServiceName);
mir_free(param);
}
return 0;
}
static int OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
Menu_ShowItem(hmiHistory, db_event_first(hContact) != 0);
return 0;
}
void InitMenus()
{
{ // Contact menu items
CMenuItem mi(&g_plugin);
SET_UID(mi, 0xc20d7a69, 0x7607, 0x4aad, 0xa7, 0x42, 0x10, 0x86, 0xfb, 0x32, 0x49, 0x21);
mi.name.a = LPGEN("User history");
mi.position = 1000090000;
mi.pszService = MS_HISTORY_SHOWCONTACTHISTORY;
mi.hIcolibItem = g_plugin.getIconHandle(ICO_NEWSTORY);
hmiHistory = Menu_AddContactMenuItem(&mi);
CreateServiceFunction(mi.pszService, svcShowNewstory);
HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu);
// Main menu items
SET_UID(mi, 0x1848519e, 0x639d, 0x497a, 0xa5, 0x37, 0x6b, 0x76, 0x17, 0x2a, 0x6, 0xd9);
mi.name.a = LPGEN("Global search");
mi.position = 500060001;
mi.pszService = "NewStory/GlobalSearch";
Menu_AddMainMenuItem(&mi);
CreateServiceFunction(mi.pszService, svcGlobalSearch);
}
// Init history item's menu
CreateServiceFunction("NSMenu/Helper", NSMenuHelper);
CreateServiceFunction("NSMenu/AddService", NSMenuAddService);
CreateServiceFunction("NSMenu/ExecService", NSMenuExecService);
CreateServiceFunction("NSMenu/FreeOwnerData", NSMenuFreeOwnerData);
hEventPreBuildMenu = CreateHookableEvent(ME_NS_PREBUILDMENU);
hMenuObject = Menu_AddObject("NSMenu", "NewStory item menu", nullptr, "NSMenu/ExecService");
Menu_ConfigureObject(hMenuObject, MCO_OPT_USERDEFINEDITEMS, INT_PTR(FALSE));
Menu_ConfigureObject(hMenuObject, MCO_OPT_FREE_SERVICE, INT_PTR("NSMenu/FreeOwnerData"));
Menu_ConfigureObject(hMenuObject, MCO_OPT_ONADD_SERVICE, INT_PTR("NSMenu/OnAddService"));
CMenuItem mi(&g_plugin);
mi.pszService = "NSMenu/Helper";
mi.position = 100000;
mi.name.a = LPGEN("Copy");
hmiCopy = Menu_AddNewStoryMenuItem(&mi, 1);
mi.position = 100001;
mi.name.a = LPGEN("Save as");
hmiSaveAs = Menu_AddNewStoryMenuItem(&mi, 5);
mi.position = 100002;
mi.name.a = LPGEN("Download");
hmiDownload = Menu_AddNewStoryMenuItem(&mi, 6);
mi.position = 200000;
mi.name.a = LPGEN("Edit");
Menu_AddNewStoryMenuItem(&mi, 2);
mi.position = 200001;
mi.name.a = LPGEN("Delete");
Menu_AddNewStoryMenuItem(&mi, 3);
mi.position = 300000;
mi.name.a = LPGEN("Select all");
Menu_AddNewStoryMenuItem(&mi, 4);
}
|