2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-06-23 05:58:56 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
#include "print.h"
|
|
|
|
#include "print-settings.h"
|
|
|
|
#include "print-page-layout.h"
|
|
|
|
#include "print-draw-page.h"
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-23 16:46:46 +08:00
|
|
|
|
2006-12-26 21:47:51 +08:00
|
|
|
#define PRINT_PROC_NAME "file-print-gtk"
|
2006-12-26 20:36:43 +08:00
|
|
|
#define PLUG_IN_BINARY "print"
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-12-26 20:36:43 +08:00
|
|
|
|
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
static gboolean print_image (gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
gboolean interactive);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
static void begin_print (GtkPrintOperation *operation,
|
|
|
|
GtkPrintContext *context,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
static void end_print (GtkPrintOperation *operation,
|
|
|
|
GtkPrintContext *context,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
static void draw_page (GtkPrintOperation *print,
|
|
|
|
GtkPrintContext *context,
|
|
|
|
int page_nr,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data);
|
2006-12-29 23:36:54 +08:00
|
|
|
static void print_status_changed (GtkPrintOperation *operation);
|
2006-12-29 22:26:55 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
static GtkWidget * create_custom_widget (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-30 01:58:54 +08:00
|
|
|
|
2006-12-29 22:26:55 +08:00
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
|
|
|
};
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
|
|
|
query (void)
|
|
|
|
{
|
|
|
|
static const GimpParamDef print_args[] =
|
|
|
|
{
|
2006-12-26 20:36:43 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to print" }
|
2006-06-23 05:58:56 +08:00
|
|
|
};
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
gimp_install_procedure (PRINT_PROC_NAME,
|
2006-06-23 16:46:46 +08:00
|
|
|
N_("Print the image"),
|
|
|
|
"Print the image using the GTK+ Print API.",
|
2006-06-23 05:58:56 +08:00
|
|
|
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",
|
|
|
|
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",
|
|
|
|
"2006",
|
|
|
|
N_("_Print..."),
|
2006-12-27 21:46:27 +08:00
|
|
|
"*",
|
2006-06-23 05:58:56 +08:00
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (print_args), 0,
|
|
|
|
print_args, NULL);
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
gimp_plugin_menu_register (PRINT_PROC_NAME, "<Image>/File/Send");
|
|
|
|
gimp_plugin_icon_register (PRINT_PROC_NAME, GIMP_ICON_TYPE_STOCK_ID,
|
2006-06-23 05:58:56 +08:00
|
|
|
(const guint8 *) GTK_STOCK_PRINT);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
|
|
|
{
|
|
|
|
static GimpParam values[2];
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
gint32 image_ID;
|
|
|
|
gint32 drawable_ID;
|
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
2006-12-29 23:36:54 +08:00
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
|
|
|
|
image_ID = param[1].data.d_int32;
|
|
|
|
drawable_ID = param[2].data.d_int32;
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
if (strcmp (name, PRINT_PROC_NAME) == 0)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
|
|
|
|
|
|
|
if (! print_image (image_ID, drawable_ID,
|
|
|
|
run_mode == GIMP_RUN_INTERACTIVE))
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
print_image (gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
gboolean interactive)
|
|
|
|
{
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintOperation *operation = gtk_print_operation_new ();
|
|
|
|
GError *error = NULL;
|
|
|
|
PrintData *data;
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
data = g_new0 (PrintData, 1);
|
2006-12-26 20:36:43 +08:00
|
|
|
|
2006-12-27 07:29:33 +08:00
|
|
|
data->num_pages = 1;
|
|
|
|
data->image_id = image_ID;
|
|
|
|
data->drawable_id = drawable_ID;
|
|
|
|
data->operation = operation;
|
2006-12-29 09:35:08 +08:00
|
|
|
data->unit = gimp_get_default_unit ();
|
2006-06-27 06:48:05 +08:00
|
|
|
gimp_image_get_resolution (data->image_id, &data->xres, &data->yres);
|
|
|
|
|
|
|
|
load_print_settings (data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-12-26 05:03:27 +08:00
|
|
|
g_signal_connect (operation, "begin-print",
|
|
|
|
G_CALLBACK (begin_print),
|
|
|
|
data);
|
|
|
|
g_signal_connect (operation, "draw-page",
|
|
|
|
G_CALLBACK (draw_page),
|
|
|
|
data);
|
|
|
|
g_signal_connect (operation, "end-print",
|
|
|
|
G_CALLBACK (end_print),
|
|
|
|
data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
if (interactive)
|
|
|
|
{
|
2006-12-26 20:36:43 +08:00
|
|
|
GtkPrintOperationResult result;
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
g_signal_connect (operation, "create-custom-widget",
|
2006-12-26 05:03:27 +08:00
|
|
|
G_CALLBACK (create_custom_widget),
|
|
|
|
data);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2006-12-27 21:46:27 +08:00
|
|
|
gtk_print_operation_set_custom_tab_label (operation, _("Image"));
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2006-12-29 23:36:54 +08:00
|
|
|
g_signal_connect (operation, "status-changed",
|
|
|
|
G_CALLBACK (print_status_changed),
|
2006-12-29 22:26:55 +08:00
|
|
|
&result);
|
|
|
|
|
2006-12-26 20:36:43 +08:00
|
|
|
result = gtk_print_operation_run (operation,
|
|
|
|
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
|
|
|
NULL, &error);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-12-26 20:36:43 +08:00
|
|
|
switch (result)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2006-12-26 20:36:43 +08:00
|
|
|
case GTK_PRINT_OPERATION_RESULT_APPLY:
|
2006-12-29 22:26:55 +08:00
|
|
|
case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
|
2006-12-29 23:36:54 +08:00
|
|
|
save_print_settings (data);
|
2006-12-29 22:26:55 +08:00
|
|
|
break;
|
|
|
|
|
2006-12-26 20:36:43 +08:00
|
|
|
case GTK_PRINT_OPERATION_RESULT_ERROR:
|
|
|
|
case GTK_PRINT_OPERATION_RESULT_CANCEL:
|
|
|
|
break;
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-12-26 05:03:27 +08:00
|
|
|
{
|
|
|
|
gtk_print_operation_run (operation,
|
|
|
|
GTK_PRINT_OPERATION_ACTION_PRINT,
|
|
|
|
NULL, &error);
|
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
g_object_unref (operation);
|
|
|
|
|
|
|
|
if (error)
|
2006-12-26 20:36:43 +08:00
|
|
|
{
|
2006-12-30 22:08:33 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (NULL, 0,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
_("An error occurred while trying to print:"));
|
|
|
|
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
error->message);
|
2006-12-26 20:36:43 +08:00
|
|
|
g_error_free (error);
|
2006-12-30 22:08:33 +08:00
|
|
|
|
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
|
|
|
|
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
2006-12-26 20:36:43 +08:00
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
begin_print (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintContext *context,
|
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
|
|
|
data->num_pages = 1;
|
2006-12-26 05:03:27 +08:00
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
gtk_print_operation_set_n_pages (operation, data->num_pages);
|
2006-12-27 21:46:27 +08:00
|
|
|
|
|
|
|
gimp_progress_init (_("Printing"));
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
end_print (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintContext *context,
|
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2006-12-27 21:46:27 +08:00
|
|
|
gimp_progress_update (1.0);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
2006-12-29 22:26:55 +08:00
|
|
|
static void
|
2006-12-29 23:36:54 +08:00
|
|
|
print_status_changed (GtkPrintOperation *operation)
|
2006-12-29 22:26:55 +08:00
|
|
|
{
|
2006-12-29 23:36:54 +08:00
|
|
|
const gchar *status = gtk_print_operation_get_status_string (operation);
|
|
|
|
|
|
|
|
if (status && strlen (status))
|
|
|
|
{
|
|
|
|
/* display status of the print operation in the status bar */
|
|
|
|
gimp_progress_set_text_printf (_("Print: %s"), status);
|
|
|
|
}
|
2006-12-29 22:26:55 +08:00
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
draw_page (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintContext *context,
|
|
|
|
int page_nr,
|
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2006-06-27 06:48:05 +08:00
|
|
|
draw_page_cairo (context, data);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
/*
|
|
|
|
* This callback creates a "custom" widget that gets inserted into the
|
|
|
|
* print operation dialog.
|
|
|
|
*/
|
|
|
|
static GtkWidget *
|
|
|
|
create_custom_widget (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2006-12-26 05:03:27 +08:00
|
|
|
return print_page_layout_gui (data);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|