Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/teraprn.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9038 - (hide annotations) (download) (as text)
Sun Nov 29 15:26:19 2020 UTC (3 years, 4 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 16134 byte(s)
グローバル変数削除

- PrnDlg
- PrnBox()内でグローバル変数 PrintDC にセットしないようにした
- Prnlf
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3     * (C) 2007-2017 TeraTerm Project
4     * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227
30     /* TERATERM.EXE, Printing routines */
31     #include "teraterm.h"
32     #include "tttypes.h"
33     #include <commdlg.h>
34     #include <stdio.h>
35 zmatsuo 7936 #include <crtdbg.h>
36 maya 3227
37     #include "ttwinman.h"
38     #include "commlib.h"
39     #include "ttcommon.h"
40     #include "ttlib.h"
41 zmatsuo 7290 #include "win16api.h"
42 maya 3227
43     #include "tt_res.h"
44 zmatsuo 7528 #include "tmfc.h"
45 maya 3227 #include "prnabort.h"
46    
47     #include "teraprn.h"
48    
49 zmatsuo 7936 #ifdef _DEBUG
50     #if defined(_MSC_VER)
51     #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
52 maya 3227 #endif
53 zmatsuo 7936 #endif
54 maya 3227
55     static HDC PrintDC;
56     static HFONT PrnFont[AttrFontMask+1];
57     static int PrnFW, PrnFH;
58     static RECT Margin;
59     static COLORREF White, Black;
60     static int PrnX, PrnY;
61     static int PrnDx[256];
62     static TCharAttr PrnAttr;
63    
64     static BOOL Printing = FALSE;
65     static BOOL PrintAbortFlag = FALSE;
66    
67     /* pass-thru printing */
68 maya 4031 static char PrnFName[MAX_PATH];
69 zmatsuo 7290 static HANDLE HPrnFile = INVALID_HANDLE_VALUE;
70 maya 3227 static char PrnBuff[TermWidthMax];
71     static int PrnBuffCount = 0;
72    
73     static CPrnAbortDlg *PrnAbortDlg;
74     static HWND HPrnAbortDlg;
75    
76     /* Print Abortion Call Back Function */
77 zmatsuo 7933 static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
78 maya 3227 {
79 maya 3392 MSG m;
80 maya 3227
81 maya 3392 while ((! PrintAbortFlag) && PeekMessage(&m, 0,0,0, PM_REMOVE))
82     if ((HPrnAbortDlg==NULL) || (! IsDialogMessage(HPrnAbortDlg, &m))) {
83     TranslateMessage(&m);
84     DispatchMessage(&m);
85     }
86 maya 3227
87 maya 3392 if (PrintAbortFlag) {
88     HPrnAbortDlg = NULL;
89     PrnAbortDlg = NULL;
90     return FALSE;
91     }
92     else {
93     return TRUE;
94     }
95 maya 3227 }
96    
97 yutakapon 8331 static UINT_PTR CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
98     {
99     return 0;
100     }
101    
102 maya 3227 HDC PrnBox(HWND HWin, PBOOL Sel)
103     {
104 maya 3392 /* initialize PrnDlg record */
105 zmatsuo 9038 PRINTDLGW PrnDlg = {};
106     PrnDlg.lStructSize = sizeof(PrnDlg);
107 maya 3392 PrnDlg.hwndOwner = HWin;
108 yutakapon 8331 PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP | PD_ENABLEPRINTHOOK;
109 maya 3392 if (! *Sel) {
110 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
111     } else {
112     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
113 maya 3392 }
114     PrnDlg.nCopies = 1;
115 yutakapon 8331 /*
116     * Windows NT�n���������A�����_�C�A���O���w���v�{�^�����\�����������A
117     * �v���V�[�W�����t�b�N�����B
118     */
119     PrnDlg.lpfnPrintHook = PrintHookProc;
120 maya 3227
121 maya 3392 /* 'Print' dialog box */
122 zmatsuo 9038 if (! PrintDlgW(&PrnDlg)) {
123 maya 3392 return NULL; /* if 'Cancel' button clicked, exit */
124     }
125     if (PrnDlg.hDC == NULL) {
126     return NULL;
127     }
128     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
129 zmatsuo 9038 return PrnDlg.hDC;
130 maya 3227 }
131    
132     BOOL PrnStart(LPSTR DocumentName)
133     {
134 zmatsuo 7527 DOCINFOA Doc;
135 maya 3392 char DocName[50];
136 zmatsuo 7933 HWND hParent;
137 maya 3227
138 maya 3392 Printing = FALSE;
139     PrintAbortFlag = FALSE;
140 maya 3227
141 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
142     if (PrnAbortDlg==NULL) {
143     return FALSE;
144     }
145     if (ActiveWin==IdVT) {
146 zmatsuo 7933 hParent = HVTWin;
147 maya 3392 }
148     else {
149 zmatsuo 7933 hParent = HTEKWin;
150 maya 3392 }
151 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
152 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
153 maya 3227
154 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
155 maya 3227
156 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
157 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
158     Doc.lpszDocName = DocName;
159     Doc.lpszOutput = NULL;
160     Doc.lpszDatatype = NULL;
161     Doc.fwType = 0;
162 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
163 maya 3392 Printing = TRUE;
164     }
165     else {
166     if (PrnAbortDlg != NULL) {
167     PrnAbortDlg->DestroyWindow();
168     PrnAbortDlg = NULL;
169     HPrnAbortDlg = NULL;
170     }
171     }
172     return Printing;
173 maya 3227 }
174    
175     void PrnStop()
176     {
177 maya 3392 if (Printing) {
178     EndDoc(PrintDC);
179     DeleteDC(PrintDC);
180     Printing = FALSE;
181     }
182     if (PrnAbortDlg != NULL) {
183     PrnAbortDlg->DestroyWindow();
184     PrnAbortDlg = NULL;
185     HPrnAbortDlg = NULL;
186     }
187 maya 3227 }
188    
189     int VTPrintInit(int PrnFlag)
190     // Initialize printing of VT window
191     // PrnFlag: specifies object to be printed
192     // = IdPrnScreen Current screen
193     // = IdPrnSelectedText Selected text
194     // = IdPrnScrollRegion Scroll region
195     // = IdPrnFile Spooled file (printer sequence)
196     // Return: print object ID specified by user
197     // = IdPrnCancel (user clicks "Cancel" button)
198     // = IdPrnScreen (user don't select "print selection" option)
199     // = IdPrnSelectedText (user selects "print selection")
200     // = IdPrnScrollRegion (always when PrnFlag=IdPrnScrollRegion)
201     // = IdPrnFile (always when PrnFlag=IdPrnFile)
202 doda 6435 {
203 maya 3392 BOOL Sel;
204     TEXTMETRIC Metrics;
205     POINT PPI, PPI2;
206     HDC DC;
207     int i;
208     TCharAttr TempAttr = {
209     AttrDefault,
210     AttrDefault,
211     AttrDefaultFG,
212     AttrDefaultBG
213     };
214 zmatsuo 9038 LOGFONTA Prnlf;
215 maya 3227
216 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
217 zmatsuo 9038 PrintDC = PrnBox(HVTWin,&Sel);
218     if (PrintDC == NULL) {
219 maya 3392 return (IdPrnCancel);
220     }
221 maya 3227
222 maya 3392 /* start printing */
223     if (! PrnStart(ts.Title)) {
224     return (IdPrnCancel);
225     }
226 maya 3227
227 maya 3392 /* initialization */
228     StartPage(PrintDC);
229 maya 3227
230 maya 3392 /* pixels per inch */
231     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
232     PPI = ts.VTPPI;
233     }
234     else {
235     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
236     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
237     }
238 maya 3227
239 maya 3392 /* left margin */
240     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
241     /* right margin */
242     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
243     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
244     /* top margin */
245     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
246     /* bottom margin */
247     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
248     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
249 maya 3227
250 maya 3392 /* create test font */
251 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
252 maya 3227
253 maya 3392 if (ts.PrnFont[0]==0) {
254     Prnlf.lfHeight = ts.VTFontSize.y;
255     Prnlf.lfWidth = ts.VTFontSize.x;
256     Prnlf.lfCharSet = ts.VTFontCharSet;
257     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
258     }
259     else {
260     Prnlf.lfHeight = ts.PrnFontSize.y;
261     Prnlf.lfWidth = ts.PrnFontSize.x;
262     Prnlf.lfCharSet = ts.PrnFontCharSet;
263     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
264     }
265     Prnlf.lfWeight = FW_NORMAL;
266     Prnlf.lfItalic = 0;
267     Prnlf.lfUnderline = 0;
268     Prnlf.lfStrikeOut = 0;
269     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
270     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
271     Prnlf.lfQuality = DEFAULT_QUALITY;
272     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
273 maya 3227
274 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
275 maya 3227
276 maya 3392 DC = GetDC(HVTWin);
277     SelectObject(DC, PrnFont[0]);
278     GetTextMetrics(DC, &Metrics);
279     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
280     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
281     ReleaseDC(HVTWin,DC);
282     DeleteObject(PrnFont[0]); /* Delete test font */
283 maya 3227
284 maya 3392 /* Adjust font size */
285     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
286     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
287 maya 3227
288 maya 3392 /* Create New Fonts */
289 maya 3227
290 maya 3392 /* Normal Font */
291     Prnlf.lfWeight = FW_NORMAL;
292     Prnlf.lfUnderline = 0;
293 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
294 maya 3392 SelectObject(PrintDC,PrnFont[0]);
295     GetTextMetrics(PrintDC, &Metrics);
296     PrnFW = Metrics.tmAveCharWidth;
297     PrnFH = Metrics.tmHeight;
298     /* Under line */
299     Prnlf.lfUnderline = 1;
300 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
301 maya 3227
302 doda 3666 if (ts.FontFlag & FF_BOLD) {
303 maya 3392 /* Bold */
304     Prnlf.lfUnderline = 0;
305     Prnlf.lfWeight = FW_BOLD;
306 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
307 maya 3392 /* Bold + Underline */
308     Prnlf.lfUnderline = 1;
309 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
310 maya 3392 }
311     else {
312     PrnFont[AttrBold] = PrnFont[AttrDefault];
313     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
314     }
315     /* Special font */
316     Prnlf.lfWeight = FW_NORMAL;
317     Prnlf.lfUnderline = 0;
318     Prnlf.lfWidth = PrnFW; /* adjust width */
319     Prnlf.lfHeight = PrnFH;
320     Prnlf.lfCharSet = SYMBOL_CHARSET;
321 maya 3227
322 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
323 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
324 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
325     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
326     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
327 maya 3227
328 maya 3392 Black = RGB(0,0,0);
329     White = RGB(255,255,255);
330     for (i = 0 ; i <= 255 ; i++) {
331     PrnDx[i] = PrnFW;
332     }
333     PrnSetAttr(TempAttr);
334 maya 3227
335 maya 3392 PrnY = Margin.top;
336     PrnX = Margin.left;
337 maya 3227
338 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
339     return (IdPrnScrollRegion);
340     }
341     if (PrnFlag == IdPrnFile) {
342     return (IdPrnFile);
343     }
344     if (Sel) {
345     return (IdPrnSelectedText);
346     }
347     else {
348     return (IdPrnScreen);
349     }
350 maya 3227 }
351 zmatsuo 7291
352 maya 3227 void PrnSetAttr(TCharAttr Attr)
353     // Set text attribute of printing
354     //
355     {
356 maya 3392 PrnAttr = Attr;
357     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
358 maya 3227
359 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
360     SetTextColor(PrintDC,White);
361     SetBkColor( PrintDC,Black);
362     }
363     else {
364     SetTextColor(PrintDC,Black);
365     SetBkColor( PrintDC,White);
366     }
367 maya 3227 }
368    
369     void PrnOutText(PCHAR Buff, int Count)
370     // Print out text
371     // Buff: points text buffer
372     // Count: number of characters to be printed
373     {
374 maya 3392 int i;
375     RECT RText;
376     PCHAR Ptr, Ptr1, Ptr2;
377     char Buff2[256];
378 maya 3227
379 maya 3392 if (Count<=0) {
380     return;
381     }
382     if (Count>(sizeof(Buff2)-1)) {
383     Count=sizeof(Buff2)-1;
384     }
385     memcpy(Buff2,Buff,Count);
386     Buff2[Count] = 0;
387     Ptr = Buff2;
388 maya 3227
389 maya 3392 if (ts.Language==IdRussian) {
390     if (ts.PrnFont[0]==0) {
391     RussConvStr(ts.RussClient,ts.RussFont,Buff2,Count);
392     }
393     else {
394     RussConvStr(ts.RussClient,ts.RussPrint,Buff2,Count);
395     }
396     }
397 maya 3227
398 maya 3392 do {
399     if (PrnX+PrnFW > Margin.right) {
400     /* new line */
401     PrnX = Margin.left;
402     PrnY = PrnY + PrnFH;
403     }
404     if (PrnY+PrnFH > Margin.bottom) {
405     /* next page */
406     EndPage(PrintDC);
407     StartPage(PrintDC);
408     PrnSetAttr(PrnAttr);
409     PrnY = Margin.top;
410     }
411 maya 3227
412 maya 3392 i = (Margin.right-PrnX) / PrnFW;
413     if (i==0) {
414     i=1;
415     }
416     if (i>Count) {
417     i=Count;
418     }
419 maya 3227
420 maya 3392 if (i<Count) {
421     Ptr2 = Ptr;
422     do {
423     Ptr1 = Ptr2;
424 zmatsuo 7527 Ptr2 = CharNextA(Ptr1);
425 maya 3392 } while ((Ptr2!=NULL) && ((Ptr2-Ptr)<=i));
426     i = Ptr1-Ptr;
427     if (i<=0) {
428     i=1;
429     }
430     }
431 maya 3227
432 maya 3392 RText.left = PrnX;
433     RText.right = PrnX + i*PrnFW;
434     RText.top = PrnY;
435     RText.bottom = PrnY+PrnFH;
436 zmatsuo 7527 ExtTextOutA(PrintDC,PrnX,PrnY,6,&RText,Ptr,i,&PrnDx[0]);
437 maya 3392 PrnX = RText.right;
438     Count=Count-i;
439     Ptr = Ptr + i;
440     } while (Count>0);
441 maya 3227
442     }
443    
444     void PrnNewLine()
445     // Moves to the next line in printing
446     {
447 maya 3392 PrnX = Margin.left;
448     PrnY = PrnY + PrnFH;
449 maya 3227 }
450    
451     void VTPrintEnd()
452     {
453 maya 3392 int i, j;
454 maya 3227
455 maya 3392 EndPage(PrintDC);
456 maya 3227
457 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
458     for (j = i+1 ; j <= AttrFontMask ; j++) {
459     if (PrnFont[j]==PrnFont[i]) {
460     PrnFont[j] = NULL;
461     }
462     }
463     if (PrnFont[i] != NULL) {
464     DeleteObject(PrnFont[i]);
465     }
466     }
467 maya 3227
468 maya 3392 PrnStop();
469     return;
470 maya 3227 }
471    
472     /* printer emulation routines */
473     void OpenPrnFile()
474     {
475 maya 4031 char Temp[MAX_PATH];
476 maya 3227
477 maya 3392 KillTimer(HVTWin,IdPrnStartTimer);
478 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
479 maya 3392 return;
480     }
481     if (PrnFName[0] == 0) {
482 zmatsuo 7527 GetTempPathA(sizeof(Temp),Temp);
483     if (GetTempFileNameA(Temp,"tmp",0,PrnFName)==0) {
484 maya 3392 return;
485     }
486     HPrnFile = _lcreat(PrnFName,0);
487     }
488     else {
489     HPrnFile = _lopen(PrnFName,OF_WRITE);
490 zmatsuo 7290 if (HPrnFile == INVALID_HANDLE_VALUE) {
491 maya 3392 HPrnFile = _lcreat(PrnFName,0);
492     }
493     }
494 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
495 maya 3392 _llseek(HPrnFile,0,2);
496     }
497 maya 3227 }
498    
499     void PrintFile()
500     {
501 maya 3392 char Buff[256];
502     BOOL CRFlag = FALSE;
503     int c, i;
504     BYTE b;
505 maya 3227
506 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
507     HPrnFile = _lopen(PrnFName,OF_READ);
508 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
509 maya 3392 do {
510     i = 0;
511     do {
512     c = _lread(HPrnFile,&b,1);
513     if (c==1) {
514     switch (b) {
515     case HT:
516     memset(&(Buff[i]),0x20,8);
517     i = i + 8;
518     CRFlag = FALSE;
519     break;
520     case LF:
521     CRFlag = ! CRFlag;
522     break;
523     case FF:
524     case CR:
525     CRFlag = TRUE;
526     break;
527     default:
528     if (b >= 0x20) {
529     Buff[i] = b;
530     i++;
531     }
532     CRFlag = FALSE;
533     break;
534     }
535     }
536     if (i>=(sizeof(Buff)-7)) {
537     CRFlag=TRUE;
538     }
539     } while ((c>0) && (! CRFlag));
540     if (i>0) {
541     PrnOutText(Buff, i);
542     }
543     if (CRFlag) {
544     PrnX = Margin.left;
545     if ((b==FF) && (ts.PrnConvFF==0)) { // new page
546     PrnY = Margin.bottom;
547     }
548     else { // new line
549     PrnY = PrnY + PrnFH;
550     }
551     }
552     CRFlag = (b==CR);
553     } while (c>0);
554     _lclose(HPrnFile);
555 maya 3227 }
556 maya 3392 HPrnFile = 0;
557     VTPrintEnd();
558 maya 3227 }
559 maya 3392 remove(PrnFName);
560     PrnFName[0] = 0;
561 maya 3227 }
562    
563     void PrintFileDirect()
564     {
565 zmatsuo 7933 HWND hParent;
566 maya 3227
567 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
568     if (PrnAbortDlg==NULL) {
569     remove(PrnFName);
570     PrnFName[0] = 0;
571     return;
572     }
573     if (ActiveWin==IdVT) {
574 zmatsuo 7933 hParent = HVTWin;
575 maya 3392 }
576     else {
577 zmatsuo 7933 hParent = HTEKWin;
578 maya 3392 }
579 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
580 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
581 maya 3227
582 maya 3392 HPrnFile = _lopen(PrnFName,OF_READ);
583 zmatsuo 7290 PrintAbortFlag = (HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev);
584 maya 3392 PrnBuffCount = 0;
585     SetTimer(HVTWin,IdPrnProcTimer,0,NULL);
586 maya 3227 }
587    
588     void PrnFileDirectProc()
589     {
590 maya 3392 int c;
591 maya 3227
592 zmatsuo 7290 if (HPrnFile==INVALID_HANDLE_VALUE) {
593 maya 3392 return;
594     }
595     if (PrintAbortFlag) {
596     HPrnAbortDlg = NULL;
597     PrnAbortDlg = NULL;
598     PrnCancel();
599     }
600 zmatsuo 7290 if (!PrintAbortFlag && (HPrnFile != INVALID_HANDLE_VALUE)) {
601 maya 3392 do {
602     if (PrnBuffCount==0) {
603     PrnBuffCount = _lread(HPrnFile,PrnBuff,1);
604     if (ts.Language==IdRussian) {
605     RussConvStr(ts.RussClient,ts.RussPrint,PrnBuff,PrnBuffCount);
606     }
607     }
608 maya 3227
609 maya 3392 if (PrnBuffCount==1) {
610     c = PrnWrite(PrnBuff,1);
611     if (c==0) {
612     SetTimer(HVTWin,IdPrnProcTimer,10,NULL);
613     return;
614     }
615     PrnBuffCount = 0;
616     }
617     else {
618     c = 0;
619     }
620     } while (c>0);
621 maya 3227 }
622 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
623 maya 3392 _lclose(HPrnFile);
624     }
625 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
626 maya 3392 PrnClose();
627     remove(PrnFName);
628     PrnFName[0] = 0;
629     if (PrnAbortDlg!=NULL) {
630     PrnAbortDlg->DestroyWindow();
631     PrnAbortDlg = NULL;
632     HPrnAbortDlg = NULL;
633     }
634 maya 3227 }
635    
636     void PrnFileStart()
637     {
638 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
639 maya 3392 return;
640     }
641     if (PrnFName[0]==0) {
642     return;
643     }
644     if (ts.PrnDev[0]!=0) {
645     PrintFileDirect(); // send file directry to printer port
646     }
647     else { // print file by using Windows API
648     PrintFile();
649     }
650 maya 3227 }
651    
652     void ClosePrnFile()
653     {
654 maya 3392 PrnBuffCount = 0;
655 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
656 maya 3392 _lclose(HPrnFile);
657     }
658 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
659 maya 3392 SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
660 maya 3227 }
661    
662     void WriteToPrnFile(BYTE b, BOOL Write)
663     // (b,Write) =
664     // (0,FALSE): clear buffer
665     // (0,TRUE): write buffer to file
666     // (b,FALSE): put b in buff
667     // (b,TRUE): put b in buff and
668     // write buffer to file
669     {
670 maya 3392 if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) {
671     PrnBuff[PrnBuffCount++] = b;
672     }
673 maya 3227
674 maya 3392 if (Write) {
675     _lwrite(HPrnFile,PrnBuff,PrnBuffCount);
676     PrnBuffCount = 0;
677     }
678     if ((b==0) && ! Write) {
679     PrnBuffCount = 0;
680     }
681 maya 3227 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26