[gnome-panel] add panel-image-menu-item.[c/h]



commit e16c2484c3cba8ae5cdd22d693d4150afc80fdc0
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Jul 11 17:55:28 2014 +0300

    add panel-image-menu-item.[c/h]
    
    GtkImageMenuItem has been deprecated, but we will want to continue
    to use image menu items at least in Main Menu and Menu Bar applets.
    
    Added files are copied from GTK+ 3.8.9 version and then modified:
    - GtkImageMenuItem renamed to PanelImageMenuItem.
    - Removed deprecated parts - GtkStock, GtkActivatable.
    - Changed license from LGPL to GPL. This should be allowed. At
      least that is how I understand it. See third paragraph in LGPL
      license.
    
    We already had panel_image_menu_new function. This commit renames
    function name to panel_image_new_new2 to not conflict with newly
    added files.

 gnome-panel/Makefile.am             |    2 +
 gnome-panel/menu.c                  |    6 +-
 gnome-panel/menu.h                  |    2 +-
 gnome-panel/panel-image-menu-item.c |  725 +++++++++++++++++++++++++++++++++++
 gnome-panel/panel-image-menu-item.h |   71 ++++
 gnome-panel/panel-menu-bar.c        |    2 +-
 gnome-panel/panel-menu-items.c      |   12 +-
 7 files changed, 809 insertions(+), 11 deletions(-)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 149eaaf..b8c7c7d 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -41,6 +41,7 @@ panel_sources =                       \
        panel-background-monitor.c      \
        panel-stock-icons.c     \
        panel-action-button.c   \
+       panel-image-menu-item.c \
        panel-menu-bar.c        \
        panel-menu-bar-object.c \
        panel-menu-button.c     \
@@ -88,6 +89,7 @@ panel_headers =                       \
        panel-background-monitor.h      \
        panel-stock-icons.h     \
        panel-action-button.h   \
+       panel-image-menu-item.h \
        panel-menu-bar.h        \
        panel-menu-bar-object.h \
        panel-menu-button.h     \
diff --git a/gnome-panel/menu.c b/gnome-panel/menu.c
index 38afaa2..0b484f8 100644
--- a/gnome-panel/menu.c
+++ b/gnome-panel/menu.c
@@ -964,7 +964,7 @@ create_fake_menu (GMenuTreeDirectory *directory)
 }
 
 GtkWidget *
