From 0c110c0cdad72f32ad86aa53ef9f2ea19c9788e0 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Wed, 28 Jan 1998 07:22:23 +0000 Subject: [PATCH] more quick-fill basic infrastructure git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@456 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/Ledger.c | 2 +- src/Makefile.in | 2 +- src/QuickFill.c | 38 +++++++++++++-------------- src/RegWindow.c | 1 - src/register/quickfillcell.c | 50 +++++++++++++++++++++++++++++++++--- src/register/quickfillcell.h | 12 +++++++-- src/register/register.c | 7 +++-- src/register/register.h | 27 +++++++++---------- 8 files changed, 95 insertions(+), 44 deletions(-) diff --git a/src/Ledger.c b/src/Ledger.c index d0e1629140..6038151bda 100644 --- a/src/Ledger.c +++ b/src/Ledger.c @@ -32,7 +32,7 @@ xaccLoadRegister (BasicRegister *reg, Split **slist) xaccSetBasicCellValue (reg->dateCell, buff); xaccSetBasicCellValue (reg->numCell, trans->num); - xaccSetBasicCellValue (reg->descCell, trans->description); + xaccSetQuickFillCellValue (reg->descCell, trans->description); xaccSetBasicCellValue (reg->memoCell, split->memo); buff[0] = split->reconciled; diff --git a/src/Makefile.in b/src/Makefile.in index 86f48454d3..821ebe8a03 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -55,7 +55,7 @@ LIBREG = libregister.a ###################################################################### SRCS = AccWindow.c Account.c AccountMenu.c AdjBWindow.c \ BuildMenu.c Data.c Destroy.c FileBox.c FileIO.c HelpWindow.c \ - Ledger.c LedgerUtils.c MainWindow.c QIFIO.c QuickFill.c \ + Ledger.c LedgerUtils.c MainWindow.c QIFIO.c \ RecnWindow.c RegWindow.c Reports.c TextBox.c Transaction.c \ XferWindow.c date.c main.c util.c xtutil.c # OBJS = ${SRCS:.c=.o} $(LIBHTMLW) $(LIBXBAE) $(LIBCOMBO) diff --git a/src/QuickFill.c b/src/QuickFill.c index 2b6aaf214c..7cc7371d8a 100644 --- a/src/QuickFill.c +++ b/src/QuickFill.c @@ -55,7 +55,7 @@ CHAR_TO_INDEX( char c ) /********************************************************************\ \********************************************************************/ QuickFill * -mallocQuickFill( void ) +xaccMallocQuickFill( void ) { int i; QuickFill *qf = (QuickFill *)_malloc(sizeof(QuickFill)); @@ -71,14 +71,14 @@ mallocQuickFill( void ) /********************************************************************\ \********************************************************************/ void -freeQuickFill( QuickFill *qf ) +xaccFreeQuickFill( QuickFill *qf ) { if( qf != NULL ) { int i; for( i=0; iqf[i] ); + xaccFreeQuickFill( qf->qf[i] ); _free(qf); } @@ -87,7 +87,7 @@ freeQuickFill( QuickFill *qf ) /********************************************************************\ \********************************************************************/ QuickFill * -getQuickFill( QuickFill *qf, char c ) +xaccGetQuickFill( QuickFill *qf, char c ) { if( qf != NULL ) { @@ -101,9 +101,9 @@ getQuickFill( QuickFill *qf, char c ) /********************************************************************\ \********************************************************************/ void -qfInsertText( QuickFill *qf, const char * text ) +xaccQFInsertText( QuickFill *qf, const char * text ) { - qfInsertTransactionRec( qf, text, 0 ); + qfInsertTextRec( qf, text, 0 ); } /********************************************************************\ @@ -111,23 +111,23 @@ qfInsertText( QuickFill *qf, const char * text ) static void qfInsertTextRec( QuickFill *qf, const char *text, int depth ) { - if( qf != NULL ) + if (NULL == qf) return; + + if( text ) { - if( text ) + if( text[depth] != '\0' ) { - if( text[depth] != '\0' ) - { - int index = CHAR_TO_INDEX( text[depth] ); - - if( qf->qf[index] == NULL ) - qf->qf[index] = mallocQuickFill(); - - qf->qf[index]->text = text; - - qfInsertTransactionRec( qf->qf[index], text, ++depth ); - } + int index = CHAR_TO_INDEX( text[depth] ); + + if( qf->qf[index] == NULL ) + qf->qf[index] = xaccMallocQuickFill(); + + qf->qf[index]->text = text; + + qfInsertTextRec( qf->qf[index], text, ++depth ); } } } + /********************** END OF FILE *********************************\ \********************************************************************/ diff --git a/src/RegWindow.c b/src/RegWindow.c index 7059b2f6d5..bd337e9ace 100644 --- a/src/RegWindow.c +++ b/src/RegWindow.c @@ -46,7 +46,6 @@ #include "MainWindow.h" #include "main.h" #include "messages.h" -#include "QuickFill.h" #include "RecnWindow.h" #include "Transaction.h" #include "util.h" diff --git a/src/register/quickfillcell.c b/src/register/quickfillcell.c index a39f24fe35..88011c9cf6 100644 --- a/src/register/quickfillcell.c +++ b/src/register/quickfillcell.c @@ -4,19 +4,51 @@ #include "basiccell.h" #include "quickfillcell.h" +/* ================================================ */ +/* when entering new cell, reset pointer to root */ + +static const char * +quick_enter (struct _BasicCell *_cell, + const char *val) +{ + QuickFillCell *cell = (QuickFillCell *) _cell; + + cell->qf = cell->qfRoot; + return val; +} + /* ================================================ */ /* by definition, all text is valid text. So accept * all modifications */ static const char * -quickMV (struct _BasicCell *_cell, +quick_modify (struct _BasicCell *_cell, const char *oldval, const char *change, const char *newval) { + +printf ("change is %s \n", change); + if (change) { + } + return newval; } +/* ================================================ */ +/* when leaving cell, make sure that text was put into the qf */ + +static const char * +quick_leave (struct _BasicCell *_cell, + const char *val) +{ + QuickFillCell *cell = (QuickFillCell *) _cell; + + cell->qf = cell->qfRoot; + xaccQFInsertText (cell->qfRoot, val); + return val; +} + /* ================================================ */ QuickFillCell * @@ -26,7 +58,8 @@ xaccMallocQuickFillCell (void) cell = xaccMallocQuickFillCell(); xaccInitBasicCell (&(cell->cell)); - cell->qf = xaccMallocQuickFill(); + cell->qfRoot = xaccMallocQuickFill(); + cell->qf = cell->qfRoot; return cell; } @@ -35,7 +68,18 @@ xaccMallocQuickFillCell (void) void xaccInitQuickFillCell (QuickFillCell *cell) { - cell->cell.modify_verify = quickMV; + cell->cell.enter_cell = quick_enter; + cell->cell.modify_verify = quick_modify; + cell->cell.leave_cell = quick_leave; +} + +/* ================================================ */ + +void +xaccSetQuickFillCellValue (QuickFillCell *cell, char * value) +{ + xaccQFInsertText (cell->qfRoot, value); + xaccSetBasicCellValue (&(cell->cell), value); } /* =============== END OF FILE ==================== */ diff --git a/src/register/quickfillcell.h b/src/register/quickfillcell.h index de492d0fac..fcdddb957e 100644 --- a/src/register/quickfillcell.h +++ b/src/register/quickfillcell.h @@ -4,7 +4,12 @@ * quickfillcell.h * * FUNCTION: - * implements a text cell with quick-fill capabilities + * Implements a text cell with quick-fill capabilities. + * + * The xaccSetQuickFillCellValue() method sets the + * current cell value to the indicated string, + * simultaneously adding the string to the quick-fill + * tree. * * HISTORY: * Copyright (c) 1997, 1998 Linas Vepstas @@ -18,13 +23,16 @@ typedef struct _QuickFillCell { BasicCell cell; - QuickFill *qf; + QuickFill *qfRoot; /* root of quickfill-tree + * handled by this cell */ + QuickFill *qf; /* current positin in tree */ } QuickFillCell; /* installs a callback to handle price recording */ QuickFillCell * xaccMallocQuickFillCell (void); void xaccInitQuickFillCell (QuickFillCell *); +void xaccSetQuickFillCellValue (QuickFillCell *, char *); #endif /* __XACC_FILL_CELL_C__ */ diff --git a/src/register/register.c b/src/register/register.c index 9d19b3462d..4b5f3e35fc 100644 --- a/src/register/register.c +++ b/src/register/register.c @@ -129,10 +129,9 @@ void xaccInitBasicRegister (BasicRegister *reg) xaccAddCell (curs, cell, XFRM_CELL_R, XFRM_CELL_C); reg->xferCell = cell; - cell = xaccMallocTextCell(); - cell->width = 9; - xaccAddCell (curs, cell, DESC_CELL_R, DESC_CELL_C); - reg->descCell = cell; + reg->descCell = xaccMallocQuickFillCell(); + reg->descCell->cell.width = 9; + xaccAddCell (curs, &(reg->descCell->cell), DESC_CELL_R, DESC_CELL_C); cell = xaccMallocTextCell(); cell->width = 9; diff --git a/src/register/register.h b/src/register/register.h index c293e75e63..78a8d6786e 100644 --- a/src/register/register.h +++ b/src/register/register.h @@ -8,25 +8,26 @@ #include "basiccell.h" #include "datecell.h" +#include "quickfillcell.h" #include "pricecell.h" #include "table.h" #include "recncell.h" #include "textcell.h" typedef struct _BasicRegister { - Table * table; - CellBlock * cursor; - CellBlock * header; - BasicCell * dateCell; - BasicCell * numCell; - BasicCell * actionCell; - BasicCell * xferCell; - BasicCell * descCell; - BasicCell * memoCell; - BasicCell * recnCell; - PriceCell * creditCell; - PriceCell * debitCell; - PriceCell * balanceCell; + Table * table; + CellBlock * cursor; + CellBlock * header; + BasicCell * dateCell; + BasicCell * numCell; + BasicCell * actionCell; + BasicCell * xferCell; + QuickFillCell * descCell; + BasicCell * memoCell; + BasicCell * recnCell; + PriceCell * creditCell; + PriceCell * debitCell; + PriceCell * balanceCell; } BasicRegister;