Commit 527f33bb authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

libgimp/Makefile.am libgimp/gimpui.h libgimp/gimpuitypes.h new widget

2004-09-01  Michael Natterer  <mitch@gimp.org>

	* libgimp/Makefile.am
	* libgimp/gimpui.h
	* libgimp/gimpuitypes.h
	* libgimp/gimpprogressbar.[ch]: new widget GimpProgressBar which
	automatically redirects any progress calls to itself while
	it exists.

	* plug-ins/script-fu/script-fu-interface.c: removed all progress
	callback and simply use a GimpProgressBar.
parent b7607592
2004-09-01 Michael Natterer <mitch@gimp.org>
* libgimp/Makefile.am
* libgimp/gimpui.h
* libgimp/gimpuitypes.h
* libgimp/gimpprogressbar.[ch]: new widget GimpProgressBar which
automatically redirects any progress calls to itself while
it exists.
* plug-ins/script-fu/script-fu-interface.c: removed all progress
callback and simply use a GimpProgressBar.
2004-09-01 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimppreview.[ch]: set a busy cursor while the
......
......@@ -226,6 +226,8 @@ libgimpui_2_0_la_SOURCES = \
gimpimagecombobox.h \
gimppixbuf.c \
gimppixbuf.h \
gimpprogressbar.c \
gimpprogressbar.h \
gimpexport.c \
gimpexport.h
......@@ -263,6 +265,7 @@ gimpinclude_HEADERS = \
gimppalettemenu.h \
gimppatternmenu.h \
gimppixbuf.h \
gimpprogressbar.h \
gimpdrawablecombobox.h \
gimpimagecombobox.h \
gimpexport.h
......
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpprogressbar.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gimpuitypes.h"
#include "gimp.h"
#include "gimpprogressbar.h"
static void gimp_progress_bar_class_init (GimpProgressBarClass *klass);
static void gimp_progress_bar_init (GimpProgressBar *bar);
static void gimp_progress_bar_destroy (GtkObject *object);
static void gimp_progress_bar_start (const gchar *message,
gboolean cancelable,
gpointer user_data);
static void gimp_progress_bar_end (gpointer user_data);
static void gimp_progress_bar_set_text (const gchar *message,
gpointer user_data);
static void gimp_progress_bar_set_value (gdouble percentage,
gpointer user_data);
static GtkProgressBarClass *parent_class = NULL;
GType
gimp_progress_bar_get_type (void)
{
static GType bar_type = 0;
if (! bar_type)
{
static const GTypeInfo bar_info =
{
sizeof (GimpProgressBarClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_progress_bar_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpProgressBar),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_progress_bar_init,
};
bar_type = g_type_register_static (GTK_TYPE_PROGRESS_BAR,
"GimpProgressBar",
&bar_info, 0);
}
return bar_type;
}
static void
gimp_progress_bar_class_init (GimpProgressBarClass *klass)
{
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->destroy = gimp_progress_bar_destroy;
}
static void
gimp_progress_bar_init (GimpProgressBar *bar)
{
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (bar), " ");
bar->progress_callback = gimp_progress_install (gimp_progress_bar_start,
gimp_progress_bar_end,
gimp_progress_bar_set_text,
gimp_progress_bar_set_value,
bar);
}
static void
gimp_progress_bar_destroy (GtkObject *object)
{
GimpProgressBar *bar = GIMP_PROGRESS_BAR (object);
if (bar->progress_callback)
{
gimp_progress_uninstall (bar->progress_callback);
bar->progress_callback = NULL;
}
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_progress_bar_start (const gchar *message,
gboolean cancelable,
gpointer user_data)
{
GimpProgressBar *bar = GIMP_PROGRESS_BAR (user_data);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (bar), message ? message : " ");
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (bar), 0.0);
if (GTK_WIDGET_DRAWABLE (bar))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
static void
gimp_progress_bar_end (gpointer user_data)
{
GimpProgressBar *bar = GIMP_PROGRESS_BAR (user_data);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (bar), " ");
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (bar), 0.0);
if (GTK_WIDGET_DRAWABLE (bar))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
static void
gimp_progress_bar_set_text (const gchar *message,
gpointer user_data)
{
GimpProgressBar *bar = GIMP_PROGRESS_BAR (user_data);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (bar), message ? message : " ");
if (GTK_WIDGET_DRAWABLE (bar))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
static void
gimp_progress_bar_set_value (gdouble percentage,
gpointer user_data)
{
GimpProgressBar *bar = GIMP_PROGRESS_BAR (user_data);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (bar), percentage);
if (GTK_WIDGET_DRAWABLE (bar))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
/**
* gimp_progress_bar_new:
*
* Creates a new #GimpProgressBar widget.
*
* Return value: the new widget.
*
* Since: GIMP 2.2
**/
GtkWidget *
gimp_progress_bar_new (void)
{
return g_object_new (GIMP_TYPE_PROGRESS_BAR, NULL);
}
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpprogressbar.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
#ifndef __GIMP_PROGRESS_BAR_H__
#define __GIMP_PROGRESS_BAR_H__
#include <gtk/gtkprogressbar.h>
G_BEGIN_DECLS
#define GIMP_TYPE_PROGRESS_BAR (gimp_progress_bar_get_type ())
#define GIMP_PROGRESS_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PROGRESS_BAR, GimpProgressBar))
#define GIMP_PROGRESS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PROGRESS_BAR, GimpProgressBarClass))
#define GIMP_IS_PROGRESS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PROGRESS_BAR))
#define GIMP_IS_PROGRESS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PROGRESS_BAR))
#define GIMP_PROGRESS_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PROGRESS_BAR, GimpProgressBarClass))
typedef struct _GimpProgressBarClass GimpProgressBarClass;
struct _GimpProgressBar
{
GtkProgressBar parent_instance;
const gchar *progress_callback;
gboolean cancelable;
};
struct _GimpProgressBarClass
{
GtkProgressBarClass parent_class;
};
GType gimp_progress_bar_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_progress_bar_new (void);
G_END_DECLS
#endif /* __GIMP_PROGRESS_BAR_H__ */
......@@ -35,6 +35,7 @@
#include <libgimp/gimppalettemenu.h>
#include <libgimp/gimppatternmenu.h>
#include <libgimp/gimppixbuf.h>
#include <libgimp/gimpprogressbar.h>
#include <libgimp/gimpdrawablecombobox.h>
#include <libgimp/gimpimagecombobox.h>
......
......@@ -30,6 +30,7 @@ G_BEGIN_DECLS
typedef struct _GimpDrawablePreview GimpDrawablePreview;
typedef struct _GimpProgressBar GimpProgressBar;
G_END_DECLS
......
......@@ -54,8 +54,7 @@ typedef struct
GtkWidget **args_widgets;
GtkWidget *progress_label;
GtkWidget *progress;
const gchar *progress_callback;
GtkWidget *progress_bar;
GtkWidget *about_dialog;
......@@ -151,63 +150,6 @@ script_fu_interface_report_cc (gchar *command)
while (gtk_main_iteration ());
}
static void
script_fu_progress_start (const gchar *message,
gboolean cancelable,
gpointer user_data)
{
SFInterface *sf_interface = user_data;
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sf_interface->progress),
message ? message : " ");
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (sf_interface->progress), 0.0);
if (GTK_WIDGET_DRAWABLE (sf_interface->progress))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
static void
script_fu_progress_end (gpointer user_data)
{
SFInterface *sf_interface = user_data;
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sf_interface->progress), " ");
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (sf_interface->progress), 0.0);
if (GTK_WIDGET_DRAWABLE (sf_interface->progress))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
static void
script_fu_progress_text (const gchar *message,
gpointer user_data)
{
SFInterface *sf_interface = user_data;
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sf_interface->progress),
message ? message : " ");
if (GTK_WIDGET_DRAWABLE (sf_interface->progress))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
static void
script_fu_progress_value (gdouble percentage,
gpointer user_data)
{
SFInterface *sf_interface = user_data;
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (sf_interface->progress),
percentage);
if (GTK_WIDGET_DRAWABLE (sf_interface->progress))
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, TRUE);
}
void
script_fu_interface (SFScript *script)
{
......@@ -546,17 +488,10 @@ script_fu_interface (SFScript *script)
FALSE, FALSE, 0);
gtk_widget_show (sf_interface->progress_label);
sf_interface->progress = gtk_progress_bar_new ();
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sf_interface->progress), " ");
gtk_box_pack_start (GTK_BOX (vbox2), sf_interface->progress, FALSE, FALSE, 0);
gtk_widget_show (sf_interface->progress);
sf_interface->progress_callback =
gimp_progress_install (script_fu_progress_start,
script_fu_progress_end,
script_fu_progress_text,
script_fu_progress_value,
sf_interface);
sf_interface->progress_bar = gimp_progress_bar_new ();
gtk_box_pack_start (GTK_BOX (vbox2), sf_interface->progress_bar,
FALSE, FALSE, 0);
gtk_widget_show (sf_interface->progress_bar);
gtk_widget_show (dlg);
......@@ -724,7 +659,6 @@ script_fu_response (GtkWidget *widget,
/* fallthru */
default:
gimp_progress_uninstall (sf_interface->progress_callback);
gtk_widget_destroy (sf_interface->dialog);
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment