1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 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 237 238 239 240 241 242 243 244 245 246
|
/* Hey EMACS -*- linux-c -*- */
/* $Id: screenshot.c 3976 2007-11-05 13:08:26Z roms $ */
/* TiLP - Tilp Is a Linking Program
* Copyright (C) 1999-2006 Romain Lievin
*
* 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.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* */
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <string.h>
#include "support.h"
#include "screenshot.h"
#include "support.h"
#include "dboxes.h"
#include "scroptions.h"
#include "filesel.h"
#include "tilp_core.h"
GtkWidget *scrn_win;
static GtkWidget *scrn_img;
gint display_screenshot_dbox()
{
GladeXML *xml;
GdkPixbuf *pixbuf;
xml = glade_xml_new(tilp_paths_build_glade("screenshot-2.glade"), "screenshot_dbox", PACKAGE);
if (!xml)
g_error("GUI loading failed !\n");
glade_xml_signal_autoconnect(xml);
scrn_win = glade_xml_get_widget(xml, "screenshot_dbox");
scrn_img = glade_xml_get_widget(xml, "pixmap7");
pixbuf = create_pixbuf("screendump.png");
gtk_image_set_from_pixbuf(GTK_IMAGE(scrn_img), pixbuf);
g_object_unref(pixbuf);
gtk_widget_show_all(scrn_win);
return 0;
}
GLADE_CB void on_sc_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
const gchar *filename;
GdkPixbuf *pixbuf;
GError *error = NULL;
filename = create_fsel(local.cwdir, NULL, "*.jpg;*.png;*.xpm;*.bmp", FALSE);
if (!filename)
return;
pixbuf = gdk_pixbuf_new_from_file(filename, &error);
if (!pixbuf)
{
tilp_warning("Failed to load pixbuf file: %s: %s\n",
filename, error->message);
g_error_free(error);
}
gtk_image_set_from_pixbuf(GTK_IMAGE(scrn_img), pixbuf);
g_object_unref(pixbuf);
}
static gboolean screen_success = FALSE;
GLADE_CB void on_sc_save1_activate(GtkMenuItem * menuitem,
gpointer user_data)
{
GdkPixbuf *pixbuf;
gboolean result = FALSE;
GError *error = NULL;
gchar *type;
const gchar *filename = NULL;
if(screen_success == FALSE)
return;
switch (options.screen_format)
{
case XPM:
type = "xpm";
filename = create_fsel(local.cwdir, "screenshot.xpm", "*.xpm", TRUE);
if (!filename)
return;
pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(scrn_img));
result = gdk_pixbuf_save(pixbuf, filename, type, &error, NULL);
break;
case BMP:
type = "bmp";
filename = create_fsel(local.cwdir, "screenshot.bmp", "*.bmp", TRUE);
if (!filename)
return;
pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(scrn_img));
result = gdk_pixbuf_save(pixbuf, filename, type, &error, NULL);
break;
case JPG:
type = "jpeg";
filename = create_fsel(local.cwdir, "screenshot.jpg", "*.jpg", TRUE);
if (!filename)
return;
pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(scrn_img));
result = gdk_pixbuf_save(pixbuf, filename, type, &error, "quality", "100", NULL);
break;
case PNG:
type = "png";
filename = create_fsel(local.cwdir, "screenshot.png", "*.png", TRUE);
if (!filename)
return;
pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(scrn_img));
result = gdk_pixbuf_save(pixbuf, filename, type, &error, NULL);
break;
case PDF:
type = "pdf";
filename = create_fsel(local.cwdir, "screenshot.pdf", "*.pdf", TRUE);
if (!filename)
return;
result = screen_write_pdf(filename, &error);
break;
case EPS:
type = "eps";
filename = create_fsel(local.cwdir, "screenshot.eps", "*.eps", TRUE);
if (!filename)
return;
result = screen_write_eps(filename, &error);
break;
default:
type = "";
break;
}
if (result == FALSE)
{
tilp_warning("Failed to save pixbuf file: %s: %s\n", filename, error->message);
g_error_free(error);
}
filename = NULL;
}
GLADE_CB void on_sc_quit1_activate(GtkMenuItem * menuitem,
gpointer user_data)
{
gtk_widget_destroy(scrn_win);
}
GLADE_CB void on_sc_options1_activate(GtkMenuItem * menuitem,
gpointer user_data)
{
display_scroptions_dbox();
}
static void destroy_pixbuf(guchar * pixels, gpointer data)
{
g_free(pixels);
}
extern void on_manual1_activate(GtkMenuItem * menuitem, gpointer user_data);
GLADE_CB void on_scdbox_button1_clicked(GtkButton * button,
gpointer user_data)
{
GdkPixbuf *pixbuf;
guchar *bytemap;
gint w, h;
if (screen_capture())
{
screen_success = FALSE;
return;
}
else
{
screen_success = TRUE;
}
w = screen.width;
h = screen.height;
if(options.calc_model != CALC_NSPIRE)
{
if (options.screen_blurry)
bytemap = screen_bw_blurry();
else
bytemap = screen_bw_convert();
}
else
bytemap = screen_gs_convert();
pixbuf = gdk_pixbuf_new_from_data(bytemap, GDK_COLORSPACE_RGB, FALSE,
8, w, h, 3 * w, destroy_pixbuf, NULL);
gtk_image_set_from_pixbuf(GTK_IMAGE(scrn_img), pixbuf);
g_object_unref(pixbuf);
}
GLADE_CB void on_scdbox_button2_clicked(GtkButton * button,
gpointer user_data)
{
on_sc_save1_activate(NULL, NULL);
}
GLADE_CB void on_scdbox_button3_clicked(GtkButton * button,
gpointer user_data)
{
gtk_widget_destroy(scrn_win);
}
GLADE_CB void on_scdbox_button4_clicked(GtkButton * button, gpointer user_data)
{
on_manual1_activate(NULL, NULL);
}
GLADE_CB void on_scdbox_button5_clicked(GtkButton * button, gpointer user_data)
{
GdkPixbuf *pixbuf;
GtkClipboard *clipboard;
pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(scrn_img));
clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_image(clipboard, pixbuf);
}
|