/* needs faster algorithm -- if we find that parenting is slow. * If it works, don't optimize it until it's a hotspot. */ void diagram_parent_selected(Diagram *dia) { GList *list = dia->data->selected; int length = g_list_length(list); int idx, idx2; ObjectExtent *oe; gboolean any_parented = FALSE; GPtrArray *extents = g_ptr_array_sized_new(length); while (list) { oe = g_new(ObjectExtent, 1); oe->object = list->data; parent_handle_extents(list->data, &oe->extent); g_ptr_array_add(extents, oe); list = g_list_next(list); } /* sort all the objects by their left position */ g_ptr_array_sort(extents, diagram_parent_sort_cb); for (idx = 0; idx < length; idx++) { ObjectExtent *oe1 = g_ptr_array_index(extents, idx); if (oe1->object->parent) continue; for (idx2 = idx + 1; idx2 < length; idx2++) { ObjectExtent *oe2 = g_ptr_array_index(extents, idx2); if (!object_flags_set(oe2->object, DIA_OBJECT_CAN_PARENT)) continue; if (oe1->extent.right <= oe2->extent.right && oe1->extent.bottom <= oe2->extent.bottom) { Change *change; change = undo_parenting(dia, oe2->object, oe1->object, TRUE); (change->apply)(change, dia); any_parented = TRUE; /* oe1->object->parent = oe2->object; oe2->object->children = g_list_append(oe2->object->children, oe1->object); */ break; } } } g_ptr_array_free(extents, TRUE); if (any_parented) { diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); } }
bool parent_handle_move_out_check(Object *obj, Point *to) { Rectangle p_ext, c_ext; Point new_delta; Object *parent = obj->parent(); if (parent == NULL) return false; parent_handle_extents(parent, &p_ext); parent_point_extents(to, &c_ext); new_delta = parent_move_child_delta(&p_ext, &c_ext, NULL); new_delta += *to; if (new_delta.x() || new_delta.y()) return true; return false; }