static void message_move_handle(Message *message, Handle *handle, Point *to, HandleMoveReason reason, ModifierKeys modifiers) { Point p1, p2; Point *endpoints; assert(message!=NULL); assert(handle!=NULL); assert(to!=NULL); if (handle->id == HANDLE_MOVE_TEXT) { message->text_pos = *to; } else { endpoints = &message->connection.endpoints[0]; p1.x = 0.5*(endpoints[0].x + endpoints[1].x); p1.y = 0.5*(endpoints[0].y + endpoints[1].y); connection_move_handle(&message->connection, handle->id, to, reason); p2.x = 0.5*(endpoints[0].x + endpoints[1].x); p2.y = 0.5*(endpoints[0].y + endpoints[1].y); point_sub(&p2, &p1); point_add(&message->text_pos, &p2); } message_update_data(message); }
static void message_set_props(Message *message, GPtrArray *props) { object_set_props_from_offsets(&message->connection.object, message_offsets, props); message_update_data(message); }
/* creation here */ static DiaObject * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; LineBBExtras *extra; DiaObject *obj; if (message_font == NULL) { message_font = dia_font_new_from_style (DIA_FONT_SANS, MESSAGE_FONTHEIGHT); } message = g_malloc0(sizeof(Message)); conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &jackson_phenomenon_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text = g_strdup(""); message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y); message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; extra->start_long = extra->start_trans = extra->end_long = MESSAGE_WIDTH/2.0; extra->end_trans = MAX(MESSAGE_WIDTH,MESSAGE_ARROWLEN)/2.0; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; /* init type */ switch (GPOINTER_TO_INT(user_data)) { case 1: message->type=MSG_SHARED; break; case 2: message->type=MSG_REQ; break; default: message->type=MSG_SHARED; break; } if (GPOINTER_TO_INT(user_data)!=0) message->init=-1; else message->init=0; return &message->connection.object; }
static void message_set_props(Message *message, GPtrArray *props) { if (message->init==-1) { message->init++; return; } object_set_props_from_offsets(&message->connection.object, message_offsets, props); message_update_data(message); }
static DiaObject * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; LineBBExtras *extra; DiaObject *obj; message = g_malloc0(sizeof(Message)); /* old defaults */ message->font_height = 0.8; message->font = dia_font_new_from_style (DIA_FONT_SANS, message->font_height); message->line_width = 0.1; conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &message_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text_color = color_black; message->line_color = attributes_get_foreground(); message->text = g_strdup(""); message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) + 0.5; message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; extra->start_long = extra->start_trans = extra->end_long = message->line_width/2.0; extra->end_trans = MAX(message->line_width,MESSAGE_ARROWLEN)/2.0; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &message->connection.object; }
static void message_set_state(Message *message, MessageState *state) { g_free(message->text); message->text = state->text; message->type = state->type; g_free(state); message_update_data(message); }
static Object * message_load(ObjectNode obj_node, int version, const char *filename) { Message *message; AttributeNode attr; Connection *conn; Object *obj; if (message_font == NULL) message_font = font_getfont("Helvetica"); message = g_malloc(sizeof(Message)); conn = &message->connection; obj = (Object *) message; obj->type = &message_type; obj->ops = &message_ops; connection_load(conn, obj_node); connection_init(conn, 3, 0); message->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) message->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &message->text_pos); attr = object_find_attribute(obj_node, "type"); if (attr != NULL) message->type = (MessageType)data_int(attribute_first_data(attr)); if (message->text) message->text_width = font_string_width(message->text, message_font, MESSAGE_FONTHEIGHT); else message->text_width = 0; message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; message_update_data(message); return (Object *)message; }
static Object * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; Object *obj; if (message_font == NULL) message_font = font_getfont("Helvetica"); message = g_malloc(sizeof(Message)); conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = (Object *) message; obj->type = &message_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text = NULL; message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y); message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (Object *)message; }
static void message_move(Message *message, Point *to) { Point start_to_end; Point *endpoints = &message->connection.endpoints[0]; Point delta; delta = *to; point_sub(&delta, &endpoints[0]); start_to_end = endpoints[1]; point_sub(&start_to_end, &endpoints[0]); endpoints[1] = endpoints[0] = *to; point_add(&endpoints[1], &start_to_end); point_add(&message->text_pos, &delta); message_update_data(message); }
static ObjectChange * message_apply_properties(Message *message) { MessageDialog *prop_dialog; ObjectState *old_state; prop_dialog = properties_dialog; old_state = (ObjectState *)message_get_state(message); /* Read from dialog and put in object: */ g_free(message->text); message->text = strdup(gtk_entry_get_text(prop_dialog->text)); message->text_width = font_string_width(message->text, message_font, MESSAGE_FONTHEIGHT); if (GTK_TOGGLE_BUTTON(prop_dialog->m_call)->active) message->type = MESSAGE_CALL; else if (GTK_TOGGLE_BUTTON( prop_dialog->m_return )->active) message->type = MESSAGE_RETURN; else if (GTK_TOGGLE_BUTTON( prop_dialog->m_create )->active) message->type = MESSAGE_CREATE; else if (GTK_TOGGLE_BUTTON( prop_dialog->m_destroy )->active) message->type = MESSAGE_DESTROY; else if (GTK_TOGGLE_BUTTON( prop_dialog->m_send )->active) message->type = MESSAGE_SEND; else if (GTK_TOGGLE_BUTTON( prop_dialog->m_simple )->active) message->type = MESSAGE_SIMPLE; else if (GTK_TOGGLE_BUTTON( prop_dialog->m_recursive )->active) message->type = MESSAGE_RECURSIVE; message_update_data(message); return new_object_state_change((Object *)message, old_state, (GetStateFunc)message_get_state, (SetStateFunc)message_set_state); }