summaryrefslogtreecommitdiff
path: root/src/xsane-front-gtk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xsane-front-gtk.c')
-rw-r--r--src/xsane-front-gtk.c1222
1 files changed, 1002 insertions, 220 deletions
diff --git a/src/xsane-front-gtk.c b/src/xsane-front-gtk.c
index b4373ed..3695db8 100644
--- a/src/xsane-front-gtk.c
+++ b/src/xsane-front-gtk.c
@@ -3,7 +3,7 @@
xsane-front-gtk.c
Oliver Rauch <Oliver.Rauch@rauch-domain.de>
- Copyright (C) 1998-2002 Oliver Rauch
+ Copyright (C) 1998-2005 Oliver Rauch
This file is part of the XSANE package.
This program is free software; you can redistribute it and/or modify
@@ -68,20 +68,22 @@ void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const
char *str_list[], const char *val,
GtkObject **data, int option,
void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
-void xsane_scale_new(GtkBox *parent, char *labeltext, const char *desc,
- float min, float max, float quant, float step, float page_step,
- int digits, double *val, GtkObject **data, void *xsane_scale_callback, SANE_Int settable);
-void xsane_scale_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
- float min, float max, float quant, float step, float page_step, int digits,
- double *val, GtkObject **data, int option, void *xsane_scale_callback, SANE_Int settable);
+void xsane_range_new(GtkBox *parent, char *labeltext, const char *desc,
+ float min, float max, float quant, float page_step,
+ int digits, double *val, GtkObject **data, void *xsane_range_callback, SANE_Int settable);
+void xsane_range_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
+ float min, float max, float quant, float page_step, int digits,
+ double *val, GtkObject **data, int option, void *xsane_range_callback, SANE_Int settable);
+static void xsane_outputfilename_changed_callback(GtkWidget *widget, gpointer data);
+void xsane_set_filename(gchar *filename);
void xsane_separator_new(GtkWidget *xsane_parent, int dist);
+void xsane_vseparator_new(GtkWidget *xsane_parent, int dist);
GtkWidget *xsane_info_table_text_new(GtkWidget *table, gchar *text, int row, int colomn);
GtkWidget *xsane_info_text_new(GtkWidget *parent, gchar *text);
void xsane_refresh_dialog(void);
-void xsane_set_sensitivity(SANE_Int sensitivity);
void xsane_update_param(void *arg);
void xsane_define_output_filename(void);
-int xsane_identify_output_format(char *filename, char **ext);
+int xsane_identify_output_format(char *filename, char *filetype, char **ext);
/* ---------------------------------------------------------------------------------------------------------------------- */
@@ -141,7 +143,7 @@ void xsane_get_bounds(const SANE_Option_Descriptor *opt, double *minp, double *m
case SANE_CONSTRAINT_RANGE:
min = opt->constraint.range->min;
max = opt->constraint.range->max;
- break;
+ break;
case SANE_CONSTRAINT_WORD_LIST:
min = INF;
@@ -333,8 +335,11 @@ int xsane_set_resolution(int well_known_option, double resolution)
return 1; /* error */
}
+ /* it makes problems to call xsane_back_gtk_set_option. This would allow a */
+ /* panel_rebuild that can mess up a lot at this place*/
xsane_control_option(xsane.dev, well_known_option, SANE_ACTION_SET_VALUE, &dpi, 0);
- return 0; /* everything is ok */
+
+ return 0; /* everything is ok */
}
/* ---------------------------------------------------------------------------------------------------------------------- */
@@ -345,15 +350,6 @@ void xsane_set_all_resolutions(void)
DBG(DBG_proc, "xsane_set_all_resolutions\n");
-#if 0
- xsane_set_resolution(xsane.well_known.dpi_y, xsane.resolution_y); /* set y resolution if possible */
- if (xsane_set_resolution(xsane.well_known.dpi_x, xsane.resolution_x)) /* set x resolution if possible */
- {
- xsane_set_resolution(xsane.well_known.dpi, xsane.resolution); /* set common resolution if necessary */
- xsane.resolution_x = xsane.resolution;
- xsane.resolution_y = xsane.resolution;
- }
-#else
if (xsane_set_resolution(xsane.well_known.dpi_y, xsane.resolution_y)) /* set y resolution if possible */
{
xsane_set_resolution(xsane.well_known.dpi, xsane.resolution); /* set common resolution if necessary */
@@ -364,7 +360,6 @@ void xsane_set_all_resolutions(void)
{
xsane_set_resolution(xsane.well_known.dpi_x, xsane.resolution_x); /* set x resolution if possible */
}
-#endif
switch (xsane.param.format)
{
@@ -377,7 +372,7 @@ void xsane_set_all_resolutions(void)
{
printer_resolution = preferences.printer[preferences.printernr]->grayscale_resolution;
}
- break;
+ break;
case SANE_FRAME_RGB:
case SANE_FRAME_RED:
@@ -385,7 +380,7 @@ void xsane_set_all_resolutions(void)
case SANE_FRAME_BLUE:
default:
printer_resolution = preferences.printer[preferences.printernr]->color_resolution;
- break;
+ break;
}
xsane.zoom = xsane.resolution / printer_resolution;
@@ -410,45 +405,47 @@ void xsane_define_maximum_output_size()
case XSANE_SAVE:
xsane_define_output_filename();
- xsane.xsane_output_format = xsane_identify_output_format(xsane.output_filename, 0);
+ xsane.xsane_output_format = xsane_identify_output_format(xsane.output_filename, preferences.filetype, 0);
- preview_set_maximum_output_size(xsane.preview, INF, INF);
+ preview_set_maximum_output_size(xsane.preview, INF, INF, 0);
break;
case XSANE_VIEWER:
- preview_set_maximum_output_size(xsane.preview, INF, INF);
+ preview_set_maximum_output_size(xsane.preview, INF, INF, 0);
break;
case XSANE_COPY:
- if (preferences.psrotate) /* rotate: landscape */
+ if (preferences.paper_orientation >= 8) /* rotate: landscape */
{
preview_set_maximum_output_size(xsane.preview,
preferences.printer[preferences.printernr]->height / xsane.zoom_y,
- preferences.printer[preferences.printernr]->width / xsane.zoom_x);
+ preferences.printer[preferences.printernr]->width / xsane.zoom_x,
+ preferences.paper_orientation);
}
else /* do not rotate: portrait */
{
preview_set_maximum_output_size(xsane.preview,
preferences.printer[preferences.printernr]->width / xsane.zoom_x,
- preferences.printer[preferences.printernr]->height / xsane.zoom_y);
+ preferences.printer[preferences.printernr]->height / xsane.zoom_y,
+ preferences.paper_orientation);
}
break;
case XSANE_FAX:
- preview_set_maximum_output_size(xsane.preview, preferences.fax_width, preferences.fax_height);
+ preview_set_maximum_output_size(xsane.preview, preferences.fax_width, preferences.fax_height, 0);
break;
case XSANE_MAIL:
- preview_set_maximum_output_size(xsane.preview, INF, INF);
+ preview_set_maximum_output_size(xsane.preview, INF, INF, 0);
break;
default:
- preview_set_maximum_output_size(xsane.preview, INF, INF);
+ preview_set_maximum_output_size(xsane.preview, INF, INF, 0);
}
}
else
{
- preview_set_maximum_output_size(xsane.preview, INF, INF);
+ preview_set_maximum_output_size(xsane.preview, INF, INF, 0);
}
}
@@ -483,7 +480,7 @@ gint xsane_authorization_callback(SANE_String_Const resource,
GtkWidget *authorize_dialog, *vbox, *hbox, *button, *label;
GtkWidget *username_widget, *password_widget;
char buf[SANE_MAX_PASSWORD_LEN+SANE_MAX_USERNAME_LEN+128];
- char *input;
+ const gchar *input;
char *resource_string;
int len;
int resource_len;
@@ -586,11 +583,10 @@ gint xsane_authorization_callback(SANE_String_Const resource,
if (query_user)
{
- authorize_dialog = gtk_window_new(GTK_WINDOW_DIALOG);
+ authorize_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(authorize_dialog), GTK_WIN_POS_CENTER);
- gtk_window_set_policy(GTK_WINDOW(authorize_dialog), FALSE, FALSE, FALSE);
- gtk_signal_connect(GTK_OBJECT(authorize_dialog), "delete_event",
- GTK_SIGNAL_FUNC(xsane_authorization_button_callback), (void *) -1); /* -1 = cancel */
+ gtk_window_set_resizable(GTK_WINDOW(authorize_dialog), FALSE);
+ g_signal_connect(GTK_OBJECT(authorize_dialog), "delete_event", GTK_SIGNAL_FUNC(xsane_authorization_button_callback), (void *) -1); /* -1 = cancel */
snprintf(buf, sizeof(buf), "%s %s", xsane.prog_name, WINDOW_AUTHORIZE);
gtk_window_set_title(GTK_WINDOW(authorize_dialog), buf);
xsane_set_window_icon(authorize_dialog, 0);
@@ -627,7 +623,7 @@ gint xsane_authorization_callback(SANE_String_Const resource,
gtk_widget_show(label);
username_widget = gtk_entry_new_with_max_length(SANE_MAX_USERNAME_LEN-1);
- gtk_widget_set_usize(username_widget, 250, 0);
+ gtk_widget_set_size_request(username_widget, 250, -1);
gtk_entry_set_text(GTK_ENTRY(username_widget), "");
gtk_box_pack_end(GTK_BOX(hbox), username_widget, FALSE, FALSE, 10); /* x-space around input filed */
gtk_widget_show(username_widget);
@@ -644,7 +640,7 @@ gint xsane_authorization_callback(SANE_String_Const resource,
password_widget = gtk_entry_new_with_max_length(SANE_MAX_PASSWORD_LEN-1);
gtk_entry_set_visibility(GTK_ENTRY(password_widget), FALSE); /* make entered text invisible */
- gtk_widget_set_usize(password_widget, 250, 0);
+ gtk_widget_set_size_request(password_widget, 250, -1);
gtk_entry_set_text(GTK_ENTRY(password_widget), "");
gtk_box_pack_end(GTK_BOX(hbox), password_widget, FALSE, FALSE, 10); /* x-space around input filed */
gtk_widget_show(password_widget);
@@ -654,15 +650,23 @@ gint xsane_authorization_callback(SANE_String_Const resource,
hbox = gtk_hbox_new(TRUE, 10); /* x-space between buttons */
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 10); /* y-space around buttons */
+#ifdef HAVE_GTK2
+ button = gtk_button_new_from_stock(GTK_STOCK_OK);
+#else
button = gtk_button_new_with_label(BUTTON_OK);
+#endif
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(xsane_authorization_button_callback), (void *) 1);
+ g_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(xsane_authorization_button_callback), (void *) 1);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 10); /* x-space around OK-button */
gtk_widget_grab_default(button);
gtk_widget_show(button);
+#ifdef HAVE_GTK2
+ button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
+#else
button = gtk_button_new_with_label(BUTTON_CANCEL);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(xsane_authorization_button_callback), (void *) -1);
+#endif
+ g_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(xsane_authorization_button_callback), (void *) -1);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 10); /* x-space around cancel-button */
gtk_widget_show(button);
@@ -742,7 +746,7 @@ void xsane_progress_new(char *bar_text, char *info, GtkSignalFunc callback, int
gtk_progress_bar_update(GTK_PROGRESS_BAR(xsane.progress_bar), 0.0);
gtk_widget_set_sensitive(GTK_WIDGET(xsane.cancel_button), TRUE);
gtk_object_set_data(GTK_OBJECT(xsane.cancel_button), "progress-cancel-data-pointer", cancel_data_pointer);
- gtk_signal_connect(GTK_OBJECT(xsane.cancel_button), "clicked", (GtkSignalFunc) xsane_progress_cancel, callback);
+ g_signal_connect(GTK_OBJECT(xsane.cancel_button), "clicked", (GtkSignalFunc) xsane_progress_cancel, callback);
xsane.cancel_callback = callback;
}
@@ -759,7 +763,7 @@ void xsane_progress_clear()
if (xsane.cancel_callback)
{
- gtk_signal_disconnect_by_func(GTK_OBJECT(xsane.cancel_button), (GtkSignalFunc) xsane_progress_cancel, xsane.cancel_callback);
+ g_signal_handlers_disconnect_by_func(GTK_OBJECT(xsane.cancel_button), (GtkSignalFunc) xsane_progress_cancel, xsane.cancel_callback);
xsane.cancel_callback = 0;
}
}
@@ -792,7 +796,7 @@ GtkWidget *xsane_vendor_pixmap_new(GdkWindow *window, GtkWidget *parent)
char filename[PATH_MAX];
GtkWidget *hbox, *vbox;
GtkWidget *pixmapwidget = NULL;
- GdkBitmap *mask;
+ GdkBitmap *mask = NULL;
GdkPixmap *pixmap = NULL;
if (xsane.devlist[xsane.selected_dev]->vendor)
@@ -824,9 +828,9 @@ GtkWidget *xsane_vendor_pixmap_new(GdkWindow *window, GtkWidget *parent)
gtk_container_set_border_width(GTK_CONTAINER(hbox), 0);
gtk_widget_show(hbox);
- pixmapwidget = gtk_pixmap_new(pixmap, mask); /* now add the pixmap */
+ pixmapwidget = gtk_image_new_from_pixmap(pixmap, mask); /* now add the pixmap */
gtk_box_pack_start(GTK_BOX(hbox), pixmapwidget, FALSE /* expand */, FALSE /* fill */, 2);
- gdk_pixmap_unref(pixmap);
+ gdk_drawable_unref(pixmap);
gtk_widget_show(pixmapwidget);
}
@@ -849,13 +853,13 @@ GtkWidget *xsane_toggle_button_new_with_pixmap(GdkWindow *window, GtkWidget *par
xsane_back_gtk_set_tooltip(xsane.tooltips, button, desc);
pixmap = gdk_pixmap_create_from_xpm_d(window, &mask, xsane.bg_trans, (gchar **) xpm_d);
- pixmapwidget = gtk_pixmap_new(pixmap, mask);
+ pixmapwidget = gtk_image_new_from_pixmap(pixmap, mask);
gtk_container_add(GTK_CONTAINER(button), pixmapwidget);
gtk_widget_show(pixmapwidget);
- gdk_pixmap_unref(pixmap);
+ gdk_drawable_unref(pixmap);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *state);
- gtk_signal_connect(GTK_OBJECT(button), "toggled", (GtkSignalFunc) xsane_toggle_button_callback, (GtkObject *) state);
+ g_signal_connect(GTK_OBJECT(button), "toggled", (GtkSignalFunc) xsane_toggle_button_callback, (GtkObject *) state);
gtk_box_pack_start(GTK_BOX(parent), button, FALSE, FALSE, 0);
gtk_widget_show(button);
@@ -878,14 +882,14 @@ GtkWidget *xsane_button_new_with_pixmap(GdkWindow *window, GtkWidget *parent, co
xsane_back_gtk_set_tooltip(xsane.tooltips, button, desc);
pixmap = gdk_pixmap_create_from_xpm_d(window, &mask, xsane.bg_trans, (gchar **) xpm_d);
- pixmapwidget = gtk_pixmap_new(pixmap, mask);
+ pixmapwidget = gtk_image_new_from_pixmap(pixmap, mask);
gtk_container_add(GTK_CONTAINER(button), pixmapwidget);
gtk_widget_show(pixmapwidget);
- gdk_pixmap_unref(pixmap);
+ gdk_drawable_unref(pixmap);
if (xsane_button_callback)
{
- gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_button_callback, data);
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_button_callback, data);
}
gtk_box_pack_start(GTK_BOX(parent), button, FALSE, FALSE, 0);
gtk_widget_show(button);
@@ -895,22 +899,25 @@ GtkWidget *xsane_button_new_with_pixmap(GdkWindow *window, GtkWidget *parent, co
/* ---------------------------------------------------------------------------------------------------------------------- */
-static int xsane_option_menu_lookup(GSGMenuItem menu_items[], const char *string)
+static int xsane_option_menu_lookup(MenuItem menu_items[], const char *string)
{
int i;
DBG(DBG_proc, "xsane_option_menu_lookup\n");
- for (i = 0; strcmp(menu_items[i].label, string) != 0; ++i);
- return i;
+ for (i = 0; (menu_items[i].label) && strcmp(menu_items[i].label, string); ++i)
+ {
+ }
+
+ return i;
}
/* ---------------------------------------------------------------------------------------------------------------------- */
static void xsane_option_menu_callback(GtkWidget *widget, gpointer data)
{
- GSGMenuItem *menu_item = data;
- GSGDialogElement *elem = menu_item->elem;
+ MenuItem *menu_item = data;
+ DialogElement *elem = menu_item->elem;
const SANE_Option_Descriptor *opt;
int opt_num;
double dval;
@@ -925,20 +932,20 @@ static void xsane_option_menu_callback(GtkWidget *widget, gpointer data)
{
case SANE_TYPE_INT:
sscanf(menu_item->label, "%d", &val);
- break;
+ break;
case SANE_TYPE_FIXED:
sscanf(menu_item->label, "%lg", &dval);
val = SANE_FIX(dval);
- break;
+ break;
case SANE_TYPE_STRING:
valp = menu_item->label;
- break;
+ break;
default:
DBG(DBG_error, "xsane_option_menu_callback: %s %d\n", ERR_UNKNOWN_TYPE, opt->type);
- break;
+ break;
}
xsane_back_gtk_set_option(opt_num, valp, SANE_ACTION_SET_VALUE);
}
@@ -949,16 +956,19 @@ void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val,
void *option_menu_callback, SANE_Int settable, const gchar *widget_name)
{
GtkWidget *option_menu, *menu, *item;
- GSGMenuItem *menu_items;
- GSGDialogElement *elem;
+ MenuItem *menu_items;
+ DialogElement *elem;
int i, num_items;
DBG(DBG_proc, "xsane_option_menu_new\n");
elem = xsane.element + option_number;
- for (num_items = 0; str_list[num_items]; ++num_items);
- menu_items = malloc(num_items * sizeof(menu_items[0]));
+ for (num_items = 0; str_list[num_items]; ++num_items)
+ {
+ }
+
+ menu_items = malloc((num_items + 1) * sizeof(menu_items[0]));
menu = gtk_menu_new();
if (widget_name)
@@ -973,11 +983,11 @@ void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val,
if (option_menu_callback)
{
- gtk_signal_connect(GTK_OBJECT(item), "activate", (GtkSignalFunc) option_menu_callback, menu_items + i);
+ g_signal_connect(GTK_OBJECT(item), "activate", (GtkSignalFunc) option_menu_callback, menu_items + i);
}
else
{
- gtk_signal_connect(GTK_OBJECT(item), "activate", (GtkSignalFunc) xsane_option_menu_callback, menu_items + i);
+ g_signal_connect(GTK_OBJECT(item), "activate", (GtkSignalFunc) xsane_option_menu_callback, menu_items + i);
}
gtk_widget_show(item);
@@ -987,6 +997,11 @@ void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val,
menu_items[i].index = i;
}
+ /* add empty element as end of list marker */
+ menu_items[i].label = NULL;
+ menu_items[i].elem = NULL;
+ menu_items[i].index = 0;
+
option_menu = gtk_option_menu_new();
xsane_back_gtk_set_tooltip(xsane.tooltips, option_menu, desc);
gtk_box_pack_end(GTK_BOX(parent), option_menu, FALSE, FALSE, 2);
@@ -997,7 +1012,7 @@ void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val,
gtk_widget_set_sensitive(option_menu, settable);
- elem->widget = option_menu;
+ elem->widget = option_menu;
elem->menu_size = num_items;
elem->menu = menu_items;
}
@@ -1020,7 +1035,7 @@ void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const
gtk_box_pack_start(parent, hbox, FALSE, FALSE, 0);
pixmap = gdk_pixmap_create_from_xpm_d(window, &mask, xsane.bg_trans, (gchar **) xpm_d);
- pixmapwidget = gtk_pixmap_new(pixmap, mask);
+ pixmapwidget = gtk_image_new_from_pixmap(pixmap, mask);
gtk_box_pack_start(GTK_BOX(hbox), pixmapwidget, FALSE, FALSE, 2);
gtk_widget_show(pixmapwidget);
@@ -1030,97 +1045,431 @@ void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const
/* ---------------------------------------------------------------------------------------------------------------------- */
-void xsane_scale_new(GtkBox *parent, char *labeltext, const char *desc,
- float min, float max, float quant, float page_step, float page_size,
- int digits, double *val, GtkObject **data, void *xsane_scale_callback, SANE_Int settable)
+static void xsane_range_display_value_right_callback(GtkAdjustment *adjust, gpointer data)
+{
+ gchar buf[256];
+ int digits = (int) data;
+ GtkLabel *label;
+
+ snprintf(buf, sizeof(buf), "%1.*f", digits, adjust->value);
+ label = (GtkLabel *) gtk_object_get_data(GTK_OBJECT(adjust), "value-label");
+ gtk_label_set_text(label, buf);
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+void xsane_range_new(GtkBox *parent, char *labeltext, const char *desc,
+ float min, float max, float quant, float page_step,
+ int digits, double *val, GtkObject **data, void *xsane_range_callback, SANE_Int settable)
{
GtkWidget *hbox;
GtkWidget *label;
- GtkWidget *scale;
+ GtkWidget *slider = NULL;
+ GtkWidget *spinbutton;
+ GtkWidget *value_label;
- DBG(DBG_proc, "xsane_scale_new\n");
+ DBG(DBG_proc, "xsane_range_new\n");
hbox = gtk_hbox_new(FALSE, 5);
- gtk_box_pack_start(parent, hbox, FALSE, FALSE, 0);
+ gtk_box_pack_start(parent, hbox, FALSE, FALSE, 2);
label = gtk_label_new(labeltext);
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 1);
- *data = gtk_adjustment_new(*val, min, max, quant, page_step, page_size);
- scale = gtk_hscale_new(GTK_ADJUSTMENT(*data));
- xsane_back_gtk_set_tooltip(xsane.tooltips, scale, desc);
- gtk_widget_set_usize(scale, 201, 0); /* minimum scale with = 201 pixels */
- gtk_range_set_update_policy(GTK_RANGE(scale), preferences.gtk_update_policy);
- /* GTK_UPDATE_CONTINUOUS, GTK_UPDATE_DISCONTINUOUS, GTK_UPDATE_DELAYED */
- gtk_scale_set_value_pos(GTK_SCALE(scale), GTK_POS_TOP);
- gtk_scale_set_digits(GTK_SCALE(scale), digits);
- gtk_box_pack_end(GTK_BOX(hbox), scale, FALSE, TRUE, 5); /* make scale not sizeable */
+ *data = gtk_adjustment_new(*val, min, max, quant, page_step, (max-min) * 1e-30);
+ /* 1e-30 => hscrollbar has an unwanted side effect: the maximum is not the maximum */
+ /* of the given range, it is reduced by the page_size, so it has to be very small */
- if (xsane_scale_callback)
+ /* value label */
+ if (preferences.show_range_mode & 8)
{
- gtk_signal_connect(*data, "value_changed", (GtkSignalFunc) xsane_scale_callback, val);
+ value_label = gtk_label_new("");
+ gtk_widget_set_size_request(value_label, 35, -1);
+ gtk_box_pack_end(GTK_BOX(hbox), value_label, FALSE, FALSE, 1);
+
+ g_signal_connect(*data, "value_changed", (GtkSignalFunc) xsane_range_display_value_right_callback, (void *) digits);
+ gtk_object_set_data(GTK_OBJECT(*data), "value-label", value_label);
+ g_signal_emit_by_name(GTK_OBJECT(*data), "value_changed"); /* update value */
+ gtk_widget_show(value_label);
+ gtk_widget_set_sensitive(value_label, settable);
}
- gtk_widget_show(label);
- gtk_widget_show(scale);
- gtk_widget_show(hbox);
+ /* spinbutton */
+ if (preferences.show_range_mode & 4)
+ {
+ spinbutton = gtk_spin_button_new(GTK_ADJUSTMENT(*data), 0, digits);
+ if (preferences.show_range_mode & 3) /* slider also visible */
+ {
+ gtk_widget_set_size_request(spinbutton, 60, -1);
+ }
+ else /* slider not visible */
+ {
+ gtk_widget_set_size_request(spinbutton, 100, -1);
+ }
+ xsane_back_gtk_set_tooltip(xsane.tooltips, spinbutton, desc);
+ gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(spinbutton), FALSE);
+ gtk_box_pack_end(GTK_BOX(hbox), spinbutton, FALSE, FALSE, 5); /* make spinbutton not sizeable */
+ gtk_widget_show(spinbutton);
+ gtk_widget_set_sensitive(spinbutton, settable);
+ }
+
+ /* slider */
+ if (preferences.show_range_mode & 3)
+ {
+ if (preferences.show_range_mode & 1) /* bit 0 (val 1) : scale */
+ {
+ slider = gtk_hscale_new(GTK_ADJUSTMENT(*data));
+ gtk_scale_set_draw_value(GTK_SCALE(slider), FALSE);
+ gtk_scale_set_digits(GTK_SCALE(slider), digits);
+ }
+ else /* bit 1 (val 2) : scrollbar */
+ {
+ slider = gtk_hscrollbar_new(GTK_ADJUSTMENT(*data));
+ }
+ xsane_back_gtk_set_tooltip(xsane.tooltips, slider, desc);
+ gtk_widget_set_size_request(slider, 180, -1);
+ /* GTK_UPDATE_CONTINUOUS, GTK_UPDATE_DISCONTINUOUS, GTK_UPDATE_DELAYED */
+ gtk_range_set_update_policy(GTK_RANGE(slider), preferences.gtk_update_policy);
+ gtk_box_pack_end(GTK_BOX(hbox), slider, FALSE, FALSE, 5); /* make slider not sizeable */
+ gtk_widget_show(slider);
+ gtk_widget_set_sensitive(slider, settable);
+ }
- gtk_widget_set_sensitive(scale, settable);
+ if (xsane_range_callback)
+ {
+ g_signal_connect(*data, "value_changed", (GtkSignalFunc) xsane_range_callback, val);
+ }
+ gtk_widget_show(label);
+ gtk_widget_show(hbox);
}
/* ---------------------------------------------------------------------------------------------------------------------- */
-void xsane_scale_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
- float min, float max, float quant, float page_step, float page_size,
- int digits, double *val, GtkObject **data, int option, void *xsane_scale_callback, SANE_Int settable)
+void xsane_range_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
+ float min, float max, float quant, float page_step,
+ int digits, double *val, GtkObject **data, int option, void *xsane_range_callback, SANE_Int settable)
{
GtkWidget *hbox;
- GtkWidget *scale;
+ GtkWidget *slider = NULL;
+ GtkWidget *spinbutton;
GtkWidget *pixmapwidget;
GdkBitmap *mask;
GdkPixmap *pixmap;
+ GtkWidget *value_label;
- DBG(DBG_proc, "xsane_scale_new_with_pixmap\n");
+ DBG(DBG_proc, "xsane_slider_new_with_pixmap\n");
hbox = gtk_hbox_new(FALSE, 5);
- gtk_box_pack_start(parent, hbox, FALSE, FALSE, 0);
+ gtk_box_pack_start(parent, hbox, FALSE, FALSE, 1);
pixmap = gdk_pixmap_create_from_xpm_d(window, &mask, xsane.bg_trans, (gchar **) xpm_d);
- pixmapwidget = gtk_pixmap_new(pixmap, mask);
+ pixmapwidget = gtk_image_new_from_pixmap(pixmap, mask);
gtk_box_pack_start(GTK_BOX(hbox), pixmapwidget, FALSE, FALSE, 2);
+ gtk_widget_show(pixmapwidget);
+ gdk_drawable_unref(pixmap);
- *data = gtk_adjustment_new(*val, min, max, quant, page_step, page_size);
- scale = gtk_hscale_new(GTK_ADJUSTMENT(*data));
- xsane_back_gtk_set_tooltip(xsane.tooltips, scale, desc);
- gtk_widget_set_usize(scale, 201, 0); /* minimum scale with = 201 pixels */
- gtk_range_set_update_policy(GTK_RANGE(scale), preferences.gtk_update_policy);
- /* GTK_UPDATE_CONTINUOUS, GTK_UPDATE_DISCONTINUOUS, GTK_UPDATE_DELAYED */
- gtk_scale_set_value_pos(GTK_SCALE(scale), GTK_POS_TOP);
- gtk_scale_set_digits(GTK_SCALE(scale), digits);
- gtk_box_pack_end(GTK_BOX(hbox), scale, TRUE, TRUE, 5); /* make scale sizeable */
+ *data = gtk_adjustment_new(*val, min, max, quant, page_step, (max-min) * 1e-30);
+ /* 1e-30 => hscrollbar has an unwanted side effect: the maximum is not the maximum */
+ /* of the given range, it is reduced by the page_size, so it has to be very small */
- if (xsane_scale_callback)
+ /* value label */
+ if (preferences.show_range_mode & 8)
{
- gtk_signal_connect(*data, "value_changed", (GtkSignalFunc) xsane_scale_callback, val);
+ value_label = gtk_label_new("");
+ gtk_widget_set_size_request(value_label, 35, -1);
+ gtk_box_pack_end(GTK_BOX(hbox), value_label, FALSE, FALSE, 1);
+
+ g_signal_connect(*data, "value_changed", (GtkSignalFunc) xsane_range_display_value_right_callback, (void *) digits);
+ gtk_object_set_data(GTK_OBJECT(*data), "value-label", value_label);
+ g_signal_emit_by_name(GTK_OBJECT(*data), "value_changed"); /* update value */
+ gtk_widget_show(value_label);
+ gtk_widget_set_sensitive(value_label, settable);
}
- gtk_widget_show(pixmapwidget);
- gtk_widget_show(scale);
- gtk_widget_show(hbox);
+ /* spinbutton */
+ if (preferences.show_range_mode & 4)
+ {
+ spinbutton = gtk_spin_button_new(GTK_ADJUSTMENT(*data), 0, digits);
+ gtk_widget_set_size_request(spinbutton, 60, -1);
+ xsane_back_gtk_set_tooltip(xsane.tooltips, spinbutton, desc);
+ gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(spinbutton), FALSE);
+ if (preferences.show_range_mode & 3) /* slider also visible */
+ {
+ gtk_box_pack_end(GTK_BOX(hbox), spinbutton, FALSE, FALSE, 5); /* make spinbutton not sizeable */
+ }
+ else /* slider not visible */
+ {
+ gtk_box_pack_end(GTK_BOX(hbox), spinbutton, TRUE, TRUE, 5); /* make spinbutton sizeable */
+ }
+ gtk_widget_show(spinbutton);
+ gtk_widget_set_sensitive(spinbutton, settable);
+ }
- gtk_widget_set_sensitive(scale, settable);
+ /* slider */
+ if (preferences.show_range_mode & 3)
+ {
+ if (preferences.show_range_mode & 1) /* bit 0 (val 1) : scale */
+ {
+ slider = gtk_hscale_new(GTK_ADJUSTMENT(*data));
+ gtk_scale_set_draw_value(GTK_SCALE(slider), FALSE);
+ gtk_scale_set_digits(GTK_SCALE(slider), digits);
+ }
+ else /* bit 1 (val 2) : scrollbar */
+ {
+ slider = gtk_hscrollbar_new(GTK_ADJUSTMENT(*data));
+ }
+ xsane_back_gtk_set_tooltip(xsane.tooltips, slider, desc);
+ gtk_widget_set_size_request(slider, 170, -1);
+ /* GTK_UPDATE_CONTINUOUS, GTK_UPDATE_DISCONTINUOUS, GTK_UPDATE_DELAYED */
+ gtk_range_set_update_policy(GTK_RANGE(slider), preferences.gtk_update_policy);
+ gtk_box_pack_end(GTK_BOX(hbox), slider, TRUE, TRUE, 5); /* make slider sizeable */
+ gtk_widget_show(slider);
+ gtk_widget_set_sensitive(slider, settable);
+ }
- gdk_pixmap_unref(pixmap);
+ if (xsane_range_callback)
+ {
+ g_signal_connect(*data, "value_changed", (GtkSignalFunc) xsane_range_callback, val);
+ }
+
+ gtk_widget_show(hbox);
if (option)
{
- GSGDialogElement *elem;
+ DialogElement *elem;
elem=xsane.element + option;
- elem->data = *data;
- elem->widget = scale;
+ elem->data = *data;
+ elem->widget = slider;
+ }
+}
+
+/* ----------------------------------------------------------------------------------------------------------------- */
+
+static void xsane_browse_filename_callback(GtkWidget *widget, gpointer data)
+{
+ char filename[1024];
+ char windowname[256];
+
+ DBG(DBG_proc, "xsane_browse_filename_callback\n");
+
+ xsane_set_sensitivity(FALSE);
+
+ if (preferences.filename) /* make sure a correct filename is defined */
+ {
+ strncpy(filename, preferences.filename, sizeof(filename));
+ filename[sizeof(filename) - 1] = '\0';
+ }
+ else /* no filename given, take standard filename */
+ {
+ strcpy(filename, OUT_FILENAME);
+ }
+
+ snprintf(windowname, sizeof(windowname), "%s %s %s", xsane.prog_name, WINDOW_OUTPUT_FILENAME, xsane.device_text);
+
+ umask((mode_t) preferences.directory_umask); /* define new file permissions */
+ xsane_back_gtk_get_filename(windowname, filename, sizeof(filename), filename, &preferences.filetype, TRUE, TRUE, FALSE, TRUE);
+ umask(XSANE_DEFAULT_UMASK); /* define new file permissions */
+
+ if (preferences.filename)
+ {
+ free((void *) preferences.filename);
+ }
+
+ preferences.filename = strdup(filename);
+
+ xsane_set_sensitivity(TRUE);
+
+ xsane_back_gtk_filetype_menu_set_history(xsane.filetype_option_menu, preferences.filetype);
+
+ /* correct length of filename counter if it is shorter than minimum length */
+ xsane_update_counter_in_filename(&preferences.filename, FALSE, 0, preferences.filename_counter_len);
+
+ xsane_set_filename(preferences.filename);
+
+ xsane_define_maximum_output_size(); /* is necessary in postscript mode */
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+void xsane_set_filename(gchar *filename)
+{
+ g_signal_handlers_block_by_func(GTK_OBJECT(xsane.outputfilename_entry), (GtkSignalFunc) xsane_outputfilename_changed_callback, NULL);
+ gtk_entry_set_text(GTK_ENTRY(xsane.outputfilename_entry), (char *) filename); /* update filename in entry */
+ gtk_entry_set_position(GTK_ENTRY(xsane.outputfilename_entry), strlen(filename)); /* set cursor to right position of filename */
+
+ g_signal_handlers_unblock_by_func(GTK_OBJECT(xsane.outputfilename_entry), (GtkSignalFunc) xsane_outputfilename_changed_callback, NULL);
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+static void xsane_filename_counter_step_callback(GtkWidget *widget, gpointer data)
+{
+ DBG(DBG_proc, "xsane_filename_counter_step_callback\n");
+
+ preferences.filename_counter_step = (int) data;
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+static void xsane_filetype_callback(GtkWidget *widget, gpointer data)
+{
+ char *new_filetype = (char *) data;
+ char buffer[PATH_MAX];
+ char *filename;
+
+ DBG(DBG_proc, "xsane_filetype_callback\n");
+
+ filename = preferences.filename;
+
+ if ((new_filetype) && (*new_filetype)) /* filetype exists and is not empty (by ext) */
+ {
+ char *extension;
+
+ extension = strrchr(preferences.filename, '.');
+
+ if ((extension) && (extension != preferences.filename))
+ {
+ if ( (!strcasecmp(extension, ".pnm")) || (!strcasecmp(extension, ".raw"))
+ || (!strcasecmp(extension, ".png")) || (!strcasecmp(extension, ".ps"))
+ || (!strcasecmp(extension, ".rgba"))
+ || (!strcasecmp(extension, ".tiff")) || (!strcasecmp(extension, ".tif"))
+ || (!strcasecmp(extension, ".text")) || (!strcasecmp(extension, ".txt"))
+ || (!strcasecmp(extension, ".jpg")) || (!strcasecmp(extension, ".jpeg"))
+ ) /* remove filetype extension */
+ {
+ *extension = 0; /* remove extension */
+ }
+ }
+ snprintf(buffer, sizeof(buffer), "%s%s", filename, new_filetype);
+ free(filename);
+ preferences.filename = strdup(buffer);
+ }
+
+ if (preferences.filetype)
+ {
+ free(preferences.filetype);
+ preferences.filetype = NULL;
+ }
+
+ if (new_filetype)
+ {
+ preferences.filetype = strdup(new_filetype);
+ }
+
+ /* correct length of filename counter if it is shorter than minimum length */
+ xsane_update_counter_in_filename(&preferences.filename, FALSE, 0, preferences.filename_counter_len);
+ xsane_set_filename(preferences.filename);
+ xsane_define_maximum_output_size(); /* is necessary in postscript mode */
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+static void xsane_outputfilename_changed_callback(GtkWidget *widget, gpointer data)
+{
+ DBG(DBG_proc, "xsane_outputfilename_changed_callback\n");
+
+ if (preferences.filename)
+ {
+ free((void *) preferences.filename);
+ }
+ preferences.filename = strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
+
+ xsane_define_maximum_output_size(); /* is necessary in postscript mode */
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+void xsane_outputfilename_new(GtkWidget *vbox)
+{
+ GtkWidget *hbox;
+ GtkWidget *text;
+ GtkWidget *button;
+ GtkWidget *xsane_filename_counter_step_option_menu;
+ GtkWidget *xsane_filename_counter_step_menu;
+ GtkWidget *xsane_filename_counter_step_item;
+ GtkWidget *xsane_label;
+ gchar buf[200];
+ int i,j;
+ int select_item = 0;
+
+ DBG(DBG_proc, "xsane_outputfilename_new\n");
+
+ /* first line: disk icon, filename box */
+
+ hbox = gtk_hbox_new(FALSE, 2);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 2);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
+
+ button = xsane_button_new_with_pixmap(xsane.xsane_window->window, hbox, file_xpm, DESC_BROWSE_FILENAME,
+ (GtkSignalFunc) xsane_browse_filename_callback, NULL);
+ gtk_widget_add_accelerator(button, "clicked", xsane.accelerator_group, GDK_B, GDK_CONTROL_MASK, DEF_GTK_ACCEL_LOCKED);
+
+ text = gtk_entry_new();
+ gtk_widget_set_size_request(text, 80, -1); /* set minimum size */
+ xsane_back_gtk_set_tooltip(xsane.tooltips, text, DESC_FILENAME);
+ gtk_entry_set_max_length(GTK_ENTRY(text), 255);
+ gtk_entry_set_text(GTK_ENTRY(text), (char *) preferences.filename);
+ gtk_entry_set_position(GTK_ENTRY(text), strlen(preferences.filename)); /* set cursor to right position of filename */
+
+ gtk_box_pack_start(GTK_BOX(hbox), text, TRUE, TRUE, 4);
+ g_signal_connect(GTK_OBJECT(text), "changed", (GtkSignalFunc) xsane_outputfilename_changed_callback, NULL);
+
+ xsane.outputfilename_entry = text;
+
+ gtk_widget_show(text);
+ gtk_widget_show(hbox);
+
+
+ /* second line: Step, Type */
+
+ hbox = gtk_hbox_new(FALSE, 2);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 2);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
+
+ /* filename counter step */
+
+ xsane_label = gtk_label_new(TEXT_FILENAME_COUNTER_STEP);
+ gtk_box_pack_start(GTK_BOX(hbox), xsane_label, FALSE, FALSE, 2);
+ gtk_widget_show(xsane_label);
+
+ xsane_filename_counter_step_option_menu = gtk_option_menu_new();
+ xsane_back_gtk_set_tooltip(xsane.tooltips, xsane_filename_counter_step_option_menu, DESC_FILENAME_COUNTER_STEP);
+ gtk_box_pack_start(GTK_BOX(hbox), xsane_filename_counter_step_option_menu, FALSE, FALSE, 2);
+ gtk_widget_show(xsane_filename_counter_step_option_menu);
+ gtk_widget_show(hbox);
+
+ xsane_filename_counter_step_menu = gtk_menu_new();
+
+ select_item = 0;
+ j = -2;
+ for (i=0; i < 5; i++)
+ {
+ snprintf(buf, sizeof(buf), "%+d", j);
+ xsane_filename_counter_step_item = gtk_menu_item_new_with_label(buf);
+ gtk_container_add(GTK_CONTAINER(xsane_filename_counter_step_menu), xsane_filename_counter_step_item);
+ g_signal_connect(GTK_OBJECT(xsane_filename_counter_step_item), "activate", (GtkSignalFunc) xsane_filename_counter_step_callback, (void *) j);
+ gtk_widget_show(xsane_filename_counter_step_item);
+ if (preferences.filename_counter_step == j++)
+ {
+ select_item = i;
+ }
}
+
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(xsane_filename_counter_step_option_menu), xsane_filename_counter_step_menu);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(xsane_filename_counter_step_option_menu), select_item);
+
+ xsane.filetype_option_menu = xsane_back_gtk_filetype_menu_new(preferences.filetype, (GtkSignalFunc) xsane_filetype_callback);
+ gtk_box_pack_end(GTK_BOX(hbox), xsane.filetype_option_menu, FALSE, FALSE, 2);
+ gtk_widget_show(xsane.filetype_option_menu);
+
+ xsane_label = gtk_label_new(TEXT_FILETYPE); /* opposite order because of box_pack_end */
+ gtk_box_pack_end(GTK_BOX(hbox), xsane_label, FALSE, FALSE, 2);
+ gtk_widget_show(xsane_label);
+
+ gtk_widget_show(text);
+ gtk_widget_show(hbox);
}
/* ---------------------------------------------------------------------------------------------------------------------- */
@@ -1138,6 +1487,20 @@ void xsane_separator_new(GtkWidget *xsane_parent, int dist)
/* ---------------------------------------------------------------------------------------------------------------------- */
+void xsane_vseparator_new(GtkWidget *xsane_parent, int dist)
+{
+ GtkWidget *xsane_vseparator;
+
+ DBG(DBG_proc, "xsane_vseparator_new\n");
+
+ xsane_vseparator = gtk_vseparator_new();
+ gtk_box_pack_start(GTK_BOX(xsane_parent), xsane_vseparator, FALSE, FALSE, dist);
+ gtk_widget_show(xsane_vseparator);
+
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
GtkWidget *xsane_info_table_text_new(GtkWidget *table, gchar *text, int row, int colomn)
{
GtkWidget *hbox, *label;
@@ -1293,8 +1656,6 @@ void xsane_update_param(void *arg)
void xsane_define_output_filename(void)
{
- char buffer[256];
-
DBG(DBG_proc, "xsane_define_output_filename\n");
if (xsane.output_filename)
@@ -1305,52 +1666,44 @@ void xsane_define_output_filename(void)
if (!xsane.force_filename)
{
- if (xsane.filetype)
- {
- snprintf(buffer, sizeof(buffer), "%s%s", preferences.filename, xsane.filetype);
- xsane.output_filename = strdup(buffer);
- }
- else
- {
- xsane.output_filename = strdup(preferences.filename);
- }
+ xsane.output_filename = strdup(preferences.filename);
}
else
{
- xsane.output_filename = strdup(xsane.external_filename);
+ xsane.output_filename = strdup(xsane.external_filename);
}
}
/* ---------------------------------------------------------------------------------------------------------------------- */
-int xsane_identify_output_format(char *filename, char **ext)
+int xsane_identify_output_format(char *filename, char *filetype, char **ext)
{
char *extension;
int output_format=-1;
DBG(DBG_proc, "xsane_identify_output_format\n");
- extension = strrchr(filename, '.');
- if (extension)
+ if ((filetype) && (*filetype))
{
- extension++; /* skip "." */
+ extension = filetype+1; /* go to filetype, skip leading dot */
+ }
+ else
+ {
+ extension = strrchr(filename, '.');
+ if (extension)
+ {
+ extension++; /* skip "." */
+ }
}
output_format = XSANE_UNKNOWN;
if (extension)
{
- if (!strcasecmp(extension, "raw"))
+ if ( (!strcasecmp(extension, "pnm")) || (!strcasecmp(extension, "ppm")) ||
+ (!strcasecmp(extension, "pgm")) || (!strcasecmp(extension, "pbm")) )
{
- if (xsane.param.depth == 16)
- {
- output_format = XSANE_RAW16;
- }
- }
- else if ( (!strcasecmp(extension, "pnm")) || (!strcasecmp(extension, "ppm")) ||
- (!strcasecmp(extension, "pgm")) || (!strcasecmp(extension, "pbm")) )
- {
- if (xsane.param.depth == 16)
+ if ((xsane.param.depth == 16) && (!preferences.reduce_16bit_to_8bit) )
{
output_format = XSANE_PNM16;
}
@@ -1359,6 +1712,10 @@ int xsane_identify_output_format(char *filename, char **ext)
output_format = XSANE_PNM;
}
}
+ else if ( (!strcasecmp(extension, "txt")) || (!strcasecmp(extension, "text")) )
+ {
+ output_format = XSANE_TEXT;
+ }
#ifdef HAVE_LIBPNG
#ifdef HAVE_LIBZ
else if (!strcasecmp(extension, "png"))
@@ -1420,7 +1777,7 @@ void xsane_change_working_directory(void)
sprintf(windowname, "%s %s %s", xsane.prog_name, WINDOW_CHANGE_WORKING_DIR, xsane.device_text);
if (getcwd(filename, sizeof(filename)))
{
- xsane_back_gtk_get_filename(windowname, filename, sizeof(filename), filename, TRUE, FALSE, TRUE);
+ xsane_back_gtk_get_filename(windowname, filename, sizeof(filename), filename, NULL, TRUE, FALSE, TRUE, FALSE);
if (chdir(filename))
{
char buf[256];
@@ -1430,6 +1787,14 @@ void xsane_change_working_directory(void)
xsane_set_sensitivity(TRUE);
return;
}
+ else
+ {
+ if (preferences.working_directory)
+ {
+ free(preferences.working_directory);
+ }
+ preferences.working_directory = strdup(filename);
+ }
}
xsane_set_sensitivity(TRUE);
@@ -1437,55 +1802,79 @@ void xsane_change_working_directory(void)
/* ---------------------------------------------------------------------------------------------------------------------- */
-static int license_flag;
-static GtkWidget *license_dialog = NULL;
+static int eula_accept_flag;
+static GtkWidget *eula_dialog = NULL;
-static void xsane_license_button_callback(GtkWidget *widget, gpointer data)
+static gboolean xsane_eula_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
- license_flag = (int) data;
+ eula_accept_flag = (int) data;
- DBG(DBG_proc ,"xsane_license_button_callback(%d)\n", license_flag);
+ DBG(DBG_proc ,"xsane_eula_delete_event(%d)\n", eula_accept_flag);
+ eula_dialog = NULL;
- gtk_widget_destroy(license_dialog);
- license_dialog = NULL;
+ return FALSE; /* continue with original delete even routine */
}
-/* ---------------------------------------------------------------------------------------------------------------------- */
+/* -------------------------------------- */
+
+static void xsane_eula_button_callback(GtkWidget *widget, gpointer data)
+{
+ eula_accept_flag = (int) data;
+
+ DBG(DBG_proc ,"xsane_eula_button_callback(%d)\n", eula_accept_flag);
+
+ gtk_widget_destroy(eula_dialog);
+ eula_dialog = NULL;
+}
+
+/* -------------------------------------- */
-int xsane_display_license(int ask_for_accept)
+int xsane_display_eula(int ask_for_accept)
/* returns FALSE if accepted, TRUE if not accepted */
{
- GtkWidget *vbox, *hbox, *button, *label;
- GtkWidget *text, *vscrollbar;
+ GtkWidget *vbox, *hbox, *button, *label, *frame;
GtkAccelGroup *accelerator_group;
char buf[1024];
char filename[PATH_MAX];
FILE *infile;
- DBG(DBG_proc, "xsane_display_license(%d)\n", ask_for_accept);
+ DBG(DBG_proc, "xsane_display_eula(%d)\n", ask_for_accept);
- if (license_dialog) /* make sure the dialog is only opend once */
+ if (eula_dialog) /* make sure the dialog is only opend once */
{
return 0;
}
- license_dialog = gtk_window_new(GTK_WINDOW_DIALOG);
- gtk_widget_set_usize(license_dialog, 550, 580);
- gtk_window_set_position(GTK_WINDOW(license_dialog), GTK_WIN_POS_CENTER);
- gtk_window_set_policy(GTK_WINDOW(license_dialog), FALSE, TRUE, FALSE);
- gtk_signal_connect(GTK_OBJECT(license_dialog), "delete_event",
- GTK_SIGNAL_FUNC(xsane_license_button_callback), (void *) -1); /* -1 = cancel */
- snprintf(buf, sizeof(buf), "%s %s", xsane.prog_name, WINDOW_LICENSE);
- gtk_window_set_title(GTK_WINDOW(license_dialog), buf);
- xsane_set_window_icon(license_dialog, 0);
-
+ eula_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(eula_dialog, 550, 580);
+ gtk_window_set_position(GTK_WINDOW(eula_dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_resizable(GTK_WINDOW(eula_dialog), TRUE);
+ g_signal_connect(GTK_OBJECT(eula_dialog), "delete_event", GTK_SIGNAL_FUNC(xsane_eula_delete_event), (void *) -1); /* -1 = cancel */
+ snprintf(buf, sizeof(buf), "%s %s", xsane.prog_name, WINDOW_EULA);
+ gtk_window_set_title(GTK_WINDOW(eula_dialog), buf);
accelerator_group = gtk_accel_group_new();
- gtk_accel_group_attach(accelerator_group, GTK_OBJECT(license_dialog));
+ gtk_window_add_accel_group(GTK_WINDOW(eula_dialog), accelerator_group);
+
+#if 0
+ xsane_set_window_icon(eula_dialog, 0);
+#endif
+
+ /* create a frame */
+ frame = gtk_frame_new(NULL);
+ gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
+ gtk_container_add(GTK_CONTAINER(eula_dialog), frame);
+ gtk_widget_show(frame);
vbox = gtk_vbox_new(FALSE, 5);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
- gtk_container_add(GTK_CONTAINER(license_dialog), vbox);
+ gtk_container_add(GTK_CONTAINER(frame), vbox);
gtk_widget_show(vbox);
+#if 1
+ /* this is normally done directly after gtk_window_set_title() */
+ /* but gtk crashes when we would do that and select a text with the mouse */
+ xsane_set_window_icon(eula_dialog, 0);
+#endif
/* display XSane copyright message */
snprintf(buf, sizeof(buf), "XSane %s %s\n"
@@ -1496,7 +1885,7 @@ int xsane_display_license(int ask_for_accept)
"%s %s\n",
TEXT_VERSION, XSANE_VERSION,
XSANE_COPYRIGHT_SIGN, XSANE_COPYRIGHT_TXT,
- TEXT_GPL,
+ TEXT_EULA,
TEXT_HOMEPAGE, XSANE_HOMEPAGE,
TEXT_EMAIL, XSANE_EMAIL);
@@ -1504,52 +1893,103 @@ int xsane_display_license(int ask_for_accept)
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);
- /* add hbox with text and scrollbar to display the license text */
+ /* add hbox with text and scrollbar to display the eula text */
hbox = gtk_hbox_new(FALSE, 2);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show(hbox);
+
+#ifdef HAVE_GTK_TEXT_VIEW_H
+ {
+ GtkWidget *scrolled_window, *text_view;
+ GtkTextBuffer *text_buffer;
+
+ /* create a scrolled window to get a vertical scrollbar */
+ scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_container_add(GTK_CONTAINER(hbox), scrolled_window);
+ gtk_widget_show(scrolled_window);
- /* Create the GtkText widget */
- text = gtk_text_new(NULL, NULL);
- gtk_text_set_editable(GTK_TEXT(text), FALSE); /* text is not editable */
- gtk_text_set_word_wrap(GTK_TEXT(text), TRUE); /* wrap complete words */
- gtk_box_pack_start(GTK_BOX(hbox), text, TRUE, TRUE, 0);
- gtk_widget_show(text);
+ /* create the gtk_text_view widget */
+ text_view = gtk_text_view_new();
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE);
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD);
+ gtk_container_add(GTK_CONTAINER(scrolled_window), text_view);
+ gtk_widget_show(text_view);
+
+ /* get the text_buffer widget and insert the text from file */
+ text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
+
+ xsane_back_gtk_make_path(sizeof(filename), filename, "xsane", 0, "xsane-eula", 0, ".txt", XSANE_PATH_SYSTEM);
+ infile = fopen(filename, "r");
+
+ if (infile)
+ {
+ char buffer[4096];
+ int nchars;
+
+ while (!feof(infile))
+ {
+ nchars = fread(buffer, 1, 4096, infile);
+ gtk_text_buffer_insert_at_cursor(text_buffer, buffer, nchars);
+ }
- /* Add a vertical scrollbar to the GtkText widget */
- vscrollbar = gtk_vscrollbar_new(GTK_TEXT(text)->vadj);
- gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0);
- gtk_widget_show(vscrollbar);
+ fclose(infile);
+ }
+ else
+ {
+ DBG(DBG_error0, "ERROR: eula text not found. Looks like xsane is not installed correct.\n");
+ return TRUE;
+ }
+
+ }
+#else /* we do not have gtk_text_view, so we use gtk_text */
+ {
+ GtkWidget *text, *vscrollbar;
+
+ /* Create the gtk_text widget */
+ text = gtk_text_new(NULL, NULL);
+ gtk_text_set_editable(GTK_TEXT(text), FALSE); /* text is not editable */
+ gtk_text_set_word_wrap(GTK_TEXT(text), TRUE); /* wrap complete words */
+ gtk_box_pack_start(GTK_BOX(hbox), text, TRUE, TRUE, 0);
+ gtk_widget_show(text);
+
+ /* Add a vertical scrollbar to the GtkText widget */
+ vscrollbar = gtk_vscrollbar_new(GTK_TEXT(text)->vadj);
+ gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0);
+ gtk_widget_show(vscrollbar);
- /* Freeze the text widget, ready for multiple updates */
- gtk_text_freeze(GTK_TEXT(text));
+ /* Freeze the text widget, ready for multiple updates */
+ gtk_text_freeze(GTK_TEXT(text));
- /* Load the file text.c into the text window */
- xsane_back_gtk_make_path(sizeof(filename), filename, "xsane", 0, "xsane-license", 0, ".txt", XSANE_PATH_SYSTEM);
- infile = fopen(filename, "r");
+ /* Load the file text.c into the text window */
+ xsane_back_gtk_make_path(sizeof(filename), filename, "xsane", 0, "xsane-eula", 0, ".txt", XSANE_PATH_SYSTEM);
+ infile = fopen(filename, "r");
- if (infile)
- {
- char buffer[4096];
- int nchars;
+ if (infile)
+ {
+ char buffer[4096];
+ int nchars;
+
+ while (!feof(infile))
+ {
+ nchars = fread(buffer, 1, 4096, infile);
+ gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buffer, nchars);
+ }
- while (!feof(infile))
+ fclose(infile);
+ }
+ else
{
- nchars = fread(buffer, 1, 4096, infile);
- gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buffer, nchars);
+ DBG(DBG_error0, "ERROR: eula text not found. Looks like xsane is not installed correct.\n");
+ return TRUE;
}
-
- fclose(infile);
- }
- else
- {
- DBG(DBG_error0, "ERROR: license text not found. Looks like xsane is not installed correct.\n");
- return TRUE;
- }
- /* Thaw the text widget, allowing the updates to become visible */
- gtk_text_thaw(GTK_TEXT(text));
+ /* Thaw the text widget, allowing the updates to become visible */
+ gtk_text_thaw(GTK_TEXT(text));
+ }
+#endif
@@ -1560,24 +2000,28 @@ int xsane_display_license(int ask_for_accept)
if (ask_for_accept) /* show accept + not accept buttons */
{
button = gtk_button_new_with_label(BUTTON_ACCEPT);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_license_button_callback, (void *) 0 /* accept */);
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_eula_button_callback, (void *) 0 /* accept */);
gtk_container_add(GTK_CONTAINER(hbox), button);
gtk_widget_show(button);
button = gtk_button_new_with_label(BUTTON_NOT_ACCEPT);
- gtk_widget_add_accelerator(button, "clicked", accelerator_group, GDK_Escape, 0, GTK_ACCEL_LOCKED);
+ gtk_widget_add_accelerator(button, "clicked", accelerator_group, GDK_Escape, 0, DEF_GTK_ACCEL_LOCKED);
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_license_button_callback, (void *) 1 /* not accept */);
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_eula_button_callback, (void *) 1 /* not accept */);
gtk_container_add(GTK_CONTAINER(hbox), button);
gtk_widget_grab_default(button);
gtk_widget_show(button);
}
else /* show close button */
{
+#ifdef HAVE_GTK2
+ button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+#else
button = gtk_button_new_with_label(BUTTON_CLOSE);
- gtk_widget_add_accelerator(button, "clicked", accelerator_group, GDK_Escape, 0, GTK_ACCEL_LOCKED);
+#endif
+ gtk_widget_add_accelerator(button, "clicked", accelerator_group, GDK_Escape, 0, DEF_GTK_ACCEL_LOCKED);
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_license_button_callback, (void *) 0 /* ok = accept */);
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_eula_button_callback, (void *) 0 /* ok = accept */);
gtk_container_add(GTK_CONTAINER(hbox), button);
gtk_widget_grab_default(button);
gtk_widget_show(button);
@@ -1585,16 +2029,16 @@ int xsane_display_license(int ask_for_accept)
gtk_widget_show(hbox);
gtk_widget_show(vbox);
- gtk_widget_show(license_dialog);
+ gtk_widget_show(eula_dialog);
if (ask_for_accept == 0) /* do not ask for accept */
{
return 0;
}
- license_flag = -255;
+ eula_accept_flag = -255;
- while(license_flag == -255)
+ while(eula_accept_flag == -255)
{
gtk_main_iteration(); /* allow gtk to react to user action */
}
@@ -1604,29 +2048,241 @@ int xsane_display_license(int ask_for_accept)
gtk_main_iteration();
}
- return license_flag;
+ return eula_accept_flag;
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+static GtkWidget *license_dialog = NULL;
+
+static void xsane_close_license_dialog_callback(GtkWidget *widget, gpointer data)
+{
+ DBG(DBG_proc ,"xsane_close_license_dialog_callback\n");
+
+ gtk_widget_destroy(license_dialog);
+ license_dialog = NULL;
+}
+
+/* ------------------------------------------------ */
+
+static gboolean xsane_license_dialog_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ DBG(DBG_proc ,"xsane_license_dialog_delete_event\n");
+
+ license_dialog = NULL;
+
+ return FALSE; /* continue with original delete even routine */
+}
+
+/* ------------------------------------------------ */
+
+void xsane_display_gpl(void)
+{
+ GtkWidget *vbox, *hbox, *button, *label, *frame;
+ GtkAccelGroup *accelerator_group;
+ char buf[1024];
+ char filename[PATH_MAX];
+ FILE *infile;
+
+ if (license_dialog) /* make sure the dialog is only opend once */
+ {
+ return;
+ }
+
+ license_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(license_dialog, 550, 580);
+ gtk_window_set_position(GTK_WINDOW(license_dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_resizable(GTK_WINDOW(license_dialog), TRUE);
+ g_signal_connect(GTK_OBJECT(license_dialog), "delete_event", GTK_SIGNAL_FUNC(xsane_license_dialog_delete_event), NULL);
+ snprintf(buf, sizeof(buf), "%s: %s", xsane.prog_name, WINDOW_GPL);
+ gtk_window_set_title(GTK_WINDOW(license_dialog), buf);
+ accelerator_group = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(license_dialog), accelerator_group);
+
+#if 0
+ xsane_set_window_icon(license_dialog, 0);
+#endif
+
+ /* create a frame */
+ frame = gtk_frame_new(NULL);
+ gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
+ gtk_container_add(GTK_CONTAINER(license_dialog), frame);
+ gtk_widget_show(frame);
+
+ vbox = gtk_vbox_new(FALSE, 5);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
+ gtk_container_add(GTK_CONTAINER(frame), vbox);
+ gtk_widget_show(vbox);
+#if 1
+ /* this is normally done directly after gtk_window_set_title() */
+ /* but gtk crashes when we would do that and select a text with the mouse */
+ xsane_set_window_icon(license_dialog, 0);
+#endif
+
+ /* display XSane copyright message */
+ snprintf(buf, sizeof(buf), "XSane %s %s\n"
+ "%s %s\n"
+ "\n"
+ "%s\n"
+ "%s %s\n"
+ "%s %s\n",
+ TEXT_VERSION, XSANE_VERSION,
+ XSANE_COPYRIGHT_SIGN, XSANE_COPYRIGHT_TXT,
+ TEXT_GPL,
+ TEXT_HOMEPAGE, XSANE_HOMEPAGE,
+ TEXT_EMAIL, XSANE_EMAIL);
+
+ label = gtk_label_new(buf);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_widget_show(label);
+
+ /* add hbox with text and scrollbar to display the license text */
+ hbox = gtk_hbox_new(FALSE, 2);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
+ gtk_widget_show(hbox);
+
+#ifdef HAVE_GTK_TEXT_VIEW_H
+ {
+ GtkWidget *scrolled_window, *text_view;
+ GtkTextBuffer *text_buffer;
+
+ /* create a scrolled window to get a vertical scrollbar */
+ scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_container_add(GTK_CONTAINER(hbox), scrolled_window);
+ gtk_widget_show(scrolled_window);
+
+ /* create the gtk_text_view widget */
+ text_view = gtk_text_view_new();
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE);
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD);
+ gtk_container_add(GTK_CONTAINER(scrolled_window), text_view);
+ gtk_widget_show(text_view);
+
+ /* get the text_buffer widget and insert the text from file */
+ text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
+
+ xsane_back_gtk_make_path(sizeof(filename), filename, "xsane", 0, "xsane-gpl", 0, ".txt", XSANE_PATH_SYSTEM);
+ infile = fopen(filename, "r");
+
+ if (infile)
+ {
+ char buffer[4096];
+ int nchars;
+
+ while (!feof(infile))
+ {
+ nchars = fread(buffer, 1, 4096, infile);
+ gtk_text_buffer_insert_at_cursor(text_buffer, buffer, nchars);
+ }
+
+ fclose(infile);
+ }
+ else
+ {
+ DBG(DBG_error0, "ERROR: license text not found. Looks like xsane is not installed correct.\n");
+ return;
+ }
+
+ }
+#else /* we do not have gtk_text_view, so we use gtk_text */
+ {
+ GtkWidget *text, *vscrollbar;
+
+ /* Create the gtk_text widget */
+ text = gtk_text_new(NULL, NULL);
+ gtk_text_set_editable(GTK_TEXT(text), FALSE); /* text is not editable */
+ gtk_text_set_word_wrap(GTK_TEXT(text), TRUE); /* wrap complete words */
+ gtk_box_pack_start(GTK_BOX(hbox), text, TRUE, TRUE, 0);
+ gtk_widget_show(text);
+
+ /* Add a vertical scrollbar to the GtkText widget */
+ vscrollbar = gtk_vscrollbar_new(GTK_TEXT(text)->vadj);
+ gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0);
+ gtk_widget_show(vscrollbar);
+
+ /* Freeze the text widget, ready for multiple updates */
+ gtk_text_freeze(GTK_TEXT(text));
+
+ /* Load the file text.c into the text window */
+ xsane_back_gtk_make_path(sizeof(filename), filename, "xsane", 0, "xsane-gpl", 0, ".txt", XSANE_PATH_SYSTEM);
+ infile = fopen(filename, "r");
+
+ if (infile)
+ {
+ char buffer[4096];
+ int nchars;
+
+ while (!feof(infile))
+ {
+ nchars = fread(buffer, 1, 4096, infile);
+ gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buffer, nchars);
+ }
+
+ fclose(infile);
+ }
+ else
+ {
+ DBG(DBG_error0, "ERROR: license text not found. Looks like xsane is not installed correct.\n");
+ return;
+ }
+
+ /* Thaw the text widget, allowing the updates to become visible */
+ gtk_text_thaw(GTK_TEXT(text));
+ }
+#endif
+
+
+
+ hbox = gtk_hbox_new(FALSE, 2);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+#ifdef HAVE_GTK2
+ button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+#else
+ button = gtk_button_new_with_label(BUTTON_CLOSE);
+#endif
+ gtk_widget_add_accelerator(button, "clicked", accelerator_group, GDK_Escape, 0, DEF_GTK_ACCEL_LOCKED);
+ GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_close_license_dialog_callback, (void *) 0 /* ok = accept */);
+ gtk_container_add(GTK_CONTAINER(hbox), button);
+ gtk_widget_grab_default(button);
+ gtk_widget_show(button);
+
+ gtk_widget_show(hbox);
+ gtk_widget_show(vbox);
+ gtk_widget_show(license_dialog);
}
/* ---------------------------------------------------------------------------------------------------------------------- */
-void xsane_widget_get_uposition(GtkWidget *gtk_window, gint *x, gint *y)
+void xsane_window_get_position(GtkWidget *gtk_window, gint *x, gint *y)
{
+#ifdef USE_GTK2_WINDOW_GET_POSITION
+ gtk_window_get_position(GTK_WINDOW(gtk_window), x, y);
+#else
if (xsane.get_deskrelative_origin)
{
- DBG(DBG_proc, "xsane_widget_get_uposition(deskrelative)\n");
+ DBG(DBG_proc, "xsane_window_get_position(deskrelative)\n");
gdk_window_get_deskrelative_origin(gtk_window->window, x, y);
}
else
{
- DBG(DBG_proc, "xsane_widget_get_uposition(root)\n");
+ DBG(DBG_proc, "xsane_window_get_position(root)\n");
gdk_window_get_root_origin(gtk_window->window, x, y);
}
+#endif
}
/* ---------------------------------------------------------------------------------------------------------------------- */
void xsane_widget_test_uposition(GtkWidget *gtk_window)
{
+#ifndef USE_GTK2_WINDOW_GET_POSITION
gint x, y, x_orig, y_orig;
DBG(DBG_proc, "xsane_widget_test_uposition\n");
@@ -1638,16 +2294,16 @@ void xsane_widget_test_uposition(GtkWidget *gtk_window)
gtk_main_iteration();
}
- xsane_widget_get_uposition(gtk_window, &x, &y);
- xsane_widget_get_uposition(gtk_window, &x, &y);
+ xsane_window_get_position(gtk_window, &x, &y);
+ xsane_window_get_position(gtk_window, &x, &y);
DBG(DBG_info, "xsane_widget_test_uposition: original position = %d, %d\n", x, y);
x_orig = x;
y_orig = y;
- gtk_widget_set_uposition(gtk_window, x, y);
+ gtk_window_move(GTK_WINDOW(gtk_window), x, y);
- xsane_widget_get_uposition(gtk_window, &x, &y);
+ xsane_window_get_position(gtk_window, &x, &y);
DBG(DBG_info, "xsane_widget_test_uposition: new position = %d, %d\n", x, y);
if ( (x != x_orig) || (y != y_orig) )
@@ -1659,6 +2315,132 @@ void xsane_widget_test_uposition(GtkWidget *gtk_window)
{
DBG(DBG_proc, "xsane_widget_test_uposition: using root function\n");
}
+#endif
}
/* ---------------------------------------------------------------------------------------------------------------------- */
+
+static int xsane_front_gtk_getname_button;
+
+static void xsane_front_gtk_getname_button_callback(GtkWidget *widget, gpointer data)
+{
+ DBG(DBG_proc, "xsane_front_gtk_getname_button_callback\n");
+
+ xsane_front_gtk_getname_button = (int) data;
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+int xsane_front_gtk_getname_dialog(const char *dialog_title, const char *desc_text, char *oldname, char **newname)
+{
+ GtkWidget *getname_dialog;
+ GtkWidget *text;
+ GtkWidget *button;
+ GtkWidget *vbox, *hbox;
+ GtkAccelGroup *accelerator_group;
+ char buf[256];
+
+ DBG(DBG_proc, "xsane_getname_dialog, oldname = %s\n", oldname);
+
+ getname_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ xsane_set_window_icon(getname_dialog, 0);
+
+ /* set getname dialog */
+ gtk_window_set_position(GTK_WINDOW(getname_dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_resizable(GTK_WINDOW(getname_dialog), FALSE);
+ snprintf(buf, sizeof(buf), "%s %s", xsane.prog_name, dialog_title);
+ gtk_window_set_title(GTK_WINDOW(getname_dialog), buf);
+ g_signal_connect(GTK_OBJECT(getname_dialog), "delete_event", (GtkSignalFunc) xsane_front_gtk_getname_button_callback, (void *) -1);
+ gtk_widget_show(getname_dialog);
+
+ /* set the main vbox */
+ vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 0);
+ gtk_container_add(GTK_CONTAINER(getname_dialog), vbox);
+ gtk_widget_show(vbox);
+
+ /* set the main hbox */
+ hbox = gtk_hbox_new(FALSE, 0);
+ xsane_separator_new(vbox, 2);
+ gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
+ gtk_widget_show(hbox);
+
+ text = gtk_entry_new_with_max_length(64);
+ xsane_back_gtk_set_tooltip(xsane.tooltips, text, desc_text);
+ gtk_entry_set_text(GTK_ENTRY(text), oldname);
+ gtk_widget_set_size_request(text, 300, -1);
+ gtk_box_pack_start(GTK_BOX(vbox), text, TRUE, TRUE, 4);
+ gtk_widget_show(text);
+
+ accelerator_group = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(getname_dialog), accelerator_group);
+
+#ifdef HAVE_GTK2
+ button = gtk_button_new_from_stock(GTK_STOCK_OK);
+#else
+ button = gtk_button_new_with_label(BUTTON_OK);
+#endif
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_front_gtk_getname_button_callback, (void *) 1);
+ GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
+ gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+
+#ifdef HAVE_GTK2
+ button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
+#else
+ button = gtk_button_new_with_label(BUTTON_CANCEL);
+#endif
+ g_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) xsane_front_gtk_getname_button_callback, (void *) -1);
+ gtk_widget_add_accelerator(button, "clicked", accelerator_group, GDK_Escape, 0, DEF_GTK_ACCEL_LOCKED); /* ESC */
+ gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+
+ xsane_front_gtk_getname_button = 0;
+
+ while (xsane_front_gtk_getname_button == 0)
+ {
+ while (gtk_events_pending())
+ {
+ DBG(DBG_info, "xsane_getname_dialog: calling gtk_main_iteration\n");
+ gtk_main_iteration();
+ }
+ }
+
+ *newname = strdup(gtk_entry_get_text(GTK_ENTRY(text)));
+
+ gtk_widget_destroy(getname_dialog);
+
+ xsane_set_sensitivity(TRUE);
+
+ if (xsane_front_gtk_getname_button == 1) /* OK button has been pressed */
+ {
+ DBG(DBG_info, "renaming %s to %s\n", oldname, *newname);
+ return 0; /* OK */
+ }
+
+ return 1; /* Escape */
+}
+
+/* ---------------------------------------------------------------------------------------------------------------------- */
+#ifdef XSANE_ACTIVATE_MAIL
+void xsane_front_gtk_mail_project_update_lockfile_status()
+{
+ FILE *lockfile;
+ char filename[PATH_MAX];
+
+ snprintf(filename, sizeof(filename), "%s/lockfile", preferences.mail_project);
+ lockfile = fopen(filename, "wb");
+
+ if (lockfile)
+ {
+ fprintf(lockfile, "%s\n", xsane.mail_status); /* first line is status of mail */
+ fprintf(lockfile, "%3d\n", (int) (xsane.mail_progress_val * 100));
+ }
+
+ fclose(lockfile);
+}
+#endif
+/* ---------------------------------------------------------------------------------------------------------------------- */
+
+