move gui-independent parts of table out of gtk, motif code

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@865 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-06-01 03:24:16 +00:00
parent dc78507a70
commit e980652775
8 changed files with 301 additions and 422 deletions

View File

@ -42,18 +42,12 @@
#define __XACC_REGISTER_H__
#include "basiccell.h"
#include "cellblock.h"
#include "combocell.h"
#include "datecell.h"
#include "quickfillcell.h"
#include "pricecell.h"
#ifdef MOTIF
#include "table-motif.h"
#endif
#ifdef GNOME
#include "table-gtk.h"
#endif
#include "table-allgui.h"
/* defined register types */
/* "registers" are single-account display windows.

View File

@ -39,18 +39,12 @@
#define __XACC_SPLITREG_H__
#include "basiccell.h"
#include "cellblock.h"
#include "combocell.h"
#include "datecell.h"
#include "quickfillcell.h"
#include "pricecell.h"
#ifdef MOTIF
#include "table-motif.h"
#endif
#ifdef GNOME
#include "table-gtk.h"
#endif
#include "table-allgui.h"
/* defined register types */
/* "registers" are single-account display windows.

View File

@ -25,12 +25,94 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
\********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cellblock.h"
#include "table-allgui.h"
/* ==================================================== */
Table *
xaccMallocTable (void)
{
Table *table;
table = (Table *) malloc (sizeof (Table));
xaccInitTable (table);
return table;
}
/* ==================================================== */
void
xaccInitTable (Table * table)
{
table->num_phys_rows = -1;
table->num_phys_cols = -1;
table->num_virt_rows = -1;
table->num_virt_cols = -1;
table->current_cursor = NULL;
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->move_cursor = NULL;
table->client_data = NULL;
table->entries = NULL;
table->locators = NULL;
table->user_data = NULL;
table->handlers = NULL;
/* invalidate the "previous" traversed cell */
table->prev_phys_traverse_row = -1;
table->prev_phys_traverse_col = -1;
/* call the "derived" class constructor */
TABLE_PRIVATE_DATA_INIT (table);
}
/* ==================================================== */
void
xaccDestroyTable (Table * table)
{
/* call derived class destructor */
TABLE_PRIVATE_DATA_DESTROY (table);
/* free the gui-independent parts */
xaccFreeTableEntries (table);
/* intialize vars to null value so that any access is voided. */
xaccInitTable (table);
free (table);
}
/* ==================================================== */
void
xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
int virt_rows, int virt_cols)
{
xaccTableResize (table, phys_rows, phys_cols, virt_rows, virt_cols);
/* invalidate the "previous" traversed cell */
table->prev_phys_traverse_row = -1;
table->prev_phys_traverse_col = -1;
/* invalidate the current cursor position, if needed */
if ((table->current_cursor_virt_row >= table->num_virt_rows) ||
(table->current_cursor_virt_col >= table->num_virt_cols)) {
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->current_cursor = NULL;
}
}
/* ==================================================== */
/* in C, we don't have templates. So cook up a $define that acts like a

View File

@ -3,6 +3,12 @@
* table-allgui.h
*
* FUNCTION:
* The table is the complete, displayed table.
* It consists of a header, followed by a simple
* list of repeated entries.
*
* It provides the mechanism to handle tab-trversing.
*
* Implements the gui-independent parts of the table infrastructure.
*
* HISTORY:
@ -28,12 +34,6 @@
#ifndef __XACC_TABLE_ALLGUI_H__
#define __XACC_TABLE_ALLGUI_H__
/* hack alert -- move a portion of the gui-independent
* table structure definition, currentlu in table-motif.h,
* to here. But C lacks the inheritance of C++, so this
* is ugly.
*/
#ifdef MOTIF
#include "table-motif.h"
#endif
@ -42,6 +42,113 @@
#include "table-gtk.h"
#endif
#include "basiccell.h"
#include "cellblock.h"
/* the Locator structure is used provide a mapping from
* the physical array of cells to the logical array of
* virtual cell blocks.
*
* There is one instance of Locator for each physical cell.
* The virt_row and virt_col members identify the corresponding
* cellblock/virtual cell that this physical cell is a member of.
* The two phys_offsets provide the location of the physical cell
* as an offset from the cell block origin. That is, the offsets
* should never be less than zero, or greater than the size of
* the cell block.
*/
struct _Locator {
short phys_row_offset;
short phys_col_offset;
short virt_row;
short virt_col;
};
typedef struct _Locator Locator;
/* The number of "physical" rows/cols is the number
* of displayed one-line gui rows/cols in the table.
* The number of physical rows can differ from the
* number of "virtual" rows because each virtual row
* consist of one or more physical rows.
*
* Given the location of a physical row & col, the corresponding
* virtual row & col can be found by looking it up in the
* "locators" member. The locator will provide the matching
* virtual row and column.
*
* Given the location of the virtual row and column, the
* corresponding GUI handler, and any associated user data can
* be directly accessed.
*/
struct _Table {
int num_phys_rows;
int num_phys_cols;
int num_virt_rows;
int num_virt_cols;
/* the current cursor row/col is the virt row/col */
CellBlock *current_cursor;
int current_cursor_phys_row;
int current_cursor_phys_col;
int current_cursor_virt_row;
int current_cursor_virt_col;
/* callback that is called when the cursor is moved */
/* hack alert -- this should be a callback list, actually */
void (*move_cursor) (Table *, void *client_data);
void * client_data;
/* string values for each cell,
* of dimension num_phys_rows * num_phys_cols */
char ***entries;
/* handler locators for each cell,
* of dimension num_phys_rows * num_phys_cols */
Locator ***locators;
/* user hooks, of dimension num_virt_rows * num_virt_cols */
void ***user_data;
/* cell blocks, of dimension num_virt_rows * num_virt_cols */
CellBlock ***handlers;
/* private data, caches, etc. */
/* This is black-box stuff that no user of this class
* should ever want to access */
/* This class implements tab-key and arrow key
* traversal through the cells of the table.
* To perform this traversal, the location
* of the "previous" cell having input focus
* is required.
*/
int prev_phys_traverse_row;
int prev_phys_traverse_col;
/* Since we are using C not C++, but we need inheritance,
* cock it up with a #defined thingy that the "derived class"
* can specify.
*/
TABLE_PRIVATE_DATA;
};
Table * xaccMallocTable (void);
void xaccInitTable (Table *);
void xaccDestroyTable (Table *);
/* The xaccSetTableSize() method will resize the table to the
* indicated dimensions. This method calls the gui-independent
* xaccTableResize() routine, and then does some motif-specific
* cleanup.
*/
void xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
int virt_rows, int virt_cols);
/* free the gui-independent parts of the table structure. */
void xaccFreeTableEntries (Table *);
@ -66,7 +173,7 @@ void xaccMoveCursorGUI (Table *, int phys_row, int phys_col);
/* copy text in the cursor cells to the table */
void xaccCommitCursor (Table *);
/* hackl alert --
/* hack alert --
* for all practical purposes, RefreshHeader is identical
* tp CommitCursor(), except that it acts on cellblock 0,0.
* it should probably be made obsolete.

View File

@ -57,108 +57,14 @@
/* ==================================================== */
Table *
xaccMallocTable (void)
{
Table *table;
table = (Table *) malloc (sizeof (Table));
xaccInitTable (table);
return table;
}
/* ==================================================== */
void
xaccInitTable (Table * table)
{
table->table_widget = NULL;
table->entry_frame = NULL;
table->entry_widget = NULL;
table->current_col = -1; /* coords ignoring header lines */
table->current_row = -1;
table->prev_entry_text = NULL;
table->next_tab_group = 0;
table->num_phys_rows = -1;
table->num_phys_cols = -1;
table->num_virt_rows = -1;
table->num_virt_cols = -1;
table->current_cursor = NULL;
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->move_cursor = NULL;
table->client_data = NULL;
table->entries = NULL;
table->locators = NULL;
table->user_data = NULL;
table->handlers = NULL;
/* invalidate the "previous" traversed cell */
table->prev_phys_traverse_row = -1;
table->prev_phys_traverse_col = -1;
}
/* ==================================================== */
void
xaccDestroyTable (Table * table)
{
/* free the gui-independent parts */
xaccFreeTableEntries (table);
/* Let GTK know we're finished with this */
if(table->table_widget) gtk_widget_unref(table->table_widget);
if(table->entry_frame) gtk_widget_unref(table->entry_frame);
if(table->entry_widget) gtk_widget_unref(table->entry_widget);
table->table_widget = NULL;
table->entry_frame = NULL;
table->entry_widget = NULL;
g_free(table->prev_entry_text); table->prev_entry_text = NULL;
/* intialize vars to null value so that any access is voided. */
xaccInitTable (table);
free (table);
}
/* ==================================================== */
void
xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
int virt_rows, int virt_cols)
{
xaccTableResize (table, phys_rows, phys_cols, virt_rows, virt_cols);
/* invalidate the "previous" traversed cell */
table->prev_phys_traverse_row = -1;
table->prev_phys_traverse_col = -1;
/* invalidate the current cursor position, if needed */
if ((table->current_cursor_virt_row >= table->num_virt_rows) ||
(table->current_cursor_virt_col >= table->num_virt_cols)) {
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->current_cursor = NULL;
}
}
/* ==================================================== */
void
xaccNextTabGroup (Table *table, GtkWidget * w)
{
table->next_tab_group = w;
}
/* ==================================================== */
static int
verify_cell_interaction_OK(Table *table, const int row, const int col)
{
@ -301,6 +207,8 @@ cell_entered(Table *table, const int row, const int col)
table->prev_phys_traverse_col = col;
}
/* ==================================================== */
static void
compute_string_single_change(const gchar *a, const gchar *b, gchar **result) {
/* Compute the change from a to b assuming that the changed region
@ -573,6 +481,8 @@ traverseCB (GtkWidget * mw, gpointer cd, gpointer cb)
#endif
/* ==================================================== */
static int counter;
static void
@ -599,6 +509,8 @@ table_edit_entry_cb(GtkEntry *entry, gpointer user_data) {
}
}
/* ==================================================== */
static void
table_select_row_cb(GtkCList *cl, gint row, gint column, GdkEventButton *e,
gpointer user_data) {
@ -762,8 +674,8 @@ xaccCreateTable (Table *table, GtkWidget * parent)
}
}
/* if any of the cells have GUI specific components that need
* initialization, initialize them now.
/* if any of the cells have GUI specific components that
* need initialization, initialize them now.
* The cell realize method, if present on a cell,
* is how that cell can find out that now is the time to
* initialize that GUI.

View File

@ -9,16 +9,6 @@
*
* It provides the mechanism to handle tab-traversal.
*
* hack alert -- this file and the corresponding one
* for motif share some basic comon code.
* C++ style inheritance from a coon base class would
* solve this problem, but with just C, there is no easy
* way to accomplish this.
*
* In particular, the file table-motif.h contains a fair
* amount of documentation for these comon parts ...
*
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 1998 Rob Browning <rlb@cs.utexas.edu>
@ -45,115 +35,70 @@
#define __XACC_TABLE_GTK_H__
#include <gtk/gtk.h>
#include "basiccell.h"
#include "cellblock.h"
/* the Locator structure is used provide a mapping from
* the physical array of cells to the logical array of
* virtual cell blocks.
*
* There is one instance of Locator for each physical cell.
* The virt_row and virt_col members identify the corresponding
* cellblock/virtual cell that this physical cell is a member of.
* The two phys_offsets provide the location of the physical cell
* as an offset from the cell block origin. That is, the offsets
* should never be less than zero, or greater than the size of
* the cell block.
*/
struct _Locator {
short phys_row_offset;
short phys_col_offset;
short virt_row;
short virt_col;
};
typedef struct _Locator Locator;
typedef struct _Table Table;
struct _Table {
/* The number of "physical" rows/cols is the number
* of displayed one-line gui rows/cols in the table.
* The number of physical rows can differ from the
* number of "virtual" rows because each virtual row
* consist of one or more physical rows.
*/
int num_phys_rows;
int num_phys_cols;
int num_virt_rows;
int num_virt_cols;
/* the current cursor row/col is the virt row/col */
CellBlock *current_cursor;
int current_cursor_phys_row;
int current_cursor_phys_col;
int current_cursor_virt_row;
int current_cursor_virt_col;
/* callback that is called when the cursor is moved */
/* hack alert -- this should be a callback list, actually */
void (*move_cursor) (Table *, void *client_data);
void * client_data;
/* string values for each cell,
* of dimension num_phys_rows * num_phys_cols */
char ***entries;
/* handler locators for each cell,
* of dimension num_phys_rows * num_phys_cols */
Locator ***locators;
/* user hooks, of dimension num_virt_rows * num_virt_cols */
void ***user_data;
/* cell blocks, of dimension num_virt_rows * num_virt_cols */
CellBlock ***handlers;
/* private data, caches, etc. */
/* This is black-box stuff that no user of this class
* should ever want to access */
/* This class implements tab-key and arrow key
* traversal through the cells of the table.
* To perform this traversal, the location
* of the "previous" cell having input focus
* is required.
*/
int prev_phys_traverse_row;
int prev_phys_traverse_col;
/* Gtk-only date below, gui-independent data above */
/* protected data -- vital for the implementation,
* but not something we want to generally expose */
GtkWidget *table_widget; /* the CList */
GtkWidget *entry_frame; /* the editing widget frame */
GtkWidget *entry_widget; /* the current cell editing widget */
/* Current editing cell */
int current_col;
int current_row;
/* snapshot of entry text -- used to detect changes in callback */
char *prev_entry_text;
GtkWidget *next_tab_group; /* where to traverse in the end */
};
Table * xaccMallocTable (void);
void xaccInitTable (Table *);
void xaccDestroyTable (Table *);
/* resize the table to the indicated dimensions.
* calls the gui-independent xaccTableResize() routine,
* and then does some gtk-specific cleanup.
/* We use C not C++ in this project, but we none-the-less need
* the general mechanism of inheritance. The three #defines
* below implement that.
*
* the TABLE_PRIVATE_DATA declaration should be thought of as a
* "derived class" of which Table is the base class. This
* define is included as a part of the definition of the Table
* structure in table-allgui.h
*
* The TABLE_PRIVATE_DATA_INIT and DESTROY are the constructors
* and destructors, respectively, for this derived class.
* These are included in the xaccTableInit() and the xaccTableDestroy()
* routines in the file table-allgui.c, where they are called,
* respectively, last, and first, just as "real" constructors &
* destructors would be
*/
void xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
int virt_rows, int virt_cols);
#define TABLE_PRIVATE_DATA \
/* Gtk-only private table members */ \
GtkWidget *table_widget; /* the CList */ \
GtkWidget *entry_frame; /* the editing widget frame */ \
GtkWidget *entry_widget; /* the current cell editing widget */\
\
/* Current editing cell */ \
int current_col; \
int current_row; \
\
/* snapshot of entry text -- used to detect changes in callback */ \
char *prev_entry_text; \
\
GtkWidget *next_tab_group; /* where to traverse in the end */ \
#define TABLE_PRIVATE_DATA_INIT(table) { \
table->table_widget = NULL; \
table->entry_frame = NULL; \
table->entry_widget = NULL; \
\
table->current_col = -1; /* coords ignoring header lines */ \
table->current_row = -1; \
table->prev_entry_text = NULL; \
\
table->next_tab_group = 0; \
}
#define TABLE_PRIVATE_DATA_DESTROY(table) { \
\
/* Let GTK know we're finished with this */ \
if(table->table_widget) gtk_widget_unref(table->table_widget); \
if(table->entry_frame) gtk_widget_unref(table->entry_frame); \
if(table->entry_widget) gtk_widget_unref(table->entry_widget); \
table->table_widget = NULL; \
table->entry_frame = NULL; \
table->entry_widget = NULL; \
\
g_free(table->prev_entry_text); table->prev_entry_text = NULL; \
}
typdef struct _Table Table;
/* create the GtkWidget */
GtkWidget *xaccCreateTable (Table *, GtkWidget *parent);

