aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'lib/widgets')
-rw-r--r--lib/widgets/ephy-spinner-tool-item.c115
-rw-r--r--lib/widgets/ephy-spinner-tool-item.h62
-rw-r--r--lib/widgets/testspinner.c109
3 files changed, 282 insertions, 4 deletions
diff --git a/lib/widgets/ephy-spinner-tool-item.c b/lib/widgets/ephy-spinner-tool-item.c
new file mode 100644
index 000000000..d92e7f9ed
--- /dev/null
+++ b/lib/widgets/ephy-spinner-tool-item.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2006 Christian Persch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+
+#ifndef COMPILING_TESTSPINNER
+#include "config.h"
+#endif
+
+#include "ephy-spinner-tool-item.h"
+#include "ephy-spinner.h"
+
+G_DEFINE_TYPE (EphySpinnerToolItem, ephy_spinner_tool_item, GTK_TYPE_TOOL_ITEM)
+
+static void
+ephy_spinner_tool_item_init (EphySpinnerToolItem *item)
+{
+ GtkWidget *spinner;
+
+ spinner = ephy_spinner_new ();
+ gtk_container_add (GTK_CONTAINER (item), spinner);
+ gtk_widget_show (spinner);
+}
+
+static void
+ephy_spinner_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
+{
+ EphySpinner *spinner;
+ GtkToolbarStyle style;
+ GtkIconSize spinner_size;
+
+ spinner = EPHY_SPINNER (gtk_bin_get_child (GTK_BIN (tool_item)));
+ g_return_if_fail (spinner);
+
+ style = gtk_tool_item_get_toolbar_style (tool_item);
+
+ /* FIXME: be smarter by taking the toolbar icon size (gtk_toolbar_get_icon_size) into account! */
+
+ if (style == GTK_TOOLBAR_BOTH)
+ {
+ spinner_size = GTK_ICON_SIZE_INVALID;
+ }
+ else
+ {
+ spinner_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
+ }
+
+ ephy_spinner_set_size (spinner, spinner_size);
+
+ if (GTK_TOOL_ITEM_CLASS (ephy_spinner_tool_item_parent_class)->toolbar_reconfigured)
+ GTK_TOOL_ITEM_CLASS (ephy_spinner_tool_item_parent_class)->toolbar_reconfigured (tool_item);
+}
+
+static void
+ephy_spinner_tool_item_class_init (EphySpinnerToolItemClass *klass)
+{
+ GtkToolItemClass *tool_item_class = GTK_TOOL_ITEM_CLASS (klass);
+
+ tool_item_class->toolbar_reconfigured = ephy_spinner_tool_item_toolbar_reconfigured;
+}
+
+/*
+ * ephy_spinner_tool_item_new:
+ *
+ * Create a new #EphySpinnerToolItem. The spinner is a widget
+ * that gives the user feedback about network status with
+ * an animated image.
+ *
+ * Return Value: the spinner tool item
+ **/
+GtkToolItem *
+ephy_spinner_tool_item_new (void)
+{
+ return GTK_TOOL_ITEM (g_object_new (EPHY_TYPE_SPINNER_TOOL_ITEM, NULL));
+}
+
+/*
+ * ephy_spinner_tool_item_set_spinning:
+ *
+ * Start or stop the spinner.
+ **/
+void
+ephy_spinner_tool_item_set_spinning (EphySpinnerToolItem *item,
+ gboolean spinning)
+{
+ EphySpinner *spinner;
+
+ spinner = EPHY_SPINNER (gtk_bin_get_child (GTK_BIN (item)));
+ g_return_if_fail (spinner);
+
+ if (spinning)
+ {
+ ephy_spinner_start (spinner);
+ }
+ else
+ {
+ ephy_spinner_stop (spinner);
+ }
+}
diff --git a/lib/widgets/ephy-spinner-tool-item.h b/lib/widgets/ephy-spinner-tool-item.h
new file mode 100644
index 000000000..759ead10f
--- /dev/null
+++ b/lib/widgets/ephy-spinner-tool-item.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2006 Christian Persch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_SPINNER_TOOL_ITEM_H
+#define EPHY_SPINNER_TOOL_ITEM_H
+
+#include <gtk/gtktoolitem.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_SPINNER_TOOL_ITEM (ephy_spinner_tool_item_get_type ())
+#define EPHY_SPINNER_TOOL_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_SPINNER_TOOL_ITEM, EphySpinnerToolItem))
+#define EPHY_SPINNER_TOOL_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_SPINNER_TOOL_ITEM, EphySpinnerToolItemClass))
+#define EPHY_IS_SPINNER_TOOL_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_SPINNER_TOOL_ITEM))
+#define EPHY_IS_SPINNER_TOOL_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_SPINNER_TOOL_ITEM))
+#define EPHY_SPINNER_TOOL_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_SPINNER_TOOL_ITEM, EphySpinnerToolItemClass))
+
+typedef struct _EphySpinnerToolItem EphySpinnerToolItem;
+typedef struct _EphySpinnerToolItemClass EphySpinnerToolItemClass;
+typedef struct _EphySpinnerToolItemDetails EphySpinnerToolItemDetails;
+
+struct _EphySpinnerToolItem
+{
+ GtkToolItem parent;
+
+ /*< private >*/
+ EphySpinnerToolItemDetails *details;
+};
+
+struct _EphySpinnerToolItemClass
+{
+ GtkToolItemClass parent_class;
+};
+
+GType ephy_spinner_tool_item_get_type (void);
+
+GtkToolItem *ephy_spinner_tool_item_new (void);
+
+void ephy_spinner_tool_item_set_spinning (EphySpinnerToolItem *item,
+ gboolean spinning);
+
+G_END_DECLS
+
+#endif /* !EPHY_SPINNER_TOOL_ITEM_H */
diff --git a/lib/widgets/testspinner.c b/lib/widgets/testspinner.c
index 31488d55c..f986d752f 100644
--- a/lib/widgets/testspinner.c
+++ b/lib/widgets/testspinner.c
@@ -27,6 +27,7 @@
#define STOP_PROFILER(name)
#include "ephy-spinner.c"
+#include "ephy-spinner-tool-item.c"
#define MOVE_TIMEOUT 211 /* ms */
@@ -113,12 +114,60 @@ start_or_stop_repeated_moves (GtkWindow *window)
}
}
+static void
+change_toolbar_style_cb (GtkComboBox *combo,
+ GtkToolbar *toolbar)
+{
+ int value = gtk_combo_box_get_active (combo);
+
+ gtk_toolbar_set_style (toolbar, value);
+}
+
+static void
+change_toolbar_icon_size_cb (GtkComboBox *combo,
+ GtkToolbar *toolbar)
+{
+ int value = gtk_combo_box_get_active (combo);
+
+ if (value == GTK_ICON_SIZE_INVALID)
+ {
+ gtk_toolbar_unset_icon_size (toolbar);
+ }
+ else
+ {
+ gtk_toolbar_set_icon_size (toolbar, value);
+ }
+}
+
+static void
+spin_toolbar_spinner_cb (GtkToggleButton *button,
+ EphySpinnerToolItem *item)
+{
+ ephy_spinner_tool_item_set_spinning (item, gtk_toggle_button_get_active (button));
+}
+
int main(int argc, char **argv)
{
- GtkWidget *window, *vbox, *widget;
+ GtkWidget *window, *vbox, *vbox2, *widget, *toolbar, *combo;
+ GtkToolItem *item;
GtkTable *table;
- int row = 0;
-
+ int row = 0, i;
+ const char *toolbar_styles[] = {
+ "icons",
+ "text",
+ "both (vertical)",
+ "both (horizontal)"
+ };
+ const char *icon_sizes[] = {
+ "default",
+ "menu",
+ "small toolbar",
+ "large toolbar",
+ "button",
+ "dnd",
+ "dialog"
+ };
+
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -141,7 +190,59 @@ int main(int argc, char **argv)
add_spinner (table, row++, GTK_ICON_SIZE_BUTTON, "Button", 0, FALSE);
add_spinner (table, row++, GTK_ICON_SIZE_DND, "Drag-and-drop", 0, FALSE);
add_spinner (table, row++, GTK_ICON_SIZE_DIALOG, "Dialog", 0, FALSE);
-
+
+ /* Test toolbar */
+ vbox2 = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
+
+ toolbar = gtk_toolbar_new ();
+ gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH);
+ gtk_box_pack_end (GTK_BOX (vbox2), toolbar, FALSE, FALSE, 0);
+
+ item = gtk_tool_button_new_from_stock (GTK_STOCK_NEW);
+ gtk_tool_item_set_homogeneous (item, FALSE);
+ gtk_tool_item_set_is_important (item, TRUE);
+ gtk_widget_show (GTK_WIDGET (item));
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0);
+
+ item = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
+ gtk_tool_item_set_homogeneous (item, FALSE);
+ gtk_widget_show (GTK_WIDGET (item));
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0);
+
+ item = gtk_tool_item_new ();
+ gtk_tool_item_set_homogeneous (item, FALSE);
+ gtk_widget_show (GTK_WIDGET (item));
+ gtk_tool_item_set_expand (item, TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
+
+ item = ephy_spinner_tool_item_new ();
+ gtk_widget_show (GTK_WIDGET (item));
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
+
+ widget = gtk_check_button_new_with_label ("Spin");
+ g_signal_connect (widget, "toggled", G_CALLBACK (spin_toolbar_spinner_cb), item);
+ gtk_box_pack_start (GTK_BOX (vbox2), widget, FALSE, FALSE, 0);
+
+ combo = gtk_combo_box_new_text ();
+ g_signal_connect (combo, "changed", G_CALLBACK (change_toolbar_style_cb), toolbar);
+ for (i = 0; i < G_N_ELEMENTS (toolbar_styles); ++i)
+ {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), toolbar_styles[i]);
+ }
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), GTK_TOOLBAR_BOTH);
+ gtk_box_pack_start (GTK_BOX (vbox2), combo, FALSE, FALSE, 0);
+
+ combo = gtk_combo_box_new_text ();
+ g_signal_connect (combo, "changed", G_CALLBACK (change_toolbar_icon_size_cb), toolbar);
+ for (i = 0; i < G_N_ELEMENTS (icon_sizes); ++i)
+ {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), icon_sizes[i]);
+ }
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), GTK_ICON_SIZE_INVALID);
+ gtk_box_pack_start (GTK_BOX (vbox2), combo, FALSE, FALSE, 0);
+
+ /* Controls */
widget = gtk_button_new_with_label ("Move to next screen");
g_signal_connect_swapped (widget, "clicked", G_CALLBACK (move_window), window);
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);