[dia] Implement diagram_data_clone_selected()
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Implement diagram_data_clone_selected()
- Date: Sun, 17 Apr 2011 12:06:10 +0000 (UTC)
commit fa64bb4ba1c2081f723e9ea99334659646f6ddad
Author: Hans Breuer <hans breuer org>
Date: Sun Apr 17 13:11:50 2011 +0200
Implement diagram_data_clone_selected()
This is going to be used for global clipboard interaction.
It could someday also be used to export selected. OTOH that
might be cleaner by extending some interfaces.
lib/diagramdata.c | 43 +++++++++++++++++++++++++++++++++++++++++++
lib/diagramdata.h | 1 +
lib/libdia.def | 1 +
3 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/lib/diagramdata.c b/lib/diagramdata.c
index d2b8d5b..0e05c6d 100644
--- a/lib/diagramdata.c
+++ b/lib/diagramdata.c
@@ -156,6 +156,14 @@ diagram_data_finalize(GObject *object)
}
+/**
+ * Create a copy of the whole diagram data
+ *
+ * This is kind of a deep copy, everything not immutable gets duplicated.
+ * Still this is supposed to be relatively fast, because the most expensive
+ * objects have immutuable properties, namely the pixbufs in DiaImage are
+ * only referenced.
+ */
DiagramData *
diagram_data_clone (DiagramData *data)
{
@@ -192,6 +200,41 @@ diagram_data_clone (DiagramData *data)
return clone;
}
+/**
+ * Create a new diagram data object only containing the selected objects
+ */
+DiagramData *
+diagram_data_clone_selected (DiagramData *data)
+{
+ DiagramData *clone;
+ guint i;
+ Layer *dest_layer;
+ GList *sorted;
+
+ clone = g_object_new (DIA_TYPE_DIAGRAM_DATA, NULL);
+
+ clone->extents = data->extents;
+ clone->bg_color = data->bg_color;
+ clone->paper = data->paper; /* so ugly */
+ clone->paper.name = g_strdup (data->paper.name);
+ clone->is_compressed = data->is_compressed;
+
+ /* the selection - if any - can only be on the active layer */
+ dest_layer = g_ptr_array_index(clone->layers, 0);
+ g_free (dest_layer->name);
+ dest_layer->name = layer_get_name (data->active_layer);
+
+ sorted = data_get_sorted_selected (data);
+ dest_layer->objects = object_copy_list (sorted);
+ g_list_free (sorted);
+ dest_layer->visible = data->active_layer->visible;
+ dest_layer->connectable = data->active_layer->connectable;
+
+ data_update_extents (clone);
+
+ return clone;
+}
+
/** Initialize the DiagramData class data.
* @param klass The class object to initialize functions for.
*/
diff --git a/lib/diagramdata.h b/lib/diagramdata.h
index 96fe764..41de1dc 100644
--- a/lib/diagramdata.h
+++ b/lib/diagramdata.h
@@ -177,6 +177,7 @@ void layer_render(Layer *layer, DiaRenderer *renderer, Rectangle *update,
int active_layer);
DiagramData *diagram_data_clone (DiagramData *data);
+DiagramData *diagram_data_clone_selected (DiagramData *data);
int layer_object_get_index(Layer *layer, DiaObject *obj);
DiaObject *layer_object_get_nth(Layer *layer, guint index);
diff --git a/lib/libdia.def b/lib/libdia.def
index 62b7c58..74894f4 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -153,6 +153,7 @@ EXPORTS
data_font
diagram_data_clone
+ diagram_data_clone_selected
data_foreach_object
data_get_sorted_selected
data_get_sorted_selected_remove
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]