Update RecnCell API to return the string_getter callback, but

place it into the cell instead of globally set.  Internally
deal with flag values directly but use the string-getter to
convert to i18n for display.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6146 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2001-11-30 02:11:24 +00:00
parent 9ee21ea922
commit ce3903a31e
5 changed files with 75 additions and 63 deletions

View File

@@ -707,48 +707,30 @@ gnc_get_reconcile_str (char reconciled_flag)
} }
/********************************************************************\ /********************************************************************\
* gnc_get_reconcile_valid_chars * * gnc_get_reconcile_valid_flags *
* return a string containing the i18n'd * * return a string containing the list of reconciled flags *
* characters for the list of reconciled flags *
* * * *
* Returns: the i18n'd reconciled flags string * * Returns: the i18n'd reconciled flags string *
\********************************************************************/ \********************************************************************/
const char * const char *
gnc_get_reconcile_valid_chars (void) gnc_get_reconcile_valid_flags (void)
{ {
const char flags[4] = { NREC, CREC, YREC, FREC }; static const char flags[] = { NREC, CREC, YREC, FREC, 0 };
static char str[5] = { 0, 0, 0, 0, 0 }; return flags;
int i = 0;
for (i = 0; i < sizeof (flags); i++) {
char *s = gnc_get_reconcile_str (flags[i]);
str[i] = *s;
}
return str;
} }
/********************************************************************\ /********************************************************************\
* gnc_get_reconcile_char_order * * gnc_get_reconcile_flag_order *
* return a string containing the i18n'd * * return a string containing the reconciled-flag change order *
* characters for the list of reconciled-flag order changes *
* * * *
* Args: reconciled_flag - the flag to stringize * * Args: reconciled_flag - the flag to stringize *
* Returns: the i18n'd reconciled string * * Returns: the i18n'd reconciled string *
\********************************************************************/ \********************************************************************/
const char * const char *
gnc_get_reconcile_char_order (void) gnc_get_reconcile_flag_order (void)
{ {
const char flags[2] = { NREC, CREC }; static const char flags[] = { NREC, CREC, 0 };
static char str[3] = { 0, 0, 0 }; return flags;
int i = 0;
for (i = 0; i < sizeof (flags); i++) {
char *s = gnc_get_reconcile_str (flags[i]);
str[i] = *s;
}
return str;
} }

View File

@@ -90,8 +90,8 @@ gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
gboolean include_children); gboolean include_children);
const char * gnc_get_reconcile_str (char reconciled_flag); const char * gnc_get_reconcile_str (char reconciled_flag);
const char * gnc_get_reconcile_valid_chars (void); const char * gnc_get_reconcile_valid_flags (void);
const char * gnc_get_reconcile_char_order (void); const char * gnc_get_reconcile_flag_order (void);
typedef enum typedef enum
{ {

View File

@@ -52,9 +52,10 @@ gnc_split_register_load_recn_cells (SplitRegister *reg)
if (!cell) return; if (!cell) return;
s = gnc_get_reconcile_valid_chars (); s = gnc_get_reconcile_valid_flags ();
gnc_recn_cell_set_valid_chars (cell, s, *s); gnc_recn_cell_set_valid_flags (cell, s, *s);
gnc_recn_cell_set_char_order (cell, gnc_get_reconcile_char_order ()); gnc_recn_cell_set_flag_order (cell, gnc_get_reconcile_flag_order ());
gnc_recn_cell_set_string_getter (cell, gnc_get_reconcile_str);
} }
static void static void
@@ -71,8 +72,8 @@ gnc_split_register_load_type_cells (SplitRegister *reg)
if (!cell) return; if (!cell) return;
/* FIXME: These should get moved to an i18n function */ /* FIXME: These should get moved to an i18n function */
gnc_recn_cell_set_valid_chars (cell, "IP", 'I'); gnc_recn_cell_set_valid_flags (cell, "IP", 'I');
gnc_recn_cell_set_char_order (cell, "IP"); gnc_recn_cell_set_flag_order (cell, "IP");
} }
static void static void

View File

@@ -50,6 +50,19 @@ static short module = MOD_REGISTER;
static void gnc_recn_cell_set_value (BasicCell *_cell, const char *value); static void gnc_recn_cell_set_value (BasicCell *_cell, const char *value);
static const char *
gnc_recn_cell_get_string (RecnCell *cell, char flag)
{
static char str[2] = { 0, 0 };
if (cell->get_string != NULL)
return (cell->get_string)(flag);
str[0] = flag;
return str;
}
static gboolean static gboolean
gnc_recn_cell_enter (BasicCell *_cell, gnc_recn_cell_enter (BasicCell *_cell,
int *cursor_position, int *cursor_position,
@@ -60,15 +73,15 @@ gnc_recn_cell_enter (BasicCell *_cell,
char * this_flag; char * this_flag;
if (cell->confirm_cb && if (cell->confirm_cb &&
! (cell->confirm_cb (cell->reconciled_flag, cell->confirm_data))) ! (cell->confirm_cb (cell->flag, cell->confirm_data)))
return FALSE; return FALSE;
/* Find the current flag in the list of flags */ /* Find the current flag in the list of flags */
this_flag = strchr (cell->char_order, cell->reconciled_flag); this_flag = strchr (cell->flag_order, cell->flag);
if (this_flag == NULL || *this_flag == '\0') { if (this_flag == NULL || *this_flag == '\0') {
/* If it's not there (or the list is empty) use default_flag */ /* If it's not there (or the list is empty) use default_flag */
cell->reconciled_flag = cell->default_flag; cell->flag = cell->default_flag;
} else { } else {
/* It is in the list -- choose the -next- item in the list (wrapping /* It is in the list -- choose the -next- item in the list (wrapping
@@ -76,13 +89,13 @@ gnc_recn_cell_enter (BasicCell *_cell,
*/ */
this_flag++; this_flag++;
if (*this_flag != '\0') if (*this_flag != '\0')
cell->reconciled_flag = *this_flag; cell->flag = *this_flag;
else else
cell->reconciled_flag = *(cell->char_order); cell->flag = *(cell->flag_order);
} }
/* And set the display */ /* And set the display */
gnc_recn_cell_set_flag (cell, cell->reconciled_flag); gnc_recn_cell_set_flag (cell, cell->flag);
return FALSE; return FALSE;
} }
@@ -92,10 +105,11 @@ gnc_recn_cell_init (RecnCell *cell)
{ {
gnc_basic_cell_init (&cell->cell); gnc_basic_cell_init (&cell->cell);
gnc_recn_cell_set_flag (cell, ' '); gnc_recn_cell_set_flag (cell, '\0');
cell->confirm_cb = NULL; cell->confirm_cb = NULL;
cell->valid_chars = ""; cell->get_string = NULL;
cell->char_order = ""; cell->valid_flags = "";
cell->flag_order = "";
cell->cell.enter_cell = gnc_recn_cell_enter; cell->cell.enter_cell = gnc_recn_cell_enter;
cell->cell.set_value = gnc_recn_cell_set_value; cell->cell.set_value = gnc_recn_cell_set_value;
@@ -122,26 +136,27 @@ gnc_recn_cell_set_value (BasicCell *_cell, const char *value)
if (!value || *value == '\0') if (!value || *value == '\0')
{ {
cell->reconciled_flag = cell->default_flag; cell->flag = cell->default_flag;
gnc_basic_cell_set_value_internal (_cell, ""); gnc_basic_cell_set_value_internal (_cell, "");
return; return;
} }
flag = cell->default_flag; flag = cell->default_flag;
if (strchr (cell->valid_chars, *value) != NULL) if (strchr (cell->valid_flags, *value) != NULL)
flag = *value; flag = *value;
gnc_recn_cell_set_flag (cell, flag); gnc_recn_cell_set_flag (cell, flag);
} }
void void
gnc_recn_cell_set_flag (RecnCell *cell, char reconciled_flag) gnc_recn_cell_set_flag (RecnCell *cell, char flag)
{ {
static char string[2] = { 0 , 0 }; const char *string;
g_return_if_fail (cell != NULL); g_return_if_fail (cell != NULL);
string[0] = cell->reconciled_flag = reconciled_flag; cell->flag = flag;
string = gnc_recn_cell_get_string (cell, flag);
gnc_basic_cell_set_value_internal (&cell->cell, string); gnc_basic_cell_set_value_internal (&cell->cell, string);
} }
@@ -151,7 +166,15 @@ gnc_recn_cell_get_flag (RecnCell *cell)
{ {
g_return_val_if_fail (cell != NULL, '\0'); g_return_val_if_fail (cell != NULL, '\0');
return cell->reconciled_flag; return cell->flag;
}
void
gnc_recn_cell_set_string_getter (RecnCell *cell,
RecnCellStringGetter get_string)
{
g_return_if_fail (cell != NULL);
cell->get_string = get_string;
} }
void void
@@ -165,22 +188,22 @@ gnc_recn_cell_set_confirm_cb (RecnCell *cell, RecnCellConfirm confirm_cb,
} }
void void
gnc_recn_cell_set_valid_chars (RecnCell *cell, const char *chars, gnc_recn_cell_set_valid_flags (RecnCell *cell, const char *flags,
char default_flag) char default_flag)
{ {
g_return_if_fail (cell != NULL); g_return_if_fail (cell != NULL);
g_return_if_fail (chars != NULL); g_return_if_fail (flags != NULL);
cell->valid_chars = (char *)chars; cell->valid_flags = (char *)flags;
cell->default_flag = default_flag; cell->default_flag = default_flag;
} }
void void
gnc_recn_cell_set_char_order (RecnCell *cell, const char *chars) gnc_recn_cell_set_flag_order (RecnCell *cell, const char *flags)
{ {
g_return_if_fail (cell != NULL); g_return_if_fail (cell != NULL);
g_return_if_fail (chars != NULL); g_return_if_fail (flags != NULL);
cell->char_order = (char *)chars; cell->flag_order = (char *)flags;
} }

