gtkprintoperation.c 66.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* GTK - The GIMP Toolkit
 * gtkprintoperation.c: Print Operation
 * Copyright (C) 2006, Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
22 23 24 25

#include <errno.h>
#include <stdlib.h>       

26
#include <string.h>
27 28 29 30 31
#include "gtkprintoperation-private.h"
#include "gtkmarshalers.h"
#include <cairo-pdf.h>
#include "gtkintl.h"
#include "gtkprivate.h"
32
#include "gtkmessagedialog.h"
33 34
#include "gtkalias.h"

35 36
#define SHOW_PROGRESS_TIME 1200

37 38
#define GTK_PRINT_OPERATION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationPrivate))

Matthias Clasen's avatar
Matthias Clasen committed
39 40
enum 
{
41
  DONE,
42
  BEGIN_PRINT,
43
  PAGINATE,
44 45 46 47
  REQUEST_PAGE_SETUP,
  DRAW_PAGE,
  END_PRINT,
  STATUS_CHANGED,
48 49
  CREATE_CUSTOM_WIDGET,
  CUSTOM_WIDGET_APPLY,
50
  PREVIEW,
51 52 53
  LAST_SIGNAL
};

Matthias Clasen's avatar
Matthias Clasen committed
54 55
enum 
{
56 57 58 59
  PROP_0,
  PROP_DEFAULT_PAGE_SETUP,
  PROP_PRINT_SETTINGS,
  PROP_JOB_NAME,
Alexander Larsson's avatar
Alexander Larsson committed
60
  PROP_N_PAGES,
61 62
  PROP_CURRENT_PAGE,
  PROP_USE_FULL_PAGE,
63
  PROP_TRACK_PRINT_STATUS,
64
  PROP_UNIT,
65
  PROP_SHOW_PROGRESS,
66
  PROP_ALLOW_ASYNC,
67
  PROP_EXPORT_FILENAME,
68
  PROP_STATUS,
Matthias Clasen's avatar
Matthias Clasen committed
69 70
  PROP_STATUS_STRING,
  PROP_CUSTOM_TAB_LABEL
71 72 73 74 75
};

static guint signals[LAST_SIGNAL] = { 0 };
static int job_nr = 0;

76 77 78 79 80 81 82 83 84
static void          preview_iface_init (GtkPrintOperationPreviewIface *iface);
static GtkPageSetup *create_page_setup  (GtkPrintOperation             *op);
static void          common_render_page (GtkPrintOperation             *op,
					 gint                           page_nr);


G_DEFINE_TYPE_WITH_CODE (GtkPrintOperation, gtk_print_operation, G_TYPE_OBJECT,
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_PRINT_OPERATION_PREVIEW,
						preview_iface_init))
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/**
 * gtk_print_error_quark:
 *
 * Registers an error quark for #GtkPrintOperation if necessary.
 * 
 * Return value: The error quark used for #GtkPrintOperation errors.
 *
 * Since: 2.10
 **/
GQuark     
gtk_print_error_quark (void)
{
  static GQuark quark = 0;
  if (quark == 0)
    quark = g_quark_from_static_string ("gtk-print-error-quark");
  return quark;
}
     
static void
gtk_print_operation_finalize (GObject *object)
{
  GtkPrintOperation *print_operation = GTK_PRINT_OPERATION (object);
108
  GtkPrintOperationPrivate *priv = print_operation->priv;
109

110 111
  if (priv->free_platform_data &&
      priv->platform_data)
112
    {
113 114
      priv->free_platform_data (priv->platform_data);
      priv->free_platform_data = NULL;
115 116
    }

117 118
  if (priv->default_page_setup)
    g_object_unref (priv->default_page_setup);
119
  
120 121
  if (priv->print_settings)
    g_object_unref (priv->print_settings);
122
  
123
  g_free (priv->export_filename);
124
  g_free (priv->job_name);
Matthias Clasen's avatar
Matthias Clasen committed
125
  g_free (priv->custom_tab_label);
126

127 128 129
  if (priv->print_pages_idle_id > 0)
    g_source_remove (priv->print_pages_idle_id);

130 131 132
  if (priv->show_progress_timeout_id > 0)
    g_source_remove (priv->show_progress_timeout_id);

133 134 135
  if (priv->error)
    g_error_free (priv->error);
  
136 137 138 139 140 141
  G_OBJECT_CLASS (gtk_print_operation_parent_class)->finalize (object);
}

static void
gtk_print_operation_init (GtkPrintOperation *operation)
{
142
  GtkPrintOperationPrivate *priv;
143 144
  const char *appname;

145
  priv = operation->priv = GTK_PRINT_OPERATION_GET_PRIVATE (operation);
146

147 148 149 150 151 152 153
  priv->status = GTK_PRINT_STATUS_INITIAL;
  priv->status_string = g_strdup ("");
  priv->default_page_setup = NULL;
  priv->print_settings = NULL;
  priv->nr_of_pages = -1;
  priv->current_page = -1;
  priv->use_full_page = FALSE;
154
  priv->show_progress = FALSE;
155
  priv->export_filename = NULL;
156
  priv->track_print_status = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
157
  priv->is_sync = FALSE;
158

Matthias Clasen's avatar
Matthias Clasen committed
159
  priv->rloop = NULL;
160
  priv->unit = GTK_UNIT_PIXEL;
161 162

  appname = g_get_application_name ();
163
  priv->job_name = g_strdup_printf ("%s job #%d", appname, ++job_nr);
164 165
}

166 167
static void
preview_iface_render_page (GtkPrintOperationPreview *preview,
Matthias Clasen's avatar
Matthias Clasen committed
168
			   gint                      page_nr)
