forked from rizonesoft/Notepad3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrint.cpp
More file actions
770 lines (642 loc) · 26.9 KB
/
Copy pathPrint.cpp
File metadata and controls
770 lines (642 loc) · 26.9 KB
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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
// encoding: UTF-8
/******************************************************************************
* *
* *
* Notepad3 *
* *
* Print.cpp *
* Scintilla Printing Functionality *
* Based on code from Notepad2, (c) Florian Balmer 1996-2011 *
* *
* Mostly taken from SciTE, (c) Neil Hodgson *
* *
* (c) Rizonesoft 2008-2022 *
* https://rizonesoft.com *
* *
* *
*******************************************************************************/
#if (defined(_DEBUG) || defined(DEBUG)) && !defined(NDEBUG)
#define DBG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
// Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the
// allocations to be of _CLIENT_BLOCK type
#else
#define DBG_NEW new
#endif
#if !defined(WINVER)
#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/
#endif
#if !defined(_WIN32_WINNT)
#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/
#endif
#if !defined(NTDDI_VERSION)
#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/
#endif
#define VC_EXTRALEAN 1
#define WIN32_LEAN_AND_MEAN 1
#define NOMINMAX 1
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <string_view>
extern "C" {
#include "Helpers.h"
#include "MuiLanguage.h"
#include "Dialogs.h"
#include "SciCall.h"
}
#include "DarkMode/DarkMode.h"
extern "C" float Style_GetBaseFontSize();
// Stored objects...
static HGLOBAL hDevMode = nullptr;
static HGLOBAL hDevNames = nullptr;
static void EditPrintInit();
static void _StatusUpdatePrintPage(int iPageNum)
{
WCHAR tch[80] = { L'\0' };
FormatLngStringW(tch,COUNTOF(tch),IDS_MUI_PRINTFILE,iPageNum);
StatusSetText(Globals.hwndStatus, STATUS_HELP, tch);
//InvalidateRect(Globals.hwndStatus,NULL,TRUE);
}
//=============================================================================
//
// LPPRINTHOOKPROC _LPPrintHookProc()
//
static UINT_PTR CALLBACK _LPPrintHookProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg) {
case WM_INITDIALOG: {
SetDialogIconNP3(hwnd);
InitWindowCommon(hwnd, true);
#ifdef D_NP3_WIN10_DARK_MODE
if (UseDarkMode()) {
SetExplorerTheme(GetDlgItem(hwnd, IDOK));
SetExplorerTheme(GetDlgItem(hwnd, IDCANCEL));
SetExplorerTheme(GetDlgItem(hwnd, 0x401));
int const ctl[] = { chx1, rad1, rad2, rad3, grp1, grp2, grp4, cmb4 };
for (int i = 0; i < COUNTOF(ctl); ++i) {
SetWindowTheme(GetDlgItem(hwnd, ctl[i]), L"", L""); // remove theme for BS_AUTORADIOBUTTON
}
}
#endif
SendMessage(hwnd, WM_THEMECHANGED, 0, 0);
}
break;
case WM_DPICHANGED:
UpdateWindowLayoutForDPI(hwnd, (RECT*)lParam, 0);
break;
#ifdef D_NP3_WIN10_DARK_MODE
CASE_WM_CTLCOLOR_SET:
return SetDarkModeCtlColors((HDC)wParam, UseDarkMode());
break;
case WM_SETTINGCHANGE:
if (IsDarkModeSupported() && IsColorSchemeChangeMessage(lParam)) {
SendMessage(hwnd, WM_THEMECHANGED, 0, 0);
}
break;
case WM_THEMECHANGED:
if (IsDarkModeSupported()) {
bool const darkModeEnabled = CheckDarkModeEnabled();
AllowDarkModeForWindowEx(hwnd, darkModeEnabled);
RefreshTitleBarThemeColor(hwnd);
int const buttons[] = { IDOK, IDCANCEL, 0x401 };
for (int id = 0; id < COUNTOF(buttons); ++id) {
HWND const hBtn = GetDlgItem(hwnd, buttons[id]);
AllowDarkModeForWindowEx(hBtn, darkModeEnabled);
SendMessage(hBtn, WM_THEMECHANGED, 0, 0);
}
UpdateWindowEx(hwnd);
}
break;
#endif
case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
}
break;
default:
break;
}
return FALSE;
}
//=============================================================================
//
// EditPrint() - Code from SciTE
//
extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat)
{
// Don't print empty documents
if (SendMessage(hwnd,SCI_GETLENGTH,0,0) == 0) {
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_PRINT_EMPTY);
return true;
}
PRINTDLG pdlg = { sizeof(PRINTDLG), nullptr, nullptr, nullptr, nullptr,
0, 0, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
};
pdlg.hwndOwner = GetParent(hwnd);
pdlg.hInstance = Globals.hInstance;
pdlg.Flags = PD_ENABLEPRINTHOOK | PD_USEDEVMODECOPIES | PD_ALLPAGES | PD_RETURNDC;
pdlg.nFromPage = 1;
pdlg.nToPage = 1;
pdlg.nMinPage = 1;
pdlg.nMaxPage = 0xffffU;
pdlg.nCopies = 1;
pdlg.hDC = nullptr;
pdlg.hDevMode = hDevMode;
pdlg.hDevNames = hDevNames;
pdlg.lpfnPrintHook = _LPPrintHookProc;
DocPos const startPos = SciCall_GetSelectionStart();
DocPos const endPos = SciCall_GetSelectionEnd();
if (startPos == endPos) {
pdlg.Flags |= PD_NOSELECTION;
} else {
pdlg.Flags |= PD_SELECTION;
}
// |= 0 - Don't display dialog box, just use the default printer and options
pdlg.Flags |= (Flags.PrintFileAndLeave == 1) ? PD_RETURNDEFAULT : 0;
if (!PrintDlg(&pdlg)) {
return true; // False means error...
}
hDevMode = pdlg.hDevMode;
hDevNames = pdlg.hDevNames;
HDC const hdc = pdlg.hDC;
// Get printer resolution
POINT ptDpi;
ptDpi.x = GetDeviceCaps(hdc, LOGPIXELSX); // dpi in X direction
ptDpi.y = GetDeviceCaps(hdc, LOGPIXELSY); // dpi in Y direction
// Start by getting the physical page size (in device units).
POINT ptPage;
ptPage.x = GetDeviceCaps(hdc, PHYSICALWIDTH); // device units
ptPage.y = GetDeviceCaps(hdc, PHYSICALHEIGHT); // device units
// Get the dimensions of the unprintable
// part of the page (in device units).
RECT rectPhysMargins;
rectPhysMargins.left = GetDeviceCaps(hdc, PHYSICALOFFSETX);
rectPhysMargins.top = GetDeviceCaps(hdc, PHYSICALOFFSETY);
// To get the right and lower unprintable area,
// we take the entire width and height of the paper and
// subtract everything else.
rectPhysMargins.right = ptPage.x // total paper width
- GetDeviceCaps(hdc, HORZRES) // printable width
- rectPhysMargins.left; // left unprintable margin
rectPhysMargins.bottom = ptPage.y // total paper height
- GetDeviceCaps(hdc, VERTRES) // printable height
- rectPhysMargins.top; // right unprintable margin
// At this point, rectPhysMargins contains the widths of the
// unprintable regions on all four sides of the page in device units.
EditPrintInit();
RECT rectMargins;
// Take in account the page setup given by the user (if one value is not null)
if (Settings.PrintMargin.left != 0 || Settings.PrintMargin.right != 0 ||
Settings.PrintMargin.top != 0 || Settings.PrintMargin.bottom != 0) {
// Convert the hundredths of millimeters (HiMetric) or
// thousandths of inches (HiEnglish) margin values
// from the Page Setup dialog to device units.
// (There are 2540 hundredths of a mm in an inch.)
WCHAR localeInfo[SMALL_BUFFER];
GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, COUNTOF(localeInfo));
RECT rectSetup;
if (localeInfo[0] == L'0') { // Metric system. L'1' is US System
rectSetup.left = MulDiv (Settings.PrintMargin.left, ptDpi.x, 2540);
rectSetup.top = MulDiv (Settings.PrintMargin.top, ptDpi.y, 2540);
rectSetup.right = MulDiv(Settings.PrintMargin.right, ptDpi.x, 2540);
rectSetup.bottom = MulDiv(Settings.PrintMargin.bottom, ptDpi.y, 2540);
} else {
rectSetup.left = MulDiv(Settings.PrintMargin.left, ptDpi.x, 1000);
rectSetup.top = MulDiv(Settings.PrintMargin.top, ptDpi.y, 1000);
rectSetup.right = MulDiv(Settings.PrintMargin.right, ptDpi.x, 1000);
rectSetup.bottom = MulDiv(Settings.PrintMargin.bottom, ptDpi.y, 1000);
}
// Don't reduce margins below the minimum printable area
rectMargins.left = max_l(rectPhysMargins.left, rectSetup.left);
rectMargins.top = max_l(rectPhysMargins.top, rectSetup.top);
rectMargins.right = max_l(rectPhysMargins.right, rectSetup.right);
rectMargins.bottom = max_l(rectPhysMargins.bottom, rectSetup.bottom);
} else {
rectMargins.left = rectPhysMargins.left;
rectMargins.top = rectPhysMargins.top;
rectMargins.right = rectPhysMargins.right;
rectMargins.bottom = rectPhysMargins.bottom;
}
// rectMargins now contains the values used to shrink the printable
// area of the page.
// Convert device coordinates into logical coordinates
DPtoLP(hdc, (LPPOINT)&rectMargins, 2);
DPtoLP(hdc, (LPPOINT)&rectPhysMargins, 2);
// Convert page size to logical units and we're done!
DPtoLP(hdc, (LPPOINT) &ptPage, 1);
int headerLineHeight = MulDiv(8, ptDpi.y, 72);
HFONT fontHeader = CreateFont(headerLineHeight,
0, 0, 0,
FW_BOLD,
0,
0,
0, 0, 0,
0, 0, 0,
L"Arial");
SelectObject(hdc, fontHeader);
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
headerLineHeight = tm.tmHeight + tm.tmExternalLeading;
if (Settings.PrintHeader == 3) {
headerLineHeight = 0;
}
int footerLineHeight = MulDiv(7,ptDpi.y, 72);
HFONT fontFooter = CreateFont(footerLineHeight,
0, 0, 0,
FW_REGULAR,
0,
0,
0, 0, 0,
0, 0, 0,
L"Arial");
SelectObject(hdc, fontFooter);
GetTextMetrics(hdc, &tm);
footerLineHeight = tm.tmHeight + tm.tmExternalLeading;
if (Settings.PrintFooter == 1) {
footerLineHeight = 0;
}
DOCINFO di = { sizeof(DOCINFO), nullptr, nullptr, nullptr, 0 };
di.lpszDocName = pszDocTitle;
di.lpszOutput = nullptr;
di.lpszDatatype = nullptr;
di.fwType = 0;
if (StartDoc(hdc, &di) < 0) {
DeleteDC(hdc);
if (fontHeader) {
DeleteObject(fontHeader);
}
if (fontFooter) {
DeleteObject(fontFooter);
}
return false;
}
// Get current date...
WCHAR dateString[MIDSZ_BUFFER] = { L'\0' };
SYSTEMTIME st;
GetLocalTime(&st);
GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&st,nullptr,dateString,MIDSZ_BUFFER);
// Get current time...
if (Settings.PrintHeader == 0) {
WCHAR timeString[SMALL_BUFFER] = { L'\0' };
GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,nullptr,timeString,SMALL_BUFFER);
StringCchCat(dateString,COUNTOF(dateString),L" ");
StringCchCat(dateString,COUNTOF(dateString),timeString);
}
// Set print color mode
int printColorModes[6] = {
SC_PRINT_NORMAL,
SC_PRINT_INVERTLIGHT,
SC_PRINT_BLACKONWHITE,
SC_PRINT_COLOURONWHITE,
SC_PRINT_COLOURONWHITEDEFAULTBG,
SC_PRINT_SCREENCOLOURS
};
SendMessage(hwnd,SCI_SETPRINTCOLOURMODE,printColorModes[Settings.PrintColorMode],0);
//SendMessage(hwnd, SCI_SETPRINTWRAPMODE, SC_WRAP_WORD, 0); // default: SC_WRAP_WORD
// Set print magnification...
SendMessage(hwnd, SCI_SETPRINTMAGNIFICATION, (WPARAM)Settings.PrintZoom, 0);
DocPos const lengthDocMax = SciCall_GetTextLength();
DocPos lengthDoc = lengthDocMax;
DocPos lengthPrinted = 0;
// Requested to print selection
if (pdlg.Flags & PD_SELECTION) {
if (startPos > endPos) {
lengthPrinted = endPos;
lengthDoc = startPos;
} else {
lengthPrinted = startPos;
lengthDoc = endPos;
}
if (lengthPrinted < 0) {
lengthPrinted = 0;
}
if (lengthDoc > lengthDocMax) {
lengthDoc = lengthDocMax;
}
}
// We must substract the physical margins from the printable area
struct Sci_RangeToFormat frPrint;
frPrint.hdc = hdc;
frPrint.hdcTarget = hdc;
frPrint.rc.left = rectMargins.left - rectPhysMargins.left;
frPrint.rc.top = rectMargins.top - rectPhysMargins.top;
frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left;
frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top;
frPrint.rcPage.left = 0;
frPrint.rcPage.top = 0;
frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1;
frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1;
frPrint.rc.top += headerLineHeight + headerLineHeight / 2;
frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2;
// Print each page
int pageNum = 1;
WCHAR pageString[32] = { L'\0' };
while (lengthPrinted < lengthDoc) {
bool printPage = (!(pdlg.Flags & PD_PAGENUMS) ||
((pageNum >= pdlg.nFromPage) && (pageNum <= pdlg.nToPage)));
StringCchPrintf(pageString,COUNTOF(pageString),pszPageFormat,pageNum);
if (printPage) {
// Show wait cursor...
SciCall_SetCursor(SC_CURSORWAIT);
// Display current page number in Statusbar
_StatusUpdatePrintPage(pageNum);
StartPage(hdc);
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF));
SelectObject(hdc, fontHeader);
UINT ta = SetTextAlign(hdc, TA_BOTTOM);
RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2,
frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2
};
rcw.bottom = rcw.top + headerLineHeight;
if (Settings.PrintHeader < 3) {
ExtTextOut(hdc, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2,
/*ETO_OPAQUE*/0, &rcw, pszDocTitle,
(UINT)StringCchLenW(pszDocTitle,0), nullptr);
}
// Print date in header
if (Settings.PrintHeader == 0 || Settings.PrintHeader == 1) {
SIZE sizeInfo;
SelectObject(hdc,fontFooter);
GetTextExtentPoint32(hdc,dateString,(int)StringCchLenW(dateString,COUNTOF(dateString)),&sizeInfo);
ExtTextOut(hdc, frPrint.rc.right - 5 - sizeInfo.cx, frPrint.rc.top - headerLineHeight / 2,
/*ETO_OPAQUE*/0, &rcw, dateString,
(UINT)StringCchLenW(dateString,COUNTOF(dateString)), nullptr);
}
if (Settings.PrintHeader < 3) {
SetTextAlign(hdc, ta);
HPEN pen = CreatePen(0, 1, RGB(0,0,0));
HPEN const penOld = (HPEN)SelectObject(hdc, pen);
MoveToEx(hdc, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, nullptr);
LineTo(hdc, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4);
SelectObject(hdc, penOld);
DeleteObject(pen);
}
}
frPrint.chrg.cpMin = static_cast<DocPosCR>(lengthPrinted);
frPrint.chrg.cpMax = static_cast<DocPosCR>(lengthDoc);
lengthPrinted = (int)SendMessage(hwnd, SCI_FORMATRANGE, printPage, (LPARAM)&frPrint);
if (printPage) {
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF));
SelectObject(hdc, fontFooter);
UINT ta = SetTextAlign(hdc, TA_TOP);
RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2,
frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2
};
if (Settings.PrintFooter == 0) {
SIZE sizeFooter;
GetTextExtentPoint32(hdc,pageString,(int)StringCchLenW(pageString,COUNTOF(pageString)),&sizeFooter);
ExtTextOut(hdc, frPrint.rc.right - 5 - sizeFooter.cx, frPrint.rc.bottom + footerLineHeight / 2,
/*ETO_OPAQUE*/0, &rcw, pageString,
(UINT)StringCchLenW(pageString,COUNTOF(pageString)), nullptr);
SetTextAlign(hdc, ta);
HPEN pen = ::CreatePen(0, 1, RGB(0,0,0));
HPEN const penOld = (HPEN)SelectObject(hdc, pen);
SetBkColor(hdc, RGB(0,0,0));
MoveToEx(hdc, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, nullptr);
LineTo(hdc, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4);
SelectObject(hdc, penOld);
DeleteObject(pen);
}
EndPage(hdc);
}
pageNum++;
if ((pdlg.Flags & PD_PAGENUMS) && (pageNum > pdlg.nToPage)) {
break;
}
}
SendMessage(hwnd,SCI_FORMATRANGE, false, 0);
EndDoc(hdc);
DeleteDC(hdc);
if (fontHeader) {
DeleteObject(fontHeader);
}
if (fontFooter) {
DeleteObject(fontFooter);
}
// Remove wait cursor...
{
POINT pt;
SciCall_SetCursor(SC_CURSORNORMAL);
GetCursorPos(&pt);
SetCursorPos(pt.x, pt.y);
}
return true;
}
//=============================================================================
//
// LPSETUPHOOKPROC LPSetupHookProc() - Code from SciTE
//
// Custom controls: 30 Zoom
// 31 Spin
// 32 Header
// 33 Footer
// 34 Colors
//
static UINT_PTR CALLBACK _LPSetupHookProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (uiMsg) {
case WM_INITDIALOG: {
WCHAR tch[512];
WCHAR *p1, *p2;
SetDialogIconNP3(hwnd);
InitWindowCommon(hwnd, true);
#ifdef D_NP3_WIN10_DARK_MODE
if (UseDarkMode()) {
SetExplorerTheme(GetDlgItem(hwnd, IDOK));
SetExplorerTheme(GetDlgItem(hwnd, IDCANCEL));
SetExplorerTheme(GetDlgItem(hwnd, IDC_PRINTER));
int const ctl[] = { 30, 31, 32, 33, 34, cmb2, cmb3, 1037, 1038, 1056, 1057, 1072, 1073, 1074, 1075, 1076, 1089, 1090,
IDC_STATIC, IDC_STATIC2, IDC_STATIC3, IDC_STATIC4, IDC_STATIC5, IDC_STATIC6
};
for (int i = 0; i < COUNTOF(ctl); ++i) {
SetWindowTheme(GetDlgItem(hwnd, ctl[i]), L"", L""); // remove theme for BS_AUTORADIOBUTTON
}
}
#endif
UDACCEL const acc[1] = { { 0, 10 } };
SendDlgItemMessage(hwnd, 30, EM_LIMITTEXT, 32, 0);
SendDlgItemMessage(hwnd, 31, UDM_SETACCEL, 1, (WPARAM)acc);
SendDlgItemMessage(hwnd, 31, UDM_SETRANGE32, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL);
SendDlgItemMessage(hwnd, 31, UDM_SETPOS32, 0, Settings.PrintZoom);
// Set header options
GetLngString(IDS_MUI_PRINT_HEADER, tch, COUNTOF(tch));
StringCchCat(tch, COUNTOF(tch), L"|");
p1 = tch;
p2 = StrChr(p1, L'|');
while (p2) {
*p2++ = L'\0';
if (*p1) {
SendDlgItemMessage(hwnd, 32, CB_ADDSTRING, 0, (LPARAM)p1);
}
p1 = p2;
p2 = StrChr(p1, L'|'); // next
}
SendDlgItemMessage(hwnd, 32, CB_SETCURSEL, (WPARAM)Settings.PrintHeader, 0);
// Set footer options
GetLngString(IDS_MUI_PRINT_FOOTER, tch, COUNTOF(tch));
StringCchCat(tch, COUNTOF(tch), L"|");
p1 = tch;
p2 = StrChr(p1, L'|');
while (p2) {
*p2++ = L'\0';
if (*p1) {
SendDlgItemMessage(hwnd, 33, CB_ADDSTRING, 0, (LPARAM)p1);
}
p1 = p2;
p2 = StrChr(p1, L'|'); // next
}
SendDlgItemMessage(hwnd, 33, CB_SETCURSEL, (WPARAM)Settings.PrintFooter, 0);
// Set color options
GetLngString(IDS_MUI_PRINT_COLOR, tch, COUNTOF(tch));
StringCchCat(tch, COUNTOF(tch), L"|");
p1 = tch;
p2 = StrChr(p1, L'|');
while (p2) {
*p2++ = L'\0';
if (*p1) {
SendDlgItemMessage(hwnd, 34, CB_ADDSTRING, 0, (LPARAM)p1);
}
p1 = p2;
p2 = StrChr(p1, L'|'); // next
}
SendDlgItemMessage(hwnd, 34, CB_SETCURSEL, (LPARAM)Settings.PrintColorMode, 0);
// Make combos handier
SendDlgItemMessage(hwnd, 32, CB_SETEXTENDEDUI, true, 0);
SendDlgItemMessage(hwnd, 33, CB_SETEXTENDEDUI, true, 0);
SendDlgItemMessage(hwnd, 34, CB_SETEXTENDEDUI, true, 0);
SendDlgItemMessage(hwnd, 1137, CB_SETEXTENDEDUI, true, 0);
SendDlgItemMessage(hwnd, 1138, CB_SETEXTENDEDUI, true, 0);
SendMessage(hwnd, WM_THEMECHANGED, 0, 0);
}
break;
case WM_DPICHANGED:
UpdateWindowLayoutForDPI(hwnd, (RECT *)lParam, 0);
break;
#ifdef D_NP3_WIN10_DARK_MODE
CASE_WM_CTLCOLOR_SET:
return SetDarkModeCtlColors((HDC)wParam, UseDarkMode());
break;
case WM_SETTINGCHANGE:
if (IsDarkModeSupported() && IsColorSchemeChangeMessage(lParam)) {
SendMessage(hwnd, WM_THEMECHANGED, 0, 0);
}
break;
case WM_THEMECHANGED:
if (IsDarkModeSupported()) {
bool const darkModeEnabled = CheckDarkModeEnabled();
AllowDarkModeForWindowEx(hwnd, darkModeEnabled);
RefreshTitleBarThemeColor(hwnd);
int const buttons[] = { IDOK, IDCANCEL, IDC_PRINTER };
for (int id = 0; id < COUNTOF(buttons); ++id) {
HWND const hBtn = GetDlgItem(hwnd, buttons[id]);
AllowDarkModeForWindowEx(hBtn, darkModeEnabled);
SendMessage(hBtn, WM_THEMECHANGED, 0, 0);
}
UpdateWindowEx(hwnd);
}
break;
#endif
case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
BOOL bError = FALSE;
int const iZoom = (int)SendDlgItemMessage(hwnd, 31, UDM_GETPOS32, 0, (LPARAM)&bError);
Settings.PrintZoom = bError ? Defaults.PrintZoom : iZoom;
/*int const iFontSize = (int)*/ SendDlgItemMessage(hwnd, 41, UDM_GETPOS32, 0, (LPARAM)&bError);
Settings.PrintHeader = (int)SendDlgItemMessage(hwnd, 32, CB_GETCURSEL, 0, 0);
Settings.PrintFooter = (int)SendDlgItemMessage(hwnd, 33, CB_GETCURSEL, 0, 0);
Settings.PrintColorMode = (int)SendDlgItemMessage(hwnd, 34, CB_GETCURSEL, 0, 0);
} else if (LOWORD(wParam) == IDC_PRINTER) {
PostWMCommand(hwnd, 1026);
}
break;
default:
break;
}
return FALSE;
}
extern "C" void EditPrintSetup(HWND hwnd)
{
DLGTEMPLATE* const pDlgTemplate = LoadThemedDialogTemplate(MAKEINTRESOURCE(IDD_MUI_PAGESETUP),Globals.hLngResContainer);
PAGESETUPDLG pdlg = { sizeof(PAGESETUPDLG) };
pdlg.Flags = PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGESETUPTEMPLATEHANDLE;
pdlg.lpfnPageSetupHook = _LPSetupHookProc;
pdlg.hPageSetupTemplate = pDlgTemplate;
pdlg.hwndOwner = GetParent(hwnd);
pdlg.hInstance = Globals.hInstance;
EditPrintInit();
if (Settings.PrintMargin.left != 0 || Settings.PrintMargin.right != 0 ||
Settings.PrintMargin.top != 0 || Settings.PrintMargin.bottom != 0) {
pdlg.Flags |= PSD_MARGINS;
pdlg.rtMargin.left = Settings.PrintMargin.left;
pdlg.rtMargin.top = Settings.PrintMargin.top;
pdlg.rtMargin.right = Settings.PrintMargin.right;
pdlg.rtMargin.bottom = Settings.PrintMargin.bottom;
}
pdlg.hDevMode = hDevMode;
pdlg.hDevNames = hDevNames;
if (PageSetupDlg(&pdlg)) {
Settings.PrintMargin.left = pdlg.rtMargin.left;
Settings.PrintMargin.top = pdlg.rtMargin.top;
Settings.PrintMargin.right = pdlg.rtMargin.right;
Settings.PrintMargin.bottom = pdlg.rtMargin.bottom;
hDevMode = pdlg.hDevMode;
hDevNames = pdlg.hDevNames;
}
FreeMem(pDlgTemplate);
}
//=============================================================================
//
// EditPrintInit() - Setup default page margin if no values from registry
//
static void EditPrintInit()
{
if (Settings.PrintMargin.left <= -1 || Settings.PrintMargin.top <= -1 ||
Settings.PrintMargin.right <= -1 || Settings.PrintMargin.bottom <= -1) {
WCHAR localeInfo[3];
GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);
LONG const _margin = (localeInfo[0] == L'0') ? 2000L : 1000L; // Metric system. L'1' is US System
Settings.PrintMargin = { _margin, _margin, _margin, _margin };
}
}
#if 0
#include <fcntl.h>
#include <io.h>
//#include <iostream>
//#include <fstream>
void RedirectIOToConsole()
{
int hConHandle;
intptr_t lStdHandle;
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
// allocate a console for this app
AllocConsole();
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = 500;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
// redirect unbuffered STDOUT to the console
lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
// redirect unbuffered STDIN to the console
lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "r");
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
// redirect unbuffered STDERR to the console
lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
}
#endif
// End of Print.cpp