GnuCash  5.6-150-g038405b370+
table-gnome.c
1 /********************************************************************\
2  * table-gnome.c -- implementation of table object in GNOME *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA gnu@gnu.org *
20  * *
21 \********************************************************************/
22 
23 /*
24  * FILE:
25  * table-gnome.c
26  *
27  * FUNCTION:
28  * Implements the infrastructure for the displayed table.
29  * This is the Gnome implementation.
30  *
31  * HISTORY:
32  * Copyright (c) 1998 Linas Vepstas
33  * Copyright (c) 1998 Rob Browning <rlb@cs.utexas.edu>
34  * Copyright (c) 1999 Heath Martin <martinh@pegasus.cc.ucf.edu>
35  * Copyright (c) 2000 Heath Martin <martinh@pegasus.cc.ucf.edu>
36  * Copyright (c) 2000 Dave Peticolas <dave@krondo.com>
37  * Copyright (c) 2001 Gnumatic, Inc.
38  */
39 
40 #include <config.h>
41 
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <glib.h>
46 
47 #include "gnucash-sheet.h"
48 #include "gnucash-sheetP.h"
49 #include "gnucash-style.h"
50 #include "table-allgui.h"
51 #include "table-gnome.h"
52 #include "gnc-prefs.h"
53 #include "gnc-engine.h"
54 #include "gnc-state.h"
55 
56 #include "gnc-ledger-display.h"
57 
58 
59 
62 #define UNUSED_VAR __attribute__ ((unused))
63 
64 /* This static indicates the debugging module that this .o belongs to. */
65 static QofLogModule UNUSED_VAR log_module = GNC_MOD_REGISTER;
66 
67 
70 void
71 gnc_table_save_state (Table *table, const gchar * state_section)
72 {
73  GnucashSheet *sheet;
74  GNCHeaderWidths widths;
75  GList *node;
76  gchar *key;
77  GKeyFile *state_file = gnc_state_get_current();
78 
79  if (!table)
80  return;
81 
82  if (table->ui_data == NULL)
83  return;
84 
85  if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
86  return;
87  sheet = GNUCASH_SHEET (table->ui_data);
88 
89  widths = gnc_header_widths_new ();
90 
91  gnucash_sheet_get_header_widths (sheet, widths);
92 
93  node = gnc_table_layout_get_cells (table->layout);
94  for (; node; node = node->next)
95  {
96  BasicCell *cell = node->data;
97  int width;
98 
99  width = gnc_header_widths_get_width (widths, cell->cell_name);
100 
101  /* Remember whether the column is visible */
102  key = g_strdup_printf("%s_width", cell->cell_name);
103  if ((width > 0) && (!cell->expandable))
104  {
105  g_key_file_set_integer (state_file, state_section, key, width);
106  }
107  else if (g_key_file_has_key (state_file, state_section, key, NULL))
108  g_key_file_remove_key (state_file, state_section, key, NULL);
109  g_free (key);
110  }
111  gnc_header_widths_destroy (widths);
112 }
113 
114 static void
115 table_ui_redraw_cb (Table *table)
116 {
117  GnucashSheet *sheet;
118 
119  if (table == NULL)
120  return;
121 
122  if (table->ui_data == NULL)
123  return;
124 
125  sheet = GNUCASH_SHEET (table->ui_data);
126 
127  gnucash_sheet_redraw_help (sheet);
128 }
129 
130 static void
131 table_destroy_cb (Table *table)
132 {
133  GnucashSheet *sheet;
134 
135  if (table == NULL)
136  return;
137 
138  if (table->ui_data == NULL)
139  return;
140 
141  sheet = GNUCASH_SHEET (table->ui_data);
142 
143  g_object_unref (sheet);
144 
145  table->ui_data = NULL;
146 }
147 
148 static gboolean
149 table_default_direct_update (BasicCell *bcell,
150  int *cursor_position,
151  int *start_selection,
152  int *end_selection,
153  void *gui_data)
154 {
155  GdkEventKey *event = gui_data;
156 
157  if (event->keyval == GDK_KEY_Escape && bcell->changed)
158  {
159  GnucashSheet *sheet = (GnucashSheet *) bcell->gui_private;
160  const char *value = gnc_table_get_model_entry (sheet->table, bcell->cell_name);
161 
162  gnc_basic_cell_set_value_internal (bcell, value);
163  bcell->changed = FALSE;
164  *cursor_position = 0;
165  *start_selection = 0;
166  *end_selection = -1;
167  return TRUE;
168  }
169  return FALSE;
170 }
171 
172 void
174 {
175  table->gui_handlers.redraw_help = table_ui_redraw_cb;
176  table->gui_handlers.destroy = table_destroy_cb;
177  table->gui_handlers.default_direct_update = table_default_direct_update;
178 }
179 
180 void
181 gnc_table_refresh_gui (Table * table, gboolean do_scroll)
182 {
183  GnucashSheet *sheet;
184 
185  if (!table)
186  return;
187  if (!table->ui_data)
188  return;
189 
190  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
191 
192  sheet = GNUCASH_SHEET(table->ui_data);
193 
194  gnucash_sheet_styles_recompile (sheet);
195  gnucash_sheet_table_load (sheet, do_scroll);
196  gnucash_sheet_redraw_all (sheet);
197 }
198 
199 
200 static void
201 gnc_table_refresh_cursor_gnome (Table * table,
202  VirtualCellLocation vcell_loc,
203  gboolean do_scroll)
204 {
205  GnucashSheet *sheet;
206 
207  if (!table || !table->ui_data)
208  return;
209 
210  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
211 
213  return;
214 
215  sheet = GNUCASH_SHEET (table->ui_data);
216 
217  gnucash_sheet_cursor_set_from_table (sheet, do_scroll);
218 
219  if (gnucash_sheet_block_set_from_table (sheet, vcell_loc))
220  {
221  gnucash_sheet_recompute_block_offsets (sheet);
222  gnucash_sheet_set_scroll_region (sheet);
223  gnucash_sheet_compute_visible_range (sheet);
224  gnucash_sheet_redraw_all (sheet);
225  }
226  else
227  gnucash_sheet_redraw_block (sheet, vcell_loc);
228 }
229 
230 void
232  VirtualCellLocation start_loc,
233  VirtualCellLocation end_loc)
234 {
235  GnucashSheet *sheet;
236 
237  if (!table || !table->ui_data)
238  return;
239 
240  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
241 
243  return;
244 
246  return;
247 
248  sheet = GNUCASH_SHEET (table->ui_data);
249 
250  gnucash_sheet_show_range (sheet, start_loc, end_loc);
251 }
252 
253 void
254 gnc_table_gnome_init (void)
255 {
256  TableGUIHandlers gui_handlers;
257 
258  gui_handlers.cursor_refresh = gnc_table_refresh_cursor_gnome;
259 
260  gnc_table_set_default_gui_handlers (&gui_handlers);
261 }
262 
Public declarations for GncLedgerDisplay class.
Functions to load, save and get gui state.
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
void gnc_table_init_gui(Table *table)
UI-specific functions.
Definition: table-gnome.c:173
void gnc_table_refresh_gui(Table *table, gboolean do_scroll)
Refresh the whole GUI from the table.
Definition: table-gnome.c:181
void gnc_table_show_range(Table *table, VirtualCellLocation start_loc, VirtualCellLocation end_loc)
Try to show the whole range in the register.
Definition: table-gnome.c:231
void gnc_table_set_default_gui_handlers(TableGUIHandlers *gui_handlers)
Implementation.
Definition: table-allgui.c:67
Public declarations of GnucashRegister class.
Private declarations for GnucashSheet class.
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
gboolean gnc_table_virtual_cell_out_of_bounds(Table *table, VirtualCellLocation vcell_loc)
checks the given location and returns true if it is out of bounds of the table.
Definition: table-allgui.c:207
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
Declarations for the Table object.
Styling functions for RegisterGnome.
void gnc_table_save_state(Table *table, const gchar *state_section)
Implementation.
Definition: table-gnome.c:71