Blame gtk/gtkpathbar.c

Packit 98cdb6
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
Packit 98cdb6
/* gtkpathbar.c
Packit 98cdb6
 * Copyright (C) 2004  Red Hat, Inc.,  Jonathan Blandford <jrb@gnome.org>
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Library General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Library General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Library General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include <string.h>
Packit 98cdb6
#include "gtkpathbar.h"
Packit 98cdb6
#include "gtktogglebutton.h"
Packit 98cdb6
#include "gtkalignment.h"
Packit 98cdb6
#include "gtkarrow.h"
Packit 98cdb6
#include "gtkdnd.h"
Packit 98cdb6
#include "gtkimage.h"
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkicontheme.h"
Packit 98cdb6
#include "gtkiconfactory.h"
Packit 98cdb6
#include "gtklabel.h"
Packit 98cdb6
#include "gtkhbox.h"
Packit 98cdb6
#include "gtkmain.h"
Packit 98cdb6
#include "gtkmarshalers.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
enum {
Packit 98cdb6
  PATH_CLICKED,
Packit 98cdb6
  LAST_SIGNAL
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
typedef enum {
Packit 98cdb6
  NORMAL_BUTTON,
Packit 98cdb6
  ROOT_BUTTON,
Packit 98cdb6
  HOME_BUTTON,
Packit 98cdb6
  DESKTOP_BUTTON
Packit 98cdb6
} ButtonType;
Packit 98cdb6
Packit 98cdb6
#define BUTTON_DATA(x) ((ButtonData *)(x))
Packit 98cdb6
Packit 98cdb6
#define SCROLL_DELAY_FACTOR 5
Packit 98cdb6
Packit 98cdb6
static guint path_bar_signals [LAST_SIGNAL] = { 0 };
Packit 98cdb6
Packit 98cdb6
/* Icon size for if we can't get it from the theme */
Packit 98cdb6
#define FALLBACK_ICON_SIZE 16
Packit 98cdb6
Packit 98cdb6
typedef struct _ButtonData ButtonData;
Packit 98cdb6
Packit 98cdb6
struct _ButtonData
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *button;
Packit 98cdb6
  ButtonType type;
Packit 98cdb6
  char *dir_name;
Packit 98cdb6
  GFile *file;
Packit 98cdb6
  GtkWidget *image;
Packit 98cdb6
  GtkWidget *label;
Packit 98cdb6
  GCancellable *cancellable;
Packit 98cdb6
  guint ignore_changes : 1;
Packit 98cdb6
  guint file_is_hidden : 1;
Packit 98cdb6
};
Packit 98cdb6
/* This macro is used to check if a button can be used as a fake root.
Packit 98cdb6
 * All buttons in front of a fake root are automatically hidden when in a
Packit 98cdb6
 * directory below a fake root and replaced with the "<" arrow button.
Packit 98cdb6
 */
Packit 98cdb6
#define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
Packit 98cdb6
Packit 98cdb6
static void gtk_path_bar_finalize                 (GObject          *object);
Packit 98cdb6
static void gtk_path_bar_dispose                  (GObject          *object);
Packit 98cdb6
static void gtk_path_bar_realize                  (GtkWidget        *widget);
Packit 98cdb6
static void gtk_path_bar_unrealize                (GtkWidget        *widget);
Packit 98cdb6
static void gtk_path_bar_size_request             (GtkWidget        *widget,
Packit 98cdb6
						   GtkRequisition   *requisition);
Packit 98cdb6
static void gtk_path_bar_map                      (GtkWidget        *widget);
Packit 98cdb6
static void gtk_path_bar_unmap                    (GtkWidget        *widget);
Packit 98cdb6
static void gtk_path_bar_size_allocate            (GtkWidget        *widget,
Packit 98cdb6
						   GtkAllocation    *allocation);
Packit 98cdb6
static void gtk_path_bar_add                      (GtkContainer     *container,
Packit 98cdb6
						   GtkWidget        *widget);
Packit 98cdb6
static void gtk_path_bar_remove                   (GtkContainer     *container,
Packit 98cdb6
						   GtkWidget        *widget);
Packit 98cdb6
static void gtk_path_bar_forall                   (GtkContainer     *container,
Packit 98cdb6
						   gboolean          include_internals,
Packit 98cdb6
						   GtkCallback       callback,
Packit 98cdb6
						   gpointer          callback_data);
Packit 98cdb6
static gboolean gtk_path_bar_scroll               (GtkWidget        *widget,
Packit 98cdb6
						   GdkEventScroll   *event);
Packit 98cdb6
static void gtk_path_bar_scroll_up                (GtkPathBar       *path_bar);
Packit 98cdb6
static void gtk_path_bar_scroll_down              (GtkPathBar       *path_bar);
Packit 98cdb6
static void gtk_path_bar_stop_scrolling           (GtkPathBar       *path_bar);
Packit 98cdb6
static gboolean gtk_path_bar_slider_up_defocus    (GtkWidget        *widget,
Packit 98cdb6
						   GdkEventButton   *event,
Packit 98cdb6
						   GtkPathBar       *path_bar);
Packit 98cdb6
static gboolean gtk_path_bar_slider_down_defocus  (GtkWidget        *widget,
Packit 98cdb6
						   GdkEventButton   *event,
Packit 98cdb6
						   GtkPathBar       *path_bar);
Packit 98cdb6
static gboolean gtk_path_bar_slider_button_press  (GtkWidget        *widget,
Packit 98cdb6
						   GdkEventButton   *event,
Packit 98cdb6
						   GtkPathBar       *path_bar);
Packit 98cdb6
static gboolean gtk_path_bar_slider_button_release(GtkWidget        *widget,
Packit 98cdb6
						   GdkEventButton   *event,
Packit 98cdb6
						   GtkPathBar       *path_bar);
Packit 98cdb6
static void gtk_path_bar_grab_notify              (GtkWidget        *widget,
Packit 98cdb6
						   gboolean          was_grabbed);
Packit 98cdb6
static void gtk_path_bar_state_changed            (GtkWidget        *widget,
Packit 98cdb6
						   GtkStateType      previous_state);
Packit 98cdb6
static void gtk_path_bar_style_set                (GtkWidget        *widget,
Packit 98cdb6
						   GtkStyle         *previous_style);
Packit 98cdb6
static void gtk_path_bar_screen_changed           (GtkWidget        *widget,
Packit 98cdb6
						   GdkScreen        *previous_screen);
Packit 98cdb6
static void gtk_path_bar_check_icon_theme         (GtkPathBar       *path_bar);
Packit 98cdb6
static void gtk_path_bar_update_button_appearance (GtkPathBar       *path_bar,
Packit 98cdb6
						   ButtonData       *button_data,
Packit 98cdb6
						   gboolean          current_dir);
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
on_slider_unmap (GtkWidget  *widget,
Packit 98cdb6
		 GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  if (path_bar->timer &&
Packit 98cdb6
      ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
Packit 98cdb6
       (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
Packit 98cdb6
    gtk_path_bar_stop_scrolling (path_bar);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static GtkWidget *
Packit 98cdb6
get_slider_button (GtkPathBar  *path_bar,
Packit 98cdb6
		   GtkArrowType arrow_type)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *button;
Packit 98cdb6
  AtkObject *atk_obj;
Packit 98cdb6
Packit 98cdb6
  gtk_widget_push_composite_child ();
Packit 98cdb6
Packit 98cdb6
  button = gtk_button_new ();
Packit 98cdb6
  atk_obj = gtk_widget_get_accessible (button);
Packit 98cdb6
  if (arrow_type == GTK_ARROW_LEFT)
Packit 98cdb6
    atk_object_set_name (atk_obj, _("Up Path"));
Packit 98cdb6
  else
Packit 98cdb6
    atk_object_set_name (atk_obj, _("Down Path"));
Packit 98cdb6
Packit 98cdb6
  gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (button),
Packit 98cdb6
                     gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (path_bar), button);
Packit 98cdb6
  gtk_widget_show_all (button);
Packit 98cdb6
Packit 98cdb6
  g_signal_connect (G_OBJECT (button), "unmap",
Packit 98cdb6
		    G_CALLBACK (on_slider_unmap), path_bar);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_pop_composite_child ();
Packit 98cdb6
Packit 98cdb6
  return button;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_init (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
Packit 98cdb6
  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
Packit 98cdb6
Packit 98cdb6
  path_bar->get_info_cancellable = NULL;
Packit 98cdb6
Packit 98cdb6
  path_bar->spacing = 0;
Packit 98cdb6
  path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
Packit 98cdb6
  path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
Packit 98cdb6
  path_bar->icon_size = FALLBACK_ICON_SIZE;
Packit 98cdb6
  
Packit 98cdb6
  g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
Packit 98cdb6
                            G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
Packit 98cdb6
  g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
Packit 98cdb6
                            G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
Packit 98cdb6
Packit 98cdb6
  g_signal_connect (path_bar->up_slider_button, "focus-out-event",
Packit 98cdb6
                    G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
Packit 98cdb6
  g_signal_connect (path_bar->down_slider_button, "focus-out-event",
Packit 98cdb6
                    G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
Packit 98cdb6
Packit 98cdb6
  g_signal_connect (path_bar->up_slider_button, "button-press-event",
Packit 98cdb6
                    G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
Packit 98cdb6
  g_signal_connect (path_bar->up_slider_button, "button-release-event",
Packit 98cdb6
                    G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
Packit 98cdb6
  g_signal_connect (path_bar->down_slider_button, "button-press-event",
Packit 98cdb6
                    G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
Packit 98cdb6
  g_signal_connect (path_bar->down_slider_button, "button-release-event",
Packit 98cdb6
                    G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *gobject_class;
Packit 98cdb6
  GtkObjectClass *object_class;
Packit 98cdb6
  GtkWidgetClass *widget_class;
Packit 98cdb6
  GtkContainerClass *container_class;
Packit 98cdb6
Packit 98cdb6
  gobject_class = (GObjectClass *) path_bar_class;
Packit 98cdb6
  object_class = (GtkObjectClass *) path_bar_class;
Packit 98cdb6
  widget_class = (GtkWidgetClass *) path_bar_class;
Packit 98cdb6
  container_class = (GtkContainerClass *) path_bar_class;
Packit 98cdb6
Packit 98cdb6
  gobject_class->finalize = gtk_path_bar_finalize;
Packit 98cdb6
  gobject_class->dispose = gtk_path_bar_dispose;
Packit 98cdb6
Packit 98cdb6
  widget_class->size_request = gtk_path_bar_size_request;
Packit 98cdb6
  widget_class->realize = gtk_path_bar_realize;
Packit 98cdb6
  widget_class->unrealize = gtk_path_bar_unrealize;
Packit 98cdb6
  widget_class->map = gtk_path_bar_map;
Packit 98cdb6
  widget_class->unmap = gtk_path_bar_unmap;
Packit 98cdb6
  widget_class->size_allocate = gtk_path_bar_size_allocate;
Packit 98cdb6
  widget_class->style_set = gtk_path_bar_style_set;
Packit 98cdb6
  widget_class->screen_changed = gtk_path_bar_screen_changed;
Packit 98cdb6
  widget_class->grab_notify = gtk_path_bar_grab_notify;
Packit 98cdb6
  widget_class->state_changed = gtk_path_bar_state_changed;
Packit 98cdb6
  widget_class->scroll_event = gtk_path_bar_scroll;
Packit 98cdb6
Packit 98cdb6
  container_class->add = gtk_path_bar_add;
Packit 98cdb6
  container_class->forall = gtk_path_bar_forall;
Packit 98cdb6
  container_class->remove = gtk_path_bar_remove;
Packit 98cdb6
  /* FIXME: */
Packit 98cdb6
  /*  container_class->child_type = gtk_path_bar_child_type;*/
Packit 98cdb6
Packit 98cdb6
  path_bar_signals [PATH_CLICKED] =
Packit 98cdb6
    g_signal_new (I_("path-clicked"),
Packit 98cdb6
		  G_OBJECT_CLASS_TYPE (object_class),
Packit 98cdb6
		  G_SIGNAL_RUN_FIRST,
Packit 98cdb6
		  G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
Packit 98cdb6
		  NULL, NULL,
Packit 98cdb6
		  _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
Packit 98cdb6
		  G_TYPE_NONE, 3,
Packit 98cdb6
		  G_TYPE_POINTER,
Packit 98cdb6
		  G_TYPE_POINTER,
Packit 98cdb6
		  G_TYPE_BOOLEAN);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_finalize (GObject *object)
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
Packit 98cdb6
  path_bar = GTK_PATH_BAR (object);
Packit 98cdb6
Packit 98cdb6
  gtk_path_bar_stop_scrolling (path_bar);
Packit 98cdb6
Packit 98cdb6
  g_list_free (path_bar->button_list);
Packit 98cdb6
  if (path_bar->root_file)
Packit 98cdb6
    g_object_unref (path_bar->root_file);
Packit 98cdb6
  if (path_bar->home_file)
Packit 98cdb6
    g_object_unref (path_bar->home_file);
Packit 98cdb6
  if (path_bar->desktop_file)
Packit 98cdb6
    g_object_unref (path_bar->desktop_file);
Packit 98cdb6
Packit 98cdb6
  if (path_bar->root_icon)
Packit 98cdb6
    g_object_unref (path_bar->root_icon);
Packit 98cdb6
  if (path_bar->home_icon)
Packit 98cdb6
    g_object_unref (path_bar->home_icon);
Packit 98cdb6
  if (path_bar->desktop_icon)
Packit 98cdb6
    g_object_unref (path_bar->desktop_icon);
Packit 98cdb6
Packit 98cdb6
  if (path_bar->file_system)
Packit 98cdb6
    g_object_unref (path_bar->file_system);
Packit 98cdb6
Packit 98cdb6
  G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/* Removes the settings signal handler.  It's safe to call multiple times */
Packit 98cdb6
static void
Packit 98cdb6
remove_settings_signal (GtkPathBar *path_bar,
Packit 98cdb6
			GdkScreen  *screen)
Packit 98cdb6
{
Packit 98cdb6
  if (path_bar->settings_signal_id)
Packit 98cdb6
    {
Packit 98cdb6
      GtkSettings *settings;
Packit 98cdb6
Packit 98cdb6
      settings = gtk_settings_get_for_screen (screen);
Packit 98cdb6
      g_signal_handler_disconnect (settings,
Packit 98cdb6
				   path_bar->settings_signal_id);
Packit 98cdb6
      path_bar->settings_signal_id = 0;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_dispose (GObject *object)
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar = GTK_PATH_BAR (object);
Packit 98cdb6
Packit 98cdb6
  remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
Packit 98cdb6
Packit 98cdb6
  if (path_bar->get_info_cancellable)
Packit 98cdb6
    g_cancellable_cancel (path_bar->get_info_cancellable);
Packit 98cdb6
  path_bar->get_info_cancellable = NULL;
Packit 98cdb6
Packit 98cdb6
  G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/* Size requisition:
Packit 98cdb6
 * 
Packit 98cdb6
 * Ideally, our size is determined by another widget, and we are just filling
Packit 98cdb6
 * available space.
Packit 98cdb6
 */
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_size_request (GtkWidget      *widget,
Packit 98cdb6
			   GtkRequisition *requisition)
Packit 98cdb6
{
Packit 98cdb6
  ButtonData *button_data;
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  GtkRequisition child_requisition;
Packit 98cdb6
  GList *list;
Packit 98cdb6
Packit 98cdb6
  path_bar = GTK_PATH_BAR (widget);
Packit 98cdb6
Packit 98cdb6
  requisition->width = 0;
Packit 98cdb6
  requisition->height = 0;
Packit 98cdb6
Packit 98cdb6
  for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      button_data = BUTTON_DATA (list->data);
Packit 98cdb6
      gtk_widget_size_request (button_data->button, &child_requisition);
Packit 98cdb6
      
Packit 98cdb6
      if (button_data->type == NORMAL_BUTTON)
Packit 98cdb6
	/* Use 2*Height as button width because of ellipsized label.  */
Packit 98cdb6
	requisition->width = MAX (child_requisition.height * 2, requisition->width);
Packit 98cdb6
      else
Packit 98cdb6
	requisition->width = MAX (child_requisition.width, requisition->width);
Packit 98cdb6
Packit 98cdb6
      requisition->height = MAX (child_requisition.height, requisition->height);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  /* Add space for slider, if we have more than one path */
Packit 98cdb6
  /* Theoretically, the slider could be bigger than the other button.  But we're
Packit 98cdb6
   * not going to worry about that now.
Packit 98cdb6
   */
Packit 98cdb6
  path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
Packit 98cdb6
  if (path_bar->button_list && path_bar->button_list->next != NULL)
Packit 98cdb6
    requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
Packit 98cdb6
Packit 98cdb6
  gtk_widget_size_request (path_bar->up_slider_button, &child_requisition);
Packit 98cdb6
  gtk_widget_size_request (path_bar->down_slider_button, &child_requisition);
Packit 98cdb6
Packit 98cdb6
  requisition->width += GTK_CONTAINER (widget)->border_width * 2;
Packit 98cdb6
  requisition->height += GTK_CONTAINER (widget)->border_width * 2;
Packit 98cdb6
Packit 98cdb6
  widget->requisition = *requisition;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  if (path_bar->button_list)
Packit 98cdb6
    {
Packit 98cdb6
      GtkWidget *button;
Packit 98cdb6
Packit 98cdb6
      button = BUTTON_DATA (path_bar->button_list->data)->button;
Packit 98cdb6
      if (gtk_widget_get_child_visible (button))
Packit 98cdb6
	{
Packit 98cdb6
	  gtk_path_bar_stop_scrolling (path_bar);
Packit 98cdb6
	  gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
Packit 98cdb6
Packit 98cdb6
      button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
Packit 98cdb6
      if (gtk_widget_get_child_visible (button))
Packit 98cdb6
	{
Packit 98cdb6
	  gtk_path_bar_stop_scrolling (path_bar);
Packit 98cdb6
	  gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_map (GtkWidget *widget)
Packit 98cdb6
{
Packit 98cdb6
  gdk_window_show (GTK_PATH_BAR (widget)->event_window);
Packit 98cdb6
Packit 98cdb6
  GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_unmap (GtkWidget *widget)
Packit 98cdb6
{
Packit 98cdb6
  gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
Packit 98cdb6
  gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
Packit 98cdb6
Packit 98cdb6
  GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_realize (GtkWidget *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  GdkWindowAttr attributes;
Packit 98cdb6
  gint attributes_mask;
Packit 98cdb6
Packit 98cdb6
  gtk_widget_set_realized (widget, TRUE);
Packit 98cdb6
Packit 98cdb6
  path_bar = GTK_PATH_BAR (widget);
Packit 98cdb6
  widget->window = gtk_widget_get_parent_window (widget);
Packit 98cdb6
  g_object_ref (widget->window);
Packit 98cdb6
Packit 98cdb6
  attributes.window_type = GDK_WINDOW_CHILD;
Packit 98cdb6
  attributes.x = widget->allocation.x;
Packit 98cdb6
  attributes.y = widget->allocation.y;
Packit 98cdb6
  attributes.width = widget->allocation.width;
Packit 98cdb6
  attributes.height = widget->allocation.height;
Packit 98cdb6
  attributes.wclass = GDK_INPUT_ONLY;
Packit 98cdb6
  attributes.event_mask = gtk_widget_get_events (widget);
Packit 98cdb6
  attributes.event_mask |= GDK_SCROLL_MASK;
Packit 98cdb6
  attributes_mask = GDK_WA_X | GDK_WA_Y;
Packit 98cdb6
Packit 98cdb6
  path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
Packit 98cdb6
							&attributes, attributes_mask);
Packit 98cdb6
  gdk_window_set_user_data (path_bar->event_window, widget);
Packit 98cdb6
Packit 98cdb6
  widget->style = gtk_style_attach (widget->style, widget->window);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_unrealize (GtkWidget *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
Packit 98cdb6
  path_bar = GTK_PATH_BAR (widget);
Packit 98cdb6
Packit 98cdb6
  gdk_window_set_user_data (path_bar->event_window, NULL);
Packit 98cdb6
  gdk_window_destroy (path_bar->event_window);
Packit 98cdb6
  path_bar->event_window = NULL;
Packit 98cdb6
Packit 98cdb6
  GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/* This is a tad complicated
Packit 98cdb6
 */
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_size_allocate (GtkWidget     *widget,
Packit 98cdb6
			    GtkAllocation *allocation)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *child;
Packit 98cdb6
  GtkPathBar *path_bar = GTK_PATH_BAR (widget);
Packit 98cdb6
  GtkTextDirection direction;
Packit 98cdb6
  GtkAllocation child_allocation;
Packit 98cdb6
  GList *list, *first_button;
Packit 98cdb6
  gint width;
Packit 98cdb6
  gint allocation_width;
Packit 98cdb6
  gint border_width;
Packit 98cdb6
  gboolean need_sliders = FALSE;
Packit 98cdb6
  gint up_slider_offset = 0;
Packit 98cdb6
Packit 98cdb6
  widget->allocation = *allocation;
Packit 98cdb6
Packit 98cdb6
  if (gtk_widget_get_realized (widget))
Packit 98cdb6
    gdk_window_move_resize (path_bar->event_window,
Packit 98cdb6
			    allocation->x, allocation->y,
Packit 98cdb6
			    allocation->width, allocation->height);
Packit 98cdb6
Packit 98cdb6
  /* No path is set; we don't have to allocate anything. */
Packit 98cdb6
  if (path_bar->button_list == NULL)
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  direction = gtk_widget_get_direction (widget);
Packit 98cdb6
  border_width = (gint) GTK_CONTAINER (path_bar)->border_width;
Packit 98cdb6
  allocation_width = allocation->width - 2 * border_width;
Packit 98cdb6
Packit 98cdb6
  /* First, we check to see if we need the scrollbars. */
Packit 98cdb6
  if (path_bar->fake_root)
Packit 98cdb6
    width = path_bar->spacing + path_bar->slider_width;
Packit 98cdb6
  else
Packit 98cdb6
      width = 0;
Packit 98cdb6
Packit 98cdb6
  for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      child = BUTTON_DATA (list->data)->button;
Packit 98cdb6
Packit 98cdb6
      width += child->requisition.width + path_bar->spacing;
Packit 98cdb6
      if (list == path_bar->fake_root)
Packit 98cdb6
	break;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (width <= allocation_width)
Packit 98cdb6
    {
Packit 98cdb6
      if (path_bar->fake_root)
Packit 98cdb6
	first_button = path_bar->fake_root;
Packit 98cdb6
      else
Packit 98cdb6
	first_button = g_list_last (path_bar->button_list);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      gboolean reached_end = FALSE;
Packit 98cdb6
      gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
Packit 98cdb6
Packit 98cdb6
      if (path_bar->first_scrolled_button)
Packit 98cdb6
	first_button = path_bar->first_scrolled_button;
Packit 98cdb6
      else
Packit 98cdb6
	first_button = path_bar->button_list;
Packit 98cdb6
      need_sliders = TRUE;
Packit 98cdb6
      
Packit 98cdb6
      /* To see how much space we have, and how many buttons we can display.
Packit 98cdb6
       * We start at the first button, count forward until hit the new
Packit 98cdb6
       * button, then count backwards.
Packit 98cdb6
       */
Packit 98cdb6
      /* Count down the path chain towards the end. */
Packit 98cdb6
      width = BUTTON_DATA (first_button->data)->button->requisition.width;
Packit 98cdb6
      list = first_button->prev;
Packit 98cdb6
      while (list && !reached_end)
Packit 98cdb6
	{
Packit 98cdb6
	  child = BUTTON_DATA (list->data)->button;
Packit 98cdb6
Packit 98cdb6
	  if (width + child->requisition.width +
Packit 98cdb6
	      path_bar->spacing + slider_space > allocation_width)
Packit 98cdb6
	    reached_end = TRUE;
Packit 98cdb6
	  else if (list == path_bar->fake_root)
Packit 98cdb6
	    break;
Packit 98cdb6
	  else
Packit 98cdb6
	    width += child->requisition.width + path_bar->spacing;
Packit 98cdb6
Packit 98cdb6
	  list = list->prev;
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      /* Finally, we walk up, seeing how many of the previous buttons we can
Packit 98cdb6
       * add */
Packit 98cdb6
      while (first_button->next && !reached_end)
Packit 98cdb6
	{
Packit 98cdb6
	  child = BUTTON_DATA (first_button->next->data)->button;
Packit 98cdb6
Packit 98cdb6
	  if (width + child->requisition.width + path_bar->spacing + slider_space > allocation_width)
Packit 98cdb6
	    {
Packit 98cdb6
	      reached_end = TRUE;
Packit 98cdb6
	    }
Packit 98cdb6
	  else
Packit 98cdb6
	    {
Packit 98cdb6
	      width += child->requisition.width + path_bar->spacing;
Packit 98cdb6
	      if (first_button == path_bar->fake_root)
Packit 98cdb6
		break;
Packit 98cdb6
	      first_button = first_button->next;
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  /* Now, we allocate space to the buttons */
Packit 98cdb6
  child_allocation.y = allocation->y + border_width;
Packit 98cdb6
  child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
Packit 98cdb6
Packit 98cdb6
  if (direction == GTK_TEXT_DIR_RTL)
Packit 98cdb6
    {
Packit 98cdb6
      child_allocation.x = allocation->x + allocation->width - border_width;
Packit 98cdb6
      if (need_sliders || path_bar->fake_root)
Packit 98cdb6
	{
Packit 98cdb6
	  child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
Packit 98cdb6
	  up_slider_offset = allocation->width - border_width - path_bar->slider_width;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      child_allocation.x = allocation->x + border_width;
Packit 98cdb6
      if (need_sliders || path_bar->fake_root)
Packit 98cdb6
	{
Packit 98cdb6
	  up_slider_offset = border_width;
Packit 98cdb6
	  child_allocation.x += (path_bar->spacing + path_bar->slider_width);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  for (list = first_button; list; list = list->prev)
Packit 98cdb6
    {
Packit 98cdb6
      ButtonData *button_data;
Packit 98cdb6
Packit 98cdb6
      button_data = BUTTON_DATA (list->data);
Packit 98cdb6
      child = button_data->button;
Packit 98cdb6
Packit 98cdb6
      child_allocation.width = MIN (child->requisition.width,
Packit 98cdb6
				    allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
Packit 98cdb6
Packit 98cdb6
      if (direction == GTK_TEXT_DIR_RTL)
Packit 98cdb6
	child_allocation.x -= child_allocation.width;
Packit 98cdb6
Packit 98cdb6
      /* Check to see if we've don't have any more space to allocate buttons */
Packit 98cdb6
      if (need_sliders && direction == GTK_TEXT_DIR_RTL)
Packit 98cdb6
	{
Packit 98cdb6
	  if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width)
Packit 98cdb6
	    break;
Packit 98cdb6
	}
Packit 98cdb6
      else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
Packit 98cdb6
	{
Packit 98cdb6
	  if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
Packit 98cdb6
	      widget->allocation.x + border_width + allocation_width)
Packit 98cdb6
	    break;
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      if (child_allocation.width < child->requisition.width)
Packit 98cdb6
	{
Packit 98cdb6
	  if (!gtk_widget_get_has_tooltip (child))
Packit 98cdb6
	    gtk_widget_set_tooltip_text (child, button_data->dir_name);
Packit 98cdb6
	}
Packit 98cdb6
      else if (gtk_widget_get_has_tooltip (child))
Packit 98cdb6
	gtk_widget_set_tooltip_text (child, NULL);
Packit 98cdb6
      
Packit 98cdb6
      gtk_widget_set_child_visible (child, TRUE);
Packit 98cdb6
      gtk_widget_size_allocate (child, &child_allocation);
Packit 98cdb6
Packit 98cdb6
      if (direction == GTK_TEXT_DIR_RTL)
Packit 98cdb6
	child_allocation.x -= path_bar->spacing;
Packit 98cdb6
      else
Packit 98cdb6
	child_allocation.x += child_allocation.width + path_bar->spacing;
Packit 98cdb6
    }
Packit 98cdb6
  /* Now we go hide all the widgets that don't fit */
Packit 98cdb6
  while (list)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
Packit 98cdb6
      list = list->prev;
Packit 98cdb6
    }
Packit 98cdb6
  for (list = first_button->next; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (need_sliders || path_bar->fake_root)
Packit 98cdb6
    {
Packit 98cdb6
      child_allocation.width = path_bar->slider_width;
Packit 98cdb6
      child_allocation.x = up_slider_offset + allocation->x;
Packit 98cdb6
      gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
Packit 98cdb6
Packit 98cdb6
      gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
Packit 98cdb6
      gtk_widget_show_all (path_bar->up_slider_button);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
Packit 98cdb6
      
Packit 98cdb6
  if (need_sliders)
Packit 98cdb6
    {
Packit 98cdb6
      child_allocation.width = path_bar->slider_width;
Packit 98cdb6
Packit 98cdb6
      if (direction == GTK_TEXT_DIR_RTL)
Packit 98cdb6
	child_allocation.x = border_width;
Packit 98cdb6
      else
Packit 98cdb6
	child_allocation.x = allocation->width - border_width - path_bar->slider_width;
Packit 98cdb6
Packit 98cdb6
      child_allocation.x += allocation->x;
Packit 98cdb6
      
Packit 98cdb6
      gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
Packit 98cdb6
Packit 98cdb6
      gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
Packit 98cdb6
      gtk_widget_show_all (path_bar->down_slider_button);
Packit 98cdb6
      gtk_path_bar_update_slider_buttons (path_bar);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_style_set (GtkWidget *widget,
Packit 98cdb6
			GtkStyle  *previous_style)
Packit 98cdb6
{
Packit 98cdb6
  GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
Packit 98cdb6
Packit 98cdb6
  gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_screen_changed (GtkWidget *widget,
Packit 98cdb6
			     GdkScreen *previous_screen)
Packit 98cdb6
{
Packit 98cdb6
  if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
Packit 98cdb6
    GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
Packit 98cdb6
Packit 98cdb6
  /* We might nave a new settings, so we remove the old one */
Packit 98cdb6
  if (previous_screen)
Packit 98cdb6
    remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
Packit 98cdb6
Packit 98cdb6
  gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_scroll (GtkWidget      *widget,
Packit 98cdb6
		     GdkEventScroll *event)
Packit 98cdb6
{
Packit 98cdb6
  switch (event->direction)
Packit 98cdb6
    {
Packit 98cdb6
    case GDK_SCROLL_RIGHT:
Packit 98cdb6
    case GDK_SCROLL_DOWN:
Packit 98cdb6
      gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
Packit 98cdb6
      break;
Packit 98cdb6
    case GDK_SCROLL_LEFT:
Packit 98cdb6
    case GDK_SCROLL_UP:
Packit 98cdb6
      gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_add (GtkContainer *container,
Packit 98cdb6
		  GtkWidget    *widget)
Packit 98cdb6
{
Packit 98cdb6
  gtk_widget_set_parent (widget, GTK_WIDGET (container));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_remove_1 (GtkContainer *container,
Packit 98cdb6
		       GtkWidget    *widget)
Packit 98cdb6
{
Packit 98cdb6
  gboolean was_visible = gtk_widget_get_visible (widget);
Packit 98cdb6
  gtk_widget_unparent (widget);
Packit 98cdb6
  if (was_visible)
Packit 98cdb6
    gtk_widget_queue_resize (GTK_WIDGET (container));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_remove (GtkContainer *container,
Packit 98cdb6
		     GtkWidget    *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  GList *children;
Packit 98cdb6
Packit 98cdb6
  path_bar = GTK_PATH_BAR (container);
Packit 98cdb6
Packit 98cdb6
  if (widget == path_bar->up_slider_button)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_path_bar_remove_1 (container, widget);
Packit 98cdb6
      path_bar->up_slider_button = NULL;
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (widget == path_bar->down_slider_button)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_path_bar_remove_1 (container, widget);
Packit 98cdb6
      path_bar->down_slider_button = NULL;
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  children = path_bar->button_list;
Packit 98cdb6
  while (children)
Packit 98cdb6
    {
Packit 98cdb6
      if (widget == BUTTON_DATA (children->data)->button)
Packit 98cdb6
	{
Packit 98cdb6
	  gtk_path_bar_remove_1 (container, widget);
Packit 98cdb6
	  path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
Packit 98cdb6
	  g_list_free (children);
Packit 98cdb6
	  return;
Packit 98cdb6
	}
Packit 98cdb6
      
Packit 98cdb6
      children = children->next;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_forall (GtkContainer *container,
Packit 98cdb6
		     gboolean      include_internals,
Packit 98cdb6
		     GtkCallback   callback,
Packit 98cdb6
		     gpointer      callback_data)
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  GList *children;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (callback != NULL);
Packit 98cdb6
  path_bar = GTK_PATH_BAR (container);
Packit 98cdb6
Packit 98cdb6
  children = path_bar->button_list;
Packit 98cdb6
  while (children)
Packit 98cdb6
    {
Packit 98cdb6
      GtkWidget *child;
Packit 98cdb6
      child = BUTTON_DATA (children->data)->button;
Packit 98cdb6
      children = children->next;
Packit 98cdb6
Packit 98cdb6
      (* callback) (child, callback_data);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (path_bar->up_slider_button)
Packit 98cdb6
    (* callback) (path_bar->up_slider_button, callback_data);
Packit 98cdb6
Packit 98cdb6
  if (path_bar->down_slider_button)
Packit 98cdb6
    (* callback) (path_bar->down_slider_button, callback_data);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_scroll_down (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
  GList *down_button = NULL;
Packit 98cdb6
  gint space_available;
Packit 98cdb6
Packit 98cdb6
  if (path_bar->ignore_click)
Packit 98cdb6
    {
Packit 98cdb6
      path_bar->ignore_click = FALSE;
Packit 98cdb6
      return;   
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
Packit 98cdb6
    {
Packit 98cdb6
      /* Return if the last button is already visible */
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  gtk_widget_queue_resize (GTK_WIDGET (path_bar));
Packit 98cdb6
Packit 98cdb6
  /* We find the button at the 'down' end that we have to make
Packit 98cdb6
   * visible */
Packit 98cdb6
  for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
Packit 98cdb6
	{
Packit 98cdb6
	  down_button = list;
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  space_available = (GTK_WIDGET (path_bar)->allocation.width
Packit 98cdb6
		     - 2 * GTK_CONTAINER (path_bar)->border_width
Packit 98cdb6
		     - 2 * path_bar->spacing - 2 * path_bar->slider_width
Packit 98cdb6
		     - BUTTON_DATA (down_button->data)->button->allocation.width);
Packit 98cdb6
  path_bar->first_scrolled_button = down_button;
Packit 98cdb6
  
Packit 98cdb6
  /* We have space_available free space that's not being used.  
Packit 98cdb6
   * So we walk down from the end, adding buttons until we use all free space.
Packit 98cdb6
   */
Packit 98cdb6
  while (space_available > 0)
Packit 98cdb6
    {
Packit 98cdb6
      path_bar->first_scrolled_button = down_button;
Packit 98cdb6
      down_button = down_button->next;
Packit 98cdb6
      if (!down_button)
Packit 98cdb6
	break;
Packit 98cdb6
      space_available -= (BUTTON_DATA (down_button->data)->button->allocation.width
Packit 98cdb6
			  + path_bar->spacing);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_scroll_up (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
Packit 98cdb6
  if (path_bar->ignore_click)
Packit 98cdb6
    {
Packit 98cdb6
      path_bar->ignore_click = FALSE;
Packit 98cdb6
      return;   
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  list = g_list_last (path_bar->button_list);
Packit 98cdb6
Packit 98cdb6
  if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
Packit 98cdb6
    {
Packit 98cdb6
      /* Return if the first button is already visible */
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  gtk_widget_queue_resize (GTK_WIDGET (path_bar));
Packit 98cdb6
Packit 98cdb6
  for ( ; list; list = list->prev)
Packit 98cdb6
    {
Packit 98cdb6
      if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
Packit 98cdb6
	{
Packit 98cdb6
	  if (list->prev == path_bar->fake_root)
Packit 98cdb6
	    path_bar->fake_root = NULL;
Packit 98cdb6
	  path_bar->first_scrolled_button = list;
Packit 98cdb6
	  return;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  gboolean retval = FALSE;
Packit 98cdb6
Packit 98cdb6
  if (path_bar->timer)
Packit 98cdb6
    {
Packit 98cdb6
      if (path_bar->scrolling_up)
Packit 98cdb6
	gtk_path_bar_scroll_up (path_bar);
Packit 98cdb6
      else if (path_bar->scrolling_down)
Packit 98cdb6
	gtk_path_bar_scroll_down (path_bar);
Packit 98cdb6
Packit 98cdb6
      if (path_bar->need_timer) 
Packit 98cdb6
	{
Packit 98cdb6
          GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
Packit 98cdb6
          guint        timeout;
Packit 98cdb6
Packit 98cdb6
          g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
Packit 98cdb6
Packit 98cdb6
	  path_bar->need_timer = FALSE;
Packit 98cdb6
Packit 98cdb6
	  path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
Packit 98cdb6
					   (GSourceFunc)gtk_path_bar_scroll_timeout,
Packit 98cdb6
					   path_bar);
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	retval = TRUE;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  return retval;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void 
Packit 98cdb6
gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  if (path_bar->timer)
Packit 98cdb6
    {
Packit 98cdb6
      g_source_remove (path_bar->timer);
Packit 98cdb6
      path_bar->timer = 0;
Packit 98cdb6
      path_bar->need_timer = FALSE;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_slider_up_defocus (GtkWidget      *widget,
Packit 98cdb6
                                    GdkEventButton *event,
Packit 98cdb6
                                    GtkPathBar     *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
  GList *up_button = NULL;
Packit 98cdb6
Packit 98cdb6
  if (event->type != GDK_FOCUS_CHANGE)
Packit 98cdb6
    return FALSE;
Packit 98cdb6
Packit 98cdb6
  for (list = g_list_last (path_bar->button_list); list; list = list->prev)
Packit 98cdb6
    {
Packit 98cdb6
      if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
Packit 98cdb6
        {
Packit 98cdb6
          up_button = list;
Packit 98cdb6
          break;
Packit 98cdb6
        }
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  /* don't let the focus vanish */
Packit 98cdb6
  if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
Packit 98cdb6
      (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
Packit 98cdb6
    gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
Packit 98cdb6
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_slider_down_defocus (GtkWidget      *widget,
Packit 98cdb6
                                    GdkEventButton *event,
Packit 98cdb6
                                    GtkPathBar     *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
  GList *down_button = NULL;
Packit 98cdb6
Packit 98cdb6
  if (event->type != GDK_FOCUS_CHANGE)
Packit 98cdb6
    return FALSE;
Packit 98cdb6
Packit 98cdb6
  for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
Packit 98cdb6
        {
Packit 98cdb6
          down_button = list;
Packit 98cdb6
          break;
Packit 98cdb6
        }
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  /* don't let the focus vanish */
Packit 98cdb6
  if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
Packit 98cdb6
      (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
Packit 98cdb6
    gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
Packit 98cdb6
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_slider_button_press (GtkWidget      *widget, 
Packit 98cdb6
				  GdkEventButton *event,
Packit 98cdb6
				  GtkPathBar     *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  if (event->type != GDK_BUTTON_PRESS || event->button != 1)
Packit 98cdb6
    return FALSE;
Packit 98cdb6
Packit 98cdb6
  path_bar->ignore_click = FALSE;
Packit 98cdb6
Packit 98cdb6
  if (widget == path_bar->up_slider_button)
Packit 98cdb6
    {
Packit 98cdb6
      path_bar->scrolling_down = FALSE;
Packit 98cdb6
      path_bar->scrolling_up = TRUE;
Packit 98cdb6
      gtk_path_bar_scroll_up (path_bar);
Packit 98cdb6
    }
Packit 98cdb6
  else if (widget == path_bar->down_slider_button)
Packit 98cdb6
    {
Packit 98cdb6
      path_bar->scrolling_up = FALSE;
Packit 98cdb6
      path_bar->scrolling_down = TRUE;
Packit 98cdb6
      gtk_path_bar_scroll_down (path_bar);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (!path_bar->timer)
Packit 98cdb6
    {
Packit 98cdb6
      GtkSettings *settings = gtk_widget_get_settings (widget);
Packit 98cdb6
      guint        timeout;
Packit 98cdb6
Packit 98cdb6
      g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
Packit 98cdb6
Packit 98cdb6
      path_bar->need_timer = TRUE;
Packit 98cdb6
      path_bar->timer = gdk_threads_add_timeout (timeout,
Packit 98cdb6
				       (GSourceFunc)gtk_path_bar_scroll_timeout,
Packit 98cdb6
				       path_bar);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_slider_button_release (GtkWidget      *widget, 
Packit 98cdb6
				    GdkEventButton *event,
Packit 98cdb6
				    GtkPathBar     *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  if (event->type != GDK_BUTTON_RELEASE)
Packit 98cdb6
    return FALSE;
Packit 98cdb6
Packit 98cdb6
  path_bar->ignore_click = TRUE;
Packit 98cdb6
  gtk_path_bar_stop_scrolling (path_bar);
Packit 98cdb6
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_grab_notify (GtkWidget *widget,
Packit 98cdb6
			  gboolean   was_grabbed)
Packit 98cdb6
{
Packit 98cdb6
  if (!was_grabbed)
Packit 98cdb6
    gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_state_changed (GtkWidget    *widget,
Packit 98cdb6
			    GtkStateType  previous_state)
Packit 98cdb6
{
Packit 98cdb6
  if (!gtk_widget_is_sensitive (widget))
Packit 98cdb6
    gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
/* Changes the icons wherever it is needed */
Packit 98cdb6
static void
Packit 98cdb6
reload_icons (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
Packit 98cdb6
  if (path_bar->root_icon)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (path_bar->root_icon);
Packit 98cdb6
      path_bar->root_icon = NULL;
Packit 98cdb6
    }
Packit 98cdb6
  if (path_bar->home_icon)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (path_bar->home_icon);
Packit 98cdb6
      path_bar->home_icon = NULL;
Packit 98cdb6
    }
Packit 98cdb6
  if (path_bar->desktop_icon)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (path_bar->desktop_icon);
Packit 98cdb6
      path_bar->desktop_icon = NULL;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      ButtonData *button_data;
Packit 98cdb6
      gboolean current_dir;
Packit 98cdb6
Packit 98cdb6
      button_data = BUTTON_DATA (list->data);
Packit 98cdb6
      if (button_data->type != NORMAL_BUTTON)
Packit 98cdb6
	{
Packit 98cdb6
	  current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
Packit 98cdb6
	  gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
change_icon_theme (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GtkSettings *settings;
Packit 98cdb6
  gint width, height;
Packit 98cdb6
Packit 98cdb6
  settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
Packit 98cdb6
Packit 98cdb6
  if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
Packit 98cdb6
    path_bar->icon_size = MAX (width, height);
Packit 98cdb6
  else
Packit 98cdb6
    path_bar->icon_size = FALLBACK_ICON_SIZE;
Packit 98cdb6
Packit 98cdb6
  reload_icons (path_bar);
Packit 98cdb6
}
Packit 98cdb6
/* Callback used when a GtkSettings value changes */
Packit 98cdb6
static void
Packit 98cdb6
settings_notify_cb (GObject    *object,
Packit 98cdb6
		    GParamSpec *pspec,
Packit 98cdb6
		    GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  const char *name;
Packit 98cdb6
Packit 98cdb6
  name = g_param_spec_get_name (pspec);
Packit 98cdb6
Packit 98cdb6
  if (! strcmp (name, "gtk-icon-theme-name") ||
Packit 98cdb6
      ! strcmp (name, "gtk-icon-sizes"))
Packit 98cdb6
    change_icon_theme (path_bar);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GtkSettings *settings;
Packit 98cdb6
Packit 98cdb6
  if (path_bar->settings_signal_id)
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
Packit 98cdb6
  path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
Packit 98cdb6
Packit 98cdb6
  change_icon_theme (path_bar);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/* Public functions and their helpers */
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  while (path_bar->button_list != NULL)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
Packit 98cdb6
    }
Packit 98cdb6
  path_bar->first_scrolled_button = NULL;
Packit 98cdb6
  path_bar->fake_root = NULL;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
button_clicked_cb (GtkWidget *button,
Packit 98cdb6
		   gpointer   data)
Packit 98cdb6
{
Packit 98cdb6
  ButtonData *button_data;
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  GList *button_list;
Packit 98cdb6
  gboolean child_is_hidden;
Packit 98cdb6
  GFile *child_file;
Packit 98cdb6
Packit 98cdb6
  button_data = BUTTON_DATA (data);
Packit 98cdb6
  if (button_data->ignore_changes)
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  path_bar = GTK_PATH_BAR (button->parent);
Packit 98cdb6
Packit 98cdb6
  button_list = g_list_find (path_bar->button_list, button_data);
Packit 98cdb6
  g_assert (button_list != NULL);
Packit 98cdb6
Packit 98cdb6
  g_signal_handlers_block_by_func (button,
Packit 98cdb6
				   G_CALLBACK (button_clicked_cb), data);
Packit 98cdb6
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
Packit 98cdb6
  g_signal_handlers_unblock_by_func (button,
Packit 98cdb6
				     G_CALLBACK (button_clicked_cb), data);
Packit 98cdb6
Packit 98cdb6
  if (button_list->prev)
Packit 98cdb6
    {
Packit 98cdb6
      ButtonData *child_data;
Packit 98cdb6
Packit 98cdb6
      child_data = BUTTON_DATA (button_list->prev->data);
Packit 98cdb6
      child_file = child_data->file;
Packit 98cdb6
      child_is_hidden = child_data->file_is_hidden;
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      child_file = NULL;
Packit 98cdb6
      child_is_hidden = FALSE;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
Packit 98cdb6
		 button_data->file, child_file, child_is_hidden);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
struct SetButtonImageData
Packit 98cdb6
{
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  ButtonData *button_data;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
set_button_image_get_info_cb (GCancellable *cancellable,
Packit 98cdb6
			      GFileInfo    *info,
Packit 98cdb6
			      const GError *error,
Packit 98cdb6
			      gpointer      user_data)
Packit 98cdb6
{
Packit 98cdb6
  gboolean cancelled = g_cancellable_is_cancelled (cancellable);
Packit 98cdb6
  GdkPixbuf *pixbuf;
Packit 98cdb6
  struct SetButtonImageData *data = user_data;
Packit 98cdb6
Packit 98cdb6
  if (cancellable != data->button_data->cancellable)
Packit 98cdb6
    goto out;
Packit 98cdb6
Packit 98cdb6
  data->button_data->cancellable = NULL;
Packit 98cdb6
Packit 98cdb6
  if (!data->button_data->button)
Packit 98cdb6
    {
Packit 98cdb6
      g_free (data->button_data);
Packit 98cdb6
      goto out;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (cancelled || error)
Packit 98cdb6
    goto out;
Packit 98cdb6
Packit 98cdb6
  pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
Packit 98cdb6
			 	       data->path_bar->icon_size);
Packit 98cdb6
  gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
Packit 98cdb6
Packit 98cdb6
  switch (data->button_data->type)
Packit 98cdb6
    {
Packit 98cdb6
      case HOME_BUTTON:
Packit 98cdb6
	if (data->path_bar->home_icon)
Packit 98cdb6
	  g_object_unref (pixbuf);
Packit 98cdb6
	else
Packit 98cdb6
	  data->path_bar->home_icon = pixbuf;
Packit 98cdb6
	break;
Packit 98cdb6
Packit 98cdb6
      case DESKTOP_BUTTON:
Packit 98cdb6
	if (data->path_bar->desktop_icon)
Packit 98cdb6
	  g_object_unref (pixbuf);
Packit 98cdb6
	else
Packit 98cdb6
	  data->path_bar->desktop_icon = pixbuf;
Packit 98cdb6
	break;
Packit 98cdb6
Packit 98cdb6
      default:
Packit 98cdb6
	break;
Packit 98cdb6
    };
Packit 98cdb6
Packit 98cdb6
out:
Packit 98cdb6
  g_free (data);
Packit 98cdb6
  g_object_unref (cancellable);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
set_button_image (GtkPathBar *path_bar,
Packit 98cdb6
		  ButtonData *button_data)
Packit 98cdb6
{
Packit 98cdb6
  GtkFileSystemVolume *volume;
Packit 98cdb6
  struct SetButtonImageData *data;
Packit 98cdb6
Packit 98cdb6
  switch (button_data->type)
Packit 98cdb6
    {
Packit 98cdb6
    case ROOT_BUTTON:
Packit 98cdb6
Packit 98cdb6
      if (path_bar->root_icon != NULL)
Packit 98cdb6
        {
Packit 98cdb6
          gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
Packit 98cdb6
      if (volume == NULL)
Packit 98cdb6
	return;
Packit 98cdb6
Packit 98cdb6
      path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
Packit 98cdb6
								 GTK_WIDGET (path_bar),
Packit 98cdb6
								 path_bar->icon_size,
Packit 98cdb6
								 NULL);
Packit 98cdb6
      _gtk_file_system_volume_unref (volume);
Packit 98cdb6
Packit 98cdb6
      gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
Packit 98cdb6
      break;
Packit 98cdb6
Packit 98cdb6
    case HOME_BUTTON:
Packit 98cdb6
      if (path_bar->home_icon != NULL)
Packit 98cdb6
        {
Packit 98cdb6
	  gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      data = g_new0 (struct SetButtonImageData, 1);
Packit 98cdb6
      data->path_bar = path_bar;
Packit 98cdb6
      data->button_data = button_data;
Packit 98cdb6
Packit 98cdb6
      if (button_data->cancellable)
Packit 98cdb6
	g_cancellable_cancel (button_data->cancellable);
Packit 98cdb6
Packit 98cdb6
      button_data->cancellable =
Packit 98cdb6
        _gtk_file_system_get_info (path_bar->file_system,
Packit 98cdb6
				   path_bar->home_file,
Packit 98cdb6
				   "standard::icon",
Packit 98cdb6
				   set_button_image_get_info_cb,
Packit 98cdb6
				   data);
Packit 98cdb6
      break;
Packit 98cdb6
Packit 98cdb6
    case DESKTOP_BUTTON:
Packit 98cdb6
      if (path_bar->desktop_icon != NULL)
Packit 98cdb6
        {
Packit 98cdb6
	  gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      data = g_new0 (struct SetButtonImageData, 1);
Packit 98cdb6
      data->path_bar = path_bar;
Packit 98cdb6
      data->button_data = button_data;
Packit 98cdb6
Packit 98cdb6
      if (button_data->cancellable)
Packit 98cdb6
	g_cancellable_cancel (button_data->cancellable);
Packit 98cdb6
Packit 98cdb6
      button_data->cancellable =
Packit 98cdb6
        _gtk_file_system_get_info (path_bar->file_system,
Packit 98cdb6
				   path_bar->desktop_file,
Packit 98cdb6
				   "standard::icon",
Packit 98cdb6
				   set_button_image_get_info_cb,
Packit 98cdb6
				   data);
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
button_data_free (ButtonData *button_data)
Packit 98cdb6
{
Packit 98cdb6
  if (button_data->file)
Packit 98cdb6
    g_object_unref (button_data->file);
Packit 98cdb6
  button_data->file = NULL;
Packit 98cdb6
Packit 98cdb6
  g_free (button_data->dir_name);
Packit 98cdb6
  button_data->dir_name = NULL;
Packit 98cdb6
Packit 98cdb6
  button_data->button = NULL;
Packit 98cdb6
Packit 98cdb6
  if (button_data->cancellable)
Packit 98cdb6
    g_cancellable_cancel (button_data->cancellable);
Packit 98cdb6
  else
Packit 98cdb6
    g_free (button_data);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static const char *
Packit 98cdb6
get_dir_name (ButtonData *button_data)
Packit 98cdb6
{
Packit 98cdb6
  return button_data->dir_name;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/* We always want to request the same size for the label, whether
Packit 98cdb6
 * or not the contents are bold
Packit 98cdb6
 */
Packit 98cdb6
static void
Packit 98cdb6
label_size_request_cb (GtkWidget      *widget,
Packit 98cdb6
		       GtkRequisition *requisition,
Packit 98cdb6
		       ButtonData     *button_data)
Packit 98cdb6
{
Packit 98cdb6
  const gchar *dir_name = get_dir_name (button_data);
Packit 98cdb6
  PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
Packit 98cdb6
  gint bold_width, bold_height;
Packit 98cdb6
  gchar *markup;
Packit 98cdb6
Packit 98cdb6
  pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
Packit 98cdb6
  
Packit 98cdb6
  markup = g_markup_printf_escaped ("%s", dir_name);
Packit 98cdb6
  pango_layout_set_markup (layout, markup, -1);
Packit 98cdb6
  g_free (markup);
Packit 98cdb6
Packit 98cdb6
  pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
Packit 98cdb6
  requisition->width = MAX (requisition->width, bold_width);
Packit 98cdb6
  requisition->height = MAX (requisition->height, bold_height);
Packit 98cdb6
  
Packit 98cdb6
  g_object_unref (layout);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
Packit 98cdb6
				       ButtonData *button_data,
Packit 98cdb6
				       gboolean    current_dir)
Packit 98cdb6
{
Packit 98cdb6
  const gchar *dir_name = get_dir_name (button_data);
Packit 98cdb6
Packit 98cdb6
  if (button_data->label != NULL)
Packit 98cdb6
    {
Packit 98cdb6
      if (current_dir)
Packit 98cdb6
	{
Packit 98cdb6
	  char *markup;
Packit 98cdb6
Packit 98cdb6
	  markup = g_markup_printf_escaped ("%s", dir_name);
Packit 98cdb6
	  gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
Packit 98cdb6
	  g_free (markup);
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	{
Packit 98cdb6
	  gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (button_data->image != NULL)
Packit 98cdb6
    {
Packit 98cdb6
      set_button_image (path_bar, button_data);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
Packit 98cdb6
    {
Packit 98cdb6
      button_data->ignore_changes = TRUE;
Packit 98cdb6
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
Packit 98cdb6
      button_data->ignore_changes = FALSE;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static ButtonType
Packit 98cdb6
find_button_type (GtkPathBar  *path_bar,
Packit 98cdb6
		  GFile       *file)
Packit 98cdb6
{
Packit 98cdb6
  if (path_bar->root_file != NULL &&
Packit 98cdb6
      g_file_equal (file, path_bar->root_file))
Packit 98cdb6
    return ROOT_BUTTON;
Packit 98cdb6
  if (path_bar->home_file != NULL &&
Packit 98cdb6
      g_file_equal (file, path_bar->home_file))
Packit 98cdb6
    return HOME_BUTTON;
Packit 98cdb6
  if (path_bar->desktop_file != NULL &&
Packit 98cdb6
      g_file_equal (file, path_bar->desktop_file))
Packit 98cdb6
    return DESKTOP_BUTTON;
Packit 98cdb6
Packit 98cdb6
 return NORMAL_BUTTON;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
button_drag_data_get_cb (GtkWidget          *widget,
Packit 98cdb6
			 GdkDragContext     *context,
Packit 98cdb6
			 GtkSelectionData   *selection_data,
Packit 98cdb6
			 guint               info,
Packit 98cdb6
			 guint               time_,
Packit 98cdb6
			 gpointer            data)
Packit 98cdb6
{
Packit 98cdb6
  ButtonData *button_data;
Packit 98cdb6
  char *uris[2];
Packit 98cdb6
Packit 98cdb6
  button_data = data;
Packit 98cdb6
Packit 98cdb6
  uris[0] = g_file_get_uri (button_data->file);
Packit 98cdb6
  uris[1] = NULL;
Packit 98cdb6
Packit 98cdb6
  gtk_selection_data_set_uris (selection_data, uris);
Packit 98cdb6
  g_free (uris[0]);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static ButtonData *
Packit 98cdb6
make_directory_button (GtkPathBar  *path_bar,
Packit 98cdb6
		       const char  *dir_name,
Packit 98cdb6
		       GFile       *file,
Packit 98cdb6
		       gboolean     current_dir,
Packit 98cdb6
		       gboolean     file_is_hidden)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *atk_obj;
Packit 98cdb6
  GtkWidget *child = NULL;
Packit 98cdb6
  GtkWidget *label_alignment = NULL;
Packit 98cdb6
  ButtonData *button_data;
Packit 98cdb6
Packit 98cdb6
  file_is_hidden = !! file_is_hidden;
Packit 98cdb6
  /* Is it a special button? */
Packit 98cdb6
  button_data = g_new0 (ButtonData, 1);
Packit 98cdb6
Packit 98cdb6
  button_data->type = find_button_type (path_bar, file);
Packit 98cdb6
  button_data->button = gtk_toggle_button_new ();
Packit 98cdb6
  atk_obj = gtk_widget_get_accessible (button_data->button);
Packit 98cdb6
  gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
Packit 98cdb6
Packit 98cdb6
  switch (button_data->type)
Packit 98cdb6
    {
Packit 98cdb6
    case ROOT_BUTTON:
Packit 98cdb6
      button_data->image = gtk_image_new ();
Packit 98cdb6
      child = button_data->image;
Packit 98cdb6
      button_data->label = NULL;
Packit 98cdb6
      atk_object_set_name (atk_obj, _("File System Root"));
Packit 98cdb6
      break;
Packit 98cdb6
    case HOME_BUTTON:
Packit 98cdb6
    case DESKTOP_BUTTON:
Packit 98cdb6
      button_data->image = gtk_image_new ();
Packit 98cdb6
      button_data->label = gtk_label_new (NULL);
Packit 98cdb6
      label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
Packit 98cdb6
      gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
Packit 98cdb6
      child = gtk_hbox_new (FALSE, 2);
Packit 98cdb6
      gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
Packit 98cdb6
      gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
Packit 98cdb6
      break;
Packit 98cdb6
    case NORMAL_BUTTON:
Packit 98cdb6
    default:
Packit 98cdb6
      button_data->label = gtk_label_new (NULL);
Packit 98cdb6
      gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
Packit 98cdb6
      label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
Packit 98cdb6
      gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
Packit 98cdb6
      child = label_alignment;
Packit 98cdb6
      button_data->image = NULL;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  /* label_alignment is created because we can't override size-request
Packit 98cdb6
   * on label itself and still have the contents of the label centered
Packit 98cdb6
   * properly in the label's requisition
Packit 98cdb6
   */
Packit 98cdb6
  if (label_alignment)
Packit 98cdb6
    g_signal_connect (label_alignment, "size-request",
Packit 98cdb6
		      G_CALLBACK (label_size_request_cb), button_data);
Packit 98cdb6
Packit 98cdb6
  button_data->dir_name = g_strdup (dir_name);
Packit 98cdb6
  button_data->file = g_object_ref (file);
Packit 98cdb6
  button_data->file_is_hidden = file_is_hidden;
Packit 98cdb6
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (button_data->button), child);
Packit 98cdb6
  gtk_widget_show_all (button_data->button);
Packit 98cdb6
Packit 98cdb6
  gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
Packit 98cdb6
Packit 98cdb6
  g_signal_connect (button_data->button, "clicked",
Packit 98cdb6
		    G_CALLBACK (button_clicked_cb),
Packit 98cdb6
		    button_data);
Packit 98cdb6
  g_object_weak_ref (G_OBJECT (button_data->button),
Packit 98cdb6
		     (GWeakNotify) button_data_free, button_data);
Packit 98cdb6
Packit 98cdb6
  gtk_drag_source_set (button_data->button,
Packit 98cdb6
		       GDK_BUTTON1_MASK,
Packit 98cdb6
		       NULL, 0,
Packit 98cdb6
		       GDK_ACTION_COPY);
Packit 98cdb6
  gtk_drag_source_add_uri_targets (button_data->button);
Packit 98cdb6
  g_signal_connect (button_data->button, "drag-data-get",
Packit 98cdb6
		    G_CALLBACK (button_drag_data_get_cb), button_data);
Packit 98cdb6
Packit 98cdb6
  return button_data;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_path_bar_check_parent_path (GtkPathBar         *path_bar,
Packit 98cdb6
				GFile              *file,
Packit 98cdb6
				GtkFileSystem      *file_system)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
  GList *current_path = NULL;
Packit 98cdb6
  gboolean need_new_fake_root = FALSE;
Packit 98cdb6
Packit 98cdb6
  for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
    {
Packit 98cdb6
      ButtonData *button_data;
Packit 98cdb6
Packit 98cdb6
      button_data = list->data;
Packit 98cdb6
      if (g_file_equal (file, button_data->file))
Packit 98cdb6
	{
Packit 98cdb6
	  current_path = list;
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
      if (list == path_bar->fake_root)
Packit 98cdb6
	need_new_fake_root = TRUE;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (current_path)
Packit 98cdb6
    {
Packit 98cdb6
      if (need_new_fake_root)
Packit 98cdb6
	{
Packit 98cdb6
	  path_bar->fake_root = NULL;
Packit 98cdb6
	  for (list = current_path; list; list = list->next)
Packit 98cdb6
	    {
Packit 98cdb6
	      ButtonData *button_data;
Packit 98cdb6
Packit 98cdb6
	      button_data = list->data;
Packit 98cdb6
	      if (BUTTON_IS_FAKE_ROOT (button_data))
Packit 98cdb6
		{
Packit 98cdb6
		  path_bar->fake_root = list;
Packit 98cdb6
		  break;
Packit 98cdb6
		}
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      for (list = path_bar->button_list; list; list = list->next)
Packit 98cdb6
	{
Packit 98cdb6
	  gtk_path_bar_update_button_appearance (path_bar,
Packit 98cdb6
						 BUTTON_DATA (list->data),
Packit 98cdb6
						 (list == current_path) ? TRUE : FALSE);
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
Packit 98cdb6
	{
Packit 98cdb6
	  path_bar->first_scrolled_button = current_path;
Packit 98cdb6
	  gtk_widget_queue_resize (GTK_WIDGET (path_bar));
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      return TRUE;
Packit 98cdb6
    }
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
struct SetFileInfo
Packit 98cdb6
{
Packit 98cdb6
  GFile *file;
Packit 98cdb6
  GFile *parent_file;
Packit 98cdb6
  GtkPathBar *path_bar;
Packit 98cdb6
  GList *new_buttons;
Packit 98cdb6
  GList *fake_root;
Packit 98cdb6
  gboolean first_directory;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_set_file_finish (struct SetFileInfo *info,
Packit 98cdb6
                              gboolean            result)
Packit 98cdb6
{
Packit 98cdb6
  if (result)
Packit 98cdb6
    {
Packit 98cdb6
      GList *l;
Packit 98cdb6
Packit 98cdb6
      gtk_path_bar_clear_buttons (info->path_bar);
Packit 98cdb6
      info->path_bar->button_list = g_list_reverse (info->new_buttons);
Packit 98cdb6
      info->path_bar->fake_root = info->fake_root;
Packit 98cdb6
Packit 98cdb6
      for (l = info->path_bar->button_list; l; l = l->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GtkWidget *button = BUTTON_DATA (l->data)->button;
Packit 98cdb6
	  gtk_container_add (GTK_CONTAINER (info->path_bar), button);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      GList *l;
Packit 98cdb6
Packit 98cdb6
      for (l = info->new_buttons; l; l = l->next)
Packit 98cdb6
	{
Packit 98cdb6
	  ButtonData *button_data;
Packit 98cdb6
Packit 98cdb6
	  button_data = BUTTON_DATA (l->data);
Packit 98cdb6
	  gtk_widget_destroy (button_data->button);
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      g_list_free (info->new_buttons);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (info->file)
Packit 98cdb6
    g_object_unref (info->file);
Packit 98cdb6
  if (info->parent_file)
Packit 98cdb6
    g_object_unref (info->parent_file);
Packit 98cdb6
  g_free (info);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_path_bar_get_info_callback (GCancellable *cancellable,
Packit 98cdb6
			        GFileInfo    *info,
Packit 98cdb6
			        const GError *error,
Packit 98cdb6
			        gpointer      data)
Packit 98cdb6
{
Packit 98cdb6
  gboolean cancelled = g_cancellable_is_cancelled (cancellable);
Packit 98cdb6
  struct SetFileInfo *file_info = data;
Packit 98cdb6
  ButtonData *button_data;
Packit 98cdb6
  const gchar *display_name;
Packit 98cdb6
  gboolean is_hidden;
Packit 98cdb6
Packit 98cdb6
  if (cancellable != file_info->path_bar->get_info_cancellable)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_path_bar_set_file_finish (file_info, FALSE);
Packit 98cdb6
      g_object_unref (cancellable);
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_object_unref (cancellable);
Packit 98cdb6
  file_info->path_bar->get_info_cancellable = NULL;
Packit 98cdb6
Packit 98cdb6
  if (cancelled || !info)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_path_bar_set_file_finish (file_info, FALSE);
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  display_name = g_file_info_get_display_name (info);
Packit 98cdb6
  is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_push_composite_child ();
Packit 98cdb6
  button_data = make_directory_button (file_info->path_bar, display_name,
Packit 98cdb6
                                       file_info->file,
Packit 98cdb6
				       file_info->first_directory, is_hidden);
Packit 98cdb6
  gtk_widget_pop_composite_child ();
Packit 98cdb6
  g_object_unref (file_info->file);
Packit 98cdb6
Packit 98cdb6
  file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
Packit 98cdb6
Packit 98cdb6
  if (BUTTON_IS_FAKE_ROOT (button_data))
Packit 98cdb6
    file_info->fake_root = file_info->new_buttons;
Packit 98cdb6
Packit 98cdb6
  file_info->file = file_info->parent_file;
Packit 98cdb6
  file_info->first_directory = FALSE;
Packit 98cdb6
Packit 98cdb6
  if (!file_info->file)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_path_bar_set_file_finish (file_info, TRUE);
Packit 98cdb6
      return;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  file_info->parent_file = g_file_get_parent (file_info->file);
Packit 98cdb6
Packit 98cdb6
  file_info->path_bar->get_info_cancellable =
Packit 98cdb6
    _gtk_file_system_get_info (file_info->path_bar->file_system,
Packit 98cdb6
			       file_info->file,
Packit 98cdb6
			       "standard::display-name,standard::is-hidden,standard::is-backup",
Packit 98cdb6
			       gtk_path_bar_get_info_callback,
Packit 98cdb6
			       file_info);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
gboolean
Packit 98cdb6
_gtk_path_bar_set_file (GtkPathBar         *path_bar,
Packit 98cdb6
			GFile              *file,
Packit 98cdb6
			const gboolean      keep_trail,
Packit 98cdb6
			GError            **error)
Packit 98cdb6
{
Packit 98cdb6
  struct SetFileInfo *info;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
Packit 98cdb6
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
Packit 98cdb6
Packit 98cdb6
  /* Check whether the new path is already present in the pathbar as buttons.
Packit 98cdb6
   * This could be a parent directory or a previous selected subdirectory.
Packit 98cdb6
   */
Packit 98cdb6
  if (keep_trail &&
Packit 98cdb6
      gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
Packit 98cdb6
    return TRUE;
Packit 98cdb6
Packit 98cdb6
  info = g_new0 (struct SetFileInfo, 1);
Packit 98cdb6
  info->file = g_object_ref (file);
Packit 98cdb6
  info->path_bar = path_bar;
Packit 98cdb6
  info->first_directory = TRUE;
Packit 98cdb6
  info->parent_file = g_file_get_parent (info->file);
Packit 98cdb6
Packit 98cdb6
  if (path_bar->get_info_cancellable)
Packit 98cdb6
    g_cancellable_cancel (path_bar->get_info_cancellable);
Packit 98cdb6
Packit 98cdb6
  path_bar->get_info_cancellable =
Packit 98cdb6
    _gtk_file_system_get_info (path_bar->file_system,
Packit 98cdb6
			       info->file,
Packit 98cdb6
			       "standard::display-name,standard::is-hidden,standard::is-backup",
Packit 98cdb6
			       gtk_path_bar_get_info_callback,
Packit 98cdb6
			       info);
Packit 98cdb6
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/* FIXME: This should be a construct-only property */
Packit 98cdb6
void
Packit 98cdb6
_gtk_path_bar_set_file_system (GtkPathBar    *path_bar,
Packit 98cdb6
			       GtkFileSystem *file_system)
Packit 98cdb6
{
Packit 98cdb6
  const char *home;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
Packit 98cdb6
Packit 98cdb6
  g_assert (path_bar->file_system == NULL);
Packit 98cdb6
Packit 98cdb6
  path_bar->file_system = g_object_ref (file_system);
Packit 98cdb6
Packit 98cdb6
  home = g_get_home_dir ();
Packit 98cdb6
  if (home != NULL)
Packit 98cdb6
    {
Packit 98cdb6
      const gchar *desktop;
Packit 98cdb6
Packit 98cdb6
      path_bar->home_file = g_file_new_for_path (home);
Packit 98cdb6
      /* FIXME: Need file system backend specific way of getting the
Packit 98cdb6
       * Desktop path.
Packit 98cdb6
       */
Packit 98cdb6
      desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
Packit 98cdb6
      if (desktop != NULL)
Packit 98cdb6
        path_bar->desktop_file = g_file_new_for_path (desktop);
Packit 98cdb6
      else 
Packit 98cdb6
        path_bar->desktop_file = NULL;
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      path_bar->home_file = NULL;
Packit 98cdb6
      path_bar->desktop_file = NULL;
Packit 98cdb6
    }
Packit 98cdb6
  path_bar->root_file = g_file_new_for_path ("/");
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * _gtk_path_bar_up:
Packit 98cdb6
 * @path_bar: a #GtkPathBar
Packit 98cdb6
 * 
Packit 98cdb6
 * If the selected button in the pathbar is not the furthest button "up" (in the
Packit 98cdb6
 * root direction), act as if the user clicked on the next button up.
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
_gtk_path_bar_up (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *l;
Packit 98cdb6
Packit 98cdb6
  for (l = path_bar->button_list; l; l = l->next)
Packit 98cdb6
    {
Packit 98cdb6
      GtkWidget *button = BUTTON_DATA (l->data)->button;
Packit 98cdb6
      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
Packit 98cdb6
	{
Packit 98cdb6
	  if (l->next)
Packit 98cdb6
	    {
Packit 98cdb6
	      GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
Packit 98cdb6
	      button_clicked_cb (next_button, l->next->data);
Packit 98cdb6
	    }
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * _gtk_path_bar_down:
Packit 98cdb6
 * @path_bar: a #GtkPathBar
Packit 98cdb6
 * 
Packit 98cdb6
 * If the selected button in the pathbar is not the furthest button "down" (in the
Packit 98cdb6
 * leaf direction), act as if the user clicked on the next button down.
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
_gtk_path_bar_down (GtkPathBar *path_bar)
Packit 98cdb6
{
Packit 98cdb6
  GList *l;
Packit 98cdb6
Packit 98cdb6
  for (l = path_bar->button_list; l; l = l->next)
Packit 98cdb6
    {
Packit 98cdb6
      GtkWidget *button = BUTTON_DATA (l->data)->button;
Packit 98cdb6
      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
Packit 98cdb6
	{
Packit 98cdb6
	  if (l->prev)
Packit 98cdb6
	    {
Packit 98cdb6
	      GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
Packit 98cdb6
	      button_clicked_cb (prev_button, l->prev->data);
Packit 98cdb6
	    }
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_PATH_BAR_C__
Packit 98cdb6
#include "gtkaliasdef.c"