diff options
author | Colomban Wendling <[email protected]> | 2017-01-23 18:08:45 +0100 |
---|---|---|
committer | lukefromdc <[email protected]> | 2017-01-23 13:49:34 -0500 |
commit | 017323dd4f8337ec91dd18f13955ab2e9df26cff (patch) | |
tree | af49218e14eda0ff5d019e5fb35fa006977812ad /applets/notification_area | |
parent | 352600f12126c2f974a2510dfb744ba4f562da3f (diff) | |
download | mate-panel-017323dd4f8337ec91dd18f13955ab2e9df26cff.tar.bz2 mate-panel-017323dd4f8337ec91dd18f13955ab2e9df26cff.tar.xz |
status-notifier: Remove custom image menu item class
It's only there because GtkImageMenuItem is deprecated, it doesn't
offer any original features.
Diffstat (limited to 'applets/notification_area')
4 files changed, 32 insertions, 300 deletions
diff --git a/applets/notification_area/status-notifier/Makefile.am b/applets/notification_area/status-notifier/Makefile.am index 38585c5d..dc3f134f 100644 --- a/applets/notification_area/status-notifier/Makefile.am +++ b/applets/notification_area/status-notifier/Makefile.am @@ -22,8 +22,6 @@ libstatus_notifier_la_SOURCES = \ sn-flat-button.h \ sn-host-v0.c \ sn-host-v0.h \ - sn-image-menu-item.c \ - sn-image-menu-item.h \ sn-item.c \ sn-item.h \ sn-item-v0.c \ diff --git a/applets/notification_area/status-notifier/sn-dbus-menu-item.c b/applets/notification_area/status-notifier/sn-dbus-menu-item.c index 3e740b1c..862fd3b0 100644 --- a/applets/notification_area/status-notifier/sn-dbus-menu-item.c +++ b/applets/notification_area/status-notifier/sn-dbus-menu-item.c @@ -18,7 +18,6 @@ #include "config.h" #include "sn-dbus-menu-item.h" -#include "sn-image-menu-item.h" static GdkPixbuf * pxibuf_new (GVariant *variant) @@ -178,30 +177,28 @@ sn_dbus_menu_item_new (GVariant *props) if (g_strcmp0 (item->toggle_type, "checkmark") == 0) { item->item = gtk_check_menu_item_new (); - gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item->item), TRUE); } else if (g_strcmp0 (item->toggle_type, "radio") == 0) { item->item = gtk_radio_menu_item_new (NULL); - gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item->item), TRUE); } else { - SnImageMenuItem *image_item; - - item->item = sn_image_menu_item_new (); - image_item = SN_IMAGE_MENU_ITEM (item->item); + GtkWidget *image = NULL; if (item->icon_name) { - sn_image_menu_item_set_image_from_icon_name (image_item, - item->icon_name); + image = gtk_image_new_from_icon_name (item->icon_name, + GTK_ICON_SIZE_MENU); } else if (item->icon_data) { - sn_image_menu_item_set_image_from_icon_pixbuf (image_item, - item->icon_data); + image = gtk_image_new_from_pixbuf (item->icon_data); } + + item->item = gtk_image_menu_item_new (); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item->item), + image); } if (g_strcmp0 (item->children_display, "submenu") == 0) @@ -215,6 +212,7 @@ sn_dbus_menu_item_new (GVariant *props) g_object_ref_sink (item->submenu); } + gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item->item), TRUE); gtk_menu_item_set_label (GTK_MENU_ITEM (item->item), item->label); if (item->shortcuts) @@ -305,41 +303,42 @@ sn_dbus_menu_item_update_props (SnDBusMenuItem *item, } else if (g_strcmp0 (prop, "icon-name") == 0) { - SnImageMenuItem *image_item; + GtkWidget *image; g_free (item->icon_name); item->icon_name = g_variant_dup_string (value, NULL); - image_item = SN_IMAGE_MENU_ITEM (item->item); - if (item->icon_name) { - sn_image_menu_item_set_image_from_icon_name (image_item, - item->icon_name); + image = gtk_image_new_from_icon_name (item->icon_name, + GTK_ICON_SIZE_MENU); } else { - sn_image_menu_item_unset_image (image_item); + image = NULL; } + + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item->item), + image); } else if (g_strcmp0 (prop, "icon-data") == 0) { - SnImageMenuItem *image_item; + GtkWidget *image; g_clear_object (&item->icon_data); item->icon_data = pxibuf_new (value); - image_item = SN_IMAGE_MENU_ITEM (item->item); - if (item->icon_data) { - sn_image_menu_item_set_image_from_icon_pixbuf (image_item, - item->icon_data); + image = gtk_image_new_from_pixbuf (item->icon_data); } else { - sn_image_menu_item_unset_image (image_item); + image = NULL; } + + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item->item), + image); } else if (g_strcmp0 (prop, "label") == 0) { @@ -428,14 +427,20 @@ sn_dbus_menu_item_remove_props (SnDBusMenuItem *item, else if (g_strcmp0 (prop, "icon-name") == 0) { g_clear_pointer (&item->icon_name, g_free); - if (SN_IS_IMAGE_MENU_ITEM (item->item)) - sn_image_menu_item_unset_image (SN_IMAGE_MENU_ITEM (item->item)); + if (GTK_IS_IMAGE_MENU_ITEM (item->item)) + { + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item->item), + NULL); + } } else if (g_strcmp0 (prop, "icon-data") == 0) { g_clear_object (&item->icon_data); - if (SN_IS_IMAGE_MENU_ITEM (item->item)) - sn_image_menu_item_unset_image (SN_IMAGE_MENU_ITEM (item->item)); + if (GTK_IS_IMAGE_MENU_ITEM (item->item)) + { + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item->item), + NULL); + } } else if (g_strcmp0 (prop, "label") == 0) { diff --git a/applets/notification_area/status-notifier/sn-image-menu-item.c b/applets/notification_area/status-notifier/sn-image-menu-item.c deleted file mode 100644 index 412ba11e..00000000 --- a/applets/notification_area/status-notifier/sn-image-menu-item.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2016 Alberts Muktupāvels - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "sn-image-menu-item.h" - -#define SPACING 6 - -struct _SnImageMenuItem -{ - GtkMenuItem parent; - - GtkWidget *box; - GtkWidget *image; - GtkWidget *accel_label; - - gchar *label; -}; - -G_DEFINE_TYPE (SnImageMenuItem, sn_image_menu_item, GTK_TYPE_MENU_ITEM) - -static void -sn_image_menu_item_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - GtkWidgetClass *widget_class; - SnImageMenuItem *item; - GtkRequisition image_requisition; - - widget_class = GTK_WIDGET_CLASS (sn_image_menu_item_parent_class); - item = SN_IMAGE_MENU_ITEM (widget); - - widget_class->get_preferred_width (widget, minimum, natural); - - if (!gtk_widget_get_visible (item->image)) - return; - - gtk_widget_get_preferred_size (item->image, &image_requisition, NULL); - - if (image_requisition.width > 0) - { - *minimum -= image_requisition.width + SPACING; - *natural -= image_requisition.width + SPACING; - } -} - -static void -sn_image_menu_item_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkWidgetClass *widget_class; - SnImageMenuItem *item; - GtkRequisition image_requisition; - GtkAllocation box_allocation; - - widget_class = GTK_WIDGET_CLASS (sn_image_menu_item_parent_class); - item = SN_IMAGE_MENU_ITEM (widget); - - widget_class->size_allocate (widget, allocation); - - if (!gtk_widget_get_visible (item->image)) - return; - - gtk_widget_get_preferred_size (item->image, &image_requisition, NULL); - gtk_widget_get_allocation (item->box, &box_allocation); - - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) - { - if (image_requisition.width > 0) - box_allocation.x -= image_requisition.width + SPACING; - } - else - { - if (image_requisition.width > 0) - box_allocation.x += image_requisition.width + SPACING; - } - - gtk_widget_size_allocate (item->box, &box_allocation); -} - -static const gchar * -sn_image_menu_item_get_label (GtkMenuItem *menu_item) -{ - SnImageMenuItem *item; - - item = SN_IMAGE_MENU_ITEM (menu_item); - - return item->label; -} - -static void -sn_image_menu_item_toggle_size_request (GtkMenuItem *menu_item, - gint *requisition) -{ - SnImageMenuItem *item; - GtkRequisition image_requisition; - - item = SN_IMAGE_MENU_ITEM (menu_item); - - *requisition = 0; - - if (!gtk_widget_get_visible (item->image)) - return; - - gtk_widget_get_preferred_size (item->image, &image_requisition, NULL); - - if (image_requisition.width > 0) - *requisition = image_requisition.width + SPACING; -} - -static void -sn_image_menu_item_set_label (GtkMenuItem *menu_item, - const gchar *label) -{ - SnImageMenuItem *item; - - item = SN_IMAGE_MENU_ITEM (menu_item); - - if (g_strcmp0 (item->label, label) != 0) - { - g_free (item->label); - item->label = g_strdup (label); - - gtk_label_set_text_with_mnemonic (GTK_LABEL (item->accel_label), label); - g_object_notify (G_OBJECT (menu_item), "label"); - } -} - -static void -sn_image_menu_item_class_init (SnImageMenuItemClass *item_class) -{ - GtkWidgetClass *widget_class; - GtkMenuItemClass *menu_item_class; - - widget_class = GTK_WIDGET_CLASS (item_class); - menu_item_class = GTK_MENU_ITEM_CLASS (item_class); - - widget_class->get_preferred_width = sn_image_menu_item_get_preferred_width; - widget_class->size_allocate = sn_image_menu_item_size_allocate; - - menu_item_class->get_label = sn_image_menu_item_get_label; - menu_item_class->toggle_size_request = sn_image_menu_item_toggle_size_request; - menu_item_class->set_label = sn_image_menu_item_set_label; -} - -static void -sn_image_menu_item_init (SnImageMenuItem *item) -{ - GtkAccelLabel *accel_label; - - item->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING); - gtk_container_add (GTK_CONTAINER (item), item->box); - gtk_widget_show (item->box); - - item->image = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (item->box), item->image, FALSE, FALSE, 0); - - item->accel_label = gtk_accel_label_new (""); - gtk_box_pack_end (GTK_BOX (item->box), item->accel_label, TRUE, TRUE, 0); -#if GTK_CHECK_VERSION (3, 16, 0) - gtk_label_set_xalign (GTK_LABEL (item->accel_label), 0.0); -#else - gtk_misc_set_alignment (GTK_MISC (item->accel_label), 0.0, 0.5); -#endif - gtk_widget_show (item->accel_label); - - accel_label = GTK_ACCEL_LABEL (item->accel_label); - gtk_accel_label_set_accel_widget (accel_label, GTK_WIDGET (item)); - gtk_label_set_use_underline (GTK_LABEL (accel_label), TRUE); -} - -GtkWidget * -sn_image_menu_item_new (void) -{ - return g_object_new (SN_TYPE_IMAGE_MENU_ITEM, NULL); -} - -void -sn_image_menu_item_set_image_from_icon_name (SnImageMenuItem *item, - const gchar *icon_name) -{ - GtkImage *image; - - image = GTK_IMAGE (item->image); - - gtk_image_set_from_icon_name (image, icon_name, GTK_ICON_SIZE_MENU); - gtk_image_set_pixel_size (image, 16); - gtk_widget_show (item->image); -} - -void -sn_image_menu_item_set_image_from_icon_pixbuf (SnImageMenuItem *item, - GdkPixbuf *pixbuf) -{ - gtk_image_set_from_pixbuf (GTK_IMAGE (item->image), pixbuf); - gtk_widget_show (item->image); -} - -void -sn_image_menu_item_unset_image (SnImageMenuItem *item) -{ - gtk_image_clear (GTK_IMAGE (item->image)); - gtk_widget_hide (item->image); -} diff --git a/applets/notification_area/status-notifier/sn-image-menu-item.h b/applets/notification_area/status-notifier/sn-image-menu-item.h deleted file mode 100644 index 9aa9a4a1..00000000 --- a/applets/notification_area/status-notifier/sn-image-menu-item.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2016 Alberts Muktupāvels - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef SN_IMAGE_MENU_ITEM_H -#define SN_IMAGE_MENU_ITEM_H - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define SN_TYPE_IMAGE_MENU_ITEM (sn_image_menu_item_get_type ()) -#define SN_IMAGE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SN_TYPE_IMAGE_MENU_ITEM, SnImageMenuItem)) -#define SN_IS_IMAGE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SN_TYPE_IMAGE_MENU_ITEM)) - -typedef struct _SnImageMenuItem SnImageMenuItem; -typedef struct _SnImageMenuItemClass SnImageMenuItemClass; - -struct _SnImageMenuItemClass -{ - GtkMenuItemClass parent_class; -}; - -GType sn_image_menu_item_get_type (void); - -GtkWidget *sn_image_menu_item_new (void); - -void sn_image_menu_item_set_image_from_icon_name (SnImageMenuItem *item, - const gchar *icon_name); - -void sn_image_menu_item_set_image_from_icon_pixbuf (SnImageMenuItem *item, - GdkPixbuf *pixbuf); - -void sn_image_menu_item_unset_image (SnImageMenuItem *item); - -G_END_DECLS - -#endif |