*/
#include "config.h"
+
#include <string.h>
#include "gtkaccellabel.h"
#include "gtkbuildable.h"
#include "gtkactivatable.h"
#include "gtkintl.h"
+#include "gtktypebuiltins.h"
enum {
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
gtk_menu_item_activatable_interface_init))
-#define GET_PRIVATE(object) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((object), GTK_TYPE_MENU_ITEM, GtkMenuItemPrivate))
static void
gtk_menu_item_class_init (GtkMenuItemClass *klass)
priv->action = NULL;
priv->use_action_appearance = TRUE;
- menu_item->submenu = NULL;
- menu_item->toggle_size = 0;
- menu_item->accelerator_width = 0;
+ menu_item->priv->submenu = NULL;
+ menu_item->priv->toggle_size = 0;
+ menu_item->priv->accelerator_width = 0;
if (gtk_widget_get_direction (GTK_WIDGET (menu_item)) == GTK_TEXT_DIR_RTL)
priv->submenu_direction = GTK_DIRECTION_LEFT;
else
GtkWidget *child,
gint *size)
{
+ GtkStyleContext *style_context;
+ GtkStateFlags state;
PangoContext *context;
PangoFontMetrics *metrics;
gfloat arrow_scaling;
NULL);
context = gtk_widget_get_pango_context (child);
+ style_context = gtk_widget_get_style_context (child);
+ state = gtk_widget_get_state_flags (child);
+
metrics = pango_context_get_metrics (context,
- gtk_widget_get_style (child)->font_desc,
+ gtk_style_context_get_font (style_context, state),
pango_context_get_language (context));
*size = (PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
static gint
get_minimum_width (GtkWidget *widget)
{
+ GtkStyleContext *style_context;
+ GtkStateFlags state;
PangoContext *context;
PangoFontMetrics *metrics;
gint width;
gint width_chars;
context = gtk_widget_get_pango_context (widget);
+ style_context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
metrics = pango_context_get_metrics (context,
- gtk_widget_get_style (widget)->font_desc,
+ gtk_style_context_get_font (style_context, state),
pango_context_get_language (context));
width = pango_font_metrics_get_approximate_char_width (metrics);
GtkPackDirection pack_dir;
GtkPackDirection child_pack_dir;
gint min_width, nat_width;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding, border;
min_width = nat_width = 0;
}
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- min_width = (border_width + gtk_widget_get_style (widget)->xthickness) * 2;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, state, &padding);
+ gtk_style_context_get_border (context, state, &border);
+
+ min_width = (border_width * 2) + padding.left + padding.right +
+ border.left + border.right;
if ((pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) &&
(child_pack_dir == GTK_PACK_DIRECTION_LTR || child_pack_dir == GTK_PACK_DIRECTION_RTL))
min_width += 2 * horizontal_padding;
nat_width = min_width;
-
+
child = gtk_bin_get_child (bin);
if (child != NULL && gtk_widget_get_visible (child))
{
- GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
+ GtkMenuItemPrivate *priv = menu_item->priv;
gint child_min, child_nat;
gtk_widget_get_preferred_width (child, &child_min, &child_nat);
- if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator);
+ if ((menu_item->priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
guint arrow_spacing;
gint arrow_size;
GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
GtkMenuItemPrivate *priv = menu_item->priv;
GtkBin *bin;
- GtkStyle *style;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding, border;
GtkWidget *child;
GtkWidget *parent;
guint accel_width;
min_height = nat_height = 0;
- style = gtk_widget_get_style (widget);
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, state, &padding);
+ gtk_style_context_get_border (context, state, &border);
gtk_widget_style_get (widget,
"horizontal-padding", &horizontal_padding,
}
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- min_height = (border_width + style->ythickness) * 2;
+ min_height = (border_width * 2) + padding.top + padding.bottom + border.top + border.bottom;
if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
(child_pack_dir == GTK_PACK_DIRECTION_TTB || child_pack_dir == GTK_PACK_DIRECTION_BTT))
if (child != NULL && gtk_widget_get_visible (child))
{
- GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
+ GtkMenuItemPrivate *priv = menu_item->priv;
gint child_min, child_nat;
gtk_widget_get_preferred_height (child, &child_min, &child_nat);
min_height += child_min;
nat_height += child_nat;
- if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
+ if ((menu_item->priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
gint arrow_size;
NULL);
if (wide_separators)
- min_height += separator_height + style->ythickness;
+ min_height += separator_height + padding.top + border.top;
else
- min_height += style->ythickness * 2;
+ min_height += padding.top + padding.bottom + border.top + border.bottom;
nat_height = min_height;
}
GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
GtkMenuItemPrivate *priv = menu_item->priv;
GtkBin *bin;
- GtkStyle *style;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding, border;
GtkWidget *child;
GtkWidget *parent;
guint horizontal_padding;
min_height = nat_height = 0;
- style = gtk_widget_get_style (widget);
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, state, &padding);
+ gtk_style_context_get_border (context, state, &border);
gtk_widget_style_get (widget,
"horizontal-padding", &horizontal_padding,
}
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- min_height = (border_width + style->ythickness) * 2;
+ min_height = (border_width * 2) + padding.top + padding.bottom + border.top + border.bottom;
avail_size = for_size;
- avail_size -= (border_width + style->xthickness) * 2;
+ avail_size -= (border_width * 2) + padding.left + padding.right + border.left + border.right;
if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
(child_pack_dir == GTK_PACK_DIRECTION_TTB || child_pack_dir == GTK_PACK_DIRECTION_BTT))
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)) || priv->reserve_indicator)
+ if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
guint arrow_spacing;
min_height += child_min;
nat_height += child_nat;
- if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
+ if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
min_height = MAX (min_height, arrow_size);
nat_height = MAX (nat_height, arrow_size);
NULL);
if (wide_separators)
- min_height += separator_height + style->ythickness;
+ min_height += separator_height + padding.top + border.top;
else
- min_height += style->ythickness * 2;
+ min_height += padding.top + padding.bottom + border.top + border.bottom;
nat_height = min_height;
}
child = gtk_bin_get_child (bin);
if (child)
{
- GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
- GtkRequisition child_requisition;
- GtkStyle *style;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding, border;
guint horizontal_padding;
guint border_width;
- style = gtk_widget_get_style (widget);
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, state, &padding);
+ gtk_style_context_get_border (context, state, &border);
+
gtk_widget_style_get (widget,
"horizontal-padding", &horizontal_padding,
NULL);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- child_allocation.x = border_width + style->xthickness;
- child_allocation.y = border_width + style->ythickness;
+ child_allocation.x = border_width + padding.left + border.left;
+ child_allocation.y = border_width + padding.top + border.top;
+
+ child_allocation.width = allocation->width - (border_width * 2) -
+ padding.left - padding.right - border.left - border.right;
+ child_allocation.height = allocation->height - (border_width * 2) -
+ padding.top - padding.bottom - border.top - border.bottom;
if ((pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) &&
(child_pack_dir == GTK_PACK_DIRECTION_LTR || child_pack_dir == GTK_PACK_DIRECTION_RTL))
- child_allocation.x += horizontal_padding;
+ {
+ child_allocation.x += horizontal_padding;
+ child_allocation.width -= 2 * horizontal_padding;
+ }
else if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
(child_pack_dir == GTK_PACK_DIRECTION_TTB || child_pack_dir == GTK_PACK_DIRECTION_BTT))
- child_allocation.y += horizontal_padding;
-
- child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
- child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
+ {
+ child_allocation.y += horizontal_padding;
+ child_allocation.height -= 2 * horizontal_padding;
+ }
if (child_pack_dir == GTK_PACK_DIRECTION_LTR ||
child_pack_dir == GTK_PACK_DIRECTION_RTL)
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
- if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
+ if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
{
+ guint arrow_spacing;
+ gint arrow_size;
+
+ gtk_widget_style_get (widget,
+ "arrow-spacing", &arrow_spacing,
+ NULL);
+
+ get_arrow_size (widget, child, &arrow_size);
+
if (direction == GTK_TEXT_DIR_RTL)
- child_allocation.x += child_requisition.height;
- child_allocation.width -= child_requisition.height;
+ child_allocation.x += arrow_size + arrow_spacing;
+ child_allocation.width -= arrow_size + arrow_spacing;
}
if (child_allocation.width < 1)
priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gdk_window_set_user_data (priv->event_window, widget);
-
- gtk_widget_style_attach (widget);
}
static void
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
GtkMenuItemPrivate *priv = menu_item->priv;
- GtkStateType state_type;
- GtkShadowType shadow_type, selected_shadow_type;
- GtkStyle *style;
+ GtkStateFlags state;
+ GtkStyleContext *context;
+ GtkBorder padding;
GtkWidget *child, *parent;
- GdkWindow *window;
gint x, y, w, h, width, height;
guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- state_type = gtk_widget_get_state (widget);
- style = gtk_widget_get_style (widget);
- window = gtk_widget_get_window (widget);
+ state = gtk_widget_get_state_flags (widget);
+ context = gtk_widget_get_style_context (widget);
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
child = gtk_bin_get_child (GTK_BIN (menu_item));
parent = gtk_widget_get_parent (widget);
-
- if (child && state_type == GTK_STATE_PRELIGHT)
+
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
+
+ gtk_style_context_get_padding (context, state, &padding);
+
+ if (child && (state & GTK_STATE_FLAG_PRELIGHT))
{
- gtk_widget_style_get (widget,
- "selected-shadow-type", &selected_shadow_type,
- NULL);
- gtk_paint_box (style,
- cr,
- GTK_STATE_PRELIGHT,
- selected_shadow_type,
- widget, "menuitem",
- x, y, w, h);
+ gtk_render_background (context, cr, x, y, w, h);
+ gtk_render_frame (context, cr, x, y, w, h);
}
- if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
+ if (priv->submenu && !GTK_IS_MENU_BAR (parent))
{
gint arrow_x, arrow_y;
gint arrow_size;
guint horizontal_padding;
GtkTextDirection direction;
- GtkArrowType arrow_type;
+ gdouble angle;
direction = gtk_widget_get_direction (widget);
get_arrow_size (widget, child, &arrow_size);
- shadow_type = GTK_SHADOW_OUT;
- if (state_type == GTK_STATE_PRELIGHT)
- shadow_type = GTK_SHADOW_IN;
-
if (direction == GTK_TEXT_DIR_LTR)
{
arrow_x = x + w - horizontal_padding - arrow_size;
- arrow_type = GTK_ARROW_RIGHT;
+ angle = G_PI / 2;
}
else
{
arrow_x = x + horizontal_padding;
- arrow_type = GTK_ARROW_LEFT;
+ angle = (3 * G_PI) / 2;
}
arrow_y = y + (h - arrow_size) / 2;
- gtk_paint_arrow (style, cr,
- state_type, shadow_type,
- widget, "menuitem",
- arrow_type, TRUE,
- arrow_x, arrow_y,
- arrow_size, arrow_size);
+ gtk_render_arrow (context, cr, angle, arrow_x, arrow_y, arrow_size);
}
else if (!child)
{
"separator-height", &separator_height,
"horizontal-padding", &horizontal_padding,
NULL);
-
if (wide_separators)
- gtk_paint_box (style, cr,
- GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_OUT,
- widget, "hseparator",
- horizontal_padding + style->xthickness,
- (height - separator_height - style->ythickness) / 2,
- width - 2 * (horizontal_padding + style->xthickness),
- separator_height);
+ gtk_render_frame (context, cr,
+ horizontal_padding + padding.left,
+ (height - separator_height - padding.top) / 2,
+ width - (2 * horizontal_padding) - padding.left - padding.right,
+ separator_height);
else
- gtk_paint_hline (style, cr,
- GTK_STATE_NORMAL, widget, "menuitem",
- horizontal_padding + style->xthickness,
- width - horizontal_padding - style->xthickness - 1,
- (height - style->ythickness) / 2);
+ gtk_render_line (context, cr,
+ horizontal_padding + padding.left,
+ (height - padding.top) / 2,
+ width - horizontal_padding - padding.right - 1,
+ (height - padding.top) / 2);
}
GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->draw (widget, cr);
+ gtk_style_context_restore (context);
+
return FALSE;
}
{
gint vertical_padding;
gint horizontal_padding;
-
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding;
+
gtk_widget_style_get (GTK_WIDGET (menu),
"horizontal-offset", horizontal_offset,
"vertical-offset", vertical_offset,
"vertical-padding", &vertical_padding,
NULL);
- *vertical_offset -= gtk_widget_get_style (GTK_WIDGET (menu))->ythickness;
+ context = gtk_widget_get_style_context (GTK_WIDGET (menu));
+ state = gtk_widget_get_state_flags (GTK_WIDGET (menu));
+ gtk_style_context_get_padding (context, state, &padding);
+
+ *vertical_offset -= padding.top;
*vertical_offset -= vertical_padding;
*horizontal_offset += horizontal_padding;
}
gint monitor_num;
gint horizontal_offset;
gint vertical_offset;
- gint parent_xthickness;
gint available_left, available_right;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder parent_padding;
g_return_if_fail (menu != NULL);
g_return_if_fail (x != NULL);
else
parent_menu_item = NULL;
- parent_xthickness = gtk_widget_get_style (parent)->xthickness;
+ context = gtk_widget_get_style_context (parent);
+ state = gtk_widget_get_state_flags (parent);
+ gtk_style_context_get_padding (context, state, &parent_padding);
if (parent_menu_item && !GTK_MENU (parent)->priv->torn_off)
{
switch (priv->submenu_direction)
{
case GTK_DIRECTION_LEFT:
- if (tx - twidth - parent_xthickness - horizontal_offset >= monitor.x ||
+ if (tx - twidth - parent_padding.left - horizontal_offset >= monitor.x ||
available_left >= available_right)
- tx -= twidth + parent_xthickness + horizontal_offset;
+ tx -= twidth + parent_padding.left + horizontal_offset;
else
{
priv->submenu_direction = GTK_DIRECTION_RIGHT;
- tx += allocation.width + parent_xthickness + horizontal_offset;
+ tx += allocation.width + parent_padding.right + horizontal_offset;
}
break;
case GTK_DIRECTION_RIGHT:
- if (tx + allocation.width + parent_xthickness + horizontal_offset + twidth <= monitor.x + monitor.width ||
+ if (tx + allocation.width + parent_padding.right + horizontal_offset + twidth <= monitor.x + monitor.width ||
available_right >= available_left)
- tx += allocation.width + parent_xthickness + horizontal_offset;
+ tx += allocation.width + parent_padding.right + horizontal_offset;
else
{
priv->submenu_direction = GTK_DIRECTION_LEFT;
- tx -= twidth + parent_xthickness + horizontal_offset;
+ tx -= twidth + parent_padding.left + horizontal_offset;
}
break;
}
g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
- priv = GET_PRIVATE (menu_item);
+ priv = menu_item->priv;
if (priv->reserve_indicator != reserve)
{
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;
+ return menu_item->priv->reserve_indicator;
}