From 120687c8a8b3b7df579f2dcad8badefb67e4d30b Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Tue, 25 Jul 2000 20:55:07 +0000 Subject: Added comments to the bit field code. 2000-07-25 Christopher James Lahey * e-table-selection-model.c: Added comments to the bit field code. * e-table-selection-model.h: Made the selection data guint32s. svn path=/trunk/; revision=4329 --- widgets/e-table/ChangeLog | 10 ++++++++++ widgets/e-table/e-table-selection-model.c | 15 +++++++++++++-- widgets/e-table/e-table-selection-model.h | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'widgets/e-table') diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index 3a6e2d9fb6..6b8b1f6918 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,3 +1,13 @@ +2000-07-25 Christopher James Lahey + + * e-table-selection-model.c: Added comments to the bit data. + + * e-table-selection-model.h: Made the selection data guint32s. + +2000-07-25 Christopher James Lahey + + * e-table-selection-model.c: More fixes. + 2000-07-25 Christopher James Lahey * e-table-selection-model.c: Fixed up the bit manipulation a bit diff --git a/widgets/e-table/e-table-selection-model.c b/widgets/e-table/e-table-selection-model.c index b8c4d65d2e..6bdfa90990 100644 --- a/widgets/e-table/e-table-selection-model.c +++ b/widgets/e-table/e-table-selection-model.c @@ -44,19 +44,26 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) if(etsm->row_count >= 0) { guint32 bitmask1 = 0xffff; guint32 bitmask2; + + /* Add another word if needed. */ if ((etsm->row_count & 0x1f) == 0) { etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5) + 1); etsm->selection[etsm->row_count >> 5] = 0; } + + /* The box is the word that our row is in. */ box = row >> 5; + /* Shift all words to the right of our box right one bit. */ for (i = etsm->row_count >> 5; i > box; i--) { etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31) } + /* Build bitmasks for the left and right half of the box */ offset = row & 0x1f; bitmask1 = bitmask1 << (32 - offset); bitmask2 = ~bitmask1; - etsm->selection[i] = (etsm->selection[i] & bitmask1) | ((etsm->selection[i] & bitmask2) >> 1); + /* Shift right half of box one bit to the right. */ + etsm->selection[box] = (etsm->selection[box] & bitmask1) | ((etsm->selection[box] & bitmask2) >> 1); etsm->row_count ++; } } @@ -71,13 +78,16 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) guint32 bitmask1 = 0xffff; guint32 bitmask2; box = row >> 5; - last = etsm->row_count >> 5 + last = etsm->row_count >> 5; + /* Build bitmasks for the left and right half of the box */ offset = row & 0x1f; bitmask1 = bitmask1 << (32 - offset); bitmask2 = (~bitmask1) >> 1; + /* Shift right half of box one bit to the left. */ etsm->selection[box] = (etsm->selection[box] & bitmask1) | ((etsm->selection[box] & bitmask2) << 1); + /* Shift all words to the right of our box left one bit. */ if (box < last) { etsm->selection[box] &= etsm->selection[box + 1] >> 31; @@ -87,6 +97,7 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) etsm->selection[i] = etsm->selection[i] << 1; } etsm->row_count --; + /* Remove the last word if not needed. */ if ((etsm->row_count & 0x1f) == 0) { etsm->selection = e_realloc(etsm->selection, etsm->row_count >> 5); } diff --git a/widgets/e-table/e-table-selection-model.h b/widgets/e-table/e-table-selection-model.h index 8b7d0a0507..7fb6158ad2 100644 --- a/widgets/e-table/e-table-selection-model.h +++ b/widgets/e-table/e-table-selection-model.h @@ -23,7 +23,7 @@ typedef struct { ETableModel *model; gint row_count; - guint *selection; + guint32 *selection; gint cursor_row; gint cursor_col; -- cgit v1.2.3