From a52de434be2c70c717721aadd233f2926a02aa3b Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 23 Sep 2003 18:11:09 +0000 Subject: [PATCH] added the title pango layout to the GimpDockable struct. Made 2003-09-23 Sven Neumann * app/widgets/gimpdockable.[ch]: added the title pango layout to the GimpDockable struct. Made gimp_dockable_menu_position() handle RTL layout correctly. * app/display/gimpdisplayshell-callbacks.c (gimp_display_shell_origin_menu_position): handle RTL layout. --- ChangeLog | 9 +++ app/display/gimpdisplayshell-callbacks.c | 37 +++++++---- app/widgets/gimpdockable.c | 78 +++++++++++++++++------- app/widgets/gimpdockable.h | 1 + 4 files changed, 93 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1cc6c4f163..8cfd377131 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-09-23 Sven Neumann + + * app/widgets/gimpdockable.[ch]: added the title pango layout to + the GimpDockable struct. Made gimp_dockable_menu_position() handle + RTL layout correctly. + + * app/display/gimpdisplayshell-callbacks.c + (gimp_display_shell_origin_menu_position): handle RTL layout. + 2003-09-23 Sven Neumann * libgimpwidgets/gimpchainbutton.c (gimp_chain_button_draw_lines): diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c index 2e9d936648..6a7b7c31da 100644 --- a/app/display/gimpdisplayshell-callbacks.c +++ b/app/display/gimpdisplayshell-callbacks.c @@ -1641,25 +1641,40 @@ gimp_display_shell_origin_menu_position (GtkMenu *menu, gint *y, gpointer data) { - GtkWidget *origin; - GdkScreen *screen; - gint origin_x; - gint origin_y; + GtkRequisition menu_requisition; + GtkWidget *widget; + GtkWidget *origin; + GdkScreen *screen; + gint origin_x; + gint origin_y; - origin = (GtkWidget *) data; + widget = GTK_WIDGET (menu); + origin = GTK_WIDGET (data); gdk_window_get_origin (origin->window, &origin_x, &origin_y); - *x = origin_x + origin->allocation.x + origin->allocation.width - 1; + gtk_widget_size_request (widget, &menu_requisition); + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) + *x = origin_x + origin->allocation.x + origin->allocation.width - 1; + else + *x = origin_x + origin->allocation.x - menu_requisition.width - 1; + *y = origin_y + origin->allocation.y + (origin->allocation.height - 1) / 2; - screen = gtk_widget_get_screen (GTK_WIDGET (menu)); + screen = gtk_widget_get_screen (menu); - if (*x + GTK_WIDGET (menu)->allocation.width > gdk_screen_get_width (screen)) - *x -= (GTK_WIDGET (menu)->allocation.width + origin->allocation.width); + if (*x + menu_requisition.width > gdk_screen_get_width (screen)) + *x -= menu_requisition.width + origin->allocation.width; - if (*y + GTK_WIDGET (menu)->allocation.height > gdk_screen_get_height (screen)) - *y -= (GTK_WIDGET (menu)->allocation.height); + if (*x < 0) + *x += menu_requisition.width + origin->allocation.width; + + if (*y + widget->allocation.height > gdk_screen_get_height (screen)) + *y -= menu_requisition.height; + + if (*y < 0) + *y = 0; } /* gimp_display_shell_compress_motion: diff --git a/app/widgets/gimpdockable.c b/app/widgets/gimpdockable.c index 2fad8ebd99..18cee9a3c2 100644 --- a/app/widgets/gimpdockable.c +++ b/app/widgets/gimpdockable.c @@ -153,6 +153,8 @@ gimp_dockable_init (GimpDockable *dockable) dockable->get_preview_data = NULL; dockable->set_context_func = NULL; + dockable->title_layout = NULL; + gtk_widget_push_composite_child (); dockable->menu_button = gtk_button_new (); gtk_widget_pop_composite_child (); @@ -220,6 +222,12 @@ gimp_dockable_destroy (GtkObject *object) dockable->help_id = NULL; } + if (dockable->title_layout) + { + g_object_unref (dockable->title_layout); + dockable->title_layout = NULL; + } + if (dockable->menu_button) { gtk_widget_unparent (dockable->menu_button); @@ -290,12 +298,15 @@ gimp_dockable_size_allocate (GtkWidget *widget, { gtk_widget_size_request (dockable->close_button, &button_requisition); - child_allocation.x = (allocation->x + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) + child_allocation.x = (allocation->x + allocation->width - container->border_width - button_requisition.width); - child_allocation.y = (allocation->y + - container->border_width); + else + child_allocation.x = allocation->x + container->border_width; + + child_allocation.y = allocation->y + container->border_width; child_allocation.width = button_requisition.width; child_allocation.height = button_requisition.height; @@ -304,10 +315,15 @@ gimp_dockable_size_allocate (GtkWidget *widget, if (dockable->menu_button) { - child_allocation.x = (allocation->x + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) + child_allocation.x = (allocation->x + allocation->width - container->border_width - 2 * button_requisition.width); + else + child_allocation.x = (allocation->x + container->border_width + + button_requisition.width); + child_allocation.y = allocation->y + container->border_width; child_allocation.width = button_requisition.width; child_allocation.height = button_requisition.height; @@ -337,7 +353,8 @@ static void gimp_dockable_style_set (GtkWidget *widget, GtkStyle *prev_style) { - gint content_border; + GimpDockable *dockable; + gint content_border; gtk_widget_style_get (widget, "content_border", &content_border, @@ -345,6 +362,14 @@ gimp_dockable_style_set (GtkWidget *widget, gtk_container_set_border_width (GTK_CONTAINER (widget), content_border); + dockable = GIMP_DOCKABLE (widget); + + if (dockable->title_layout) + { + g_object_unref (dockable->title_layout); + dockable->title_layout = NULL; + } + if (GTK_WIDGET_CLASS (parent_class)->style_set) GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style); } @@ -365,21 +390,30 @@ gimp_dockable_expose_event (GtkWidget *widget, title_area.x = widget->allocation.x + container->border_width; title_area.y = widget->allocation.y + container->border_width; + title_area.width = (widget->allocation.width - 2 * container->border_width - 2 * dockable->close_button->allocation.width); title_area.height = dockable->close_button->allocation.height; + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + title_area.x += 2 * dockable->close_button->allocation.width; + if (gdk_rectangle_intersect (&title_area, &event->area, &expose_area)) { - PangoLayout *layout; - gint layout_width; - gint layout_height; - gint text_x; - gint text_y; + gint layout_width; + gint layout_height; + gint text_x; + gint text_y; - layout = gtk_widget_create_pango_layout (widget, dockable->blurb); - pango_layout_get_pixel_size (layout, &layout_width, &layout_height); + if (!dockable->title_layout) + { + dockable->title_layout = + gtk_widget_create_pango_layout (widget, dockable->blurb); + } + + pango_layout_get_pixel_size (dockable->title_layout, + &layout_width, &layout_height); if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) { @@ -395,9 +429,7 @@ gimp_dockable_expose_event (GtkWidget *widget, gtk_paint_layout (widget->style, widget->window, widget->state, TRUE, &expose_area, widget, NULL, - text_x, text_y, layout); - - g_object_unref (layout); + text_x, text_y, dockable->title_layout); } } @@ -658,20 +690,24 @@ gimp_dockable_menu_position (GtkMenu *menu, gtk_widget_size_request (GIMP_DOCKABLE (dockable)->close_button, &button_requisition); - *x += (dockable->allocation.x + dockable->allocation.width - - container->border_width - - 2 * button_requisition.width - - menu_requisition.width); + if (gtk_widget_get_direction (GTK_WIDGET (menu)) == GTK_TEXT_DIR_LTR) + *x += (dockable->allocation.x + dockable->allocation.width - + container->border_width - 2 * button_requisition.width - + menu_requisition.width); + else + *x += (dockable->allocation.x + container->border_width + + 2 * button_requisition.width); + *y += (dockable->allocation.y + container->border_width + button_requisition.height / 2); screen = gtk_widget_get_screen (GTK_WIDGET (menu)); if (*x + menu_requisition.width > gdk_screen_get_width (screen)) - *x -= menu_requisition.width; + *x -= menu_requisition.width + button_requisition.width; if (*x < 0) - *x = 0; + *x += menu_requisition.width + button_requisition.width; if (*y + menu_requisition.height > gdk_screen_get_height (screen)) *y -= menu_requisition.height; diff --git a/app/widgets/gimpdockable.h b/app/widgets/gimpdockable.h index 1bb55167c0..c0a076e7ce 100644 --- a/app/widgets/gimpdockable.h +++ b/app/widgets/gimpdockable.h @@ -60,6 +60,7 @@ struct _GimpDockable GimpContext *context; + PangoLayout *title_layout; GtkWidget *menu_button; GtkWidget *close_button;