add destroy method

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@727 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-03-25 08:16:38 +00:00
parent 93232d8899
commit 0ade72fb1b
2 changed files with 73 additions and 3 deletions

View File

@ -3,7 +3,8 @@
* register.c
*
* FUNCTION:
* implements the register object
* Implements the register object.
* See the header file for additional documentation.
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
@ -300,12 +301,16 @@ BasicRegister * xaccMallocBasicRegister (int type)
xaccAddCell (curs, reg->CN##Cell, CL##_CELL_R, CL##_CELL_C); \
}
/* ============================================== */
void xaccInitBasicRegister (BasicRegister *reg, int type)
{
Table * table;
CellBlock *curs, *header;
reg->user_hook = NULL;
reg->destroy = NULL;
/* --------------------------- */
configLayout (reg, type);
@ -376,6 +381,60 @@ void xaccInitBasicRegister (BasicRegister *reg, int type)
/* ============================================== */
void
xaccDestroyBasicRegister (BasicRegister *reg)
{
/* give the user a chance to clean up */
if (reg->destroy) {
(*(reg->destroy)) (reg);
}
reg->destroy = NULL;
reg->user_hook = NULL;
xaccDestroyTable (reg->table);
reg->table = NULL;
xaccDestroyCellBlock (reg->header);
xaccDestroyCellBlock (reg->cursor);
reg->header = NULL;
reg->cursor = NULL;
xaccDestroyDateCell (reg->dateCell);
xaccDestroyBasicCell (reg->numCell);
xaccDestroyQuickFillCell (reg->descCell);
xaccDestroyBasicCell (reg->recnCell);
xaccDestroyPriceCell (reg->creditCell);
xaccDestroyPriceCell (reg->debitCell);
xaccDestroyPriceCell (reg->shrsCell);
xaccDestroyPriceCell (reg->priceCell);
xaccDestroyPriceCell (reg->valueCell);
xaccDestroyBasicCell (reg->memoCell);
xaccDestroyComboCell (reg->actionCell);
xaccDestroyComboCell (reg->xfrmCell);
xaccDestroyComboCell (reg->xtoCell);
xaccDestroyPriceCell (reg->balanceCell);
reg->dateCell = NULL;
reg->numCell = NULL;
reg->descCell = NULL;
reg->recnCell = NULL;
reg->creditCell = NULL;
reg->debitCell = NULL;
reg->shrsCell = NULL;
reg->priceCell = NULL;
reg->valueCell = NULL;
reg->memoCell = NULL;
reg->actionCell = NULL;
reg->xfrmCell = NULL;
reg->xtoCell = NULL;
reg->balanceCell = NULL;
/* free the memory itself */
free (reg);
}
/* ============================================== */
unsigned int
xaccGetChangeFlag (BasicRegister *reg)
{

View File

@ -77,7 +77,9 @@
#define NUM_CELLS 20
typedef struct _BasicRegister {
typedef struct _BasicRegister BasicRegister;
struct _BasicRegister {
/* the table itself that implements the underlying GUI. */
Table * table;
@ -110,10 +112,19 @@ typedef struct _BasicRegister {
short rows[NUM_CELLS];
short wids[NUM_CELLS];
} BasicRegister;
/* user_hook allows users of this object to hang
* private data onto it */
void *user_hook;
/* The destroy callback gives user's a chance
* to free up any associated user_hook data */
void (* destroy) (BasicRegister *);
};
BasicRegister * xaccMallocBasicRegister (int type);
void xaccInitBasicRegister (BasicRegister *, int type);
void xaccDestroyBasicRegister (BasicRegister *);
/* returns non-zero value if updates have been made to data */
unsigned int xaccGetChangeFlag (BasicRegister *);