aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2014-03-12 18:18:58 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2014-03-12 18:18:58 +0100
commitb500b83b4b0d5ac3e69e6d908ad43aa243996e45 (patch)
tree2806c7b23ce06332c8e4eebca1860cfbf34ab563 /src
parenta52c1a6c80feeba8d8b4d9c4082cfc98578e2de9 (diff)
downloadayatana-ido-b500b83b4b0d5ac3e69e6d908ad43aa243996e45.tar.gz
ayatana-ido-b500b83b4b0d5ac3e69e6d908ad43aa243996e45.tar.bz2
ayatana-ido-b500b83b4b0d5ac3e69e6d908ad43aa243996e45.zip
idoscalemenuitem: use the scale's actual size allocation for events
Instead of calculating it ourselves in size_allocate, which used deprecated style functions to find out about paddings and got it wrong in some cases. Also, clicking anywhere to the left or right of the scale now activates the min and max buttons, respectively.
Diffstat (limited to 'src')
-rw-r--r--src/idoscalemenuitem.c128
1 files changed, 33 insertions, 95 deletions
diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c
index 51e41b3..8fec7df 100644
--- a/src/idoscalemenuitem.c
+++ b/src/idoscalemenuitem.c
@@ -72,9 +72,6 @@ struct _IdoScaleMenuItemPrivate {
GtkWidget *primary_label;
GtkWidget *secondary_label;
GtkWidget *hbox;
- GtkAllocation child_allocation;
- gdouble left_padding;
- gdouble right_padding;
gboolean reverse_scroll;
gboolean grabbed;
IdoScaleMenuItemStyle style;
@@ -138,72 +135,6 @@ ido_scale_menu_item_scroll_event (GtkWidget *menuitem,
}
static void
-ido_scale_menu_item_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- IdoScaleMenuItemPrivate *priv = GET_PRIVATE (widget);
- GtkRequisition primary_req;
- GtkRequisition secondary_req;
- gint horizontal_padding;
- gint primary_padding, secondary_padding;
-
- GTK_WIDGET_CLASS (ido_scale_menu_item_parent_class)->size_allocate (widget, allocation);
-
- switch (priv->style)
- {
- case IDO_SCALE_MENU_ITEM_STYLE_IMAGE:
- gtk_widget_get_preferred_size (priv->primary_image, &primary_req, NULL);
- gtk_widget_get_preferred_size (priv->secondary_image, &secondary_req, NULL);
- primary_padding = gtk_widget_get_visible (priv->primary_image) ? primary_req.width : 0;
- secondary_padding = gtk_widget_get_visible (priv->secondary_image) ? secondary_req.width : 0;
- break;
-
- case IDO_SCALE_MENU_ITEM_STYLE_LABEL:
- gtk_widget_get_preferred_size (priv->primary_label, &primary_req, NULL);
- gtk_widget_get_preferred_size (priv->secondary_label, &secondary_req, NULL);
- primary_padding = gtk_widget_get_visible (priv->primary_label) ? primary_req.width : 0;
- secondary_padding = gtk_widget_get_visible (priv->secondary_label) ? secondary_req.width : 0;
- break;
-
- default:
- primary_req.width = primary_req.height = 0;
- secondary_req.width = secondary_req.height = 0;
- primary_padding = 0;
- secondary_padding = 0;
- break;
- }
-
- gtk_widget_style_get (widget,
- "horizontal-padding", &horizontal_padding,
- NULL);
-
- priv->left_padding = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ? primary_padding : secondary_padding;
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
- {
- priv->left_padding = primary_padding;
- priv->right_padding = secondary_padding;
- }
- else
- {
- priv->left_padding = secondary_padding;
- priv->right_padding = primary_padding;
- }
-
- priv->child_allocation.x = gtk_container_get_border_width (GTK_CONTAINER (widget)) + gtk_widget_get_style (widget)->xthickness;
- priv->child_allocation.y = gtk_container_get_border_width (GTK_CONTAINER (widget)) + gtk_widget_get_style (widget)->ythickness;
-
- priv->child_allocation.x += horizontal_padding;
- priv->child_allocation.x += priv->toggle_size;
-
- priv->child_allocation.width = MAX (1, (gint)allocation->width - priv->child_allocation.x * 2);
- priv->child_allocation.width -= (primary_padding + secondary_padding);
- priv->child_allocation.height = MAX (1, (gint)allocation->height - priv->child_allocation.y * 2);
-
- gtk_widget_set_size_request (priv->scale, priv->child_allocation.width, -1);
-}
-
-static void
ido_scale_menu_item_toggle_size_allocate (IdoScaleMenuItem *item,
gint toggle_size,
gpointer user_data)
@@ -292,7 +223,6 @@ ido_scale_menu_item_class_init (IdoScaleMenuItemClass *item_class)
widget_class->button_release_event = ido_scale_menu_item_button_release_event;
widget_class->motion_notify_event = ido_scale_menu_item_motion_notify_event;
widget_class->scroll_event = ido_scale_menu_item_scroll_event;
- widget_class->size_allocate = ido_scale_menu_item_size_allocate;
widget_class->parent_set = ido_scale_menu_item_parent_set;
gobject_class->constructed = ido_scale_menu_item_constructed;
@@ -523,13 +453,17 @@ ido_scale_menu_item_get_property (GObject *object,
}
static void
-translate_event_coordinates (GtkWidget *widget,
- gdouble in_x,
- gdouble *out_x)
+ido_scale_menu_item_get_scale_allocation (IdoScaleMenuItem *menuitem,
+ GtkAllocation *allocation)
{
- IdoScaleMenuItemPrivate *priv = GET_PRIVATE (widget);
+ IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);
+ GtkAllocation parent_allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (menuitem), &parent_allocation);
+ gtk_widget_get_allocation (priv->scale, allocation);
- *out_x = in_x - priv->child_allocation.x - priv->left_padding;
+ allocation->x -= parent_allocation.x;
+ allocation->y -= parent_allocation.y;
}
static gboolean
@@ -586,15 +520,17 @@ ido_scale_menu_item_button_press_event (GtkWidget *menuitem,
GdkEventButton *event)
{
IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);
- gdouble x;
-
+ GtkAllocation alloc;
+
+ ido_scale_menu_item_get_scale_allocation (IDO_SCALE_MENU_ITEM (menuitem), &alloc);
+
// can we block emissions of "grab-notify" on parent??
- translate_event_coordinates (menuitem, event->x, &x);
- event->x = x;
+ event->x -= alloc.x;
+ event->y -= alloc.y;
- translate_event_coordinates (menuitem, event->x_root, &x);
- event->x_root = x;
+ event->x_root -= alloc.x;
+ event->y_root -= alloc.y;
gtk_widget_event (priv->scale,
((GdkEvent *)(void*)(event)));
@@ -615,11 +551,12 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem,
IdoScaleMenuItem *item = IDO_SCALE_MENU_ITEM (menuitem);
IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);
GtkWidget *scale = priv->scale;
- gdouble x;
+ GtkAllocation alloc;
+
+ ido_scale_menu_item_get_scale_allocation (IDO_SCALE_MENU_ITEM (menuitem), &alloc);
/* if user clicked to the left of the scale... */
- if (event->x > priv->child_allocation.x &&
- event->x < priv->child_allocation.x + priv->left_padding)
+ if (event->x < alloc.x)
{
if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)
{
@@ -632,8 +569,7 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem,
}
/* if user clicked to the right of the scale... */
- else if (event->x < priv->child_allocation.x + priv->child_allocation.width + priv->right_padding + priv->left_padding &&
- event->x > priv->child_allocation.x + priv->child_allocation.width + priv->left_padding)
+ else if (event->x > alloc.x + alloc.width)
{
if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)
{
@@ -648,11 +584,11 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem,
/* user clicked on the scale... */
else
{
- translate_event_coordinates (menuitem, event->x, &x);
- event->x = x;
+ event->x -= alloc.x;
+ event->y -= alloc.y;
- translate_event_coordinates (menuitem, event->x_root, &x);
- event->x_root= x;
+ event->x_root -= alloc.x;
+ event->y_root -= alloc.y;
gtk_widget_event (scale, (GdkEvent*)event);
}
@@ -672,13 +608,15 @@ ido_scale_menu_item_motion_notify_event (GtkWidget *menuitem,
{
IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);
GtkWidget *scale = priv->scale;
- gdouble x;
+ GtkAllocation alloc;
+
+ ido_scale_menu_item_get_scale_allocation (IDO_SCALE_MENU_ITEM (menuitem), &alloc);
- translate_event_coordinates (menuitem, event->x, &x);
- event->x = x;
+ event->x -= alloc.x;
+ event->y -= alloc.y;
- translate_event_coordinates (menuitem, event->x_root, &x);
- event->x_root= x;
+ event->x_root -= alloc.x;
+ event->y_root -= alloc.y;
gtk_widget_event (scale,
((GdkEvent *)(void*)(event)));