From cbaec9459607a60bf56a727f74ffd45de0543207 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Tue, 25 Jul 2000 20:46:49 +0000 Subject: More fixes. 2000-07-25 Christopher James Lahey * e-table-selection-model.c: More fixes. svn path=/trunk/; revision=4328 --- widgets/e-table/e-table-selection-model.c | 30 ++++++++++++++++++++++-------- widgets/table/e-table-selection-model.c | 30 ++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 16 deletions(-) (limited to 'widgets') diff --git a/widgets/e-table/e-table-selection-model.c b/widgets/e-table/e-table-selection-model.c index 44ecc07979..b8c4d65d2e 100644 --- a/widgets/e-table/e-table-selection-model.c +++ b/widgets/e-table/e-table-selection-model.c @@ -42,16 +42,21 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) int i; int offset; if(etsm->row_count >= 0) { + guint32 bitmask1 = 0xffff; + guint32 bitmask2; 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; for (i = etsm->row_count >> 5; i > box; i--) { - etsm->selection[i] = (etsm->selection[i] >> 1) & (etsm->selection[i - 1] << 31) + etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31) } + offset = row & 0x1f; - etsm->selection[i] = ((etsm->selection[i] >> (32 - offset)) << (32 - offset)) & ((etsm->selection[i] << offset) >> (offset + 1)); + bitmask1 = bitmask1 << (32 - offset); + bitmask2 = ~bitmask1; + etsm->selection[i] = (etsm->selection[i] & bitmask1) | ((etsm->selection[i] & bitmask2) >> 1); etsm->row_count ++; } } @@ -63,19 +68,21 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) int i; int offset; if(etsm->row_count >= 0) { + guint32 bitmask1 = 0xffff; + guint32 bitmask2; 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; + bitmask1 = bitmask1 << (32 - offset); + bitmask2 = (~bitmask1) >> 1; + etsm->selection[box] = (etsm->selection[box] & bitmask1) | ((etsm->selection[box] & bitmask2) << 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->selection[i + 1] >> 31); } etsm->selection[i] = etsm->selection[i] << 1; } @@ -90,8 +97,15 @@ inline static void add_model(ETableSelectionModel *etsm, ETableModel *model) { etsm->model = model; - if (model) + if (model) { gtk_object_ref(GTK_OBJECT(model)); + etsm->model_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_changed", + GTK_SIGNAL_FUNC(model_changed), etsm); + etsm->model_row_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_inserted", + GTK_SIGNAL_FUNC(model_row_inserted), etsm); + etsm->model_row_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_deleted", + GTK_SIGNAL_FUNC(model_row_deleted), etsm); + } } inline static void diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c index 44ecc07979..b8c4d65d2e 100644 --- a/widgets/table/e-table-selection-model.c +++ b/widgets/table/e-table-selection-model.c @@ -42,16 +42,21 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) int i; int offset; if(etsm->row_count >= 0) { + guint32 bitmask1 = 0xffff; + guint32 bitmask2; 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; for (i = etsm->row_count >> 5; i > box; i--) { - etsm->selection[i] = (etsm->selection[i] >> 1) & (etsm->selection[i - 1] << 31) + etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31) } + offset = row & 0x1f; - etsm->selection[i] = ((etsm->selection[i] >> (32 - offset)) << (32 - offset)) & ((etsm->selection[i] << offset) >> (offset + 1)); + bitmask1 = bitmask1 << (32 - offset); + bitmask2 = ~bitmask1; + etsm->selection[i] = (etsm->selection[i] & bitmask1) | ((etsm->selection[i] & bitmask2) >> 1); etsm->row_count ++; } } @@ -63,19 +68,21 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) int i; int offset; if(etsm->row_count >= 0) { + guint32 bitmask1 = 0xffff; + guint32 bitmask2; 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; + bitmask1 = bitmask1 << (32 - offset); + bitmask2 = (~bitmask1) >> 1; + etsm->selection[box] = (etsm->selection[box] & bitmask1) | ((etsm->selection[box] & bitmask2) << 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->selection[i + 1] >> 31); } etsm->selection[i] = etsm->selection[i] << 1; } @@ -90,8 +97,15 @@ inline static void add_model(ETableSelectionModel *etsm, ETableModel *model) { etsm->model = model; - if (model) + if (model) { gtk_object_ref(GTK_OBJECT(model)); + etsm->model_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_changed", + GTK_SIGNAL_FUNC(model_changed), etsm); + etsm->model_row_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_inserted", + GTK_SIGNAL_FUNC(model_row_inserted), etsm); + etsm->model_row_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_deleted", + GTK_SIGNAL_FUNC(model_row_deleted), etsm); + } } inline static void -- cgit