/* Takes an iter structure and sets it to point to the next row. */ static gboolean packet_list_iter_next(GtkTreeModel *tree_model, GtkTreeIter *iter) { PacketListRecord *record, *nextrecord; PacketList *packet_list; g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), FALSE); if(iter == NULL || iter->user_data == NULL) return FALSE; packet_list = PACKET_LIST(tree_model); record = (PacketListRecord*) iter->user_data; /* Is this the last record in the list? */ if((record->pos + 1) >= PACKET_LIST_RECORD_COUNT(packet_list->rows)) return FALSE; nextrecord = PACKET_LIST_RECORD_GET(packet_list->rows, (record->pos + 1)); g_assert(nextrecord != NULL); g_assert(nextrecord->pos == (record->pos + 1)); iter->stamp = packet_list->stamp; iter->user_data = nextrecord; return TRUE; }
static gboolean packet_list_iter_children(GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent) { PacketList *packet_list; g_return_val_if_fail(parent == NULL || parent->user_data != NULL, FALSE); /* This is a list, nodes have no children. */ if(parent) return FALSE; /* parent == NULL is a special case; we need to return the first top- * level row */ g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), FALSE); packet_list = PACKET_LIST(tree_model); /* No rows => no first row */ if(PACKET_LIST_RECORD_COUNT(packet_list->rows) == 0) return FALSE; /* Set iter to first item in list */ iter->stamp = packet_list->stamp; iter->user_data = PACKET_LIST_RECORD_GET(packet_list->rows, 0); return TRUE; }
static gint packet_list_get_n_columns(GtkTreeModel *tree_model) { g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), 0); return PACKET_LIST(tree_model)->n_columns; }
/* Takes an iter structure and sets it to point to the next row. */ static gboolean packet_list_iter_next(GtkTreeModel *tree_model, GtkTreeIter *iter) { PacketListRecord *record, *nextrecord; PacketList *packet_list; g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), FALSE); if(iter == NULL) return FALSE; g_return_val_if_fail(iter->user_data, FALSE); packet_list = PACKET_LIST(tree_model); record = (PacketListRecord*) iter->user_data; nextrecord = packet_list_iter_next_visible(packet_list, record); if (!nextrecord) return FALSE; iter->stamp = packet_list->stamp; iter->user_data = nextrecord; return TRUE; }
static GType packet_list_get_column_type(GtkTreeModel *tree_model, gint index) { PacketList *packet_list; g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), G_TYPE_INVALID); packet_list = PACKET_LIST(tree_model); g_return_val_if_fail(index < packet_list->n_columns && index >= 0, G_TYPE_INVALID); return packet_list->column_types[index]; }
static GType packet_list_get_column_type(GtkTreeModel *tree_model, gint idx) { PacketList *packet_list; g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), G_TYPE_INVALID); packet_list = PACKET_LIST(tree_model); /* Note: We use one extra column to store the entire PacketListRecord */ g_return_val_if_fail(idx < packet_list->n_columns && idx >= 0, G_TYPE_INVALID); return packet_list->column_types[idx]; }
static GtkTreePath * packet_list_get_path(GtkTreeModel *tree_model, GtkTreeIter *iter) { GtkTreePath *path; PacketListRecord *record; PacketList *packet_list; g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), NULL); g_return_val_if_fail(iter != NULL, NULL); g_return_val_if_fail(iter->user_data != NULL, NULL); packet_list = PACKET_LIST(tree_model); record = (PacketListRecord*) iter->user_data; path = gtk_tree_path_new(); gtk_tree_path_append_index(path, record->pos); return path; }
static void packet_list_get_value(GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value) { PacketListRecord *record; PacketList *packet_list; GType type; g_return_if_fail(PACKETLIST_IS_LIST(tree_model)); g_return_if_fail(iter != NULL); packet_list = PACKET_LIST(tree_model); /* Note: We use one extra column to store the entire PacketListRecord */ g_return_if_fail(column < packet_list->n_columns); record = (PacketListRecord*) iter->user_data; g_return_if_fail(PACKET_LIST_RECORD_INDEX_VALID(packet_list->physical_rows, record->physical_pos)); g_return_if_fail(PACKET_LIST_RECORD_INDEX_VALID(packet_list->visible_rows, record->visible_pos)); type = packet_list->column_types[column]; g_value_init(value, type); /* XXX Probably the switch should be on column or * should we allways return the pointer and read the data as required?? * If we use FOREGROUND_COLOR_COL etc we'll need a couple of "internal" columns */ switch(type){ case G_TYPE_POINTER: g_value_set_pointer(value, record); break; case G_TYPE_STRING: g_return_if_fail(record->fdata->col_text); g_value_set_string(value, record->fdata->col_text[column]); break; default: g_warning (G_STRLOC ": Unsupported type (%s) retrieved.", g_type_name (value->g_type)); break; } }
static gboolean packet_list_get_iter(GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path) { PacketList *packet_list; PacketListRecord *record; gint *indices, depth; gint n; g_assert(PACKETLIST_IS_LIST(tree_model)); g_assert(path != NULL); indices = gtk_tree_path_get_indices(path); depth = gtk_tree_path_get_depth(path); /* we do not allow children since it's just a list */ g_assert(depth == 1); n = indices[0]; /* the n-th top level row */ packet_list = PACKET_LIST(tree_model); if(PACKET_LIST_RECORD_COUNT(packet_list->visible_rows) == 0) return FALSE; if(!PACKET_LIST_RECORD_INDEX_VALID(packet_list->visible_rows, n)) return FALSE; record = PACKET_LIST_RECORD_GET(packet_list->visible_rows, n); g_assert(record->visible_pos == n); /* We simply store a pointer to our custom record in the iter */ iter->stamp = packet_list->stamp; iter->user_data = record; iter->user_data2 = NULL; iter->user_data3 = NULL; return TRUE; }