-panel_image_menu_item_new (void)
+panel_image_menu_item_new2 (void)
 {
        GtkWidget *menuitem;
        GtkStyleContext *context;
@@ -989,7 +989,7 @@ create_submenu_entry (GtkWidget          *menu,
                                                   "panel-menu-force-icon-for-categories") != NULL;
 
        if (force_categories_icon)
-               menuitem = panel_image_menu_item_new ();
+               menuitem = panel_image_menu_item_new2 ();
        else
                menuitem = gtk_image_menu_item_new ();
 
@@ -1059,7 +1059,7 @@ create_menuitem (GtkWidget          *menu,
 {
        GtkWidget  *menuitem;
        
-       menuitem = panel_image_menu_item_new ();
+       menuitem = panel_image_menu_item_new2 ();
 
        if (alias_directory)
                panel_load_menu_image_deferred (menuitem,
diff --git a/gnome-panel/menu.h b/gnome-panel/menu.h
index 529e07e..ec1bc77 100644
--- a/gnome-panel/menu.h
+++ b/gnome-panel/menu.h
@@ -52,7 +52,7 @@ void            setup_uri_drag             (GtkWidget  *menuitem,
 
 GtkWidget *    panel_create_menu              (void);
 
-GtkWidget *    panel_image_menu_item_new      (void);
+GtkWidget *    panel_image_menu_item_new2     (void);
 
 GdkPixbuf *    panel_make_menu_icon (GtkIconTheme *icon_theme,
                                      const char   *icon,
diff --git a/gnome-panel/panel-image-menu-item.c b/gnome-panel/panel-image-menu-item.c
new file mode 100644
index 0000000..a4cb808
--- /dev/null
+++ b/gnome-panel/panel-image-menu-item.c
@@ -0,0 +1,725 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2001 Red Hat, Inc.
+ *
+ * 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 library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+/*
+ * This is modified version of gtkimagemenuitem.c copied from GTK+
+ * 3.8.9 release:
+ * https://git.gnome.org/browse/gtk+/plain/gtk/gtkimagemenuitem.c?id=3.8.9
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+
+#include "panel-image-menu-item.h"
+
+struct _PanelImageMenuItemPrivate {
+  GtkWidget *image;
+
+  gchar     *label;
+  guint      always_show_image : 1;
+};
+
+enum {
+  PROP_0,
+  PROP_IMAGE,
+  PROP_ALWAYS_SHOW_IMAGE
+};
+
+static void panel_image_menu_item_destroy              (GtkWidget        *widget);
+static void panel_image_menu_item_get_preferred_width  (GtkWidget        *widget,
+                                                        gint             *minimum,
+                                                        gint             *natural);
+static void panel_image_menu_item_get_preferred_height (GtkWidget        *widget,
+                                                        gint             *minimum,
+                                                        gint             *natural);
+static void panel_image_menu_item_get_preferred_height_for_width (GtkWidget *widget,
+                                                                  gint       width,
+                                                                  gint      *minimum,
+                                                                  gint      *natural);
+static void panel_image_menu_item_size_allocate        (GtkWidget        *widget,
+                                                        GtkAllocation    *allocation);
+static void panel_image_menu_item_map                  (GtkWidget        *widget);
+static void panel_image_menu_item_remove               (GtkContainer     *container,
+                                                        GtkWidget        *child);
+static void panel_image_menu_item_toggle_size_request  (GtkMenuItem      *menu_item,
+                                                        gint             *requisition);
+static void panel_image_menu_item_set_label            (GtkMenuItem      *menu_item,
+                                                        const gchar      *label);
+static const gchar * panel_image_menu_item_get_label   (GtkMenuItem *menu_item);
+
+static void panel_image_menu_item_forall               (GtkContainer    *container,
+                                                        gboolean         include_internals,
+                                                        GtkCallback      callback,
+                                                        gpointer         callback_data);
+
+static void panel_image_menu_item_finalize             (GObject         *object);
+static void panel_image_menu_item_set_property         (GObject         *object,
+                                                        guint            prop_id,
+                                                        const GValue    *value,
+                                                        GParamSpec      *pspec);
+static void panel_image_menu_item_get_property         (GObject         *object,
+                                                        guint            prop_id,
+                                                        GValue          *value,
+                                                        GParamSpec      *pspec);
+static void panel_image_menu_item_screen_changed       (GtkWidget        *widget,
+                                                        GdkScreen        *previous_screen);
+
+static void panel_image_menu_item_recalculate          (PanelImageMenuItem *image_menu_item);
+
+G_DEFINE_TYPE_WITH_PRIVATE (PanelImageMenuItem, panel_image_menu_item, GTK_TYPE_MENU_ITEM)
+
+static void
+panel_image_menu_item_class_init (PanelImageMenuItemClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass*) klass;
+  GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
+  GtkMenuItemClass *menu_item_class = (GtkMenuItemClass*) klass;
+  GtkContainerClass *container_class = (GtkContainerClass*) klass;
+
+  widget_class->destroy = panel_image_menu_item_destroy;
+  widget_class->screen_changed = panel_image_menu_item_screen_changed;
+  widget_class->get_preferred_width = panel_image_menu_item_get_preferred_width;
+  widget_class->get_preferred_height = panel_image_menu_item_get_preferred_height;
+  widget_class->get_preferred_height_for_width = panel_image_menu_item_get_preferred_height_for_width;
+  widget_class->size_allocate = panel_image_menu_item_size_allocate;
+  widget_class->map = panel_image_menu_item_map;
+
+  container_class->forall = panel_image_menu_item_forall;
+  container_class->remove = panel_image_menu_item_remove;
+
+  menu_item_class->toggle_size_request = panel_image_menu_item_toggle_size_request;
+  menu_item_class->set_label           = panel_image_menu_item_set_label;
+  menu_item_class->get_label           = panel_image_menu_item_get_label;
+
+  gobject_class->finalize     = panel_image_menu_item_finalize;
+  gobject_class->set_property = panel_image_menu_item_set_property;
+  gobject_class->get_property = panel_image_menu_item_get_property;
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_IMAGE,
+                                   g_param_spec_object ("image",
+                                                        _("Image widget"),
+                                                        _("Child widget to appear next to the menu text"),
+                                                        GTK_TYPE_WIDGET,
+                                                        G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_ALWAYS_SHOW_IMAGE,
+                                   g_param_spec_boolean ("always-show-image",
+                                                         _("Always show image"),
+                                                         _("Whether the image will always be shown"),
+                                                         FALSE,
+                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+panel_image_menu_item_init (PanelImageMenuItem *image_menu_item)
+{
+  PanelImageMenuItemPrivate *priv;
+
+  image_menu_item->priv = G_TYPE_INSTANCE_GET_PRIVATE (image_menu_item,
+                                                       PANEL_TYPE_IMAGE_MENU_ITEM,
+                                                       PanelImageMenuItemPrivate);
+  priv = image_menu_item->priv;
+
+  priv->image = NULL;
+  priv->label  = NULL;
+}
+
+static void
+panel_image_menu_item_finalize (GObject *object)
+{
+  PanelImageMenuItemPrivate *priv = PANEL_IMAGE_MENU_ITEM (object)->priv;
+
+  g_free (priv->label);
+  priv->label  = NULL;
+
+  G_OBJECT_CLASS (panel_image_menu_item_parent_class)->finalize (object);
+}
+
+static void
+panel_image_menu_item_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_IMAGE:
+      panel_image_menu_item_set_image (image_menu_item, (GtkWidget *) g_value_get_object (value));
+      break;
+    case PROP_ALWAYS_SHOW_IMAGE:
+      panel_image_menu_item_set_always_show_image (image_menu_item, g_value_get_boolean (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+panel_image_menu_item_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_IMAGE:
+      g_value_set_object (value, panel_image_menu_item_get_image (image_menu_item));
+      break;
+    case PROP_ALWAYS_SHOW_IMAGE:
+      g_value_set_boolean (value, panel_image_menu_item_get_always_show_image (image_menu_item));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static gboolean
+show_image (PanelImageMenuItem *image_menu_item)
+{
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (image_menu_item));
+  gboolean show;
+
+  if (priv->always_show_image)
+    show = TRUE;
+  else
+    g_object_get (settings, "gtk-menu-images", &show, NULL);
+
+  return show;
+}
+
+static void
+panel_image_menu_item_map (GtkWidget *widget)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (widget);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+
+  GTK_WIDGET_CLASS (panel_image_menu_item_parent_class)->map (widget);
+
+  if (priv->image)
+    g_object_set (priv->image,
+                  "visible", show_image (image_menu_item),
+                  NULL);
+}
+
+static void
+panel_image_menu_item_destroy (GtkWidget *widget)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (widget);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+
+  if (priv->image)
+    gtk_container_remove (GTK_CONTAINER (image_menu_item),
+                          priv->image);
+
+  GTK_WIDGET_CLASS (panel_image_menu_item_parent_class)->destroy (widget);
+}
+
+static void
+panel_image_menu_item_toggle_size_request (GtkMenuItem *menu_item,
+                                           gint        *requisition)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (menu_item);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  GtkPackDirection pack_dir;
+  GtkWidget *parent;
+  GtkWidget *widget = GTK_WIDGET (menu_item);
+
+  parent = gtk_widget_get_parent (widget);
+
+  if (GTK_IS_MENU_BAR (parent))
+    pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
+  else
+    pack_dir = GTK_PACK_DIRECTION_LTR;
+
+  *requisition = 0;
+
+  if (priv->image && gtk_widget_get_visible (priv->image))
+    {
+      GtkRequisition image_requisition;
+      guint toggle_spacing;
+
+      gtk_widget_get_preferred_size (priv->image, &image_requisition, NULL);
+
+      gtk_widget_style_get (GTK_WIDGET (menu_item),
+                            "toggle-spacing", &toggle_spacing,
+                            NULL);
+
+      if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
+        {
+          if (image_requisition.width > 0)
+            *requisition = image_requisition.width + toggle_spacing;
+        }
+      else
+        {
+          if (image_requisition.height > 0)
+            *requisition = image_requisition.height + toggle_spacing;
+        }
+    }
+}
+
+static void
+panel_image_menu_item_recalculate (PanelImageMenuItem *image_menu_item)
+{
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  const gchar               *resolved_label = priv->label;
+
+  if (priv->label)
+    gtk_menu_item_set_use_underline (GTK_MENU_ITEM (image_menu_item), TRUE);
+
+  GTK_MENU_ITEM_CLASS (panel_image_menu_item_parent_class)->set_label (GTK_MENU_ITEM (image_menu_item), 
resolved_label);
+}
+
+static void
+panel_image_menu_item_set_label (GtkMenuItem *menu_item,
+                                 const gchar *label)
+{
+  PanelImageMenuItemPrivate *priv = PANEL_IMAGE_MENU_ITEM (menu_item)->priv;
+
+  if (priv->label != label)
+    {
+      g_free (priv->label);
+      priv->label = g_strdup (label);
+
+      panel_image_menu_item_recalculate (PANEL_IMAGE_MENU_ITEM (menu_item));
+
+      g_object_notify (G_OBJECT (menu_item), "label");
+    }
+}
+
+static const gchar *
+panel_image_menu_item_get_label (GtkMenuItem *menu_item)
+{
+  PanelImageMenuItemPrivate *priv = PANEL_IMAGE_MENU_ITEM (menu_item)->priv;
+
+  return priv->label;
+}
+
+static void
+panel_image_menu_item_get_preferred_width (GtkWidget *widget,
+                                           gint      *minimum,
+                                           gint      *natural)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (widget);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  GtkPackDirection pack_dir;
+  GtkWidget *parent;
+
+  parent = gtk_widget_get_parent (widget);
+
+  if (GTK_IS_MENU_BAR (parent))
+    pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
+  else
+    pack_dir = GTK_PACK_DIRECTION_LTR;
+
+  GTK_WIDGET_CLASS (panel_image_menu_item_parent_class)->get_preferred_width (widget, minimum, natural);
+
+  if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
+      priv->image &&
+      gtk_widget_get_visible (priv->image))
+    {
+      gint child_minimum, child_natural;
+
+      gtk_widget_get_preferred_width (priv->image, &child_minimum, &child_natural);
+
+      *minimum = MAX (*minimum, child_minimum);
+      *natural = MAX (*natural, child_natural);
+    }
+}
+
+static void
+panel_image_menu_item_get_preferred_height (GtkWidget *widget,
+                                            gint      *minimum,
+                                            gint      *natural)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (widget);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  gint child_height = 0;
+  GtkPackDirection pack_dir;
+  GtkWidget *parent;
+
+  parent = gtk_widget_get_parent (widget);
+
+  if (GTK_IS_MENU_BAR (parent))
+    pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
+  else
+    pack_dir = GTK_PACK_DIRECTION_LTR;
+
+  if (priv->image && gtk_widget_get_visible (priv->image))
+    {
+      GtkRequisition child_requisition;
+
+      gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
+
+      child_height = child_requisition.height;
+    }
+
+  GTK_WIDGET_CLASS (panel_image_menu_item_parent_class)->get_preferred_height (widget, minimum, natural);
+
+  if (pack_dir == GTK_PACK_DIRECTION_RTL || pack_dir == GTK_PACK_DIRECTION_LTR)
+    {
+      *minimum = MAX (*minimum, child_height);
+      *natural = MAX (*natural, child_height);
+    }
+}
+
+static void
+panel_image_menu_item_get_preferred_height_for_width (GtkWidget *widget,
+                                                      gint       width,
+                                                      gint      *minimum,
+                                                      gint      *natural)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (widget);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  gint child_height = 0;
+  GtkPackDirection pack_dir;
+  GtkWidget *parent;
+
+  parent = gtk_widget_get_parent (widget);
+
+  if (GTK_IS_MENU_BAR (parent))
+    pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
+  else
+    pack_dir = GTK_PACK_DIRECTION_LTR;
+
+  if (priv->image && gtk_widget_get_visible (priv->image))
+    {
+      GtkRequisition child_requisition;
+
+      gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
+
+      child_height = child_requisition.height;
+    }
+
+  GTK_WIDGET_CLASS (panel_image_menu_item_parent_class)->get_preferred_height_for_width (widget, width, 
minimum, natural);
+
+  if (pack_dir == GTK_PACK_DIRECTION_RTL || pack_dir == GTK_PACK_DIRECTION_LTR)
+    {
+      *minimum = MAX (*minimum, child_height);
+      *natural = MAX (*natural, child_height);
+    }
+}
+
+static void
+panel_image_menu_item_size_allocate (GtkWidget     *widget,
+                                     GtkAllocation *allocation)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (widget);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+  GtkAllocation widget_allocation;
+  GtkPackDirection pack_dir;
+  GtkWidget *parent;
+
+  parent = gtk_widget_get_parent (widget);
+
+  if (GTK_IS_MENU_BAR (parent))
+    pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
+  else
+    pack_dir = GTK_PACK_DIRECTION_LTR;
+
+  GTK_WIDGET_CLASS (panel_image_menu_item_parent_class)->size_allocate (widget, allocation);
+
+  if (priv->image && gtk_widget_get_visible (priv->image))
+    {
+      gint x, y, offset;
+      GtkStyleContext *context;
+      GtkStateFlags state;
+      GtkBorder padding;
+      GtkRequisition child_requisition;
+      GtkAllocation child_allocation;
+      guint horizontal_padding, toggle_spacing;
+      gint toggle_size = 0;
+
+      panel_image_menu_item_toggle_size_request (GTK_MENU_ITEM (image_menu_item), &toggle_size);
+
+      gtk_widget_style_get (widget,
+                            "horizontal-padding", &horizontal_padding,
+                            "toggle-spacing", &toggle_spacing,
+                            NULL);
+
+      /* Man this is lame hardcoding action, but I can't
+       * come up with a solution that's really better.
+       */
+
+      gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
+
+      gtk_widget_get_allocation (widget, &widget_allocation);
+
+      context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+      gtk_style_context_get_padding (context, state, &padding);
+      offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item));
+
+      if (pack_dir == GTK_PACK_DIRECTION_LTR ||
+          pack_dir == GTK_PACK_DIRECTION_RTL)
+        {
+          if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
+              (pack_dir == GTK_PACK_DIRECTION_LTR))
+            x = offset + horizontal_padding + padding.left +
+               (toggle_size - toggle_spacing - child_requisition.width) / 2;
+          else
+            x = widget_allocation.width - offset - horizontal_padding - padding.right -
+              toggle_size + toggle_spacing +
+              (toggle_size - toggle_spacing - child_requisition.width) / 2;
+
+          y = (widget_allocation.height - child_requisition.height) / 2;
+        }
+      else
+        {
+          if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
+              (pack_dir == GTK_PACK_DIRECTION_TTB))
+            y = offset + horizontal_padding + padding.top +
+              (toggle_size - toggle_spacing - child_requisition.height) / 2;
+          else
+            y = widget_allocation.height - offset - horizontal_padding - padding.bottom -
+              toggle_size + toggle_spacing +
+              (toggle_size - toggle_spacing - child_requisition.height) / 2;
+
+          x = (widget_allocation.width - child_requisition.width) / 2;
+        }
+
+      child_allocation.width = child_requisition.width;
+      child_allocation.height = child_requisition.height;
+      child_allocation.x = widget_allocation.x + MAX (x, 0);
+      child_allocation.y = widget_allocation.y + MAX (y, 0);
+
+      gtk_widget_size_allocate (priv->image, &child_allocation);
+    }
+}
+
+static void
+panel_image_menu_item_forall (GtkContainer   *container,
+                              gboolean        include_internals,
+                              GtkCallback     callback,
+                              gpointer        callback_data)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (container);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+
+  GTK_CONTAINER_CLASS (panel_image_menu_item_parent_class)->forall (container,
+                                                                    include_internals,
+                                                                    callback,
+                                                                    callback_data);
+
+  if (include_internals && priv->image)
+    (* callback) (priv->image, callback_data);
+}
+
+GtkWidget*
+panel_image_menu_item_new (void)
+{
+  return g_object_new (PANEL_TYPE_IMAGE_MENU_ITEM, NULL);
+}
+
+GtkWidget*
+panel_image_menu_item_new_with_label (const gchar *label)
+{
+  return g_object_new (PANEL_TYPE_IMAGE_MENU_ITEM,
+                       "label", label,
+                       NULL);
+}
+
+GtkWidget*
+panel_image_menu_item_new_with_mnemonic (const gchar *label)
+{
+  return g_object_new (PANEL_TYPE_IMAGE_MENU_ITEM,
+                       "use-underline", TRUE,
+                       "label", label,
+                       NULL);
+}
+
+void
+panel_image_menu_item_set_always_show_image (PanelImageMenuItem *image_menu_item,
+                                             gboolean            always_show)
+{
+  PanelImageMenuItemPrivate *priv;
+
+  g_return_if_fail (PANEL_IS_IMAGE_MENU_ITEM (image_menu_item));
+
+  priv = image_menu_item->priv;
+
+  if (priv->always_show_image != always_show)
+    {
+      priv->always_show_image = always_show;
+
+      if (priv->image)
+        {
+          if (show_image (image_menu_item))
+            gtk_widget_show (priv->image);
+          else
+            gtk_widget_hide (priv->image);
+        }
+
+      g_object_notify (G_OBJECT (image_menu_item), "always-show-image");
+    }
+}
+
+gboolean
+panel_image_menu_item_get_always_show_image (PanelImageMenuItem *image_menu_item)
+{
+  g_return_val_if_fail (PANEL_IS_IMAGE_MENU_ITEM (image_menu_item), FALSE);
+
+  return image_menu_item->priv->always_show_image;
+}
+
+void
+panel_image_menu_item_set_image (PanelImageMenuItem *image_menu_item,
+                                 GtkWidget          *image)
+{
+  PanelImageMenuItemPrivate *priv;
+
+  g_return_if_fail (PANEL_IS_IMAGE_MENU_ITEM (image_menu_item));
+
+  priv = image_menu_item->priv;
+
+  if (image == priv->image)
+    return;
+
+  if (priv->image)
+    gtk_container_remove (GTK_CONTAINER (image_menu_item),
+                          priv->image);
+
+  priv->image = image;
+
+  if (image == NULL)
+    return;
+
+  gtk_widget_set_parent (image, GTK_WIDGET (image_menu_item));
+  g_object_set (image,
+                "visible", show_image (image_menu_item),
+                "no-show-all", TRUE,
+                NULL);
+
+  g_object_notify (G_OBJECT (image_menu_item), "image");
+}
+
+GtkWidget*
+panel_image_menu_item_get_image (PanelImageMenuItem *image_menu_item)
+{
+  g_return_val_if_fail (PANEL_IS_IMAGE_MENU_ITEM (image_menu_item), NULL);
+
+  return image_menu_item->priv->image;
+}
+
+static void
+panel_image_menu_item_remove (GtkContainer *container,
+                              GtkWidget    *child)
+{
+  PanelImageMenuItem *image_menu_item = PANEL_IMAGE_MENU_ITEM (container);
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+
+  if (child == priv->image)
+    {
+      gboolean widget_was_visible;
+
+      widget_was_visible = gtk_widget_get_visible (child);
+
+      gtk_widget_unparent (child);
+      priv->image = NULL;
+
+      if (widget_was_visible &&
+          gtk_widget_get_visible (GTK_WIDGET (container)))
+        gtk_widget_queue_resize (GTK_WIDGET (container));
+
+      g_object_notify (G_OBJECT (image_menu_item), "image");
+    }
+  else
+    {
+      GTK_CONTAINER_CLASS (panel_image_menu_item_parent_class)->remove (container, child);
+    }
+}
+
+static void
+show_image_change_notify (PanelImageMenuItem *image_menu_item)
+{
+  PanelImageMenuItemPrivate *priv = image_menu_item->priv;
+
+  if (priv->image)
+    {
+      if (show_image (image_menu_item))
+        gtk_widget_show (priv->image);
+      else
+        gtk_widget_hide (priv->image);
+    }
+}
+
+static void
+traverse_container (GtkWidget *widget,
+                    gpointer   data)
+{
+  if (PANEL_IS_IMAGE_MENU_ITEM (widget))
+    show_image_change_notify (PANEL_IMAGE_MENU_ITEM (widget));
+  else if (GTK_IS_CONTAINER (widget))
+    gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
+}
+
+static void
+panel_image_menu_item_setting_changed (GtkSettings *settings)
+{
+  GList *list, *l;
+
+  list = gtk_window_list_toplevels ();
+
+  for (l = list; l; l = l->next)
+    gtk_container_forall (GTK_CONTAINER (l->data),
+                          traverse_container, NULL);
+
+  g_list_free (list);
+}
+
+static void
+panel_image_menu_item_screen_changed (GtkWidget *widget,
+                                      GdkScreen *previous_screen)
+{
+  GtkSettings *settings;
+  gulong show_image_connection;
+
+  if (!gtk_widget_has_screen (widget))
+    return;
+
+  settings = gtk_widget_get_settings (widget);
+
+  show_image_connection =
+    g_signal_handler_find (settings, G_SIGNAL_MATCH_FUNC, 0, 0,
+                           NULL, panel_image_menu_item_setting_changed, NULL);
+
+  if (show_image_connection)
+    return;
+
+  g_signal_connect (settings, "notify::gtk-menu-images",
+                    G_CALLBACK (panel_image_menu_item_setting_changed), NULL);
+
+  show_image_change_notify (PANEL_IMAGE_MENU_ITEM (widget));
+}
diff --git a/gnome-panel/panel-image-menu-item.h b/gnome-panel/panel-image-menu-item.h
new file mode 100644
index 0000000..f8cbdba
--- /dev/null
+++ b/gnome-panel/panel-image-menu-item.h
@@ -0,0 +1,71 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) Red Hat, Inc.
+ *
+ * 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 library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+/*
+ * This is modified version of gtkimagemenuitem.h copied from GTK+
+ * 3.8.9 release:
+ * https://git.gnome.org/browse/gtk+/plain/gtk/gtkimagemenuitem.h?id=3.8.9
+ */
+
+#ifndef PANEL_IMAGE_MENU_ITEM_H
+#define PANEL_IMAGE_MENU_ITEM_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PANEL_TYPE_IMAGE_MENU_ITEM         (panel_image_menu_item_get_type ())
+#define PANEL_IMAGE_MENU_ITEM(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_IMAGE_MENU_ITEM, 
PanelImageMenuItem))
+#define PANEL_IMAGE_MENU_ITEM_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c),    PANEL_TYPE_IMAGE_MENU_ITEM, 
PanelImageMenuItemClass))
+#define PANEL_IS_IMAGE_MENU_ITEM(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_IMAGE_MENU_ITEM))
+#define PANEL_IS_IMAGE_MENU_ITEM_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),    PANEL_TYPE_IMAGE_MENU_ITEM))
+#define PANEL_IMAGE_MENU_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),  PANEL_TYPE_IMAGE_MENU_ITEM, 
PanelImageMenuItemClass))
+
+typedef struct _PanelImageMenuItem        PanelImageMenuItem;
+typedef struct _PanelImageMenuItemPrivate PanelImageMenuItemPrivate;
+typedef struct _PanelImageMenuItemClass   PanelImageMenuItemClass;
+
+struct _PanelImageMenuItem {
+  GtkMenuItem                parent;
+  PanelImageMenuItemPrivate *priv;
+};
+
+struct _PanelImageMenuItemClass {
+  GtkMenuItemClass parent_class;
+};
+
+GType     panel_image_menu_item_get_type              (void) G_GNUC_CONST;
+GtkWidget* panel_image_menu_item_new                   (void);
+GtkWidget* panel_image_menu_item_new_with_label        (const gchar        *label);
+GtkWidget* panel_image_menu_item_new_with_mnemonic     (const gchar        *label);
+void       panel_image_menu_item_set_always_show_image (PanelImageMenuItem *image_menu_item,
+                                                        gboolean            always_show);
+gboolean   panel_image_menu_item_get_always_show_image (PanelImageMenuItem *image_menu_item);
+void       panel_image_menu_item_set_image             (PanelImageMenuItem *image_menu_item,
+                                                        GtkWidget          *image);
+GtkWidget* panel_image_menu_item_get_image             (PanelImageMenuItem *image_menu_item);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-panel/panel-menu-bar.c b/gnome-panel/panel-menu-bar.c
index d0f8854..733abfc 100644
--- a/gnome-panel/panel-menu-bar.c
+++ b/gnome-panel/panel-menu-bar.c
@@ -116,7 +116,7 @@ panel_menu_bar_init (PanelMenuBar *menubar)
 
        menubar->priv->applications_menu = create_applications_menu ("gnome-applications.menu", NULL, TRUE);
 
-       menubar->priv->applications_item = panel_image_menu_item_new ();
+       menubar->priv->applications_item = panel_image_menu_item_new2 ();
        gtk_menu_item_set_label (GTK_MENU_ITEM (menubar->priv->applications_item),
                                 _("Applications"));
        menubar->priv->image = gtk_image_new_from_icon_name (PANEL_ICON_MAIN_MENU,
diff --git a/gnome-panel/panel-menu-items.c b/gnome-panel/panel-menu-items.c
index e52af1c..15ab68d 100644
--- a/gnome-panel/panel-menu-items.c
+++ b/gnome-panel/panel-menu-items.c
@@ -324,7 +324,7 @@ panel_menu_item_desktop_new (char      *path,
                name = g_strdup (force_name);
 
        if (use_icon) {
-               item = panel_image_menu_item_new ();
+               item = panel_image_menu_item_new2 ();
         } else {
                item = gtk_image_menu_item_new ();
        }
@@ -374,7 +374,7 @@ panel_menu_item_uri_new (const char *uri,
        GtkWidget *item;
        char      *user_data;
 
-       item = panel_image_menu_item_new ();
+       item = panel_image_menu_item_new2 ();
        setup_menu_item_with_icon (item,
                                   panel_menu_icon_get_size (),
                                   icon_name, gicon,
@@ -475,7 +475,7 @@ panel_menu_items_create_switch_user (gboolean use_icon)
        GtkWidget *item;
 
        if (use_icon) {
-               item = panel_image_menu_item_new ();
+               item = panel_image_menu_item_new2 ();
         } else {
                item = gtk_image_menu_item_new ();
        }
@@ -741,7 +741,7 @@ panel_menu_item_drive_new (GDrive *drive)
        icon = g_drive_get_icon (drive);
        title = g_drive_get_name (drive);
 
-       item = panel_image_menu_item_new ();
+       item = panel_image_menu_item_new2 ();
        setup_menu_item_with_icon (item,
                                   panel_menu_icon_get_size (),
                                   NULL, icon,
@@ -840,7 +840,7 @@ panel_menu_item_volume_new (GVolume *volume)
        icon = g_volume_get_icon (volume);
        title = g_volume_get_name (volume);
 
-       item = panel_image_menu_item_new ();
+       item = panel_image_menu_item_new2 ();
        setup_menu_item_with_icon (item,
                                   panel_menu_icon_get_size (),
                                   NULL, icon,
@@ -1142,7 +1142,7 @@ panel_place_menu_item_append_remote_gio (PanelPlaceMenuItem *place_item,
        } else {
                GtkWidget  *item;
 
-               item = panel_image_menu_item_new ();
+               item = panel_image_menu_item_new2 ();
                setup_menu_item_with_icon (item, panel_menu_icon_get_size (),
                                           PANEL_ICON_NETWORK_SERVER,
                                           NULL,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]