[gthumb] image-viewer-tool: added [set|unset]_viewer functions
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] image-viewer-tool: added [set|unset]_viewer functions
- Date: Tue, 17 May 2011 22:11:02 +0000 (UTC)
commit ac839cd7d49d8072f850bba82b29446cca9cb0a2
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue May 17 23:55:21 2011 +0200
image-viewer-tool: added [set|unset]_viewer functions
extensions/file_tools/gth-file-tool-crop.c | 2 +-
extensions/file_tools/gth-image-rotator.c | 52 +++++++++++++++++---
extensions/file_tools/gth-image-rotator.h | 2 +-
extensions/red_eye_removal/gth-file-tool-red-eye.c | 2 +-
gthumb/gth-image-dragger.c | 29 ++++++++---
gthumb/gth-image-dragger.h | 3 +-
gthumb/gth-image-selector.c | 24 ++++++++-
gthumb/gth-image-selector.h | 4 +-
gthumb/gth-image-viewer-tool.c | 18 ++++++-
gthumb/gth-image-viewer-tool.h | 8 +++
gthumb/gth-image-viewer.c | 12 +++--
gthumb/gth-image-viewer.h | 5 ++-
12 files changed, 130 insertions(+), 31 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-crop.c b/extensions/file_tools/gth-file-tool-crop.c
index 2fde58d..f5f82a7 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -519,7 +519,7 @@ gth_file_tool_crop_get_options (GthFileTool *base)
G_CALLBACK (center_button_clicked_cb),
self);
- self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
+ self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_SELECTOR_TYPE_REGION);
gth_image_selector_set_grid_type (self->priv->selector, gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->grid_type_combobox)));
gth_image_selector_bind_dimensions (self->priv->selector,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET("bind_dimensions_checkbutton"))),
diff --git a/extensions/file_tools/gth-image-rotator.c b/extensions/file_tools/gth-image-rotator.c
index 2349b82..a3a151e 100644
--- a/extensions/file_tools/gth-image-rotator.c
+++ b/extensions/file_tools/gth-image-rotator.c
@@ -65,10 +65,38 @@ struct _GthImageRotatorPrivate {
GdkPoint preview_center;
GdkRectangle clip_area;
cairo_matrix_t matrix;
+ GthFit original_fit_mode;
+ gboolean original_zoom_enabled;
};
static void
+gth_image_rotator_set_viewer (GthImageViewerTool *base,
+ GthImageViewer *viewer)
+{
+ GthImageRotator *self = GTH_IMAGE_ROTATOR (base);
+
+ self->priv->viewer = viewer;
+ self->priv->original_fit_mode = gth_image_viewer_get_fit_mode (GTH_IMAGE_VIEWER (viewer));
+ self->priv->original_zoom_enabled = gth_image_viewer_get_zoom_enabled (GTH_IMAGE_VIEWER (viewer));
+ gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (viewer), GTH_FIT_SIZE_IF_LARGER);
+ gth_image_viewer_set_zoom_enabled (GTH_IMAGE_VIEWER (viewer), FALSE);
+}
+
+
+static void
+gth_image_rotator_unset_viewer (GthImageViewerTool *base,
+ GthImageViewer *viewer)
+{
+ GthImageRotator *self = GTH_IMAGE_ROTATOR (base);
+
+ gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (viewer), self->priv->original_fit_mode);
+ gth_image_viewer_set_zoom_enabled (GTH_IMAGE_VIEWER (viewer), self->priv->original_zoom_enabled);
+ self->priv->viewer = NULL;
+}
+
+
+static void
gth_image_rotator_realize (GthImageViewerTool *base)
{
/* void */
@@ -498,6 +526,8 @@ gth_image_rotator_class_init (GthImageRotatorClass *class)
static void
gth_image_rotator_gth_image_tool_interface_init (GthImageViewerToolIface *iface)
{
+ iface->set_viewer = gth_image_rotator_set_viewer;
+ iface->unset_viewer = gth_image_rotator_unset_viewer;
iface->realize = gth_image_rotator_realize;
iface->unrealize = gth_image_rotator_unrealize;
iface->size_allocate = gth_image_rotator_size_allocate;
@@ -547,12 +577,11 @@ gth_image_rotator_get_type (void)
GthImageViewerTool *
-gth_image_rotator_new (GthImageViewer *viewer)
+gth_image_rotator_new (void)
{
GthImageRotator *rotator;
rotator = g_object_new (GTH_TYPE_IMAGE_ROTATOR, NULL);
- rotator->priv->viewer = viewer;
rotator->priv->angle = 0.0;
return GTH_IMAGE_VIEWER_TOOL (rotator);
@@ -589,7 +618,9 @@ gth_image_rotator_set_center (GthImageRotator *self,
self->priv->center.x = x;
self->priv->center.y = y;
_gth_image_rotator_update_tranformation_matrix (self);
- gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+
+ if (self->priv->viewer != NULL)
+ gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
g_signal_emit (self, signals[CENTER_CHANGED], 0);
}
@@ -616,7 +647,9 @@ gth_image_rotator_set_angle (GthImageRotator *self,
return;
self->priv->angle = radiants;
_gth_image_rotator_update_tranformation_matrix (self);
- gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+
+ if (self->priv->viewer != NULL)
+ gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
g_signal_emit (self, signals[CHANGED], 0);
}
@@ -635,7 +668,9 @@ gth_image_rotator_set_resize (GthImageRotator *self,
{
self->priv->resize = resize;
_gth_image_rotator_update_tranformation_matrix (self);
- gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+
+ if (self->priv->viewer != NULL)
+ gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
g_signal_emit (self, signals[CHANGED], 0);
}
@@ -656,7 +691,8 @@ gth_image_rotator_set_crop_region (GthImageRotator *self,
if (region != NULL)
self->priv->crop_region = *region;
- gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+ if (self->priv->viewer != NULL)
+ gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
g_signal_emit (self, signals[CHANGED], 0);
}
@@ -667,7 +703,9 @@ gth_image_rotator_set_background (GthImageRotator *self,
cairo_color_t *color)
{
self->priv->background_color = *color;
- gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+
+ if (self->priv->viewer != NULL)
+ gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
g_signal_emit (self, signals[CHANGED], 0);
}
diff --git a/extensions/file_tools/gth-image-rotator.h b/extensions/file_tools/gth-image-rotator.h
index f7d71d6..b811bc0 100644
--- a/extensions/file_tools/gth-image-rotator.h
+++ b/extensions/file_tools/gth-image-rotator.h
@@ -62,7 +62,7 @@ struct _GthImageRotatorClass
};
GType gth_image_rotator_get_type (void);
-GthImageViewerTool * gth_image_rotator_new (GthImageViewer *viewer);
+GthImageViewerTool * gth_image_rotator_new (void);
void gth_image_rotator_set_grid_type (GthImageRotator *self,
GthGridType grid_type);
GthGridType gth_image_rotator_get_grid_type (GthImageRotator *self);
diff --git a/extensions/red_eye_removal/gth-file-tool-red-eye.c b/extensions/red_eye_removal/gth-file-tool-red-eye.c
index 3e37233..9b1c9ee 100644
--- a/extensions/red_eye_removal/gth-file-tool-red-eye.c
+++ b/extensions/red_eye_removal/gth-file-tool-red-eye.c
@@ -414,7 +414,7 @@ gth_file_tool_red_eye_get_options (GthFileTool *base)
viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
self->priv->original_zoom_change = gth_image_viewer_get_zoom_change (GTH_IMAGE_VIEWER (viewer));
gth_image_viewer_set_zoom_change (GTH_IMAGE_VIEWER (viewer), GTH_ZOOM_CHANGE_KEEP_PREV);
- self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_POINT);
+ self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_SELECTOR_TYPE_POINT);
gth_image_selector_set_mask_visible (self->priv->selector, FALSE);
g_signal_connect (self->priv->selector,
"selected",
diff --git a/gthumb/gth-image-dragger.c b/gthumb/gth-image-dragger.c
index 414651a..1cc5a76 100644
--- a/gthumb/gth-image-dragger.c
+++ b/gthumb/gth-image-dragger.c
@@ -66,6 +66,24 @@ gth_image_dragger_instance_init (GthImageDragger *dragger)
static void
+gth_image_dragger_set_viewer (GthImageViewerTool *base,
+ GthImageViewer *image_viewer)
+{
+ GthImageDragger *self = GTH_IMAGE_DRAGGER (base);
+ self->priv->viewer = image_viewer;
+}
+
+
+static void
+gth_image_dragger_unset_viewer (GthImageViewerTool *base,
+ GthImageViewer *image_viewer)
+{
+ GthImageDragger *self = GTH_IMAGE_DRAGGER (base);
+ self->priv->viewer = NULL;
+}
+
+
+static void
gth_image_dragger_realize (GthImageViewerTool *base)
{
/* void */
@@ -276,6 +294,8 @@ gth_image_dragger_zoom_changed (GthImageViewerTool *self)
static void
gth_image_dragger_gth_image_tool_interface_init (GthImageViewerToolIface *iface)
{
+ iface->set_viewer = gth_image_dragger_set_viewer;
+ iface->unset_viewer = gth_image_dragger_unset_viewer;
iface->realize = gth_image_dragger_realize;
iface->unrealize = gth_image_dragger_unrealize;
iface->size_allocate = gth_image_dragger_size_allocate;
@@ -325,12 +345,7 @@ gth_image_dragger_get_type (void)
GthImageViewerTool *
-gth_image_dragger_new (GthImageViewer *viewer)
+gth_image_dragger_new (void)
{
- GthImageDragger *dragger;
-
- dragger = g_object_new (GTH_TYPE_IMAGE_DRAGGER, NULL);
- dragger->priv->viewer = viewer;
-
- return GTH_IMAGE_VIEWER_TOOL (dragger);
+ return (GthImageViewerTool *) g_object_new (GTH_TYPE_IMAGE_DRAGGER, NULL);
}
diff --git a/gthumb/gth-image-dragger.h b/gthumb/gth-image-dragger.h
index 89aa182..f778449 100644
--- a/gthumb/gth-image-dragger.h
+++ b/gthumb/gth-image-dragger.h
@@ -25,7 +25,6 @@
#include <glib.h>
#include <glib-object.h>
#include "gth-image-viewer.h"
-#include "gth-image-viewer-tool.h"
G_BEGIN_DECLS
@@ -52,7 +51,7 @@ struct _GthImageDraggerClass
};
GType gth_image_dragger_get_type (void);
-GthImageViewerTool * gth_image_dragger_new (GthImageViewer *viewer);
+GthImageViewerTool * gth_image_dragger_new (void);
G_END_DECLS
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index 9fad640..df825d8 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -515,6 +515,24 @@ init_selection (GthImageSelector *self)
static void
+gth_image_selector_set_viewer (GthImageViewerTool *base,
+ GthImageViewer *image_viewer)
+{
+ GthImageSelector *self = GTH_IMAGE_SELECTOR (base);
+ self->priv->viewer = image_viewer;
+}
+
+
+static void
+gth_image_selector_unset_viewer (GthImageViewerTool *base,
+ GthImageViewer *image_viewer)
+{
+ GthImageSelector *self = GTH_IMAGE_SELECTOR (base);
+ self->priv->viewer = NULL;
+}
+
+
+static void
gth_image_selector_realize (GthImageViewerTool *base)
{
GthImageSelector *self = GTH_IMAGE_SELECTOR (base);
@@ -1572,6 +1590,8 @@ gth_image_selector_class_init (GthImageSelectorClass *class)
static void
gth_image_selector_gth_image_tool_interface_init (GthImageViewerToolIface *iface)
{
+ iface->set_viewer = gth_image_selector_set_viewer;
+ iface->unset_viewer = gth_image_selector_unset_viewer;
iface->realize = gth_image_selector_realize;
iface->unrealize = gth_image_selector_unrealize;
iface->size_allocate = gth_image_selector_size_allocate;
@@ -1621,13 +1641,11 @@ gth_image_selector_get_type (void)
GthImageViewerTool *
-gth_image_selector_new (GthImageViewer *viewer,
- GthSelectorType type)
+gth_image_selector_new (GthSelectorType type)
{
GthImageSelector *selector;
selector = g_object_new (GTH_TYPE_IMAGE_SELECTOR, NULL);
- selector->priv->viewer = viewer;
selector->priv->type = type;
return GTH_IMAGE_VIEWER_TOOL (selector);
diff --git a/gthumb/gth-image-selector.h b/gthumb/gth-image-selector.h
index 610615b..bf59ad1 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -25,7 +25,6 @@
#include <glib.h>
#include <glib-object.h>
#include "gth-image-viewer.h"
-#include "gth-image-viewer-tool.h"
G_BEGIN_DECLS
@@ -69,8 +68,7 @@ struct _GthImageSelectorClass
};
GType gth_image_selector_get_type (void);
-GthImageViewerTool * gth_image_selector_new (GthImageViewer *viewer,
- GthSelectorType type);
+GthImageViewerTool * gth_image_selector_new (GthSelectorType type);
gboolean gth_image_selector_set_selection_x (GthImageSelector *selector,
int x);
gboolean gth_image_selector_set_selection_y (GthImageSelector *selector,
diff --git a/gthumb/gth-image-viewer-tool.c b/gthumb/gth-image-viewer-tool.c
index 99d282a..76ddd4e 100644
--- a/gthumb/gth-image-viewer-tool.c
+++ b/gthumb/gth-image-viewer-tool.c
@@ -20,7 +20,7 @@
*/
#include <config.h>
-#include "gth-image-viewer-tool.h"
+#include "gth-image-viewer.h"
GType
@@ -50,6 +50,22 @@ gth_image_viewer_tool_get_type (void)
void
+gth_image_viewer_tool_set_viewer (GthImageViewerTool *self,
+ GthImageViewer *viewer)
+{
+ GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->set_viewer (self, viewer);
+}
+
+
+void
+gth_image_viewer_tool_unset_viewer (GthImageViewerTool *self,
+ GthImageViewer *viewer)
+{
+ GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->unset_viewer (self, viewer);
+}
+
+
+void
gth_image_viewer_tool_map (GthImageViewerTool *self)
{
GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->map (self);
diff --git a/gthumb/gth-image-viewer-tool.h b/gthumb/gth-image-viewer-tool.h
index cef89e4..df78c48 100644
--- a/gthumb/gth-image-viewer-tool.h
+++ b/gthumb/gth-image-viewer-tool.h
@@ -37,6 +37,10 @@ typedef struct _GthImageViewerToolIface GthImageViewerToolIface;
struct _GthImageViewerToolIface {
GTypeInterface parent_iface;
+ void (*set_viewer) (GthImageViewerTool *self,
+ GthImageViewer *viewer);
+ void (*unset_viewer) (GthImageViewerTool *self,
+ GthImageViewer *viewer);
void (*map) (GthImageViewerTool *self);
void (*unmap) (GthImageViewerTool *self);
void (*realize) (GthImageViewerTool *self);
@@ -57,6 +61,10 @@ struct _GthImageViewerToolIface {
};
GType gth_image_viewer_tool_get_type (void);
+void gth_image_viewer_tool_set_viewer (GthImageViewerTool *self,
+ GthImageViewer *viewer);
+void gth_image_viewer_tool_unset_viewer (GthImageViewerTool *self,
+ GthImageViewer *viewer);
void gth_image_viewer_tool_map (GthImageViewerTool *self);
void gth_image_viewer_tool_unmap (GthImageViewerTool *self);
void gth_image_viewer_tool_realize (GthImageViewerTool *self);
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 224260d..916e63e 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -1493,7 +1493,7 @@ gth_image_viewer_instance_init (GthImageViewer *self)
self->priv->reset_scrollbars = TRUE;
self->priv->update_adjustment_values = 0;
- self->priv->tool = gth_image_dragger_new (self);
+ gth_image_viewer_set_tool (self, NULL);
/* Create the widget. */
@@ -1997,7 +1997,7 @@ gth_image_viewer_set_zoom (GthImageViewer *self,
{
GtkAllocation allocation;
- if (! self->priv->zoom_enabled)
+ if (! self->priv->zoom_enabled && ! self->priv->doing_zoom_fit)
return;
gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
@@ -2259,11 +2259,15 @@ void
gth_image_viewer_set_tool (GthImageViewer *self,
GthImageViewerTool *tool)
{
- _g_object_unref (self->priv->tool);
+ if (self->priv->tool != NULL) {
+ gth_image_viewer_tool_unset_viewer (self->priv->tool, self);
+ g_object_unref (self->priv->tool);
+ }
if (tool == NULL)
- self->priv->tool = gth_image_dragger_new (self);
+ self->priv->tool = gth_image_dragger_new ();
else
self->priv->tool = g_object_ref (tool);
+ gth_image_viewer_tool_set_viewer (self->priv->tool, self);
if (gtk_widget_get_realized (GTK_WIDGET (self)))
gth_image_viewer_tool_realize (self->priv->tool);
gth_image_viewer_tool_image_changed (self->priv->tool);
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index bad66a5..f9b63ec 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -25,6 +25,9 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "gth-image.h"
+
+typedef struct _GthImageViewer GthImageViewer;
+
#include "gth-image-viewer-tool.h"
G_BEGIN_DECLS
@@ -36,7 +39,7 @@ G_BEGIN_DECLS
#define GTH_IS_IMAGE_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_IMAGE_VIEWER))
#define GTH_IMAGE_VIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_IMAGE_VIEWER, GthImageViewerClass))
-typedef struct _GthImageViewer GthImageViewer;
+
typedef struct _GthImageViewerClass GthImageViewerClass;
typedef struct _GthImageViewerPrivate GthImageViewerPrivate;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]