/**** TREE ITEM constructor ****/ int clip_GTK_TREEITEMNEW(ClipMachine * ClipMachineMemory) { ClipVar *cv = _clip_spar(ClipMachineMemory, 1); char *label = _clip_parc(ClipMachineMemory, 2); GtkWidget *wid = NULL; C_widget *cwid; CHECKOPT(1, MAP_type_of_ClipVarType); CHECKOPT(2, CHARACTER_type_of_ClipVarType); if (_clip_parinfo(ClipMachineMemory, 2) == CHARACTER_type_of_ClipVarType) { LOCALE_TO_UTF(label); wid = gtk_tree_item_new_with_label(label); FREE_TEXT(label); } else wid = gtk_tree_item_new(); if (!wid) goto err; cwid = _register_widget(ClipMachineMemory, wid, cv); _clip_mclone(ClipMachineMemory, RETPTR(ClipMachineMemory), &cwid->obj); return 0; err: return 1; }
GtkWidget * create_subtree(action *a_node, int n) { int i; GtkWidget *new_subtree; char *str; new_subtree = gtk_tree_new(); for (i = 0; i < a_node->count; i++){ GtkWidget *item, *sub_subtree; GtkWidget *box; if (!xmlStrcmp (a_node->action[i]->name, (const xmlChar *) "action")) { item = gtk_tree_item_new(); str = (char *) malloc (sizeof(char) * (2+ strlen (xmlGetProp (a_node->action[i], "name")))); strcpy (str, (xmlGetProp (a_node->action[i], "name"))); box = setpixmap (str, a_node->action[i]); gtk_container_add (GTK_CONTAINER (item), box); gtk_tree_append (GTK_TREE(new_subtree), item); free (str); str = NULL; linklist[n][counting_action-1].next = a_node->action[i]; linklist[n][counting_action].cur = a_node->action[i]; linklist[n][counting_action].item = item; linklist[n][counting_action+1].prev = a_node->action[i]; counting_action++; } else if ( xmlStrcmp (a_node->action[i]->name, (const xmlChar *) "action")) { item = gtk_tree_item_new(); str = (char *) malloc (sizeof(char) * (2 +strlen(a_node->action[i]->name))); strcpy (str, a_node->action[i]->name); box = setpixmap (str, a_node->action[i]); gtk_container_add (GTK_CONTAINER (item), box); free (str); str = NULL; gtk_tree_append (GTK_TREE(new_subtree), item); sub_subtree = create_subtree(a_node->iterptr, n); gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), sub_subtree); gtk_tree_item_expand (GTK_TREE_ITEM (item)); gtk_widget_show (sub_subtree); } gtk_signal_connect (GTK_OBJECT(item), "select", GTK_SIGNAL_FUNC(tree_select), a_node->action[i]); gtk_signal_connect (GTK_OBJECT(item), "deselect", GTK_SIGNAL_FUNC(tree_deselect), NULL); gtk_signal_connect (GTK_OBJECT(item), "toggle", GTK_SIGNAL_FUNC(tree_toggle), NULL); gtk_signal_connect (GTK_OBJECT(item), "expand", GTK_SIGNAL_FUNC(tree_expand),NULL); gtk_signal_connect (GTK_OBJECT(item), "collapse", GTK_SIGNAL_FUNC(tree_collapse), NULL); gtk_widget_show (item); } return new_subtree; }
/*** sfeBuildTreeItemWithImage - create a new treeview item which contains *** the appropriate image for the given node type as well as a label with *** the node's name. ***/ GtkWidget* sfeBuildTreeItemWithImage(pStructInf data_item) { GtkWidget *hbox, *label, *pixmap, *treeitem, *hiddenlabel; int i, n_icons, found; GtkStyle *style; gchar hiddenlabel_text[32]; /** Figure out which pixmap file to use. **/ found = SFE_DEFAULT_ICON; n_icons = sizeof(icon_table) / sizeof(icon_table[0]); for (i=0;i<n_icons;i++) if (!strcasecmp(data_item->UsrType, icon_table[i].Type)) found = i; /** build the gdk pixmap structure if needed **/ if (!icon_table[found].Pixmap) { style = gtk_widget_get_style(SFE_Globals.TreeView); icon_table[found].Pixmap = gdk_pixmap_create_from_xpm_d(SFE_Globals.Window->window, &(icon_table[found].Mask), &style->bg[GTK_STATE_NORMAL], (gchar**) icon_table[found].XPM); } /** Create the hbox, label, and pixmap **/ hbox = gtk_hbox_new(FALSE,1); pixmap = gtk_pixmap_new(icon_table[found].Pixmap, icon_table[found].Mask); gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 0); gtk_widget_show(pixmap); label = gtk_label_new(data_item->Name); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_widget_show(label); gtk_widget_show(hbox); /** We need a hidden label to reference the structure **/ snprintf(hiddenlabel_text, 32, "%16.16lx", (unsigned long)(data_item)); hiddenlabel = gtk_label_new(hiddenlabel_text); gtk_box_pack_start(GTK_BOX(hbox), hiddenlabel, FALSE, FALSE, 0); /** Create the tree item and plop the hbox in it **/ treeitem = gtk_tree_item_new(); gtk_container_add(GTK_CONTAINER(treeitem), hbox); return treeitem; }
GtkWidget * create_task_tree(int n) { int i; /*n=Process #*/ char *strr; char *str; counting_action = 0; GtkWidget *tree, *subtree; GtkWidget *treename; GtkWidget *box; tree = gtk_tree_new(); strr = (char *) malloc (sizeof(char) * (strlen(xmlGetProp (table[n].process, "model"))) + strlen (" Pid: ")+ strlen (xmlGetProp(table[n].process, "pid")) + 256); strcat (strcat (strcpy (strr, xmlGetProp (table[n].process, "model")), " Pid: "), xmlGetProp(table[n].process, "pid")); treename = gtk_tree_item_new(); box = setpixmap (strr, NULL); gtk_container_add (GTK_CONTAINER (treename), box); gtk_tree_append (GTK_TREE (tree), treename); free (strr); strr = NULL; subtree = gtk_tree_new(); gtk_tree_item_set_subtree(GTK_TREE_ITEM(treename), subtree); gtk_tree_item_expand (GTK_TREE_ITEM(treename)); linklist[n][counting_action].prev = NULL; for (i = 0; i < table[n].list.count; i++) { GtkWidget *item, *itersubtree; GtkWidget *box; if (!xmlStrcmp ((table[n].list.action[i])->name, (const xmlChar *) "action")) { item = gtk_tree_item_new(); str = (char *) malloc (sizeof(char) * (2+ strlen (xmlGetProp (table[n].list.action[i], "name")))); strcpy (str, xmlGetProp (table[n].list.action[i], "name")); box = setpixmap (str, table[n].list.action[i]); gtk_container_add (GTK_CONTAINER (item), box); gtk_tree_append (GTK_TREE(subtree), item); free (str); str = NULL; linklist[n][counting_action-1].next = table[n].list.action[i]; linklist[n][counting_action].cur = table[n].list.action[i]; linklist[n][counting_action].item = item; linklist[n][counting_action+1].prev = table[n].list.action[i]; counting_action++; } else if ( xmlStrcmp (table[n].list.action[i]->name, (const xmlChar *) "action")) { str = (char *) malloc (sizeof(char) * (2 +strlen(table[n].list.action[i]->name))); item = gtk_tree_item_new(); strcpy (str, table[n].list.action[i]->name); box = setpixmap (str, table[n].list.action[i]); gtk_container_add (GTK_CONTAINER (item), box); free (str); str = NULL; itersubtree = create_subtree(table[n].list.iterptr, n); gtk_tree_append (GTK_TREE(subtree), item); gtk_tree_set_view_mode (GTK_TREE (itersubtree), GTK_TREE_VIEW_LINE); gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), itersubtree); gtk_tree_item_expand (GTK_TREE_ITEM(item)); gtk_widget_show(itersubtree); } gtk_signal_connect (GTK_OBJECT(item), "select", GTK_SIGNAL_FUNC(tree_select), table[n].list.action[i]); gtk_signal_connect (GTK_OBJECT(item), "deselect", GTK_SIGNAL_FUNC(tree_deselect), NULL); gtk_signal_connect (GTK_OBJECT(item), "toggle", GTK_SIGNAL_FUNC(tree_toggle), NULL); gtk_signal_connect (GTK_OBJECT(item), "expand", GTK_SIGNAL_FUNC(tree_expand), NULL); gtk_signal_connect (GTK_OBJECT(item), "collapse", GTK_SIGNAL_FUNC(tree_collapse), NULL); gtk_widget_show (item); } linklist[n][counting_action-1].next = NULL; gtk_widget_show(subtree); gtk_widget_show(treename); gtk_widget_show(tree); return tree; }