View File

@@ -42,31 +42,36 @@
#include "basiccell.h" #include "basiccell.h"
typedef const char * (*RecnCellStringGetter) (char flag);
typedef gboolean (*RecnCellConfirm) (char old_flag, gpointer data); typedef gboolean (*RecnCellConfirm) (char old_flag, gpointer data);
typedef struct typedef struct
{ {
BasicCell cell; BasicCell cell;
char reconciled_flag; /* The actual flag value */ char flag; /* The actual flag value */
char * valid_chars; /* The list of valid flag types */ char * valid_flags; /* The list of valid flags */
char * char_order; /* The order of automatic flag selection */ char * flag_order; /* Automatic flag selection order */
char default_flag; /* The default flag for unknown user input */ char default_flag; /* Default flag for unknown user input */
RecnCellStringGetter get_string;
RecnCellConfirm confirm_cb; RecnCellConfirm confirm_cb;
gpointer confirm_data; gpointer confirm_data;
} RecnCell; } RecnCell;
BasicCell * gnc_recn_cell_new (void); BasicCell * gnc_recn_cell_new (void);
void gnc_recn_cell_set_flag (RecnCell *cell, char reconciled_flag); void gnc_recn_cell_set_flag (RecnCell *cell, char flag);
char gnc_recn_cell_get_flag (RecnCell *cell); char gnc_recn_cell_get_flag (RecnCell *cell);
void gnc_recn_cell_set_confirm_cb (RecnCell *cell, void gnc_recn_cell_set_confirm_cb (RecnCell *cell,
RecnCellConfirm confirm_cb, RecnCellConfirm confirm_cb,
gpointer data); gpointer data);
void gnc_recn_cell_set_string_getter (RecnCell *cell,
RecnCellStringGetter getter);
/* /*
* note that chars is copied into the RecnCell directly, but remains * note that chars is copied into the RecnCell directly, but remains
* the "property" of the caller. The caller must maintain the chars * the "property" of the caller. The caller must maintain the chars
@@ -75,8 +80,9 @@ void gnc_recn_cell_set_confirm_cb (RecnCell *cell,
* that use the same set of flags -- this saves you an alloc/free for * that use the same set of flags -- this saves you an alloc/free for
* each cell. - warlord 2001-11-28 * each cell. - warlord 2001-11-28
*/ */
void gnc_recn_cell_set_valid_chars (RecnCell *cell, const char *chars, void gnc_recn_cell_set_valid_flags (RecnCell *cell, const char *flags,
char default_flag); char default_flag);
void gnc_recn_cell_set_char_order (RecnCell *cell, const char *chars); void gnc_recn_cell_set_flag_order (RecnCell *cell, const char *flags);
#endif #endif