169
{
Matthias Clasen's avatar
Matthias Clasen committed
170

171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  GtkPrintOperation *op;

  op = GTK_PRINT_OPERATION (preview);
  common_render_page (op, page_nr);
}

static void
preview_iface_end_preview (GtkPrintOperationPreview *preview)
{
  GtkPrintOperation *op;
  
  op = GTK_PRINT_OPERATION (preview);

  g_signal_emit (op, signals[END_PRINT], 0, op->priv->print_context);

  if (op->priv->rloop)
    g_main_loop_quit (op->priv->rloop);

  op->priv->end_run (op, op->priv->is_sync, TRUE);
190 191 192
  
  g_signal_emit (op, signals[DONE], 0,
		 GTK_PRINT_OPERATION_RESULT_APPLY);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
}

static gboolean
preview_iface_is_selected (GtkPrintOperationPreview *preview,
			   gint                      page_nr)
{
  GtkPrintOperation *op;
  GtkPrintOperationPrivate *priv;
  int i;
  
  op = GTK_PRINT_OPERATION (preview);
  priv = op->priv;
  
  switch (priv->print_pages)
    {
    case GTK_PRINT_PAGES_ALL:
      return (page_nr >= 0) && (page_nr < priv->nr_of_pages);
    case GTK_PRINT_PAGES_CURRENT:
      return page_nr == priv->current_page;
    case GTK_PRINT_PAGES_RANGES:
      for (i = 0; i < priv->num_page_ranges; i++)
	{
	  if (page_nr >= priv->page_ranges[i].start &&
	      page_nr <= priv->page_ranges[i].end)
	    return TRUE;
	}
      return FALSE;
    }
  return FALSE;
}

static void
preview_iface_init (GtkPrintOperationPreviewIface *iface)
{
  iface->render_page = preview_iface_render_page;
  iface->end_preview = preview_iface_end_preview;
  iface->is_selected = preview_iface_is_selected;
}

static void
preview_start_page (GtkPrintOperation *op,
		    GtkPrintContext   *print_context,
		    GtkPageSetup      *page_setup)
{
Matthias Clasen's avatar
Matthias Clasen committed
237
  g_signal_emit_by_name (op, "got-page-size", print_context, page_setup);
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
}

static void
preview_end_page (GtkPrintOperation *op,
		  GtkPrintContext   *print_context)
{
}

static void
preview_end_run (GtkPrintOperation *op,
		 gboolean           wait,
		 gboolean           cancelled)
{
  g_free (op->priv->page_ranges);
  op->priv->page_ranges = NULL;

  _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED, NULL);
}


