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
|
#include "stdafx.h"
/////////////////////////////////////////////////////////////////////////////////////////
// General options dialog
class CGeneralOptsDlg : public CDlgBase
{
CCtrlCheck chkGrouping, chkVScroll, chkDrawEdge;
public:
CGeneralOptsDlg() :
CDlgBase(g_plugin, IDD_OPT_ADVANCED),
chkVScroll(this, IDC_VSCROLL),
chkDrawEdge(this, IDC_DRAWEDGE),
chkGrouping(this, IDC_GROUPING)
{
CreateLink(chkVScroll, g_plugin.bOptVScroll);
CreateLink(chkGrouping, g_bOptGrouping);
CreateLink(chkDrawEdge, g_bOptDrawEdge);
}
bool OnApply() override
{
g_plugin.bDrawEdge = g_bOptDrawEdge;
g_plugin.bMsgGrouping = g_bOptGrouping;
return true;
}
};
/////////////////////////////////////////////////////////////////////////////////////////
// Template options dialog
class CTemplateOptsDlg : public CDlgBase
{
MCONTACT m_hContact;
MEVENT m_hDbEVent;
TemplateInfo *m_curr = 0;
void UpdatePreview(CCtrlButton*)
{
replaceStrW(m_curr->tmpValue, m_edit.GetText());
ItemData item;
item.hContact = m_hContact;
item.hEvent = m_hDbEVent;
item.load(true);
ptrW wszText(TplFormatStringEx(int(m_curr-templates), m_curr->tmpValue, item.hContact, &item));
preview.SetText(wszText);
gpreview.SetText(wszText);
}
CCtrlBase preview, gpreview;
CCtrlEdit m_edit;
CCtrlMButton btnDiscard, btnPreview, bthVarHelp, btnReset;
CCtrlTreeView m_tree;
public:
CTemplateOptsDlg() :
CDlgBase(g_plugin, IDD_OPT_TEMPLATES),
m_edit(this, IDC_EDITTEMPLATE),
m_tree(this, IDC_TEMPLATES),
preview(this, IDC_PREVIEW),
gpreview(this, IDC_GPREVIEW),
btnReset(this, IDC_RESET, Skin_LoadIcon(SKINICON_OTHER_UNDO), LPGEN("Reset to default")),
btnDiscard(this, IDC_DISCARD, g_plugin.getIcon(ICO_RESET), LPGEN("Cancel edit")),
bthVarHelp(this, IDC_VARHELP, g_plugin.getIcon(ICO_VARHELP), LPGEN("Variables help")),
btnPreview(this, IDC_UPDATEPREVIEW, g_plugin.getIcon(ICO_PREVIEW), LPGEN("Update preview"))
{
btnReset.OnClick = Callback(this, &CTemplateOptsDlg::onClick_Reset);
btnDiscard.OnClick = Callback(this, &CTemplateOptsDlg::onClick_Discard);
btnPreview.OnClick = Callback(this, &CTemplateOptsDlg::UpdatePreview);
bthVarHelp.OnClick = Callback(this, &CTemplateOptsDlg::onVarHelp);
m_tree.OnSelChanged = Callback(this, &CTemplateOptsDlg::onSelChanged);
m_hContact = db_add_contact();
Proto_AddToContact(m_hContact, META_PROTO);
Contact_Hide(m_hContact);
Contact_RemoveFromList(m_hContact);
db_set_ws(m_hContact, META_PROTO, "Nick", TranslateT("Test contact"));
DBEVENTINFO dbei = {};
dbei.pBlob = (BYTE *)"The quick brown fox jumps over the lazy dog";
dbei.cbBlob = (DWORD)strlen((char*)dbei.pBlob);
dbei.flags = DBEF_TEMPORARY;
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.timestamp = time(0);
m_hDbEVent = db_event_add(m_hContact, &dbei);
}
bool OnInitDialog() override
{
HIMAGELIST himgTree = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 1, 1);
m_tree.SetImageList(himgTree, TVSIL_NORMAL);
ImageList_AddIcon(himgTree, g_plugin.getIcon(ICO_TPLGROUP));
HTREEITEM hGroup = 0, hFirst = 0;
const wchar_t *pwszPrevGroup = nullptr;
for (auto &it : templates) {
if (mir_wstrcmp(it.group, pwszPrevGroup)) {
if (hGroup)
m_tree.Expand(hGroup, TVE_EXPAND);
TVINSERTSTRUCT tvis = {};
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.pszText = TranslateW(it.group);
tvis.item.lParam = 0;
hGroup = m_tree.InsertItem(&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 = TranslateW(it.title);
tvis.item.iSelectedImage = tvis.item.iImage = ImageList_AddIcon(himgTree, g_plugin.getIcon(it.icon));
tvis.item.lParam = (LPARAM)⁢
m_tree.InsertItem(&tvis);
pwszPrevGroup = it.group;
}
if (hGroup)
m_tree.Expand(hGroup, TVE_EXPAND);
m_tree.SelectItem(hFirst);
m_tree.EnsureVisible(hFirst);
return true;
}
bool OnApply() override
{
if (m_curr != nullptr)
replaceStrW(m_curr->tmpValue, m_edit.GetText());
for (auto &it : templates) {
if (it.tmpValue) {
replaceStrW(it.value, it.tmpValue);
it.tmpValue = nullptr;
}
}
SaveTemplates();
return true;
}
void OnDestroy() override
{
db_event_delete(m_hDbEVent);
db_delete_contact(m_hContact);
for (auto &it : templates)
replaceStrW(it.tmpValue, nullptr);
}
void onClick_Reset(CCtrlButton *)
{
if (m_curr) {
replaceStrW(m_curr->tmpValue, nullptr);
replaceStrW(m_curr->value, nullptr);
m_edit.SetText(m_curr->defvalue);
}
UpdatePreview(0);
NotifyChange();
}
void onClick_Discard(CCtrlButton *)
{
replaceStrW(m_curr->tmpValue, 0);
if (m_curr->value)
m_edit.SetText(m_curr->value);
else
m_edit.SetText(m_curr->defvalue);
UpdatePreview(0);
}
void onVarHelp(CCtrlButton*)
{
CMStringW wszVarHelp;
wszVarHelp.Format(L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s",
L"%%", TranslateT("simply % character"),
L"%n", TranslateT("a \"hard\" line break (cr/lf - will break indent)"),
L"%S", TranslateT("my nickname"),
L"%N", TranslateT("buddy\'s nickname"),
L"%c", TranslateT("event count"),
L"%I", TranslateT("icon"),
L"%i", TranslateT("direction icon"),
L"%D", TranslateT("direction symbol"),
L"%t", TranslateT("timestamp"),
L"%h", TranslateT("hour (24 hour format, 0-23)"),
L"%a", TranslateT("hour (12 hour format)"),
L"%m", TranslateT("minute"),
L"%s", TranslateT("second"),
L"%o", TranslateT("month"),
L"%d", TranslateT("day of month"),
L"%y", TranslateT("year (4 digits)"),
L"%w", TranslateT("day of week (Sunday, Monday... translatable)"),
L"%p", TranslateT("AM/PM symbol"),
L"%O", TranslateT("name of month, translatable"),
L"%M", TranslateT("the message string itself"));
MessageBox(m_hwnd, wszVarHelp, TranslateT("Variables help"), MB_OK);
}
void onSelChanged(CCtrlTreeView::TEventInfo*)
{
TVITEMEX tvi;
tvi.hItem = m_tree.GetSelection();
tvi.mask = TVIF_PARAM;
m_tree.GetItem(&tvi);
if (tvi.lParam == 0) {
m_edit.Disable();
preview.Disable();
gpreview.Disable();
btnDiscard.Disable();
btnPreview.Disable();
bthVarHelp.Disable();
HTREEITEM hItem = m_tree.GetChild(tvi.hItem);
if (hItem) {
m_tree.Expand(tvi.hItem, TVE_EXPAND);
m_tree.SelectItem(hItem);
}
return;
}
m_edit.Enable();
preview.Enable();
gpreview.Enable();
btnDiscard.Enable();
btnPreview.Enable();
bthVarHelp.Enable();
if (m_curr != nullptr)
replaceStrW(m_curr->tmpValue, m_edit.GetText());
m_curr = (TemplateInfo*)tvi.lParam;
if (m_curr->tmpValue)
m_edit.SetText(m_curr->tmpValue);
else if (m_curr->value)
m_edit.SetText(m_curr->value);
else
m_edit.SetText(m_curr->defvalue);
UpdatePreview(0);
}
};
int OptionsInitialize(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 100000000;
odp.szGroup.a = LPGEN("History");
odp.szTitle.a = LPGEN("NewStory");
odp.flags = ODPF_BOLDGROUPS;
odp.szTab.a = LPGEN("Templates");
odp.pDialog = new CTemplateOptsDlg();
g_plugin.addOptions(wParam, &odp);
odp.szTab.a = LPGEN("Advanced");
odp.pDialog = new CGeneralOptsDlg();
g_plugin.addOptions(wParam, &odp);
return 0;
}
|