GnuCash  4.11-11-ge9df8d41d2+
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 
149 /* Um, this function checks that data is not null but never uses it.
150  Weird. Also, since this function only works with a GnucashRegister
151  widget, maybe some of it should be moved to gnucash-sheet.c. */
152 /* Adding to previous note: Since data doesn't appear do anything and to
153  align the function with save_state() I've removed the check for
154  NULL and changed two calls in dialog_order.c and dialog_invoice.c
155  to pass NULL as second parameter. */
156 
157 void
159 {
160  table->gui_handlers.redraw_help = table_ui_redraw_cb;
161  table->gui_handlers.destroy = table_destroy_cb;
162 }
163 
164 void
165 gnc_table_refresh_gui (Table * table, gboolean do_scroll)
166 {
167  GnucashSheet *sheet;
168 
169  if (!table)
170  return;
171  if (!table->ui_data)
172  return;
173 
174  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
175 
176  sheet = GNUCASH_SHEET(table->ui_data);
177 
178  gnucash_sheet_styles_recompile (sheet);
179  gnucash_sheet_table_load (sheet, do_scroll);
180  gnucash_sheet_redraw_all (sheet);
181 }
182 
183 
184 static void
185 gnc_table_refresh_cursor_gnome (Table * table,
186  VirtualCellLocation vcell_loc,
187  gboolean do_scroll)
188 {
189  GnucashSheet *sheet;
190 
191  if (!table || !table->ui_data)
192  return;
193 
194  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
195 
197  return;
198 
199  sheet = GNUCASH_SHEET (table->ui_data);
200 
201  gnucash_sheet_cursor_set_from_table (sheet, do_scroll);
202 
203  if (gnucash_sheet_block_set_from_table (sheet, vcell_loc))
204  {
205  gnucash_sheet_recompute_block_offsets (sheet);
206  gnucash_sheet_set_scroll_region (sheet);
207  gnucash_sheet_compute_visible_range (sheet);
208  gnucash_sheet_redraw_all (sheet);
209  }
210  else
211  gnucash_sheet_redraw_block (sheet, vcell_loc);
212 }
213 
214 void
216  VirtualCellLocation start_loc,
217  VirtualCellLocation end_loc)
218 {
219  GnucashSheet *sheet;
220 
221  if (!table || !table->ui_data)
222  return;
223 
224  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
225 
227  return;
228 
230  return;
231 
232  sheet = GNUCASH_SHEET (table->ui_data);
233 
234  gnucash_sheet_show_range (sheet, start_loc, end_loc);
235 }
236 
237 void
238 gnc_table_gnome_init (void)
239 {
240  TableGUIHandlers gui_handlers;
241 
242  gui_handlers.cursor_refresh = gnc_table_refresh_cursor_gnome;
243 
244  gnc_table_set_default_gui_handlers (&gui_handlers);
245 }
246 
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:158
void gnc_table_refresh_gui(Table *table, gboolean do_scroll)
Refresh the whole GUI from the table.
Definition: table-gnome.c:165
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:215
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