258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
static void
gtk_print_operation_set_property (GObject      *object,
				  guint         prop_id,
				  const GValue *value,
				  GParamSpec   *pspec)
{
  GtkPrintOperation *op = GTK_PRINT_OPERATION (object);
  
  switch (prop_id)
    {
    case PROP_DEFAULT_PAGE_SETUP:
      gtk_print_operation_set_default_page_setup (op, g_value_get_object (value));
      break;
    case PROP_PRINT_SETTINGS:
      gtk_print_operation_set_print_settings (op, g_value_get_object (value));
      break;
    case PROP_JOB_NAME:
      gtk_print_operation_set_job_name (op, g_value_get_string (value));
      break;
Alexander Larsson's avatar
Alexander Larsson committed
277 278
    case PROP_N_PAGES:
      gtk_print_operation_set_n_pages (op, g_value_get_int (value));
279 280 281 282 283 284 285
      break;
    case PROP_CURRENT_PAGE:
      gtk_print_operation_set_current_page (op, g_value_get_int (value));
      break;
    case PROP_USE_FULL_PAGE:
      gtk_print_operation_set_use_full_page (op, g_value_get_boolean (value));
      break;
286 287 288
    case PROP_TRACK_PRINT_STATUS:
      gtk_print_operation_set_track_print_status (op, g_value_get_boolean (value));
      break;
289 290 291
    case PROP_UNIT:
      gtk_print_operation_set_unit (op, g_value_get_enum (value));
      break;
292 293
    case PROP_ALLOW_ASYNC:
      gtk_print_operation_set_allow_async (op, g_value_get_boolean (value));
294
      break;
295 296 297
    case PROP_SHOW_PROGRESS:
      gtk_print_operation_set_show_progress (op, g_value_get_boolean (value));
      break;
298 299
    case PROP_EXPORT_FILENAME:
      gtk_print_operation_set_export_filename (op, g_value_get_string (value));
300
      break;
Matthias Clasen's avatar
Matthias Clasen committed
301 302 303
    case PROP_CUSTOM_TAB_LABEL:
      gtk_print_operation_set_custom_tab_label (op, g_value_get_string (value));
      break;
304 305 306 307 308 309 310 311 312 313 314 315 316
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_print_operation_get_property (GObject    *object,
				  guint       prop_id,
				  GValue     *value,
				  GParamSpec *pspec)
{
  GtkPrintOperation *op = GTK_PRINT_OPERATION (object);
317 318
  GtkPrintOperationPrivate *priv = op->priv;

319 320 321
  switch (prop_id)
    {
    case PROP_DEFAULT_PAGE_SETUP:
322
      g_value_set_object (value, priv->default_page_setup);
323 324
      break;
    case PROP_PRINT_SETTINGS:
325
      g_value_set_object (value, priv->print_settings);
326 327
      break;
    case PROP_JOB_NAME:
328
      g_value_set_string (value, priv->job_name);
329
      break;
Alexander Larsson's avatar
Alexander Larsson committed
330
    case PROP_N_PAGES:
331
      g_value_set_int (value, priv->nr_of_pages);
332 333
      break;
    case PROP_CURRENT_PAGE:
334
      g_value_set_int (value, priv->current_page);
335 336
      break;      
    case PROP_USE_FULL_PAGE:
337
      g_value_set_boolean (value, priv->use_full_page);
338
      break;
339 340 341
    case PROP_TRACK_PRINT_STATUS:
      g_value_set_boolean (value, priv->track_print_status);
      break;
342
    case PROP_UNIT:
343
      g_value_set_enum (value, priv->unit);
344
      break;
345 346
    case PROP_ALLOW_ASYNC:
      g_value_set_boolean (value, priv->allow_async);
347
      break;
348 349 350
    case PROP_SHOW_PROGRESS:
      g_value_set_boolean (value, priv->show_progress);
      break;
351 352
    case PROP_EXPORT_FILENAME:
      g_value_set_string (value, priv->export_filename);
353 354
      break;
    case PROP_STATUS:
355
      g_value_set_enum (value, priv->status);
356 357
      break;
    case PROP_STATUS_STRING:
358
      g_value_set_string (value, priv->status_string);
359
      break;
Matthias Clasen's avatar
Matthias Clasen committed
360 361 362
    case PROP_CUSTOM_TAB_LABEL:
      g_value_set_string (value, priv->custom_tab_label);
      break;
363 364 365 366 367 368
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
typedef struct
{
  GtkPrintOperationPreview *preview;
  GtkPrintContext *print_context;
  GtkWindow *parent;
  cairo_surface_t *surface;
  gchar *filename;
  guint page_nr;
  gboolean wait;
} PreviewOp;

static void
preview_print_idle_done (gpointer data)
{
  GtkPrintOperation *op;
  PreviewOp *pop = (PreviewOp *) data;

  GDK_THREADS_ENTER ();
  
  op = GTK_PRINT_OPERATION (pop->preview);

390 391
  cairo_surface_finish (pop->surface);
  /* Surface is destroyed in launch_preview */
392
  _gtk_print_operation_platform_backend_launch_preview (op,
393
							pop->surface,
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
							pop->parent,
							pop->filename);

  g_free (pop->filename);

  gtk_print_operation_preview_end_preview (pop->preview);
  g_free (pop);
  
  GDK_THREADS_LEAVE ();
}

static gboolean
preview_print_idle (gpointer data)
{
  PreviewOp *pop;
  GtkPrintOperation *op;
  gboolean retval = TRUE;
  cairo_t *cr;

  GDK_THREADS_ENTER ();

  pop = (PreviewOp *) data;
  op = GTK_PRINT_OPERATION (pop->preview);

  gtk_print_operation_preview_render_page (pop->preview, pop->page_nr);
  
  cr = gtk_print_context_get_cairo_context (pop->print_context);
421
  _gtk_print_operation_platform_backend_preview_end_page (op, pop->surface, cr);
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
  
  /* TODO: print out sheets not pages and follow ranges */
  pop->page_nr++;
  if (op->priv->nr_of_pages <= pop->page_nr)
    retval = FALSE;

  GDK_THREADS_LEAVE ();

  return retval;
}

static void
preview_got_page_size (GtkPrintOperationPreview *preview, 
		       GtkPrintContext          *context,
		       GtkPageSetup             *page_setup,
Matthias Clasen's avatar
Matthias Clasen committed
437
		       PreviewOp                *pop)
438 439
{
  GtkPrintOperation *op = GTK_PRINT_OPERATION (preview);
440
  cairo_t *cr;
441 442

  _gtk_print_operation_platform_backend_resize_preview_surface (op, page_setup, pop->surface);
443 444

  cr = gtk_print_context_get_cairo_context (pop->print_context);
445
  _gtk_print_operation_platform_backend_preview_start_page (op, pop->surface, cr);
446

447 448 449 450
}

static void
preview_ready (GtkPrintOperationPreview *preview,
Matthias Clasen's avatar
Matthias Clasen committed
451 452
               GtkPrintContext          *context,
	       PreviewOp                *pop)
453 454 455 456 457 458 459
{
  pop->page_nr = 0;
  pop->print_context = context;

  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
	           preview_print_idle,
		   pop,
Matthias Clasen's avatar
Matthias Clasen committed
460
		   preview_print_idle_done);
461 462
}

Matthias Clasen's avatar
Matthias Clasen committed
463

464
static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
465
gtk_print_operation_preview_handler (GtkPrintOperation        *op,
466 467 468 469 470 471 472 473 474 475
                                     GtkPrintOperationPreview *preview, 
				     GtkPrintContext          *context,
				     GtkWindow                *parent)
{
  gdouble dpi_x, dpi_y;
  PreviewOp *pop;
  GtkPageSetup *page_setup;
  cairo_t *cr;

  pop = g_new0 (PreviewOp, 1);
476
  pop->filename = NULL;
477 478 479 480 481 482 483 484 485
  pop->preview = preview;
  pop->parent = parent;

  page_setup = gtk_print_context_get_page_setup (context);

  pop->surface =
    _gtk_print_operation_platform_backend_create_preview_surface (op,
								  page_setup,
								  &dpi_x, &dpi_y,
486
								  &pop->filename);
487 488 489 490 491 492 493 494 495 496 497 498

  cr = cairo_create (pop->surface);
  gtk_print_context_set_cairo_context (op->priv->print_context, cr,
				       dpi_x, dpi_y);
  cairo_destroy (cr);

  g_signal_connect (preview, "ready", (GCallback) preview_ready, pop);
  g_signal_connect (preview, "got-page-size", (GCallback) preview_got_page_size, pop);
  
  return TRUE;
}

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
static GtkWidget *
gtk_print_operation_create_custom_widget (GtkPrintOperation *operation)
{
  return NULL;
}

static gboolean
custom_widget_accumulator (GSignalInvocationHint *ihint,
			   GValue                *return_accu,
			   const GValue          *handler_return,
			   gpointer               dummy)
{
  gboolean continue_emission;
  GtkWidget *widget;
  
514
  widget = g_value_get_object (handler_return);
515
  if (widget != NULL)
516
    g_value_set_object (return_accu, widget);
517 518 519 520 521
  continue_emission = (widget == NULL);
  
  return continue_emission;
}

522 523 524 525 526 527 528 529
static void
gtk_print_operation_class_init (GtkPrintOperationClass *class)
{
  GObjectClass *gobject_class = (GObjectClass *)class;

  gobject_class->set_property = gtk_print_operation_set_property;
  gobject_class->get_property = gtk_print_operation_get_property;
  gobject_class->finalize = gtk_print_operation_finalize;
530 531
 
  class->preview = gtk_print_operation_preview_handler; 
532
  class->create_custom_widget = gtk_print_operation_create_custom_widget;
533 534 535
  
  g_type_class_add_private (gobject_class, sizeof (GtkPrintOperationPrivate));

536 537 538 539 540
  /**
   * GtkPrintOperation::done:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @result: the result of the print operation
   *
Matthias Clasen's avatar
Matthias Clasen committed
541
   * Emitted when the print operation run has finished doing
542 543
   * everything required for printing. @result gives you information
   * about what happened during the run. If @result is
Matthias Clasen's avatar
Matthias Clasen committed
544
   * %GTK_PRINT_OPERATION_RESULT_ERROR then you can call
545 546
   * gtk_print_operation_get_error() for more information.
   *
Matthias Clasen's avatar
Matthias Clasen committed
547 548 549
   * If you enabled print status tracking then 
   * gtk_print_operation_is_finished() may still return %FALSE 
   * after this was emitted.
550 551 552 553 554 555 556 557 558 559 560 561
   *
   * Since: 2.10
   */
  signals[DONE] =
    g_signal_new (I_("done"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, done),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__INT,
		  G_TYPE_NONE, 1, G_TYPE_INT);

562 563 564 565 566
  /**
   * GtkPrintOperation::begin-print:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @context: the #GtkPrintContext for the current operation
   *
Matthias Clasen's avatar
Matthias Clasen committed
567
   * Emitted after the user has finished changing print settings
568 569 570 571
   * in the dialog, before the actual rendering starts. 
   *
   * A typical use for this signal is to use the parameters from the
   * #GtkPrintContext and paginate the document accordingly, and then
Alexander Larsson's avatar
Alexander Larsson committed
572
   * set the number of pages with gtk_print_operation_set_n_pages().
573 574 575 576
   *
   * Since: 2.10
   */
  signals[BEGIN_PRINT] =
Matthias Clasen's avatar
Matthias Clasen committed
577
    g_signal_new (I_("begin-print"),
578 579 580 581 582 583 584
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, begin_print),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__OBJECT,
		  G_TYPE_NONE, 1, GTK_TYPE_PRINT_CONTEXT);

585 586 587 588 589
   /**
   * Gtkprintoperation::paginate:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @context: the #GtkPrintContext for the current operation
   *
Matthias Clasen's avatar
Matthias Clasen committed
590
   * Emitted after the begin-print signal, but before the actual 
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
   * rendering starts. It keeps getting emitted until it returns %FALSE. 
   *
   * This signal is intended to be used for paginating the document
   * in small chunks, to avoid blocking the user interface for a long
   * time. The signal handler should update the number of pages using
   * gtk_print_operation_set_n_pages(), and return %TRUE if the document
   * has been completely paginated.
   *
   * If you don't need to do pagination in chunks, you can simply do
   * it all in the begin-print handler, and set the number of pages
   * from there.
   *
   * Since: 2.10
   */
  signals[PAGINATE] =
    g_signal_new (I_("paginate"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, paginate),
		  _gtk_boolean_handled_accumulator, NULL,
		  _gtk_marshal_BOOLEAN__OBJECT,
		  G_TYPE_BOOLEAN, 1, GTK_TYPE_PRINT_CONTEXT);


615 616 617 618 619 620 621
  /**
   * GtkPrintOperation::request-page-setup:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @context: the #GtkPrintContext for the current operation
   * @page_nr: the number of the currently printed page
   * @setup: the #GtkPageSetup 
   * 
Matthias Clasen's avatar
Matthias Clasen committed
622
   * Emitted once for every page that is printed, to give
623 624 625 626 627 628
   * the application a chance to modify the page setup. Any changes 
   * done to @setup will be in force only for printing this page.
   *
   * Since: 2.10
   */
  signals[REQUEST_PAGE_SETUP] =
Matthias Clasen's avatar
Matthias Clasen committed
629
    g_signal_new (I_("request-page-setup"),
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, request_page_setup),
		  NULL, NULL,
		  _gtk_marshal_VOID__OBJECT_INT_OBJECT,
		  G_TYPE_NONE, 3,
		  GTK_TYPE_PRINT_CONTEXT,
		  G_TYPE_INT,
		  GTK_TYPE_PAGE_SETUP);

  /**
   * GtkPrintOperation::draw-page:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @context: the #GtkPrintContext for the current operation
   * @page_nr: the number of the currently printed page
   *
Matthias Clasen's avatar
Matthias Clasen committed
646
   * Emitted for every page that is printed. The signal handler
647
   * must render the @page_nr's page onto the cairo context obtained
648
   * from @context using gtk_print_context_get_cairo_context().
Matthias Clasen's avatar
Matthias Clasen committed
649
   *
650
   * <informalexample><programlisting>
Matthias Clasen's avatar
Matthias Clasen committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
   * static void
   * draw_page (GtkPrintOperation *operation,
   *            GtkPrintContext   *context,
   *            gint               page_nr,
   *            gpointer           user_data)
   * {
   *   cairo_t *cr;
   *   PangoLayout *layout;
   *   gdouble width, text_height;
   *   gint layout_height;
   *   PangoFontDescription *desc;
   *   
   *   cr = gtk_print_context_get_cairo_context (context);
   *   width = gtk_print_context_get_width (context);
   *   
   *   cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);
   *   
   *   cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
   *   cairo_fill (cr);
   *   
   *   layout = gtk_print_context_create_pango_layout (context);
   *   
   *   desc = pango_font_description_from_string ("sans 14");
   *   pango_layout_set_font_description (layout, desc);
   *   pango_font_description_free (desc);
   *   
   *   pango_layout_set_text (layout, "some text", -1);
   *   pango_layout_set_width (layout, width);
   *   pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
Matthias Clasen's avatar
2.9.2  
Matthias Clasen committed
680
   *      		      
Matthias Clasen's avatar
Matthias Clasen committed
681 682 683 684 685
   *   pango_layout_get_size (layout, NULL, &amp;layout_height);
   *   text_height = (gdouble)layout_height / PANGO_SCALE;
   *   
   *   cairo_move_to (cr, width / 2,  (HEADER_HEIGHT - text_height) / 2);
   *   pango_cairo_show_layout (cr, layout);
Matthias Clasen's avatar
2.9.2  
Matthias Clasen committed
686
   *   
Matthias Clasen's avatar
Matthias Clasen committed
687 688
   *   g_object_unref (layout);
   * }
689 690
   * </programlisting></informalexample>
   *
Matthias Clasen's avatar
Matthias Clasen committed
691 692 693 694 695
   * Use gtk_print_operation_set_use_full_page() and 
   * gtk_print_operation_set_unit() before starting the print operation
   * to set up the transformation of the cairo context according to your
   * needs.
   * 
696 697 698
   * Since: 2.10
   */
  signals[DRAW_PAGE] =
Matthias Clasen's avatar
Matthias Clasen committed
699
    g_signal_new (I_("draw-page"),
700 701 702 703 704 705 706 707 708 709 710 711 712 713
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, draw_page),
		  NULL, NULL,
		  _gtk_marshal_VOID__OBJECT_INT,
		  G_TYPE_NONE, 2,
		  GTK_TYPE_PRINT_CONTEXT,
		  G_TYPE_INT);

  /**
   * GtkPrintOperation::end-print:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @context: the #GtkPrintContext for the current operation
   *
Matthias Clasen's avatar
Matthias Clasen committed
714
   * Emitted after all pages have been rendered. 
715 716 717 718 719 720
   * A handler for this signal can clean up any resources that have
   * been allocated in the ::begin-print handler.
   * 
   * Since: 2.10
   */
  signals[END_PRINT] =
Matthias Clasen's avatar
Matthias Clasen committed
721
    g_signal_new (I_("end-print"),
722 723 724 725 726 727 728 729 730 731 732
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, end_print),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__OBJECT,
		  G_TYPE_NONE, 1, GTK_TYPE_PRINT_CONTEXT);

  /**
   * GtkPrintOperation::status-changed:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   *
Matthias Clasen's avatar
Matthias Clasen committed
733
   * Emitted at between the various phases of the print operation.
734 735 736 737 738 739 740
   * See #GtkPrintStatus for the phases that are being discriminated.
   * Use gtk_print_operation_get_status() to find out the current
   * status.
   *
   * Since: 2.10
   */
  signals[STATUS_CHANGED] =
