New function to cancel a running print operation.

2006-05-19  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtk.symbols:
	* gtk/gtkprintoperation.h:
	* gtk/gtkprintoperation.c (gtk_print_operation_cancel): New function
	to cancel a running print operation.

	* gtk/gtkprintoperation-private.h (struct _GtkPrintOperationPrivate):
	Add a cancelled flag, use g types, use bitfields.

	* gtk/gtkprintoperation.c (print_pages): Clean up after the idle
	in the synchronous case.
This commit is contained in:
Matthias Clasen 2006-05-19 19:25:51 +00:00 committed by Matthias Clasen
parent fbe7b81261
commit a59a999d7c
8 changed files with 90 additions and 32 deletions

View File

@ -1,5 +1,16 @@
2006-05-19 Matthias Clasen <mclasen@redhat.com> 2006-05-19 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk.symbols:
* gtk/gtkprintoperation.h:
* gtk/gtkprintoperation.c (gtk_print_operation_cancel): New function
to cancel a running print operation.
* gtk/gtkprintoperation-private.h (struct _GtkPrintOperationPrivate):
Add a cancelled flag, use g types, use bitfields.
* gtk/gtkprintoperation.c (print_pages): Clean up after the idle
in the synchronous case.
* gtk/gtknotebook.c (gtk_notebook_pages_allocate): Fix a * gtk/gtknotebook.c (gtk_notebook_pages_allocate): Fix a
boundary case in scrolling where a tab was not shown. (#168105, boundary case in scrolling where a tab was not shown. (#168105,
Hiroyuki Ikezoe, patch by Kouhei Sutou) Hiroyuki Ikezoe, patch by Kouhei Sutou)

View File

@ -1,5 +1,16 @@
2006-05-19 Matthias Clasen <mclasen@redhat.com> 2006-05-19 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk.symbols:
* gtk/gtkprintoperation.h:
* gtk/gtkprintoperation.c (gtk_print_operation_cancel): New function
to cancel a running print operation.
* gtk/gtkprintoperation-private.h (struct _GtkPrintOperationPrivate):
Add a cancelled flag, use g types, use bitfields.
* gtk/gtkprintoperation.c (print_pages): Clean up after the idle
in the synchronous case.
* gtk/gtknotebook.c (gtk_notebook_pages_allocate): Fix a * gtk/gtknotebook.c (gtk_notebook_pages_allocate): Fix a
boundary case in scrolling where a tab was not shown. (#168105, boundary case in scrolling where a tab was not shown. (#168105,
Hiroyuki Ikezoe, patch by Kouhei Sutou) Hiroyuki Ikezoe, patch by Kouhei Sutou)

View File

@ -1,3 +1,7 @@
2006-05-19 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Additions
2006-05-18 Matthias Clasen <mclasen@redhat.com> 2006-05-18 Matthias Clasen <mclasen@redhat.com>
* gtk/tmpl/gtkenums.sgml: Updates * gtk/tmpl/gtkenums.sgml: Updates

View File

@ -6084,8 +6084,8 @@ gtk_print_operation_set_use_full_page
gtk_print_operation_set_unit gtk_print_operation_set_unit
gtk_print_operation_set_show_dialog gtk_print_operation_set_show_dialog
gtk_print_operation_set_pdf_target gtk_print_operation_set_pdf_target
gtk_print_operation_run
gtk_print_operation_run_async gtk_print_operation_run_async
gtk_print_operation_cancel
gtk_print_operation_get_status gtk_print_operation_get_status
gtk_print_operation_get_status_string gtk_print_operation_get_status_string
gtk_print_operation_is_finished gtk_print_operation_is_finished

View File

@ -2701,6 +2701,7 @@ gtk_print_operation_run_async
gtk_print_operation_get_status gtk_print_operation_get_status
gtk_print_operation_get_status_string gtk_print_operation_get_status_string
gtk_print_operation_is_finished gtk_print_operation_is_finished
gtk_print_operation_cancel
#endif #endif
#endif #endif

View File

@ -28,45 +28,46 @@ G_BEGIN_DECLS
struct _GtkPrintOperationPrivate struct _GtkPrintOperationPrivate
{ {
GtkPrintStatus status; GtkPrintStatus status;
char *status_string; gchar *status_string;
GtkPageSetup *default_page_setup; GtkPageSetup *default_page_setup;
GtkPrintSettings *print_settings; GtkPrintSettings *print_settings;
char *job_name; gchar *job_name;
int nr_of_pages; gint nr_of_pages;
int current_page; gint current_page;
gboolean use_full_page;
GtkUnit unit; GtkUnit unit;
gboolean show_dialog; gchar *pdf_target;
gboolean track_print_status; guint use_full_page : 1;
char *pdf_target; guint show_dialog : 1;
guint track_print_status : 1;
guint cancelled : 1;
guint print_pages_idle_id; guint print_pages_idle_id;
/* Data for the print job: */ /* Data for the print job: */
cairo_surface_t *surface; cairo_surface_t *surface;
double dpi_x, dpi_y; gdouble dpi_x, dpi_y;
GtkPrintPages print_pages; GtkPrintPages print_pages;
GtkPageRange *page_ranges; GtkPageRange *page_ranges;
int num_page_ranges; gint num_page_ranges;
int manual_num_copies; gint manual_num_copies;
gboolean manual_collation; guint manual_collation : 1;
gboolean manual_reverse; guint manual_reverse : 1;
gboolean manual_orientation; guint manual_orientation : 1;
double manual_scale; double manual_scale;
GtkPageSet manual_page_set; GtkPageSet manual_page_set;
void *platform_data; gpointer platform_data;
GDestroyNotify free_platform_data;
void (*start_page) (GtkPrintOperation *operation, void (*start_page) (GtkPrintOperation *operation,
GtkPrintContext *print_context, GtkPrintContext *print_context,
GtkPageSetup *page_setup); GtkPageSetup *page_setup);
void (*end_page) (GtkPrintOperation *operation, void (*end_page) (GtkPrintOperation *operation,
GtkPrintContext *print_context); GtkPrintContext *print_context);
void (*end_run) (GtkPrintOperation *operation, void (*end_run) (GtkPrintOperation *operation,
gboolean wait); gboolean wait);
GDestroyNotify free_platform_data;
}; };
GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation, GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation,
@ -75,15 +76,15 @@ GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPri
GError **error); GError **error);
typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op, typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op,
gboolean wait); gboolean wait);
void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op, void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
GtkWindow *parent, GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb); GtkPrintOperationPrintFunc print_cb);
void _gtk_print_operation_set_status (GtkPrintOperation *op, void _gtk_print_operation_set_status (GtkPrintOperation *op,
GtkPrintStatus status, GtkPrintStatus status,
const char *string); const gchar *string);
/* GtkPrintContext private functions: */ /* GtkPrintContext private functions: */

View File

@ -1347,18 +1347,15 @@ static void
print_pages_idle_done (gpointer user_data) print_pages_idle_done (gpointer user_data)
{ {
PrintPagesData *data; PrintPagesData *data;
GtkPrintOperationPrivate *priv;
data = (PrintPagesData*)user_data; data = (PrintPagesData*)user_data;
priv = data->op->priv; data->op->priv->print_pages_idle_id = 0;
g_object_unref (data->print_context); g_object_unref (data->print_context);
g_object_unref (data->initial_page_setup); g_object_unref (data->initial_page_setup);
g_object_unref (data->op); g_object_unref (data->op);
g_free (data); g_free (data);
priv->print_pages_idle_id = 0;
} }
static gboolean static gboolean
@ -1484,6 +1481,17 @@ print_pages_idle (gpointer user_data)
out: out:
if (priv->cancelled)
{
g_signal_emit (data->op, signals[END_PRINT], 0, data->print_context);
cairo_surface_finish (data->op->priv->surface);
_gtk_print_operation_set_status (data->op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
done = TRUE;
}
GDK_THREADS_LEAVE (); GDK_THREADS_LEAVE ();
return !done; return !done;
@ -1535,13 +1543,13 @@ print_pages (GtkPrintOperation *op,
while (gtk_events_pending ()) while (gtk_events_pending ())
gtk_main_iteration (); gtk_main_iteration ();
} }
print_pages_idle_done (data);
} }
else else
priv->print_pages_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, priv->print_pages_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
print_pages_idle, print_pages_idle,
data, data,
print_pages_idle_done); print_pages_idle_done);}
}
/** /**
* gtk_print_operation_run: * gtk_print_operation_run:
@ -1645,5 +1653,26 @@ gtk_print_operation_run_async (GtkPrintOperation *op,
} }
/**
* gtk_print_operation_cancel:
* @op: a #GtkPrintOperation
*
* Cancels a running print operation. This function may
* be called from a begin-print, paginate or draw-page
* signal handler to stop the currently running print
* operation.
*
* Since: 2.10
*/
void
gtk_print_operation_cancel (GtkPrintOperation *op)
{
g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
op->priv->cancelled = TRUE;
}
#define __GTK_PRINT_OPERATION_C__ #define __GTK_PRINT_OPERATION_C__
#include "gtkaliasdef.c" #include "gtkaliasdef.c"

View File

@ -138,6 +138,7 @@ GtkPrintOperationResult gtk_print_operation_run (GtkPrintOper
GtkPrintStatus gtk_print_operation_get_status (GtkPrintOperation *op); GtkPrintStatus gtk_print_operation_get_status (GtkPrintOperation *op);
G_CONST_RETURN gchar * gtk_print_operation_get_status_string (GtkPrintOperation *op); G_CONST_RETURN gchar * gtk_print_operation_get_status_string (GtkPrintOperation *op);
gboolean gtk_print_operation_is_finished (GtkPrintOperation *op); gboolean gtk_print_operation_is_finished (GtkPrintOperation *op);
void gtk_print_operation_cancel (GtkPrintOperation *op);
GtkPageSetup *gtk_print_run_page_setup_dialog (GtkWindow *parent, GtkPageSetup *gtk_print_run_page_setup_dialog (GtkWindow *parent,
GtkPageSetup *page_setup, GtkPageSetup *page_setup,