2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2001-02-13 05:44:47 +00:00
|
|
|
* Copyright (C) 2001 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2008-05-19 14:15:34 +00:00
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
2001-02-13 05:44:47 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
#include "gtkimagemenuitem.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
#include "gtkmenuitemprivate.h"
|
2001-02-13 05:44:47 +00:00
|
|
|
#include "gtkaccellabel.h"
|
2001-03-21 08:56:25 +00:00
|
|
|
#include "gtkstock.h"
|
|
|
|
#include "gtkiconfactory.h"
|
|
|
|
#include "gtkimage.h"
|
2005-07-03 06:24:04 +00:00
|
|
|
#include "gtkmenubar.h"
|
2004-11-15 18:07:22 +00:00
|
|
|
#include "gtkcontainer.h"
|
|
|
|
#include "gtkwindow.h"
|
2009-01-23 15:15:28 +00:00
|
|
|
#include "gtkactivatable.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
|
|
|
#include "gtkintl.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
2004-02-19 22:39:58 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
|
2010-08-26 17:15:37 +00:00
|
|
|
struct _GtkImageMenuItemPrivate
|
2010-06-23 21:40:06 +00:00
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
|
|
|
|
gchar *label;
|
|
|
|
guint use_stock : 1;
|
|
|
|
guint always_show_image : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_IMAGE,
|
|
|
|
PROP_USE_STOCK,
|
|
|
|
PROP_ACCEL_GROUP,
|
|
|
|
PROP_ALWAYS_SHOW_IMAGE
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkActivatableIface *parent_activatable_iface;
|
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
static void gtk_image_menu_item_destroy (GtkWidget *widget);
|
2010-10-27 05:12:41 +00:00
|
|
|
static void gtk_image_menu_item_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint *natural);
|
2010-10-27 05:12:41 +00:00
|
|
|
static void gtk_image_menu_item_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint *natural);
|
2010-10-27 05:12:41 +00:00
|
|
|
static void gtk_image_menu_item_get_preferred_height_for_width (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
2001-02-13 05:44:47 +00:00
|
|
|
static void gtk_image_menu_item_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2008-11-02 05:01:23 +00:00
|
|
|
static void gtk_image_menu_item_map (GtkWidget *widget);
|
2008-11-06 17:19:08 +00:00
|
|
|
static void gtk_image_menu_item_remove (GtkContainer *container,
|
|
|
|
GtkWidget *child);
|
|
|
|
static void gtk_image_menu_item_toggle_size_request (GtkMenuItem *menu_item,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint *requisition);
|
2008-11-06 17:19:08 +00:00
|
|
|
static void gtk_image_menu_item_set_label (GtkMenuItem *menu_item,
|
2010-12-27 01:36:51 +00:00
|
|
|
const gchar *label);
|
2008-11-06 17:19:08 +00:00
|
|
|
static G_CONST_RETURN gchar *gtk_image_menu_item_get_label (GtkMenuItem *menu_item);
|
|
|
|
|
|
|
|
static void gtk_image_menu_item_forall (GtkContainer *container,
|
2010-12-27 01:36:51 +00:00
|
|
|
gboolean include_internals,
|
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data);
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
static void gtk_image_menu_item_finalize (GObject *object);
|
|
|
|
static void gtk_image_menu_item_set_property (GObject *object,
|
2010-12-27 01:36:51 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2008-11-06 17:19:08 +00:00
|
|
|
static void gtk_image_menu_item_get_property (GObject *object,
|
2010-12-27 01:36:51 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2008-11-06 17:19:08 +00:00
|
|
|
static void gtk_image_menu_item_screen_changed (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
GdkScreen *previous_screen);
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
static void gtk_image_menu_item_recalculate (GtkImageMenuItem *image_menu_item);
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
static void gtk_image_menu_item_activatable_interface_init (GtkActivatableIface *iface);
|
2009-02-22 05:20:14 +00:00
|
|
|
static void gtk_image_menu_item_update (GtkActivatable *activatable,
|
2010-12-27 01:36:51 +00:00
|
|
|
GtkAction *action,
|
|
|
|
const gchar *property_name);
|
2009-02-22 05:20:14 +00:00
|
|
|
static void gtk_image_menu_item_sync_action_properties (GtkActivatable *activatable,
|
2010-12-27 01:36:51 +00:00
|
|
|
GtkAction *action);
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkImageMenuItem, gtk_image_menu_item, GTK_TYPE_MENU_ITEM,
|
2010-12-27 01:36:51 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
|
|
|
|
gtk_image_menu_item_activatable_interface_init))
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_class_init (GtkImageMenuItemClass *klass)
|
|
|
|
{
|
2008-08-07 13:44:22 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass*) klass;
|
|
|
|
GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
|
|
|
|
GtkMenuItemClass *menu_item_class = (GtkMenuItemClass*) klass;
|
|
|
|
GtkContainerClass *container_class = (GtkContainerClass*) klass;
|
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
widget_class->destroy = gtk_image_menu_item_destroy;
|
2004-02-19 22:39:58 +00:00
|
|
|
widget_class->screen_changed = gtk_image_menu_item_screen_changed;
|
2010-10-27 05:12:41 +00:00
|
|
|
widget_class->get_preferred_width = gtk_image_menu_item_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height = gtk_image_menu_item_get_preferred_height;
|
|
|
|
widget_class->get_preferred_height_for_width = gtk_image_menu_item_get_preferred_height_for_width;
|
2001-02-13 05:44:47 +00:00
|
|
|
widget_class->size_allocate = gtk_image_menu_item_size_allocate;
|
2008-11-02 05:01:23 +00:00
|
|
|
widget_class->map = gtk_image_menu_item_map;
|
2001-02-13 05:44:47 +00:00
|
|
|
|
|
|
|
container_class->forall = gtk_image_menu_item_forall;
|
|
|
|
container_class->remove = gtk_image_menu_item_remove;
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
menu_item_class->toggle_size_request = gtk_image_menu_item_toggle_size_request;
|
2008-11-06 17:19:08 +00:00
|
|
|
menu_item_class->set_label = gtk_image_menu_item_set_label;
|
|
|
|
menu_item_class->get_label = gtk_image_menu_item_get_label;
|
2001-02-15 03:40:48 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
gobject_class->finalize = gtk_image_menu_item_finalize;
|
2001-02-15 03:40:48 +00:00
|
|
|
gobject_class->set_property = gtk_image_menu_item_set_property;
|
|
|
|
gobject_class->get_property = gtk_image_menu_item_get_property;
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2001-02-15 03:40:48 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_IMAGE,
|
|
|
|
g_param_spec_object ("image",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Image widget"),
|
|
|
|
P_("Child widget to appear next to the menu text"),
|
2001-02-15 03:40:48 +00:00
|
|
|
GTK_TYPE_WIDGET,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2008-11-06 17:19:08 +00:00
|
|
|
/**
|
|
|
|
* GtkImageMenuItem:use-stock:
|
|
|
|
*
|
|
|
|
* If %TRUE, the label set in the menuitem is used as a
|
|
|
|
* stock id to select the stock item for the item.
|
|
|
|
*
|
|
|
|
* Since: 2.16
|
2010-12-27 01:36:51 +00:00
|
|
|
*/
|
2008-11-06 17:19:08 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USE_STOCK,
|
|
|
|
g_param_spec_boolean ("use-stock",
|
2010-12-27 01:36:51 +00:00
|
|
|
P_("Use stock"),
|
|
|
|
P_("Whether to use the label text to create a stock menu item"),
|
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2009-01-27 03:56:03 +00:00
|
|
|
/**
|
|
|
|
* GtkImageMenuItem:always-show-image:
|
|
|
|
*
|
2010-12-27 01:36:51 +00:00
|
|
|
* If %TRUE, the menu item will ignore the #GtkSettings:gtk-menu-images
|
2009-01-27 03:56:03 +00:00
|
|
|
* setting and always show the image, if available.
|
|
|
|
*
|
|
|
|
* Use this property if the menuitem would be useless or hard to use
|
2010-12-27 01:36:51 +00:00
|
|
|
* without the image.
|
2009-01-27 03:56:03 +00:00
|
|
|
*
|
|
|
|
* Since: 2.16
|
2010-12-27 01:36:51 +00:00
|
|
|
*/
|
2009-01-27 03:56:03 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ALWAYS_SHOW_IMAGE,
|
|
|
|
g_param_spec_boolean ("always-show-image",
|
2010-12-27 01:36:51 +00:00
|
|
|
P_("Always show image"),
|
|
|
|
P_("Whether the image will always be shown"),
|
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2009-01-27 03:56:03 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
/**
|
|
|
|
* GtkImageMenuItem:accel-group:
|
|
|
|
*
|
|
|
|
* The Accel Group to use for stock accelerator keys
|
|
|
|
*
|
|
|
|
* Since: 2.16
|
2010-12-27 01:36:51 +00:00
|
|
|
*/
|
2008-11-06 17:19:08 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ACCEL_GROUP,
|
|
|
|
g_param_spec_object ("accel-group",
|
2010-12-27 01:36:51 +00:00
|
|
|
P_("Accel Group"),
|
|
|
|
P_("The Accel Group to use for stock accelerator keys"),
|
|
|
|
GTK_TYPE_ACCEL_GROUP,
|
|
|
|
GTK_PARAM_WRITABLE));
|
2004-02-19 22:39:58 +00:00
|
|
|
|
2010-10-19 10:47:40 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GtkImageMenuItemPrivate));
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_image_menu_item_init (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
image_menu_item->priv = G_TYPE_INSTANCE_GET_PRIVATE (image_menu_item,
|
|
|
|
GTK_TYPE_IMAGE_MENU_ITEM,
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate);
|
2010-06-23 21:40:06 +00:00
|
|
|
priv = image_menu_item->priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
priv->image = NULL;
|
|
|
|
priv->use_stock = FALSE;
|
|
|
|
priv->label = NULL;
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
static void
|
2008-11-06 17:19:08 +00:00
|
|
|
gtk_image_menu_item_finalize (GObject *object)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (object)->priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
g_free (priv->label);
|
|
|
|
priv->label = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_image_menu_item_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
static void
|
2001-02-15 03:40:48 +00:00
|
|
|
gtk_image_menu_item_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
2001-03-07 14:49:21 +00:00
|
|
|
GParamSpec *pspec)
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
2001-02-15 03:40:48 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (object);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2001-02-15 03:40:48 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_IMAGE:
|
2008-11-06 17:19:08 +00:00
|
|
|
gtk_image_menu_item_set_image (image_menu_item, (GtkWidget *) g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
case PROP_USE_STOCK:
|
|
|
|
gtk_image_menu_item_set_use_stock (image_menu_item, g_value_get_boolean (value));
|
|
|
|
break;
|
2009-01-27 03:56:03 +00:00
|
|
|
case PROP_ALWAYS_SHOW_IMAGE:
|
|
|
|
gtk_image_menu_item_set_always_show_image (image_menu_item, g_value_get_boolean (value));
|
|
|
|
break;
|
2008-11-06 17:19:08 +00:00
|
|
|
case PROP_ACCEL_GROUP:
|
|
|
|
gtk_image_menu_item_set_accel_group (image_menu_item, g_value_get_object (value));
|
2001-02-15 03:40:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2001-02-15 03:40:48 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
2001-03-07 14:49:21 +00:00
|
|
|
GParamSpec *pspec)
|
2001-02-15 03:40:48 +00:00
|
|
|
{
|
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (object);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2001-02-15 03:40:48 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_IMAGE:
|
2008-11-06 17:19:08 +00:00
|
|
|
g_value_set_object (value, gtk_image_menu_item_get_image (image_menu_item));
|
|
|
|
break;
|
|
|
|
case PROP_USE_STOCK:
|
2010-12-27 01:36:51 +00:00
|
|
|
g_value_set_boolean (value, gtk_image_menu_item_get_use_stock (image_menu_item));
|
2001-02-15 03:40:48 +00:00
|
|
|
break;
|
2009-01-27 03:56:03 +00:00
|
|
|
case PROP_ALWAYS_SHOW_IMAGE:
|
|
|
|
g_value_set_boolean (value, gtk_image_menu_item_get_always_show_image (image_menu_item));
|
|
|
|
break;
|
2001-02-15 03:40:48 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2004-02-19 22:39:58 +00:00
|
|
|
static gboolean
|
|
|
|
show_image (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2004-02-19 22:39:58 +00:00
|
|
|
GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (image_menu_item));
|
|
|
|
gboolean show;
|
|
|
|
|
2009-01-27 03:56:03 +00:00
|
|
|
if (priv->always_show_image)
|
|
|
|
show = TRUE;
|
|
|
|
else
|
|
|
|
g_object_get (settings, "gtk-menu-images", &show, NULL);
|
2004-02-19 22:39:58 +00:00
|
|
|
|
|
|
|
return show;
|
|
|
|
}
|
2001-02-15 03:40:48 +00:00
|
|
|
|
2008-11-02 05:01:23 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2008-11-02 05:01:23 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->map (widget);
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image)
|
|
|
|
g_object_set (priv->image,
|
2008-11-02 05:01:23 +00:00
|
|
|
"visible", show_image (image_menu_item),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2008-08-07 13:44:22 +00:00
|
|
|
static void
|
2010-09-18 23:55:42 +00:00
|
|
|
gtk_image_menu_item_destroy (GtkWidget *widget)
|
2008-08-07 13:44:22 +00:00
|
|
|
{
|
2010-09-18 23:55:42 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2008-08-07 13:44:22 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image)
|
2008-08-07 13:44:22 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (image_menu_item),
|
2010-06-23 21:40:06 +00:00
|
|
|
priv->image);
|
2008-08-07 13:44:22 +00:00
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->destroy (widget);
|
2008-08-07 13:44:22 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_toggle_size_request (GtkMenuItem *menu_item,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint *requisition)
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
2002-01-30 22:29:03 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (menu_item);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2005-07-03 06:24:04 +00:00
|
|
|
GtkPackDirection pack_dir;
|
2010-08-11 21:10:32 +00:00
|
|
|
GtkWidget *parent;
|
|
|
|
GtkWidget *widget = GTK_WIDGET (menu_item);
|
2010-06-23 21:40:06 +00:00
|
|
|
|
2010-08-11 21:10:32 +00:00
|
|
|
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));
|
2005-07-03 06:24:04 +00:00
|
|
|
else
|
|
|
|
pack_dir = GTK_PACK_DIRECTION_LTR;
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2003-07-26 13:22:42 +00:00
|
|
|
*requisition = 0;
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image && gtk_widget_get_visible (priv->image))
|
2003-07-06 13:14:28 +00:00
|
|
|
{
|
2004-06-03 19:22:28 +00:00
|
|
|
GtkRequisition image_requisition;
|
2005-07-03 06:24:04 +00:00
|
|
|
guint toggle_spacing;
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (priv->image, &image_requisition, NULL);
|
2004-06-03 19:22:28 +00:00
|
|
|
|
2005-07-03 06:24:04 +00:00
|
|
|
gtk_widget_style_get (GTK_WIDGET (menu_item),
|
2010-12-27 01:36:51 +00:00
|
|
|
"toggle-spacing", &toggle_spacing,
|
|
|
|
NULL);
|
|
|
|
|
2005-07-03 06:24:04 +00:00
|
|
|
if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
|
2010-12-27 01:36:51 +00:00
|
|
|
{
|
|
|
|
if (image_requisition.width > 0)
|
|
|
|
*requisition = image_requisition.width + toggle_spacing;
|
|
|
|
}
|
2005-07-03 06:24:04 +00:00
|
|
|
else
|
2010-12-27 01:36:51 +00:00
|
|
|
{
|
|
|
|
if (image_requisition.height > 0)
|
|
|
|
*requisition = image_requisition.height + toggle_spacing;
|
|
|
|
}
|
2003-07-06 13:14:28 +00:00
|
|
|
}
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_recalculate (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
GtkStockItem stock_item;
|
|
|
|
GtkWidget *image;
|
|
|
|
const gchar *resolved_label = priv->label;
|
|
|
|
|
|
|
|
if (priv->use_stock && priv->label)
|
|
|
|
{
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (!priv->image)
|
2010-12-27 01:36:51 +00:00
|
|
|
{
|
|
|
|
image = gtk_image_new_from_stock (priv->label, GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_image_menu_item_set_image (image_menu_item, image);
|
|
|
|
}
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
if (gtk_stock_lookup (priv->label, &stock_item))
|
2010-12-27 01:36:51 +00:00
|
|
|
resolved_label = stock_item.label;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_menu_item_set_use_underline (GTK_MENU_ITEM (image_menu_item), TRUE);
|
2008-11-06 17:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GTK_MENU_ITEM_CLASS
|
|
|
|
(gtk_image_menu_item_parent_class)->set_label (GTK_MENU_ITEM (image_menu_item), resolved_label);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
static void
|
2008-11-06 17:19:08 +00:00
|
|
|
gtk_image_menu_item_set_label (GtkMenuItem *menu_item,
|
2010-12-27 01:36:51 +00:00
|
|
|
const gchar *label)
|
2008-11-06 17:19:08 +00:00
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (menu_item)->priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
if (priv->label != label)
|
|
|
|
{
|
|
|
|
g_free (priv->label);
|
|
|
|
priv->label = g_strdup (label);
|
|
|
|
|
|
|
|
gtk_image_menu_item_recalculate (GTK_IMAGE_MENU_ITEM (menu_item));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (menu_item), "label");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static G_CONST_RETURN gchar *
|
|
|
|
gtk_image_menu_item_get_label (GtkMenuItem *menu_item)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (menu_item)->priv;
|
2010-06-23 21:40:06 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
return priv->label;
|
|
|
|
}
|
2001-02-13 05:44:47 +00:00
|
|
|
|
|
|
|
static void
|
2010-10-27 05:12:41 +00:00
|
|
|
gtk_image_menu_item_get_preferred_width (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
2010-06-23 21:40:06 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2005-07-03 06:24:04 +00:00
|
|
|
gint child_width = 0;
|
|
|
|
GtkPackDirection pack_dir;
|
2010-08-11 21:10:32 +00:00
|
|
|
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));
|
2005-07-03 06:24:04 +00:00
|
|
|
else
|
|
|
|
pack_dir = GTK_PACK_DIRECTION_LTR;
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image && gtk_widget_get_visible (priv->image))
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
|
|
|
GtkRequisition child_requisition;
|
2010-06-23 21:40:06 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2005-07-03 06:24:04 +00:00
|
|
|
child_width = child_requisition.width;
|
2010-10-27 05:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_width (widget, minimum, natural);
|
|
|
|
|
|
|
|
if (pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT)
|
|
|
|
{
|
|
|
|
*minimum = MAX (*minimum, child_width);
|
|
|
|
*natural = MAX (*natural, child_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_image_menu_item_get_preferred_height (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
2010-10-27 05:12:41 +00:00
|
|
|
{
|
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
|
|
|
|
GtkImageMenuItemPrivate *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);
|
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
child_height = child_requisition.height;
|
|
|
|
}
|
2008-08-12 09:06:34 +00:00
|
|
|
|
2010-10-27 05:12:41 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_height (widget, minimum, natural);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2010-10-27 05:12:41 +00:00
|
|
|
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
|
|
|
|
gtk_image_menu_item_get_preferred_height_for_width (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
2010-10-27 05:12:41 +00:00
|
|
|
{
|
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
|
|
|
|
GtkImageMenuItemPrivate *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));
|
2005-07-03 06:24:04 +00:00
|
|
|
else
|
2010-10-27 05:12:41 +00:00
|
|
|
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
|
|
|
|
(gtk_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);
|
|
|
|
}
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-27 05:12:41 +00:00
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
2010-06-23 21:40:06 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2010-08-11 21:10:32 +00:00
|
|
|
GtkAllocation widget_allocation;
|
2005-07-03 06:24:04 +00:00
|
|
|
GtkPackDirection pack_dir;
|
2010-08-11 21:10:32 +00:00
|
|
|
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));
|
2005-07-03 06:24:04 +00:00
|
|
|
else
|
|
|
|
pack_dir = GTK_PACK_DIRECTION_LTR;
|
2008-08-12 09:06:34 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->size_allocate (widget, allocation);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image && gtk_widget_get_visible (priv->image))
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
2004-06-03 19:22:28 +00:00
|
|
|
gint x, y, offset;
|
|
|
|
GtkRequisition child_requisition;
|
2001-02-13 05:44:47 +00:00
|
|
|
GtkAllocation child_allocation;
|
2003-07-06 13:14:28 +00:00
|
|
|
guint horizontal_padding, toggle_spacing;
|
2010-12-27 01:36:51 +00:00
|
|
|
gint toggle_size;
|
2003-07-06 13:14:28 +00:00
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
toggle_size = GTK_MENU_ITEM (image_menu_item)->priv->toggle_size;
|
2003-07-06 13:14:28 +00:00
|
|
|
gtk_widget_style_get (widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
"horizontal-padding", &horizontal_padding,
|
|
|
|
"toggle-spacing", &toggle_spacing,
|
|
|
|
NULL);
|
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
/* Man this is lame hardcoding action, but I can't
|
|
|
|
* come up with a solution that's really better.
|
|
|
|
*/
|
2004-06-03 19:22:28 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
|
2004-06-03 19:22:28 +00:00
|
|
|
|
2010-08-11 21:10:32 +00:00
|
|
|
gtk_widget_get_allocation (widget, &widget_allocation);
|
|
|
|
|
2005-07-03 06:24:04 +00:00
|
|
|
if (pack_dir == GTK_PACK_DIRECTION_LTR ||
|
2010-12-27 01:36:51 +00:00
|
|
|
pack_dir == GTK_PACK_DIRECTION_RTL)
|
|
|
|
{
|
|
|
|
offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item)) +
|
2010-08-11 21:10:32 +00:00
|
|
|
gtk_widget_get_style (widget)->xthickness;
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
|
|
|
|
(pack_dir == GTK_PACK_DIRECTION_LTR))
|
|
|
|
x = offset + horizontal_padding +
|
|
|
|
(toggle_size - toggle_spacing - child_requisition.width) / 2;
|
|
|
|
else
|
2010-08-11 21:10:32 +00:00
|
|
|
x = widget_allocation.width - offset - horizontal_padding -
|
2010-12-27 01:36:51 +00:00
|
|
|
toggle_size + toggle_spacing +
|
|
|
|
(toggle_size - toggle_spacing - child_requisition.width) / 2;
|
2010-08-11 21:10:32 +00:00
|
|
|
|
|
|
|
y = (widget_allocation.height - child_requisition.height) / 2;
|
2010-12-27 01:36:51 +00:00
|
|
|
}
|
2003-07-06 13:14:28 +00:00
|
|
|
else
|
2010-12-27 01:36:51 +00:00
|
|
|
{
|
|
|
|
offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item)) +
|
2010-08-11 21:10:32 +00:00
|
|
|
gtk_widget_get_style (widget)->ythickness;
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
|
|
|
|
(pack_dir == GTK_PACK_DIRECTION_TTB))
|
|
|
|
y = offset + horizontal_padding +
|
|
|
|
(toggle_size - toggle_spacing - child_requisition.height) / 2;
|
|
|
|
else
|
2010-08-11 21:10:32 +00:00
|
|
|
y = widget_allocation.height - offset - horizontal_padding -
|
2010-12-27 01:36:51 +00:00
|
|
|
toggle_size + toggle_spacing +
|
|
|
|
(toggle_size - toggle_spacing - child_requisition.height) / 2;
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2010-08-11 21:10:32 +00:00
|
|
|
x = (widget_allocation.width - child_requisition.width) / 2;
|
2010-12-27 01:36:51 +00:00
|
|
|
}
|
|
|
|
|
2004-06-03 19:22:28 +00:00
|
|
|
child_allocation.width = child_requisition.width;
|
|
|
|
child_allocation.height = child_requisition.height;
|
2010-08-11 21:10:32 +00:00
|
|
|
child_allocation.x = widget_allocation.x + MAX (x, 0);
|
|
|
|
child_allocation.y = widget_allocation.y + MAX (y, 0);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
gtk_widget_size_allocate (priv->image, &child_allocation);
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_image_menu_item_forall (GtkContainer *container,
|
2010-12-27 01:36:51 +00:00
|
|
|
gboolean include_internals,
|
2001-02-13 05:44:47 +00:00
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
2002-01-30 22:29:03 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (container);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2008-08-12 09:06:34 +00:00
|
|
|
|
|
|
|
GTK_CONTAINER_CLASS (gtk_image_menu_item_parent_class)->forall (container,
|
|
|
|
include_internals,
|
|
|
|
callback,
|
|
|
|
callback_data);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (include_internals && priv->image)
|
|
|
|
(* callback) (priv->image, callback_data);
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
static void
|
2009-01-23 15:15:28 +00:00
|
|
|
gtk_image_menu_item_activatable_interface_init (GtkActivatableIface *iface)
|
|
|
|
{
|
|
|
|
parent_activatable_iface = g_type_interface_peek_parent (iface);
|
2009-02-22 05:20:14 +00:00
|
|
|
iface->update = gtk_image_menu_item_update;
|
|
|
|
iface->sync_action_properties = gtk_image_menu_item_sync_action_properties;
|
2009-01-23 15:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
activatable_update_stock_id (GtkImageMenuItem *image_menu_item, GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
const gchar *stock_id = gtk_action_get_stock_id (action);
|
|
|
|
|
|
|
|
image = gtk_image_menu_item_get_image (image_menu_item);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
if (GTK_IS_IMAGE (image) &&
|
|
|
|
stock_id && gtk_icon_factory_lookup_default (stock_id))
|
|
|
|
{
|
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (image), stock_id, GTK_ICON_SIZE_MENU);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
activatable_update_gicon (GtkImageMenuItem *image_menu_item, GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
GIcon *icon = gtk_action_get_gicon (action);
|
|
|
|
const gchar *stock_id = gtk_action_get_stock_id (action);
|
|
|
|
|
|
|
|
image = gtk_image_menu_item_get_image (image_menu_item);
|
|
|
|
|
|
|
|
if (icon && GTK_IS_IMAGE (image) &&
|
|
|
|
!(stock_id && gtk_icon_factory_lookup_default (stock_id)))
|
|
|
|
{
|
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_MENU);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activatable_update_icon_name (GtkImageMenuItem *image_menu_item, GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
const gchar *icon_name = gtk_action_get_icon_name (action);
|
|
|
|
|
|
|
|
image = gtk_image_menu_item_get_image (image_menu_item);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
|
|
|
if (GTK_IS_IMAGE (image) &&
|
2009-01-23 15:15:28 +00:00
|
|
|
(gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
|
|
|
|
gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME))
|
|
|
|
{
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name, GTK_ICON_SIZE_MENU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
static void
|
|
|
|
gtk_image_menu_item_update (GtkActivatable *activatable,
|
2010-12-27 01:36:51 +00:00
|
|
|
GtkAction *action,
|
|
|
|
const gchar *property_name)
|
2009-01-23 15:15:28 +00:00
|
|
|
{
|
|
|
|
GtkImageMenuItem *image_menu_item;
|
|
|
|
gboolean use_appearance;
|
|
|
|
|
|
|
|
image_menu_item = GTK_IMAGE_MENU_ITEM (activatable);
|
|
|
|
|
|
|
|
parent_activatable_iface->update (activatable, action, property_name);
|
|
|
|
|
|
|
|
use_appearance = gtk_activatable_get_use_action_appearance (activatable);
|
|
|
|
if (!use_appearance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (strcmp (property_name, "stock-id") == 0)
|
|
|
|
activatable_update_stock_id (image_menu_item, action);
|
|
|
|
else if (strcmp (property_name, "gicon") == 0)
|
|
|
|
activatable_update_gicon (image_menu_item, action);
|
|
|
|
else if (strcmp (property_name, "icon-name") == 0)
|
|
|
|
activatable_update_icon_name (image_menu_item, action);
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
static void
|
2009-02-22 05:20:14 +00:00
|
|
|
gtk_image_menu_item_sync_action_properties (GtkActivatable *activatable,
|
2010-12-27 01:36:51 +00:00
|
|
|
GtkAction *action)
|
2009-01-23 15:15:28 +00:00
|
|
|
{
|
|
|
|
GtkImageMenuItem *image_menu_item;
|
|
|
|
GtkWidget *image;
|
|
|
|
gboolean use_appearance;
|
|
|
|
|
|
|
|
image_menu_item = GTK_IMAGE_MENU_ITEM (activatable);
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
parent_activatable_iface->sync_action_properties (activatable, action);
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
|
|
if (!action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
use_appearance = gtk_activatable_get_use_action_appearance (activatable);
|
|
|
|
if (!use_appearance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
image = gtk_image_menu_item_get_image (image_menu_item);
|
|
|
|
if (image && !GTK_IS_IMAGE (image))
|
|
|
|
{
|
|
|
|
gtk_image_menu_item_set_image (image_menu_item, NULL);
|
|
|
|
image = NULL;
|
|
|
|
}
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
if (!image)
|
|
|
|
{
|
|
|
|
image = gtk_image_new ();
|
|
|
|
gtk_widget_show (image);
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (activatable),
|
2010-12-27 01:36:51 +00:00
|
|
|
image);
|
2009-01-23 15:15:28 +00:00
|
|
|
}
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
if (!activatable_update_stock_id (image_menu_item, action) &&
|
|
|
|
!activatable_update_gicon (image_menu_item, action))
|
|
|
|
activatable_update_icon_name (image_menu_item, action);
|
|
|
|
|
2009-08-16 20:57:49 +00:00
|
|
|
gtk_image_menu_item_set_always_show_image (image_menu_item,
|
|
|
|
gtk_action_get_always_show_image (action));
|
2009-01-23 15:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-28 21:15:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_new:
|
|
|
|
* @returns: a new #GtkImageMenuItem.
|
|
|
|
*
|
|
|
|
* Creates a new #GtkImageMenuItem with an empty label.
|
|
|
|
**/
|
2001-02-13 05:44:47 +00:00
|
|
|
GtkWidget*
|
2001-05-18 17:35:20 +00:00
|
|
|
gtk_image_menu_item_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM, NULL);
|
|
|
|
}
|
|
|
|
|
2001-10-28 21:15:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_new_with_label:
|
|
|
|
* @label: the text of the menu item.
|
|
|
|
* @returns: a new #GtkImageMenuItem.
|
|
|
|
*
|
2010-12-27 01:36:51 +00:00
|
|
|
* Creates a new #GtkImageMenuItem containing a label.
|
|
|
|
*/
|
2001-05-18 17:35:20 +00:00
|
|
|
GtkWidget*
|
|
|
|
gtk_image_menu_item_new_with_label (const gchar *label)
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
2010-12-27 01:36:51 +00:00
|
|
|
return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM,
|
|
|
|
"label", label,
|
|
|
|
NULL);
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2001-06-05 18:22:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_new_with_mnemonic:
|
2001-10-28 21:15:36 +00:00
|
|
|
* @label: the text of the menu item, with an underscore in front of the
|
2001-06-05 18:22:30 +00:00
|
|
|
* mnemonic character
|
|
|
|
* @returns: a new #GtkImageMenuItem
|
|
|
|
*
|
|
|
|
* Creates a new #GtkImageMenuItem containing a label. The label
|
|
|
|
* will be created using gtk_label_new_with_mnemonic(), so underscores
|
|
|
|
* in @label indicate the mnemonic for the menu item.
|
2010-12-27 01:36:51 +00:00
|
|
|
*/
|
2001-06-05 18:22:30 +00:00
|
|
|
GtkWidget*
|
|
|
|
gtk_image_menu_item_new_with_mnemonic (const gchar *label)
|
|
|
|
{
|
2010-12-27 01:36:51 +00:00
|
|
|
return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM,
|
|
|
|
"use-underline", TRUE,
|
|
|
|
"label", label,
|
|
|
|
NULL);
|
2001-06-05 18:22:30 +00:00
|
|
|
}
|
|
|
|
|
2001-10-28 21:15:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_new_from_stock:
|
|
|
|
* @stock_id: the name of the stock item.
|
2010-12-27 01:36:51 +00:00
|
|
|
* @accel_group: (allow-none): the #GtkAccelGroup to add the menu items
|
2010-06-07 20:15:39 +00:00
|
|
|
* accelerator to, or %NULL.
|
2001-10-28 21:15:36 +00:00
|
|
|
* @returns: a new #GtkImageMenuItem.
|
|
|
|
*
|
2010-12-27 01:36:51 +00:00
|
|
|
* Creates a new #GtkImageMenuItem containing the image and text from a
|
|
|
|
* stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK
|
2001-10-28 21:15:36 +00:00
|
|
|
* and #GTK_STOCK_APPLY.
|
2002-03-03 01:43:01 +00:00
|
|
|
*
|
2002-10-11 20:36:21 +00:00
|
|
|
* If you want this menu item to have changeable accelerators, then pass in
|
|
|
|
* %NULL for accel_group. Next call gtk_menu_item_set_accel_path() with an
|
|
|
|
* appropriate path for the menu item, use gtk_stock_lookup() to look up the
|
|
|
|
* standard accelerator for the stock item, and if one is found, call
|
|
|
|
* gtk_accel_map_add_entry() to register it.
|
2010-12-27 01:36:51 +00:00
|
|
|
*/
|
2001-03-21 08:56:25 +00:00
|
|
|
GtkWidget*
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_image_menu_item_new_from_stock (const gchar *stock_id,
|
|
|
|
GtkAccelGroup *accel_group)
|
2001-03-21 08:56:25 +00:00
|
|
|
{
|
2010-12-27 01:36:51 +00:00
|
|
|
return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM,
|
|
|
|
"label", stock_id,
|
|
|
|
"use-stock", TRUE,
|
|
|
|
"accel-group", accel_group,
|
|
|
|
NULL);
|
2008-11-06 17:19:08 +00:00
|
|
|
}
|
2001-03-21 08:56:25 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_set_use_stock:
|
|
|
|
* @image_menu_item: a #GtkImageMenuItem
|
|
|
|
* @use_stock: %TRUE if the menuitem should use a stock item
|
|
|
|
*
|
|
|
|
* If %TRUE, the label set in the menuitem is used as a
|
|
|
|
* stock id to select the stock item for the item.
|
|
|
|
*
|
|
|
|
* Since: 2.16
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_image_menu_item_set_use_stock (GtkImageMenuItem *image_menu_item,
|
2010-12-27 01:36:51 +00:00
|
|
|
gboolean use_stock)
|
2008-11-06 17:19:08 +00:00
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
|
2001-03-21 08:56:25 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
priv = image_menu_item->priv;
|
2001-03-21 08:56:25 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
if (priv->use_stock != use_stock)
|
2001-03-21 08:56:25 +00:00
|
|
|
{
|
2008-11-06 17:19:08 +00:00
|
|
|
priv->use_stock = use_stock;
|
2001-05-18 17:35:20 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
gtk_image_menu_item_recalculate (image_menu_item);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (image_menu_item), "use-stock");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_get_use_stock:
|
|
|
|
* @image_menu_item: a #GtkImageMenuItem
|
|
|
|
*
|
|
|
|
* Checks whether the label set in the menuitem is used as a
|
|
|
|
* stock id to select the stock item for the item.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the label set in the menuitem is used as a
|
2008-12-29 04:34:04 +00:00
|
|
|
* stock id to select the stock item for the item
|
2008-11-06 17:19:08 +00:00
|
|
|
*
|
|
|
|
* Since: 2.16
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_image_menu_item_get_use_stock (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item), FALSE);
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
return image_menu_item->priv->use_stock;
|
2008-11-06 17:19:08 +00:00
|
|
|
}
|
|
|
|
|
2009-01-27 03:56:03 +00:00
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_set_always_show_image:
|
|
|
|
* @image_menu_item: a #GtkImageMenuItem
|
|
|
|
* @always_show: %TRUE if the menuitem should always show the image
|
|
|
|
*
|
2010-12-27 01:36:51 +00:00
|
|
|
* If %TRUE, the menu item will ignore the #GtkSettings:gtk-menu-images
|
2009-01-27 03:56:03 +00:00
|
|
|
* setting and always show the image, if available.
|
|
|
|
*
|
|
|
|
* Use this property if the menuitem would be useless or hard to use
|
2010-12-27 01:36:51 +00:00
|
|
|
* without the image.
|
|
|
|
*
|
2009-01-27 03:56:03 +00:00
|
|
|
* Since: 2.16
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_image_menu_item_set_always_show_image (GtkImageMenuItem *image_menu_item,
|
|
|
|
gboolean always_show)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv;
|
2009-01-27 03:56:03 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
priv = image_menu_item->priv;
|
2009-01-27 03:56:03 +00:00
|
|
|
|
|
|
|
if (priv->always_show_image != always_show)
|
|
|
|
{
|
|
|
|
priv->always_show_image = always_show;
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image)
|
2009-01-27 03:56:03 +00:00
|
|
|
{
|
|
|
|
if (show_image (image_menu_item))
|
2010-06-23 21:40:06 +00:00
|
|
|
gtk_widget_show (priv->image);
|
2009-01-27 03:56:03 +00:00
|
|
|
else
|
2010-06-23 21:40:06 +00:00
|
|
|
gtk_widget_hide (priv->image);
|
2009-01-27 03:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (image_menu_item), "always-show-image");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_get_always_show_image:
|
|
|
|
* @image_menu_item: a #GtkImageMenuItem
|
|
|
|
*
|
2009-11-27 05:46:18 +00:00
|
|
|
* Returns whether the menu item will ignore the #GtkSettings:gtk-menu-images
|
2009-01-27 03:56:03 +00:00
|
|
|
* setting and always show the image, if available.
|
2010-12-27 01:36:51 +00:00
|
|
|
*
|
2009-01-27 03:56:03 +00:00
|
|
|
* Returns: %TRUE if the menu item will always show the image
|
|
|
|
*
|
|
|
|
* Since: 2.16
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_image_menu_item_get_always_show_image (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item), FALSE);
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
return image_menu_item->priv->always_show_image;
|
2009-01-27 03:56:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_set_accel_group:
|
|
|
|
* @image_menu_item: a #GtkImageMenuItem
|
|
|
|
* @accel_group: the #GtkAccelGroup
|
|
|
|
*
|
|
|
|
* Specifies an @accel_group to add the menu items accelerator to
|
|
|
|
* (this only applies to stock items so a stock item must already
|
|
|
|
* be set, make sure to call gtk_image_menu_item_set_use_stock()
|
|
|
|
* and gtk_menu_item_set_label() with a valid stock item first).
|
|
|
|
*
|
|
|
|
* If you want this menu item to have changeable accelerators then
|
|
|
|
* you shouldnt need this (see gtk_image_menu_item_new_from_stock()).
|
|
|
|
*
|
|
|
|
* Since: 2.16
|
|
|
|
*/
|
|
|
|
void
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_image_menu_item_set_accel_group (GtkImageMenuItem *image_menu_item,
|
|
|
|
GtkAccelGroup *accel_group)
|
2008-11-06 17:19:08 +00:00
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
GtkStockItem stock_item;
|
|
|
|
|
|
|
|
/* Silent return for the constructor */
|
2010-12-27 01:36:51 +00:00
|
|
|
if (!accel_group)
|
2008-11-06 17:19:08 +00:00
|
|
|
return;
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2008-11-06 17:19:08 +00:00
|
|
|
g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
|
|
|
|
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
priv = image_menu_item->priv;
|
2008-11-06 17:19:08 +00:00
|
|
|
|
|
|
|
if (priv->use_stock && priv->label && gtk_stock_lookup (priv->label, &stock_item))
|
|
|
|
if (stock_item.keyval)
|
|
|
|
{
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_widget_add_accelerator (GTK_WIDGET (image_menu_item),
|
|
|
|
"activate",
|
|
|
|
accel_group,
|
|
|
|
stock_item.keyval,
|
|
|
|
stock_item.modifier,
|
|
|
|
GTK_ACCEL_VISIBLE);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (image_menu_item), "accel-group");
|
2008-11-06 17:19:08 +00:00
|
|
|
}
|
2001-03-21 08:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
/**
|
2001-10-28 21:15:36 +00:00
|
|
|
* gtk_image_menu_item_set_image:
|
|
|
|
* @image_menu_item: a #GtkImageMenuItem.
|
2009-12-10 10:23:40 +00:00
|
|
|
* @image: (allow-none): a widget to set as the image for the menu item.
|
|
|
|
*
|
2001-10-28 21:15:36 +00:00
|
|
|
* Sets the image of @image_menu_item to the given widget.
|
2004-11-15 20:07:26 +00:00
|
|
|
* Note that it depends on the show-menu-images setting whether
|
|
|
|
* the image will be displayed or not.
|
2010-12-27 01:36:51 +00:00
|
|
|
*/
|
2001-02-13 05:44:47 +00:00
|
|
|
void
|
2001-05-18 17:35:20 +00:00
|
|
|
gtk_image_menu_item_set_image (GtkImageMenuItem *image_menu_item,
|
|
|
|
GtkWidget *image)
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv;
|
2010-06-23 21:40:06 +00:00
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
|
2001-05-18 17:35:20 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
priv = image_menu_item->priv;
|
|
|
|
|
|
|
|
if (image == priv->image)
|
2001-05-18 17:35:20 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (priv->image)
|
2001-05-18 17:35:20 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (image_menu_item),
|
2010-06-23 21:40:06 +00:00
|
|
|
priv->image);
|
2001-05-18 17:35:20 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
priv->image = image;
|
2001-05-18 17:35:20 +00:00
|
|
|
|
|
|
|
if (image == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_widget_set_parent (image, GTK_WIDGET (image_menu_item));
|
2008-11-02 05:01:23 +00:00
|
|
|
g_object_set (image,
|
2010-12-27 01:36:51 +00:00
|
|
|
"visible", show_image (image_menu_item),
|
|
|
|
"no-show-all", TRUE,
|
|
|
|
NULL);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2001-02-15 03:40:48 +00:00
|
|
|
g_object_notify (G_OBJECT (image_menu_item), "image");
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2001-10-28 21:15:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_image_menu_item_get_image:
|
2010-09-21 04:18:11 +00:00
|
|
|
* @image_menu_item: a #GtkImageMenuItem
|
2001-10-28 21:15:36 +00:00
|
|
|
*
|
|
|
|
* Gets the widget that is currently set as the image of @image_menu_item.
|
|
|
|
* See gtk_image_menu_item_set_image().
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer none): the widget set as image of @image_menu_item
|
2001-10-28 21:15:36 +00:00
|
|
|
**/
|
2001-02-13 05:44:47 +00:00
|
|
|
GtkWidget*
|
|
|
|
gtk_image_menu_item_get_image (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item), NULL);
|
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
return image_menu_item->priv->image;
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
|
2001-02-15 03:40:48 +00:00
|
|
|
static void
|
2001-02-13 05:44:47 +00:00
|
|
|
gtk_image_menu_item_remove (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
2010-06-23 21:40:06 +00:00
|
|
|
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (container);
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2010-06-23 21:40:06 +00:00
|
|
|
if (child == priv->image)
|
2001-02-13 05:44:47 +00:00
|
|
|
{
|
|
|
|
gboolean widget_was_visible;
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
widget_was_visible = gtk_widget_get_visible (child);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2001-02-13 05:44:47 +00:00
|
|
|
gtk_widget_unparent (child);
|
2010-06-23 21:40:06 +00:00
|
|
|
priv->image = NULL;
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (widget_was_visible &&
|
|
|
|
gtk_widget_get_visible (GTK_WIDGET (container)))
|
2001-02-13 05:44:47 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (container));
|
2001-02-15 03:40:48 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (image_menu_item), "image");
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-12 09:06:34 +00:00
|
|
|
GTK_CONTAINER_CLASS (gtk_image_menu_item_parent_class)->remove (container, child);
|
2001-02-13 05:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
static void
|
2004-02-19 22:39:58 +00:00
|
|
|
show_image_change_notify (GtkImageMenuItem *image_menu_item)
|
|
|
|
{
|
2010-08-26 17:15:37 +00:00
|
|
|
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
|
2010-06-23 21:40:06 +00:00
|
|
|
|
|
|
|
if (priv->image)
|
2004-11-15 18:07:22 +00:00
|
|
|
{
|
|
|
|
if (show_image (image_menu_item))
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_widget_show (priv->image);
|
2004-11-15 18:07:22 +00:00
|
|
|
else
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_widget_hide (priv->image);
|
2004-11-15 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
traverse_container (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
gpointer data)
|
2004-11-15 18:07:22 +00:00
|
|
|
{
|
|
|
|
if (GTK_IS_IMAGE_MENU_ITEM (widget))
|
|
|
|
show_image_change_notify (GTK_IMAGE_MENU_ITEM (widget));
|
|
|
|
else if (GTK_IS_CONTAINER (widget))
|
|
|
|
gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_image_menu_item_setting_changed (GtkSettings *settings)
|
|
|
|
{
|
2004-11-16 02:06:20 +00:00
|
|
|
GList *list, *l;
|
2004-11-15 18:07:22 +00:00
|
|
|
|
|
|
|
list = gtk_window_list_toplevels ();
|
|
|
|
|
2004-11-16 02:06:20 +00:00
|
|
|
for (l = list; l; l = l->next)
|
2010-12-27 01:36:51 +00:00
|
|
|
gtk_container_forall (GTK_CONTAINER (l->data),
|
|
|
|
traverse_container, NULL);
|
2004-11-15 18:07:22 +00:00
|
|
|
|
2010-12-27 01:36:51 +00:00
|
|
|
g_list_free (list);
|
2004-02-19 22:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_image_menu_item_screen_changed (GtkWidget *widget,
|
2010-12-27 01:36:51 +00:00
|
|
|
GdkScreen *previous_screen)
|
2004-02-19 22:39:58 +00:00
|
|
|
{
|
|
|
|
GtkSettings *settings;
|
2010-10-08 00:37:23 +00:00
|
|
|
gulong show_image_connection;
|
2004-02-19 22:39:58 +00:00
|
|
|
|
2004-11-15 18:07:22 +00:00
|
|
|
if (!gtk_widget_has_screen (widget))
|
2004-02-19 22:39:58 +00:00
|
|
|
return;
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2004-11-15 18:07:22 +00:00
|
|
|
settings = gtk_widget_get_settings (widget);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
|
|
|
show_image_connection =
|
2010-10-08 00:37:23 +00:00
|
|
|
g_signal_handler_find (settings, G_SIGNAL_MATCH_FUNC, 0, 0,
|
|
|
|
NULL, gtk_image_menu_item_setting_changed, NULL);
|
2010-12-27 01:36:51 +00:00
|
|
|
|
2004-11-15 18:07:22 +00:00
|
|
|
if (show_image_connection)
|
|
|
|
return;
|
2004-02-19 22:39:58 +00:00
|
|
|
|
2010-10-08 00:37:23 +00:00
|
|
|
g_signal_connect (settings, "notify::gtk-menu-images",
|
|
|
|
G_CALLBACK (gtk_image_menu_item_setting_changed), NULL);
|
2004-02-19 22:39:58 +00:00
|
|
|
|
|
|
|
show_image_change_notify (GTK_IMAGE_MENU_ITEM (widget));
|
|
|
|
}
|