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