diff options
author | Cody Russell <crussell@canonical.com> | 2010-02-05 10:02:08 -0800 |
---|---|---|
committer | Cody Russell <crussell@canonical.com> | 2010-02-05 10:02:08 -0800 |
commit | e892ebeac57c5481a834ba16f902609f226a9ca4 (patch) | |
tree | 09567d269f3cecc22cd88751489429473bafa44a | |
parent | 1595f645706a345a19beee6566427a8106e286f6 (diff) | |
parent | 50ae8efb58be0ed7febbd70f92e5ce1e8f08a1bd (diff) | |
download | ayatana-ido-e892ebeac57c5481a834ba16f902609f226a9ca4.tar.gz ayatana-ido-e892ebeac57c5481a834ba16f902609f226a9ca4.tar.bz2 ayatana-ido-e892ebeac57c5481a834ba16f902609f226a9ca4.zip |
merge scale-spacing-fixes branch
-rw-r--r-- | example/menus.c | 4 | ||||
-rw-r--r-- | src/idoscalemenuitem.c | 57 |
2 files changed, 52 insertions, 9 deletions
diff --git a/example/menus.c b/example/menus.c index 6cf0c75..9877d5e 100644 --- a/example/menus.c +++ b/example/menus.c @@ -38,8 +38,8 @@ main (int argc, char *argv[]) menuitem = gtk_menu_item_new_with_label ("Open"); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - //menuitem = ido_scale_menu_item_new_with_range ("Volume", 0, 100, 1); - //gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + menuitem = ido_scale_menu_item_new_with_range ("Volume", 0, 100, 1); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); menuitem = ido_entry_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 7bc75d9..0767364 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -54,6 +54,7 @@ struct _IdoScaleMenuItemPrivate { GtkWidget *scale; GtkAdjustment *adjustment; GtkWidget *offscreen; + GtkAllocation child_allocation; }; enum { @@ -84,6 +85,35 @@ 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 child_requisition; + gint horizontal_padding; + + GTK_WIDGET_CLASS (ido_scale_menu_item_parent_class)->size_allocate (widget, allocation); + + gtk_widget_get_child_requisition (priv->scale, &child_requisition); + + gtk_widget_style_get (widget, + "horizontal-padding", &horizontal_padding, + NULL); + + priv->child_allocation.x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness; + priv->child_allocation.y = GTK_CONTAINER (widget)->border_width + widget->style->ythickness; + + priv->child_allocation.x += horizontal_padding; + + priv->child_allocation.x += GTK_MENU_ITEM (widget)->toggle_size; + + priv->child_allocation.width = MAX (1, (gint)allocation->width - priv->child_allocation.x * 2); + 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_class_init (IdoScaleMenuItemClass *item_class) { GObjectClass *gobject_class = G_OBJECT_CLASS (item_class); @@ -99,6 +129,7 @@ ido_scale_menu_item_class_init (IdoScaleMenuItemClass *item_class) widget_class->scroll_event = ido_scale_menu_item_scroll_event; widget_class->state_changed = ido_scale_menu_item_state_changed; widget_class->expose_event = ido_scale_menu_item_expose; + widget_class->size_allocate = ido_scale_menu_item_size_allocate; gobject_class->constructor = ido_scale_menu_item_constructor; gobject_class->set_property = ido_scale_menu_item_set_property; @@ -192,7 +223,8 @@ ido_scale_menu_item_expose (GtkWidget *widget, widget->style->black_gc, pixbuf, 0, 0, - widget->allocation.x, widget->allocation.y, + widget->allocation.x + priv->child_allocation.x, + widget->allocation.y, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GDK_RGB_DITHER_NORMAL, @@ -222,7 +254,6 @@ ido_scale_menu_item_constructor (GType type, priv->scale = gtk_hscale_new_with_range (0.0, 100.0, 1.0); gtk_scale_set_draw_value (GTK_SCALE (priv->scale), FALSE); - gtk_widget_set_size_request (priv->scale, 95, 21); gtk_container_add (GTK_CONTAINER (priv->offscreen), priv->scale); gtk_widget_show (priv->scale); gtk_widget_show (priv->offscreen); @@ -256,10 +287,14 @@ ido_scale_menu_item_forall (GtkContainer *container, } static gboolean -ido_scale_menu_item_button_press_event (GtkWidget *menuitem, +ido_scale_menu_item_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { - GtkWidget *scale = GET_PRIVATE (IDO_SCALE_MENU_ITEM (menuitem))->scale; + IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); + GtkWidget *scale = priv->scale; + + event->x -= priv->child_allocation.x; + event->x_root -= priv->child_allocation.x; gtk_widget_event (scale, (GdkEvent *)event); @@ -270,10 +305,13 @@ static gboolean ido_scale_menu_item_button_release_event (GtkWidget *menuitem, GdkEventButton *event) { - GtkWidget *scale = GET_PRIVATE (IDO_SCALE_MENU_ITEM (menuitem))->scale; + IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); + GtkWidget *scale = priv->scale; GdkWindow *tmp = event->window; event->window = GTK_RANGE (scale)->event_window; + event->x -= priv->child_allocation.x; + event->x_root -= priv->child_allocation.x; gtk_widget_event (scale, (GdkEvent *) event); @@ -283,10 +321,15 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem, } static gboolean -ido_scale_menu_item_motion_notify_event (GtkWidget *menuitem, +ido_scale_menu_item_motion_notify_event (GtkWidget *menuitem, GdkEventMotion *event) { - GtkWidget *scale = GET_PRIVATE (IDO_SCALE_MENU_ITEM (menuitem))->scale; + IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); + GtkWidget *scale = priv->scale; + + event->x -= priv->child_allocation.x; + event->x_root -= priv->child_allocation.x; + gtk_widget_event (scale, (GdkEvent *) event); return TRUE; |