Commit 4f5181ca authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

preparatory redistribution of code for #623559

2010-07-04  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* src/commands.c (cmd_objects_move): move most code into
	  sheet_object_move_undo and sheet_object_move_do
	* src/sheet-object.h (sheet_object_move_undo): new
	(sheet_object_move_do): new
	* src/sheet-object.c (sheet_object_move_undo): new
	(sheet_object_move_do): new
parent 50346573
2010-07-04 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/commands.c (cmd_objects_move): move most code into
sheet_object_move_undo and sheet_object_move_do
* src/sheet-object.h (sheet_object_move_undo): new
(sheet_object_move_do): new
* src/sheet-object.c (sheet_object_move_undo): new
(sheet_object_move_do): new
2010-07-04 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/sheet-control-gui.c (scg_objects_drag_commit): simplify slightly
......
......@@ -4448,56 +4448,28 @@ cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
{
GOUndo *undo = NULL;
GOUndo *redo = NULL;
GSList *objs = objects, *anchs = anchors;
gboolean result;
g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), TRUE);
g_return_val_if_fail (NULL != objects, TRUE);
g_return_val_if_fail (NULL != anchors, TRUE);
g_return_val_if_fail (g_slist_length (objects) == g_slist_length (anchors), TRUE);
/*
* There is no need to move the object around, because this has
* already happened.
*/
for (; objs && anchs; objs = objs->next, anchs = anchs->next) {
SheetObject *obj = objs->data;
SheetObjectAnchor *anch = anchs->data;
SheetObjectAnchor *tmp;
undo = sheet_object_move_undo (objects, objects_created);
redo = sheet_object_move_do (objects, anchors, objects_created);
if (objects_created) {
undo = go_undo_combine
(undo,
go_undo_unary_new
(g_object_ref (obj),
(GOUndoUnaryFunc) sheet_object_clear_sheet,
(GFreeFunc) g_object_unref));
redo = go_undo_combine
(redo,
go_undo_binary_new (g_object_ref (obj),
sheet_object_get_sheet (obj),
(GOUndoBinaryFunc) sheet_object_set_sheet,
(GFreeFunc) g_object_unref,
NULL));
}
tmp = g_new (SheetObjectAnchor, 1);
*tmp = *sheet_object_get_anchor (obj);
undo = go_undo_combine
(undo, go_undo_binary_new (g_object_ref (obj), tmp,
(GOUndoBinaryFunc) sheet_object_set_anchor,
(GFreeFunc) g_object_unref,
(GFreeFunc) g_free));
redo = go_undo_combine
(go_undo_binary_new (g_object_ref (obj), anch,
(GOUndoBinaryFunc) sheet_object_set_anchor,
(GFreeFunc) g_object_unref,
(GFreeFunc) g_free), redo);
if (undo == NULL || redo == NULL) {
if (undo) g_object_unref (undo);
if (redo) g_object_unref (redo);
return TRUE;
}
result = cmd_generic (wbc, name, undo, redo);
if (result)
return TRUE;
g_slist_free (objects);
g_slist_free (anchors);
go_slist_free_custom (anchors, g_free);
return cmd_generic (wbc, name, undo, redo);
return FALSE;
}
/******************************************************************/
......
......@@ -1463,6 +1463,79 @@ sheet_object_write_object (SheetObject const *so, char const *format,
gnm_pop_C_locale (locale);
}
GOUndo *
sheet_object_move_undo (GSList *objects, gboolean objects_created)
{
GOUndo *undo = NULL;
GSList *objs = objects;
g_return_val_if_fail (NULL != objects, NULL);
for (; objs; objs = objs->next) {
SheetObject *obj = objs->data;
SheetObjectAnchor *tmp;
if (objects_created) {
undo = go_undo_combine
(undo,
go_undo_unary_new
(g_object_ref (obj),
(GOUndoUnaryFunc) sheet_object_clear_sheet,
(GFreeFunc) g_object_unref));
}
tmp = g_new (SheetObjectAnchor, 1);
*tmp = *sheet_object_get_anchor (obj);
undo = go_undo_combine
(undo, go_undo_binary_new
(g_object_ref (obj), tmp,
(GOUndoBinaryFunc) sheet_object_set_anchor,
(GFreeFunc) g_object_unref,
(GFreeFunc) g_free));
}
return undo;
}
GOUndo *
sheet_object_move_do (GSList *objects, GSList *anchors,
gboolean objects_created)
{
GOUndo *undo = NULL;
GSList *objs = objects, *anchs = anchors;
g_return_val_if_fail (NULL != objects, NULL);
g_return_val_if_fail (NULL != anchors, NULL);
g_return_val_if_fail (g_slist_length (objects)
== g_slist_length (anchors), NULL);
for (; objs && anchs; objs = objs->next, anchs = anchs->next) {
SheetObject *obj = objs->data;
SheetObjectAnchor *anch = anchs->data;
SheetObjectAnchor *tmp;
if (objects_created) {
undo = go_undo_combine
(undo,
go_undo_binary_new
(g_object_ref (obj),
sheet_object_get_sheet (obj),
(GOUndoBinaryFunc) sheet_object_set_sheet,
(GFreeFunc) g_object_unref,
NULL));
}
tmp = g_new (SheetObjectAnchor, 1);
*tmp = *anch;
undo = go_undo_combine
(go_undo_binary_new
(g_object_ref (obj), tmp,
(GOUndoBinaryFunc) sheet_object_set_anchor,
(GFreeFunc) g_object_unref,
(GFreeFunc) g_free), undo);
}
return undo;
}
/*****************************************************************************/
void
......
......@@ -104,6 +104,9 @@ void sheet_objects_relocate (GnmExprRelocateInfo const *rinfo,
gboolean update, GOUndo **pundo);
void sheet_objects_clear (Sheet const *sheet, GnmRange const *r,
GType t, GOUndo **pundo);
GOUndo *sheet_object_move_undo (GSList *objects, gboolean objects_created);
GOUndo *sheet_object_move_do (GSList *objects, GSList *anchors,
gboolean objects_created);
GSList *sheet_objects_get (Sheet const *sheet, GnmRange const *r,
GType t);
void sheet_objects_dup (Sheet const *src, Sheet *dst, GnmRange *range);
......
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