diff --git a/src/register/basiccell.c b/src/register/basiccell.c index 89d78f2541..61a651afab 100644 --- a/src/register/basiccell.c +++ b/src/register/basiccell.c @@ -1,3 +1,30 @@ +/* + * FILE: + * basiccell.c + * + * FUNCTION: + * Implements the base class for the cell handler object. + * See the header file for additional documentation. + * + * 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 @@ -35,9 +62,27 @@ void xaccInitBasicCell (BasicCell *cell) /* ===================================================== */ +void xaccDestroyBasicCell (BasicCell *cell) +{ + /* give any gui elements a chance to clean up */ + if (cell->destroy) { + (*(cell->destroy)) (cell); + } + + /* free up data strings */ + if (cell->value) { + free (cell->value); + } + + /* help prevent access to freed memory */ + xaccInitBasicCell (cell); +} + +/* ===================================================== */ + void xaccSetBasicCellValue (BasicCell *cell, const char *val) { - void (*cb) (struct _BasicCell *, const char *); + void (*cb) (BasicCell *, const char *); cb = cell->set_value; if (cb) { diff --git a/src/register/basiccell.h b/src/register/basiccell.h index fccf1a30b9..cf4d051ba0 100644 --- a/src/register/basiccell.h +++ b/src/register/basiccell.h @@ -107,12 +107,33 @@ * to work around the fact that the combo-box requires a width * in pixels, rather than in characters. It would be nice if * ComboBox supported the XmNunits resource, but it doesn't. + * + * HISTORY: + * Copyright (c) 1998 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_BASIC_CELL_H__ #define __XACC_BASIC_CELL_H__ -typedef struct _BasicCell { +typedef struct _BasicCell BasicCell; + +struct _BasicCell { short width; /* column width, in chars, not pixels */ short alignment; /* column text alignment */ @@ -122,13 +143,13 @@ typedef struct _BasicCell { unsigned int changed; /* 2^32-1 if value modified */ /* "virtual", overloaded set-value method */ - void (*set_value) (struct _BasicCell *, + void (*set_value) (BasicCell *, const char * new_value); /* cell-editing callbacks */ - const char * (*enter_cell) (struct _BasicCell *, + const char * (*enter_cell) (BasicCell *, const char * current); - const char * (*modify_verify) (struct _BasicCell *, + const char * (*modify_verify) (BasicCell *, const char *old, const char *add, const char *new); @@ -136,20 +157,21 @@ typedef struct _BasicCell { const char * current); /* private, GUI-specific callbacks */ - void (* realize) (struct _BasicCell *, + void (* realize) (BasicCell *, void *gui_handle, int pixel_width); - void (* move) (struct _BasicCell *, + void (* move) (BasicCell *, int phys_row, int phys_col); - void (* destroy) (struct _BasicCell *); + void (* destroy) (BasicCell *); /* general hook for gui-private data */ void * gui_private; -} BasicCell; +}; BasicCell * xaccMallocBasicCell (void); void xaccInitBasicCell (BasicCell *); +void xaccDestroyBasicCell (BasicCell *); void xaccSetBasicCellValue (BasicCell *, const char *); diff --git a/src/register/pricecell.c b/src/register/pricecell.c index 4aba057ed7..8b961dfff8 100644 --- a/src/register/pricecell.c +++ b/src/register/pricecell.c @@ -33,7 +33,7 @@ #include "basiccell.h" #include "pricecell.h" -static void PriceSetValue (struct _BasicCell *, const char *); +static void PriceSetValue (BasicCell *, const char *); #define DECIMAL_PT '.' @@ -49,7 +49,7 @@ static void PriceSetValue (struct _BasicCell *, const char *); * decimal point in them */ static const char * -PriceMV (struct _BasicCell *_cell, +PriceMV (BasicCell *_cell, const char * oldval, const char *change, const char *newval) @@ -104,6 +104,15 @@ xaccInitPriceCell (PriceCell *cell) /* ================================================ */ +void +xaccDestroyPriceCell (PriceCell *cell) +{ + cell->amount = 0.0; + xaccDestroyBasicCell ( &(cell->cell)); +} + +/* ================================================ */ + void xaccSetPriceCellValue (PriceCell * cell, double amt) { char buff[40]; @@ -145,7 +154,7 @@ void xaccSetDebCredCellValue (PriceCell * deb, /* ================================================ */ static void -PriceSetValue (struct _BasicCell *_cell, const char *str) +PriceSetValue (BasicCell *_cell, const char *str) { char buff[40]; PriceCell *cell = (PriceCell *) _cell; diff --git a/src/register/pricecell.h b/src/register/pricecell.h index 97c280a8f6..8ff3e6c0da 100644 --- a/src/register/pricecell.h +++ b/src/register/pricecell.h @@ -1,3 +1,46 @@ +/* + * FILE: + * pricecell.h + * + * FUNCTION: + * The PriceCell object Implements a cell handler that + * knows about storing and displaying a price or amount. + * + * By default, the PriceCell is an input/output cell. + * + * On input, this cell accepts only numeric characters + * and numeric punctuation. The punctuation accepted is *not* + * currently internationalized. Read the source for details. + * + * One output, it can display numeric values with two or three + * decimal places. A planned enhancement would be to store + * formating data with an instance of this cell. This is *not* + * currently done. + * + * hack alert -- implement the above formating & internationalization. + * + * The stored amount is stored as a double-precision floating point + * variable. This should be sufficient precision to store trillions of + * dollars with penny accuracy. + * + * 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_PRICE_CELL_C__ #define __XACC_PRICE_CELL_C__ @@ -12,6 +55,7 @@ typedef struct _PriceCell { /* installs a callback to handle price recording */ PriceCell * xaccMallocPriceCell (void); void xaccInitPriceCell (PriceCell *); +void xaccDestroyPriceCell (PriceCell *); /* updates amount, string format is three decimal places */ void xaccSetPriceCellValue (PriceCell *, double amount);