gint zoom;
gint max_zoom;
gint min_zoom;
+ gboolean zoom_to_mouse;
gfloat units_conv;
gchar *units_str;
static void gtk_map_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void gtk_map_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static gboolean gtk_map_button_press_cb(GtkWidget *widget, GdkEventButton *event);
+static gboolean gtk_map_button_release_cb(GtkWidget *widget, GdkEventButton *event);
+static gboolean gtk_map_scroll_event_cb(GtkWidget *widget, GdkEventScroll *event);
+
/* Signal IDs */
enum {
MAP_LOCATION_CHANGED,
-
- MAP_ZOOMED_IN,
- MAP_ZOOMED_OUT,
-
+ MAP_ZOOM_CHANGED,
MAP_PANNED,
-
MARKER_CLICK,
-
LAST_SIGNAL
};
widget_class->size_allocate = gtk_map_size_allocate;
g_type_class_add_private (object_class, sizeof(GtkMapPriv));
+
+gtk_map_signals[MAP_ZOOM_CHANGED]=g_signal_new("zoom-changed", G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkMapClass, zoom_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+
}
static inline void
priv->zoom=3;
priv->min_zoom=0;
priv->max_zoom=17;
+priv->zoom_to_mouse=TRUE;
priv->center_mode=CENTER_LATLON;
priv->center.unitx=0;
}
#endif
+#if 0
+g_signal_connect(G_OBJECT(map), "button_press_event", G_CALLBACK(map_cb_button_press), NULL);
+g_signal_connect(G_OBJECT(map), "button_release_event",G_CALLBACK(map_cb_button_release), NULL);
+#endif
+
+g_signal_connect(G_OBJECT(map), "scroll_event", G_CALLBACK(gtk_map_scroll_event_cb), NULL);
+
priv->scale_context=gtk_widget_get_pango_context(widget);
priv->scale_layout=pango_layout_new(priv->scale_context);
priv->scale_font=pango_font_description_new();
}
-static void
-draw (GtkWidget *clock, cairo_t *cr)
-{
- double x, y;
- double radius;
- int i;
-
- x = clock->allocation.x + clock->allocation.width / 2;
- y = clock->allocation.y + clock->allocation.height / 2;
- radius = MIN (clock->allocation.width / 2, clock->allocation.height / 2) - 5;
-
- /* clock back */
- cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
- cairo_set_source_rgb (cr, 1, 1, 1);
- cairo_fill_preserve (cr);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_stroke (cr);
-}
-
static gboolean
gtk_map_expose(GtkWidget *widget, GdkEventExpose *event)
{
gtk_map_recalc_focus_size(priv);
gtk_map_refresh(widget);
+g_signal_emit(widget, gtk_map_signals[MAP_ZOOM_CHANGED], 0, priv->zoom);
return TRUE;
}
cache_size=512;
image_cache_set_size(priv->icache, cache_size);
}
+
+/**
+ * Mouse scroller zoom in/out callback
+ */
+static gboolean
+gtk_map_scroll_event_cb(GtkWidget *widget, GdkEventScroll *event)
+{
+GtkMap *map;
+GtkMapPriv *priv;
+
+g_return_if_fail(GTK_IS_MAP(widget));
+
+map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
+gtk_map_zoom(widget, event->direction==GDK_SCROLL_UP ? -1 : 1);
+if (priv->zoom_to_mouse)
+ gtk_map_set_center(widget, x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5)));
+return FALSE;
+}