mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
finally, a compilabe, working demo
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@403 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
9acee0e3f7
commit
116f067e91
@ -1,8 +1,13 @@
|
|||||||
|
|
||||||
|
#include <Xm/Xm.h>
|
||||||
|
#include <Xm/Form.h>
|
||||||
|
#include <Xm/MainW.h>
|
||||||
|
|
||||||
#include "price.h"
|
#include "price.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
|
||||||
main () {
|
Table *
|
||||||
|
CreateReg(Widget parent ) {
|
||||||
|
|
||||||
Table * table;
|
Table * table;
|
||||||
CellBlock *curs, *header;
|
CellBlock *curs, *header;
|
||||||
@ -12,13 +17,56 @@ main () {
|
|||||||
header = xaccMallocCellBlock (1, 10);
|
header = xaccMallocCellBlock (1, 10);
|
||||||
|
|
||||||
cell = xaccMallocPriceCell();
|
cell = xaccMallocPriceCell();
|
||||||
cell->row = 1;
|
cell->row = 0;
|
||||||
cell->col = 3;
|
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 -> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <Xbae/Matrix.h>
|
#include <Xbae/Matrix.h>
|
||||||
|
|
||||||
|
#include "cell.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
|
||||||
Table *
|
Table *
|
||||||
@ -26,13 +27,22 @@ xaccInitTable (Table * table, int numentries)
|
|||||||
int num_phys_rows;
|
int num_phys_rows;
|
||||||
int num_phys_cols;
|
int num_phys_cols;
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
/* delete old entries */
|
/* delete old entries */
|
||||||
|
num_phys_rows = table->num_phys_rows;
|
||||||
|
num_phys_cols = table->num_phys_cols;
|
||||||
if (table->entries) {
|
if (table->entries) {
|
||||||
|
for (i=0; i<num_phys_rows; i++) {
|
||||||
|
if (table->entries[i]) {
|
||||||
|
for (j=0; j<num_phys_cols; j++) {
|
||||||
|
free (table->entries[i][j]);
|
||||||
|
}
|
||||||
|
free (table->entries[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free (table->entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
table->numEntries = numentries;
|
|
||||||
|
|
||||||
/* compute number of physical rows */
|
/* compute number of physical rows */
|
||||||
num_header_rows = 0;
|
num_header_rows = 0;
|
||||||
num_phys_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_rows = num_phys_rows;
|
||||||
table->num_phys_cols = num_phys_cols;
|
table->num_phys_cols = num_phys_cols;
|
||||||
|
|
||||||
|
table->numEntries = numentries;
|
||||||
|
|
||||||
/* create an empty table */
|
/* create an empty table */
|
||||||
table->entries = (char ***) malloc (num_phys_rows * sizeof (char **));
|
table->entries = (char ***) malloc (num_phys_rows * sizeof (char **));
|
||||||
for (i=0; i<num_phys_rows; i++) {
|
for (i=0; i<num_phys_rows; i++) {
|
||||||
@ -60,14 +72,44 @@ xaccInitTable (Table * table, int numentries)
|
|||||||
|
|
||||||
|
|
||||||
/* ==================================================== */
|
/* ==================================================== */
|
||||||
|
/* hack alert -- will core dump if numrows has changed, etc. */
|
||||||
|
|
||||||
|
static
|
||||||
void
|
void
|
||||||
|
xaccRefreshHeader (Table *table)
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
CellBlock *arr;
|
||||||
|
|
||||||
|
/* copy header data into entries cache */
|
||||||
|
arr = table->header;
|
||||||
|
if (arr) {
|
||||||
|
for (i=0; i<arr->numRows; i++) {
|
||||||
|
for (j=0; j<arr->numCols; 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)
|
xaccCreateTable (Table *table, Widget parent, char * name)
|
||||||
{
|
{
|
||||||
unsigned char * alignments;
|
unsigned char * alignments;
|
||||||
short * widths;
|
short * widths;
|
||||||
|
|
||||||
if (!table) return;
|
if (!table) return 0;
|
||||||
|
|
||||||
/* if a header exists, get alignments, widths from there */
|
/* if a header exists, get alignments, widths from there */
|
||||||
alignments = NULL;
|
alignments = NULL;
|
||||||
@ -81,6 +123,9 @@ xaccCreateTable (Table *table, Widget parent, char * name)
|
|||||||
widths = table->header->widths;
|
widths = table->header->widths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy header data into entries cache */
|
||||||
|
xaccRefreshHeader (table);
|
||||||
|
|
||||||
table->reg = XtVaCreateWidget( name,
|
table->reg = XtVaCreateWidget( name,
|
||||||
xbaeMatrixWidgetClass, parent,
|
xbaeMatrixWidgetClass, parent,
|
||||||
XmNcells, table->entries,
|
XmNcells, table->entries,
|
||||||
@ -100,6 +145,9 @@ xaccCreateTable (Table *table, Widget parent, char * name)
|
|||||||
XmNnavigationType, XmEXCLUSIVE_TAB_GROUP,
|
XmNnavigationType, XmEXCLUSIVE_TAB_GROUP,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
XtManageChild (table->reg);
|
||||||
|
|
||||||
|
return (table->reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ==================================================== */
|
/* ==================================================== */
|
||||||
|
@ -31,10 +31,13 @@ typedef struct _Table {
|
|||||||
|
|
||||||
Table * xaccMallocTable (int numentries);
|
Table * xaccMallocTable (int numentries);
|
||||||
void xaccInitTable (Table *, int entries);
|
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 *);
|
void xaccDestroyTable (Table *);
|
||||||
|
|
||||||
|
/* redraw the table */
|
||||||
void xaccRefreshTable (Table *);
|
void xaccRefreshTable (Table *);
|
||||||
|
|
||||||
/* add a cell to the array */
|
/* add a cell to the array */
|
||||||
|
Loading…
Reference in New Issue
Block a user