moe infrastructure

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@401 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
1998-01-09 20:58:51 +00:00
parent f0e8b299de
commit a347a39c00
10 changed files with 157 additions and 21 deletions

View File

@@ -16,16 +16,16 @@ CFLAGS = -g -DCELL_WIDGETS=1
LFLAGS = -O2
LIBS = -lXpm -lXm -lXmu -lXt -lXext -lSM -lICE -lX11 -lpng -ljpeg -lz -lm
LIBPATH = -L/lib -L/usr/lib -L/usr/X11R6/lib/.
TARGET = xacc
TARGET = demo
STATIC = xacc-static
# LIBHTMLW = ../lib/libhtmlw/libhtmlw.a
LIBXMHTML= ../lib/XmHTML-1.1.0/src/libXmHTML.a
LIBXBAE = ../lib/Xbae-4.6.2-linas/libXbae.a
LIBXBAE = ../../lib/Xbae-4.6.2-linas/libXbae.a
LIBCOMBO = ../lib/ComboBox-1.33/libComboBox.a
######################################################################
SRCS = cell.c price.c single.c table.c
OBJS = ${SRCS:.c=.o}
SRCS = cell.c main.c price.c single.c table.c
OBJS = ${SRCS:.c=.o} $(LIBXBAE)
######################################################################
default: $(TARGET)

View File

@@ -17,6 +17,7 @@ void xaccInitSingleCell (SingleCell *cell)
cell->row = 0;
cell->col = 0;
cell->width = 0;
cell->alignment = 0;
cell->value = 0x0;
cell->modify_verify = NULL;
}

View File

