summaryrefslogtreecommitdiff
path: root/protocols/WebView/src/webview_opts.cpp
blob: 923b45142c3977f773dda10fea45c2e8ece5d8c3 (plain)
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
* A plugin for Miranda IM which displays web page text in a window 
* Copyright (C) 2005 Vincent Joyce.
*
* Miranda IM: the free icq client for MS Windows  Copyright (C) 2000-2
* Richard Hughes, Roland Rabien & Tristan Van de Vreede
*
* 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"
#include "webview.h"

static char *fontSizes[] = { "8", "10", "14", "16", "18", "20", "24", "28" };

#define M_FILLSCRIPTCOMBO    (WM_USER+16)

/////////////////////////////////////////////////////////////////////////////////////////

static int CALLBACK EnumFontScriptsProc(ENUMLOGFONTEX * lpelfe, NEWTEXTMETRICEX*, int, LPARAM lParam)
{
	if (SendMessage((HWND)lParam, CB_FINDSTRINGEXACT, -1, (LPARAM)lpelfe->elfScript) == CB_ERR) {
		int i = SendMessage((HWND)lParam, CB_ADDSTRING, 0, (LPARAM)lpelfe->elfScript);

		SendMessage((HWND)lParam, CB_SETITEMDATA, i, lpelfe->elfLogFont.lfCharSet);
	}
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////////////////
// copied and modified from NewStatusNotify

static INT_PTR CALLBACK DlgPopUpOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	char str[512];
	DWORD  BGColour = 0;
	DWORD  TextColour = 0;
	DWORD  delay = 0;
	static int test = 0;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hdlg);

		delay = g_plugin.getDword(POP_DELAY_KEY, 0);

		// setting popup delay option
		_itoa(delay, str, 10);
		SetDlgItemTextA(hdlg, IDC_DELAY, str);

		BGColour = g_plugin.getDword(POP_BG_CLR_KEY, Def_color_bg);
		TextColour = g_plugin.getDword(POP_TXT_CLR_KEY, Def_color_txt);

		// Colours. First step is configuring the colours.
		SendDlgItemMessage(hdlg, IDC_POP_BGCOLOUR, CPM_SETCOLOUR, 0, BGColour);
		SendDlgItemMessage(hdlg, IDC_POP_TEXTCOLOUR, CPM_SETCOLOUR, 0, TextColour);
		// Second step is disabling them if we want to use default Windows
		// ones.
		CheckDlgButton(hdlg, IDC_POP_USEWINCOLORS, g_plugin.getByte(POP_USEWINCLRS_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_POP_USESAMECOLORS, g_plugin.getByte(POP_USESAMECLRS_KEY, 1) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_POP_USECUSTCOLORS, g_plugin.getByte(POP_USECUSTCLRS_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);

		if (IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS) || IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)) {
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), 0);
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), 0);
		}

		CheckDlgButton(hdlg, IDC_LCLK_WINDOW, g_plugin.getByte(LCLK_WINDOW_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_LCLK_WEB_PGE, g_plugin.getByte(LCLK_WEB_PGE_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_LCLK_DISMISS, g_plugin.getByte(LCLK_DISMISS_KEY, 1) ? BST_CHECKED : BST_UNCHECKED);

		CheckDlgButton(hdlg, IDC_RCLK_WINDOW, g_plugin.getByte(RCLK_WINDOW_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_RCLK_WEB_PGE, g_plugin.getByte(RCLK_WEB_PGE_KEY, 1) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_RCLK_DISMISS, g_plugin.getByte(RCLK_DISMISS_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
		return TRUE;

	case WM_COMMAND:
		// enable the "apply" button 
		if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam)
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
		// These are simple clicks: we don't save, but we tell the Options Page 
		// to enable the "Apply" button.
		switch (LOWORD(wParam)) {
		case IDC_POP_BGCOLOUR: // Fall through
		case IDC_POP_TEXTCOLOUR:
			// select new colors
			if (HIWORD(wParam) == CPN_COLOURCHANGED)
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_POP_USESAMECOLORS:
			// use same color as data window - enable/disable color selection
			// controls
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), !((uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)));
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), !((uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)));
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_POP_USEWINCOLORS:
			// use window color - enable/disable color selection controls
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), !((uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS)));
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), !((uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS)));
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_POP_USECUSTCOLORS:
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), ((uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS)));
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), ((uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS)));
			break;

		case IDC_PD1:
			SetDlgItemText(hdlg, IDC_DELAY, L"0");
			break;
		case IDC_PD2:
			// Popup delay = permanent
			SetDlgItemText(hdlg, IDC_DELAY, L"-1");
			break;

		case IDC_DELAY:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 1) {
				//CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3);
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			}
			break;

		case IDC_PREVIEW:
			wchar_t str3[512];
			POPUPDATAW ppd;

			GetDlgItemText(hdlg, IDC_DELAY, str3, _countof(str3));

			if (IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS)) {
				BGColour = (SendDlgItemMessage(hdlg, IDC_POP_BGCOLOUR, CPM_GETCOLOUR, 0, 0));
				TextColour = (SendDlgItemMessage(hdlg, IDC_POP_TEXTCOLOUR, CPM_GETCOLOUR, 0, 0));
			}
			if (IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS)) {
				BGColour = GetSysColor(COLOR_BTNFACE);
				TextColour = GetSysColor(COLOR_WINDOWTEXT);
			}
			if (IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)) {
				BGColour = BackgoundClr;
				TextColour = TextClr;
			}
			ppd.lchContact = NULL;
			mir_wstrcpy(ppd.lpwzContactName, _A2W(MODULENAME));
			ppd.lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SITE));
			mir_wstrcpy(ppd.lpwzText, TranslateT("This is a preview popup."));
			ppd.colorBack = BGColour;
			ppd.colorText = TextColour;
			ppd.PluginWindowProc = nullptr;
			ppd.iSeconds = _wtol(str3);
			// display popups
			PUAddPopupW(&ppd);
		}
		break;

	case WM_NOTIFY: // Here we have pressed either the OK or the APPLY button.
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			int popupdelayval = 0;
			wchar_t str2[512];
			GetDlgItemText(hdlg, IDC_DELAY, str2, _countof(str2));

			popupdelayval = _wtol(str2);
			g_plugin.setDword(POP_DELAY_KEY, popupdelayval);

			g_plugin.setByte(LCLK_WINDOW_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_LCLK_WINDOW));
			g_plugin.setByte(LCLK_WEB_PGE_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_LCLK_WEB_PGE));
			g_plugin.setByte(LCLK_DISMISS_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_LCLK_DISMISS));

			g_plugin.setByte(RCLK_WINDOW_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_RCLK_WINDOW));
			g_plugin.setByte(RCLK_WEB_PGE_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_RCLK_WEB_PGE));
			g_plugin.setByte(RCLK_DISMISS_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_RCLK_DISMISS));

			g_plugin.setByte(POP_USECUSTCLRS_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS));
			g_plugin.setByte(POP_USEWINCLRS_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS));
			g_plugin.setByte(POP_USESAMECLRS_KEY, (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS));

			BGColour = (SendDlgItemMessage(hdlg, IDC_POP_BGCOLOUR, CPM_GETCOLOUR, 0, 0));
			TextColour = (SendDlgItemMessage(hdlg, IDC_POP_TEXTCOLOUR, CPM_GETCOLOUR, 0, 0));

			g_plugin.setDword(POP_BG_CLR_KEY, BGColour);
			g_plugin.setDword(POP_TXT_CLR_KEY, TextColour);

			test = 0;
			return TRUE;
		}
		break;
	}
	return FALSE;
}

