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
|
#include "stdafx.h"
// min allowed alpha (don't want 0 because it's a waste of resources as well as might confuse user)
#define MIN_ALPHA 30
HICON g_hReminderIcon = nullptr;
LOGFONT lfBody, lfCaption;
HFONT hBodyFont = nullptr, hCaptionFont = nullptr;
long BodyColor;
COLORREF CaptionFontColor, BodyFontColor;
int g_NoteTitleDate, g_NoteTitleTime;
int g_NoteWidth, g_NoteHeight;
int g_Transparency;
char *g_RemindSMS = nullptr;
char *g_lpszAltBrowser = nullptr;
#define NRCDEFAULT_BODYCLR RGB(255,255,0)
struct DateFormat
{
wchar_t *lpszUI;
wchar_t *lpszFmt;
}
static dateFormats[] =
{
{ L"1981-12-31", L"yyyy'-'MM'-'dd" },
{ L"31-12-1981", L"dd'-'MM'-'yyyy" },
{ L"12-31-1981", L"MM'-'dd'-'yyyy" },
{ L"1981-dec-31", L"yyyy'-'MMM'-'dd" },
{ L"31-dec-1981", L"dd'-'MMM'-'yyyy" },
{ L"dec-31-1981", L"MMM'-'dd'-'yyyy" },
{ L"1981/12/31", L"yyyy'/'MM'/'dd" },
{ L"31/12/1981", L"dd'/'MM'/'yyyy" },
{ L"12/31/1981", L"MM'/'dd'/'yyyy" },
{ L"1981/dec/31", L"yyyy'/'MMM'/'dd" },
{ L"31/dec/1981", L"dd'/'MMM'/'yyyy" },
{ L"dec/31/1981", L"MMM'/'dd'/'yyyy" },
{ L"1981 dec 31", L"yyyy MMM dd" },
{ L"31 dec 1981", L"dd MMM yyyy" },
{ L"dec 31 1981", L"MMM dd yyyy" }
};
struct TimeFormat
{
wchar_t *lpszUI;
wchar_t *lpszFmt;
}
static timeFormats[] =
{
{ L"19:30:00", L"HH':'mm':'ss" },
{ L"19:30", L"HH':'mm'" },
{ L"7:30:00 PM", L"hh':'mm':'ss tt" },
{ L"7:30 PM", L"hh':'mm tt" },
{ L"7:30:00P", L"hh':'mm':'sst" },
{ L"7:30P", L"hh':'mmt" }
};
struct FontOptionsList
{
wchar_t *szDescr;
COLORREF defColour;
wchar_t *szDefFace;
uint8_t defStyle;
int defSize;
wchar_t *szBkgName;
}
static fontOptionsList[] =
{
{ LPGENW("Sticky Note Caption"), RGB(0, 0, 0), L"Small Fonts", 0, 7, LPGENW("Sticky Note Background Color") },
{ LPGENW("Sticky Note Body"), RGB(0, 0, 0), L"System", DBFONTF_BOLD, 10, LPGENW("Sticky Note Background Color") },
};
struct ColourOptionsList
{
char *szName;
char *szSettingName;
COLORREF defColour;
}
static colourOptionsList[] =
{
{ LPGEN("Sticky Note Background Color"), "BodyColor", NRCDEFAULT_BODYCLR }
};
wchar_t* GetDateFormatStr()
{
return dateFormats[g_NoteTitleDate ? g_NoteTitleDate - 1 : 0].lpszFmt;
}
wchar_t* GetTimeFormatStr()
{
return timeFormats[g_NoteTitleTime ? g_NoteTitleTime - 1 : 0].lpszFmt;
}
static void InitFonts()
{
memset(&lfBody, 0, sizeof(lfBody));
memset(&lfCaption, 0, sizeof(lfCaption));
LoadNRFont(NR_FONTID_CAPTION, &lfCaption, &CaptionFontColor);
LoadNRFont(NR_FONTID_BODY, &lfBody, &BodyFontColor);
if (hBodyFont)
DeleteObject(hBodyFont);
if (hCaptionFont)
DeleteObject(hCaptionFont);
hBodyFont = CreateFontIndirectW(&lfBody);
hCaptionFont = CreateFontIndirectW(&lfCaption);
}
static int FS_FontsChanged(WPARAM, LPARAM)
{
InitFonts();
SaveNotes();
LoadNotes(false);
return 0;
}
static int FS_ColorChanged(WPARAM, LPARAM)
{
LoadNRFont(NR_FONTID_CAPTION, &lfCaption, (COLORREF*)&CaptionFontColor);
LoadNRFont(NR_FONTID_BODY, &lfBody, (COLORREF*)&BodyFontColor);
BodyColor = g_plugin.getDword(colourOptionsList[0].szSettingName, colourOptionsList[0].defColour);
SaveNotes();
LoadNotes(false);
return 0;
}
void RegisterFontServiceFonts()
{
char szTemp[100];
FontIDW fontid = {};
wcsncpy_s(fontid.group, _A2W(SECTIONNAME), _TRUNCATE);
wcsncpy_s(fontid.backgroundGroup, _A2W(SECTIONNAME), _TRUNCATE);
strncpy_s(fontid.dbSettingsGroup, MODULENAME, _TRUNCATE);
fontid.flags = FIDF_ALLOWREREGISTER | FIDF_DEFAULTVALID | FIDF_SAVEPOINTSIZE;
HDC hDC = GetDC(nullptr);
int nFontScale = GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC(nullptr, hDC);
for (int i = 0; i < _countof(fontOptionsList); i++) {
fontid.order = i;
mir_snprintf(szTemp, "Font%d", i);
strncpy_s(fontid.setting, szTemp, _countof(fontid.setting));
wcsncpy_s(fontid.name, fontOptionsList[i].szDescr, _TRUNCATE);
fontid.deffontsettings.colour = fontOptionsList[i].defColour;
fontid.deffontsettings.size = (char)-MulDiv(fontOptionsList[i].defSize, nFontScale, 72);
fontid.deffontsettings.style = fontOptionsList[i].defStyle;
fontid.deffontsettings.charset = DEFAULT_CHARSET;
wcsncpy_s(fontid.deffontsettings.szFace, fontOptionsList[i].szDefFace, _TRUNCATE);
wcsncpy_s(fontid.backgroundName, fontOptionsList[i].szBkgName, _TRUNCATE);
g_plugin.addFont(&fontid);
}
ColourID colorid = {};
strncpy_s(colorid.group, SECTIONNAME, _TRUNCATE);
strncpy_s(colorid.dbSettingsGroup, MODULENAME, _TRUNCATE);
for (int i = 0; i < _countof(colourOptionsList); i++) {
colorid.order = i;
strncpy_s(colorid.name, colourOptionsList[i].szName, _TRUNCATE);
colorid.defcolour = colourOptionsList[i].defColour;
strncpy_s(colorid.setting, colourOptionsList[i].szSettingName, _TRUNCATE);
g_plugin.addColor(&colorid);
}
HookEvent(ME_FONT_RELOAD, FS_FontsChanged);
HookEvent(ME_COLOUR_RELOAD, FS_ColorChanged);
}
void LoadNRFont(int i, LOGFONT *lf, COLORREF *colour)
{
COLORREF col = Font_GetW(_A2W(SECTIONNAME), fontOptionsList[i].szDescr, lf);
if (colour)
*colour = col;
}
/////////////////////////////////////////////////////////////////////////////////////////
class CNROptionsDlg : public CDlgBase
{
void FillValues()
{
chkHide.SetState(!g_plugin.bShowNotesAtStart); // reversed
SetDlgItemInt(m_hwnd, IDC_EDIT_WIDTH, g_NoteWidth, FALSE);
SetDlgItemInt(m_hwnd, IDC_EDIT_HEIGHT, g_NoteHeight, FALSE);
cmbDate.SetCurSel(g_NoteTitleDate ? g_NoteTitleDate - 1 : cmbDate.GetCount()-1);
cmbTime.SetCurSel(g_NoteTitleTime ? g_NoteTitleTime - 1 : cmbTime.GetCount()-1);
slider.SetPosition(255 - g_Transparency);
}
CCtrlEdit edtBrowser, edtEmail;
CCtrlCombo cmbDate, cmbTime;
CCtrlCheck chkHide, chkButtons, chkScroll, chkClose, chkMSI;
CCtrlButton btnBrowse, btnReset;
CCtrlSlider slider;
public:
CNROptionsDlg() :
CDlgBase(g_plugin, IDD_STNOTEOPTIONS),
slider(this, IDC_SLIDER_TRANSPARENCY, 255 - MIN_ALPHA),
edtEmail(this, IDC_EDIT_EMAILSMS),
edtBrowser(this, IDC_EDIT_ALTBROWSER),
cmbDate(this, IDC_COMBODATE),
cmbTime(this, IDC_COMBOTIME),
chkMSI(this, IDC_CHECK_MSI),
chkHide(this, IDC_CHECK_HIDENOTES),
chkClose(this, IDC_CHECK_CLOSE),
chkScroll(this, IDC_CHECK_SCROLLBARS),
chkButtons(this, IDC_CHECK_BUTTONS),
btnReset(this, IDC_BUTTON_RESET),
btnBrowse(this, IDC_BTN_BROWSEBROWSER)
{
btnReset.OnClick = Callback(this, &CNROptionsDlg::onClick_Reset);
btnBrowse.OnClick = Callback(this, &CNROptionsDlg::onClick_Browse);
CreateLink(chkMSI, g_plugin.bUseMSI);
CreateLink(chkClose, g_plugin.bCloseAfterAddReminder);
CreateLink(chkScroll, g_plugin.bShowScrollbar);
CreateLink(chkButtons, g_plugin.bShowNoteButtons);
}
bool OnInitDialog() override
{
cmbDate.ResetContent();
for (auto &it : dateFormats)
cmbDate.AddString(it.lpszUI);
cmbDate.AddString(TranslateT("None"));
cmbTime.ResetContent();
for (auto &it : timeFormats)
cmbTime.AddString(it.lpszUI);
cmbTime.AddString(TranslateT("None"));
FillValues();
if (g_RemindSMS)
edtEmail.SetTextA(g_RemindSMS);
else
edtEmail.SetTextA("");
edtBrowser.SetTextA(g_lpszAltBrowser ? g_lpszAltBrowser : "");
return true;
}
bool OnApply() override
{
g_plugin.bShowNotesAtStart = !chkHide.GetState(); // reversed
BOOL LB;
g_NoteWidth = GetDlgItemInt(m_hwnd, IDC_EDIT_WIDTH, &LB, FALSE);
g_NoteHeight = GetDlgItemInt(m_hwnd, IDC_EDIT_HEIGHT, &LB, FALSE);
g_Transparency = 255 - slider.GetPosition();
g_NoteTitleDate = (cmbDate.GetCurSel()+1) % cmbDate.GetCount();
g_NoteTitleTime = (cmbTime.GetCurSel()+1) % cmbTime.GetCount();
if (g_NoteWidth < 179) {
g_NoteWidth = 179;
SetDlgItemInt(m_hwnd, IDC_EDIT_WIDTH, g_NoteWidth, FALSE);
}
if (g_NoteHeight < 35) {
g_NoteHeight = 35;
SetDlgItemInt(m_hwnd, IDC_EDIT_HEIGHT, g_NoteHeight, FALSE);
}
mir_free(g_RemindSMS);
g_RemindSMS = edtEmail.GetTextA();
g_plugin.setString("RemindEmail", g_RemindSMS);
mir_free(g_lpszAltBrowser);
g_lpszAltBrowser = edtBrowser.GetTextA();
g_plugin.setString("AltBrowser", g_lpszAltBrowser);
g_plugin.setDword("NoteWidth", g_NoteWidth);
g_plugin.setDword("NoteHeight", g_NoteHeight);
g_plugin.setDword("Transparency", g_Transparency);
g_plugin.setDword("NoteTitleDate", g_NoteTitleDate);
g_plugin.setDword("NoteTitleTime", g_NoteTitleTime);
SaveNotes();
LoadNotes(false);
return true;
}
void onClick_Browse(CCtrlButton*)
{
wchar_t s[MAX_PATH];
GetDlgItemText(m_hwnd, IDC_EDIT_ALTBROWSER, s, _countof(s));
OPENFILENAME ofn = {0};
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = TranslateT("Executable Files\0*.exe\0All Files\0*.*\0\0");
ofn.lpstrFile = s;
ofn.nMaxFile = _countof(s);
ofn.lpstrTitle = TranslateT("Select Executable");
ofn.lpstrInitialDir = L".";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_ENABLESIZING | OFN_DONTADDTORECENT;
if (GetOpenFileNameW(&ofn)) {
SetDlgItemText(m_hwnd, IDC_EDIT_ALTBROWSER, s);
NotifyChange();
}
}
void onClick_Reset(CCtrlButton*)
{
edtEmail.SetTextA("");
edtBrowser.SetTextA("");
replaceStr(g_RemindSMS, nullptr);
replaceStr(g_lpszAltBrowser, nullptr);
g_plugin.bShowNotesAtStart = g_plugin.bShowScrollbar = g_plugin.bShowNoteButtons = true;
g_plugin.bCloseAfterAddReminder = g_plugin.bUseMSI = true;
g_NoteTitleDate = 1;
g_NoteTitleTime = 1;
g_NoteWidth = 179;
g_NoteHeight = 35;
g_Transparency = 255;
FillValues();
NotifyChange();
}
};
int OnOptInitialise(WPARAM w, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 900002000;
odp.szTitle.a = SECTIONNAME;
odp.szGroup.a = LPGEN("Plugins");
odp.pDialog = new CNROptionsDlg();
g_plugin.addOptions(w, &odp);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
void InitSettings(void)
{
g_RemindSMS = g_plugin.getStringA("RemindEmail");
g_lpszAltBrowser = g_plugin.getStringA("AltBrowser");
g_NoteWidth = g_plugin.getDword("NoteWidth", 179);
g_NoteHeight = g_plugin.getDword("NoteHeight", 50);
g_Transparency = g_plugin.getDword("Transparency", 255);
g_NoteTitleDate = g_plugin.getDword("NoteTitleDate", 1);
g_NoteTitleTime = g_plugin.getDword("NoteTitleTime", 1);
BodyColor = g_plugin.getDword(colourOptionsList[0].szSettingName, colourOptionsList[0].defColour);
InitFonts();
g_hReminderIcon = IcoLib_GetIconByHandle(iconList[10].hIcolib);
if (g_Transparency < MIN_ALPHA)
g_Transparency = MIN_ALPHA;
else if (g_Transparency > 255)
g_Transparency = 255;
}
void TermSettings(void)
{
if (g_lpszAltBrowser) {
mir_free(g_lpszAltBrowser);
g_lpszAltBrowser = nullptr;
}
}
|