@@ -25,6 +25,7 @@ typedef struct _SingleCell {
short row; /* relative row position */
short col; /* relative column position */
short width; /* column width, in chars, not pixels */
short alignment; /* column text alignment */
char * value; /* current value */

View File

@@ -2,14 +2,16 @@
#include <stdlib.h>
#include "cell.h"
CellArray * xaccMallocCellArray (int numrows, int numcols)
CellBlock * xaccMallocCellBlock (int numrows, int numcols)
{
CellArray *arr;
arr = (CellArray *) malloc (sizeof (CellArray *));
CellBlock *arr;
arr = (CellBlock *) malloc (sizeof (CellBlock *));
arr->cells = NULL;
xaccInitCellArray (arr, numrows, numcols);
arr->widths = NULL;
arr->alignments = NULL;
xaccInitCellBlock (arr, numrows, numcols);
return arr;
}
@@ -17,13 +19,16 @@ CellArray * xaccMallocCellArray (int numrows, int numcols)
/* =================================================== */
void
xaccInitCellArray (CellArray *arr, int numrows, int numcols)
xaccInitCellBlock (CellBlock *arr, int numrows, int numcols)
{
int i;
if (!arr) return;
arr->numRows = numrows;
arr->numCols = numcols;
/* free old cell array, if any */
if (arr->cells) {
for (i=0; i<numrows; i++) {
if (arr->cells[i]) free (arr->cells[i]);
@@ -31,23 +36,56 @@ xaccInitCellArray (CellArray *arr, int numrows, int numcols)
free (arr->cells);
}
/* malloc new cell array */
{
char * tmp;
printf ("%d %d \n", numrows, sizeof (SingleCell **));
tmp = malloc (numrows * sizeof (SingleCell **));
tmp = malloc (2);
arr->cells = (SingleCell ***) tmp;
printf ("%p %p %p %d \n", arr, tmp, arr->cells, numrows);
}
arr->cells = (SingleCell ***) malloc (numrows * sizeof (SingleCell **));
printf ("%p %p %d \n", arr, arr->cells, numrows);
for (i=0; i<numrows; i++) {
arr->cells[i] = (SingleCell **) malloc (numcols * sizeof (SingleCell *));
printf ("%d %p %p \n", i, arr->cells, arr->cells[i]);
(arr->cells)[i] = (SingleCell **) malloc (numcols * sizeof (SingleCell *));
}
/* free old widths, alignments */
if (arr->widths) free (arr->widths);
if (arr->alignments) free (arr->alignments);
arr->widths = (short *) malloc (numcols * sizeof(short));
arr->alignments = (unsigned char *) malloc (numcols * sizeof(unsigned char));
for (i=0; i<numcols; i++) {
arr->widths[i] = 0;
arr->alignments[i] = 0;
}
}
/* =================================================== */
void
xaccAddCell (CellArray *arr, SingleCell *cell)
xaccAddCell (CellBlock *arr, SingleCell *cell)
{
int i,j;
if (!arr) return;
if (!cell) return;
i = cell->row;
j = cell->col;
/* avoid embarrasement if cell incorrectly specified */
if ((0 > i) || (0 > j)) return;
if ((i >= arr->numRows) || (j >= arr->numCols)) return;
arr->cells[i][j] = cell;
arr->widths[j] = cell->width;
arr->alignments[j] = cell->alignment;
}
/* --------------- end of file ----------------- */

View File

@@ -6,19 +6,24 @@
/* a cell array is a traversal group for one entry in the register */
typedef struct _CellArray {
typedef struct _CellBlock {
short numRows;
short numCols;
SingleCell ***cells; /* row-col array */
} CellArray;
/* private, utility cahced data */
short *widths; /* column widths */
unsigned char *alignments; /* column text alignments */
} CellBlock;
CellArray * xaccMallocCellArray (int numrows, int numcols);
void xaccInitCellArray (CellArray *, int numrows, int numcols);
CellBlock * xaccMallocCellBlock (int numrows, int numcols);
void xaccInitCellBlock (CellBlock *, int numrows, int numcols);
/* add a cell to the array */
void xaccAddCell (CellArray *, SingleCell *);
void xaccAddCell (CellBlock *, SingleCell *);
#endif __XACC_CELL_H__

24
src/register/main.c Normal file
View File

@@ -0,0 +1,24 @@
#include "price.h"
#include "table.h"
main () {
Table * table;
CellBlock *curs, *header;
SingleCell *cell;
curs = xaccMallocCellBlock (2, 10);
header = xaccMallocCellBlock (1, 10);
cell = xaccMallocPriceCell();
cell->row = 1;
cell->col = 3;
xaccAddCell (curs, cell);
table = xaccMallocTable (15);
table -> cursor = curs;
}

View File

@@ -9,9 +9,25 @@ static char * PriceMV (char * input)
return strdup (input);
}
/* ================================================ */
SingleCell *
xaccMallocPriceCell (void)
{
SingleCell *cell;
cell = xaccMallocSingleCell();
xaccInitPriceCell (cell);
return cell;
}
/* ================================================ */
void
xaccInitPriceCell (SingleCell *cell)
{
if (cell->value) free (cell->value);
cell ->value = strdup ("0.0");
cell ->modify_verify = PriceMV;
}

View File

@@ -5,7 +5,8 @@
#include "single.h"
/* installs a callback to handle price recording */
void xaccInitPriceCell (SingleCell *);
SingleCell * xaccMallocPriceCell (void);
void xaccInitPriceCell (SingleCell *);
#endif /* __XACC_PRICE_C__ */

View File

@@ -22,6 +22,7 @@ xaccMallocTable (int numentries)
void
xaccInitTable (Table * table, int numentries)
{
int num_header_rows;
int num_phys_rows;
int num_phys_cols;
int i,j;
@@ -33,8 +34,11 @@ xaccInitTable (Table * table, int numentries)
table->numEntries = numentries;
/* compute number of physical rows */
num_header_rows = 0;
num_phys_rows = 0;
num_phys_cols = 0;
if (table->header) {
num_header_rows = table->header->numRows;
num_phys_rows += table->header->numRows;
}
if (table->cursor) {
@@ -54,12 +58,55 @@ xaccInitTable (Table * table, int numentries)
}
}
/* ==================================================== */
void
xaccCreateTable (Table *table, Widget parent, char * name)
{
unsigned char * alignments;
short * widths;
if (!table) return;
/* if a header exists, get alignments, widths from there */
alignments = NULL;
widths = NULL;
if (table->cursor) {
alignments = table->cursor->alignments;
widths = table->cursor->widths;
}
if (table->header) {
alignments = table->header->alignments;
widths = table->header->widths;
}
table->reg = XtVaCreateWidget( name,
xbaeMatrixWidgetClass, parent,
XmNcells, table->entries,
XmNfixedRows, table->num_header_rows,
XmNfixedColumns, 0,
XmNrows, table->num_phys_rows,
XmNvisibleRows, 15,
XmNfill, True,
XmNcolumns, table->num_phys_cols,
XmNcolumnWidths, widths,
XmNcolumnAlignments, alignments,
XmNtraverseFixedCells, False,
XmNgridType, XmGRID_SHADOW_IN,
XmNshadowType, XmSHADOW_ETCHED_IN,
XmNverticalScrollBarDisplayPolicy,XmDISPLAY_STATIC,
XmNselectScrollVisible, True,
XmNnavigationType, XmEXCLUSIVE_TAB_GROUP,
NULL);
}
/* ==================================================== */
void
xaccRefreshTable (Table * table)
{
XtVaSetValues (table->reg, XmNcells, table->entries, NULL);
}

View File

@@ -15,14 +15,15 @@ typedef struct _Table {
short numEntries;
CellArray *header;
CellArray *cursor;
CellBlock *header;
CellBlock *cursor;
char ***entries;
Widget reg; /* the XbaeMatrix */
/* private data, cahces, etc. */
int num_header_rows;
int num_phys_rows;
int num_phys_cols;
} Table;
@@ -30,12 +31,14 @@ typedef struct _Table {
Table * xaccMallocTable (int numentries);
void xaccInitTable (Table *, int entries);
void xaccCreateTable (Table *, Widget parent, char * name);
void xaccDestroyTable (Table *);
void xaccRefreshTable (Table *);
/* add a cell to the array */
void xaccSetCursor (Table *, CellArray *);
void xaccSetCursor (Table *, CellBlock *);
#endif __XACC_TABLE_H__
/* ================== end of file ======================= */