comparison win/dw.c @ 1138:caeae1ff0289

Initial implementation of the print object on Windows. May need to add a document name parameter to dw_print_new(). Not quite fully functional, but needed to commit to change computers.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 09 Sep 2011 10:45:04 +0000
parents e24e5a13ff2c
children 65b750569a0a
comparison
equal deleted inserted replaced
1137:e24e5a13ff2c 1138:caeae1ff0289
9988 if(retcode<33 && retcode != 2) 9988 if(retcode<33 && retcode != 2)
9989 return DW_ERROR_UNKNOWN; 9989 return DW_ERROR_UNKNOWN;
9990 return DW_ERROR_NONE; 9990 return DW_ERROR_NONE;
9991 } 9991 }
9992 9992
9993 typedef struct _dwprint
9994 {
9995 PRINTDLG pd;
9996 DOCINFO di;
9997 int (*drawfunc)(HPRINT, HPIXMAP, int, void *);
9998 void *drawdata;
9999 unsigned long flags;
10000 } DWPrint;
10001
9993 /* 10002 /*
9994 * Creates a new print object. 10003 * Creates a new print object.
9995 * Parameters: 10004 * Parameters:
9996 * flags: Flags to initially configure the print object. 10005 * flags: Flags to initially configure the print object.
9997 * pages: Number of pages to print. 10006 * pages: Number of pages to print.
10000 * Returns: 10009 * Returns:
10001 * A handle to the print object or NULL on failure. 10010 * A handle to the print object or NULL on failure.
10002 */ 10011 */
10003 HPRINT API dw_print_new(unsigned long flags, unsigned int pages, void *drawfunc, void *drawdata) 10012 HPRINT API dw_print_new(unsigned long flags, unsigned int pages, void *drawfunc, void *drawdata)
10004 { 10013 {
10005 return NULL; 10014 DWPrint *print;
10015
10016 if(!drawfunc || !(print = calloc(1, sizeof(DWPrint))))
10017 return NULL;
10018
10019 print->drawfunc = drawfunc;
10020 print->drawdata = drawdata;
10021 print->pd.lStructSize = sizeof(PRINTDLG);
10022 print->pd.hwndOwner = HWND_DESKTOP;
10023 print->pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
10024 print->pd.nCopies = 1;
10025 print->pd.nFromPage = 0xFFFF;
10026 print->pd.nToPage = 0xFFFF;
10027 print->pd.nMinPage = 1;
10028 print->pd.nMaxPage = pages;
10029
10030 if(!PrintDlg(&(print->pd)))
10031 {
10032 free(print);
10033 return NULL;
10034 }
10035
10036 print->di.cbSize = sizeof(DOCINFO);
10037 print->di.lpszDocName = "Dynamic Windows Print Job";
10038 return print;
10006 } 10039 }
10007 10040
10008 /* 10041 /*
10009 * Runs the print job, causing the draw page callbacks to fire. 10042 * Runs the print job, causing the draw page callbacks to fire.
10010 * Parameters: 10043 * Parameters:
10013 * Returns: 10046 * Returns:
10014 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success. 10047 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success.
10015 */ 10048 */
10016 int API dw_print_run(HPRINT print, unsigned long flags) 10049 int API dw_print_run(HPRINT print, unsigned long flags)
10017 { 10050 {
10018 return DW_ERROR_UNKNOWN; 10051 DWPrint *p = print;
10052 HPIXMAP pixmap;
10053 int x;
10054
10055 if(!p)
10056 return DW_ERROR_UNKNOWN;
10057
10058 if (!(pixmap = calloc(1,sizeof(struct _hpixmap))))
10059 return DW_ERROR_UNKNOWN;
10060
10061 pixmap->width = GetDeviceCaps(p->pd.hDC, PHYSICALWIDTH);
10062 pixmap->height = GetDeviceCaps(p->pd.hDC, PHYSICALHEIGHT);
10063
10064 /*pixmap->handle = handle;*/
10065 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height);
10066 pixmap->hdc = CreateCompatibleDC(p->pd.hDC);
10067 pixmap->transcolor = DW_RGB_TRANSPARENT;
10068
10069 SelectObject(pixmap->hdc, pixmap->hbm);
10070
10071 /* Start the job */
10072 StartDoc(p->pd.hDC, &(p->di));
10073
10074 /* Cycle through each page */
10075 for(x=p->pd.nFromPage; x<p->pd.nToPage && p->drawfunc; x++)
10076 {
10077 StartPage(p->pd.hDC);
10078 p->drawfunc(print, pixmap, x-1, p->drawdata);
10079 EndPage(p->pd.hDC);
10080 }
10081 EndDoc(p->pd.hDC);
10082 /* Free memory */
10083 dw_pixmap_destroy(pixmap);
10084 free(p);
10085 return p->drawfunc ? DW_ERROR_NONE : DW_ERROR_UNKNOWN;
10019 } 10086 }
10020 10087
10021 /* 10088 /*
10022 * Cancels the print job, typically called from a draw page callback. 10089 * Cancels the print job, typically called from a draw page callback.
10023 * Parameters: 10090 * Parameters:
10024 * print: Handle to the print object returned by dw_print_new(). 10091 * print: Handle to the print object returned by dw_print_new().
10025 */ 10092 */
10026 void API dw_print_cancel(HPRINT print) 10093 void API dw_print_cancel(HPRINT print)
10027 { 10094 {
10095 DWPrint *p = print;
10096
10097 if(p)
10098 p->drawfunc = NULL;
10028 } 10099 }
10029 10100
10030 /* 10101 /*
10031 * Returns a pointer to a static buffer which containes the 10102 * Returns a pointer to a static buffer which containes the
10032 * current user directory. Or the root directory (C:\ on 10103 * current user directory. Or the root directory (C:\ on