Implement foreground color handler. Remove cruft.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3010 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-10-03 08:03:47 +00:00
parent 184ae7b53d
commit d66f044a61
7 changed files with 111 additions and 38 deletions

View File

@ -410,6 +410,7 @@ xaccLedgerDisplayGeneral (Account *lead_account, GList *accounts,
* but will not do the gui init */
regData->ledger = xaccMallocSplitRegister (type, style,
xaccSRGetEntryHandler,
xaccSRGetFGColorHandler,
xaccGUIDMalloc,
xaccGUIDFree,
xaccGUIDCopy);

View File

@ -2956,6 +2956,75 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type,
}
}
guint32
xaccSRGetFGColorHandler (gpointer vcell_data, short _cell_type,
gpointer user_data)
{
GUID *guid = vcell_data;
CellType cell_type = _cell_type;
SplitRegister *reg = user_data;
const guint32 black = 0x000000;
const guint32 red = 0xff0000;
Split *split;
split = xaccSplitLookup (guid);
if (split == NULL)
return black;
switch (cell_type)
{
case SHRBALN_CELL:
{
double balance;
balance = xaccSplitGetShareBalance (split);
if (DEQ (balance, 0.0))
balance = 0.0;
if (balance < 0.0)
return red;
return black;
}
break;
case BALN_CELL:
{
double balance;
/* If the reverse_balance callback is present use that.
* Otherwise, reverse income and expense by default. */
balance = xaccSplitGetBalance (split);
if (reverse_balance != NULL)
{
Account *account;
account = xaccSplitGetAccount(split);
if (reverse_balance(account))
balance = -balance;
}
else if ((INCOME_REGISTER == reg->type) ||
(EXPENSE_REGISTER == reg->type))
balance = -balance;
if (DEQ (balance, 0.0))
balance = 0.0;
if (balance < 0.0)
return red;
return black;
}
break;
default:
break;
}
return black;
}
/* ======================================================== */
static void
@ -3357,8 +3426,6 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist,
vcell_loc.virt_col = 0;
gnc_table_set_cursor (table, reg->header, vcell_loc);
PINFO ("load register of %d phys rows ----------- \n", reg->num_phys_rows);
/* populate the table */
i = 0;
vcell_loc.virt_row = 1; /* header is vrow zero */

View File

@ -179,5 +179,7 @@ void xaccSRShowPresentDivider (SplitRegister *reg, gboolean show_present);
/* Private function, for MultiLedger.c only */
const char * xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type,
gpointer user_data);
guint32 xaccSRGetFGColorHandler (gpointer vcell_data, short _cell_type,
gpointer user_data);
#endif /* __XACC_SPLIT_LEDGER_H__ */

View File

