Skip to content

Commit

Permalink
Only allow price & shares to be editied for stock, mutual, and currency
Browse files Browse the repository at this point in the history
accounts.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3235 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
jdavisp3 committed Dec 5, 2000
1 parent e38062b commit c2cfb72
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 57 deletions.
1 change: 1 addition & 0 deletions src/MultiLedger.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ xaccLedgerDisplayGeneral (Account *lead_account, GList *accounts,
* but will not do the gui init */
regData->ledger = xaccMallocSplitRegister (type, style, FALSE,
xaccSRGetEntryHandler,
xaccSRGetIOFlagsHandler,
xaccSRGetFGColorHandler,
xaccSRGetBGColorHandler,
xaccGUIDMalloc,
Expand Down
94 changes: 85 additions & 9 deletions src/SplitLedger.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ gnc_split_get_quantity_denom (Split *split)
static void
sr_set_cell_fractions (SplitRegister *reg, Split *split)
{
SRInfo *info = xaccSRGetInfo(reg);
SRInfo *info = xaccSRGetInfo (reg);
Account *account;

account = xaccSplitGetAccount (split);
Expand Down Expand Up @@ -893,8 +893,6 @@ LedgerMoveCursor (Table *table, VirtualLocation *p_new_virt_loc)
xaccSRSetTransVisible (reg, vc_loc, TRUE,
reg->style == REG_STYLE_JOURNAL);

gnc_table_find_close_valid_cell (table, p_new_virt_loc, exact_traversal);

do_refresh = TRUE;
}
else
Expand All @@ -907,8 +905,13 @@ LedgerMoveCursor (Table *table, VirtualLocation *p_new_virt_loc)

sr_set_cell_fractions (reg, new_split);

gnc_table_find_close_valid_cell (table, p_new_virt_loc, exact_traversal);

if (do_refresh)
gnc_table_refresh_gui (reg->table);
{
gnc_table_refresh_gui (table);
gnc_table_leave_update (table, table->current_cursor_loc);
}
}

/* This function determines if auto-completion is appropriate and,
Expand Down Expand Up @@ -1465,10 +1468,10 @@ xaccSRGetTrans (SplitRegister *reg, VirtualCellLocation vcell_loc)
vcell_loc.virt_row--;

split = sr_get_split (reg, vcell_loc);
if (split == NULL) {
PERR ("no parent \n");

/* This split could be NULL during register initialization. */
if (split == NULL)
return NULL;
}

return xaccSplitGetParent(split);
}
Expand Down Expand Up @@ -1550,7 +1553,7 @@ xaccSRGetCurrentTrans (SplitRegister *reg)

/* ======================================================== */

Split *
Split *
xaccSRGetCurrentSplit (SplitRegister *reg)
{
if (reg == NULL)
Expand All @@ -1561,7 +1564,7 @@ xaccSRGetCurrentSplit (SplitRegister *reg)

/* ======================================================== */

Split *
Split *
xaccSRGetBlankSplit (SplitRegister *reg)
{
SRInfo *info = xaccSRGetInfo(reg);
Expand Down Expand Up @@ -3471,6 +3474,79 @@ xaccSRGetEntryHandler (VirtualLocation virt_loc, short _cell_type,
}
}

CellIOFlags
xaccSRGetIOFlagsHandler (VirtualLocation virt_loc, gpointer user_data)
{
SplitRegister *reg = user_data;
CellType cell_type;

cell_type = xaccSplitRegisterGetCellType (reg, virt_loc);

switch (cell_type)
{
case DATE_CELL:
case NUM_CELL:
case DESC_CELL:
case ACTN_CELL:
case XFRM_CELL:
case XTO_CELL:
case MEMO_CELL:
case CRED_CELL:
case DEBT_CELL:
case MXFRM_CELL:
case NOTES_CELL:
return XACC_CELL_ALLOW_ALL;

case RECN_CELL:
return XACC_CELL_ALLOW_ALL | XACC_CELL_ALLOW_EXACT_ONLY;

case PRIC_CELL:
case SHRS_CELL:
{
Split *split = sr_get_split (reg, virt_loc.vcell_loc);
GNCAccountType account_type;
CursorClass cursor_class;
Account *account;
guint32 changed;

if (!split)
return XACC_CELL_ALLOW_ALL;

cursor_class = xaccSplitRegisterGetCursorClass (reg,
virt_loc.vcell_loc);
if (cursor_class != CURSOR_CLASS_SPLIT)
return XACC_CELL_ALLOW_ALL;

changed = xaccSplitRegisterGetChangeFlag (reg);
if (MOD_XFRM & changed)
{
account = xaccGetAccountFromFullName (gncGetCurrentGroup (),
reg->xfrmCell->cell.value,
account_separator);
if (!account)
account = xaccSplitGetAccount (split);
}
else
account = xaccSplitGetAccount (split);

if (!account)
return XACC_CELL_ALLOW_ALL;

account_type = xaccAccountGetType (account);

if (account_type == STOCK ||
account_type == MUTUAL ||
account_type == CURRENCY)
return XACC_CELL_ALLOW_ALL;

return XACC_CELL_ALLOW_SHADOW;
}

default:
return XACC_CELL_ALLOW_NONE;
}
}

guint32
xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
{
Expand Down
2 changes: 2 additions & 0 deletions src/SplitLedger.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ const char * xaccSRGetEntryHandler (VirtualLocation virt_loc,
short _cell_type,
gboolean *changed,
gpointer user_data);
CellIOFlags xaccSRGetIOFlagsHandler (VirtualLocation virt_loc,
gpointer user_data);
guint32 xaccSRGetFGColorHandler (VirtualLocation virt_loc,
gpointer user_data);
guint32 xaccSRGetBGColorHandler (VirtualLocation virt_loc,
Expand Down
1 change: 0 additions & 1 deletion src/register/basiccell.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ xaccInitBasicCell (BasicCell *cell)
{
cell->changed = 0;
cell->conditionally_changed = 0;
cell->input_output = XACC_CELL_ALLOW_ALL;

cell->value = g_strdup("");
cell->blank_help = NULL;
Expand Down
14 changes: 8 additions & 6 deletions src/register/basiccell.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@


/* define a bitmask */
#define XACC_CELL_ALLOW_NONE 0x0
#define XACC_CELL_ALLOW_SHADOW 0x1
#define XACC_CELL_ALLOW_INPUT 0x2
#define XACC_CELL_ALLOW_ALL 0x3
#define XACC_CELL_ALLOW_EXACT_ONLY 0x4
typedef enum
{
XACC_CELL_ALLOW_NONE = 0,
XACC_CELL_ALLOW_SHADOW = 1 << 0,
XACC_CELL_ALLOW_INPUT = 1 << 1,
XACC_CELL_ALLOW_ALL = XACC_CELL_ALLOW_SHADOW | XACC_CELL_ALLOW_INPUT,
XACC_CELL_ALLOW_EXACT_ONLY = 1 << 2
} CellIOFlags;

#define GNC_CELL_CHANGED 0xffffffff

Expand Down Expand Up @@ -222,7 +225,6 @@ struct _BasicCell

guint32 changed; /* 2^32-1 if value modified */
guint32 conditionally_changed; /* value if modified conditionally */
guint8 input_output; /* allowed behavior flags */

/* "virtual", overloaded set-value method */
CellSetValueFunc set_value;
Expand Down
29 changes: 9 additions & 20 deletions src/register/splitreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ xaccInitSplitRegister (SplitRegister *reg,
SplitRegisterStyle style,
gboolean use_double_line,
TableGetEntryHandler entry_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
VirtCellDataAllocator allocator,
Expand Down Expand Up @@ -501,7 +502,6 @@ configLayout (SplitRegister *reg)
set_cell (reg, curs, DATE_CELL, 0, 0);
set_cell (reg, curs, NUM_CELL, 0, 1);
set_cell (reg, curs, DESC_CELL, 0, 2);
set_cell (reg, curs, XTO_CELL, 0, 3);
set_cell (reg, curs, TDEBT_CELL, 0, 6);
set_cell (reg, curs, TCRED_CELL, 0, 7);

Expand Down Expand Up @@ -563,7 +563,7 @@ configLayout (SplitRegister *reg)
set_cell (reg, curs, ACTN_CELL, 0, 1);
set_cell (reg, curs, MEMO_CELL, 0, 2);
set_cell (reg, curs, XFRM_CELL, 0, 3);
set_cell (reg, curs, RECN_CELL, 0, 4);
set_cell (reg, curs, RECN_CELL, 0, 4);
set_cell (reg, curs, SHRS_CELL, 0, 5);
set_cell (reg, curs, PRIC_CELL, 0, 6);
set_cell (reg, curs, DEBT_CELL, 0, 7);
Expand Down Expand Up @@ -597,7 +597,6 @@ configLayout (SplitRegister *reg)
set_cell (reg, curs, DATE_CELL, 0, 0);
set_cell (reg, curs, NUM_CELL, 0, 1);
set_cell (reg, curs, DESC_CELL, 0, 2);
set_cell (reg, curs, XTO_CELL, 0, 3);
set_cell (reg, curs, TSHRS_CELL, 0, 6);
set_cell (reg, curs, TDEBT_CELL, 0, 8);
set_cell (reg, curs, TCRED_CELL, 0, 9);
Expand Down Expand Up @@ -634,6 +633,7 @@ xaccMallocSplitRegister (SplitRegisterType type,
SplitRegisterStyle style,
gboolean use_double_line,
TableGetEntryHandler entry_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
VirtCellDataAllocator allocator,
Expand All @@ -645,7 +645,8 @@ xaccMallocSplitRegister (SplitRegisterType type,
reg = g_new0 (SplitRegister, 1);

xaccInitSplitRegister (reg, type, style, use_double_line,
entry_handler, fg_color_handler, bg_color_handler,
entry_handler, io_flag_handler,
fg_color_handler, bg_color_handler,
allocator, deallocator, copy);

return reg;
Expand Down Expand Up @@ -755,6 +756,7 @@ xaccInitSplitRegister (SplitRegister *reg,
SplitRegisterStyle style,
gboolean use_double_line,
TableGetEntryHandler entry_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
VirtCellDataAllocator allocator,
Expand Down Expand Up @@ -825,7 +827,6 @@ xaccInitSplitRegister (SplitRegister *reg,
* result of which is that an empty cell has landed on a cell that
* was previously non-empty. We want to make sure that we erase
* those cell contents. The null cells handles this for us. */
reg->nullCell->input_output = XACC_CELL_ALLOW_NONE;
xaccSetBasicCellValue (reg->nullCell, "");

/* The num cell is the transaction number */
Expand Down Expand Up @@ -869,25 +870,12 @@ xaccInitSplitRegister (SplitRegister *reg,
xaccSetBasicCellBlankHelp (&reg->notesCell->cell,
_("Enter notes for the transaction"));

/* The balance and total cells are just placeholders */
reg->balanceCell->cell.input_output = XACC_CELL_ALLOW_NONE;
reg->shrbalnCell->cell.input_output = XACC_CELL_ALLOW_NONE;
reg->tcreditCell->cell.input_output = XACC_CELL_ALLOW_NONE;
reg->tdebitCell->cell.input_output = XACC_CELL_ALLOW_NONE;
reg->tsharesCell->cell.input_output = XACC_CELL_ALLOW_NONE;
reg->tbalanceCell->cell.input_output = XACC_CELL_ALLOW_NONE;
reg->tshrbalnCell->cell.input_output = XACC_CELL_ALLOW_NONE;

/* by default, don't blank zeros on the price cells. */
xaccSetPriceCellBlankZero(reg->priceCell, FALSE);

/* Use 5 decimal places for prices */
xaccSetPriceCellFraction (reg->priceCell, 1000000);

/* The reconcile cell should only be entered with the pointer, and
* only then when the user clicks directly on the cell. */
reg->recnCell->cell.input_output |= XACC_CELL_ALLOW_EXACT_ONLY;

/* Initialize price cells */
xaccSetPriceCellValue (reg->debitCell, gnc_numeric_zero ());
xaccSetPriceCellValue (reg->creditCell, gnc_numeric_zero ());
Expand Down Expand Up @@ -932,6 +920,7 @@ xaccInitSplitRegister (SplitRegister *reg,
configAction (reg);

table = gnc_table_new (entry_handler,
io_flag_handler,
fg_color_handler,
bg_color_handler,
sr_get_cell_borders,
Expand All @@ -940,6 +929,8 @@ xaccInitSplitRegister (SplitRegister *reg,
deallocator,
copy);

reg->table = table;

/* Set up header */
{
VirtualCellLocation vcell_loc = { 0, 0 };
Expand All @@ -961,8 +952,6 @@ xaccInitSplitRegister (SplitRegister *reg,
NULL, TRUE, TRUE, vloc.vcell_loc);
gnc_table_move_cursor (table, vloc);
}

reg->table = table;
}

/* ============================================== */
Expand Down
1 change: 1 addition & 0 deletions src/register/splitreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ xaccMallocSplitRegister (SplitRegisterType type,
SplitRegisterStyle style,
gboolean use_double_line,
TableGetEntryHandler entry_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
VirtCellDataAllocator allocator,
Expand Down

0 comments on commit c2cfb72

Please sign in to comment.