Mercurial > dwindows
comparison gtk3/dw.c @ 1136:1a5b0908659b
Initial implementation of the DynamicWindows Print object for GTK3.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 09 Sep 2011 00:28:25 +0000 |
parents | ed7cbdc37a75 |
children | e24e5a13ff2c |
comparison
equal
deleted
inserted
replaced
1135:6828a01ecf3c | 1136:1a5b0908659b |
---|---|
10191 gtk_clipboard_set_text( clipboard_object, str, len ); | 10191 gtk_clipboard_set_text( clipboard_object, str, len ); |
10192 } | 10192 } |
10193 DW_MUTEX_UNLOCK; | 10193 DW_MUTEX_UNLOCK; |
10194 } | 10194 } |
10195 | 10195 |
10196 /* | 10196 /* Internal function to create the drawable pixmap and call the function */ |
10197 * Returns a pointer to a static buffer which containes the | 10197 static void _dw_draw_page(GtkPrintOperation *operation, GtkPrintContext *context, int page_nr) |
10198 { | |
10199 cairo_t *cr = gtk_print_context_get_cairo_context(context); | |
10200 void *drawdata = g_object_get_data(G_OBJECT(operation), "_dw_drawdata"); | |
10201 int (*drawfunc)(HPRINT, HPIXMAP, int, void *) = g_object_get_data(G_OBJECT(operation), "_dw_drawfunc"); | |
10202 int result = 0; | |
10203 HPIXMAP pixmap; | |
10204 | |
10205 if(cr && drawfunc && (pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
10206 { | |
10207 pixmap->image = cairo_get_group_target(cr); | |
10208 pixmap->handle = (HWND)operation; | |
10209 pixmap->width = gtk_print_context_get_width(context); | |
10210 pixmap->height = gtk_print_context_get_height(context); | |
10211 result = drawfunc((HPRINT)operation, pixmap, page_nr, drawdata); | |
10212 if(result) | |
10213 gtk_print_operation_draw_page_finish(operation); | |
10214 free(pixmap); | |
10215 } | |
10216 } | |
10217 | |
10218 /* | |
10219 * Creates a new print object. | |
10220 * Parameters: | |
10221 * flags: Flags to initially configure the print object. | |
10222 * pages: Number of pages to print. | |
10223 * drawfunc: The pointer to the function to be used as the callback. | |
10224 * drawdata: User data to be passed to the handler function. | |
10225 * Returns: | |
10226 * A handle to the print object. | |
10227 */ | |
10228 HPRINT API dw_print_new(unsigned long flags, unsigned int pages, void *drawfunc, void *drawdata) | |
10229 { | |
10230 GtkPrintOperation *op; | |
10231 int _locked_by_me = FALSE; | |
10232 | |
10233 if(!drawfunc) | |
10234 return NULL; | |
10235 | |
10236 DW_MUTEX_LOCK; | |
10237 if((op = gtk_print_operation_new())) | |
10238 { | |
10239 gtk_print_operation_set_n_pages(op, pages); | |
10240 g_object_set_data(G_OBJECT(op), "_dw_drawfunc", drawfunc); | |
10241 g_object_set_data(G_OBJECT(op), "_dw_drawdata", drawdata); | |
10242 g_signal_connect(op, "draw_page", G_CALLBACK(_dw_draw_page), NULL); | |
10243 } | |
10244 DW_MUTEX_UNLOCK; | |
10245 return (HPRINT)op; | |
10246 } | |
10247 | |
10248 /* | |
10249 * Runs the print job, causing the draw page callbacks to fire. | |
10250 * Parameters: | |
10251 * print: Handle to the print object returned by dw_print_new(). | |
10252 * flags: Flags to run the print job. | |
10253 * Returns: | |
10254 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success. | |
10255 */ | |
10256 int API dw_print_run(HPRINT print, unsigned long flags) | |
10257 { | |
10258 GtkPrintOperationResult res; | |
10259 GtkPrintOperation *op = (GtkPrintOperation *)print; | |
10260 int _locked_by_me = FALSE; | |
10261 | |
10262 DW_MUTEX_LOCK; | |
10263 res = gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); | |
10264 DW_MUTEX_UNLOCK; | |
10265 return (res == GTK_PRINT_OPERATION_RESULT_ERROR ? DW_ERROR_UNKNOWN : DW_ERROR_NONE); | |
10266 } | |
10267 | |
10268 /* | |
10269 * Cancels the print job, typically called from a draw page callback. | |
10270 * Parameters: | |
10271 * print: Handle to the print object returned by dw_print_new(). | |
10272 */ | |
10273 void API dw_print_cancel(HPRINT print) | |
10274 { | |
10275 int _locked_by_me = FALSE; | |
10276 GtkPrintOperation *op = (GtkPrintOperation *)print; | |
10277 | |
10278 DW_MUTEX_LOCK; | |
10279 gtk_print_operation_cancel(op); | |
10280 DW_MUTEX_UNLOCK; | |
10281 } | |
10282 | |
10283 /* | |
10284 * Returns a pointer to a static buffer which contains the | |
10198 * current user directory. Or the root directory (C:\ on | 10285 * current user directory. Or the root directory (C:\ on |
10199 * OS/2 and Windows). | 10286 * OS/2 and Windows). |
10200 */ | 10287 */ |
10201 char *dw_user_dir(void) | 10288 char *dw_user_dir(void) |
10202 { | 10289 { |