home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- * Zap *
- * === *
- * *
- * Windows 3 Text Editor *
- * *
- * Printing module *
- * BOOL PrintFile(int); *
- * int FAR PASCAL AbortProc(HDC, int); *
- * int FAR PASCAL AbortDlg(HWND, unsigned, WORD, LONG); *
- * *
- * This programme was developed using Microsoft C6.0 and the Microsoft *
- * SDK, however any ANSI C could be used if suitable libraries and the *
- * Windows header are available. *
- ***********************************************************************/
-
- #include <windows.h>
- #include <commdlg.h>
- #include <string.h>
- #include "zap.h"
- #include "zapdlg.h"
-
-
- /***********************************************************************
- * External variables *
- ***********************************************************************/
-
- extern HANDLE hInst;
- extern HWND hMainWnd;
-
- extern EDIT_WND EditWnd[MAX_FILES];
- extern int NumFiles, CurrentFile;
-
- extern FARPROC lpNewEditWndProc;
-
- extern HANDLE hTransBuf;
- extern LPSTR TransBuf;
-
- extern int CharWd, CharDp;
-
- extern char WorkStr[WORK_STR_LEN];
-
-
- /***********************************************************************
- * Global variables *
- ***********************************************************************/
-
- static PRINTDLG PrintDlgStruct;
- static HDC hPrintDC;
- static RECT PrintRect;
- static int CharDp;
-
- static HWND hAbortDlgWnd;
- static BOOL AbortPrintJob;
-
-
- /***********************************************************************
- * Routine to print a file or files *
- ***********************************************************************/
-
- BOOL PrintFile(int Id)
- { int tabs[16], cur_line_pos, len, i, j;
- FARPROC lpAbortProc, lpAbortDlg;
- TEXTMETRIC tm;
-
- /*** Open printer */
-
- PrintDlgStruct.lStructSize = sizeof(PRINTDLG);
- PrintDlgStruct.hwndOwner = hMainWnd;
- PrintDlgStruct.hDevMode = (HANDLE) NULL;
- PrintDlgStruct.hDevNames = (HANDLE) NULL;
- PrintDlgStruct.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION;
- PrintDlgStruct.nCopies = 0;
- PrintDlgStruct.hInstance = (HANDLE) NULL;
-
- if (!PrintDlg(&PrintDlgStruct)) return(FALSE);
-
- hPrintDC = PrintDlgStruct.hDC;
-
- /*** Set abort print routine */
-
- lpAbortProc = MakeProcInstance(AbortProc, hInst);
- Escape(hPrintDC, SETABORTPROC, NULL, (LPSTR)(LONG)lpAbortProc, (LPSTR) NULL);
-
- /*** Start print run */
-
- if (Escape(hPrintDC, STARTDOC, 3, "Zap", (LPSTR) NULL) < 0)
- { Comment("Unable to start print job");
- FreeProcInstance(lpAbortProc);
- DeleteDC(hPrintDC);
- return(FALSE);
- }
-
- /*** Open abort print dialog box */
-
- AbortPrintJob = FALSE;
- lpAbortDlg = MakeProcInstance(AbortDlg, hInst);
- if (!(hAbortDlgWnd = CreateDialog(hInst, "AbortBox", hMainWnd, lpAbortDlg)))
- { Comment("Cannot open printer dialog box");
- FreeProcInstance(lpAbortDlg);
- FreeProcInstance(lpAbortProc);
- DeleteDC(hPrintDC);
- return(FALSE);
- }
-
- ShowWindow (hAbortDlgWnd, SW_NORMAL);
- UpdateWindow(hAbortDlgWnd);
-
- /*** Disable main window to avoid reentrancy problems */
-
- EnableWindow(hMainWnd, FALSE);
-
- /*** Set page layout */
-
- GetTextMetrics(hPrintDC, &tm);
- CharDp = tm.tmHeight + tm.tmExternalLeading;
- for (i = 0; i < 16; i++) tabs[i] = tm.tmAveCharWidth*8*i;
-
- PrintRect.right = GetDeviceCaps(hPrintDC, HORZRES);
- PrintRect.bottom = GetDeviceCaps(hPrintDC, VERTRES);
-
- PrintRect.left = min(PrintRect.right/10, GetDeviceCaps(hPrintDC, LOGPIXELSX));
- PrintRect.top = min(PrintRect.bottom/10, GetDeviceCaps(hPrintDC, LOGPIXELSY));
- PrintRect.bottom -= PrintRect.top + CharDp;
-
- /*** Now print the file */
-
- len = GetWindowText(EditWnd[Id].hwnd, TransBuf, TRANS_BUF_SIZE);
- cur_line_pos = PrintRect.top;
-
- i = 0;
- while (i < len)
- { for (j = 0; TransBuf[i+j] != '\r' && TransBuf[i+j] != '\0'; j++);
-
- TabbedTextOut(hPrintDC, PrintRect.left, cur_line_pos, TransBuf + i, j, 16, tabs, PrintRect.left);
- cur_line_pos += CharDp;
- if (cur_line_pos > PrintRect.bottom)
- { Escape(hPrintDC, NEWFRAME, 0, 0L, 0L);
- cur_line_pos = PrintRect.top;
- }
-
- i += j + 2;
- }
-
- if (cur_line_pos > PrintRect.top) Escape(hPrintDC, NEWFRAME, 0, 0L, 0L);
-
- /*** Clean up and exit */
-
- if (!AbortPrintJob)
- { SetDlgItemText(hAbortDlgWnd, IDD_ABORT_STATUS, "Formatting page");
- Escape(hPrintDC, ENDDOC, 0, 0L, 0L);
- }
- EnableWindow(hMainWnd, TRUE);
-
- DestroyWindow(hAbortDlgWnd);
- FreeProcInstance(lpAbortDlg);
- FreeProcInstance(lpAbortProc);
- DeleteDC(hPrintDC);
-
- /*** Return signalling success */
-
- return(TRUE);
- }
-
-
- /***********************************************************************
- * Abort routine for printer *
- ***********************************************************************/
-
- int FAR PASCAL AbortProc(HDC hPr, int Code)
- { MSG msg;
-
- while (!AbortPrintJob && PeekMessage(&msg, NULL, NULL, NULL, TRUE))
- if (!IsDialogMessage(hAbortDlgWnd, &msg))
- { TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return (!AbortPrintJob);
- }
-
-
- /***********************************************************************
- * Message handler for abort printer dialog box *
- ***********************************************************************/
-
- int FAR PASCAL AbortDlg(HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
- {
- switch(msg)
- { case WM_COMMAND:
- if (wParam == IDCANCEL)
- { AbortPrintJob = TRUE;
- return(TRUE);
- }
- break;
-
- case WM_INITDIALOG:
- SetFocus(GetDlgItem(hDlg, IDCANCEL));
- return (TRUE);
- }
-
- return (FALSE);
- }
-
-