/* * add empty row */ static void add_empty_row(void) { GtkTreeIter empty; GtkTreePath *path; if (empty_row) gtk_tree_row_reference_free(empty_row); gtk_tree_store_prepend (store, &empty, NULL); gtk_tree_store_set (store, &empty, W_NAME, "", W_VALUE, "", W_TYPE, "", W_LAST_VISIBLE, "", W_INTERNAL, "", W_EXPRESSION, "", W_STUB, 0, W_CHANGED, 0, W_VT, VT_NONE, -1); /* save reference */ path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &empty); empty_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), path); gtk_tree_path_free(path); }
void tree_store_prepend(GtkWidget *w, GtkTreeIter *iter, GtkTreeIter *parent) { GtkTreeModel *model; model = gtk_tree_view_get_model(GTK_TREE_VIEW(w)); gtk_tree_store_prepend(GTK_TREE_STORE(model), iter, parent); }
/** * bmark_get_iter_at_tree_position: * * determine bookmark's location in the tree and insert - result GtkTreeIter is stored in m->iter */ static void bmark_get_iter_at_tree_position(Tbfwin * bfwin, Tbmark * m) { GtkTreeIter *parent; gpointer ptr; DEBUG_MSG("bmark_get_iter_at_tree_position, started for filepath=%s\n",m->filepath); if (!bfwin->bmark_files) { DEBUG_MSG("bmark_get_iter_at_tree_position, creating hashtable for bfwin=%p\n",bfwin); bfwin->bmark_files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); } ptr = g_hash_table_lookup(bfwin->bmark_files, m->filepath); if (ptr == NULL) { /* closed document or bookmarks never set */ gchar *title = NULL; parent = g_new0(GtkTreeIter, 1); gtk_tree_store_append(bfwin->bookmarkstore, parent, NULL); switch (main_v->props.bookmarks_filename_mode) { case BM_FMODE_FULL: g_strdup(m->filepath); break; case BM_FMODE_HOME: /* todo */ if (bfwin->project != NULL && bfwin->project->basedir && strlen(bfwin->project->basedir)) { gint baselen = strlen(bfwin->project->basedir); if (strncmp(m->filepath, bfwin->project->basedir, baselen)==0) { title = g_strdup(m->filepath + baselen); } } break; /* case BM_FMODE_FILE: title = g_path_get_basename(m->filepath); break;*/ } if (title == NULL) { title = g_path_get_basename(m->filepath); } gtk_tree_store_set(bfwin->bookmarkstore, parent, NAME_COLUMN, title, PTR_COLUMN, m->doc, -1); g_free (title); if (m->doc != NULL) { DEBUG_MSG("bmark_get_iter_at_tree_position, setting parent iter %p for doc%p\n",parent,m->doc); m->doc->bmark_parent = parent; } DEBUG_MSG("bmark_get_iter_at_tree_position, appending parent %p in hashtable for filepath=%s\n",parent, m->filepath); /* the hash table frees the key, but not the value, on destroy */ g_hash_table_insert(bfwin->bmark_files, g_strdup(m->filepath), parent); } else parent = (GtkTreeIter *) ptr; { Tbmark *bef = bmark_find_bookmark_before_offset(bfwin, m->offset, parent); if (bef == NULL) { gtk_tree_store_prepend(bfwin->bookmarkstore, &m->iter, parent); return; } else { gtk_tree_store_insert_after(GTK_TREE_STORE(bfwin->bookmarkstore),&m->iter,parent,&bef->iter); return; } } }
static void key_store_populate (CryptUIKeyStore *ckstore) { GList *keys, *l = NULL; if (!ckstore->priv->initialized) return; /* Clear the store and then add all the keys */ gtk_tree_store_clear (ckstore->priv->store); g_hash_table_foreach_remove (ckstore->priv->rows, hashtable_remove_all, NULL); /* Add the none option */ if (ckstore->priv->none_option) { GtkTreeIter iter; /* Second row is a separator */ gtk_tree_store_prepend (ckstore->priv->store, &iter, NULL); gtk_tree_store_set (ckstore->priv->store, &iter, CRYPTUI_KEY_STORE_NAME, NULL, CRYPTUI_KEY_STORE_SEPARATOR, TRUE, -1); /* The first row is the none option */ gtk_tree_store_prepend (ckstore->priv->store, &iter, NULL); gtk_tree_store_set (ckstore->priv->store, &iter, CRYPTUI_KEY_STORE_NAME, ckstore->priv->none_option, CRYPTUI_KEY_STORE_KEY, NULL, -1); } g_assert (CRYPTUI_IS_KEYSET (ckstore->ckset)); keys = cryptui_keyset_get_keys (ckstore->ckset); for (l = keys; l; l = g_list_next (l)) { g_assert (l->data != NULL); key_store_key_added (ckstore->ckset, l->data, ckstore); } g_list_free (keys); }
/* * add new breakpoint to the tree view * arguments: * bp - breakpoint to add */ void bptree_add_breakpoint(breakpoint* bp) { GtkTreeIter file_iter, iter, child, *sibling = NULL; GtkTreeRowReference *file_reference = (GtkTreeRowReference*)g_hash_table_lookup(files, bp->file); if (!file_reference) { GtkTreePath *file_path; gtk_tree_store_prepend (store, &file_iter, NULL); gtk_tree_store_set (store, &file_iter, FILEPATH, bp->file, ENABLED, TRUE, -1); file_path = gtk_tree_model_get_path(model, &file_iter); file_reference = gtk_tree_row_reference_new(model, file_path); gtk_tree_path_free(file_path); g_hash_table_insert(files, (gpointer)g_strdup(bp->file),(gpointer)file_reference); } else { GtkTreePath *path = gtk_tree_row_reference_get_path(file_reference); gtk_tree_model_get_iter(model, &file_iter, path); gtk_tree_path_free(path); } /* lookup where to insert new row */ if(gtk_tree_model_iter_children(model, &child, &file_iter)) { do { int line; gtk_tree_model_get ( model, &child, LINE, &line, -1); if (line > bp->line) { sibling = &child; break; } } while(gtk_tree_model_iter_next(model, &child)); } gtk_tree_store_insert_before(store, &iter, &file_iter, sibling); bp->iter = iter; bptree_update_breakpoint(bp); }
static GtkTreeModel * audit_build_model (GvaAuditData *data, GError **error) { GtkTreeModel *model; GtkTreeIter iter; gboolean iter_valid; model = gva_game_store_new_from_query (SQL_SELECT_BAD_GAMES, error); if (model == NULL) return NULL; iter_valid = gtk_tree_model_get_iter_first (model, &iter); while (iter_valid) { GtkTreeIter child; guint index; gchar *name; gtk_tree_model_get (model, &iter, 0, &name, -1); index = GPOINTER_TO_UINT (g_hash_table_lookup ( data->output_index, name)); while (index > 0) { const gchar *line; line = g_ptr_array_index (data->output, --index); if (!g_str_has_prefix (line, name)) break; gtk_tree_store_prepend ( GTK_TREE_STORE (model), &child, &iter); gtk_tree_store_set ( GTK_TREE_STORE (model), &child, GVA_GAME_STORE_COLUMN_DESCRIPTION, line, -1); } g_free (name); iter_valid = gtk_tree_model_iter_next (model, &iter); } gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (model), GVA_GAME_STORE_COLUMN_DESCRIPTION, GTK_SORT_ASCENDING); return model; }
static VALUE rg_prepend(VALUE self, VALUE parent) { VALUE ret; GtkTreeIter iter; GtkTreeStore* model = _SELF(self); gtk_tree_store_prepend(model, &iter, NIL_P(parent)?NULL:RVAL2GTKTREEITER(parent)); iter.user_data3 = model; ret = GTKTREEITER2RVAL(&iter); G_CHILD_ADD(self, ret); return ret; }
static void tree_store_prepend (GtkTreeModel *model, gint items, gint i) { GtkTreeStore *store = GTK_TREE_STORE (model); GtkTreeIter iter; gchar *text; text = g_strdup_printf ("row %d", i); gtk_tree_store_prepend (store, &iter, NULL); gtk_tree_store_set (store, &iter, 0, i, 1, text, -1); g_free (text); }
/* * add new thread to the tree view */ void stree_add_thread(int thread_id) { GtkTreeIter thread_iter, new_thread_iter; if (gtk_tree_model_get_iter_first(model, &thread_iter)) { GtkTreeIter *consecutive = NULL; do { int existing_thread_id; gtk_tree_model_get(model, &thread_iter, S_THREAD_ID, &existing_thread_id); if (existing_thread_id > thread_id) { consecutive = &thread_iter; break; } } while(gtk_tree_model_iter_next(model, &thread_iter)); if(consecutive) { gtk_tree_store_prepend(store, &new_thread_iter, consecutive); } else { gtk_tree_store_append(store, &new_thread_iter, NULL); } } else { gtk_tree_store_append (store, &new_thread_iter, NULL); } gchar *thread_label = g_strdup_printf(_("Thread %i"), thread_id); gtk_tree_store_set (store, &new_thread_iter, S_ADRESS, thread_label, S_THREAD_ID, thread_id, -1); g_free(thread_label); GtkTreePath *tpath = gtk_tree_model_get_path(model, &new_thread_iter); GtkTreeRowReference *reference = gtk_tree_row_reference_new(model, tpath); g_hash_table_insert(threads, (gpointer)(long)thread_id,(gpointer)reference); gtk_tree_path_free(tpath); }
static void item_list_view_add_item_to_tree_store (ItemListView *ilv, GtkTreeStore *itemstore, itemPtr item) { gint state = 0; nodePtr node; GtkTreeIter *iter; GtkTreeIter old_iter; gboolean exists; if (item->flagStatus) state += 2; if (!item->readStatus) state += 1; node = node_from_id (item->nodeId); if(!node) return; /* comment items do cause this... maybe filtering them earlier would be a good idea... */ exists = item_list_view_id_to_iter (ilv, item->id, &old_iter); iter = &old_iter; if (!exists) { iter = g_new0 (GtkTreeIter, 1); gtk_tree_store_prepend (itemstore, iter, NULL); g_hash_table_insert (ilv->priv->item_id_to_iter, GUINT_TO_POINTER (item->id), (gpointer)iter); } gtk_tree_store_set (itemstore, iter, IS_TIME, (guint64)item->time, IS_NR, item->id, IS_PARENT, node, IS_FAVICON, node->icon, IS_ENCICON, item->hasEnclosure?icon_get (ICON_ENCLOSURE):NULL, IS_ENCLOSURE, item->hasEnclosure, IS_SOURCE, node, IS_STATE, state, -1); }
int clip_GTK_TREESTOREPREPEND(ClipMachine * ClipMachineMemory) { C_object *cstree = _fetch_co_arg(ClipMachineMemory); gchar *parent = _clip_parc(ClipMachineMemory, 2); GtkTreeIter iter; GtkTreeIter parentiter; GtkTreePath *path; gchar *path_string; CHECKCOBJ(cstree, GTK_IS_TREE_STORE(cstree->object)); CHECKOPT(2, CHARACTER_type_of_ClipVarType); if (parent) gtk_tree_model_get_iter(GTK_TREE_MODEL(GTK_TREE_STORE(cstree->object)), &parentiter, gtk_tree_path_new_from_string(parent)); gtk_tree_store_prepend(GTK_TREE_STORE(cstree->object), &iter, (parent ? &parentiter : NULL)); __tree_store_set(ClipMachineMemory, &iter, 3); path = gtk_tree_model_get_path(GTK_TREE_MODEL(GTK_TREE_STORE(cstree->object)), &iter); path_string = gtk_tree_path_to_string(path); _clip_retc(ClipMachineMemory, path_string); g_free(path_string); return 0; err: return 1; }
static gboolean dispose_item_in_model (GtkTreeModel *model, const gchar *item_id, GDateTime *date, GtkTreeIter *iter) { gint index; gint diff; gboolean found; gchar *date_str; gchar *test_id; GDateTime *test_date; GtkTreeStore *tstore; GtkTreeIter parent; found = FALSE; index = 0; tstore = GTK_TREE_STORE (model); if (gtk_tree_model_get_iter_first (model, &parent) == TRUE) { do { gtk_tree_model_get (model, &parent, ITEM_COLUMN_TIME, &test_date, -1); diff = date_time_day_difference (date, test_date); if (diff > 0) { break; } else if (diff == 0) { found = TRUE; break; } index++; } while (gtk_tree_model_iter_next (model, &parent)); } if (found == FALSE) { date_str = g_date_time_format (date, "%x"); gtk_tree_store_insert (tstore, &parent, NULL, index); gtk_tree_store_set (tstore, &parent, ITEM_COLUMN_TITLE, date_str, ITEM_COLUMN_TIME, date, ITEM_COLUMN_READ, TITLE_FONT_WEIGHT, ITEM_COLUMN_BG, "gray", -1); gtk_tree_store_prepend (tstore, iter, &parent); g_free (date_str); } else { found = FALSE; if (gtk_tree_model_iter_children (model, iter, &parent) == TRUE) { do { gtk_tree_model_get (model, iter, ITEM_COLUMN_ID, &test_id, -1); if (strcmp (test_id, item_id) == 0) { found = TRUE; break; } g_free (test_id); } while (gtk_tree_model_iter_next (model, iter)); } if (found == FALSE) gtk_tree_store_prepend (tstore, iter, &parent); } return !found; }
static gboolean audit_build_model (GtkTreeStore *tree_store, GvaAuditData *data, GError **error) { GtkTreeModel *game_store; GtkTreeIter iter; gboolean iter_valid; game_store = gva_game_store_new_from_query ( SQL_SELECT_BAD_GAMES, error); if (game_store == NULL) return FALSE; gtk_tree_store_clear (tree_store); iter_valid = gtk_tree_model_get_iter_first (game_store, &iter); while (iter_valid) { GtkTreeIter parent; GtkTreeIter child; guint index; gchar *name; gchar *description; gtk_tree_model_get ( game_store, &iter, GVA_GAME_STORE_COLUMN_NAME, &name, GVA_GAME_STORE_COLUMN_DESCRIPTION, &description, -1); gtk_tree_store_append (tree_store, &parent, NULL); gtk_tree_store_set (tree_store, &parent, 0, description, -1); index = GPOINTER_TO_UINT (g_hash_table_lookup ( data->output_index, name)); while (index > 0) { const gchar *line; line = g_ptr_array_index (data->output, --index); if (!g_str_has_prefix (line, name)) break; gtk_tree_store_prepend (tree_store, &child, &parent); gtk_tree_store_set (tree_store, &child, 0, line, -1); } g_free (name); g_free (description); iter_valid = gtk_tree_model_iter_next (game_store, &iter); } gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (tree_store), 0, GTK_SORT_ASCENDING); g_object_unref (game_store); return TRUE; }
/* Test for GNOME bugzilla bug 359231 */ static void test_bug359231 (void) { int i; int height1, height2; GtkTreePath *path; GtkTreeIter iter, child; GtkTreeStore *store; GdkRectangle rect; ScrollFixture *fixture; /* See #359231. */ g_test_bug ("359231"); /* Create model (GtkTreeStore in this case) */ store = gtk_tree_store_new (1, G_TYPE_STRING); gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter, 0, "Foo", -1); for (i = 0; i < 4; i++) { gtk_tree_store_append (store, &child, &iter); gtk_tree_store_set (store, &child, 0, "Two\nLines", -1); } fixture = g_new0 (ScrollFixture, 1); scroll_fixture_setup (fixture, GTK_TREE_MODEL (store), NULL); gtk_widget_show_all (fixture->window); while (gtk_events_pending ()) gtk_main_iteration (); /* Prepend some rows at the top, expand */ gtk_tree_store_prepend (store, &iter, NULL); gtk_tree_store_set (store, &iter, 0, "Foo", -1); gtk_tree_store_prepend (store, &child, &iter); gtk_tree_store_set (store, &child, 0, "Two\nLines", -1); gtk_tree_view_expand_all (GTK_TREE_VIEW (fixture->tree_view)); while (gtk_events_pending ()) gtk_main_iteration (); /* Test if height of row 0:0 is correct */ path = gtk_tree_path_new_from_indices (0, -1); gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view), path, NULL, &rect); height1 = rect.height; gtk_tree_path_down (path); gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view), path, NULL, &rect); height2 = rect.height; gtk_tree_path_free (path); g_assert (height2 > height1); /* Clean up; the tear down also cleans up the model */ scroll_fixture_teardown (fixture, NULL); }
static void treestore_torture_recurse (GtkTreeStore *store, GtkTreeIter *root, gint depth) { GtkTreeModel *model; gint i; GtkTreeIter iter; model = GTK_TREE_MODEL (store); if (depth > 2) return; ++depth; gtk_tree_store_append (store, &iter, root); gtk_tree_model_iter_children (model, &iter, root); i = 0; while (i < 100) { gtk_tree_store_append (store, &iter, root); ++i; } while (gtk_tree_model_iter_children (model, &iter, root)) gtk_tree_store_remove (store, &iter); gtk_tree_store_append (store, &iter, root); /* inserts before last node in tree */ i = 0; while (i < 100) { gtk_tree_store_insert_before (store, &iter, root, &iter); ++i; } /* inserts after the node before the last node */ i = 0; while (i < 100) { gtk_tree_store_insert_after (store, &iter, root, &iter); ++i; } /* inserts after the last node */ gtk_tree_store_append (store, &iter, root); i = 0; while (i < 100) { gtk_tree_store_insert_after (store, &iter, root, &iter); ++i; } /* remove everything again */ while (gtk_tree_model_iter_children (model, &iter, root)) gtk_tree_store_remove (store, &iter); /* Prepends */ gtk_tree_store_prepend (store, &iter, root); i = 0; while (i < 100) { gtk_tree_store_prepend (store, &iter, root); ++i; } /* remove everything again */ while (gtk_tree_model_iter_children (model, &iter, root)) gtk_tree_store_remove (store, &iter); gtk_tree_store_append (store, &iter, root); gtk_tree_store_append (store, &iter, root); gtk_tree_store_append (store, &iter, root); gtk_tree_store_append (store, &iter, root); while (gtk_tree_model_iter_children (model, &iter, root)) { treestore_torture_recurse (store, &iter, depth); gtk_tree_store_remove (store, &iter); } }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *vbox; GtkWidget *scrolled_window; GtkWidget *tree_view; GtkTreeStore *model; GtkTreeModel *smodel = NULL; GtkTreeModel *ssmodel = NULL; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeIter iter; gint i; GtkWidget *entry, *button; GtkWidget *window2, *vbox2, *scrolled_window2, *tree_view2; GtkWidget *window3, *vbox3, *scrolled_window3, *tree_view3; gtk_init (&argc, &argv); /** * First window - Just a GtkTreeStore */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Words, words, words - Window 1"); g_signal_connect (window, "destroy", gtk_main_quit, NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Jonathan and Kristian's list of cool words. (And Anders' cool list of numbers) \n\nThis is just a GtkTreeStore"), FALSE, FALSE); gtk_container_add (GTK_CONTAINER (window), vbox); entry = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE); button = gtk_button_new_with_label ("Switch search method"); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE); model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); /* smodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model)); ssmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (smodel)); */ tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_ENTRY (entry)); g_object_set_data (G_OBJECT (tree_view), "my-search-entry", entry); g_signal_connect (button, "clicked", G_CALLBACK (switch_search_method), tree_view); /* gtk_tree_selection_set_select_function (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), select_func, NULL, NULL);*/ /* 12 iters now, 12 later... */ for (i = 0; data[i].word_1 != NULL; i++) { gint k; GtkTreeIter child_iter; gtk_tree_store_prepend (GTK_TREE_STORE (model), &iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (model), &iter, WORD_COLUMN_1, data[i].word_1, WORD_COLUMN_2, data[i].word_2, WORD_COLUMN_3, data[i].word_3, WORD_COLUMN_4, data[i].word_4, NUMBER_COLUMN_1, data[i].number_1, -1); gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter); gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter, WORD_COLUMN_1, data[i].word_1, WORD_COLUMN_2, data[i].word_2, WORD_COLUMN_3, data[i].word_3, WORD_COLUMN_4, data[i].word_4, NUMBER_COLUMN_1, data[i].number_1, -1); for (k = 0; childdata[k].word_1 != NULL; k++) { gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter); gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter, WORD_COLUMN_1, childdata[k].word_1, WORD_COLUMN_2, childdata[k].word_2, WORD_COLUMN_3, childdata[k].word_3, WORD_COLUMN_4, childdata[k].word_4, NUMBER_COLUMN_1, childdata[k].number_1, -1); } } smodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model)); ssmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (smodel)); g_object_unref (model); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("First Word", renderer, "text", WORD_COLUMN_1, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer, "text", WORD_COLUMN_2, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer, "text", WORD_COLUMN_3, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer, "text", WORD_COLUMN_4, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("First Number", renderer, "text", NUMBER_COLUMN_1, NULL); gtk_tree_view_column_set_sort_column_id (column, NUMBER_COLUMN_1); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); /* gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (smodel), WORD_COLUMN_1, GTK_SORT_ASCENDING);*/ gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view); gtk_window_set_default_size (GTK_WINDOW (window), 400, 400); gtk_widget_show_all (window); /** * Second window - GtkTreeModelSort wrapping the GtkTreeStore */ if (smodel) { window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window2), "Words, words, words - window 2"); g_signal_connect (window2, "destroy", gtk_main_quit, NULL); vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); gtk_box_pack_start (GTK_BOX (vbox2), gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeStore of window 1"), FALSE, FALSE); gtk_container_add (GTK_CONTAINER (window2), vbox2); scrolled_window2 = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window2), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (vbox2), scrolled_window2, TRUE, TRUE); tree_view2 = gtk_tree_view_new_with_model (smodel); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("First Word", renderer, "text", WORD_COLUMN_1, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer, "text", WORD_COLUMN_2, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer, "text", WORD_COLUMN_3, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer, "text", WORD_COLUMN_4, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column); /* gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (smodel), (GtkTreeIterCompareFunc)gtk_tree_data_list_compare_func, NULL, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (smodel), WORD_COLUMN_1, GTK_SORT_DESCENDING);*/ gtk_container_add (GTK_CONTAINER (scrolled_window2), tree_view2); gtk_window_set_default_size (GTK_WINDOW (window2), 400, 400); gtk_widget_show_all (window2); } /** * Third window - GtkTreeModelSort wrapping the GtkTreeModelSort which * is wrapping the GtkTreeStore. */ if (ssmodel) { window3 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window3), "Words, words, words - Window 3"); g_signal_connect (window3, "destroy", gtk_main_quit, NULL); vbox3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); gtk_box_pack_start (GTK_BOX (vbox3), gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeModelSort of window 2"), FALSE, FALSE); gtk_container_add (GTK_CONTAINER (window3), vbox3); scrolled_window3 = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window3), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window3), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (vbox3), scrolled_window3, TRUE, TRUE); tree_view3 = gtk_tree_view_new_with_model (ssmodel); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("First Word", renderer, "text", WORD_COLUMN_1, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer, "text", WORD_COLUMN_2, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer, "text", WORD_COLUMN_3, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer, "text", WORD_COLUMN_4, NULL); gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column); /* gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (ssmodel), (GtkTreeIterCompareFunc)gtk_tree_data_list_compare_func, NULL, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (ssmodel), WORD_COLUMN_1, GTK_SORT_ASCENDING);*/ gtk_container_add (GTK_CONTAINER (scrolled_window3), tree_view3); gtk_window_set_default_size (GTK_WINDOW (window3), 400, 400); gtk_widget_show_all (window3); } for (i = 0; data[i].word_1 != NULL; i++) { gint k; gtk_tree_store_prepend (GTK_TREE_STORE (model), &iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (model), &iter, WORD_COLUMN_1, data[i].word_1, WORD_COLUMN_2, data[i].word_2, WORD_COLUMN_3, data[i].word_3, WORD_COLUMN_4, data[i].word_4, -1); for (k = 0; childdata[k].word_1 != NULL; k++) { GtkTreeIter child_iter; gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter); gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter, WORD_COLUMN_1, childdata[k].word_1, WORD_COLUMN_2, childdata[k].word_2, WORD_COLUMN_3, childdata[k].word_3, WORD_COLUMN_4, childdata[k].word_4, -1); } } gtk_main (); return 0; }
// Create a new bus from the current selection static void create_bus_button_clicked (GtkWidget *widget, gpointer data) { int row_type = -1 ; bus_layout_D *dialog = (bus_layout_D *)data ; GList *llTreeRefs = NULL, *llItr = NULL ; GtkTreeStore *ts = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tview))) ; GtkTreeIter itrBus, itr, itrSrc, itrSrcParent ; GtkTreeRowReference *refBus = NULL, *refSrcParent = NULL ; GtkTreePath *tp = NULL, *tpSrcParent = NULL ; llTreeRefs = get_selected_refs (gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->tview))) ; if (NULL == llTreeRefs) return ; if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itr, tp = gtk_tree_row_reference_get_path (llTreeRefs->data))) { gtk_tree_path_free (tp) ; return ; } gtk_tree_model_get (GTK_TREE_MODEL (ts), &itr, BUS_LAYOUT_MODEL_COLUMN_TYPE, &row_type, -1) ; gtk_tree_path_free (tp) ; gtk_tree_store_prepend (ts, &itrBus, NULL) ; gtk_tree_store_set (ts, &itrBus, BUS_LAYOUT_MODEL_COLUMN_ICON, (row_type & ROW_TYPE_INPUT) ? QCAD_STOCK_BUS_INPUT : QCAD_STOCK_BUS_OUTPUT, BUS_LAYOUT_MODEL_COLUMN_NAME, _("Untitled Bus"), BUS_LAYOUT_MODEL_COLUMN_TYPE, (row_type & ROW_TYPE_INPUT) ? ROW_TYPE_BUS_INPUT : ROW_TYPE_BUS_OUTPUT, BUS_LAYOUT_MODEL_COLUMN_INDEX, -1, -1) ; refBus = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &itrBus)) ; gtk_tree_path_free (tp) ; for (llItr = g_list_last (llTreeRefs) ; llItr != NULL ; llItr = llItr->prev) { if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrBus, tp = gtk_tree_row_reference_get_path (refBus))) { gtk_tree_path_free (tp) ; gtk_tree_store_append (ts, &itr, &itrBus) ; if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrSrc, tp = gtk_tree_row_reference_get_path (llItr->data))) swap_model_iters_contents (GTK_TREE_MODEL (ts), &itrSrc, &itr) ; gtk_tree_path_free (tp) ; if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrSrc, tp = gtk_tree_row_reference_get_path (llItr->data))) { if (gtk_tree_path_get_depth (tp) > 1) { if (gtk_tree_path_up (tpSrcParent = gtk_tree_path_copy (tp))) refSrcParent = (1 == gtk_tree_model_path_n_children (GTK_TREE_MODEL (ts), tpSrcParent)) ? gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tpSrcParent) : NULL ; gtk_tree_path_free (tpSrcParent) ; } } gtk_tree_path_free (tp) ; gtk_tree_row_reference_free (llItr->data) ; // Remove cell from old location gtk_tree_store_remove (ts, &itrSrc) ; // The bus that owned the row we just moved has become empty - delete it if (NULL != refSrcParent) { tpSrcParent = gtk_tree_row_reference_get_path (refSrcParent) ; if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrSrcParent, tpSrcParent)) gtk_tree_store_remove (ts, &itrSrcParent) ; gtk_tree_path_free (tpSrcParent) ; gtk_tree_row_reference_free (refSrcParent) ; refSrcParent = NULL ; } } else gtk_tree_path_free (tp) ; } gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->tview)), tp = gtk_tree_row_reference_get_path (refBus)) ; gtk_tree_path_free (tp) ; gtk_tree_row_reference_free (refBus) ; g_list_free (llTreeRefs) ; }