summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM/src/msgoptions_plus.cpp
blob: 7c505e08669d620bf3079e3dda0866e78848141c (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
/*
 * astyle --force-indent=tab=4 --brackets=linux --indent-switches
 *		  --pad=oper --one-line=keep-blocks  --unpad=paren
 *
 * Miranda NG: the free IM client for Microsoft* Windows*
 *
 * Copyright 2000-2009 Miranda ICQ/IM project,
 * all portions of this codebase are copyrighted to the people
 * listed in contributors.txt.
 *
 * 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.
 *
 * part of tabSRMM messaging plugin for Miranda.
 *
 * (C) 2005-2009 by silvercircle _at_ gmail _dot_ com and contributors
 *
 * implements the "advanced tweak" option page
 *
 * originally developed by Mad Cluster for the tabSRMM "MADMOD" patch in
 * May 2008.
 *
 */

#include "commonheaders.h"

static void FillDialog(HWND hwndDlg)
{
	TVINSERTSTRUCT tvi = {0};
	int i;

	TOptionListGroup *lvGroups = CTranslator::getGroupTree(CTranslator::TREE_MODPLUS);
	for (i=0; lvGroups[i].szName != NULL; i++) {
		tvi.hParent = 0;
		tvi.hInsertAfter = TVI_LAST;
		tvi.item.mask = TVIF_TEXT | TVIF_STATE;
		tvi.item.pszText = TranslateTS(lvGroups[i].szName);
		tvi.item.stateMask = TVIS_STATEIMAGEMASK | TVIS_EXPANDED | TVIS_BOLD;
		tvi.item.state = INDEXTOSTATEIMAGEMASK(0) | TVIS_EXPANDED | TVIS_BOLD;
		lvGroups[i].handle = (LRESULT)TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_PLUS_CHECKTREE), &tvi);
	}

	TOptionListItem *lvItems = CTranslator::getTree(CTranslator::TREE_MODPLUS);
	for (i=0; lvItems[i].szName != 0; i++) {
		tvi.hParent = (HTREEITEM)lvGroups[lvItems[i].uGroup].handle;
		tvi.hInsertAfter = TVI_LAST;
		tvi.item.pszText = TranslateTS(lvItems[i].szName);
		tvi.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
		tvi.item.lParam = i;
		tvi.item.stateMask = TVIS_STATEIMAGEMASK;
		if (lvItems[i].uType == LOI_TYPE_SETTING)
			tvi.item.state = INDEXTOSTATEIMAGEMASK(M->GetByte((char *)lvItems[i].lParam, lvItems[i].id) ? 3 : 2);  // NOTE: was 2 : 1 without state image mask
		lvItems[i].handle = (LRESULT)TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_PLUS_CHECKTREE), &tvi);
	}

	SendDlgItemMessage(hwndDlg, IDC_TIMEOUTSPIN, UDM_SETRANGE, 0, MAKELONG(300, SRMSGSET_MSGTIMEOUT_MIN / 1000));
	SendDlgItemMessage(hwndDlg, IDC_TIMEOUTSPIN, UDM_SETPOS, 0, PluginConfig.m_MsgTimeout / 1000);

	SendDlgItemMessage(hwndDlg, IDC_HISTORYSIZESPIN, UDM_SETRANGE, 0, MAKELONG(255, 15));
	SendDlgItemMessage(hwndDlg, IDC_HISTORYSIZESPIN, UDM_SETPOS, 0, (int)M->GetByte("historysize", 0));
}

