Gimp/app/gimpprogress.c
Michael Natterer 18dd072836 app/gimpprogress.[ch] s/GDisplay/GimpDisplay/
2001-10-16  Michael Natterer  <mitch@gimp.org>

	* app/gimpprogress.[ch]
	* app/undo.c: s/GDisplay/GimpDisplay/

	* app/plug_in.[ch]: removed unused boolean "destroy" field of
	the PlugIn struct.

	* app/core/gimpedit.c: don't include "app_procs.h"

	* app/display/gimpdisplay-callbacks.c: moved the "grab_abd_scroll"
	stuff from gimpdisplay-scroll.* here (less complicated and easier
	to cleanup...)

	* app/display/gimpdisplay-scroll.[ch]: removed here.

	* app/display/gimpdisplay-render.[ch]
	* app/display/gimpdisplay-selection.[ch]
	* app/display/gimpdisplayshell.c: s/GDisplay/GimpDisplay/g

	* app/display/gimpdisplay.[ch]: ditto, removed gdisplay_active()
	which was just a wrapper around
	"gimp_context_get_display (gimp_get_user_context (the_gimp))"
	(which is more to type but makes the use of the global
	"the_gimp" variable more obvious).

	* app/gui/color-area.h
	* app/gui/edit-commands.c
	* app/gui/file-commands.c
	* app/gui/file-dialog-utils.c
	* app/gui/image-commands.c
	* app/gui/info-window.h
	* app/gui/paths-dialog.h
	* app/gui/select-commands.c
	* app/gui/tool-options-dialog.c
	* app/gui/tools-commands.c
	* app/gui/view-commands.c: s/GDisplay/GimpDisplay/, gdisplay_active()
	removal, include "app_procs.h" for "the_gimp".

	* app/tools/gimpbezierselecttool.h
	* app/tools/gimpbrightnesscontrasttool.[ch]
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpcolorbalancetool.[ch]
	* app/tools/gimpcurvestool.[ch]
	* app/tools/gimpeditselectiontool.h
	* app/tools/gimphistogramtool.[ch]
	* app/tools/gimphuesaturationtool.[ch]
	* app/tools/gimplevelstool.[ch]
	* app/tools/gimpmovetool.h
	* app/tools/gimpperspectivetool.h
	* app/tools/gimpposterizetool.[ch]
	* app/tools/gimprotatetool.h
	* app/tools/gimpscaletool.h
	* app/tools/gimpsheartool.h
	* app/tools/gimptexttool.h
	* app/tools/gimpthresholdtool.[ch]
	* app/tools/gimptool.[ch]
	* app/tools/gimptransformtool.h
	* app/tools/tool_manager.[ch]: lots of s/GDisplay/GimpDisplay/, made
	all *_dialog_hide() functions private, cleanup.

	* app/widgets/*: removed GtkType and gtk_type_* stuff entirely and
	use GObject functions, removed lots of empty "destroy" methods and
	use more type checking class cast macros instead of casting
	directly.

	* app/widgets/gimpcontainermenu.c: fixed item insert order.

	* app/widgets/gimphistogramview.[ch]: cleaned up and renamed all
	functions.

	* app/widgets/gimpwidgets-utils.[ch]: removed gimp_dialog_hide() as
	Gtk+ does the right thing (TM) now.

	* tools/pdbgen/pdb/color.pdb: implemented "histogram" without
	digging into tools/ and widgets/ (needs to be done for all
	color PDB functions).

	* tools/pdbgen/pdb/gimprc.pdb: no need to use "the_gimp" in a PDB
	function as a "Gimp" pointer is passed to them all.

	* tools/pdbgen/pdb/image.pdb: don't include "app_procs.h"

	* app/pdb/color_cmds.c
	* app/pdb/gimprc_cmds.c
	* app/pdb/image_cmds.c: regenerated.

	* app/pdb/procedural_db.c: don't include "app_procs.h"
2001-10-17 11:33:43 +00:00

344 lines
8.9 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 "libgimpwidgets/gimpwidgets.h"
#include "core/core-types.h"
#include "display/gimpdisplay.h"
#include "gimpprogress.h"
#include "libgimp/gimpintl.h"
struct _GimpProgress
{
GimpDisplay *gdisp; /* gdisp in use, or NULL*/
/* next four fields are only valid if gdisp is NULL */
GtkWidget *dialog; /* progress dialog, NULL if using gdisp */
GtkWidget *dialog_label;
GtkWidget *progressbar;
GtkWidget *cancelbutton;
GCallback cancel_callback; /* callback to remove, or NULL */
gpointer cancel_data;
};
/* prototypes */
static void progress_signal_setup (GimpProgress *progress,
GCallback cancel_callback,
gpointer cancel_data);
/* These progress bar routines are re-entrant, and so should be
* thread-safe.
*/
/* Start a progress bar on "gdisp" with reason "message". If "gdisp"
* is NULL, the progress bar is presented in a new dialog box. If
* "message" is NULL, then no message is used.
*
* If "cancel_callback" is not NULL, it is attached to the progress
* bar cancel button's "clicked" signal, with data "cancel_data". The
* cancel button is only made sensitive if the callback is set.
*
* It is an error to progress_start() a bar on a "gdisp" for which
* there is already a progress bar active.
*
* Progress bars with "important" set to TRUE will be shown to the
* user in any possible way. Unimportant progress bars will not be
* shown to the user if it would mean creating a new window.
*/
GimpProgress *
progress_start (GimpDisplay *gdisp,
const gchar *message,
gboolean important,
GCallback cancel_callback,
gpointer cancel_data)
{
GimpProgress *p;
guint cid;
GtkWidget *vbox;
p = g_new (GimpProgress, 1);
p->gdisp = gdisp;
p->dialog = NULL;
p->cancel_callback = NULL;
p->cancel_data = NULL;
/* do we have a useful gdisplay and statusarea? */
if (gdisp && GTK_WIDGET_VISIBLE (gdisp->statusarea))
{
if (message)
{
cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (gdisp->statusbar),
"progress");
gtk_statusbar_push (GTK_STATUSBAR (gdisp->statusbar), cid, message);
}
/* really need image locking to stop multiple people going at
* the image */
if (gdisp->progressid)
g_warning("%d progress bars already active for display %p\n",
gdisp->progressid, gdisp);
gdisp->progressid++;
}
else
{
/* unimporant progress indications are occasionally failed */
if (!important)
{
g_free (p);
return NULL;
}
p->gdisp = NULL;
p->dialog = gimp_dialog_new (_("Progress"), "plug_in_progress",
NULL, NULL,
GTK_WIN_POS_NONE,
FALSE, TRUE, FALSE,
GTK_STOCK_CANCEL, NULL,
NULL, NULL, &p->cancelbutton, TRUE, TRUE,
NULL);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (p->dialog)->vbox), vbox);
gtk_widget_show (vbox);
p->dialog_label = gtk_label_new (message ? message :
_("Please wait..."));
gtk_misc_set_alignment (GTK_MISC (p->dialog_label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox), p->dialog_label, FALSE, TRUE, 0);
gtk_widget_show (p->dialog_label);
p->progressbar = gtk_progress_bar_new ();
gtk_widget_set_usize (p->progressbar, 150, 20);
gtk_box_pack_start (GTK_BOX (vbox), p->progressbar, TRUE, TRUE, 0);
gtk_widget_show (p->progressbar);
gtk_widget_show (p->dialog);
}
progress_signal_setup (p, cancel_callback, cancel_data);
return p;
}
/* Update the message and/or the callbacks for a progress and reset
* the bar to zero, with the minimum of disturbance to the user. */
GimpProgress *
progress_restart (GimpProgress *p,
const char *message,
GCallback cancel_callback,
gpointer cancel_data)
{
int cid;
GtkWidget *bar;
g_return_val_if_fail (p != NULL, p);
/* change the message */
if (p->gdisp)
{
cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (p->gdisp->statusbar),
"progress");
gtk_statusbar_pop (GTK_STATUSBAR (p->gdisp->statusbar), cid);
if (message)
gtk_statusbar_push (GTK_STATUSBAR (p->gdisp->statusbar), cid, message);
bar = p->gdisp->progressbar;
}
else
{
gtk_label_set_text (GTK_LABEL (p->dialog_label),
message ? message : _("Please wait..."));
bar = p->progressbar;
}
/* reset the progress bar */
gtk_progress_bar_update (GTK_PROGRESS_BAR (bar), 0.0);
/* do we need to change the callbacks? */
progress_signal_setup (p, cancel_callback, cancel_data);
return p;
}
void
progress_update (GimpProgress *progress,
gdouble percentage)
{
GtkWidget *bar;
g_return_if_fail (progress != NULL);
if (!(percentage >= 0.0 && percentage <= 1.0))
return;
/* do we have a dialog box, or are we using the statusbar? */
if (progress->gdisp)
bar = progress->gdisp->progressbar;
else
bar = progress->progressbar;
gtk_progress_bar_update (GTK_PROGRESS_BAR (bar), percentage);
}
/* This function's prototype is conveniently the same as progress_func_t */
void
progress_update_and_flush (gint ymin,
gint ymax,
gint curr_y,
gpointer data)
{
progress_update ((GimpProgress *) data,
(float)(curr_y - ymin) / (float)(ymax - ymin));
/* HACK until we do long-running operations in the gtk idle thread */
while (gtk_events_pending())
gtk_main_iteration();
}
/* Step the progress bar by one percent, wrapping at 100% */
void
progress_step (GimpProgress *progress)
{
GtkWidget *bar;
float val;
g_return_if_fail (progress != NULL);
if (progress->gdisp)
bar = progress->gdisp->progressbar;
else
bar = progress->progressbar;
val = gtk_progress_get_current_percentage (GTK_PROGRESS (bar)) + 0.01;
if (val > 1.0)
val = 0.0;
progress_update (progress, val);
}
/* Finish using the progress bar "p" */
void
progress_end (GimpProgress *p)
{
gint cid;
g_return_if_fail (p != NULL);
/* remove all callbacks so they don't get called while we're
* destroying widgets */
progress_signal_setup (p, NULL, NULL);
if (p->gdisp)
{
cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (p->gdisp->statusbar),
"progress");
gtk_statusbar_pop (GTK_STATUSBAR (p->gdisp->statusbar), cid);
gtk_progress_bar_update (GTK_PROGRESS_BAR (p->gdisp->progressbar), 0.0);
if (p->gdisp->progressid > 0)
p->gdisp->progressid--;
}
else
{
gtk_widget_destroy (p->dialog);
}
g_free (p);
}
/* Helper function to add or remove signals */
static void
progress_signal_setup (GimpProgress *p,
GCallback cancel_callback,
gpointer cancel_data)
{
GtkWidget *button;
GtkWidget *dialog;
if (p->cancel_callback == cancel_callback && p->cancel_data == cancel_data)
return;
/* are we using the statusbar or a freestanding dialog? */
if (p->gdisp)
{
dialog = NULL;
button = p->gdisp->cancelbutton;
}
else
{
dialog = p->dialog;
button = p->cancelbutton;
}
/* remove any existing signal handlers */
if (p->cancel_callback)
{
g_signal_handlers_disconnect_by_func (G_OBJECT (button),
p->cancel_callback,
p->cancel_data);
if (dialog)
g_signal_handlers_disconnect_by_func (G_OBJECT (dialog),
p->cancel_callback,
p->cancel_data);
}
/* add the new handlers */
if (cancel_callback)
{
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (cancel_callback),
cancel_data);
if (dialog)
g_signal_connect (G_OBJECT (dialog), "destroy",
G_CALLBACK (cancel_callback),
cancel_data);
}
gtk_widget_set_sensitive (GTK_WIDGET (button),
cancel_callback ? TRUE : FALSE);
p->cancel_callback = cancel_callback;
p->cancel_data = cancel_data;
}
/* End of gimpprogress.c */