gschem

gschem_action.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include "gschem.h"
00024 
00025 
00026 enum {
00027   PROP_MULTIKEY_ACCEL = 1,
00028 };
00029 
00030 
00031 static GObjectClass *gschem_action_parent_class = NULL;
00032 
00033 
00042 static void gschem_action_finalize (GObject *object)
00043 {
00044   GschemAction *action = GSCHEM_ACTION (object);
00045 
00046   g_free (action->multikey_accel);
00047 
00048   G_OBJECT_CLASS (gschem_action_parent_class)->finalize (object);
00049 }
00050 
00051 
00064 static void gschem_action_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
00065 {
00066   GschemAction *action = GSCHEM_ACTION (object);
00067 
00068   switch(property_id) {
00069     case PROP_MULTIKEY_ACCEL:
00070       g_free (action->multikey_accel);
00071       action->multikey_accel = g_strdup (g_value_get_string (value));
00072       break;
00073     default:
00074       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
00075   }
00076 }
00077 
00078 
00091 static void gschem_action_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
00092 {
00093   GschemAction *action = GSCHEM_ACTION (object);
00094 
00095   switch(property_id) {
00096     case PROP_MULTIKEY_ACCEL:
00097       g_value_set_string (value, action->multikey_accel);
00098       break;
00099     default:
00100       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
00101   }
00102 
00103 }
00104 
00105 static void
00106 gschem_action_connect_proxy (GtkAction *action,
00107                              GtkWidget *proxy)
00108 {
00109   GschemAction *gs_action = GSCHEM_ACTION (action);
00110   char *label_string;
00111 
00112   /* Override the type of label widget used with the menu item */
00113   if (GTK_IS_MENU_ITEM (proxy)) {
00114     GtkWidget *label;
00115 
00116     label = GTK_BIN (proxy)->child;
00117 
00118     /* make sure label is a GschemAccelLabel */
00119     if (label && !GSCHEM_IS_ACCEL_LABEL (label)) {
00120       gtk_container_remove (GTK_CONTAINER (proxy), label);
00121       label = NULL;
00122     }
00123 
00124     if (label == NULL) {
00125       g_object_get (action, "label", &label_string, NULL);
00126       (void) g_object_new (GSCHEM_TYPE_ACCEL_LABEL,
00127                "use-underline", TRUE,
00128                "xalign", 0.0,
00129                "visible", TRUE,
00130                "parent", proxy,
00131                "label", label_string,
00132                "accel-string", gs_action->multikey_accel,
00133                NULL);
00134     }
00135   }
00136 
00137   /* Let the parent class do its work now we've fiddled with the label */
00138   GTK_ACTION_CLASS (gschem_action_parent_class)->connect_proxy (action, proxy);
00139 }
00140 
00141 
00150 static void gschem_action_class_init (GschemActionClass *klass)
00151 {
00152   GObjectClass     *gobject_class = G_OBJECT_CLASS (klass);
00153   GtkActionClass *gtkaction_class = GTK_ACTION_CLASS (klass);
00154 
00155   gtkaction_class->connect_proxy  = gschem_action_connect_proxy;
00156 
00157   gobject_class->finalize      = gschem_action_finalize;
00158   gobject_class->set_property  = gschem_action_set_property;
00159   gobject_class->get_property  = gschem_action_get_property;
00160 
00161   gschem_action_parent_class = g_type_class_peek_parent (klass);
00162 
00163   g_object_class_install_property (
00164     gobject_class, PROP_MULTIKEY_ACCEL,
00165     g_param_spec_string ("multikey-accel",
00166                          "",
00167                          "",
00168                          NULL,
00169                          G_PARAM_READWRITE));
00170 }
00171 
00172 
00182 GType gschem_action_get_type ()
00183 {
00184   static GType gschem_action_type = 0;
00185 
00186   if (!gschem_action_type) {
00187     static const GTypeInfo gschem_action_info = {
00188       sizeof(GschemActionClass),
00189       NULL, /* base_init */
00190       NULL, /* base_finalize */
00191       (GClassInitFunc) gschem_action_class_init,
00192       NULL, /* class_finalize */
00193       NULL, /* class_data */
00194       sizeof(GschemAction),
00195       0,    /* n_preallocs */
00196       NULL, /* instance_init */
00197     };
00198 
00199     gschem_action_type = g_type_register_static (GTK_TYPE_ACTION,
00200                                                  "GschemAction",
00201                                                  &gschem_action_info, 0);
00202   }
00203 
00204   return gschem_action_type;
00205 }
00206 
00207 
00222 GschemAction *gschem_action_new (const gchar *name,
00223                                  const gchar *label,
00224                                  const gchar *tooltip,
00225                                  const gchar *stock_id,
00226                                  const gchar *multikey_accel)
00227 {
00228   g_return_val_if_fail (name != NULL, NULL);
00229 
00230   return g_object_new (GSCHEM_TYPE_ACTION,
00231                        "name", name,
00232                        "label", label,
00233                        "tooltip", tooltip,
00234                        "stock-id", stock_id,
00235                        "multikey-accel", multikey_accel,
00236                        NULL);
00237 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines