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 7936 - (hide annotations) (download) (as text)
Sat Aug 10 07:32:44 2019 UTC (4 years, 8 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 15943 byte(s)
印字中止ダイアログがダイアログフォントの設定どおりになるよう修正

- ダイアログフォントの設定を考慮していなかった
- teraterm/teraprn.cpp 未使用変数、マクロ削除、debug用new設定
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 PRINTDLG PrnDlg;
56    
57     static HDC PrintDC;
58 zmatsuo 7527 static LOGFONTA Prnlf;
59 maya 3227 static HFONT PrnFont[AttrFontMask+1];
60     static int PrnFW, PrnFH;
61     static RECT Margin;
62     static COLORREF White, Black;
63     static int PrnX, PrnY;
64     static int PrnDx[256];
65     static TCharAttr PrnAttr;
66    
67     static BOOL Printing = FALSE;
68     static BOOL PrintAbortFlag = FALSE;
69    
70     /* pass-thru printing */
71 maya 4031 static char PrnFName[MAX_PATH];
72 zmatsuo 7290 static HANDLE HPrnFile = INVALID_HANDLE_VALUE;
73 maya 3227 static char PrnBuff[TermWidthMax];
74     static int PrnBuffCount = 0;
75    
76     static CPrnAbortDlg *PrnAbortDlg;
77     static HWND HPrnAbortDlg;
78    
79     /* Print Abortion Call Back Function */
80 zmatsuo 7933 static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
81 maya 3227 {
82 maya 3392 MSG m;
83 maya 3227
84 maya 3392 while ((! PrintAbortFlag) && PeekMessage(&m, 0,0,0, PM_REMOVE))
85     if ((HPrnAbortDlg==NULL) || (! IsDialogMessage(HPrnAbortDlg, &m))) {
86     TranslateMessage(&m);
87     DispatchMessage(&m);
88     }
89 maya 3227
90 maya 3392 if (PrintAbortFlag) {
91     HPrnAbortDlg = NULL;
92     PrnAbortDlg = NULL;
93     return FALSE;
94     }
95     else {
96     return TRUE;
97     }
98 maya 3227 }
99    
100     HDC PrnBox(HWND HWin, PBOOL Sel)
101     {
102 maya 3392 /* initialize PrnDlg record */
103     memset(&PrnDlg, 0, sizeof(PRINTDLG));
104     PrnDlg.lStructSize = sizeof(PRINTDLG);
105     PrnDlg.hwndOwner = HWin;
106     PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP;
107     if (! *Sel) {
108 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
109     } else {
110     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
111 maya 3392 }
112     PrnDlg.nCopies = 1;
113 maya 3227
114 maya 3392 /* 'Print' dialog box */
115     if (! PrintDlg(&PrnDlg)) {
116     return NULL; /* if 'Cancel' button clicked, exit */
117     }
118     if (PrnDlg.hDC == NULL) {
119     return NULL;
120     }
121     PrintDC = PrnDlg.hDC;
122     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
123     return PrintDC;
124 maya 3227 }
125    
126     BOOL PrnStart(LPSTR DocumentName)
127     {
128 zmatsuo 7527 DOCINFOA Doc;
129 maya 3392 char DocName[50];
130 zmatsuo 7933 HWND hParent;
131 maya 3227
132 maya 3392 Printing = FALSE;
133     PrintAbortFlag = FALSE;
134 maya 3227
135 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
136     if (PrnAbortDlg==NULL) {
137     return FALSE;
138     }
139     if (ActiveWin==IdVT) {
140 zmatsuo 7933 hParent = HVTWin;
141 maya 3392 }
142     else {
143 zmatsuo 7933 hParent = HTEKWin;
144 maya 3392 }
145 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
146 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
147 maya 3227
148 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
149 maya 3227
150 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
151 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
152     Doc.lpszDocName = DocName;
153     Doc.lpszOutput = NULL;
154     Doc.lpszDatatype = NULL;
155     Doc.fwType = 0;
156 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
157 maya 3392 Printing = TRUE;
158     }
159     else {
160     if (PrnAbortDlg != NULL) {
161     PrnAbortDlg->DestroyWindow();
162     PrnAbortDlg = NULL;
163     HPrnAbortDlg = NULL;
164     }
165     }
166     return Printing;
167 maya 3227 }
168    
169     void PrnStop()
170     {
171 maya 3392 if (Printing) {
172     EndDoc(PrintDC);
173     DeleteDC(PrintDC);
174     Printing = FALSE;
175     }
176     if (PrnAbortDlg != NULL) {
177     PrnAbortDlg->DestroyWindow();
178     PrnAbortDlg = NULL;
179     HPrnAbortDlg = NULL;
180     }
181 maya 3227 }
182    
183     int VTPrintInit(int PrnFlag)
184     // Initialize printing of VT window
185     // PrnFlag: specifies object to be printed
186     // = IdPrnScreen Current screen
187     // = IdPrnSelectedText Selected text
188     // = IdPrnScrollRegion Scroll region
189     // = IdPrnFile Spooled file (printer sequence)
190     // Return: print object ID specified by user
191     // = IdPrnCancel (user clicks "Cancel" button)
192     // = IdPrnScreen (user don't select "print selection" option)
193     // = IdPrnSelectedText (user selects "print selection")
194     // = IdPrnScrollRegion (always when PrnFlag=IdPrnScrollRegion)
195     // = IdPrnFile (always when PrnFlag=IdPrnFile)
196 doda 6435 {
197 maya 3392 BOOL Sel;
198     TEXTMETRIC Metrics;
199     POINT PPI, PPI2;
200     HDC DC;
201     int i;
202     TCharAttr TempAttr = {
203     AttrDefault,
204     AttrDefault,
205     AttrDefaultFG,
206     AttrDefaultBG
207     };
208 maya 3227
209 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
210     if (PrnBox(HVTWin,&Sel)==NULL) {
211     return (IdPrnCancel);
212     }
213 maya 3227
214 maya 3392 if (PrintDC==0) {
215     return (IdPrnCancel);
216     }
217 maya 3227
218 maya 3392 /* start printing */
219     if (! PrnStart(ts.Title)) {
220     return (IdPrnCancel);
221     }
222 maya 3227
223 maya 3392 /* initialization */
224     StartPage(PrintDC);
225 maya 3227
226 maya 3392 /* pixels per inch */
227     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
228     PPI = ts.VTPPI;
229     }
230     else {
231     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
232     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
233     }
234 maya 3227
235 maya 3392 /* left margin */
236     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
237     /* right margin */
238     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
239     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
240     /* top margin */
241     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
242     /* bottom margin */
243     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
244     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
245 maya 3227
246 maya 3392 /* create test font */
247 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
248 maya 3227
249 maya 3392 if (ts.PrnFont[0]==0) {
250     Prnlf.lfHeight = ts.VTFontSize.y;
251     Prnlf.lfWidth = ts.VTFontSize.x;
252     Prnlf.lfCharSet = ts.VTFontCharSet;
253     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
254     }
255     else {
256     Prnlf.lfHeight = ts.PrnFontSize.y;
257     Prnlf.lfWidth = ts.PrnFontSize.x;
258     Prnlf.lfCharSet = ts.PrnFontCharSet;
259     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
260     }
261     Prnlf.lfWeight = FW_NORMAL;
262     Prnlf.lfItalic = 0;
263     Prnlf.lfUnderline = 0;
264     Prnlf.lfStrikeOut = 0;
265     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
266     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
267     Prnlf.lfQuality = DEFAULT_QUALITY;
268     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
269 maya 3227
270 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
271 maya 3227
272 maya 3392 DC = GetDC(HVTWin);
273     SelectObject(DC, PrnFont[0]);
274     GetTextMetrics(DC, &Metrics);
275     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
276     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
277     ReleaseDC(HVTWin,DC);
278     DeleteObject(PrnFont[0]); /* Delete test font */
279 maya 3227
280 maya 3392 /* Adjust font size */
281     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
282     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
283 maya 3227
284 maya 3392 /* Create New Fonts */
285 maya 3227
286 maya 3392 /* Normal Font */
287     Prnlf.lfWeight = FW_NORMAL;
288     Prnlf.lfUnderline = 0;
289 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
290 maya 3392 SelectObject(PrintDC,PrnFont[0]);
291     GetTextMetrics(PrintDC, &Metrics);
292     PrnFW = Metrics.tmAveCharWidth;
293     PrnFH = Metrics.tmHeight;
294     /* Under line */
295     Prnlf.lfUnderline = 1;
296 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
297 maya 3227
298 doda 3666 if (ts.FontFlag & FF_BOLD) {
299 maya 3392 /* Bold */
300     Prnlf.lfUnderline = 0;
301     Prnlf.lfWeight = FW_BOLD;
302 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
303 maya 3392 /* Bold + Underline */
304     Prnlf.lfUnderline = 1;
305 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
306 maya 3392 }
307     else {
308     PrnFont[AttrBold] = PrnFont[AttrDefault];
309     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
310     }
311     /* Special font */
312     Prnlf.lfWeight = FW_NORMAL;
313     Prnlf.lfUnderline = 0;
314     Prnlf.lfWidth = PrnFW; /* adjust width */
315     Prnlf.lfHeight = PrnFH;
316     Prnlf.lfCharSet = SYMBOL_CHARSET;
317 maya 3227
318 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
319 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
320 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
321     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
322     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
323 maya 3227
324 maya 3392 Black = RGB(0,0,0);
325     White = RGB(255,255,255);
326     for (i = 0 ; i <= 255 ; i++) {
327     PrnDx[i] = PrnFW;
328     }
329     PrnSetAttr(TempAttr);
330 maya 3227
331 maya 3392 PrnY = Margin.top;
332     PrnX = Margin.left;
333 maya 3227
334 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
335     return (IdPrnScrollRegion);
336     }
337     if (PrnFlag == IdPrnFile) {
338     return (IdPrnFile);
339     }
340     if (Sel) {
341     return (IdPrnSelectedText);
342     }
343     else {
344     return (IdPrnScreen);
345     }
346 maya 3227 }
347 zmatsuo 7291
348 maya 3227 void PrnSetAttr(TCharAttr Attr)
349     // Set text attribute of printing
350     //
351     {
352 maya 3392 PrnAttr = Attr;
353     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
354 maya 3227
355 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
356     SetTextColor(PrintDC,White);
357     SetBkColor( PrintDC,Black);
358     }
359     else {
360     SetTextColor(PrintDC,Black);
361     SetBkColor( PrintDC,White);
362     }
363 maya 3227 }
364    
365     void PrnOutText(PCHAR Buff, int Count)
366     // Print out text
367     // Buff: points text buffer
368     // Count: number of characters to be printed
369     {
370 maya 3392 int i;
371     RECT RText;
372     PCHAR Ptr, Ptr1, Ptr2;
373     char Buff2[256];
374 maya 3227
375 maya 3392 if (Count<=0) {
376     return;
377     }
378     if (Count>(sizeof(Buff2)-1)) {
379     Count=sizeof(Buff2)-1;
380     }
381     memcpy(Buff2,Buff,Count);
382     Buff2[Count] = 0;
383     Ptr = Buff2;
384 maya 3227
385 maya 3392 if (ts.Language==IdRussian) {
386     if (ts.PrnFont[0]==0) {
387     RussConvStr(ts.RussClient,ts.RussFont,Buff2,Count);
388     }
389     else {
390     RussConvStr(ts.RussClient,ts.RussPrint,Buff2,Count);
391     }
392     }
393 maya 3227
394 maya 3392 do {
395     if (PrnX+PrnFW > Margin.right) {
396     /* new line */
397     PrnX = Margin.left;
398     PrnY = PrnY + PrnFH;
399     }
400     if (PrnY+PrnFH > Margin.bottom) {
401     /* next page */
402     EndPage(PrintDC);
403     StartPage(PrintDC);
404     PrnSetAttr(PrnAttr);
405     PrnY = Margin.top;
406     }
407 maya 3227
408 maya 3392 i = (Margin.right-PrnX) / PrnFW;
409     if (i==0) {
410     i=1;
411     }
412     if (i>Count) {
413     i=Count;
414     }
415 maya 3227
416 maya 3392 if (i<Count) {
417     Ptr2 = Ptr;
418     do {
419     Ptr1 = Ptr2;
420 zmatsuo 7527 Ptr2 = CharNextA(Ptr1);
421 maya 3392 } while ((Ptr2!=NULL) && ((Ptr2-Ptr)<=i));
422     i = Ptr1-Ptr;
423     if (i<=0) {
424     i=1;
425     }
426     }
427 maya 3227
428 maya 3392 RText.left = PrnX;
429     RText.right = PrnX + i*PrnFW;
430     RText.top = PrnY;
431     RText.bottom = PrnY+PrnFH;
432 zmatsuo 7527 ExtTextOutA(PrintDC,PrnX,PrnY,6,&RText,Ptr,i,&PrnDx[0]);
433 maya 3392 PrnX = RText.right;
434     Count=Count-i;
435     Ptr = Ptr + i;
436     } while (Count>0);
437 maya 3227
438     }
439    
440     void PrnNewLine()
441     // Moves to the next line in printing
442     {
443 maya 3392 PrnX = Margin.left;
444     PrnY = PrnY + PrnFH;
445 maya 3227 }
446    
447     void VTPrintEnd()
448     {
449 maya 3392 int i, j;
450 maya 3227
451 maya 3392 EndPage(PrintDC);
452 maya 3227
453 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
454     for (j = i+1 ; j <= AttrFontMask ; j++) {
455     if (PrnFont[j]==PrnFont[i]) {
456     PrnFont[j] = NULL;
457     }
458     }
459     if (PrnFont[i] != NULL) {
460     DeleteObject(PrnFont[i]);
461     }
462     }
463 maya 3227
464 maya 3392 PrnStop();
465     return;
466 maya 3227 }
467    
468     /* printer emulation routines */
469     void OpenPrnFile()
470     {
471 maya 4031 char Temp[MAX_PATH];
472 maya 3227
473 maya 3392 KillTimer(HVTWin,IdPrnStartTimer);
474 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
475 maya 3392 return;
476     }
477     if (PrnFName[0] == 0) {
478 zmatsuo 7527 GetTempPathA(sizeof(Temp),Temp);
479     if (GetTempFileNameA(Temp,"tmp",0,PrnFName)==0) {
480 maya 3392 return;
481     }
482     HPrnFile = _lcreat(PrnFName,0);
483     }
484     else {
485     HPrnFile = _lopen(PrnFName,OF_WRITE);
486 zmatsuo 7290 if (HPrnFile == INVALID_HANDLE_VALUE) {
487 maya 3392 HPrnFile = _lcreat(PrnFName,0);
488     }
489     }
490 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
491 maya 3392 _llseek(HPrnFile,0,2);
492     }
493 maya 3227 }
494    
495     void PrintFile()
496     {
497 maya 3392 char Buff[256];
498     BOOL CRFlag = FALSE;
499     int c, i;
500     BYTE b;
501 maya 3227
502 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
503     HPrnFile = _lopen(PrnFName,OF_READ);
504 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
505 maya 3392 do {
506     i = 0;
507     do {
508     c = _lread(HPrnFile,&b,1);
509     if (c==1) {
510     switch (b) {
511     case HT:
512     memset(&(Buff[i]),0x20,8);
513     i = i + 8;
514     CRFlag = FALSE;
515     break;
516     case LF:
517     CRFlag = ! CRFlag;
518     break;
519     case FF:
520     case CR:
521     CRFlag = TRUE;
522     break;
523     default:
524     if (b >= 0x20) {
525     Buff[i] = b;
526     i++;
527     }
528     CRFlag = FALSE;
529     break;
530     }
531     }
532     if (i>=(sizeof(Buff)-7)) {
533     CRFlag=TRUE;
534     }
535     } while ((c>0) && (! CRFlag));
536     if (i>0) {
537     PrnOutText(Buff, i);
538     }
539     if (CRFlag) {
540     PrnX = Margin.left;
541     if ((b==FF) && (ts.PrnConvFF==0)) { // new page
542     PrnY = Margin.bottom;
543     }
544     else { // new line
545     PrnY = PrnY + PrnFH;
546     }
547     }
548     CRFlag = (b==CR);
549     } while (c>0);
550     _lclose(HPrnFile);
551 maya 3227 }
552 maya 3392 HPrnFile = 0;
553     VTPrintEnd();
554 maya 3227 }
555 maya 3392 remove(PrnFName);
556     PrnFName[0] = 0;
557 maya 3227 }
558    
559     void PrintFileDirect()
560     {
561 zmatsuo 7933 HWND hParent;
562 maya 3227
563 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
564     if (PrnAbortDlg==NULL) {
565     remove(PrnFName);
566     PrnFName[0] = 0;
567     return;
568     }
569     if (ActiveWin==IdVT) {
570 zmatsuo 7933 hParent = HVTWin;
571 maya 3392 }
572     else {
573 zmatsuo 7933 hParent = HTEKWin;
574 maya 3392 }
575 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
576 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
577 maya 3227
578 maya 3392 HPrnFile = _lopen(PrnFName,OF_READ);
579 zmatsuo 7290 PrintAbortFlag = (HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev);
580 maya 3392 PrnBuffCount = 0;
581     SetTimer(HVTWin,IdPrnProcTimer,0,NULL);
582 maya 3227 }
583    
584     void PrnFileDirectProc()
585     {
586 maya 3392 int c;
587 maya 3227
588 zmatsuo 7290 if (HPrnFile==INVALID_HANDLE_VALUE) {
589 maya 3392 return;
590     }
591     if (PrintAbortFlag) {
592     HPrnAbortDlg = NULL;
593     PrnAbortDlg = NULL;
594     PrnCancel();
595     }
596 zmatsuo 7290 if (!PrintAbortFlag && (HPrnFile != INVALID_HANDLE_VALUE)) {
597 maya 3392 do {
598     if (PrnBuffCount==0) {
599     PrnBuffCount = _lread(HPrnFile,PrnBuff,1);
600     if (ts.Language==IdRussian) {
601     RussConvStr(ts.RussClient,ts.RussPrint,PrnBuff,PrnBuffCount);
602     }
603     }
604 maya 3227
605 maya 3392 if (PrnBuffCount==1) {
606     c = PrnWrite(PrnBuff,1);
607     if (c==0) {
608     SetTimer(HVTWin,IdPrnProcTimer,10,NULL);
609     return;
610     }
611     PrnBuffCount = 0;
612     }
613     else {
614     c = 0;
615     }
616     } while (c>0);
617 maya 3227 }
618 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
619 maya 3392 _lclose(HPrnFile);
620     }
621 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
622 maya 3392 PrnClose();
623     remove(PrnFName);
624     PrnFName[0] = 0;
625     if (PrnAbortDlg!=NULL) {
626     PrnAbortDlg->DestroyWindow();
627     PrnAbortDlg = NULL;
628     HPrnAbortDlg = NULL;
629     }
630 maya 3227 }
631    
632     void PrnFileStart()
633     {
634 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
635 maya 3392 return;
636     }
637     if (PrnFName[0]==0) {
638     return;
639     }
640     if (ts.PrnDev[0]!=0) {
641     PrintFileDirect(); // send file directry to printer port
642     }
643     else { // print file by using Windows API
644     PrintFile();
645     }
646 maya 3227 }
647    
648     void ClosePrnFile()
649     {
650 maya 3392 PrnBuffCount = 0;
651 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
652 maya 3392 _lclose(HPrnFile);
653     }
654 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
655 maya 3392 SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
656 maya 3227 }
657    
658     void WriteToPrnFile(BYTE b, BOOL Write)
659     // (b,Write) =
660     // (0,FALSE): clear buffer
661     // (0,TRUE): write buffer to file
662     // (b,FALSE): put b in buff
663     // (b,TRUE): put b in buff and
664     // write buffer to file
665     {
666 maya 3392 if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) {
667     PrnBuff[PrnBuffCount++] = b;
668     }
669 maya 3227
670 maya 3392 if (Write) {
671     _lwrite(HPrnFile,PrnBuff,PrnBuffCount);
672     PrnBuffCount = 0;
673     }
674     if ((b==0) && ! Write) {
675     PrnBuffCount = 0;
676     }
677 maya 3227 }

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