2001-02-05 23:22:20 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-25 01:16:46 +08:00
|
|
|
* gimpview.c
|
2001-10-18 00:11:28 +08:00
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
2001-02-05 23:22:20 +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 <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-05-03 20:26:05 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-02-05 23:22:20 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2002-03-22 23:47:59 +08:00
|
|
|
#include "core/gimpviewable.h"
|
2001-02-23 11:29:53 +08:00
|
|
|
|
2001-03-05 06:07:19 +08:00
|
|
|
#include "gimpdnd.h"
|
2004-08-25 01:16:46 +08:00
|
|
|
#include "gimpview.h"
|
2004-08-26 06:31:44 +08:00
|
|
|
#include "gimpview-popup.h"
|
|
|
|
#include "gimpviewrenderer.h"
|
2004-08-26 22:20:30 +08:00
|
|
|
#include "gimpviewrenderer-utils.h"
|
2001-05-08 11:48:54 +08:00
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
#define VIEW_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \
|
|
|
|
GDK_BUTTON_RELEASE_MASK | \
|
|
|
|
GDK_ENTER_NOTIFY_MASK | \
|
|
|
|
GDK_LEAVE_NOTIFY_MASK)
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2003-04-04 00:13:12 +08:00
|
|
|
|
2001-02-07 05:43:59 +08:00
|
|
|
enum
|
|
|
|
{
|
2005-03-26 01:16:07 +08:00
|
|
|
SET_VIEWABLE,
|
2001-02-07 05:43:59 +08:00
|
|
|
CLICKED,
|
2001-02-13 08:12:15 +08:00
|
|
|
DOUBLE_CLICKED,
|
2001-07-09 05:44:52 +08:00
|
|
|
CONTEXT,
|
2001-02-07 05:43:59 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
static void gimp_view_class_init (GimpViewClass *klass);
|
|
|
|
static void gimp_view_init (GimpView *view);
|
2002-01-31 01:39:56 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
static void gimp_view_destroy (GtkObject *object);
|
|
|
|
static void gimp_view_realize (GtkWidget *widget);
|
|
|
|
static void gimp_view_unrealize (GtkWidget *widget);
|
|
|
|
static void gimp_view_map (GtkWidget *widget);
|
|
|
|
static void gimp_view_unmap (GtkWidget *widget);
|
|
|
|
static void gimp_view_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
|
|
|
static void gimp_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean gimp_view_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
static gboolean gimp_view_button_press_event (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static gboolean gimp_view_button_release_event (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static gboolean gimp_view_enter_notify_event (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event);
|
|
|
|
static gboolean gimp_view_leave_notify_event (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2005-03-26 01:16:07 +08:00
|
|
|
static void gimp_view_real_set_viewable (GimpView *view,
|
2005-03-26 02:58:04 +08:00
|
|
|
GimpViewable *old,
|
2005-03-26 01:16:07 +08:00
|
|
|
GimpViewable *viewable);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
static void gimp_view_update_callback (GimpViewRenderer *renderer,
|
|
|
|
GimpView *view);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
static GimpViewable * gimp_view_drag_viewable (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2003-04-04 00:13:12 +08:00
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
static guint view_signals[LAST_SIGNAL] = { 0 };
|
2001-02-07 05:43:59 +08:00
|
|
|
|
2003-04-11 16:37:26 +08:00
|
|
|
static GtkWidgetClass *parent_class = NULL;
|
2001-02-05 23:22:20 +08:00
|
|
|
|
|
|
|
|
2001-08-07 08:06:06 +08:00
|
|
|
GType
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_get_type (void)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
static GType view_type = 0;
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (! view_type)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
static const GTypeInfo view_info =
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
sizeof (GimpViewClass),
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2004-08-25 01:16:46 +08:00
|
|
|
(GClassInitFunc) gimp_view_class_init,
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2004-08-25 01:16:46 +08:00
|
|
|
sizeof (GimpView),
|
2001-10-17 19:33:43 +08:00
|
|
|
0, /* n_preallocs */
|
2004-08-25 01:16:46 +08:00
|
|
|
(GInstanceInitFunc) gimp_view_init,
|
2001-02-05 23:22:20 +08:00
|
|
|
};
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view_type = g_type_register_static (GTK_TYPE_WIDGET,
|
|
|
|
"GimpView",
|
|
|
|
&view_info, 0);
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
2003-02-27 21:59:41 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return view_type;
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_class_init (GimpViewClass *klass)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2005-03-26 01:16:07 +08:00
|
|
|
view_signals[SET_VIEWABLE] =
|
|
|
|
g_signal_new ("set-viewable",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpViewClass, set_viewable),
|
|
|
|
NULL, NULL,
|
2005-03-26 02:58:04 +08:00
|
|
|
gimp_marshal_VOID__OBJECT_OBJECT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
GIMP_TYPE_VIEWABLE, GIMP_TYPE_VIEWABLE);
|
2005-03-26 01:16:07 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view_signals[CLICKED] =
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_new ("clicked",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpViewClass, clicked),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__FLAGS,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GDK_TYPE_MODIFIER_TYPE);
|
|
|
|
|
|
|
|
view_signals[DOUBLE_CLICKED] =
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_new ("double_clicked",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpViewClass, double_clicked),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
view_signals[CONTEXT] =
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_new ("context",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpViewClass, context),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
object_class->destroy = gimp_view_destroy;
|
|
|
|
|
|
|
|
widget_class->activate_signal = view_signals[CLICKED];
|
|
|
|
widget_class->realize = gimp_view_realize;
|
|
|
|
widget_class->unrealize = gimp_view_unrealize;
|
|
|
|
widget_class->map = gimp_view_map;
|
|
|
|
widget_class->unmap = gimp_view_unmap;
|
|
|
|
widget_class->size_request = gimp_view_size_request;
|
|
|
|
widget_class->size_allocate = gimp_view_size_allocate;
|
|
|
|
widget_class->expose_event = gimp_view_expose_event;
|
|
|
|
widget_class->button_press_event = gimp_view_button_press_event;
|
|
|
|
widget_class->button_release_event = gimp_view_button_release_event;
|
|
|
|
widget_class->enter_notify_event = gimp_view_enter_notify_event;
|
|
|
|
widget_class->leave_notify_event = gimp_view_leave_notify_event;
|
2001-02-07 05:43:59 +08:00
|
|
|
|
2005-03-26 01:16:07 +08:00
|
|
|
klass->set_viewable = gimp_view_real_set_viewable;
|
2001-06-18 21:10:03 +08:00
|
|
|
klass->clicked = NULL;
|
|
|
|
klass->double_clicked = NULL;
|
2001-07-09 05:44:52 +08:00
|
|
|
klass->context = NULL;
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_init (GimpView *view)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (view, GTK_NO_WINDOW);
|
2003-04-11 16:37:26 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->viewable = NULL;
|
|
|
|
view->renderer = NULL;
|
2001-02-08 02:01:54 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->clickable = FALSE;
|
|
|
|
view->eat_button_events = TRUE;
|
|
|
|
view->show_popup = FALSE;
|
|
|
|
view->expand = FALSE;
|
2001-02-07 05:43:59 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->in_button = FALSE;
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_destroy (GtkObject *object)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (object);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->viewable)
|
|
|
|
gimp_view_set_viewable (view, NULL);
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->renderer)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
g_object_unref (view->renderer);
|
|
|
|
view->renderer = NULL;
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
|
2002-03-22 23:21:18 +08:00
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
2003-04-04 00:13:12 +08:00
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_realize (GtkWidget *widget)
|
2003-04-04 00:13:12 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2003-04-11 16:37:26 +08:00
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
|
|
|
|
2003-04-04 00:13:12 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->realize (widget);
|
2003-08-14 07:28:26 +08:00
|
|
|
|
2003-04-11 16:37:26 +08:00
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.x = widget->allocation.x;
|
|
|
|
attributes.y = widget->allocation.y;
|
|
|
|
attributes.width = widget->allocation.width;
|
|
|
|
attributes.height = widget->allocation.height;
|
2003-08-14 07:28:26 +08:00
|
|
|
|
2003-04-11 16:37:26 +08:00
|
|
|
attributes.wclass = GDK_INPUT_ONLY;
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget);
|
2004-08-25 01:16:46 +08:00
|
|
|
attributes.event_mask |= VIEW_EVENT_MASK;
|
2003-04-04 00:13:12 +08:00
|
|
|
|
2003-04-11 16:37:26 +08:00
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->event_window = gdk_window_new (widget->window,
|
|
|
|
&attributes, attributes_mask);
|
|
|
|
gdk_window_set_user_data (view->event_window, view);
|
2003-04-11 16:37:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_unrealize (GtkWidget *widget)
|
2003-04-11 16:37:26 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2003-04-11 16:37:26 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->event_window)
|
2003-04-11 16:37:26 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_window_set_user_data (view->event_window, NULL);
|
|
|
|
gdk_window_destroy (view->event_window);
|
|
|
|
view->event_window = NULL;
|
2003-04-11 16:37:26 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->renderer)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_unrealize (view->renderer);
|
2003-11-13 23:04:13 +08:00
|
|
|
|
2003-04-11 16:37:26 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_map (GtkWidget *widget)
|
2003-04-11 16:37:26 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2003-04-11 16:37:26 +08:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->map (widget);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->event_window)
|
|
|
|
gdk_window_show (view->event_window);
|
2003-04-11 16:37:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_unmap (GtkWidget *widget)
|
2003-04-11 16:37:26 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2003-04-11 16:37:26 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->has_grab)
|
2003-08-14 07:28:26 +08:00
|
|
|
gtk_grab_remove (widget);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->event_window)
|
|
|
|
gdk_window_hide (view->event_window);
|
2003-04-11 16:37:26 +08:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
|
2003-04-04 00:13:12 +08:00
|
|
|
}
|
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
2003-03-03 20:59:03 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2003-03-03 20:59:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->expand)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
requisition->width = 2 * view->renderer->border_width + 1;
|
|
|
|
requisition->height = 2 * view->renderer->border_width + 1;
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
requisition->width = (view->renderer->width +
|
|
|
|
2 * view->renderer->border_width);
|
|
|
|
requisition->height = (view->renderer->height +
|
|
|
|
2 * view->renderer->border_width);
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
2003-03-03 20:59:03 +08:00
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->size_request)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
|
|
|
|
}
|
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
static void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2004-08-25 01:16:46 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->expand)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2003-04-01 21:53:47 +08:00
|
|
|
width = MIN (GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
|
2004-08-25 01:16:46 +08:00
|
|
|
allocation->width - 2 * view->renderer->border_width);
|
2003-04-01 21:53:47 +08:00
|
|
|
height = MIN (GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
|
2004-08-25 01:16:46 +08:00
|
|
|
allocation->height - 2 * view->renderer->border_width);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->renderer->width != width ||
|
|
|
|
view->renderer->height != height)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
gint border_width = view->renderer->border_width;
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->renderer->size != -1 && view->renderer->viewable)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
gint view_width;
|
|
|
|
gint view_height;
|
2003-03-10 22:07:22 +08:00
|
|
|
gint scaled_width;
|
|
|
|
gint scaled_height;
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_viewable_get_preview_size (view->renderer->viewable,
|
2003-04-01 21:53:47 +08:00
|
|
|
GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
|
2004-08-25 01:16:46 +08:00
|
|
|
view->renderer->is_popup,
|
|
|
|
view->renderer->dot_for_dot,
|
|
|
|
&view_width,
|
|
|
|
&view_height);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_viewable_calc_preview_size (view_width, view_height,
|
2003-03-10 22:07:22 +08:00
|
|
|
width, height,
|
|
|
|
TRUE, 1.0, 1.0,
|
|
|
|
&scaled_width, &scaled_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (scaled_width > width)
|
|
|
|
{
|
|
|
|
scaled_height = scaled_height * width / scaled_width;
|
|
|
|
scaled_width = scaled_width * width / scaled_width;
|
|
|
|
}
|
|
|
|
else if (scaled_height > height)
|
|
|
|
{
|
|
|
|
scaled_width = scaled_width * height / scaled_height;
|
|
|
|
scaled_height = scaled_height * height / scaled_height;
|
|
|
|
}
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size (view->renderer,
|
|
|
|
MAX (scaled_width, scaled_height),
|
|
|
|
border_width);
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size_full (view->renderer,
|
|
|
|
width, height,
|
|
|
|
border_width);
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_remove_idle (view->renderer);
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
width = (view->renderer->width +
|
|
|
|
2 * view->renderer->border_width);
|
|
|
|
height = (view->renderer->height +
|
|
|
|
2 * view->renderer->border_width);
|
2002-06-12 23:39:03 +08:00
|
|
|
|
|
|
|
if (allocation->width > width)
|
|
|
|
allocation->x += (allocation->width - width) / 2;
|
|
|
|
|
|
|
|
if (allocation->height > height)
|
|
|
|
allocation->y += (allocation->height - height) / 2;
|
|
|
|
|
|
|
|
allocation->width = width;
|
|
|
|
allocation->height = height;
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2003-04-11 16:37:26 +08:00
|
|
|
widget->allocation = *allocation;
|
|
|
|
|
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_window_move_resize (view->event_window,
|
|
|
|
allocation->x,
|
|
|
|
allocation->y,
|
|
|
|
allocation->width,
|
2003-04-11 16:37:26 +08:00
|
|
|
allocation->height);
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_expose_event (GtkWidget *widget,
|
2002-02-01 00:47:20 +08:00
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
2003-02-27 00:17:10 +08:00
|
|
|
if (! GTK_WIDGET_DRAWABLE (widget))
|
2002-02-01 00:47:20 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_draw (GIMP_VIEW (widget)->renderer,
|
|
|
|
widget->window, widget,
|
|
|
|
&widget->allocation,
|
|
|
|
&event->area);
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-02-07 19:33:01 +08:00
|
|
|
|
|
|
|
#define DEBUG_MEMSIZE 1
|
|
|
|
|
|
|
|
#ifdef DEBUG_MEMSIZE
|
|
|
|
extern gboolean gimp_debug_memsize;
|
|
|
|
#endif
|
|
|
|
|
2002-03-22 23:47:59 +08:00
|
|
|
static gboolean
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_button_press_event (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_MEMSIZE
|
|
|
|
if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 2)
|
|
|
|
{
|
2002-02-07 19:33:01 +08:00
|
|
|
gimp_debug_memsize = TRUE;
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_object_get_memsize (GIMP_OBJECT (view->viewable), NULL);
|
2002-02-07 19:33:01 +08:00
|
|
|
|
|
|
|
gimp_debug_memsize = FALSE;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
#endif /* DEBUG_MEMSIZE */
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (! view->clickable &&
|
|
|
|
! view->show_popup)
|
2002-02-01 00:47:20 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2003-08-14 07:28:26 +08:00
|
|
|
if (! GTK_WIDGET_REALIZED (widget))
|
|
|
|
return FALSE;
|
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
if (bevent->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
if (bevent->button == 1)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
gtk_grab_add (widget);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->has_grab = TRUE;
|
|
|
|
view->press_state = bevent->state;
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->show_popup && view->viewable)
|
2003-02-27 21:59:41 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_popup_show (widget, bevent,
|
|
|
|
view->viewable,
|
|
|
|
view->renderer->width,
|
|
|
|
view->renderer->height,
|
|
|
|
view->renderer->dot_for_dot);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
|
|
|
}
|
2002-02-01 00:47:20 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
view->press_state = 0;
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-05 21:43:38 +08:00
|
|
|
if (bevent->button == 2)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_popup_show (widget, bevent,
|
|
|
|
view->viewable,
|
|
|
|
view->renderer->width,
|
|
|
|
view->renderer->height,
|
|
|
|
view->renderer->dot_for_dot);
|
2004-08-05 21:43:38 +08:00
|
|
|
|
2003-02-27 21:59:41 +08:00
|
|
|
if (bevent->button == 3)
|
2004-08-25 01:16:46 +08:00
|
|
|
g_signal_emit (widget, view_signals[CONTEXT], 0);
|
|
|
|
else
|
2003-08-14 07:28:26 +08:00
|
|
|
return FALSE;
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
else if (bevent->type == GDK_2BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
if (bevent->button == 1)
|
2004-08-25 01:16:46 +08:00
|
|
|
g_signal_emit (widget, view_signals[DOUBLE_CLICKED], 0);
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return view->eat_button_events ? TRUE : FALSE;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
2003-08-14 07:28:26 +08:00
|
|
|
|
2002-03-22 23:47:59 +08:00
|
|
|
static gboolean
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_button_release_event (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (! view->clickable &&
|
|
|
|
! view->show_popup)
|
2002-02-01 00:47:20 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
|
|
|
gtk_grab_remove (widget);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->has_grab = FALSE;
|
2003-08-14 07:28:26 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->clickable && view->in_button)
|
|
|
|
{
|
2005-03-26 01:16:07 +08:00
|
|
|
g_signal_emit (widget, view_signals[CLICKED], 0, view->press_state);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return view->eat_button_events ? TRUE : FALSE;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
2002-03-22 23:47:59 +08:00
|
|
|
static gboolean
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_enter_notify_event (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
|
|
|
GtkWidget *event_widget = gtk_get_event_widget ((GdkEvent *) event);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
|
|
|
if ((event_widget == widget) &&
|
|
|
|
(event->detail != GDK_NOTIFY_INFERIOR))
|
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
view->in_button = TRUE;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-22 23:47:59 +08:00
|
|
|
static gboolean
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_leave_notify_event (GtkWidget *widget,
|
2004-08-26 06:31:44 +08:00
|
|
|
GdkEventCrossing *event)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
|
|
|
GtkWidget *event_widget = gtk_get_event_widget ((GdkEvent *) event);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
|
|
|
if ((event_widget == widget) &&
|
|
|
|
(event->detail != GDK_NOTIFY_INFERIOR))
|
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
view->in_button = FALSE;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-03-26 01:16:07 +08:00
|
|
|
static void
|
|
|
|
gimp_view_real_set_viewable (GimpView *view,
|
2005-03-26 02:58:04 +08:00
|
|
|
GimpViewable *old,
|
2005-03-26 01:16:07 +08:00
|
|
|
GimpViewable *viewable)
|
|
|
|
{
|
|
|
|
GType viewable_type = G_TYPE_NONE;
|
|
|
|
|
|
|
|
if (viewable == view->viewable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (viewable)
|
|
|
|
{
|
|
|
|
viewable_type = G_TYPE_FROM_INSTANCE (viewable);
|
|
|
|
|
|
|
|
g_return_if_fail (g_type_is_a (viewable_type,
|
|
|
|
view->renderer->viewable_type));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->viewable)
|
|
|
|
{
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (view->viewable),
|
|
|
|
(gpointer *) &view->viewable);
|
|
|
|
|
|
|
|
if (! viewable && ! view->renderer->is_popup)
|
|
|
|
{
|
|
|
|
if (gimp_dnd_viewable_source_remove (GTK_WIDGET (view),
|
|
|
|
G_TYPE_FROM_INSTANCE (view->viewable)))
|
|
|
|
{
|
|
|
|
gtk_drag_source_unset (GTK_WIDGET (view));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (viewable && ! view->renderer->is_popup)
|
|
|
|
{
|
|
|
|
if (gimp_dnd_drag_source_set_by_type (GTK_WIDGET (view),
|
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
|
|
|
|
viewable_type,
|
|
|
|
GDK_ACTION_COPY))
|
|
|
|
{
|
|
|
|
gimp_dnd_viewable_source_add (GTK_WIDGET (view),
|
|
|
|
viewable_type,
|
|
|
|
gimp_view_drag_viewable,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_view_renderer_set_viewable (view->renderer, viewable);
|
|
|
|
view->viewable = viewable;
|
|
|
|
|
|
|
|
if (view->viewable)
|
|
|
|
{
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (view->viewable),
|
|
|
|
(gpointer *) &view->viewable);
|
|
|
|
}
|
|
|
|
}
|
2002-02-01 00:47:20 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-06-18 21:10:03 +08:00
|
|
|
GtkWidget *
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_new (GimpViewable *viewable,
|
|
|
|
gint size,
|
|
|
|
gint border_width,
|
|
|
|
gboolean is_popup)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GtkWidget *view;
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2001-06-18 21:10:03 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view = gimp_view_new_by_types (GIMP_TYPE_VIEW,
|
|
|
|
G_TYPE_FROM_INSTANCE (viewable),
|
|
|
|
size, border_width, is_popup);
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view)
|
|
|
|
gimp_view_set_viewable (GIMP_VIEW (view), viewable);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_remove_idle (GIMP_VIEW (view)->renderer);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return view;
|
2001-02-09 23:12:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_new_full (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint border_width,
|
|
|
|
gboolean is_popup,
|
|
|
|
gboolean clickable,
|
|
|
|
gboolean show_popup)
|
2003-03-03 20:59:03 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GtkWidget *view;
|
2003-03-03 20:59:03 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view = gimp_view_new_full_by_types (GIMP_TYPE_VIEW,
|
|
|
|
G_TYPE_FROM_INSTANCE (viewable),
|
|
|
|
width, height, border_width,
|
|
|
|
is_popup, clickable, show_popup);
|
2003-03-03 20:59:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view)
|
|
|
|
gimp_view_set_viewable (GIMP_VIEW (view), viewable);
|
2003-03-03 20:59:03 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_remove_idle (GIMP_VIEW (view)->renderer);
|
2003-03-03 20:59:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return view;
|
2003-03-03 20:59:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_new_by_types (GType view_type,
|
|
|
|
GType viewable_type,
|
|
|
|
gint size,
|
|
|
|
gint border_width,
|
|
|
|
gboolean is_popup)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
GimpView *view;
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (view_type, GIMP_TYPE_VIEW), NULL);
|
2003-03-03 20:59:03 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (viewable_type, GIMP_TYPE_VIEWABLE), NULL);
|
2003-04-01 21:53:47 +08:00
|
|
|
g_return_val_if_fail (size > 0 &&
|
|
|
|
size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
2002-08-27 23:31:24 +08:00
|
|
|
g_return_val_if_fail (border_width >= 0 &&
|
2004-08-26 06:31:44 +08:00
|
|
|
border_width <= GIMP_VIEW_MAX_BORDER_WIDTH, NULL);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer = gimp_view_renderer_new (viewable_type, size,
|
|
|
|
border_width, is_popup);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (renderer != NULL, NULL);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view = g_object_new (view_type, NULL);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_connect (renderer, "update",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_CALLBACK (gimp_view_update_callback),
|
|
|
|
view);
|
2001-02-08 07:14:14 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->renderer = renderer;
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return GTK_WIDGET (view);
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
2002-08-22 20:49:01 +08:00
|
|
|
GtkWidget *
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_new_full_by_types (GType view_type,
|
|
|
|
GType viewable_type,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint border_width,
|
|
|
|
gboolean is_popup,
|
|
|
|
gboolean clickable,
|
|
|
|
gboolean show_popup)
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
GimpView *view;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (view_type, GIMP_TYPE_VIEW), NULL);
|
2002-08-22 20:49:01 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (viewable_type, GIMP_TYPE_VIEWABLE), NULL);
|
2003-04-01 21:53:47 +08:00
|
|
|
g_return_val_if_fail (width > 0 &&
|
|
|
|
width <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
|
|
|
g_return_val_if_fail (height > 0 &&
|
|
|
|
height <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
2002-08-27 23:31:24 +08:00
|
|
|
g_return_val_if_fail (border_width >= 0 &&
|
2004-08-26 06:31:44 +08:00
|
|
|
border_width <= GIMP_VIEW_MAX_BORDER_WIDTH, NULL);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer = gimp_view_renderer_new_full (viewable_type, width, height,
|
|
|
|
border_width, is_popup);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (renderer != NULL, NULL);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view = g_object_new (view_type, NULL);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_connect (renderer, "update",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_CALLBACK (gimp_view_update_callback),
|
|
|
|
view);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
view->renderer = renderer;
|
|
|
|
view->clickable = clickable ? TRUE : FALSE;
|
|
|
|
view->show_popup = show_popup ? TRUE : FALSE;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
return GTK_WIDGET (view);
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|
|
|
|
|
2005-03-26 01:16:07 +08:00
|
|
|
GimpViewable *
|
|
|
|
gimp_view_get_viewable (GimpView *view)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
return view->viewable;
|
|
|
|
}
|
|
|
|
|
2001-02-08 12:16:41 +08:00
|
|
|
void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_set_viewable (GimpView *view,
|
|
|
|
GimpViewable *viewable)
|
2001-02-08 12:16:41 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW (view));
|
2003-04-01 21:53:47 +08:00
|
|
|
g_return_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable));
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (viewable == view->viewable)
|
2003-11-17 21:34:38 +08:00
|
|
|
return;
|
|
|
|
|
2005-03-26 02:58:04 +08:00
|
|
|
g_signal_emit (view, view_signals[SET_VIEWABLE], 0, view->viewable, viewable);
|
2001-02-08 12:16:41 +08:00
|
|
|
}
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
void
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_set_expand (GimpView *view,
|
|
|
|
gboolean expand)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW (view));
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->expand != expand)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
view->expand = expand ? TRUE : FALSE;
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (view));
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
/* private functions */
|
2001-02-07 05:43:59 +08:00
|
|
|
|
2002-11-04 20:15:29 +08:00
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_update_callback (GimpViewRenderer *renderer,
|
|
|
|
GimpView *view)
|
2002-11-04 20:15:29 +08:00
|
|
|
{
|
2004-10-09 02:09:41 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (view);
|
2003-03-01 11:53:41 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2002-11-04 20:15:29 +08:00
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
width = renderer->width + 2 * renderer->border_width;
|
|
|
|
height = renderer->height + 2 * renderer->border_width;
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
if (width != widget->requisition.width ||
|
|
|
|
height != widget->requisition.height)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2003-03-03 20:59:03 +08:00
|
|
|
widget->requisition.width = width;
|
|
|
|
widget->requisition.height = height;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
gtk_widget_queue_resize (widget);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2002-11-04 20:15:29 +08:00
|
|
|
else
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
gtk_widget_queue_draw (widget);
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
static GimpViewable *
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_drag_viewable (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
return GIMP_VIEW (widget)->viewable;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|