summaryrefslogtreecommitdiff
path: root/protocols/Dummy/src/dummy_options.cpp
blob: 935dc955ffd041f16f5ec6569b6095b4d9b6b7dc (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
/*
Copyright (c) 2014 Robert Pösel

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 version 2
of the License.

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, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"

//////////////////////////////////////////////////////////////////////////////
// Account manager dialog

void onTemplateSelected(HWND hwndDlg, CDummyProto *ppro, int templateId)
{
	// Enable custom fields when selected custom template
	EnableWindow(GetDlgItem(hwndDlg, IDC_ID_TEXT), templateId == 0);
	EnableWindow(GetDlgItem(hwndDlg, IDC_ID_SETTING), templateId == 0);

	ptrA tszIdText(templateId > 0 ? mir_strdup(Translate(templates[templateId].text)) : ppro->getStringA(DUMMY_ID_TEXT));
	if (tszIdText != NULL)
		SetDlgItemTextA(hwndDlg, IDC_ID_TEXT, tszIdText);

	ptrA tszIdSetting(templateId > 0 ? mir_strdup(templates[templateId].setting) : ppro->getStringA(DUMMY_ID_SETTING));
	if (tszIdSetting != NULL)
		SetDlgItemTextA(hwndDlg, IDC_ID_SETTING, tszIdSetting);
}

INT_PTR CALLBACK DummyAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	CDummyProto *ppro = (CDummyProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		ppro = (CDummyProto*)lParam;
		SetWindowLongPtr( hwndDlg, GWLP_USERDATA, lParam );

		Window_SetIcon_IcoLib(hwndDlg, ppro->m_hProtoIcon);
		{
			SendDlgItemMessageA(hwndDlg, IDC_TEMPLATE, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>(Translate(templates[0].name)));
			for (size_t i = 1; i < _countof(templates); i++)
				SendDlgItemMessageA(hwndDlg, IDC_TEMPLATE, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(templates[i].name));
		
			int templateId = ppro->getTemplateId();
			SendDlgItemMessage(hwndDlg, IDC_TEMPLATE, CB_SETCURSEL, templateId, 0);

			boolean allowSending = ppro->getByte(DUMMY_KEY_ALLOW_SENDING, 0);
			CheckDlgButton(hwndDlg, IDC_ALLOW_SENDING, allowSending ? BST_CHECKED : BST_UNCHECKED);

			onTemplateSelected(hwndDlg, ppro, templateId);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_TEMPLATE:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				int templateId = SendDlgItemMessage(hwndDlg, IDC_TEMPLATE, CB_GETCURSEL, 0, 0);
				onTemplateSelected(hwndDlg, ppro, templateId);
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			}
			break;
		case IDC_ID_TEXT:
		case IDC_ID_SETTING:
			if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			}
		default:
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			int templateId = SendDlgItemMessage(hwndDlg, IDC_TEMPLATE, CB_GETCURSEL, 0, 0);
			ppro->setByte(DUMMY_ID_TEMPLATE, templateId);

			// Save custom fields only when this is custom template
			if (templateId == 0) {
				char str[128];
				GetDlgItemTextA(hwndDlg, IDC_ID_TEXT, str, _countof(str));
				ppro->setString(DUMMY_ID_TEXT, str);

				GetDlgItemTextA(hwndDlg, IDC_ID_SETTING, str, _countof(str));
				ppro->setString(DUMMY_ID_SETTING, str);
			}

			ppro->setByte(DUMMY_KEY_ALLOW_SENDING, IsDlgButtonChecked(hwndDlg, IDC_ALLOW_SENDING));
		}
		break;

	case WM_CLOSE:
		EndDialog(hwndDlg, 0);
		break;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		break;
	}

	return FALSE;
}

INT_PTR CDummyProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam)
{
	return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ACCMGRUI), (HWND)lParam, DummyAccountProc, (LPARAM)this);
}