📄 tprint.c
字号:
int pages;
/***************************************************************************
* Function: gtab_printjob
*
* Purpose:
*
* Sets up print job and dialogs
*/
void
gtab_printjob(HWND hwnd, lpTable ptab, lpPrintContext pcontext)
{
int moveables;
int endpage;
int startpage = 1;
HDC hpr;
int status;
HANDLE hcurs;
static char str[256];
DOCINFO di;
CHAR szPage[60]; /* for LoadString */
hcurs = SetCursor(LoadCursor(NULL, IDC_WAIT));
moveables = ptab->nlines - ptab->hdr.fixedrows;
pages = (int) (ptab->hdr.nrows - ptab->hdr.fixedrows + moveables - 1)
/ moveables;
endpage = pages;
if (pcontext->pd->Flags & PD_PAGENUMS) {
startpage = pcontext->pd->nFromPage;
endpage = pcontext->pd->nToPage;
}
hpr = pcontext->pd->hDC;
lpAbortDlg = (DLGPROC) MakeProcInstance((WNDPROC) AbortDlg, hLibInst);
lpAbortProc = (FARPROC) MakeProcInstance((WNDPROC)AbortProc, hLibInst);
SetAbortProc(hpr, (ABORTPROC) lpAbortProc);
ZeroMemory( &di, sizeof( DOCINFO ) );
di.lpszDocName = "Table";
di.cbSize = sizeof( DOCINFO );
di.lpszOutput = NULL;
StartDoc(hpr, &di);
bAbort = FALSE;
/* add abort modeless dialog later!! */
hAbortWnd = CreateDialog(hLibInst, "GABRTDLG", hwnd, lpAbortDlg);
if (hAbortWnd != NULL) {
ShowWindow(hAbortWnd, SW_NORMAL);
EnableWindow(hwnd, FALSE);
}
SetCursor(hcurs);
for (npage = startpage; npage<=endpage; npage++) {
LoadString(hLibInst, IDS_PAGE_STR, szPage, sizeof(szPage));
wsprintf(str, szPage, npage, pages);
SetDlgItemText(hAbortWnd, IDC_LPAGENR, str);
status = gtab_printpage(hwnd, ptab, pcontext, npage);
if (status < 0) {
AbortDoc(hpr);
break;
}
}
if (status >= 0) {
EndDoc(hpr);
}
if (hAbortWnd != NULL) {
EnableWindow(hwnd, TRUE);
DestroyWindow(hAbortWnd);
}
FreeProcInstance((WNDPROC) lpAbortDlg);
FreeProcInstance(lpAbortProc);
DeleteDC(hpr);
}
/***************************************************************************
* Function: AbortProc
*
* Purpose:
*
* Abort procedure for print job
*/
int APIENTRY
AbortProc(HDC hpr, int code)
{
MSG msg;
if (!hAbortWnd) {
return(TRUE);
}
while (!bAbort && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (!IsDialogMessage(hAbortWnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(!bAbort);
}
/***************************************************************************
* Function: AbortDlg
*
* Purpose:
*
* Dialog for abort procedure
*/
int APIENTRY
AbortDlg(HWND hdlg, UINT msg, UINT wParam, LONG lParam)
{
switch(msg) {
case WM_COMMAND:
bAbort = TRUE;
DestroyWindow (hdlg);
return TRUE;
case WM_INITDIALOG:
return TRUE;
}
return(FALSE);
}
/***************************************************************************
* Function: gtab_printpage
*
* Purpose:
*
* Print a single page. page number is 1-based
*/
BOOL
gtab_printpage(HWND hwnd, lpTable ptab, lpPrintContext pcontext, int page)
{
HDC hpr;
int moveables, i;
int x1, y1, x2, y2;
hpr = pcontext->pd->hDC;
StartPage(hpr);
moveables = ptab->nlines - ptab->hdr.fixedrows;
ptab->toprow = moveables * (page-1);
gtab_invallines(hwnd, ptab, ptab->hdr.fixedrows, moveables);
for (i =0; i < ptab->nlines; i++) {
gtab_paint(hwnd, hpr, ptab, i);
}
if ((ptab->hdr.vseparator) && (ptab->hdr.fixedcols > 0)) {
x1 = ptab->pcellpos[ptab->hdr.fixedcols -1].clipend+1;
y1 = ptab->pdata[0].linepos.clipstart;
y2 = ptab->pdata[ptab->nlines-1].linepos.clipend;
MoveToEx(hpr, x1, y1, NULL);
LineTo(hpr, x1, y2);
}
if ((ptab->hdr.hseparator) && (ptab->hdr.fixedrows > 0)) {
y1 = ptab->pdata[ptab->hdr.fixedrows-1].linepos.clipend;
x1 = ptab->pcellpos[0].clipstart;
x2 = ptab->pcellpos[ptab->hdr.ncols-1].clipend;
MoveToEx(hpr, x1, y1, NULL);
LineTo(hpr, x2, y1);
}
if (pcontext->head != NULL) {
gtab_printhead(hwnd, hpr, ptab, pcontext->head, page);
}
if (pcontext->foot != NULL) {
gtab_printhead(hwnd, hpr, ptab, pcontext->foot, page);
}
return(EndPage(hpr));
}
/***************************************************************************
* Function: gtab_setrects
*
* Purpose:
*
* Calculate the outline positions in pixels for the headers
* (outer rect) and for the page itself (inner rect). Based on
* page size and PrintContext margin info (which is in millimetres).
*/
void
gtab_setrects(lpPrintContext pcontext, LPRECT rcinner, LPRECT rcouter)
{
HDC hpr;
int hpixels, hmms;
int vpixels, vmms;
int h_pixpermm, v_pixpermm;
hpr = pcontext->pd->hDC;
hpixels = GetDeviceCaps(hpr, HORZRES);
vpixels = GetDeviceCaps(hpr, VERTRES);
vmms = GetDeviceCaps(hpr, VERTSIZE);
hmms = GetDeviceCaps(hpr, HORZSIZE);
h_pixpermm = hpixels / hmms;
v_pixpermm = vpixels / vmms;
rcouter->top = (pcontext->margin->top * v_pixpermm);
rcouter->bottom = vpixels - (pcontext->margin->bottom * v_pixpermm);
rcouter->left = (pcontext->margin->left * h_pixpermm);
rcouter->right = hpixels - (pcontext->margin->right * h_pixpermm);
rcinner->left = rcouter->left;
rcinner->right = rcouter->right;
rcinner->top = rcouter->top +
(pcontext->margin->topinner * v_pixpermm);
rcinner->bottom = rcouter->bottom -
(pcontext->margin->bottominner * v_pixpermm);
}
/***************************************************************************
* Function: gtab_printhead
*
* Purpose:
*
* Print header information
*/
void
gtab_printhead(HWND hwnd, HDC hdc, lpTable ptab, lpTitle head, int page)
{
RECT rc, rcbox;
int i, cx, x, y, tab;
UINT align;
LPSTR chp, tabp;
DWORD fcol, bkcol;
char str[256];
rc.top = head->ypos.clipstart;
rc.bottom = head->ypos.clipend;
rc.left = head->xpos.clipstart;
rc.right = head->xpos.clipend;
/* update page number */
chp = str;
for (i = 0; i < lstrlen(head->ptext); i++) {
switch(head->ptext[i]) {
case '#':
chp += wsprintf(chp, "%d", page);
break;
case '$':
chp += wsprintf(chp, "%d", pages);
break;
default:
if (IsDBCSLeadByte(head->ptext[i]) &&
head->ptext[i+1]) {
*chp = head->ptext[i];
chp++;
i++;
}
*chp++ = head->ptext[i];
break;
}
}
*chp = '\0';
chp = str;
if (head->props.valid & P_ALIGN) {
align = head->props.alignment;
} else {
align = P_LEFT;
}
/* set colours if not default */
if (head->props.valid & P_FCOLOUR) {
fcol = SetTextColor(hdc, head->props.forecolour);
}
if (head->props.valid & P_BCOLOUR) {
bkcol = SetBkColor(hdc, head->props.backcolour);
}
/* calc offset of text within cell for right-align or centering */
if (align == P_LEFT) {
cx = ptab->avewidth/2;
} else {
cx = LOWORD(GetTextExtent(hdc, chp, lstrlen(chp)));
if (align == P_CENTRE) {
cx = (head->xpos.size - cx) / 2;
} else {
cx = head->xpos.size - cx - (ptab->avewidth/2);
}
}
cx += head->xpos.start;
/* expand tabs on output */
tab = ptab->avewidth * 8;
x = 0;
y = head->ypos.start;
for ( ; (tabp = strchr(chp, '\t')) != NULL; ) {
/* perform output upto tab char */
ExtTextOut(hdc, x+cx, y, ETO_CLIPPED, &rc, chp, tabp-chp, NULL);
/* advance past the tab */
x += LOWORD(GetTextExtent(hdc, chp, tabp - chp));
x = ( (x + tab) / tab) * tab;
chp = ++tabp;
}
/*no more tabs - output rest of string */
ExtTextOut(hdc, x+cx, y, ETO_CLIPPED, &rc, chp, lstrlen(chp), NULL);
/* reset colours to original if not default */
if (head->props.valid & P_FCOLOUR) {
SetTextColor(hdc, fcol);
}
if (head->props.valid & P_BCOLOUR) {
SetBkColor(hdc, bkcol);
}
/* now box cell if marked */
if (head->props.valid & P_BOX) {
if (head->props.box != 0) {
rcbox.top = head->ypos.start;
rcbox.bottom = rcbox.top + head->ypos.size;
rcbox.left = head->xpos.start;
rcbox.right = rcbox.left + head->xpos.size;
gtab_boxcell(hwnd, hdc, &rcbox, &rc, head->props.box);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -