diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | lib/widgets/ephy-spinner-tool-item.c | 115 | ||||
-rw-r--r-- | lib/widgets/ephy-spinner-tool-item.h | 62 | ||||
-rw-r--r-- | lib/widgets/testspinner.c | 109 | ||||
-rwxr-xr-x | src/ephy-toolbar.c | 47 |
5 files changed, 301 insertions, 45 deletions
@@ -1,5 +1,18 @@ 2006-10-17 Christian Persch <chpe@cvs.gnome.org> + * lib/widgets/Makefile.am: + A lib/widgets/ephy-spinner-tool-item.c: + A lib/widgets/ephy-spinner-tool-item.h: + * lib/widgets/testspinner.c: (change_toolbar_style_cb), + (change_toolbar_icon_size_cb), (spin_toolbar_spinner_cb), (main): + * src/ephy-toolbar.c: (ephy_toolbar_update_spinner), + (ephy_toolbar_constructor): + + Add EphySpinnerToolItem which encapsulates a spinner and automatically + adapts its size to toolbar style changes, and use it in EphyToolbar. + +2006-10-17 Christian Persch <chpe@cvs.gnome.org> + * lib/widgets/ephy-spinner.c: (ephy_spinner_images_load), (ephy_spinner_cache_get_images), (ephy_spinner_get_type), (ephy_spinner_init), (ephy_spinner_new): 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); diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c index 60acce052..a4c4bd8b7 100755 --- a/src/ephy-toolbar.c +++ b/src/ephy-toolbar.c @@ -31,7 +31,7 @@ #include "ephy-navigation-action.h" #include "ephy-topic-action.h" #include "ephy-zoom-action.h" -#include "ephy-spinner.h" +#include "ephy-spinner-tool-item.h" #include "ephy-dnd.h" #include "ephy-shell.h" #include "ephy-stock-icons.h" @@ -71,8 +71,7 @@ struct _EphyToolbarPrivate GtkActionGroup *action_group; GtkAction *actions[LAST_ACTION]; GtkWidget *fixed_toolbar; - GtkWidget *spinner; - GtkToolItem *spinner_item; + EphySpinnerToolItem *spinner; GtkToolItem *sep_item; GtkToolItem *exit_button; gulong set_focus_handler; @@ -135,35 +134,7 @@ ephy_toolbar_update_spinner (EphyToolbar *toolbar) { EphyToolbarPrivate *priv = toolbar->priv; - if (priv->spinning) - { - ephy_spinner_start (EPHY_SPINNER (priv->spinner)); - } - else - { - ephy_spinner_stop (EPHY_SPINNER (priv->spinner)); - } -} - -static void -fixed_toolbar_reconfigured_cb (GtkToolItem *item, - EphySpinner *spinner) -{ - GtkToolbarStyle style; - GtkIconSize size; - - style = gtk_tool_item_get_toolbar_style (item); - - if (style == GTK_TOOLBAR_BOTH) - { - size = GTK_ICON_SIZE_INVALID; - } - else - { - size = GTK_ICON_SIZE_LARGE_TOOLBAR; - } - - ephy_spinner_set_size (spinner, size); + ephy_spinner_tool_item_set_spinning (priv->spinner, priv->spinning); } static void @@ -589,15 +560,9 @@ ephy_toolbar_constructor (GType type, gtoolbar = GTK_TOOLBAR (priv->fixed_toolbar); gtk_toolbar_set_show_arrow (gtoolbar, FALSE); - priv->spinner = ephy_spinner_new (); - gtk_widget_show (priv->spinner); - - priv->spinner_item = gtk_tool_item_new (); - g_signal_connect (priv->spinner_item, "toolbar-reconfigured", - G_CALLBACK (fixed_toolbar_reconfigured_cb), priv->spinner); - gtk_container_add (GTK_CONTAINER (priv->spinner_item), priv->spinner); - gtk_toolbar_insert (gtoolbar, priv->spinner_item, -1); - gtk_widget_show (GTK_WIDGET (priv->spinner_item)); + priv->spinner = ephy_spinner_tool_item_new (); + gtk_toolbar_insert (gtoolbar, GTK_TOOL_ITEM (priv->spinner), -1); + gtk_widget_show (GTK_WIDGET (priv->spinner)); priv->sep_item = gtk_separator_tool_item_new (); gtk_toolbar_insert (gtoolbar, priv->sep_item, -1); |