@ -123,6 +123,7 @@ xaccInitSplitRegister (SplitRegister *reg,
SplitRegisterType type,
SplitRegisterStyle style,
TableGetEntryHandler entry_handler,
TableGetFGColorHandler fg_color_handler,
VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy);
@ -130,11 +131,11 @@ xaccInitSplitRegister (SplitRegister *reg,
/* ============================================== */
#define LABEL(NAME,label) \
{ \
BasicCell *hcell; \
hcell = reg->header_label_cells[NAME##_CELL]; \
xaccSetBasicCellValue (hcell, label); \
#define LABEL(NAME,label) \
{ \
BasicCell *hcell; \
hcell = reg->header_label_cells[NAME##_CELL]; \
xaccSetBasicCellValue (hcell, label); \
}
/* ============================================== */
@ -590,6 +591,7 @@ SplitRegister *
xaccMallocSplitRegister (SplitRegisterType type,
SplitRegisterStyle style,
TableGetEntryHandler entry_handler,
TableGetFGColorHandler fg_color_handler,
VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy)
@ -598,7 +600,8 @@ xaccMallocSplitRegister (SplitRegisterType type,
reg = g_new(SplitRegister, 1);
xaccInitSplitRegister (reg, type, style, entry_handler,
xaccInitSplitRegister (reg, type, style,
entry_handler, fg_color_handler,
allocator, deallocator, copy);
return reg;
@ -723,8 +726,7 @@ mallocCursors (SplitRegister *reg)
return;
}
reg->num_header_rows = 1;
reg->header = gnc_cellblock_new (reg->num_header_rows, num_cols);
reg->header = gnc_cellblock_new (1, num_cols);
/* cursors used in the single & double line displays */
reg->single_cursor = gnc_cellblock_new (1, num_cols);
@ -752,6 +754,7 @@ xaccInitSplitRegister (SplitRegister *reg,
SplitRegisterType type,
SplitRegisterStyle style,
TableGetEntryHandler entry_handler,
TableGetFGColorHandler fg_color_handler,
VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy)
@ -902,7 +905,9 @@ xaccInitSplitRegister (SplitRegister *reg,
reg->cursor_virt_row = 1;
reg->num_virt_rows = 2; /* one header, one single_cursor */
table = gnc_table_new (entry_handler, reg, allocator, deallocator, copy);
table = gnc_table_new (entry_handler, fg_color_handler, reg,
allocator, deallocator, copy);
gnc_table_set_size (table, reg->num_virt_rows, 1);
/* Set up header */
@ -912,7 +917,7 @@ xaccInitSplitRegister (SplitRegister *reg,
gnc_table_set_cursor (table, header, vcell_loc);
}
/* Set up first and only cursor */
/* Set up first and only initial row */
{
VirtualLocation vloc;

View File

@ -145,10 +145,6 @@ typedef enum
CURSOR_NONE
} CursorClass;
/* The value of NUM_CELLS should be larger than the number of
* cells defined in the structure below!
*/
#define NUM_CELLS 25
typedef struct _SplitRegisterBuffer SplitRegisterBuffer;
typedef struct _SplitRegister SplitRegister;
@ -184,21 +180,15 @@ struct _SplitRegister {
PriceCell * priceCell;
PriceCell * sharesCell;
/* The type of the register, must be one of the enumerated types
* named *_REGISTER, *_LEDGER, above */
SplitRegisterType type;
SplitRegisterStyle style;
/* some private data; outsiders should not access this */
int num_header_rows;
int num_phys_rows;
int num_virt_rows;
int cursor_virt_row;
BasicCell *header_label_cells[NUM_CELLS];
BasicCell *header_label_cells[CELL_TYPE_COUNT];
/* user_data allows users of this object to hang
* private data onto it */
@ -242,6 +232,7 @@ SplitRegister *
xaccMallocSplitRegister (SplitRegisterType type,
SplitRegisterStyle style,
TableGetEntryHandler entry_handler,
TableGetFGColorHandler fg_color_handler,
VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy);

View File

@ -72,6 +72,7 @@ static void gnc_table_resize (Table * table, int virt_rows, int virt_cols);
Table *
gnc_table_new (TableGetEntryHandler entry_handler,
TableGetFGColorHandler fg_color_handler,
gpointer entry_handler_data,
VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator,
@ -88,6 +89,7 @@ gnc_table_new (TableGetEntryHandler entry_handler,
table = g_new0(Table, 1);
table->entry_handler = entry_handler;
table->fg_color_handler = fg_color_handler;
table->entry_handler_data = entry_handler_data;
table->vcell_data_allocator = allocator;
table->vcell_data_deallocator = deallocator;
@ -244,32 +246,31 @@ gnc_table_get_fg_color_virtual (Table *table, VirtualLocation virt_loc)
VirtualCell *vcell;
CellBlockCell *cb_cell;
BasicCell *cell;
guint32 fg_color;
guint32 fg_color = 0x0; /* black */
fg_color = 0x000000; /* black */
vcell = gnc_table_get_virtual_cell (table, virt_loc.vcell_loc);
if (vcell == NULL)
return fg_color;
cb_cell = gnc_cellblock_get_cell (vcell->cellblock,
virt_loc.phys_row_offset,
virt_loc.phys_col_offset);
if (cb_cell == NULL)
return fg_color;
if (virt_cell_loc_equal (table->current_cursor_loc.vcell_loc,
virt_loc.vcell_loc))
{
vcell = gnc_table_get_virtual_cell (table, virt_loc.vcell_loc);
if (vcell == NULL)
return fg_color;
cb_cell = gnc_cellblock_get_cell (vcell->cellblock,
virt_loc.phys_row_offset,
virt_loc.phys_col_offset);
if (cb_cell == NULL)
return fg_color;
cell = cb_cell->cell;
if (cell == NULL)
return fg_color;
if (cell->use_fg_color)
fg_color = cell->fg_color;
if (cell->use_fg_color && (XACC_CELL_ALLOW_SHADOW & cell->input_output))
return cell->fg_color;
}
return fg_color;
return table->fg_color_handler (vcell->vcell_data, cb_cell->cell_type,
table->entry_handler_data);
}
/* ==================================================== */

View File

@ -132,6 +132,10 @@ typedef const char * (*TableGetEntryHandler) (gpointer vcell_data,
short cell_type,
gpointer user_data);
typedef guint32 (*TableGetFGColorHandler) (gpointer vcell_data,
short cell_type,
gpointer user_data);
typedef gpointer (*VirtCellDataAllocator) (void);
typedef void (*VirtCellDataDeallocator) (gpointer user_data);
typedef void (*VirtCellDataCopy) (gpointer to, gconstpointer from);
@ -178,6 +182,7 @@ struct _Table
void * ui_data;
TableGetEntryHandler entry_handler;
TableGetFGColorHandler fg_color_handler;
gpointer entry_handler_data;
TableDestroyFunc destroy;
@ -190,6 +195,7 @@ struct _Table
/* Functions to create and destroy Tables. */
Table * gnc_table_new (TableGetEntryHandler entry_handler,
TableGetFGColorHandler fg_color_handler,
gpointer entry_handler_data,
VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator,