Revision: 2161 http://geany.svn.sourceforge.net/geany/?rev=2161&view=rev Author: eht16 Date: 2008-01-11 06:23:29 -0800 (Fri, 11 Jan 2008)
Log Message: ----------- Fix crash while reading Scintilla styles. Add GTK's progress dialog when printing large documents which also provides the ability to cancel a print operation.
Modified Paths: -------------- trunk/ChangeLog trunk/src/printing.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-01-11 13:17:00 UTC (rev 2160) +++ trunk/ChangeLog 2008-01-11 14:23:29 UTC (rev 2161) @@ -1,6 +1,10 @@ 2008-01-11 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/dialogs.c: Fix broken Rename functionality (closes #1868621). + * src/printing.c: + Fix crash while reading Scintilla styles. + Add GTK's progress dialog when printing large documents which also + provides the ability to cancel a print operation.
2008-01-10 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/printing.c =================================================================== --- trunk/src/printing.c 2008-01-11 13:17:00 UTC (rev 2160) +++ trunk/src/printing.c 2008-01-11 14:23:29 UTC (rev 2161) @@ -83,6 +83,7 @@ gint styles[STYLE_MAX + 1][MAX_TYPES]; gdouble line_height; gboolean long_line; // whether we have a wrapped line on page end to take care of on next page + gboolean cancelled; // set in begin_print() to hold the time when printing was started to ensure all printed // pages have the same date and time (in case of slow machines and many pages where rendering // takes more than a second) @@ -266,7 +267,7 @@ g_free(data); g_free(file_name);
- data = g_strdup_printf("<b>page %d of %d</b>", page_nr + 1, dinfo->n_pages); + data = g_strdup_printf(_("<b>Page %d of %d</b>"), page_nr + 1, dinfo->n_pages); pango_layout_set_markup(layout, data, -1); pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); cairo_move_to(cr, 4, dinfo->line_height * 1.5); @@ -409,6 +410,7 @@ DocInfo *dinfo = user_data; PangoFontDescription *desc; gint i; + gint style_max;
if (dinfo == NULL) return; @@ -421,6 +423,7 @@ dinfo->cur_line = 0; dinfo->cur_pos = 0; dinfo->long_line = FALSE; + dinfo->cancelled = FALSE; dinfo->print_time = time(NULL); dinfo->max_line_number_margin = get_line_numbers_arity(dinfo->lines) + 1; // increase font width by 1 (looks better) @@ -432,7 +435,8 @@ dinfo->n_pages = get_page_count(context, dinfo);
// read all styles from Scintilla - for (i = 0; i <= STYLE_MAX; i++) + style_max = pow(2, scintilla_send_message(doc_list[dinfo->idx].sci, SCI_GETSTYLEBITS, 0, 0)); + for (i = 0; i < style_max; i++) { dinfo->styles[i][FORE] = ROTATE_RGB(scintilla_send_message( doc_list[dinfo->idx].sci, SCI_STYLEGETFORE, i, 0)); @@ -455,6 +459,11 @@ if (dinfo->n_pages >= 0) gtk_print_operation_set_n_pages(operation, dinfo->n_pages);
+ // if we have many pages we show GTK's progress dialog which also allows cancelling of the + // print operation + if (dinfo->n_pages > 3) + gtk_print_operation_set_show_progress(operation, TRUE); + pango_font_description_free(desc); }
@@ -707,6 +716,15 @@ }
+static void status_changed(GtkPrintOperation *op, gpointer data) +{ + if (gtk_print_operation_get_status(op) == GTK_PRINT_STATUS_FINISHED_ABORTED) + { + ((DocInfo*)data)->cancelled = TRUE; + } +} + + static void printing_print_gtk(gint idx) { GtkPrintOperation *op; @@ -729,6 +747,7 @@ 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), dinfo); 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);
@@ -745,14 +764,21 @@ if (settings != NULL) g_object_unref(settings); settings = g_object_ref(gtk_print_operation_get_print_settings(op)); - msgwin_status_add(_("File %s printed."), doc_list[idx].file_name); + if (dinfo->cancelled) + msgwin_status_add(_("Printing of file %s was cancelled."), doc_list[idx].file_name); + else + msgwin_status_add(_("File %s printed."), doc_list[idx].file_name); } else if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { - dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of "%s" failed (%s)."), + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of %s failed (%s)."), doc_list[idx].file_name, error->message); g_error_free(error); } + else if (res == GTK_PRINT_OPERATION_RESULT_CANCEL) + { // not sure when this actually happens but just in case we print a message + msgwin_status_add(_("Printing of file %s was cancelled."), doc_list[idx].file_name); + }
g_object_unref(op); g_free(dinfo);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.