From 7ec82bee955b65550ce806186c7f01070170e2de Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Thu, 8 Nov 2012 08:22:02 +0200 Subject: [pathbar] don't use deprecated size_request vfunc http://git.gnome.org/browse/nautilus/commit/?id=22cb1accd98c1ae10938eac10cc6beda8fb6b145 --- src/caja-pathbar.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 186 insertions(+), 13 deletions(-) (limited to 'src/caja-pathbar.c') diff --git a/src/caja-pathbar.c b/src/caja-pathbar.c index 6a582014..cc79e497 100644 --- a/src/caja-pathbar.c +++ b/src/caja-pathbar.c @@ -103,8 +103,17 @@ G_DEFINE_TYPE (CajaPathBar, static void caja_path_bar_finalize (GObject *object); static void caja_path_bar_dispose (GObject *object); +#if GTK_CHECK_VERSION(3,0,0) +static void caja_path_bar_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural); +static void caja_path_bar_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural); +#else static void caja_path_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition); + GtkRequisition *requisition); +#endif static void caja_path_bar_unmap (GtkWidget *widget); static void caja_path_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation); @@ -375,7 +384,12 @@ caja_path_bar_class_init (CajaPathBarClass *path_bar_class) gobject_class->finalize = caja_path_bar_finalize; gobject_class->dispose = caja_path_bar_dispose; +#if GTK_CHECK_VERSION(3,0,0) + widget_class->get_preferred_height = caja_path_bar_get_preferred_height; + widget_class->get_preferred_width = caja_path_bar_get_preferred_width; +#else widget_class->size_request = caja_path_bar_size_request; +#endif widget_class->unmap = caja_path_bar_unmap; widget_class->size_allocate = caja_path_bar_size_allocate; widget_class->style_set = caja_path_bar_style_set; @@ -406,6 +420,10 @@ caja_path_bar_class_init (CajaPathBarClass *path_bar_class) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_FILE); + +#if GTK_CHECK_VERSION(3,0,0) + gtk_container_class_handle_border_width (container_class); +#endif } @@ -479,6 +497,77 @@ caja_path_bar_dispose (GObject *object) * Ideally, our size is determined by another widget, and we are just filling * available space. */ +#if GTK_CHECK_VERSION(3,0,0) +static void +caja_path_bar_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + ButtonData *button_data; + CajaPathBar *path_bar; + GList *list; + gint child_height; + gint height; + gint child_min, child_nat; + + path_bar = CAJA_PATH_BAR (widget); + + *minimum = *natural = 0; + height = 0; + + for (list = path_bar->button_list; list; list = list->next) { + button_data = BUTTON_DATA (list->data); + gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat); + gtk_widget_get_preferred_height (button_data->button, &child_height, NULL); + height = MAX (height, child_height); + + if (button_data->type == NORMAL_BUTTON) { + /* Use 2*Height as button width because of ellipsized label. */ + child_min = MAX (child_min, child_height * 2); + child_nat = MAX (child_min, child_height * 2); + } + + *minimum = MAX (*minimum, child_min); + *natural = MAX (*natural, child_nat); + } + + /* Add space for slider, if we have more than one path */ + /* Theoretically, the slider could be bigger than the other button. But we're + * not going to worry about that now. + */ + path_bar->slider_width = MIN (height * 2 / 3 + 5, height); + + if (path_bar->button_list && path_bar->button_list->next != NULL) { + *minimum += (path_bar->spacing + path_bar->slider_width) * 2; + *natural += (path_bar->spacing + path_bar->slider_width) * 2; + } +} + +static void +caja_path_bar_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + ButtonData *button_data; + CajaPathBar *path_bar; + GList *list; + gint child_min, child_nat; + + path_bar = CAJA_PATH_BAR (widget); + + *minimum = *natural = 0; + + for (list = path_bar->button_list; list; list = list->next) { + button_data = BUTTON_DATA (list->data); + gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat); + + *minimum = MAX (*minimum, child_min); + *natural = MAX (*natural, child_nat); + } +} + +#else /* GTK_CHECK_VERSION(3,0,0) */ + static void caja_path_bar_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -497,8 +586,7 @@ caja_path_bar_size_request (GtkWidget *widget, for (list = path_bar->button_list; list; list = list->next) { button_data = BUTTON_DATA (list->data); - gtk_widget_get_preferred_size (button_data->button, - &child_requisition, NULL); + gtk_widget_size_request (button_data->button, &child_requisition); requisition->width = MAX (child_requisition.width, requisition->width); requisition->height = MAX (child_requisition.height, requisition->height); } @@ -513,10 +601,8 @@ caja_path_bar_size_request (GtkWidget *widget, requisition->width += (path_bar->spacing + path_bar->slider_width) * 2; } - gtk_widget_get_preferred_size (path_bar->up_slider_button, - &child_requisition, NULL); - gtk_widget_get_preferred_size (path_bar->down_slider_button, - &child_requisition, NULL); + gtk_widget_size_request (path_bar->up_slider_button, &child_requisition); + gtk_widget_size_request (path_bar->down_slider_button, &child_requisition); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); requisition->width += border_width * 2; @@ -525,6 +611,7 @@ caja_path_bar_size_request (GtkWidget *widget, gtk_widget_set_size_request (widget, requisition->width, requisition->height); } +#endif /* GTK_CHECK_VERSION(3,0,0) */ static void caja_path_bar_update_slider_buttons (CajaPathBar *path_bar) @@ -575,7 +662,6 @@ caja_path_bar_size_allocate (GtkWidget *widget, GList *list, *first_button; gint width; gint allocation_width; - gint border_width; gboolean need_sliders; gint up_slider_offset; gint down_slider_offset; @@ -595,8 +681,12 @@ caja_path_bar_size_allocate (GtkWidget *widget, return; } direction = gtk_widget_get_direction (widget); - border_width = (gint) gtk_container_get_border_width (GTK_CONTAINER (path_bar)); +#if GTK_CHECK_VERSION(3,0,0) + allocation_width = allocation->width; +#else + gint border_width = (gint) gtk_container_get_border_width (GTK_CONTAINER (path_bar)); allocation_width = allocation->width - 2 * border_width; +#endif /* First, we check to see if we need the scrollbars. */ if (path_bar->fake_root) @@ -709,24 +799,45 @@ caja_path_bar_size_allocate (GtkWidget *widget, } /* Now, we allocate space to the buttons */ +#if GTK_CHECK_VERSION(3,0,0) + child_allocation.y = allocation->y; + child_allocation.height = allocation->height; +#else child_allocation.y = allocation->y + border_width; child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2); +#endif if (direction == GTK_TEXT_DIR_RTL) { +#if GTK_CHECK_VERSION(3,0,0) + child_allocation.x = allocation->x + allocation->width; +#else child_allocation.x = allocation->x + allocation->width - border_width; +#endif if (need_sliders || path_bar->fake_root) { child_allocation.x -= (path_bar->spacing + path_bar->slider_width); +#if GTK_CHECK_VERSION(3,0,0) + up_slider_offset = allocation->width - path_bar->slider_width; +#else up_slider_offset = allocation->width - border_width - path_bar->slider_width; +#endif } } else { +#if GTK_CHECK_VERSION(3,0,0) + child_allocation.x = allocation->x; +#else child_allocation.x = allocation->x + border_width; +#endif if (need_sliders || path_bar->fake_root) { +#if GTK_CHECK_VERSION(3,0,0) + up_slider_offset = 0; +#else up_slider_offset = border_width; +#endif child_allocation.x += (path_bar->spacing + path_bar->slider_width); } } @@ -746,7 +857,11 @@ caja_path_bar_size_allocate (GtkWidget *widget, /* Check to see if we've don't have any more space to allocate buttons */ if (need_sliders && direction == GTK_TEXT_DIR_RTL) { +#if GTK_CHECK_VERSION(3,0,0) + if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x) { +#else if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x + border_width) +#endif { break; } @@ -755,7 +870,11 @@ caja_path_bar_size_allocate (GtkWidget *widget, { if (need_sliders && direction == GTK_TEXT_DIR_LTR) { +#if GTK_CHECK_VERSION(3,0,0) + if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width > widget_allocation.x + allocation_width) { +#else if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width > widget_allocation.x + border_width + allocation_width) +#endif { break; } @@ -769,12 +888,20 @@ caja_path_bar_size_allocate (GtkWidget *widget, { child_allocation.x -= path_bar->spacing; down_slider_offset = child_allocation.x - widget_allocation.x - path_bar->slider_width; +#if GTK_CHECK_VERSION(3,0,0) + down_slider_offset = 0; +#else down_slider_offset = border_width; +#endif } else { down_slider_offset = child_allocation.x - widget_allocation.x; +#if GTK_CHECK_VERSION(3,0,0) + down_slider_offset = allocation->width - path_bar->slider_width; +#else down_slider_offset = allocation->width - border_width - path_bar->slider_width; +#endif child_allocation.x += child_allocation.width + path_bar->spacing; } } @@ -968,7 +1095,6 @@ caja_path_bar_scroll_down (CajaPathBar *path_bar) GList *up_button; gint space_available; gint space_needed; - gint border_width; GtkTextDirection direction; GtkAllocation allocation, button_allocation, slider_allocation; @@ -983,7 +1109,9 @@ caja_path_bar_scroll_down (CajaPathBar *path_bar) gtk_widget_queue_resize (GTK_WIDGET (path_bar)); - border_width = gtk_container_get_border_width (GTK_CONTAINER (path_bar)); +#if !GTK_CHECK_VERSION(3,0,0) + gint border_width = gtk_container_get_border_width (GTK_CONTAINER (path_bar)); +#endif direction = gtk_widget_get_direction (GTK_WIDGET (path_bar)); /* We find the button at the 'down' end that we have to make */ @@ -1023,7 +1151,10 @@ caja_path_bar_scroll_down (CajaPathBar *path_bar) } else { - space_available = (allocation.x + allocation.width - border_width) - + space_available = (allocation.x + allocation.width) - +#if !GTK_CHECK_VERSION(3,0,0) + border_width - +#endif (slider_allocation.x + slider_allocation.width); } @@ -1415,6 +1546,34 @@ get_dir_name (ButtonData *button_data) /* We always want to request the same size for the label, whether * or not the contents are bold */ +#if GTK_CHECK_VERSION(3,0,0) +static void +set_label_size_request (GtkWidget *alignment, + ButtonData *button_data) +{ + const gchar *dir_name = get_dir_name (button_data); + PangoLayout *layout; + gint width, height, bold_width, bold_height; + gchar *markup; + + layout = gtk_widget_create_pango_layout (button_data->label, dir_name); + pango_layout_get_pixel_size (layout, &width, &height); + + markup = g_markup_printf_escaped ("%s", dir_name); + pango_layout_set_markup (layout, markup, -1); + g_free (markup); + + pango_layout_get_pixel_size (layout, &bold_width, &bold_height); + + gtk_widget_set_size_request (alignment, + MAX (width, bold_width), + MAX (height, bold_height)); + + g_object_unref (layout); +} + +#else /* GTK_CHECK_VERSION(3,0,0) */ + static void label_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, @@ -1438,6 +1597,7 @@ label_size_request_cb (GtkWidget *widget, g_object_unref (layout); } +#endif /* GTK_CHECK_VERSION(3,0,0) */ static void caja_path_bar_update_button_appearance (ButtonData *button_data) @@ -1872,16 +2032,17 @@ make_directory_button (CajaPathBar *path_bar, button_data->is_base_dir = base_dir; } +#if !GTK_CHECK_VERSION(3,0,0) /* label_alignment is created because we can't override size-request * on label itself and still have the contents of the label centered * properly in the label's requisition */ - if (label_alignment) { g_signal_connect (label_alignment, "size-request", G_CALLBACK (label_size_request_cb), button_data); } +#endif if (button_data->path == NULL) { @@ -1904,6 +2065,18 @@ make_directory_button (CajaPathBar *path_bar, button_data->file_is_hidden = file_is_hidden; +#if GTK_CHECK_VERSION(3,0,0) + /* FIXME: Maybe we dont need this alignment at all and we can + * use GtkMisc aligments or even GtkWidget:halign/valign center. + * + * The following function ensures that the alignment will always + * request the same size whether the button's text is bold or not. + */ + if (label_alignment) { + set_label_size_request (label_alignment, button_data); + } +#endif + gtk_container_add (GTK_CONTAINER (button_data->button), child); gtk_widget_show_all (button_data->button); -- cgit v1.2.1