Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gschem / src / gschem_action.c
blob0e6bf01872e2fcdf2e484364f9a087810ca196f7
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 #include <config.h>
23 #include "gschem.h"
26 enum {
27 PROP_MULTIKEY_ACCEL = 1,
31 static GObjectClass *gschem_action_parent_class = NULL;
34 /*! \brief GObject finalise handler
36 * \par Function Description
37 * Just before the GschemAction GObject is finalized, free our
38 * allocated data, and then chain up to the parent's finalize handler.
40 * \param [in] widget The GObject being finalized.
42 static void gschem_action_finalize (GObject *object)
44 GschemAction *action = GSCHEM_ACTION (object);
46 g_free (action->multikey_accel);
48 G_OBJECT_CLASS (gschem_action_parent_class)->finalize (object);
52 /*! \brief GObject property setter function
54 * \par Function Description
55 * Setter function for GschemAction's GObject properties,
56 * "settings-name" and "toplevel".
58 * \param [in] object The GObject whose properties we are setting
59 * \param [in] property_id The numeric id. under which the property was
60 * registered with g_object_class_install_property()
61 * \param [in] value The GValue the property is being set from
62 * \param [in] pspec A GParamSpec describing the property being set
64 static void gschem_action_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
66 GschemAction *action = GSCHEM_ACTION (object);
68 switch(property_id) {
69 case PROP_MULTIKEY_ACCEL:
70 g_free (action->multikey_accel);
71 action->multikey_accel = g_strdup (g_value_get_string (value));
72 break;
73 default:
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
79 /*! \brief GObject property getter function
81 * \par Function Description
82 * Getter function for GschemAction's GObject properties,
83 * "settings-name" and "toplevel".
85 * \param [in] object The GObject whose properties we are getting
86 * \param [in] property_id The numeric id. under which the property was
87 * registered with g_object_class_install_property()
88 * \param [out] value The GValue in which to return the value of the property
89 * \param [in] pspec A GParamSpec describing the property being got
91 static void gschem_action_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
93 GschemAction *action = GSCHEM_ACTION (object);
95 switch(property_id) {
96 case PROP_MULTIKEY_ACCEL:
97 g_value_set_string (value, action->multikey_accel);
98 break;
99 default:
100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
105 static void
106 gschem_action_connect_proxy (GtkAction *action,
107 GtkWidget *proxy)
109 GschemAction *gs_action = GSCHEM_ACTION (action);
110 char *label_string;
112 /* Override the type of label widget used with the menu item */
113 if (GTK_IS_MENU_ITEM (proxy)) {
114 GtkWidget *label;
116 label = GTK_BIN (proxy)->child;
118 /* make sure label is a GschemAccelLabel */
119 if (label && !GSCHEM_IS_ACCEL_LABEL (label)) {
120 gtk_container_remove (GTK_CONTAINER (proxy), label);
121 label = NULL;
124 if (label == NULL) {
125 g_object_get (action, "label", &label_string, NULL);
126 label = g_object_new (GSCHEM_TYPE_ACCEL_LABEL,
127 "use-underline", TRUE,
128 "xalign", 0.0,
129 "visible", TRUE,
130 "parent", proxy,
131 "label", label_string,
132 "accel-string", gs_action->multikey_accel,
133 NULL);
137 /* Let the parent class do its work now we've fiddled with the label */
138 GTK_ACTION_CLASS (gschem_action_parent_class)->connect_proxy (action, proxy);
142 /*! \brief GType class initialiser for GschemAction
144 * \par Function Description
145 * GType class initialiser for GschemAction. We override our parent
146 * virtual class methods as needed and register our GObject properties.
148 * \param [in] klass The GschemActionClass we are initialising
150 static void gschem_action_class_init (GschemActionClass *klass)
152 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
153 GtkActionClass *gtkaction_class = GTK_ACTION_CLASS (klass);
155 gtkaction_class->connect_proxy = gschem_action_connect_proxy;
157 gobject_class->finalize = gschem_action_finalize;
158 gobject_class->set_property = gschem_action_set_property;
159 gobject_class->get_property = gschem_action_get_property;
161 gschem_action_parent_class = g_type_class_peek_parent (klass);
163 g_object_class_install_property (
164 gobject_class, PROP_MULTIKEY_ACCEL,
165 g_param_spec_string ("multikey-accel",
168 NULL,
169 G_PARAM_READWRITE));
173 /*! \brief Function to retrieve GschemAction's GType identifier.
175 * \par Function Description
176 * Function to retrieve GschemAction's GType identifier.
177 * Upon first call, this registers the GschemAction in the GType system.
178 * Subsequently it returns the saved value from its first execution.
180 * \return the GType identifier associated with GschemAction.
182 GType gschem_action_get_type ()
184 static GType gschem_action_type = 0;
186 if (!gschem_action_type) {
187 static const GTypeInfo gschem_action_info = {
188 sizeof(GschemActionClass),
189 NULL, /* base_init */
190 NULL, /* base_finalize */
191 (GClassInitFunc) gschem_action_class_init,
192 NULL, /* class_finalize */
193 NULL, /* class_data */
194 sizeof(GschemAction),
195 0, /* n_preallocs */
196 NULL, /* instance_init */
199 gschem_action_type = g_type_register_static (GTK_TYPE_ACTION,
200 "GschemAction",
201 &gschem_action_info, 0);
204 return gschem_action_type;
208 /*! /brief Creates a new GschemAction object
210 * /par Function Descriptions
212 * Creates a new GschemAction object.
214 * /param [in] name A unique name for the action
215 * /param [in] label The label displayed in menu items and on buttons, or NULL
216 * /param [in] tooltip A tooltip for the action, or NULL
217 * /param [in] stock_id The stock icon to display in widgets representing the action, or NULL
218 * /param [in] multikey_accel The (potentially) multi-key accelerator used for this action
220 * /returns A new GschemAction
222 GschemAction *gschem_action_new (const gchar *name,
223 const gchar *label,
224 const gchar *tooltip,
225 const gchar *stock_id,
226 const gchar *multikey_accel)
228 g_return_val_if_fail (name != NULL, NULL);
230 return g_object_new (GSCHEM_TYPE_ACTION,
231 "name", name,
232 "label", label,
233 "tooltip", tooltip,
234 "stock-id", stock_id,
235 "multikey-accel", multikey_accel,
236 NULL);