X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkpathbar.c;h=24c038dd7b9b8f8e4e506ee59409713153e9f0cc;hb=24de7cd86fb65fa77c6a66e1f558ed9a7eb4e314;hp=81d06c642d8def08ac1999048b89aa80071cff23;hpb=214a023e9160fa008db069f5ec10ce3a4999a4dc;p=~andy%2Fgtk diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index 81d06c642..24c038dd7 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -19,8 +19,11 @@ */ #include "config.h" -#include + #include "gtkpathbar.h" + +#include + #include "gtktogglebutton.h" #include "gtkalignment.h" #include "gtkarrow.h" @@ -33,7 +36,7 @@ #include "gtkhbox.h" #include "gtkmain.h" #include "gtkmarshalers.h" -#include "gtkalias.h" + enum { PATH_CLICKED, @@ -82,8 +85,12 @@ static void gtk_path_bar_finalize (GObject *object); static void gtk_path_bar_dispose (GObject *object); static void gtk_path_bar_realize (GtkWidget *widget); static void gtk_path_bar_unrealize (GtkWidget *widget); -static void gtk_path_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition); +static void gtk_path_bar_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural); +static void gtk_path_bar_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural); static void gtk_path_bar_map (GtkWidget *widget); static void gtk_path_bar_unmap (GtkWidget *widget); static void gtk_path_bar_size_allocate (GtkWidget *widget, @@ -117,8 +124,7 @@ static void gtk_path_bar_grab_notify (GtkWidget *widget, gboolean was_grabbed); static void gtk_path_bar_state_changed (GtkWidget *widget, GtkStateType previous_state); -static void gtk_path_bar_style_set (GtkWidget *widget, - GtkStyle *previous_style); +static void gtk_path_bar_style_updated (GtkWidget *widget); static void gtk_path_bar_screen_changed (GtkWidget *widget, GdkScreen *previous_screen); static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar); @@ -169,7 +175,7 @@ get_slider_button (GtkPathBar *path_bar, static void gtk_path_bar_init (GtkPathBar *path_bar) { - GTK_WIDGET_SET_FLAGS (path_bar, GTK_NO_WINDOW); + gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE); gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE); path_bar->get_info_cancellable = NULL; @@ -203,25 +209,24 @@ static void gtk_path_bar_class_init (GtkPathBarClass *path_bar_class) { GObjectClass *gobject_class; - GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; gobject_class = (GObjectClass *) path_bar_class; - object_class = (GtkObjectClass *) path_bar_class; widget_class = (GtkWidgetClass *) path_bar_class; container_class = (GtkContainerClass *) path_bar_class; gobject_class->finalize = gtk_path_bar_finalize; gobject_class->dispose = gtk_path_bar_dispose; - widget_class->size_request = gtk_path_bar_size_request; + widget_class->get_preferred_width = gtk_path_bar_get_preferred_width; + widget_class->get_preferred_height = gtk_path_bar_get_preferred_height; widget_class->realize = gtk_path_bar_realize; widget_class->unrealize = gtk_path_bar_unrealize; widget_class->map = gtk_path_bar_map; widget_class->unmap = gtk_path_bar_unmap; widget_class->size_allocate = gtk_path_bar_size_allocate; - widget_class->style_set = gtk_path_bar_style_set; + widget_class->style_updated = gtk_path_bar_style_updated; widget_class->screen_changed = gtk_path_bar_screen_changed; widget_class->grab_notify = gtk_path_bar_grab_notify; widget_class->state_changed = gtk_path_bar_state_changed; @@ -230,12 +235,13 @@ gtk_path_bar_class_init (GtkPathBarClass *path_bar_class) container_class->add = gtk_path_bar_add; container_class->forall = gtk_path_bar_forall; container_class->remove = gtk_path_bar_remove; + gtk_container_class_handle_border_width (container_class); /* FIXME: */ /* container_class->child_type = gtk_path_bar_child_type;*/ path_bar_signals [PATH_CLICKED] = g_signal_new (I_("path-clicked"), - G_OBJECT_CLASS_TYPE (object_class), + G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GtkPathBarClass, path_clicked), NULL, NULL, @@ -313,48 +319,74 @@ gtk_path_bar_dispose (GObject *object) * available space. */ static void -gtk_path_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition) +gtk_path_bar_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural) { ButtonData *button_data; GtkPathBar *path_bar; - GtkRequisition child_requisition; GList *list; + gint child_height; + gint height; + gint child_min, child_nat; path_bar = GTK_PATH_BAR (widget); - requisition->width = 0; - requisition->height = 0; + *minimum = *natural = 0; + height = 0; for (list = path_bar->button_list; list; list = list->next) { button_data = BUTTON_DATA (list->data); - gtk_widget_size_request (button_data->button, &child_requisition); - + 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. */ - requisition->width = MAX (child_requisition.height * 2, requisition->width); - else - requisition->width = MAX (child_requisition.width, requisition->width); + { + /* 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); + } - requisition->height = MAX (child_requisition.height, requisition->height); + *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(requisition->height * 2 / 3 + 5, requisition->height); + path_bar->slider_width = MIN (height * 2 / 3 + 5, height); if (path_bar->button_list && path_bar->button_list->next != NULL) - requisition->width += (path_bar->spacing + path_bar->slider_width) * 2; + { + *minimum += (path_bar->spacing + path_bar->slider_width) * 2; + *natural += (path_bar->spacing + path_bar->slider_width) * 2; + } +} - gtk_widget_size_request (path_bar->up_slider_button, &child_requisition); - gtk_widget_size_request (path_bar->down_slider_button, &child_requisition); +static void +gtk_path_bar_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + ButtonData *button_data; + GtkPathBar *path_bar; + GList *list; + gint child_min, child_nat; - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; + path_bar = GTK_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); - widget->requisition = *requisition; + *minimum = MAX (*minimum, child_min); + *natural = MAX (*natural, child_nat); + } } static void @@ -405,30 +437,33 @@ static void gtk_path_bar_realize (GtkWidget *widget) { GtkPathBar *path_bar; + GtkAllocation allocation; + GdkWindow *window; GdkWindowAttr attributes; gint attributes_mask; - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + gtk_widget_set_realized (widget, TRUE); path_bar = GTK_PATH_BAR (widget); - widget->window = gtk_widget_get_parent_window (widget); - g_object_ref (widget->window); + window = gtk_widget_get_parent_window (widget); + gtk_widget_set_window (widget, window); + g_object_ref (window); + + gtk_widget_get_allocation (widget, &allocation); attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; attributes.wclass = GDK_INPUT_ONLY; attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= GDK_SCROLL_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y; path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); + &attributes, attributes_mask); gdk_window_set_user_data (path_bar->event_window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); } static void @@ -458,13 +493,13 @@ gtk_path_bar_size_allocate (GtkWidget *widget, GList *list, *first_button; gint width; gint allocation_width; - gint border_width; gboolean need_sliders = FALSE; gint up_slider_offset = 0; + GtkRequisition child_requisition; - widget->allocation = *allocation; + gtk_widget_set_allocation (widget, allocation); - if (GTK_WIDGET_REALIZED (widget)) + if (gtk_widget_get_realized (widget)) gdk_window_move_resize (path_bar->event_window, allocation->x, allocation->y, allocation->width, allocation->height); @@ -474,20 +509,21 @@ gtk_path_bar_size_allocate (GtkWidget *widget, return; direction = gtk_widget_get_direction (widget); - border_width = (gint) GTK_CONTAINER (path_bar)->border_width; - allocation_width = allocation->width - 2 * border_width; + allocation_width = allocation->width; /* First, we check to see if we need the scrollbars. */ if (path_bar->fake_root) width = path_bar->spacing + path_bar->slider_width; else - width = 0; + width = 0; for (list = path_bar->button_list; list; list = list->next) { child = BUTTON_DATA (list->data)->button; - width += child->requisition.width + path_bar->spacing; + gtk_widget_get_preferred_size (child, &child_requisition, NULL); + + width += child_requisition.width + path_bar->spacing; if (list == path_bar->fake_root) break; } @@ -515,19 +551,24 @@ gtk_path_bar_size_allocate (GtkWidget *widget, * button, then count backwards. */ /* Count down the path chain towards the end. */ - width = BUTTON_DATA (first_button->data)->button->requisition.width; + gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button, + &child_requisition, NULL); + + width = child_requisition.width; list = first_button->prev; while (list && !reached_end) { child = BUTTON_DATA (list->data)->button; - if (width + child->requisition.width + + gtk_widget_get_preferred_size (child, &child_requisition, NULL); + + if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width) reached_end = TRUE; else if (list == path_bar->fake_root) break; else - width += child->requisition.width + path_bar->spacing; + width += child_requisition.width + path_bar->spacing; list = list->prev; } @@ -538,13 +579,15 @@ gtk_path_bar_size_allocate (GtkWidget *widget, { child = BUTTON_DATA (first_button->next->data)->button; - if (width + child->requisition.width + path_bar->spacing + slider_space > allocation_width) + gtk_widget_get_preferred_size (child, &child_requisition, NULL); + + if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width) { reached_end = TRUE; } else { - width += child->requisition.width + path_bar->spacing; + width += child_requisition.width + path_bar->spacing; if (first_button == path_bar->fake_root) break; first_button = first_button->next; @@ -553,36 +596,39 @@ gtk_path_bar_size_allocate (GtkWidget *widget, } /* Now, we allocate space to the buttons */ - child_allocation.y = allocation->y + border_width; - child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2); + child_allocation.y = allocation->y; + child_allocation.height = allocation->height; if (direction == GTK_TEXT_DIR_RTL) { - child_allocation.x = allocation->x + allocation->width - border_width; + child_allocation.x = allocation->x + allocation->width; if (need_sliders || path_bar->fake_root) { child_allocation.x -= (path_bar->spacing + path_bar->slider_width); - up_slider_offset = allocation->width - border_width - path_bar->slider_width; + up_slider_offset = allocation->width - path_bar->slider_width; } } else { - child_allocation.x = allocation->x + border_width; + child_allocation.x = allocation->x; if (need_sliders || path_bar->fake_root) { - up_slider_offset = border_width; + up_slider_offset = 0; child_allocation.x += (path_bar->spacing + path_bar->slider_width); } } for (list = first_button; list; list = list->prev) { + GtkAllocation widget_allocation; ButtonData *button_data; button_data = BUTTON_DATA (list->data); child = button_data->button; - child_allocation.width = MIN (child->requisition.width, + gtk_widget_get_preferred_size (child, &child_requisition, NULL); + + child_allocation.width = MIN (child_requisition.width, allocation_width - (path_bar->spacing + path_bar->slider_width) * 2); if (direction == GTK_TEXT_DIR_RTL) @@ -591,17 +637,19 @@ gtk_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 (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width) + gtk_widget_get_allocation (widget, &widget_allocation); + if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x) break; } else if (need_sliders && direction == GTK_TEXT_DIR_LTR) { + gtk_widget_get_allocation (widget, &widget_allocation); if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width > - widget->allocation.x + border_width + allocation_width) + widget_allocation.x + allocation_width) break; } - if (child_allocation.width < child->requisition.width) + if (child_allocation.width < child_requisition.width) { if (!gtk_widget_get_has_tooltip (child)) gtk_widget_set_tooltip_text (child, button_data->dir_name); @@ -645,9 +693,9 @@ gtk_path_bar_size_allocate (GtkWidget *widget, child_allocation.width = path_bar->slider_width; if (direction == GTK_TEXT_DIR_RTL) - child_allocation.x = border_width; + child_allocation.x = 0; else - child_allocation.x = allocation->width - border_width - path_bar->slider_width; + child_allocation.x = allocation->width - path_bar->slider_width; child_allocation.x += allocation->x; @@ -662,10 +710,9 @@ gtk_path_bar_size_allocate (GtkWidget *widget, } static void -gtk_path_bar_style_set (GtkWidget *widget, - GtkStyle *previous_style) +gtk_path_bar_style_updated (GtkWidget *widget) { - GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style); + GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget); gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget)); } @@ -790,6 +837,7 @@ gtk_path_bar_forall (GtkContainer *container, static void gtk_path_bar_scroll_down (GtkPathBar *path_bar) { + GtkAllocation allocation, button_allocation; GList *list; GList *down_button = NULL; gint space_available; @@ -819,10 +867,12 @@ gtk_path_bar_scroll_down (GtkPathBar *path_bar) } } - space_available = (GTK_WIDGET (path_bar)->allocation.width - - 2 * GTK_CONTAINER (path_bar)->border_width + gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation); + gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation); + + space_available = (allocation.width - 2 * path_bar->spacing - 2 * path_bar->slider_width - - BUTTON_DATA (down_button->data)->button->allocation.width); + - button_allocation.width); path_bar->first_scrolled_button = down_button; /* We have space_available free space that's not being used. @@ -834,7 +884,7 @@ gtk_path_bar_scroll_down (GtkPathBar *path_bar) down_button = down_button->next; if (!down_button) break; - space_available -= (BUTTON_DATA (down_button->data)->button->allocation.width + space_available -= (button_allocation.width + path_bar->spacing); } } @@ -1148,7 +1198,7 @@ button_clicked_cb (GtkWidget *button, if (button_data->ignore_changes) return; - path_bar = GTK_PATH_BAR (button->parent); + path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button)); button_list = g_list_find (path_bar->button_list, button_data); g_assert (button_list != NULL); @@ -1261,7 +1311,7 @@ set_button_image (GtkPathBar *path_bar, GTK_WIDGET (path_bar), path_bar->icon_size, NULL); - _gtk_file_system_volume_free (volume); + _gtk_file_system_volume_unref (volume); gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon); break; @@ -1342,25 +1392,25 @@ get_dir_name (ButtonData *button_data) * or not the contents are bold */ static void -label_size_request_cb (GtkWidget *widget, - GtkRequisition *requisition, - ButtonData *button_data) +set_label_size_request (GtkWidget *alignment, + ButtonData *button_data) { const gchar *dir_name = get_dir_name (button_data); PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name); - gint bold_width, bold_height; + gint width, height, bold_width, bold_height; gchar *markup; - - pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height); + + 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); - requisition->width = MAX (requisition->width, bold_width); - requisition->height = MAX (requisition->height, bold_height); - + + gtk_widget_set_size_request (alignment, + MAX (width, bold_width), + MAX (height, bold_height)); g_object_unref (layout); } @@ -1418,24 +1468,23 @@ find_button_type (GtkPathBar *path_bar, } static void -button_drag_data_get_cb (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time_, - gpointer data) +button_drag_data_get_cb (GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint info, + guint time_, + gpointer data) { ButtonData *button_data; - GtkPathBar *path_bar; char *uris[2]; button_data = data; - path_bar = GTK_PATH_BAR (widget->parent); /* the button's parent *is* the path bar */ uris[0] = g_file_get_uri (button_data->file); uris[1] = NULL; gtk_selection_data_set_uris (selection_data, uris); + g_free (uris[0]); } @@ -1474,7 +1523,7 @@ make_directory_button (GtkPathBar *path_bar, button_data->label = gtk_label_new (NULL); label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label); - child = gtk_hbox_new (FALSE, 2); + child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0); break; @@ -1488,18 +1537,19 @@ make_directory_button (GtkPathBar *path_bar, button_data->image = NULL; } - /* 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); - button_data->dir_name = g_strdup (dir_name); button_data->file = g_object_ref (file); button_data->file_is_hidden = file_is_hidden; + /* 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); + gtk_container_add (GTK_CONTAINER (button_data->button), child); gtk_widget_show_all (button_data->button); @@ -1695,19 +1745,16 @@ gtk_path_bar_get_info_callback (GCancellable *cancellable, } gboolean -_gtk_path_bar_set_file (GtkPathBar *path_bar, - GFile *file, - const gboolean keep_trail, - GError **error) +_gtk_path_bar_set_file (GtkPathBar *path_bar, + GFile *file, + const gboolean keep_trail, + GError **error) { struct SetFileInfo *info; - gboolean result; g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); - result = TRUE; - /* Check whether the new path is already present in the pathbar as buttons. * This could be a parent directory or a previous selected subdirectory. */ @@ -1726,10 +1773,10 @@ _gtk_path_bar_set_file (GtkPathBar *path_bar, path_bar->get_info_cancellable = _gtk_file_system_get_info (path_bar->file_system, - info->file, - "standard::display-name,standard::is-hidden,standard::is-backup", - gtk_path_bar_get_info_callback, - info); + info->file, + "standard::display-name,standard::is-hidden,standard::is-backup", + gtk_path_bar_get_info_callback, + info); return TRUE; } @@ -1823,6 +1870,3 @@ _gtk_path_bar_down (GtkPathBar *path_bar) } } } - -#define __GTK_PATH_BAR_C__ -#include "gtkaliasdef.c"