コード例 #1
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gint
name_sort_func (GtkTreeModel *model,
		GtkTreeIter  *a,
		GtkTreeIter  *b,
		gpointer      user_data)
{
  DiaObject *pa = NODE_OBJECT(a), *pb = NODE_OBJECT(b);
  gchar *na, *nb;
  gint ret = cmp_diagram (a, b);
  if (ret)
    return ret;
  ret = cmp_layer (a, b);
  if (ret)
    return ret;
  if (pa == pb)
    return 0;
  else if (!pa || !pb)
    return (pa > pb) ? -1 : 1;
  na = object_get_displayname (pa);
  nb = object_get_displayname (pb);
  if (!na || !nb)
      return (na > nb) ? -1 : 1;
  ret = strcmp (na, nb);
  g_free (na);
  g_free (nb);
  return ret;
}
コード例 #2
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gboolean
_dtm_iter_nth_child (GtkTreeModel *tree_model,
		     GtkTreeIter  *iter,
		     GtkTreeIter  *parent,
		     gint          n)
{
  if (parent) {
    *iter = *parent;
    if (NODE_OBJECT(parent)) {
      return FALSE;
    } else if (NODE_LAYER(parent)) {
      NODE_OBJECT(iter) = layer_object_get_nth(NODE_LAYER(iter), n);
      return NODE_OBJECT(iter) != NULL;
    } else if (NODE_DIAGRAM(parent)) {
      NODE_LAYER(iter) = data_layer_get_nth(NODE_DIAGRAM(iter), n);
      return NODE_LAYER(iter) != NULL;
    }
  }
  if (!parent || !NODE_DIAGRAM(parent)) {
    /* the nth diagram */
    GList *list = dia_open_diagrams();
    list = g_list_nth(list, n);
    NODE_DIAGRAM(iter) = list ? list->data : NULL;
    NODE_LAYER(iter) = NULL;
    NODE_OBJECT(iter) = NULL;
    return NODE_DIAGRAM(iter) != NULL;
  }
  return FALSE;
}
コード例 #3
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static void
_object_remove(DiagramData      *dia,
	       Layer            *layer,
               DiaObject        *obj,
	       DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter;
  GtkTreeIter *iter = &_iter;
  gboolean last_child = layer_object_count (layer) == 0;

  g_return_if_fail (DIA_DIAGRAM(dia) != NULL);
  
  NODE_DIAGRAM(iter) = dia;
  NODE_LAYER(iter)   = layer;
  NODE_OBJECT(iter)  = obj;

  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path);
  gtk_tree_path_free (path);
  /* enforce update - but the arrow on layer does not vanish */
  if (last_child) {
    NODE_OBJECT(iter)  = NULL;
    path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
    gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, iter);
    gtk_tree_path_free (path);
  }
}
コード例 #4
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gboolean
_dtm_iter_next (GtkTreeModel *tree_model,
		GtkTreeIter  *iter)
{
  int i;
  if (NODE_OBJECT(iter)) {
    if (!NODE_LAYER(iter))
      return FALSE;
    i = layer_object_get_index (NODE_LAYER(iter), NODE_OBJECT(iter));
    ++i;
    NODE_OBJECT(iter) = layer_object_get_nth(NODE_LAYER(iter), i);
    return NODE_OBJECT(iter) != NULL;
  } else if (NODE_LAYER(iter)) {
    if (!NODE_DIAGRAM(iter))
      return FALSE;
    i = data_layer_get_index (NODE_DIAGRAM(iter), NODE_LAYER(iter));
    ++i;
    NODE_LAYER(iter) = data_layer_get_nth(NODE_DIAGRAM(iter), i);
    return NODE_LAYER(iter) != NULL;
  } else if (NODE_DIAGRAM(iter)) {
    GList *list = dia_open_diagrams();
    i = g_list_index (list, NODE_DIAGRAM(iter));
    ++i;
    list = g_list_nth (list, i);
    NODE_DIAGRAM(iter) = list ? list->data : NULL;
    return NODE_DIAGRAM(iter) != NULL;
  } else {
    /* empy iter? */
    GList *list = dia_open_diagrams();
    NODE_DIAGRAM(iter) = list ? list->data : NULL;
    return NODE_DIAGRAM(iter) != NULL;
  }
  return FALSE;
}
コード例 #5
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static void
_diagram_change (DiaApplication   *app,
                 Diagram          *dia,
		 guint             flags,
		 gpointer          object,
	         DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter = {0,};
  GtkTreeIter *iter = &_iter;
  
  NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA(dia);

  if (flags & DIAGRAM_CHANGE_NAME)
    /* nothing special */;
  if (flags & DIAGRAM_CHANGE_LAYER)
    NODE_LAYER(iter) = object;
  if (flags & DIAGRAM_CHANGE_OBJECT) {
    NODE_OBJECT(iter) = object;
    NODE_LAYER(iter) = dia_object_get_parent_layer (object);
  }

  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  gtk_tree_model_row_changed (GTK_TREE_MODEL (dtm), path, iter);
  gtk_tree_path_free (path);
}
コード例 #6
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
/* listen on the diagram for object add/remove */
static void
_object_add (DiagramData      *dia,
	     Layer            *layer,
             DiaObject        *obj,
	     DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter;
  GtkTreeIter *iter = &_iter;
  /* a bit backward: the first child is in the diagram, but not the tree yet */
  gboolean had_child = layer_object_count (layer) > 1;

  g_return_if_fail (DIA_DIAGRAM(dia) != NULL);

  NODE_DIAGRAM(iter) = dia;
  NODE_LAYER(iter)   = layer;
  NODE_OBJECT(iter)  = obj;


  /* FIXME: this may get called before the layer is added to the tree */
  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  if (path) {
    gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter);
    /* enforce update */
    if (!had_child && gtk_tree_path_up (path))
      gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, &_iter);
    gtk_tree_path_free (path);
  }
}
コード例 #7
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gint
type_sort_func (GtkTreeModel *model,
		GtkTreeIter  *a,
		GtkTreeIter  *b,
		gpointer      user_data)
{
  DiaObject *pa = NODE_OBJECT(a), *pb = NODE_OBJECT(b);
  gint ret = cmp_diagram (a, b);
  if (ret)
    return ret;
  ret = cmp_layer (a, b);
  if (ret)
    return ret;
  if (pa == pb)
    return 0;
  else if (!pa || !pb)
    return (pa > pb) ? -1 : 1;
  return strcmp (pa->type->name, pb->type->name);
}
コード例 #8
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gboolean
_dtm_iter_parent (GtkTreeModel *tree_model,
		  GtkTreeIter  *iter,
		  GtkTreeIter  *child)
{
  *iter = *child;
  if (!NODE_DIAGRAM(child))
    return FALSE;
  if (NODE_OBJECT(child))
    NODE_OBJECT(iter) = NULL;
  else if (NODE_LAYER(child))
    NODE_LAYER(iter) = NULL;
  else if (NODE_DIAGRAM(child))
    NODE_DIAGRAM(iter) = NULL;
  else
    return FALSE;

  return TRUE;
}
コード例 #9
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static GtkTreePath *
_dtm_get_path (GtkTreeModel *tree_model,
	       GtkTreeIter  *iter)
{
  GtkTreePath *result;
  int index = 0;

  if (!NODE_DIAGRAM(iter) && !NODE_LAYER(iter) && !NODE_OBJECT(iter)) {
    /* the root path */
    return gtk_tree_path_new_first ();
  }

  result = gtk_tree_path_new ();

  if (NODE_DIAGRAM(iter)) {
    GList *list = dia_open_diagrams();
    gtk_tree_path_append_index (result, g_list_index (list, NODE_DIAGRAM(iter)));
  }
  if (NODE_LAYER(iter)) {
    g_return_val_if_fail (NODE_DIAGRAM(iter) == layer_get_parent_diagram (NODE_LAYER(iter)), NULL);
    index = data_layer_get_index (NODE_DIAGRAM(iter), NODE_LAYER(iter));
    if (index >= 0)
      gtk_tree_path_append_index (result, index);
  }
  if (index >= 0 && NODE_OBJECT(iter)) {
    g_return_val_if_fail (NODE_LAYER(iter) == dia_object_get_parent_layer (NODE_OBJECT(iter)), NULL);
    index = layer_object_get_index (NODE_LAYER(iter), NODE_OBJECT(iter));
    if (index >= 0)
      gtk_tree_path_append_index (result, index);
  }

  if (index < 0) {
    gtk_tree_path_free (result);
    return NULL;
  }
  return result;
}
コード例 #10
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static void
_dtm_get_value (GtkTreeModel *tree_model,
		GtkTreeIter  *iter,
		gint          column,
		GValue       *value)
{

  switch (column) {
  case DIAGRAM_COLUMN :
    g_value_init (value, G_TYPE_OBJECT);
    g_value_set_object (value, NODE_DIAGRAM(iter));
    break;
  case LAYER_COLUMN :
    g_value_init (value, G_TYPE_POINTER);
    g_value_set_pointer (value, NODE_LAYER(iter));
    break;
  case OBJECT_COLUMN :
    g_value_init (value, G_TYPE_POINTER);
    g_value_set_pointer (value, NODE_OBJECT(iter));
    break;
  case NAME_COLUMN :
    g_value_init (value, G_TYPE_STRING);
    /* deduce the requested name from the iter */
    if (NODE_OBJECT(iter))
      g_value_set_string (value, object_get_displayname (NODE_OBJECT (iter)));
    else if (NODE_LAYER(iter))
      g_value_set_string (value, layer_get_name (NODE_LAYER (iter)));
    else if (NODE_DIAGRAM(iter))
      g_value_set_string (value, diagram_get_name (DIA_DIAGRAM(NODE_DIAGRAM(iter))));
    else /* warn on it? */
      g_value_set_string (value, NULL);
    break;
  default :
    g_assert_not_reached ();
  }
}
コード例 #11
0
ファイル: diagram_tree_model.c プロジェクト: rennhak/Dia
static void
_object_remove(DiagramData      *dia,
	       Layer            *layer,
               DiaObject        *obj,
	       DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter;
  GtkTreeIter *iter = &_iter;

  g_return_if_fail (DIA_DIAGRAM(dia) != NULL);
  
  NODE_DIAGRAM(iter) = dia;
  NODE_LAYER(iter)   = layer;
  NODE_OBJECT(iter)  = obj;

  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path);
  gtk_tree_path_free (path);
}
コード例 #12
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static void
_diagram_remove (DiaApplication   *app,
                 Diagram          *dia,
	         DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter = {0,};
  GtkTreeIter *iter = &_iter;
  
  NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA(dia);
  NODE_LAYER(iter)   = NULL;
  NODE_OBJECT(iter)  = NULL;

  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path);
  gtk_tree_path_free (path);

  /* stop listening on this diagram */
  g_signal_handlers_disconnect_by_func (dia, _object_add, dtm);
  g_signal_handlers_disconnect_by_func (dia, _object_remove, dtm);
}
コード例 #13
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gint
_dtm_iter_n_children (GtkTreeModel *tree_model,
		      GtkTreeIter  *iter)
{
  if (!iter)
    return g_list_length (dia_open_diagrams());

  if (NODE_OBJECT(iter)) {
    /* TODO: dive into objects (groups?)? */
    return 0;
  } else if (NODE_LAYER(iter)) {
    if (!NODE_LAYER(iter))
      return 0;
    return layer_object_count (NODE_LAYER(iter));
  } else if (NODE_DIAGRAM(iter)) {
     if (!NODE_DIAGRAM(iter))
       return 0;
     return data_layer_count (NODE_DIAGRAM(iter));
  }
  return 0;
}
コード例 #14
0
ファイル: diagram_tree_model.c プロジェクト: rennhak/Dia
/* listen on the diagram for object add/remove */
static void
_object_add (DiagramData      *dia,
	     Layer            *layer,
             DiaObject        *obj,
	     DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter;
  GtkTreeIter *iter = &_iter;

  g_return_if_fail (DIA_DIAGRAM(dia) != NULL);

  NODE_DIAGRAM(iter) = dia;
  NODE_LAYER(iter)   = layer;
  NODE_OBJECT(iter)  = obj;


  /* FIXME: this may get called before the layer is added to the tree */
  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  if (path) {
    gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter);
    gtk_tree_path_free (path);
  }
}
コード例 #15
0
ファイル: diagram_tree_model.c プロジェクト: brunetton/dia
static gboolean
_dtm_iter_children (GtkTreeModel *tree_model,
		    GtkTreeIter  *iter,
		    GtkTreeIter  *parent)
{
  if (parent) {
    if (NODE_OBJECT(parent))
      return FALSE;
    else if (NODE_LAYER(parent)) {
      NODE_OBJECT(iter) = layer_object_get_nth(NODE_LAYER(parent), 0);
      if (NODE_OBJECT(iter)) {
        NODE_LAYER(iter) = dia_object_get_parent_layer(NODE_OBJECT(iter));
	NODE_DIAGRAM(iter) = layer_get_parent_diagram (NODE_LAYER(iter));
	return TRUE;
      }
    } else if (NODE_DIAGRAM(parent)) {
      NODE_LAYER(iter) = data_layer_get_nth(NODE_DIAGRAM(parent), 0);
      if (NODE_LAYER(iter)) {
	NODE_DIAGRAM(iter) = layer_get_parent_diagram (NODE_LAYER(iter));
	NODE_OBJECT(iter) = NULL;
	return TRUE;
      }
    } else {
      /* deliver root's children */
      parent = NULL;
    }
  }
  if (!parent) {
    /* the first diagram */
    GList *list = dia_open_diagrams();
    NODE_DIAGRAM(iter) = list ? list->data : NULL;
    NODE_LAYER(iter) = NULL;
    NODE_OBJECT(iter) = NULL;
    return NODE_DIAGRAM(iter) != NULL;
  }
  return FALSE;
}