[libgda] Use GtkSpinner if GTK+ >= 2.20.0, for bug #609683



commit 717c9acde1f0e8f16fa0544b01b2e3cbe4bdbea3
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue May 4 21:02:24 2010 +0200

    Use GtkSpinner if GTK+ >= 2.20.0, for bug #609683

 tools/browser/browser-spinner.c          |   80 ++++++++++++++++++-----------
 tools/browser/browser-spinner.h          |    9 +++
 tools/browser/browser-window.c           |   11 +++-
 tools/browser/data-manager/data-widget.c |   11 +++-
 4 files changed, 77 insertions(+), 34 deletions(-)
---
diff --git a/tools/browser/browser-spinner.c b/tools/browser/browser-spinner.c
index 4a34da5..69aa6c0 100644
--- a/tools/browser/browser-spinner.c
+++ b/tools/browser/browser-spinner.c
@@ -33,6 +33,54 @@
   #define GSEAL_ENABLE
   #undef KEEP_GSEAL_ENABLE
 #endif
+#if GTK_CHECK_VERSION(2,20,0)
+#include "browser-spinner.h"
+/**
+ * browser_spinner_start:
+ * @spinner: a #BrowserSpinner
+ *
+ * Start the spinner animation.
+ **/
+void
+browser_spinner_start (BrowserSpinner *spinner)
+{
+	gtk_widget_show (GTK_WIDGET (spinner));
+	gtk_spinner_start (spinner);
+}
+
+/**
+ * browser_spinner_stop:
+ * @spinner: a #BrowserSpinner
+ *
+ * Stop the spinner animation.
+ **/
+void
+browser_spinner_stop (BrowserSpinner *spinner)
+{
+	gtk_widget_hide (GTK_WIDGET (spinner));
+	gtk_spinner_stop (spinner);
+}
+
+/*
+ * browser_spinner_set_size:
+ * @spinner: a #BrowserSpinner
+ * @size: the size of type %GtkIconSize
+ *
+ * Set the size of the spinner.
+ **/
+void
+browser_spinner_set_size (BrowserSpinner *spinner,
+			  GtkIconSize size)
+{
+	gint width, height;
+	if (size == GTK_ICON_SIZE_INVALID)
+		size = GTK_ICON_SIZE_DIALOG;
+	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings ((GtkWidget*) spinner),
+					   size, &width, &height);
+	gtk_widget_set_size_request (GTK_WIDGET (spinner), width, height);
+}
+#else
+
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include "browser-spinner.h"
 
@@ -787,34 +835,6 @@ browser_spinner_set_size (BrowserSpinner *spinner,
 	}
 }
 
-#if 0
-/*
- * browser_spinner_set_timeout:
- * @spinner: a #BrowserSpinner
- * @timeout: time delay between updates to the spinner.
- *
- * Sets the timeout delay for spinner updates.
- **/
-void
-browser_spinner_set_timeout (BrowserSpinner *spinner,
-			  guint timeout)
-{
-	BrowserSpinnerPriv *priv = spinner->priv;
-
-	if (timeout != priv->timeout)
-	{
-		browser_spinner_stop (spinner);
-
-		priv->timeout = timeout;
-
-		if (priv->spinning)
-		{
-			browser_spinner_start (spinner);
-		}
-	}
-}
-#endif
-
 static void
 browser_spinner_size_request (GtkWidget *widget,
 			   GtkRequisition *requisition)
@@ -855,9 +875,7 @@ browser_spinner_map (GtkWidget *widget)
 	GTK_WIDGET_CLASS (parent_class)->map (widget);
 
 	if (priv->spinning)
-	{
 		browser_spinner_start (spinner);
-	}
 }
 
 static void
@@ -966,3 +984,5 @@ browser_spinner_new (void)
 {
 	return GTK_WIDGET (g_object_new (BROWSER_TYPE_SPINNER, NULL));
 }
+
+#endif /* GTK_CHECK_VERSION */
diff --git a/tools/browser/browser-spinner.h b/tools/browser/browser-spinner.h
index 8ec6871..6019bac 100644
--- a/tools/browser/browser-spinner.h
+++ b/tools/browser/browser-spinner.h
@@ -25,6 +25,14 @@
 #ifndef BROWSER_SPINNER_H
 #define BROWSER_SPINNER_H
 
