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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
#include "common.h"
#include "services.h"
FontIDWList font_id_list_w2, font_id_list_w3;
ColourIDWList colour_id_list_w2, colour_id_list_w3;
#define M_SETFONTGROUP (WM_USER + 101)
#define TIMER_ID 11015
extern void UpdateFontSettingsW(FontIDW *font_id, FontSettingsW *fontsettings);
extern void UpdateColourSettingsW(ColourIDW *colour_id, COLORREF *colour);
void WriteLine(HANDLE fhand, char *line) {
DWORD wrote;
strcat(line, "\r\n");
WriteFile(fhand, line, strlen(line), &wrote, 0);
}
bool ExportSettings(HWND hwndDlg, TCHAR *filename, FontIDWList flist, ColourIDWList clist) {
HANDLE fhand = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if(fhand == INVALID_HANDLE_VALUE) {
MessageBox(hwndDlg, filename, _T("Failed to create file"), MB_ICONWARNING | MB_OK);
return false;
}
char header[512], buff[1024], abuff[1024];
header[0] = 0;
strcpy(buff, "SETTINGS:\r\n");
WriteLine(fhand, buff);
FontIDSettingsWPair *it;
for (FontIDWList::Iterator lit = flist.start(); lit.has_val(); lit.next()) {
it = &lit.val();
strcpy(buff, "[");
strcat(buff, it->first.dbSettingsGroup);
strcat(buff, "]");
if(strcmp(buff, header) != 0) {
strcpy(header, buff);
WriteLine(fhand, buff);
}
if(it->first.flags & FIDF_APPENDNAME) {
wsprintfA(buff, "%sName", it->first.prefix);
} else {
wsprintfA(buff, "%s", it->first.prefix);
}
strcat(buff, "=s");
WideCharToMultiByte(code_page, 0, it->second.szFace, -1, abuff, 1024, 0, 0);
abuff[1023]=0;
strcat(buff, abuff);
WriteLine(fhand, buff);
wsprintfA(buff, "%sSize=b", it->first.prefix);
if(it->first.flags & FIDF_SAVEACTUALHEIGHT) {
HDC hdc;
SIZE size;
HFONT hFont, hOldFont;
LOGFONTW lf;
CreateFromFontSettingsW(&it->second, &lf, it->first.flags);
hFont = CreateFontIndirectW(&lf);
//hFont = CreateFontA(it->second.size, 0, 0, 0,
// it->second.style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL,
// it->second.style & DBFONTF_ITALIC ? 1 : 0, 0, 0, it->second.charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, it->second.szFace);
hdc = GetDC(hwndDlg);
hOldFont = (HFONT)SelectObject(hdc, hFont);
GetTextExtentPoint32(hdc, _T("_W"), 2, &size);
ReleaseDC(hwndDlg, hdc);
SelectObject(hdc, hOldFont);
DeleteObject(hFont);
strcat(buff, _itoa((BYTE)size.cy, abuff, 10));
} else if(it->first.flags & FIDF_SAVEPOINTSIZE) {
HDC hdc = GetDC(hwndDlg);
//lf->lfHeight = -MulDiv(lf->lfHeight,GetDeviceCaps(hdc, LOGPIXELSY), 72);
strcat(buff, _itoa((BYTE)-MulDiv(it->second.size, 72, GetDeviceCaps(hdc, LOGPIXELSY)), abuff, 10));
ReleaseDC(hwndDlg, hdc);
} else {
strcat(buff, _itoa((BYTE)it->second.size, abuff, 10));
}
WriteLine(fhand, buff);
wsprintfA(buff, "%sSty=b%d", it->first.prefix, (BYTE)it->second.style);
WriteLine(fhand, buff);
wsprintfA(buff, "%sSet=b%d", it->first.prefix, (BYTE)it->second.charset);
WriteLine(fhand, buff);
wsprintfA(buff, "%sCol=d%d", it->first.prefix, (DWORD)it->second.colour);
WriteLine(fhand, buff);
if(it->first.flags & FIDF_NOAS) {
wsprintfA(buff, "%sAs=w%d", it->first.prefix, (WORD)0x00FF);
WriteLine(fhand, buff);
}
wsprintfA(buff, "%sFlags=w%d", it->first.prefix, (WORD)it->first.flags);
WriteLine(fhand, buff);
}
header[0] = 0;
ColourIDColourWPair *cit;
for (ColourIDWList::Iterator lcit = clist.start(); lcit.has_val(); lcit.next()) {
cit = &lcit.val();
strcpy(buff, "[");
strcat(buff, cit->first.dbSettingsGroup);
strcat(buff, "]");
if(strcmp(buff, header) != 0) {
strcpy(header, buff);
WriteLine(fhand, buff);
}
wsprintfA(buff, "%s=d%d", cit->first.setting, (DWORD)cit->second);
WriteLine(fhand, buff);
}
CloseHandle(fhand);
return true;
}
void OptionsChanged() {
#define INTM_RELOADOPTIONS (WM_USER+21)
HWND hWnd = FindWindowEx((HWND)CallService(MS_CLUI_GETHWND, 0, 0), 0, CLISTCONTROL_CLASS, 0);
if(hWnd) SendMessage(hWnd, INTM_RELOADOPTIONS, 0, 0);
NotifyEventHooks(hFontReloadEvent, 0, 0);
NotifyEventHooks(hColourReloadEvent, 0, 0);
}
TOOLINFO ti;
int x, y;
UINT_PTR CALLBACK CFHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) {
switch(uiMsg) {
case WM_INITDIALOG:
TranslateDialogDefault(hdlg);
return 0;
}
return 0;
}
static BOOL CALLBACK DlgProcLogOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HBRUSH hBkgColourBrush = 0;
switch (msg) {
case WM_INITDIALOG:
{
TranslateDialogDefault(hwndDlg);
/*
// create tooltip tool
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
ti.hwnd = GetDlgItem(hwndDlg, IDC_TOOLTIP);
ti.uId = (UINT)hwndDlg;
ti.hinst = hInstance;
ti.lpszText = L"hi there";
ti.rect.left = ti.rect.top = ti.rect.bottom = ti.rect.right = 0;
SendMessage(GetDlgItem(hwndDlg, IDC_TOOLTIP), TTM_ADDTOOL,0, (LPARAM)&ti);
*/
font_id_list_w3 = font_id_list_w2 = font_id_list_w;
colour_id_list_w3 = colour_id_list_w2 = colour_id_list_w;
FontIDSettingsWPair *it;
for (FontIDWList::Iterator lit = font_id_list_w2.start(); lit.has_val(); lit.next()) {
it = &lit.val();
// sync settings with database
UpdateFontSettingsW(&it->first, &it->second);
if(SendDlgItemMessageW(hwndDlg, IDC_FONTGROUP, LB_FINDSTRINGEXACT, (WPARAM)-1, (WPARAM)it->first.group) == CB_ERR) {
SendDlgItemMessageW(hwndDlg, IDC_FONTGROUP, LB_ADDSTRING, (WPARAM)-1, (WPARAM)it->first.group);
}
}
ColourIDColourWPair *cit;
for (ColourIDWList::Iterator lcit = colour_id_list_w2.start(); lcit.has_val(); lcit.next()) {
cit = &lcit.val();
// sync settings with database
UpdateColourSettingsW(&cit->first, &cit->second);
}
SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETDEFAULTCOLOUR, 0, (LPARAM)GetSysColor(COLOR_WINDOW));
if(font_id_list_w2.size()) SendDlgItemMessage(hwndDlg, IDC_FONTGROUP, LB_SETCURSEL, 0, 0);
SendMessage(hwndDlg, M_SETFONTGROUP, 0, 0);
return TRUE;
}
case M_SETFONTGROUP:
{
int sel = SendDlgItemMessage(hwndDlg, IDC_FONTGROUP, LB_GETCURSEL, 0, 0);
if(sel != -1) {
wchar_t group_buff[64];
SendDlgItemMessage(hwndDlg, IDC_FONTGROUP, LB_GETTEXT, sel, (LPARAM)group_buff);
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_RESETCONTENT, 0, 0);
{
BOOL need_restart = false;
int fontId = 0, itemId;
int first_font_index = -1;
FontIDSettingsWPair *it;
for (FontIDWList::Iterator lit = font_id_list_w2.start(); lit.has_val(); lit.next(), fontId++) {
it = &lit.val();
if(wcsncmp(it->first.group, group_buff, 64) == 0) {
if(first_font_index == -1)
first_font_index = fontId;
//itemId = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_ADDSTRING, -1, (LPARAM)"");
//SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_SETITEMDATA, itemId, fontId);
itemId = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_ADDSTRING, (WPARAM)-1, fontId);
need_restart |= (it->first.flags & FIDF_NEEDRESTART);
//SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_SETITEMDATA, itemId, fontId);
}
}
ShowWindow(GetDlgItem(hwndDlg, IDC_STAT_RESTART), (need_restart ? SW_SHOW : SW_HIDE));
if(hBkgColourBrush) {
DeleteObject(hBkgColourBrush);
hBkgColourBrush = 0;
}
int colourId = 0;
int first_colour_index = -1;
ColourIDColourWPair *cit;
for (ColourIDWList::Iterator lcit = colour_id_list_w2.start(); lcit.has_val(); lcit.next(), colourId++) {
cit = &lcit.val();
if(wcsncmp(cit->first.group, group_buff, 64) == 0) {
if(first_colour_index == -1)
first_colour_index = colourId;
itemId = SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_ADDSTRING, (WPARAM)-1, (LPARAM) TranslateW(cit->first.name));
SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_SETITEMDATA, itemId, colourId);
if(wcscmp(cit->first.name, TranslateW(L"Background")) == 0) {
hBkgColourBrush = CreateSolidBrush(cit->second);
}
}
}
if(!hBkgColourBrush)
hBkgColourBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_SETSEL, TRUE, 0);
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETCOLOUR, 0, (LPARAM)font_id_list_w2[first_font_index].second.colour);
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETDEFAULTCOLOUR, 0, (LPARAM)font_id_list_w2[first_font_index].first.deffontsettings.colour);
if(font_id_list_w2[first_font_index].first.flags & FIDF_DEFAULTVALID) {
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_RESET), TRUE);
} else
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_RESET), FALSE);
if(first_colour_index == -1) {
HWND hw = GetDlgItem(hwndDlg, IDC_COLOURLIST);
EnableWindow(hw, FALSE);
hw = GetDlgItem(hwndDlg, IDC_BKGCOLOUR);
EnableWindow(hw, FALSE);
} else {
HWND hw = GetDlgItem(hwndDlg, IDC_COLOURLIST);
EnableWindow(hw, TRUE);
hw = GetDlgItem(hwndDlg, IDC_BKGCOLOUR);
EnableWindow(hw, TRUE);
SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETCOLOUR, 0, (LPARAM)colour_id_list_w2[first_colour_index].second);
SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETDEFAULTCOLOUR, 0, colour_id_list_w2[first_colour_index].first.defcolour);
}
}
}
return TRUE;
}
case WM_CTLCOLORLISTBOX:
{
if((HWND)lParam == GetDlgItem(hwndDlg, IDC_FONTLIST)) {
return (BOOL) hBkgColourBrush;
}
}
break;
case WM_MEASUREITEM:
{
MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
if(mis->CtlID == IDC_FONTLIST && font_id_list_w2.size()) {
HFONT hFont, hoFont;
SIZE fontSize;
int iItem = mis->itemData;
//int iItem = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA, mis->itemID, 0);
HDC hdc = GetDC(GetDlgItem(hwndDlg, mis->CtlID));
LOGFONTW lf;
CreateFromFontSettingsW(&font_id_list_w2[iItem].second, &lf, font_id_list_w2[iItem].first.flags);
hFont = CreateFontIndirectW(&lf);
//hFont = CreateFontA(font_id_list2[iItem].second.size, 0, 0, 0,
// font_id_list2[iItem].second.style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL,
// font_id_list2[iItem].second.style & DBFONTF_ITALIC ? 1 : 0, 0, 0, font_id_list2[iItem].second.charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, font_id_list2[iItem].second.szFace);
hoFont = (HFONT) SelectObject(hdc, hFont);
GetTextExtentPoint32W(hdc, font_id_list_w2[iItem].first.name, wcslen(font_id_list_w2[iItem].first.name), &fontSize);
SelectObject(hdc, hoFont);
ReleaseDC(GetDlgItem(hwndDlg, mis->CtlID), hdc);
DeleteObject(hFont);
mis->itemWidth = fontSize.cx;
mis->itemHeight = fontSize.cy;
return TRUE;
}
break;
}
case WM_DRAWITEM:
{
DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *) lParam;
if(dis->CtlID == IDC_FONTLIST && font_id_list_w2.size()) {
HFONT hFont, hoFont;
wchar_t *pszText;
int iItem = dis->itemData;
LOGFONTW lf;
CreateFromFontSettingsW(&font_id_list_w2[iItem].second, &lf, font_id_list_w2[iItem].first.flags);
hFont = CreateFontIndirectW(&lf);
//hFont = CreateFontA(font_id_list2[iItem].second.size, 0, 0, 0,
// font_id_list2[iItem].second.style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL,
// font_id_list2[iItem].second.style & DBFONTF_ITALIC ? 1 : 0, 0, 0, font_id_list2[iItem].second.charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, font_id_list2[iItem].second.szFace);
hoFont = (HFONT) SelectObject(dis->hDC, hFont);
SetBkMode(dis->hDC, TRANSPARENT);
FillRect(dis->hDC, &dis->rcItem, hBkgColourBrush);
if (dis->itemState & ODS_SELECTED)
FrameRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
SetTextColor(dis->hDC, font_id_list_w2[iItem].second.colour);
pszText = TranslateW(font_id_list_w2[iItem].first.name);
TextOutW(dis->hDC, dis->rcItem.left, dis->rcItem.top, pszText, wcslen(pszText));
SelectObject(dis->hDC, hoFont);
DeleteObject(hFont);
return TRUE;
}
break;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_COLOURLIST:
if (HIWORD(wParam) == LBN_SELCHANGE) {
int sel = SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_GETCURSEL, 0, 0);
if(sel != -1) {
int i = SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_GETITEMDATA, sel, 0);
SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETCOLOUR, 0, colour_id_list_w2[i].second);
SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETDEFAULTCOLOUR, 0, colour_id_list_w2[i].first.defcolour);
}
}
if (HIWORD(wParam) != LBN_DBLCLK)
return TRUE;
//fall through
case IDC_BKGCOLOUR:
{
int sel = SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_GETCURSEL, 0, 0);
if(sel != -1) {
int i = SendDlgItemMessage(hwndDlg, IDC_COLOURLIST, CB_GETITEMDATA, sel, 0);
colour_id_list_w2[i].second = SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_GETCOLOUR, 0, 0);
if(wcscmp(colour_id_list_w2[i].first.name, TranslateW(L"Background")) == 0) {
DeleteObject(hBkgColourBrush);
hBkgColourBrush = CreateSolidBrush(SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_GETCOLOUR, 0, 0));
}
}
}
InvalidateRect(GetDlgItem(hwndDlg, IDC_FONTLIST), NULL, TRUE);
break;
case IDC_FONTGROUP:
if (HIWORD(wParam) == LBN_SELCHANGE) {
SendMessage(hwndDlg, M_SETFONTGROUP, 0, 0);
}
return TRUE;
case IDC_FONTLIST:
if (HIWORD(wParam) == LBN_SELCHANGE) {
if(font_id_list_w2.size()) {
int *selItems = (int *)mir_alloc(font_id_list_w2.size() * sizeof(int));
int sel, selCount, i;
selCount = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETSELITEMS, (WPARAM)font_id_list_w2.size(), (LPARAM) selItems);
if (selCount > 1) {
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETCOLOUR, 0, GetSysColor(COLOR_3DFACE));
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETDEFAULTCOLOUR, 0, GetSysColor(COLOR_WINDOWTEXT));
BOOL show_default = FALSE;
for (sel = 0; sel < selCount; sel++) {
i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA, selItems[sel], 0);
show_default |= (font_id_list_w2[i].first.flags & FIDF_DEFAULTVALID);
}
if(show_default) {
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_RESET), TRUE);
} else
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_RESET), FALSE);
}
else {
int i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA,
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETCURSEL, 0, 0), 0);
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETCOLOUR, 0, font_id_list_w2[i].second.colour);
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETDEFAULTCOLOUR, 0, (LPARAM)font_id_list_w2[i].first.deffontsettings.colour);
if(font_id_list_w2[i].first.flags & FIDF_DEFAULTVALID) {
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_RESET), TRUE);
} else
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_RESET), FALSE);
}
mir_free(selItems);
}
return TRUE;
}
if (HIWORD(wParam) != LBN_DBLCLK)
return TRUE;
//fall through
case IDC_CHOOSEFONT:
{
LOGFONTW lf = { 0 };
if(SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETCOUNT, 0, 0)) {
int sel = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETCURSEL, 0, 0);
int i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA, sel, 0);
CreateFromFontSettingsW(&font_id_list_w2[i].second, &lf, font_id_list_w2[i].first.flags);
CreateFontIndirectW(&lf);
CHOOSEFONTW cf = { 0 };
cf.lStructSize = sizeof(cf);
cf.hwndOwner = hwndDlg;
cf.lpLogFont = &lf;
if(font_id_list_w2[i].first.flags & FIDF_ALLOWEFFECTS) {
cf.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS | CF_ENABLETEMPLATE | CF_ENABLEHOOK;
// use custom font dialog to disable colour selection
cf.hInstance = hInstance;
cf.lpTemplateName = MAKEINTRESOURCEW(IDD_CUSTOM_FONT);
cf.lpfnHook = CFHookProc;
} else {
cf.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
}
if (ChooseFontW(&cf)) {
int *selItems = (int *)mir_alloc(font_id_list_w2.size() * sizeof(int));
int sel, selCount;
selCount = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETSELITEMS, (WPARAM)font_id_list_w2.size(), (LPARAM) selItems);
for (sel = 0; sel < selCount; sel++) {
i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA, selItems[sel], 0);
font_id_list_w2[i].second.size = (char)lf.lfHeight;
font_id_list_w2[i].second.style = (lf.lfWeight >= FW_BOLD ? DBFONTF_BOLD : 0) | (lf.lfItalic ? DBFONTF_ITALIC : 0) | (lf.lfUnderline ? DBFONTF_UNDERLINE : 0) | (lf.lfStrikeOut ? DBFONTF_STRIKEOUT : 0);
font_id_list_w2[i].second.charset = lf.lfCharSet;
wcscpy(font_id_list_w2[i].second.szFace, lf.lfFaceName);
{
MEASUREITEMSTRUCT mis = { 0 };
mis.CtlID = IDC_FONTLIST;
mis.itemData = i;
SendMessage(hwndDlg, WM_MEASUREITEM, 0, (LPARAM) & mis);
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_SETITEMHEIGHT, selItems[sel], mis.itemHeight);
}
}
mir_free(selItems);
InvalidateRect(GetDlgItem(hwndDlg, IDC_FONTLIST), NULL, TRUE);
break;
}
}
return TRUE;
}
case IDC_FONTCOLOUR:
{
if(font_id_list_w2.size()) {
int *selItems = (int *)mir_alloc(font_id_list_w2.size() * sizeof(int));
int sel, selCount, i;
selCount = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETSELITEMS, (WPARAM)font_id_list_w2.size(), (LPARAM) selItems);
for (sel = 0; sel < selCount; sel++) {
i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA, selItems[sel], 0);
font_id_list_w2[i].second.colour = SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_GETCOLOUR, 0, 0);
}
mir_free(selItems);
InvalidateRect(GetDlgItem(hwndDlg, IDC_FONTLIST), NULL, FALSE);
}
break;
}
case IDC_BTN_RESET:
{
if(font_id_list_w2.size()) {
int *selItems = (int *)mir_alloc(font_id_list_w2.size() * sizeof(int));
int sel, selCount, i;
selCount = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETSELITEMS, (WPARAM)font_id_list_w2.size(), (LPARAM) selItems);
for (sel = 0; sel < selCount; sel++) {
i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA, selItems[sel], 0);
if(font_id_list_w2[i].first.flags & FIDF_DEFAULTVALID) {
font_id_list_w2[i].second = font_id_list_w2[i].first.deffontsettings;
{
MEASUREITEMSTRUCT mis = { 0 };
mis.CtlID = IDC_FONTLIST;
mis.itemData = i;
SendMessage(hwndDlg, WM_MEASUREITEM, 0, (LPARAM) & mis);
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_SETITEMHEIGHT, selItems[sel], mis.itemHeight);
}
}
}
if (selCount > 1) {
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETCOLOUR, 0, GetSysColor(COLOR_3DFACE));
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETDEFAULTCOLOUR, 0, GetSysColor(COLOR_WINDOWTEXT));
}
else {
int i = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMDATA,
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETCURSEL, 0, 0), 0);
SendDlgItemMessage(hwndDlg, IDC_FONTCOLOUR, CPM_SETCOLOUR, 0, font_id_list_w2[i].second.colour);
}
mir_free(selItems);
InvalidateRect(GetDlgItem(hwndDlg, IDC_FONTLIST), NULL, FALSE);
}
break;
}
case IDC_BTN_UNDO:
{
font_id_list_w2 = font_id_list_w3;
colour_id_list_w2 = colour_id_list_w3;
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UNDO), FALSE);
SendDlgItemMessage(hwndDlg, IDC_FONTGROUP, LB_SETCURSEL, 0, 0);
SendMessage(hwndDlg, M_SETFONTGROUP, 0, 0);
break;
}
case IDC_BTN_EXPORT:
{
TCHAR fname_buff[MAX_PATH];
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = fname_buff;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH;
ofn.hwndOwner = hwndDlg;
ofn.Flags = OFN_NOREADONLYRETURN | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT;
ofn.lpstrFilter = _T("INI\0*.ini\0Text\0*.TXT\0All\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrDefExt = _T("ini");
if(GetSaveFileName(&ofn) == TRUE) {
if(!ExportSettings(hwndDlg, ofn.lpstrFile, font_id_list_w, colour_id_list_w))
MessageBox(hwndDlg, _T("Error writing file"), _T("Error"), MB_ICONWARNING | MB_OK);
}
return TRUE;
}
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
case WM_NOTIFY:
switch (((LPNMHDR) lParam)->idFrom) {
case 0:
switch (((LPNMHDR) lParam)->code) {
case PSN_APPLY:
{
font_id_list_w3 = font_id_list_w;
colour_id_list_w3 = colour_id_list_w;
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UNDO), TRUE);
font_id_list_w = font_id_list_w2;
colour_id_list_w = colour_id_list_w2;
char str[32];
FontIDSettingsWPair *it;
for (FontIDWList::Iterator lit = font_id_list_w2.start(); lit.has_val(); lit.next()) {
it = &lit.val();
if(it->first.flags & FIDF_APPENDNAME) wsprintfA(str, "%sName", it->first.prefix);
else wsprintfA(str, "%s", it->first.prefix);
if(DBWriteContactSettingWString(NULL, it->first.dbSettingsGroup, str, it->second.szFace)) {
char buff[1024];
WideCharToMultiByte(code_page, 0, it->second.szFace, -1, buff, 1024, 0, 0);
DBWriteContactSettingString(NULL, it->first.dbSettingsGroup, str, buff);
}
wsprintfA(str, "%sSize", it->first.prefix);
if(it->first.flags & FIDF_SAVEACTUALHEIGHT) {
HDC hdc;
SIZE size;
HFONT hFont, hOldFont;
LOGFONTW lf;
CreateFromFontSettingsW(&it->second, &lf, it->first.flags);
hFont = CreateFontIndirectW(&lf);
//hFont = CreateFontA(it->second.size, 0, 0, 0,
// it->second.style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL,
// it->second.style & DBFONTF_ITALIC ? 1 : 0, 0, 0, it->second.charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, it->second.szFace);
hdc = GetDC(hwndDlg);
hOldFont = (HFONT)SelectObject(hdc, hFont);
GetTextExtentPoint32(hdc, _T("_W"), 2, &size);
ReleaseDC(hwndDlg, hdc);
SelectObject(hdc, hOldFont);
DeleteObject(hFont);
DBWriteContactSettingByte(NULL, it->first.dbSettingsGroup, str, (char)size.cy);
} else if(it->first.flags & FIDF_SAVEPOINTSIZE) {
HDC hdc = GetDC(hwndDlg);
//lf->lfHeight = -MulDiv(lf->lfHeight,GetDeviceCaps(hdc, LOGPIXELSY), 72);
DBWriteContactSettingByte(NULL, it->first.dbSettingsGroup, str, (BYTE)-MulDiv(it->second.size, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
ReleaseDC(hwndDlg, hdc);
} else {
DBWriteContactSettingByte(NULL, it->first.dbSettingsGroup, str, it->second.size);
}
wsprintfA(str, "%sSty", it->first.prefix);
DBWriteContactSettingByte(NULL, it->first.dbSettingsGroup, str, it->second.style);
wsprintfA(str, "%sSet", it->first.prefix);
DBWriteContactSettingByte(NULL, it->first.dbSettingsGroup, str, it->second.charset);
wsprintfA(str, "%sCol", it->first.prefix);
DBWriteContactSettingDword(NULL, it->first.dbSettingsGroup, str, it->second.colour);
if(it->first.flags & FIDF_NOAS) {
wsprintfA(str, "%sAs", it->first.prefix);
DBWriteContactSettingWord(NULL, it->first.dbSettingsGroup, str, (WORD)0x00FF);
}
wsprintfA(str, "%sFlags", it->first.prefix);
DBWriteContactSettingWord(NULL, it->first.dbSettingsGroup, str, (WORD)it->first.flags);
}
ColourIDColourWPair *cit;
for(ColourIDWList::Iterator lcit = colour_id_list_w2.start(); lcit.has_val(); lcit.next()) {
cit = &lcit.val();
wsprintfA(str, "%s", cit->first.setting);
DBWriteContactSettingDword(NULL, cit->first.dbSettingsGroup, str, cit->second);
}
}
OptionsChanged();
return TRUE;
}
break;
}
break;
/*
// tooltip stuff
case WM_MOUSEMOVE:
#define X_OFFSET 15
#define Y_OFFSET 15
SendMessage(GetDlgItem(hwndDlg, IDC_TOOLTIP),TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti);
x = LOWORD(lParam);
y = HIWORD(lParam);
SendMessage(GetDlgItem(hwndDlg, IDC_TOOLTIP), TTM_TRACKPOSITION, 0, (LPARAM)MAKELPARAM(LOWORD(lParam) + X_OFFSET, HIWORD(lParam) + Y_OFFSET));
KillTimer(hwndDlg, TIMER_ID);
SetTimer(hwndDlg, TIMER_ID, 1000, 0);
break;
case WM_TIMER:
{
*/
/*
//POINT p;
RECT r;
GetClientRect(GetDlgItem(hwndDlg, IDC_FONTLIST), &r);
DWORD lParam = MAKELPARAM(x - r.left, y - r.bottom);
DWORD res = SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_ITEMFROMPOINT, 0, lParam);
if(HIWORD(res) == 0 && HIWORD(res) >= 0) {
char buf[256];
int sel = LOWORD(res);
//SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETITEMRECT, (WPARAM)sel, (LPARAM)&r);
SendDlgItemMessage(hwndDlg, IDC_FONTLIST, LB_GETTEXT, (WPARAM)sel, (LPARAM)buf);
*/
/*
KillTimer(hwndDlg, TIMER_ID);
SendMessage(GetDlgItem(hwndDlg, IDC_TOOLTIP),TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti);
MessageBox(hwndDlg, "Hi", "blah", MB_OK);
//}
break;
}
*/
case WM_DESTROY:
KillTimer(hwndDlg, TIMER_ID);
DeleteObject(hBkgColourBrush);
break;
}
return FALSE;
}
int OptInit(WPARAM wParam, LPARAM lParam) {
OPTIONSDIALOGPAGE odp = {0};
#define OPTIONPAGE_OLD_SIZE2 60
//odp.cbSize = sizeof(odp);
odp.cbSize = OPTIONPAGE_OLD_SIZE2;
odp.position = -790000000;
odp.hInstance = hInstance;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT2);
odp.pszTitle = Translate("Fonts");
odp.pszGroup = Translate("Customize");
odp.flags = ODPF_BOLDGROUPS;
odp.nIDBottomSimpleControl = 0;
odp.pfnDlgProc = DlgProcLogOptions;
CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp );
return 0;
}
|