From 42f53ab58e3f905b242029c2ea446d79d2113725 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Sat, 30 Mar 2013 16:35:39 +0900 Subject: [PATCH] GtkPathBar: Define children with a GtkBuilder template --- gtk/Makefile.am | 1 + gtk/gtk.gresource.xml | 1 + gtk/gtkpathbar.c | 577 ++++++++++++++++++++++-------------------- gtk/gtkpathbar.h | 35 +-- gtk/gtkpathbar.ui | 47 ++++ gtk/tests/templates.c | 1 + 6 files changed, 351 insertions(+), 311 deletions(-) create mode 100644 gtk/gtkpathbar.ui diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 6a9a36384c..dd34bb9be2 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1111,6 +1111,7 @@ COMPOSITE_TEMPLATES = \ gtklockbutton.ui \ gtkmessagedialog.ui \ gtkpagesetupunixdialog.ui \ + gtkpathbar.ui \ gtkprintunixdialog.ui \ gtkrecentchooserdefault.ui \ gtkscalebutton.ui \ diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml index 55aafdc9ea..0e40d07b0a 100644 --- a/gtk/gtk.gresource.xml +++ b/gtk/gtk.gresource.xml @@ -26,6 +26,7 @@ gtklockbutton.ui gtkmessagedialog.ui gtkpagesetupunixdialog.ui + gtkpathbar.ui gtkprintunixdialog.ui gtkrecentchooserdefault.ui gtkscalebutton.ui diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index b68be639af..242a55d4cf 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -37,6 +37,38 @@ #include "gtkwidgetpath.h" #include "gtkwidgetprivate.h" +struct _GtkPathBarPrivate +{ + GtkFileSystem *file_system; + GFile *root_file; + GFile *home_file; + GFile *desktop_file; + + GCancellable *get_info_cancellable; + + GdkPixbuf *root_icon; + GdkPixbuf *home_icon; + GdkPixbuf *desktop_icon; + + GdkWindow *event_window; + + GList *button_list; + GList *first_scrolled_button; + GList *fake_root; + GtkWidget *up_slider_button; + GtkWidget *down_slider_button; + guint settings_signal_id; + gint icon_size; + gint16 slider_width; + gint16 spacing; + gint16 button_offset; + guint timer; + guint slider_visible : 1; + guint need_timer : 1; + guint ignore_click : 1; + guint scrolling_up : 1; + guint scrolling_down : 1; +}; enum { PATH_CLICKED, @@ -138,75 +170,42 @@ static void on_slider_unmap (GtkWidget *widget, GtkPathBar *path_bar) { - if (path_bar->timer && - ((widget == path_bar->up_slider_button && path_bar->scrolling_up) || - (widget == path_bar->down_slider_button && path_bar->scrolling_down))) + if (path_bar->priv->timer && + ((widget == path_bar->priv->up_slider_button && path_bar->priv->scrolling_up) || + (widget == path_bar->priv->down_slider_button && path_bar->priv->scrolling_down))) gtk_path_bar_stop_scrolling (path_bar); } -static GtkWidget * -get_slider_button (GtkPathBar *path_bar, - GtkArrowType arrow_type) -{ - GtkWidget *button; - AtkObject *atk_obj; - - button = gtk_button_new (); - atk_obj = gtk_widget_get_accessible (button); - if (arrow_type == GTK_ARROW_LEFT) - atk_object_set_name (atk_obj, _("Up Path")); - else - atk_object_set_name (atk_obj, _("Down Path")); - - gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE); - gtk_widget_add_events (button, GDK_SCROLL_MASK); - gtk_container_add (GTK_CONTAINER (button), - gtk_arrow_new (arrow_type, GTK_SHADOW_OUT)); - gtk_container_add (GTK_CONTAINER (path_bar), button); - gtk_widget_show_all (button); - - g_signal_connect (G_OBJECT (button), "unmap", - G_CALLBACK (on_slider_unmap), path_bar); - - return button; -} - static void gtk_path_bar_init (GtkPathBar *path_bar) { - GtkStyleContext *context; + path_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (path_bar, + GTK_TYPE_PATH_BAR, + GtkPathBarPrivate); + + gtk_widget_init_template (GTK_WIDGET (path_bar)); + + /* Add the children manually because GtkPathBar derives from an abstract class, + * Glade cannot edit a