1 /* 2 * Gnome Crystal 3 * grid.h 4 * 5 * Copyright (C) 2010-2012 Jean Bréfort <jean.brefort@normalesup.org> 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 as 9 * published by the Free Software Foundation; either version 3 of the 10 * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 20 * USA 21 */ 22 23 #ifndef GCR_GRID_H 24 #define GCR_GRID_H 25 26 /*!\file 27 @brief Grid widget. 28 29 The grid widget used in GCrystal dialogs to display lists of atoms, cleavages, 30 or lines. 31 */ 32 33 #include <gtk/gtk.h> 34 35 G_BEGIN_DECLS 36 37 /*!\return the GType associated to GcrGrid */ 38 #define GCR_TYPE_GRID (gcr_grid_get_type ()) 39 /*! 40 Casts \a obj to a GcrGrid * pointer. 41 @return a pointer to the GcrGrid * or NULL if \a obj does not point to 42 a GcrGrid widget. 43 */ 44 #define GCR_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCR_TYPE_GRID, GcrGrid)) 45 /*! 46 @return TRUE if \a obj points to a GcrGrid widget, FALSE otherwise. 47 */ 48 #define GCR_IS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCR_TYPE_GRID)) 49 50 /*!\struct GcrGrid 51 @brief Grid widget. 52 53 The grid widget used in GCrystal dialogs to display lists of atoms, cleavages, 54 or lines. 55 56 Functions related to the GcrGrid Widget are described in the gcrgrid.h page. 57 */ 58 typedef struct _GcrGrid GcrGrid; 59 60 GType gcr_grid_get_type (void); 61 62 /*! 63 @param col_title the first column title. 64 @param col_type the first column data type. 65 66 Builds a new GcrGrid widget. 67 The arguments must include titles and types for each column in the grid. 68 Supported types are G_TYPE_INT, G_TYPE_UINT, G_TYPE_DOUBLE, G_TYPE_STRING, 69 and G_TYPE_BOOLEAN. Strings can't be edited in this version. 70 @return a pointer to the new widget. 71 */ 72 GtkWidget *gcr_grid_new (char const *col_title, GType col_type,...); 73 74 /*! 75 @param grid a GcrGrid. 76 @param row the row. 77 @param column the column. 78 79 Retrieves the integer value stored in the cell. If the column type is not 80 G_TYPE_INT, a critical will be emitted and the function will return 0. 81 @return the integer value stored in the cell defined by \a row and \a column. 82 */ 83 int gcr_grid_get_int (GcrGrid *grid, unsigned row, unsigned column); 84 85 /*! 86 @param grid a GcrGrid. 87 @param row the row. 88 @param column the column. 89 90 Retrieves the unsigned integer value stored in the cell. If the column type is not 91 G_TYPE_UINT, a critical will be emitted and the function will return 0. 92 @return the unsigned integer value stored in the cell defined by \a row and \a column. 93 */ 94 unsigned gcr_grid_get_uint (GcrGrid *grid, unsigned row, unsigned column); 95 96 /*! 97 @param grid a GcrGrid. 98 @param row the row. 99 @param column the column. 100 101 Retrieves the floating point value stored in the cell. If the column type is not 102 G_TYPE_DOUBLE, a critical will be emitted and the function will return NAN. 103 @return the double value stored in the cell defined by \a row and \a column. 104 */ 105 double gcr_grid_get_double (GcrGrid *grid, unsigned row, unsigned column); 106 107 /*! 108 @param grid a GcrGrid. 109 @param row the row. 110 @param column the column. 111 112 Retrieves the string stored in the cell. If the column type is not 113 G_TYPE_DOUBLE, a critical will be emitted and the function will return NULL. 114 @return the string stored in the cell defined by \a row and \a column. 115 */ 116 char const *gcr_grid_get_string (GcrGrid *grid, unsigned row, unsigned column); 117 118 /*! 119 @param grid a GcrGrid. 120 @param row the row. 121 @param column the column. 122 123 Retrieves the boolean value stored in the cell. If the column type is not 124 G_TYPE_BOOLEAN, a critical will be emitted and the function will return false. 125 @return the boolean value stored in the cell defined by \a row and \a column. 126 */ 127 bool gcr_grid_get_boolean (GcrGrid *grid, unsigned row, unsigned column); 128 129 /*! 130 @param grid a GcrGrid. 131 @param row the row. 132 @param column the column. 133 @param value the new value. 134 135 Sets the integer value stored in the cell. If the column type is not 136 G_TYPE_INT, a critical will be emitted and the cell content will be unchanged. 137 */ 138 void gcr_grid_set_int (GcrGrid *grid, unsigned row, unsigned column, int value); 139 140 /*! 141 @param grid a GcrGrid. 142 @param row the row. 143 @param column the column. 144 @param value the new value. 145 146 Sets the unsigned integer value stored in the cell. If the column type is not 147 G_TYPE_UINT, a critical will be emitted and the cell content will be unchanged. 148 */ 149 void gcr_grid_set_uint (GcrGrid *grid, unsigned row, unsigned column, unsigned value); 150 151 /*! 152 @param grid a GcrGrid. 153 @param row the row. 154 @param column the column. 155 @param value the new value. 156 157 Sets the floating point value stored in the cell. If the column type is not 158 G_TYPE_DOUBLE, a critical will be emitted and the cell content will be unchanged. 159 */ 160 void gcr_grid_set_double (GcrGrid *grid, unsigned row, unsigned column, double value); 161 162 /*! 163 @param grid a GcrGrid. 164 @param row the row. 165 @param column the column. 166 @param value the new value. 167 168 Sets the string stored in the cell. If the column type is not 169 G_TYPE_STRING, a critical will be emitted and the cell content will be unchanged. 170 */ 171 void gcr_grid_set_string (GcrGrid *grid, unsigned row, unsigned column, char const *value); 172 173 /*! 174 @param grid a GcrGrid. 175 @param row the row. 176 @param column the column. 177 @param value the new value. 178 179 Sets the boolean value stored in the cell. If the column type is not 180 G_TYPE_BOOLEAN, a critical will be emitted and the cell content will be unchanged. 181 */ 182 void gcr_grid_set_boolean (GcrGrid *grid, unsigned row, unsigned column, bool value); 183 184 /*! 185 @param grid a GcrGrid. 186 187 Adds a new row to the grid. The \a grid argument must be followed by the values to fill 188 inside the cells. 189 @return the new row index. 190 */ 191 unsigned gcr_grid_append_row (GcrGrid *grid,...); 192 193 /*! 194 @param grid a GcrGrid. 195 @param row the row. 196 197 Deletes a row from the grid. 198 */ 199 void gcr_grid_delete_row (GcrGrid *grid, unsigned row); 200 201 /*! 202 @param grid a GcrGrid. 203 204 Deletes all selected rows from the grid. 205 */ 206 void gcr_grid_delete_selected_rows (GcrGrid *grid); 207 208 /*! 209 @param grid a GcrGrid. 210 211 Deletes all rows from the grid. 212 */ 213 void gcr_grid_delete_all (GcrGrid *grid); 214 215 /*! 216 @param grid a GcrGrid. 217 218 Selects all rows in the grid. 219 */ 220 void gcr_grid_select_all (GcrGrid *grid); 221 222 /*! 223 @param grid a GcrGrid. 224 @param column the column. 225 @param chars the maximum number of characters to display. 226 @param editable whether data in the column can be edited. 227 228 Changes the properties for the column. 229 */ 230 void gcr_grid_customize_column (GcrGrid *grid, unsigned column, unsigned chars, bool editable); 231 232 /*! 233 @param grid a GcrGrid. 234 @param allow boolean. 235 236 Sets whether multiple rows selection is allowed for the grid. 237 */ 238 void gcr_grid_set_allow_multiple_selection (GcrGrid *grid, bool allow); 239 240 /*! 241 @param grid a GcrGrid. 242 @param row the row to select. 243 244 Adds the row to the selection if multiple selection is allowed or just select the 245 row and replace the previous selection. 246 */ 247 void gcr_grid_add_row_to_selection (GcrGrid *grid, unsigned row); 248 249 /*! 250 @param grid a GcrGrid. 251 @param row a row index. 252 253 Unselects a row. 254 */ 255 void gcr_grid_unselect_row (GcrGrid *grid, unsigned row); 256 257 258 /*! 259 @param i a row index. 260 @param user_data user data. 261 262 Callback for gcr_grid_for_each_selected(). 263 */ 264 typedef void (*GridCb) (unsigned i, void *user_data); 265 266 /*! 267 @param grid a GcrGrid. 268 @param cb callback. 269 @param user_data user data. 270 271 Executes \a cb for each selected row. 272 */ 273 void gcr_grid_for_each_selected (GcrGrid *grid, GridCb cb, void *user_data); 274 G_END_DECLS 275 276 #endif // GCR_GRID_H 277