treeview-tutorial-xml/examples/custom-list-model-sorted/custom-list.h

108 lines
3.3 KiB
C

/***********************************************************
*
* custom-list.h
*
* A simple custom list model with sorting
*
* part of the Gtk+ tree view tutorial
*
* by Tim-Philipp Mueller < tim at centricular dot net >
*
***********************************************************/
#ifndef _custom_list_h_included_
#define _custom_list_h_included_
#include <gtk/gtk.h>
/* Some boilerplate GObject defines. 'klass' is used instead of 'class', because 'class' is a C++ keyword */
#define CUSTOM_TYPE_LIST (custom_list_get_type ())
#define CUSTOM_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CUSTOM_TYPE_LIST, CustomList))
#define CUSTOM_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CUSTOM_TYPE_LIST, CustomListClass))
#define CUSTOM_IS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUSTOM_TYPE_LIST))
#define CUSTOM_IS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CUSTOM_TYPE_LIST))
#define CUSTOM_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CUSTOM_TYPE_LIST, CustomListClass))
/* The data columns that we export via the tree model interface */
enum
{
CUSTOM_LIST_COL_RECORD = 0,
CUSTOM_LIST_COL_NAME,
CUSTOM_LIST_COL_YEAR_BORN,
CUSTOM_LIST_N_COLUMNS,
} ;
enum
{
SORT_ID_NONE = 0,
SORT_ID_NAME,
SORT_ID_YEAR_BORN,
};
typedef struct _CustomRecord CustomRecord;
typedef struct _CustomList CustomList;
typedef struct _CustomListClass CustomListClass;
/* CustomRecord: this structure represents a row */
struct _CustomRecord
{
/* data - you can extend this */
gchar *name;
gchar *name_collate_key;
guint year_born;
/* admin stuff used by the custom list model */
guint pos; /* pos within the array */
};
/* CustomList: this structure contains everything we need for our
* model implementation. You can add extra fields to
* this structure, e.g. hashtables to quickly lookup
* rows or whatever else you might need, but it is
* crucial that 'parent' is the first member of the
* structure. */
struct _CustomList
{
GObject parent; /* this MUST be the first member */
guint num_rows; /* number of rows that we have */
CustomRecord **rows; /* a dynamically allocated array of pointers to the CustomRecord structure for each row */
gint n_columns; /* These two fields are not absolutely necessary, but they */
GType column_types[CUSTOM_LIST_N_COLUMNS]; /* speed things up a bit in our get_value implementation */
gint sort_id;
GtkSortType sort_order;
gint stamp; /* A random integer to check if an iter belongs to our model */
};
/* CustomListClass: more boilerplate GObject stuff */
struct _CustomListClass
{
GObjectClass parent_class;
};
GType custom_list_get_type (void);
CustomList *custom_list_new (void);
void custom_list_append_record (CustomList *custom_list,
const gchar *name,
guint year_born);
#endif /* _custom_list_h_included_ */