[evolution/gtk3: 7/10] Adapt EMap to latest gtk+-3.0 API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gtk3: 7/10] Adapt EMap to latest gtk+-3.0 API.
- Date: Thu, 11 Nov 2010 19:08:04 +0000 (UTC)
commit 2b9684fc6c54b3690c083acac5c65a19600ddbe2
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Nov 9 09:45:28 2010 -0500
Adapt EMap to latest gtk+-3.0 API.
widgets/misc/e-map.c | 986 ++++++++++++++++++++++----------------------------
1 files changed, 431 insertions(+), 555 deletions(-)
---
diff --git a/widgets/misc/e-map.c b/widgets/misc/e-map.c
index 4c292bf..b18b608 100644
--- a/widgets/misc/e-map.c
+++ b/widgets/misc/e-map.c
@@ -64,11 +64,11 @@ EMapZoomState;
typedef struct _EMapTween EMapTween;
struct _EMapTween {
- guint start_time;
- guint end_time;
- double longitude_offset;
- double latitude_offset;
- double zoom_factor;
+ guint start_time;
+ guint end_time;
+ gdouble longitude_offset;
+ gdouble latitude_offset;
+ gdouble zoom_factor;
};
/* Private part of the EMap structure */
@@ -76,7 +76,7 @@ struct _EMapTween {
struct _EMapPrivate {
/* Pointer to map image */
GdkPixbuf *map_pixbuf;
- cairo_surface_t *map_render_surface;
+ cairo_surface_t *map_render_surface;
/* Settings */
gboolean frozen, smooth_zoom;
@@ -95,36 +95,24 @@ struct _EMapPrivate {
/* Dots */
GPtrArray *points;
- /* Tweens */
- GSList *tweens;
- GTimer *timer;
- guint timer_current_ms;
- guint tween_id;
+ /* Tweens */
+ GSList *tweens;
+ GTimer *timer;
+ guint timer_current_ms;
+ guint tween_id;
};
/* Internal prototypes */
-static void e_map_finalize (GObject *object);
-static void e_map_realize (GtkWidget *widget);
-static void e_map_unrealize (GtkWidget *widget);
-static void e_map_size_request (GtkWidget *widget, GtkRequisition *requisition);
-static void e_map_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
-static gint e_map_button_press (GtkWidget *widget, GdkEventButton *event);
-static gint e_map_button_release (GtkWidget *widget, GdkEventButton *event);
-static gint e_map_motion (GtkWidget *widget, GdkEventMotion *event);
-static gint e_map_expose (GtkWidget *widget, GdkEventExpose *event);
-static gint e_map_key_press (GtkWidget *widget, GdkEventKey *event);
-static void e_map_set_scroll_adjustments (GtkWidget *widget, GtkAdjustment *hadj, GtkAdjustment *vadj);
-
-static void e_map_get_current_location (EMap *map, double *longitude, double *latitude);
+static void e_map_get_current_location (EMap *map, gdouble *longitude, gdouble *latitude);
static void e_map_world_to_render_surface (EMap *map, gdouble world_longitude, gdouble world_latitude,
gdouble *win_x, gdouble *win_y);
static void update_render_surface (EMap *map, gboolean render_overlays);
-static void set_scroll_area (EMap *view, gint width, gint height);
-static void center_at (EMap *map, double longitude, double latitude);
-static void scroll_to (EMap *view, gint x, gint y);
-static gint load_map_background (EMap *view, gchar *name);
-static void adjustment_changed_cb (GtkAdjustment *adj, gpointer data);
+static void set_scroll_area (EMap *map, gint width, gint height);
+static void center_at (EMap *map, gdouble longitude, gdouble latitude);
+static void scroll_to (EMap *map, gint x, gint y);
+static gint load_map_background (EMap *map, gchar *name);
+static void adjustment_changed_cb (EMap *map);
static void update_and_paint (EMap *map);
static void update_render_point (EMap *map, EMapPoint *point);
static void repaint_point (EMap *map, EMapPoint *point);
@@ -134,104 +122,96 @@ static void repaint_point (EMap *map, EMapPoint *point);
* ------ */
static gboolean
-e_map_is_tweening (EMap *view)
+e_map_is_tweening (EMap *map)
{
- return view->priv->timer != NULL;
+ return map->priv->timer != NULL;
}
static void
-e_map_stop_tweening (EMap *view)
+e_map_stop_tweening (EMap *map)
{
- EMapPrivate *priv = view->priv;
+ g_assert (map->priv->tweens == NULL);
- g_assert (priv->tweens == NULL);
-
- if (!e_map_is_tweening (view))
- return;
+ if (!e_map_is_tweening (map))
+ return;
- g_timer_destroy (priv->timer);
- priv->timer = NULL;
- g_source_remove (priv->tween_id);
- priv->tween_id = 0;
+ g_timer_destroy (map->priv->timer);
+ map->priv->timer = NULL;
+ g_source_remove (map->priv->tween_id);
+ map->priv->tween_id = 0;
}
static void
-e_map_tween_destroy (EMap *view, EMapTween *tween)
+e_map_tween_destroy (EMap *map, EMapTween *tween)
{
- EMapPrivate *priv = view->priv;
+ map->priv->tweens = g_slist_remove (map->priv->tweens, tween);
+ g_slice_free (EMapTween, tween);
- priv->tweens = g_slist_remove (priv->tweens, tween);
- g_slice_free (EMapTween, tween);
-
- if (priv->tweens == NULL)
- e_map_stop_tweening (view);
+ if (map->priv->tweens == NULL)
+ e_map_stop_tweening (map);
}
static gboolean
e_map_do_tween_cb (gpointer data)
{
- EMap *view = data;
- EMapPrivate *priv = view->priv;
- GSList *walk;
+ EMap *map = data;
+ GSList *walk;
- priv->timer_current_ms = g_timer_elapsed (priv->timer, NULL) * 1000;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ map->priv->timer_current_ms =
+ g_timer_elapsed (map->priv->timer, NULL) * 1000;
+ gtk_widget_queue_draw (GTK_WIDGET (map));
- /* Can't use for loop here, because we need to advance
- * the list before deleting.
- */
- walk = priv->tweens;
- while (walk)
- {
- EMapTween *tween = walk->data;
+ /* Can't use for loop here, because we need to advance
+ * the list before deleting.
+ */
+ walk = map->priv->tweens;
+ while (walk)
+ {
+ EMapTween *tween = walk->data;
- walk = walk->next;
+ walk = walk->next;
- if (tween->end_time <= priv->timer_current_ms)
- e_map_tween_destroy (view, tween);
- }
+ if (tween->end_time <= map->priv->timer_current_ms)
+ e_map_tween_destroy (map, tween);
+ }
- return TRUE;
+ return TRUE;
}
static void
-e_map_start_tweening (EMap *view)
+e_map_start_tweening (EMap *map)
{
- EMapPrivate *priv = view->priv;
-
- if (e_map_is_tweening (view))
- return;
+ if (e_map_is_tweening (map))
+ return;
- priv->timer = g_timer_new ();
- priv->timer_current_ms = 0;
- priv->tween_id = gdk_threads_add_timeout (E_MAP_TWEEN_TIMEOUT_MSECS,
- e_map_do_tween_cb,
- view);
- g_timer_start (priv->timer);
+ map->priv->timer = g_timer_new ();
+ map->priv->timer_current_ms = 0;
+ map->priv->tween_id = gdk_threads_add_timeout (
+ E_MAP_TWEEN_TIMEOUT_MSECS, e_map_do_tween_cb, map);
+ g_timer_start (map->priv->timer);
}
static void
-e_map_tween_new (EMap *view, guint msecs, double longitude_offset, double latitude_offset, double zoom_factor)
+e_map_tween_new (EMap *map, guint msecs, gdouble longitude_offset, gdouble latitude_offset, gdouble zoom_factor)
{
- EMapPrivate *priv = view->priv;
- EMapTween *tween;
+ EMapTween *tween;
- if (!priv->smooth_zoom)
- return;
+ if (!map->priv->smooth_zoom)
+ return;
- e_map_start_tweening (view);
+ e_map_start_tweening (map);
- tween = g_slice_new (EMapTween);
+ tween = g_slice_new (EMapTween);
- tween->start_time = priv->timer_current_ms;
- tween->end_time = tween->start_time + msecs;
- tween->longitude_offset = longitude_offset;
- tween->latitude_offset = latitude_offset;
- tween->zoom_factor = zoom_factor;
+ tween->start_time = map->priv->timer_current_ms;
+ tween->end_time = tween->start_time + msecs;
+ tween->longitude_offset = longitude_offset;
+ tween->latitude_offset = latitude_offset;
+ tween->zoom_factor = zoom_factor;
- priv->tweens = g_slist_prepend (priv->tweens, tween);
+ map->priv->tweens = g_slist_prepend (map->priv->tweens, tween);
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_widget_queue_draw (GTK_WIDGET (map));
}
G_DEFINE_TYPE (
@@ -240,127 +220,179 @@ G_DEFINE_TYPE (
GTK_TYPE_WIDGET)
static void
-e_map_tween_new_from (EMap *view, guint msecs, double longitude, double latitude, double zoom)
+e_map_tween_new_from (EMap *map,
+ guint msecs,
+ gdouble longitude,
+ gdouble latitude,
+ gdouble zoom)
{
- double current_longitude, current_latitude;
+ gdouble current_longitude, current_latitude;
- e_map_get_current_location (view, ¤t_longitude, ¤t_latitude);
+ e_map_get_current_location (
+ map, ¤t_longitude, ¤t_latitude);
- e_map_tween_new (view,
- msecs,
- longitude - current_longitude,
- latitude - current_latitude,
- zoom / e_map_get_magnification (view));
+ e_map_tween_new (
+ map, msecs,
+ longitude - current_longitude,
+ latitude - current_latitude,
+ zoom / e_map_get_magnification (map));
}
-/* ----------------- *
- * Widget management *
- * ----------------- */
+static gdouble
+e_map_get_tween_effect (EMap *map,
+ EMapTween *tween)
+{
+ gdouble elapsed;
+
+ elapsed = (gdouble)
+ (map->priv->timer_current_ms - tween->start_time) /
+ tween->end_time;
-/* Class initialization function for the map view */
+ return MAX (0.0, 1.0 - elapsed);
+}
static void
-e_map_class_init (EMapClass *class)
+e_map_apply_tween (EMapTween *tween,
+ gdouble effect,
+ gdouble *longitude,
+ gdouble *latitude,
+ gdouble *zoom)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
+ *zoom *= pow (tween->zoom_factor, effect);
+ *longitude += tween->longitude_offset * effect;
+ *latitude += tween->latitude_offset * effect;
+}
+
+static void
+e_map_tweens_compute_matrix (EMap *map, cairo_matrix_t *matrix)
+{
+ GSList *walk;
+ gdouble zoom, x, y, latitude, longitude, effect;
+ GtkAllocation allocation;
+
+ if (!e_map_is_tweening (map)) {
+ cairo_matrix_init_translate (
+ matrix, -map->priv->xofs, -map->priv->yofs);
+ return;
+ }
- gobject_class = (GObjectClass *) class;
- widget_class = (GtkWidgetClass *) class;
+ e_map_get_current_location (map, &longitude, &latitude);
+ zoom = 1.0;
- gobject_class->finalize = e_map_finalize;
+ for (walk = map->priv->tweens; walk; walk = walk->next) {
+ EMapTween *tween = walk->data;
- class->set_scroll_adjustments = e_map_set_scroll_adjustments;
- widget_class->set_scroll_adjustments_signal = g_signal_new ("set_scroll_adjustments",
- G_OBJECT_CLASS_TYPE (gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EMapClass, set_scroll_adjustments),
- NULL, NULL,
- e_marshal_NONE__OBJECT_OBJECT,
- G_TYPE_NONE, 2,
- GTK_TYPE_ADJUSTMENT,
- GTK_TYPE_ADJUSTMENT);
+ effect = e_map_get_tween_effect (map, tween);
+ e_map_apply_tween (tween, effect, &longitude, &latitude, &zoom);
+ }
- widget_class->realize = e_map_realize;
- widget_class->unrealize = e_map_unrealize;
- widget_class->size_request = e_map_size_request;
- widget_class->size_allocate = e_map_size_allocate;
- widget_class->button_press_event = e_map_button_press;
- widget_class->button_release_event = e_map_button_release;
- widget_class->motion_notify_event = e_map_motion;
- widget_class->expose_event = e_map_expose;
- widget_class->key_press_event = e_map_key_press;
+ gtk_widget_get_allocation (GTK_WIDGET (map), &allocation);
+ cairo_matrix_init_translate (matrix,
+ allocation.width / 2.0,
+ allocation.height / 2.0);
+
+ e_map_world_to_render_surface (map, longitude, latitude, &x, &y);
+ cairo_matrix_scale (matrix, zoom, zoom);
+ cairo_matrix_translate (matrix, -x, -y);
}
-/* Object initialization function for the map view */
+/* ----------------- *
+ * Widget management *
+ * ----------------- */
static void
-e_map_init (EMap *view)
+e_map_notify_hadjustment_cb (EMap *map)
{
- EMapPrivate *priv;
- GtkWidget *widget;
- gchar *map_file_name = g_build_filename (EVOLUTION_IMAGESDIR, "world_map-960.png", NULL);
+ GtkScrollable *scrollable;
+ GtkAdjustment *hadjustment;
- widget = GTK_WIDGET (view);
+ scrollable = GTK_SCROLLABLE (map);
+ hadjustment = gtk_scrollable_get_hadjustment (scrollable);
- priv = g_new0 (EMapPrivate, 1);
- view->priv = priv;
+ if (hadjustment != NULL)
+ g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
+ else
+ hadjustment = gtk_adjustment_new (.0, .0, .0, .0, .0, .0);
- load_map_background (view, map_file_name);
- g_free (map_file_name);
- priv->frozen = FALSE;
- priv->smooth_zoom = TRUE;
- priv->zoom_state = E_MAP_ZOOMED_OUT;
- priv->points = g_ptr_array_new ();
+ if (map->priv->hadj != NULL && map->priv->hadj != hadjustment) {
+ g_signal_handlers_disconnect_by_func (
+ map->priv->hadj, adjustment_changed_cb, map);
+ g_object_unref (map->priv->hadj);
+ }
- gtk_widget_set_can_focus (widget, TRUE);
- gtk_widget_set_has_window (widget, TRUE);
+ if (map->priv->hadj != hadjustment) {
+ map->priv->hadj = g_object_ref_sink (hadjustment);
+ g_signal_connect_swapped (
+ hadjustment, "value-changed",
+ G_CALLBACK (adjustment_changed_cb), map);
+ adjustment_changed_cb (map);
+ }
}
-/* Finalize handler for the map view */
+static void
+e_map_notify_vadjustment_cb (EMap *map)
+{
+ GtkScrollable *scrollable;
+ GtkAdjustment *vadjustment;
+
+ scrollable = GTK_SCROLLABLE (map);
+ vadjustment = gtk_scrollable_get_vadjustment (scrollable);
+
+ if (vadjustment != NULL)
+ g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
+ else
+ vadjustment = gtk_adjustment_new (.0, .0, .0, .0, .0, .0);
+
+ if (map->priv->vadj != NULL && map->priv->vadj != vadjustment) {
+ g_signal_handlers_disconnect_by_func (
+ map->priv->vadj, adjustment_changed_cb, map);
+ g_object_unref (map->priv->vadj);
+ }
+
+ if (map->priv->vadj != vadjustment) {
+ map->priv->vadj = g_object_ref_sink (vadjustment);
+ g_signal_connect_swapped (
+ vadjustment, "value-changed",
+ G_CALLBACK (adjustment_changed_cb), map);
+ adjustment_changed_cb (map);
+ }
+}
static void
e_map_finalize (GObject *object)
{
- EMap *view;
- EMapPrivate *priv;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (E_IS_MAP (object));
+ EMap *map;
- view = E_MAP (object);
- priv = view->priv;
+ map = E_MAP (object);
- while (priv->tweens)
- e_map_tween_destroy (view, priv->tweens->data);
- e_map_stop_tweening (view);
+ while (map->priv->tweens)
+ e_map_tween_destroy (map, map->priv->tweens->data);
+ e_map_stop_tweening (map);
- g_signal_handlers_disconnect_by_func (priv->hadj, adjustment_changed_cb, view);
- g_signal_handlers_disconnect_by_func (priv->vadj, adjustment_changed_cb, view);
+ g_signal_handlers_disconnect_by_func (map->priv->hadj, adjustment_changed_cb, map);
+ g_signal_handlers_disconnect_by_func (map->priv->vadj, adjustment_changed_cb, map);
- g_object_unref ((priv->hadj));
- priv->hadj = NULL;
+ g_object_unref ((map->priv->hadj));
+ map->priv->hadj = NULL;
- g_object_unref ((priv->vadj));
- priv->vadj = NULL;
+ g_object_unref ((map->priv->vadj));
+ map->priv->vadj = NULL;
- if (priv->map_pixbuf)
+ if (map->priv->map_pixbuf)
{
- g_object_unref (priv->map_pixbuf);
- priv->map_pixbuf = NULL;
+ g_object_unref (map->priv->map_pixbuf);
+ map->priv->map_pixbuf = NULL;
}
- /* gone in unrealize */
- g_assert (priv->map_render_surface == NULL);
+ /* gone in unrealize */
+ g_assert (map->priv->map_render_surface == NULL);
- g_free (priv);
- view->priv = NULL;
+ g_free (map->priv);
+ map->priv = NULL;
G_OBJECT_CLASS (e_map_parent_class)->finalize (object);
}
-/* Realize handler for the map view */
-
static void
e_map_realize (GtkWidget *widget)
{
@@ -384,12 +416,11 @@ e_map_realize (GtkWidget *widget)
attr.height = allocation.height;
attr.wclass = GDK_INPUT_OUTPUT;
attr.visual = gtk_widget_get_visual (widget);
- attr.colormap = gtk_widget_get_colormap (widget);
attr.event_mask = gtk_widget_get_events (widget) |
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK;
- attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
window = gdk_window_new (
gtk_widget_get_parent_window (widget), &attr, attr_mask);
@@ -400,56 +431,48 @@ e_map_realize (GtkWidget *widget)
style = gtk_style_attach (style, window);
gtk_widget_set_style (widget, style);
- gdk_window_set_back_pixmap (window, NULL, FALSE);
update_render_surface (E_MAP (widget), TRUE);
}
static void
e_map_unrealize (GtkWidget *widget)
{
- EMap *view = E_MAP (widget);
- EMapPrivate *priv = view->priv;
+ EMap *map = E_MAP (widget);
- cairo_surface_destroy (priv->map_render_surface);
- priv->map_render_surface = NULL;
+ cairo_surface_destroy (map->priv->map_render_surface);
+ map->priv->map_render_surface = NULL;
- if (GTK_WIDGET_CLASS (e_map_parent_class)->unrealize)
- (*GTK_WIDGET_CLASS (e_map_parent_class)->unrealize) (widget);
+ if (GTK_WIDGET_CLASS (e_map_parent_class)->unrealize)
+ (*GTK_WIDGET_CLASS (e_map_parent_class)->unrealize) (widget);
}
-/* Size_request handler for the map view */
-
static void
e_map_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
- EMap *view;
- EMapPrivate *priv;
+ EMap *map;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_MAP (widget));
g_return_if_fail (requisition != NULL);
- view = E_MAP (widget);
- priv = view->priv;
+ map = E_MAP (widget);
/* TODO: Put real sizes here. */
- requisition->width = gdk_pixbuf_get_width (priv->map_pixbuf);
- requisition->height = gdk_pixbuf_get_height (priv->map_pixbuf);
+ requisition->width = gdk_pixbuf_get_width (map->priv->map_pixbuf);
+ requisition->height = gdk_pixbuf_get_height (map->priv->map_pixbuf);
}
-/* Size_allocate handler for the map view */
-
static void
e_map_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
- EMap *view;
+ EMap *map;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_MAP (widget));
g_return_if_fail (allocation != NULL);
- view = E_MAP (widget);
+ map = E_MAP (widget);
/* Resize the window */
@@ -464,13 +487,31 @@ e_map_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
window, allocation->x, allocation->y,
allocation->width, allocation->height);
- gtk_widget_queue_draw (widget);
+ gtk_widget_queue_draw (widget);
}
- update_render_surface (view, TRUE);
+ update_render_surface (map, TRUE);
}
-/* Button press handler for the map view */
+static gboolean
+e_map_draw (GtkWidget *widget, cairo_t *cr)
+{
+ EMap *map;
+ cairo_matrix_t matrix;
+
+ if (!gtk_widget_is_drawable (widget))
+ return FALSE;
+
+ map = E_MAP (widget);
+
+ e_map_tweens_compute_matrix (map, &matrix);
+ cairo_transform (cr, &matrix);
+
+ cairo_set_source_surface (cr, map->priv->map_render_surface, 0, 0);
+ cairo_paint (cr);
+
+ return FALSE;
+}
static gint
e_map_button_press (GtkWidget *widget, GdkEventButton *event)
@@ -479,8 +520,6 @@ e_map_button_press (GtkWidget *widget, GdkEventButton *event)
return TRUE;
}
-/* Button release handler for the map view */
-
static gint
e_map_button_release (GtkWidget *widget, GdkEventButton *event)
{
@@ -490,190 +529,21 @@ e_map_button_release (GtkWidget *widget, GdkEventButton *event)
return TRUE;
}
-/* Motion handler for the map view */
-
static gint
e_map_motion (GtkWidget *widget, GdkEventMotion *event)
{
return FALSE;
-
-/*
- * if (event->is_hint)
- * gdk_window_get_pointer(widget->window, &x, &y, &mods);
- * else
- * {
- * x = event->x;
- * y = event->y;
- * }
- *
- * return TRUE;
- */
-}
-
-static double
-e_map_get_tween_effect (EMap *view, EMapTween *tween)
-{
- double elapsed;
-
- elapsed = (double) (view->priv->timer_current_ms - tween->start_time) / tween->end_time;
-
- return MAX (0.0, 1.0 - elapsed);
-}
-
-static void
-e_map_apply_tween (EMapTween *tween, double effect, double *longitude, double *latitude, double *zoom)
-{
- *zoom *= pow (tween->zoom_factor, effect);
- *longitude += tween->longitude_offset * effect;
- *latitude += tween->latitude_offset * effect;
-}
-
-static void
-e_map_tweens_compute_matrix (EMap *view, cairo_matrix_t *matrix)
-{
- EMapPrivate *priv = view->priv;
- GSList *walk;
- double zoom, x, y, latitude, longitude, effect;
- GtkAllocation allocation;
-
- if (!e_map_is_tweening (view))
- {
- cairo_matrix_init_translate (matrix, -priv->xofs, -priv->yofs);
- return;
- }
-
- e_map_get_current_location (view, &longitude, &latitude);
- zoom = 1.0;
-
- for (walk = priv->tweens; walk; walk = walk->next)
- {
- EMapTween *tween = walk->data;
-
- effect = e_map_get_tween_effect (view, tween);
- e_map_apply_tween (tween, effect, &longitude, &latitude, &zoom);
- }
-
- gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
- cairo_matrix_init_translate (matrix,
- allocation.width / 2.0,
- allocation.height / 2.0);
-
- e_map_world_to_render_surface (view,
- longitude, latitude,
- &x, &y);
- cairo_matrix_scale (matrix, zoom, zoom);
- cairo_matrix_translate (matrix, -x, -y);
}
-/* Expose handler for the map view */
-
-static gboolean
-e_map_expose (GtkWidget *widget, GdkEventExpose *event)
-{
- EMap *view;
- EMapPrivate *priv;
- cairo_t *cr;
- cairo_matrix_t matrix;
-
- if (!gtk_widget_is_drawable (widget))
- return FALSE;
-
- view = E_MAP (widget);
- priv = view->priv;
-
- cr = gdk_cairo_create (event->window);
- gdk_cairo_region (cr, event->region);
- cairo_clip (cr);
-
- e_map_tweens_compute_matrix (view, &matrix);
- cairo_transform (cr, &matrix);
-
- cairo_set_source_surface (cr,
- priv->map_render_surface,
- 0, 0);
- cairo_paint (cr);
-
- cairo_destroy (cr);
-
- return FALSE;
-}
-
-/* Set_scroll_adjustments handler for the map view */
-
-static void
-e_map_set_scroll_adjustments (GtkWidget *widget, GtkAdjustment *hadj, GtkAdjustment *vadj)
-{
- EMap *view;
- EMapPrivate *priv;
- gboolean need_adjust;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (E_IS_MAP (widget));
-
- view = E_MAP (widget);
- priv = view->priv;
-
- if (hadj) g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
- else hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
-
- if (vadj) g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
- else vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
-
- if (priv->hadj && priv->hadj != hadj)
- {
- g_signal_handlers_disconnect_by_func (priv->hadj,
- adjustment_changed_cb,
- view);
- g_object_unref (priv->hadj);
- }
-
- if (priv->vadj && priv->vadj != vadj)
- {
- g_signal_handlers_disconnect_by_func (priv->vadj,
- adjustment_changed_cb,
- view);
- g_object_unref (priv->vadj);
- }
-
- need_adjust = FALSE;
-
- if (priv->hadj != hadj)
- {
- priv->hadj = hadj;
- g_object_ref_sink (priv->hadj);
-
- g_signal_connect (priv->hadj, "value_changed",
- G_CALLBACK (adjustment_changed_cb), view);
-
- need_adjust = TRUE;
- }
-
- if (priv->vadj != vadj)
- {
- priv->vadj = vadj;
- g_object_ref_sink (priv->vadj);
-
- g_signal_connect (priv->vadj, "value_changed",
- G_CALLBACK (adjustment_changed_cb), view);
-
- need_adjust = TRUE;
- }
-
- if (need_adjust) adjustment_changed_cb (NULL, view);
-}
-
-/* Key press handler for the map view */
-
static gint
-e_map_key_press (GtkWidget *widget, GdkEventKey *event)
+e_map_key_press (GtkWidget *widget,
+ GdkEventKey *event)
{
- EMap *view;
- EMapPrivate *priv;
+ EMap *map;
gboolean do_scroll;
gint xofs, yofs;
- view = E_MAP (widget);
- priv = view->priv;
+ map = E_MAP (widget);
switch (event->keyval)
{
@@ -705,29 +575,78 @@ e_map_key_press (GtkWidget *widget, GdkEventKey *event)
return FALSE;
}
- if (do_scroll)
- {
+ if (do_scroll) {
gint page_size;
gint upper;
gint x, y;
- page_size = gtk_adjustment_get_page_size (priv->hadj);
- upper = gtk_adjustment_get_upper (priv->hadj);
- x = CLAMP (priv->xofs + xofs, 0, upper - page_size);
+ page_size = gtk_adjustment_get_page_size (map->priv->hadj);
+ upper = gtk_adjustment_get_upper (map->priv->hadj);
+ x = CLAMP (map->priv->xofs + xofs, 0, upper - page_size);
- page_size = gtk_adjustment_get_page_size (priv->vadj);
- upper = gtk_adjustment_get_upper (priv->vadj);
- y = CLAMP (priv->yofs + yofs, 0, upper - page_size);
+ page_size = gtk_adjustment_get_page_size (map->priv->vadj);
+ upper = gtk_adjustment_get_upper (map->priv->vadj);
+ y = CLAMP (map->priv->yofs + yofs, 0, upper - page_size);
- scroll_to (view, x, y);
+ scroll_to (map, x, y);
- gtk_adjustment_set_value (priv->hadj, x);
- gtk_adjustment_set_value (priv->vadj, y);
+ gtk_adjustment_set_value (map->priv->hadj, x);
+ gtk_adjustment_set_value (map->priv->vadj, y);
}
return TRUE;
}
+static void
+e_map_class_init (EMapClass *class)
+{
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->finalize = e_map_finalize;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->realize = e_map_realize;
+ widget_class->unrealize = e_map_unrealize;
+ widget_class->size_request = e_map_size_request;
+ widget_class->size_allocate = e_map_size_allocate;
+ widget_class->draw = e_map_draw;
+ widget_class->button_press_event = e_map_button_press;
+ widget_class->button_release_event = e_map_button_release;
+ widget_class->motion_notify_event = e_map_motion;
+ widget_class->key_press_event = e_map_key_press;
+}
+
+static void
+e_map_init (EMap *map)
+{
+ GtkWidget *widget;
+ gchar *map_file_name = g_build_filename (EVOLUTION_IMAGESDIR, "world_map-960.png", NULL);
+
+ widget = GTK_WIDGET (map);
+
+ map->priv = g_new0 (EMapPrivate, 1);
+
+ load_map_background (map, map_file_name);
+ g_free (map_file_name);
+ map->priv->frozen = FALSE;
+ map->priv->smooth_zoom = TRUE;
+ map->priv->zoom_state = E_MAP_ZOOMED_OUT;
+ map->priv->points = g_ptr_array_new ();
+
+ gtk_widget_set_can_focus (widget, TRUE);
+ gtk_widget_set_has_window (widget, TRUE);
+
+ g_signal_connect (
+ map, "notify::hadjustment",
+ G_CALLBACK (e_map_notify_hadjustment_cb), NULL);
+
+ g_signal_connect (
+ map, "notify::vadjustment",
+ G_CALLBACK (e_map_notify_vadjustment_cb), NULL);
+}
+
/* ---------------- *
* Widget interface *
* ---------------- */
@@ -766,20 +685,18 @@ e_map_new (void)
void
e_map_window_to_world (EMap *map, gdouble win_x, gdouble win_y, gdouble *world_longitude, gdouble *world_latitude)
{
- EMapPrivate *priv;
gint width, height;
g_return_if_fail (map);
- priv = map->priv;
g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (map)));
width = E_MAP_GET_WIDTH (map);
height = E_MAP_GET_HEIGHT (map);
- *world_longitude = (win_x + priv->xofs - (gdouble) width / 2.0) /
+ *world_longitude = (win_x + map->priv->xofs - (gdouble) width / 2.0) /
((gdouble) width / 2.0) * 180.0;
- *world_latitude = ((gdouble) height / 2.0 - win_y - priv->yofs) /
+ *world_latitude = ((gdouble) height / 2.0 - win_y - map->priv->yofs) /
((gdouble) height / 2.0) * 90.0;
}
@@ -798,18 +715,14 @@ e_map_world_to_render_surface (EMap *map, gdouble world_longitude, gdouble world
void
e_map_world_to_window (EMap *map, gdouble world_longitude, gdouble world_latitude, gdouble *win_x, gdouble *win_y)
{
- EMapPrivate *priv;
-
g_return_if_fail (E_IS_MAP (map));
g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (map)));
g_return_if_fail (world_longitude >= -180.0 && world_longitude <= 180.0);
g_return_if_fail (world_latitude >= -90.0 && world_latitude <= 90.0);
- priv = map->priv;
-
- e_map_world_to_render_surface (map, world_longitude, world_latitude, win_x, win_y);
- *win_x -= priv->xofs;
- *win_y -= priv->yofs;
+ e_map_world_to_render_surface (map, world_longitude, world_latitude, win_x, win_y);
+ *win_x -= map->priv->xofs;
+ *win_y -= map->priv->yofs;
#ifdef DEBUG
printf ("Map size: (%d, %d)\nCoords: (%.1f, %.1f) -> (%.1f, %.1f)\n---\n", width, height, world_longitude, world_latitude, *win_x, *win_y);
@@ -821,61 +734,54 @@ e_map_world_to_window (EMap *map, gdouble world_longitude, gdouble world_latitud
gdouble
e_map_get_magnification (EMap *map)
{
- EMapPrivate *priv;
-
- priv = map->priv;
- if (priv->zoom_state == E_MAP_ZOOMED_IN) return 2.0;
+ if (map->priv->zoom_state == E_MAP_ZOOMED_IN) return 2.0;
else return 1.0;
}
static void
-e_map_set_zoom (EMap *view, EMapZoomState zoom)
+e_map_set_zoom (EMap *map, EMapZoomState zoom)
{
- EMapPrivate *priv = view->priv;
-
- if (priv->zoom_state == zoom)
- return;
+ if (map->priv->zoom_state == zoom)
+ return;
- priv->zoom_state = zoom;
- update_render_surface (view, TRUE);
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ map->priv->zoom_state = zoom;
+ update_render_surface (map, TRUE);
+ gtk_widget_queue_draw (GTK_WIDGET (map));
}
void
e_map_zoom_to_location (EMap *map, gdouble longitude, gdouble latitude)
{
- EMapPrivate *priv;
- double prevlong, prevlat;
- double prevzoom;
+ gdouble prevlong, prevlat;
+ gdouble prevzoom;
g_return_if_fail (map);
g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (map)));
- priv = map->priv;
- e_map_get_current_location (map, &prevlong, &prevlat);
- prevzoom = e_map_get_magnification (map);
+ e_map_get_current_location (map, &prevlong, &prevlat);
+ prevzoom = e_map_get_magnification (map);
- e_map_set_zoom (map, E_MAP_ZOOMED_IN);
- center_at (map, longitude, latitude);
+ e_map_set_zoom (map, E_MAP_ZOOMED_IN);
+ center_at (map, longitude, latitude);
- e_map_tween_new_from (map, E_MAP_TWEEN_DURATION_MSECS, prevlong, prevlat, prevzoom);
+ e_map_tween_new_from (map, E_MAP_TWEEN_DURATION_MSECS, prevlong, prevlat, prevzoom);
}
void
e_map_zoom_out (EMap *map)
{
- double longitude, latitude;
- double prevzoom;
+ gdouble longitude, latitude;
+ gdouble prevzoom;
g_return_if_fail (map);
g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (map)));
- e_map_get_current_location (map, &longitude, &latitude);
- prevzoom = e_map_get_magnification (map);
- e_map_set_zoom (map, E_MAP_ZOOMED_OUT);
- center_at (map, longitude, latitude);
+ e_map_get_current_location (map, &longitude, &latitude);
+ prevzoom = e_map_get_magnification (map);
+ e_map_set_zoom (map, E_MAP_ZOOMED_OUT);
+ center_at (map, longitude, latitude);
- e_map_tween_new_from (map, E_MAP_TWEEN_DURATION_MSECS, longitude, latitude, prevzoom);
+ e_map_tween_new_from (map, E_MAP_TWEEN_DURATION_MSECS, longitude, latitude, prevzoom);
}
void
@@ -908,10 +814,8 @@ e_map_thaw (EMap *map)
EMapPoint *
e_map_add_point (EMap *map, gchar *name, gdouble longitude, gdouble latitude, guint32 color_rgba)
{
- EMapPrivate *priv;
EMapPoint *point;
- priv = map->priv;
point = g_new0 (EMapPoint, 1);
point->name = name; /* Can be NULL */
@@ -919,9 +823,9 @@ e_map_add_point (EMap *map, gchar *name, gdouble longitude, gdouble latitude, gu
point->latitude = latitude;
point->rgba = color_rgba;
- g_ptr_array_add (priv->points, (gpointer) point);
+ g_ptr_array_add (map->priv->points, (gpointer) point);
- if (!priv->frozen)
+ if (!map->priv->frozen)
{
update_render_point (map, point);
repaint_point (map, point);
@@ -933,10 +837,7 @@ e_map_add_point (EMap *map, gchar *name, gdouble longitude, gdouble latitude, gu
void
e_map_remove_point (EMap *map, EMapPoint *point)
{
- EMapPrivate *priv;
-
- priv = map->priv;
- g_ptr_array_remove (priv->points, point);
+ g_ptr_array_remove (map->priv->points, point);
if (!((EMapPrivate *) map->priv)->frozen)
{
@@ -998,12 +899,10 @@ e_map_point_get_data (EMapPoint *point)
gboolean
e_map_point_is_in_view (EMap *map, EMapPoint *point)
{
- EMapPrivate *priv;
GtkAllocation allocation;
gdouble x, y;
- priv = map->priv;
- if (!priv->map_render_surface) return FALSE;
+ if (!map->priv->map_render_surface) return FALSE;
e_map_world_to_window (map, point->longitude, point->latitude, &x, &y);
gtk_widget_get_allocation (GTK_WIDGET (map), &allocation);
@@ -1018,17 +917,14 @@ e_map_point_is_in_view (EMap *map, EMapPoint *point)
EMapPoint *
e_map_get_closest_point (EMap *map, gdouble longitude, gdouble latitude, gboolean in_view)
{
- EMapPrivate *priv;
EMapPoint *point_chosen = NULL, *point;
gdouble min_dist = 0.0, dist;
gdouble dx, dy;
gint i;
- priv = map->priv;
-
- for (i = 0; i < priv->points->len; i++)
+ for (i = 0; i < map->priv->points->len; i++)
{
- point = g_ptr_array_index (priv->points, i);
+ point = g_ptr_array_index (map->priv->points, i);
if (in_view && !e_map_point_is_in_view (map, point)) continue;
dx = point->longitude - longitude;
@@ -1057,20 +953,17 @@ update_and_paint (EMap *map)
}
static gint
-load_map_background (EMap *view, gchar *name)
+load_map_background (EMap *map, gchar *name)
{
- EMapPrivate *priv;
GdkPixbuf *pb0;
- priv = view->priv;
-
pb0 = gdk_pixbuf_new_from_file (name, NULL);
if (!pb0)
return FALSE;
- if (priv->map_pixbuf) g_object_unref (priv->map_pixbuf);
- priv->map_pixbuf = pb0;
- update_render_surface (view, TRUE);
+ if (map->priv->map_pixbuf) g_object_unref (map->priv->map_pixbuf);
+ map->priv->map_pixbuf = pb0;
+ update_render_surface (map, TRUE);
return TRUE;
}
@@ -1079,7 +972,6 @@ static void
update_render_surface (EMap *map,
gboolean render_overlays)
{
- EMapPrivate *priv;
EMapPoint *point;
GtkAllocation allocation;
gint width, height, orig_width, orig_height;
@@ -1093,11 +985,10 @@ update_render_surface (EMap *map,
/* Set up value shortcuts */
- priv = map->priv;
width = allocation.width;
height = allocation.height;
- orig_width = gdk_pixbuf_get_width (priv->map_pixbuf);
- orig_height = gdk_pixbuf_get_height (priv->map_pixbuf);
+ orig_width = gdk_pixbuf_get_width (map->priv->map_pixbuf);
+ orig_height = gdk_pixbuf_get_height (map->priv->map_pixbuf);
/* Compute scaled width and height based on the extreme dimension */
@@ -1106,40 +997,40 @@ update_render_surface (EMap *map,
else
zoom = (gdouble) height / (gdouble) orig_height;
- if (priv->zoom_state == E_MAP_ZOOMED_IN)
+ if (map->priv->zoom_state == E_MAP_ZOOMED_IN)
zoom *= 2.0;
height = (orig_height * zoom) + 0.5;
width = (orig_width * zoom) + 0.5;
/* Reallocate the pixbuf */
- if (priv->map_render_surface) cairo_surface_destroy (priv->map_render_surface);
- priv->map_render_surface = gdk_window_create_similar_surface (gtk_widget_get_window (GTK_WIDGET (map)),
- CAIRO_CONTENT_COLOR,
- width, height);
+ if (map->priv->map_render_surface)
+ cairo_surface_destroy (map->priv->map_render_surface);
+ map->priv->map_render_surface = gdk_window_create_similar_surface (
+ gtk_widget_get_window (GTK_WIDGET (map)),
+ CAIRO_CONTENT_COLOR, width, height);
/* Scale the original map into the rendering pixbuf */
if (width > 1 && height > 1)
{
- cairo_t *cr = cairo_create (priv->map_render_surface);
- cairo_scale (cr, (double) width / orig_width, (double) height / orig_height);
- gdk_cairo_set_source_pixbuf (cr, priv->map_pixbuf, 0, 0);
- cairo_paint (cr);
- cairo_destroy (cr);
+ cairo_t *cr = cairo_create (map->priv->map_render_surface);
+ cairo_scale (cr, (gdouble) width / orig_width, (gdouble) height / orig_height);
+ gdk_cairo_set_source_pixbuf (cr, map->priv->map_pixbuf, 0, 0);
+ cairo_paint (cr);
+ cairo_destroy (cr);
}
- /* Compute image offsets with respect to window */
+ /* Compute image offsets with respect to window */
- set_scroll_area (map, width, height);
+ set_scroll_area (map, width, height);
- if (render_overlays)
- {
+ if (render_overlays) {
/* Add points */
- for (i = 0; i < priv->points->len; i++)
+ for (i = 0; i < map->priv->points->len; i++)
{
- point = g_ptr_array_index (priv->points, i);
+ point = g_ptr_array_index (map->priv->points, i);
update_render_point (map, point);
}
}
@@ -1150,46 +1041,43 @@ update_render_surface (EMap *map,
static void
update_render_point (EMap *map, EMapPoint *point)
{
- EMapPrivate *priv;
- cairo_t *cr;
+ cairo_t *cr;
gdouble px, py;
- static guchar mask1[] = { 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static guchar mask2[] = { 0x00, 0xff, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00 };
- cairo_surface_t *mask;
-
- priv = map->priv;
-
- if (priv->map_render_surface == NULL)
- return;
+ static guchar mask1[] = { 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
+ 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static guchar mask2[] = { 0x00, 0xff, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00 };
+ cairo_surface_t *mask;
+
+ if (map->priv->map_render_surface == NULL)
+ return;
- cr = cairo_create (priv->map_render_surface);
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cr = cairo_create (map->priv->map_render_surface);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
e_map_world_to_window (map, point->longitude, point->latitude, &px, &py);
- px = floor (px + priv->xofs);
- py = floor (py + priv->yofs);
-
- cairo_set_source_rgb (cr, 0, 0, 0);
- mask = cairo_image_surface_create_for_data (mask1, CAIRO_FORMAT_A8, 5, 5, 8);
- cairo_mask_surface (cr, mask, px - 2, py - 2);
- cairo_surface_destroy (mask);
-
- cairo_set_source_rgba (cr,
- ((point->rgba >> 24) & 0xff) / 255.0,
- ((point->rgba >> 16) & 0xff) / 255.0,
- ((point->rgba >> 8) & 0xff) / 255.0,
- ( point->rgba & 0xff) / 255.0);
- mask = cairo_image_surface_create_for_data (mask2, CAIRO_FORMAT_A8, 3, 3, 4);
- cairo_mask_surface (cr, mask, px - 1, py - 1);
- cairo_surface_destroy (mask);
-
- cairo_destroy (cr);
+ px = floor (px + map->priv->xofs);
+ py = floor (py + map->priv->yofs);
+
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ mask = cairo_image_surface_create_for_data (mask1, CAIRO_FORMAT_A8, 5, 5, 8);
+ cairo_mask_surface (cr, mask, px - 2, py - 2);
+ cairo_surface_destroy (mask);
+
+ cairo_set_source_rgba (cr,
+ ((point->rgba >> 24) & 0xff) / 255.0,
+ ((point->rgba >> 16) & 0xff) / 255.0,
+ ((point->rgba >> 8) & 0xff) / 255.0,
+ ( point->rgba & 0xff) / 255.0);
+ mask = cairo_image_surface_create_for_data (mask2, CAIRO_FORMAT_A8, 3, 3, 4);
+ cairo_mask_surface (cr, mask, px - 1, py - 1);
+ cairo_surface_destroy (mask);
+
+ cairo_destroy (cr);
}
/* Repaint point on X server */
@@ -1199,27 +1087,24 @@ repaint_point (EMap *map, EMapPoint *point)
{
gdouble px, py;
- if (!gtk_widget_is_drawable (GTK_WIDGET (map)))
- return;
+ if (!gtk_widget_is_drawable (GTK_WIDGET (map)))
+ return;
e_map_world_to_window (map, point->longitude, point->latitude, &px, &py);
gtk_widget_queue_draw_area (GTK_WIDGET (map),
- (gint) px - 2, (gint) py - 2,
- 5, 5);
+ (gint) px - 2, (gint) py - 2,
+ 5, 5);
}
static void
-center_at (EMap *map, double longitude, double latitude)
+center_at (EMap *map, gdouble longitude, gdouble latitude)
{
- EMapPrivate *priv;
GtkAllocation allocation;
gint pb_width, pb_height;
- double x, y;
-
- e_map_world_to_render_surface (map, longitude, latitude, &x, &y);
+ gdouble x, y;
- priv = map->priv;
+ e_map_world_to_render_surface (map, longitude, latitude, &x, &y);
pb_width = E_MAP_GET_WIDTH (map);
pb_height = E_MAP_GET_HEIGHT (map);
@@ -1229,97 +1114,88 @@ center_at (EMap *map, double longitude, double latitude)
x = CLAMP (x - (allocation.width / 2), 0, pb_width - allocation.width);
y = CLAMP (y - (allocation.height / 2), 0, pb_height - allocation.height);
- gtk_adjustment_set_value (priv->hadj, x);
- gtk_adjustment_set_value (priv->vadj, y);
+ gtk_adjustment_set_value (map->priv->hadj, x);
+ gtk_adjustment_set_value (map->priv->vadj, y);
- gtk_widget_queue_draw (GTK_WIDGET (map));
+ gtk_widget_queue_draw (GTK_WIDGET (map));
}
/* Scrolls the view to the specified offsets. Does not perform range checking! */
static void
-scroll_to (EMap *view, gint x, gint y)
+scroll_to (EMap *map, gint x, gint y)
{
- EMapPrivate *priv;
gint xofs, yofs;
- priv = view->priv;
-
/* Compute offsets and check bounds */
- xofs = x - priv->xofs;
- yofs = y - priv->yofs;
+ xofs = x - map->priv->xofs;
+ yofs = y - map->priv->yofs;
if (xofs == 0 && yofs == 0)
return;
- priv->xofs = x;
- priv->yofs = y;
+ map->priv->xofs = x;
+ map->priv->yofs = y;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_widget_queue_draw (GTK_WIDGET (map));
}
static void
-e_map_get_current_location (EMap *map, double *longitude, double *latitude)
+e_map_get_current_location (EMap *map, gdouble *longitude, gdouble *latitude)
{
GtkAllocation allocation;
gtk_widget_get_allocation (GTK_WIDGET (map), &allocation);
e_map_window_to_world (map,
- allocation.width / 2.0, allocation.height / 2.0,
+ allocation.width / 2.0, allocation.height / 2.0,
longitude, latitude);
}
/* Callback used when an adjustment is changed */
static void
-adjustment_changed_cb (GtkAdjustment *adj, gpointer data)
+adjustment_changed_cb (EMap *map)
{
- EMap *view;
gint hadj_value;
gint vadj_value;
- view = E_MAP (data);
-
- hadj_value = gtk_adjustment_get_value (view->priv->hadj);
- vadj_value = gtk_adjustment_get_value (view->priv->vadj);
+ hadj_value = gtk_adjustment_get_value (map->priv->hadj);
+ vadj_value = gtk_adjustment_get_value (map->priv->vadj);
- scroll_to (view, hadj_value, vadj_value);
+ scroll_to (map, hadj_value, vadj_value);
}
static void
-set_scroll_area (EMap *view, gint width, gint height)
+set_scroll_area (EMap *map, gint width, gint height)
{
- EMapPrivate *priv;
GtkAllocation allocation;
- priv = view->priv;
-
- if (!gtk_widget_get_realized (GTK_WIDGET (view))) return;
- if (!priv->hadj || !priv->vadj) return;
+ if (!gtk_widget_get_realized (GTK_WIDGET (map))) return;
+ if (!map->priv->hadj || !map->priv->vadj) return;
- g_object_freeze_notify (G_OBJECT (priv->hadj));
- g_object_freeze_notify (G_OBJECT (priv->vadj));
+ g_object_freeze_notify (G_OBJECT (map->priv->hadj));
+ g_object_freeze_notify (G_OBJECT (map->priv->vadj));
- gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
-
- priv->xofs = CLAMP (priv->xofs, 0, width - allocation.width);
- priv->yofs = CLAMP (priv->yofs, 0, height - allocation.height);
-
- gtk_adjustment_configure (priv->hadj,
- priv->xofs,
- 0, width,
- SCROLL_STEP_SIZE,
- allocation.width / 2,
- allocation.width);
- gtk_adjustment_configure (priv->vadj,
- priv->yofs,
- 0, height,
- SCROLL_STEP_SIZE,
- allocation.height / 2,
- allocation.height);
+ gtk_widget_get_allocation (GTK_WIDGET (map), &allocation);
- g_object_thaw_notify (G_OBJECT (priv->hadj));
- g_object_thaw_notify (G_OBJECT (priv->vadj));
+ map->priv->xofs = CLAMP (map->priv->xofs, 0, width - allocation.width);
+ map->priv->yofs = CLAMP (map->priv->yofs, 0, height - allocation.height);
+
+ gtk_adjustment_configure (map->priv->hadj,
+ map->priv->xofs,
+ 0, width,
+ SCROLL_STEP_SIZE,
+ allocation.width / 2,
+ allocation.width);
+ gtk_adjustment_configure (map->priv->vadj,
+ map->priv->yofs,
+ 0, height,
+ SCROLL_STEP_SIZE,
+ allocation.height / 2,
+ allocation.height);
+
+ g_object_thaw_notify (G_OBJECT (map->priv->hadj));
+ g_object_thaw_notify (G_OBJECT (map->priv->vadj));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]