mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
introduce more flexible, robust format handling
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@952 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
6312a46216
commit
a5c17b4111
@ -108,6 +108,7 @@ xaccInitPriceCell (PriceCell *cell)
|
|||||||
xaccInitBasicCell( &(cell->cell));
|
xaccInitBasicCell( &(cell->cell));
|
||||||
cell->amount = 0.0;
|
cell->amount = 0.0;
|
||||||
cell->blank_zero = 1;
|
cell->blank_zero = 1;
|
||||||
|
cell->prt_format = strdup ("%.2f");
|
||||||
|
|
||||||
SET ( &(cell->cell), "");
|
SET ( &(cell->cell), "");
|
||||||
|
|
||||||
@ -121,6 +122,7 @@ void
|
|||||||
xaccDestroyPriceCell (PriceCell *cell)
|
xaccDestroyPriceCell (PriceCell *cell)
|
||||||
{
|
{
|
||||||
cell->amount = 0.0;
|
cell->amount = 0.0;
|
||||||
|
free (cell->prt_format); cell->prt_format = 0x0;
|
||||||
xaccDestroyBasicCell ( &(cell->cell));
|
xaccDestroyBasicCell ( &(cell->cell));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +137,7 @@ void xaccSetPriceCellValue (PriceCell * cell, double amt)
|
|||||||
if (cell->blank_zero && (VERY_SMALL > amt) && ((-VERY_SMALL) < amt)) {
|
if (cell->blank_zero && (VERY_SMALL > amt) && ((-VERY_SMALL) < amt)) {
|
||||||
buff[0] = 0x0;
|
buff[0] = 0x0;
|
||||||
} else {
|
} else {
|
||||||
sprintf (buff, "%.3f", amt);
|
sprintf (buff, cell->prt_format, amt);
|
||||||
}
|
}
|
||||||
SET ( &(cell->cell), buff);
|
SET ( &(cell->cell), buff);
|
||||||
|
|
||||||
@ -145,21 +147,13 @@ void xaccSetPriceCellValue (PriceCell * cell, double amt)
|
|||||||
|
|
||||||
/* ================================================ */
|
/* ================================================ */
|
||||||
|
|
||||||
void xaccSetAmountCellValue (PriceCell * cell, double amt)
|
void xaccSetPriceCellFormat (PriceCell * cell, char * fmt)
|
||||||
{
|
{
|
||||||
char buff[40];
|
if (cell->prt_format) free (cell->prt_format);
|
||||||
cell->amount = amt;
|
cell->prt_format = strdup (fmt);
|
||||||
|
|
||||||
/* if amount is zero, and blanking is set, then print blank */
|
/* make sure that the cell is updated with the new format */
|
||||||
if (cell->blank_zero && (VERY_SMALL > amt) && ((-VERY_SMALL) < amt)) {
|
xaccSetPriceCellValue (cell, cell->amount);
|
||||||
buff[0] = 0x0;
|
|
||||||
} else {
|
|
||||||
sprintf (buff, "%.2f", amt);
|
|
||||||
}
|
|
||||||
SET ( &(cell->cell), buff);
|
|
||||||
|
|
||||||
/* set the cell color to red if the value is negative */
|
|
||||||
COLORIZE (cell, amt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================ */
|
/* ================================================ */
|
||||||
@ -179,11 +173,11 @@ void xaccSetDebCredCellValue (PriceCell * deb,
|
|||||||
SET ( &(deb->cell), "");
|
SET ( &(deb->cell), "");
|
||||||
} else
|
} else
|
||||||
if (0.0 < amt) {
|
if (0.0 < amt) {
|
||||||
sprintf (buff, "%.2f", amt);
|
sprintf (buff, cred->prt_format, amt);
|
||||||
SET ( &(cred->cell), buff);
|
SET ( &(cred->cell), buff);
|
||||||
SET ( &(deb->cell), "");
|
SET ( &(deb->cell), "");
|
||||||
} else {
|
} else {
|
||||||
sprintf (buff, "%.2f", -amt);
|
sprintf (buff, deb->prt_format, -amt);
|
||||||
SET ( &(cred->cell), "");
|
SET ( &(cred->cell), "");
|
||||||
SET ( &(deb->cell), buff);
|
SET ( &(deb->cell), buff);
|
||||||
}
|
}
|
||||||
@ -194,15 +188,10 @@ void xaccSetDebCredCellValue (PriceCell * deb,
|
|||||||
static void
|
static void
|
||||||
PriceSetValue (BasicCell *_cell, const char *str)
|
PriceSetValue (BasicCell *_cell, const char *str)
|
||||||
{
|
{
|
||||||
char buff[40];
|
|
||||||
PriceCell *cell = (PriceCell *) _cell;
|
PriceCell *cell = (PriceCell *) _cell;
|
||||||
|
double amt = xaccParseUSAmount (str);
|
||||||
|
|
||||||
SET (_cell, str);
|
xaccSetPriceCellValue (cell, amt);
|
||||||
|
|
||||||
cell->amount = xaccParseUSAmount (str);
|
|
||||||
|
|
||||||
sprintf (buff, "%.2f", cell->amount);
|
|
||||||
SET ( &(cell->cell), buff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------- end of file ---------------------- */
|
/* --------------- end of file ---------------------- */
|
||||||
|
@ -52,9 +52,9 @@
|
|||||||
|
|
||||||
typedef struct _PriceCell {
|
typedef struct _PriceCell {
|
||||||
BasicCell cell;
|
BasicCell cell;
|
||||||
double amount; /* the amount associated with this cell */
|
double amount; /* the amount associated with this cell */
|
||||||
short blank_zero; /* controls printing of zero values */
|
short blank_zero; /* controls printing of zero values */
|
||||||
|
char *prt_format; /* controls display of value; printf format */
|
||||||
} PriceCell;
|
} PriceCell;
|
||||||
|
|
||||||
/* installs a callback to handle price recording */
|
/* installs a callback to handle price recording */
|
||||||
@ -65,8 +65,8 @@ void xaccDestroyPriceCell (PriceCell *);
|
|||||||
/* updates amount, string format is three decimal places */
|
/* updates amount, string format is three decimal places */
|
||||||
void xaccSetPriceCellValue (PriceCell *, double amount);
|
void xaccSetPriceCellValue (PriceCell *, double amount);
|
||||||
|
|
||||||
/* updates amount, string format is two decimal places */
|
/* use printf-style format to control display */
|
||||||
void xaccSetAmountCellValue (PriceCell *, double amount);
|
void xaccSetPriceCellFormat (PriceCell *, char * fmt);
|
||||||
|
|
||||||
/* updates two cells; the deb cell if amt is negative,
|
/* updates two cells; the deb cell if amt is negative,
|
||||||
* the credit cell if amount is positive, and makes the other cell
|
* the credit cell if amount is positive, and makes the other cell
|
||||||
|
@ -466,6 +466,11 @@ void xaccInitSplitRegister (SplitRegister *reg, int type)
|
|||||||
xaccSetPriceCellValue (reg->creditCell, 0.0);
|
xaccSetPriceCellValue (reg->creditCell, 0.0);
|
||||||
xaccSetPriceCellValue (reg->valueCell, 0.0);
|
xaccSetPriceCellValue (reg->valueCell, 0.0);
|
||||||
|
|
||||||
|
/* use three decimal places to print share-related info.
|
||||||
|
* The format is a printf-style format for a double. */
|
||||||
|
xaccSetPriceCellFormat (reg->shrsCell, "%.3f");
|
||||||
|
xaccSetPriceCellFormat (reg->priceCell, "%.3f");
|
||||||
|
|
||||||
/* -------------------------------- */
|
/* -------------------------------- */
|
||||||
/* define how traversal works */
|
/* define how traversal works */
|
||||||
configTraverse (reg);
|
configTraverse (reg);
|
||||||
|
Loading…
Reference in New Issue
Block a user