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
|
/*
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.
===============================================================================
File name : $HeadURL: http://svn.miranda.im/mainrepo/popup/trunk/src/config.cpp $
Revision : $Revision: 1651 $
Last change on : $Date: 2010-07-15 20:31:06 +0300 (Чт, 15 июл 2010) $
Last change by : $Author: Merlin_de $
===============================================================================
*/
#include "headers.h"
//===== General Plugin =====
HINSTANCE hInst;
HANDLE hMainThread;
//MNOTIFYLINK *notifyLink; //deprecatet
PLUGINLINK *pluginLink;
HANDLE hSemaphore;
BOOL closing = FALSE;
MM_INTERFACE mmi;
LIST_INTERFACE li;
UTF8_INTERFACE utfi;
MTEXT_INTERFACE MText = {0};
HANDLE folderId;
BOOL gbPopupLoaded = FALSE;
BOOL gbHppInstalled = FALSE;
LPCSTR gszMetaProto = "";
//===== Brushes, Colours and Fonts =====
HBITMAP hbmNoAvatar;
//===== Options =====
POPUPOPTIONS PopUpOptions;
//SKINELEMENT *skin;
//SKINELEMENT *w_skin;
//SKINELEMENT *n_skin;
//===== Plugin information =====
PLUGININFOEX pluginInfoEx =
{
sizeof(PLUGININFOEX),
POPUP_DISPLAYNAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM),
POPUP_DESCRIPTION,
POPUP_AUTHOR,
POPUP_EMAIL,
POPUP_COPYRIGHT,
POPUP_WEBPAGE,
0,
0,
POPUP_UUID
};
PLUGININFO pluginInfo =
{
sizeof(PLUGININFO),
pluginInfoEx.shortName,
pluginInfoEx.version,
pluginInfoEx.description,
pluginInfoEx.author,
pluginInfoEx.authorEmail,
pluginInfoEx.copyright,
pluginInfoEx.homepage,
pluginInfoEx.flags,
pluginInfoEx.replacesDefaultModule
};
// MLU layer for ansi release
#if !defined(_UNICODE)
BOOL (WINAPI *MySetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
BOOL (WINAPI *MyAnimateWindow)(HWND hWnd,DWORD dwTime,DWORD dwFlags);
BOOL (WINAPI *MyGetMonitorInfo)(HMONITOR hMonitor, LPMONITORINFO lpmi);
BOOL (WINAPI *MyUpdateLayeredWindow)
(HWND hwnd, HDC hdcDST, POINT *pptDst, SIZE *psize, HDC hdcSrc, POINT *pptSrc,
COLORREF crKey, BLENDFUNCTION *pblend, DWORD dwFlags);
HMONITOR (WINAPI *MyMonitorFromWindow)(HWND hWnd, DWORD dwFlags);
BOOL (WINAPI *MyTransparentBlt)(HDC, int, int, int, int, HDC, int, int, int, int, UINT);
BOOL (WINAPI *MyAlphaBlend)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION);
// gdi32.dll
BOOL (WINAPI *MyGetTextExtentPoint32W)(HDC, LPCWSTR, int, LPSIZE);
//user32.dll
int (WINAPI *MyDrawTextW)(HDC, LPCWSTR, int, LPRECT, UINT);
int (WINAPI *MyDrawTextExW)(HDC, LPCWSTR, int, LPRECT, UINT, LPDRAWTEXTPARAMS);
BOOL (WINAPI *MySetWindowTextW)(HWND, LPCWSTR);
LRESULT (WINAPI *MySendMessageW)(HWND, UINT, WPARAM, LPARAM);
LRESULT (WINAPI *MyCallWindowProcW)(WNDPROC, HWND, UINT, WPARAM, LPARAM);
HWND (WINAPI *MyCreateWindowExW)(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
#endif
HRESULT (WINAPI *MyDwmEnableBlurBehindWindow)(HWND hWnd, DWM_BLURBEHIND *pBlurBehind);
//====== Common Vars ========================
static int NukePopupSettings(const char* szModul);
static INT_PTR __stdcall DlgProcPopupWelcome(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
{
TranslateDialogDefault(hwnd);
LOGFONT lf;
GetObject((HFONT)SendMessage(GetDlgItem(hwnd, IDC_TITLE), WM_GETFONT, 0, 0), sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
lf.lfHeight *= 1.8;
SendMessage(GetDlgItem(hwnd, IDC_TITLE), WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), TRUE);
GetObject((HFONT)SendMessage(GetDlgItem(hwnd, IDC_VERSION), WM_GETFONT, 0, 0), sizeof(lf), &lf);
lf.lfHeight *= 1.3;
SendMessage(GetDlgItem(hwnd, IDC_VERSION), WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), TRUE);
SetWindowText(GetDlgItem(hwnd, IDC_VERSION), _T(__VERSION_STRING_DOT));
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDR_WHATSNEW), _T("TEXT"));
DWORD ResSize = SizeofResource(hInst,hRes);
HRSRC hResLoad = (HRSRC)LoadResource(hInst, hRes);
char *lpResLock = (char *)LockResource(hResLoad);
// lpResLock [ResSize] = 0;
TCHAR* ptszMsg = mir_a2t(lpResLock);
SetWindowText(GetDlgItem(hwnd, IDC_WHATSNEW), ptszMsg);
mir_free(ptszMsg);
UnlockResource(lpResLock);
FreeResource(hRes);
CheckDlgButton(hwnd, IDC_NONEWS, DBGetContactSettingByte(NULL, MODULNAME, "NeverShowNews", 0));
return TRUE;
}
case WM_CTLCOLORSTATIC:
{
if (GetWindowLongPtr((HWND)lParam, GWLP_ID) != IDC_NONEWS)
return (INT_PTR)GetStockObject(WHITE_BRUSH);
break;
}
case WM_COMMAND:
{
switch (LOWORD(wParam)) // control id
{
case ID_OK:
{
DBWriteContactSettingByte(NULL, MODULNAME, "NeverShowNews", IsDlgButtonChecked(hwnd, IDC_NONEWS)?1:0);
SendMessage(hwnd, WM_CLOSE, 0, 0);
return TRUE;
}
case IDC_RESET:
{
if (MessageBox(hwnd, TranslateT("Do you really want to reset Popup Plus settings?"), _T(MODULNAME_LONG), MB_ICONWARNING|MB_YESNO) == IDYES)
{
NukePopupSettings(MODULNAME);
OptionLoaded = false;
LoadOptions();
}
return TRUE;
}
}
break;
}
case WM_CLOSE:
{
DestroyWindow(hwnd);
return TRUE;
}
}
return FALSE;
}
// common funcs
void LoadOptions() {
ZeroMemory(&PopUpOptions, sizeof(PopUpOptions));
#if defined(_DEBUG)
PopUpOptions.debug = DBGetContactSettingByte(NULL, MODULNAME, "debug", FALSE);
#endif
DWORD prevVersion = DBGetContactSettingDword(NULL, MODULNAME, "PopupPlusVersion", 0);
if ( (prevVersion < pluginInfo.version) &&
!PopUpOptions.debug &&
!DBGetContactSettingByte(NULL, MODULNAME, "NeverShowNews", 0)
) {
HWND hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_WELCOME), NULL, DlgProcPopupWelcome, prevVersion);
RECT rc, rcDesk;
GetWindowRect(hwnd, &rc);
SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesk, 0);
SetWindowPos(hwnd, HWND_TOP,
rcDesk.left + (rcDesk.right - rcDesk.left - (rc.right - rc.left)) / 2,
rcDesk.top + (rcDesk.bottom - rcDesk.top - (rc.bottom - rc.top)) / 2,
rc.right - rc.left,
rc.bottom - rc.top,
SWP_SHOWWINDOW);
ShowWindow(hwnd, SW_SHOWNORMAL);
}
DBWriteContactSettingDword(NULL, MODULNAME, "PopupPlusVersion", pluginInfo.version);
//Load PopUp Options
if(!OptionLoaded){
LoadOption_General();
LoadOption_Skins();
LoadOption_Actions();
LoadOption_AdvOpts();
LoadOption_OldOpts();
}
Check_ReorderPopUps();
OptionLoaded = true;
return;
}
void PopUpPreview()
{
TCHAR *lptzTitle1Eng = TranslateT("The Jabberwocky");
TCHAR *lptzText1Eng = TranslateTS(
_T("`Twas brillig, and the slithy toves\r\n")
_T("Did gyre and gimble in the wabe:\r\n")
_T("All mimsy were the borogoves,\r\n")
_T("And the mome raths outgrabe.\r\n")
_T("\t[b][i]Lewis Carroll, 1855[/i][/b]")
);
TCHAR *lptzTitle2 = TranslateT("Test preview for the popup plugin settings. This is supposed to be long enough not to fit in one line...");
TCHAR *lptzText2 = TranslateTS(
_T("This is a special test preview for the popup ")
_T("plugin settings. The text and title are quite ")
_T("long so you can tweak your skin and plugin ")
_T("settings to best fit your needs :)")
);
POPUPDATA2 ppd = {0};
ZeroMemory(&ppd, sizeof(ppd));
ppd.cbSize = sizeof(ppd);
ppd.flags = PU2_TCHAR;
#if defined(_DEBUG)
// test per-contact popups
for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact;
hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
{
if (DBGetContactSettingDword(hContact, "ICQ", "UIN", 0) == 256771455)
{
ppd.lchContact = hContact;
break;
}
}
#endif
ppd.lptzTitle = lptzTitle1Eng;
ppd.lptzText = lptzText1Eng;
ppd.lchIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE);
CallService(MS_POPUP_ADDPOPUP2, (WPARAM)&ppd, APF_NO_HISTORY);
if (PopUpOptions.UseAnimations || PopUpOptions.UseEffect) Sleep((ANIM_TIME*2)/3); //Pause
ZeroMemory(&ppd, sizeof(ppd));
ppd.cbSize = sizeof(ppd);
ppd.flags = PU2_TCHAR;
ppd.lptzTitle = lptzTitle2;
ppd.lptzText = lptzText2;
ppd.lchIcon = LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
ppd.hbmAvatar = hbmNoAvatar;
#if defined(_DEBUG)
//remove testactions
POPUPACTION actions[3];
actions[0].cbSize = sizeof(POPUPACTION);
actions[0].flags = PAF_ENABLED;
lstrcpyA(actions[0].lpzTitle, "Popup Plus/Test action");
actions[0].lchIcon = IcoLib_GetIcon(ICO_POPUP_ON,0);
actions[0].wParam = actions[0].lParam = -1;
actions[1].cbSize = sizeof(POPUPACTION);
actions[1].flags = PAF_ENABLED;
lstrcpyA(actions[1].lpzTitle, "Popup Plus/Second test action");
actions[1].lchIcon = IcoLib_GetIcon(ICO_ACT_CLOSE,0);
actions[1].wParam = actions[1].lParam = -1;
actions[2].cbSize = sizeof(POPUPACTION);
actions[2].flags = PAF_ENABLED;
lstrcpyA(actions[2].lpzTitle, "Popup Plus/One more action");
actions[2].lchIcon = LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
actions[2].wParam = actions[2].lParam = -1;
ppd.lpActions = actions;
ppd.actionCount = SIZEOF(actions);
#endif
CallService(MS_POPUP_ADDPOPUP2, (WPARAM)&ppd, APF_NO_HISTORY);
if (PopUpOptions.UseAnimations || PopUpOptions.UseEffect) Sleep((ANIM_TIME*2)/3); //Pause
PUShowMessageT(TranslateT("This is a notification message"), (DWORD)SM_NOTIFY|0x80000000);
if (PopUpOptions.UseAnimations || PopUpOptions.UseEffect) Sleep((ANIM_TIME*2)/3); //Pause
PUShowMessageT(TranslateT("This is a warning message"), (DWORD)SM_WARNING|0x80000000);
if (PopUpOptions.UseAnimations || PopUpOptions.UseEffect) Sleep((ANIM_TIME*2)/3); //Pause
PUShowMessageT(TranslateT("This is an error message"), (DWORD)SM_ERROR|0x80000000);
}
// nuke settings:
struct NukeSettingsList
{
char *name;
NukeSettingsList *next;
} *setting_items = NULL;
int SettingsEnumProc(const char *szSetting, LPARAM lParam)
{
NukeSettingsList *newItem = (NukeSettingsList *)mir_alloc(sizeof(NukeSettingsList));
newItem->name = mir_strdup(szSetting);
newItem->next = setting_items;
setting_items = newItem;
return 0;
}
static int NukePopupSettings(const char* szModul)
{
DBCONTACTENUMSETTINGS dbces;
setting_items = 0;
dbces.pfnEnumProc = SettingsEnumProc;
dbces.szModule = szModul;
CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)(DBCONTACTENUMSETTINGS*)&dbces);
while (setting_items)
{
NukeSettingsList *next = setting_items->next;
DBCONTACTGETSETTING dbcgs;
dbcgs.szModule = szModul;
dbcgs.szSetting = setting_items->name;
CallService(MS_DB_CONTACT_DELETESETTING, 0, (LPARAM)&dbcgs);
mir_free(setting_items->name);
mir_free(setting_items);
setting_items = next;
}
DBWriteContactSettingDword(NULL, MODULNAME, "PopupPlusVersion", pluginInfo.version);
return 0;
}
|