/////////////////////////////////////////////////////////////////////////////////////////

static INT_PTR CALLBACK DlgProcOpt(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	DWORD timerval, delaytime, oldcolor;
	DBVARIANT dbv;
	static int test = 0;
	static int test2 = 0;

	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			test = 0;

			SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(999, 0));
			SendDlgItemMessage(hwndDlg, IDC_SPIN2, UDM_SETRANGE, 0, MAKELONG(120, 0));

			SetDlgItemInt(hwndDlg, IDC_TIME, g_plugin.getDword(REFRESH_KEY, TIME), FALSE);
			SetDlgItemInt(hwndDlg, IDC_START_DELAY, g_plugin.getWord(START_DELAY_KEY, 0), FALSE);

			mir_forkthread(FillFontListThread, hwndDlg);

			CheckDlgButton(hwndDlg, IDC_SUPPRESS, g_plugin.getByte(SUPPRESS_ERR_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_UPDATE_ONSTART, g_plugin.getByte(UPDATE_ONSTART_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_UPDATE_ON_OPEN, g_plugin.getByte(UPDATE_ON_OPEN_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_HIDE_STATUS_ICON, g_plugin.getByte(HIDE_STATUS_ICON_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_FONT_BOLD, g_plugin.getByte(FONT_BOLD_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_FONT_ITALIC, g_plugin.getByte(FONT_ITALIC_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_FONT_UNDERLINE, g_plugin.getByte(FONT_UNDERLINE_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_ERROR_POPUP, g_plugin.getByte(ERROR_POPUP_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_UPDATE_ONALERT, g_plugin.getByte(UPDATE_ONALERT_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_SAVE_INDIVID_POS, g_plugin.getByte(SAVE_INDIVID_POS_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_NO_PROTECT, g_plugin.getByte(NO_PROTECT_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_DATAPOPUP, g_plugin.getByte(DATA_POPUP_KEY, 0) ? BST_CHECKED : BST_UNCHECKED);

			if (!g_plugin.getWString(FONT_FACE_KEY, &dbv)) {
				SetDlgItemText(hwndDlg, IDC_TYPEFACE, dbv.pwszVal);
				db_free(&dbv);
			}
			else SetDlgItemText(hwndDlg, IDC_TYPEFACE, Def_font_face);

			for (int i = 0; i < _countof(fontSizes); i++)
				SendDlgItemMessage(hwndDlg, IDC_FONTSIZE, CB_ADDSTRING, 0, (LPARAM)fontSizes[i]);

			SendMessage(hwndDlg, M_FILLSCRIPTCOMBO, wParam, 0);

			SetDlgItemInt(hwndDlg, IDC_FONTSIZE, g_plugin.getByte(FONT_SIZE_KEY, 14), FALSE);

			EnableWindow(GetDlgItem(hwndDlg, IDC_FIND_BUTTON), 0);
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_BUTTON), 0);

			SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_SETCOLOUR, 0, (BackgoundClr));
			SendDlgItemMessage(hwndDlg, IDC_TXTCOLOR, CPM_SETCOLOUR, 0, (TextClr));

			/*
			* record bg value for later comparison
			*/
			oldcolor = BackgoundClr;

			if (g_plugin.getByte(SUPPRESS_ERR_KEY, 0)) {
				CheckDlgButton(hwndDlg, IDC_SUPPRESS, BST_CHECKED);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), 0);
			}
			else {
				CheckDlgButton(hwndDlg, IDC_SUPPRESS, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), 1);
			}

			EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), 0);

			if (g_plugin.getByte(UPDATE_ONSTART_KEY, 0)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START_DELAY), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN2), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STARTDELAYTXT), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STDELAYSECTXT), 1);
			}
			else {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START_DELAY), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STARTDELAYTXT), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STDELAYSECTXT), 0);
			}
		}
		break;

	case M_FILLSCRIPTCOMBO: // fill the script combo box and set the
		// selection to the value for fontid wParam
		{
			LOGFONT lf = { 0 };
			int i;
			HDC hdc = GetDC(hwndDlg);

			lf.lfCharSet = DEFAULT_CHARSET;
			GetDlgItemText(hwndDlg, IDC_TYPEFACE, lf.lfFaceName, _countof(lf.lfFaceName));
			lf.lfPitchAndFamily = 0;
			SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_RESETCONTENT, 0, 0);
			EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontScriptsProc, (LPARAM)GetDlgItem(hwndDlg, IDC_SCRIPT), 0);
			ReleaseDC(hwndDlg, hdc);
			for (i = SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETCOUNT, 0, 0) - 1; i >= 0; i--) {
				if (SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETITEMDATA, i, 0) == (uint8_t)((g_plugin.getByte(FONT_SCRIPT_KEY, 0)))) {
					SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_SETCURSEL, i, 0);
					break;
				}
			}
			if (i < 0)
				SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_SETCURSEL, 0, 0);
		}
		break;

	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam)
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);

		switch (LOWORD(wParam)) {
		case IDC_TXTCOLOR:
			TextClr = SendDlgItemMessage(hwndDlg, IDC_TXTCOLOR, CPM_GETCOLOUR, 0, 0);
			g_plugin.setDword(TXT_COLOR_KEY, TextClr);
			if (HIWORD(wParam) == CPN_COLOURCHANGED) {
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				TxtclrLoop();
			}
			break;

		case IDC_BGCOLOR:
			BackgoundClr = SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0);
			g_plugin.setDword(BG_COLOR_KEY, BackgoundClr);
			if (HIWORD(wParam) == CPN_COLOURCHANGED) {
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				BGclrLoop();
			}
			break;

		case IDC_HIDE_STATUS_ICON:
			ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
			break;

		case IDC_SUPPRESS:
			EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), (!(IsDlgButtonChecked(hwndDlg, IDC_SUPPRESS))));
			break;

		case IDC_UPDATE_ONSTART:
			EnableWindow(GetDlgItem(hwndDlg, IDC_START_DELAY), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN2), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			EnableWindow(GetDlgItem(hwndDlg, IDC_STARTDELAYTXT), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			EnableWindow(GetDlgItem(hwndDlg, IDC_STDELAYSECTXT), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			break;

		case IDC_TYPEFACE:
			SendMessage(hwndDlg, M_FILLSCRIPTCOMBO, wParam, 0);
		case IDC_FONTSIZE:
		case IDC_SCRIPT:
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_START_DELAY:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 1)
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_TIME:
			if (HIWORD(wParam) == EN_CHANGE)
				test2++;
			if (test2 > 2)
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		} // end WM_COMMAND
		break;

	case WM_DESTROY:
		test = 0;
		test2 = 0;
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			g_plugin.setByte(SUPPRESS_ERR_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_SUPPRESS));
			g_plugin.setByte(UPDATE_ONSTART_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART));
			g_plugin.setByte(UPDATE_ON_OPEN_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ON_OPEN));
			g_plugin.setByte(HIDE_STATUS_ICON_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_HIDE_STATUS_ICON));
			g_plugin.setByte(FONT_BOLD_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_FONT_BOLD));
			g_plugin.setByte(FONT_ITALIC_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_FONT_ITALIC));
			g_plugin.setByte(FONT_UNDERLINE_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_FONT_UNDERLINE));
			g_plugin.setByte(UPDATE_ONALERT_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONALERT));
			g_plugin.setByte(SAVE_INDIVID_POS_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_SAVE_INDIVID_POS));
			g_plugin.setByte(NO_PROTECT_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_NO_PROTECT));
			g_plugin.setByte(DATA_POPUP_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_DATAPOPUP));

			wchar_t str[100];
			GetDlgItemText(hwndDlg, IDC_TYPEFACE, str, _countof(str));
			g_plugin.setWString(FONT_FACE_KEY, str);

			g_plugin.setByte(FONT_SIZE_KEY, (GetDlgItemInt(hwndDlg, IDC_FONTSIZE, nullptr, FALSE)));
			g_plugin.setByte(FONT_SCRIPT_KEY, ((uint8_t)SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETCURSEL, 0, 0), 0)));

			g_plugin.setByte(ERROR_POPUP_KEY, (uint8_t)IsDlgButtonChecked(hwndDlg, IDC_ERROR_POPUP));

			timerval = GetDlgItemInt(hwndDlg, IDC_TIME, nullptr, FALSE);
			g_plugin.setDword(REFRESH_KEY, timerval);
			g_plugin.setDword(COUNTDOWN_KEY, timerval);


			delaytime = GetDlgItemInt(hwndDlg, IDC_START_DELAY, nullptr, FALSE);
			g_plugin.setDword(START_DELAY_KEY, delaytime);

			BackgoundClr = (SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0));
			TextClr = (SendDlgItemMessage(hwndDlg, IDC_TXTCOLOR, CPM_GETCOLOUR, 0, 0));

			if ((g_plugin.getDword(REFRESH_KEY, 0) != 0)) {
				KillTimer(nullptr, timerId);
				KillTimer(nullptr, Countdown);
				timerId = SetTimer(nullptr, 0, ((g_plugin.getDword(REFRESH_KEY, 0)) * MINUTE), timerfunc);
				Countdown = SetTimer(nullptr, 0, MINUTE, Countdownfunc);
			}
			if ((g_plugin.getDword(REFRESH_KEY, 0) == 0)) {
				KillTimer(nullptr, timerId);
				KillTimer(nullptr, Countdown);
			}
			test = 0;
		}
		break; // end apply
	}

	return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////
// module entry point

int OptInitialise(WPARAM wParam, LPARAM)
{
	OPTIONSDIALOGPAGE odp = {};
	odp.szTitle.a = MODULENAME;
	odp.flags = ODPF_BOLDGROUPS;

	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT);
	odp.szGroup.a = LPGEN("Network");
	odp.pfnDlgProc = DlgProcOpt;
	g_plugin.addOptions(wParam, &odp);

	// if popup service exists
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUP);
	odp.szGroup.a = LPGEN("Popups");
	odp.pfnDlgProc = DlgPopUpOpts;
	g_plugin.addOptions(wParam, &odp);
	return 0;
}