diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-10-22 11:30:11 -0400 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-10-22 11:30:11 -0400 |
commit | 8a99eded6f8c2830f6b9c8b3acaddf781e28884e (patch) | |
tree | 932198e41aa2c91ff9bfa21e0d673d8af899cca6 /src | |
parent | 6e849d59f8ca112a42e4fda71d14ece905038e41 (diff) | |
download | ayatana-ido-8a99eded6f8c2830f6b9c8b3acaddf781e28884e.tar.gz ayatana-ido-8a99eded6f8c2830f6b9c8b3acaddf781e28884e.tar.bz2 ayatana-ido-8a99eded6f8c2830f6b9c8b3acaddf781e28884e.zip |
IdoSwitchMenuItem: deprecate get_content_area and add set_{label,icon}
Diffstat (limited to 'src')
-rw-r--r-- | src/idoswitchmenuitem.c | 79 | ||||
-rw-r--r-- | src/idoswitchmenuitem.h | 6 |
2 files changed, 84 insertions, 1 deletions
diff --git a/src/idoswitchmenuitem.c b/src/idoswitchmenuitem.c index 10ff1f3..100c6fb 100644 --- a/src/idoswitchmenuitem.c +++ b/src/idoswitchmenuitem.c @@ -30,6 +30,8 @@ struct _IdoSwitchMenuItemPrivate { GtkWidget * box; GtkWidget * content_area; + GtkWidget * label; + GtkWidget * image; GtkWidget * switch_w; }; @@ -63,7 +65,7 @@ ido_switch_menu_item_init (IdoSwitchMenuItem *item) priv = item->priv = G_TYPE_INSTANCE_GET_PRIVATE (item, IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemPrivate); priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - priv->content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + priv->content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); priv->switch_w = gtk_switch_new (); gtk_box_pack_start (GTK_BOX (priv->box), priv->content_area, TRUE, TRUE, 0); @@ -120,12 +122,87 @@ ido_switch_menu_item_new (void) * * Get the #GtkContainer to add additional widgets into. * + * This function is dperecated. + * * Return Value: (transfer none): The #GtkContainer to add additional widgets into. **/ GtkContainer * ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item) { + static gboolean warned = FALSE; + g_return_val_if_fail (IDO_IS_SWITCH_MENU_ITEM(item), NULL); + if (!warned) + { + g_warning ("%s is deprecated. Please don't use it, especially if you're using" + "ido_switch_menu_set_{label,icon}()", G_STRFUNC); + warned = TRUE; + } + return GTK_CONTAINER (item->priv->content_area); } + +/** + * ido_switch_menu_item_set_label: + * @item: a #IdoSwitchMenuItem. + * @label: a string to set as the label of @item + * + * Set the label of @item to @label. + **/ +void +ido_switch_menu_item_set_label (IdoSwitchMenuItem *item, + const gchar *label) +{ + IdoSwitchMenuItemPrivate *priv; + + g_return_if_fail (IDO_IS_SWITCH_MENU_ITEM (item)); + g_return_if_fail (label != NULL); + + priv = item->priv; + + if (priv->label == NULL) + { + priv->label = gtk_label_new (NULL); + gtk_widget_set_halign (priv->label, GTK_ALIGN_START); + gtk_widget_show (priv->label); + gtk_box_pack_end (GTK_BOX (priv->content_area), priv->label, TRUE, TRUE, 0); + } + + gtk_label_set_text (GTK_LABEL (priv->label), label); +} + +/** + * ido_switch_menu_item_set_icon: + * @item: a #IdoSwitchMenuItem. + * @icon: (allow-none): a #GIcon + * + * Set the icon of @item to @icon. + **/ +void +ido_switch_menu_item_set_icon (IdoSwitchMenuItem *item, + GIcon *icon) +{ + IdoSwitchMenuItemPrivate *priv; + + g_return_if_fail (IDO_IS_SWITCH_MENU_ITEM (item)); + g_return_if_fail (icon == NULL || G_IS_ICON (icon)); + + priv = item->priv; + + if (icon) + { + if (priv->image == NULL) + { + priv->image = gtk_image_new (); + gtk_widget_show (priv->image); + gtk_box_pack_start (GTK_BOX (priv->content_area), priv->image, FALSE, FALSE, 0); + } + + gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_MENU); + } + else + { + gtk_image_clear (GTK_IMAGE (priv->image)); + } +} diff --git a/src/idoswitchmenuitem.h b/src/idoswitchmenuitem.h index 7e7e2d2..9130edd 100644 --- a/src/idoswitchmenuitem.h +++ b/src/idoswitchmenuitem.h @@ -52,6 +52,12 @@ GType ido_switch_menu_item_get_type (void) G_GNUC_CONST; GtkWidget *ido_switch_menu_item_new (void); GtkContainer *ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item); +void ido_switch_menu_item_set_label (IdoSwitchMenuItem *item, + const gchar *label); + +void ido_switch_menu_item_set_icon (IdoSwitchMenuItem *item, + GIcon *icon); + G_END_DECLS #endif /* __IDO_SWITCH_MENU_ITEM_H__ */ |