Beispiel #1
0
static void
text_split_line(Text *text)
{
  int i;
  int row;
  int numlines;
  char *line;
  int orig_len;
  real width;
  
  text->numlines += 1;
  numlines = text->numlines;
  text->line = g_realloc(text->line, sizeof(char *)*numlines);
  text->strlen = g_realloc(text->strlen, sizeof(int)*numlines);
  text->alloclen = g_realloc(text->alloclen, sizeof(int)*numlines);
  text->row_width = g_realloc(text->row_width, sizeof(real)*numlines);

  row = text->cursor_row;
  for (i=text->numlines-1;i>row+1;i--) {
    text->line[i] = text->line[i-1];
    text->strlen[i] = text->strlen[i-1];
    text->alloclen[i] = text->alloclen[i-1];
    text->row_width[i] = text->row_width[i-1];
  }
  /* row and row+1 needs to be changed: */
  line = text->line[row];
  orig_len = text->strlen[row];
  
  text->strlen[row] = text->cursor_pos;
  text->alloclen[row] = text->strlen[row] + 1;
  text->line[row] = g_malloc(sizeof(char)*(text->alloclen[row]));
  memcpy(text->line[row], line, text->strlen[row]);
  text->line[row][text->strlen[row]] = 0;
  
  text->strlen[row+1] = orig_len - text->strlen[row];
  text->alloclen[row+1] = text->strlen[row+1] + 1;
  text->line[row+1] = g_malloc(sizeof(char)*(text->alloclen[row+1]));
  memcpy(text->line[row+1], line + text->cursor_pos, text->strlen[row+1]);
  text->line[row+1][text->strlen[row+1]] = 0;

  g_free(line);

  text->row_width[row] = 
    font_string_width(text->line[row], text->font, text->height);
  text->row_width[row+1] = 
    font_string_width(text->line[row+1], text->font, text->height);

  width = 0.0;
  for (i=0;i<text->numlines;i++) {
    width = MAX(width, text->row_width[i]);
  }
  text->max_width = width;

  text->cursor_row += 1;
  text->cursor_pos = 0;
}
static ObjectChange *
generalization_apply_properties(Generalization *genlz)
{
  GeneralizationPropertiesDialog *prop_dialog;
  ObjectState *old_state;
  char *str;

  prop_dialog = genlz->properties_dialog;

  old_state = (ObjectState *)generalization_get_state(genlz);

  /* Read from dialog and put in object: */
  if (genlz->name != NULL)
    g_free(genlz->name);
  str = gtk_entry_get_text(prop_dialog->name);
  if (strlen(str) != 0)
    genlz->name = strdup(str);
  else
    genlz->name = NULL;

  if (genlz->stereotype != NULL)
    g_free(genlz->stereotype);
  
  str = gtk_entry_get_text(prop_dialog->stereotype);
  
  if (strlen(str) != 0) {
    genlz->stereotype = g_malloc(sizeof(char)*strlen(str)+2+1);
    genlz->stereotype[0] = UML_STEREOTYPE_START;
    genlz->stereotype[1] = 0;
    strcat(genlz->stereotype, str);
    genlz->stereotype[strlen(str)+1] = UML_STEREOTYPE_END;
    genlz->stereotype[strlen(str)+2] = 0;
  } else {
    genlz->stereotype = NULL;
  }

  genlz->text_width = 0.0;

  if (genlz->name != NULL) {
    genlz->text_width =
      font_string_width(genlz->name, genlz_font, GENERALIZATION_FONTHEIGHT);
  }
  if (genlz->stereotype != NULL) {
    genlz->text_width = MAX(genlz->text_width,
			  font_string_width(genlz->stereotype, genlz_font, GENERALIZATION_FONTHEIGHT));
  }
  
  generalization_update_data(genlz);
  return new_object_state_change((Object *)genlz, old_state, 
				 (GetStateFunc)generalization_get_state,
				 (SetStateFunc)generalization_set_state);
}
static Object *
generalization_load(ObjectNode obj_node, int version,
		    const char *filename)
{
  Generalization *genlz;
  AttributeNode attr;
  OrthConn *orth;
  Object *obj;

  if (genlz_font == NULL) {
    genlz_font = font_getfont("Courier");
  }

  genlz = g_new(Generalization, 1);

  orth = &genlz->orth;
  obj = (Object *) genlz;

  obj->type = &generalization_type;
  obj->ops = &generalization_ops;

  orthconn_load(orth, obj_node);

  genlz->name = NULL;
  attr = object_find_attribute(obj_node, "name");
  if (attr != NULL)
    genlz->name = data_string(attribute_first_data(attr));
  
  genlz->stereotype = NULL;
  attr = object_find_attribute(obj_node, "stereotype");
  if (attr != NULL)
    genlz->stereotype = data_string(attribute_first_data(attr));

  genlz->text_width = 0.0;

  genlz->properties_dialog = NULL;
  
  if (genlz->name != NULL) {
    genlz->text_width =
      font_string_width(genlz->name, genlz_font, GENERALIZATION_FONTHEIGHT);
  }
  if (genlz->stereotype != NULL) {
    genlz->text_width = MAX(genlz->text_width,
			  font_string_width(genlz->stereotype, genlz_font, GENERALIZATION_FONTHEIGHT));
  }
  
  generalization_update_data(genlz);

  return (Object *)genlz;
}
static ObjectChange *
constraint_apply_properties(Constraint *constraint)
{
  ConstraintDialog *prop_dialog;
  char *str;
  ObjectState *old_state;
  
  prop_dialog = constraint->properties_dialog;

  old_state = (ObjectState *)constraint_get_state(constraint);

  /* Read from dialog and put in object: */
  g_free(constraint->text);
  str = strdup(gtk_entry_get_text(prop_dialog->text));
  constraint->text = g_malloc(sizeof(char)*strlen(str)+2+1);
  strcpy(constraint->text, "{");
  strcat(constraint->text, str);
  strcat(constraint->text, "}");
    
  constraint->text_width =
      font_string_width(constraint->text, constraint_font,
			CONSTRAINT_FONTHEIGHT);
  
  constraint_update_data(constraint);
  return new_object_state_change((Object *)constraint, old_state, 
				 (GetStateFunc)constraint_get_state,
				 (SetStateFunc)constraint_set_state);

}
Beispiel #5
0
static void
text_insert_char(Text *text, char c)
{
  int row;
  int i;
  char *line;
  
  row = text->cursor_row;

  if ( text->strlen[row]+2 > text->alloclen[row] ) {
    text->alloclen[row] = text->strlen[row]+2;
    text->line[row] =
      g_realloc( text->line[row], sizeof(char)*text->alloclen[row] );
  }

  line = text->line[row];
  for (i=text->strlen[row];i>=text->cursor_pos;i--) {
    line[i+1] = line[i];
  }
  line[text->cursor_pos] = c;
  text->cursor_pos += 1;
  text->strlen[row] += 1;

  text->row_width[row] = font_string_width(text->line[row], text->font, text->height);
  text->max_width = MAX(text->max_width, text->row_width[row]);
}
static Object *
implements_load(ObjectNode obj_node, int version, const char *filename)
{
  Implements *implements;
  AttributeNode attr;
  Connection *conn;
  Object *obj;

  if (implements_font == NULL)
    implements_font = font_getfont("Courier");

  implements = g_malloc(sizeof(Implements));

  conn = &implements->connection;
  obj = (Object *) implements;

  obj->type = &implements_type;
  obj->ops = &implements_ops;

  connection_load(conn, obj_node);
  
  connection_init(conn, 4, 0);

  implements->circle_diameter = 1.0;
  attr = object_find_attribute(obj_node, "diameter");
  if (attr != NULL)
    implements->circle_diameter = data_real(attribute_first_data(attr));

  implements->text = NULL;
  attr = object_find_attribute(obj_node, "text");
  if (attr != NULL)
    implements->text = data_string(attribute_first_data(attr));

  attr = object_find_attribute(obj_node, "text_pos");
  if (attr != NULL)
    data_point(attribute_first_data(attr), &implements->text_pos);

  implements->text_width =
      font_string_width(implements->text, implements_font,
			IMPLEMENTS_FONTHEIGHT);

  implements->text_handle.id = HANDLE_MOVE_TEXT;
  implements->text_handle.type = HANDLE_MINOR_CONTROL;
  implements->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  implements->text_handle.connected_to = NULL;
  obj->handles[2] = &implements->text_handle;
  
  implements->circle_handle.id = HANDLE_CIRCLE_SIZE;
  implements->circle_handle.type = HANDLE_MINOR_CONTROL;
  implements->circle_handle.connect_type = HANDLE_NONCONNECTABLE;
  implements->circle_handle.connected_to = NULL;
  obj->handles[3] = &implements->circle_handle;

  implements->properties_dialog = NULL;

  
  implements_update_data(implements);
  
  return (Object *)implements;
}
Beispiel #7
0
static void
text_delete_backward(Text *text)
{
  int row;
  int i;
  real width;
  
  row = text->cursor_row;
  
  if (text->cursor_pos <= 0) {
    if (row > 0)
      text_join_lines(text, row-1);
    return;
  }
  memmove(text->line[row] + text->cursor_pos - 1,
	  text->line[row] + text->cursor_pos,
	  text->strlen[row] - text->cursor_pos + 1);

  text->strlen[row]--;

  text->cursor_pos --;
  
  if (text->cursor_pos > text->strlen[text->cursor_row])
    text->cursor_pos = text->strlen[text->cursor_row];

  text->row_width[row] = font_string_width(text->line[row], text->font, text->height);

  width = 0.0;
  for (i=0;i<text->numlines;i++) {
    width = MAX(width, text->row_width[i]);
  }
  text->max_width = width;
}
Beispiel #8
0
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 void
generalization_set_state(Generalization *genlz, GeneralizationState *state)
{
  g_free(genlz->name);
  g_free(genlz->stereotype);
  genlz->name = state->name;
  genlz->stereotype = state->stereotype;
  
  genlz->text_width = 0.0;
  if (genlz->name != NULL) {
    genlz->text_width =
      font_string_width(genlz->name, genlz_font, GENERALIZATION_FONTHEIGHT);
  }
  if (genlz->stereotype != NULL) {
    genlz->text_width = MAX(genlz->text_width,
			  font_string_width(genlz->stereotype, genlz_font, GENERALIZATION_FONTHEIGHT));
  }
  
  g_free(state);
  
  generalization_update_data(genlz);
}
Beispiel #10
0
static void
text_join_lines(Text *text, int first_line)
{
  int i;
  int len1;
  real width;
  char *str1, *str2;
  int numlines;

  str1 = text->line[first_line];
  str2 = text->line[first_line+1];

  text->line[first_line] = NULL;
  text->line[first_line+1] = NULL;

  for (i=first_line+1;i<text->numlines-1;i++) {
    text->line[i] = text->line[i+1];
    text->strlen[i] = text->strlen[i+1];
    text->alloclen[i] = text->alloclen[i+1];
    text->row_width[i] = text->row_width[i+1];
  }
  len1 = strlen(str1);
  text->strlen[first_line] = len1 + strlen(str2);
  text->alloclen[first_line] = text->strlen[first_line] + 1;
  text->line[first_line] =
    g_malloc(sizeof(char)*(text->alloclen[first_line]));
  strcpy(text->line[first_line], str1);
  strcat(text->line[first_line], str2);
  g_free(str1);
  g_free(str2);
  
  text->numlines -= 1;
  numlines = text->numlines;
  text->line = g_realloc(text->line, sizeof(char *)*numlines);
  text->strlen = g_realloc(text->strlen, sizeof(int)*numlines);
  text->alloclen = g_realloc(text->alloclen, sizeof(int)*numlines);
  text->row_width = g_realloc(text->row_width, sizeof(real)*numlines);

  text->row_width[first_line] = 
    font_string_width(text->line[first_line], text->font, text->height);

  width = 0.0;
  for (i=0;i<text->numlines;i++) {
    width = MAX(width, text->row_width[i]);
  }
  text->max_width = width;

  text->cursor_row = first_line;
  text->cursor_pos = len1;
  
}
Beispiel #11
0
static Object *
constraint_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Constraint *constraint;
  Connection *conn;
  Object *obj;
  Point defaultlen = { 1.0, 1.0 };

  if (constraint_font == NULL)
    constraint_font = font_getfont("Courier");
  
  constraint = g_malloc(sizeof(Constraint));

  conn = &constraint->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  point_add(&conn->endpoints[1], &defaultlen);
 
  obj = (Object *) constraint;
  
  obj->type = &constraint_type;
  obj->ops = &constraint_ops;
  
  connection_init(conn, 3, 0);

  constraint->text = strdup("{}");
  constraint->text_width =
      font_string_width(constraint->text, constraint_font, CONSTRAINT_FONTHEIGHT);
  constraint->text_width = 0.0;
  constraint->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x);
  constraint->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y);

  constraint->text_handle.id = HANDLE_MOVE_TEXT;
  constraint->text_handle.type = HANDLE_MINOR_CONTROL;
  constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  constraint->text_handle.connected_to = NULL;
  obj->handles[2] = &constraint->text_handle;
  
  constraint->properties_dialog = NULL;
  
  constraint_update_data(constraint);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return (Object *)constraint;
}
Beispiel #12
0
static void
constraint_set_state(Constraint *constraint, ConstraintState *state)
{
  g_free(constraint->text);
  constraint->text = state->text;
  constraint->text_width = 0.0;
  if (constraint->text != NULL) {
    constraint->text_width =
      font_string_width(constraint->text, constraint_font, CONSTRAINT_FONTHEIGHT);
  } 
  
  g_free(state);
  
  constraint_update_data(constraint);
}
Beispiel #13
0
static void
calc_width(Text *text)
{
  real width;
  int i;

  width = 0.0;
  for (i=0;i<text->numlines;i++) {
    text->row_width[i] =
      font_string_width(text->line[i], text->font, text->height);
    width = MAX(width, text->row_width[i]);
  }
  
  text->max_width = width;
}
Beispiel #14
0
static Object *
constraint_load(ObjectNode obj_node, int version, const char *filename)
{
  Constraint *constraint;
  AttributeNode attr;
  Connection *conn;
  Object *obj;

  if (constraint_font == NULL)
    constraint_font = font_getfont("Courier");

  constraint = g_malloc(sizeof(Constraint));

  conn = &constraint->connection;
  obj = (Object *) constraint;

  obj->type = &constraint_type;
  obj->ops = &constraint_ops;

  connection_load(conn, obj_node);
  
  connection_init(conn, 3, 0);

  constraint->text = NULL;
  attr = object_find_attribute(obj_node, "text");
  if (attr != NULL)
    constraint->text = data_string(attribute_first_data(attr));

  attr = object_find_attribute(obj_node, "text_pos");
  if (attr != NULL)
    data_point(attribute_first_data(attr), &constraint->text_pos);

  constraint->text_width =
      font_string_width(constraint->text, constraint_font, CONSTRAINT_FONTHEIGHT);

  constraint->text_handle.id = HANDLE_MOVE_TEXT;
  constraint->text_handle.type = HANDLE_MINOR_CONTROL;
  constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  constraint->text_handle.connected_to = NULL;
  obj->handles[2] = &constraint->text_handle;
  
  constraint->properties_dialog = NULL;
  
  constraint_update_data(constraint);
  
  return (Object *)constraint;
}
Beispiel #15
0
//strwidth(char string, int font);
HRESULT openbor_strwidth(ScriptVariant **varlist , ScriptVariant **pretvar, int paramCount)
{
    LONG ltemp;
    if(paramCount < 2 || varlist[0]->vt != VT_STR ||
            FAILED(ScriptVariant_IntegerValue(varlist[1], &ltemp)))
    {
        goto strwidth_error;
    }

    ScriptVariant_ChangeType(*pretvar, VT_INTEGER);
    (*pretvar)->lVal = font_string_width((int)ltemp, (char *)StrCache_Get(varlist[0]->strVal));
    return S_OK;

strwidth_error:
    printf("Error, strwidth({string}, {font}): Invalid or missing parameter.\n");
    *pretvar = NULL;
    return E_FAIL;
}
Beispiel #16
0
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);
}
Beispiel #17
0
static ObjectChange *
implements_apply_properties(Implements *implements)
{
  ImplementsDialog *prop_dialog;
  ObjectState *old_state;

  prop_dialog = implements->properties_dialog;

  old_state = (ObjectState *)implements_get_state(implements);
  
  /* Read from dialog and put in object: */
  g_free(implements->text);
  implements->text = strdup(gtk_entry_get_text(prop_dialog->text));

  implements->text_width =
      font_string_width(implements->text, implements_font,
			IMPLEMENTS_FONTHEIGHT);
  
  implements_update_data(implements);

  return new_object_state_change((Object *)implements, old_state, 
				 (GetStateFunc)implements_get_state,
				 (SetStateFunc)implements_set_state);
}