static void gnc_price_cell_set_value_internal (BasicCell *_cell, const char *str) { PriceCell *cell = (PriceCell *) _cell; gnc_numeric amount; if (str == NULL) str = ""; if (*str == '\0') gnc_price_cell_set_value (cell, gnc_numeric_zero ()); else if (gnc_exp_parser_parse (str, &amount, NULL)) gnc_price_cell_set_value (cell, amount); }
void gnc_price_cell_set_debt_credit_value (PriceCell * debit, PriceCell * credit, gnc_numeric amount) { /* debits are positive, credits are negative */ if (gnc_numeric_positive_p (amount)) { gnc_price_cell_set_value (debit, amount); gnc_price_cell_set_value (credit, gnc_numeric_zero ()); } else { gnc_price_cell_set_value (debit, gnc_numeric_zero ()); gnc_price_cell_set_value (credit, gnc_numeric_neg (amount)); } }
static void set_value_price_cell(BasicCell *cell, gnc_numeric new_value) { PriceCell *pcell = (PriceCell*) cell; if (!cell) return; if (gnc_numeric_equal (new_value, gnc_price_cell_get_value(pcell))) return; gnc_price_cell_set_value (pcell, new_value); gnc_basic_cell_set_changed (cell, TRUE); }
static gboolean gnc_price_cell_direct_update (BasicCell *bcell, int *cursor_position, int *start_selection, int *end_selection, void *gui_data) { PriceCell *cell = (PriceCell *) bcell; GdkEventKey *event = gui_data; struct lconv *lc; gboolean is_return; if (event->type != GDK_KEY_PRESS) return FALSE; lc = gnc_localeconv (); is_return = FALSE; #ifdef G_OS_WIN32 /* gdk never sends GDK_KP_Decimal on win32. See #486658 */ if (event->hardware_keycode == VK_DECIMAL) event->keyval = GDK_KP_Decimal; #endif switch (event->keyval) { case GDK_KEY_Return: if (!(event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK))) is_return = TRUE; /* fall through */ case GDK_KEY_KP_Enter: { char *error_loc; gnc_numeric amount; gboolean parse_ok; gboolean changed = FALSE; if (!cell->need_to_parse) return FALSE; parse_ok = gnc_exp_parser_parse (cell->cell.value, &amount, &error_loc); if (parse_ok) changed = gnc_price_cell_set_value (cell, amount); else if (!cell->cell.value || cell->cell.value[0] == '\0') changed = gnc_price_cell_set_value (cell, gnc_numeric_zero ()); else *cursor_position = error_loc - cell->cell.value; /* If there is a problem with the parse, swallow * the key so we stay put. */ if (!parse_ok) return TRUE; /* If nothing has changed, let the key cause a * cursor activation no matter what. */ if (!changed) return FALSE; /* If it's not a plain return, stay put. This * allows a 'calculator' style operation using * keypad enter where you can keep entering more * items to add, say. */ return !is_return; } case GDK_KEY_KP_Decimal: break; default: return FALSE; } /* This point is only reached when the KP_Decimal key is pressed. */ gnc_basic_cell_insert_decimal(bcell, cell->print_info.monetary ? lc->mon_decimal_point[0] : lc->decimal_point[0], cursor_position, start_selection, end_selection); cell->need_to_parse = TRUE; return TRUE; }