2001-02-05 06:10:54 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-04-22 08:38:56 +08:00
|
|
|
* gimpviewable.h
|
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2001-02-05 06:10:54 +08:00
|
|
|
* 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>
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-02-05 06:10:54 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-02-05 06:10:54 +08:00
|
|
|
#include "gimpmarshal.h"
|
|
|
|
#include "gimpviewable.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
INVALIDATE_PREVIEW,
|
2001-02-07 08:06:58 +08:00
|
|
|
GET_PREVIEW,
|
|
|
|
GET_NEW_PREVIEW,
|
2001-02-05 06:10:54 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-05-07 00:14:34 +08:00
|
|
|
static void gimp_viewable_class_init (GimpViewableClass *klass);
|
|
|
|
static void gimp_viewable_init (GimpViewable *viewable);
|
|
|
|
|
|
|
|
static void gimp_viewable_real_invalidate_preview (GimpViewable *viewable);
|
2001-02-05 06:10:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
static guint viewable_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GimpObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GtkType
|
|
|
|
gimp_viewable_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType viewable_type = 0;
|
|
|
|
|
|
|
|
if (! viewable_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo viewable_info =
|
|
|
|
{
|
|
|
|
"GimpViewable",
|
|
|
|
sizeof (GimpViewable),
|
|
|
|
sizeof (GimpViewableClass),
|
|
|
|
(GtkClassInitFunc) gimp_viewable_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_viewable_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
|
|
|
(GtkClassInitFunc) NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
viewable_type = gtk_type_unique (GIMP_TYPE_OBJECT, &viewable_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return viewable_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_viewable_class_init (GimpViewableClass *klass)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass *) klass;
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
|
|
|
|
|
|
|
|
viewable_signals[INVALIDATE_PREVIEW] =
|
|
|
|
gtk_signal_new ("invalidate_preview",
|
|
|
|
GTK_RUN_FIRST,
|
|
|
|
object_class->type,
|
|
|
|
GTK_SIGNAL_OFFSET (GimpViewableClass,
|
|
|
|
invalidate_preview),
|
|
|
|
gtk_signal_default_marshaller,
|
|
|
|
GTK_TYPE_NONE, 0);
|
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
viewable_signals[GET_PREVIEW] =
|
|
|
|
gtk_signal_new ("get_preview",
|
2001-02-05 06:10:54 +08:00
|
|
|
GTK_RUN_LAST,
|
|
|
|
object_class->type,
|
|
|
|
GTK_SIGNAL_OFFSET (GimpViewableClass,
|
2001-02-07 08:06:58 +08:00
|
|
|
get_preview),
|
2001-02-05 06:10:54 +08:00
|
|
|
gimp_marshal_POINTER__INT_INT,
|
|
|
|
GTK_TYPE_POINTER, 3,
|
|
|
|
GTK_TYPE_POINTER,
|
|
|
|
GTK_TYPE_INT,
|
|
|
|
GTK_TYPE_INT);
|
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
viewable_signals[GET_NEW_PREVIEW] =
|
|
|
|
gtk_signal_new ("get_new_preview",
|
2001-02-05 06:10:54 +08:00
|
|
|
GTK_RUN_LAST,
|
|
|
|
object_class->type,
|
|
|
|
GTK_SIGNAL_OFFSET (GimpViewableClass,
|
2001-02-07 08:06:58 +08:00
|
|
|
get_new_preview),
|
2001-02-05 06:10:54 +08:00
|
|
|
gimp_marshal_POINTER__INT_INT,
|
|
|
|
GTK_TYPE_POINTER, 3,
|
|
|
|
GTK_TYPE_POINTER,
|
|
|
|
GTK_TYPE_INT,
|
|
|
|
GTK_TYPE_INT);
|
|
|
|
|
|
|
|
gtk_object_class_add_signals (object_class, viewable_signals, LAST_SIGNAL);
|
|
|
|
|
2001-05-07 00:14:34 +08:00
|
|
|
klass->invalidate_preview = gimp_viewable_real_invalidate_preview;
|
2001-02-07 08:06:58 +08:00
|
|
|
klass->get_preview = NULL;
|
|
|
|
klass->get_new_preview = NULL;
|
2001-02-05 06:10:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_viewable_init (GimpViewable *viewable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_viewable_invalidate_preview (GimpViewable *viewable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (viewable);
|
|
|
|
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
|
|
|
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[INVALIDATE_PREVIEW]);
|
|
|
|
}
|
|
|
|
|
2001-05-07 00:14:34 +08:00
|
|
|
static void
|
|
|
|
gimp_viewable_real_invalidate_preview (GimpViewable *viewable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (viewable);
|
|
|
|
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
|
|
|
|
|
|
|
|
gtk_object_set_data (GTK_OBJECT (viewable), "static-viewable-preview", NULL);
|
|
|
|
}
|
|
|
|
|
2001-02-05 06:10:54 +08:00
|
|
|
TempBuf *
|
2001-02-07 08:06:58 +08:00
|
|
|
gimp_viewable_get_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2001-02-05 06:10:54 +08:00
|
|
|
{
|
|
|
|
TempBuf *temp_buf = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (viewable, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
|
|
|
|
|
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_PREVIEW],
|
2001-02-05 06:10:54 +08:00
|
|
|
width, height, &temp_buf);
|
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
if (temp_buf)
|
|
|
|
return temp_buf;
|
|
|
|
|
|
|
|
temp_buf = gtk_object_get_data (GTK_OBJECT (viewable),
|
2001-05-07 00:14:34 +08:00
|
|
|
"static-viewable-preview");
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-05-07 00:14:34 +08:00
|
|
|
if (temp_buf &&
|
|
|
|
temp_buf->width == width &&
|
|
|
|
temp_buf->height == height)
|
|
|
|
return temp_buf;
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-05-07 00:14:34 +08:00
|
|
|
temp_buf = NULL;
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_NEW_PREVIEW],
|
2001-02-06 05:52:57 +08:00
|
|
|
width, height, &temp_buf);
|
|
|
|
|
2001-05-07 00:14:34 +08:00
|
|
|
gtk_object_set_data_full (GTK_OBJECT (viewable), "static-viewable-preview",
|
|
|
|
temp_buf,
|
|
|
|
(GtkDestroyNotify) temp_buf_free);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-02-05 06:10:54 +08:00
|
|
|
return temp_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
TempBuf *
|
2001-02-07 08:06:58 +08:00
|
|
|
gimp_viewable_get_new_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2001-02-05 06:10:54 +08:00
|
|
|
{
|
|
|
|
TempBuf *temp_buf = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (viewable, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
|
|
|
|
|
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_NEW_PREVIEW],
|
2001-02-05 06:10:54 +08:00
|
|
|
width, height, &temp_buf);
|
|
|
|
|
|
|
|
if (temp_buf)
|
|
|
|
return temp_buf;
|
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_PREVIEW],
|
|
|
|
width, height, &temp_buf);
|
2001-02-05 06:10:54 +08:00
|
|
|
|
|
|
|
if (temp_buf)
|
|
|
|
return temp_buf_copy (temp_buf, NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|