From a2caee658af54b32ac3ad88564d8a04822db2fff Mon Sep 17 00:00:00 2001 From: Peter TB Brett Date: Thu, 16 Jun 2011 15:36:29 +0100 Subject: [PATCH] libgeda: Add o_get_parent() function. Add a function to retrieve an OBJECT's containing complex OBJECT, if present. --- libgeda/include/libgeda/prototype.h | 1 + libgeda/src/o_basic.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libgeda/include/libgeda/prototype.h b/libgeda/include/libgeda/prototype.h index 4f0f58401..7bc486a73 100644 --- a/libgeda/include/libgeda/prototype.h +++ b/libgeda/include/libgeda/prototype.h @@ -114,6 +114,7 @@ void o_mirror_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, OB double o_shortest_distance(OBJECT *object, int x, int y); void o_set_color(TOPLEVEL *toplevel, OBJECT *object, int color); PAGE *o_get_page (TOPLEVEL *toplevel, OBJECT *object); +OBJECT *o_get_parent (TOPLEVEL *toplevel, OBJECT *object); void o_add_change_notify(TOPLEVEL *toplevel, ChangeNotifyFunc pre_change_func, ChangeNotifyFunc change_func, void *user_data); void o_remove_change_notify(TOPLEVEL *toplevel, ChangeNotifyFunc pre_change_func, ChangeNotifyFunc change_func, void *user_data); gboolean o_is_visible (TOPLEVEL *toplevel, OBJECT *object); diff --git a/libgeda/src/o_basic.c b/libgeda/src/o_basic.c index 020e549db..bbbd47761 100644 --- a/libgeda/src/o_basic.c +++ b/libgeda/src/o_basic.c @@ -643,6 +643,27 @@ o_get_page_compat (TOPLEVEL *toplevel, OBJECT *object) { } } +/*! \brief Get an object's containing complex object. + * + * \par Function Description + * If \a object is part of a complex #OBJECT, returns that + * #OBJECT. Otherwise, returns NULL. + * + * \param [in] toplevel The TOPLEVEL structure. + * \param [in] object The OBJECT for which to get the containing OBJECT. + * \return The complex OBJECT which owns \a object, or NULL. + */ +OBJECT * +o_get_parent (TOPLEVEL *toplevel, OBJECT *object) +{ + g_return_val_if_fail ((object != NULL), NULL); + + if (object->parent != NULL) { + return object->parent; + } + return NULL; +} + /* Structure for each entry in a TOPLEVEL's list of registered change * notification handlers */ struct change_notify_entry { -- 2.11.4.GIT