src/gtk/iupgtk_tree.c
static void gtkTreeCopyMoveNode(Ihandle* ih, GtkTreeModel* model, GtkTreeIter *iterItemSrc, GtkTreeIter *iterItemDst, GtkTreeIter* iterNewItem, int is_copy)
{
  int kind, position = 0; /* insert after iterItemDst */
  int id_new, count, id_src, id_dst;

  int old_count = ih->data->node_count;

  id_src = gtkTreeFindNodeId(ih, iterItemSrc);
  id_dst = gtkTreeFindNodeId(ih, iterItemDst);
  id_new = id_dst+1; /* contains the position for a copy operation */

  gtk_tree_model_get(model, iterItemDst, IUPGTK_NODE_KIND, &kind, -1);

  if (kind == ITREE_BRANCH)
  {
    GtkTreePath* path = gtk_tree_model_get_path(model, iterItemDst);
    if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(ih->handle), path))
      position = 1;  /* insert as first child of iterItemDst */
    else
    {
      int child_count = gtkTreeTotalChildCount(ih, iterItemDst);
      id_new += child_count;
    }
    gtk_tree_path_free(path);
  }

  /* move to the same place does nothing */
  if (!is_copy && id_new == id_src)
  {
    iterNewItem->stamp = 0;
    return;
  }

  gtkTreeCopyItem(ih, model, iterItemSrc, iterItemDst, position, iterNewItem);  

  gtkTreeCopyChildren(ih, model, iterItemSrc, iterNewItem);

  count = ih->data->node_count - old_count;
  iupTreeCopyMoveCache(ih, id_src, id_new, count, is_copy);

  if (!is_copy)
  {
    /* Deleting the node of its old position */
    iupAttribSet(ih, "_IUPTREE_IGNORE_SELECTION_CB", "1");
    gtk_tree_store_remove(GTK_TREE_STORE(model), iterItemSrc);
    iupAttribSet(ih, "_IUPTREE_IGNORE_SELECTION_CB", NULL);

    /* restore count, because we remove src */
    ih->data->node_count = old_count;

    /* compensate position for a move */
    if (id_new > id_src)
      id_new -= count;
  }

  gtkTreeRebuildNodeCache(ih, id_new, *iterNewItem);
}
/* Copies all items in a branch to a new location. Returns the new branch node. */
Copies all items in a branch to a new location. Returns the new branch node.
Copies all items in a branch to a new location . Returns the new branch node .
static void gtkTreeCopyMoveNode(Ihandle* ih, GtkTreeModel* model, GtkTreeIter *iterItemSrc, GtkTreeIter *iterItemDst, GtkTreeIter* iterNewItem, int is_copy)
{
  int kind, position = 0; 
  int id_new, count, id_src, id_dst;
  int old_count = ih->data->node_count;
  id_src = gtkTreeFindNodeId(ih, iterItemSrc);
  id_dst = gtkTreeFindNodeId(ih, iterItemDst);
  id_new = id_dst+1; 
  gtk_tree_model_get(model, iterItemDst, IUPGTK_NODE_KIND, &kind, -1);
  if (kind == ITREE_BRANCH)
  {
    GtkTreePath* path = gtk_tree_model_get_path(model, iterItemDst);
    if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(ih->handle), path))
      position = 1;  
    else
    {
      int child_count = gtkTreeTotalChildCount(ih, iterItemDst);
      id_new += child_count;
    }
    gtk_tree_path_free(path);
  }
  if (!is_copy && id_new == id_src)
  {
    iterNewItem->stamp = 0;
    return;
  }
  gtkTreeCopyItem(ih, model, iterItemSrc, iterItemDst, position, iterNewItem);  
  gtkTreeCopyChildren(ih, model, iterItemSrc, iterNewItem);
  count = ih->data->node_count - old_count;
  iupTreeCopyMoveCache(ih, id_src, id_new, count, is_copy);
  if (!is_copy)
  {
    iupAttribSet(ih, "_IUPTREE_IGNORE_SELECTION_CB", "1");
    gtk_tree_store_remove(GTK_TREE_STORE(model), iterItemSrc);
    iupAttribSet(ih, "_IUPTREE_IGNORE_SELECTION_CB", NULL);
    ih->data->node_count = old_count;
    if (id_new > id_src)
      id_new -= count;
  }
  gtkTreeRebuildNodeCache(ih, id_new, *iterNewItem);
}
static void gtkTreeCopyMoveNode ( Ihandle * ih , GtkTreeModel * model , GtkTreeIter * iterItemSrc , GtkTreeIter * iterItemDst , GtkTreeIter * iterNewItem , int is_copy ) { int kind , position = 0 ; int id_new , count , id_src , id_dst ; int old_count = ih -> data -> node_count ; id_src = gtkTreeFindNodeId ( ih , iterItemSrc ) ; id_dst = gtkTreeFindNodeId ( ih , iterItemDst ) ; id_new = id_dst + 1 ; gtk_tree_model_get ( model , iterItemDst , IUPGTK_NODE_KIND , & kind , -1 ) ; if ( kind == ITREE_BRANCH ) { GtkTreePath * path = gtk_tree_model_get_path ( model , iterItemDst ) ; if ( gtk_tree_view_row_expanded ( GTK_TREE_VIEW ( ih -> handle ) , path ) ) position = 1 ; else { int child_count = gtkTreeTotalChildCount ( ih , iterItemDst ) ; id_new += child_count ; } gtk_tree_path_free ( path ) ; } if ( ! is_copy && id_new == id_src ) { iterNewItem -> stamp = 0 ; return ; } gtkTreeCopyItem ( ih , model , iterItemSrc , iterItemDst , position , iterNewItem ) ; gtkTreeCopyChildren ( ih , model , iterItemSrc , iterNewItem ) ; count = ih -> data -> node_count - old_count ; iupTreeCopyMoveCache ( ih , id_src , id_new , count , is_copy ) ; if ( ! is_copy ) { iupAttribSet ( ih , " " , " " ) ; gtk_tree_store_remove ( GTK_TREE_STORE ( model ) , iterItemSrc ) ; iupAttribSet ( ih , " " , NULL ) ; ih -> data -> node_count = old_count ; if ( id_new > id_src ) id_new -= count ; } gtkTreeRebuildNodeCache ( ih , id_new , * iterNewItem ) ; }
Copies all items in a branch to a new location.
Copies all items in a branch to a new location .
/* insert after iterItemDst */ /* contains the position for a copy operation */ /* insert as first child of iterItemDst */ /* move to the same place does nothing */ /* Deleting the node of its old position */ /* restore count, because we remove src */ /* compensate position for a move */