2001-01-22 05:29:31 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-02-04 12:51:17 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
#include "gui-types.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimppalette.h"
|
|
|
|
#include "core/gimppalette-import.h"
|
|
|
|
|
2002-04-15 01:28:58 +08:00
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
#include "widgets/gimpcontainermenuimpl.h"
|
|
|
|
#include "widgets/gimppreview.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gradient-select.h"
|
|
|
|
#include "palette-import-dialog.h"
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
#define IMPORT_PREVIEW_SIZE 80
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
GRADIENT_IMPORT,
|
|
|
|
IMAGE_IMPORT
|
2001-01-22 05:29:31 +08:00
|
|
|
} ImportType;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _ImportDialog ImportDialog;
|
|
|
|
|
|
|
|
struct _ImportDialog
|
|
|
|
{
|
2002-03-13 05:02:10 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
GimpContext *context;
|
|
|
|
GradientSelect *gradient_select;
|
|
|
|
ImportType import_type;
|
|
|
|
|
|
|
|
GtkWidget *select_area;
|
|
|
|
GtkWidget *preview;
|
|
|
|
GtkWidget *select_button;
|
|
|
|
GtkWidget *image_menu;
|
|
|
|
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *image_menu_item_image;
|
|
|
|
GtkWidget *image_menu_item_gradient;
|
|
|
|
GtkWidget *type_option;
|
|
|
|
GtkWidget *threshold_scale;
|
|
|
|
GtkWidget *threshold_text;
|
|
|
|
GtkAdjustment *threshold;
|
|
|
|
GtkAdjustment *sample;
|
2001-01-22 05:29:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ImportDialog *import_dialog = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* palette import dialog functions *****************************************/
|
|
|
|
|
|
|
|
/* functions to create & update the import dialog's gradient selection *****/
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_select_grad_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
ImportDialog *import_dialog;
|
2002-03-13 05:02:10 +08:00
|
|
|
GimpGradient *gradient;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
|
|
|
import_dialog = (ImportDialog *) data;
|
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
gradient = gimp_context_get_gradient (import_dialog->context);
|
|
|
|
|
|
|
|
import_dialog->gradient_select =
|
|
|
|
gradient_select_new (import_dialog->context->gimp,
|
|
|
|
import_dialog->context,
|
|
|
|
_("Select a Gradient to Create a Palette from"),
|
|
|
|
GIMP_OBJECT (gradient)->name,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (import_dialog->gradient_select->shell),
|
|
|
|
(gpointer *) &import_dialog->gradient_select);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_gradient_changed (GimpContext *context,
|
|
|
|
GimpGradient *gradient,
|
|
|
|
gpointer data)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
ImportDialog *import_dialog;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog = (ImportDialog *) data;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
if (gradient && import_dialog->import_type == GRADIENT_IMPORT)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
gimp_preview_set_viewable (GIMP_PREVIEW (import_dialog->preview),
|
|
|
|
GIMP_VIEWABLE (gradient));
|
2001-02-11 03:35:29 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry),
|
|
|
|
GIMP_OBJECT (gradient)->name);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_image_changed (GimpContext *context,
|
|
|
|
GimpImage *gimage,
|
|
|
|
gpointer data)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
ImportDialog *import_dialog;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog = (ImportDialog *) data;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
if (gimage && import_dialog->import_type == IMAGE_IMPORT)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
gchar *basename;
|
|
|
|
gchar *label;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gimp_preview_set_viewable (GIMP_PREVIEW (import_dialog->preview),
|
|
|
|
GIMP_VIEWABLE (gimage));
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-04-15 01:28:58 +08:00
|
|
|
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
|
2001-12-18 07:41:01 +08:00
|
|
|
label = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
|
|
|
|
g_free (basename);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry), label);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
g_free (label);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the import source menu item callbacks ***********************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_grad_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
ImportDialog *import_dialog;
|
|
|
|
GimpGradient *gradient;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog = (ImportDialog *) data;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gradient = gimp_context_get_gradient (import_dialog->context);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->import_type = GRADIENT_IMPORT;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_widget_hide (import_dialog->image_menu);
|
|
|
|
gtk_widget_show (import_dialog->select_button);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_widget_destroy (import_dialog->preview);
|
|
|
|
|
|
|
|
import_dialog->preview = gimp_preview_new_full (GIMP_VIEWABLE (gradient),
|
|
|
|
IMPORT_PREVIEW_SIZE,
|
|
|
|
IMPORT_PREVIEW_SIZE,
|
|
|
|
1, FALSE, FALSE, FALSE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (import_dialog->select_area),
|
|
|
|
import_dialog->preview,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (import_dialog->select_area),
|
|
|
|
import_dialog->preview, 0);
|
|
|
|
gtk_widget_show (import_dialog->preview);
|
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry),
|
|
|
|
GIMP_OBJECT (gradient)->name);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->threshold_scale, FALSE);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->threshold_text, FALSE);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_image_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
ImportDialog *import_dialog;
|
2001-12-18 07:41:01 +08:00
|
|
|
GimpImage *gimage;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
|
|
|
import_dialog = (ImportDialog *) data;
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gimage = gimp_context_get_image (import_dialog->context);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
if (! gimage)
|
|
|
|
{
|
|
|
|
gimage = (GimpImage *)
|
|
|
|
gimp_container_get_child_by_index (import_dialog->context->gimp->images, 0);
|
|
|
|
}
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->import_type = IMAGE_IMPORT;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_widget_hide (import_dialog->select_button);
|
|
|
|
gtk_widget_show (import_dialog->image_menu);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_widget_destroy (import_dialog->preview);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->preview = gimp_preview_new_full (GIMP_VIEWABLE (gimage),
|
|
|
|
IMPORT_PREVIEW_SIZE,
|
|
|
|
IMPORT_PREVIEW_SIZE,
|
|
|
|
1, FALSE, FALSE, FALSE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (import_dialog->select_area),
|
|
|
|
import_dialog->preview,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (import_dialog->select_area),
|
|
|
|
import_dialog->preview, 0);
|
|
|
|
gtk_widget_show (import_dialog->preview);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_widget_set_sensitive (import_dialog->threshold_scale, TRUE);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->threshold_text, TRUE);
|
|
|
|
}
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
/* functions & callbacks to keep the import dialog uptodate ****************/
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_image_add (GimpContainer *container,
|
2001-02-04 06:05:41 +08:00
|
|
|
GimpImage *gimage,
|
|
|
|
gpointer data)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
ImportDialog *import_dialog;
|
|
|
|
|
|
|
|
import_dialog = (ImportDialog *) data;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
if (! GTK_WIDGET_IS_SENSITIVE (import_dialog->image_menu_item_image))
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (import_dialog->image_menu_item_image, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_image_remove (GimpContainer *container,
|
|
|
|
GimpImage *gimage,
|
|
|
|
gpointer data)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
ImportDialog *import_dialog;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog = (ImportDialog *) data;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
if (! gimp_container_num_children (import_dialog->context->gimp->images))
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
gimp_option_menu_set_history (GTK_OPTION_MENU (import_dialog->type_option),
|
|
|
|
GINT_TO_POINTER (GRADIENT_IMPORT));
|
|
|
|
gtk_widget_set_sensitive (import_dialog->image_menu_item_image, FALSE);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_grad_callback (NULL, import_dialog);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the palette import action area callbacks ********************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_close_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2002-03-13 05:02:10 +08:00
|
|
|
if (import_dialog->gradient_select)
|
|
|
|
gradient_select_free (import_dialog->gradient_select);
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
gtk_widget_destroy (import_dialog->dialog);
|
|
|
|
g_free (import_dialog);
|
|
|
|
import_dialog = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_import_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
ImportDialog *import_dialog;
|
2001-02-20 02:07:08 +08:00
|
|
|
GimpPalette *palette = NULL;
|
|
|
|
gchar *palette_name;
|
|
|
|
GimpGradient *gradient;
|
2001-12-18 07:41:01 +08:00
|
|
|
GimpImage *gimage;
|
2001-02-20 02:07:08 +08:00
|
|
|
gint n_colors;
|
|
|
|
gint threshold;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
import_dialog = (ImportDialog *) data;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-07-25 08:42:47 +08:00
|
|
|
palette_name = (gchar *) gtk_entry_get_text (GTK_ENTRY (import_dialog->entry));
|
2001-02-20 02:07:08 +08:00
|
|
|
|
|
|
|
if (! (palette_name && strlen (palette_name)))
|
2002-01-15 02:54:06 +08:00
|
|
|
palette_name = g_strdup (_("Untitled"));
|
2001-01-22 05:29:31 +08:00
|
|
|
else
|
2001-02-20 02:07:08 +08:00
|
|
|
palette_name = g_strdup (palette_name);
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gradient = gimp_context_get_gradient (import_dialog->context);
|
|
|
|
gimage = gimp_context_get_image (import_dialog->context);
|
|
|
|
|
2001-02-20 02:07:08 +08:00
|
|
|
n_colors = (gint) import_dialog->sample->value;
|
|
|
|
threshold = (gint) import_dialog->threshold->value;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
switch (import_dialog->import_type)
|
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
case GRADIENT_IMPORT:
|
2001-02-20 02:07:08 +08:00
|
|
|
palette = gimp_palette_import_from_gradient (gradient,
|
|
|
|
palette_name,
|
|
|
|
n_colors);
|
2001-01-22 05:29:31 +08:00
|
|
|
break;
|
2001-02-20 02:07:08 +08:00
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
case IMAGE_IMPORT:
|
2001-12-18 07:41:01 +08:00
|
|
|
if (gimp_image_base_type (gimage) == GIMP_INDEXED)
|
|
|
|
{
|
|
|
|
palette = gimp_palette_import_from_image (gimage,
|
|
|
|
palette_name,
|
|
|
|
n_colors,
|
|
|
|
threshold);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
palette =
|
|
|
|
gimp_palette_import_from_indexed_image (gimage,
|
|
|
|
palette_name);
|
|
|
|
}
|
2001-01-22 05:29:31 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-20 02:07:08 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
|
|
|
|
if (palette)
|
2001-12-18 07:41:01 +08:00
|
|
|
gimp_container_add (import_dialog->context->gimp->palette_factory->container,
|
2001-02-20 02:07:08 +08:00
|
|
|
GIMP_OBJECT (palette));
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
palette_import_close_callback (NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the palette import dialog constructor ***********************************/
|
|
|
|
|
|
|
|
static ImportDialog *
|
2001-10-29 19:47:11 +08:00
|
|
|
palette_import_dialog_new (Gimp *gimp)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
ImportDialog *import_dialog;
|
|
|
|
GimpGradient *gradient;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *hbox2;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkWidget *menu;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gradient = gimp_context_get_gradient (gimp_get_user_context (gimp));
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog = g_new0 (ImportDialog, 1);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
import_dialog->context = gimp_context_new (gimp, "Palette Import",
|
|
|
|
gimp_get_user_context (gimp));
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->dialog =
|
2001-01-22 05:29:31 +08:00
|
|
|
gimp_dialog_new (_("Import Palette"), "import_palette",
|
2001-12-18 07:41:01 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
"dialogs/palette_editor/import_palette.html",
|
|
|
|
GTK_WIN_POS_NONE,
|
|
|
|
FALSE, TRUE, FALSE,
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
GTK_STOCK_CANCEL, palette_import_close_callback,
|
|
|
|
import_dialog, NULL, NULL, TRUE, TRUE,
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
_("Import"), palette_import_import_callback,
|
|
|
|
import_dialog, NULL, NULL, FALSE, FALSE,
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
NULL);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
/* The main hbox */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (import_dialog->dialog)->vbox),
|
|
|
|
hbox);
|
2001-01-22 05:29:31 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
/* The "Import" frame */
|
|
|
|
frame = gtk_frame_new (_("Import"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
table = gtk_table_new (4, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
/* The source's name */
|
|
|
|
label = gtk_label_new (_("Name:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->entry = gtk_entry_new ();
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), import_dialog->entry,
|
|
|
|
1, 2, 0, 1);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry),
|
|
|
|
gradient ? GIMP_OBJECT (gradient)->name : _("new_import"));
|
|
|
|
gtk_widget_show (import_dialog->entry);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
/* The source type */
|
|
|
|
label = gtk_label_new (_("Source:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->type_option =
|
|
|
|
gimp_option_menu_new (FALSE,
|
2001-07-25 08:42:47 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
_("Gradient"),
|
|
|
|
palette_import_grad_callback, import_dialog,
|
|
|
|
GINT_TO_POINTER (GRADIENT_IMPORT),
|
|
|
|
&import_dialog->image_menu_item_gradient,
|
|
|
|
TRUE,
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
_("Image"),
|
|
|
|
palette_import_image_callback, import_dialog,
|
|
|
|
GINT_TO_POINTER (IMAGE_IMPORT),
|
|
|
|
&import_dialog->image_menu_item_image,
|
|
|
|
FALSE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (import_dialog->image_menu_item_image,
|
|
|
|
gimp_container_num_children (gimp->images) > 0);
|
2001-07-25 08:42:47 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), import_dialog->type_option,
|
|
|
|
1, 2, 1, 2);
|
|
|
|
gtk_widget_show (import_dialog->type_option);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
/* The sample size */
|
|
|
|
label = gtk_label_new (_("Sample Size:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
import_dialog->sample =
|
|
|
|
GTK_ADJUSTMENT(gtk_adjustment_new (256, 2, 10000, 1, 10, 10));
|
|
|
|
spinbutton = gtk_spin_button_new (import_dialog->sample, 1, 0);
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), spinbutton, 1, 2, 2, 3);
|
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
|
|
|
|
/* The interval */
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->threshold_text = gtk_label_new (_("Interval:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (import_dialog->threshold_text), 1.0, 1.0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), import_dialog->threshold_text,
|
|
|
|
0, 1, 3, 4,
|
2001-01-22 05:29:31 +08:00
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_widget_set_sensitive (import_dialog->threshold_text, FALSE);
|
|
|
|
gtk_widget_show (import_dialog->threshold_text);
|
|
|
|
|
|
|
|
import_dialog->threshold = GTK_ADJUSTMENT (gtk_adjustment_new (1, 1, 128,
|
|
|
|
1, 1, 1));
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->threshold_scale = gtk_hscale_new (import_dialog->threshold);
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (import_dialog->threshold_scale),
|
|
|
|
GTK_POS_TOP);
|
|
|
|
gtk_scale_set_digits (GTK_SCALE (import_dialog->threshold_scale), 0);
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), import_dialog->threshold_scale,
|
|
|
|
1, 2, 3, 4);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->threshold_scale, FALSE);
|
|
|
|
gtk_widget_show (import_dialog->threshold_scale);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
/* The preview frame */
|
|
|
|
frame = gtk_frame_new (_("Preview"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
vbox = import_dialog->select_area = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->preview = gimp_preview_new_full (GIMP_VIEWABLE (gradient),
|
|
|
|
IMPORT_PREVIEW_SIZE,
|
|
|
|
IMPORT_PREVIEW_SIZE,
|
|
|
|
1, FALSE, FALSE, FALSE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), import_dialog->preview, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (import_dialog->preview);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->select_button = gtk_button_new_with_label (_("Select"));
|
|
|
|
GTK_WIDGET_UNSET_FLAGS (import_dialog->select_button, GTK_RECEIVES_DEFAULT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), import_dialog->select_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (import_dialog->select_button);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
g_signal_connect (G_OBJECT (import_dialog->select_button), "clicked",
|
2001-07-25 08:42:47 +08:00
|
|
|
G_CALLBACK (palette_import_select_grad_callback),
|
2001-10-29 19:47:11 +08:00
|
|
|
import_dialog);
|
2001-07-25 08:42:47 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
hbox2 = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox2);
|
|
|
|
|
|
|
|
import_dialog->image_menu = gtk_option_menu_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox2), import_dialog->image_menu, TRUE, TRUE, 0);
|
|
|
|
/* DON'T gtk_widget_show (import_dialog->image_menu); */
|
2001-07-25 08:42:47 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
menu = gimp_container_menu_new (gimp->images, import_dialog->context, 24);
|
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (import_dialog->image_menu), menu);
|
|
|
|
gtk_widget_show (menu);
|
|
|
|
|
|
|
|
import_dialog->import_type = GRADIENT_IMPORT;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
/* keep the dialog up-to-date */
|
2001-12-18 07:41:01 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
g_signal_connect (G_OBJECT (gimp->images), "add",
|
2001-12-18 07:41:01 +08:00
|
|
|
G_CALLBACK (palette_import_image_add),
|
|
|
|
import_dialog);
|
2001-10-29 19:47:11 +08:00
|
|
|
g_signal_connect (G_OBJECT (gimp->images), "remove",
|
2001-12-18 07:41:01 +08:00
|
|
|
G_CALLBACK (palette_import_image_remove),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->context), "gradient_changed",
|
|
|
|
G_CALLBACK (palette_import_gradient_changed),
|
|
|
|
import_dialog);
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->context), "image_changed",
|
|
|
|
G_CALLBACK (palette_import_image_changed),
|
|
|
|
import_dialog);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
return import_dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-29 19:47:11 +08:00
|
|
|
palette_import_dialog_show (Gimp *gimp)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
if (! import_dialog)
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog = palette_import_dialog_new (gimp);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
if (! GTK_WIDGET_VISIBLE (import_dialog->dialog))
|
|
|
|
{
|
|
|
|
gtk_widget_show (import_dialog->dialog);
|
|
|
|
}
|
|
|
|
else if (import_dialog->dialog->window)
|
|
|
|
{
|
|
|
|
gdk_window_raise (import_dialog->dialog->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
palette_import_dialog_destroy (void)
|
|
|
|
{
|
|
|
|
if (import_dialog)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (import_dialog->dialog);
|
|
|
|
g_free (import_dialog);
|
|
|
|
import_dialog = NULL;
|
|
|
|
}
|
|
|
|
}
|