38 #include <glib/gi18n.h> 41 #include "gnc-exp-parser.h" 52 static void gnc_price_cell_init (
PriceCell *cell);
53 static void gnc_price_cell_set_value_internal (BasicCell *bcell,
55 static const char * gnc_price_cell_print_value (
PriceCell *cell);
59 gnc_price_cell_enter (BasicCell *_cell,
64 *cursor_position = -1;
72 gnc_price_cell_modify_verify (BasicCell *_cell,
82 const char *toks =
"+-*/=()_";
83 char *validated_newval = NULL;
85 DEBUG(
"%s, %d, %s, %d, %d, %d, %d",
86 change ? (gchar *)change :
"(null)", change_len,
87 newval ? (gchar *)newval :
"(null)", newval_len,
88 *cursor_position, *start_selection, *end_selection);
90 validated_newval = gnc_basic_cell_validate (_cell, cell->
print_info,
94 if (!validated_newval)
97 gnc_basic_cell_set_value_internal (_cell, validated_newval);
98 g_free (validated_newval);
100 *end_selection = *start_selection = *cursor_position;
105 gnc_price_cell_parse (
PriceCell *cell, gboolean update_value)
114 oldval = cell->cell.value;
119 char *err_location = NULL;
120 if (strlen(g_strstrip(cell->cell.value)) == 0)
122 cell->amount = gnc_numeric_zero ();
124 else if (gnc_exp_parser_parse (cell->cell.value, &amount, &err_location))
129 cell->amount = amount;
133 return (err_location - cell->cell.value);
140 newval = gnc_price_cell_print_value (cell);
143 if (strcmp(newval, oldval) == 0)
147 gnc_basic_cell_set_value_internal (&cell->cell, newval);
152 gnc_price_cell_leave (BasicCell *_cell)
154 gint error_position = -1;
157 error_position = gnc_price_cell_parse (cell, TRUE);
158 if (error_position != -1)
161 _(
"An error occurred while processing '%s' at position %d"),
162 cell->cell.value, error_position);
174 gnc_price_cell_init (cell);
182 gnc_basic_cell_init (&(cell->cell));
184 cell->amount = gnc_numeric_zero ();
188 cell->
print_info = gnc_default_print_info (FALSE);
192 cell->cell.enter_cell = gnc_price_cell_enter;
193 cell->cell.modify_verify = gnc_price_cell_modify_verify;
194 cell->cell.leave_cell = gnc_price_cell_leave;
195 cell->cell.set_value = gnc_price_cell_set_value_internal;
199 gnc_price_cell_print_value (
PriceCell *cell)
211 return gnc_numeric_zero ();
213 gnc_price_cell_parse (cell, FALSE);
229 cell->amount = amount;
230 buff = gnc_price_cell_print_value (cell);
233 if (g_strcmp0 (buff, cell->cell.value) == 0)
236 gnc_basic_cell_set_value_internal (&cell->cell, buff);
256 cell->amount = gnc_numeric_zero ();
259 gnc_basic_cell_set_value_internal (&cell->cell,
"");
299 gnc_price_cell_set_value_internal (BasicCell *_cell,
const char *str)
309 else if (gnc_exp_parser_parse (str, &amount, NULL))
gboolean blank_zero
fraction used for rounding, if 0 no rounding
int fraction
the amount associated with this cell
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
utility functions for the GnuCash UI
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
#define DEBUG(format, args...)
Print a debugging message.
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
void gnc_price_cell_blank(PriceCell *cell)
Sets the cell as blank, regardless of the blank_zero value.
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
Change the denominator of a gnc_numeric value to the specified denominator under standard arguments '...
The PriceCell object implements a cell handler that stores a single double-precision value...
GNCPrintAmountInfo print_info
controls printing of zero values
All type declarations for the whole Gnucash engine.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
void gnc_price_cell_set_fraction(PriceCell *cell, int fraction)
Sets the fraction used for rounding.
void gnc_price_cell_set_print_info(PriceCell *cell, GNCPrintAmountInfo print_info)
set the printing context of the price cell
gboolean need_to_parse
amount printing context
void gnc_price_cell_set_blank_zero(PriceCell *cell, gboolean blank_zero)
determines whether 0 values are left blank or printed.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
gboolean gnc_price_cell_set_value(PriceCell *cell, gnc_numeric amount)
updates amount, returns TRUE if string representation actually changed
BasicCell * gnc_price_cell_new(void)
installs a callback to handle price recording
void gnc_price_cell_set_debt_credit_value(PriceCell *debit, PriceCell *credit, gnc_numeric amount)
updates two cells; the deb cell if amt is negative, the credit cell if amount is positive, and makes the other cell blank.
gnc_numeric gnc_price_cell_get_value(PriceCell *cell)
return the value of a price cell