2005-06-25 06:46:42 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpenumlabel.c
|
|
|
|
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2005-06-25 06:46:42 +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.
|
2005-06-25 06:46:42 +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/>.
|
2005-06-25 06:46:42 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimpenumlabel.h"
|
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpenumlabel
|
|
|
|
* @title: GimpEnumLabel
|
|
|
|
* @short_description: A #GtkLabel subclass that displays an enum value.
|
|
|
|
*
|
|
|
|
* A #GtkLabel subclass that displays an enum value.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2011-02-16 04:26:11 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_ENUM_TYPE,
|
|
|
|
PROP_ENUM_VALUE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-03 20:08:25 +08:00
|
|
|
struct _GimpEnumLabelPrivate
|
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
};
|
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
#define GET_PRIVATE(obj) (((GimpEnumLabel *) (obj))->priv)
|
2011-01-03 20:08:25 +08:00
|
|
|
|
|
|
|
|
2011-02-16 04:26:11 +08:00
|
|
|
static void gimp_enum_label_finalize (GObject *object);
|
|
|
|
static void gimp_enum_label_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_enum_label_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-06-25 06:46:42 +08:00
|
|
|
|
|
|
|
|
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 (GimpEnumLabel, gimp_enum_label, GTK_TYPE_LABEL)
|
2005-06-25 06:46:42 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_enum_label_parent_class
|
2005-06-25 06:46:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_enum_label_class_init (GimpEnumLabelClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2011-02-16 04:26:11 +08:00
|
|
|
object_class->finalize = gimp_enum_label_finalize;
|
|
|
|
object_class->get_property = gimp_enum_label_get_property;
|
|
|
|
object_class->set_property = gimp_enum_label_set_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GimpEnumLabel:enum-type:
|
|
|
|
*
|
|
|
|
* The #GType of the enum.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.8
|
2011-02-16 04:26:11 +08:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_ENUM_TYPE,
|
2017-06-07 03:19:17 +08:00
|
|
|
g_param_spec_gtype ("enum-type",
|
|
|
|
"Enum Type",
|
|
|
|
"The type of the displayed enum",
|
2011-02-16 04:26:11 +08:00
|
|
|
G_TYPE_NONE,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GimpEnumLabel:enum-value:
|
|
|
|
*
|
|
|
|
* The value to display.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.8
|
2011-02-16 04:26:11 +08:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_ENUM_VALUE,
|
2017-06-07 03:19:17 +08:00
|
|
|
g_param_spec_int ("enum-value",
|
|
|
|
"Enum Value",
|
|
|
|
"The enum value to display",
|
2011-02-16 04:26:11 +08:00
|
|
|
G_MININT, G_MAXINT, 0,
|
|
|
|
GIMP_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
2005-06-25 06:46:42 +08:00
|
|
|
}
|
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static void
|
|
|
|
gimp_enum_label_init (GimpEnumLabel *enum_label)
|
|
|
|
{
|
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
|
|
|
enum_label->priv = gimp_enum_label_get_instance_private (enum_label);
|
2005-12-21 04:35:23 +08:00
|
|
|
}
|
|
|
|
|
2005-06-25 06:46:42 +08:00
|
|
|
static void
|
|
|
|
gimp_enum_label_finalize (GObject *object)
|
|
|
|
{
|
2011-01-03 20:08:25 +08:00
|
|
|
GimpEnumLabelPrivate *private = GET_PRIVATE (object);
|
2005-06-25 06:46:42 +08:00
|
|
|
|
2019-07-25 18:37:52 +08:00
|
|
|
g_clear_pointer (&private->enum_class, g_type_class_unref);
|
2005-06-25 06:46:42 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-02-16 04:26:11 +08:00
|
|
|
static void
|
|
|
|
gimp_enum_label_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2011-01-03 20:08:25 +08:00
|
|
|
GimpEnumLabelPrivate *private = GET_PRIVATE (object);
|
2011-02-16 04:26:11 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ENUM_TYPE:
|
2011-01-03 20:08:25 +08:00
|
|
|
if (private->enum_class)
|
|
|
|
g_value_set_gtype (value, G_TYPE_FROM_CLASS (private->enum_class));
|
2011-02-16 04:26:11 +08:00
|
|
|
else
|
|
|
|
g_value_set_gtype (value, G_TYPE_NONE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_enum_label_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2011-01-03 20:08:25 +08:00
|
|
|
GimpEnumLabel *label = GIMP_ENUM_LABEL (object);
|
|
|
|
GimpEnumLabelPrivate *private = GET_PRIVATE (label);
|
2011-02-16 04:26:11 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ENUM_TYPE:
|
2011-01-03 20:08:25 +08:00
|
|
|
private->enum_class = g_type_class_ref (g_value_get_gtype (value));
|
2011-02-16 04:26:11 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ENUM_VALUE:
|
|
|
|
gimp_enum_label_set_value (label, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-25 06:46:42 +08:00
|
|
|
/**
|
|
|
|
* gimp_enum_label_new:
|
2018-05-17 03:11:16 +08:00
|
|
|
* @enum_type: the #GType of an enum
|
|
|
|
* @value: an enum value
|
2005-06-25 06:46:42 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpEnumLabel.
|
2005-06-25 06:46:42 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-06-25 06:46:42 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_enum_label_new (GType enum_type,
|
|
|
|
gint value)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
|
|
|
|
|
2011-02-16 04:26:11 +08:00
|
|
|
return g_object_new (GIMP_TYPE_ENUM_LABEL,
|
|
|
|
"enum-type", enum_type,
|
|
|
|
"enum-value", value,
|
|
|
|
NULL);
|
2005-06-25 06:46:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_enum_label_set_value
|
|
|
|
* @label: a #GimpEnumLabel
|
2018-05-17 03:11:16 +08:00
|
|
|
* @value: an enum value
|
2005-06-25 06:46:42 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-06-25 06:46:42 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_enum_label_set_value (GimpEnumLabel *label,
|
|
|
|
gint value)
|
|
|
|
{
|
2011-01-03 20:08:25 +08:00
|
|
|
GimpEnumLabelPrivate *private;
|
|
|
|
const gchar *nick;
|
|
|
|
const gchar *desc;
|
2005-06-25 06:46:42 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_ENUM_LABEL (label));
|
|
|
|
|
2011-01-03 20:08:25 +08:00
|
|
|
private = GET_PRIVATE (label);
|
|
|
|
|
|
|
|
if (! gimp_enum_get_value (G_TYPE_FROM_CLASS (private->enum_class), value,
|
2018-05-17 03:11:16 +08:00
|
|
|
NULL, &nick, &desc, NULL))
|
2005-06-25 06:46:42 +08:00
|
|
|
{
|
|
|
|
g_warning ("%s: %d is not valid for enum of type '%s'",
|
|
|
|
G_STRLOC, value,
|
2011-01-03 20:08:25 +08:00
|
|
|
g_type_name (G_TYPE_FROM_CLASS (private->enum_class)));
|
2005-06-25 06:46:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-17 03:11:16 +08:00
|
|
|
if (! desc)
|
|
|
|
desc = nick;
|
|
|
|
|
2005-06-25 06:46:42 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (label), desc);
|
|
|
|
}
|