|
|
1.1 root 1: /******************************* Module Header ******************************\
2: * Module Name: Print.c
3: *
4: *
5: * Created by Microsoft, IBM Corporation 1990
6: *
7: *
8: * PM OS2.ini Editor
9: *
10: * Printing Functions
11: *
12: \***************************************************************************/
13:
14:
15: #define LINT_ARGS
16: #define INCL_WINSHELLDATA
17: #define INCL_GPIBITMAPS
18: #define INCL_GPIREGIONS
19: #define INCL_GPILCIDS
20: #define INCL_GPIPRIMITIVES
21: #define INCL_DEV
22:
23: #include <string.h>
24: #include <stdio.h>
25:
26: #include <os2.h>
27:
28: #include "noncomm.h"
29: #include "IniEdit.h"
30:
31:
32: /******************************* Constants *********************************/
33:
34: #define LEFT_MARGIN 3
35: #define TOP_MARGIN 7
36: #define BOTTOM_MARGIN 15
37: #define MAX_PRINT_LEN 1024
38:
39:
40: /******************************* Externals *********************************/
41:
42: extern USHORT cAppNames;
43: extern PGROUPSTRUCT pGroups;
44: extern HAB habIniEdit;
45: extern USHORT usLineHeight;
46: extern USHORT usPrintFormat;
47:
48: /******************************* Internals ********************************/
49: CHAR szBuf[MAX_STRING_LEN]; // Output character buffer
50: CHAR szPrinter[MAX_PRINT_LEN]; // Logical Printer Name
51: CHAR szDetails[MAX_PRINT_LEN]; // Logical Printer Details
52:
53:
54: /***************************** Function Header *****************************\
55: *
56: * PrintThread
57: *
58: *
59: * Prints the ini info in specified format
60: *
61: \***************************************************************************/
62:
63: VOID PrintThread()
64: {
65: HAB habPrint; // HAB of Print Thread
66: HDC hdcPrint; // DC of Printer
67: HPS hpsPrint; // PS of Printer
68: SIZEL sizel; // Size of PS to Create
69: POINTL ptlOutput; // Output location
70: BYTE abOut[50]; // DevEscape Output
71: ULONG ulOut; // DevEscape Output Count
72: USHORT usHeight; // Height of Printer Page
73: USHORT cch; // Count of Characters in buffer
74: INT i,j; // Loop Counters
75: DEVOPENSTRUC dop; // DevOpenDC Info
76: CHAR szMessage[80];
77:
78: /* initialization of thread */
79: if (!(habPrint = WinInitialize(NULL))) DosExit(EXIT_THREAD, -1);
80:
81:
82: /*** Select Port ***/
83: /* get name of default logical printer */
84: cch = PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER", "PRINTER",
85: "", /* default */
86: szPrinter,
87: MAX_PRINT_LEN); /* max chars */
88:
89: szPrinter[cch-2] = 0; /* remove terminating ';' */
90:
91: /* get specifics of default logical printer */
92: cch = PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER_PRINTER", szPrinter,
93: "", /* default */
94: szDetails,
95: MAX_PRINT_LEN); /* max chars */
96:
97:
98: /* info in form of "port; driver; logical address" */
99: /* grab driver name; one past semicolon */
100: dop.pszDriverName = strchr( szDetails, ';' )+1;
101:
102: /* Grab logical address */
103: dop.pszLogAddress = strchr( dop.pszDriverName, ';' )+1;
104:
105: /* Make driver and Logical address Null terminated */
106: dop.pszLogAddress = strtok( dop.pszLogAddress, ",;" );
107: dop.pszDriverName = strtok( dop.pszDriverName, ",.;" ); /* Driver.Model */
108:
109: dop.pdriv = NULL;
110: dop.pszDataType = NULL;
111:
112: /* Create Printer DC */
113: hdcPrint = DevOpenDC( habPrint, OD_QUEUED, "*", 3L, (PDEVOPENDATA)&dop,
114: (HDC)NULL);
115:
116: if( hdcPrint == (HDC)NULL )
117: {
118: DosExit(EXIT_THREAD, -1);
119: }
120:
121: strcpy( szBuf, (usPrintFormat == APP_FORM) ? SZAPP : SZALL );
122: DevEscape( hdcPrint, DEVESC_STARTDOC, (LONG)strlen( szBuf ), (PBYTE)szBuf,
123: &ulOut, (PBYTE)NULL );
124:
125: /* Determine size of page */
126: DevQueryCaps( hdcPrint, CAPS_HEIGHT, 1L, (PLONG)&usHeight );
127: ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
128: ptlOutput.x = LEFT_MARGIN;
129:
130: /* Create Printer PS */
131: sizel.cx = sizel.cy = 0L;
132: hpsPrint = GpiCreatePS( habPrint, hdcPrint, &sizel,
133: PU_PELS | GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC );
134:
135: if( hpsPrint == (HPS)NULL )
136: {
137: DosExit(EXIT_THREAD, -1);
138: }
139:
140:
141: /* print items */
142: if( usPrintFormat == APP_FORM )
143: {
144: for( i=0; i<cAppNames; i++ )
145: {
146: sprintf(szMessage,"CharString: X = %ld, Y = %ld",
147: ptlOutput.x, ptlOutput.y);
148: GpiCharStringAt( hpsPrint, &ptlOutput, (LONG)strlen( pGroups[i].szAppName ),
149: pGroups[i].szAppName );
150: ptlOutput.y -= usLineHeight;
151:
152: if( ptlOutput.y <= BOTTOM_MARGIN )
153: {
154: DevEscape( hdcPrint, DEVESC_NEWFRAME, 0L, (PBYTE)NULL , &ulOut, abOut );
155: ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
156: }
157:
158: }
159: } /* if */
160: else
161: {
162: /* Print App Names */
163: for( i=0; i<cAppNames; i++ )
164: {
165: GpiCharStringAt( hpsPrint, &ptlOutput, (LONG)strlen( pGroups[i].szAppName ),
166: pGroups[i].szAppName );
167: ptlOutput.y -= usLineHeight;
168: if( ptlOutput.y <= BOTTOM_MARGIN )
169: {
170: DevEscape( hdcPrint, DEVESC_NEWFRAME, 0L, (PBYTE)NULL , &ulOut, abOut );
171: ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
172: }
173:
174: /* Print Key Value Pairs for current App Name */
175: for( j=0; j<pGroups[i].cKeys; j++ )
176: {
177: sprintf( szBuf, " %s: %s", pGroups[i].pPairs[j].szKey,
178: pGroups[i].pPairs[j].szValue );
179:
180: if( GpiCharStringAt( hpsPrint, &ptlOutput, (LONG)strlen( szBuf ), szBuf ) == GPI_ERROR )
181: ;
182:
183: ptlOutput.y -= usLineHeight;
184: if( ptlOutput.y <= BOTTOM_MARGIN )
185: {
186: DevEscape( hdcPrint, DEVESC_NEWFRAME, 0L, (PBYTE)NULL , &ulOut, abOut );
187: ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
188: }
189: } /* for */
190: } /* for */
191:
192: }
193:
194: /* Cleanup */
195: DevEscape( hdcPrint, DEVESC_ENDDOC, 0L, (PBYTE)NULL , &ulOut, abOut );
196: GpiAssociate( hpsPrint, (HDC)NULL );
197: GpiDestroyPS( hpsPrint );
198: DevCloseDC( hdcPrint );
199: DosExit(EXIT_THREAD, 0);
200: } /* PrintThread */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.