diff --git a/ChangeLog b/ChangeLog index 319516aa5b..41548e19a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-04-20 Michael Natterer + + * 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 * plug-ins/common/bumpmap.c (bumpmap_dialog): restrict scale for diff --git a/libgimp/gimpfileselection.c b/libgimp/gimpfileselection.c index 57b6ee6cf2..1215f1fa9e 100644 --- a/libgimp/gimpfileselection.c +++ b/libgimp/gimpfileselection.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * * gimpfileselection.c - * Copyright (C) 1999 Michael Natterer + * Copyright (C) 1999-2000 Michael Natterer * * 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); diff --git a/libgimp/gimpfileselection.h b/libgimp/gimpfileselection.h index 631c453c7e..628564067c 100644 --- a/libgimp/gimpfileselection.h +++ b/libgimp/gimpfileselection.h @@ -25,8 +25,6 @@ #include -#include "gimppixmap.h" - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -42,18 +40,22 @@ typedef struct _GimpFileSelectionClass GimpFileSelectionClass; struct _GimpFileSelection { - GtkHBox hbox; + GtkHBox hbox; - GtkWidget *yes_pixmap; - GtkWidget *no_pixmap; - GtkWidget *entry; - GtkWidget *browse_button; + GtkWidget *file_exists; + GtkWidget *entry; + GtkWidget *browse_button; - GtkWidget *file_selection; + GtkWidget *file_selection; - gchar *title; - gboolean dir_only; - gboolean check_valid; + GdkPixmap *yes_pixmap; + GdkBitmap *yes_mask; + GdkPixmap *no_pixmap; + GdkBitmap *no_mask; + + gchar *title; + gboolean dir_only; + gboolean check_valid; }; struct _GimpFileSelectionClass diff --git a/libgimpwidgets/gimpfileentry.c b/libgimpwidgets/gimpfileentry.c index 57b6ee6cf2..1215f1fa9e 100644 --- a/libgimpwidgets/gimpfileentry.c +++ b/libgimpwidgets/gimpfileentry.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * * gimpfileselection.c - * Copyright (C) 1999 Michael Natterer + * Copyright (C) 1999-2000 Michael Natterer * * 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); diff --git a/libgimpwidgets/gimpfileentry.h b/libgimpwidgets/gimpfileentry.h index 631c453c7e..628564067c 100644 --- a/libgimpwidgets/gimpfileentry.h +++ b/libgimpwidgets/gimpfileentry.h @@ -25,8 +25,6 @@ #include -#include "gimppixmap.h" - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -42,18 +40,22 @@ typedef struct _GimpFileSelectionClass GimpFileSelectionClass; struct _GimpFileSelection { - GtkHBox hbox; + GtkHBox hbox; - GtkWidget *yes_pixmap; - GtkWidget *no_pixmap; - GtkWidget *entry; - GtkWidget *browse_button; + GtkWidget *file_exists; + GtkWidget *entry; + GtkWidget *browse_button; - GtkWidget *file_selection; + GtkWidget *file_selection; - gchar *title; - gboolean dir_only; - gboolean check_valid; + GdkPixmap *yes_pixmap; + GdkBitmap *yes_mask; + GdkPixmap *no_pixmap; + GdkBitmap *no_mask; + + gchar *title; + gboolean dir_only; + gboolean check_valid; }; struct _GimpFileSelectionClass diff --git a/libgimpwidgets/gimpfileselection.c b/libgimpwidgets/gimpfileselection.c index 57b6ee6cf2..1215f1fa9e 100644 --- a/libgimpwidgets/gimpfileselection.c +++ b/libgimpwidgets/gimpfileselection.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * * gimpfileselection.c - * Copyright (C) 1999 Michael Natterer + * Copyright (C) 1999-2000 Michael Natterer * * 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); diff --git a/libgimpwidgets/gimpfileselection.h b/libgimpwidgets/gimpfileselection.h index 631c453c7e..628564067c 100644 --- a/libgimpwidgets/gimpfileselection.h +++ b/libgimpwidgets/gimpfileselection.h @@ -25,8 +25,6 @@ #include -#include "gimppixmap.h" - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -42,18 +40,22 @@ typedef struct _GimpFileSelectionClass GimpFileSelectionClass; struct _GimpFileSelection { - GtkHBox hbox; + GtkHBox hbox; - GtkWidget *yes_pixmap; - GtkWidget *no_pixmap; - GtkWidget *entry; - GtkWidget *browse_button; + GtkWidget *file_exists; + GtkWidget *entry; + GtkWidget *browse_button; - GtkWidget *file_selection; + GtkWidget *file_selection; - gchar *title; - gboolean dir_only; - gboolean check_valid; + GdkPixmap *yes_pixmap; + GdkBitmap *yes_mask; + GdkPixmap *no_pixmap; + GdkBitmap *no_mask; + + gchar *title; + gboolean dir_only; + gboolean check_valid; }; struct _GimpFileSelectionClass