2004-04-21 06:14:49 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2006-11-16 07:20:06 +08:00
|
|
|
* gimpitemcombobox.c
|
2004-04-21 06:14:49 +08:00
|
|
|
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
|
2006-11-16 07:20:06 +08:00
|
|
|
* Copyright (C) 2006 Simon Budig <simon@gimp.org>
|
2004-04-21 06:14:49 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2004-04-21 06:14:49 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2004-04-21 06:14:49 +08:00
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2004-04-21 06:14:49 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2005-03-26 22:05:03 +08:00
|
|
|
#include <stdlib.h>
|
2012-09-03 08:17:55 +08:00
|
|
|
#include <string.h>
|
2005-03-26 22:05:03 +08:00
|
|
|
|
2013-11-02 05:29:46 +08:00
|
|
|
#include <gegl.h>
|
2004-04-21 06:14:49 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
|
2005-06-04 07:38:45 +08:00
|
|
|
#include "gimpuitypes.h"
|
2006-11-16 07:20:06 +08:00
|
|
|
#include "gimpitemcombobox.h"
|
2004-04-21 06:14:49 +08:00
|
|
|
#include "gimppixbuf.h"
|
|
|
|
|
|
|
|
|
2010-07-07 17:48:10 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpitemcombobox
|
|
|
|
* @title: GimpItemComboBox
|
|
|
|
* @short_description: Widgets providing popup menus of items.
|
|
|
|
*
|
|
|
|
* Widgets providing popup menus of items (layers, channels,
|
2024-07-08 10:09:42 +08:00
|
|
|
* drawables, paths).
|
2010-07-07 17:48:10 +08:00
|
|
|
**/
|
|
|
|
|
|
|
|
|
2005-03-03 08:06:28 +08:00
|
|
|
#define THUMBNAIL_SIZE 24
|
|
|
|
#define WIDTH_REQUEST 200
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2006-11-16 07:20:06 +08:00
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
#define GET_PRIVATE(obj) (g_object_get_data (G_OBJECT (obj), "gimp-item-combo-box-private"))
|
2012-10-09 04:01:30 +08:00
|
|
|
|
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
typedef struct _GimpItemComboBoxPrivate GimpItemComboBoxPrivate;
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
struct _GimpItemComboBoxPrivate
|
2012-10-09 04:01:30 +08:00
|
|
|
{
|
|
|
|
GimpItemConstraintFunc constraint;
|
|
|
|
gpointer data;
|
|
|
|
};
|
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
typedef struct _GimpDrawableComboBoxClass GimpDrawableComboBoxClass;
|
|
|
|
typedef struct _GimpChannelComboBoxClass GimpChannelComboBoxClass;
|
|
|
|
typedef struct _GimpLayerComboBoxClass GimpLayerComboBoxClass;
|
2024-07-13 13:07:57 +08:00
|
|
|
typedef struct _GimpPathComboBoxClass GimpPathComboBoxClass;
|
2012-10-09 04:01:30 +08:00
|
|
|
|
2005-06-04 07:38:45 +08:00
|
|
|
struct _GimpDrawableComboBox
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBox parent_instance;
|
2005-06-04 07:38:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpDrawableComboBoxClass
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBoxClass parent_class;
|
2005-06-04 07:38:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpChannelComboBox
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBox parent_instance;
|
2005-06-04 07:38:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpChannelComboBoxClass
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBoxClass parent_class;
|
2005-06-04 07:38:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpLayerComboBox
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBox parent_instance;
|
2005-06-04 07:38:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpLayerComboBoxClass
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBoxClass parent_class;
|
2005-06-04 07:38:45 +08:00
|
|
|
};
|
|
|
|
|
2024-07-13 13:07:57 +08:00
|
|
|
struct _GimpPathComboBox
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBox parent_instance;
|
2006-11-16 07:20:06 +08:00
|
|
|
};
|
|
|
|
|
2024-07-13 13:07:57 +08:00
|
|
|
struct _GimpPathComboBoxClass
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBoxClass parent_class;
|
2006-11-16 07:20:06 +08:00
|
|
|
};
|
|
|
|
|
2005-06-04 07:38:45 +08:00
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
static GtkWidget * gimp_item_combo_box_new (GType type,
|
2006-11-16 07:20:06 +08:00
|
|
|
GimpItemConstraintFunc constraint,
|
2019-08-08 05:16:25 +08:00
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy);
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
static void gimp_item_combo_box_populate (GimpIntComboBox *combo_box);
|
|
|
|
static void gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
|
2012-10-09 04:01:30 +08:00
|
|
|
GtkListStore *store,
|
2019-08-11 23:12:20 +08:00
|
|
|
GimpImage *image,
|
2019-08-14 17:08:42 +08:00
|
|
|
GList *items,
|
2012-10-09 04:01:30 +08:00
|
|
|
gint tree_level);
|
2006-11-16 07:20:06 +08:00
|
|
|
|
|
|
|
static void gimp_item_combo_box_drag_data_received (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection,
|
|
|
|
guint info,
|
|
|
|
guint time);
|
2005-03-26 22:05:03 +08:00
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
static void gimp_item_combo_box_changed (GimpIntComboBox *combo_box);
|
2012-10-09 04:01:30 +08:00
|
|
|
|
2005-03-26 22:05:03 +08:00
|
|
|
|
|
|
|
static const GtkTargetEntry targets[] =
|
|
|
|
{
|
|
|
|
{ "application/x-gimp-channel-id", 0 },
|
2006-11-16 07:20:06 +08:00
|
|
|
{ "application/x-gimp-layer-id", 0 },
|
2024-07-13 13:07:57 +08:00
|
|
|
{ "application/x-gimp-path-id", 0 }
|
2005-03-26 22:05:03 +08:00
|
|
|
};
|
|
|
|
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
G_DEFINE_TYPE (GimpDrawableComboBox, gimp_drawable_combo_box,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_INT_COMBO_BOX)
|
|
|
|
|
2005-06-04 07:38:45 +08:00
|
|
|
static void
|
2012-10-11 05:10:56 +08:00
|
|
|
gimp_drawable_combo_box_class_init (GimpDrawableComboBoxClass *klass)
|
2005-06-04 07:38:45 +08:00
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2005-06-04 07:38:45 +08:00
|
|
|
|
2006-11-16 07:20:06 +08:00
|
|
|
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
|
2005-06-04 07:38:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_combo_box_init (GimpDrawableComboBox *combo_box)
|
|
|
|
{
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (combo_box),
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
targets, 2,
|
|
|
|
GDK_ACTION_COPY);
|
2012-10-11 05:10:56 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
|
|
|
|
g_new0 (GimpItemComboBoxPrivate, 1),
|
|
|
|
(GDestroyNotify) g_free);
|
2005-06-04 07:38:45 +08:00
|
|
|
}
|
|
|
|
|
2004-04-21 19:51:21 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_combo_box_new:
|
2021-03-20 23:37:30 +08:00
|
|
|
* @constraint: (nullable): A #GimpItemConstraintFunc or %NULL
|
|
|
|
* @data: (closure constraint): A pointer that is passed to @constraint
|
|
|
|
* @data_destroy: (destroy data): Destroy function for @data
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
|
|
|
* Creates a new #GimpIntComboBox filled with all currently opened
|
|
|
|
* drawables. If a @constraint function is specified, it is called for
|
|
|
|
* each drawable and only if the function returns %TRUE, the drawable
|
|
|
|
* is added to the combobox.
|
|
|
|
*
|
2004-12-13 20:38:26 +08:00
|
|
|
* You should use gimp_int_combo_box_connect() to initialize and connect
|
2004-10-29 04:58:16 +08:00
|
|
|
* the combo. Use gimp_int_combo_box_set_active() to get the active
|
|
|
|
* drawable ID and gimp_int_combo_box_get_active() to retrieve the ID
|
|
|
|
* of the selected drawable.
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-04-21 19:51:21 +08:00
|
|
|
**/
|
2004-04-21 06:14:49 +08:00
|
|
|
GtkWidget *
|
2019-08-08 05:16:25 +08:00
|
|
|
gimp_drawable_combo_box_new (GimpItemConstraintFunc constraint,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy)
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2012-10-09 04:01:30 +08:00
|
|
|
return gimp_item_combo_box_new (GIMP_TYPE_DRAWABLE_COMBO_BOX,
|
2019-08-08 05:16:25 +08:00
|
|
|
constraint, data, data_destroy);
|
2005-06-04 07:38:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
G_DEFINE_TYPE (GimpChannelComboBox, gimp_channel_combo_box,
|
2012-10-11 05:10:56 +08:00
|
|
|
GIMP_TYPE_INT_COMBO_BOX)
|
2005-06-04 07:38:45 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_channel_combo_box_class_init (GimpChannelComboBoxClass *klass)
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
|
2005-06-04 07:38:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_channel_combo_box_init (GimpChannelComboBox *combo_box)
|
|
|
|
{
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (combo_box),
|
2005-03-26 22:05:03 +08:00
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
2005-06-04 07:38:45 +08:00
|
|
|
targets, 1,
|
2005-03-26 22:05:03 +08:00
|
|
|
GDK_ACTION_COPY);
|
2012-10-11 05:10:56 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
|
|
|
|
g_new0 (GimpItemComboBoxPrivate, 1),
|
|
|
|
(GDestroyNotify) g_free);
|
2004-04-21 06:14:49 +08:00
|
|
|
}
|
|
|
|
|
2004-04-21 19:51:21 +08:00
|
|
|
/**
|
|
|
|
* gimp_channel_combo_box_new:
|
2021-03-20 23:37:30 +08:00
|
|
|
* @constraint: (nullable): A #GimpItemConstraintFunc or %NULL
|
|
|
|
* @data: (closure constraint): A pointer that is passed to @constraint
|
|
|
|
* @data_destroy: (destroy data): Destroy function for @data
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
|
|
|
* Creates a new #GimpIntComboBox filled with all currently opened
|
2008-06-03 21:46:50 +08:00
|
|
|
* channels. See gimp_drawable_combo_box_new() for more information.
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-04-21 19:51:21 +08:00
|
|
|
**/
|
2004-04-21 06:14:49 +08:00
|
|
|
GtkWidget *
|
2019-08-08 05:16:25 +08:00
|
|
|
gimp_channel_combo_box_new (GimpItemConstraintFunc constraint,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy)
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2012-10-09 04:01:30 +08:00
|
|
|
return gimp_item_combo_box_new (GIMP_TYPE_CHANNEL_COMBO_BOX,
|
2019-08-08 05:16:25 +08:00
|
|
|
constraint, data, data_destroy);
|
2005-06-04 07:38:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
G_DEFINE_TYPE (GimpLayerComboBox, gimp_layer_combo_box,
|
2012-10-11 05:10:56 +08:00
|
|
|
GIMP_TYPE_INT_COMBO_BOX)
|
2005-06-04 07:38:45 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_combo_box_class_init (GimpLayerComboBoxClass *klass)
|
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
|
2005-06-04 07:38:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_combo_box_init (GimpLayerComboBox *combo_box)
|
|
|
|
{
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (combo_box),
|
2005-03-26 22:05:03 +08:00
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
2005-06-04 07:38:45 +08:00
|
|
|
targets + 1, 1,
|
2005-03-26 22:05:03 +08:00
|
|
|
GDK_ACTION_COPY);
|
2012-10-11 05:10:56 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
|
|
|
|
g_new0 (GimpItemComboBoxPrivate, 1),
|
|
|
|
(GDestroyNotify) g_free);
|
2004-04-21 06:14:49 +08:00
|
|
|
}
|
|
|
|
|
2004-04-21 19:51:21 +08:00
|
|
|
/**
|
|
|
|
* gimp_layer_combo_box_new:
|
2021-03-20 23:37:30 +08:00
|
|
|
* @constraint: (nullable): A #GimpItemConstraintFunc or %NULL
|
|
|
|
* @data: (closure constraint): A pointer that is passed to @constraint
|
|
|
|
* @data_destroy: (destroy data): Destroy function for @data
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
|
|
|
* Creates a new #GimpIntComboBox filled with all currently opened
|
2008-06-03 21:46:50 +08:00
|
|
|
* layers. See gimp_drawable_combo_box_new() for more information.
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2004-04-21 19:51:21 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-04-21 19:51:21 +08:00
|
|
|
**/
|
2004-04-21 06:14:49 +08:00
|
|
|
GtkWidget *
|
2019-08-08 05:16:25 +08:00
|
|
|
gimp_layer_combo_box_new (GimpItemConstraintFunc constraint,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy)
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2012-10-09 04:01:30 +08:00
|
|
|
return gimp_item_combo_box_new (GIMP_TYPE_LAYER_COMBO_BOX,
|
2019-08-08 05:16:25 +08:00
|
|
|
constraint, data, data_destroy);
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-13 13:07:57 +08:00
|
|
|
G_DEFINE_TYPE (GimpPathComboBox, gimp_path_combo_box,
|
2012-10-11 05:10:56 +08:00
|
|
|
GIMP_TYPE_INT_COMBO_BOX)
|
2006-11-16 07:20:06 +08:00
|
|
|
|
|
|
|
static void
|
2024-07-13 13:07:57 +08:00
|
|
|
gimp_path_combo_box_class_init (GimpPathComboBoxClass *klass)
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2024-07-13 13:07:57 +08:00
|
|
|
gimp_path_combo_box_init (GimpPathComboBox *combo_box)
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (combo_box),
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
targets + 2, 1,
|
|
|
|
GDK_ACTION_COPY);
|
2012-10-11 05:10:56 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
|
|
|
|
g_new0 (GimpItemComboBoxPrivate, 1),
|
|
|
|
(GDestroyNotify) g_free);
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
|
2006-11-16 07:20:06 +08:00
|
|
|
/**
|
2024-07-13 13:07:57 +08:00
|
|
|
* gimp_path_combo_box_new:
|
2021-03-20 23:37:30 +08:00
|
|
|
* @constraint: (nullable): A #GimpItemConstraintFunc or %NULL
|
|
|
|
* @data: (closure constraint): A pointer that is passed to @constraint
|
|
|
|
* @data_destroy: (destroy data): Destroy function for @data
|
2006-11-16 07:20:06 +08:00
|
|
|
*
|
|
|
|
* Creates a new #GimpIntComboBox filled with all currently opened
|
2024-07-13 13:07:57 +08:00
|
|
|
* path objects. If a @constraint function is specified, it is called for
|
|
|
|
* each path object and only if the function returns %TRUE, the path
|
2006-11-16 07:20:06 +08:00
|
|
|
* object is added to the combobox.
|
|
|
|
*
|
|
|
|
* You should use gimp_int_combo_box_connect() to initialize and connect
|
|
|
|
* the combo. Use gimp_int_combo_box_set_active() to set the active
|
2024-07-13 13:07:57 +08:00
|
|
|
* path ID and gimp_int_combo_box_get_active() to retrieve the ID
|
|
|
|
* of the selected path object.
|
2006-11-16 07:20:06 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2006-11-16 07:20:06 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2006-11-16 07:20:06 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
2024-07-13 13:07:57 +08:00
|
|
|
gimp_path_combo_box_new (GimpItemConstraintFunc constraint,
|
2019-08-08 05:16:25 +08:00
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy)
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2024-07-13 13:07:57 +08:00
|
|
|
return gimp_item_combo_box_new (GIMP_TYPE_PATH_COMBO_BOX,
|
2019-08-08 05:16:25 +08:00
|
|
|
constraint, data, data_destroy);
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
2012-10-09 04:01:30 +08:00
|
|
|
gimp_item_combo_box_new (GType type,
|
2006-11-16 07:20:06 +08:00
|
|
|
GimpItemConstraintFunc constraint,
|
2019-08-08 05:16:25 +08:00
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy)
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpIntComboBox *combo_box;
|
|
|
|
GimpItemComboBoxPrivate *private;
|
2012-10-09 04:01:30 +08:00
|
|
|
|
|
|
|
combo_box = g_object_new (type,
|
|
|
|
"width-request", WIDTH_REQUEST,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_MIDDLE,
|
|
|
|
NULL);
|
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
private = GET_PRIVATE (combo_box);
|
|
|
|
|
|
|
|
private->constraint = constraint;
|
|
|
|
private->data = data;
|
2012-10-09 04:01:30 +08:00
|
|
|
|
2019-08-08 05:45:25 +08:00
|
|
|
if (data_destroy)
|
|
|
|
g_object_weak_ref (G_OBJECT (combo_box), (GWeakNotify) data_destroy, data);
|
2019-08-08 05:16:25 +08:00
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
gimp_item_combo_box_populate (combo_box);
|
|
|
|
|
|
|
|
g_signal_connect (combo_box, "changed",
|
|
|
|
G_CALLBACK (gimp_item_combo_box_changed),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return GTK_WIDGET (combo_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-11 05:10:56 +08:00
|
|
|
gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
|
2012-10-09 04:01:30 +08:00
|
|
|
{
|
2004-04-21 06:14:49 +08:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
2019-08-14 17:08:42 +08:00
|
|
|
GList *images;
|
|
|
|
GList *list;
|
2004-04-21 06:14:49 +08:00
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
|
|
|
|
|
2019-08-27 19:26:27 +08:00
|
|
|
images = gimp_list_images ();
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2019-08-27 19:26:27 +08:00
|
|
|
for (list = images; list; list = g_list_next (list))
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2019-08-14 17:08:42 +08:00
|
|
|
GimpImage *image = list->data;
|
|
|
|
GList *items;
|
2006-11-16 07:20:06 +08:00
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
if (GIMP_IS_DRAWABLE_COMBO_BOX (combo_box) ||
|
|
|
|
GIMP_IS_LAYER_COMBO_BOX (combo_box))
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2019-08-27 19:26:27 +08:00
|
|
|
items = gimp_image_list_layers (image);
|
2012-10-09 04:01:30 +08:00
|
|
|
gimp_item_combo_box_model_add (combo_box, GTK_LIST_STORE (model),
|
2019-08-14 17:08:42 +08:00
|
|
|
image, items, 0);
|
2019-08-15 18:12:25 +08:00
|
|
|
g_list_free (items);
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
if (GIMP_IS_DRAWABLE_COMBO_BOX (combo_box) ||
|
|
|
|
GIMP_IS_CHANNEL_COMBO_BOX (combo_box))
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2019-08-27 19:26:27 +08:00
|
|
|
items = gimp_image_list_channels (image);
|
2012-10-09 04:01:30 +08:00
|
|
|
gimp_item_combo_box_model_add (combo_box, GTK_LIST_STORE (model),
|
2019-08-14 17:08:42 +08:00
|
|
|
image, items, 0);
|
2019-08-15 18:12:25 +08:00
|
|
|
g_list_free (items);
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
|
|
|
|
2024-07-13 13:07:57 +08:00
|
|
|
if (GIMP_IS_PATH_COMBO_BOX (combo_box))
|
2006-11-16 07:20:06 +08:00
|
|
|
{
|
2024-07-08 10:09:42 +08:00
|
|
|
items = gimp_image_list_paths (image);
|
2012-10-09 04:01:30 +08:00
|
|
|
gimp_item_combo_box_model_add (combo_box, GTK_LIST_STORE (model),
|
2019-08-14 17:08:42 +08:00
|
|
|
image, items, 0);
|
2019-08-15 18:12:25 +08:00
|
|
|
g_list_free (items);
|
2006-11-16 07:20:06 +08:00
|
|
|
}
|
2004-04-21 06:14:49 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 16:01:08 +08:00
|
|
|
g_list_free (images);
|
2004-04-21 06:14:49 +08:00
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter_first (model, &iter))
|
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
|
|
|
|
}
|
|
|
|
|
2005-06-04 07:38:45 +08:00
|
|
|
static void
|
2012-10-11 05:10:56 +08:00
|
|
|
gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
|
|
|
|
GtkListStore *store,
|
2019-08-11 23:12:20 +08:00
|
|
|
GimpImage *image,
|
2019-08-14 17:08:42 +08:00
|
|
|
GList *items,
|
2012-10-11 05:10:56 +08:00
|
|
|
gint tree_level)
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2012-10-11 05:10:56 +08:00
|
|
|
GimpItemComboBoxPrivate *private = GET_PRIVATE (combo_box);
|
|
|
|
GtkTreeIter iter;
|
2019-08-14 17:08:42 +08:00
|
|
|
GList *list;
|
2012-10-11 05:10:56 +08:00
|
|
|
gchar *indent;
|
2012-09-03 08:17:55 +08:00
|
|
|
|
|
|
|
if (tree_level > 0)
|
|
|
|
{
|
|
|
|
indent = g_new (gchar, tree_level + 2);
|
|
|
|
memset (indent, '-', tree_level);
|
|
|
|
indent[tree_level] = ' ';
|
|
|
|
indent[tree_level + 1] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
indent = g_strdup ("");
|
|
|
|
}
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2019-08-27 19:26:27 +08:00
|
|
|
for (list = items; list; list = g_list_next (list))
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2019-08-14 17:08:42 +08:00
|
|
|
GimpItem *item = list->data;
|
|
|
|
gint32 item_id = gimp_item_get_id (item);
|
2019-08-13 22:16:08 +08:00
|
|
|
|
2019-09-03 17:10:43 +08:00
|
|
|
if (! private->constraint ||
|
|
|
|
private->constraint (image, item, private->data))
|
2004-04-21 06:14:49 +08:00
|
|
|
{
|
2006-11-16 07:20:06 +08:00
|
|
|
gchar *image_name = gimp_image_get_name (image);
|
2019-08-13 22:16:08 +08:00
|
|
|
gchar *item_name = gimp_item_get_name (item);
|
2004-04-21 06:14:49 +08:00
|
|
|
gchar *label;
|
|
|
|
GdkPixbuf *thumb;
|
|
|
|
|
2012-09-03 08:17:55 +08:00
|
|
|
label = g_strdup_printf ("%s%s-%d / %s-%d",
|
2019-08-11 23:12:20 +08:00
|
|
|
indent, image_name,
|
|
|
|
gimp_image_get_id (image),
|
2019-08-14 17:08:42 +08:00
|
|
|
item_name, item_id);
|
2004-04-21 06:14:49 +08:00
|
|
|
|
2006-11-16 07:20:06 +08:00
|
|
|
g_free (item_name);
|
2004-04-21 06:14:49 +08:00
|
|
|
g_free (image_name);
|
|
|
|
|
2024-07-13 13:07:57 +08:00
|
|
|
if (GIMP_IS_PATH_COMBO_BOX (combo_box))
|
2006-11-16 07:20:06 +08:00
|
|
|
thumb = NULL;
|
|
|
|
else
|
2019-08-13 22:16:08 +08:00
|
|
|
thumb = gimp_drawable_get_thumbnail (GIMP_DRAWABLE (item),
|
2006-11-16 07:20:06 +08:00
|
|
|
THUMBNAIL_SIZE, THUMBNAIL_SIZE,
|
|
|
|
GIMP_PIXBUF_SMALL_CHECKS);
|
2004-04-21 06:14:49 +08:00
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
2019-08-14 17:08:42 +08:00
|
|
|
GIMP_INT_STORE_VALUE, item_id,
|
2004-04-21 06:14:49 +08:00
|
|
|
GIMP_INT_STORE_LABEL, label,
|
|
|
|
GIMP_INT_STORE_PIXBUF, thumb,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (thumb)
|
|
|
|
g_object_unref (thumb);
|
|
|
|
|
|
|
|
g_free (label);
|
2015-06-22 00:10:22 +08:00
|
|
|
}
|
2012-09-03 08:17:55 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_item_is_group (item))
|
2015-06-22 00:10:22 +08:00
|
|
|
{
|
2019-08-14 17:08:42 +08:00
|
|
|
GList *children;
|
2015-06-22 00:10:22 +08:00
|
|
|
|
2019-08-27 19:26:27 +08:00
|
|
|
children = gimp_item_list_children (item);
|
2015-06-22 00:10:22 +08:00
|
|
|
gimp_item_combo_box_model_add (combo_box, store,
|
2019-08-14 17:08:42 +08:00
|
|
|
image, children,
|
2015-06-22 00:10:22 +08:00
|
|
|
tree_level + 1);
|
2019-08-15 18:12:25 +08:00
|
|
|
g_list_free (children);
|
2004-04-21 06:14:49 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-03 08:17:55 +08:00
|
|
|
|
|
|
|
g_free (indent);
|
2004-04-21 06:14:49 +08:00
|
|
|
}
|
2005-03-26 22:05:03 +08:00
|
|
|
|
|
|
|
static void
|
2006-11-16 07:20:06 +08:00
|
|
|
gimp_item_combo_box_drag_data_received (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection,
|
|
|
|
guint info,
|
|
|
|
guint time)
|
2005-03-26 22:05:03 +08:00
|
|
|
{
|
2009-03-22 23:49:13 +08:00
|
|
|
gint length = gtk_selection_data_get_length (selection);
|
2005-07-25 21:53:00 +08:00
|
|
|
gchar *str;
|
2005-03-26 22:05:03 +08:00
|
|
|
|
2009-03-22 23:49:13 +08:00
|
|
|
if (gtk_selection_data_get_format (selection) != 8 || length < 1)
|
2005-03-26 22:05:03 +08:00
|
|
|
{
|
2009-03-22 23:49:13 +08:00
|
|
|
g_warning ("%s: received invalid item ID data", G_STRFUNC);
|
2005-03-26 22:05:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-22 23:49:13 +08:00
|
|
|
str = g_strndup ((const gchar *) gtk_selection_data_get_data (selection),
|
|
|
|
length);
|
2005-07-25 21:53:00 +08:00
|
|
|
|
|
|
|
if (g_utf8_validate (str, -1, NULL))
|
|
|
|
{
|
|
|
|
gint pid;
|
|
|
|
gint ID;
|
|
|
|
|
|
|
|
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
|
|
|
|
pid == gimp_getpid ())
|
|
|
|
{
|
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 22:05:03 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
g_free (str);
|
2005-03-26 22:05:03 +08:00
|
|
|
}
|
2012-10-09 04:01:30 +08:00
|
|
|
|
2013-02-16 01:52:02 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_item_combo_box_remove_items (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2013-02-17 08:45:20 +08:00
|
|
|
gint item_ID;
|
|
|
|
GList **remove = data;
|
2013-02-16 01:52:02 +08:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
GIMP_INT_STORE_VALUE, &item_ID,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (item_ID > 0)
|
2021-08-26 23:18:32 +08:00
|
|
|
*remove = g_list_prepend (*remove, g_memdup2 (iter, sizeof (GtkTreeIter)));
|
2013-02-16 01:52:02 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
static void
|
2012-10-11 05:10:56 +08:00
|
|
|
gimp_item_combo_box_changed (GimpIntComboBox *combo_box)
|
2012-10-09 04:01:30 +08:00
|
|
|
{
|
|
|
|
gint item_ID;
|
|
|
|
|
2012-10-11 05:10:56 +08:00
|
|
|
if (gimp_int_combo_box_get_active (combo_box, &item_ID))
|
2012-10-09 04:01:30 +08:00
|
|
|
{
|
2019-08-30 23:58:18 +08:00
|
|
|
if (item_ID > 0 && ! gimp_item_get_by_id (item_ID))
|
2012-10-09 04:01:30 +08:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
2013-02-17 08:45:20 +08:00
|
|
|
GList *remove = NULL;
|
|
|
|
GList *list;
|
2012-10-09 04:01:30 +08:00
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
g_signal_stop_emission_by_name (combo_box, "changed");
|
|
|
|
|
2013-02-16 01:52:02 +08:00
|
|
|
gtk_tree_model_foreach (model,
|
|
|
|
gimp_item_combo_box_remove_items,
|
2013-02-17 08:45:20 +08:00
|
|
|
&remove);
|
|
|
|
|
|
|
|
for (list = remove; list; list = g_list_next (list))
|
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (model), list->data);
|
|
|
|
|
|
|
|
g_list_free_full (remove, (GDestroyNotify) g_free);
|
|
|
|
|
2012-10-09 04:01:30 +08:00
|
|
|
gimp_item_combo_box_populate (combo_box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|