From 4ab46c1b63a253f77aff9de8a128160ab1b2468f Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Tue, 25 Jul 2000 20:17:59 +0000 Subject: Fixed up the bit manipulation a bit here. 2000-07-25 Christopher James Lahey * e-table-selection-model.c: Fixed up the bit manipulation a bit here. svn path=/trunk/; revision=4327 --- widgets/e-table/ChangeLog | 5 +++++ widgets/e-table/e-table-selection-model.c | 37 ++++++++++++++++++++++++++++--- widgets/table/e-table-selection-model.c | 37 ++++++++++++++++++++++++++++--- 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index c6348038fd..3a6e2d9fb6 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,3 +1,8 @@ +2000-07-25 Christopher James Lahey + + * e-table-selection-model.c: Fixed up the bit manipulation a bit + here. + 2000-07-25 Christopher James Lahey * e-table-selection-model.c, e-table-selection-model.h: New files diff --git a/widgets/e-table/e-table-selection-model.c b/widgets/e-table/e-table-selection-model.c index 9a199f74e8..44ecc07979 100644 --- a/widgets/e-table/e-table-selection-model.c +++ b/widgets/e-table/e-table-selection-model.c @@ -42,8 +42,8 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) int i; int offset; if(etsm->row_count >= 0) { - if ((etsm->row_count & 0x1f /*%32*/) == 0) { - etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5/* /32 */) + 1); + if ((etsm->row_count & 0x1f) == 0) { + etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5) + 1); etsm->selection[etsm->row_count >> 5] = 0; } box = row >> 5; @@ -51,7 +51,38 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) etsm->selection[i] = (etsm->selection[i] >> 1) & (etsm->selection[i - 1] << 31) } offset = row & 0x1f; - etsm->selection[i] = ((etsm->selection[i] >> (32 - offset)) << (31 - offset)) & ((etsm->selection[i] << offset) >> offset); + etsm->selection[i] = ((etsm->selection[i] >> (32 - offset)) << (32 - offset)) & ((etsm->selection[i] << offset) >> (offset + 1)); + etsm->row_count ++; + } +} + +static void +model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) +{ + int box; + int i; + int offset; + if(etsm->row_count >= 0) { + box = row >> 5; + last = etsm->row_count >> 5 + + offset = row & 0x1f; + if (offset) + etsm->selection[box] = ((etsm->selection[box] >> (32 - offset)) << (32 - offset)) & ((etsm->selection[box] << offset) >> (offset - 1)); + else + etsm->selection[box] = etsm->selection[box] << 1; + if (box < last) { + etsm->selection[box] &= etsm->selection[box + 1] >> 31; + + for (i = box + 1; i < last; i++) { + etsm->selection[i] = (etsm->selection[i] << 1) & (etsm->selection[i + 1] >> 31); + } + etsm->selection[i] = etsm->selection[i] << 1; + } + etsm->row_count --; + if ((etsm->row_count & 0x1f) == 0) { + etsm->selection = e_realloc(etsm->selection, etsm->row_count >> 5); + } } } diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c index 9a199f74e8..44ecc07979 100644 --- a/widgets/table/e-table-selection-model.c +++ b/widgets/table/e-table-selection-model.c @@ -42,8 +42,8 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) int i; int offset; if(etsm->row_count >= 0) { - if ((etsm->row_count & 0x1f /*%32*/) == 0) { - etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5/* /32 */) + 1); + if ((etsm->row_count & 0x1f) == 0) { + etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5) + 1); etsm->selection[etsm->row_count >> 5] = 0; } box = row >> 5; @@ -51,7 +51,38 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) etsm->selection[i] = (etsm->selection[i] >> 1) & (etsm->selection[i - 1] << 31) } offset = row & 0x1f; - etsm->selection[i] = ((etsm->selection[i] >> (32 - offset)) << (31 - offset)) & ((etsm->selection[i] << offset) >> offset); + etsm->selection[i] = ((etsm->selection[i] >> (32 - offset)) << (32 - offset)) & ((etsm->selection[i] << offset) >> (offset + 1)); + etsm->row_count ++; + } +} + +static void +model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) +{ + int box; + int i; + int offset; + if(etsm->row_count >= 0) { + box = row >> 5; + last = etsm->row_count >> 5 + + offset = row & 0x1f; + if (offset) + etsm->selection[box] = ((etsm->selection[box] >> (32 - offset)) << (32 - offset)) & ((etsm->selection[box] << offset) >> (offset - 1)); + else + etsm->selection[box] = etsm->selection[box] << 1; + if (box < last) { + etsm->selection[box] &= etsm->selection[box + 1] >> 31; + + for (i = box + 1; i < last; i++) { + etsm->selection[i] = (etsm->selection[i] << 1) & (etsm->selection[i + 1] >> 31); + } + etsm->selection[i] = etsm->selection[i] << 1; + } + etsm->row_count --; + if ((etsm->row_count & 0x1f) == 0) { + etsm->selection = e_realloc(etsm->selection, etsm->row_count >> 5); + } } } -- cgit v1.2.3