View File

@ -49,87 +49,6 @@ static XrmQuark QPointer, QLeft, QRight, QUp, QDown;
static Boolean haveQuarks = False;
/* ==================================================== */
Table *
xaccMallocTable (void)
{
Table *table;
table = (Table *) malloc (sizeof (Table));
xaccInitTable (table);
return table;
}
/* ==================================================== */
void
xaccInitTable (Table * table)
{
table->table_widget = 0;
table->next_tab_group = 0;
table->num_phys_rows = -1;
table->num_phys_cols = -1;
table->num_virt_rows = -1;
table->num_virt_cols = -1;
table->current_cursor = NULL;
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->move_cursor = NULL;
table->client_data = NULL;
table->entries = NULL;
table->locators = NULL;
table->user_data = NULL;
table->handlers = NULL;
/* invalidate the "previous" traversed cell */
table->prev_phys_traverse_row = -1;
table->prev_phys_traverse_col = -1;
}
/* ==================================================== */
void
xaccDestroyTable (Table * table)
{
/* free the gui-independent parts */
xaccFreeTableEntries (table);
/* hmmm what about the motif widget ??? */
/* intialize vars to null value so that any access is voided. */
xaccInitTable (table);
free (table);
}
/* ==================================================== */
void
xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
int virt_rows, int virt_cols)
{
xaccTableResize (table, phys_rows, phys_cols, virt_rows, virt_cols);
/* invalidate the "previous" traversed cell */
table->prev_phys_traverse_row = -1;
table->prev_phys_traverse_col = -1;
/* invalidate the current cursor position, if needed */
if ((table->current_cursor_virt_row >= table->num_virt_rows) ||
(table->current_cursor_virt_col >= table->num_virt_cols)) {
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->current_cursor = NULL;
}
}
/* ==================================================== */
void
@ -615,7 +534,9 @@ xaccCreateTable (Table *table, Widget parent, char * name)
table->table_widget = reg;
/* if any of the cells have GUI specific components that need
* initialization, initialize them now. */
* initialization, initialize them now. The realize() callback
* on the cursor cell is how we inform the cell handler that
* now is the time to initialize it's GUI. */
curs = table->current_cursor;
if (curs) {

View File

@ -34,116 +34,40 @@
#define __XACC_TABLE_MOTIF_H__
#include <Xm/Xm.h>
#include "basiccell.h"
#include "cellblock.h"
/* the Locator structure is used provide a mapping from
* the physical array of cells to the logical array of
* virtual cell blocks.
/* We use C not C++ in this project, but we none-the-less need
* the general mechanism of inheritance. The three #defines
* below implement that.
*
* There is one instance of Locator for each physical cell.
* The virt_row and virt_col members identify the corresponding
* cellblock/virtual cell that this physical cell is a member of.
* The two phys_offsets provide the location of the physical cell
* as an offset from the cell block origin. That is, the offsets
* should never be less than zero, or greater than the size of
* the cell block.
* the TABLE_PRIVATE_DATA declaration should be thought of as a
* "derived class" of which Table is the base class. This
* define is included as a part of the definition of the Table
* structure in table-allgui.h
*
* The TABLE_PRIVATE_DATA_INIT and DESTROY are the constructors
* and destructors, respectively, for this derived class.
* These are included in the xaccTableInit() and the xaccTableDestroy()
* routines in the file table-allgui.c, where they are called,
* respectively, last, and first, just as "real" constructors &
* destructors would be
*/
struct _Locator {
short phys_row_offset;
short phys_col_offset;
short virt_row;
short virt_col;
};
typedef struct _Locator Locator;
#define TABLE_PRIVATE_DATA \
/* Motif specific private data */ \
Widget table_widget; /* the XbaeMatrix */ \
Widget next_tab_group; /* where to traverse in the end */
/* The number of "physical" rows/cols is the number
* of displayed one-line gui rows/cols in the table.
* The number of physical rows can differ from the
* number of "virtual" rows because each virtual row
* consist of one or more physical rows.
*
* Given the location of a physical row & col, the corresponding
* virtual row & col can be found by looking it up in the
* "locators" member. The locator will provide the matching
* virtual row and column.
*
* Given the location of the virtual row and column, the
* corresponding GUI handler, and any associated user data can
* be directly accessed.
*/
#define TABLE_PRIVATE_DATA_INIT(table) { \
table->table_widget = 0; \
table->next_tab_group = 0; \
}
/* hack alert -- shouldn't destroy get rid of the widget? */
#define TABLE_PRIVATE_DATA_DESTROY(table)
typedef struct _Table Table;
struct _Table {
int num_phys_rows;
int num_phys_cols;
int num_virt_rows;
int num_virt_cols;
/* the current cursor row/col is the virt row/col */
CellBlock *current_cursor;
int current_cursor_phys_row;
int current_cursor_phys_col;
int current_cursor_virt_row;
int current_cursor_virt_col;
/* callback that is called when the cursor is moved */
/* hack alert -- this should be a callback list, actually */
void (*move_cursor) (Table *, void *client_data);
void * client_data;
/* string values for each cell,
* of dimension num_phys_rows * num_phys_cols */
char ***entries;
/* handler locators for each cell,
* of dimension num_phys_rows * num_phys_cols */
Locator ***locators;
/* user hooks, of dimension num_virt_rows * num_virt_cols */
void ***user_data;
/* cell blocks, of dimension num_virt_rows * num_virt_cols */
CellBlock ***handlers;
/* private data, caches, etc. */
/* This is black-box stuff that no user of this class
* should ever want to access */
/* This class implements tab-key and arrow key
* traversal through the cells of the table.
* To perform this traversal, the location
* of the "previous" cell having input focus
* is required.
*/
int prev_phys_traverse_row;
int prev_phys_traverse_col;
/* Motif-only date below, gui-independent data above */
/* protected data -- vital for the implementation,
* but not something we want to generally expose */
Widget table_widget; /* the XbaeMatrix */
Widget next_tab_group; /* where to traverse in the end */
};
Table * xaccMallocTable (void);
void xaccInitTable (Table *);
void xaccDestroyTable (Table *);
/* The xaccSetTableSize() method will resize the table to the
* indicated dimensions. This method calls the gui-independent
* xaccTableResize() routine, and then does some motif-specific
* cleanup.
*/
void xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
int virt_rows, int virt_cols);
/* create the widget */
Widget xaccCreateTable (Table *, Widget parent, char * name);
void xaccNextTabGroup (Table *, Widget);