INT_PTR CALLBACK PlusOptionsProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)	{
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PLUS_CHECKTREE), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PLUS_CHECKTREE), GWL_STYLE) | (TVS_NOHSCROLL | TVS_CHECKBOXES));

		g_himlOptions = (HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC_PLUS_CHECKTREE, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)CreateStateImageList());
		ImageList_Destroy(g_himlOptions);

		FillDialog(hwndDlg);
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR) lParam)->idFrom) {
		case IDC_PLUS_CHECKTREE:
			if (((LPNMHDR)lParam)->code == NM_CLICK || (((LPNMHDR)lParam)->code == TVN_KEYDOWN && ((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE)) {
				TVHITTESTINFO hti;
				TVITEM item = {0};

				item.mask = TVIF_HANDLE | TVIF_STATE;
				item.stateMask = TVIS_STATEIMAGEMASK | TVIS_BOLD;
				hti.pt.x = (short)LOWORD(GetMessagePos());
				hti.pt.y = (short)HIWORD(GetMessagePos());
				ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
				if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti) || ((LPNMHDR)lParam)->code == TVN_KEYDOWN) {
					if (((LPNMHDR)lParam)->code == TVN_KEYDOWN) {
						hti.flags |= TVHT_ONITEMSTATEICON;
						item.hItem = TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom);
					} else
						item.hItem = (HTREEITEM)hti.hItem;
					SendDlgItemMessageA(hwndDlg, IDC_PLUS_CHECKTREE, TVM_GETITEMA, 0, (LPARAM)&item);
					if (item.state & TVIS_BOLD && hti.flags & TVHT_ONITEMSTATEICON) {
						item.state = INDEXTOSTATEIMAGEMASK(0) | TVIS_BOLD;
						SendDlgItemMessageA(hwndDlg, IDC_PLUS_CHECKTREE, TVM_SETITEMA, 0, (LPARAM)&item);
					} 
					else if (hti.flags & TVHT_ONITEMSTATEICON) {
						if (((item.state & TVIS_STATEIMAGEMASK) >> 12) == 3) {
							item.state = INDEXTOSTATEIMAGEMASK(1);
							SendDlgItemMessageA(hwndDlg, IDC_PLUS_CHECKTREE, TVM_SETITEMA, 0, (LPARAM)&item);
						}
						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					}
				}
			}
			break;

		default:
			switch (((LPNMHDR) lParam)->code) {
			case PSN_APPLY:
				TOptionListItem* lvItems = CTranslator::getTree(CTranslator::TREE_MODPLUS);

				for (int i=0; lvItems[i].szName != NULL; i++) {
					TVITEM item = {0};
					item.mask = TVIF_HANDLE | TVIF_STATE;
					item.hItem = (HTREEITEM)lvItems[i].handle;
					item.stateMask = TVIS_STATEIMAGEMASK;

					SendDlgItemMessageA(hwndDlg, IDC_PLUS_CHECKTREE, TVM_GETITEMA, 0, (LPARAM)&item);
					if (lvItems[i].uType == LOI_TYPE_SETTING)
						M->WriteByte(SRMSGMOD_T, (char *)lvItems[i].lParam, (BYTE)((item.state >> 12) == 3/*2*/ ? 1 : 0));  // NOTE: state image masks changed
				}

				int msgTimeout = 1000 * GetDlgItemInt(hwndDlg, IDC_SECONDS, NULL, FALSE);
				PluginConfig.m_MsgTimeout = msgTimeout >= SRMSGSET_MSGTIMEOUT_MIN ? msgTimeout : SRMSGSET_MSGTIMEOUT_MIN;
				M->WriteDword(SRMSGMOD, SRMSGSET_MSGTIMEOUT, PluginConfig.m_MsgTimeout);

				M->WriteByte(SRMSGMOD_T, "historysize", (BYTE)SendDlgItemMessage(hwndDlg, IDC_HISTORYSIZESPIN, UDM_GETPOS, 0, 0));
				PluginConfig.reloadAdv();
				return TRUE;
			}
		}
		break;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDC_PLUS_HELP) {
			CallService(MS_UTILS_OPENURL, 0, (LPARAM)"http://wiki.miranda.or.at/TabSRMM/AdvancedTweaks");
			break;
		}
		else if (LOWORD(wParam) == IDC_PLUS_REVERT) {		// revert to defaults...
			TOptionListItem *lvItems = CTranslator::getTree(CTranslator::TREE_MODPLUS);

			for (int i=0; lvItems[i].szName; i++)
				if (lvItems[i].uType == LOI_TYPE_SETTING)
					M->WriteByte(SRMSGMOD_T, (char *)lvItems[i].lParam, (BYTE)lvItems[i].id);

			TreeView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_PLUS_CHECKTREE));
			FillDialog(hwndDlg);
			break;
		}
		if (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus())
			return TRUE;

		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		break;

	case WM_CLOSE:
		EndDialog(hwndDlg,0);
		return 0;
	}
	return 0;
}