[dia] format: update the connection object
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] format: update the connection object
- Date: Wed, 29 Jan 2020 00:43:07 +0000 (UTC)
commit e6c8523aebee6ef146e2857b1bd82caeec9b6563
Author: Zander Brown <zbrown gnome org>
Date: Wed Jan 29 00:33:06 2020 +0000
format: update the connection object
app/commands.c | 2 +-
lib/connection.c | 289 ++++++++++++++++++++++++++++++++-----------------------
lib/connection.h | 55 ++++++-----
3 files changed, 202 insertions(+), 144 deletions(-)
---
diff --git a/app/commands.c b/app/commands.c
index 6cbe5b9f..78e0a8f9 100644
--- a/app/commands.c
+++ b/app/commands.c
@@ -1136,7 +1136,7 @@ help_about_callback (GtkAction *action)
"version", VERSION,
"comments", _("A program for drawing structured diagrams."),
"copyright", "(C) 1998-2011 The Free Software Foundation and the authors\n"
- "© 2018-2019 Zander Brown et al\n",
+ "© 2018-2020 Zander Brown et al\n",
"website", "https://wiki.gnome.org/Apps/Dia/",
"authors", authors,
"documenters", documentors,
diff --git a/lib/connection.c b/lib/connection.c
index 6283c5fa..3556e3f1 100644
--- a/lib/connection.c
+++ b/lib/connection.c
@@ -24,12 +24,16 @@
#include "connection.h"
-/** Adjust connection endings for autogap. This function actually moves the
- * ends of the connection, but only when the end is connected to
+
+/**
+ * connection_adjust_for_autogap:
+ *
+ * Adjust connection endings for autogap. This function actually moves the
+ * ends of the connection, but only when the end is connected to
* a mainpoint.
*/
void
-connection_adjust_for_autogap(Connection *connection)
+connection_adjust_for_autogap (Connection *connection)
{
Point endpoints[2];
ConnectionPoint *start_cp, *end_cp;
@@ -40,72 +44,102 @@ connection_adjust_for_autogap(Connection *connection)
endpoints[0] = connection->endpoints[0];
endpoints[1] = connection->endpoints[1];
- if (connpoint_is_autogap(start_cp)) {
+ if (connpoint_is_autogap (start_cp)) {
endpoints[0] = start_cp->pos;
}
- if (connpoint_is_autogap(end_cp)) {
+
+ if (connpoint_is_autogap (end_cp)) {
endpoints[1] = end_cp->pos;
}
- if (connpoint_is_autogap(start_cp)) {
- connection->endpoints[0] = calculate_object_edge(&endpoints[0],
- &endpoints[1],
- start_cp->object);
+ if (connpoint_is_autogap (start_cp)) {
+ connection->endpoints[0] = calculate_object_edge (&endpoints[0],
+ &endpoints[1],
+ start_cp->object);
}
- if (connpoint_is_autogap(end_cp)) {
- connection->endpoints[1] = calculate_object_edge(&endpoints[1],
- &endpoints[0],
- end_cp->object);
+
+ if (connpoint_is_autogap (end_cp)) {
+ connection->endpoints[1] = calculate_object_edge (&endpoints[1],
+ &endpoints[0],
+ end_cp->object);
}
}
-/** Function called to move one of the handles associated with the object.
- * @param conn The object whose handle is being moved.
- * @param id The handle being moved.
- * @param to The position it has been moved to (corrected for
+
+/**
+ * connection_move_handle:
+ * @conn: The object whose handle is being moved.
+ * @id: The handle being moved.
+ * @to: The position it has been moved to (corrected for
* vertical/horizontal only movement).
- * @param cp If non-NULL, the connectionpoint found at this position.
- * If @a cp is NULL, there may or may not be a connectionpoint.
- * @param reason The reason the handle was moved.
- * - HANDLE_MOVE_USER means the user is dragging the point.
- * - HANDLE_MOVE_USER_FINAL means the user let go of the point.
- * - HANDLE_MOVE_CONNECTED means it was moved because something
- * it was connected to moved.
- * @param modifiers gives a bitset of modifier keys currently held down
- * - MODIFIER_SHIFT is either shift key
- * - MODIFIER_ALT is either alt key
- * - MODIFIER_CONTROL is either control key
- * Each has MODIFIER_LEFT_* and MODIFIER_RIGHT_* variants
- * @return An @a ObjectChange* with additional undo information, or
- * (in most cases) NULL. Undo for moving the handle itself is handled
- * elsewhere.
- * \memberof _Connection
+ * @cp: If non-%NULL, the connectionpoint found at this position.
+ * If @cp is %NULL, there may or may not be a connectionpoint.
+ * @reason: The reason the handle was moved.
+ * - %HANDLE_MOVE_USER means the user is dragging the point.
+ * - %HANDLE_MOVE_USER_FINAL means the user let go of the point.
+ * - %HANDLE_MOVE_CONNECTED means it was moved because something it was
+ * connected to moved.
+ * @modifiers: gives a bitset of modifier keys currently held down
+ * - %MODIFIER_SHIFT is either shift key
+ * - %MODIFIER_ALT is either alt key
+ * - %MODIFIER_CONTROL is either control key
+ * Each has %MODIFIER_LEFT_* and %MODIFIER_RIGHT_* variants
+ *
+ * Function called to move one of the handles associated with the object.
+ *
+ * Returns: An #ObjectChange with additional undo information, or
+ * (in most cases) %NULL. Undo for moving the handle itself is
+ * handled elsewhere.
*/
ObjectChange*
-connection_move_handle(Connection *conn, HandleId id,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers)
+connection_move_handle (Connection *conn,
+ HandleId id,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers)
{
- switch(id) {
- case HANDLE_MOVE_STARTPOINT:
- conn->endpoints[0] = *to;
- break;
- case HANDLE_MOVE_ENDPOINT:
- conn->endpoints[1] = *to;
- break;
- default:
- g_warning("Internal error in connection_move_handle.\n");
- break;
+ switch (id) {
+ case HANDLE_MOVE_STARTPOINT:
+ conn->endpoints[0] = *to;
+ break;
+ case HANDLE_MOVE_ENDPOINT:
+ conn->endpoints[1] = *to;
+ break;
+ case HANDLE_RESIZE_NW:
+ case HANDLE_RESIZE_N:
+ case HANDLE_RESIZE_NE:
+ case HANDLE_RESIZE_W:
+ case HANDLE_RESIZE_E:
+ case HANDLE_RESIZE_SW:
+ case HANDLE_RESIZE_S:
+ case HANDLE_RESIZE_SE:
+ case HANDLE_CUSTOM1:
+ case HANDLE_CUSTOM2:
+ case HANDLE_CUSTOM3:
+ case HANDLE_CUSTOM4:
+ case HANDLE_CUSTOM5:
+ case HANDLE_CUSTOM6:
+ case HANDLE_CUSTOM7:
+ case HANDLE_CUSTOM8:
+ case HANDLE_CUSTOM9:
+ default:
+ g_return_val_if_reached (NULL);
+ break;
}
return NULL;
}
-/** Update the type and placement of the two handles.
+
+/**
+ * connection_update_handles:
+ * @conn: The connection object to do the update on.
+ *
+ * Update the type and placement of the two handles.
* This only updates handles 0 and 1, not any handles added by subclasses.
- * @param conn The connection object to do the update on.
*/
void
-connection_update_handles(Connection *conn)
+connection_update_handles (Connection *conn)
{
conn->endpoint_handles[0].id = HANDLE_MOVE_STARTPOINT;
conn->endpoint_handles[0].pos = conn->endpoints[0];
@@ -114,123 +148,142 @@ connection_update_handles(Connection *conn)
conn->endpoint_handles[1].pos = conn->endpoints[1];
}
-/** Update the bounding box for a connection.
- * @param conn The connection to update bounding box on.
+
+/**
+ * connection_update_boundingbox:
+ * @conn: The #Connection to update bounding box on.
+ *
+ * Update the bounding box for a connection.
*/
void
-connection_update_boundingbox(Connection *conn)
+connection_update_boundingbox (Connection *conn)
{
- assert(conn != NULL);
-
- line_bbox(&conn->endpoints[0],&conn->endpoints[1],
- &conn->extra_spacing,&conn->object.bounding_box);
+ g_return_if_fail (conn != NULL);
+
+ line_bbox (&conn->endpoints[0],
+ &conn->endpoints[1],
+ &conn->extra_spacing,
+ &conn->object.bounding_box);
}
-/** Initialize a connection objects.
- * This will in turn call object_init.
- * @param conn A newly allocated connection object.
- * @param num_handles How many handles to allocate room for.
- * @param num_connections How many connectionpoints to allocate room for.
+
+/**
+ * connection_init:
+ * @conn: A newly allocated connection object.
+ * @num_handles: How many handles to allocate room for.
+ * @num_connections: How many connectionpoints to allocate room for.
+ *
+ * Initialize a connection objects.
+ * This will in turn call object_init.
*/
void
-connection_init(Connection *conn, int num_handles, int num_connections)
+connection_init (Connection *conn, int num_handles, int num_connections)
{
- DiaObject *obj;
- int i;
+ g_return_if_fail (num_handles >= 2);
- obj = &conn->object;
+ object_init (DIA_OBJECT (conn), num_handles, num_connections);
- assert(num_handles>=2);
-
- object_init(obj, num_handles, num_connections);
+ g_return_if_fail (DIA_OBJECT (conn)->handles != NULL);
- assert(obj->handles!=NULL);
-
- for (i=0;i<2;i++) {
- obj->handles[i] = &conn->endpoint_handles[i];
- obj->handles[i]->type = HANDLE_MAJOR_CONTROL;
- obj->handles[i]->connect_type = HANDLE_CONNECTABLE;
- obj->handles[i]->connected_to = NULL;
+ for (int i = 0; i < 2; i++) {
+ DIA_OBJECT (conn)->handles[i] = &conn->endpoint_handles[i];
+ DIA_OBJECT (conn)->handles[i]->type = HANDLE_MAJOR_CONTROL;
+ DIA_OBJECT (conn)->handles[i]->connect_type = HANDLE_CONNECTABLE;
+ DIA_OBJECT (conn)->handles[i]->connected_to = NULL;
}
}
-/** Copies an object connection-level and down.
- * @param from The object to copy from.
- * @param to The newly allocated object to copy into.
+
+/**
+ * connection_copy:
+ * @from: The object to copy from.
+ * @to: The newly allocated object to copy into.
+ *
+ * Copies an object connection-level and down.
*/
void
-connection_copy(Connection *from, Connection *to)
+connection_copy (Connection *from, Connection *to)
{
int i;
- DiaObject *toobj;
- DiaObject *fromobj;
- toobj = &to->object;
- fromobj = &from->object;
+ object_copy (DIA_OBJECT (from), DIA_OBJECT (to));
- object_copy(fromobj, toobj);
-
- for (i=0;i<2;i++) {
+ for (i = 0; i < 2; i++) {
to->endpoints[i] = from->endpoints[i];
}
- for (i=0;i<2;i++) {
+ for (i = 0; i < 2; i++) {
/* handles: */
to->endpoint_handles[i] = from->endpoint_handles[i];
to->endpoint_handles[i].connected_to = NULL;
- toobj->handles[i] = &to->endpoint_handles[i];
+ DIA_OBJECT (to)->handles[i] = &to->endpoint_handles[i];
}
- memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
+
+ memcpy (&to->extra_spacing,
+ &from->extra_spacing,
+ sizeof (to->extra_spacing));
}
-/** Function called before an object is deleted.
- * This function must call the parent class's DestroyFunc, and then free
- * the memory associated with the object, but not the object itself
- * Must also unconnect itself from all other objects, which can be done
- * by calling object_destroy, or letting the super-class call it)
- * This is one of the object_ops functions.
- * @param conn An object to destroy.
+
+/**
+ * connection_destroy:
+ * @conn: An object to destroy.
+ *
+ * Function called before an object is deleted.
+ * This function must call the parent class's DestroyFunc, and then free
+ * the memory associated with the object, but not the object itself
+ * Must also unconnect itself from all other objects, which can be done
+ * by calling object_destroy, or letting the super-class call it)
+ * This is one of the object_ops functions.
*/
void
-connection_destroy(Connection *conn)
+connection_destroy (Connection *conn)
{
- object_destroy(&conn->object);
+ object_destroy (DIA_OBJECT (conn));
}
-/** Save a connections data to XML.
- * @param conn The connection to save.
- * @param obj_node The XML node to save it to.
+
+/**
+ * connection_save:
+ * @conn: The connection to save.
+ * @obj_node: The XML node to save it to.
+ *
+ * Save a connections data to XML.
*/
void
-connection_save(Connection *conn, ObjectNode obj_node, DiaContext *ctx)
+connection_save (Connection *conn, ObjectNode obj_node, DiaContext *ctx)
{
AttributeNode attr;
-
- object_save(&conn->object, obj_node, ctx);
- attr = new_attribute(obj_node, "conn_endpoints");
- data_add_point(attr, &conn->endpoints[0], ctx);
- data_add_point(attr, &conn->endpoints[1], ctx);
+ object_save (DIA_OBJECT (conn), obj_node, ctx);
+
+ attr = new_attribute (obj_node, "conn_endpoints");
+ data_add_point (attr, &conn->endpoints[0], ctx);
+ data_add_point (attr, &conn->endpoints[1], ctx);
}
-/** Load a connections data from XML.
- * @param conn A fresh connection object to load into.
- * @param obj_node The XML node to load from.
- * @param ctx The context in which this function is called
+
+/**
+ * connection_load:
+ * @conn: A fresh connection object to load into.
+ * @obj_node: The XML node to load from.
+ * @ctx: The context in which this function is called
+ *
+ * Load a connections data from XML.
*/
void
-connection_load(Connection *conn, ObjectNode obj_node, DiaContext *ctx)
+connection_load (Connection *conn, ObjectNode obj_node, DiaContext *ctx)
{
AttributeNode attr;
DataNode data;
- object_load(&conn->object, obj_node, ctx);
+ object_load (DIA_OBJECT (conn), obj_node, ctx);
- attr = object_find_attribute(obj_node, "conn_endpoints");
+ attr = object_find_attribute (obj_node, "conn_endpoints");
if (attr != NULL) {
- data = attribute_first_data(attr);
- data_point(data, &conn->endpoints[0], ctx);
- data = data_next(data);
- data_point(data, &conn->endpoints[1], ctx);
+ data = attribute_first_data (attr);
+ data_point (data, &conn->endpoints[0], ctx);
+ data = data_next (data);
+ data_point (data, &conn->endpoints[1], ctx);
}
}
diff --git a/lib/connection.h b/lib/connection.h
index 470dab42..87680ca8 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -16,43 +16,50 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef CONNECTION_H
-#define CONNECTION_H
+#pragma once
#include "diatypes.h"
#include "object.h"
#include "boundingbox.h"
-/*!
- * \brief Base class for simple (straight) lines connecting object
+
+/**
+ * Connection:
*
- * This is a subclass of DiaObject used to help implementing objects
- * of a line-like type.
+ * Base class for simple (straight) lines connecting object
*
- * \extends _DiaObject
+ * This is a subclass of #DiaObject used to help implementing objects
+ * of a line-like type.
*/
struct _Connection {
- DiaObject object; /*!< inheritance */
-
+ DiaObject object;
+
Point endpoints[2]; /*!< start and end position */
Handle endpoint_handles[2]; /*!< start and end handles */
LineBBExtras extra_spacing; /*!< calcualted bounding box */
};
-void connection_update_handles(Connection *conn);
-void connection_update_boundingbox(Connection *conn);
-void connection_init(Connection *conn,
- int num_handles, int num_connections);
-void connection_destroy(Connection *conn);
-void connection_copy(Connection *from, Connection *to);
-void connection_save(Connection *conn, ObjectNode obj_node, DiaContext *ctx);
-void connection_load(Connection *conn, ObjectNode obj_node, DiaContext *ctx);
-ObjectChange* connection_move_handle(Connection *conn, HandleId id,
- Point *to, ConnectionPoint* cp,
- HandleMoveReason reason,
- ModifierKeys modifiers);
-
-void connection_adjust_for_autogap(Connection *conn);
+void connection_update_handles (Connection *conn);
+void connection_update_boundingbox (Connection *conn);
+void connection_init (Connection *conn,
+ int num_handles,
+ int num_connections);
+void connection_destroy (Connection *conn);
+void connection_copy (Connection *from,
+ Connection *to);
+void connection_save (Connection *conn,
+ ObjectNode obj_node,
+ DiaContext *ctx);
+void connection_load (Connection *conn,
+ ObjectNode obj_node,
+ DiaContext *ctx);
+ObjectChange* connection_move_handle (Connection *conn,
+ HandleId id,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers);
+void connection_adjust_for_autogap (Connection *conn);
/* base property stuff... */
#define CONNECTION_COMMON_PROPERTIES \
@@ -62,5 +69,3 @@ void connection_adjust_for_autogap(Connection *conn);
#define CONNECTION_COMMON_PROPERTIES_OFFSETS \
OBJECT_COMMON_PROPERTIES_OFFSETS, \
{ "conn_endpoints", PROP_TYPE_ENDPOINTS, offsetof(Connection,endpoints)}
-
-#endif /* CONNECTION_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]