GnuCash 2.4.99
table-gnome.c
00001 /********************************************************************\
00002  * table-gnome.c -- implementation of table object in GNOME         *
00003  *                                                                  *
00004  * This program is free software; you can redistribute it and/or    *
00005  * modify it under the terms of the GNU General Public License as   *
00006  * published by the Free Software Foundation; either version 2 of   *
00007  * the License, or (at your option) any later version.              *
00008  *                                                                  *
00009  * This program is distributed in the hope that it will be useful,  *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00012  * GNU General Public License for more details.                     *
00013  *                                                                  *
00014  * You should have received a copy of the GNU General Public License*
00015  * along with this program; if not, contact:                        *
00016  *                                                                  *
00017  * Free Software Foundation           Voice:  +1-617-542-5942       *
00018  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00019  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00020  *                                                                  *
00021 \********************************************************************/
00022 
00023 /*
00024  * FILE:
00025  * table-gnome.c
00026  *
00027  * FUNCTION:
00028  * Implements the infrastructure for the displayed table.
00029  * This is the Gnome implementation.
00030  *
00031  * HISTORY:
00032  * Copyright (c) 1998 Linas Vepstas
00033  * Copyright (c) 1998 Rob Browning <rlb@cs.utexas.edu>
00034  * Copyright (c) 1999 Heath Martin <martinh@pegasus.cc.ucf.edu>
00035  * Copyright (c) 2000 Heath Martin <martinh@pegasus.cc.ucf.edu>
00036  * Copyright (c) 2000 Dave Peticolas <dave@krondo.com>
00037  * Copyright (c) 2001 Gnumatic, Inc.
00038  */
00039 
00040 #include "config.h"
00041 
00042 #include <gnome.h>
00043 #include <libguile.h>
00044 #include <stdio.h>
00045 #include <stdlib.h>
00046 #include <string.h>
00047 
00048 #include "gnucash-sheet.h"
00049 #include "gnucash-style.h"
00050 #include "table-allgui.h"
00051 #include "table-gnome.h"
00052 #include "guile-mappings.h"
00053 #include "gnc-gconf-utils.h"
00054 #include "gnc-engine.h"
00055 
00056 #define GCONF_SECTION "window/pages/register"
00057 
00058 
00061 /* This static indicates the debugging module that this .o belongs to. */
00062 static QofLogModule log_module = GNC_MOD_REGISTER;
00063 
00064 
00067 void
00068 gnc_table_save_state (Table *table)
00069 {
00070     GnucashSheet *sheet;
00071     GNCHeaderWidths widths;
00072     GList *node;
00073     gchar *key;
00074 
00075     if (!table)
00076         return;
00077 
00078     if (table->ui_data == NULL)
00079         return;
00080 
00081     if (!gnc_gconf_get_bool(GCONF_GENERAL, KEY_SAVE_GEOMETRY, NULL))
00082         return;
00083 
00084     sheet = GNUCASH_SHEET (table->ui_data);
00085 
00086     widths = gnc_header_widths_new ();
00087 
00088     gnucash_sheet_get_header_widths (sheet, widths);
00089 
00090     node = gnc_table_layout_get_cells (table->layout);
00091     for (; node; node = node->next)
00092     {
00093         BasicCell *cell = node->data;
00094         int width;
00095 
00096         width = gnc_header_widths_get_width (widths, cell->cell_name);
00097         if (width <= 0)
00098             continue;
00099 
00100         if (cell->expandable)
00101             continue;
00102 
00103         /* Remember whether the column is visible */
00104         key = g_strdup_printf("%s_width", cell->cell_name);
00105         gnc_gconf_set_int(GCONF_SECTION, key, width, NULL);
00106         g_free(key);
00107     }
00108 
00109     gnc_header_widths_destroy (widths);
00110 }
00111 
00112 static void
00113 table_ui_redraw_cb (Table *table)
00114 {
00115     GnucashSheet *sheet;
00116 
00117     if (table == NULL)
00118         return;
00119 
00120     if (table->ui_data == NULL)
00121         return;
00122 
00123     sheet = GNUCASH_SHEET (table->ui_data);
00124 
00125     gnucash_sheet_redraw_help (sheet);
00126 }
00127 
00128 static void
00129 table_destroy_cb (Table *table)
00130 {
00131     GnucashSheet *sheet;
00132 
00133     if (table == NULL)
00134         return;
00135 
00136     if (table->ui_data == NULL)
00137         return;
00138 
00139     sheet = GNUCASH_SHEET (table->ui_data);
00140 
00141     g_object_unref (sheet);
00142 
00143     table->ui_data = NULL;
00144 }
00145 
00146 
00147 /* Um, this function checks that data is not null but never uses it.
00148    Weird.  Also, since this function only works with a GnucashRegister
00149    widget, maybe some of it should be moved to gnucash-sheet.c. */
00150 void
00151 gnc_table_init_gui (GtkWidget *widget, void *data)
00152 {
00153     GNCHeaderWidths widths;
00154     GnucashSheet *sheet;
00155     GnucashRegister *greg;
00156     Table *table;
00157     GList *node;
00158     gchar *key;
00159     guint value;
00160 
00161     g_return_if_fail (widget != NULL);
00162     g_return_if_fail (GNUCASH_IS_REGISTER (widget));
00163     g_return_if_fail (data != NULL);
00164 
00165     ENTER("widget=%p, data=%p", widget, data);
00166 
00167     greg = GNUCASH_REGISTER (widget);
00168     sheet = GNUCASH_SHEET (greg->sheet);
00169     table = sheet->table;
00170 
00171     table->gui_handlers.redraw_help = table_ui_redraw_cb;
00172     table->gui_handlers.destroy = table_destroy_cb;
00173     table->ui_data = sheet;
00174 
00175     g_object_ref (sheet);
00176 
00177     /* config the cell-block styles */
00178 
00179     widths = gnc_header_widths_new ();
00180 
00181     if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_SAVE_GEOMETRY, NULL))
00182     {
00183         node = gnc_table_layout_get_cells (table->layout);
00184         for (; node; node = node->next)
00185         {
00186             BasicCell *cell = node->data;
00187 
00188             if (cell->expandable)
00189                 continue;
00190 
00191             /* Remember whether the column is visible */
00192             key = g_strdup_printf("%s_width", cell->cell_name);
00193             value = gnc_gconf_get_int(GCONF_SECTION, key, NULL);
00194             if (value != 0)
00195                 gnc_header_widths_set_width (widths, cell->cell_name, value);
00196             g_free(key);
00197         }
00198     }
00199 
00200     gnucash_sheet_create_styles (sheet);
00201 
00202     gnucash_sheet_set_header_widths (sheet, widths);
00203 
00204     gnucash_sheet_compile_styles (sheet);
00205 
00206     gnucash_sheet_table_load (sheet, TRUE);
00207     gnucash_sheet_cursor_set_from_table (sheet, TRUE);
00208     gnucash_sheet_redraw_all (sheet);
00209 
00210     gnc_header_widths_destroy (widths);
00211 
00212     LEAVE(" ");
00213 }
00214 
00215 void
00216 gnc_table_refresh_gui (Table * table, gboolean do_scroll)
00217 {
00218     GnucashSheet *sheet;
00219 
00220     if (!table)
00221         return;
00222     if (!table->ui_data)
00223         return;
00224 
00225     g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
00226 
00227     sheet = GNUCASH_SHEET(table->ui_data);
00228 
00229     gnucash_sheet_styles_recompile (sheet);
00230     gnucash_sheet_table_load (sheet, do_scroll);
00231     gnucash_sheet_redraw_all (sheet);
00232 }
00233 
00234 
00235 static void
00236 gnc_table_refresh_cursor_gnome (Table * table,
00237                                 VirtualCellLocation vcell_loc,
00238                                 gboolean do_scroll)
00239 {
00240     GnucashSheet *sheet;
00241 
00242     if (!table || !table->ui_data)
00243         return;
00244 
00245     g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
00246 
00247     if (gnc_table_virtual_cell_out_of_bounds (table, vcell_loc))
00248         return;
00249 
00250     sheet = GNUCASH_SHEET (table->ui_data);
00251 
00252     gnucash_sheet_cursor_set_from_table (sheet, do_scroll);
00253 
00254     if (gnucash_sheet_block_set_from_table (sheet, vcell_loc))
00255     {
00256         gnucash_sheet_recompute_block_offsets (sheet);
00257         gnucash_sheet_set_scroll_region (sheet);
00258         gnucash_sheet_compute_visible_range (sheet);
00259         gnucash_sheet_redraw_all (sheet);
00260     }
00261     else
00262         gnucash_sheet_redraw_block (sheet, vcell_loc);
00263 }
00264 
00265 void
00266 gnc_table_show_range (Table *table,
00267                       VirtualCellLocation start_loc,
00268                       VirtualCellLocation end_loc)
00269 {
00270     GnucashSheet *sheet;
00271 
00272     if (!table || !table->ui_data)
00273         return;
00274 
00275     g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
00276 
00277     if (gnc_table_virtual_cell_out_of_bounds (table, start_loc))
00278         return;
00279 
00280     if (gnc_table_virtual_cell_out_of_bounds (table, end_loc))
00281         return;
00282 
00283     sheet = GNUCASH_SHEET (table->ui_data);
00284 
00285     gnucash_sheet_show_range (sheet, start_loc, end_loc);
00286 }
00287 
00288 void
00289 gnc_table_gnome_init (void)
00290 {
00291     TableGUIHandlers gui_handlers;
00292 
00293     gui_handlers.cursor_refresh = gnc_table_refresh_cursor_gnome;
00294 
00295     gnc_table_set_default_gui_handlers (&gui_handlers);
00296 }
00297 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines