[gtk/global-coords: 11/24] menuitem: Introduce gtk_menu_item_get_menu_shell()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/global-coords: 11/24] menuitem: Introduce gtk_menu_item_get_menu_shell()
- Date: Fri, 31 May 2019 23:37:28 +0000 (UTC)
commit e702a334323d9be112f3f2c8bf905c8bfcfc857c
Author: Benjamin Otte <otte redhat com>
Date: Sun Apr 21 15:50:24 2019 +0200
menuitem: Introduce gtk_menu_item_get_menu_shell()
Returns the parent menu shell or NULL.
Replace all calls to gtk_widget_get_parent() with this function.
gtk/gtkmenuitem.c | 125 +++++++++++++++++++++++++++---------------------------
1 file changed, 63 insertions(+), 62 deletions(-)
---
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 018420c9c5..c0d46800a6 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -262,6 +262,12 @@ gtk_menu_item_actionable_interface_init (GtkActionableInterface *iface)
iface->get_action_target_value = gtk_menu_item_get_action_target_value;
}
+static GtkMenuShell *
+gtk_menu_item_get_menu_shell (GtkMenuItem *item)
+{
+ return GTK_MENU_SHELL (gtk_widget_get_ancestor (GTK_WIDGET (item), GTK_TYPE_MENU_SHELL));
+}
+
static void
gtk_menu_item_size_allocate (GtkWidget *widget,
int width,
@@ -273,13 +279,13 @@ gtk_menu_item_size_allocate (GtkWidget *widget,
GtkAllocation child_allocation;
GtkTextDirection direction;
GtkWidget *child;
- GtkWidget *parent;
+ GtkMenuShell *shell;
g_return_if_fail (GTK_IS_MENU_ITEM (widget));
direction = gtk_widget_get_direction (widget);
- parent = gtk_widget_get_parent (widget);
+ shell = gtk_menu_item_get_menu_shell (menu_item);
child = gtk_bin_get_child (GTK_BIN (widget));
if (child)
@@ -290,7 +296,7 @@ gtk_menu_item_size_allocate (GtkWidget *widget,
child_allocation.x += priv->toggle_size;
child_allocation.width -= priv->toggle_size;
- if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
+ if ((priv->submenu && !GTK_IS_MENU_BAR (shell)) || priv->reserve_indicator)
{
GtkAllocation arrow_alloc;
@@ -359,13 +365,13 @@ gtk_menu_item_real_get_width (GtkWidget *widget,
GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
GtkMenuItemPrivate *priv = menu_item->priv;
GtkWidget *child;
- GtkWidget *parent;
+ GtkMenuShell *shell;
guint accel_width;
gint min_width, nat_width;
min_width = nat_width = 0;
- parent = gtk_widget_get_parent (widget);
+ shell = gtk_menu_item_get_menu_shell (menu_item);
child = gtk_bin_get_child (GTK_BIN (widget));
if (child != NULL && gtk_widget_get_visible (child))
@@ -375,7 +381,7 @@ gtk_menu_item_real_get_width (GtkWidget *widget,
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, -1,
&child_min, &child_nat, NULL, NULL);
- if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
+ if ((priv->submenu && !GTK_IS_MENU_BAR (shell)) || priv->reserve_indicator)
{
gint arrow_size;
@@ -412,7 +418,7 @@ gtk_menu_item_real_get_height (GtkWidget *widget,
GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
GtkMenuItemPrivate *priv = menu_item->priv;
GtkWidget *child;
- GtkWidget *parent;
+ GtkMenuShell *shell;
guint accel_width;
gint min_height, nat_height;
gint avail_size = 0;
@@ -422,7 +428,7 @@ gtk_menu_item_real_get_height (GtkWidget *widget,
if (for_size != -1)
avail_size = for_size;
- parent = gtk_widget_get_parent (widget);
+ shell = gtk_menu_item_get_menu_shell (menu_item);
child = gtk_bin_get_child (GTK_BIN (widget));
if (child != NULL && gtk_widget_get_visible (child))
@@ -430,7 +436,7 @@ gtk_menu_item_real_get_height (GtkWidget *widget,
gint child_min, child_nat;
gint arrow_size = 0;
- if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
+ if ((priv->submenu && !GTK_IS_MENU_BAR (shell)) || priv->reserve_indicator)
gtk_widget_measure (priv->arrow_widget,
GTK_ORIENTATION_VERTICAL,
-1,
@@ -871,7 +877,7 @@ gtk_menu_item_buildable_custom_finished (GtkBuildable *buildable,
GtkMenuShell *menu_shell;
GtkWidget *attach;
- menu_shell = GTK_MENU_SHELL (gtk_widget_get_parent (GTK_WIDGET (buildable)));
+ menu_shell = gtk_menu_item_get_menu_shell (GTK_MENU_ITEM (buildable));
if (menu_shell)
{
while (GTK_IS_MENU (menu_shell) &&
@@ -938,7 +944,7 @@ update_arrow_widget (GtkMenuItem *menu_item)
gboolean should_have_arrow;
should_have_arrow = priv->reserve_indicator ||
- (priv->submenu && !GTK_IS_MENU_BAR (gtk_widget_get_parent (widget)));
+ (priv->submenu && !GTK_IS_MENU_BAR (gtk_menu_item_get_menu_shell (menu_item)));
if (should_have_arrow)
{
@@ -993,9 +999,7 @@ gtk_menu_item_set_submenu (GtkMenuItem *menu_item,
}
update_arrow_widget (menu_item);
-
- if (gtk_widget_get_parent (widget))
- gtk_widget_queue_resize (widget);
+ gtk_widget_queue_resize (widget);
g_object_notify_by_pspec (G_OBJECT (menu_item), menu_item_props[PROP_SUBMENU]);
}
@@ -1113,7 +1117,7 @@ gtk_menu_item_enter (GtkEventController *controller,
gpointer user_data)
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
- GtkWidget *menu_shell;
+ GtkMenuShell *menu_shell;
GdkEvent *event;
gboolean is_focus, contains_focus;
@@ -1128,17 +1132,17 @@ gtk_menu_item_enter (GtkEventController *controller,
gdk_event_get_source_device ((GdkEvent*) event))
return;
- menu_shell = gtk_widget_get_parent (GTK_WIDGET (menu_item));
+ menu_shell = gtk_menu_item_get_menu_shell (menu_item);
g_object_get (controller,
"is-pointer-focus", &is_focus,
"contains-pointer-focus", &contains_focus,
NULL);
- if (GTK_IS_MENU_SHELL (menu_shell) &&
- GTK_MENU_SHELL (menu_shell)->priv->active &&
+ if (menu_shell != NULL &&
+ menu_shell->priv->active &&
(is_focus || contains_focus))
- gtk_menu_shell_select_item (GTK_MENU_SHELL (menu_shell), GTK_WIDGET (menu_item));
+ gtk_menu_shell_select_item (menu_shell, GTK_WIDGET (menu_item));
}
static void
@@ -1148,7 +1152,7 @@ gtk_menu_item_leave (GtkEventController *controller,
gpointer user_data)
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
- GtkWidget *menu_shell = gtk_widget_get_parent (GTK_WIDGET (menu_item));
+ GtkMenuShell *menu_shell = gtk_menu_item_get_menu_shell (menu_item);
gboolean is_focus, contains_focus;
g_object_get (controller,
@@ -1156,10 +1160,10 @@ gtk_menu_item_leave (GtkEventController *controller,
"contains-pointer-focus", &contains_focus,
NULL);
- if (GTK_IS_MENU_SHELL (menu_shell) &&
+ if (menu_shell &&
!menu_item->priv->submenu &&
!(is_focus || contains_focus))
- gtk_menu_shell_deselect (GTK_MENU_SHELL (menu_shell));
+ gtk_menu_shell_deselect (menu_shell);
}
static void
@@ -1205,19 +1209,18 @@ static gboolean
gtk_menu_item_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling)
{
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
+
+ menu_shell = gtk_menu_item_get_menu_shell (GTK_MENU_ITEM (widget));
- parent = gtk_widget_get_parent (widget);
-
- if (GTK_IS_MENU_SHELL (parent))
- _gtk_menu_shell_set_keyboard_mode (GTK_MENU_SHELL (parent), TRUE);
+ if (menu_shell)
+ _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
if (group_cycling &&
- parent &&
- GTK_IS_MENU_SHELL (parent) &&
- GTK_MENU_SHELL (parent)->priv->active)
+ menu_shell &&
+ menu_shell->priv->active)
{
- gtk_menu_shell_select_item (GTK_MENU_SHELL (parent), widget);
+ gtk_menu_shell_select_item (menu_shell, widget);
}
else
g_signal_emit (widget, menu_item_signals[ACTIVATE_ITEM], 0);
@@ -1239,16 +1242,14 @@ static void
gtk_real_menu_item_activate_item (GtkMenuItem *menu_item)
{
GtkMenuItemPrivate *priv = menu_item->priv;
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
GtkWidget *widget;
-
+
widget = GTK_WIDGET (menu_item);
- parent = gtk_widget_get_parent (widget);
+ menu_shell = gtk_menu_item_get_menu_shell (menu_item);
- if (parent && GTK_IS_MENU_SHELL (parent))
+ if (menu_shell)
{
- GtkMenuShell *menu_shell = GTK_MENU_SHELL (parent);
-
if (priv->submenu == NULL)
gtk_menu_shell_activate_item (menu_shell, widget, TRUE);
else
@@ -1327,8 +1328,8 @@ popped_up_cb (GtkMenu *menu,
gboolean flipped_y,
GtkMenuItem *menu_item)
{
- GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (menu_item));
- GtkMenu *parent_menu = GTK_IS_MENU (parent) ? GTK_MENU (parent) : NULL;
+ GtkMenuShell *menu_shell = gtk_menu_item_get_menu_shell (menu_item);
+ GtkMenu *parent_menu = GTK_IS_MENU (menu_shell) ? GTK_MENU (menu_shell) : NULL;
if (parent_menu && GTK_IS_MENU_ITEM (parent_menu->priv->parent_menu_item))
menu_item->priv->submenu_direction = GTK_MENU_ITEM
(parent_menu->priv->parent_menu_item)->priv->submenu_direction;
@@ -1367,17 +1368,17 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
GtkBorder menu_padding;
gint horizontal_offset;
gint vertical_offset;
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
GtkMenu *parent_menu;
- parent = gtk_widget_get_parent (widget);
- parent_menu = GTK_IS_MENU (parent) ? GTK_MENU (parent) : NULL;
+ menu_shell = gtk_menu_item_get_menu_shell (menu_item);
+ parent_menu = GTK_IS_MENU (menu_shell) ? GTK_MENU (menu_shell) : NULL;
- if (gtk_widget_is_sensitive (priv->submenu) && parent)
+ if (gtk_widget_is_sensitive (priv->submenu) && menu_shell)
{
gboolean take_focus;
- take_focus = gtk_menu_shell_get_take_focus (GTK_MENU_SHELL (parent));
+ take_focus = gtk_menu_shell_get_take_focus (menu_shell);
gtk_menu_shell_set_take_focus (GTK_MENU_SHELL (priv->submenu), take_focus);
if (remember_exact_time)
@@ -1434,7 +1435,7 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
horizontal_offset = 0;
vertical_offset = 0;
- context = gtk_widget_get_style_context (parent);
+ context = gtk_widget_get_style_context (GTK_WIDGET (menu_shell));
gtk_style_context_get_padding (context, &parent_padding);
context = gtk_widget_get_style_context (priv->submenu);
gtk_style_context_get_padding (context, &menu_padding);
@@ -1501,11 +1502,11 @@ gtk_menu_item_popup_timeout (gpointer data)
PopupInfo *info = data;
GtkMenuItem *menu_item = info->menu_item;
GtkMenuItemPrivate *priv = menu_item->priv;
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
- parent = gtk_widget_get_parent (GTK_WIDGET (menu_item));
+ menu_shell = gtk_menu_item_get_menu_shell (menu_item);
- if (GTK_IS_MENU_SHELL (parent) && GTK_MENU_SHELL (parent)->priv->active)
+ if (menu_shell && menu_shell->priv->active)
gtk_menu_item_real_popup_submenu (GTK_WIDGET (menu_item), info->trigger_event, TRUE);
priv->timer = 0;
@@ -1519,11 +1520,11 @@ gtk_menu_item_popup_timeout (gpointer data)
static gint
get_popup_delay (GtkWidget *widget)
{
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
- parent = gtk_widget_get_parent (widget);
- if (GTK_IS_MENU_SHELL (parent))
- return _gtk_menu_shell_get_popup_delay (GTK_MENU_SHELL (parent));
+ menu_shell = gtk_menu_item_get_menu_shell (GTK_MENU_ITEM (widget));
+ if (menu_shell)
+ return _gtk_menu_shell_get_popup_delay (menu_shell);
else
return MENU_POPUP_DELAY;
}
@@ -1590,13 +1591,13 @@ static gboolean
gtk_menu_item_can_activate_accel (GtkWidget *widget,
guint signal_id)
{
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
- parent = gtk_widget_get_parent (widget);
+ menu_shell = gtk_menu_item_get_menu_shell (GTK_MENU_ITEM (widget));
/* Chain to the parent GtkMenu for further checks */
return (gtk_widget_is_sensitive (widget) && gtk_widget_get_visible (widget) &&
- parent && gtk_widget_can_activate_accel (parent, signal_id));
+ menu_shell && gtk_widget_can_activate_accel (GTK_WIDGET (menu_shell), signal_id));
}
static void
@@ -1627,10 +1628,10 @@ gtk_menu_item_parent_cb (GObject *object,
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
GtkMenu *menu;
- GtkWidget *parent;
+ GtkMenuShell *menu_shell;
- parent = gtk_widget_get_parent (GTK_WIDGET (object));
- menu = GTK_IS_MENU (parent) ? GTK_MENU (parent) : NULL;
+ menu_shell = gtk_menu_item_get_menu_shell (menu_item);
+ menu = GTK_IS_MENU (menu_shell) ? GTK_MENU (menu_shell) : NULL;
if (menu)
_gtk_menu_item_refresh_accel_path (menu_item,
@@ -1731,8 +1732,8 @@ gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,
const gchar *accel_path)
{
GtkMenuItemPrivate *priv = menu_item->priv;
- GtkWidget *parent;
GtkWidget *widget;
+ GtkMenuShell *menu_shell;
g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
g_return_if_fail (accel_path == NULL ||
@@ -1747,10 +1748,10 @@ gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,
gtk_widget_set_accel_path (widget, NULL, NULL);
/* install accelerators associated with new path */
- parent = gtk_widget_get_parent (widget);
- if (GTK_IS_MENU (parent))
+ menu_shell = gtk_menu_item_get_menu_shell (menu_item);
+ if (GTK_IS_MENU (menu_shell))
{
- GtkMenu *menu = GTK_MENU (parent);
+ GtkMenu *menu = GTK_MENU (menu_shell);
if (menu->priv->accel_group)
_gtk_menu_item_refresh_accel_path (GTK_MENU_ITEM (widget),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]