[gthumb/ext] update the cursor only when a window is present



commit 1980b9f34a6ff74c4da4eaef5fc7e40594526baf
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Sep 4 15:48:13 2009 +0200

    update the cursor only when a window is present
    
    added map/unmap to the gth-image-viewer-tool interface

 gthumb/gth-image-dragger.c     |   49 ++++++++++++++++++++++++++++++---------
 gthumb/gth-image-selector.c    |   16 +++++++++++++
 gthumb/gth-image-viewer-tool.c |   14 +++++++++++
 gthumb/gth-image-viewer-tool.h |    4 +++
 gthumb/gth-image-viewer.c      |   30 ++++++++++++++++++++++++
 5 files changed, 101 insertions(+), 12 deletions(-)
---
diff --git a/gthumb/gth-image-dragger.c b/gthumb/gth-image-dragger.c
index d987de2..2093f34 100644
--- a/gthumb/gth-image-dragger.c
+++ b/gthumb/gth-image-dragger.c
@@ -68,6 +68,21 @@ gth_image_dragger_instance_init (GthImageDragger *dragger)
 
 
 static void
+_gth_image_dragger_update_cursor (GthImageDragger *self)
+{
+	GdkCursor *cursor;
+
+	if (self->priv->draggable)
+		cursor = gth_cursor_get (gtk_widget_get_window (GTK_WIDGET (self->priv->viewer)), GTH_CURSOR_HAND_OPEN);
+	else
+		cursor = gdk_cursor_new (GDK_LEFT_PTR);
+	gth_image_viewer_set_cursor (self->priv->viewer, cursor);
+
+	gdk_cursor_unref (cursor);
+}
+
+
+static void
 gth_image_dragger_realize (GthImageViewerTool *base)
 {
 	/* void */
@@ -82,24 +97,32 @@ gth_image_dragger_unrealize (GthImageViewerTool *base)
 
 
 static void
-gth_image_dragger_size_allocate (GthImageViewerTool  *self,
+gth_image_dragger_size_allocate (GthImageViewerTool  *base,
 				 GtkAllocation       *allocation)
 {
-	GthImageDragger *dragger;
+	GthImageDragger *self;
 	GthImageViewer  *viewer;
-	GdkCursor       *cursor;
 
-	dragger = (GthImageDragger *) self;
-	viewer = (GthImageViewer *) dragger->priv->viewer;
+	self = (GthImageDragger *) base;
+	viewer = (GthImageViewer *) self->priv->viewer;
 
-	dragger->priv->draggable = (viewer->hadj->upper > viewer->hadj->page_size) || (viewer->vadj->upper > viewer->vadj->page_size);
-	if (dragger->priv->draggable)
-		cursor = gth_cursor_get (GTK_WIDGET (viewer)->window, GTH_CURSOR_HAND_OPEN);
-	else
-		cursor = gdk_cursor_new (GDK_LEFT_PTR);
-	gth_image_viewer_set_cursor (viewer, cursor);
+	self->priv->draggable = (viewer->hadj->upper > viewer->hadj->page_size) || (viewer->vadj->upper > viewer->vadj->page_size);
+	if (GTK_WIDGET_REALIZED (viewer))
+		_gth_image_dragger_update_cursor (self);
+}
 
-	gdk_cursor_unref (cursor);
+
+static void
+gth_image_dragger_map (GthImageViewerTool *base)
+{
+	/* void */
+}
+
+
+static void
+gth_image_dragger_unmap (GthImageViewerTool *base)
+{
+	/* void */
 }
 
 
@@ -248,6 +271,8 @@ gth_image_dragger_gth_image_tool_interface_init (GthImageViewerToolIface *iface)
 	iface->realize = gth_image_dragger_realize;
 	iface->unrealize = gth_image_dragger_unrealize;
 	iface->size_allocate = gth_image_dragger_size_allocate;
+	iface->map = gth_image_dragger_map;
+	iface->unmap = gth_image_dragger_unmap;
 	iface->expose = gth_image_dragger_expose;
 	iface->button_press = gth_image_dragger_button_press;
 	iface->button_release = gth_image_dragger_button_release;
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index aefe823..0fe16e0 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -569,6 +569,20 @@ gth_image_selector_size_allocate (GthImageViewerTool *base,
 }
 
 
+static void
+gth_image_selector_map (GthImageViewerTool *base)
+{
+	/* void */
+}
+
+
+static void
+gth_image_selector_unmap (GthImageViewerTool *base)
+{
+	/* void */
+}
+
+
 G_GNUC_UNUSED
 static void
 print_rectangle (const char   *name,
@@ -1344,6 +1358,8 @@ gth_image_selector_gth_image_tool_interface_init (GthImageViewerToolIface *iface
 	iface->realize = gth_image_selector_realize;
 	iface->unrealize = gth_image_selector_unrealize;
 	iface->size_allocate = gth_image_selector_size_allocate;
+	iface->map = gth_image_selector_map;
+	iface->unmap = gth_image_selector_unmap;
 	iface->expose = gth_image_selector_expose;
 	iface->button_press = gth_image_selector_button_press;
 	iface->button_release = gth_image_selector_button_release;
diff --git a/gthumb/gth-image-viewer-tool.c b/gthumb/gth-image-viewer-tool.c
index c56d35a..46c82fb 100644
--- a/gthumb/gth-image-viewer-tool.c
+++ b/gthumb/gth-image-viewer-tool.c
@@ -51,6 +51,20 @@ gth_image_viewer_tool_get_type (void)
 
 
 void
+gth_image_viewer_tool_map (GthImageViewerTool *self)
+{
+	GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->map (self);
+}
+
+
+void
+gth_image_viewer_tool_unmap (GthImageViewerTool *self)
+{
+	GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->unmap (self);
+}
+
+
+void
 gth_image_viewer_tool_realize (GthImageViewerTool *self)
 {
 	GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->realize (self);
diff --git a/gthumb/gth-image-viewer-tool.h b/gthumb/gth-image-viewer-tool.h
index be2f28b..1a30398 100644
--- a/gthumb/gth-image-viewer-tool.h
+++ b/gthumb/gth-image-viewer-tool.h
@@ -38,6 +38,8 @@ typedef struct _GthImageViewerToolIface GthImageViewerToolIface;
 struct _GthImageViewerToolIface {
 	GTypeInterface parent_iface;
 
+	void      (*map)            (GthImageViewerTool   *self);
+	void      (*unmap)          (GthImageViewerTool   *self);
 	void      (*realize)        (GthImageViewerTool   *self);
 	void      (*unrealize)      (GthImageViewerTool   *self);
 	void      (*size_allocate)  (GthImageViewerTool   *self,
@@ -55,6 +57,8 @@ struct _GthImageViewerToolIface {
 };
 
 GType      gth_image_viewer_tool_get_type         (void);
+void       gth_image_viewer_tool_map              (GthImageViewerTool *self);
+void       gth_image_viewer_tool_unmap            (GthImageViewerTool *self);
 void       gth_image_viewer_tool_realize          (GthImageViewerTool *self);
 void       gth_image_viewer_tool_unrealize        (GthImageViewerTool *self);
 void       gth_image_viewer_tool_size_allocate    (GthImageViewerTool *self,
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index fda7c3d..d253884 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -411,6 +411,34 @@ gth_image_viewer_unrealize (GtkWidget *widget)
 
 
 static void
+gth_image_viewer_map (GtkWidget *widget)
+{
+	GthImageViewer *viewer;
+
+	g_return_if_fail (GTH_IS_IMAGE_VIEWER (widget));
+
+	GTK_WIDGET_CLASS (parent_class)->map (widget);
+
+	viewer = GTH_IMAGE_VIEWER (widget);
+	gth_image_viewer_tool_map (viewer->priv->tool);
+}
+
+
+static void
+gth_image_viewer_unmap (GtkWidget *widget)
+{
+	GthImageViewer *viewer;
+
+	g_return_if_fail (GTH_IS_IMAGE_VIEWER (widget));
+
+	viewer = GTH_IMAGE_VIEWER (widget);
+	gth_image_viewer_tool_unmap (viewer->priv->tool);
+
+	GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+}
+
+
+static void
 zoom_to_fit (GthImageViewer *viewer)
 {
 	GdkPixbuf *buf;
@@ -1469,6 +1497,8 @@ gth_image_viewer_class_init (GthImageViewerClass *class)
 
 	widget_class->realize         = gth_image_viewer_realize;
 	widget_class->unrealize       = gth_image_viewer_unrealize;
+	widget_class->map             = gth_image_viewer_map;
+	widget_class->unmap           = gth_image_viewer_unmap;
 	widget_class->size_allocate   = gth_image_viewer_size_allocate;
 	widget_class->focus_in_event  = gth_image_viewer_focus_in;
 	widget_class->focus_out_event = gth_image_viewer_focus_out;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]