using the GimpPixmap here was a bad idea because showing/hiding the pixmap

2000-04-20  Michael Natterer  <mitch@gimp.org>

	* libgimp/gimpfileselection.[ch]: using the GimpPixmap here was a
	bad idea because showing/hiding the pixmap widgets is no solution
	(somebody may call gtk_widget_show_all() and we suddenly see both
	pixmaps, eek).
	Reverted it to use GtkPixmap and gtk_pixmap_set().
This commit is contained in:
Michael Natterer 2000-04-20 15:48:00 +00:00 committed by Michael Natterer
parent 91d956d412
commit 66e1b6f680
7 changed files with 215 additions and 96 deletions

View File

@ -1,3 +1,11 @@
2000-04-20 Michael Natterer <mitch@gimp.org>
* libgimp/gimpfileselection.[ch]: using the GimpPixmap here was a
bad idea because showing/hiding the pixmap widgets is no solution
(somebody may call gtk_widget_show_all() and we suddenly see both
pixmaps, eek).
Reverted it to use GtkPixmap and gtk_pixmap_set().
2000-04-20 Jens Lautenbacher <jtl@schlund.de>
* plug-ins/common/bumpmap.c (bumpmap_dialog): restrict scale for

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpfileselection.c
* Copyright (C) 1999 Michael Natterer <mitch@gimp.org>
* Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -47,6 +47,7 @@
#endif
/* callbacks */
static void gimp_file_selection_realize (GtkWidget *widget);
static void gimp_file_selection_entry_callback (GtkWidget *widget,
gpointer data);
static gint gimp_file_selection_entry_focus_out_callback (GtkWidget *widget,
@ -84,6 +85,16 @@ gimp_file_selection_destroy (GtkObject *object)
if (gfs->title)
g_free (gfs->title);
if (gfs->yes_pixmap)
gdk_pixmap_unref (gfs->yes_pixmap);
if (gfs->yes_mask)
gdk_bitmap_unref (gfs->yes_mask);
if (gfs->no_pixmap)
gdk_pixmap_unref (gfs->no_pixmap);
if (gfs->no_mask)
gdk_bitmap_unref (gfs->no_mask);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
@ -92,8 +103,10 @@ static void
gimp_file_selection_class_init (GimpFileSelectionClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_hbox_get_type ());
@ -111,6 +124,8 @@ gimp_file_selection_class_init (GimpFileSelectionClass *class)
class->filename_changed = NULL;
object_class->destroy = gimp_file_selection_destroy;
widget_class->realize = gimp_file_selection_realize;
}
static void
@ -120,8 +135,11 @@ gimp_file_selection_init (GimpFileSelection *gfs)
gfs->file_selection = NULL;
gfs->check_valid = FALSE;
gfs->file_exists = NULL;
gfs->yes_pixmap = NULL;
gfs->yes_mask = NULL;
gfs->no_pixmap = NULL;
gfs->no_mask = NULL;
gtk_box_set_spacing (GTK_BOX (gfs), 2);
gtk_box_set_homogeneous (GTK_BOX (gfs), FALSE);
@ -196,17 +214,6 @@ gimp_file_selection_new (gchar *title,
gfs->dir_only = dir_only;
gfs->check_valid = check_valid;
if (check_valid)
{
gfs->yes_pixmap = gimp_pixmap_new (yes_xpm);
gtk_box_pack_start (GTK_BOX (gfs), gfs->yes_pixmap, FALSE, FALSE, 0);
/* don't show */
gfs->no_pixmap = gimp_pixmap_new (no_xpm);
gtk_box_pack_start (GTK_BOX (gfs), gfs->no_pixmap, FALSE, FALSE, 0);
gtk_widget_show (gfs->no_pixmap);
}
gimp_file_selection_set_filename (gfs, filename);
return GTK_WIDGET (gfs);
@ -254,6 +261,37 @@ gimp_file_selection_set_filename (GimpFileSelection *gfs,
gimp_file_selection_entry_callback (gfs->entry, (gpointer) gfs);
}
static void
gimp_file_selection_realize (GtkWidget *widget)
{
GimpFileSelection *gfs;
GtkStyle *style;
gfs = GIMP_FILE_SELECTION (widget);
if (! gfs->check_valid)
return;
if (GTK_WIDGET_CLASS (parent_class)->realize)
(* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
style = gtk_widget_get_style (widget);
gfs->yes_pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&gfs->yes_mask,
&style->bg[GTK_STATE_NORMAL],
yes_xpm);
gfs->no_pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&gfs->no_mask,
&style->bg[GTK_STATE_NORMAL],
no_xpm);
gfs->file_exists = gtk_pixmap_new (gfs->no_pixmap, gfs->no_mask);
gtk_box_pack_start (GTK_BOX (gfs), gfs->file_exists, FALSE, FALSE, 0);
gimp_file_selection_check_filename (gfs);
gtk_widget_show (gfs->file_exists);
}
static void
gimp_file_selection_entry_callback (GtkWidget *widget,
gpointer data)
@ -400,23 +438,20 @@ gimp_file_selection_check_filename (GimpFileSelection *gfs)
if (! gfs->check_valid)
return;
if (gfs->yes_pixmap == NULL || gfs->no_pixmap == NULL)
if (gfs->file_exists == NULL)
return;
filename = gtk_editable_get_chars (GTK_EDITABLE (gfs->entry), 0, -1);
if ((stat (filename, &statbuf) == 0) &&
(gfs->dir_only ? S_ISDIR (statbuf.st_mode) : S_ISREG (statbuf.st_mode)))
{
if (GTK_WIDGET_VISIBLE (gfs->no_pixmap))
{
gtk_widget_hide (gfs->no_pixmap);
gtk_widget_show (gfs->yes_pixmap);
gtk_pixmap_set (GTK_PIXMAP (gfs->file_exists),
gfs->yes_pixmap, gfs->yes_mask);
}
}
else if (GTK_WIDGET_VISIBLE (gfs->yes_pixmap))
else
{
gtk_widget_hide (gfs->yes_pixmap);
gtk_widget_show (gfs->no_pixmap);
gtk_pixmap_set (GTK_PIXMAP (gfs->file_exists),
gfs->no_pixmap, gfs->no_mask);
}
g_free (filename);

