2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-08-11 06:21:56 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpprogressbox.c
|
|
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-08-11 06:21:56 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-08-11 06:21:56 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-08-11 06:21:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-11-02 05:28:18 +08:00
|
|
|
#include <gegl.h>
|
2004-08-11 06:21:56 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-12-31 01:25:58 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2004-08-11 06:21:56 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpprogress.h"
|
|
|
|
|
|
|
|
#include "gimpprogressbox.h"
|
2014-07-11 06:40:56 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2004-08-11 06:21:56 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static void gimp_progress_box_progress_iface_init (GimpProgressInterface *iface);
|
2004-08-11 06:21:56 +08:00
|
|
|
|
2010-09-27 04:38:01 +08:00
|
|
|
static void gimp_progress_box_dispose (GObject *object);
|
2008-10-22 19:01:15 +08:00
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
static GimpProgress *
|
2004-08-11 18:29:56 +08:00
|
|
|
gimp_progress_box_progress_start (GimpProgress *progress,
|
2014-07-13 05:45:20 +08:00
|
|
|
gboolean cancellable,
|
|
|
|
const gchar *message);
|
2004-08-11 18:29:56 +08:00
|
|
|
static void gimp_progress_box_progress_end (GimpProgress *progress);
|
|
|
|
static gboolean gimp_progress_box_progress_is_active (GimpProgress *progress);
|
|
|
|
static void gimp_progress_box_progress_set_text (GimpProgress *progress,
|
|
|
|
const gchar *message);
|
|
|
|
static void gimp_progress_box_progress_set_value (GimpProgress *progress,
|
|
|
|
gdouble percentage);
|
|
|
|
static gdouble gimp_progress_box_progress_get_value (GimpProgress *progress);
|
2005-02-12 22:18:12 +08:00
|
|
|
static void gimp_progress_box_progress_pulse (GimpProgress *progress);
|
2004-08-11 06:21:56 +08:00
|
|
|
|
|
|
|
|
2010-10-30 21:44:46 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpProgressBox, gimp_progress_box, GTK_TYPE_BOX,
|
2005-12-20 06:37:49 +08:00
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_progress_box_progress_iface_init))
|
2004-08-11 06:21:56 +08:00
|
|
|
|
2008-10-22 19:01:15 +08:00
|
|
|
#define parent_class gimp_progress_box_parent_class
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_progress_box_class_init (GimpProgressBoxClass *klass)
|
|
|
|
{
|
2010-09-27 04:38:01 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2008-10-22 19:01:15 +08:00
|
|
|
|
2010-09-27 04:38:01 +08:00
|
|
|
object_class->dispose = gimp_progress_box_dispose;
|
2005-12-20 06:37:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_progress_box_init (GimpProgressBox *box)
|
2004-08-11 06:21:56 +08:00
|
|
|
{
|
2010-10-30 21:44:46 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
2007-02-01 20:06:21 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (box), 6);
|
|
|
|
|
|
|
|
box->progress = gtk_progress_bar_new ();
|
|
|
|
gtk_widget_set_size_request (box->progress, 250, 20);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), box->progress, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (box->progress);
|
|
|
|
|
|
|
|
box->label = gtk_label_new ("");
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (box->label), PANGO_ELLIPSIZE_MIDDLE);
|
2016-09-09 01:11:20 +08:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (box->label), 0.0);
|
2007-02-01 20:06:21 +08:00
|
|
|
gimp_label_set_attributes (GTK_LABEL (box->label),
|
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), box->label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (box->label);
|
2004-08-11 06:21:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-12-20 06:37:49 +08:00
|
|
|
gimp_progress_box_progress_iface_init (GimpProgressInterface *iface)
|
2004-08-11 06:21:56 +08:00
|
|
|
{
|
2005-12-20 06:37:49 +08:00
|
|
|
iface->start = gimp_progress_box_progress_start;
|
|
|
|
iface->end = gimp_progress_box_progress_end;
|
|
|
|
iface->is_active = gimp_progress_box_progress_is_active;
|
|
|
|
iface->set_text = gimp_progress_box_progress_set_text;
|
|
|
|
iface->set_value = gimp_progress_box_progress_set_value;
|
|
|
|
iface->get_value = gimp_progress_box_progress_get_value;
|
|
|
|
iface->pulse = gimp_progress_box_progress_pulse;
|
2004-08-11 06:21:56 +08:00
|
|
|
}
|
|
|
|
|
2008-10-22 19:01:15 +08:00
|
|
|
static void
|
2010-09-27 04:38:01 +08:00
|
|
|
gimp_progress_box_dispose (GObject *object)
|
2008-10-22 19:01:15 +08:00
|
|
|
{
|
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (object);
|
|
|
|
|
2010-09-27 04:38:01 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2008-10-22 19:01:15 +08:00
|
|
|
|
|
|
|
box->progress = NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
static GimpProgress *
|
|
|
|
gimp_progress_box_progress_start (GimpProgress *progress,
|
2014-07-13 05:45:20 +08:00
|
|
|
gboolean cancellable,
|
|
|
|
const gchar *message)
|
2004-08-11 06:21:56 +08:00
|
|
|
{
|
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (progress);
|
|
|
|
|
2008-10-22 19:01:15 +08:00
|
|
|
if (! box->progress)
|
|
|
|
return NULL;
|
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
if (! box->active)
|
|
|
|
{
|
|
|
|
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (box->label), message);
|
|
|
|
gtk_progress_bar_set_fraction (bar, 0.0);
|
|
|
|
|
2014-07-13 05:45:20 +08:00
|
|
|
box->active = TRUE;
|
|
|
|
box->cancellable = cancellable;
|
|
|
|
box->value = 0.0;
|
2004-08-11 06:21:56 +08:00
|
|
|
|
2009-10-18 02:20:39 +08:00
|
|
|
if (gtk_widget_is_drawable (box->progress))
|
2009-03-23 00:35:53 +08:00
|
|
|
gdk_window_process_updates (gtk_widget_get_window (box->progress),
|
|
|
|
TRUE);
|
2007-05-22 18:07:36 +08:00
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_progress_box_progress_end (GimpProgress *progress)
|
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
if (gimp_progress_box_progress_is_active (progress))
|
2004-08-11 06:21:56 +08:00
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (progress);
|
|
|
|
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
|
2004-08-11 06:21:56 +08:00
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (box->label), "");
|
|
|
|
gtk_progress_bar_set_fraction (bar, 0.0);
|
|
|
|
|
2014-07-13 05:45:20 +08:00
|
|
|
box->active = FALSE;
|
|
|
|
box->cancellable = FALSE;
|
|
|
|
box->value = 0.0;
|
2004-08-11 06:21:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 18:29:56 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_progress_box_progress_is_active (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (progress);
|
|
|
|
|
2008-10-22 19:01:15 +08:00
|
|
|
return (box->progress && box->active);
|
2004-08-11 18:29:56 +08:00
|
|
|
}
|
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
static void
|
|
|
|
gimp_progress_box_progress_set_text (GimpProgress *progress,
|
|
|
|
const gchar *message)
|
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
if (gimp_progress_box_progress_is_active (progress))
|
2004-08-11 06:21:56 +08:00
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (progress);
|
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (box->label), message);
|
2007-05-22 18:07:36 +08:00
|
|
|
|
2009-10-18 02:20:39 +08:00
|
|
|
if (gtk_widget_is_drawable (box->progress))
|
2009-03-23 00:35:53 +08:00
|
|
|
gdk_window_process_updates (gtk_widget_get_window (box->progress),
|
|
|
|
TRUE);
|
2004-08-11 06:21:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_progress_box_progress_set_value (GimpProgress *progress,
|
|
|
|
gdouble percentage)
|
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
if (gimp_progress_box_progress_is_active (progress))
|
2004-08-11 06:21:56 +08:00
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (progress);
|
|
|
|
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
|
2010-01-15 22:33:08 +08:00
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (bar), &allocation);
|
2004-08-11 06:21:56 +08:00
|
|
|
|
2007-12-31 01:25:58 +08:00
|
|
|
box->value = percentage;
|
2004-08-11 06:21:56 +08:00
|
|
|
|
2007-12-31 01:25:58 +08:00
|
|
|
/* only update the progress bar if this causes a visible change */
|
2010-01-15 22:33:08 +08:00
|
|
|
if (fabs (allocation.width *
|
2007-12-31 01:25:58 +08:00
|
|
|
(percentage - gtk_progress_bar_get_fraction (bar))) > 1.0)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_set_fraction (bar, box->value);
|
|
|
|
|
2014-07-11 06:40:56 +08:00
|
|
|
gimp_widget_flush_expose (box->progress);
|
2007-12-31 01:25:58 +08:00
|
|
|
}
|
2004-08-11 06:21:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble
|
|
|
|
gimp_progress_box_progress_get_value (GimpProgress *progress)
|
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
if (gimp_progress_box_progress_is_active (progress))
|
|
|
|
{
|
|
|
|
return GIMP_PROGRESS_BOX (progress)->value;
|
|
|
|
}
|
2004-08-11 06:21:56 +08:00
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2005-02-12 22:18:12 +08:00
|
|
|
static void
|
|
|
|
gimp_progress_box_progress_pulse (GimpProgress *progress)
|
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
if (gimp_progress_box_progress_is_active (progress))
|
2005-02-12 22:18:12 +08:00
|
|
|
{
|
2008-10-22 19:01:15 +08:00
|
|
|
GimpProgressBox *box = GIMP_PROGRESS_BOX (progress);
|
|
|
|
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
|
2005-02-12 22:18:12 +08:00
|
|
|
|
|
|
|
gtk_progress_bar_pulse (bar);
|
|
|
|
|
2009-10-18 02:20:39 +08:00
|
|
|
if (gtk_widget_is_drawable (box->progress))
|
2009-03-23 00:35:53 +08:00
|
|
|
gdk_window_process_updates (gtk_widget_get_window (box->progress),
|
|
|
|
TRUE);
|
2005-02-12 22:18:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_progress_box_new (void)
|
|
|
|
{
|
2007-02-01 20:06:21 +08:00
|
|
|
return g_object_new (GIMP_TYPE_PROGRESS_BOX, NULL);
|
2004-08-11 06:21:56 +08:00
|
|
|
}
|