Matthias Clasen's avatar
Matthias Clasen committed
741
    g_signal_new (I_("status-changed"),
742 743 744 745 746 747 748 749 750
		  G_TYPE_FROM_CLASS (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, status_changed),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);


  /**
Matthias Clasen's avatar
Matthias Clasen committed
751
   * GtkPrintOperation::create-custom-widget:
752 753
   * @operation: the #GtkPrintOperation on which the signal was emitted
   *
Matthias Clasen's avatar
Matthias Clasen committed
754
   * Emitted when displaying the print dialog. If you return a
755 756 757 758 759 760 761 762 763 764
   * widget in a handler for this signal it will be added to a custom
   * tab in the print dialog. You typically return a container widget
   * with multiple widgets in it.
   *
   * The print dialog owns the returned widget, and its lifetime
   * isn't controlled by the app. However, the widget is guaranteed
   * to stay around until the custom-widget-apply signal is emitted
   * on the operation. Then you can read out any information you need
   * from the widgets.
   *
Matthias Clasen's avatar
Matthias Clasen committed
765 766 767
   * Returns: A custom widget that gets embedded in the print dialog,
   *          or %NULL
   *
768 769 770 771 772 773 774 775
   * Since: 2.10
   */
  signals[CREATE_CUSTOM_WIDGET] =
    g_signal_new (I_("create-custom-widget"),
		  G_TYPE_FROM_CLASS (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, create_custom_widget),
		  custom_widget_accumulator, NULL,
776 777
		  _gtk_marshal_OBJECT__VOID,
		  G_TYPE_OBJECT, 0);
778 779 780 781 782 783

  /**
   * GtkPrintOperation::custom-widget-apply:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @widget: the custom widget added in create-custom-widget
   *
Matthias Clasen's avatar
Matthias Clasen committed
784
   * Emitted right before begin-print if you added
785 786 787 788 789 790 791 792 793 794 795 796 797 798
   * a custom widget in the create-custom-widget handler. When you get
   * this signal you should read the information from the custom widgets,
   * as the widgets are not guaraneed to be around at a later time.
   *
   * Since: 2.10
   */
  signals[CUSTOM_WIDGET_APPLY] =
    g_signal_new (I_("custom-widget-apply"),
		  G_TYPE_FROM_CLASS (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, custom_widget_apply),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__OBJECT,
		  G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
799

800 801 802 803 804
   /**
   * GtkPrintOperation::preview:
   * @operation: the #GtkPrintOperation on which the signal was emitted
   * @preview: the #GtkPrintPreviewOperation for the current operation
   * @context: the #GtkPrintContext that will be used
Matthias Clasen's avatar
Matthias Clasen committed
805
   * @parent: the #GtkWindow to use as window parent, or %NULL
806 807 808 809 810 811 812
   *
   * Gets emitted when a preview is requested from the native dialog.
   * If you handle this you must set the cairo context on the printing context.
   *
   * If you don't override this a default implementation using an external
   * viewer will be used.
   *
Matthias Clasen's avatar
Matthias Clasen committed
813
   * Returns: %TRUE if the listener wants to take over control of the preview
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
   * 
   * Since: 2.10
   */
  signals[PREVIEW] =
    g_signal_new (I_("preview"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintOperationClass, preview),
		  _gtk_boolean_handled_accumulator, NULL,
		  _gtk_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT,
		  G_TYPE_BOOLEAN, 3,
		  GTK_TYPE_PRINT_OPERATION_PREVIEW,
		  GTK_TYPE_PRINT_CONTEXT,
		  GTK_TYPE_WINDOW);

  
Matthias Clasen's avatar
Matthias Clasen committed
830 831 832 833 834 835 836 837 838 839 840
  /**
   * GtkPrintOperation:default-page-setup:
   *
   * The #GtkPageSetup used by default.
   * 
   * This page setup will be used by gtk_print_operation_run(),
   * but it can be overridden on a per-page basis by connecting
   * to the ::request-page-setup signal.
   *
   * Since: 2.10
   */
841 842 843 844 845 846 847 848
  g_object_class_install_property (gobject_class,
				   PROP_DEFAULT_PAGE_SETUP,
				   g_param_spec_object ("default-page-setup",
							P_("Default Page Setup"),
							P_("The GtkPageSetup used by default"),
							GTK_TYPE_PAGE_SETUP,
							GTK_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
849 850 851 852 853
  /**
   * GtkPrintOperation:print-settings:
   *
   * The #GtkPrintSettings used for initializing the dialog.
   *
Matthias Clasen's avatar
Matthias Clasen committed
854 855 856
   * Setting this property is typically used to re-establish 
   * print settings from a previous print operation, see 
   * gtk_print_operation_run().
Matthias Clasen's avatar
Matthias Clasen committed
857 858 859
   *
   * Since: 2.10
   */
860 861 862 863 864 865 866
  g_object_class_install_property (gobject_class,
				   PROP_PRINT_SETTINGS,
				   g_param_spec_object ("print-settings",
							P_("Print Settings"),
							P_("The GtkPrintSettings used for initializing the dialog"),
							GTK_TYPE_PRINT_SETTINGS,
							GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
867 868 869 870
  
  /**
   * GtkPrintOperation:job-name:
   *
Matthias Clasen's avatar
Matthias Clasen committed
871 872
   * A string used to identify the job (e.g. in monitoring 
   * applications like eggcups). 
Matthias Clasen's avatar
Matthias Clasen committed
873
   * 
Matthias Clasen's avatar
Matthias Clasen committed
874 875
   * If you don't set a job name, GTK+ picks a default one 
   * by numbering successive print jobs.
Matthias Clasen's avatar
Matthias Clasen committed
876 877 878
   *
   * Since: 2.10
   */
879 880 881 882 883 884 885
  g_object_class_install_property (gobject_class,
				   PROP_JOB_NAME,
				   g_param_spec_string ("job-name",
							P_("Job Name"),
							P_("A string used for identifying the print job."),
							"",
							GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
886 887

  /**
Alexander Larsson's avatar
Alexander Larsson committed
888
   * GtkPrintOperation:n-pages:
Matthias Clasen's avatar
Matthias Clasen committed
889 890 891 892
   *
   * The number of pages in the document. 
   *
   * This <emphasis>must</emphasis> be set to a positive number
Matthias Clasen's avatar
Matthias Clasen committed
893 894
   * before the rendering starts. It may be set in a ::begin-print 
   * signal hander.
Matthias Clasen's avatar
Matthias Clasen committed
895
   *
Matthias Clasen's avatar
Matthias Clasen committed
896 897 898 899
   * Note that the page numbers passed to the ::request-page-setup 
   * and ::draw-page signals are 0-based, i.e. if the user chooses 
   * to print all pages, the last ::draw-page signal will be for 
   * page @n_pages - 1.
Matthias Clasen's avatar
Matthias Clasen committed
900 901 902
   *
   * Since: 2.10
   */
903
  g_object_class_install_property (gobject_class,
Alexander Larsson's avatar
Alexander Larsson committed
904 905
				   PROP_N_PAGES,
				   g_param_spec_int ("n-pages",
906 907 908 909 910 911
						     P_("Number of Pages"),
						     P_("The number of pages in the document."),
						     -1,
						     G_MAXINT,
						     -1,
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
912 913 914 915 916 917 918 919 920 921 922 923 924

  /**
   * GtkPrintOperation:current-page:
   *
   * The current page in the document.
   *
   * If this is set before gtk_print_operation_run(), 
   * the user will be able to select to print only the current page.
   *
   * Note that this only makes sense for pre-paginated documents.
   *
   * Since: 2.10
   */
925 926 927 928 929 930 931 932 933 934
  g_object_class_install_property (gobject_class,
				   PROP_CURRENT_PAGE,
				   g_param_spec_int ("current-page",
						     P_("Current Page"),
						     P_("The current page in the document."),
						     -1,
						     G_MAXINT,
						     -1,
						     GTK_PARAM_READWRITE));
  
Matthias Clasen's avatar
Matthias Clasen committed
935 936 937
  /**
   * GtkPrintOperation:use-full-page:
   *
Matthias Clasen's avatar
Matthias Clasen committed
938 939 940 941 942 943
   * If %TRUE, the transformation for the cairo context obtained 
   * from #GtkPrintContext puts the origin at the top left corner 
   * of the page (which may not be the top left corner of the sheet, 
   * depending on page orientation and the number of pages per sheet). 
   * Otherwise, the origin is at the top left corner of the imageable 
   * area (i.e. inside the margins).
Matthias Clasen's avatar
Matthias Clasen committed
944 945 946
   * 
   * Since: 2.10
   */
947 948 949 950
  g_object_class_install_property (gobject_class,
				   PROP_USE_FULL_PAGE,
				   g_param_spec_boolean ("use-full-page",
							 P_("Use full page"),
Matthias Clasen's avatar
Matthias Clasen committed
951
							 P_("TRUE if the the origin of the context should be at the corner of the page and not the corner of the imageable area"),
952 953 954 955
							 FALSE,
							 GTK_PARAM_READWRITE));
  

956 957 958
  /**
   * GtkPrintOperation:track-print-status:
   *
Matthias Clasen's avatar
Matthias Clasen committed
959 960 961 962 963 964
   * If %TRUE, the print operation will try to continue report on 
   * the status of the print job in the printer queues and printer. 
   * This can allow your application to show things like "out of paper" 
   * issues, and when the print job actually reaches the printer. 
   * However, this is often implemented using polling, and should 
   * not be enabled unless needed.
965 966 967 968
   * 
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
Matthias Clasen's avatar
Matthias Clasen committed
969
				   PROP_TRACK_PRINT_STATUS,
970 971
				   g_param_spec_boolean ("track-print-status",
							 P_("Track Print Status"),
Matthias Clasen's avatar
Matthias Clasen committed
972
							 P_("TRUE if the print operation will continue to report on the print job status after the print data has been sent to the printer or print server."),
973 974 975 976
							 FALSE,
							 GTK_PARAM_READWRITE));
  

Matthias Clasen's avatar
Matthias Clasen committed
977 978 979 980
  /**
   * GtkPrintOperation:unit:
   *
   * The transformation for the cairo context obtained from
Matthias Clasen's avatar
Matthias Clasen committed
981 982
   * #GtkPrintContext is set up in such a way that distances 
   * are measured in units of @unit.
Matthias Clasen's avatar
Matthias Clasen committed
983 984 985
   *
   * Since: 2.10
   */
986 987 988 989
  g_object_class_install_property (gobject_class,
				   PROP_UNIT,
				   g_param_spec_enum ("unit",
						      P_("Unit"),
Matthias Clasen's avatar
Matthias Clasen committed
990
						      P_("The unit in which distances can be measured in the context"),
991 992 993 994
						      GTK_TYPE_UNIT,
						      GTK_UNIT_PIXEL,
						      GTK_PARAM_READWRITE));
  
995
  
Matthias Clasen's avatar
Matthias Clasen committed
996
  /**
997
   * GtkPrintOperation:show-progress:
Matthias Clasen's avatar
Matthias Clasen committed
998
   *
999 1000
   * Determines whether to show a progress dialog during the 
   * print operation.
Matthias Clasen's avatar
Matthias Clasen committed
1001 1002 1003
   *
   * Since: 2.10
   */
1004
  g_object_class_install_property (gobject_class,
1005 1006
				   PROP_SHOW_PROGRESS,
				   g_param_spec_boolean ("show-progress",
1007
							 P_("Show Dialog"),
1008 1009
							 P_("TRUE if a progress dialog is shown while printing."),
							 FALSE,
1010
							 GTK_PARAM_READWRITE));
1011

1012
  /**
1013
   * GtkPrintOperation:allow-async:
1014
   *
Matthias Clasen's avatar
Matthias Clasen committed
1015
   * Determines whether the print operation may run asynchronously or not.
1016
   * Some systems don't support asynchronous printing, but those that do
Matthias Clasen's avatar
Matthias Clasen committed
1017
   * will return %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS as the status, and
1018
   * emit the done signal when the operation is actually done.
1019 1020 1021 1022
   *
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
1023 1024 1025 1026
				   PROP_ALLOW_ASYNC,
				   g_param_spec_boolean ("allow-async",
							 P_("Allow Async"),
							 P_("TRUE if print process may run asynchronous."),
1027 1028 1029
							 FALSE,
							 GTK_PARAM_READWRITE));
  
Matthias Clasen's avatar
Matthias Clasen committed
1030
  /**
Matthias Clasen's avatar
Matthias Clasen committed
1031
   * GtkPrintOperation:export-filename:
Matthias Clasen's avatar
Matthias Clasen committed
1032
   *
Matthias Clasen's avatar
Matthias Clasen committed
1033 1034 1035
   * The name of a file file to generate instead of showing 
   * the print dialog. Currently, PDF is the only supported
   * format.
Matthias Clasen's avatar
Matthias Clasen committed
1036
   *
Matthias Clasen's avatar
Matthias Clasen committed
1037 1038
   * The intended use of this property is for implementing 
   * "Export to PDF" actions.
Matthias Clasen's avatar
Matthias Clasen committed
1039 1040
   *
   * "Print to PDF" support is independent of this and is done
Matthias Clasen's avatar
Matthias Clasen committed
1041 1042
   * by letting the user pick the "Print to PDF" item from the 
   * list of printers in the print dialog.
Matthias Clasen's avatar
Matthias Clasen committed
1043 1044 1045
   *
   * Since: 2.10
   */
1046
  g_object_class_install_property (gobject_class,
Matthias Clasen's avatar
Matthias Clasen committed
1047 1048 1049 1050
				   PROP_EXPORT_FILENAME,
				   g_param_spec_string ("export-filename",
							P_("Export filename"),
							P_("Export filename"),
1051 1052 1053
							NULL,
							GTK_PARAM_READWRITE));
  
Matthias Clasen's avatar
Matthias Clasen committed
1054 1055 1056 1057 1058 1059 1060
  /**
   * GtkPrintOperation:status:
   *
   * The status of the print operation.
   * 
   * Since: 2.10
   */
1061 1062 1063 1064 1065 1066 1067 1068 1069
  g_object_class_install_property (gobject_class,
				   PROP_STATUS,
				   g_param_spec_enum ("status",
						      P_("Status"),
						      P_("The status of the print operation"),
						      GTK_TYPE_PRINT_STATUS,
						      GTK_PRINT_STATUS_INITIAL,
						      GTK_PARAM_READABLE));
  
Matthias Clasen's avatar
Matthias Clasen committed
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
  /**
   * GtkPrintOperation:status-string:
   *
   * A string representation of the status of the print operation. 
   * The string is translated and suitable for displaying the print 
   * status e.g. in a #GtkStatusbar.
   *
   * See the ::status property for a status value that is suitable 
   * for programmatic use. 
   *
   * Since: 2.10
   */
1082 1083 1084 1085 1086 1087 1088 1089 1090
  g_object_class_install_property (gobject_class,
				   PROP_STATUS_STRING,
				   g_param_spec_string ("status-string",
							P_("Status String"),
							P_("A human-readable description of the status"),
							"",
							GTK_PARAM_READABLE));
  

Matthias Clasen's avatar
Matthias Clasen committed
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
  /**
   * GtkPrintOperation:custom-tab-label:
   *
   * Used as the label of the tab containing custom widgets.
   * Note that this property may be ignored on some platforms.
   * 
   * If this is %NULL, GTK+ uses a default label.
   *
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
				   PROP_CUSTOM_TAB_LABEL,
				   g_param_spec_string ("custom-tab-label",
							P_("Custom tab label"),
							P_("Label for the tab containing custom widgets."),
							NULL,
							GTK_PARAM_READWRITE));

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
}

/**
 * gtk_print_operation_new:
 *
 * Creates a new #GtkPrintOperation. 
 *
 * Returns: a new #GtkPrintOperation
 *
 * Since: 2.10
 */
GtkPrintOperation *
gtk_print_operation_new (void)
{
  GtkPrintOperation *print_operation;

  print_operation = g_object_new (GTK_TYPE_PRINT_OPERATION, NULL);
  
  return print_operation;
}

/**
 * gtk_print_operation_set_default_page_setup:
 * @op: a #GtkPrintOperation
 * @default_page_setup: a #GtkPageSetup, or %NULL
 * 
 * Makes @default_page_setup the default page setup for @op.
 *
 * This page setup will be used by gtk_print_operation_run(),
 * but it can be overridden on a per-page basis by connecting
 * to the ::request-page-setup signal.
 *
 * Since: 2.10
 **/
void
gtk_print_operation_set_default_page_setup (GtkPrintOperation *op,
					    GtkPageSetup      *default_page_setup)
{
1147 1148
  GtkPrintOperationPrivate *priv;

1149 1150 1151 1152
  g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
  g_return_if_fail (default_page_setup == NULL || 
                    GTK_IS_PAGE_SETUP (default_page_setup));

1153 1154 1155
  priv = op->priv;

  if (default_page_setup != priv->default_page_setup)
1156 1157 1158 1159
    {
      if (default_page_setup)
	g_object_ref (default_page_setup);
      
1160 1161
      if (priv->default_page_setup)
	g_object_unref (priv->default_page_setup);
1162
      
1163
      priv->default_page_setup = default_page_setup;
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
     
      g_object_notify (G_OBJECT (op), "default-page-setup");
    }
}

/**
 * gtk_print_operation_get_default_page_setup:
 * @op: a #GtkPrintOperation
 *
 * Returns the default page setup, see 
 * gtk_print_operation_set_default_page_setup().
 *
 * Returns: the default page setup 
 *
 * Since: 2.10
 */
GtkPageSetup *
gtk_print_operation_get_default_page_setup (GtkPrintOperation *op)
{
  g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), NULL);

  return op->priv->default_page_setup;
}


/**
 * gtk_print_operation_set_print_settings:
 * @op: a #GtkPrintOperation
 * @print_settings: #GtkPrintSettings, or %NULL
 * 
 * Sets the print settings for @op. This is typically used to
 * re-establish print settings from a previous print operation,
 * see gtk_print_operation_run().
 *
 * Since: 2.10
 **/
void
gtk_print_operation_set_print_settings (GtkPrintOperation *op,
					GtkPrintSettings  *print_settings)
{
1204 1205
  GtkPrintOperationPrivate *priv;

1206 1207 1208 1209
  g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
  g_return_if_fail (print_settings == NULL || 
                    GTK_IS_PRINT_SETTINGS (print_settings));

1210 1211 1212
  priv = op->priv;

  if (print_settings != priv->print_settings)
1213 1214 1215 1216
    {
      if (print_settings)
        g_object_ref (print_settings);

1217 1218
      if (priv->print_settings)
        g_object_unref (priv->print_settings);
1219
  
1220
      priv->print_settings = print_settings;
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260