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

View File

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

View File

@@ -52,9 +52,10 @@ gnc_split_register_load_recn_cells (SplitRegister *reg)
if (!cell) return;
s = gnc_get_reconcile_valid_chars ();
gnc_recn_cell_set_valid_chars (cell, s, *s);
gnc_recn_cell_set_char_order (cell, gnc_get_reconcile_char_order ());
s = gnc_get_reconcile_valid_flags ();
gnc_recn_cell_set_valid_flags (cell, s, *s);
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
@@ -71,8 +72,8 @@ gnc_split_register_load_type_cells (SplitRegister *reg)
if (!cell) return;
/* FIXME: These should get moved to an i18n function */
gnc_recn_cell_set_valid_chars (cell, "IP", 'I');
gnc_recn_cell_set_char_order (cell, "IP");
gnc_recn_cell_set_valid_flags (cell, "IP", 'I');
gnc_recn_cell_set_flag_order (cell, "IP");
}
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 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
gnc_recn_cell_enter (BasicCell *_cell,
int *cursor_position,
@@ -60,15 +73,15 @@ gnc_recn_cell_enter (BasicCell *_cell,
char * this_flag;
if (cell->confirm_cb &&
! (cell->confirm_cb (cell->reconciled_flag, cell->confirm_data)))
! (cell->confirm_cb (cell->flag, cell->confirm_data)))
return FALSE;
/* 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 it's not there (or the list is empty) use default_flag */
cell->reconciled_flag = cell->default_flag;
cell->flag = cell->default_flag;
} else {
/* 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++;
if (*this_flag != '\0')
cell->reconciled_flag = *this_flag;
cell->flag = *this_flag;
else
cell->reconciled_flag = *(cell->char_order);
cell->flag = *(cell->flag_order);
}
/* And set the display */
gnc_recn_cell_set_flag (cell, cell->reconciled_flag);
gnc_recn_cell_set_flag (cell, cell->flag);
return FALSE;
}
@@ -92,10 +105,11 @@ gnc_recn_cell_init (RecnCell *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->valid_chars = "";
cell->char_order = "";
cell->get_string = NULL;
cell->valid_flags = "";
cell->flag_order = "";
cell->cell.enter_cell = gnc_recn_cell_enter;
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')
{
cell->reconciled_flag = cell->default_flag;
cell->flag = cell->default_flag;
gnc_basic_cell_set_value_internal (_cell, "");
return;
}
flag = cell->default_flag;
if (strchr (cell->valid_chars, *value) != NULL)
if (strchr (cell->valid_flags, *value) != NULL)
flag = *value;
gnc_recn_cell_set_flag (cell, flag);
}
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);
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);
}
@@ -151,7 +166,15 @@ gnc_recn_cell_get_flag (RecnCell *cell)
{
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
@@ -165,22 +188,22 @@ gnc_recn_cell_set_confirm_cb (RecnCell *cell, RecnCellConfirm confirm_cb,
}
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)
{
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;
}
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 (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"
typedef const char * (*RecnCellStringGetter) (char flag);
typedef gboolean (*RecnCellConfirm) (char old_flag, gpointer data);
typedef struct
{
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 * char_order; /* The order of automatic flag selection */
char default_flag; /* The default flag for unknown user input */
char * valid_flags; /* The list of valid flags */
char * flag_order; /* Automatic flag selection order */
char default_flag; /* Default flag for unknown user input */
RecnCellStringGetter get_string;
RecnCellConfirm confirm_cb;
gpointer confirm_data;
} RecnCell;
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);
void gnc_recn_cell_set_confirm_cb (RecnCell *cell,
RecnCellConfirm confirm_cb,
gpointer data);
void gnc_recn_cell_set_string_getter (RecnCell *cell,
RecnCellStringGetter getter);
/*
* note that chars is copied into the RecnCell directly, but remains
* 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
* 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);
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