Commit dab360d9 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

plug-ins/helpbrowser/Makefile.am plug-ins/helpbrowser/gimpthrobber.[ch]

2005-04-17  Sven Neumann  <sven@gimp.org>

	* plug-ins/helpbrowser/Makefile.am
	* plug-ins/helpbrowser/gimpthrobber.[ch]
	* plug-ins/helpbrowser/gimpthrobberaction.[ch]: new files
	implementing a custom GtkToolItem and a GtkAction to use it.

	* plug-ins/helpbrowser/dialog.c: use the new widget.
parent 1967e63d
2005-04-17 Sven Neumann <sven@gimp.org>
* plug-ins/helpbrowser/Makefile.am
* plug-ins/helpbrowser/gimpthrobber.[ch]
* plug-ins/helpbrowser/gimpthrobberaction.[ch]: new files
implementing a custom GtkToolItem and a GtkAction to use it.
* plug-ins/helpbrowser/dialog.c: use the new widget.
2005-04-17 Sven Neumann <sven@gimp.org>
* app/widgets/gimpaction.h
......
......@@ -13,12 +13,16 @@ libexecdir = $(gimpplugindir)/plug-ins
libexec_PROGRAMS = helpbrowser
helpbrowser_SOURCES = \
helpbrowser.c \
dialog.c \
dialog.h \
queue.c \
queue.h \
uri.c \
gimpthrobber.c \
gimpthrobber.h \
gimpthrobberaction.c \
gimpthrobberaction.h \
helpbrowser.c \
dialog.c \
dialog.h \
queue.c \
queue.h \
uri.c \
uri.h
INCLUDES = \
......
......@@ -45,6 +45,9 @@
#include "libgimpbase/gimpwin32-io.h"
#endif
#include "gimpthrobber.h"
#include "gimpthrobberaction.h"
#include "dialog.h"
#include "queue.h"
#include "uri.h"
......@@ -188,10 +191,6 @@ browser_dialog_open (void)
gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
gtk_widget_show (toolbar);
item = gtk_separator_tool_item_new ();
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0);
gtk_widget_show (GTK_WIDGET (item));
item = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0);
gtk_widget_show (GTK_WIDGET (item));
......@@ -408,8 +407,6 @@ ui_manager_new (GtkWidget *window)
{
static GtkActionEntry actions[] =
{
// { "help-browser-menu", NULL, NULL },
{ "back", GTK_STOCK_GO_BACK,
NULL, NULL, N_("Go back one page"),
G_CALLBACK (back_callback) },
......@@ -422,26 +419,33 @@ ui_manager_new (GtkWidget *window)
NULL, NULL, N_("Go to the index page"),
G_CALLBACK (index_callback) },
{ "online", GIMP_STOCK_WILBER,
"", NULL, N_("Visit the GIMP documentation website"),
G_CALLBACK (online_callback) },
{ "close", GTK_STOCK_CLOSE,
NULL, "<control>W", N_("Close the help browser"),
NULL, "<control>W", NULL,
G_CALLBACK (close_callback) },
{ "quit", GTK_STOCK_QUIT,
NULL, "<control>Q", N_("Close the help browser"),
NULL, "<control>Q", NULL,
G_CALLBACK (close_callback) },
};
GtkUIManager *ui_manager = gtk_ui_manager_new ();
GtkActionGroup *group = gtk_action_group_new ("Actions");
GtkAction *action;
GError *error = NULL;
gtk_action_group_set_translation_domain (group, NULL);
gtk_action_group_add_actions (group, actions, G_N_ELEMENTS (actions), NULL);
action = gimp_throbber_action_new ("online",
_("Visit the GIMP documentation website"),
GIMP_STOCK_WILBER);
g_signal_connect_closure (action, "activate",
g_cclosure_new (G_CALLBACK (online_callback),
NULL, NULL),
FALSE);
gtk_action_group_add_action (group, action);
g_object_unref (action);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (ui_manager));
gtk_accel_group_lock (gtk_ui_manager_get_accel_group (ui_manager));
......@@ -555,7 +559,7 @@ static void
online_callback (GtkAction *action,
gpointer data)
{
load_remote_page ("http://www.gimp.org/docs/");
load_remote_page ("http://docs.gimp.org/");
}
static void
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpThrobber
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gimpthrobber.h"
enum
{
CLICKED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_STOCK_ID
};
static void gimp_throbber_class_init (GimpThrobberClass *klass);
static void gimp_throbber_init (GimpThrobber *button);
static void gimp_throbber_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_throbber_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gimp_throbber_finalize (GObject *object);
static gboolean gimp_throbber_create_menu_proxy (GtkToolItem *tool_item);
static void gimp_throbber_toolbar_reconfigured (GtkToolItem *tool_item);
static void gimp_throbber_button_clicked (GtkWidget *widget,
GimpThrobber *button);
static void gimp_throbber_construct_contents (GtkToolItem *tool_item);
static GObjectClass *parent_class = NULL;
static guint toolbutton_signals[LAST_SIGNAL] = { 0 };
#define GIMP_THROBBER_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_THROBBER, GimpThrobberPrivate))
struct _GimpThrobberPrivate
{
GtkWidget *button;
gchar *stock_id;
};
GType
gimp_throbber_get_type (void)
{
static GtkType type = 0;
if (!type)
{
static const GTypeInfo type_info =
{
sizeof (GimpThrobberClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_throbber_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GimpThrobber),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_throbber_init,
};
type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
"GimpThrobber",
&type_info, 0);
}
return type;
}
static void
gimp_throbber_class_init (GimpThrobberClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkToolItemClass *tool_item_class = GTK_TOOL_ITEM_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->set_property = gimp_throbber_set_property;
object_class->get_property = gimp_throbber_get_property;
object_class->finalize = gimp_throbber_finalize;
tool_item_class->create_menu_proxy = gimp_throbber_create_menu_proxy;
tool_item_class->toolbar_reconfigured = gimp_throbber_toolbar_reconfigured;
g_object_class_install_property (object_class,
PROP_STOCK_ID,
g_param_spec_string ("stock-id", NULL, NULL,
NULL,
G_PARAM_READWRITE));
toolbutton_signals[CLICKED] =
g_signal_new ("clicked",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpThrobberClass, clicked),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_type_class_add_private (object_class, sizeof (GimpThrobberPrivate));
}
static void
gimp_throbber_init (GimpThrobber *button)
{
GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
button->priv = GIMP_THROBBER_GET_PRIVATE (button);
gtk_tool_item_set_homogeneous (toolitem, TRUE);
button->priv->button = g_object_new (GTK_TYPE_BUTTON,
"yalign", 0.0,
NULL);
gtk_button_set_focus_on_click (GTK_BUTTON (button->priv->button), FALSE);
g_signal_connect_object (button->priv->button, "clicked",
G_CALLBACK (gimp_throbber_button_clicked),
button, 0);
gtk_container_add (GTK_CONTAINER (button), button->priv->button);
gtk_widget_show (button->priv->button);
}
static void
gimp_throbber_construct_contents (GtkToolItem *tool_item)
{
GimpThrobber *button = GIMP_THROBBER (tool_item);
GtkWidget *icon;
GtkToolbarStyle style;
GtkIconSize icon_size;
if (GTK_BIN (button->priv->button)->child)
gtk_widget_destroy (GTK_BIN (button->priv->button)->child);
style = gtk_tool_item_get_toolbar_style (tool_item);
if (style == GTK_TOOLBAR_TEXT)
icon_size = GTK_ICON_SIZE_MENU;
else
icon_size = gtk_tool_item_get_icon_size (tool_item);
icon = gtk_image_new_from_stock (button->priv->stock_id, icon_size);
gtk_container_add (GTK_CONTAINER (button->priv->button), icon);
gtk_widget_show (icon);
gtk_button_set_relief (GTK_BUTTON (button->priv->button),
gtk_tool_item_get_relief_style (tool_item));
gtk_widget_queue_resize (GTK_WIDGET (button));
}
static void
gimp_throbber_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GimpThrobber *button = GIMP_THROBBER (object);
switch (prop_id)
{
case PROP_STOCK_ID:
gimp_throbber_set_stock_id (button, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gimp_throbber_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GimpThrobber *button = GIMP_THROBBER (object);
switch (prop_id)
{
case PROP_STOCK_ID:
g_value_set_string (value, button->priv->stock_id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gimp_throbber_finalize (GObject *object)
{
GimpThrobber *button = GIMP_THROBBER (object);
if (button->priv->stock_id)
g_free (button->priv->stock_id);
parent_class->finalize (object);
}
static void
gimp_throbber_button_clicked (GtkWidget *widget,
GimpThrobber *button)
{
g_signal_emit_by_name (button, "clicked");
}
static gboolean
gimp_throbber_create_menu_proxy (GtkToolItem *tool_item)
{
gtk_tool_item_set_proxy_menu_item (tool_item, "gimp-throbber-menu-id", NULL);
return FALSE;
}
static void
gimp_throbber_toolbar_reconfigured (GtkToolItem *tool_item)
{
gimp_throbber_construct_contents (tool_item);
}
GtkToolItem *
gimp_throbber_new (const gchar *stock_id)
{
GimpThrobber *button;
g_return_val_if_fail (stock_id != NULL, NULL);
button = g_object_new (GIMP_TYPE_THROBBER,
"stock-id", stock_id,
NULL);
return GTK_TOOL_ITEM (button);
}
void
gimp_throbber_set_stock_id (GimpThrobber *button,
const gchar *stock_id)
{
gchar *old_stock_id;
g_return_if_fail (GIMP_IS_THROBBER (button));
old_stock_id = button->priv->stock_id;
button->priv->stock_id = g_strdup (stock_id);
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
g_object_notify (G_OBJECT (button), "stock-id");
g_free (old_stock_id);
}
G_CONST_RETURN gchar *
gimp_throbber_get_stock_id (GimpThrobber *button)
{
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
return button->priv->stock_id;
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpThrobber
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_THROBBER_H__
#define __GIMP_THROBBER_H__
G_BEGIN_DECLS
#define GIMP_TYPE_THROBBER (gimp_throbber_get_type ())
#define GIMP_THROBBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_THROBBER, GimpThrobber))
#define GIMP_THROBBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_THROBBER, GimpThrobberClass))
#define GIMP_IS_THROBBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_THROBBER))
#define GIMP_IS_THROBBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_THROBBER))
#define GIMP_THROBBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GIMP_TYPE_THROBBER, GimpThrobberClass))
typedef struct _GimpThrobber GimpThrobber;
typedef struct _GimpThrobberClass GimpThrobberClass;
typedef struct _GimpThrobberPrivate GimpThrobberPrivate;
struct _GimpThrobber
{
GtkToolItem parent;
/*< private >*/
GimpThrobberPrivate *priv;
};
struct _GimpThrobberClass
{
GtkToolItemClass parent_class;
/* signal */
void (* clicked) (GimpThrobber *tool_item);
};
GType gimp_throbber_get_type (void) G_GNUC_CONST;
GtkToolItem * gimp_throbber_new (const gchar *stock_id);
void gimp_throbber_set_stock_id (GimpThrobber *button,
const gchar *stock_id);
const gchar * gimp_throbber_get_stock_id (GimpThrobber *button);
G_END_DECLS
#endif /* __GIMP_THROBBER_H__ */
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpThrobberAction
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gimpthrobberaction.h"
#include "gimpthrobber.h"
static void gimp_throbber_action_class_init (GimpThrobberActionClass *klass);
static void gimp_throbber_action_connect_proxy (GtkAction *action,
GtkWidget *proxy);
static void gimp_throbber_action_sync_property (GtkAction *action,
GParamSpec *pspec,
GtkWidget *proxy);
static GtkActionClass *parent_class = NULL;
GType
gimp_throbber_action_get_type (void)
{
static GType type = 0;
if (!type)
{
static const GTypeInfo type_info =
{
sizeof (GtkActionClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_throbber_action_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkAction),
0, /* n_preallocs */
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GTK_TYPE_ACTION,
"GimpThrobberAction",
&type_info, 0);
}
return type;
}
static void
gimp_throbber_action_class_init (GimpThrobberActionClass *klass)
{
GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
action_class->connect_proxy = gimp_throbber_action_connect_proxy;
action_class->toolbar_item_type = GIMP_TYPE_THROBBER;
}
static void
gimp_throbber_action_connect_proxy (GtkAction *action,
GtkWidget *proxy)
{
GParamSpec *pspec;
GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (action),
"stock-id");
gimp_throbber_action_sync_property (action, pspec, proxy);
g_signal_connect_object (action, "notify::stock-id",
G_CALLBACK (gimp_throbber_action_sync_property),
proxy, 0);
g_signal_connect_object (proxy, "clicked",
G_CALLBACK (gtk_action_activate), action,
G_CONNECT_SWAPPED);
}
static void
gimp_throbber_action_sync_property (GtkAction *action,
GParamSpec *pspec,
GtkWidget *proxy)
{
const gchar *property = g_param_spec_get_name (pspec);
GValue value = { 0, };
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
g_object_get_property (G_OBJECT (action), property, &value);
g_object_set_property (G_OBJECT (proxy), property, &value);
g_value_unset (&value);
}
GtkAction *
gimp_throbber_action_new (const gchar *name,
const gchar *tooltip,
const gchar *stock_id)
{
return g_object_new (GIMP_TYPE_THROBBER_ACTION,
"name", name,
"tooltip", tooltip,
"stock-id", stock_id,
NULL);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpThrobberAction
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by