1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * gimpenumaction.c
5 * Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #include "config.h"
22
23 #include <gtk/gtk.h>
24
25 #include "widgets-types.h"
26
27 #include "core/gimpmarshal.h"
28
29 #include "gimpaction.h"
30 #include "gimpaction-history.h"
31 #include "gimpenumaction.h"
32
33
34 enum
35 {
36 PROP_0,
37 PROP_VALUE,
38 PROP_VALUE_VARIABLE
39 };
40
41
42 static void gimp_enum_action_set_property (GObject *object,
43 guint prop_id,
44 const GValue *value,
45 GParamSpec *pspec);
46 static void gimp_enum_action_get_property (GObject *object,
47 guint prop_id,
48 GValue *value,
49 GParamSpec *pspec);
50
51 static void gimp_enum_action_activate (GtkAction *action);
52
53
G_DEFINE_TYPE(GimpEnumAction,gimp_enum_action,GIMP_TYPE_ACTION_IMPL)54 G_DEFINE_TYPE (GimpEnumAction, gimp_enum_action, GIMP_TYPE_ACTION_IMPL)
55
56 #define parent_class gimp_enum_action_parent_class
57
58
59 static void
60 gimp_enum_action_class_init (GimpEnumActionClass *klass)
61 {
62 GObjectClass *object_class = G_OBJECT_CLASS (klass);
63 GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
64
65 object_class->set_property = gimp_enum_action_set_property;
66 object_class->get_property = gimp_enum_action_get_property;
67
68 action_class->activate = gimp_enum_action_activate;
69
70 g_object_class_install_property (object_class, PROP_VALUE,
71 g_param_spec_int ("value",
72 NULL, NULL,
73 G_MININT, G_MAXINT, 0,
74 GIMP_PARAM_READWRITE));
75
76 g_object_class_install_property (object_class, PROP_VALUE_VARIABLE,
77 g_param_spec_boolean ("value-variable",
78 NULL, NULL,
79 FALSE,
80 GIMP_PARAM_READWRITE));
81 }
82
83 static void
gimp_enum_action_init(GimpEnumAction * action)84 gimp_enum_action_init (GimpEnumAction *action)
85 {
86 }
87
88 static void
gimp_enum_action_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)89 gimp_enum_action_get_property (GObject *object,
90 guint prop_id,
91 GValue *value,
92 GParamSpec *pspec)
93 {
94 GimpEnumAction *action = GIMP_ENUM_ACTION (object);
95
96 switch (prop_id)
97 {
98 case PROP_VALUE:
99 g_value_set_int (value, action->value);
100 break;
101 case PROP_VALUE_VARIABLE:
102 g_value_set_boolean (value, action->value_variable);
103 break;
104 default:
105 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
106 break;
107 }
108 }
109
110 static void
gimp_enum_action_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)111 gimp_enum_action_set_property (GObject *object,
112 guint prop_id,
113 const GValue *value,
114 GParamSpec *pspec)
115 {
116 GimpEnumAction *action = GIMP_ENUM_ACTION (object);
117
118 switch (prop_id)
119 {
120 case PROP_VALUE:
121 action->value = g_value_get_int (value);
122 break;
123 case PROP_VALUE_VARIABLE:
124 action->value_variable = g_value_get_boolean (value);
125 break;
126 default:
127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 break;
129 }
130 }
131
132 GimpEnumAction *
gimp_enum_action_new(const gchar * name,const gchar * label,const gchar * tooltip,const gchar * icon_name,const gchar * help_id,gint value,gboolean value_variable)133 gimp_enum_action_new (const gchar *name,
134 const gchar *label,
135 const gchar *tooltip,
136 const gchar *icon_name,
137 const gchar *help_id,
138 gint value,
139 gboolean value_variable)
140 {
141 GimpEnumAction *action;
142
143 action = g_object_new (GIMP_TYPE_ENUM_ACTION,
144 "name", name,
145 "label", label,
146 "tooltip", tooltip,
147 "icon-name", icon_name,
148 "value", value,
149 "value-variable", value_variable,
150 NULL);
151
152 gimp_action_set_help_id (GIMP_ACTION (action), help_id);
153
154 return action;
155 }
156
157 static void
gimp_enum_action_activate(GtkAction * action)158 gimp_enum_action_activate (GtkAction *action)
159 {
160 GimpEnumAction *enum_action = GIMP_ENUM_ACTION (action);
161
162 gimp_action_emit_activate (GIMP_ACTION (enum_action),
163 g_variant_new_int32 (enum_action->value));
164
165 gimp_action_history_action_activated (GIMP_ACTION (action));
166 }
167