aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/e-reflow.c40
-rw-r--r--widgets/misc/e-reflow.h1
-rw-r--r--widgets/misc/e-selection-model-array.c71
-rw-r--r--widgets/misc/e-selection-model-array.h9
-rw-r--r--widgets/misc/e-selection-model.c65
-rw-r--r--widgets/misc/e-selection-model.h147
6 files changed, 221 insertions, 112 deletions
diff --git a/widgets/misc/e-reflow.c b/widgets/misc/e-reflow.c
index 6287ce45ad..ed83956232 100644
--- a/widgets/misc/e-reflow.c
+++ b/widgets/misc/e-reflow.c
@@ -117,6 +117,22 @@ e_reflow_resize_children (GnomeCanvasItem *item)
}
}
+static inline void
+e_reflow_update_selection_row (EReflow *reflow, int row)
+{
+ if (reflow->items[row]) {
+ gtk_object_set(GTK_OBJECT(reflow->items[row]),
+ "selected", e_selection_model_is_row_selected(E_SELECTION_MODEL(reflow->selection), row),
+ NULL);
+ } else if (e_selection_model_is_row_selected (E_SELECTION_MODEL (reflow->selection), row)) {
+ reflow->items[row] = e_reflow_model_incarnate (reflow->model, row, GNOME_CANVAS_GROUP (reflow));
+ gtk_object_set (GTK_OBJECT (reflow->items[row]),
+ "selected", e_selection_model_is_row_selected(E_SELECTION_MODEL(reflow->selection), row),
+ "width", (double) reflow->column_width,
+ NULL);
+ }
+}
+
static void
e_reflow_update_selection (EReflow *reflow)
{
@@ -125,17 +141,7 @@ e_reflow_update_selection (EReflow *reflow)
count = reflow->count;
for (i = 0; i < count; i++) {
- if (reflow->items[i]) {
- gtk_object_set(GTK_OBJECT(reflow->items[i]),
- "selected", e_selection_model_is_row_selected(E_SELECTION_MODEL(reflow->selection), i),
- NULL);
- } else if (e_selection_model_is_row_selected (E_SELECTION_MODEL (reflow->selection), i)) {
- reflow->items[i] = e_reflow_model_incarnate (reflow->model, i, GNOME_CANVAS_GROUP (reflow));
- gtk_object_set (GTK_OBJECT (reflow->items[i]),
- "selected", e_selection_model_is_row_selected(E_SELECTION_MODEL(reflow->selection), i),
- "width", (double) reflow->column_width,
- NULL);
- }
+ e_reflow_update_selection_row (reflow, i);
}
}
@@ -146,6 +152,12 @@ selection_changed (ESelectionModel *selection, EReflow *reflow)
}
static void
+selection_row_changed (ESelectionModel *selection, int row, EReflow *reflow)
+{
+ e_reflow_update_selection_row (reflow, row);
+}
+
+static void
cursor_changed (ESelectionModel *selection, int row, int col, EReflow *reflow)
{
int count = reflow->count;
@@ -453,10 +465,13 @@ disconnect_selection (EReflow *reflow)
gtk_signal_disconnect (GTK_OBJECT (reflow->selection),
reflow->selection_changed_id);
gtk_signal_disconnect (GTK_OBJECT (reflow->selection),
+ reflow->selection_row_changed_id);
+ gtk_signal_disconnect (GTK_OBJECT (reflow->selection),
reflow->cursor_changed_id);
gtk_object_unref (GTK_OBJECT (reflow->selection));
reflow->selection_changed_id = 0;
+ reflow->selection_row_changed_id = 0;
reflow->cursor_changed_id = 0;
reflow->selection = NULL;
}
@@ -1308,6 +1323,9 @@ e_reflow_init (EReflow *reflow)
reflow->selection_changed_id =
gtk_signal_connect(GTK_OBJECT(reflow->selection), "selection_changed",
GTK_SIGNAL_FUNC(selection_changed), reflow);
+ reflow->selection_row_changed_id =
+ gtk_signal_connect(GTK_OBJECT(reflow->selection), "selection_row_changed",
+ GTK_SIGNAL_FUNC(selection_row_changed), reflow);
reflow->cursor_changed_id =
gtk_signal_connect(GTK_OBJECT(reflow->selection), "cursor_changed",
GTK_SIGNAL_FUNC(cursor_changed), reflow);
diff --git a/widgets/misc/e-reflow.h b/widgets/misc/e-reflow.h
index 0e0a7b273d..5b699431cc 100644
--- a/widgets/misc/e-reflow.h
+++ b/widgets/misc/e-reflow.h
@@ -69,6 +69,7 @@ struct _EReflow
ESelectionModel *selection;
guint selection_changed_id;
+ guint selection_row_changed_id;
guint cursor_changed_id;
ESorterArray *sorter;
diff --git a/widgets/misc/e-selection-model-array.c b/widgets/misc/e-selection-model-array.c
index 13c964bfba..dd81fb2554 100644
--- a/widgets/misc/e-selection-model-array.c
+++ b/widgets/misc/e-selection-model-array.c
@@ -70,6 +70,8 @@ e_selection_model_array_delete_rows(ESelectionModelArray *esma, int row, int cou
if (esma->cursor_row >= 0)
e_bit_array_change_one_row(esma->eba, esma->cursor_row, TRUE);
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
e_selection_model_cursor_changed(E_SELECTION_MODEL(esma), esma->cursor_row, esma->cursor_col);
}
@@ -84,6 +86,8 @@ e_selection_model_array_insert_rows(ESelectionModelArray *esma, int row, int cou
if (esma->cursor_row >= row)
esma->cursor_row += count;
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
e_selection_model_cursor_changed(E_SELECTION_MODEL(esma), esma->cursor_row, esma->cursor_col);
}
@@ -114,6 +118,8 @@ e_selection_model_array_move_row(ESelectionModelArray *esma, int old_row, int ne
if (cursor) {
esma->cursor_row = new_row;
}
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
e_selection_model_selection_changed(esm);
e_selection_model_cursor_changed(esm, esma->cursor_row, esma->cursor_col);
}
@@ -223,6 +229,8 @@ esma_clear(ESelectionModel *selection)
}
esma->cursor_row = -1;
esma->cursor_col = -1;
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
e_selection_model_cursor_changed(E_SELECTION_MODEL(esma), -1, -1);
}
@@ -267,6 +275,8 @@ esma_select_all (ESelectionModel *selection)
esma->cursor_col = 0;
esma->cursor_row = 0;
esma->selection_start_row = 0;
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
e_selection_model_cursor_changed(E_SELECTION_MODEL(esma), 0, 0);
}
@@ -290,6 +300,8 @@ esma_invert_selection (ESelectionModel *selection)
esma->cursor_col = -1;
esma->cursor_row = -1;
esma->selection_start_row = 0;
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
e_selection_model_cursor_changed(E_SELECTION_MODEL(esma), -1, -1);
}
@@ -356,15 +368,33 @@ esma_cursor_col (ESelectionModel *selection)
}
static void
-esma_select_single_row (ESelectionModel *selection, int row)
+esma_real_select_single_row (ESelectionModel *selection, int row)
{
ESelectionModelArray *esma = E_SELECTION_MODEL_ARRAY(selection);
e_selection_model_array_confirm_row_count(esma);
+
e_bit_array_select_single_row(esma->eba, row);
- e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
esma->selection_start_row = row;
+ esma->selected_row = row;
+ esma->selected_range_end = row;
+}
+
+static void
+esma_select_single_row (ESelectionModel *selection, int row)
+{
+ int selected_row = E_SELECTION_MODEL_ARRAY(selection)->selected_row;
+ esma_real_select_single_row (selection, row);
+
+ if (selected_row != -1) {
+ if (selected_row != row) {
+ e_selection_model_selection_row_changed(selection, selected_row);
+ e_selection_model_selection_row_changed(selection, row);
+ }
+ } else {
+ e_selection_model_selection_changed(selection);
+ }
}
static void
@@ -376,11 +406,13 @@ esma_toggle_single_row (ESelectionModel *selection, int row)
e_bit_array_toggle_single_row(esma->eba, row);
esma->selection_start_row = row;
- e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
+ e_selection_model_selection_row_changed(E_SELECTION_MODEL(esma), row);
}
static void
-esma_move_selection_end (ESelectionModel *selection, int row)
+esma_real_move_selection_end (ESelectionModel *selection, int row)
{
ESelectionModelArray *esma = E_SELECTION_MODEL_ARRAY(selection);
int old_start;
@@ -411,16 +443,38 @@ esma_move_selection_end (ESelectionModel *selection, int row)
esma_change_range(selection, old_end, new_end, TRUE);
if (new_end < old_end)
esma_change_range(selection, new_end, old_end, FALSE);
- e_selection_model_selection_changed(E_SELECTION_MODEL(esma));
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
+}
+
+static void
+esma_move_selection_end (ESelectionModel *selection, int row)
+{
+ esma_real_move_selection_end (selection, row);
+ e_selection_model_selection_changed(selection);
}
static void
esma_set_selection_end (ESelectionModel *selection, int row)
{
ESelectionModelArray *esma = E_SELECTION_MODEL_ARRAY(selection);
- esma_select_single_row(selection, esma->selection_start_row);
+ int selected_range_end = esma->selected_range_end;
+ int view_row = e_sorter_model_to_sorted(selection->sorter, row);
+
+ esma_real_select_single_row(selection, esma->selection_start_row);
esma->cursor_row = esma->selection_start_row;
- esma_move_selection_end(selection, row);
+ esma_real_move_selection_end(selection, row);
+
+ esma->selected_range_end = view_row;
+ if (selected_range_end != -1 && view_row != -1) {
+ if (selected_range_end == view_row - 1 ||
+ selected_range_end == view_row + 1) {
+ e_selection_model_selection_row_changed(selection, selected_range_end);
+ e_selection_model_selection_row_changed(selection, view_row);
+ return;
+ }
+ }
+ e_selection_model_selection_changed(selection);
}
int
@@ -443,6 +497,9 @@ e_selection_model_array_init (ESelectionModelArray *esma)
esma->selection_start_row = 0;
esma->cursor_row = -1;
esma->cursor_col = -1;
+
+ esma->selected_row = -1;
+ esma->selected_range_end = -1;
}
static void
diff --git a/widgets/misc/e-selection-model-array.h b/widgets/misc/e-selection-model-array.h
index cf336eebb7..805f331e88 100644
--- a/widgets/misc/e-selection-model-array.h
+++ b/widgets/misc/e-selection-model-array.h
@@ -50,6 +50,15 @@ typedef struct {
guint model_changed_id;
guint model_row_inserted_id, model_row_deleted_id;
+ /* Anything other than -1 means that the selection is a single
+ * row. This being -1 does not impart any information. */
+ gint selected_row;
+ /* Anything other than -1 means that the selection is a all
+ * rows between selection_start_path and cursor_path where
+ * selected_range_end is the rwo number of cursor_path. This
+ * being -1 does not impart any information. */
+ gint selected_range_end;
+
guint frozen : 1;
guint selection_model_changed : 1;
guint group_info_changed : 1;
diff --git a/widgets/misc/e-selection-model.c b/widgets/misc/e-selection-model.c
index 3aa78af31d..b7472e99f5 100644
--- a/widgets/misc/e-selection-model.c
+++ b/widgets/misc/e-selection-model.c
@@ -37,6 +37,7 @@ enum {
CURSOR_CHANGED,
CURSOR_ACTIVATED,
SELECTION_CHANGED,
+ SELECTION_ROW_CHANGED,
LAST_SIGNAL
};
@@ -171,27 +172,36 @@ e_selection_model_class_init (ESelectionModelClass *klass)
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
- klass->cursor_changed = NULL;
- klass->cursor_activated = NULL;
- klass->selection_changed = NULL;
-
- klass->is_row_selected = NULL;
- klass->foreach = NULL;
- klass->clear = NULL;
- klass->selected_count = NULL;
- klass->select_all = NULL;
- klass->invert_selection = NULL;
- klass->row_count = NULL;
-
- klass->change_one_row = NULL;
- klass->change_cursor = NULL;
- klass->cursor_row = NULL;
- klass->cursor_col = NULL;
-
- klass->select_single_row = NULL;
- klass->toggle_single_row = NULL;
- klass->move_selection_end = NULL;
- klass->set_selection_end = NULL;
+ e_selection_model_signals [SELECTION_ROW_CHANGED] =
+ gtk_signal_new ("selection_row_changed",
+ GTK_RUN_LAST,
+ E_OBJECT_CLASS_TYPE (object_class),
+ GTK_SIGNAL_OFFSET (ESelectionModelClass, selection_row_changed),
+ gtk_marshal_NONE__INT,
+ GTK_TYPE_NONE, 1, GTK_TYPE_INT);
+
+ klass->cursor_changed = NULL;
+ klass->cursor_activated = NULL;
+ klass->selection_changed = NULL;
+ klass->selection_row_changed = NULL;
+
+ klass->is_row_selected = NULL;
+ klass->foreach = NULL;
+ klass->clear = NULL;
+ klass->selected_count = NULL;
+ klass->select_all = NULL;
+ klass->invert_selection = NULL;
+ klass->row_count = NULL;
+
+ klass->change_one_row = NULL;
+ klass->change_cursor = NULL;
+ klass->cursor_row = NULL;
+ klass->cursor_col = NULL;
+
+ klass->select_single_row = NULL;
+ klass->toggle_single_row = NULL;
+ klass->move_selection_end = NULL;
+ klass->set_selection_end = NULL;
E_OBJECT_CLASS_ADD_SIGNALS (object_class, e_selection_model_signals, LAST_SIGNAL);
@@ -495,6 +505,8 @@ e_selection_model_select_as_key_press (ESelectionModel *selection,
switch (selection->mode) {
case GTK_SELECTION_BROWSE:
+ case GTK_SELECTION_MULTIPLE:
+ case GTK_SELECTION_EXTENDED:
if (shift_p) {
e_selection_model_set_selection_end (selection, row);
} else if (!ctrl_p) {
@@ -503,8 +515,6 @@ e_selection_model_select_as_key_press (ESelectionModel *selection,
cursor_activated = FALSE;
break;
case GTK_SELECTION_SINGLE:
- case GTK_SELECTION_MULTIPLE:
- case GTK_SELECTION_EXTENDED:
e_selection_model_select_single_row (selection, row);
break;
}
@@ -640,3 +650,12 @@ e_selection_model_selection_changed (ESelectionModel *selection)
gtk_signal_emit(GTK_OBJECT(selection),
e_selection_model_signals[SELECTION_CHANGED]);
}
+
+void
+e_selection_model_selection_row_changed (ESelectionModel *selection,
+ int row)
+{
+ gtk_signal_emit(GTK_OBJECT(selection),
+ e_selection_model_signals[SELECTION_ROW_CHANGED],
+ row);
+}
diff --git a/widgets/misc/e-selection-model.h b/widgets/misc/e-selection-model.h
index 611add91c9..fde97a0035 100644
--- a/widgets/misc/e-selection-model.h
+++ b/widgets/misc/e-selection-model.h
@@ -66,94 +66,99 @@ typedef struct {
GtkObjectClass parent_class;
/* Virtual methods */
- gboolean (*is_row_selected) (ESelectionModel *esm, int row);
- void (*foreach) (ESelectionModel *esm, EForeachFunc callback, gpointer closure);
- void (*clear) (ESelectionModel *esm);
- gint (*selected_count) (ESelectionModel *esm);
- void (*select_all) (ESelectionModel *esm);
- void (*invert_selection) (ESelectionModel *esm);
- int (*row_count) (ESelectionModel *esm);
+ gboolean (*is_row_selected) (ESelectionModel *esm, int row);
+ void (*foreach) (ESelectionModel *esm, EForeachFunc callback, gpointer closure);
+ void (*clear) (ESelectionModel *esm);
+ gint (*selected_count) (ESelectionModel *esm);
+ void (*select_all) (ESelectionModel *esm);
+ void (*invert_selection) (ESelectionModel *esm);
+ int (*row_count) (ESelectionModel *esm);
/* Protected virtual methods. */
- void (*change_one_row) (ESelectionModel *esm, int row, gboolean on);
- void (*change_cursor) (ESelectionModel *esm, int row, int col);
- int (*cursor_row) (ESelectionModel *esm);
- int (*cursor_col) (ESelectionModel *esm);
+ void (*change_one_row) (ESelectionModel *esm, int row, gboolean on);
+ void (*change_cursor) (ESelectionModel *esm, int row, int col);
+ int (*cursor_row) (ESelectionModel *esm);
+ int (*cursor_col) (ESelectionModel *esm);
- void (*select_single_row) (ESelectionModel *selection, int row);
- void (*toggle_single_row) (ESelectionModel *selection, int row);
- void (*move_selection_end) (ESelectionModel *selection, int row);
- void (*set_selection_end) (ESelectionModel *selection, int row);
+ void (*select_single_row) (ESelectionModel *selection, int row);
+ void (*toggle_single_row) (ESelectionModel *selection, int row);
+ void (*move_selection_end) (ESelectionModel *selection, int row);
+ void (*set_selection_end) (ESelectionModel *selection, int row);
/*
* Signals
*/
- void (*cursor_changed) (ESelectionModel *esm, int row, int col);
- void (*cursor_activated) (ESelectionModel *esm, int row, int col);
- void (*selection_changed) (ESelectionModel *esm);
+ void (*cursor_changed) (ESelectionModel *esm, int row, int col);
+ void (*cursor_activated) (ESelectionModel *esm, int row, int col);
+ void (*selection_row_changed) (ESelectionModel *esm, int row);
+ void (*selection_changed) (ESelectionModel *esm);
} ESelectionModelClass;
-GtkType e_selection_model_get_type (void);
-void e_selection_model_do_something (ESelectionModel *esm,
- guint row,
- guint col,
- GdkModifierType state);
-gboolean e_selection_model_maybe_do_something (ESelectionModel *esm,
- guint row,
- guint col,
- GdkModifierType state);
-void e_selection_model_right_click_down (ESelectionModel *selection,
- guint row,
- guint col,
- GdkModifierType state);
-void e_selection_model_right_click_up (ESelectionModel *selection);
-gint e_selection_model_key_press (ESelectionModel *esm,
- GdkEventKey *key);
-void e_selection_model_select_as_key_press (ESelectionModel *esm,
- guint row,
- guint col,
- GdkModifierType state);
+
+
+GtkType e_selection_model_get_type (void);
+void e_selection_model_do_something (ESelectionModel *esm,
+ guint row,
+ guint col,
+ GdkModifierType state);
+gboolean e_selection_model_maybe_do_something (ESelectionModel *esm,
+ guint row,
+ guint col,
+ GdkModifierType state);
+void e_selection_model_right_click_down (ESelectionModel *selection,
+ guint row,
+ guint col,
+ GdkModifierType state);
+void e_selection_model_right_click_up (ESelectionModel *selection);
+gint e_selection_model_key_press (ESelectionModel *esm,
+ GdkEventKey *key);
+void e_selection_model_select_as_key_press (ESelectionModel *esm,
+ guint row,
+ guint col,
+ GdkModifierType state);
/* Virtual functions */
-gboolean e_selection_model_is_row_selected (ESelectionModel *esm,
- gint n);
-void e_selection_model_foreach (ESelectionModel *esm,
- EForeachFunc callback,
- gpointer closure);
-void e_selection_model_clear (ESelectionModel *esm);
-gint e_selection_model_selected_count (ESelectionModel *esm);
-void e_selection_model_select_all (ESelectionModel *esm);
-void e_selection_model_invert_selection (ESelectionModel *esm);
-int e_selection_model_row_count (ESelectionModel *esm);
+gboolean e_selection_model_is_row_selected (ESelectionModel *esm,
+ gint n);
+void e_selection_model_foreach (ESelectionModel *esm,
+ EForeachFunc callback,
+ gpointer closure);
+void e_selection_model_clear (ESelectionModel *esm);
+gint e_selection_model_selected_count (ESelectionModel *esm);
+void e_selection_model_select_all (ESelectionModel *esm);
+void e_selection_model_invert_selection (ESelectionModel *esm);
+int e_selection_model_row_count (ESelectionModel *esm);
/* Private virtual Functions */
-void e_selection_model_change_one_row (ESelectionModel *esm,
- int row,
- gboolean on);
-void e_selection_model_change_cursor (ESelectionModel *esm,
- int row,
- int col);
-int e_selection_model_cursor_row (ESelectionModel *esm);
-int e_selection_model_cursor_col (ESelectionModel *esm);
-void e_selection_model_select_single_row (ESelectionModel *selection,
- int row);
-void e_selection_model_toggle_single_row (ESelectionModel *selection,
- int row);
-void e_selection_model_move_selection_end (ESelectionModel *selection,
- int row);
-void e_selection_model_set_selection_end (ESelectionModel *selection,
- int row);
+void e_selection_model_change_one_row (ESelectionModel *esm,
+ int row,
+ gboolean on);
+void e_selection_model_change_cursor (ESelectionModel *esm,
+ int row,
+ int col);
+int e_selection_model_cursor_row (ESelectionModel *esm);
+int e_selection_model_cursor_col (ESelectionModel *esm);
+void e_selection_model_select_single_row (ESelectionModel *selection,
+ int row);
+void e_selection_model_toggle_single_row (ESelectionModel *selection,
+ int row);
+void e_selection_model_move_selection_end (ESelectionModel *selection,
+ int row);
+void e_selection_model_set_selection_end (ESelectionModel *selection,
+ int row);
/* Signals */
-void e_selection_model_cursor_changed (ESelectionModel *selection,
- int row,
- int col);
-void e_selection_model_cursor_activated (ESelectionModel *selection,
- int row,
- int col);
-void e_selection_model_selection_changed (ESelectionModel *selection);
+void e_selection_model_cursor_changed (ESelectionModel *selection,
+ int row,
+ int col);
+void e_selection_model_cursor_activated (ESelectionModel *selection,
+ int row,
+ int col);
+void e_selection_model_selection_row_changed (ESelectionModel *selection,
+ int row);
+void e_selection_model_selection_changed (ESelectionModel *selection);
#ifdef __cplusplus
}