+#if GTK_CHECK_VERSION(2,20,0)
+#define BROWSER_SPINNER(x) GTK_SPINNER(x)
+#define BrowserSpinner GtkSpinner
+#define browser_spinner_new() gtk_spinner_new()
+void		browser_spinner_start	 (BrowserSpinner *throbber);
+void		browser_spinner_stop	 (BrowserSpinner *throbber);
+void            browser_spinner_set_size (BrowserSpinner *spinner, GtkIconSize size);
+#else
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
@@ -61,5 +69,6 @@ void		browser_spinner_set_size (BrowserSpinner *spinner,
 					  GtkIconSize size);
 
 G_END_DECLS
+#endif /* GTK_CHECK_VERSION */
 
 #endif /* BROWSER_SPINNER_H */
diff --git a/tools/browser/browser-window.c b/tools/browser/browser-window.c
index bd2b692..edf56f2 100644
--- a/tools/browser/browser-window.c
+++ b/tools/browser/browser-window.c
@@ -393,7 +393,7 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
 	bwin->priv->toolbar_style = gtk_toolbar_get_style (GTK_TOOLBAR (toolbar));
 
 	GtkToolItem *ti;
-	GtkWidget *spinner;
+	GtkWidget *spinner, *svbox, *align;
 
 	ti = gtk_separator_tool_item_new ();
 	gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (ti), FALSE);
@@ -402,8 +402,15 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
         gtk_widget_show (GTK_WIDGET (ti));
 
 	spinner = browser_spinner_new ();
+	browser_spinner_set_size ((BrowserSpinner*) spinner, GTK_ICON_SIZE_SMALL_TOOLBAR);
+
+	svbox = gtk_vbox_new (FALSE, 0);
+	align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+	gtk_container_add (GTK_CONTAINER (align), spinner);
+	gtk_box_pack_start (GTK_BOX (svbox), align, TRUE, TRUE, 0);
+
 	ti = gtk_tool_item_new  ();
-	gtk_container_add (GTK_CONTAINER (ti), spinner);
+	gtk_container_add (GTK_CONTAINER (ti), svbox);
 	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), ti, -1);
         gtk_widget_show_all (GTK_WIDGET (ti));
 	bwin->priv->spinner = spinner;
diff --git a/tools/browser/data-manager/data-widget.c b/tools/browser/data-manager/data-widget.c
index 7a3bc46..205a67d 100644
--- a/tools/browser/data-manager/data-widget.c
+++ b/tools/browser/data-manager/data-widget.c
@@ -157,14 +157,21 @@ create_part (DataWidget *dwid, DataSource *source)
 	gtk_label_set_ellipsize (GTK_LABEL (header), PANGO_ELLIPSIZE_END);
 	gtk_box_pack_start (GTK_BOX (vbox), header, FALSE, FALSE, 0);
 
-	GtkWidget *nb;
+	GtkWidget *nb, *page;
 	nb = gtk_notebook_new ();
 	gtk_notebook_set_show_border (GTK_NOTEBOOK (nb), FALSE);
 	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE);
 	part->nb = GTK_NOTEBOOK (nb);
 
 	part->spinner = BROWSER_SPINNER (browser_spinner_new ());
-	gtk_notebook_append_page (GTK_NOTEBOOK (nb), GTK_WIDGET (part->spinner), NULL);
+	browser_spinner_set_size ((BrowserSpinner*) part->spinner, GTK_ICON_SIZE_LARGE_TOOLBAR);
+#if GTK_CHECK_VERSION(2,20,0)
+	page = gtk_alignment_new (0.5, 0.5, 0., 0.);
+	gtk_container_add (GTK_CONTAINER (page), (GtkWidget*) part->spinner);
+#else
+	page = GTK_WIDGET (part->spinner);
+#endif
+	gtk_notebook_append_page (GTK_NOTEBOOK (nb), page, NULL);
 	part->data_widget = NULL;
 
 	gtk_box_pack_start (GTK_BOX (vbox), nb, TRUE, TRUE, 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]