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
|
/*
Favorite Contacts for Miranda IM
Copyright 2007 Victor Pavlychko
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"
static MCONTACT hContactToActivate;
static MWindowList hDialogsList;
INT_PTR svcShowMenu(WPARAM, LPARAM)
{
ShowMenu(false);
return 0;
}
INT_PTR svcShowMenuCentered(WPARAM, LPARAM)
{
ShowMenu(g_Options.bCenterHotkey ? true : false);
return 0;
}
INT_PTR svcOpenContact(WPARAM wParam, LPARAM)
{
hContactToActivate = wParam;
Clist_ContactDoubleClicked(hContactToActivate);
return 0;
}
int ProcessSrmmEvent(WPARAM, LPARAM lParam)
{
MessageWindowEventData *event = (MessageWindowEventData *)lParam;
if (event->uType == MSG_WINDOW_EVT_OPEN) {
if (!hDialogsList)
hDialogsList = WindowList_Create();
WindowList_Add(hDialogsList, event->hwndWindow, event->hContact);
BYTE fav = db_get_b(event->hContact, "FavContacts", "IsFavourite", 0);
StatusIconData sid = { sizeof(sid) };
sid.szModule = "FavContacts";
sid.flags = fav ? 0 : MBF_DISABLED;
Srmm_ModifyIcon(event->hContact, &sid);
if (event->hContact == hContactToActivate) {
HWND hwndRoot = event->hwndWindow;
while (HWND hwndParent = GetParent(hwndRoot))
hwndRoot = hwndParent;
AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), NULL), GetCurrentThreadId(), TRUE);
SetForegroundWindow(hwndRoot);
SetActiveWindow(hwndRoot);
SetFocus(hwndRoot);
AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), NULL), GetCurrentThreadId(), FALSE);
}
hContactToActivate = NULL;
}
else if (event->uType == MSG_WINDOW_EVT_CLOSING) {
if (hDialogsList)
WindowList_Remove(hDialogsList, event->hwndWindow);
}
return 0;
}
int ProcessSrmmIconClick(WPARAM hContact, LPARAM lParam)
{
StatusIconClickData *sicd = (StatusIconClickData *)lParam;
if (mir_strcmp(sicd->szModule, "FavContacts")) return 0;
if (!hContact)
return 0;
if (sicd->flags & MBCF_RIGHTBUTTON) {
BYTE fav = !db_get_b(hContact, "FavContacts", "IsFavourite", 0);
db_set_b(hContact, "FavContacts", "IsFavourite", fav);
if (fav) CallService(MS_AV_GETAVATARBITMAP, hContact, 0);
StatusIconData sid = { sizeof(sid) };
sid.szModule = "FavContacts";
sid.flags = fav ? 0 : MBF_DISABLED;
Srmm_ModifyIcon(hContact, &sid);
}
else ShowMenu(false);
return 0;
}
static __forceinline COLORREF sttShadeColor(COLORREF clLine1, COLORREF clBack)
{
return RGB(
(GetRValue(clLine1) * 66UL + GetRValue(clBack) * 34UL) / 100,
(GetGValue(clLine1) * 66UL + GetGValue(clBack) * 34UL) / 100,
(GetBValue(clLine1) * 66UL + GetBValue(clBack) * 34UL) / 100);
}
int ProcessTBLoaded(WPARAM, LPARAM)
{
TTBButton ttb = { 0 };
ttb.pszTooltipUp = ttb.name = LPGEN("Favorite Contacts");
ttb.pszService = MS_FAVCONTACTS_SHOWMENU;
ttb.dwFlags = TTBBF_SHOWTOOLTIP | TTBBF_VISIBLE;
ttb.hIconHandleUp = iconList[0].hIcolib;
TopToolbar_AddButton(&ttb);
return 0;
}
int ProcessReloadFonts(WPARAM, LPARAM)
{
if (g_Options.hfntName) DeleteObject(g_Options.hfntName);
if (g_Options.hfntSecond) DeleteObject(g_Options.hfntSecond);
LOGFONT lf = { 0 };
FontIDW fontid = { sizeof(fontid) };
mir_wstrcpy(fontid.group, LPGENW("Favorite Contacts"));
mir_wstrcpy(fontid.name, LPGENW("Contact name"));
g_Options.clLine1 = CallService(MS_FONT_GETW, (WPARAM)&fontid, (LPARAM)&lf);
g_Options.hfntName = CreateFontIndirect(&lf);
mir_wstrcpy(fontid.name, LPGENW("Second line"));
g_Options.clLine2 = CallService(MS_FONT_GETW, (WPARAM)&fontid, (LPARAM)&lf);
g_Options.hfntSecond = CreateFontIndirect(&lf);
mir_wstrcpy(fontid.name, LPGENW("Selected contact name (color)"));
g_Options.clLine1Sel = CallService(MS_FONT_GETW, (WPARAM)&fontid, (LPARAM)&lf);
mir_wstrcpy(fontid.name, LPGENW("Selected second line (color)"));
g_Options.clLine2Sel = CallService(MS_FONT_GETW, (WPARAM)&fontid, (LPARAM)&lf);
ColourIDW colourid = { sizeof(colourid) };
mir_wstrcpy(colourid.group, LPGENW("Favorite Contacts"));
mir_wstrcpy(colourid.name, LPGENW("Background"));
g_Options.clBack = CallService(MS_COLOUR_GETW, (WPARAM)&colourid, (LPARAM)&lf);
mir_wstrcpy(colourid.name, LPGENW("Selected background"));
g_Options.clBackSel = CallService(MS_COLOUR_GETW, (WPARAM)&colourid, (LPARAM)&lf);
return 0;
}
int ProcessModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_TTB_MODULELOADED, ProcessTBLoaded);
StatusIconData sid = { sizeof(sid) };
sid.szModule = "FavContacts";
sid.szTooltip = LPGEN("Favorite Contacts");
sid.hIcon = IcoLib_GetIconByHandle(iconList[0].hIcolib);
sid.hIconDisabled = IcoLib_GetIconByHandle(iconList[1].hIcolib);
Srmm_AddIcon(&sid);
HookEvent(ME_MSG_ICONPRESSED, ProcessSrmmIconClick);
HookEvent(ME_MSG_WINDOWEVENT, ProcessSrmmEvent);
/////////////////////////////////////////////////////////////////////////////////////
FontIDW fontid = { sizeof(fontid) };
mir_wstrcpy(fontid.group, LPGENW("Favorite Contacts"));
mir_strcpy(fontid.dbSettingsGroup, "FavContacts");
mir_wstrcpy(fontid.backgroundGroup, LPGENW("Favorite Contacts"));
fontid.flags = FIDF_DEFAULTVALID;
fontid.deffontsettings.charset = DEFAULT_CHARSET;
fontid.deffontsettings.size = -11;
mir_wstrcpy(fontid.deffontsettings.szFace, L"MS Shell Dlg");
fontid.deffontsettings.style = 0;
mir_wstrcpy(fontid.backgroundName, LPGENW("Background"));
mir_wstrcpy(fontid.name, LPGENW("Contact name"));
mir_strcpy(fontid.prefix, "fntName");
fontid.deffontsettings.colour = GetSysColor(COLOR_MENUTEXT);
fontid.deffontsettings.style = DBFONTF_BOLD;
FontRegisterW(&fontid);
mir_wstrcpy(fontid.name, LPGENW("Second line"));
mir_strcpy(fontid.prefix, "fntSecond");
fontid.deffontsettings.colour = sttShadeColor(GetSysColor(COLOR_MENUTEXT), GetSysColor(COLOR_MENU));
fontid.deffontsettings.style = 0;
FontRegisterW(&fontid);
mir_wstrcpy(fontid.backgroundName, LPGENW("Selected background"));
mir_wstrcpy(fontid.name, LPGENW("Selected contact name (color)"));
mir_strcpy(fontid.prefix, "fntNameSel");
fontid.deffontsettings.colour = GetSysColor(COLOR_HIGHLIGHTTEXT);
fontid.deffontsettings.style = DBFONTF_BOLD;
FontRegisterW(&fontid);
mir_wstrcpy(fontid.name, LPGENW("Selected second line (color)"));
mir_strcpy(fontid.prefix, "fntSecondSel");
fontid.deffontsettings.colour = sttShadeColor(GetSysColor(COLOR_HIGHLIGHTTEXT), GetSysColor(COLOR_HIGHLIGHT));
fontid.deffontsettings.style = 0;
FontRegisterW(&fontid);
/////////////////////////////////////////////////////////////////////////////////////
ColourIDW colourid = { sizeof(colourid) };
mir_wstrcpy(colourid.group, LPGENW("Favorite Contacts"));
mir_strcpy(colourid.dbSettingsGroup, "FavContacts");
mir_wstrcpy(colourid.name, LPGENW("Background"));
mir_strcpy(colourid.setting, "BackColour");
colourid.defcolour = GetSysColor(COLOR_MENU);
ColourRegisterW(&colourid);
mir_wstrcpy(colourid.name, LPGENW("Selected background"));
mir_strcpy(colourid.setting, "SelectedColour");
colourid.defcolour = GetSysColor(COLOR_HIGHLIGHT);
ColourRegisterW(&colourid);
HookEvent(ME_FONT_RELOAD, ProcessReloadFonts);
HookEvent(ME_COLOUR_RELOAD, ProcessReloadFonts);
ProcessReloadFonts(0, 0);
/////////////////////////////////////////////////////////////////////////////////////
HOTKEYDESC hotkey = { sizeof(hotkey) };
hotkey.pszName = "FavContacts/ShowMenu";
hotkey.pszDescription = LPGEN("Show favorite contacts");
hotkey.pszSection = "Contacts";
hotkey.pszService = MS_FAVCONTACTS_SHOWMENU_CENTERED;
hotkey.DefHotKey = MAKEWORD('Q', HOTKEYF_EXT);
Hotkey_Register(&hotkey);
if (ServiceExists(MS_AV_GETAVATARBITMAP)) {
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
if (db_get_b(hContact, "FavContacts", "IsFavourite", 0))
CallService(MS_AV_GETAVATARBITMAP, hContact, 0);
}
return 0;
}
void InitServices()
{
CreateServiceFunction(MS_FAVCONTACTS_SHOWMENU, svcShowMenu);
CreateServiceFunction(MS_FAVCONTACTS_SHOWMENU_CENTERED, svcShowMenuCentered);
CreateServiceFunction(MS_FAVCONTACTS_OPEN_CONTACT, svcOpenContact);
HookEvent(ME_OPT_INITIALISE, ProcessOptInitialise);
HookEvent(ME_SYSTEM_MODULESLOADED, ProcessModulesLoaded);
}
void UninitServices()
{
WindowList_Destroy(hDialogsList);
}
|