| 1 |
/************************************************************************ |
| 2 |
* treeview.h GtkTreeView (and friends) implementation for gtkport * |
| 3 |
* Copyright (C) 1998-2022 Ben Webb * |
| 4 |
* Email: [email protected] * |
| 5 |
* WWW: https://dopewars.sourceforge.io/ * |
| 6 |
* * |
| 7 |
* This program is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU General Public License * |
| 9 |
* as published by the Free Software Foundation; either version 2 * |
| 10 |
* of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This program is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU General Public License * |
| 18 |
* along with this program; if not, write to the Free Software * |
| 19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, * |
| 20 |
* MA 02111-1307, USA. * |
| 21 |
************************************************************************/ |
| 22 |
|
| 23 |
#ifndef __TREEVIEW_H__ |
| 24 |
#define __TREEVIEW_H__ |
| 25 |
|
| 26 |
#ifdef HAVE_CONFIG_H |
| 27 |
#include <config.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#ifdef CYGWIN |
| 31 |
|
| 32 |
#include <glib.h> |
| 33 |
#include "gtkenums.h" |
| 34 |
|
| 35 |
typedef struct _GtkTreeView GtkTreeView; |
| 36 |
typedef struct _GtkTreeViewColumn GtkTreeViewColumn; |
| 37 |
typedef struct _GtkListStore GtkListStore; |
| 38 |
/* ListStore is the only model we provide here, so they can be synonyms */ |
| 39 |
typedef struct _GtkListStore GtkTreeModel; |
| 40 |
typedef struct _GtkCellRenderer GtkCellRenderer; |
| 41 |
|
| 42 |
/* Our TreeModel is sortable, so this can be a synonym */ |
| 43 |
typedef struct _GtkListStore GtkTreeSortable; |
| 44 |
|
| 45 |
/* We only support one selection per tree view, so make them synonyms */ |
| 46 |
typedef struct _GtkTreeView GtkTreeSelection; |
| 47 |
|
| 48 |
/* A list row is just a list of pointers to column data */ |
| 49 |
typedef struct _GtkListStoreRow GtkListStoreRow; |
| 50 |
|
| 51 |
/* Tree iterators and paths are each just a row index */ |
| 52 |
typedef guint GtkTreeIter; |
| 53 |
typedef guint GtkTreePath; |
| 54 |
|
| 55 |
typedef gint (*GtkTreeIterCompareFunc) (GtkTreeModel *model, |
| 56 |
GtkTreeIter *a, GtkTreeIter *b, |
| 57 |
gpointer user_data); |
| 58 |
|
| 59 |
struct _GtkTreeView { |
| 60 |
GtkContainer container; |
| 61 |
HWND header, scrollwin; |
| 62 |
GtkTreeModel *model; |
| 63 |
int scrollpos; |
| 64 |
gint16 header_size; |
| 65 |
GtkSelectionMode mode; |
| 66 |
GSList *columns; /* List of GtkTreeViewColumn objects */ |
| 67 |
GList *selection; |
| 68 |
gint headers_clickable:1; |
| 69 |
}; |
| 70 |
|
| 71 |
struct _GtkTreeViewColumn { |
| 72 |
gchar *title; /* header title */ |
| 73 |
int model_column; /* the index of the column in the GtkTreeModel */ |
| 74 |
gint sort_column_id; /* what to sort by when this column is selected */ |
| 75 |
gint width; |
| 76 |
gint optimal_width; |
| 77 |
gfloat xalign; /* 0.0 for left, 0.5 for center, 1.0 for right align */ |
| 78 |
guint visible:1; |
| 79 |
guint resizeable:1; |
| 80 |
guint auto_resize:1; |
| 81 |
guint expand:1; /* should the column take up available space? */ |
| 82 |
}; |
| 83 |
|
| 84 |
struct _GtkListStoreRow { |
| 85 |
gpointer *data; /* Data for each column */ |
| 86 |
}; |
| 87 |
|
| 88 |
struct _GtkListStore { |
| 89 |
GObject object; |
| 90 |
int ncols; /* Number of columns */ |
| 91 |
int *coltype; /* Type of each column (e.g. G_TYPE_STRING) */ |
| 92 |
GArray *rows; /* All rows in the list as GtkListStoreRow */ |
| 93 |
GtkTreeView *view; /* The currently connected view (only one supported) */ |
| 94 |
gint sort_column_id; /* what to sort by, if >= 0 */ |
| 95 |
GtkSortType sort_order; |
| 96 |
GArray *sort_func; /* callback functions for sorting, by sort_column_id */ |
| 97 |
gint need_sort:1; /* set once data is added/changed */ |
| 98 |
}; |
| 99 |
|
| 100 |
/* Empty struct; we don't support customizing the renderer */ |
| 101 |
struct _GtkCellRenderer { |
| 102 |
}; |
| 103 |
|
| 104 |
typedef void (*GtkTreeSelectionForeachFunc) (GtkTreeModel *model, |
| 105 |
GtkTreePath *path, GtkTreeIter *iter, gpointer data); |
| 106 |
|
| 107 |
#define GTK_TREE_VIEW(obj) ((GtkTreeView *)(obj)) |
| 108 |
#define GTK_TREE_MODEL(obj) ((GtkTreeModel *)(obj)) |
| 109 |
#define GTK_TREE_SORTABLE(obj) ((GtkTreeSortable *)(obj)) |
| 110 |
#define GTK_LIST_STORE(obj) ((GtkListStore *)(obj)) |
| 111 |
|
| 112 |
#define GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID (-1) |
| 113 |
#define GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID (-2) |
| 114 |
|
| 115 |
GtkListStore *gtk_list_store_new(gint n_columns, ...); |
| 116 |
void gtk_list_store_clear(GtkListStore *list_store); |
| 117 |
void gtk_list_store_insert(GtkListStore *list_store, GtkTreeIter *iter, |
| 118 |
gint position); |
| 119 |
void gtk_list_store_append(GtkListStore *list_store, GtkTreeIter *iter); |
| 120 |
gboolean gtk_list_store_remove(GtkListStore *list_store, GtkTreeIter *iter); |
| 121 |
void gtk_list_store_set(GtkListStore *list_store, GtkTreeIter *iter, ...); |
| 122 |
void gtk_list_store_swap(GtkListStore *store, GtkTreeIter *a, GtkTreeIter *b); |
| 123 |
|
| 124 |
void gtk_tree_model_get(GtkTreeModel *tree_model, GtkTreeIter *iter, ...); |
| 125 |
gboolean gtk_tree_model_iter_nth_child(GtkTreeModel *tree_model, |
| 126 |
GtkTreeIter *iter, |
| 127 |
GtkTreeIter *parent, gint n); |
| 128 |
gint gtk_tree_model_iter_n_children(GtkTreeModel *tree_model, |
| 129 |
GtkTreeIter *iter); |
| 130 |
|
| 131 |
GtkWidget *gtk_tree_view_new(void); |
| 132 |
GtkTreeSelection *gtk_tree_view_get_selection(GtkTreeView *tree_view); |
| 133 |
void gtk_tree_view_set_model(GtkTreeView *tree_view, GtkTreeModel *model); |
| 134 |
GtkTreeModel *gtk_tree_view_get_model(GtkTreeView *tree_view); |
| 135 |
void gtk_tree_view_set_headers_clickable(GtkTreeView *tree_view, |
| 136 |
gboolean setting); |
| 137 |
gint gtk_tree_view_insert_column_with_attributes |
| 138 |
(GtkTreeView *tree_view, gint position, const gchar *title, |
| 139 |
GtkCellRenderer *cell, ...); |
| 140 |
void gtk_tree_view_scroll_to_cell(GtkTreeView *tree_view, |
| 141 |
GtkTreePath *path, |
| 142 |
GtkTreeViewColumn *column, |
| 143 |
gboolean use_align, gfloat row_align, |
| 144 |
gfloat col_align); |
| 145 |
void gtk_tree_selection_selected_foreach(GtkTreeSelection *selection, |
| 146 |
GtkTreeSelectionForeachFunc func, |
| 147 |
gpointer data); |
| 148 |
void gtk_tree_selection_set_mode(GtkTreeSelection *selection, |
| 149 |
GtkSelectionMode type); |
| 150 |
gboolean gtk_tree_selection_get_selected(GtkTreeSelection *selection, |
| 151 |
GtkTreeModel **model, |
| 152 |
GtkTreeIter *iter); |
| 153 |
gint gtk_tree_selection_count_selected_rows(GtkTreeSelection *selection); |
| 154 |
void gtk_tree_selection_select_path(GtkTreeSelection *selection, |
| 155 |
GtkTreePath *path); |
| 156 |
void gtk_tree_selection_unselect_path(GtkTreeSelection *selection, |
| 157 |
GtkTreePath *path); |
| 158 |
void gtk_tree_selection_unselect_all(GtkTreeSelection *selection); |
| 159 |
#define gtk_tree_selection_select_iter(sel, iter) gtk_tree_selection_select_path(sel, iter) |
| 160 |
#define gtk_tree_selection_unselect_iter(sel, iter) gtk_tree_selection_unselect_path(sel, iter) |
| 161 |
GList *gtk_tree_selection_get_selected_rows(GtkTreeSelection *selection, |
| 162 |
GtkTreeModel **model); |
| 163 |
#define gtk_tree_path_free g_free |
| 164 |
gint *gtk_tree_path_get_indices_with_depth(GtkTreePath *path, gint *depth); |
| 165 |
GtkTreeViewColumn *gtk_tree_view_column_new_with_attributes |
| 166 |
(const gchar *title, GtkCellRenderer *cell, ...); |
| 167 |
void gtk_tree_view_column_set_resizable(GtkTreeViewColumn *tree_column, |
| 168 |
gboolean resizable); |
| 169 |
void gtk_tree_view_column_set_expand(GtkTreeViewColumn *tree_column, |
| 170 |
gboolean expand); |
| 171 |
void gtk_tree_view_column_set_sort_column_id(GtkTreeViewColumn *tree_column, |
| 172 |
gint sort_column_id); |
| 173 |
/* We treat this as the alignment of all cells in this column, not just the |
| 174 |
alignment of the header */ |
| 175 |
void gtk_tree_view_column_set_alignment(GtkTreeViewColumn *tree_column, |
| 176 |
gfloat xalign); |
| 177 |
/* This is only used to set the xalign property, so make it a noop */ |
| 178 |
#define g_object_set(object, name, value, end) {} |
| 179 |
gint gtk_tree_view_insert_column(GtkTreeView *tree_view, |
| 180 |
GtkTreeViewColumn *column, |
| 181 |
gint position); |
| 182 |
GtkTreeViewColumn *gtk_tree_view_get_column(GtkTreeView *tree_view, gint n); |
| 183 |
|
| 184 |
/* Force a sort of the view */ |
| 185 |
void gtk_tree_view_sort(GtkTreeView *tv); |
| 186 |
|
| 187 |
void gtk_tree_sortable_set_sort_func(GtkTreeSortable *sortable, |
| 188 |
gint sort_column_id, |
| 189 |
GtkTreeIterCompareFunc sort_func, |
| 190 |
gpointer user_data, |
| 191 |
GDestroyNotify destroy); |
| 192 |
void gtk_tree_sortable_set_sort_column_id(GtkTreeSortable *sortable, |
| 193 |
gint sort_column_id, |
| 194 |
GtkSortType order); |
| 195 |
GtkCellRenderer *gtk_cell_renderer_text_new(void); |
| 196 |
|
| 197 |
void g_object_unref(gpointer object); |
| 198 |
gpointer g_object_ref(gpointer object); |
| 199 |
|
| 200 |
/* Private functions */ |
| 201 |
void InitTreeViewClass(HINSTANCE hInstance); |
| 202 |
void gtk_tree_model_free(GtkTreeModel *model); |
| 203 |
#endif /* CYGWIN */ |
| 204 |
|
| 205 |
#endif |