Commit 1a1aead8 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

Add the screenshot key with default to the print screen key ("Print"). The

Wed May 30 22:56:57 2001  George Lebl <jirka@5z.com>

	* gnome-panel-properties.c, gnome-panel-screenshot.(c|glade|glade.h),
	  Makefile.am, session.c, global-keys.c, panel_config_global.h:  Add
	  the screenshot key with default to the print screen key ("Print").
	  The screenshot program was written by Jonathan Blandford
	  <jrb@redhat.com> and it rocks!  The printing stuff is now disabled
	  pending come more configure foo to detect and optionally link with
	  gnome-print.
parent d4530e1d
......@@ -19,6 +19,7 @@ gnome-panel-impl.c
gnome-panel-skelimpl.c
gnome-panel-properties-capplet
gnome-panel-add-launcher
gnome-panel-screenshot
bad-applet
my_gnome_panel_idl
gwmh.c
......
Wed May 30 22:56:57 2001 George Lebl <jirka@5z.com>
* gnome-panel-properties.c, gnome-panel-screenshot.(c|glade|glade.h),
Makefile.am, session.c, global-keys.c, panel_config_global.h: Add
the screenshot key with default to the print screen key ("Print").
The screenshot program was written by Jonathan Blandford
<jrb@redhat.com> and it rocks! The printing stuff is now disabled
pending come more configure foo to detect and optionally link with
gnome-print.
Tue May 29 19:23:10 2001 George Lebl <jirka@5z.com>
* gnome-run.c: load pixmaps correctly, when loading icon from dentry
......
Wed May 30 22:56:57 2001 George Lebl <jirka@5z.com>
* gnome-panel-properties.c, gnome-panel-screenshot.(c|glade|glade.h),
Makefile.am, session.c, global-keys.c, panel_config_global.h: Add
the screenshot key with default to the print screen key ("Print").
The screenshot program was written by Jonathan Blandford
<jrb@redhat.com> and it rocks! The printing stuff is now disabled
pending come more configure foo to detect and optionally link with
gnome-print.
Tue May 29 19:23:10 2001 George Lebl <jirka@5z.com>
* gnome-run.c: load pixmaps correctly, when loading icon from dentry
......
......@@ -16,10 +16,12 @@ INCLUDES = \
-I$(top_builddir)/panel \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-DGNOME_DATADIR=\""$(datadir)"\" \
-DGLADEDIR=\""$(datadir)/gnome/panel"\" \
-DGLOBAL_CONFDIR=\""$(sysconfdir)/gnome/panel-config"\" \
-I$(includedir) \
$(GNOME_INCLUDEDIR) \
$(ORB_CFLAGS) \
@GLADE_CFLAGS@ \
@PIXBUF_CFLAGS@
gwmh_dir = $(top_srcdir)/applets/desk-guide
......@@ -27,7 +29,8 @@ gwmh_dir = $(top_srcdir)/applets/desk-guide
bin_PROGRAMS = \
panel \
gnome-panel-properties-capplet \
gnome-panel-add-launcher
gnome-panel-add-launcher \
gnome-panel-screenshot
noinst_PROGRAMS = bad-applet
......@@ -212,6 +215,9 @@ gnome_panel_add_launcher_SOURCES = \
gnome-panel-add-launcher.c \
$(CORBA_SRCLIST)
gnome_panel_screenshot_SOURCES = \
gnome-panel-screenshot.c
gnome_panel_add_launcher_LDADD = \
$(GNOME_LIBDIR) \
$(GNOMEUI_LIBS) \
......@@ -220,6 +226,14 @@ gnome_panel_add_launcher_LDADD = \
$(INTLLIBS) \
@PIXBUF_LIBS@
gnome_panel_screenshot_LDADD = \
$(GNOME_LIBDIR) \
$(GNOMEUI_LIBS) \
@GLADE_LIBS@ \
$(INTLLIBS) \
@PNG_LIBS@ \
@PIXBUF_LIBS@
MAINTAINERCLEANFILES = $(CORBA_SRCLIST)
EXTRA_DIST = \
......@@ -231,7 +245,9 @@ EXTRA_DIST = \
panel.hints \
gnome-panel-properties.desktop \
nothing.cP \
title-item.gob
title-item.gob \
gnome-panel-screenshot.glade \
gnome-panel-screenshot.glade.h
## Put `exec' in the name because this should be installed by
## `install-exec', not `install-data'.
......@@ -266,6 +282,9 @@ panelgnorba_DATA = panel.gnorba
soundlistdir = $(sysconfdir)/sound/events
soundlist_DATA = panel.soundlist
gladedir = $(datadir)/gnome/panel
glade_DATA =gnome-panel-screenshot.glade
hintsdir = $(datadir)/gnome/hints
hints_DATA = panel.hints
......
......@@ -30,6 +30,7 @@ menu_flags=-1
keys_enabled=true
menu_key=Mod1-F1
run_key=Mod1-F2
screenshot_key=Print
fast_button_scaling=false
avoid_collisions=true
new_tiles_enabled_0=false
......
......@@ -101,42 +101,85 @@ panel_global_keys_setup (void)
static guint laststate_menu = 0;
static guint lastkey_run = 0;
static guint laststate_run = 0;
gboolean same;
static guint lastkey_screenshot = 0;
static guint laststate_screenshot = 0;
same = (lastkey_menu == lastkey_run &&
laststate_menu == laststate_run);
/* FIXME: the if trees are horrible, this shoul dbe cleaned up with
* lists or something */
gdk_error_trap_push();
if (lastkey_menu)
if (lastkey_menu != 0) {
ungrab_key (laststate_menu, lastkey_menu);
if (lastkey_run && !same)
}
if (lastkey_run != 0 &&
(lastkey_menu != lastkey_run ||
laststate_menu != laststate_run)) {
ungrab_key (laststate_run, lastkey_run);
}
if (lastkey_run != 0 &&
(lastkey_menu != lastkey_screenshot ||
laststate_menu != laststate_screenshot) &&
(lastkey_run != lastkey_screenshot ||
laststate_run != laststate_screenshot)) {
ungrab_key (laststate_screenshot, lastkey_screenshot);
}
if (global_config.keys_enabled &&
global_config.menu_keysym) {
lastkey_menu = XKeysymToKeycode(GDK_DISPLAY(),
global_config.menu_keysym);
laststate_menu = global_config.menu_state;
if(lastkey_menu)
grab_key (laststate_menu, lastkey_menu);
} else
if (lastkey_menu != 0)
grab_key (laststate_menu, lastkey_menu);
} else {
lastkey_menu = 0;
}
if (global_config.keys_enabled &&
global_config.run_keysym) {
lastkey_run = XKeysymToKeycode(GDK_DISPLAY(),
lastkey_run = XKeysymToKeycode (GDK_DISPLAY (),
global_config.run_keysym);
laststate_run = global_config.run_state;
if(lastkey_run &&
(lastkey_menu != lastkey_run ||
laststate_menu != laststate_run))
if (lastkey_run != 0 &&
(lastkey_menu != lastkey_run ||
laststate_menu != laststate_run))
grab_key (laststate_run, lastkey_run);
} else
} else {
lastkey_run = 0;
}
if (global_config.keys_enabled &&
global_config.screenshot_keysym) {
lastkey_screenshot = XKeysymToKeycode
(GDK_DISPLAY (), global_config.screenshot_keysym);
laststate_screenshot = global_config.screenshot_state;
if (lastkey_screenshot != 0 &&
(lastkey_menu != lastkey_screenshot ||
laststate_menu != laststate_screenshot) &&
(lastkey_run != lastkey_screenshot ||
laststate_run != laststate_screenshot))
grab_key (laststate_screenshot, lastkey_screenshot);
} else {
lastkey_screenshot = 0;
}
gdk_flush ();
gdk_error_trap_pop();
}
static gboolean
check_for_grabs (void)
{
if (gdk_pointer_grab (GDK_ROOT_PARENT(), FALSE,
0, NULL, NULL, GDK_CURRENT_TIME)
!= GrabSuccess) {
return TRUE;
} else {
gdk_pointer_ungrab (GDK_CURRENT_TIME);
return FALSE;
}
}
GdkFilterReturn
panel_global_keys_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
......@@ -146,6 +189,7 @@ panel_global_keys_filter (GdkXEvent *gdk_xevent,
guint keycode, state;
guint menu_keycode, menu_state;
guint run_keycode, run_state;
guint screenshot_keycode, screenshot_state;
if(xevent->type != KeyPress)
return GDK_FILTER_CONTINUE;
......@@ -161,17 +205,17 @@ panel_global_keys_filter (GdkXEvent *gdk_xevent,
global_config.run_keysym);
run_state = global_config.run_state;
screenshot_keycode = XKeysymToKeycode (GDK_DISPLAY (),
global_config.screenshot_keysym);
screenshot_state = global_config.screenshot_state;
if (keycode == menu_keycode &&
(state & menu_state) == menu_state) {
PanelWidget *panel;
GtkWidget *menu, *basep;
/* check if anybody else has a grab */
if (gdk_pointer_grab (GDK_ROOT_PARENT(), FALSE,
0, NULL, NULL, GDK_CURRENT_TIME)
!= GrabSuccess) {
if (check_for_grabs ()) {
return GDK_FILTER_CONTINUE;
} else {
gdk_pointer_ungrab (GDK_CURRENT_TIME);
}
panel = panels->data;
......@@ -187,15 +231,37 @@ panel_global_keys_filter (GdkXEvent *gdk_xevent,
} else if (keycode == run_keycode &&
(state & run_state) == run_state) {
/* check if anybody else has a grab */
if (gdk_pointer_grab (GDK_ROOT_PARENT(), FALSE,
0, NULL, NULL, GDK_CURRENT_TIME)
!= GrabSuccess) {
if (check_for_grabs ()) {
return GDK_FILTER_CONTINUE;
} else {
gdk_pointer_ungrab (GDK_CURRENT_TIME);
}
show_run_dialog ();
return GDK_FILTER_REMOVE;
} else if (keycode == screenshot_keycode &&
(state & run_state) == screenshot_state) {
char *argv[2];
char *proggie;
/* check if anybody else has a grab */
if (check_for_grabs ()) {
return GDK_FILTER_CONTINUE;
}
proggie = gnome_is_program_in_path ("gnome-panel-screenshot");
if (proggie == NULL) {
panel_error_dialog (_("Can't find the screenshot "
"program"));
return GDK_FILTER_REMOVE;
}
argv[0] = proggie;
argv[1] = NULL;
if (gnome_execute_async (g_get_home_dir (), 1, argv)<0)
panel_error_dialog (_("Can't execute the screenshot "
"program"));
g_free (proggie);
return GDK_FILTER_REMOVE;
}
......
......@@ -138,6 +138,7 @@ static GtkWidget *normal_layer_cb;
static GtkWidget *keys_enabled_cb;
static GtkWidget *menu_key_entry;
static GtkWidget *run_key_entry;
static GtkWidget *screenshot_key_entry;
static GtkWidget *confirm_panel_remove_cb;
static GtkWidget *avoid_collisions_cb;
......@@ -194,6 +195,7 @@ set_config (GlobalConfig *dest, GlobalConfig *src)
}
g_free (dest->menu_key);
g_free (dest->run_key);
g_free (dest->screenshot_key);
*dest = *src;
......@@ -203,6 +205,7 @@ set_config (GlobalConfig *dest, GlobalConfig *src)
}
dest->menu_key = g_strdup (dest->menu_key);
dest->run_key = g_strdup (dest->run_key);
dest->screenshot_key = g_strdup (dest->screenshot_key);
}
......@@ -923,9 +926,11 @@ sync_misc_page_with_config(GlobalConfig *conf)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (keys_enabled_cb),
conf->keys_enabled);
gtk_entry_set_text (GTK_ENTRY (menu_key_entry),
conf->menu_key ? conf->menu_key : "");
sure_string (conf->menu_key));
gtk_entry_set_text (GTK_ENTRY (run_key_entry),
conf->run_key ? conf->run_key : "");
sure_string (conf->run_key));
gtk_entry_set_text (GTK_ENTRY (screenshot_key_entry),
sure_string (conf->screenshot_key));
}
static void
......@@ -953,6 +958,9 @@ sync_config_with_misc_page(GlobalConfig *conf)
g_free (conf->run_key);
conf->run_key =
g_strdup (gtk_entry_get_text (GTK_ENTRY (run_key_entry)));
g_free (conf->screenshot_key);
conf->screenshot_key =
g_strdup (gtk_entry_get_text (GTK_ENTRY (screenshot_key_entry)));
}
static GtkWidget *grab_dialog;
......@@ -1216,6 +1224,32 @@ misc_notebook_page(void)
GTK_SIGNAL_FUNC (grab_button_pressed),
run_key_entry);
/* screenshot key...*/
w = gtk_label_new (_("Take screenshot key"));
gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), w, 0, 1, 3, 4,
GTK_FILL, GTK_FILL, 0, 0);
list = g_list_append(NULL, "Print");
list = g_list_append(list, "Control-Mod1-s");
list = g_list_append(list, "Control-Mod1-p");
list = g_list_append(list, _("Disabled"));
w = gtk_combo_new();
gtk_combo_set_popdown_strings(GTK_COMBO(w), list);
g_list_free(list);
screenshot_key_entry = GTK_COMBO(w)->entry;
gtk_signal_connect (GTK_OBJECT (screenshot_key_entry),
"changed",
GTK_SIGNAL_FUNC (changed_cb), NULL);
/*gtk_widget_set_sensitive (screenshot_key_entry, FALSE);*/
gtk_table_attach_defaults (GTK_TABLE (table), w, 1, 2, 3, 4);
w = gtk_button_new_with_label (_("Grab key..."));
gtk_table_attach (GTK_TABLE (table), w, 2, 3, 3, 4,
GTK_FILL, GTK_FILL, 0, 0);
gtk_signal_connect (GTK_OBJECT (w), "clicked",
GTK_SIGNAL_FUNC (grab_button_pressed),
screenshot_key_entry);
return (vbox);
}
......@@ -1337,6 +1371,15 @@ loadup_vals (void)
&global_config.run_keysym,
&global_config.run_state);
g_free(global_config.screenshot_key);
global_config.screenshot_key =
conditional_get_string ("screenshot_key", "Print",
NULL);
convert_string_to_keysym_state(global_config.screenshot_key,
&global_config.screenshot_keysym,
&global_config.screenshot_state);
global_config.applet_padding =
conditional_get_int ("applet_padding", 3, NULL);
......@@ -1511,6 +1554,7 @@ write_config (GlobalConfig *conf)
gnome_config_set_bool("keys_enabled", conf->keys_enabled);
gnome_config_set_string("menu_key", conf->menu_key);
gnome_config_set_string("run_key", conf->run_key);
gnome_config_set_string("screenshot_key", conf->screenshot_key);
gnome_config_set_bool("fast_button_scaling", conf->fast_button_scaling);
buf = g_string_new(NULL);
......
......@@ -138,6 +138,7 @@ static GtkWidget *normal_layer_cb;
static GtkWidget *keys_enabled_cb;
static GtkWidget *menu_key_entry;
static GtkWidget *run_key_entry;
static GtkWidget *screenshot_key_entry;
static GtkWidget *confirm_panel_remove_cb;
static GtkWidget *avoid_collisions_cb;
......@@ -194,6 +195,7 @@ set_config (GlobalConfig *dest, GlobalConfig *src)
}
g_free (dest->menu_key);
g_free (dest->run_key);
g_free (dest->screenshot_key);
*dest = *src;
......@@ -203,6 +205,7 @@ set_config (GlobalConfig *dest, GlobalConfig *src)
}
dest->menu_key = g_strdup (dest->menu_key);
dest->run_key = g_strdup (dest->run_key);
dest->screenshot_key = g_strdup (dest->screenshot_key);
}
......@@ -923,9 +926,11 @@ sync_misc_page_with_config(GlobalConfig *conf)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (keys_enabled_cb),
conf->keys_enabled);
gtk_entry_set_text (GTK_ENTRY (menu_key_entry),
conf->menu_key ? conf->menu_key : "");
sure_string (conf->menu_key));
gtk_entry_set_text (GTK_ENTRY (run_key_entry),
conf->run_key ? conf->run_key : "");
sure_string (conf->run_key));
gtk_entry_set_text (GTK_ENTRY (screenshot_key_entry),
sure_string (conf->screenshot_key));
}
static void
......@@ -953,6 +958,9 @@ sync_config_with_misc_page(GlobalConfig *conf)
g_free (conf->run_key);
conf->run_key =
g_strdup (gtk_entry_get_text (GTK_ENTRY (run_key_entry)));
g_free (conf->screenshot_key);
conf->screenshot_key =
g_strdup (gtk_entry_get_text (GTK_ENTRY (screenshot_key_entry)));
}
static GtkWidget *grab_dialog;
......@@ -1216,6 +1224,32 @@ misc_notebook_page(void)
GTK_SIGNAL_FUNC (grab_button_pressed),
run_key_entry);
/* screenshot key...*/
w = gtk_label_new (_("Take screenshot key"));
gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), w, 0, 1, 3, 4,
GTK_FILL, GTK_FILL, 0, 0);
list = g_list_append(NULL, "Print");
list = g_list_append(list, "Control-Mod1-s");
list = g_list_append(list, "Control-Mod1-p");
list = g_list_append(list, _("Disabled"));
w = gtk_combo_new();
gtk_combo_set_popdown_strings(GTK_COMBO(w), list);
g_list_free(list);
screenshot_key_entry = GTK_COMBO(w)->entry;
gtk_signal_connect (GTK_OBJECT (screenshot_key_entry),
"changed",
GTK_SIGNAL_FUNC (changed_cb), NULL);
/*gtk_widget_set_sensitive (screenshot_key_entry, FALSE);*/
gtk_table_attach_defaults (GTK_TABLE (table), w, 1, 2, 3, 4);
w = gtk_button_new_with_label (_("Grab key..."));
gtk_table_attach (GTK_TABLE (table), w, 2, 3, 3, 4,
GTK_FILL, GTK_FILL, 0, 0);
gtk_signal_connect (GTK_OBJECT (w), "clicked",
GTK_SIGNAL_FUNC (grab_button_pressed),
screenshot_key_entry);
return (vbox);
}
......@@ -1337,6 +1371,15 @@ loadup_vals (void)
&global_config.run_keysym,
&global_config.run_state);
g_free(global_config.screenshot_key);
global_config.screenshot_key =
conditional_get_string ("screenshot_key", "Print",
NULL);
convert_string_to_keysym_state(global_config.screenshot_key,
&global_config.screenshot_keysym,
&global_config.screenshot_state);
global_config.applet_padding =
conditional_get_int ("applet_padding", 3, NULL);
......@@ -1511,6 +1554,7 @@ write_config (GlobalConfig *conf)
gnome_config_set_bool("keys_enabled", conf->keys_enabled);
gnome_config_set_string("menu_key", conf->menu_key);
gnome_config_set_string("run_key", conf->run_key);
gnome_config_set_string("screenshot_key", conf->screenshot_key);
gnome_config_set_bool("fast_button_scaling", conf->fast_button_scaling);
buf = g_string_new(NULL);
......
/* simple-screenshot.c */
/* Copyright (C) 2001 Jonathan Blandford <jrb@alum.mit.edu>
*
* 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
*/
/* FIXME: currently undone things */
#undef HAVE_PAPER_WIDTH
#undef HAVE_GNOME_PRINT
/* THERE ARE NO FEATURE REQUESTS ALLOWED */
/* IF YOU WANT YOUR OWN FEATURE -- WRITE THE DAMN THING YOURSELF (-:*/
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkx.h>
#include <png.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_GNOME_PRINT
#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-master.h>
#include <libgnomeprint/gnome-print-preview.h>
#include <libgnomeprint/gnome-print-dialog.h>
#include <libgnomeprint/gnome-print-master-preview.h>
#endif
#include <X11/cursorfont.h>
#include <libart_lgpl/art_rgb_affine.h>
#ifdef HAVE_PAPER_WIDTH
#include <stdio.h>
#include <locale.h>
#include <langinfo.h>
#endif
static GladeXML *xml = NULL;
static GtkWidget *toplevel;
static GdkPixbuf *screenshot = NULL;
static GdkPixbuf *preview_image = NULL;
static gchar *web_dir;
static gchar *desktop_dir;
static gchar *home_dir;
/* some prototypes for the glade autoconnecting sutff */
void on_save_rbutton_toggled (GtkWidget *toggle, gpointer data);
void on_preview_expose_event (GtkWidget *drawing_area,
GdkEventExpose *event,
gpointer data);
void on_preview_configure_event (GtkWidget *drawing_area,
GdkEventConfigure *event,
gpointer data);
void on_ok_button_clicked (GtkWidget *widget, gpointer data);
void on_cancel_button_clicked (GtkWidget *widget, gpointer data);
int on_toplevel_key_press_event (GtkWidget *widget, GdkEventKey *key);
/* helper functions */
/* This code is copied from gdk-pixbuf-HEAD. It does no memory management and
* is very hard-coded. Please do not use it anywhere else. */
static gboolean
save_to_file (gchar *file)
{
FILE *f = NULL;
png_structp png_ptr;
png_infop info_ptr;
guchar *ptr;
guchar *pixels;
int x, y, j;
png_bytep row_ptr, data = NULL;
png_color_8 sig_bit;
int w, h, rowstride;
int has_alpha;
int bpc;
gchar *error = NULL;
GtkWidget *dialog;
f = fopen (file, "w");
if (f == NULL) {
error = g_strdup_printf (_("Unable to create the file:\n"
"\"%s\"\n"
"Please check your permissions of "
"the parent directory"), file);
goto handle_error;
}
bpc = gdk_pixbuf_get_bits_per_sample (screenshot);
w = gdk_pixbuf_get_width (screenshot);
h = gdk_pixbuf_get_height (screenshot);
rowstride = gdk_pixbuf_get_rowstride (screenshot);
has_alpha = gdk_pixbuf_get_has_alpha (screenshot);
pixels = gdk_pixbuf_get_pixels (screenshot);
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (png_ptr == NULL) {
error = _("Unable to initialize png structure.\n"
"You probably have a bad version of libpng "
"on your system");
goto handle_error;
}
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
error = _("Unable to create png info.\n"
"You probably have a bad version of libpng "
"on your system");
goto handle_error;
}
if (setjmp (png_ptr->jmpbuf)) {
error = _("Unable to set png info.\n"
"You probably have a bad version of libpng "
"on your system");
goto handle_error;
}
png_init_io (png_ptr, f);
png_set_IHDR (png_ptr, info_ptr, w, h, bpc,
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
data = malloc (w * 3 * sizeof (char));
if (data == NULL) {
fclose (f);
unlink (file);
error = _("Insufficient memory to save the screenshot.\n"
"Please free up some resources and try again.");
goto handle_error;
}
sig_bit.red = bpc;
sig_bit.green = bpc;
sig_bit.blue = bpc;
sig_bit.alpha = bpc;
png_set_sBIT (png_ptr, info_ptr, &sig_bit);
png_write_info (png_ptr, info_ptr);
png_set_shift (png_ptr, &sig_bit);
png_set_packing (png_ptr);
ptr = pixels;
for (y = 0; y < h; y++) {
for (j = 0, x = 0; x < w; x++)
memcpy (&(data[x*3]), &(ptr[x*3]), 3);
row_ptr = (png_bytep)data;
png_write_rows (png_ptr, &row_ptr, 1);
ptr += rowstride;
}
if (data)
free (data);
png_write_end (png_ptr, info_ptr);
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
fclose (f);
return TRUE;
handle_error:
dialog = gnome_error_dialog_parented (error, GTK_WINDOW (toplevel));
gnome_dialog_run (GNOME_DIALOG (dialog));
return FALSE;
}
#ifdef HAVE_GNOME_PRINT
static GdkPixbuf *
rotate_image (GdkPixbuf *image)
{
GdkPixbuf *retval;
double affine[6];
gint width, height;
width = gdk_pixbuf_get_width (image);
height = gdk_pixbuf_get_height (image);
retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, height, width);
affine[0] = 0.0; /* = cos(90) */
affine[2] = 1.0; /* = sin(90) */
affine[3] = 0.0; /* = cos(90) */
affine[1] = -1.0; /* = -sin(90) */
affine[4] = 0; /* x translation */
affine[5] = width; /* y translation */
art_rgb_affine (gdk_pixbuf_get_pixels (retval),
0, 0,
height, width,
gdk_pixbuf_get_rowstride (retval),
gdk_pixbuf_get_pixels (image),
width, height,
gdk_pixbuf_get_rowstride (image),
affine,
ART_FILTER_NEAREST,
NULL);
return retval;
}
#endif
#ifdef HAVE_GNOME_PRINT
static void
print_page (GnomePrintContext *context, const GnomePaper *paper)
{
GdkPixbuf *printed_image;
gint real_width = gnome_paper_pswidth (paper);
gint real_height = gnome_paper_psheight (paper);
gint pix_width;
gint pix_height;
gint width, height;
/* always make sure that it is taller then wide, under the potentially
* mistaken assumption that all paper is this way too. */
if (gdk_pixbuf_get_width (screenshot) > gdk_pixbuf_get_height (screenshot)) {
printed_image = rotate_image (screenshot);
} else {
gdk_pixbuf_ref (screenshot);
printed_image = screenshot;
}
pix_width = gdk_pixbuf_get_width (printed_image);
pix_height = gdk_pixbuf_get_height (printed_image);
width = real_width - 2 * gnome_paper_tmargin (paper);
height = real_height - 2 * gnome_paper_rmargin (paper);