From b4a29a9aca43490ebf44722cfd849404d0f37ec6 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 15 Mar 1998 19:07:15 +0000 Subject: [PATCH] new gui-independet table parts git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@646 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/table-allgui.c | 238 ++++++++++++++++++++++++++++++++++++ src/register/table-allgui.h | 52 ++++++++ 2 files changed, 290 insertions(+) create mode 100644 src/register/table-allgui.c create mode 100644 src/register/table-allgui.h diff --git a/src/register/table-allgui.c b/src/register/table-allgui.c new file mode 100644 index 0000000000..3f62dab82c --- /dev/null +++ b/src/register/table-allgui.c @@ -0,0 +1,238 @@ +/* + * FILE: + * table-allgui.c + * + * FUNCTION: + * Implements the gui-independent parts of the table infrastructure. + * + * HISTORY: + * Copyright (c) 1988 Linas Vepstas + */ + +/********************************************************************\ + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +\********************************************************************/ + +#include + +#include "cellblock.h" +#include "table-allgui.h" + +/* ==================================================== */ + +void +xaccTableResizeStringArr (Table * table, int num_phys_rows, int num_phys_cols) +{ + int old_phys_rows, old_phys_cols; + int i,j; + + /* save old table size */ + old_phys_rows = table->num_phys_rows; + old_phys_cols = table->num_phys_cols; + + table->num_phys_rows = num_phys_rows; + table->num_phys_cols = num_phys_cols; + + /* realloc to get the new table size. Note that the + * new table may be wider or slimmer, taller or shorter. */ + if (old_phys_rows >= num_phys_rows) { + if (old_phys_cols >= num_phys_cols) { + + /* if we are here, new table has fewer cols + * simply truncate columns */ + for (i=0; ientries[i][j]); + table->entries[i][j] = NULL; + } + } + } else { + + /* if we are here, the new table has more + * columns. Realloc the columns. */ + for (i=0; ientries[i]; + table->entries[i] = (char **) malloc (num_phys_cols * sizeof (char *)); + for (j=0; jentries[i][j] = old_row[j]; + } + for (j=old_phys_cols; jentries[i][j] = strdup (""); + } + free (old_row); + } + } + + /* new table has fewer rows. Simply truncate the rows */ + for (i=num_phys_rows; ientries[i][j]); + } + free (table->entries[i]); + table->entries[i] = NULL; + } + + } else { + char ***old_entries; + + if (old_phys_cols >= num_phys_cols) { + + /* new table has fewer columns. + * Simply truncate the columns */ + for (i=0; ientries[i][j]); + table->entries[i][j] = NULL; + } + } + } else { + + /* if we are here, the new table has more + * columns. Realloc the columns. */ + for (i=0; ientries[i]; + table->entries[i] = (char **) malloc (num_phys_cols * sizeof (char *)); + for (j=0; jentries[i][j] = old_row[j]; + } + for (j=old_phys_cols; jentries[i][j] = strdup (""); + } + free (old_row); + } + } + + /* now, add all new rows */ + old_entries = table->entries; + table->entries = (char ***) malloc (num_phys_rows * sizeof (char **)); + for (i=0; ientries[i] = old_entries[i]; + } + if (old_entries) free (old_entries); + + for (i=old_phys_rows; ientries[i] = (char **) malloc (num_phys_cols * sizeof (char *)); + for (j=0; jentries[i][j] = strdup (""); + } + } + } +} + +/* ==================================================== */ + +void +xaccTableResizeUserData (Table * table, int new_virt_rows, int new_virt_cols) +{ + int old_virt_rows, old_virt_cols; + int i,j; + + /* save old table size */ + old_virt_rows = table->num_virt_rows; + old_virt_cols = table->num_virt_cols; + + table->num_virt_rows = new_virt_rows; + table->num_virt_cols = new_virt_cols; + + /* realloc to get the new table size. Note that the + * new table may be wider or slimmer, taller or shorter. */ + if (old_virt_rows >= new_virt_rows) { + if (old_virt_cols >= new_virt_cols) { + + /* if we are here, new table has fewer cols + * simply truncate columns */ + for (i=0; iuser_data[i][j] = NULL; + } + } + } else { + + /* if we are here, the new table has more + * columns. Realloc the columns. */ + for (i=0; iuser_data[i]; + table->user_data[i] = (void **) malloc (new_virt_cols * sizeof (void *)); + for (j=0; juser_data[i][j] = old_row[j]; + } + for (j=old_virt_cols; juser_data[i][j] = NULL; + } + free (old_row); + } + } + + /* new table has fewer rows. Simply truncate the rows */ + for (i=new_virt_rows; iuser_data[i]); + table->user_data[i] = NULL; + } + + } else { + void ***old_user_data; + + if (old_virt_cols >= new_virt_cols) { + + /* new table has fewer columns. + * Simply truncate the columns */ + for (i=0; iuser_data[i][j] = NULL; + } + } + } else { + + /* if we are here, the new table has more + * columns. Realloc the columns. */ + for (i=0; iuser_data[i]; + table->user_data[i] = (void **) malloc (new_virt_cols * sizeof (void *)); + for (j=0; juser_data[i][j] = old_row[j]; + } + for (j=old_virt_cols; juser_data[i][j] = NULL; + } + free (old_row); + } + } + + /* now, add all new rows */ + old_user_data = table->user_data; + table->user_data = (void ***) malloc (new_virt_rows * sizeof (void **)); + for (i=0; iuser_data[i] = old_user_data[i]; + } + if (old_user_data) free (old_user_data); + + for (i=old_virt_rows; iuser_data[i] = (void **) malloc (new_virt_cols * sizeof (void *)); + for (j=0; juser_data[i][j] = NULL; + } + } + } +} + +/* ================== end of file ======================= */ diff --git a/src/register/table-allgui.h b/src/register/table-allgui.h new file mode 100644 index 0000000000..7c345e12b5 --- /dev/null +++ b/src/register/table-allgui.h @@ -0,0 +1,52 @@ +/* + * FILE: + * table-allgui.h + * + * FUNCTION: + * Implements the gui-independent parts of the table infrastructure. + * + * HISTORY: + * Copyright (c) 1988 Linas Vepstas + */ + +/********************************************************************\ + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +\********************************************************************/ + +#ifndef __XACC_TABLE_ALLGUI_H__ +#define __XACC_TABLE_ALLGUI_H__ + +/* hack-alert, to pick up the table definition. + * since C lacks the inheritance of C++ + * fix this someday. + */ +#define XMOTIF +#ifdef XMOTIF +#include "table-motif.h" +#endif + +#ifdef GNOME +#include "table-gtk.h" +#endif + +extern void +xaccTableResizeStringArr (Table * table, int num_phys_rows, int num_phys_cols); + +extern void +xaccTableResizeUserData (Table * table, int new_virt_rows, int new_virt_cols); + +#endif /* __XACC_TABLE_ALLGUI_H__ */ + +/* ================== end of file ======================= */