GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 [email protected] *
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 <[email protected]>
34  * Copyright (c) 1999 Heath Martin <[email protected]>
35  * Copyright (c) 2000 Heath Martin <[email protected]>
36  * Copyright (c) 2000 Dave Peticolas <[email protected]>
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 
46 #include "gnucash-sheet.h"
47 #include "gnucash-sheetP.h"
48 #include "gnucash-style.h"
49 #include "table-allgui.h"
50 #include "table-gnome.h"
51 #include "gnc-prefs.h"
52 #include "gnc-engine.h"
53 #include "gnc-state.h"
54 
55 #include "gnc-ledger-display.h"
56 
57 
58 
61 /* This static indicates the debugging module that this .o belongs to. */
62 static QofLogModule log_module = GNC_MOD_REGISTER;
63 
64 
67 void
68 gnc_table_save_state (Table *table, gchar * state_section)
69 {
70  GnucashSheet *sheet;
71  GNCHeaderWidths widths;
72  GList *node;
73  gchar *key;
74  GKeyFile *state_file = gnc_state_get_current();
75 
76  if (!table)
77  return;
78 
79  if (table->ui_data == NULL)
80  return;
81 
82  if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
83  return;
84 
85  sheet = GNUCASH_SHEET (table->ui_data);
86 
87  widths = gnc_header_widths_new ();
88 
89  gnucash_sheet_get_header_widths (sheet, widths);
90 
91  node = gnc_table_layout_get_cells (table->layout);
92  for (; node; node = node->next)
93  {
94  BasicCell *cell = node->data;
95  int width;
96 
97  width = gnc_header_widths_get_width (widths, cell->cell_name);
98 
99  /* Remember whether the column is visible */
100  key = g_strdup_printf("%s_width", cell->cell_name);
101  if ((width > 0) && (!cell->expandable))
102  {
103  g_key_file_set_integer (state_file, state_section, key, width);
104  }
105  else if (g_key_file_has_key (state_file, state_section, key, NULL))
106  g_key_file_remove_key (state_file, state_section, key, NULL);
107  g_free (key);
108  }
109 
110  gnc_header_widths_destroy (widths);
111 }
112 
113 static void
114 table_ui_redraw_cb (Table *table)
115 {
116  GnucashSheet *sheet;
117 
118  if (table == NULL)
119  return;
120 
121  if (table->ui_data == NULL)
122  return;
123 
124  sheet = GNUCASH_SHEET (table->ui_data);
125 
126  gnucash_sheet_redraw_help (sheet);
127 }
128 
129 static void
130 table_destroy_cb (Table *table)
131 {
132  GnucashSheet *sheet;
133 
134  if (table == NULL)
135  return;
136 
137  if (table->ui_data == NULL)
138  return;
139 
140  sheet = GNUCASH_SHEET (table->ui_data);
141 
142  g_object_unref (sheet);
143 
144  table->ui_data = NULL;
145 }
146 
147 
148 /* Um, this function checks that data is not null but never uses it.
149  Weird. Also, since this function only works with a GnucashRegister
150  widget, maybe some of it should be moved to gnucash-sheet.c. */
151 /* Adding to previous note: Since data doesn't appear do anything and to
152  align the function with save_state() I've removed the check for
153  NULL and changed two calls in dialog_order.c and dialog_invoice.c
154  to pass NULL as second parameter. */
155 
156 void
157 gnc_table_init_gui (GtkWidget *widget, gchar * state_section)
158 {
159  GNCHeaderWidths widths;
160  GnucashSheet *sheet;
161  GnucashRegister *greg;
162  Table *table;
163  GList *node;
164  gchar *key;
165  guint value;
166  GKeyFile *state_file = gnc_state_get_current();
167 
168  // Stuff for per-register settings load.
169  g_return_if_fail (widget != NULL);
170  g_return_if_fail (GNUCASH_IS_REGISTER (widget));
171 
172  PINFO("state_section=%s",state_section);
173 
174  ENTER("widget=%p, data=%p", widget, "");
175 
176 
177  greg = GNUCASH_REGISTER (widget);
178  sheet = GNUCASH_SHEET (greg->sheet);
179  table = sheet->table;
180 
181  table->gui_handlers.redraw_help = table_ui_redraw_cb;
182  table->gui_handlers.destroy = table_destroy_cb;
183  table->ui_data = sheet;
184 
185  g_object_ref (sheet);
186 
187  /* config the cell-block styles */
188 
189  widths = gnc_header_widths_new ();
190 
191  if (state_section && gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
192  {
193  node = gnc_table_layout_get_cells (table->layout);
194  for (; node; node = node->next)
195  {
196  BasicCell *cell = node->data;
197 
198  if (cell->expandable)
199  continue;
200 
201  /* Remember whether the column is visible */
202  key = g_strdup_printf("%s_width", cell->cell_name);
203  value = g_key_file_get_integer (state_file, state_section, key, NULL);
204  if (value != 0)
205  gnc_header_widths_set_width (widths, cell->cell_name, value);
206  g_free(key);
207  }
208  }
209 
210  gnucash_sheet_create_styles (sheet);
211 
212  gnucash_sheet_set_header_widths (sheet, widths);
213 
214  gnucash_sheet_compile_styles (sheet);
215 
216  gnucash_sheet_table_load (sheet, TRUE);
217  gnucash_sheet_cursor_set_from_table (sheet, TRUE);
218  gnucash_sheet_redraw_all (sheet);
219 
220  gnc_header_widths_destroy (widths);
221 
222  LEAVE(" ");
223 }
224 
225 void
226 gnc_table_refresh_gui (Table * table, gboolean do_scroll)
227 {
228  GnucashSheet *sheet;
229 
230  if (!table)
231  return;
232  if (!table->ui_data)
233  return;
234 
235  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
236 
237  sheet = GNUCASH_SHEET(table->ui_data);
238 
239  gnucash_sheet_styles_recompile (sheet);
240  gnucash_sheet_table_load (sheet, do_scroll);
241  gnucash_sheet_redraw_all (sheet);
242 }
243 
244 
245 static void
246 gnc_table_refresh_cursor_gnome (Table * table,
247  VirtualCellLocation vcell_loc,
248  gboolean do_scroll)
249 {
250  GnucashSheet *sheet;
251 
252  if (!table || !table->ui_data)
253  return;
254 
255  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
256 
257  if (gnc_table_virtual_cell_out_of_bounds (table, vcell_loc))
258  return;
259 
260  sheet = GNUCASH_SHEET (table->ui_data);
261 
262  gnucash_sheet_cursor_set_from_table (sheet, do_scroll);
263 
264  if (gnucash_sheet_block_set_from_table (sheet, vcell_loc))
265  {
266  gnucash_sheet_recompute_block_offsets (sheet);
267  gnucash_sheet_set_scroll_region (sheet);
268  gnucash_sheet_compute_visible_range (sheet);
269  gnucash_sheet_redraw_all (sheet);
270  }
271  else
272  gnucash_sheet_redraw_block (sheet, vcell_loc);
273 }
274 
275 void
276 gnc_table_show_range (Table *table,
277  VirtualCellLocation start_loc,
278  VirtualCellLocation end_loc)
279 {
280  GnucashSheet *sheet;
281 
282  if (!table || !table->ui_data)
283  return;
284 
285  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
286 
287  if (gnc_table_virtual_cell_out_of_bounds (table, start_loc))
288  return;
289 
290  if (gnc_table_virtual_cell_out_of_bounds (table, end_loc))
291  return;
292 
293  sheet = GNUCASH_SHEET (table->ui_data);
294 
295  gnucash_sheet_show_range (sheet, start_loc, end_loc);
296 }
297 
298 void
299 gnc_table_gnome_init (void)
300 {
301  TableGUIHandlers gui_handlers;
302 
303  gui_handlers.cursor_refresh = gnc_table_refresh_cursor_gnome;
304 
305  gnc_table_set_default_gui_handlers (&gui_handlers);
306 }
307 
Functions to load, save and get gui state.
#define PINFO(format, args...)
Definition: qoflog.h:249
void gnc_table_set_default_gui_handlers(TableGUIHandlers *gui_handlers)
Definition: table-allgui.c:67
#define ENTER(format, args...)
Definition: qoflog.h:261
GKeyFile * gnc_state_get_current(void)
Definition: gnc-state.c:252
void gnc_table_save_state(Table *table, gchar *state_section)
Definition: table-gnome.c:68
void gnc_table_init_gui(GtkWidget *widget, gchar *state_section)
Definition: table-gnome.c:157
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:196
Declarations for the Table object.
#define LEAVE(format, args...)
Definition: qoflog.h:271
const gchar * QofLogModule
Definition: qofid.h:89