2009-05-18 06:01:34 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpintcombobox.c
|
|
|
|
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2009-05-18 06:01:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <libintl.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2019-07-31 16:16:21 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimpintcombobox.h"
|
|
|
|
#include "gimpintstore.h"
|
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpintcombobox
|
|
|
|
* @title: GimpIntComboBox
|
|
|
|
* @short_description: A widget providing a popup menu of integer
|
|
|
|
* values (e.g. enums).
|
|
|
|
*
|
|
|
|
* A widget providing a popup menu of integer values (e.g. enums).
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2013-06-03 22:36:25 +08:00
|
|
|
PROP_ELLIPSIZE,
|
2017-11-30 05:39:16 +08:00
|
|
|
PROP_LABEL,
|
2020-09-18 21:19:24 +08:00
|
|
|
PROP_LAYOUT,
|
|
|
|
PROP_VALUE
|
2009-05-18 06:01:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
typedef struct _GimpIntComboBoxPrivate
|
2009-05-18 06:01:34 +08:00
|
|
|
{
|
|
|
|
GtkCellRenderer *text_renderer;
|
|
|
|
|
2013-06-03 22:36:25 +08:00
|
|
|
PangoEllipsizeMode ellipsize;
|
|
|
|
gchar *label;
|
2017-11-30 05:39:16 +08:00
|
|
|
GimpIntComboBoxLayout layout;
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
GimpIntSensitivityFunc sensitivity_func;
|
|
|
|
gpointer sensitivity_data;
|
|
|
|
GDestroyNotify sensitivity_destroy;
|
2024-07-29 09:51:38 +08:00
|
|
|
} GimpIntComboBoxPrivate;
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
|
2018-04-29 09:54:43 +08:00
|
|
|
static void gimp_int_combo_box_constructed (GObject *object);
|
2009-05-18 06:01:34 +08:00
|
|
|
static void gimp_int_combo_box_finalize (GObject *object);
|
|
|
|
static void gimp_int_combo_box_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_int_combo_box_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2020-09-29 23:02:21 +08:00
|
|
|
static void gimp_int_combo_box_changed (GtkComboBox *combo_box,
|
|
|
|
gpointer user_data);
|
|
|
|
|
2013-06-03 22:36:25 +08:00
|
|
|
static void gimp_int_combo_box_create_cells (GimpIntComboBox *combo_box);
|
2009-05-18 06:01:34 +08:00
|
|
|
static void gimp_int_combo_box_data_func (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpIntComboBox, gimp_int_combo_box,
|
|
|
|
GTK_TYPE_COMBO_BOX)
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_int_combo_box_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_int_combo_box_class_init (GimpIntComboBoxClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2018-04-29 09:54:43 +08:00
|
|
|
object_class->constructed = gimp_int_combo_box_constructed;
|
2013-06-03 22:36:25 +08:00
|
|
|
object_class->finalize = gimp_int_combo_box_finalize;
|
2009-05-18 06:01:34 +08:00
|
|
|
object_class->set_property = gimp_int_combo_box_set_property;
|
|
|
|
object_class->get_property = gimp_int_combo_box_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GimpIntComboBox:ellipsize:
|
|
|
|
*
|
|
|
|
* Specifies the preferred place to ellipsize text in the combo-box,
|
|
|
|
* if the cell renderer does not have enough room to display the
|
|
|
|
* entire string.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2009-05-18 06:01:34 +08:00
|
|
|
*/
|
2013-06-03 22:36:25 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_ELLIPSIZE,
|
2017-06-07 03:19:17 +08:00
|
|
|
g_param_spec_enum ("ellipsize",
|
|
|
|
"Ellipsize",
|
|
|
|
"Ellipsize mode for the used text cell renderer",
|
2009-05-18 06:01:34 +08:00
|
|
|
PANGO_TYPE_ELLIPSIZE_MODE,
|
|
|
|
PANGO_ELLIPSIZE_NONE,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2013-06-03 22:36:25 +08:00
|
|
|
/**
|
|
|
|
* GimpIntComboBox:label:
|
|
|
|
*
|
|
|
|
* Sets a label on the combo-box, see gimp_int_combo_box_set_label().
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-06-03 22:36:25 +08:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_LABEL,
|
2017-06-07 03:19:17 +08:00
|
|
|
g_param_spec_string ("label",
|
|
|
|
"Label",
|
|
|
|
"An optional label to be displayed",
|
2013-06-03 22:36:25 +08:00
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2017-11-30 05:39:16 +08:00
|
|
|
/**
|
|
|
|
* GimpIntComboBox:layout:
|
|
|
|
*
|
|
|
|
* Specifies the combo box layout.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_LAYOUT,
|
|
|
|
g_param_spec_enum ("layout",
|
|
|
|
"Layout",
|
|
|
|
"Combo box layout",
|
|
|
|
GIMP_TYPE_INT_COMBO_BOX_LAYOUT,
|
2017-12-01 21:35:46 +08:00
|
|
|
GIMP_INT_COMBO_BOX_LAYOUT_ABBREVIATED,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2020-09-18 21:19:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GimpIntComboBox:value:
|
|
|
|
*
|
|
|
|
* The active value (different from the "active" property of
|
|
|
|
* GtkComboBox which is the active index).
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_VALUE,
|
|
|
|
g_param_spec_int ("value",
|
|
|
|
"Value",
|
|
|
|
"Value of active item",
|
|
|
|
G_MININT, G_MAXINT, 0,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2009-05-18 06:01:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_int_combo_box_init (GimpIntComboBox *combo_box)
|
|
|
|
{
|
2017-12-01 21:35:46 +08:00
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
GtkListStore *store;
|
2009-05-18 06:01:34 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
2019-09-24 06:16:55 +08:00
|
|
|
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
|
2009-05-18 06:01:34 +08:00
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
|
|
|
|
g_object_unref (store);
|
|
|
|
|
2017-12-01 21:35:46 +08:00
|
|
|
priv->layout = GIMP_INT_COMBO_BOX_LAYOUT_ABBREVIATED;
|
2020-09-29 23:02:21 +08:00
|
|
|
|
|
|
|
g_signal_connect (combo_box, "changed",
|
|
|
|
G_CALLBACK (gimp_int_combo_box_changed),
|
|
|
|
NULL);
|
2018-04-29 09:54:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_int_combo_box_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2017-12-01 21:35:46 +08:00
|
|
|
|
2018-04-29 09:54:43 +08:00
|
|
|
gimp_int_combo_box_create_cells (GIMP_INT_COMBO_BOX (object));
|
2009-05-18 06:01:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_int_combo_box_finalize (GObject *object)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpIntComboBox *combo = GIMP_INT_COMBO_BOX (object);
|
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
2017-09-03 21:14:51 +08:00
|
|
|
g_clear_pointer (&priv->label, g_free);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
if (priv->sensitivity_destroy)
|
|
|
|
{
|
|
|
|
GDestroyNotify d = priv->sensitivity_destroy;
|
|
|
|
|
|
|
|
priv->sensitivity_destroy = NULL;
|
|
|
|
d (priv->sensitivity_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_int_combo_box_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpIntComboBox *combo = GIMP_INT_COMBO_BOX (object);
|
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ELLIPSIZE:
|
2013-06-03 22:36:25 +08:00
|
|
|
priv->ellipsize = g_value_get_enum (value);
|
2017-11-30 05:39:16 +08:00
|
|
|
if (priv->text_renderer)
|
|
|
|
{
|
|
|
|
g_object_set_property (G_OBJECT (priv->text_renderer),
|
|
|
|
pspec->name, value);
|
|
|
|
}
|
2009-05-18 06:01:34 +08:00
|
|
|
break;
|
2013-06-03 22:36:25 +08:00
|
|
|
case PROP_LABEL:
|
|
|
|
gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (object),
|
|
|
|
g_value_get_string (value));
|
|
|
|
break;
|
2017-11-30 05:39:16 +08:00
|
|
|
case PROP_LAYOUT:
|
|
|
|
gimp_int_combo_box_set_layout (GIMP_INT_COMBO_BOX (object),
|
|
|
|
g_value_get_enum (value));
|
|
|
|
break;
|
2020-09-18 21:19:24 +08:00
|
|
|
case PROP_VALUE:
|
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (object),
|
|
|
|
g_value_get_int (value));
|
|
|
|
break;
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_int_combo_box_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpIntComboBox *combo = GIMP_INT_COMBO_BOX (object);
|
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ELLIPSIZE:
|
2013-06-03 22:36:25 +08:00
|
|
|
g_value_set_enum (value, priv->ellipsize);
|
2009-05-18 06:01:34 +08:00
|
|
|
break;
|
2013-06-03 22:36:25 +08:00
|
|
|
case PROP_LABEL:
|
|
|
|
g_value_set_string (value, priv->label);
|
|
|
|
break;
|
2017-11-30 05:39:16 +08:00
|
|
|
case PROP_LAYOUT:
|
|
|
|
g_value_set_enum (value, priv->layout);
|
|
|
|
break;
|
2020-09-18 21:19:24 +08:00
|
|
|
case PROP_VALUE:
|
|
|
|
{
|
|
|
|
gint v;
|
|
|
|
|
|
|
|
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (object), &v);
|
|
|
|
g_value_set_int (value, v);
|
|
|
|
}
|
|
|
|
break;
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-21 19:43:47 +08:00
|
|
|
* gimp_int_combo_box_new: (skip)
|
2009-05-18 06:01:34 +08:00
|
|
|
* @first_label: the label of the first item
|
|
|
|
* @first_value: the value of the first item
|
|
|
|
* @...: a %NULL terminated list of more label, value pairs
|
|
|
|
*
|
|
|
|
* Creates a GtkComboBox that has integer values associated with each
|
|
|
|
* item. The items to fill the combo box with are specified as a %NULL
|
|
|
|
* terminated list of label/value pairs.
|
|
|
|
*
|
|
|
|
* If you need to construct an empty #GimpIntComboBox, it's best to use
|
|
|
|
* g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL).
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_int_combo_box_new (const gchar *first_label,
|
|
|
|
gint first_value,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, first_value);
|
|
|
|
|
|
|
|
combo_box = gimp_int_combo_box_new_valist (first_label, first_value, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-25 22:04:21 +08:00
|
|
|
* gimp_int_combo_box_new_valist: (skip)
|
2009-05-18 06:01:34 +08:00
|
|
|
* @first_label: the label of the first item
|
|
|
|
* @first_value: the value of the first item
|
|
|
|
* @values: a va_list with more values
|
|
|
|
*
|
|
|
|
* A variant of gimp_int_combo_box_new() that takes a va_list of
|
2019-09-24 06:16:55 +08:00
|
|
|
* label/value pairs.
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_int_combo_box_new_valist (const gchar *first_label,
|
|
|
|
gint first_value,
|
|
|
|
va_list values)
|
|
|
|
{
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
GtkListStore *store;
|
|
|
|
|
2019-09-24 06:16:55 +08:00
|
|
|
store = gimp_int_store_new_valist (first_label, first_value, values);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
2019-09-24 06:16:55 +08:00
|
|
|
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
|
|
|
|
"model", store,
|
|
|
|
NULL);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
2019-09-24 06:16:55 +08:00
|
|
|
g_object_unref (store);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-25 22:04:21 +08:00
|
|
|
* gimp_int_combo_box_new_array: (rename-to gimp_int_combo_box_new)
|
2009-05-18 06:01:34 +08:00
|
|
|
* @n_values: the number of values
|
2020-12-25 22:04:21 +08:00
|
|
|
* @labels: (array length=n_values): an array of labels
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
|
|
|
* A variant of gimp_int_combo_box_new() that takes an array of labels.
|
|
|
|
* The array indices are used as values.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpIntComboBox.
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_int_combo_box_new_array (gint n_values,
|
|
|
|
const gchar *labels[])
|
|
|
|
{
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
GtkListStore *store;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (n_values >= 0, NULL);
|
|
|
|
g_return_val_if_fail (labels != NULL || n_values == 0, NULL);
|
|
|
|
|
|
|
|
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
|
|
|
|
|
|
|
|
for (i = 0; i < n_values; i++)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (labels[i])
|
|
|
|
{
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
GIMP_INT_STORE_VALUE, i,
|
|
|
|
GIMP_INT_STORE_LABEL, gettext (labels[i]),
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-21 19:43:47 +08:00
|
|
|
* gimp_int_combo_box_prepend: (skip)
|
2009-05-18 06:01:34 +08:00
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @...: pairs of column number and value, terminated with -1
|
|
|
|
*
|
|
|
|
* This function provides a convenient way to prepend items to a
|
|
|
|
* #GimpIntComboBox. It prepends a row to the @combo_box's list store
|
|
|
|
* and calls gtk_list_store_set() for you.
|
|
|
|
*
|
|
|
|
* The column number must be taken from the enum #GimpIntStoreColumns.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_int_combo_box_prepend (GimpIntComboBox *combo_box,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
|
|
|
|
|
|
|
|
va_start (args, combo_box);
|
|
|
|
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
gtk_list_store_set_valist (store, &iter, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-21 19:43:47 +08:00
|
|
|
* gimp_int_combo_box_append: (skip)
|
2009-05-18 06:01:34 +08:00
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @...: pairs of column number and value, terminated with -1
|
|
|
|
*
|
|
|
|
* This function provides a convenient way to append items to a
|
|
|
|
* #GimpIntComboBox. It appends a row to the @combo_box's list store
|
|
|
|
* and calls gtk_list_store_set() for you.
|
|
|
|
*
|
|
|
|
* The column number must be taken from the enum #GimpIntStoreColumns.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_int_combo_box_append (GimpIntComboBox *combo_box,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
|
|
|
|
|
|
|
|
va_start (args, combo_box);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set_valist (store, &iter, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_set_active:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @value: an integer value
|
|
|
|
*
|
|
|
|
* Looks up the item that belongs to the given @value and makes it the
|
|
|
|
* selected item in the @combo_box.
|
|
|
|
*
|
2020-09-29 23:02:21 +08:00
|
|
|
* Returns: %TRUE on success (value changed or not) or %FALSE if there
|
|
|
|
* was no item for this value.
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_int_combo_box_set_active (GimpIntComboBox *combo_box,
|
|
|
|
gint value)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
2020-09-29 23:02:21 +08:00
|
|
|
gint current_value;
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), FALSE);
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
|
|
|
|
|
2020-09-29 23:02:21 +08:00
|
|
|
if (gimp_int_combo_box_get_active (combo_box, ¤t_value) &&
|
|
|
|
value == current_value)
|
|
|
|
{
|
|
|
|
/* Guard for identical value to not loop forever between
|
|
|
|
* GimpIntComboBox "value" and GtkComboBox "active" properties.
|
|
|
|
*/
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (gimp_int_store_lookup_by_value (model, value, &iter))
|
2009-05-18 06:01:34 +08:00
|
|
|
{
|
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_get_active:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
2020-05-08 23:11:14 +08:00
|
|
|
* @value: (out): return location for the integer value
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
|
|
|
* Retrieves the value of the selected (active) item in the @combo_box.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: %TRUE if @value has been set or %FALSE if no item was
|
2009-05-18 06:01:34 +08:00
|
|
|
* active.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_int_combo_box_get_active (GimpIntComboBox *combo_box,
|
|
|
|
gint *value)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkTreeIter iter;
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)),
|
|
|
|
&iter,
|
|
|
|
GIMP_INT_STORE_VALUE, value,
|
|
|
|
-1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-01-22 04:43:15 +08:00
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_set_active_by_user_data:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @user_data: an integer value
|
|
|
|
*
|
|
|
|
* Looks up the item that has the given @user_data and makes it the
|
|
|
|
* selected item in the @combo_box.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: %TRUE on success or %FALSE if there was no item for
|
2016-01-22 04:43:15 +08:00
|
|
|
* this user-data.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_int_combo_box_set_active_by_user_data (GimpIntComboBox *combo_box,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), FALSE);
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
if (gimp_int_store_lookup_by_user_data (model, user_data, &iter))
|
|
|
|
{
|
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_get_active_user_data:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
2020-05-05 03:29:42 +08:00
|
|
|
* @user_data: (out): return location for the gpointer value
|
2016-01-22 04:43:15 +08:00
|
|
|
*
|
|
|
|
* Retrieves the user-data of the selected (active) item in the @combo_box.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: %TRUE if @user_data has been set or %FALSE if no item was
|
2016-01-22 04:43:15 +08:00
|
|
|
* active.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_int_combo_box_get_active_user_data (GimpIntComboBox *combo_box,
|
|
|
|
gpointer *user_data)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkTreeIter iter;
|
2016-01-22 04:43:15 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), FALSE);
|
|
|
|
g_return_val_if_fail (user_data != NULL, FALSE);
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)),
|
|
|
|
&iter,
|
|
|
|
GIMP_INT_STORE_USER_DATA, user_data,
|
|
|
|
-1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_connect:
|
2019-08-08 06:22:15 +08:00
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @value: the value to set
|
|
|
|
* @callback: a callback to connect to the @combo_box's "changed" signal
|
|
|
|
* @data: a pointer passed as data to g_signal_connect()
|
|
|
|
* @data_destroy: Destroy function for @data.
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2013-01-27 23:52:38 +08:00
|
|
|
* A convenience function that sets the initial @value of a
|
2009-05-18 06:01:34 +08:00
|
|
|
* #GimpIntComboBox and connects @callback to the "changed"
|
|
|
|
* signal.
|
|
|
|
*
|
|
|
|
* This function also calls the @callback once after setting the
|
|
|
|
* initial @value. This is often convenient when working with combo
|
|
|
|
* boxes that select a default active item, like for example
|
|
|
|
* gimp_drawable_combo_box_new(). If you pass an invalid initial
|
|
|
|
* @value, the @callback will be called with the default item active.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the signal handler ID as returned by g_signal_connect()
|
2009-05-18 06:01:34 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
gulong
|
|
|
|
gimp_int_combo_box_connect (GimpIntComboBox *combo_box,
|
|
|
|
gint value,
|
|
|
|
GCallback callback,
|
2019-08-08 06:22:15 +08:00
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify data_destroy)
|
2009-05-18 06:01:34 +08:00
|
|
|
{
|
|
|
|
gulong handler = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), 0);
|
|
|
|
|
|
|
|
if (callback)
|
|
|
|
handler = g_signal_connect (combo_box, "changed", callback, data);
|
|
|
|
|
2019-08-08 06:22:15 +08:00
|
|
|
if (data_destroy)
|
|
|
|
g_object_weak_ref (G_OBJECT (combo_box), (GWeakNotify) data_destroy,
|
|
|
|
data);
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
if (! gimp_int_combo_box_set_active (combo_box, value))
|
|
|
|
g_signal_emit_by_name (combo_box, "changed", NULL);
|
|
|
|
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
|
2013-06-03 22:36:25 +08:00
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_set_label:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @label: a string to be shown as label
|
|
|
|
*
|
|
|
|
* Sets a caption on the @combo_box that will be displayed
|
|
|
|
* left-aligned inside the box. When a label is set, the remaining
|
|
|
|
* contents of the box will be right-aligned. This is useful for
|
|
|
|
* places where screen estate is rare, like in tool options.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-06-03 22:36:25 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_int_combo_box_set_label (GimpIntComboBox *combo_box,
|
|
|
|
const gchar *label)
|
|
|
|
{
|
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
|
|
|
if (label == priv->label)
|
|
|
|
return;
|
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (priv->label)
|
|
|
|
{
|
|
|
|
g_free (priv->label);
|
|
|
|
priv->label = NULL;
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (combo_box,
|
|
|
|
gimp_int_combo_box_create_cells,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
{
|
|
|
|
priv->label = g_strdup (label);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
g_signal_connect (combo_box, "notify::popup-shown",
|
|
|
|
G_CALLBACK (gimp_int_combo_box_create_cells),
|
|
|
|
NULL);
|
|
|
|
}
|
2013-06-03 22:36:25 +08:00
|
|
|
|
|
|
|
gimp_int_combo_box_create_cells (combo_box);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (combo_box), "label");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_get_label:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
*
|
|
|
|
* Returns the label previously set with gimp_int_combo_box_set_label(),
|
|
|
|
* or %NULL,
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the @combo_box' label.
|
2013-06-03 22:36:25 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-06-03 22:36:25 +08:00
|
|
|
**/
|
|
|
|
const gchar *
|
|
|
|
gimp_int_combo_box_get_label (GimpIntComboBox *combo_box)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
2013-06-03 22:36:25 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), NULL);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
|
|
|
|
|
|
|
return priv->label;
|
2013-06-03 22:36:25 +08:00
|
|
|
}
|
|
|
|
|
2017-11-30 05:39:16 +08:00
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_set_layout:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @layout: the combo box layout
|
|
|
|
*
|
|
|
|
* Sets the layout of @combo_box to @layout.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_int_combo_box_set_layout (GimpIntComboBox *combo_box,
|
|
|
|
GimpIntComboBoxLayout layout)
|
|
|
|
{
|
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
2017-11-30 05:39:16 +08:00
|
|
|
|
|
|
|
if (layout == priv->layout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->layout = layout;
|
|
|
|
|
|
|
|
gimp_int_combo_box_create_cells (combo_box);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (combo_box), "layout");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_get_layout:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
*
|
|
|
|
* Returns the layout of @combo_box
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the @combo_box's layout.
|
2017-11-30 05:39:16 +08:00
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
**/
|
|
|
|
GimpIntComboBoxLayout
|
|
|
|
gimp_int_combo_box_get_layout (GimpIntComboBox *combo_box)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
2017-12-01 18:11:11 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box),
|
2017-12-01 21:35:46 +08:00
|
|
|
GIMP_INT_COMBO_BOX_LAYOUT_ABBREVIATED);
|
2017-11-30 05:39:16 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
|
|
|
|
|
|
|
return priv->layout;
|
2017-11-30 05:39:16 +08:00
|
|
|
}
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
/**
|
|
|
|
* gimp_int_combo_box_set_sensitivity:
|
|
|
|
* @combo_box: a #GimpIntComboBox
|
|
|
|
* @func: a function that returns a boolean value, or %NULL to unset
|
|
|
|
* @data: data to pass to @func
|
|
|
|
* @destroy: destroy notification for @data
|
|
|
|
*
|
|
|
|
* Sets a function that is used to decide about the sensitivity of
|
|
|
|
* rows in the @combo_box. Use this if you want to set certain rows
|
|
|
|
* insensitive.
|
|
|
|
*
|
|
|
|
* Calling gtk_widget_queue_draw() on the @combo_box will cause the
|
|
|
|
* sensitivity to be updated.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2009-05-18 06:01:34 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_int_combo_box_set_sensitivity (GimpIntComboBox *combo_box,
|
|
|
|
GimpIntSensitivityFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GimpIntComboBoxPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
2009-05-18 06:01:34 +08:00
|
|
|
|
|
|
|
if (priv->sensitivity_destroy)
|
|
|
|
{
|
|
|
|
GDestroyNotify d = priv->sensitivity_destroy;
|
|
|
|
|
|
|
|
priv->sensitivity_destroy = NULL;
|
|
|
|
d (priv->sensitivity_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->sensitivity_func = func;
|
|
|
|
priv->sensitivity_data = data;
|
|
|
|
priv->sensitivity_destroy = destroy;
|
|
|
|
|
2017-11-30 05:39:16 +08:00
|
|
|
gimp_int_combo_box_create_cells (combo_box);
|
2009-05-18 06:01:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-04 16:41:10 +08:00
|
|
|
/* private functions */
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2020-09-29 23:02:21 +08:00
|
|
|
static void
|
|
|
|
gimp_int_combo_box_changed (GtkComboBox *combo_box,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo_box),
|
|
|
|
&value);
|
|
|
|
g_object_set (combo_box, "value", value, NULL);
|
|
|
|
}
|
|
|
|
|
2013-06-03 22:36:25 +08:00
|
|
|
static void
|
|
|
|
gimp_int_combo_box_create_cells (GimpIntComboBox *combo_box)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpIntComboBoxPrivate *priv;
|
2018-07-13 20:50:06 +08:00
|
|
|
GtkCellLayout *layout = GTK_CELL_LAYOUT (combo_box);
|
|
|
|
GtkCellRenderer *text_renderer;
|
|
|
|
GtkCellRenderer *pixbuf_renderer;
|
|
|
|
gboolean popup_shown;
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
priv = gimp_int_combo_box_get_instance_private (combo_box);
|
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
g_object_get (combo_box, "popup-shown", &popup_shown, NULL);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2017-11-30 05:39:16 +08:00
|
|
|
gtk_cell_layout_clear (layout);
|
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
priv->text_renderer = NULL;
|
2017-11-30 05:39:16 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (popup_shown)
|
2017-11-30 05:39:16 +08:00
|
|
|
{
|
2018-07-13 20:50:06 +08:00
|
|
|
/* menu layout */
|
2017-11-30 05:39:16 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
pixbuf_renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
g_object_set (pixbuf_renderer,
|
2017-11-30 05:39:16 +08:00
|
|
|
"xpad", 2,
|
|
|
|
NULL);
|
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
text_renderer = gtk_cell_renderer_text_new ();
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
gtk_cell_layout_pack_start (layout, pixbuf_renderer, FALSE);
|
|
|
|
gtk_cell_layout_pack_start (layout, text_renderer, TRUE);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
gtk_cell_layout_set_attributes (layout,
|
|
|
|
pixbuf_renderer,
|
|
|
|
"icon-name", GIMP_INT_STORE_ICON_NAME,
|
|
|
|
"pixbuf", GIMP_INT_STORE_PIXBUF,
|
|
|
|
NULL);
|
|
|
|
gtk_cell_layout_set_attributes (layout,
|
|
|
|
text_renderer,
|
|
|
|
"text", GIMP_INT_STORE_LABEL,
|
|
|
|
NULL);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (priv->sensitivity_func)
|
2017-11-30 05:39:16 +08:00
|
|
|
{
|
2018-07-13 20:50:06 +08:00
|
|
|
gtk_cell_layout_set_cell_data_func (layout,
|
|
|
|
pixbuf_renderer,
|
|
|
|
gimp_int_combo_box_data_func,
|
|
|
|
priv, NULL);
|
2017-11-30 05:39:16 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
gtk_cell_layout_set_cell_data_func (layout,
|
|
|
|
text_renderer,
|
|
|
|
gimp_int_combo_box_data_func,
|
|
|
|
priv, NULL);
|
2017-11-30 05:39:16 +08:00
|
|
|
}
|
2013-06-03 22:36:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-13 20:50:06 +08:00
|
|
|
/* combo box layout */
|
2017-11-30 05:39:16 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (priv->layout != GIMP_INT_COMBO_BOX_LAYOUT_ICON_ONLY)
|
2017-11-30 05:39:16 +08:00
|
|
|
{
|
2018-07-13 20:50:06 +08:00
|
|
|
priv->text_renderer = text_renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (priv->text_renderer,
|
|
|
|
"ellipsize", priv->ellipsize,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text_renderer = NULL;
|
2017-11-30 05:39:16 +08:00
|
|
|
}
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
pixbuf_renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
|
|
|
|
if (text_renderer)
|
|
|
|
{
|
|
|
|
g_object_set (pixbuf_renderer,
|
|
|
|
"xpad", 2,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->label)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *label_renderer;
|
|
|
|
|
|
|
|
label_renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (label_renderer,
|
|
|
|
"text", priv->label,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_cell_layout_pack_start (layout, label_renderer, FALSE);
|
|
|
|
gtk_cell_layout_pack_end (layout, pixbuf_renderer, FALSE);
|
|
|
|
|
|
|
|
if (text_renderer)
|
|
|
|
{
|
|
|
|
gtk_cell_layout_pack_end (layout, text_renderer, TRUE);
|
|
|
|
|
|
|
|
g_object_set (text_renderer,
|
|
|
|
"xalign", 1.0,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_cell_layout_pack_start (layout, pixbuf_renderer, FALSE);
|
|
|
|
|
|
|
|
if (priv->text_renderer)
|
|
|
|
gtk_cell_layout_pack_start (layout, text_renderer, TRUE);
|
|
|
|
}
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2017-11-30 05:39:16 +08:00
|
|
|
gtk_cell_layout_set_attributes (layout,
|
2018-07-13 20:50:06 +08:00
|
|
|
pixbuf_renderer,
|
|
|
|
"icon-name", GIMP_INT_STORE_ICON_NAME,
|
2017-11-30 05:39:16 +08:00
|
|
|
NULL);
|
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (text_renderer)
|
|
|
|
gtk_cell_layout_set_attributes (layout,
|
|
|
|
text_renderer,
|
|
|
|
"text", GIMP_INT_STORE_LABEL,
|
|
|
|
NULL);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (priv->layout == GIMP_INT_COMBO_BOX_LAYOUT_ABBREVIATED ||
|
|
|
|
priv->sensitivity_func)
|
2017-11-30 05:39:16 +08:00
|
|
|
{
|
|
|
|
gtk_cell_layout_set_cell_data_func (layout,
|
2018-07-13 20:50:06 +08:00
|
|
|
pixbuf_renderer,
|
2017-11-30 05:39:16 +08:00
|
|
|
gimp_int_combo_box_data_func,
|
|
|
|
priv, NULL);
|
2013-06-03 22:36:25 +08:00
|
|
|
|
2018-07-13 20:50:06 +08:00
|
|
|
if (text_renderer)
|
|
|
|
gtk_cell_layout_set_cell_data_func (layout,
|
|
|
|
text_renderer,
|
|
|
|
gimp_int_combo_box_data_func,
|
|
|
|
priv, NULL);
|
|
|
|
}
|
2013-06-03 22:36:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
static void
|
|
|
|
gimp_int_combo_box_data_func (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpIntComboBoxPrivate *priv = data;
|
|
|
|
|
2017-11-30 05:39:16 +08:00
|
|
|
if (priv->layout == GIMP_INT_COMBO_BOX_LAYOUT_ABBREVIATED &&
|
|
|
|
cell == priv->text_renderer)
|
|
|
|
{
|
|
|
|
gchar *abbrev;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
GIMP_INT_STORE_ABBREV, &abbrev,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (abbrev)
|
|
|
|
{
|
|
|
|
g_object_set (cell,
|
|
|
|
"text", abbrev,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (abbrev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 06:01:34 +08:00
|
|
|
if (priv->sensitivity_func)
|
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
GIMP_INT_STORE_VALUE, &value,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
sensitive = priv->sensitivity_func (value, priv->sensitivity_data);
|
|
|
|
|
|
|
|
g_object_set (cell,
|
|
|
|
"sensitive", sensitive,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|