-
Notifications
You must be signed in to change notification settings - Fork 0
/
apxprint.cpp
173 lines (135 loc) · 4.8 KB
/
apxprint.cpp
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
//----------------------------------------------------------------------------
// Project SwitchMin
// DoubleVision, LTD
// Copyright © 1997. All Rights Reserved.
//
// SUBSYSTEM: SwitchMin Application
// FILE: apxprint.cpp
// AUTHOR: Pat B. Double
//
// OVERVIEW
// ~~~~~~~~
// Source file for implementation of Printing.
//
//----------------------------------------------------------------------------
#include "SwitchMinEXE_Global.h"
#include "apxprint.h"
// Do not enable page range in the print dialog since only one page is
// available to be printed
//
void TApxPrintout::GetDialogInfo(int& minPage, int&, int& selFromPage, int&)
{
minPage = 1;
selFromPage = 0;
}
void TApxPrintout::BeginPrinting()
{
TRect clientR;
BeginPage(clientR);
HFONT hFont = (HFONT)Window->GetWindowFont();
TFont font("Arial", -12);
if (!hFont)
DC->SelectObject(font);
else
DC->SelectObject(TFont(hFont));
TEXTMETRIC tm;
int fHeight = DC->GetTextMetrics(tm) ? tm.tmHeight + tm.tmExternalLeading : 10;
DC->RestoreFont();
// How many lines of this font can we fit on a page.
//
int linesPerPage = MulDiv(clientR.Height(), 1, fHeight);
TPrintDialog::TData& printerData = Printer->GetSetup();
// GetMinMaxInfo event is overrided to return the number of lines when printing.
//
MINMAXINFO minmaxinfo;
Window->SendMessage(WM_GETMINMAXINFO, 0, (long)&minmaxinfo);
int maxPg = (minmaxinfo.ptMaxSize.y / linesPerPage) + 1.0;
// Compute the number of pages to print.
//
printerData.MinPage = 1;
printerData.MaxPage = maxPg;
EndPage();
TPrintout::BeginPrinting();
}
void TApxPrintout::BeginPage(TRect& clientR)
{
TScreenDC screenDC;
TSize screenRes(screenDC.GetDeviceCaps(LOGPIXELSX),
screenDC.GetDeviceCaps(LOGPIXELSY));
TSize printRes(DC->GetDeviceCaps(LOGPIXELSX),
DC->GetDeviceCaps(LOGPIXELSY));
// Temporarily change the window size (so any WM_PAINT queries on the total window size (GetClientRect) is
// the window size for the WM_PAINT of the window and the printer page size when Paint is called from
// PrintPage. Notice, we don't use AdjustWindowRect because its harder and not accurate. Instead we
// compute the difference (in pixels) between the client window and the frame window. This difference
// is then added to the clientRect to compute the new frame window size for SetWindowPos.
//
clientR = Window->GetClientRect();
Window->MapWindowPoints(HWND_DESKTOP, (TPoint*)&clientR, 2);
// Compute extra X and Y pixels to bring a client window dimensions to equal the frame window.
//
OrgR = Window->GetWindowRect();
int adjX = OrgR.Width() - clientR.Width();
int adjY = OrgR.Height() - clientR.Height();
// Conditionally scale the DC to the window so the printout will resemble the window.
//
if (Scale) {
clientR = Window->GetClientRect();
PrevMode = DC->SetMapMode(MapMode);
DC->SetViewportExt(PageSize, &OldVExt);
// Scale window to logical page size (assumes left & top are 0)
//
clientR.right = MulDiv(PageSize.cx, screenRes.cx, printRes.cx);
clientR.bottom = MulDiv(PageSize.cy, screenRes.cy, printRes.cy);
DC->SetWindowExt(clientR.Size(), &OldWExt);
}
// Compute the new size of the window based on the printer DC dimensions.
// Resize the window, notice position, order, and redraw are not done the window size changes but the user
// doesn't see any visible change to the window.
//
Window->SetRedraw(false);
Window->SetWindowPos(0, 0, 0, clientR.Width() + adjX, clientR.Height() + adjY,
SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER| SWP_NOACTIVATE);
}
void TApxPrintout::PrintPage(int page, TRect& bandRect, unsigned)
{
TRect clientR;
BeginPage(clientR);
if (Scale)
DC->DPtoLP(bandRect, 2);
// Change the printer range to this current page.
//
TPrintDialog::TData& printerData = Printer->GetSetup();
int fromPg = printerData.FromPage;
int toPg = printerData.ToPage;
printerData.FromPage = page;
printerData.ToPage = page;
// Call the window to paint itself to the printer DC.
//
Window->Paint(*DC, false, bandRect);
printerData.FromPage = fromPg;
printerData.ToPage = toPg;
if (Scale)
DC->LPtoDP(bandRect, 2);
EndPage();
}
void TApxPrintout::EndPage()
{
// Resize to original window size, no one's the wiser.
//
Window->SetWindowPos(0, 0, 0, OrgR.Width(), OrgR.Height(),
SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER| SWP_NOACTIVATE);
Window->SetRedraw(true);
// Restore changes made to the DC
//
if (Scale) {
DC->SetWindowExt(OldWExt);
DC->SetViewportExt(OldVExt);
DC->SetMapMode(PrevMode);
}
}
bool TApxPrintout::HasPage(int pageNumber)
{
TPrintDialog::TData& printerData = Printer->GetSetup();
return pageNumber >= printerData.MinPage && pageNumber <= printerData.MaxPage;
}