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