[gimp/gtk3-port: 331/460] libgimpwidgets: move all GimpPreview members to private
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 331/460] libgimpwidgets: move all GimpPreview members to private
- Date: Sun, 20 May 2018 15:39:24 +0000 (UTC)
commit de54391cac809ff11d656af53973b086cf3ca451
Author: Michael Natterer <mitch gimp org>
Date: Fri May 4 09:46:37 2018 +0200
libgimpwidgets: move all GimpPreview members to private
and add tons of API so subclasses can still do their thing, probably
subject to change/fix.
libgimp/gimpaspectpreview.c | 70 +++++---
libgimp/gimpdrawablepreview.c | 82 +++++---
libgimp/gimpzoompreview.c | 107 +++++++----
libgimpwidgets/gimppreview.c | 349 ++++++++++++++++++++++++----------
libgimpwidgets/gimppreview.h | 43 ++--
libgimpwidgets/gimpscrolledpreview.c | 143 +++++++++-----
plug-ins/common/despeckle.c | 4 +-
7 files changed, 526 insertions(+), 272 deletions(-)
---
diff --git a/libgimp/gimpaspectpreview.c b/libgimp/gimpaspectpreview.c
index a449d4e..a1995a9 100644
--- a/libgimp/gimpaspectpreview.c
+++ b/libgimp/gimpaspectpreview.c
@@ -145,7 +145,7 @@ gimp_aspect_preview_init (GimpAspectPreview *preview)
GIMP_TYPE_ASPECT_PREVIEW,
GimpAspectPreviewPrivate);
- g_object_set (GIMP_PREVIEW (preview)->area,
+ g_object_set (gimp_preview_get_area (GIMP_PREVIEW (preview)),
"check-size", gimp_check_size (),
"check-type", gimp_check_type (),
NULL);
@@ -237,14 +237,17 @@ static void
gimp_aspect_preview_style_updated (GtkWidget *widget)
{
GimpPreview *preview = GIMP_PREVIEW (widget);
+ GtkWidget *area = gimp_preview_get_area (preview);
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
- if (preview->area)
+ if (area)
{
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
gint width;
gint height;
+ gint preview_width;
+ gint preview_height;
gint size;
width = gimp_drawable_width (priv->drawable_ID);
@@ -256,29 +259,31 @@ gimp_aspect_preview_style_updated (GtkWidget *widget)
if (width > height)
{
- preview->width = MIN (width, size);
- preview->height = (height * preview->width) / width;
+ preview_width = MIN (width, size);
+ preview_height = (height * preview_width) / width;
}
else
{
- preview->height = MIN (height, size);
- preview->width = (width * preview->height) / height;
+ preview_height = MIN (height, size);
+ preview_width = (width * preview_height) / height;
}
- gtk_widget_set_size_request (preview->area,
- preview->width, preview->height);
+ gimp_preview_set_size (preview, preview_width, preview_height);
}
}
static void
gimp_aspect_preview_draw (GimpPreview *preview)
{
- g_return_if_fail (GIMP_IS_ASPECT_PREVIEW (preview));
+ GtkWidget *area = gimp_preview_get_area (preview);
+ gint width;
+ gint height;
- gimp_preview_area_fill (GIMP_PREVIEW_AREA (preview->area),
+ gimp_preview_get_size (preview, &width, &height);
+
+ gimp_preview_area_fill (GIMP_PREVIEW_AREA (area),
0, 0,
- preview->width,
- preview->height,
+ width, height,
0, 0, 0);
}
@@ -288,15 +293,20 @@ gimp_aspect_preview_draw_buffer (GimpPreview *preview,
gint rowstride)
{
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
+ GtkWidget *area = gimp_preview_get_area (preview);
+ gint width;
+ gint height;
gint32 image_ID;
+ gimp_preview_get_size (preview, &width, &height);
+
image_ID = gimp_item_get_image (priv->drawable_ID);
if (gimp_selection_is_empty (image_ID))
{
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
+ gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
0, 0,
- preview->width, preview->height,
+ width, height,
gimp_drawable_type (priv->drawable_ID),
buffer,
rowstride);
@@ -306,21 +316,21 @@ gimp_aspect_preview_draw_buffer (GimpPreview *preview,
guchar *sel;
guchar *src;
gint selection_ID;
- gint width, height;
+ gint w, h;
gint bpp;
selection_ID = gimp_image_get_selection (image_ID);
- width = preview->width;
- height = preview->height;
+ w = width;
+ h = height;
src = gimp_drawable_get_thumbnail_data (priv->drawable_ID,
- &width, &height, &bpp);
+ &w, &h, &bpp);
sel = gimp_drawable_get_thumbnail_data (selection_ID,
- &width, &height, &bpp);
+ &w, &h, &bpp);
- gimp_preview_area_mask (GIMP_PREVIEW_AREA (preview->area),
- 0, 0, preview->width, preview->height,
+ gimp_preview_area_mask (GIMP_PREVIEW_AREA (area),
+ 0, 0, width, height,
gimp_drawable_type (priv->drawable_ID),
src, width * gimp_drawable_bpp (priv->drawable_ID),
buffer, rowstride,
@@ -339,9 +349,13 @@ gimp_aspect_preview_transform (GimpPreview *preview,
gint *dest_y)
{
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
+ gint width;
+ gint height;
+
+ gimp_preview_get_size (preview, &width, &height);
- *dest_x = (gdouble) src_x * preview->width / gimp_drawable_width (priv->drawable_ID);
- *dest_y = (gdouble) src_y * preview->height / gimp_drawable_height (priv->drawable_ID);
+ *dest_x = (gdouble) src_x * width / gimp_drawable_width (priv->drawable_ID);
+ *dest_y = (gdouble) src_y * height / gimp_drawable_height (priv->drawable_ID);
}
static void
@@ -352,9 +366,13 @@ gimp_aspect_preview_untransform (GimpPreview *preview,
gint *dest_y)
{
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
+ gint width;
+ gint height;
+
+ gimp_preview_get_size (preview, &width, &height);
- *dest_x = (gdouble) src_x * gimp_drawable_width (priv->drawable_ID) / preview->width;
- *dest_y = (gdouble) src_y * gimp_drawable_height (priv->drawable_ID) / preview->height;
+ *dest_x = (gdouble) src_x * gimp_drawable_width (priv->drawable_ID) / width;
+ *dest_y = (gdouble) src_y * gimp_drawable_height (priv->drawable_ID) / height;
}
static void
@@ -388,7 +406,7 @@ gimp_aspect_preview_set_drawable_id (GimpAspectPreview *preview,
gimp_preview_set_bounds (GIMP_PREVIEW (preview), 0, 0, width, height);
if (height > 0)
- g_object_set (GIMP_PREVIEW (preview)->frame,
+ g_object_set (gimp_preview_get_frame (GIMP_PREVIEW (preview)),
"ratio",
(gdouble) d_width / (gdouble) d_height,
NULL);
diff --git a/libgimp/gimpdrawablepreview.c b/libgimp/gimpdrawablepreview.c
index 6381491..8d1cc53 100644
--- a/libgimp/gimpdrawablepreview.c
+++ b/libgimp/gimpdrawablepreview.c
@@ -144,7 +144,7 @@ gimp_drawable_preview_init (GimpDrawablePreview *preview)
GIMP_TYPE_DRAWABLE_PREVIEW,
GimpDrawablePreviewPrivate);
- g_object_set (GIMP_PREVIEW (preview)->area,
+ g_object_set (gimp_preview_get_area (GIMP_PREVIEW (preview)),
"check-size", gimp_check_size (),
"check-type", gimp_check_type (),
NULL);
@@ -184,8 +184,7 @@ gimp_drawable_preview_dispose (GObject *object)
GimpPreview *preview = GIMP_PREVIEW (object);
PreviewSettings settings;
- settings.x = preview->xoff + preview->xmin;
- settings.y = preview->yoff + preview->ymin;
+ gimp_preview_get_position (preview, &settings.x, &settings.y);
settings.update = gimp_preview_get_update (preview);
gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
@@ -240,21 +239,25 @@ static void
gimp_drawable_preview_style_updated (GtkWidget *widget)
{
GimpPreview *preview = GIMP_PREVIEW (widget);
+ GtkWidget *area = gimp_preview_get_area (preview);
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
- if (preview->area)
+ if (area)
{
- gint width = preview->xmax - preview->xmin;
- gint height = preview->ymax - preview->ymin;
+ gint xmin, ymin;
+ gint xmax, ymax;
gint size;
+ gimp_preview_get_bounds (preview, &xmin, &ymin, &xmax, &ymax);
+
gtk_widget_style_get (widget,
"size", &size,
NULL);
- gtk_widget_set_size_request (GIMP_PREVIEW (preview)->area,
- MIN (width, size), MIN (height, size));
+ gtk_widget_set_size_request (area,
+ MIN (xmax - xmin, size),
+ MIN (ymax - ymin, size));
}
}
@@ -264,24 +267,28 @@ gimp_drawable_preview_draw_original (GimpPreview *preview)
GimpDrawablePreviewPrivate *priv = GET_PRIVATE (preview);
guchar *buffer;
gint width, height;
+ gint xoff, yoff;
+ gint xmin, ymin;
+ gint xmax, ymax;
gint bpp;
GimpImageType type;
if (priv->drawable_ID < 1)
return;
- preview->xoff = CLAMP (preview->xoff,
- 0, preview->xmax - preview->xmin - preview->width);
- preview->yoff = CLAMP (preview->yoff,
- 0, preview->ymax - preview->ymin - preview->height);
+ gimp_preview_get_size (preview, &width, &height);
+ gimp_preview_get_offsets (preview, &xoff, &yoff);
+ gimp_preview_get_bounds (preview, &xmin, &ymin, &xmax, &ymax);
+
+ xoff = CLAMP (xoff, 0, xmax - xmin - width);
+ yoff = CLAMP (yoff, 0, ymax - ymin - height);
- width = preview->width;
- height = preview->height;
+ gimp_preview_set_offsets (preview, xoff, yoff);
buffer = gimp_drawable_get_sub_thumbnail_data (priv->drawable_ID,
- preview->xoff + preview->xmin,
- preview->yoff + preview->ymin,
- preview->width, preview->height,
+ xoff + xmin,
+ yoff + ymin,
+ width, height,
&width, &height, &bpp);
switch (bpp)
@@ -295,7 +302,7 @@ gimp_drawable_preview_draw_original (GimpPreview *preview)
return;
}
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
+ gimp_preview_area_draw (GIMP_PREVIEW_AREA (gimp_preview_get_area (preview)),
0, 0, width, height, type, buffer, width * bpp);
g_free (buffer);
}
@@ -402,15 +409,21 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
{
GimpDrawablePreviewPrivate *priv = GET_PRIVATE (preview);
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
+ GtkWidget *area = gimp_preview_get_area (gimp_preview);
+ gint xmin, ymin;
+ gint xoff, yoff;
gint32 image_ID;
+ gimp_preview_get_bounds (gimp_preview, &xmin, &ymin, NULL, NULL);
+ gimp_preview_get_offsets (gimp_preview, &xoff, &yoff);
+
image_ID = gimp_item_get_image (priv->drawable_ID);
if (gimp_selection_is_empty (image_ID))
{
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (gimp_preview->area),
- x - gimp_preview->xoff - gimp_preview->xmin,
- y - gimp_preview->yoff - gimp_preview->ymin,
+ gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
+ x - xoff - xmin,
+ y - yoff - ymin,
width,
height,
gimp_drawable_type (priv->drawable_ID),
@@ -475,9 +488,9 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
return;
}
- gimp_preview_area_mask (GIMP_PREVIEW_AREA (gimp_preview->area),
- draw_x - gimp_preview->xoff - gimp_preview->xmin,
- draw_y - gimp_preview->yoff - gimp_preview->ymin,
+ gimp_preview_area_mask (GIMP_PREVIEW_AREA (area),
+ draw_x - xoff - xmin,
+ draw_y - yoff - ymin,
draw_width,
draw_height,
type,
@@ -499,11 +512,15 @@ gimp_drawable_preview_draw_buffer (GimpPreview *preview,
const guchar *buffer,
gint rowstride)
{
+ gint x, y;
+ gint width, height;
+
+ gimp_preview_get_position (preview, &x, &y);
+ gimp_preview_get_size (preview, &width, &height);
+
gimp_drawable_preview_draw_area (GIMP_DRAWABLE_PREVIEW (preview),
- preview->xmin + preview->xoff,
- preview->ymin + preview->yoff,
- preview->width,
- preview->height,
+ x, y,
+ width, height,
buffer, rowstride);
}
@@ -525,12 +542,13 @@ gimp_drawable_preview_set_drawable_id (GimpDrawablePreview *drawable_preview,
if (gimp_drawable_is_indexed (drawable_ID))
{
- guint32 image_ID = gimp_item_get_image (drawable_ID);
- guchar *cmap;
- gint num_colors;
+ guint32 image_ID = gimp_item_get_image (drawable_ID);
+ GtkWidget *area = gimp_preview_get_area (preview);
+ guchar *cmap;
+ gint num_colors;
cmap = gimp_image_get_colormap (image_ID, &num_colors);
- gimp_preview_area_set_colormap (GIMP_PREVIEW_AREA (preview->area),
+ gimp_preview_area_set_colormap (GIMP_PREVIEW_AREA (area),
cmap, num_colors);
g_free (cmap);
}
diff --git a/libgimp/gimpzoompreview.c b/libgimp/gimpzoompreview.c
index 8a6da51..7c02ec6 100644
--- a/libgimp/gimpzoompreview.c
+++ b/libgimp/gimpzoompreview.c
@@ -185,18 +185,20 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
static void
gimp_zoom_preview_init (GimpZoomPreview *preview)
{
+ GtkWidget *area = gimp_preview_get_area (GIMP_PREVIEW (preview));
+
preview->priv = G_TYPE_INSTANCE_GET_PRIVATE (preview,
GIMP_TYPE_ZOOM_PREVIEW,
GimpZoomPreviewPrivate);
- g_signal_connect (GIMP_PREVIEW (preview)->area, "size-allocate",
+ g_signal_connect (area, "size-allocate",
G_CALLBACK (gimp_zoom_preview_size_allocate),
preview);
- g_signal_connect (GIMP_PREVIEW (preview)->area, "scroll-event",
+ g_signal_connect (area, "scroll-event",
G_CALLBACK (gimp_zoom_preview_scroll_event),
preview);
- g_object_set (GIMP_PREVIEW (preview)->area,
+ g_object_set (area,
"check-size", gimp_check_size (),
"check-type", gimp_check_type (),
NULL);
@@ -324,14 +326,13 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
GimpScrolledPreview *scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
GtkAdjustment *hadj;
GtkAdjustment *vadj;
- gdouble width;
- gdouble height;
+ gint width;
+ gint height;
gdouble ratio;
gimp_scrolled_preview_freeze (scrolled_preview);
- width = GIMP_PREVIEW (preview)->width;
- height = GIMP_PREVIEW (preview)->height;
+ gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
ratio = new_factor / old_factor;
@@ -365,11 +366,13 @@ gimp_zoom_preview_size_allocate (GtkWidget *widget,
{
gdouble zoom;
+#if 0
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
+#endif
zoom = gimp_zoom_model_get_factor (preview->priv->model);
@@ -380,14 +383,18 @@ static void
gimp_zoom_preview_style_updated (GtkWidget *widget)
{
GimpPreview *preview = GIMP_PREVIEW (widget);
+ GtkWidget *area = gimp_preview_get_area (preview);
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
- if (preview->area)
+ if (area)
{
GimpZoomPreviewPrivate *priv = GET_PRIVATE (preview);
gint size;
- gint width, height;
+ gint width;
+ gint height;
+ gint preview_width;
+ gint preview_height;
gint x1, y1;
gint x2, y2;
@@ -407,17 +414,16 @@ gimp_zoom_preview_style_updated (GtkWidget *widget)
if (width > height)
{
- preview->width = MIN (width, size);
- preview->height = (height * preview->width) / width;
+ preview_width = MIN (width, size);
+ preview_height = (height * preview_width) / width;
}
else
{
- preview->height = MIN (height, size);
- preview->width = (width * preview->height) / height;
+ preview_height = MIN (height, size);
+ preview_width = (width * preview_height) / height;
}
- gtk_widget_set_size_request (preview->area,
- preview->width, preview->height);
+ gimp_preview_set_size (preview, preview_width, preview_height);
}
}
@@ -472,7 +478,9 @@ gimp_zoom_preview_draw (GimpPreview *preview)
if (data)
{
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
+ GtkWidget *area = gimp_preview_get_area (preview);
+
+ gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
0, 0, width, height,
gimp_drawable_type (priv->drawable_ID),
data, width * bpp);
@@ -486,15 +494,19 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
gint rowstride)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
+ GtkWidget *area = gimp_preview_get_area (preview);
+ gint width;
+ gint height;
gint32 image_ID;
+ gimp_preview_get_size (preview, &width, &height);
image_ID = gimp_item_get_image (priv->drawable_ID);
if (gimp_selection_is_empty (image_ID))
{
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
+ gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
0, 0,
- preview->width, preview->height,
+ width, height,
gimp_drawable_type (priv->drawable_ID),
buffer,
rowstride);
@@ -504,7 +516,7 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
guchar *sel;
guchar *src;
gint selection_ID;
- gint width, height;
+ gint w, h;
gint bpp;
gint src_x;
gint src_y;
@@ -515,8 +527,8 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
selection_ID = gimp_image_get_selection (image_ID);
- width = preview->width;
- height = preview->height;
+ w = width;
+ h = height;
gimp_zoom_preview_get_source_area (preview,
&src_x, &src_y,
@@ -525,15 +537,15 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
src = gimp_drawable_get_sub_thumbnail_data (priv->drawable_ID,
src_x, src_y,
src_width, src_height,
- &width, &height, &bpp);
+ &w, &h, &bpp);
gimp_drawable_offsets (priv->drawable_ID, &offsx, &offsy);
sel = gimp_drawable_get_sub_thumbnail_data (selection_ID,
src_x + offsx, src_y + offsy,
src_width, src_height,
&width, &height, &bpp);
- gimp_preview_area_mask (GIMP_PREVIEW_AREA (preview->area),
- 0, 0, preview->width, preview->height,
+ gimp_preview_area_mask (GIMP_PREVIEW_AREA (area),
+ 0, 0, width, height,
gimp_drawable_type (priv->drawable_ID),
src, width * gimp_drawable_bpp (priv->drawable_ID),
buffer, rowstride,
@@ -561,7 +573,9 @@ gimp_zoom_preview_draw_thumb (GimpPreview *preview,
static void
gimp_zoom_preview_set_cursor (GimpPreview *preview)
{
- if (! gtk_widget_get_realized (preview->area))
+ GtkWidget *area = gimp_preview_get_area (preview);
+
+ if (! gtk_widget_get_realized (area))
return;
if (gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview)) > 1.0)
@@ -570,14 +584,14 @@ gimp_zoom_preview_set_cursor (GimpPreview *preview)
GdkCursor *cursor;
cursor = gdk_cursor_new_for_display (display, GDK_HAND1);
- gdk_window_set_cursor (gtk_widget_get_window (preview->area),
+ gdk_window_set_cursor (gtk_widget_get_window (area),
cursor);
g_object_unref (cursor);
}
else
{
- gdk_window_set_cursor (gtk_widget_get_window (preview->area),
- preview->default_cursor);
+ gdk_window_set_cursor (gtk_widget_get_window (area),
+ gimp_preview_get_default_cursor (preview));
}
}
@@ -589,14 +603,22 @@ gimp_zoom_preview_transform (GimpPreview *preview,
gint *dest_y)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
+ gint width;
+ gint height;
+ gint xoff;
+ gint yoff;
+ gdouble zoom;
+
+ gimp_preview_get_size (preview, &width, &height);
+ gimp_preview_get_offsets (preview, &xoff, &yoff);
- gdouble zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
+ zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
*dest_x = ((gdouble) (src_x - priv->extents.x) *
- preview->width / priv->extents.width * zoom) - preview->xoff;
+ width / priv->extents.width * zoom) - xoff;
*dest_y = ((gdouble) (src_y - priv->extents.y) *
- preview->height / priv->extents.height * zoom) - preview->yoff;
+ height / priv->extents.height * zoom) - yoff;
}
static void
@@ -607,16 +629,24 @@ gimp_zoom_preview_untransform (GimpPreview *preview,
gint *dest_y)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
+ gint width;
+ gint height;
+ gint xoff;
+ gint yoff;
+ gdouble zoom;
+
+ gimp_preview_get_size (preview, &width, &height);
+ gimp_preview_get_offsets (preview, &xoff, &yoff);
- gdouble zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
+ zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
*dest_x = (priv->extents.x +
- ((gdouble) (src_x + preview->xoff) *
- priv->extents.width / preview->width / zoom));
+ ((gdouble) (src_x + xoff) *
+ priv->extents.width / width / zoom));
*dest_y = (priv->extents.y +
- ((gdouble) (src_y + preview->yoff) *
- priv->extents.height / preview->height / zoom));
+ ((gdouble) (src_y + yoff) *
+ priv->extents.height / height / zoom));
}
static void
@@ -663,7 +693,7 @@ gimp_zoom_preview_set_drawable_id (GimpZoomPreview *preview,
gimp_preview_set_bounds (GIMP_PREVIEW (preview),
0, 0, max_width, max_height);
- g_object_set (GIMP_PREVIEW (preview)->frame,
+ g_object_set (gimp_preview_get_frame (GIMP_PREVIEW (preview)),
"ratio", (gdouble) width / (gdouble) height,
NULL);
}
@@ -877,8 +907,7 @@ gimp_zoom_preview_get_source (GimpZoomPreview *preview,
gint src_width;
gint src_height;
- *width = gimp_preview->width;
- *height = gimp_preview->height;
+ gimp_preview_get_size (gimp_preview, width, height);
gimp_zoom_preview_get_source_area (gimp_preview,
&src_x, &src_y,
diff --git a/libgimpwidgets/gimppreview.c b/libgimpwidgets/gimppreview.c
index bdaad98..a1aeb90 100644
--- a/libgimpwidgets/gimppreview.c
+++ b/libgimpwidgets/gimppreview.c
@@ -62,7 +62,20 @@ enum
struct _GimpPreviewPrivate
{
+ GtkWidget *area;
+ GtkWidget *table;
+ GtkWidget *frame;
+ GtkWidget *toggle;
GtkWidget *controls;
+ GdkCursor *cursor_busy;
+ GdkCursor *default_cursor;
+
+ gint xoff, yoff;
+ gint xmin, xmax, ymin, ymax;
+ gint width, height;
+
+ gboolean update_preview;
+ guint timeout_id;
};
#define GET_PRIVATE(obj) (((GimpPreview *) (obj))->priv)
@@ -224,88 +237,88 @@ gimp_preview_init (GimpPreview *preview)
if (gtk_widget_get_direction (GTK_WIDGET (preview)) == GTK_TEXT_DIR_RTL)
xalign = 1.0;
- preview->frame = gtk_aspect_frame_new (NULL, xalign, 0.0, 1.0, TRUE);
- gtk_frame_set_shadow_type (GTK_FRAME (preview->frame), GTK_SHADOW_NONE);
- gtk_box_pack_start (GTK_BOX (preview), preview->frame, TRUE, TRUE, 0);
- gtk_widget_show (preview->frame);
+ priv->frame = gtk_aspect_frame_new (NULL, xalign, 0.0, 1.0, TRUE);
+ gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
+ gtk_box_pack_start (GTK_BOX (preview), priv->frame, TRUE, TRUE, 0);
+ gtk_widget_show (priv->frame);
- preview->table = gtk_table_new (3, 2, FALSE);
- gtk_table_set_row_spacing (GTK_TABLE (preview->table), 1, 3);
- gtk_container_add (GTK_CONTAINER (preview->frame), preview->table);
- gtk_widget_show (preview->table);
+ priv->table = gtk_table_new (3, 2, FALSE);
+ gtk_table_set_row_spacing (GTK_TABLE (priv->table), 1, 3);
+ gtk_container_add (GTK_CONTAINER (priv->frame), priv->table);
+ gtk_widget_show (priv->table);
- preview->timeout_id = 0;
+ priv->timeout_id = 0;
- preview->xmin = preview->ymin = 0;
- preview->xmax = preview->ymax = 1;
- preview->width = preview->xmax - preview->xmin;
- preview->height = preview->ymax - preview->ymin;
+ priv->xmin = priv->ymin = 0;
+ priv->xmax = priv->ymax = 1;
+ priv->width = priv->xmax - priv->xmin;
+ priv->height = priv->ymax - priv->ymin;
- preview->xoff = 0;
- preview->yoff = 0;
+ priv->xoff = 0;
+ priv->yoff = 0;
- preview->default_cursor = NULL;
+ priv->default_cursor = NULL;
/* preview area */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
- gtk_table_attach (GTK_TABLE (preview->table), frame, 0, 1, 0, 1,
+ gtk_table_attach (GTK_TABLE (priv->table), frame, 0, 1, 0, 1,
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
gtk_widget_show (frame);
- preview->area = gimp_preview_area_new ();
- gtk_container_add (GTK_CONTAINER (frame), preview->area);
- gtk_widget_show (preview->area);
+ priv->area = gimp_preview_area_new ();
+ gtk_container_add (GTK_CONTAINER (frame), priv->area);
+ gtk_widget_show (priv->area);
- g_signal_connect_swapped (preview->area, "notify::check-size",
+ g_signal_connect_swapped (priv->area, "notify::check-size",
G_CALLBACK (gimp_preview_notify_checks),
preview);
- g_signal_connect_swapped (preview->area, "notify::check-type",
+ g_signal_connect_swapped (priv->area, "notify::check-type",
G_CALLBACK (gimp_preview_notify_checks),
preview);
- gtk_widget_add_events (preview->area,
+ gtk_widget_add_events (priv->area,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON_MOTION_MASK);
- g_signal_connect (preview->area, "event",
+ g_signal_connect (priv->area, "event",
G_CALLBACK (gimp_preview_area_event),
preview);
- g_signal_connect (preview->area, "realize",
+ g_signal_connect (priv->area, "realize",
G_CALLBACK (gimp_preview_area_realize),
preview);
- g_signal_connect (preview->area, "unrealize",
+ g_signal_connect (priv->area, "unrealize",
G_CALLBACK (gimp_preview_area_unrealize),
preview);
- g_signal_connect_data (preview->area, "realize",
+ g_signal_connect_data (priv->area, "realize",
G_CALLBACK (gimp_preview_area_set_cursor),
preview, NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
- g_signal_connect (preview->area, "size-allocate",
+ g_signal_connect (priv->area, "size-allocate",
G_CALLBACK (gimp_preview_area_size_allocate),
preview);
- g_signal_connect_data (preview->area, "size-allocate",
+ g_signal_connect_data (priv->area, "size-allocate",
G_CALLBACK (gimp_preview_area_set_cursor),
preview, NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
priv->controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_table_attach (GTK_TABLE (preview->table), priv->controls, 0, 2, 2, 3,
+ gtk_table_attach (GTK_TABLE (priv->table), priv->controls, 0, 2, 2, 3,
GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
gtk_widget_show (priv->controls);
/* toggle button to (de)activate the instant preview */
- preview->toggle = gtk_check_button_new_with_mnemonic (_("_Preview"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle),
- preview->update_preview);
- gtk_box_pack_start (GTK_BOX (priv->controls), preview->toggle, TRUE, TRUE, 0);
- gtk_widget_show (preview->toggle);
+ priv->toggle = gtk_check_button_new_with_mnemonic (_("_Preview"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->toggle),
+ priv->update_preview);
+ gtk_box_pack_start (GTK_BOX (priv->controls), priv->toggle, TRUE, TRUE, 0);
+ gtk_widget_show (priv->toggle);
- g_signal_connect (preview->toggle, "toggled",
+ g_signal_connect (priv->toggle, "toggled",
G_CALLBACK (gimp_preview_toggle_callback),
preview);
}
@@ -313,12 +326,12 @@ gimp_preview_init (GimpPreview *preview)
static void
gimp_preview_dispose (GObject *object)
{
- GimpPreview *preview = GIMP_PREVIEW (object);
+ GimpPreviewPrivate *priv = GET_PRIVATE (object);
- if (preview->timeout_id)
+ if (priv->timeout_id)
{
- g_source_remove (preview->timeout_id);
- preview->timeout_id = 0;
+ g_source_remove (priv->timeout_id);
+ priv->timeout_id = 0;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
@@ -330,12 +343,12 @@ gimp_preview_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GimpPreview *preview = GIMP_PREVIEW (object);
+ GimpPreviewPrivate *priv = GET_PRIVATE (object);
switch (property_id)
{
case PROP_UPDATE:
- g_value_set_boolean (value, preview->update_preview);
+ g_value_set_boolean (value, priv->update_preview);
break;
default:
@@ -350,12 +363,12 @@ gimp_preview_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GimpPreview *preview = GIMP_PREVIEW (object);
+ GimpPreviewPrivate *priv = GET_PRIVATE (object);
switch (property_id)
{
case PROP_UPDATE:
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->toggle),
g_value_get_boolean (value));
break;
@@ -369,22 +382,22 @@ static void
gimp_preview_direction_changed (GtkWidget *widget,
GtkTextDirection prev_dir)
{
- GimpPreview *preview = GIMP_PREVIEW (widget);
- gdouble xalign = 0.0;
+ GimpPreviewPrivate *priv = GET_PRIVATE (widget);
+ gdouble xalign = 0.0;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
xalign = 1.0;
- gtk_aspect_frame_set (GTK_ASPECT_FRAME (preview->frame),
+ gtk_aspect_frame_set (GTK_ASPECT_FRAME (priv->frame),
xalign, 0.0, 1.0, TRUE);
}
static gboolean
gimp_preview_popup_menu (GtkWidget *widget)
{
- GimpPreview *preview = GIMP_PREVIEW (widget);
+ GimpPreviewPrivate *priv = GET_PRIVATE (widget);
- gimp_preview_area_menu_popup (GIMP_PREVIEW_AREA (preview->area), NULL);
+ gimp_preview_area_menu_popup (GIMP_PREVIEW_AREA (priv->area), NULL);
return TRUE;
}
@@ -393,11 +406,12 @@ static void
gimp_preview_area_realize (GtkWidget *widget,
GimpPreview *preview)
{
- GdkDisplay *display = gtk_widget_get_display (widget);
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+ GdkDisplay *display = gtk_widget_get_display (widget);
- g_return_if_fail (preview->cursor_busy == NULL);
+ g_return_if_fail (priv->cursor_busy == NULL);
- preview->cursor_busy = gdk_cursor_new_for_display (display, GDK_WATCH);
+ priv->cursor_busy = gdk_cursor_new_for_display (display, GDK_WATCH);
}
@@ -405,11 +419,9 @@ static void
gimp_preview_area_unrealize (GtkWidget *widget,
GimpPreview *preview)
{
- if (preview->cursor_busy)
- {
- g_object_unref (preview->cursor_busy);
- preview->cursor_busy = NULL;
- }
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+
+ g_clear_object (&priv->cursor_busy);
}
static void
@@ -417,11 +429,12 @@ gimp_preview_area_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
GimpPreview *preview)
{
- gint width = preview->xmax - preview->xmin;
- gint height = preview->ymax - preview->ymin;
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+ gint width = priv->xmax - priv->xmin;
+ gint height = priv->ymax - priv->ymin;
- preview->width = MIN (width, allocation->width);
- preview->height = MIN (height, allocation->height);
+ priv->width = MIN (width, allocation->width);
+ priv->height = MIN (height, allocation->height);
gimp_preview_draw (preview);
gimp_preview_invalidate (preview);
@@ -462,20 +475,22 @@ static void
gimp_preview_toggle_callback (GtkWidget *toggle,
GimpPreview *preview)
{
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle)))
{
- preview->update_preview = TRUE;
+ priv->update_preview = TRUE;
g_object_notify (G_OBJECT (preview), "update");
- if (preview->timeout_id)
- g_source_remove (preview->timeout_id);
+ if (priv->timeout_id)
+ g_source_remove (priv->timeout_id);
gimp_preview_invalidate_now (preview);
}
else
{
- preview->update_preview = FALSE;
+ priv->update_preview = FALSE;
g_object_notify (G_OBJECT (preview), "update");
@@ -493,19 +508,20 @@ gimp_preview_notify_checks (GimpPreview *preview)
static gboolean
gimp_preview_invalidate_now (GimpPreview *preview)
{
- GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (preview));
- GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (preview));
+ GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
gimp_preview_draw (preview);
- preview->timeout_id = 0;
+ priv->timeout_id = 0;
if (toplevel && gtk_widget_get_realized (toplevel))
{
gdk_window_set_cursor (gtk_widget_get_window (toplevel),
- preview->cursor_busy);
- gdk_window_set_cursor (gtk_widget_get_window (preview->area),
- preview->cursor_busy);
+ priv->cursor_busy);
+ gdk_window_set_cursor (gtk_widget_get_window (priv->area),
+ priv->cursor_busy);
gdk_flush ();
@@ -525,9 +541,11 @@ gimp_preview_invalidate_now (GimpPreview *preview)
static void
gimp_preview_real_set_cursor (GimpPreview *preview)
{
- if (gtk_widget_get_realized (preview->area))
- gdk_window_set_cursor (gtk_widget_get_window (preview->area),
- preview->default_cursor);
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+
+ if (gtk_widget_get_realized (priv->area))
+ gdk_window_set_cursor (gtk_widget_get_window (priv->area),
+ priv->default_cursor);
}
static void
@@ -537,8 +555,10 @@ gimp_preview_real_transform (GimpPreview *preview,
gint *dest_x,
gint *dest_y)
{
- *dest_x = src_x - preview->xoff - preview->xmin;
- *dest_y = src_y - preview->yoff - preview->ymin;
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+
+ *dest_x = src_x - priv->xoff - priv->xmin;
+ *dest_y = src_y - priv->yoff - priv->ymin;
}
static void
@@ -548,8 +568,10 @@ gimp_preview_real_untransform (GimpPreview *preview,
gint *dest_x,
gint *dest_y)
{
- *dest_x = src_x + preview->xoff + preview->xmin;
- *dest_y = src_y + preview->yoff + preview->ymin;
+ GimpPreviewPrivate *priv = GET_PRIVATE (preview);
+
+ *dest_x = src_x + priv->xoff + priv->xmin;
+ *dest_y = src_y + priv->yoff + priv->ymin;
}
/**
@@ -586,7 +608,7 @@ gimp_preview_get_update (GimpPreview *preview)
{
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), FALSE);
- return preview->update_preview;
+ return GET_PRIVATE (preview)->update_preview;
}
/**
@@ -610,20 +632,60 @@ gimp_preview_set_bounds (GimpPreview *preview,
gint xmax,
gint ymax)
{
+ GimpPreviewPrivate *priv;
+
g_return_if_fail (GIMP_IS_PREVIEW (preview));
g_return_if_fail (xmax > xmin);
g_return_if_fail (ymax > ymin);
- preview->xmin = xmin;
- preview->ymin = ymin;
- preview->xmax = xmax;
- preview->ymax = ymax;
+ priv = GET_PRIVATE (preview);
- gimp_preview_area_set_max_size (GIMP_PREVIEW_AREA (preview->area),
+ priv->xmin = xmin;
+ priv->ymin = ymin;
+ priv->xmax = xmax;
+ priv->ymax = ymax;
+
+ gimp_preview_area_set_max_size (GIMP_PREVIEW_AREA (priv->area),
xmax - xmin,
ymax - ymin);
}
+void
+gimp_preview_get_bounds (GimpPreview *preview,
+ gint *xmin,
+ gint *ymin,
+ gint *xmax,
+ gint *ymax)
+{
+ GimpPreviewPrivate *priv;
+
+ g_return_if_fail (GIMP_IS_PREVIEW (preview));
+
+ priv = GET_PRIVATE (preview);
+
+ if (xmin) *xmin = priv->xmin;
+ if (ymin) *ymin = priv->ymin;
+ if (xmax) *xmax = priv->xmax;
+ if (ymax) *ymax = priv->ymax;
+}
+
+void
+gimp_preview_set_size (GimpPreview *preview,
+ gint width,
+ gint height)
+{
+ GimpPreviewPrivate *priv;
+
+ g_return_if_fail (GIMP_IS_PREVIEW (preview));
+
+ priv = GET_PRIVATE (preview);
+
+ priv->width = width;
+ priv->height = height;
+
+ gtk_widget_set_size_request (priv->area, width, height);
+}
+
/**
* gimp_preview_get_size:
* @preview: a #GimpPreview widget
@@ -637,13 +699,44 @@ gimp_preview_get_size (GimpPreview *preview,
gint *width,
gint *height)
{
+ GimpPreviewPrivate *priv;
+
+ g_return_if_fail (GIMP_IS_PREVIEW (preview));
+
+ priv = GET_PRIVATE (preview);
+
+ if (width) *width = priv->width;
+ if (height) *height = priv->height;
+}
+
+void
+gimp_preview_set_offsets (GimpPreview *preview,
+ gint xoff,
+ gint yoff)
+{
+ GimpPreviewPrivate *priv;
+
+ g_return_if_fail (GIMP_IS_PREVIEW (preview));
+
+ priv = GET_PRIVATE (preview);
+
+ priv->xoff = xoff;
+ priv->yoff = yoff;
+}
+
+void
+gimp_preview_get_offsets (GimpPreview *preview,
+ gint *xoff,
+ gint *yoff)
+{
+ GimpPreviewPrivate *priv;
+
g_return_if_fail (GIMP_IS_PREVIEW (preview));
- if (width)
- *width = preview->width;
+ priv = GET_PRIVATE (preview);
- if (height)
- *height = preview->height;
+ if (xoff) *xoff = priv->xoff;
+ if (yoff) *yoff = priv->yoff;
}
/**
@@ -659,13 +752,14 @@ gimp_preview_get_position (GimpPreview *preview,
gint *x,
gint *y)
{
+ GimpPreviewPrivate *priv;
+
g_return_if_fail (GIMP_IS_PREVIEW (preview));
- if (x)
- *x = preview->xoff + preview->xmin;
+ priv = GET_PRIVATE (preview);
- if (y)
- *y = preview->yoff + preview->ymin;
+ if (x) *x = priv->xoff + priv->xmin;
+ if (y) *y = priv->yoff + priv->ymin;
}
/**
@@ -721,6 +815,38 @@ gimp_preview_untransform (GimpPreview *preview,
}
/**
+ * gimp_preview_get_frame:
+ * @preview: a #GimpPreview widget
+ *
+ * Return value: a pointer to the #GtkAspectFrame used in the @preview.
+ *
+ * Since: 3.0
+ **/
+GtkWidget *
+gimp_preview_get_frame (GimpPreview *preview)
+{
+ g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
+
+ return GET_PRIVATE (preview)->frame;
+}
+
+/**
+ * gimp_preview_get_table:
+ * @preview: a #GimpPreview widget
+ *
+ * Return value: a pointer to the #GtkTable used in the @preview.
+ *
+ * Since: 3.0
+ **/
+GtkWidget *
+gimp_preview_get_table (GimpPreview *preview)
+{
+ g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
+
+ return GET_PRIVATE (preview)->table;
+}
+
+/**
* gimp_preview_get_area:
* @preview: a #GimpPreview widget
*
@@ -738,7 +864,7 @@ gimp_preview_get_area (GimpPreview *preview)
{
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
- return preview->area;
+ return GET_PRIVATE (preview)->area;
}
/**
@@ -805,14 +931,18 @@ gimp_preview_draw_buffer (GimpPreview *preview,
void
gimp_preview_invalidate (GimpPreview *preview)
{
+ GimpPreviewPrivate *priv;
+
g_return_if_fail (GIMP_IS_PREVIEW (preview));
- if (preview->update_preview)
+ priv = GET_PRIVATE (preview);
+
+ if (priv->update_preview)
{
- if (preview->timeout_id)
- g_source_remove (preview->timeout_id);
+ if (priv->timeout_id)
+ g_source_remove (priv->timeout_id);
- preview->timeout_id =
+ priv->timeout_id =
g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, PREVIEW_TIMEOUT,
(GSourceFunc) gimp_preview_invalidate_now,
preview, NULL);
@@ -834,15 +964,30 @@ void
gimp_preview_set_default_cursor (GimpPreview *preview,
GdkCursor *cursor)
{
+ GimpPreviewPrivate *priv;
+
g_return_if_fail (GIMP_IS_PREVIEW (preview));
- if (preview->default_cursor)
- g_object_unref (preview->default_cursor);
+ priv = GET_PRIVATE (preview);
+
+ if (cursor != priv->default_cursor)
+ {
+ if (priv->default_cursor)
+ g_object_unref (priv->default_cursor);
+
+ if (cursor)
+ g_object_ref (cursor);
- if (cursor)
- g_object_ref (cursor);
+ priv->default_cursor = cursor;
+ }
+}
+
+GdkCursor *
+gimp_preview_get_default_cursor (GimpPreview *preview)
+{
+ g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
- preview->default_cursor = cursor;
+ return GET_PRIVATE (preview)->default_cursor;
}
/**
diff --git a/libgimpwidgets/gimppreview.h b/libgimpwidgets/gimppreview.h
index d044556..ccef991 100644
--- a/libgimpwidgets/gimppreview.h
+++ b/libgimpwidgets/gimppreview.h
@@ -47,24 +47,6 @@ struct _GimpPreview
GtkBox parent_instance;
GimpPreviewPrivate *priv;
-
- /* FIXME MOVE TO PRIVATE */
- gboolean update_preview;
-
- /*< protected >*/
- GtkWidget *area;
- GtkWidget *table;
- GtkWidget *frame;
- GtkWidget *toggle;
- GdkCursor *cursor_busy;
- GdkCursor *default_cursor;
-
- /*< private >*/
- gint xoff, yoff;
- gint xmin, xmax, ymin, ymax;
- gint width, height;
-
- guint timeout_id;
};
struct _GimpPreviewClass
@@ -119,13 +101,29 @@ void gimp_preview_set_bounds (GimpPreview *preview,
gint ymin,
gint xmax,
gint ymax);
+void gimp_preview_get_bounds (GimpPreview *preview,
+ gint *xmin,
+ gint *ymin,
+ gint *xmax,
+ gint *ymax);
+
+void gimp_preview_set_size (GimpPreview *preview,
+ gint width,
+ gint height);
+void gimp_preview_get_size (GimpPreview *preview,
+ gint *width,
+ gint *height);
+
+void gimp_preview_set_offsets (GimpPreview *preview,
+ gint xoff,
+ gint yoff);
+void gimp_preview_get_offsets (GimpPreview *preview,
+ gint *xoff,
+ gint *yoff);
void gimp_preview_get_position (GimpPreview *preview,
gint *x,
gint *y);
-void gimp_preview_get_size (GimpPreview *preview,
- gint *width,
- gint *height);
void gimp_preview_transform (GimpPreview *preview,
gint src_x,
@@ -138,6 +136,8 @@ void gimp_preview_untransform (GimpPreview *preview,
gint *dest_x,
gint *dest_y);
+GtkWidget * gimp_preview_get_frame (GimpPreview *preview);
+GtkWidget * gimp_preview_get_table (GimpPreview *preview);
GtkWidget * gimp_preview_get_area (GimpPreview *preview);
void gimp_preview_draw (GimpPreview *preview);
@@ -149,6 +149,7 @@ void gimp_preview_invalidate (GimpPreview *preview);
void gimp_preview_set_default_cursor (GimpPreview *preview,
GdkCursor *cursor);
+GdkCursor * gimp_preview_get_default_cursor (GimpPreview *preview);
GtkWidget * gimp_preview_get_controls (GimpPreview *preview);
diff --git a/libgimpwidgets/gimpscrolledpreview.c b/libgimpwidgets/gimpscrolledpreview.c
index 0899337..5d3acf1 100644
--- a/libgimpwidgets/gimpscrolledpreview.c
+++ b/libgimpwidgets/gimpscrolledpreview.c
@@ -152,7 +152,11 @@ gimp_scrolled_preview_init (GimpScrolledPreview *preview)
{
GimpScrolledPreviewPrivate *priv;
GtkWidget *image;
+ GtkWidget *table;
+ GtkWidget *area;
GtkAdjustment *adj;
+ gint width;
+ gint height;
preview->priv = G_TYPE_INSTANCE_GET_PRIVATE (preview,
GIMP_TYPE_SCROLLED_PREVIEW,
@@ -168,54 +172,58 @@ gimp_scrolled_preview_init (GimpScrolledPreview *preview)
priv->in_drag = FALSE;
priv->frozen = 1; /* we are frozen during init */
+ table = gimp_preview_get_table (GIMP_PREVIEW (preview));
+
+ gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
+
/* scrollbars */
- adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, GIMP_PREVIEW (preview)->width - 1, 1.0,
- GIMP_PREVIEW (preview)->width,
- GIMP_PREVIEW (preview)->width));
+ adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, width - 1, 1.0,
+ width, width));
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_scrolled_preview_h_scroll),
preview);
priv->hscr = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, adj);
- gtk_table_attach (GTK_TABLE (GIMP_PREVIEW (preview)->table),
+ gtk_table_attach (GTK_TABLE (table),
priv->hscr, 0, 1, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
- adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, GIMP_PREVIEW (preview)->height - 1, 1.0,
- GIMP_PREVIEW (preview)->height,
- GIMP_PREVIEW (preview)->height));
+ adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, height - 1, 1.0,
+ height, height));
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_scrolled_preview_v_scroll),
preview);
priv->vscr = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, adj);
- gtk_table_attach (GTK_TABLE (GIMP_PREVIEW (preview)->table),
+ gtk_table_attach (GTK_TABLE (table),
priv->vscr, 1, 2, 0, 1,
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+ area = gimp_preview_get_area (GIMP_PREVIEW (preview));
+
/* Connect after here so that plug-ins get a chance to override the
* default behavior. See bug #364432.
*/
- g_signal_connect_after (GIMP_PREVIEW (preview)->area, "event",
+ g_signal_connect_after (area, "event",
G_CALLBACK (gimp_scrolled_preview_area_event),
preview);
- g_signal_connect (GIMP_PREVIEW (preview)->area, "realize",
+ g_signal_connect (area, "realize",
G_CALLBACK (gimp_scrolled_preview_area_realize),
preview);
- g_signal_connect (GIMP_PREVIEW (preview)->area, "unrealize",
+ g_signal_connect (area, "unrealize",
G_CALLBACK (gimp_scrolled_preview_area_unrealize),
preview);
- g_signal_connect (GIMP_PREVIEW (preview)->area, "size-allocate",
+ g_signal_connect (area, "size-allocate",
G_CALLBACK (gimp_scrolled_preview_area_size_allocate),
preview);
/* navigation icon */
priv->nav_icon = gtk_event_box_new ();
- gtk_table_attach (GTK_TABLE (GIMP_PREVIEW(preview)->table),
+ gtk_table_attach (GTK_TABLE (table),
priv->nav_icon, 1,2, 1,2,
GTK_SHRINK, GTK_SHRINK, 0, 0);
@@ -267,18 +275,20 @@ gimp_scrolled_preview_hscr_update (GimpScrolledPreview *preview)
{
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
GtkAdjustment *adj;
+ gint xmin, xmax;
gint width;
adj = gtk_range_get_adjustment (GTK_RANGE (priv->hscr));
- width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
+ gimp_preview_get_bounds (GIMP_PREVIEW (preview), &xmin, NULL, &xmax, NULL);
+ gimp_preview_get_size (GIMP_PREVIEW (preview), &width, NULL);
gtk_adjustment_configure (adj,
gtk_adjustment_get_value (adj),
- 0, width,
+ 0, xmax - xmin,
1.0,
- MAX (GIMP_PREVIEW (preview)->width / 2.0, 1.0),
- GIMP_PREVIEW (preview)->width);
+ MAX (width / 2.0, 1.0),
+ width);
}
static void
@@ -286,18 +296,20 @@ gimp_scrolled_preview_vscr_update (GimpScrolledPreview *preview)
{
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
GtkAdjustment *adj;
+ gint ymin, ymax;
gint height;
adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscr));
- height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
+ gimp_preview_get_bounds (GIMP_PREVIEW (preview), NULL, &ymin, NULL, &ymax);
+ gimp_preview_get_size (GIMP_PREVIEW (preview), NULL, &height);
gtk_adjustment_configure (adj,
gtk_adjustment_get_value (adj),
- 0, height,
+ 0, ymax - ymin,
1.0,
- MAX (GIMP_PREVIEW (preview)->height / 2.0, 1.0),
- GIMP_PREVIEW (preview)->height);
+ MAX (height / 2.0, 1.0),
+ height);
}
static void
@@ -306,22 +318,27 @@ gimp_scrolled_preview_area_size_allocate (GtkWidget *widget,
GimpScrolledPreview *preview)
{
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
+ gint xmin, ymin;
+ gint xmax, ymax;
+ gint width;
+ gint height;
- gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
- gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
+ gimp_preview_get_bounds (GIMP_PREVIEW (preview), &xmin, &ymin, &xmax, &ymax);
+ gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
gimp_scrolled_preview_freeze (preview);
- GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
- GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
+#if 0
+ GIMP_PREVIEW (preview)->width = MIN (xmax - xmin, allocation->width);
+ GIMP_PREVIEW (preview)->height = MIN (ymax - ymin, allocation->height);
+#endif
gimp_scrolled_preview_hscr_update (preview);
switch (priv->hscr_policy)
{
case GTK_POLICY_AUTOMATIC:
- gtk_widget_set_visible (priv->hscr,
- width > GIMP_PREVIEW (preview)->width);
+ gtk_widget_set_visible (priv->hscr, xmax - xmin > width);
break;
case GTK_POLICY_ALWAYS:
@@ -338,8 +355,7 @@ gimp_scrolled_preview_area_size_allocate (GtkWidget *widget,
switch (priv->vscr_policy)
{
case GTK_POLICY_AUTOMATIC:
- gtk_widget_set_visible (priv->vscr,
- height > GIMP_PREVIEW (preview)->height);
+ gtk_widget_set_visible (priv->vscr, ymax - ymin > height);
break;
case GTK_POLICY_ALWAYS:
@@ -367,6 +383,9 @@ gimp_scrolled_preview_area_event (GtkWidget *area,
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
GdkEventButton *button_event = (GdkEventButton *) event;
GdkCursor *cursor;
+ gint xoff, yoff;
+
+ gimp_preview_get_offsets (GIMP_PREVIEW (preview), &xoff, &yoff);
switch (event->type)
{
@@ -387,8 +406,8 @@ gimp_scrolled_preview_area_event (GtkWidget *area,
{
gtk_widget_get_pointer (area, &priv->drag_x, &priv->drag_y);
- priv->drag_xoff = GIMP_PREVIEW (preview)->xoff;
- priv->drag_yoff = GIMP_PREVIEW (preview)->yoff;
+ priv->drag_xoff = xoff;
+ priv->drag_yoff = yoff;
priv->in_drag = TRUE;
gtk_grab_add (area);
}
@@ -439,8 +458,8 @@ gimp_scrolled_preview_area_event (GtkWidget *area,
gtk_adjustment_get_upper (vadj) -
gtk_adjustment_get_page_size (vadj));
- if (GIMP_PREVIEW (preview)->xoff != x ||
- GIMP_PREVIEW (preview)->yoff != y)
+ if (xoff != x ||
+ yoff != y)
{
gtk_adjustment_set_value (hadj, x);
gtk_adjustment_set_value (vadj, y);
@@ -522,11 +541,18 @@ gimp_scrolled_preview_h_scroll (GtkAdjustment *hadj,
GimpPreview *preview)
{
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
+ GtkWidget *area;
+ gint xoff, yoff;
+
+ gimp_preview_get_offsets (preview, NULL, &yoff);
- preview->xoff = gtk_adjustment_get_value (hadj);
+ xoff = gtk_adjustment_get_value (hadj);
- gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (preview->area),
- preview->xoff, preview->yoff);
+ gimp_preview_set_offsets (preview, xoff, yoff);
+
+ area = gimp_preview_get_area (preview);
+
+ gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (area), xoff, yoff);
if (! (priv->in_drag || priv->frozen))
{
@@ -540,11 +566,18 @@ gimp_scrolled_preview_v_scroll (GtkAdjustment *vadj,
GimpPreview *preview)
{
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
+ GtkWidget *area;
+ gint xoff, yoff;
+
+ gimp_preview_get_offsets (preview, &xoff, NULL);
+
+ yoff = gtk_adjustment_get_value (vadj);
- preview->yoff = gtk_adjustment_get_value (vadj);
+ gimp_preview_set_offsets (preview, xoff, yoff);
- gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (preview->area),
- preview->xoff, preview->yoff);
+ area = gimp_preview_get_area (preview);
+
+ gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (area), xoff, yoff);
if (! (priv->in_drag || priv->frozen))
{
@@ -594,7 +627,7 @@ gimp_scrolled_preview_nav_button_press (GtkWidget *widget,
gtk_container_add (GTK_CONTAINER (outer), inner);
gtk_widget_show (inner);
- g_object_get (gimp_preview->area,
+ g_object_get (gimp_preview_get_area (gimp_preview),
"check-type", &check_type,
NULL);
@@ -799,20 +832,29 @@ static void
gimp_scrolled_preview_set_cursor (GimpPreview *preview)
{
GimpScrolledPreviewPrivate *priv = GET_PRIVATE (preview);
+ GtkWidget *area;
+ gint width, height;
+ gint xmin, ymin;
+ gint xmax, ymax;
+
+ area = gimp_preview_get_area (preview);
- if (! gtk_widget_get_realized (preview->area))
+ if (! gtk_widget_get_realized (area))
return;
- if (preview->xmax - preview->xmin > preview->width ||
- preview->ymax - preview->ymin > preview->height)
+ gimp_preview_get_size (preview, &width, &height);
+ gimp_preview_get_bounds (preview, &xmin, &ymin, &xmax, &ymax);
+
+ if (xmax - xmin > width ||
+ ymax - ymin > height)
{
- gdk_window_set_cursor (gtk_widget_get_window (preview->area),
+ gdk_window_set_cursor (gtk_widget_get_window (area),
priv->cursor_move);
}
else
{
- gdk_window_set_cursor (gtk_widget_get_window (preview->area),
- preview->default_cursor);
+ gdk_window_set_cursor (gtk_widget_get_window (area),
+ gimp_preview_get_default_cursor (preview));
}
}
@@ -831,6 +873,7 @@ gimp_scrolled_preview_set_position (GimpScrolledPreview *preview,
{
GimpScrolledPreviewPrivate *priv;
GtkAdjustment *adj;
+ gint xmin, ymin;
g_return_if_fail (GIMP_IS_SCROLLED_PREVIEW (preview));
@@ -841,11 +884,13 @@ gimp_scrolled_preview_set_position (GimpScrolledPreview *preview,
gimp_scrolled_preview_hscr_update (preview);
gimp_scrolled_preview_vscr_update (preview);
+ gimp_preview_get_bounds (GIMP_PREVIEW (preview), &xmin, &ymin, NULL, NULL);
+
adj = gtk_range_get_adjustment (GTK_RANGE (priv->hscr));
- gtk_adjustment_set_value (adj, x - GIMP_PREVIEW (preview)->xmin);
+ gtk_adjustment_set_value (adj, x - xmin);
adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscr));
- gtk_adjustment_set_value (adj, y - GIMP_PREVIEW (preview)->ymin);
+ gtk_adjustment_set_value (adj, y - ymin);
gimp_scrolled_preview_thaw (preview);
}
@@ -872,7 +917,7 @@ gimp_scrolled_preview_set_policy (GimpScrolledPreview *preview,
priv->hscr_policy = hscrollbar_policy;
priv->vscr_policy = vscrollbar_policy;
- gtk_widget_queue_resize (GIMP_PREVIEW (preview)->area);
+ gtk_widget_queue_resize (gimp_preview_get_area (GIMP_PREVIEW (preview)));
}
void
diff --git a/plug-ins/common/despeckle.c b/plug-ins/common/despeckle.c
index 7d1a001..e25a3f0 100644
--- a/plug-ins/common/despeckle.c
+++ b/plug-ins/common/despeckle.c
@@ -586,9 +586,7 @@ preview_update (GtkWidget *widget)
img_bpp = gimp_drawable_bpp (drawable->drawable_id);
- width = preview->width;
- height = preview->height;
-
+ gimp_preview_get_size (preview, &width, &height);
gimp_preview_get_position (preview, &x1, &y1);
gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, width, height, FALSE, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]