void gui_editor_print (GUIEditor *editor) { editor->print_operation = gtk_print_operation_new (); #ifdef G_OS_WIN32 gtk_print_operation_set_unit (editor->print_operation, GTK_UNIT_POINTS); #endif GtkPrintOperationResult res; GError *error; GtkWidget *error_dialog; g_signal_connect (editor->print_operation, "begin-print", G_CALLBACK (gui_editor_begin_print), editor); g_signal_connect (editor->print_operation, "draw-page", G_CALLBACK (gui_editor_draw_page), editor); gtk_print_operation_set_show_progress (editor->print_operation, TRUE); res = gtk_print_operation_run (editor->print_operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, &error); if (res == GTK_PRINT_OPERATION_RESULT_ERROR ) { error_dialog = gtk_message_dialog_new (GTK_WINDOW (editor->scroll), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error printing file:\n%s", error->message); gtk_widget_show (error_dialog); g_error_free (error); } g_object_unref (editor->print_operation); }
static void printing_print_gtk(GeanyDocument *doc) { GtkPrintOperation *op; GtkPrintOperationResult res = GTK_PRINT_OPERATION_RESULT_ERROR; GError *error = NULL; DocInfo *dinfo; PrintWidgets *widgets; /** TODO check for monospace font, detect the widest character in the font and * use it at font_width */ widgets = g_new0(PrintWidgets, 1); dinfo = g_new0(DocInfo, 1); /* all other fields are initialised in begin_print() */ dinfo->doc = doc; op = gtk_print_operation_new(); gtk_print_operation_set_unit(op, GTK_UNIT_POINTS); gtk_print_operation_set_show_progress(op, TRUE); #if GTK_CHECK_VERSION(2, 18, 0) gtk_print_operation_set_embed_page_setup(op, TRUE); #endif g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), dinfo); g_signal_connect(op, "end-print", G_CALLBACK(end_print), dinfo); g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), dinfo); g_signal_connect(op, "status-changed", G_CALLBACK(status_changed), doc->file_name); g_signal_connect(op, "create-custom-widget", G_CALLBACK(create_custom_widget), widgets); g_signal_connect(op, "custom-widget-apply", G_CALLBACK(custom_widget_apply), widgets); if (settings != NULL) gtk_print_operation_set_print_settings(op, settings); if (page_setup != NULL) gtk_print_operation_set_default_page_setup(op, page_setup); res = gtk_print_operation_run( op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(main_widgets.window), &error); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (settings != NULL) g_object_unref(settings); settings = g_object_ref(gtk_print_operation_get_print_settings(op)); /* status message is printed in the status-changed handler */ } else if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of %s failed (%s)."), doc->file_name, error->message); g_error_free(error); } g_object_unref(op); g_free(dinfo); g_free(widgets); }
void XAP_UnixDialog_Print::runModal(XAP_Frame * pFrame) { m_pFrame = pFrame; setupPrint(); gtk_print_operation_set_show_progress(m_pPO, TRUE); XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(m_pFrame->getFrameImpl()); // Get the GtkWindow of the parent frame GtkWidget * parent = pUnixFrameImpl->getTopLevelWindow(); GtkWindow * pPWindow = GTK_WINDOW(parent); // const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet(); // const gchar * szDialogName = einterpret_cast<const gchar *>(pSS->getValue(XAP_STRING_ID_DLG_UP_PrintTitle); gtk_print_operation_run (m_pPO, (m_bIsPreview)? GTK_PRINT_OPERATION_ACTION_PREVIEW: GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, pPWindow, NULL); cleanup(); }
int PrintText(const char *name, gchar *text) { GKeyFile *conf = GetConf(); GtkPrintOperation *prt; const gchar *font; GtkPageSetup *page_setup = NULL; GtkPrintSettings *print_settings = NULL; if(!text) return -EINVAL; prt = gtk_print_operation_new(); if(!prt) return -1; // Set job parameters g_object_set_data_full(G_OBJECT(prt),"3270Text",g_strsplit(g_strchomp(text),"\n",-1),(void (*)(gpointer)) g_strfreev); // Set print font = GetString("Print","Font",""); if(!*font) font = GetString("Terminal","Font","Courier"); g_object_set_data_full(G_OBJECT(prt),"3270FontName",g_strdup(font),g_free); // Configure print operation gtk_print_operation_set_job_name(prt,name); gtk_print_operation_set_allow_async(prt,0); gtk_print_operation_set_show_progress(prt,1); gtk_print_operation_set_custom_tab_label(prt,_( "Font" )); g_signal_connect(prt, "begin-print", G_CALLBACK(begin_print), 0); g_signal_connect(prt, "draw-page", G_CALLBACK(draw_page), 0); #ifdef HAVE_PRINT_FONT_DIALOG g_signal_connect(prt, "create-custom-widget", G_CALLBACK(create_custom_widget), 0); g_signal_connect(prt, "custom-widget-apply", G_CALLBACK(custom_widget_apply), 0); #endif g_signal_connect(prt, "done", G_CALLBACK(print_done), 0); if(conf) { #if GTK_CHECK_VERSION(2,12,0) gchar *ptr = g_key_file_get_string(conf,"Print Settings","output-uri",NULL); if(ptr) { gchar *uri = NULL; switch(*(ptr++)) { case '$': if(g_str_has_prefix(ptr,"home/")) uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr+5); #if GTK_CHECK_VERSION(2,14,0) else if(g_str_has_prefix(ptr,"documents/")) uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),ptr+10); else if(g_str_has_prefix(ptr,"desktop/")) uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP),ptr+8); #endif break; case '~': uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr); break; } if(uri) { g_key_file_set_string(conf,"Print Settings","output-uri",uri); g_free(uri); } } print_settings = gtk_print_settings_new_from_key_file(conf,NULL,NULL); page_setup = gtk_page_setup_new_from_key_file(conf,NULL,NULL); if(!page_setup) page_setup = gtk_page_setup_new(); #else // GTK_CHECK_VERSION(2,12,0) print_settings = gtk_print_settings_new(); if(print_settings) { gchar **list; int f; list = g_key_file_get_keys(conf,"PrintSettings",NULL,NULL); if(list) { for(f=0;list[f];f++) gtk_print_settings_set(print_settings,list[f],g_key_file_get_string(conf,"PrintSettings",list[f],NULL)); g_strfreev(list); } } page_setup = gtk_page_setup_new(); #endif } else { page_setup = gtk_page_setup_new(); gtk_print_operation_set_print_settings(prt,gtk_print_settings_new()); } Trace("page_setup: %p print_settings: %p",page_setup,print_settings); gtk_print_operation_set_print_settings(prt,print_settings); gtk_print_operation_set_default_page_setup(prt,page_setup); // Run Print dialog gtk_print_operation_run(prt,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(topwindow),NULL); g_object_unref(prt); return 0; }
static gboolean mail_printer_print_timeout_cb (gpointer user_data) { GSimpleAsyncResult *simple; AsyncContext *async_context; GCancellable *cancellable; GtkPrintOperation *print_operation; GtkPrintOperationAction print_action; EMailPrinter *printer; WebKitWebFrame *web_frame; gulong create_custom_widget_handler_id; gulong custom_widget_apply_handler_id; gulong draw_page_handler_id; GError *error = NULL; simple = G_SIMPLE_ASYNC_RESULT (user_data); async_context = g_simple_async_result_get_op_res_gpointer (simple); cancellable = async_context->cancellable; print_action = async_context->print_action; /* Check for cancellation one last time before printing. */ if (g_cancellable_set_error_if_cancelled (cancellable, &error)) goto exit; /* This returns a new reference. */ printer = (EMailPrinter *) g_async_result_get_source_object ( G_ASYNC_RESULT (simple)); print_operation = e_print_operation_new (); gtk_print_operation_set_show_progress (print_operation, TRUE); gtk_print_operation_set_unit (print_operation, GTK_UNIT_PIXEL); if (async_context->print_action == GTK_PRINT_OPERATION_ACTION_EXPORT) { const gchar *export_filename; export_filename = e_mail_printer_get_export_filename (printer); gtk_print_operation_set_export_filename ( print_operation, export_filename); } create_custom_widget_handler_id = g_signal_connect ( print_operation, "create-custom-widget", G_CALLBACK (mail_printer_create_custom_widget_cb), async_context); custom_widget_apply_handler_id = g_signal_connect ( print_operation, "custom-widget-apply", G_CALLBACK (mail_printer_custom_widget_apply_cb), async_context); draw_page_handler_id = g_signal_connect ( print_operation, "draw-page", G_CALLBACK (mail_printer_draw_footer_cb), async_context->cancellable); web_frame = webkit_web_view_get_main_frame (async_context->web_view); async_context->print_result = webkit_web_frame_print_full ( web_frame, print_operation, print_action, &error); /* Sanity check. */ switch (async_context->print_result) { case GTK_PRINT_OPERATION_RESULT_ERROR: if (error == NULL) g_warning ( "WebKit print operation returned " "ERROR result without setting a " "GError"); break; case GTK_PRINT_OPERATION_RESULT_APPLY: if (error != NULL) g_warning ( "WebKit print operation returned " "APPLY result but also set a GError"); break; case GTK_PRINT_OPERATION_RESULT_CANCEL: if (error != NULL) g_warning ( "WebKit print operation returned " "CANCEL result but also set a GError"); break; default: g_warn_if_reached (); } g_signal_handler_disconnect ( print_operation, create_custom_widget_handler_id); g_signal_handler_disconnect ( print_operation, custom_widget_apply_handler_id); g_signal_handler_disconnect ( print_operation, draw_page_handler_id); g_object_unref (print_operation); g_object_unref (printer); exit: if (error != NULL) g_simple_async_result_take_error (simple, error); g_simple_async_result_complete_in_idle (simple); return FALSE; }