1 /********************************************************************\ 2 * table-model.h -- 2D grid table object model * 3 * Copyright (c) 2001 Free Software Foundation * 4 * Author: Dave Peticolas <dave@krondo.com> * 5 * * 6 * This program is free software; you can redistribute it and/or * 7 * modify it under the terms of the GNU General Public License as * 8 * published by the Free Software Foundation; either version 2 of * 9 * the License, or (at your option) any later version. * 10 * * 11 * This program is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 14 * GNU General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU General Public License* 17 * along with this program; if not, contact: * 18 * * 19 * Free Software Foundation Voice: +1-617-542-5942 * 20 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 21 * Boston, MA 02110-1301, USA gnu@gnu.org * 22 * * 23 \********************************************************************/ 24 25 #ifndef TABLE_MODEL_H 26 #define TABLE_MODEL_H 27 28 #include <glib.h> 29 30 #include "basiccell.h" 31 #include "register-common.h" 32 33 /** @addtogroup Table Table 34 * @{ 35 * @file table-model.h 36 */ 37 typedef enum 38 { 39 XACC_CELL_ALLOW_NONE = 0, 40 XACC_CELL_ALLOW_INPUT = 1 << 0, 41 XACC_CELL_ALLOW_SHADOW = 1 << 1, 42 XACC_CELL_ALLOW_ALL = XACC_CELL_ALLOW_INPUT | XACC_CELL_ALLOW_SHADOW, 43 XACC_CELL_ALLOW_EXACT_ONLY = 1 << 2, 44 XACC_CELL_ALLOW_ENTER = 1 << 3, 45 XACC_CELL_ALLOW_READ_ONLY = XACC_CELL_ALLOW_SHADOW | XACC_CELL_ALLOW_ENTER 46 } CellIOFlags; 47 48 typedef enum 49 { 50 CELL_BORDER_LINE_NONE, 51 CELL_BORDER_LINE_LIGHT, 52 CELL_BORDER_LINE_NORMAL, 53 CELL_BORDER_LINE_HEAVY, 54 CELL_BORDER_LINE_HIGHLIGHT 55 } PhysicalCellBorderLineStyle; 56 57 typedef struct 58 { 59 PhysicalCellBorderLineStyle top; 60 PhysicalCellBorderLineStyle bottom; 61 PhysicalCellBorderLineStyle left; 62 PhysicalCellBorderLineStyle right; 63 } PhysicalCellBorders; 64 65 typedef const char * (*TableGetEntryHandler) (VirtualLocation virt_loc, 66 gboolean translate, 67 gboolean *conditionally_changed, 68 gpointer user_data); 69 70 typedef const char * (*TableGetLabelHandler) (VirtualLocation virt_loc, 71 gpointer user_data); 72 73 typedef char * (*TableGetHelpHandler) (VirtualLocation virt_loc, 74 gpointer user_data); 75 76 typedef char * (*TableGetTooltipHandler) (VirtualLocation virt_loc, 77 gpointer user_data); 78 79 typedef CellIOFlags (*TableGetCellIOFlagsHandler) (VirtualLocation virt_loc, 80 gpointer user_data); 81 82 typedef guint32 (*TableGetCellColorHandler) (VirtualLocation virt_loc, 83 gboolean *hatching, 84 gpointer user_data); 85 86 typedef void (*TableGetCellBorderHandler) (VirtualLocation virt_loc, 87 PhysicalCellBorders *borders, 88 gpointer user_data); 89 90 typedef gboolean (*TableConfirmHandler) (VirtualLocation virt_loc, 91 gpointer user_data); 92 93 typedef void (*TableSaveCellHandler) (BasicCell * cell, 94 gpointer save_data, 95 gpointer user_data); 96 97 typedef void (*TableSaveHandler) (gpointer save_data, 98 gpointer user_data); 99 100 typedef gpointer (*VirtCellDataAllocator) (void); 101 typedef void (*VirtCellDataDeallocator) (gpointer cell_data); 102 typedef void (*VirtCellDataCopy) (gpointer to, gconstpointer from); 103 104 typedef struct 105 { 106 GHashTable *entry_handlers; 107 GHashTable *label_handlers; 108 GHashTable *help_handlers; 109 GHashTable *tooltip_handlers; 110 GHashTable *io_flags_handlers; 111 GHashTable *cell_color_handlers; 112 GHashTable *cell_border_handlers; 113 GHashTable *confirm_handlers; 114 115 GHashTable *save_handlers; 116 TableSaveHandler pre_save_handler; 117 TableSaveHandler post_save_handler; 118 119 gpointer handler_user_data; 120 121 /* If true, denotes that this table is read-only 122 * and edits should not be allowed. */ 123 gboolean read_only; 124 125 /* If positive, denotes a row that marks a boundary that should 126 * be visually distinguished. */ 127 int dividing_row; 128 /* If positive, denotes a row that marks a boundary that should 129 * be visually distinguished, but different from the others. */ 130 int dividing_row_upper; 131 /* If positive, denotes a row that marks a boundary that should 132 * be visually distinguished. */ 133 int dividing_row_lower; 134 135 VirtCellDataAllocator cell_data_allocator; 136 VirtCellDataDeallocator cell_data_deallocator; 137 VirtCellDataCopy cell_data_copy; 138 } TableModel; 139 140 141 TableModel * gnc_table_model_new (void); 142 void gnc_table_model_destroy (TableModel *model); 143 144 void gnc_table_model_set_read_only (TableModel *model, 145 gboolean read_only); 146 gboolean gnc_table_model_read_only (TableModel *model); 147 148 void gnc_table_model_set_entry_handler 149 (TableModel *model, 150 TableGetEntryHandler entry_handler, 151 const char * cell_name); 152 void gnc_table_model_set_default_entry_handler 153 (TableModel *model, 154 TableGetEntryHandler entry_handler); 155 TableGetEntryHandler gnc_table_model_get_entry_handler 156 (TableModel *model, 157 const char * cell_name); 158 159 void gnc_table_model_set_label_handler 160 (TableModel *model, 161 TableGetLabelHandler label_handler, 162 const char * cell_name); 163 void gnc_table_model_set_default_label_handler 164 (TableModel *model, 165 TableGetLabelHandler label_handler); 166 TableGetLabelHandler gnc_table_model_get_label_handler 167 (TableModel *model, 168 const char * cell_name); 169 170 void gnc_table_model_set_help_handler 171 (TableModel *model, 172 TableGetHelpHandler help_handler, 173 const char * cell_name); 174 void gnc_table_model_set_default_help_handler 175 (TableModel *model, 176 TableGetHelpHandler help_handler); 177 TableGetHelpHandler gnc_table_model_get_help_handler 178 (TableModel *model, 179 const char * cell_name); 180 181 void gnc_table_model_set_tooltip_handler 182 (TableModel *model, 183 TableGetTooltipHandler tooltip_handler, 184 const char * cell_name); 185 void gnc_table_model_set_default_tooltip_handler 186 (TableModel *model, 187 TableGetTooltipHandler tooltip_handler); 188 TableGetTooltipHandler gnc_table_model_get_tooltip_handler 189 (TableModel *model, 190 const char * cell_name); 191 192 void gnc_table_model_set_io_flags_handler 193 (TableModel *model, 194 TableGetCellIOFlagsHandler io_flags_handler, 195 const char * cell_name); 196 void gnc_table_model_set_default_io_flags_handler 197 (TableModel *model, 198 TableGetCellIOFlagsHandler io_flags_handler); 199 TableGetCellIOFlagsHandler gnc_table_model_get_io_flags_handler 200 (TableModel *model, 201 const char * cell_name); 202 203 void gnc_table_model_set_cell_color_handler 204 (TableModel *model, 205 TableGetCellColorHandler io_flags_handler, 206 const char * cell_name); 207 void gnc_table_model_set_default_cell_color_handler 208 (TableModel *model, 209 TableGetCellColorHandler io_flags_handler); 210 TableGetCellColorHandler gnc_table_model_get_cell_color_handler 211 (TableModel *model, 212 const char * cell_name); 213 214 void gnc_table_model_set_cell_border_handler 215 (TableModel *model, 216 TableGetCellBorderHandler io_flags_handler, 217 const char * cell_name); 218 void gnc_table_model_set_default_cell_border_handler 219 (TableModel *model, 220 TableGetCellBorderHandler io_flags_handler); 221 TableGetCellBorderHandler gnc_table_model_get_cell_border_handler 222 (TableModel *model, 223 const char * cell_name); 224 225 void gnc_table_model_set_confirm_handler 226 (TableModel *model, 227 TableConfirmHandler io_flags_handler, 228 const char * cell_name); 229 void gnc_table_model_set_default_confirm_handler 230 (TableModel *model, 231 TableConfirmHandler io_flags_handler); 232 TableConfirmHandler gnc_table_model_get_confirm_handler 233 (TableModel *model, 234 const char * cell_name); 235 236 void gnc_table_model_set_save_handler 237 (TableModel *model, 238 TableSaveCellHandler save_handler, 239 const char * cell_name); 240 void gnc_table_model_set_pre_save_handler 241 (TableModel *model, 242 TableSaveHandler save_handler); 243 void gnc_table_model_set_post_save_handler 244 (TableModel *model, 245 TableSaveHandler save_handler); 246 TableSaveCellHandler gnc_table_model_get_save_handler 247 (TableModel *model, 248 const char * cell_name); 249 TableSaveHandler gnc_table_model_get_pre_save_handler 250 (TableModel *model); 251 TableSaveHandler gnc_table_model_get_post_save_handler 252 (TableModel *model); 253 /** @} */ 254 #endif 255