Commit 7fd5b7c1 authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer
Browse files

This is mostly unit stuff and code cleanup

1999-03-12  Michael Natterer  <mitschel@cs.tu-berlin.de>

        This is mostly unit stuff and code cleanup

        * libgimp/gimpi.def: add some functions

        * libgimp/gimpsizeentry.[ch]: new function
        gimp_size_entry_set_refval_digits() which allows for float pixel
        input. SIGFPE bugfix from Yasuhiro Shirasaki
        <yasuhiro@awa.tohoku.ac.jp>, minor bugfixes.

        * libgimp/gimpunitmenu.[ch]: add a separator after "pixels",
        bugfixes.

        * app/interface.[ch]: split up the old query_string_box() into
        query_[string|int|float|size]_box(). All functions take an
        optional GtkObject* parameter and connect to that object's
        "destroy" signal, this fixes some segfaults. And a global
        s/container_border_width/container_set_border_width/

        * app/commands.s: grow, shrink, border, feather now use the
        query_size_box. Used MIN(xres,yres) for now for the pixel<->unit
        calculations. Fixed some memory leaks.

        * app/global_edit.c
        * app/gradient.c
        * app/palette.c
        * app/paths_dialog.c: changed the query_string_box() calls
parent 136d3b29
1999-03-12 Michael Natterer <mitschel@cs.tu-berlin.de>
This is mostly unit stuff and code cleanup
* libgimp/gimpi.def: add some functions
* libgimp/gimpsizeentry.[ch]: new function
gimp_size_entry_set_refval_digits() which allows for float pixel
input. SIGFPE bugfix from Yasuhiro Shirasaki
<yasuhiro@awa.tohoku.ac.jp>, minor bugfixes.
* libgimp/gimpunitmenu.[ch]: add a separator after "pixels",
bugfixes.
* app/interface.[ch]: split up the old query_string_box() into
query_[string|int|float|size]_box(). All functions take an
optional GtkObject* parameter and connect to that object's
"destroy" signal, this fixes some segfaults. And a global
s/container_border_width/container_set_border_width/
* app/commands.s: grow, shrink, border, feather now use the
query_size_box. Used MIN(xres,yres) for now for the pixel<->unit
calculations. Fixed some memory leaks.
* app/global_edit.c
* app/gradient.c
* app/palette.c
* app/paths_dialog.c: changed the query_string_box() calls
Thu Mar 11 19:42:12 CET 1999 Marc Lehmann <pcg@goof.com>
* configure.in, config.h.in: added test for _exit (mirrors the
......
......@@ -365,15 +365,16 @@ select_border_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%d", gimage_mask_border_radius);
query_string_box (N_("Border Selection"),
N_("Border selection by:"),
initial,
gimage_mask_border_callback, gdisp->gimage);
query_size_box (N_("Border Selection"),
N_("Border selection by:"),
gimage_mask_border_radius, 1, 32767, 0,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_border_callback,
gdisp->gimage);
}
void
......@@ -381,15 +382,16 @@ select_feather_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%f", gimage_mask_feather_radius);
query_string_box (N_("Feather Selection"),
N_("Feather selection by:"),
initial,
gimage_mask_feather_callback, gdisp->gimage);
query_size_box (N_("Feather Selection"),
N_("Feather selection by:"),
gimage_mask_feather_radius, 0, 32767, 3,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_feather_callback,
gdisp->gimage);
}
void
......@@ -397,13 +399,16 @@ select_grow_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%d", gimage_mask_grow_pixels);
query_string_box (_("Grow Selection"), _("Grow selection by:"), initial,
gimage_mask_grow_callback, gdisp->gimage);
query_size_box (_("Grow Selection"),
_("Grow selection by:"),
gimage_mask_grow_pixels, 1, 32767, 0,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_grow_callback,
gdisp->gimage);
}
void
......@@ -411,13 +416,16 @@ select_shrink_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%d", gimage_mask_shrink_pixels);
query_string_box (_("Shrink Selection"), _("Shrink selection by:"), initial,
gimage_mask_shrink_callback, gdisp->gimage);
query_size_box (_("Shrink Selection"),
_("Shrink selection by:"),
gimage_mask_shrink_pixels, 1, 32767, 0,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_shrink_callback,
gdisp->gimage);
}
void
......@@ -840,7 +848,6 @@ layers_lower_cmd_callback (GtkWidget *widget,
gimage_lower_layer (gdisp->gimage, gdisp->gimage->active_layer);
gdisplays_flush ();
}
int value;
void
layers_anchor_cmd_callback (GtkWidget *widget,
......@@ -1083,11 +1090,6 @@ dialogs_module_browser_cmd_callback (GtkWidget *widget,
}
/****************************************************/
/** LOCAL FUNCTIONS **/
/****************************************************/
/*********************/
/* Local functions */
/*********************/
......@@ -1183,12 +1185,10 @@ gimage_mask_feather_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage=GIMP_IMAGE(client_data);
double feather_radius;
GImage *gimage = GIMP_IMAGE (client_data);
feather_radius = atof (call_data);
gimage_mask_feather (gimage, feather_radius);
gimage_mask_feather (gimage, *(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -1198,14 +1198,10 @@ gimage_mask_border_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage;
int border_radius;
gimage=GIMP_IMAGE(client_data);
GImage *gimage = GIMP_IMAGE (client_data);
border_radius = atoi (call_data);
gimage_mask_border (gimage, border_radius);
gimage_mask_border (gimage, (int)*(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -1215,12 +1211,10 @@ gimage_mask_grow_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage=GIMP_IMAGE(client_data);
int grow_pixels;
grow_pixels = atoi (call_data);
GImage *gimage = GIMP_IMAGE (client_data);
gimage_mask_grow (gimage, grow_pixels);
gimage_mask_grow (gimage, (int)*(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -1230,17 +1224,9 @@ gimage_mask_shrink_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage=GIMP_IMAGE(client_data);
int shrink_pixels;
GImage *gimage = GIMP_IMAGE (client_data);
shrink_pixels = atoi (call_data);
gimage_mask_shrink (gimage, shrink_pixels);
gimage_mask_shrink (gimage, (int)*(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -365,15 +365,16 @@ select_border_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%d", gimage_mask_border_radius);
query_string_box (N_("Border Selection"),
N_("Border selection by:"),
initial,
gimage_mask_border_callback, gdisp->gimage);
query_size_box (N_("Border Selection"),
N_("Border selection by:"),
gimage_mask_border_radius, 1, 32767, 0,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_border_callback,
gdisp->gimage);
}
void
......@@ -381,15 +382,16 @@ select_feather_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%f", gimage_mask_feather_radius);
query_string_box (N_("Feather Selection"),
N_("Feather selection by:"),
initial,
gimage_mask_feather_callback, gdisp->gimage);
query_size_box (N_("Feather Selection"),
N_("Feather selection by:"),
gimage_mask_feather_radius, 0, 32767, 3,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_feather_callback,
gdisp->gimage);
}
void
......@@ -397,13 +399,16 @@ select_grow_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%d", gimage_mask_grow_pixels);
query_string_box (_("Grow Selection"), _("Grow selection by:"), initial,
gimage_mask_grow_callback, gdisp->gimage);
query_size_box (_("Grow Selection"),
_("Grow selection by:"),
gimage_mask_grow_pixels, 1, 32767, 0,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_grow_callback,
gdisp->gimage);
}
void
......@@ -411,13 +416,16 @@ select_shrink_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
char initial[16];
gdisp = gdisplay_active ();
sprintf (initial, "%d", gimage_mask_shrink_pixels);
query_string_box (_("Shrink Selection"), _("Shrink selection by:"), initial,
gimage_mask_shrink_callback, gdisp->gimage);
query_size_box (_("Shrink Selection"),
_("Shrink selection by:"),
gimage_mask_shrink_pixels, 1, 32767, 0,
gdisp->dot_for_dot ? UNIT_PIXEL : gdisp->gimage->unit,
MIN(gdisp->gimage->xresolution, gdisp->gimage->yresolution),
GTK_OBJECT (gdisp->gimage), gimage_mask_shrink_callback,
gdisp->gimage);
}
void
......@@ -840,7 +848,6 @@ layers_lower_cmd_callback (GtkWidget *widget,
gimage_lower_layer (gdisp->gimage, gdisp->gimage->active_layer);
gdisplays_flush ();
}
int value;
void
layers_anchor_cmd_callback (GtkWidget *widget,
......@@ -1083,11 +1090,6 @@ dialogs_module_browser_cmd_callback (GtkWidget *widget,
}
/****************************************************/
/** LOCAL FUNCTIONS **/
/****************************************************/
/*********************/
/* Local functions */
/*********************/
......@@ -1183,12 +1185,10 @@ gimage_mask_feather_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage=GIMP_IMAGE(client_data);
double feather_radius;
GImage *gimage = GIMP_IMAGE (client_data);
feather_radius = atof (call_data);
gimage_mask_feather (gimage, feather_radius);
gimage_mask_feather (gimage, *(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -1198,14 +1198,10 @@ gimage_mask_border_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage;
int border_radius;
gimage=GIMP_IMAGE(client_data);
GImage *gimage = GIMP_IMAGE (client_data);
border_radius = atoi (call_data);
gimage_mask_border (gimage, border_radius);
gimage_mask_border (gimage, (int)*(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -1215,12 +1211,10 @@ gimage_mask_grow_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage=GIMP_IMAGE(client_data);
int grow_pixels;
grow_pixels = atoi (call_data);
GImage *gimage = GIMP_IMAGE (client_data);
gimage_mask_grow (gimage, grow_pixels);
gimage_mask_grow (gimage, (int)*(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -1230,17 +1224,9 @@ gimage_mask_shrink_callback (GtkWidget *w,
gpointer client_data,
gpointer call_data)
{
GImage *gimage=GIMP_IMAGE(client_data);
int shrink_pixels;
GImage *gimage = GIMP_IMAGE (client_data);
shrink_pixels = atoi (call_data);
gimage_mask_shrink (gimage, shrink_pixels);
gimage_mask_shrink (gimage, (int)*(float*)call_data);
g_free (call_data);
gdisplays_flush ();
}
......@@ -698,7 +698,7 @@ named_edit_cut (void *gdisp_ptr)
query_string_box (N_("Cut Named"),
N_("Enter a name for this buffer"),
NULL,
NULL, GTK_OBJECT (gdisp->gimage),
cut_named_buffer_callback, gdisp);
return TRUE;
}
......@@ -729,7 +729,7 @@ named_edit_copy (void *gdisp_ptr)
query_string_box (N_("Copy Named"),
N_("Enter a name for this buffer"),
NULL,
NULL, GTK_OBJECT (gdisp->gimage),
copy_named_buffer_callback, gdisp);
return TRUE;
}
......
......@@ -698,7 +698,7 @@ named_edit_cut (void *gdisp_ptr)
query_string_box (N_("Cut Named"),
N_("Enter a name for this buffer"),
NULL,
NULL, GTK_OBJECT (gdisp->gimage),
cut_named_buffer_callback, gdisp);
return TRUE;
}
......@@ -729,7 +729,7 @@ named_edit_copy (void *gdisp_ptr)
query_string_box (N_("Copy Named"),
N_("Enter a name for this buffer"),
NULL,
NULL, GTK_OBJECT (gdisp->gimage),
copy_named_buffer_callback, gdisp);
return TRUE;
}
......
......@@ -40,6 +40,7 @@
#include "dialog_handler.h"
#include "session.h"
#include "tools.h"
#include "libgimp/gimpsizeentry.h"
#include "pixmaps.h"
......@@ -226,7 +227,7 @@ create_color_area (GtkWidget *parent)
gtk_widget_realize (frame);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_border_width (GTK_CONTAINER (alignment), 3);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 3);
gtk_container_add (GTK_CONTAINER (frame), alignment);
col_area = color_area_create (54, 42, default_pixmap, swap_pixmap);
......@@ -290,7 +291,7 @@ create_tools (GtkWidget *parent)
if (tool_info[j].icon_data)
{
tool_info[j].tool_widget = button = gtk_radio_button_new (group);
gtk_container_border_width (GTK_CONTAINER (button), 0);
gtk_container_set_border_width (GTK_CONTAINER (button), 0);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
......@@ -303,7 +304,7 @@ create_tools (GtkWidget *parent)
0, 0);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_border_width (GTK_CONTAINER (alignment), 0);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 0);
gtk_container_add (GTK_CONTAINER (button), alignment);
pixmap = create_pixmap_widget (table->window, tool_info[j].icon_data, 22, 22);
......@@ -486,7 +487,7 @@ create_toolbox ()
}
main_vbox = gtk_vbox_new (FALSE, 1);
gtk_container_border_width (GTK_CONTAINER (main_vbox), 1);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 1);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
gtk_widget_show (main_vbox);
......@@ -511,7 +512,7 @@ create_toolbox ()
vbox = gtk_vbox_new (FALSE, 1);
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
gtk_container_border_width (GTK_CONTAINER (vbox), 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
gtk_widget_show (vbox);
create_tools (vbox);
......@@ -618,7 +619,7 @@ create_display_shell (GDisplay* gdisp,
/* the vbox, table containing all widgets */
vbox = gtk_vbox_new(0,2);
gtk_container_add(GTK_CONTAINER (gdisp->shell), vbox);
gtk_container_border_width(GTK_CONTAINER (vbox), 2);
gtk_container_set_border_width(GTK_CONTAINER (vbox), 2);
/* the table widget is pretty stupid so we need 2 tables
or it treats rulers and canvas with equal weight when
......@@ -646,7 +647,7 @@ create_display_shell (GDisplay* gdisp,
gdisp);
arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
gtk_container_border_width (GTK_CONTAINER (gdisp->origin), 0);
gtk_container_set_border_width (GTK_CONTAINER (gdisp->origin), 0);
gtk_container_add (GTK_CONTAINER (gdisp->origin), arrow);
gdisp->hrule = gtk_hruler_new ();
......@@ -792,7 +793,7 @@ create_display_shell (GDisplay* gdisp,
/*
* A text string query box
* String, integer, float and size query boxes
*/
typedef struct _QueryBox QueryBox;
......@@ -800,19 +801,30 @@ typedef struct _QueryBox QueryBox;
struct _QueryBox
{
GtkWidget *qbox;
GtkWidget *vbox;
GtkWidget *entry;
QueryFunc callback;
gpointer data;
GtkWidget *ok_button;
GtkObject *object;
QueryFunc callback;
gpointer data;
};
static void query_box_cancel_callback (GtkWidget *, gpointer);
static void query_box_ok_callback (GtkWidget *, gpointer);
static QueryBox * create_query_box (char *, char *, GtkObject *, QueryFunc,
gpointer);
static gint query_box_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void query_box_cancel_callback (GtkWidget *, gpointer);
static void string_query_box_ok_callback (GtkWidget *, gpointer);
static void int_query_box_ok_callback (GtkWidget *, gpointer);
static void float_query_box_ok_callback (GtkWidget *, gpointer);
static void size_query_box_ok_callback (GtkWidget *, gpointer);
GtkWidget *
query_string_box (char *title,
/* create a generic query box without any entry widget
*/
QueryBox *
create_query_box (char *title,
char *message,
char *initial,
GtkObject *object,
QueryFunc callback,
gpointer data)
{
......@@ -820,7 +832,7 @@ query_string_box (char *title,
GtkWidget *qbox;
GtkWidget *vbox;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *ok_button;
GtkWidget *button;
query_box = (QueryBox *) g_malloc (sizeof (QueryBox));
......@@ -833,27 +845,36 @@ query_string_box (char *title,
(GtkSignalFunc) query_box_delete_callback,
query_box);
gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (qbox)->action_area), 2);
/* if we are associated with an object, connect to that object's
* "destroy" signal
*/
if (object && GTK_IS_OBJECT (object))
gtk_signal_connect (GTK_OBJECT (object), "destroy",
(GtkSignalFunc) query_box_cancel_callback,
query_box);
else
object = NULL;
button = gtk_button_new_with_label (_("OK"));
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) query_box_ok_callback,
query_box);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (qbox)->action_area), button, TRUE, TRUE, 0);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (qbox)->action_area), 2);
ok_button = gtk_button_new_with_label (_("OK"));
GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (qbox)->action_area), ok_button,
TRUE, TRUE, 0);
gtk_widget_grab_default (ok_button);
gtk_widget_show (ok_button);
button = gtk_button_new_with_label (_("Cancel"));
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) query_box_cancel_callback,
query_box);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (qbox)->action_area), button, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (qbox)->action_area), button,
TRUE, TRUE, 0);
gtk_widget_show (button);
vbox = gtk_vbox_new (FALSE, 1);
gtk_container_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (qbox)->vbox), vbox);
gtk_widget_show (vbox);
......@@ -861,22 +882,156 @@ query_string_box (char *title,
gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0);
gtk_widget_show (label);
query_box->qbox = qbox;
query_box->vbox = vbox;
query_box->entry = NULL;
query_box->ok_button = ok_button;
query_box->object = object;
query_box->callback = callback;
query_box->data = data;
return query_box;
}
GtkWidget *
query_string_box (char *title,
char *message,
char *initial,
GtkObject *object,
QueryFunc callback,
gpointer data)
{
QueryBox *query_box;
GtkWidget *entry;
query_box = create_query_box (title, message, object, callback, data);
gtk_signal_connect (GTK_OBJECT (query_box->ok_button), "clicked",
(GtkSignalFunc) string_query_box_ok_callback,
query_box);
entry = gtk_entry_new ();
gtk_box_pack_start