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
|
#include "stdafx.h"
Options options;
// Option dialog
static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static int CurrentTemplate;
switch (msg) {
case WM_INITDIALOG:
CurrentTemplate = -1;
{
HTREEITEM hGroup = 0;
HTREEITEM hFirst = 0;
HIMAGELIST himgTree = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 1, 1);
TreeView_SetImageList(GetDlgItem(hwnd, IDC_TEMPLATES), himgTree, TVSIL_NORMAL);
ImageList_AddIcon(himgTree, g_plugin.getIcon(ICO_TPLGROUP));
for (int i = 0; i < TPL_COUNT; i++) {
if (!i || mir_wstrcmp(templates[i].group, templates[i - 1].group)) {
if (hGroup)
TreeView_Expand(GetDlgItem(hwnd, IDC_TEMPLATES), hGroup, TVE_EXPAND);
TVINSERTSTRUCT tvis;
tvis.hParent = 0;
tvis.hInsertAfter = TVI_LAST;
tvis.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvis.item.state = tvis.item.stateMask = TVIS_BOLD;
tvis.item.iSelectedImage = tvis.item.iImage = 0;
tvis.item.pszText = templates[i].group;
tvis.item.lParam = -1;
hGroup = TreeView_InsertItem(GetDlgItem(hwnd, IDC_TEMPLATES), &tvis);
if (!hFirst) hFirst = hGroup;
}
TVINSERTSTRUCT tvis;
tvis.hParent = hGroup;
tvis.hInsertAfter = TVI_LAST;
tvis.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvis.item.pszText = templates[i].title;
tvis.item.iSelectedImage = tvis.item.iImage =
ImageList_AddIcon(himgTree, g_plugin.getIcon(templates[i].icon));
tvis.item.lParam = i;
TreeView_InsertItem(GetDlgItem(hwnd, IDC_TEMPLATES), &tvis);
}
if (hGroup)
TreeView_Expand(GetDlgItem(hwnd, IDC_TEMPLATES), hGroup, TVE_EXPAND);
TreeView_SelectItem(GetDlgItem(hwnd, IDC_TEMPLATES), hFirst);
TreeView_EnsureVisible(GetDlgItem(hwnd, IDC_TEMPLATES), hFirst);
}
SendMessage(GetDlgItem(hwnd, IDC_DISCARD), BUTTONSETASFLATBTN, 0, 0);
SendMessage(GetDlgItem(hwnd, IDC_UPDATEPREVIEW), BUTTONSETASFLATBTN, 0, 0);
SendMessage(GetDlgItem(hwnd, IDC_VARHELP), BUTTONSETASFLATBTN, 0, 0);
SendMessage(GetDlgItem(hwnd, IDC_DISCARD), BUTTONADDTOOLTIP, (WPARAM)Translate("Cancel Edit"), 0);
SendMessage(GetDlgItem(hwnd, IDC_UPDATEPREVIEW), BUTTONADDTOOLTIP, (WPARAM)Translate("Update Preview"), 0);
SendMessage(GetDlgItem(hwnd, IDC_VARHELP), BUTTONADDTOOLTIP, (WPARAM)Translate("Help on Variables"), 0);
SendMessage(GetDlgItem(hwnd, IDC_DISCARD), BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(ICO_RESET));
SendMessage(GetDlgItem(hwnd, IDC_UPDATEPREVIEW), BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(ICO_PREVIEW));
SendMessage(GetDlgItem(hwnd, IDC_VARHELP), BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(ICO_VARHELP));
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_EDITTEMPLATE:
SendMessage(GetParent(GetParent(hwnd)), PSM_CHANGED, 0, 0);
case IDC_UPDATEPREVIEW:
if (templates[CurrentTemplate].tmpValue)
mir_free(templates[CurrentTemplate].tmpValue);
{
int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITTEMPLATE)) + 1;
templates[CurrentTemplate].tmpValue = (wchar_t*)mir_alloc(length * sizeof(wchar_t));
GetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].tmpValue, length);
HistoryArray::ItemData item;
item.hContact = db_find_first();
while (item.hContact && !item.hEvent) {
item.hEvent = db_event_first(item.hContact);
if (!item.hEvent)
item.hContact = db_find_next(item.hContact);
}
if (item.hContact && item.hEvent) {
item.load(ELM_DATA);
wchar_t* preview = TplFormatStringEx(CurrentTemplate, templates[CurrentTemplate].tmpValue, item.hContact, &item);
SetWindowText(GetDlgItem(hwnd, IDC_PREVIEW), preview);
// SetWindowText(GetDlgItem(hwnd, IDC_GPREVIEW), preview);
SetWindowText(GetDlgItem(hwnd, IDC_GPREVIEW), L"$hit :)");
mir_free(preview);
}
else {
SetWindowText(GetDlgItem(hwnd, IDC_PREVIEW), L"");
SetWindowText(GetDlgItem(hwnd, IDC_GPREVIEW), L"");
}
}
break;
case IDC_DISCARD:
if (templates[CurrentTemplate].tmpValue)
mir_free(templates[CurrentTemplate].tmpValue);
templates[CurrentTemplate].tmpValue = 0;
if (templates[CurrentTemplate].value)
SetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].value);
else
SetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].defvalue);
PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_UPDATEPREVIEW, 0), 0);
break;
}
break;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->idFrom) {
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_RESET:
for (int i = 0; i < TPL_COUNT; i++) {
if (templates[i].tmpValue) {
if (templates[i].tmpValue)
mir_free(templates[i].tmpValue);
}
}
return TRUE;
case PSN_APPLY:
for (int i = 0; i < TPL_COUNT; i++) {
if (templates[i].tmpValue) {
if (templates[i].value)
mir_free(templates[i].value);
templates[i].value = templates[i].tmpValue;
templates[i].tmpValue = 0;
}
}
SaveTemplates();
return TRUE;
}
break;
case IDC_TEMPLATES:
switch (((LPNMHDR)lParam)->code) {
case TVN_SELCHANGED:
case TVN_SELCHANGING:
{
LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)lParam;
TVITEM tvi;
tvi.hItem = TreeView_GetSelection(GetDlgItem(hwnd, IDC_TEMPLATES));
tvi.mask = TVIF_PARAM;
TreeView_GetItem(GetDlgItem(hwnd, IDC_TEMPLATES), &tvi);
if ((tvi.lParam < 0) || (tvi.lParam >= TPL_COUNT)) {
EnableWindow(GetDlgItem(hwnd, IDC_EDITTEMPLATE), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_GPREVIEW), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_PREVIEW), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_DISCARD), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_UPDATEPREVIEW), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_VARHELP), FALSE);
/* HTREEITEM hItem = TreeView_GetChild(GetDlgItem(hwnd, IDC_TEMPLATES), tvi.hItem);
if (hItem)
{
TreeView_Expand(GetDlgItem(hwnd, IDC_TEMPLATES), tvi.hItem, TVE_EXPAND);
TreeView_SelectItem(GetDlgItem(hwnd, IDC_TEMPLATES), hItem);
}*/
break;
}
else {
EnableWindow(GetDlgItem(hwnd, IDC_EDITTEMPLATE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_GPREVIEW), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_PREVIEW), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_DISCARD), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_UPDATEPREVIEW), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_VARHELP), TRUE);
}
if ((lpnmtv->itemOld.mask & TVIF_HANDLE) && lpnmtv->itemOld.hItem && (lpnmtv->itemOld.hItem != lpnmtv->itemNew.hItem) && (lpnmtv->itemOld.lParam >= 0) && (lpnmtv->itemOld.lParam < TPL_COUNT)) {
if (templates[lpnmtv->itemOld.lParam].tmpValue)
mir_free(templates[lpnmtv->itemOld.lParam].tmpValue);
int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITTEMPLATE)) + 1;
templates[lpnmtv->itemOld.lParam].tmpValue = (wchar_t*)mir_alloc(length * sizeof(wchar_t));
GetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[lpnmtv->itemOld.lParam].tmpValue, length);
}
CurrentTemplate = tvi.lParam;
if (templates[CurrentTemplate].tmpValue)
SetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].tmpValue);
else if (templates[CurrentTemplate].value)
SetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].value);
else
SetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].defvalue);
PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_UPDATEPREVIEW, 0), 0);
}
break;
case TVN_KEYDOWN:
case NM_CLICK:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
}
break;
}
break;
}
return FALSE;
}
static int OptionsInitialize(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
odp.position = 100000000;
odp.szGroup.a = LPGEN("History");
odp.szTitle.a = LPGEN("Newstory");
odp.flags = ODPF_BOLDGROUPS;
odp.szTab.a = LPGEN("Templates");
odp.pfnDlgProc = OptTemplatesDlgProc;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_TEMPLATES);
g_plugin.addOptions(wParam, &odp);
return 0;
}
void InitOptions()
{
HookEvent(ME_OPT_INITIALISE, OptionsInitialize);
}
|