Commit 1980b9f3 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

update the cursor only when a window is present

added map/unmap to the gth-image-viewer-tool interface
parent 115b4152
......@@ -67,6 +67,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)
{
......@@ -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;
......
......@@ -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;
......
......@@ -50,6 +50,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)
{
......
......@@ -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,
......
......@@ -410,6 +410,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)
{
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment