]> Pileus Git - ~andy/gtk/blob - gtk/gtkpathbar.c
Merge remaining fixes from the 2.8 branch, pointed out by Michael
[~andy/gtk] / gtk / gtkpathbar.c
1 /* gtkpathbar.c
2  * Copyright (C) 2004  Red Hat, Inc.,  Jonathan Blandford <jrb@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <config.h>
21 #include <string.h>
22 #include "gtkpathbar.h"
23 #include "gtktogglebutton.h"
24 #include "gtkalignment.h"
25 #include "gtkarrow.h"
26 #include "gtkdnd.h"
27 #include "gtkimage.h"
28 #include "gtkintl.h"
29 #include "gtkicontheme.h"
30 #include "gtkiconfactory.h"
31 #include "gtklabel.h"
32 #include "gtkhbox.h"
33 #include "gtkmain.h"
34 #include "gtkmarshalers.h"
35 #include "gtkalias.h"
36
37 enum {
38   PATH_CLICKED,
39   LAST_SIGNAL
40 };
41
42 typedef enum {
43   NORMAL_BUTTON,
44   ROOT_BUTTON,
45   HOME_BUTTON,
46   DESKTOP_BUTTON
47 } ButtonType;
48
49 #define BUTTON_DATA(x) ((ButtonData *)(x))
50
51 #define SCROLL_TIMEOUT           150
52 #define INITIAL_SCROLL_TIMEOUT   300
53
54 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
55
56 /* Icon size for if we can't get it from the theme */
57 #define FALLBACK_ICON_SIZE 16
58
59 typedef struct _ButtonData ButtonData;
60
61 struct _ButtonData
62 {
63   GtkWidget *button;
64   ButtonType type;
65   char *dir_name;
66   GtkFilePath *path;
67   GtkWidget *image;
68   GtkWidget *label;
69   guint ignore_changes : 1;
70   guint file_is_hidden : 1;
71 };
72 /* This macro is used to check if a button can be used as a fake root.
73  * All buttons in front of a fake root are automatically hidden when in a
74  * directory below a fake root and replaced with the "<" arrow button.
75  */
76 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
77
78 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER);
79
80 static void gtk_path_bar_finalize                 (GObject          *object);
81 static void gtk_path_bar_dispose                  (GObject          *object);
82 static void gtk_path_bar_size_request             (GtkWidget        *widget,
83                                                    GtkRequisition   *requisition);
84 static void gtk_path_bar_unmap                    (GtkWidget          *widget);
85 static void gtk_path_bar_size_allocate            (GtkWidget        *widget,
86                                                    GtkAllocation    *allocation);
87 static void gtk_path_bar_add                      (GtkContainer     *container,
88                                                    GtkWidget        *widget);
89 static void gtk_path_bar_remove                   (GtkContainer     *container,
90                                                    GtkWidget        *widget);
91 static void gtk_path_bar_forall                   (GtkContainer     *container,
92                                                    gboolean          include_internals,
93                                                    GtkCallback       callback,
94                                                    gpointer          callback_data);
95 static void gtk_path_bar_scroll_up                (GtkWidget        *button,
96                                                    GtkPathBar       *path_bar);
97 static void gtk_path_bar_scroll_down              (GtkWidget        *button,
98                                                    GtkPathBar       *path_bar);
99 static void gtk_path_bar_stop_scrolling           (GtkPathBar       *path_bar);
100 static gboolean gtk_path_bar_slider_button_press  (GtkWidget        *widget,
101                                                    GdkEventButton   *event,
102                                                    GtkPathBar       *path_bar);
103 static gboolean gtk_path_bar_slider_button_release(GtkWidget        *widget,
104                                                    GdkEventButton   *event,
105                                                    GtkPathBar       *path_bar);
106 static void gtk_path_bar_grab_notify              (GtkWidget        *widget,
107                                                    gboolean          was_grabbed);
108 static void gtk_path_bar_state_changed            (GtkWidget        *widget,
109                                                    GtkStateType      previous_state);
110 static void gtk_path_bar_style_set                (GtkWidget        *widget,
111                                                    GtkStyle         *previous_style);
112 static void gtk_path_bar_screen_changed           (GtkWidget        *widget,
113                                                    GdkScreen        *previous_screen);
114 static void gtk_path_bar_check_icon_theme         (GtkPathBar       *path_bar);
115 static void gtk_path_bar_update_button_appearance (GtkPathBar       *path_bar,
116                                                    ButtonData       *button_data,
117                                                    gboolean          current_dir);
118
119 static GtkWidget *
120 get_slider_button (GtkPathBar  *path_bar,
121                    GtkArrowType arrow_type)
122 {
123   GtkWidget *button;
124
125   gtk_widget_push_composite_child ();
126
127   button = gtk_button_new ();
128   gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
129   gtk_container_add (GTK_CONTAINER (button), gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
130   gtk_container_add (GTK_CONTAINER (path_bar), button);
131   gtk_widget_show_all (button);
132
133   gtk_widget_pop_composite_child ();
134
135   return button;
136 }
137
138 static void
139 gtk_path_bar_init (GtkPathBar *path_bar)
140 {
141   GTK_WIDGET_SET_FLAGS (path_bar, GTK_NO_WINDOW);
142   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
143
144   path_bar->spacing = 3;
145   path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
146   path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
147   path_bar->icon_size = FALLBACK_ICON_SIZE;
148   
149   g_signal_connect (path_bar->up_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
150   g_signal_connect (path_bar->down_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
151
152   g_signal_connect (path_bar->up_slider_button, "button_press_event", G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
153   g_signal_connect (path_bar->up_slider_button, "button_release_event", G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
154   g_signal_connect (path_bar->down_slider_button, "button_press_event", G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
155   g_signal_connect (path_bar->down_slider_button, "button_release_event", G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
156 }
157
158 static void
159 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
160 {
161   GObjectClass *gobject_class;
162   GtkObjectClass *object_class;
163   GtkWidgetClass *widget_class;
164   GtkContainerClass *container_class;
165
166   gobject_class = (GObjectClass *) path_bar_class;
167   object_class = (GtkObjectClass *) path_bar_class;
168   widget_class = (GtkWidgetClass *) path_bar_class;
169   container_class = (GtkContainerClass *) path_bar_class;
170
171   gobject_class->finalize = gtk_path_bar_finalize;
172   gobject_class->dispose = gtk_path_bar_dispose;
173
174   widget_class->size_request = gtk_path_bar_size_request;
175   widget_class->unmap = gtk_path_bar_unmap;
176   widget_class->size_allocate = gtk_path_bar_size_allocate;
177   widget_class->style_set = gtk_path_bar_style_set;
178   widget_class->screen_changed = gtk_path_bar_screen_changed;
179   widget_class->grab_notify = gtk_path_bar_grab_notify;
180   widget_class->state_changed = gtk_path_bar_state_changed;
181
182   container_class->add = gtk_path_bar_add;
183   container_class->forall = gtk_path_bar_forall;
184   container_class->remove = gtk_path_bar_remove;
185   /* FIXME: */
186   /*  container_class->child_type = gtk_path_bar_child_type;*/
187
188   path_bar_signals [PATH_CLICKED] =
189     g_signal_new (I_("path-clicked"),
190                   G_OBJECT_CLASS_TYPE (object_class),
191                   G_SIGNAL_RUN_FIRST,
192                   G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
193                   NULL, NULL,
194                   _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
195                   G_TYPE_NONE, 3,
196                   G_TYPE_POINTER,
197                   G_TYPE_POINTER,
198                   G_TYPE_BOOLEAN);
199 }
200
201
202 static void
203 gtk_path_bar_finalize (GObject *object)
204 {
205   GtkPathBar *path_bar;
206
207   path_bar = GTK_PATH_BAR (object);
208
209   gtk_path_bar_stop_scrolling (path_bar);
210
211   g_list_free (path_bar->button_list);
212   if (path_bar->root_path)
213     gtk_file_path_free (path_bar->root_path);
214   if (path_bar->home_path)
215     gtk_file_path_free (path_bar->home_path);
216   if (path_bar->desktop_path)
217     gtk_file_path_free (path_bar->desktop_path);
218
219   if (path_bar->root_icon)
220     g_object_unref (path_bar->root_icon);
221   if (path_bar->home_icon)
222     g_object_unref (path_bar->home_icon);
223   if (path_bar->desktop_icon)
224     g_object_unref (path_bar->desktop_icon);
225
226   if (path_bar->file_system)
227     g_object_unref (path_bar->file_system);
228
229   G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
230 }
231
232 /* Removes the settings signal handler.  It's safe to call multiple times */
233 static void
234 remove_settings_signal (GtkPathBar *path_bar,
235                         GdkScreen  *screen)
236 {
237   if (path_bar->settings_signal_id)
238     {
239       GtkSettings *settings;
240
241       settings = gtk_settings_get_for_screen (screen);
242       g_signal_handler_disconnect (settings,
243                                    path_bar->settings_signal_id);
244       path_bar->settings_signal_id = 0;
245     }
246 }
247
248 static void
249 gtk_path_bar_dispose (GObject *object)
250 {
251   remove_settings_signal (GTK_PATH_BAR (object),
252                           gtk_widget_get_screen (GTK_WIDGET (object)));
253
254   G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
255 }
256
257 /* Size requisition:
258  * 
259  * Ideally, our size is determined by another widget, and we are just filling
260  * available space.
261  */
262 static void
263 gtk_path_bar_size_request (GtkWidget      *widget,
264                            GtkRequisition *requisition)
265 {
266   ButtonData *button_data;
267   GtkPathBar *path_bar;
268   GtkRequisition child_requisition;
269   GList *list;
270
271   path_bar = GTK_PATH_BAR (widget);
272
273   requisition->width = 0;
274   requisition->height = 0;
275
276   for (list = path_bar->button_list; list; list = list->next)
277     {
278       button_data = BUTTON_DATA (list->data);
279       gtk_widget_size_request (button_data->button, &child_requisition);
280       requisition->width = MAX (child_requisition.width, requisition->width);
281       requisition->height = MAX (child_requisition.height, requisition->height);
282     }
283
284   /* Add space for slider, if we have more than one path */
285   /* Theoretically, the slider could be bigger than the other button.  But we're
286    * not going to worry about that now.
287    */
288   path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
289   if (path_bar->button_list && path_bar->button_list->next != NULL)
290     requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
291
292   gtk_widget_size_request (path_bar->up_slider_button, &child_requisition);
293   gtk_widget_size_request (path_bar->down_slider_button, &child_requisition);
294
295   requisition->width += GTK_CONTAINER (widget)->border_width * 2;
296   requisition->height += GTK_CONTAINER (widget)->border_width * 2;
297
298   widget->requisition = *requisition;
299 }
300
301 static void
302 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
303 {
304   if (path_bar->button_list)
305     {
306       GtkWidget *button;
307
308       button = BUTTON_DATA (path_bar->button_list->data)->button;
309       if (gtk_widget_get_child_visible (button))
310         {
311           gtk_path_bar_stop_scrolling (path_bar);
312           gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
313         }
314       else
315         gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
316
317       button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
318       if (gtk_widget_get_child_visible (button))
319         {
320           gtk_path_bar_stop_scrolling (path_bar);
321           gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
322         }
323       else
324         gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
325     }
326 }
327
328 static void
329 gtk_path_bar_unmap (GtkWidget *widget)
330 {
331   gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
332
333   GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
334 }
335
336 /* This is a tad complicated
337  */
338 static void
339 gtk_path_bar_size_allocate (GtkWidget     *widget,
340                             GtkAllocation *allocation)
341 {
342   GtkWidget *child;
343   GtkPathBar *path_bar = GTK_PATH_BAR (widget);
344   GtkTextDirection direction;
345   GtkAllocation child_allocation;
346   GList *list, *first_button;
347   gint width;
348   gint allocation_width;
349   gint border_width;
350   gboolean need_sliders = FALSE;
351   gint up_slider_offset = 0;
352   gint down_slider_offset = 0;
353
354   widget->allocation = *allocation;
355
356   /* No path is set; we don't have to allocate anything. */
357   if (path_bar->button_list == NULL)
358     return;
359
360   direction = gtk_widget_get_direction (widget);
361   border_width = (gint) GTK_CONTAINER (path_bar)->border_width;
362   allocation_width = allocation->width - 2 * border_width;
363
364   /* First, we check to see if we need the scrollbars. */
365   if (path_bar->fake_root)
366     width = path_bar->spacing + path_bar->slider_width;
367   else
368       width = 0;
369
370   for (list = path_bar->button_list; list; list = list->next)
371     {
372       child = BUTTON_DATA (list->data)->button;
373
374       width += child->requisition.width + path_bar->spacing;
375       if (list == path_bar->fake_root)
376         break;
377     }
378
379   if (width <= allocation_width)
380     {
381       if (path_bar->fake_root)
382         first_button = path_bar->fake_root;
383       else
384         first_button = g_list_last (path_bar->button_list);
385     }
386   else
387     {
388       gboolean reached_end = FALSE;
389       gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
390
391       if (path_bar->first_scrolled_button)
392         first_button = path_bar->first_scrolled_button;
393       else
394         first_button = path_bar->button_list;
395       need_sliders = TRUE;
396       
397       /* To see how much space we have, and how many buttons we can display.
398        * We start at the first button, count forward until hit the new
399        * button, then count backwards.
400        */
401       /* Count down the path chain towards the end. */
402       width = BUTTON_DATA (first_button->data)->button->requisition.width;
403       list = first_button->prev;
404       while (list && !reached_end)
405         {
406           child = BUTTON_DATA (list->data)->button;
407
408           if (width + child->requisition.width +
409               path_bar->spacing + slider_space > allocation_width)
410             reached_end = TRUE;
411           else if (list == path_bar->fake_root)
412             break;
413           else
414             width += child->requisition.width + path_bar->spacing;
415
416           list = list->prev;
417         }
418
419       /* Finally, we walk up, seeing how many of the previous buttons we can
420        * add */
421       while (first_button->next && !reached_end)
422         {
423           child = BUTTON_DATA (first_button->next->data)->button;
424
425           if (width + child->requisition.width + path_bar->spacing + slider_space > allocation_width)
426             {
427               reached_end = TRUE;
428             }
429           else
430             {
431               width += child->requisition.width + path_bar->spacing;
432               if (first_button == path_bar->fake_root)
433                 break;
434               first_button = first_button->next;
435             }
436         }
437     }
438
439   /* Now, we allocate space to the buttons */
440   child_allocation.y = allocation->y + border_width;
441   child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
442
443   if (direction == GTK_TEXT_DIR_RTL)
444     {
445       child_allocation.x = allocation->x + allocation->width - border_width;
446       if (need_sliders || path_bar->fake_root)
447         {
448           child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
449           up_slider_offset = allocation->width - border_width - path_bar->slider_width;
450         }
451     }
452   else
453     {
454       child_allocation.x = allocation->x + border_width;
455       if (need_sliders || path_bar->fake_root)
456         {
457           up_slider_offset = border_width;
458           child_allocation.x += (path_bar->spacing + path_bar->slider_width);
459         }
460     }
461
462   for (list = first_button; list; list = list->prev)
463     {
464       child = BUTTON_DATA (list->data)->button;
465
466       child_allocation.width = child->requisition.width;
467       if (direction == GTK_TEXT_DIR_RTL)
468         child_allocation.x -= child_allocation.width;
469
470       /* Check to see if we've don't have any more space to allocate buttons */
471       if (need_sliders && direction == GTK_TEXT_DIR_RTL)
472         {
473           if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width)
474             break;
475         }
476       else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
477         {
478           if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
479               widget->allocation.x + border_width + allocation_width)
480             break;
481         }
482
483       gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, TRUE);
484       gtk_widget_size_allocate (child, &child_allocation);
485
486       if (direction == GTK_TEXT_DIR_RTL)
487         {
488           child_allocation.x -= path_bar->spacing;
489           down_slider_offset = child_allocation.x - widget->allocation.x - path_bar->slider_width;
490           down_slider_offset = border_width;
491         }
492       else
493         {
494           down_slider_offset = child_allocation.x - widget->allocation.x;
495           down_slider_offset = allocation->width - border_width - path_bar->slider_width;
496           child_allocation.x += child_allocation.width + path_bar->spacing;
497         }
498     }
499   /* Now we go hide all the widgets that don't fit */
500   while (list)
501     {
502       gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
503       list = list->prev;
504     }
505   for (list = first_button->next; list; list = list->next)
506     {
507       gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
508     }
509
510   if (need_sliders || path_bar->fake_root)
511     {
512       child_allocation.width = path_bar->slider_width;
513       child_allocation.x = up_slider_offset + allocation->x;
514       gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
515
516       gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
517       gtk_widget_show_all (path_bar->up_slider_button);
518     }
519   else
520     gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
521       
522   if (need_sliders)
523     {
524       child_allocation.width = path_bar->slider_width;
525       child_allocation.x = down_slider_offset + allocation->x;
526       gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
527
528       gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
529       gtk_widget_show_all (path_bar->down_slider_button);
530       gtk_path_bar_update_slider_buttons (path_bar);
531     }
532   else
533     gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
534 }
535
536 static void
537 gtk_path_bar_style_set (GtkWidget *widget,
538                         GtkStyle  *previous_style)
539 {
540   if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set)
541     GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
542
543   gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
544 }
545
546 static void
547 gtk_path_bar_screen_changed (GtkWidget *widget,
548                              GdkScreen *previous_screen)
549 {
550   if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
551     GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
552
553   /* We might nave a new settings, so we remove the old one */
554   if (previous_screen)
555     remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
556
557   gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
558 }
559
560 static void
561 gtk_path_bar_add (GtkContainer *container,
562                   GtkWidget    *widget)
563 {
564   gtk_widget_set_parent (widget, GTK_WIDGET (container));
565 }
566
567 static void
568 gtk_path_bar_remove_1 (GtkContainer *container,
569                        GtkWidget    *widget)
570 {
571   gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
572   gtk_widget_unparent (widget);
573   if (was_visible)
574     gtk_widget_queue_resize (GTK_WIDGET (container));
575 }
576
577 static void
578 gtk_path_bar_remove (GtkContainer *container,
579                      GtkWidget    *widget)
580 {
581   GtkPathBar *path_bar;
582   GList *children;
583
584   path_bar = GTK_PATH_BAR (container);
585
586   if (widget == path_bar->up_slider_button)
587     {
588       gtk_path_bar_remove_1 (container, widget);
589       path_bar->up_slider_button = NULL;
590       return;
591     }
592
593   if (widget == path_bar->down_slider_button)
594     {
595       gtk_path_bar_remove_1 (container, widget);
596       path_bar->down_slider_button = NULL;
597       return;
598     }
599
600   children = path_bar->button_list;
601   while (children)
602     {
603       if (widget == BUTTON_DATA (children->data)->button)
604         {
605           gtk_path_bar_remove_1 (container, widget);
606           path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
607           g_list_free (children);
608           return;
609         }
610       
611       children = children->next;
612     }
613 }
614
615 static void
616 gtk_path_bar_forall (GtkContainer *container,
617                      gboolean      include_internals,
618                      GtkCallback   callback,
619                      gpointer      callback_data)
620 {
621   GtkPathBar *path_bar;
622   GList *children;
623
624   g_return_if_fail (callback != NULL);
625   path_bar = GTK_PATH_BAR (container);
626
627   children = path_bar->button_list;
628   while (children)
629     {
630       GtkWidget *child;
631       child = BUTTON_DATA (children->data)->button;
632       children = children->next;
633
634       (* callback) (child, callback_data);
635     }
636
637   if (path_bar->up_slider_button)
638     (* callback) (path_bar->up_slider_button, callback_data);
639
640   if (path_bar->down_slider_button)
641     (* callback) (path_bar->down_slider_button, callback_data);
642 }
643
644 static void
645 gtk_path_bar_scroll_down (GtkWidget *button, GtkPathBar *path_bar)
646 {
647   GList *list;
648   GList *down_button = NULL;
649   GList *up_button = NULL;
650   gint space_available;
651   gint space_needed;
652   gint border_width;
653   GtkTextDirection direction;
654
655   if (path_bar->ignore_click)
656     {
657       path_bar->ignore_click = FALSE;
658       return;   
659     }
660
661   gtk_widget_queue_resize (GTK_WIDGET (path_bar));
662
663   border_width = GTK_CONTAINER (path_bar)->border_width;
664   direction = gtk_widget_get_direction (GTK_WIDGET (path_bar));
665   
666   /* We find the button at the 'down' end that we have to make
667    * visible */
668   for (list = path_bar->button_list; list; list = list->next)
669     {
670       if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
671         {
672           down_button = list;
673           break;
674         }
675     }
676   
677   /* Find the last visible button on the 'up' end
678    */
679   for (list = g_list_last (path_bar->button_list); list; list = list->prev)
680     {
681       if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
682         {
683           up_button = list;
684           break;
685         }
686     }
687
688   space_needed = BUTTON_DATA (down_button->data)->button->allocation.width + path_bar->spacing;
689   if (direction == GTK_TEXT_DIR_RTL)
690     space_available = path_bar->down_slider_button->allocation.x - GTK_WIDGET (path_bar)->allocation.x;
691   else
692     space_available = (GTK_WIDGET (path_bar)->allocation.x + GTK_WIDGET (path_bar)->allocation.width - border_width) -
693       (path_bar->down_slider_button->allocation.x + path_bar->down_slider_button->allocation.width);
694
695   /* We have space_available extra space that's not being used.  We
696    * need space_needed space to make the button fit.  So we walk down
697    * from the end, removing buttons until we get all the space we
698    * need. */
699   while (space_available < space_needed)
700     {
701       space_available += BUTTON_DATA (up_button->data)->button->allocation.width + path_bar->spacing;
702       up_button = up_button->prev;
703       path_bar->first_scrolled_button = up_button;
704     }
705 }
706
707 static void
708 gtk_path_bar_scroll_up (GtkWidget *button, GtkPathBar *path_bar)
709 {
710   GList *list;
711
712   if (path_bar->ignore_click)
713     {
714       path_bar->ignore_click = FALSE;
715       return;   
716     }
717
718   gtk_widget_queue_resize (GTK_WIDGET (path_bar));
719
720   for (list = g_list_last (path_bar->button_list); list; list = list->prev)
721     {
722       if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
723         {
724           if (list->prev == path_bar->fake_root)
725             path_bar->fake_root = NULL;
726           path_bar->first_scrolled_button = list;
727           return;
728         }
729     }
730 }
731
732 static gboolean
733 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
734 {
735   gboolean retval = FALSE;
736
737   GDK_THREADS_ENTER ();
738
739   if (path_bar->timer)
740     {
741       if (path_bar->scrolling_up)
742         gtk_path_bar_scroll_up (path_bar->up_slider_button, path_bar);
743       else if (path_bar->scrolling_down)
744         gtk_path_bar_scroll_down (path_bar->down_slider_button, path_bar);
745
746       if (path_bar->need_timer) 
747         {
748           path_bar->need_timer = FALSE;
749
750           path_bar->timer = g_timeout_add (SCROLL_TIMEOUT,
751                                            (GSourceFunc)gtk_path_bar_scroll_timeout,
752                                            path_bar);
753           
754         }
755       else
756         retval = TRUE;
757       
758     }
759
760   GDK_THREADS_LEAVE ();
761
762   return retval;
763 }
764
765 static void 
766 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
767 {
768   if (path_bar->timer)
769     {
770       g_source_remove (path_bar->timer);
771       path_bar->timer = 0;
772       path_bar->need_timer = FALSE;
773     }
774 }
775
776 static gboolean
777 gtk_path_bar_slider_button_press (GtkWidget      *widget, 
778                                   GdkEventButton *event,
779                                   GtkPathBar     *path_bar)
780 {
781   if (event->type != GDK_BUTTON_PRESS || event->button != 1)
782     return FALSE;
783
784   path_bar->ignore_click = FALSE;
785
786   if (widget == path_bar->up_slider_button)
787     {
788       path_bar->scrolling_down = FALSE;
789       path_bar->scrolling_up = TRUE;
790       gtk_path_bar_scroll_up (path_bar->up_slider_button, path_bar);
791     }
792   else if (widget == path_bar->down_slider_button)
793     {
794       path_bar->scrolling_up = FALSE;
795       path_bar->scrolling_down = TRUE;
796       gtk_path_bar_scroll_down (path_bar->down_slider_button, path_bar);
797     }
798
799   if (!path_bar->timer)
800     {
801       path_bar->need_timer = TRUE;
802       path_bar->timer = g_timeout_add (INITIAL_SCROLL_TIMEOUT,
803                                        (GSourceFunc)gtk_path_bar_scroll_timeout,
804                                        path_bar);
805     }
806
807   return FALSE;
808 }
809
810 static gboolean
811 gtk_path_bar_slider_button_release (GtkWidget      *widget, 
812                                     GdkEventButton *event,
813                                     GtkPathBar     *path_bar)
814 {
815   if (event->type != GDK_BUTTON_RELEASE)
816     return FALSE;
817
818   path_bar->ignore_click = TRUE;
819   gtk_path_bar_stop_scrolling (path_bar);
820
821   return FALSE;
822 }
823
824 static void
825 gtk_path_bar_grab_notify (GtkWidget *widget,
826                           gboolean   was_grabbed)
827 {
828   if (!was_grabbed)
829     gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
830 }
831
832 static void
833 gtk_path_bar_state_changed (GtkWidget    *widget,
834                             GtkStateType  previous_state)
835 {
836   if (!GTK_WIDGET_IS_SENSITIVE (widget)) 
837     gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
838 }
839
840
841 /* Changes the icons wherever it is needed */
842 static void
843 reload_icons (GtkPathBar *path_bar)
844 {
845   GList *list;
846
847   if (path_bar->root_icon)
848     {
849       g_object_unref (path_bar->root_icon);
850       path_bar->root_icon = NULL;
851     }
852   if (path_bar->home_icon)
853     {
854       g_object_unref (path_bar->home_icon);
855       path_bar->home_icon = NULL;
856     }
857   if (path_bar->desktop_icon)
858     {
859       g_object_unref (path_bar->desktop_icon);
860       path_bar->desktop_icon = NULL;
861     }
862
863   for (list = path_bar->button_list; list; list = list->next)
864     {
865       ButtonData *button_data;
866       gboolean current_dir;
867
868       button_data = BUTTON_DATA (list->data);
869       if (button_data->type != NORMAL_BUTTON)
870         {
871           current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
872           gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
873         }
874     }
875   
876 }
877
878 static void
879 change_icon_theme (GtkPathBar *path_bar)
880 {
881   GtkSettings *settings;
882   gint width, height;
883
884   settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
885
886   if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
887     path_bar->icon_size = MAX (width, height);
888   else
889     path_bar->icon_size = FALLBACK_ICON_SIZE;
890
891   reload_icons (path_bar);
892 }
893 /* Callback used when a GtkSettings value changes */
894 static void
895 settings_notify_cb (GObject    *object,
896                     GParamSpec *pspec,
897                     GtkPathBar *path_bar)
898 {
899   const char *name;
900
901   name = g_param_spec_get_name (pspec);
902
903   if (! strcmp (name, "gtk-icon-theme-name") ||
904       ! strcmp (name, "gtk-icon-sizes"))
905     change_icon_theme (path_bar);
906 }
907
908 static void
909 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
910 {
911   GtkSettings *settings;
912
913   if (path_bar->settings_signal_id)
914     return;
915
916   settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
917   path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
918
919   change_icon_theme (path_bar);
920 }
921
922 /* Public functions and their helpers */
923 static void
924 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
925 {
926   while (path_bar->button_list != NULL)
927     {
928       gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
929     }
930   path_bar->first_scrolled_button = NULL;
931   path_bar->fake_root = NULL;
932 }
933
934 static void
935 button_clicked_cb (GtkWidget *button,
936                    gpointer   data)
937 {
938   ButtonData *button_data;
939   GtkPathBar *path_bar;
940   GList *button_list;
941   gboolean child_is_hidden;
942   GtkFilePath *child_path;
943
944   button_data = BUTTON_DATA (data);
945   if (button_data->ignore_changes)
946     return;
947
948   path_bar = GTK_PATH_BAR (button->parent);
949
950   button_list = g_list_find (path_bar->button_list, button_data);
951   g_assert (button_list != NULL);
952
953   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
954
955   if (button_list->prev)
956     {
957       ButtonData *child_data;
958
959       child_data = BUTTON_DATA (button_list->prev->data);
960       child_path = child_data->path;
961       child_is_hidden = child_data->file_is_hidden;
962     }
963   else
964     {
965       child_path = NULL;
966       child_is_hidden = FALSE;
967     }
968
969   g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
970                  button_data->path, child_path, child_is_hidden);
971 }
972
973 static GdkPixbuf *
974 get_button_image (GtkPathBar *path_bar,
975                   ButtonType  button_type)
976 {
977   GtkFileSystemVolume *volume;
978
979   switch (button_type)
980     {
981     case ROOT_BUTTON:
982
983       if (path_bar->root_icon != NULL)
984         return path_bar->root_icon;
985       
986       volume = gtk_file_system_get_volume_for_path (path_bar->file_system, path_bar->root_path);
987       if (volume == NULL)
988         return NULL;
989
990       path_bar->root_icon = gtk_file_system_volume_render_icon (path_bar->file_system,
991                                                                 volume,
992                                                                 GTK_WIDGET (path_bar),
993                                                                 path_bar->icon_size,
994                                                                 NULL);
995       gtk_file_system_volume_free (path_bar->file_system, volume);
996
997       return path_bar->root_icon;
998     case HOME_BUTTON:
999       if (path_bar->home_icon != NULL)
1000         return path_bar->home_icon;
1001
1002       path_bar->home_icon = gtk_file_system_render_icon (path_bar->file_system,
1003                                                          path_bar->home_path,
1004                                                          GTK_WIDGET (path_bar),
1005                                                          path_bar->icon_size,
1006                                                          NULL);
1007       return path_bar->home_icon;
1008     case DESKTOP_BUTTON:
1009       if (path_bar->desktop_icon != NULL)
1010         return path_bar->desktop_icon;
1011
1012       path_bar->desktop_icon = gtk_file_system_render_icon (path_bar->file_system,
1013                                                             path_bar->desktop_path,
1014                                                             GTK_WIDGET (path_bar),
1015                                                             path_bar->icon_size,
1016                                                             NULL);
1017       return path_bar->desktop_icon;
1018     default:
1019       return NULL;
1020     }
1021   
1022   return NULL;
1023 }
1024
1025 static void
1026 button_data_free (ButtonData *button_data)
1027 {
1028   gtk_file_path_free (button_data->path);
1029   g_free (button_data->dir_name);
1030   g_free (button_data);
1031 }
1032
1033 static const char *
1034 get_dir_name (ButtonData *button_data)
1035 {
1036   return button_data->dir_name;
1037 }
1038
1039 /* We always want to request the same size for the label, whether
1040  * or not the contents are bold
1041  */
1042 static void
1043 label_size_request_cb (GtkWidget      *widget,
1044                        GtkRequisition *requisition,
1045                        ButtonData     *button_data)
1046 {
1047   const gchar *dir_name = get_dir_name (button_data);
1048   PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1049   gint bold_width, bold_height;
1050   gchar *markup;
1051
1052   pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
1053   
1054   markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1055   pango_layout_set_markup (layout, markup, -1);
1056   g_free (markup);
1057
1058   pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1059   requisition->width = MAX (requisition->width, bold_width);
1060   requisition->height = MAX (requisition->height, bold_height);
1061   
1062   g_object_unref (layout);
1063 }
1064
1065 static void
1066 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1067                                        ButtonData *button_data,
1068                                        gboolean    current_dir)
1069 {
1070   const gchar *dir_name = get_dir_name (button_data);
1071
1072   if (button_data->label != NULL)
1073     {
1074       if (current_dir)
1075         {
1076           char *markup;
1077
1078           markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1079           gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1080           g_free (markup);
1081         }
1082       else
1083         {
1084           gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1085         }
1086     }
1087
1088   if (button_data->image != NULL)
1089     {
1090       GdkPixbuf *pixbuf;
1091       pixbuf = get_button_image (path_bar, button_data->type);
1092       gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), pixbuf);
1093     }
1094
1095   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1096     {
1097       button_data->ignore_changes = TRUE;
1098       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1099       button_data->ignore_changes = FALSE;
1100     }
1101 }
1102
1103 static ButtonType
1104 find_button_type (GtkPathBar  *path_bar,
1105                   GtkFilePath *path)
1106 {
1107   if (path_bar->root_path != NULL &&
1108       ! gtk_file_path_compare (path, path_bar->root_path))
1109     return ROOT_BUTTON;
1110   if (path_bar->home_path != NULL &&
1111       ! gtk_file_path_compare (path, path_bar->home_path))
1112     return HOME_BUTTON;
1113   if (path_bar->desktop_path != NULL &&
1114       ! gtk_file_path_compare (path, path_bar->desktop_path))
1115     return DESKTOP_BUTTON;
1116
1117  return NORMAL_BUTTON;
1118 }
1119
1120 static void
1121 button_drag_data_get_cb (GtkWidget          *widget,
1122                          GdkDragContext     *context,
1123                          GtkSelectionData   *selection_data,
1124                          guint               info,
1125                          guint               time_,
1126                          gpointer            data)
1127 {
1128   ButtonData *button_data;
1129   GtkPathBar *path_bar;
1130   char *uri;
1131   char *uri_list;
1132
1133   button_data = data;
1134   path_bar = GTK_PATH_BAR (widget->parent); /* the button's parent *is* the path bar */
1135
1136   uri = gtk_file_system_path_to_uri (path_bar->file_system, button_data->path);
1137   uri_list = g_strconcat (uri, "\r\n", NULL);
1138   g_free (uri);
1139
1140   gtk_selection_data_set (selection_data,
1141                           selection_data->target,
1142                           8,
1143                           (guchar *)uri_list,
1144                           strlen (uri_list));
1145   g_free (uri_list);
1146 }
1147
1148 static ButtonData *
1149 make_directory_button (GtkPathBar  *path_bar,
1150                        const char  *dir_name,
1151                        GtkFilePath *path,
1152                        gboolean     current_dir,
1153                        gboolean     file_is_hidden)
1154 {
1155   const GtkTargetEntry targets[] = {
1156     { "text/uri-list", 0, 0 }
1157   };
1158
1159   GtkWidget *child = NULL;
1160   GtkWidget *label_alignment = NULL;
1161   ButtonData *button_data;
1162
1163   file_is_hidden = !! file_is_hidden;
1164   /* Is it a special button? */
1165   button_data = g_new0 (ButtonData, 1);
1166
1167   button_data->type = find_button_type (path_bar, path);
1168   button_data->button = gtk_toggle_button_new ();
1169   gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1170
1171   switch (button_data->type)
1172     {
1173     case ROOT_BUTTON:
1174       button_data->image = gtk_image_new ();
1175       child = button_data->image;
1176       button_data->label = NULL;
1177       break;
1178     case HOME_BUTTON:
1179     case DESKTOP_BUTTON:
1180       button_data->image = gtk_image_new ();
1181       button_data->label = gtk_label_new (NULL);
1182       label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1183       gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1184       child = gtk_hbox_new (FALSE, 2);
1185       gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1186       gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1187       break;
1188     case NORMAL_BUTTON:
1189     default:
1190       button_data->label = gtk_label_new (NULL);
1191       label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1192       gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1193       child = label_alignment;
1194       button_data->image = NULL;
1195     }
1196
1197   /* label_alignment is created because we can't override size-request
1198    * on label itself and still have the contents of the label centered
1199    * properly in the label's requisition
1200    */
1201   if (label_alignment)
1202     g_signal_connect (label_alignment, "size-request",
1203                       G_CALLBACK (label_size_request_cb), button_data);
1204
1205   button_data->dir_name = g_strdup (dir_name);
1206   button_data->path = gtk_file_path_new_dup (gtk_file_path_get_string (path));
1207   button_data->file_is_hidden = file_is_hidden;
1208                           
1209   gtk_container_add (GTK_CONTAINER (button_data->button), child);
1210   gtk_widget_show_all (button_data->button);
1211
1212   gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1213
1214   g_signal_connect (button_data->button, "clicked",
1215                     G_CALLBACK (button_clicked_cb),
1216                     button_data);
1217   g_object_weak_ref (G_OBJECT (button_data->button),
1218                      (GWeakNotify) button_data_free, button_data);
1219
1220   gtk_drag_source_set (button_data->button,
1221                        GDK_BUTTON1_MASK,
1222                        targets,
1223                        G_N_ELEMENTS (targets),
1224                        GDK_ACTION_COPY);
1225   g_signal_connect (button_data->button, "drag-data-get",
1226                     G_CALLBACK (button_drag_data_get_cb), button_data);
1227
1228   return button_data;
1229 }
1230
1231 static gboolean
1232 gtk_path_bar_check_parent_path (GtkPathBar         *path_bar,
1233                                 const GtkFilePath  *file_path,
1234                                 GtkFileSystem      *file_system)
1235 {
1236   GList *list;
1237   GList *current_path = NULL;
1238   gboolean need_new_fake_root = FALSE;
1239
1240   for (list = path_bar->button_list; list; list = list->next)
1241     {
1242       ButtonData *button_data;
1243
1244       button_data = list->data;
1245       if (! gtk_file_path_compare (file_path, button_data->path))
1246         {
1247           current_path = list;
1248           break;
1249         }
1250       if (list == path_bar->fake_root)
1251         need_new_fake_root = TRUE;
1252     }
1253
1254   if (current_path)
1255     {
1256       if (need_new_fake_root)
1257         {
1258           path_bar->fake_root = NULL;
1259           for (list = current_path; list; list = list->next)
1260             {
1261               ButtonData *button_data;
1262
1263               button_data = list->data;
1264               if (BUTTON_IS_FAKE_ROOT (button_data))
1265                 {
1266                   path_bar->fake_root = list;
1267                   break;
1268                 }
1269             }
1270         }
1271
1272       for (list = path_bar->button_list; list; list = list->next)
1273         {
1274           gtk_path_bar_update_button_appearance (path_bar,
1275                                                  BUTTON_DATA (list->data),
1276                                                  (list == current_path) ? TRUE : FALSE);
1277         }
1278
1279       if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1280         {
1281           path_bar->first_scrolled_button = current_path;
1282           gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1283         }
1284
1285       return TRUE;
1286     }
1287   return FALSE;
1288 }
1289
1290 gboolean
1291 _gtk_path_bar_set_path (GtkPathBar         *path_bar,
1292                         const GtkFilePath  *file_path,
1293                         const gboolean      keep_trail,     
1294                         GError            **error)
1295 {
1296   GtkFilePath *path;
1297   gboolean first_directory = TRUE;
1298   gboolean result;
1299   GList *new_buttons = NULL;
1300   GList *fake_root = NULL;
1301
1302   g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1303   g_return_val_if_fail (file_path != NULL, FALSE);
1304
1305   result = TRUE;
1306
1307   /* Check whether the new path is already present in the pathbar as buttons.
1308    * This could be a parent directory or a previous selected subdirectory.
1309    */
1310   if (keep_trail &&
1311       gtk_path_bar_check_parent_path (path_bar, file_path, path_bar->file_system))
1312     return TRUE;
1313
1314   path = gtk_file_path_copy (file_path);
1315
1316   gtk_widget_push_composite_child ();
1317
1318   while (path != NULL)
1319     {
1320       GtkFilePath *parent_path = NULL;
1321       ButtonData *button_data;
1322       const gchar *display_name;
1323       gboolean is_hidden;
1324       GtkFileFolder *file_folder;
1325       GtkFileInfo *file_info;
1326       gboolean valid;
1327
1328       valid = gtk_file_system_get_parent (path_bar->file_system,
1329                                           path,
1330                                           &parent_path,
1331                                           error);
1332       if (!valid)
1333         {
1334           result = FALSE;
1335           gtk_file_path_free (path);
1336           break;
1337         }
1338
1339       file_folder = gtk_file_system_get_folder (path_bar->file_system,
1340                                                 parent_path ? parent_path : path,
1341                                                 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN,
1342                                                 NULL);
1343       if (!file_folder)
1344         {
1345           result = FALSE;
1346           gtk_file_path_free (parent_path);
1347           gtk_file_path_free (path);
1348           break;
1349         }
1350
1351       file_info = gtk_file_folder_get_info (file_folder, parent_path ? path : NULL, error);
1352       g_object_unref (file_folder);
1353
1354       if (!file_info)
1355         {
1356           result = FALSE;
1357           gtk_file_path_free (parent_path);
1358           gtk_file_path_free (path);
1359           break;
1360         }
1361
1362       display_name = gtk_file_info_get_display_name (file_info);
1363       is_hidden = gtk_file_info_get_is_hidden (file_info);
1364
1365       button_data = make_directory_button (path_bar, display_name, path, first_directory, is_hidden);
1366       gtk_file_info_free (file_info);
1367       gtk_file_path_free (path);
1368
1369       new_buttons = g_list_prepend (new_buttons, button_data);
1370
1371       if (BUTTON_IS_FAKE_ROOT (button_data))
1372         fake_root = new_buttons;
1373
1374       path = parent_path;
1375       first_directory = FALSE;
1376     }
1377
1378   if (result)
1379     {
1380       GList *l;
1381
1382       gtk_path_bar_clear_buttons (path_bar);
1383       path_bar->button_list = g_list_reverse (new_buttons);
1384       path_bar->fake_root = fake_root;
1385
1386       for (l = path_bar->button_list; l; l = l->next)
1387         {
1388           GtkWidget *button = BUTTON_DATA (l->data)->button;
1389           gtk_container_add (GTK_CONTAINER (path_bar), button);
1390         }
1391     }
1392   else
1393     {
1394       GList *l;
1395
1396       for (l = new_buttons; l; l = l->next)
1397         {
1398           ButtonData *button_data;
1399
1400           button_data = BUTTON_DATA (l->data);
1401           gtk_widget_destroy (button_data->button);
1402         }
1403
1404       g_list_free (new_buttons);
1405     }
1406
1407   gtk_widget_pop_composite_child ();
1408
1409   return result;
1410 }
1411
1412 /* FIXME: This should be a construct-only property */
1413 void
1414 _gtk_path_bar_set_file_system (GtkPathBar    *path_bar,
1415                                GtkFileSystem *file_system)
1416 {
1417   const char *home;
1418   char *desktop;
1419
1420   g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1421
1422   g_assert (path_bar->file_system == NULL);
1423
1424   path_bar->file_system = g_object_ref (file_system);
1425
1426   home = g_get_home_dir ();
1427   if (home != NULL)
1428     {
1429       path_bar->home_path = gtk_file_system_filename_to_path (path_bar->file_system, home);
1430       /* FIXME: Need file system backend specific way of getting the
1431        * Desktop path.
1432        */
1433       desktop = g_build_filename (home, "Desktop", NULL);
1434       path_bar->desktop_path = gtk_file_system_filename_to_path (path_bar->file_system, desktop);
1435       g_free (desktop);
1436     }
1437   else
1438     {
1439       path_bar->home_path = NULL;
1440       path_bar->desktop_path = NULL;
1441     }
1442   path_bar->root_path = gtk_file_system_filename_to_path (path_bar->file_system, "/");
1443 }
1444
1445 /**
1446  * _gtk_path_bar_up:
1447  * @path_bar: a #GtkPathBar
1448  * 
1449  * If the selected button in the pathbar is not the furthest button "up" (in the
1450  * root direction), act as if the user clicked on the next button up.
1451  **/
1452 void
1453 _gtk_path_bar_up (GtkPathBar *path_bar)
1454 {
1455   GList *l;
1456
1457   for (l = path_bar->button_list; l; l = l->next)
1458     {
1459       GtkWidget *button = BUTTON_DATA (l->data)->button;
1460       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1461         {
1462           if (l->next)
1463             {
1464               GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1465               button_clicked_cb (next_button, l->next->data);
1466             }
1467           break;
1468         }
1469     }
1470 }
1471
1472 /**
1473  * _gtk_path_bar_down:
1474  * @path_bar: a #GtkPathBar
1475  * 
1476  * If the selected button in the pathbar is not the furthest button "down" (in the
1477  * leaf direction), act as if the user clicked on the next button down.
1478  **/
1479 void
1480 _gtk_path_bar_down (GtkPathBar *path_bar)
1481 {
1482   GList *l;
1483
1484   for (l = path_bar->button_list; l; l = l->next)
1485     {
1486       GtkWidget *button = BUTTON_DATA (l->data)->button;
1487       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1488         {
1489           if (l->prev)
1490             {
1491               GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1492               button_clicked_cb (prev_button, l->prev->data);
1493             }
1494           break;
1495         }
1496     }
1497 }