#include <gobject/gvaluecollector.h>
#define G_SLIST(x) ((GSList *) x)
+#define GTK_LIST_STORE_IS_SORTED(list) (GTK_LIST_STORE (list)->sort_column_id != -1)
static void gtk_list_store_init (GtkListStore *list_store);
static void gtk_list_store_class_init (GtkListStoreClass *class);
GtkTreePath *dest_path);
/* sortable */
+static void gtk_list_store_sort (GtkListStore *list_store);
+static void gtk_list_store_sort_iter_changed (GtkListStore *list_store,
+ GtkTreeIter *iter);
static gboolean gtk_list_store_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkTreeSortOrder *order);
+
static void
validate_list_store (GtkListStore *list_store)
{
if (gtk_debug_flags & GTK_DEBUG_TREE)
{
g_assert (g_slist_length (list_store->root) == list_store->length);
-
+
g_assert (g_slist_last (list_store->root) == list_store->tail);
}
}
* i.e. all cells in a column have the same type such as #G_TYPE_STRING or
* #GDK_TYPE_PIXBUF. Use #GtkListStore to store data to be displayed in a
* #GtkTreeView.
- *
+ *
* Return value: a new #GtkListStore
**/
GtkListStore *
* simultaneously setting up the columns and column types as with
* gtk_list_store_set_n_columns() and
* gtk_list_store_set_column_type().
- *
- *
+ *
+ *
* Return value: a new #GtkListStore
**/
GtkListStore *
* @n_columns: number of columns
*
* Sets the number of columns in the #GtkListStore.
- *
+ *
**/
void
gtk_list_store_set_n_columns (GtkListStore *list_store,
* %G_TYPE_CHAR, %G_TYPE_BOOLEAN, %G_TYPE_POINTER, %G_TYPE_FLOAT,
* %G_TYPE_DOUBLE, %G_TYPE_STRING, %G_TYPE_OBJECT, and %G_TYPE_BOXED, along with
* subclasses of those types such as %GDK_TYPE_PIXBUF.
- *
+ *
**/
void
gtk_list_store_set_column_type (GtkListStore *list_store,
{
GSList *list;
gint i;
-
+
g_return_val_if_fail (GTK_IS_LIST_STORE (tree_model), FALSE);
- g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
+ g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
i = gtk_tree_path_get_indices (path)[0];
if (i >= GTK_LIST_STORE (tree_model)->length)
return FALSE;
-
+
list = g_slist_nth (G_SLIST (GTK_LIST_STORE (tree_model)->root),
i);
/* If this fails, list_store->length has gotten mangled. */
g_assert (list);
-
+
iter->stamp = GTK_LIST_STORE (tree_model)->stamp;
iter->user_data = list;
return TRUE;
/* but if parent == NULL we return the list itself as children of the
* "root"
*/
-
+
if (GTK_LIST_STORE (tree_model)->root)
{
iter->stamp = GTK_LIST_STORE (tree_model)->stamp;
gint n)
{
GSList *child;
-
+
g_return_val_if_fail (GTK_IS_LIST_STORE (tree_model), FALSE);
if (parent)
* Sets the data in the cell specified by @iter and @column.
* The type of @value must be convertible to the type of the
* column.
- *
+ *
**/
void
gtk_list_store_set_value (GtkListStore *list_store,
gtk_tree_path_free (path);
if (converted)
g_value_unset (&real_value);
+
+ if (GTK_LIST_STORE_IS_SORTED (list_store))
+ gtk_list_store_sort_iter_changed (list_store, iter);
}
/**
*
* See gtk_list_store_set(); this version takes a va_list for
* use by language bindings.
- *
+ *
**/
void
gtk_list_store_set_valist (GtkListStore *list_store,
* @list_store: a #GtkListStore
* @iter: row iterator
* @Varargs: pairs of column number and value, terminated with -1
- *
+ *
* Sets the value of one or more cells in the row referenced by @iter.
* The variable argument list should contain integer column numbers,
* each column number followed by the value to be set.
}
*prevp = prev;
-
+
return list;
}
{
GSList *prev = NULL;
-
+
list_store->root = remove_link_saving_prev (G_SLIST (list_store->root),
G_SLIST (iter->user_data),
&prev);
list_store->length -= 1;
-
+
if (iter->user_data == list_store->tail)
list_store->tail = prev;
}
-
+
list_store->stamp ++;
}
*
* Removes the given row from the list store, emitting the
* "deleted" signal on #GtkTreeModel.
- *
+ *
**/
void
gtk_list_store_remove (GtkListStore *list_store,
g_return_if_fail (list_store != NULL);
g_return_if_fail (GTK_IS_LIST_STORE (list_store));
- g_return_if_fail (iter->user_data != NULL);
+ g_return_if_fail (iter->user_data != NULL);
path = gtk_list_store_get_path (GTK_TREE_MODEL (list_store), iter);
validate_list_store (list_store);
-
+
gtk_list_store_remove_silently (list_store, iter, path);
- validate_list_store (list_store);
+ validate_list_store (list_store);
gtk_tree_model_deleted (GTK_TREE_MODEL (list_store), path);
{
g_return_if_fail (sibling != NULL);
g_return_if_fail (new_list != NULL);
-
+
/* insert new node after list */
new_list->next = sibling->next;
sibling->next = new_list;
* Creates a new row at @position, initializing @iter to point to the
* new row, and emitting the "inserted" signal from the #GtkTreeModel
* interface.
- *
+ *
**/
void
gtk_list_store_insert (GtkListStore *list_store,
GSList *list;
GtkTreePath *path;
GSList *new_list;
-
+
g_return_if_fail (list_store != NULL);
g_return_if_fail (GTK_IS_LIST_STORE (list_store));
g_return_if_fail (iter != NULL);
g_return_if_fail (position >= 0);
- if (position == 0)
+ if (position == 0 ||
+ GTK_LIST_STORE_IS_SORTED (list_store))
{
gtk_list_store_prepend (list_store, iter);
return;
}
insert_after (list_store, list, new_list);
-
+
iter->stamp = list_store->stamp;
iter->user_data = new_list;
validate_list_store (list_store);
-
+
path = gtk_tree_path_new ();
gtk_tree_path_append_index (path, position);
gtk_tree_model_inserted (GTK_TREE_MODEL (list_store), path, iter);
* Inserts a new row before @sibling, initializing @iter to point to
* the new row, and emitting the "inserted" signal from the
* #GtkTreeModel interface.
- *
+ *
**/
void
gtk_list_store_insert_before (GtkListStore *list_store,
g_return_if_fail (GTK_IS_LIST_STORE (list_store));
g_return_if_fail (iter != NULL);
+ if (GTK_LIST_STORE_IS_SORTED (list_store))
+ {
+ gtk_list_store_prepend (list_store, iter);
+ return;
+ }
+
if (sibling == NULL)
{
gtk_list_store_append (list_store, iter);
return;
}
-
+
new_list = g_slist_alloc ();
prev = NULL;
if (list_store->root == NULL)
list_store->tail = new_list;
-
+
if (prev)
{
new_list->next = prev->next;
list_store->length += 1;
validate_list_store (list_store);
-
+
path = gtk_tree_path_new ();
gtk_tree_path_append_index (path, i);
gtk_tree_model_inserted (GTK_TREE_MODEL (list_store), path, iter);
* Inserts a new row after @sibling, initializing @iter to point to
* the new row, and emitting the "inserted" signal from the
* #GtkTreeModel interface.
- *
+ *
**/
void
gtk_list_store_insert_after (GtkListStore *list_store,
if (sibling)
g_return_if_fail (sibling->stamp == list_store->stamp);
- if (sibling == NULL)
+ if (sibling == NULL ||
+ GTK_LIST_STORE_IS_SORTED (list_store))
{
gtk_list_store_prepend (list_store, iter);
return;
new_list = g_slist_alloc ();
insert_after (list_store, list, new_list);
-
+
iter->stamp = list_store->stamp;
iter->user_data = new_list;
validate_list_store (list_store);
-
+
path = gtk_tree_path_new ();
gtk_tree_path_append_index (path, i);
gtk_tree_model_inserted (GTK_TREE_MODEL (list_store), path, iter);
* Prepends a row to @store, initializing @iter to point to the
* new row, and emitting the "inserted" signal on the #GtkTreeModel
* interface for the @store.
- *
+ *
**/
void
gtk_list_store_prepend (GtkListStore *list_store,
if (list_store->root == NULL)
list_store->tail = iter->user_data;
-
+
G_SLIST (iter->user_data)->next = G_SLIST (list_store->root);
list_store->root = iter->user_data;
list_store->length += 1;
validate_list_store (list_store);
-
+
path = gtk_tree_path_new ();
gtk_tree_path_append_index (path, 0);
gtk_tree_model_inserted (GTK_TREE_MODEL (list_store), path, iter);
* Appends a row to @store, initializing @iter to point to the
* new row, and emitting the "inserted" signal on the #GtkTreeModel
* interface for the @store.
- *
+ *
**/
void
gtk_list_store_append (GtkListStore *list_store,
g_return_if_fail (GTK_IS_LIST_STORE (list_store));
g_return_if_fail (iter != NULL);
+ if (GTK_LIST_STORE_IS_SORTED (list_store))
+ {
+ gtk_list_store_prepend (list_store, iter);
+ return;
+ }
+
iter->stamp = list_store->stamp;
iter->user_data = g_slist_alloc ();
list_store->length += 1;
validate_list_store (list_store);
-
+
path = gtk_tree_path_new ();
gtk_tree_path_append_index (path, list_store->length - 1);
gtk_tree_model_inserted (GTK_TREE_MODEL (list_store), path, iter);
{
GtkTreeIter iter;
g_return_val_if_fail (GTK_IS_LIST_STORE (drag_source), FALSE);
-
+
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source),
&iter,
path))
GtkTreeModel *src_model = NULL;
GtkTreePath *src_path = NULL;
gboolean retval = FALSE;
-
+
g_return_val_if_fail (GTK_IS_LIST_STORE (drag_dest), FALSE);
tree_model = GTK_TREE_MODEL (drag_dest);
list_store = GTK_LIST_STORE (drag_dest);
-
+
if (gtk_selection_data_get_tree_row (selection_data,
&src_model,
&src_path) &&
GtkTreeIter src_iter;
GtkTreeIter dest_iter;
GtkTreePath *prev;
-
+
if (!gtk_tree_model_get_iter (src_model,
&src_iter,
src_path))
*/
gtk_list_store_prepend (GTK_LIST_STORE (tree_model),
&dest_iter);
-
+
retval = TRUE;
}
else
}
gtk_tree_path_free (prev);
-
+
/* If we succeeded in creating dest_iter, copy data from src
*/
if (retval)
{
copy_iter = _gtk_tree_data_list_node_copy (dl,
list_store->column_headers[col]);
-
+
if (copy_head == NULL)
copy_head = copy_iter;
dl = dl->next;
++col;
}
-
+
G_SLIST (dest_iter.user_data)->data = copy_head;
path = gtk_list_store_get_path (GTK_TREE_MODEL (tree_model), &dest_iter);
}
out:
-
+
if (src_path)
gtk_tree_path_free (src_path);
-
- return retval;
+
+ return retval;
}
static gboolean
GtkTreePath *dest_path)
{
gint *indices;
-
+
g_return_val_if_fail (GTK_IS_LIST_STORE (drag_dest), FALSE);
if (src_model != GTK_TREE_MODEL (drag_dest))
return FALSE;
-
+
if (gtk_tree_path_get_depth (dest_path) != 1)
return FALSE;
return FALSE;
}
+
/* Sorting */
+typedef struct _SortTuple
+{
+ gint offset;
+ GSList *el;
+} SortTuple;
+
+static gint
+_gtk_list_store_compare_func (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
+{
+ GtkListStore *list_store = user_data;
+ GtkTreeDataSortHeader *header = NULL;
+ GSList *el_a; /* Los Angeles? */
+ GSList *el_b;
+ GtkTreeIter iter_a;
+ GtkTreeIter iter_b;
+ gint retval;
+
+ header = _gtk_tree_data_list_get_header (list_store->sort_list,
+ list_store->sort_column_id);
+
+ g_return_val_if_fail (header != NULL, 0);
+ g_return_val_if_fail (header->func != NULL, 0);
+
+ el_a = ((SortTuple *) a)->el;
+ el_b = ((SortTuple *) b)->el;
+
+ iter_a.stamp = list_store->stamp;
+ iter_a.user_data = el_a;
+ iter_b.stamp = list_store->stamp;
+ iter_b.user_data = el_b;
+
+ retval = (* header->func) (GTK_TREE_MODEL (list_store),
+ &iter_a, &iter_b,
+ header->data);
+
+ if (list_store->order == GTK_TREE_SORT_DESCENDING)
+ {
+ if (retval > 0)
+ retval = -1;
+ else if (retval < 0)
+ retval = 1;
+ }
+ return retval;
+}
+
+static void
+gtk_list_store_sort (GtkListStore *list_store)
+{
+ GtkTreeDataSortHeader *header = NULL;
+ GArray *sort_array;
+ gint i;
+ GList *header_list;
+ gint *new_order;
+ GSList *list;
+ GtkTreePath *path;
+
+ if (list_store->length <= 1)
+ return;
+
+ g_assert (GTK_LIST_STORE_IS_SORTED (list_store));
+
+ for (header_list = list_store->sort_list; header_list; header_list = header_list->next)
+ {
+ header = (GtkTreeDataSortHeader*) header_list->data;
+ if (header->sort_column_id == list_store->sort_column_id)
+ break;
+ }
+
+ /* We want to make sure that we have a function */
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+
+ list = G_SLIST (list_store->root);
+
+ sort_array = g_array_sized_new (FALSE, FALSE,
+ sizeof (SortTuple),
+ list_store->length);
+
+ for (i = 0; i < list_store->length; i++)
+ {
+ SortTuple tuple;
+
+ /* If this fails, we are in an inconsistent state. Bad */
+ g_return_if_fail (list != NULL);
+
+ tuple.offset = i;
+ tuple.el = list;
+ g_array_append_val (sort_array, tuple);
+
+ list = list->next;
+ }
+
+ g_array_sort_with_data (sort_array, _gtk_list_store_compare_func, list_store);
+
+ for (i = 0; i < list_store->length - 1; i++)
+ g_array_index (sort_array, SortTuple, i).el->next =
+ g_array_index (sort_array, SortTuple, i + 1).el;
+ g_array_index (sort_array, SortTuple, list_store->length - 1).el->next = NULL;
+ list_store->root = g_array_index (sort_array, SortTuple, 0).el;
+
+ /* Let the world know about our new order */
+ new_order = g_new (gint, list_store->length);
+ for (i = 0; i < list_store->length; i++)
+ new_order[i] = g_array_index (sort_array, SortTuple, i).offset;
+ path = gtk_tree_path_new ();
+ gtk_tree_model_reordered (GTK_TREE_MODEL (list_store),
+ path, new_order);
+ gtk_tree_path_free (path);
+ g_free (new_order);
+ g_array_free (sort_array, TRUE);
+}
+
+static void
+gtk_list_store_sort_iter_changed (GtkListStore *list_store,
+ GtkTreeIter *iter)
+
+{
+ GtkTreeDataSortHeader *header;
+ GSList *prev = NULL;
+ GSList *next = NULL;
+ GSList *list = G_SLIST (list_store->root);
+
+ GtkTreeIter tmp_iter;
+ gint cmp_a = 0;
+ gint cmp_b = 0;
+
+ if (list_store->length < 2)
+ return;
+
+ tmp_iter.stamp = list_store->stamp;
+ header = _gtk_tree_data_list_get_header (list_store->sort_list,
+ list_store->sort_column_id);
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+
+ /* First we find the iter, its prev, and its next */
+ while (list)
+ {
+ if (list == G_SLIST (iter->user_data))
+ break;
+ prev = list;
+ list = list->next;
+ }
+ g_assert (list != NULL);
+
+ next = list->next;
+
+ /* Check the common case, where we don't need to sort it moved. */
+ if (prev != NULL)
+ {
+ tmp_iter.user_data = prev;
+ cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
+ &tmp_iter, iter,
+ header->data);
+ }
+
+ if (next != NULL)
+ {
+ tmp_iter.user_data = next;
+ cmp_b = (* header->func) (GTK_TREE_MODEL (list_store),
+ iter, &tmp_iter,
+ header->data);
+ }
+
+
+ if (list_store->order == GTK_TREE_SORT_DESCENDING)
+ {
+ if (cmp_a < 0)
+ cmp_a = 1;
+ else if (cmp_a > 0)
+ cmp_a = -1;
+
+ if (cmp_b < 0)
+ cmp_b = 1;
+ else if (cmp_b > 0)
+ cmp_b = -1;
+
+ }
+
+ if (prev == NULL && cmp_b <= 0)
+ return;
+ else if (next == NULL && cmp_a <= 0)
+ return;
+ else if (prev != NULL && next != NULL &&
+ cmp_a <= 0 && cmp_b <= 0)
+ return;
+
+ /* We actually need to sort it */
+ /* First, remove the old link. */
+
+ if (prev == NULL)
+ list_store->root = next;
+ else
+ prev->next = next;
+ if (next == NULL)
+ list_store->tail = prev;
+ list->next = NULL;
+
+ /* FIXME: as an optimization, we can potentially start at next */
+ prev = NULL;
+ list = G_SLIST (list_store->root);
+
+ tmp_iter.user_data = list;
+ if (list_store->order == GTK_TREE_SORT_DESCENDING)
+ cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
+ &tmp_iter, iter, header->data);
+ else
+ cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
+ iter, &tmp_iter, header->data);
+
+ while ((list->next) && (cmp_a > 0))
+ {
+ prev = list;
+ list = list->next;
+ tmp_iter.user_data = list;
+ if (list_store->order == GTK_TREE_SORT_DESCENDING)
+ cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
+ &tmp_iter, iter, header->data);
+ else
+ cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
+ iter, &tmp_iter, header->data);
+ }
+
+ if ((!list->next) && (cmp_a > 0))
+ {
+ list->next = G_SLIST (iter->user_data);
+ list_store->tail = list->next;
+ }
+ else if (prev)
+ {
+ prev->next = G_SLIST (iter->user_data);
+ G_SLIST (iter->user_data)->next = list;
+ }
+ else
+ {
+ G_SLIST (iter->user_data)->next = G_SLIST (list_store->root);
+ list_store->root = G_SLIST (iter->user_data);
+ }
+}
+
static gboolean
gtk_list_store_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
}
g_return_if_fail (list != NULL);
+ if ((list_store->sort_column_id == sort_column_id) &&
+ (list_store->order == order))
+ return;
+
list_store->sort_column_id = sort_column_id;
list_store->order = order;
+
+ if (list_store->sort_column_id >= 0)
+ gtk_list_store_sort (list_store);
}
static void
tree_column->dirty = TRUE;
tree_column->sort_order = GTK_TREE_SORT_ASCENDING;
tree_column->show_sort_indicator = FALSE;
+ tree_column->sort_signal = 0;
+ tree_column->sort_column_id = -1;
}
static void
return tree_column->xalign;
}
+
+static void
+sort_clicked_func (GtkTreeViewColumn *tree_column,
+ gpointer data)
+{
+ GList *list;
+
+ g_return_if_fail (tree_column->tree_view != NULL);
+
+ if (tree_column->show_sort_indicator)
+ {
+ if (tree_column->sort_order == GTK_TREE_SORT_ASCENDING)
+ gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_DESCENDING);
+ else
+ gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
+ }
+ else
+ {
+ gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
+ gtk_tree_view_column_set_sort_indicator (tree_column, TRUE);
+ }
+
+ list = (GTK_TREE_VIEW (tree_column->tree_view)->priv->columns);
+ g_assert (list);
+ while (list)
+ {
+ GtkTreeViewColumn *tmp_column;
+
+ tmp_column = GTK_TREE_VIEW_COLUMN (list->data);
+ if (tmp_column->visible && tmp_column != tree_column)
+ gtk_tree_view_column_set_sort_indicator (tmp_column, FALSE);
+
+ list = list->next;
+ }
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
+ tree_column->sort_column_id,
+ tree_column->sort_order);
+}
+
+/**
+ * gtk_tree_view_column_set_sort_column_id:
+ * @tree_column: a #GtkTreeViewColumn
+ * @sort_column_id: The sort_column_id of the model to sort on.
+ *
+ * Sets the sort_column_id that the column sorts on.
+ **/
+void
+gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column,
+ gint sort_column_id)
+{
+ g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
+ g_return_if_fail (sort_column_id >= 0);
+
+ if (tree_column->sort_column_id == sort_column_id)
+ return;
+
+ if (sort_column_id == -1)
+ {
+ if (tree_column->sort_signal)
+ g_signal_handler_disconnect (G_OBJECT (tree_column), tree_column->sort_signal);
+ return;
+ }
+
+ if (! tree_column->sort_signal)
+ tree_column->sort_signal = g_signal_connectc (G_OBJECT (tree_column),
+ "clicked",
+ G_CALLBACK (sort_clicked_func),
+ NULL, FALSE);
+ tree_column->sort_column_id = sort_column_id;
+ gtk_tree_view_column_set_sort_indicator (tree_column, FALSE);
+ gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
+}
+
/**
* gtk_tree_view_column_set_sort_indicator:
* @tree_column: a #GtkTreeViewColumn
* @order: sort order that the sort indicator should indicate
*
* Changes the appearance of the sort indicator. (This <emphasis>does
- * not</emphasis> actually sort the model - for the models shipped
- * with GTK+, use at gtk_tree_sortable_set_sort_column() to do
- * that. For custom models, the mechanism will vary.) The sort
- * indicator changes direction to indicate normal sort or reverse
- * sort. Note that you must have the sort indicator enabled to see
- * anything when calling this function; see
+ * not</emphasis> actually sort the model. Use
+ * gtk_tree_view_column_set_sort_column_id() if you want automatic sorting
+ * support. This function is primarily for custom sorting behavior, and should
+ * be used in conjunction with #gtk_tree_sortable_set_sort_column() to do
+ * that. For custom models, the mechanism will vary.) The sort indicator changes
+ * direction to indicate normal sort or reverse sort. Note that you must have
+ * the sort indicator enabled to see anything when calling this function; see
* gtk_tree_view_column_set_sort_indicator().
*
**/
--- /dev/null
+#include <gtk/gtk.h>
+
+
+typedef struct _ListSort ListSort;
+struct _ListSort
+{
+ const gchar *word_1;
+ const gchar *word_2;
+ const gchar *word_3;
+ const gchar *word_4;
+};
+
+static ListSort data[] =
+{
+ { "Apples", "Transmorgrify", "Exculpatory", "Gesundheit"},
+ { "Oranges", "Wicker", "Adamantine", "Convivial" },
+ { "Bovine Spongiform Encephilopathy", "Sleazebucket", "Mountaineer", "Pander" },
+ { "Foot and Mouth", "Lampshade", "Skim Milk\nFull Milk", "Viewless" },
+ { "Blood,\nsweat,\ntears", "The Man", "Horses", "Muckety-Muck" },
+ { "Rare Steak", "Siam", "Watchdog", "Xantippe" },
+ { "SIGINT", "Rabbit Breath", "Alligator", "Bloodstained" },
+ { "Google", "Chrysanthemums", "Hobnob", "Leapfrog"},
+ { "Technology fibre optic", "Turtle", "Academe", "Lonely" },
+ { "Freon", "Harpes", "Quidditch", "Reagan" },
+ { "Transposition", "Fruit Basket", "Monkey Wort", "Glogg" },
+ { "Fern", "Glasnost and Perestroika", "Latitude", "Bomberman!!!" },
+ {NULL, }
+};
+
+
+enum
+{
+ WORD_COLUMN = 0,
+ WORD_COLUMN_2,
+ WORD_COLUMN_3,
+ WORD_COLUMN_4,
+ NUM_COLUMNS
+};
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window;
+ GtkWidget *vbox;
+ GtkWidget *scrolled_window;
+ GtkWidget *tree_view;
+ GtkTreeModel *model;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+ GtkTreeIter iter;
+ gint i;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL);
+ vbox = gtk_vbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("My List of cool words"), FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ 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, 0);
+
+ model = gtk_list_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
+ 0, GTK_TREE_SORT_ASCENDING);
+ for (i = 0; data[i].word_1 != NULL; i++)
+ {
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ WORD_COLUMN, 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);
+ }
+
+ tree_view = gtk_tree_view_new_with_model (model);
+ g_object_unref (G_OBJECT (model));
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("First Word", renderer,
+ "text", WORD_COLUMN,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
+ g_object_unref (column);
+ g_object_unref (renderer);
+
+ 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);
+ g_object_unref (column);
+ g_object_unref (renderer);
+
+ 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);
+ g_object_unref (column);
+ g_object_unref (renderer);
+
+ 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);
+ g_object_unref (column);
+ g_object_unref (renderer);
+
+ gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
+ gtk_widget_show_all (window);
+ gtk_main ();
+
+ return 0;
+}