#include "gtksettings.h"
#include "gtktypebuiltins.h"
#include "a11y/gtkmenuitemaccessible.h"
-
+#include "deprecated/gtktearoffmenuitem.h"
/**
* SECTION:gtkmenuitem
/* activatable properties */
PROP_ACTIVATABLE_RELATED_ACTION,
- PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
+ PROP_ACTIVATABLE_USE_ACTION_APPEARANCE,
+
+ PROP_ACTION_NAME,
+ PROP_ACTION_TARGET
};
const gchar *tagname,
gpointer user_data);
+static void gtk_menu_item_actionable_interface_init (GtkActionableInterface *iface);
static void gtk_menu_item_activatable_interface_init (GtkActivatableIface *iface);
static void gtk_menu_item_update (GtkActivatable *activatable,
GtkAction *action,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_menu_item_buildable_interface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
- gtk_menu_item_activatable_interface_init))
+ gtk_menu_item_activatable_interface_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE,
+ gtk_menu_item_actionable_interface_init))
+
+static void
+gtk_menu_item_set_action_name (GtkActionable *actionable,
+ const gchar *action_name)
+{
+ GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
+
+ if (!menu_item->priv->action_helper)
+ menu_item->priv->action_helper = gtk_action_helper_new (actionable);
+
+ gtk_action_helper_set_action_name (menu_item->priv->action_helper, action_name);
+}
+
+static void
+gtk_menu_item_set_action_target_value (GtkActionable *actionable,
+ GVariant *action_target)
+{
+ GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
+
+ if (!menu_item->priv->action_helper)
+ menu_item->priv->action_helper = gtk_action_helper_new (actionable);
+
+ gtk_action_helper_set_action_target_value (menu_item->priv->action_helper, action_target);
+}
+
+static const gchar *
+gtk_menu_item_get_action_name (GtkActionable *actionable)
+{
+ GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
+
+ return gtk_action_helper_get_action_name (menu_item->priv->action_helper);
+}
+
+static GVariant *
+gtk_menu_item_get_action_target_value (GtkActionable *actionable)
+{
+ GtkMenuItem *menu_item = GTK_MENU_ITEM (actionable);
+
+ return gtk_action_helper_get_action_target_value (menu_item->priv->action_helper);
+}
+
+static void
+gtk_menu_item_actionable_interface_init (GtkActionableInterface *iface)
+{
+ iface->set_action_name = gtk_menu_item_set_action_name;
+ iface->get_action_name = gtk_menu_item_get_action_name;
+ iface->set_action_target_value = gtk_menu_item_set_action_target_value;
+ iface->get_action_target_value = gtk_menu_item_get_action_target_value;
+}
static void
gtk_menu_item_class_init (GtkMenuItemClass *klass)
g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
+ g_object_class_override_property (gobject_class, PROP_ACTION_NAME, "action-name");
+ g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
+
gtk_widget_class_install_style_property_parser (widget_class,
g_param_spec_enum ("selected-shadow-type",
"Selected Shadow Type",
GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
GtkMenuItemPrivate *priv = menu_item->priv;
+ g_clear_object (&priv->action_helper);
+
if (priv->action)
{
gtk_action_disconnect_accelerator (priv->action);
case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
gtk_menu_item_set_use_action_appearance (menu_item, g_value_get_boolean (value));
break;
+ case PROP_ACTION_NAME:
+ gtk_menu_item_set_action_name (GTK_ACTIONABLE (menu_item), g_value_get_string (value));
+ break;
+ case PROP_ACTION_TARGET:
+ gtk_menu_item_set_action_target_value (GTK_ACTIONABLE (menu_item), g_value_get_variant (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
g_value_set_boolean (value, priv->use_action_appearance);
break;
+ case PROP_ACTION_NAME:
+ g_value_set_string (value, gtk_action_helper_get_action_name (priv->action_helper));
+ break;
+ case PROP_ACTION_TARGET:
+ g_value_set_variant (value, gtk_action_helper_get_action_target_value (priv->action_helper));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
-gboolean _gtk_menu_is_empty (GtkWidget *menu);
+/*
+ * gtk_menu_is_empty:
+ * @menu: (allow-none): a #GtkMenu or %NULL
+ *
+ * Determines whether @menu is empty. A menu is considered empty if it
+ * the only visible children are tearoff menu items or "filler" menu
+ * items which were inserted to mark the menu as empty.
+ *
+ * This function is used by #GtkAction.
+ *
+ * Return value: whether @menu is empty.
+ **/
+static gboolean
+gtk_menu_is_empty (GtkWidget *menu)
+{
+ GList *children, *cur;
+ gboolean result = TRUE;
+
+ g_return_val_if_fail (menu == NULL || GTK_IS_MENU (menu), TRUE);
+
+ if (!menu)
+ return FALSE;
+
+ children = gtk_container_get_children (GTK_CONTAINER (menu));
+
+ cur = children;
+ while (cur)
+ {
+ if (gtk_widget_get_visible (cur->data))
+ {
+ if (!GTK_IS_TEAROFF_MENU_ITEM (cur->data) &&
+ !g_object_get_data (cur->data, "gtk-empty-menu-item"))
+ {
+ result = FALSE;
+ break;
+ }
+ }
+ cur = cur->next;
+ }
+ g_list_free (children);
+
+ return result;
+}
+
static void
gtk_menu_item_update (GtkActivatable *activatable,
if (strcmp (property_name, "visible") == 0)
_gtk_action_sync_menu_visible (action, GTK_WIDGET (menu_item),
- _gtk_menu_is_empty (gtk_menu_item_get_submenu (menu_item)));
+ gtk_menu_is_empty (gtk_menu_item_get_submenu (menu_item)));
else if (strcmp (property_name, "sensitive") == 0)
gtk_widget_set_sensitive (GTK_WIDGET (menu_item), gtk_action_is_sensitive (action));
else if (priv->use_action_appearance)
return;
_gtk_action_sync_menu_visible (action, GTK_WIDGET (menu_item),
- _gtk_menu_is_empty (gtk_menu_item_get_submenu (menu_item)));
+ gtk_menu_is_empty (gtk_menu_item_get_submenu (menu_item)));
gtk_widget_set_sensitive (GTK_WIDGET (menu_item), gtk_action_is_sensitive (action));
child = gtk_bin_get_child (GTK_BIN (menu_item));
parent = gtk_widget_get_parent (widget);
- gtk_style_context_save (context);
-
gtk_style_context_get_padding (context, state, &padding);
- if (GTK_IS_MENU_BAR (parent))
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
-
if (child && (state & GTK_STATE_FLAG_PRELIGHT))
{
gtk_render_background (context, cr, x, y, w, h);
GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->draw (widget, cr);
- gtk_style_context_restore (context);
-
return FALSE;
}
{
GtkMenuItemPrivate *priv = menu_item->priv;
+ if (priv->action_helper)
+ gtk_action_helper_activate (priv->action_helper);
+
if (priv->action)
gtk_action_activate (priv->action);
}
}
/**
- * gtk_menu_item_set_accel_path
+ * gtk_menu_item_set_accel_path:
* @menu_item: a valid #GtkMenuItem
* @accel_path: (allow-none): accelerator path, corresponding to this menu
* item's functionality, or %NULL to unset the current path.
}
/**
- * gtk_menu_item_get_accel_path
+ * gtk_menu_item_get_accel_path:
* @menu_item: a valid #GtkMenuItem
*
* Retrieve the accelerator path that was previously set on @menu_item.