Mercurial > dwindows
comparison os2/dw.c @ 1199:af4ca6ccbdff
Added support on OS/2 for querying the printer list...
Previously only the default printer was in the list.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 29 Sep 2011 21:04:21 +0000 |
parents | 1ef76e93db82 |
children | 53547c9c99a2 |
comparison
equal
deleted
inserted
replaced
1198:1ef76e93db82 | 1199:af4ca6ccbdff |
---|---|
12 #define INCL_DOS | 12 #define INCL_DOS |
13 #define INCL_DOSERRORS | 13 #define INCL_DOSERRORS |
14 #define INCL_WIN | 14 #define INCL_WIN |
15 #define INCL_GPI | 15 #define INCL_GPI |
16 #define INCL_DEV | 16 #define INCL_DEV |
17 #define INCL_SPL | |
18 #define INCL_SPLDOSPRINT | |
19 #define INCL_SPLERRORS | |
17 | 20 |
18 #include <os2.h> | 21 #include <os2.h> |
19 #include <stdlib.h> | 22 #include <stdlib.h> |
20 #include <string.h> | 23 #include <string.h> |
21 #include <stdio.h> | 24 #include <stdio.h> |
10237 { | 10240 { |
10238 char printername[32], tmpbuf[20]; | 10241 char printername[32], tmpbuf[20]; |
10239 HWND window, hbox, vbox, printerlist, button, text; | 10242 HWND window, hbox, vbox, printerlist, button, text; |
10240 DWDialog *dwwait; | 10243 DWDialog *dwwait; |
10241 DWPrint *print; | 10244 DWPrint *print; |
10242 /* Check the default printer for now... want a printer list in the future */ | 10245 PVOID pBuf = NULL; |
10246 ULONG fsType = SPL_PR_QUEUE; | |
10247 ULONG cbBuf, cRes, cTotal, cbNeeded; | |
10248 SPLERR splerr = 0 ; | |
10249 PPRINTERINFO pRes ; /* Check the default printer for now... want a printer list in the future */ | |
10243 int cb = PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER", "PRINTER", "", printername, 32); | 10250 int cb = PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER", "PRINTER", "", printername, 32); |
10244 | 10251 |
10245 if(!drawfunc || !(print = calloc(1, sizeof(DWPrint)))) | 10252 if(!drawfunc || !(print = calloc(1, sizeof(DWPrint)))) |
10246 return NULL; | 10253 return NULL; |
10247 | 10254 |
10250 print->jobname = jobname ? jobname : "Dynamic Windows Print Job"; | 10257 print->jobname = jobname ? jobname : "Dynamic Windows Print Job"; |
10251 print->startpage = 1; | 10258 print->startpage = 1; |
10252 print->endpage = pages; | 10259 print->endpage = pages; |
10253 print->flags = flags; | 10260 print->flags = flags; |
10254 | 10261 |
10262 /* Check to see how much space we need for the printer list */ | |
10263 splerr = SplEnumPrinter(NULL, 0, fsType, NULL, NULL, &cRes, &cTotal, &cbNeeded ,NULL); | |
10264 | |
10265 if(splerr == ERROR_MORE_DATA || splerr == NERR_BufTooSmall) | |
10266 { | |
10267 /* Allocate memory for the buffer using the count of bytes that were returned in cbNeeded. */ | |
10268 DosAllocMem(&pBuf, cbNeeded, PAG_READ|PAG_WRITE|PAG_COMMIT); | |
10269 | |
10270 /* Set count of bytes in buffer to value used to allocate buffer. */ | |
10271 cbBuf = cbNeeded; | |
10272 | |
10273 /* Call function again with the correct buffer size. */ | |
10274 splerr = SplEnumPrinter(NULL, 0, fsType, pBuf, cbBuf, &cRes, &cTotal, &cbNeeded, NULL); | |
10275 } | |
10276 | |
10255 /* Make sure we got a valid result */ | 10277 /* Make sure we got a valid result */ |
10256 if(cb > 2) | 10278 if(cb > 2) |
10257 printername[cb-2] = '\0'; | 10279 printername[cb-2] = '\0'; |
10258 else | 10280 else |
10281 printername[0] = '\0'; | |
10282 | |
10283 /* If we didnt' get a printer list or default printer abort */ | |
10284 if(!cRes && !printername[0]) | |
10259 { | 10285 { |
10260 /* Show an error and return failure */ | 10286 /* Show an error and return failure */ |
10261 dw_messagebox("Printing", DW_MB_ERROR | DW_MB_OK, "No printers detected."); | 10287 dw_messagebox("Printing", DW_MB_ERROR | DW_MB_OK, "No printers detected."); |
10262 free(print); | 10288 free(print); |
10263 return NULL; | 10289 return NULL; |
10270 | 10296 |
10271 dw_box_pack_start(window, vbox, 0, 0, TRUE, TRUE, 0); | 10297 dw_box_pack_start(window, vbox, 0, 0, TRUE, TRUE, 0); |
10272 | 10298 |
10273 printerlist = dw_listbox_new(0, FALSE); | 10299 printerlist = dw_listbox_new(0, FALSE); |
10274 dw_box_pack_start(vbox, printerlist, 1, 1, TRUE, TRUE, 0); | 10300 dw_box_pack_start(vbox, printerlist, 1, 1, TRUE, TRUE, 0); |
10275 dw_listbox_append(printerlist, printername); | 10301 |
10276 dw_listbox_select(printerlist, 0, TRUE); | 10302 /* If there are any returned structures in the buffer... */ |
10303 if(pBuf && cRes) | |
10304 { | |
10305 int count = 0; | |
10306 | |
10307 pRes = (PPRINTERINFO)pBuf ; | |
10308 while(cRes--) | |
10309 { | |
10310 dw_listbox_append(printerlist, pRes[cRes].pszPrintDestinationName); | |
10311 /* If this is the default printer... select it by default */ | |
10312 if(strcmp(pRes[cRes].pszPrintDestinationName, printername) == 0) | |
10313 dw_listbox_select(printerlist, count, TRUE); | |
10314 count++; | |
10315 } | |
10316 } | |
10317 else | |
10318 { | |
10319 /* Otherwise just add the default */ | |
10320 dw_listbox_append(printerlist, printername); | |
10321 dw_listbox_select(printerlist, 0, TRUE); | |
10322 } | |
10323 | |
10324 /* Free any unneeded memory */ | |
10325 if(pBuf) | |
10326 DosFreeMem(pBuf); | |
10277 | 10327 |
10278 dw_window_set_data(window, "_dw_list", (void *)printerlist); | 10328 dw_window_set_data(window, "_dw_list", (void *)printerlist); |
10279 | 10329 |
10280 /* Start spinbutton */ | 10330 /* Start spinbutton */ |
10281 hbox = dw_box_new(DW_HORZ, 0); | 10331 hbox = dw_box_new(DW_HORZ, 0); |