* added GDK_PIXBUF_LIBS in order to create pixbuf.dll
[dia.git] / lib / connection.c
blobc7c6ee028f00d96fcc2a13b61c181a3699814c7c
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <config.h>
20 #include <stdio.h>
21 #include <string.h> /* memcpy() */
22 #include <assert.h>
24 #include "connection.h"
25 #include "message.h"
27 void
28 connection_move_handle(Connection *conn, HandleId id,
29 Point *to, HandleMoveReason reason)
31 switch(id) {
32 case HANDLE_MOVE_STARTPOINT:
33 conn->endpoints[0] = *to;
34 break;
35 case HANDLE_MOVE_ENDPOINT:
36 conn->endpoints[1] = *to;
37 break;
38 default:
39 message_error("Internal error in connection_move_handle.\n");
40 break;
44 void
45 connection_update_handles(Connection *conn)
47 conn->endpoint_handles[0].id = HANDLE_MOVE_STARTPOINT;
48 conn->endpoint_handles[0].pos = conn->endpoints[0];
50 conn->endpoint_handles[1].id = HANDLE_MOVE_ENDPOINT;
51 conn->endpoint_handles[1].pos = conn->endpoints[1];
54 void
55 connection_update_boundingbox(Connection *conn)
57 assert(conn != NULL);
59 line_bbox(&conn->endpoints[0],&conn->endpoints[1],
60 &conn->extra_spacing,&conn->object.bounding_box);
63 /* Needs to have at least 2 handles
64 The two first of each are used. */
65 void
66 connection_init(Connection *conn, int num_handles, int num_connections)
68 Object *obj;
69 int i;
71 obj = &conn->object;
73 assert(num_handles>=2);
75 object_init(obj, num_handles, num_connections);
77 assert(obj->handles!=NULL);
79 for (i=0;i<2;i++) {
80 obj->handles[i] = &conn->endpoint_handles[i];
81 obj->handles[i]->type = HANDLE_MAJOR_CONTROL;
82 obj->handles[i]->connect_type = HANDLE_CONNECTABLE;
83 obj->handles[i]->connected_to = NULL;
88 void
89 connection_copy(Connection *from, Connection *to)
91 int i;
92 Object *toobj;
93 Object *fromobj;
95 toobj = &to->object;
96 fromobj = &from->object;
98 object_copy(fromobj, toobj);
100 for (i=0;i<2;i++) {
101 to->endpoints[i] = from->endpoints[i];
104 for (i=0;i<2;i++) {
105 /* handles: */
106 to->endpoint_handles[i] = from->endpoint_handles[i];
107 to->endpoint_handles[i].connected_to = NULL;
108 toobj->handles[i] = &to->endpoint_handles[i];
110 memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
113 void
114 connection_destroy(Connection *conn)
116 object_destroy(&conn->object);
120 void
121 connection_save(Connection *conn, ObjectNode obj_node)
123 AttributeNode attr;
125 object_save(&conn->object, obj_node);
127 attr = new_attribute(obj_node, "conn_endpoints");
128 data_add_point(attr, &conn->endpoints[0]);
129 data_add_point(attr, &conn->endpoints[1]);
132 void
133 connection_load(Connection *conn, ObjectNode obj_node)
135 AttributeNode attr;
136 DataNode data;
138 object_load(&conn->object, obj_node);
140 attr = object_find_attribute(obj_node, "conn_endpoints");
141 if (attr != NULL) {
142 data = attribute_first_data(attr);
143 data_point( data , &conn->endpoints[0] );
144 data = data_next(data);
145 data_point( data , &conn->endpoints[1] );