2004-08-31 06:10:26 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimppreview.c
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; 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 "gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimppreview.h"
|
|
|
|
|
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
#define PREVIEW_TIMEOUT 200
|
|
|
|
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
enum
|
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
INVALIDATED,
|
2004-08-31 06:10:26 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2004-08-31 22:29:25 +08:00
|
|
|
PROP_UPDATE,
|
|
|
|
PROP_SHOW_UPDATE_TOGGLE
|
2004-08-31 06:10:26 +08:00
|
|
|
};
|
|
|
|
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
static void gimp_preview_class_init (GimpPreviewClass *klass);
|
|
|
|
static void gimp_preview_init (GimpPreview *preview);
|
2004-09-01 07:37:04 +08:00
|
|
|
static void gimp_preview_dispose (GObject *object);
|
2004-08-31 23:13:31 +08:00
|
|
|
static void gimp_preview_get_property (GObject *object,
|
2004-09-01 02:06:36 +08:00
|
|
|
guint property_id,
|
2004-08-31 23:13:31 +08:00
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_preview_set_property (GObject *object,
|
2004-09-01 02:06:36 +08:00
|
|
|
guint property_id,
|
2004-08-31 23:13:31 +08:00
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
static void gimp_preview_draw (GimpPreview *preview);
|
2004-09-01 10:10:40 +08:00
|
|
|
|
|
|
|
static void gimp_preview_area_realize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void gimp_preview_area_unrealize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview);
|
2004-09-01 03:58:25 +08:00
|
|
|
static void gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpPreview *preview);
|
2004-09-01 10:10:40 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
static void gimp_preview_h_scroll (GtkAdjustment *hadj,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void gimp_preview_v_scroll (GtkAdjustment *vadj,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static gboolean gimp_preview_area_event (GtkWidget *area,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void gimp_preview_toggle_callback (GtkWidget *toggle,
|
|
|
|
GimpPreview *preview);
|
|
|
|
|
|
|
|
static guint preview_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GtkTableClass *parent_class = NULL;
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
GType
|
|
|
|
gimp_preview_get_type (void)
|
|
|
|
{
|
|
|
|
static GType preview_type = 0;
|
|
|
|
|
|
|
|
if (!preview_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo preview_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpPreviewClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_preview_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpPreview),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_preview_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
preview_type = g_type_register_static (GTK_TYPE_TABLE,
|
|
|
|
"GimpPreview",
|
|
|
|
&preview_info,
|
|
|
|
G_TYPE_FLAG_ABSTRACT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return preview_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_class_init (GimpPreviewClass *klass)
|
|
|
|
{
|
2004-08-31 06:49:06 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
preview_signals[INVALIDATED] =
|
|
|
|
g_signal_new ("invalidated",
|
2004-08-31 06:10:26 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-31 22:29:25 +08:00
|
|
|
G_STRUCT_OFFSET (GimpPreviewClass, invalidated),
|
2004-08-31 06:10:26 +08:00
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
object_class->dispose = gimp_preview_dispose;
|
2004-08-31 06:10:26 +08:00
|
|
|
object_class->get_property = gimp_preview_get_property;
|
|
|
|
object_class->set_property = gimp_preview_set_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
2004-08-31 22:29:25 +08:00
|
|
|
PROP_UPDATE,
|
|
|
|
g_param_spec_boolean ("update",
|
2004-08-31 06:10:26 +08:00
|
|
|
NULL, NULL,
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
2004-08-31 22:29:25 +08:00
|
|
|
PROP_SHOW_UPDATE_TOGGLE,
|
|
|
|
g_param_spec_boolean ("show_update_toggle",
|
2004-08-31 06:10:26 +08:00
|
|
|
NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
2004-08-31 23:13:31 +08:00
|
|
|
|
|
|
|
klass->draw = NULL;
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_init (GimpPreview *preview)
|
|
|
|
{
|
2004-09-01 10:10:40 +08:00
|
|
|
GtkTable *table = GTK_TABLE (preview);
|
2004-08-31 06:49:06 +08:00
|
|
|
GtkWidget *frame;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
gtk_table_resize (table, 3, 2);
|
|
|
|
gtk_table_set_homogeneous (table, FALSE);
|
2004-09-01 03:58:25 +08:00
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
preview->xoff = 0;
|
|
|
|
preview->yoff = 0;
|
|
|
|
preview->in_drag = FALSE;
|
|
|
|
preview->timeout_id = 0;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
preview->xmin = preview->ymin = 0;
|
|
|
|
preview->xmax = preview->ymax = 1;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
preview->width = preview->xmax - preview->xmin;
|
|
|
|
preview->height = preview->ymax - preview->ymin;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
preview->hadj = gtk_adjustment_new (0, 0, preview->width - 1, 1.0,
|
|
|
|
preview->width, preview->width);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
g_signal_connect (preview->hadj, "value_changed",
|
|
|
|
G_CALLBACK (gimp_preview_h_scroll),
|
|
|
|
preview);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
preview->hscr = gtk_hscrollbar_new (GTK_ADJUSTMENT (preview->hadj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (preview->hscr),
|
|
|
|
GTK_UPDATE_CONTINUOUS);
|
2004-09-01 10:10:40 +08:00
|
|
|
gtk_table_attach (table, preview->hscr, 0,1, 1,2,
|
2004-08-31 06:10:26 +08:00
|
|
|
GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
preview->vadj = gtk_adjustment_new (0, 0, preview->height - 1, 1.0,
|
|
|
|
preview->height, preview->height);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
g_signal_connect (preview->vadj, "value_changed",
|
|
|
|
G_CALLBACK (gimp_preview_v_scroll),
|
|
|
|
preview);
|
|
|
|
|
|
|
|
preview->vscr = gtk_vscrollbar_new (GTK_ADJUSTMENT (preview->vadj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (preview->vscr),
|
|
|
|
GTK_UPDATE_CONTINUOUS);
|
2004-09-01 10:10:40 +08:00
|
|
|
gtk_table_attach (table, preview->vscr, 1,2, 0,1,
|
2004-08-31 06:10:26 +08:00
|
|
|
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
/* the area itself */
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2004-09-01 10:10:40 +08:00
|
|
|
gtk_table_attach (table, frame, 0,1, 0,1, GTK_FILL, GTK_FILL, 0,0);
|
2004-08-31 06:10:26 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
preview->area = gimp_preview_area_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview->area);
|
2004-08-31 06:49:06 +08:00
|
|
|
gtk_widget_show (preview->area);
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
gtk_widget_set_events (preview->area,
|
2004-09-01 02:06:36 +08:00
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
2004-08-31 06:10:26 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
g_signal_connect (preview->area, "event",
|
2004-08-31 23:13:31 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_event),
|
|
|
|
preview);
|
|
|
|
|
|
|
|
g_signal_connect (preview->area, "realize",
|
|
|
|
G_CALLBACK (gimp_preview_area_realize),
|
2004-09-01 10:10:40 +08:00
|
|
|
preview);
|
|
|
|
g_signal_connect (preview->area, "unrealize",
|
|
|
|
G_CALLBACK (gimp_preview_area_unrealize),
|
|
|
|
preview);
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2004-09-01 03:58:25 +08:00
|
|
|
g_signal_connect (preview->area, "size_allocate",
|
|
|
|
G_CALLBACK (gimp_preview_area_size_allocate),
|
|
|
|
preview);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
/* a toggle button to (des)activate the instant preview */
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
preview->toggle_update = gtk_check_button_new_with_mnemonic (_("_Preview"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle_update),
|
|
|
|
preview->update_preview);
|
2004-09-01 07:37:04 +08:00
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (preview), 1, 6);
|
2004-09-01 10:10:40 +08:00
|
|
|
gtk_table_attach (table, preview->toggle_update,
|
2004-09-01 07:37:04 +08:00
|
|
|
0, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
|
2004-08-31 06:10:26 +08:00
|
|
|
g_signal_connect_after (preview->toggle_update, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_toggle_callback),
|
|
|
|
preview);
|
|
|
|
}
|
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
|
|
|
|
if (preview->timeout_id)
|
|
|
|
{
|
|
|
|
g_source_remove (preview->timeout_id);
|
|
|
|
preview->timeout_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_get_property (GObject *object,
|
2004-09-01 02:06:36 +08:00
|
|
|
guint property_id,
|
2004-08-31 06:10:26 +08:00
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
switch (property_id)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
case PROP_UPDATE:
|
2004-08-31 06:49:06 +08:00
|
|
|
g_value_set_boolean (value, preview->update_preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
case PROP_SHOW_UPDATE_TOGGLE:
|
2004-08-31 06:10:26 +08:00
|
|
|
g_value_set_boolean (value, GTK_WIDGET_VISIBLE (preview->toggle_update));
|
|
|
|
break;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
default:
|
2004-09-01 02:06:36 +08:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_set_property (GObject *object,
|
2004-09-01 02:06:36 +08:00
|
|
|
guint property_id,
|
2004-08-31 06:10:26 +08:00
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
switch (property_id)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
case PROP_UPDATE:
|
2004-08-31 06:10:26 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle_update),
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
case PROP_SHOW_UPDATE_TOGGLE:
|
2004-08-31 06:10:26 +08:00
|
|
|
if (g_value_get_boolean (value))
|
|
|
|
gtk_widget_show (preview->toggle_update);
|
|
|
|
else
|
|
|
|
gtk_widget_hide (preview->toggle_update);
|
|
|
|
break;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
default:
|
2004-09-01 02:06:36 +08:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_preview_draw (GimpPreview *preview)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-09-01 02:06:36 +08:00
|
|
|
GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
if (class->draw)
|
|
|
|
class->draw (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-01 10:10:40 +08:00
|
|
|
gimp_preview_area_realize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 23:13:31 +08:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (widget);
|
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
g_return_if_fail (preview->cursor == NULL);
|
|
|
|
|
|
|
|
preview->cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
if (preview->xmax - preview->xmin > preview->width ||
|
|
|
|
preview->ymax - preview->ymin > preview->height)
|
|
|
|
{
|
|
|
|
gdk_window_set_cursor (widget->window, preview->cursor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_window_set_cursor (widget->window, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_unrealize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview)
|
|
|
|
{
|
|
|
|
if (preview->cursor)
|
|
|
|
{
|
|
|
|
gdk_cursor_unref (preview->cursor);
|
|
|
|
preview->cursor = NULL;
|
|
|
|
}
|
2004-08-31 23:13:31 +08:00
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-08-31 23:13:31 +08:00
|
|
|
static void
|
2004-09-01 03:58:25 +08:00
|
|
|
gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpPreview *preview)
|
2004-08-31 23:13:31 +08:00
|
|
|
{
|
2004-09-01 10:10:40 +08:00
|
|
|
GdkCursor *cursor = NULL;
|
|
|
|
gint width = preview->xmax - preview->xmin;
|
|
|
|
gint height = preview->ymax - preview->ymin;
|
2004-09-01 03:58:25 +08:00
|
|
|
|
|
|
|
preview->width = allocation->width;
|
|
|
|
preview->height = allocation->height;
|
|
|
|
|
|
|
|
if (width > preview->width)
|
|
|
|
{
|
2004-09-01 10:10:40 +08:00
|
|
|
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
|
|
|
|
|
|
|
|
adj->lower = 0;
|
|
|
|
adj->upper = width;
|
|
|
|
adj->page_size = preview->width;
|
|
|
|
adj->step_increment = 1.0;
|
|
|
|
adj->page_increment = adj->page_size / 2;
|
|
|
|
|
|
|
|
gtk_adjustment_changed (adj);
|
|
|
|
|
2004-09-01 03:58:25 +08:00
|
|
|
gtk_widget_show (preview->hscr);
|
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
cursor = preview->cursor;
|
2004-09-01 03:58:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (preview->hscr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height > preview->height)
|
|
|
|
{
|
2004-09-01 10:10:40 +08:00
|
|
|
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (preview->vscr));
|
|
|
|
|
|
|
|
adj->lower = 0;
|
|
|
|
adj->upper = height;
|
|
|
|
adj->page_size = preview->height;
|
|
|
|
adj->step_increment = 1.0;
|
|
|
|
adj->page_increment = adj->page_size / 2;
|
|
|
|
|
|
|
|
gtk_adjustment_changed (adj);
|
|
|
|
|
2004-09-01 03:58:25 +08:00
|
|
|
gtk_widget_show (preview->vscr);
|
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
cursor = preview->cursor;
|
2004-09-01 03:58:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (preview->vscr);
|
|
|
|
}
|
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
gdk_window_set_cursor (widget->window, cursor);
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_preview_draw (preview);
|
|
|
|
gimp_preview_invalidate (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-31 23:13:31 +08:00
|
|
|
gimp_preview_h_scroll (GtkAdjustment *hadj,
|
|
|
|
GimpPreview *preview)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
|
|
|
preview->xoff = hadj->value;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (preview->area),
|
|
|
|
preview->xoff, preview->yoff);
|
|
|
|
|
2004-09-01 03:58:25 +08:00
|
|
|
if (! preview->in_drag)
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_preview_draw (preview);
|
2004-09-01 07:37:04 +08:00
|
|
|
|
|
|
|
gimp_preview_invalidate (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-31 23:13:31 +08:00
|
|
|
gimp_preview_v_scroll (GtkAdjustment *vadj,
|
|
|
|
GimpPreview *preview)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
|
|
|
preview->yoff = vadj->value;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (preview->area),
|
|
|
|
preview->xoff, preview->yoff);
|
|
|
|
|
2004-09-01 03:58:25 +08:00
|
|
|
if (! preview->in_drag)
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_preview_draw (preview);
|
2004-09-01 07:37:04 +08:00
|
|
|
|
|
|
|
gimp_preview_invalidate (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_preview_area_event (GtkWidget *area,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpPreview *preview)
|
|
|
|
{
|
2004-08-31 23:13:31 +08:00
|
|
|
gint x, y;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
2004-08-31 23:13:31 +08:00
|
|
|
gtk_widget_get_pointer (area, &x, &y);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-08-31 23:13:31 +08:00
|
|
|
preview->in_drag = TRUE;
|
|
|
|
preview->drag_x = x;
|
|
|
|
preview->drag_y = y;
|
|
|
|
preview->drag_xoff = preview->xoff;
|
|
|
|
preview->drag_yoff = preview->yoff;
|
|
|
|
|
|
|
|
gtk_grab_add (area);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
2004-08-31 23:13:31 +08:00
|
|
|
if (preview->in_drag)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
|
|
|
gtk_grab_remove (area);
|
|
|
|
preview->in_drag = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
if (preview->in_drag)
|
|
|
|
{
|
2004-08-31 23:13:31 +08:00
|
|
|
gint dx, dy;
|
2004-08-31 06:10:26 +08:00
|
|
|
gint xoff, yoff;
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
gtk_widget_get_pointer (area, &x, &y);
|
|
|
|
|
|
|
|
dx = x - preview->drag_x;
|
|
|
|
dy = y - preview->drag_y;
|
|
|
|
|
|
|
|
xoff = CLAMP (preview->drag_xoff - dx,
|
|
|
|
0, preview->xmax - preview->xmin - preview->width);
|
|
|
|
yoff = CLAMP (preview->drag_yoff - dy,
|
|
|
|
0, preview->ymax - preview->ymin - preview->height);
|
2004-09-01 03:58:25 +08:00
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
if (preview->xoff != xoff || preview->yoff != yoff)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (preview->hadj), xoff);
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (preview->vadj), yoff);
|
2004-09-01 02:06:36 +08:00
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
gimp_preview_draw (preview);
|
2004-09-01 10:10:40 +08:00
|
|
|
gimp_preview_invalidate (preview);
|
2004-09-01 09:18:19 +08:00
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_toggle_callback (GtkWidget *toggle,
|
|
|
|
GimpPreview *preview)
|
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle)))
|
|
|
|
{
|
|
|
|
preview->update_preview = TRUE;
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_preview_invalidate (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
else
|
2004-08-31 06:49:06 +08:00
|
|
|
{
|
|
|
|
preview->update_preview = FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-31 23:27:53 +08:00
|
|
|
g_object_notify (G_OBJECT (preview), "update");
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_preview_invalidate_now (GimpPreview *preview)
|
|
|
|
{
|
|
|
|
preview->timeout_id = 0;
|
|
|
|
|
|
|
|
g_signal_emit (preview, preview_signals[INVALIDATED], 0);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
/**
|
2004-08-31 22:29:25 +08:00
|
|
|
* gimp_preview_get_size:
|
2004-08-31 06:49:06 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
2004-08-31 22:29:25 +08:00
|
|
|
* @width: return location for the preview area width
|
|
|
|
* @height: return location for the preview area height
|
2004-08-31 06:49:06 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
2004-08-31 06:10:26 +08:00
|
|
|
**/
|
2004-08-31 22:29:25 +08:00
|
|
|
void
|
|
|
|
gimp_preview_get_size (GimpPreview *preview,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
if (width)
|
|
|
|
*width = preview->width;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
if (height)
|
|
|
|
*height = preview->height;
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_get_posistion:
|
2004-08-31 06:49:06 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
2004-08-31 23:13:31 +08:00
|
|
|
* @x: return location for the horizontal offset
|
|
|
|
* @y: return location for the vertical offset
|
2004-08-31 06:10:26 +08:00
|
|
|
*
|
2004-08-31 06:49:06 +08:00
|
|
|
* Since: GIMP 2.2
|
2004-08-31 06:10:26 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_get_position (GimpPreview *preview,
|
|
|
|
gint *x,
|
|
|
|
gint *y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
if (x)
|
|
|
|
*x = preview->xoff + preview->xmin;
|
|
|
|
|
|
|
|
if (y)
|
|
|
|
*y = preview->yoff + preview->ymin;
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_show_update_toggle:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
* @show_update: whether to show the "Update Preview" toggle button
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
2004-08-31 06:10:26 +08:00
|
|
|
void
|
|
|
|
gimp_preview_show_update_toggle (GimpPreview *preview,
|
|
|
|
gboolean show_update)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
g_object_set (preview,
|
2004-08-31 22:29:25 +08:00
|
|
|
"show_update_toggle", show_update,
|
2004-08-31 06:49:06 +08:00
|
|
|
NULL);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
/*
|
|
|
|
* gimp_preview_invalidate:
|
2004-08-31 23:13:31 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
2004-08-31 22:29:25 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_invalidate (GimpPreview *preview)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
if (preview->update_preview)
|
2004-09-01 07:37:04 +08:00
|
|
|
{
|
|
|
|
if (preview->timeout_id)
|
|
|
|
g_source_remove (preview->timeout_id);
|
2004-08-31 22:29:25 +08:00
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
preview->timeout_id =
|
|
|
|
g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, PREVIEW_TIMEOUT,
|
|
|
|
(GSourceFunc) gimp_preview_invalidate_now,
|
|
|
|
preview, NULL);
|
|
|
|
}
|
|
|
|
}
|