View File

@ -25,8 +25,6 @@
#include <gtk/gtk.h>
#include "gimppixmap.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -44,13 +42,17 @@ struct _GimpFileSelection
{
GtkHBox hbox;
GtkWidget *yes_pixmap;
GtkWidget *no_pixmap;
GtkWidget *file_exists;
GtkWidget *entry;
GtkWidget *browse_button;
GtkWidget *file_selection;
GdkPixmap *yes_pixmap;
GdkBitmap *yes_mask;
GdkPixmap *no_pixmap;
GdkBitmap *no_mask;
gchar *title;
gboolean dir_only;
gboolean check_valid;

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpfileselection.c
* Copyright (C) 1999 Michael Natterer <mitch@gimp.org>
* Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -47,6 +47,7 @@
#endif
/* callbacks */
static void gimp_file_selection_realize (GtkWidget *widget);
static void gimp_file_selection_entry_callback (GtkWidget *widget,
gpointer data);
static gint gimp_file_selection_entry_focus_out_callback (GtkWidget *widget,
@ -84,6 +85,16 @@ gimp_file_selection_destroy (GtkObject *object)
if (gfs->title)
g_free (gfs->title);
if (gfs->yes_pixmap)
gdk_pixmap_unref (gfs->yes_pixmap);
if (gfs->yes_mask)
gdk_bitmap_unref (gfs->yes_mask);
if (gfs->no_pixmap)
gdk_pixmap_unref (gfs->no_pixmap);
if (gfs->no_mask)
gdk_bitmap_unref (gfs->no_mask);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
@ -92,8 +103,10 @@ static void
gimp_file_selection_class_init (GimpFileSelectionClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_hbox_get_type ());
@ -111,6 +124,8 @@ gimp_file_selection_class_init (GimpFileSelectionClass *class)
class->filename_changed = NULL;
object_class->destroy = gimp_file_selection_destroy;
widget_class->realize = gimp_file_selection_realize;
}
static void
@ -120,8 +135,11 @@ gimp_file_selection_init (GimpFileSelection *gfs)
gfs->file_selection = NULL;
gfs->check_valid = FALSE;
gfs->file_exists = NULL;
gfs->yes_pixmap = NULL;
gfs->yes_mask = NULL;
gfs->no_pixmap = NULL;
gfs->no_mask = NULL;
gtk_box_set_spacing (GTK_BOX (gfs), 2);
gtk_box_set_homogeneous (GTK_BOX (gfs), FALSE);
@ -196,17 +214,6 @@ gimp_file_selection_new (gchar *title,
gfs->dir_only = dir_only;
gfs->check_valid = check_valid;
if (check_valid)
{
gfs->yes_pixmap = gimp_pixmap_new (yes_xpm);
gtk_box_pack_start (GTK_BOX (gfs), gfs->yes_pixmap, FALSE, FALSE, 0);
/* don't show */
gfs->no_pixmap = gimp_pixmap_new (no_xpm);
gtk_box_pack_start (GTK_BOX (gfs), gfs->no_pixmap, FALSE, FALSE, 0);
gtk_widget_show (gfs->no_pixmap);
}
gimp_file_selection_set_filename (gfs, filename);
return GTK_WIDGET (gfs);
@ -254,6 +261,37 @@ gimp_file_selection_set_filename (GimpFileSelection *gfs,
gimp_file_selection_entry_callback (gfs->entry, (gpointer) gfs);
}
static void
gimp_file_selection_realize (GtkWidget *widget)
{
GimpFileSelection *gfs;
GtkStyle *style;
gfs = GIMP_FILE_SELECTION (widget);
if (! gfs->check_valid)
return;
if (GTK_WIDGET_CLASS (parent_class)->realize)
(* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
style = gtk_widget_get_style (widget);
gfs->yes_pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&gfs->yes_mask,
&style->bg[GTK_STATE_NORMAL],
yes_xpm);
gfs->no_pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&gfs->no_mask,
&style->bg[GTK_STATE_NORMAL],
no_xpm);
gfs->file_exists = gtk_pixmap_new (gfs->no_pixmap, gfs->no_mask);
gtk_box_pack_start (GTK_BOX (gfs), gfs->file_exists, FALSE, FALSE, 0);
gimp_file_selection_check_filename (gfs);
gtk_widget_show (gfs->file_exists);
}
static void
gimp_file_selection_entry_callback (GtkWidget *widget,
gpointer data)
@ -400,23 +438,20 @@ gimp_file_selection_check_filename (GimpFileSelection *gfs)
if (! gfs->check_valid)
return;
if (gfs->yes_pixmap == NULL || gfs->no_pixmap == NULL)
if (gfs->file_exists == NULL)
return;
filename = gtk_editable_get_chars (GTK_EDITABLE (gfs->entry), 0, -1);
if ((stat (filename, &statbuf) == 0) &&
(gfs->dir_only ? S_ISDIR (statbuf.st_mode) : S_ISREG (statbuf.st_mode)))
{
if (GTK_WIDGET_VISIBLE (gfs->no_pixmap))
{
gtk_widget_hide (gfs->no_pixmap);
gtk_widget_show (gfs->yes_pixmap);
gtk_pixmap_set (GTK_PIXMAP (gfs->file_exists),
gfs->yes_pixmap, gfs->yes_mask);
}
}
else if (GTK_WIDGET_VISIBLE (gfs->yes_pixmap))
else
{
gtk_widget_hide (gfs->yes_pixmap);
gtk_widget_show (gfs->no_pixmap);
gtk_pixmap_set (GTK_PIXMAP (gfs->file_exists),
gfs->no_pixmap, gfs->no_mask);
}
g_free (filename);

View File

@ -25,8 +25,6 @@
#include <gtk/gtk.h>
#include "gimppixmap.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -44,13 +42,17 @@ struct _GimpFileSelection
{
GtkHBox hbox;
GtkWidget *yes_pixmap;
GtkWidget *no_pixmap;
GtkWidget *file_exists;
GtkWidget *entry;
GtkWidget *browse_button;
GtkWidget *file_selection;
GdkPixmap *yes_pixmap;
GdkBitmap *yes_mask;
GdkPixmap *no_pixmap;
GdkBitmap *no_mask;
gchar *title;
gboolean dir_only;
gboolean check_valid;

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpfileselection.c
* Copyright (C) 1999 Michael Natterer <mitch@gimp.org>
* Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -47,6 +47,7 @@
#endif
/* callbacks */
static void gimp_file_selection_realize (GtkWidget *widget);
static void gimp_file_selection_entry_callback (GtkWidget *widget,
gpointer data);
static gint gimp_file_selection_entry_focus_out_callback (GtkWidget *widget,
@ -84,6 +85,16 @@ gimp_file_selection_destroy (GtkObject *object)
if (gfs->title)
g_free (gfs->title);
if (gfs->yes_pixmap)
gdk_pixmap_unref (gfs->yes_pixmap);
if (gfs->yes_mask)
gdk_bitmap_unref (gfs->yes_mask);
if (gfs->no_pixmap)
gdk_pixmap_unref (gfs->no_pixmap);
if (gfs->no_mask)
gdk_bitmap_unref (gfs->no_mask);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
@ -92,8 +103,10 @@ static void
gimp_file_selection_class_init (GimpFileSelectionClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_hbox_get_type ());
@ -111,6 +124,8 @@ gimp_file_selection_class_init (GimpFileSelectionClass *class)
class->filename_changed = NULL;
object_class->destroy = gimp_file_selection_destroy;
widget_class->realize = gimp_file_selection_realize;
}
static void
@ -120,8 +135,11 @@ gimp_file_selection_init (GimpFileSelection *gfs)
gfs->file_selection = NULL;
gfs->check_valid = FALSE;
gfs->file_exists = NULL;
gfs->yes_pixmap = NULL;
gfs->yes_mask = NULL;
gfs->no_pixmap = NULL;
gfs->no_mask = NULL;
gtk_box_set_spacing (GTK_BOX (gfs), 2);
gtk_box_set_homogeneous (GTK_BOX (gfs), FALSE);
@ -196,17 +214,6 @@ gimp_file_selection_new (gchar *title,
gfs->dir_only = dir_only;
gfs->check_valid = check_valid;
if (check_valid)
{
gfs->yes_pixmap = gimp_pixmap_new (yes_xpm);
gtk_box_pack_start (GTK_BOX (gfs), gfs->yes_pixmap, FALSE, FALSE, 0);
/* don't show */
gfs->no_pixmap = gimp_pixmap_new (no_xpm);
gtk_box_pack_start (GTK_BOX (gfs), gfs->no_pixmap, FALSE, FALSE, 0);
gtk_widget_show (gfs->no_pixmap);
}
gimp_file_selection_set_filename (gfs, filename);
return GTK_WIDGET (gfs);
@ -254,6 +261,37 @@ gimp_file_selection_set_filename (GimpFileSelection *gfs,
gimp_file_selection_entry_callback (gfs->entry, (gpointer) gfs);
}
static void
gimp_file_selection_realize (GtkWidget *widget)
{
GimpFileSelection *gfs;
GtkStyle *style;
gfs = GIMP_FILE_SELECTION (widget);
if (! gfs->check_valid)
return;
if (GTK_WIDGET_CLASS (parent_class)->realize)
(* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
style = gtk_widget_get_style (widget);
gfs->yes_pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&gfs->yes_mask,
&style->bg[GTK_STATE_NORMAL],
yes_xpm);
gfs->no_pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&gfs->no_mask,
&style->bg[GTK_STATE_NORMAL],
no_xpm);
gfs->file_exists = gtk_pixmap_new (gfs->no_pixmap, gfs->no_mask);
gtk_box_pack_start (GTK_BOX (gfs), gfs->file_exists, FALSE, FALSE, 0);
gimp_file_selection_check_filename (gfs);
gtk_widget_show (gfs->file_exists);
}
static void
gimp_file_selection_entry_callback (GtkWidget *widget,
gpointer data)
@ -400,23 +438,20 @@ gimp_file_selection_check_filename (GimpFileSelection *gfs)
if (! gfs->check_valid)
return;
if (gfs->yes_pixmap == NULL || gfs->no_pixmap == NULL)
if (gfs->file_exists == NULL)
return;
filename = gtk_editable_get_chars (GTK_EDITABLE (gfs->entry), 0, -1);
if ((stat (filename, &statbuf) == 0) &&
(gfs->dir_only ? S_ISDIR (statbuf.st_mode) : S_ISREG (statbuf.st_mode)))
{
if (GTK_WIDGET_VISIBLE (gfs->no_pixmap))
{
gtk_widget_hide (gfs->no_pixmap);
gtk_widget_show (gfs->yes_pixmap);
gtk_pixmap_set (GTK_PIXMAP (gfs->file_exists),
gfs->yes_pixmap, gfs->yes_mask);
}
}
else if (GTK_WIDGET_VISIBLE (gfs->yes_pixmap))
else
{
gtk_widget_hide (gfs->yes_pixmap);
gtk_widget_show (gfs->no_pixmap);
gtk_pixmap_set (GTK_PIXMAP (gfs->file_exists),
gfs->no_pixmap, gfs->no_mask);
}
g_free (filename);

View File

@ -25,8 +25,6 @@
#include <gtk/gtk.h>
#include "gimppixmap.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -44,13 +42,17 @@ struct _GimpFileSelection
{
GtkHBox hbox;
GtkWidget *yes_pixmap;
GtkWidget *no_pixmap;
GtkWidget *file_exists;
GtkWidget *entry;
GtkWidget *browse_button;
GtkWidget *file_selection;
GdkPixmap *yes_pixmap;
GdkBitmap *yes_mask;
GdkPixmap *no_pixmap;
GdkBitmap *no_mask;
gchar *title;
gboolean dir_only;
gboolean check_valid;