aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--liblogdiag/ld-canvas.c61
-rw-r--r--liblogdiag/ld-canvas.h4
-rw-r--r--liblogdiag/ld-marshal.list1
3 files changed, 65 insertions, 1 deletions
diff --git a/liblogdiag/ld-canvas.c b/liblogdiag/ld-canvas.c
index 779d92b..1d05b4b 100644
--- a/liblogdiag/ld-canvas.c
+++ b/liblogdiag/ld-canvas.c
@@ -172,6 +172,7 @@ static void on_adjustment_value_changed
static void on_size_allocate (GtkWidget *widget, GtkAllocation *allocation,
gpointer user_data);
static void update_adjustments (LdCanvas *self);
+static void ld_canvas_real_move (LdCanvas *self, gdouble dx, gdouble dy);
static void diagram_connect_signals (LdCanvas *self);
static void diagram_disconnect_signals (LdCanvas *self);
@@ -247,10 +248,19 @@ ld_canvas_class_init (LdCanvasClass *klass)
klass->set_scroll_adjustments = ld_canvas_real_set_scroll_adjustments;
klass->cancel_operation = ld_canvas_real_cancel_operation;
+ klass->move = ld_canvas_real_move;
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
"cancel-operation", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
+ "move", 2, G_TYPE_DOUBLE, (gdouble) -1, G_TYPE_DOUBLE, (gdouble) 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
+ "move", 2, G_TYPE_DOUBLE, (gdouble) 1, G_TYPE_DOUBLE, (gdouble) 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
+ "move", 2, G_TYPE_DOUBLE, (gdouble) 0, G_TYPE_DOUBLE, (gdouble) -1);
+ gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
+ "move", 2, G_TYPE_DOUBLE, (gdouble) 0, G_TYPE_DOUBLE, (gdouble) 1);
/**
* LdCanvas:diagram:
@@ -311,6 +321,21 @@ ld_canvas_class_init (LdCanvasClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+/**
+ * LdCanvas::move:
+ * @self: an #LdCanvas object.
+ * @dx: The difference by which to move on the horizontal axis.
+ * @dy: The difference by which to move on the vertical axis.
+ *
+ * Move the selection, if any, or the document.
+ */
+ klass->move_signal = g_signal_new
+ ("move", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (LdCanvasClass, move), NULL, NULL,
+ ld_marshal_VOID__DOUBLE_DOUBLE,
+ G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+
g_type_class_add_private (klass, sizeof (LdCanvasPrivate));
}
@@ -552,6 +577,42 @@ update_adjustments (LdCanvas *self)
}
}
+static void
+ld_canvas_real_move (LdCanvas *self, gdouble dx, gdouble dy)
+{
+ LdDiagram *diagram;
+ GList *selection, *iter;
+
+ /* TODO: Check/move boundaries, also implement normal
+ * getters and setters for priv->x and priv->y.
+ */
+ diagram = self->priv->diagram;
+ selection = ld_diagram_get_selection (diagram);
+ if (selection)
+ {
+ ld_diagram_begin_user_action (diagram);
+ for (iter = selection; iter; iter = g_list_next (iter))
+ {
+ gdouble x, y;
+
+ g_object_get (iter->data, "x", &x, "y", &y, NULL);
+ x += dx;
+ y += dy;
+ g_object_set (iter->data, "x", x, "y", y, NULL);
+ }
+ ld_diagram_end_user_action (diagram);
+ }
+ else
+ {
+ self->priv->x += dx;
+ self->priv->y += dy;
+
+ simulate_motion (self);
+ update_adjustments (self);
+ }
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
/* ===== Generic interface etc. ============================================ */
diff --git a/liblogdiag/ld-canvas.h b/liblogdiag/ld-canvas.h
index b7e66d8..ae42f26 100644
--- a/liblogdiag/ld-canvas.h
+++ b/liblogdiag/ld-canvas.h
@@ -2,7 +2,7 @@
* ld-canvas.h
*
* This file is a part of logdiag.
- * Copyright Přemysl Janouch 2010. All rights reserved.
+ * Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
*
* See the file LICENSE for licensing information.
*
@@ -47,10 +47,12 @@ struct _LdCanvasClass
GtkDrawingAreaClass parent_class;
guint cancel_operation_signal;
+ guint move_signal;
void (*set_scroll_adjustments) (LdCanvas *self,
GtkAdjustment *horizontal, GtkAdjustment *vertical);
void (*cancel_operation) (LdCanvas *self);
+ void (*move) (LdCanvas *self, gdouble dx, gdouble dy);
};
diff --git a/liblogdiag/ld-marshal.list b/liblogdiag/ld-marshal.list
index 20c67c0..b44af85 100644
--- a/liblogdiag/ld-marshal.list
+++ b/liblogdiag/ld-marshal.list
@@ -1,2 +1,3 @@
VOID:OBJECT,OBJECT
VOID:OBJECT,STRING
+VOID:DOUBLE,DOUBLE