2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-02-20 23:40:15 +08:00
|
|
|
* 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 "widgets-types.h"
|
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2003-02-20 23:40:15 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
#include "gimpdocked.h"
|
2003-02-20 23:40:15 +08:00
|
|
|
#include "gimpimageeditor.h"
|
2004-05-13 02:36:33 +08:00
|
|
|
#include "gimpuimanager.h"
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static void gimp_image_editor_docked_iface_init (GimpDockedInterface *iface);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2004-05-23 18:04:41 +08:00
|
|
|
static void gimp_image_editor_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context);
|
|
|
|
static void gimp_image_editor_destroy (GtkObject *object);
|
|
|
|
static void gimp_image_editor_real_set_image (GimpImageEditor *editor,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image);
|
|
|
|
static void gimp_image_editor_image_flush (GimpImage *image,
|
2007-06-27 05:39:51 +08:00
|
|
|
gboolean invalidate_preview,
|
2004-05-23 18:04:41 +08:00
|
|
|
GimpImageEditor *editor);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpImageEditor, gimp_image_editor, GIMP_TYPE_EDITOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_image_editor_docked_iface_init))
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_image_editor_parent_class
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_image_editor_class_init (GimpImageEditorClass *klass)
|
|
|
|
{
|
2004-05-13 02:36:33 +08:00
|
|
|
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
object_class->destroy = gimp_image_editor_destroy;
|
|
|
|
|
|
|
|
klass->set_image = gimp_image_editor_real_set_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_image_editor_init (GimpImageEditor *editor)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
editor->image = NULL;
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
|
|
|
|
}
|
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
static void
|
2005-12-20 06:37:49 +08:00
|
|
|
gimp_image_editor_docked_iface_init (GimpDockedInterface *iface)
|
2003-10-11 05:24:12 +08:00
|
|
|
{
|
2005-12-20 06:37:49 +08:00
|
|
|
iface->set_context = gimp_image_editor_set_context;
|
2003-10-11 05:24:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-23 18:04:41 +08:00
|
|
|
gimp_image_editor_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context)
|
2003-10-11 05:24:12 +08:00
|
|
|
{
|
|
|
|
GimpImageEditor *editor = GIMP_IMAGE_EDITOR (docked);
|
2004-10-31 19:46:00 +08:00
|
|
|
GimpImage *image = NULL;
|
2003-10-11 05:24:12 +08:00
|
|
|
|
2004-05-23 18:04:41 +08:00
|
|
|
if (editor->context)
|
2004-10-25 20:42:23 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (editor->context,
|
|
|
|
gimp_image_editor_set_image,
|
|
|
|
editor);
|
2004-05-23 18:04:41 +08:00
|
|
|
|
|
|
|
editor->context = context;
|
2003-10-11 05:24:12 +08:00
|
|
|
|
|
|
|
if (context)
|
2004-10-31 19:46:00 +08:00
|
|
|
{
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect_swapped (context, "image-changed",
|
2004-10-31 19:46:00 +08:00
|
|
|
G_CALLBACK (gimp_image_editor_set_image),
|
|
|
|
editor);
|
|
|
|
|
|
|
|
image = gimp_context_get_image (context);
|
|
|
|
}
|
2003-10-11 05:24:12 +08:00
|
|
|
|
2004-10-31 19:46:00 +08:00
|
|
|
gimp_image_editor_set_image (editor, image);
|
2003-10-11 05:24:12 +08:00
|
|
|
}
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
static void
|
|
|
|
gimp_image_editor_destroy (GtkObject *object)
|
|
|
|
{
|
2004-05-13 02:36:33 +08:00
|
|
|
GimpImageEditor *editor = GIMP_IMAGE_EDITOR (object);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (editor->image)
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_image_editor_set_image (editor, NULL);
|
|
|
|
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_image_editor_real_set_image (GimpImageEditor *editor,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-02-20 23:40:15 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
if (editor->image)
|
|
|
|
g_signal_handlers_disconnect_by_func (editor->image,
|
2004-05-13 02:36:33 +08:00
|
|
|
gimp_image_editor_image_flush,
|
|
|
|
editor);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
editor->image = image;
|
2003-03-20 22:34:16 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (editor->image)
|
|
|
|
g_signal_connect (editor->image, "flush",
|
2004-05-13 02:36:33 +08:00
|
|
|
G_CALLBACK (gimp_image_editor_image_flush),
|
|
|
|
editor);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (editor), image != NULL);
|
2003-02-20 23:40:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_editor_set_image (GimpImageEditor *editor,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-02-20 23:40:15 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE_EDITOR (editor));
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image != editor->image)
|
2004-05-13 02:36:33 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GIMP_IMAGE_EDITOR_GET_CLASS (editor)->set_image (editor, image);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2004-05-13 02:36:33 +08:00
|
|
|
if (GIMP_EDITOR (editor)->ui_manager)
|
|
|
|
gimp_ui_manager_update (GIMP_EDITOR (editor)->ui_manager,
|
|
|
|
GIMP_EDITOR (editor)->popup_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-17 01:02:14 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_image_editor_get_image (GimpImageEditor *editor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE_EDITOR (editor), NULL);
|
|
|
|
|
|
|
|
return editor->image;
|
|
|
|
}
|
|
|
|
|
2004-05-13 02:36:33 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_editor_image_flush (GimpImage *image,
|
2007-06-27 05:39:51 +08:00
|
|
|
gboolean invalidate_preview,
|
2004-05-13 02:36:33 +08:00
|
|
|
GimpImageEditor *editor)
|
|
|
|
{
|
|
|
|
if (GIMP_EDITOR (editor)->ui_manager)
|
|
|
|
gimp_ui_manager_update (GIMP_EDITOR (editor)->ui_manager,
|
|
|
|
GIMP_EDITOR (editor)->popup_data);
|
2003-02-20 23:40:15 +08:00
|
|
|
}
|