Commit f15a5896 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Added gtk_menu_item_set/get_reserve_indicator.

This is needed by GtkTreeMenu to ensure that child menu items
reserve space for the submenu indicator even if they dont have
submenus... in this way we ensure the same size of all cell
areas in the menu items at allocation/request time.
parent 5e8e4429
......@@ -709,11 +709,12 @@ gtk_menu_item_get_preferred_width (GtkWidget *widget,
if (child != NULL && gtk_widget_get_visible (child))
{
GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
gint child_min, child_nat;
gtk_widget_get_preferred_width (child, &child_min, &child_nat);
if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator);
{
guint arrow_spacing;
gint arrow_size;
......@@ -807,6 +808,7 @@ gtk_menu_item_get_preferred_height (GtkWidget *widget,
if (child != NULL && gtk_widget_get_visible (child))
{
GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
gint child_min, child_nat;
gtk_widget_get_preferred_height (child, &child_min, &child_nat);
......@@ -814,7 +816,7 @@ gtk_menu_item_get_preferred_height (GtkWidget *widget,
min_height += child_min;
nat_height += child_nat;
if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
gint arrow_size;
......@@ -916,10 +918,11 @@ gtk_menu_item_get_preferred_height_for_width (GtkWidget *widget,
if (child != NULL && gtk_widget_get_visible (child))
{
GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
gint child_min, child_nat;
gint arrow_size = 0;
if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
guint arrow_spacing;
......@@ -1351,6 +1354,7 @@ gtk_menu_item_size_allocate (GtkWidget *widget,
child = gtk_bin_get_child (bin);
if (child)
{
GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
GtkRequisition child_requisition;
GtkStyle *style;
guint horizontal_padding;
......@@ -1393,7 +1397,7 @@ gtk_menu_item_size_allocate (GtkWidget *widget,
child_allocation.y += allocation->y;
gtk_widget_get_preferred_size (child, &child_requisition, NULL);
if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
if (direction == GTK_TEXT_DIR_RTL)
child_allocation.x += child_requisition.height;
......@@ -2515,3 +2519,32 @@ gtk_menu_item_get_use_underline (GtkMenuItem *menu_item)
return FALSE;
}
void
gtk_menu_item_set_reserve_indicator (GtkMenuItem *menu_item,
gboolean reserve)
{
GtkMenuItemPrivate *priv;
g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
priv = GET_PRIVATE (menu_item);
if (priv->reserve_indicator != reserve)
{
priv->reserve_indicator = reserve;
gtk_widget_queue_resize (GTK_WIDGET (menu_item));
}
}
gboolean
gtk_menu_item_get_reserve_indicator (GtkMenuItem *menu_item)
{
GtkMenuItemPrivate *priv;
g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
priv = GET_PRIVATE (menu_item);
return priv->reserve_indicator;
}
......@@ -119,6 +119,19 @@ void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item,
gboolean setting);
gboolean gtk_menu_item_get_use_underline (GtkMenuItem *menu_item);
void gtk_menu_item_set_reserve_indicator(GtkMenuItem *menu_item,
gboolean reserve);
gboolean gtk_menu_item_get_reserve_indicator(GtkMenuItem *menu_item);
/* private */
void _gtk_menu_item_refresh_accel_path (GtkMenuItem *menu_item,
const gchar *prefix,
GtkAccelGroup *accel_group,
gboolean group_changed);
gboolean _gtk_menu_item_is_selectable (GtkWidget *menu_item);
void _gtk_menu_item_popup_submenu (GtkWidget *menu_item,
gboolean with_delay);
void _gtk_menu_item_popdown_submenu (GtkWidget *menu_item);
G_END_DECLS
......
......@@ -42,6 +42,7 @@ struct _GtkMenuItemPrivate
guint timer_from_keypress : 1;
guint from_menubar : 1;
guint use_action_appearance : 1;
guint reserve_indicator : 1;
guint timer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment