1 /* 2 A widget to display and manipulate tabular data 3 Copyright (C) 2016, 2017, 2020 John Darrington 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 /* 20 Objects of this class contain 4 objects of type SswSheetSingle, arranged 21 into a 2 x 2 grid. Normally, only one such object is visible. 22 If all objects are made visible (by setting the "split" property to TRUE) 23 then the user is able to see both 'ends' of the data concurrently. 24 */ 25 26 27 #ifndef _SSW_SHEET_H 28 #define _SSW_SHEET_H 29 30 #include <gtk/gtk.h> 31 32 typedef struct 33 { 34 gint start_x; 35 gint end_x; 36 gint start_y; 37 gint end_y; 38 } SswRange; 39 40 struct _SswSheet 41 { 42 GtkBin parent_instance; 43 44 /* This refers to the selected range. 45 Its units are cells. Not pixels */ 46 SswRange *selection; 47 48 GtkAdjustment *vadj[2] ; 49 GtkAdjustment *hadj[2] ; 50 51 GtkWidget *horizontal_axis[2]; 52 GtkWidget *vertical_axis[2]; 53 GtkWidget *sheet[2 * 2]; 54 GtkWidget *sw [2 * 2]; 55 56 /* True if the view is split 4 ways */ 57 gboolean split; 58 59 /* The data model */ 60 GListModel *vmodel; 61 GListModel *hmodel; 62 GtkTreeModel *data_model; 63 64 gboolean gridlines; 65 gboolean editable; 66 67 gboolean dispose_has_run; 68 GtkWidget *selected_body; 69 70 gpointer renderer_func_datum; 71 72 GSList *cursor_stack; 73 GdkCursor *wait_cursor; 74 }; 75 76 struct _SswSheetClass 77 { 78 GtkBinClass parent_class; 79 }; 80 81 #define SSW_TYPE_SHEET ssw_sheet_get_type () 82 83 G_DECLARE_FINAL_TYPE (SswSheet, ssw_sheet, SSW, SHEET, GtkBin) 84 85 GtkWidget *ssw_sheet_new (void); 86 GtkWidget *ssw_sheet_get_button (SswSheet *s); 87 88 /* Prime CLIP such that a paste request will act upon this SHEET */ 89 void ssw_sheet_set_clip (SswSheet *sheet, GtkClipboard *clip); 90 91 void ssw_sheet_wait_push (SswSheet *sheet); 92 void ssw_sheet_wait_pop (SswSheet *sheet); 93 94 typedef void (*ssw_sheet_set_cell) (GtkTreeModel *store, gint col, gint row, 95 const GValue *value); 96 97 void ssw_sheet_paste (SswSheet *sheet, GtkClipboard *clip, ssw_sheet_set_cell sc); 98 99 /* Check if an editable is focused. If yes, cut to clipboard and return TRUE */ 100 gboolean ssw_sheet_try_cut (SswSheet *sheet); 101 102 /* Scroll the sheet so that the cell HPOS,VPOS is approximately in the center. 103 Either HPOS or VPOS may be -1, in which case that position is unchanged. */ 104 void ssw_sheet_scroll_to (SswSheet *sheet, gint hpos, gint vpos); 105 106 void ssw_sheet_set_active_cell (SswSheet *sheet, 107 gint col, gint row, GdkEvent *e); 108 109 gboolean ssw_sheet_get_active_cell (SswSheet *sheet, 110 gint *col, gint *row); 111 112 113 typedef gboolean (*ssw_sheet_reverse_conversion_func) 114 (GtkTreeModel *model, gint col, gint row, const gchar *in, GValue *out); 115 116 typedef gchar * (*ssw_sheet_forward_conversion_func) 117 (SswSheet *sheet, GtkTreeModel *m, gint col, gint row, const GValue *in); 118 119 120 gchar * ssw_sheet_default_forward_conversion (SswSheet *sheet, GtkTreeModel *m, 121 gint col, gint row, 122 const GValue *value); 123 124 gboolean ssw_sheet_default_reverse_conversion (GtkTreeModel *model, 125 gint col, gint row, 126 const gchar *in, GValue *out); 127 #endif 128