aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--widgets/e-table/ChangeLog12
-rw-r--r--widgets/e-table/Makefile.am2
-rw-r--r--widgets/e-table/e-table-selection-model.c188
-rw-r--r--widgets/e-table/e-table-selection-model.h10
-rw-r--r--widgets/table/e-table-selection-model.c188
-rw-r--r--widgets/table/e-table-selection-model.h10
6 files changed, 105 insertions, 305 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog
index 6b8b1f6918..f1c22f3167 100644
--- a/widgets/e-table/ChangeLog
+++ b/widgets/e-table/ChangeLog
@@ -1,6 +1,16 @@
2000-07-25 Christopher James Lahey <clahey@helixcode.com>
- * e-table-selection-model.c: Added comments to the bit data.
+ * Makefile.am: Added e-table-selection-model.c and
+ e-table-selection-model.h.
+
+ * e-table-selection-model.c: Added the get_selection_list and
+ is_row_selected functions. Removed some unused code.
+
+ * e-table-selection-model.h: Removed some unused code.
+
+2000-07-25 Christopher James Lahey <clahey@helixcode.com>
+
+ * e-table-selection-model.c: Added comments to the bit field code.
* e-table-selection-model.h: Made the selection data guint32s.
diff --git a/widgets/e-table/Makefile.am b/widgets/e-table/Makefile.am
index 7894bc1dec..cd60b5e7a2 100644
--- a/widgets/e-table/Makefile.am
+++ b/widgets/e-table/Makefile.am
@@ -68,6 +68,8 @@ libetable_a_SOURCES = \
e-table-one.h \
e-table-scrolled.c \
e-table-scrolled.h \
+ e-table-selection-model.c \
+ e-table-selection-model.h \
e-table-simple.c \
e-table-simple.h \
e-table-sort-info.c \
diff --git a/widgets/e-table/e-table-selection-model.c b/widgets/e-table/e-table-selection-model.c
index 6bdfa90990..77be6eb2fa 100644
--- a/widgets/e-table/e-table-selection-model.c
+++ b/widgets/e-table/e-table-selection-model.c
@@ -47,7 +47,7 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm)
/* Add another word if needed. */
if ((etsm->row_count & 0x1f) == 0) {
- etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5) + 1);
+ etsm->selection = g_realloc(etsm->selection, (etsm->row_count >> 5) + 1);
etsm->selection[etsm->row_count >> 5] = 0;
}
@@ -55,7 +55,7 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm)
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)
+ etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31);
}
/* Build bitmasks for the left and right half of the box */
@@ -73,6 +73,7 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm)
{
int box;
int i;
+ int last;
int offset;
if(etsm->row_count >= 0) {
guint32 bitmask1 = 0xffff;
@@ -99,7 +100,7 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm)
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);
+ etsm->selection = g_realloc(etsm->selection, etsm->row_count >> 5);
}
}
}
@@ -122,8 +123,15 @@ add_model(ETableSelectionModel *etsm, ETableModel *model)
inline static void
drop_model(ETableSelectionModel *etsm)
{
- if (etsm->model)
+ if (etsm->model) {
+ gtk_signal_disconnect(GTK_OBJECT(etsm->model),
+ etsm->model_changed_id);
+ gtk_signal_disconnect(GTK_OBJECT(etsm->model),
+ etsm->model_row_inserted_id);
+ gtk_signal_disconnect(GTK_OBJECT(etsm->model),
+ etsm->model_row_deleted_id);
gtk_object_unref(GTK_OBJECT(etsm->model));
+ }
etsm->model = NULL;
}
@@ -134,7 +142,7 @@ etsm_destroy (GtkObject *object)
etsm = E_TABLE_SELECTION_MODEL (object);
- g_free(etsm->selction);
+ g_free(etsm->selection);
}
static void
@@ -154,7 +162,7 @@ e_table_selection_model_class_init (ETableSelectionModelClass *klass)
object_class = GTK_OBJECT_CLASS(klass);
object_class->destroy = etsm_destroy;
-
+#if 0
e_table_selection_model_signals [SELECTION_MODEL_CHANGED] =
gtk_signal_new ("selection_model_changed",
GTK_RUN_LAST,
@@ -173,158 +181,48 @@ e_table_selection_model_class_init (ETableSelectionModelClass *klass)
klass->selection_model_changed = NULL;
klass->group_selection_changed = NULL;
-
+#endif
gtk_object_class_add_signals (object_class, e_table_selection_model_signals, LAST_SIGNAL);
}
E_MAKE_TYPE(e_table_selection_model, "ETableSelectionModel", ETableSelectionModel,
e_table_selection_model_class_init, e_table_selection_model_init, PARENT_TYPE);
-static void
-e_table_selection_model_selection_model_changed (ETableSelectionModel *selection)
-{
- g_return_if_fail (selection != NULL);
- g_return_if_fail (E_IS_TABLE_SELECTION_MODEL (selection));
-
- if (selection->frozen) {
- selection->selection_model_changed = 1;
- } else {
- gtk_signal_emit (GTK_OBJECT (selection),
- e_table_selection_model_signals [SELECTION_MODEL_CHANGED]);
- }
-}
-
-static void
-e_table_selection_model_group_selection_changed (ETableSelectionModel *selection)
-{
- g_return_if_fail (selection != NULL);
- g_return_if_fail (E_IS_TABLE_SELECTION_MODEL (selection));
-
- if (selection->frozen) {
- selection->group_selection_changed = 1;
- } else {
- gtk_signal_emit (GTK_OBJECT (selection),
- e_table_selection_model_signals [GROUP_SELECTION_CHANGED]);
- }
-}
-
-void
-e_table_selection_model_freeze (ETableSelectionModel *selection)
-{
- selection->frozen = 1;
-}
-
-void
-e_table_selection_model_thaw (ETableSelectionModel *selection)
-{
- selection->frozen = 0;
- if (selection->selection_model_changed) {
- selection->selection_model_changed = 0;
- e_table_selection_model_selection_model_changed(selection);
- }
- if (selection->group_selection_changed) {
- selection->group_selection_changed = 0;
- e_table_selection_model_group_selection_changed(selection);
- }
-}
-
-
-guint
-e_table_selection_model_grouping_get_count (ETableSelectionModel *selection)
-{
- return selection->group_count;
-}
-
-static void
-e_table_selection_model_grouping_real_truncate (ETableSelectionModel *selection, int length)
-{
- if (length < selection->group_count) {
- selection->group_count = length;
- }
- if (length > selection->group_count) {
- selection->groupings = g_realloc(selection->groupings, length * sizeof(ETableSortColumn));
- selection->group_count = length;
- }
-}
-
-void
-e_table_selection_model_grouping_truncate (ETableSelectionModel *selection, int length)
-{
- e_table_selection_model_grouping_real_truncate(selection, length);
- e_table_selection_model_group_selection_changed(selection);
-}
-
-ETableSortColumn
-e_table_selection_model_grouping_get_nth (ETableSelectionModel *selection, int n)
-{
- if (n < selection->group_count) {
- return selection->groupings[n];
- } else {
- ETableSortColumn fake = {0, 0};
- return fake;
- }
-}
-
-void
-e_table_selection_model_grouping_set_nth (ETableSelectionModel *selection, int n, ETableSortColumn column)
-{
- if (n >= selection->group_count) {
- e_table_selection_model_grouping_real_truncate(selection, n + 1);
- }
- selection->groupings[n] = column;
- e_table_selection_model_group_selection_changed(selection);
-}
-
-
-guint
-e_table_selection_model_sorting_get_count (ETableSelectionModel *selection)
-{
- return selection->sort_count;
-}
-
-static void
-e_table_selection_model_sorting_real_truncate (ETableSelectionModel *selection, int length)
-{
- if (length < selection->sort_count) {
- selection->sort_count = length;
- }
- if (length > selection->sort_count) {
- selection->sortings = g_realloc(selection->sortings, length * sizeof(ETableSortColumn));
- selection->sort_count = length;
- }
-}
-
-void
-e_table_selection_model_sorting_truncate (ETableSelectionModel *selection, int length)
+ETableSelectionModel *
+e_table_selection_model_new (void)
{
- e_table_selection_model_sorting_real_truncate (selection, length);
- e_table_selection_model_selection_model_changed(selection);
+ return gtk_type_new (e_table_selection_model_get_type ());
}
-ETableSortColumn
-e_table_selection_model_sorting_get_nth (ETableSelectionModel *selection, int n)
+gboolean
+e_table_selection_model_is_row_selected (ETableSelectionModel *selection,
+ int n)
{
- if (n < selection->sort_count) {
- return selection->sortings[n];
- } else {
- ETableSortColumn fake = {0, 0};
- return fake;
- }
+ if (selection->row_count < n)
+ return 0;
+ else
+ return ((selection->selection[n / 32]) >> (31 - (n % 32))) & 0x1;
}
-void
-e_table_selection_model_sorting_set_nth (ETableSelectionModel *selection, int n, ETableSortColumn column)
+GList *
+e_table_selection_model_get_selection_list (ETableSelectionModel *selection)
{
- if (n >= selection->sort_count) {
- e_table_selection_model_sorting_real_truncate(selection, n + 1);
+ int i;
+ GList *list = NULL;
+ if (selection->row_count < 0)
+ return NULL;
+ for (i = selection->row_count / 32; i >= 0; i--) {
+ if (selection->selection[i]) {
+ int j;
+ guint32 value = selection->selection[i];
+ for (j = 31; j >= 0; j--) {
+ if (value & 0x1) {
+ list = g_list_prepend(list, (void *) (i * 32 + j));
+ }
+ value >>= 1;
+ }
+ }
}
- selection->sortings[n] = column;
- e_table_selection_model_selection_model_changed(selection);
-}
-
-ETableSelectionModel *
-e_table_selection_model_new (void)
-{
- return gtk_type_new (e_table_selection_model_get_type ());
+ return NULL;
}
diff --git a/widgets/e-table/e-table-selection-model.h b/widgets/e-table/e-table-selection-model.h
index 7fb6158ad2..a36f4ca03c 100644
--- a/widgets/e-table/e-table-selection-model.h
+++ b/widgets/e-table/e-table-selection-model.h
@@ -3,6 +3,7 @@
#define _E_TABLE_SELECTION_MODEL_H_
#include <gtk/gtkobject.h>
+#include "widgets/e-table/e-table-model.h"
#define E_TABLE_SELECTION_MODEL_TYPE (e_table_selection_model_get_type ())
#define E_TABLE_SELECTION_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModel))
@@ -10,13 +11,6 @@
#define E_IS_TABLE_SELECTION_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_SELECTION_MODEL_TYPE))
#define E_IS_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SELECTION_MODEL_TYPE))
-typedef struct _ETableSortColumn ETableSortColumn;
-
-struct _ETableSortColumn {
- guint column : 31;
- guint ascending : 1;
-};
-
typedef struct {
GtkObject base;
@@ -42,8 +36,10 @@ typedef struct {
/*
* Signals
*/
+#if 0
void (*selection_model_changed) (ETableSelectionModel *selection);
void (*group_model_changed) (ETableSelectionModel *selection);
+#endif
} ETableSelectionModelClass;
GtkType e_table_selection_model_get_type (void);
diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c
index 6bdfa90990..77be6eb2fa 100644
--- a/widgets/table/e-table-selection-model.c
+++ b/widgets/table/e-table-selection-model.c
@@ -47,7 +47,7 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm)
/* Add another word if needed. */
if ((etsm->row_count & 0x1f) == 0) {
- etsm->selection = e_realloc(etsm->selection, (etsm->row_count >> 5) + 1);
+ etsm->selection = g_realloc(etsm->selection, (etsm->row_count >> 5) + 1);
etsm->selection[etsm->row_count >> 5] = 0;
}
@@ -55,7 +55,7 @@ model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm)
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)
+ etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31);
}
/* Build bitmasks for the left and right half of the box */
@@ -73,6 +73,7 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm)
{
int box;
int i;
+ int last;
int offset;
if(etsm->row_count >= 0) {
guint32 bitmask1 = 0xffff;
@@ -99,7 +100,7 @@ model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm)
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);
+ etsm->selection = g_realloc(etsm->selection, etsm->row_count >> 5);
}
}
}
@@ -122,8 +123,15 @@ add_model(ETableSelectionModel *etsm, ETableModel *model)
inline static void
drop_model(ETableSelectionModel *etsm)
{
- if (etsm->model)
+ if (etsm->model) {
+ gtk_signal_disconnect(GTK_OBJECT(etsm->model),
+ etsm->model_changed_id);
+ gtk_signal_disconnect(GTK_OBJECT(etsm->model),
+ etsm->model_row_inserted_id);
+ gtk_signal_disconnect(GTK_OBJECT(etsm->model),
+ etsm->model_row_deleted_id);
gtk_object_unref(GTK_OBJECT(etsm->model));
+ }
etsm->model = NULL;
}
@@ -134,7 +142,7 @@ etsm_destroy (GtkObject *object)
etsm = E_TABLE_SELECTION_MODEL (object);
- g_free(etsm->selction);
+ g_free(etsm->selection);
}
static void
@@ -154,7 +162,7 @@ e_table_selection_model_class_init (ETableSelectionModelClass *klass)
object_class = GTK_OBJECT_CLASS(klass);
object_class->destroy = etsm_destroy;
-
+#if 0
e_table_selection_model_signals [SELECTION_MODEL_CHANGED] =
gtk_signal_new ("selection_model_changed",
GTK_RUN_LAST,
@@ -173,158 +181,48 @@ e_table_selection_model_class_init (ETableSelectionModelClass *klass)
klass->selection_model_changed = NULL;
klass->group_selection_changed = NULL;
-
+#endif
gtk_object_class_add_signals (object_class, e_table_selection_model_signals, LAST_SIGNAL);
}
E_MAKE_TYPE(e_table_selection_model, "ETableSelectionModel", ETableSelectionModel,
e_table_selection_model_class_init, e_table_selection_model_init, PARENT_TYPE);
-static void
-e_table_selection_model_selection_model_changed (ETableSelectionModel *selection)
-{
- g_return_if_fail (selection != NULL);
- g_return_if_fail (E_IS_TABLE_SELECTION_MODEL (selection));
-
- if (selection->frozen) {
- selection->selection_model_changed = 1;
- } else {
- gtk_signal_emit (GTK_OBJECT (selection),
- e_table_selection_model_signals [SELECTION_MODEL_CHANGED]);
- }
-}
-
-static void
-e_table_selection_model_group_selection_changed (ETableSelectionModel *selection)
-{
- g_return_if_fail (selection != NULL);
- g_return_if_fail (E_IS_TABLE_SELECTION_MODEL (selection));
-
- if (selection->frozen) {
- selection->group_selection_changed = 1;
- } else {
- gtk_signal_emit (GTK_OBJECT (selection),
- e_table_selection_model_signals [GROUP_SELECTION_CHANGED]);
- }
-}
-
-void
-e_table_selection_model_freeze (ETableSelectionModel *selection)
-{
- selection->frozen = 1;
-}
-
-void
-e_table_selection_model_thaw (ETableSelectionModel *selection)
-{
- selection->frozen = 0;
- if (selection->selection_model_changed) {
- selection->selection_model_changed = 0;
- e_table_selection_model_selection_model_changed(selection);
- }
- if (selection->group_selection_changed) {
- selection->group_selection_changed = 0;
- e_table_selection_model_group_selection_changed(selection);
- }
-}
-
-
-guint
-e_table_selection_model_grouping_get_count (ETableSelectionModel *selection)
-{
- return selection->group_count;
-}
-
-static void
-e_table_selection_model_grouping_real_truncate (ETableSelectionModel *selection, int length)
-{
- if (length < selection->group_count) {
- selection->group_count = length;
- }
- if (length > selection->group_count) {
- selection->groupings = g_realloc(selection->groupings, length * sizeof(ETableSortColumn));
- selection->group_count = length;
- }
-}
-
-void
-e_table_selection_model_grouping_truncate (ETableSelectionModel *selection, int length)
-{
- e_table_selection_model_grouping_real_truncate(selection, length);
- e_table_selection_model_group_selection_changed(selection);
-}
-
-ETableSortColumn
-e_table_selection_model_grouping_get_nth (ETableSelectionModel *selection, int n)
-{
- if (n < selection->group_count) {
- return selection->groupings[n];
- } else {
- ETableSortColumn fake = {0, 0};
- return fake;
- }
-}
-
-void
-e_table_selection_model_grouping_set_nth (ETableSelectionModel *selection, int n, ETableSortColumn column)
-{
- if (n >= selection->group_count) {
- e_table_selection_model_grouping_real_truncate(selection, n + 1);
- }
- selection->groupings[n] = column;
- e_table_selection_model_group_selection_changed(selection);
-}
-
-
-guint
-e_table_selection_model_sorting_get_count (ETableSelectionModel *selection)
-{
- return selection->sort_count;
-}
-
-static void
-e_table_selection_model_sorting_real_truncate (ETableSelectionModel *selection, int length)
-{
- if (length < selection->sort_count) {
- selection->sort_count = length;
- }
- if (length > selection->sort_count) {
- selection->sortings = g_realloc(selection->sortings, length * sizeof(ETableSortColumn));
- selection->sort_count = length;
- }
-}
-
-void
-e_table_selection_model_sorting_truncate (ETableSelectionModel *selection, int length)
+ETableSelectionModel *
+e_table_selection_model_new (void)
{
- e_table_selection_model_sorting_real_truncate (selection, length);
- e_table_selection_model_selection_model_changed(selection);
+ return gtk_type_new (e_table_selection_model_get_type ());
}
-ETableSortColumn
-e_table_selection_model_sorting_get_nth (ETableSelectionModel *selection, int n)
+gboolean
+e_table_selection_model_is_row_selected (ETableSelectionModel *selection,
+ int n)
{
- if (n < selection->sort_count) {
- return selection->sortings[n];
- } else {
- ETableSortColumn fake = {0, 0};
- return fake;
- }
+ if (selection->row_count < n)
+ return 0;
+ else
+ return ((selection->selection[n / 32]) >> (31 - (n % 32))) & 0x1;
}
-void
-e_table_selection_model_sorting_set_nth (ETableSelectionModel *selection, int n, ETableSortColumn column)
+GList *
+e_table_selection_model_get_selection_list (ETableSelectionModel *selection)
{
- if (n >= selection->sort_count) {
- e_table_selection_model_sorting_real_truncate(selection, n + 1);
+ int i;
+ GList *list = NULL;
+ if (selection->row_count < 0)
+ return NULL;
+ for (i = selection->row_count / 32; i >= 0; i--) {
+ if (selection->selection[i]) {
+ int j;
+ guint32 value = selection->selection[i];
+ for (j = 31; j >= 0; j--) {
+ if (value & 0x1) {
+ list = g_list_prepend(list, (void *) (i * 32 + j));
+ }
+ value >>= 1;
+ }
+ }
}
- selection->sortings[n] = column;
- e_table_selection_model_selection_model_changed(selection);
-}
-
-ETableSelectionModel *
-e_table_selection_model_new (void)
-{
- return gtk_type_new (e_table_selection_model_get_type ());
+ return NULL;
}
diff --git a/widgets/table/e-table-selection-model.h b/widgets/table/e-table-selection-model.h
index 7fb6158ad2..a36f4ca03c 100644
--- a/widgets/table/e-table-selection-model.h
+++ b/widgets/table/e-table-selection-model.h
@@ -3,6 +3,7 @@
#define _E_TABLE_SELECTION_MODEL_H_
#include <gtk/gtkobject.h>
+#include "widgets/e-table/e-table-model.h"
#define E_TABLE_SELECTION_MODEL_TYPE (e_table_selection_model_get_type ())
#define E_TABLE_SELECTION_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModel))
@@ -10,13 +11,6 @@
#define E_IS_TABLE_SELECTION_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_SELECTION_MODEL_TYPE))
#define E_IS_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SELECTION_MODEL_TYPE))
-typedef struct _ETableSortColumn ETableSortColumn;
-
-struct _ETableSortColumn {
- guint column : 31;
- guint ascending : 1;
-};
-
typedef struct {
GtkObject base;
@@ -42,8 +36,10 @@ typedef struct {
/*
* Signals
*/
+#if 0
void (*selection_model_changed) (ETableSelectionModel *selection);
void (*group_model_changed) (ETableSelectionModel *selection);
+#endif
} ETableSelectionModelClass;
GtkType e_table_selection_model_get_type (void);