From 116f067e9106a24a7ae9a4ba23d047ff9aa82559 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 10 Jan 1998 10:02:02 +0000 Subject: [PATCH] finally, a compilabe, working demo git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@403 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/main.c | 58 ++++++++++++++++++++++++++++++++++++++++---- src/register/table.c | 56 +++++++++++++++++++++++++++++++++++++++--- src/register/table.h | 5 +++- 3 files changed, 109 insertions(+), 10 deletions(-) diff --git a/src/register/main.c b/src/register/main.c index 9a3446860e..5f6ecd792a 100644 --- a/src/register/main.c +++ b/src/register/main.c @@ -1,8 +1,13 @@ +#include +#include +#include + #include "price.h" #include "table.h" -main () { +Table * +CreateReg(Widget parent ) { Table * table; CellBlock *curs, *header; @@ -12,13 +17,56 @@ main () { header = xaccMallocCellBlock (1, 10); cell = xaccMallocPriceCell(); - cell->row = 1; + cell->row = 0; cell->col = 3; - xaccAddCell (curs, cell); + cell->width = 9; + xaccAddCell (header, cell); + + cell = xaccMallocPriceCell(); + cell->row = 0; + cell->col = 4; + cell->width = 9; + xaccAddCell (header, cell); - table = xaccMallocTable (15); + table = xaccMallocTable (0); table -> cursor = curs; + table -> header = header; + xaccInitTable (table, 15); - + xaccCreateTable (table, parent, "yodudue"); + return table; } + +main (int argc, char *argv[]) { + Widget toplevel, mainwindow, actionform; + XtAppContext app; + Table * table; + + + toplevel = XtVaAppInitialize( &app, "Xacc", NULL, 0, + &argc, argv, NULL, + NULL ); + + + mainwindow = XtVaCreateManagedWidget( "mainwindow", + xmMainWindowWidgetClass, toplevel, + XmNdeleteResponse, XmDESTROY, + NULL ); + + actionform = XtVaCreateWidget( "form", + xmFormWidgetClass, mainwindow, + NULL ); + + table = CreateReg (actionform); + XtManageChild (actionform); + + XtRealizeWidget(toplevel); + XtRealizeWidget (table->reg); + + XtAppMainLoop(app); + + return 0; + } + + diff --git a/src/register/table.c b/src/register/table.c index e00e5939eb..40415f6a5c 100644 --- a/src/register/table.c +++ b/src/register/table.c @@ -3,6 +3,7 @@ #include +#include "cell.h" #include "table.h" Table * @@ -26,13 +27,22 @@ xaccInitTable (Table * table, int numentries) int num_phys_rows; int num_phys_cols; int i,j; - + /* delete old entries */ + num_phys_rows = table->num_phys_rows; + num_phys_cols = table->num_phys_cols; if (table->entries) { + for (i=0; ientries[i]) { + for (j=0; jentries[i][j]); + } + free (table->entries[i]); + } + } + free (table->entries); } - table->numEntries = numentries; - /* compute number of physical rows */ num_header_rows = 0; num_phys_rows = 0; @@ -48,6 +58,8 @@ xaccInitTable (Table * table, int numentries) table->num_phys_rows = num_phys_rows; table->num_phys_cols = num_phys_cols; + table->numEntries = numentries; + /* create an empty table */ table->entries = (char ***) malloc (num_phys_rows * sizeof (char **)); for (i=0; iheader; + if (arr) { + for (i=0; inumRows; i++) { + for (j=0; jnumCols; j++) { + if (table->entries[i][j]) free (table->entries[i][j]); + if (arr->cells[i][j]) { + if ((arr->cells[i][j])->value) { + table->entries[i][j] = strdup ((arr->cells[i][j])->value); + } else { + table->entries[i][j] = strdup (""); + } + } else { + table->entries[i][j] = strdup (""); + } + } + } + } +} + +/* ==================================================== */ + +Widget xaccCreateTable (Table *table, Widget parent, char * name) { unsigned char * alignments; short * widths; - if (!table) return; + if (!table) return 0; /* if a header exists, get alignments, widths from there */ alignments = NULL; @@ -81,6 +123,9 @@ xaccCreateTable (Table *table, Widget parent, char * name) widths = table->header->widths; } + /* copy header data into entries cache */ + xaccRefreshHeader (table); + table->reg = XtVaCreateWidget( name, xbaeMatrixWidgetClass, parent, XmNcells, table->entries, @@ -100,6 +145,9 @@ xaccCreateTable (Table *table, Widget parent, char * name) XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, NULL); + XtManageChild (table->reg); + + return (table->reg); } /* ==================================================== */ diff --git a/src/register/table.h b/src/register/table.h index 3444749981..cf74552201 100644 --- a/src/register/table.h +++ b/src/register/table.h @@ -31,10 +31,13 @@ typedef struct _Table { Table * xaccMallocTable (int numentries); void xaccInitTable (Table *, int entries); -void xaccCreateTable (Table *, Widget parent, char * name); + +/* create the widget */ +Widget xaccCreateTable (Table *, Widget parent, char * name); void xaccDestroyTable (Table *); +/* redraw the table */ void xaccRefreshTable (Table *); /* add a cell to the array */