aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-06-21 11:07:30 +0800
committerChris Lahey <clahey@src.gnome.org>2000-06-21 11:07:30 +0800
commitc62863d0877fd19c90ba8a15d4438611599b0979 (patch)
treed2668eab8bcb699aa1bcb547c17075c5226bdcfe /widgets
parent798b2b01e6ecdbaea70860ca357b5c3eb5ecddfb (diff)
downloadgsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.tar
gsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.tar.gz
gsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.tar.bz2
gsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.tar.lz
gsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.tar.xz
gsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.tar.zst
gsoc2013-evolution-c62863d0877fd19c90ba8a15d4438611599b0979.zip
Removed the unfocus method since that's handled by the canvas itself now.
2000-06-20 Christopher James Lahey <clahey@helixcode.com> * e-table-group-container.c, e-table-group-leaf.c, e-table-group.c, e-table-group.h: Removed the unfocus method since that's handled by the canvas itself now. * e-table-item.c, e-table-item.h: Finished adapting ETableItem to use the canvas selection/cursor system. Selection and cursor now use row numbers associated with the source model instead of the sorted model (if the model they are given is an ETableSubset.) This has no effect on the interface, except that unfocus was removed and e_table_item_focus was renamed to e_table_item_set_cursor. svn path=/trunk/; revision=3660
Diffstat (limited to 'widgets')
-rw-r--r--widgets/e-table/ChangeLog14
-rw-r--r--widgets/e-table/e-table-group-container.c12
-rw-r--r--widgets/e-table/e-table-group-leaf.c16
-rw-r--r--widgets/e-table/e-table-group.c11
-rw-r--r--widgets/e-table/e-table-group.h2
-rw-r--r--widgets/e-table/e-table-item.c184
-rw-r--r--widgets/e-table/e-table-item.h4
-rw-r--r--widgets/table/e-table-group-container.c12
-rw-r--r--widgets/table/e-table-group-leaf.c16
-rw-r--r--widgets/table/e-table-group.c11
-rw-r--r--widgets/table/e-table-group.h2
-rw-r--r--widgets/table/e-table-item.c184
-rw-r--r--widgets/table/e-table-item.h4
13 files changed, 198 insertions, 274 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog
index dc9beda343..59463dc319 100644
--- a/widgets/e-table/ChangeLog
+++ b/widgets/e-table/ChangeLog
@@ -1,5 +1,19 @@
2000-06-20 Christopher James Lahey <clahey@helixcode.com>
+ * e-table-group-container.c, e-table-group-leaf.c,
+ e-table-group.c, e-table-group.h: Removed the unfocus method since
+ that's handled by the canvas itself now.
+
+ * e-table-item.c, e-table-item.h: Finished adapting ETableItem to
+ use the canvas selection/cursor system. Selection and cursor now
+ use row numbers associated with the source model instead of the
+ sorted model (if the model they are given is an ETableSubset.)
+ This has no effect on the interface, except that unfocus was
+ removed and e_table_item_focus was renamed to
+ e_table_item_set_cursor.
+
+2000-06-20 Christopher James Lahey <clahey@helixcode.com>
+
* e-table-item.c, e-table-item.h: Started adapting ETableItem to
use the canvas selection/cursor system.
diff --git a/widgets/e-table/e-table-group-container.c b/widgets/e-table/e-table-group-container.c
index 8e48f447a8..6e950f08ed 100644
--- a/widgets/e-table/e-table-group-container.c
+++ b/widgets/e-table/e-table-group-container.c
@@ -216,7 +216,6 @@ etgc_event (GnomeCanvasItem *item, GdkEvent *event)
if (start_col == -1)
start_col = e_table_header_count (e_table_group_get_header (child)) - 1;
- e_table_group_unfocus(child);
if (direction == E_FOCUS_END)
list = list->prev;
else
@@ -521,16 +520,6 @@ etgc_set_focus (ETableGroup *etg, EFocus direction, gint view_col)
}
}
-static void
-etgc_unfocus (ETableGroup *etg)
-{
- ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg);
- GList *list;
- for (list = etgc->children; list; list = g_list_next(list)) {
- e_table_group_unfocus (((ETableGroupContainerChildNode *)list->data)->child);
- }
-}
-
static gint
etgc_get_focus_column (ETableGroup *etg)
{
@@ -672,7 +661,6 @@ etgc_class_init (GtkObjectClass *object_class)
e_group_class->set_focus = etgc_set_focus;
e_group_class->select_row = etgc_select_row;
e_group_class->get_selected_view_row = etgc_get_selected_view_row;
- e_group_class->unfocus = etgc_unfocus;
e_group_class->get_focus_column = etgc_get_focus_column;
e_group_class->get_printable = etgc_get_printable;
diff --git a/widgets/e-table/e-table-group-leaf.c b/widgets/e-table/e-table-group-leaf.c
index 0845f93695..ea3400ceb9 100644
--- a/widgets/e-table/e-table-group-leaf.c
+++ b/widgets/e-table/e-table-group-leaf.c
@@ -207,9 +207,9 @@ etgl_set_focus (ETableGroup *etg, EFocus direction, gint view_col)
{
ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg);
if (direction == E_FOCUS_END) {
- e_table_item_focus (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1);
+ e_table_item_set_cursor (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1);
} else {
- e_table_item_focus (etgl->item, view_col, 0);
+ e_table_item_set_cursor (etgl->item, view_col, 0);
}
}
@@ -217,7 +217,9 @@ static void
etgl_select_row (ETableGroup *etg, gint row)
{
ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg);
- e_table_item_focus(etgl->item, 0, row);
+ gnome_canvas_item_set(GTK_OBJECT(etgl->item),
+ "cursor_row", row,
+ NULL);
}
static int
@@ -231,13 +233,6 @@ etgl_get_selected_view_row (ETableGroup *etg)
return row;
}
-static void
-etgl_unfocus (ETableGroup *etg)
-{
- ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg);
- e_table_item_unfocus (etgl->item);
-}
-
static gint
etgl_get_focus_column (ETableGroup *etg)
{
@@ -360,7 +355,6 @@ etgl_class_init (GtkObjectClass *object_class)
e_group_class->row_count = etgl_row_count;
e_group_class->set_focus = etgl_set_focus;
e_group_class->select_row = etgl_select_row;
- e_group_class->unfocus = etgl_unfocus;
e_group_class->get_selected_view_row = etgl_get_selected_view_row;
e_group_class->get_focus_column = etgl_get_focus_column;
e_group_class->get_printable = etgl_get_printable;
diff --git a/widgets/e-table/e-table-group.c b/widgets/e-table/e-table-group.c
index 571280e46f..98ac040037 100644
--- a/widgets/e-table/e-table-group.c
+++ b/widgets/e-table/e-table-group.c
@@ -194,16 +194,6 @@ e_table_group_get_selected_view_row (ETableGroup *etg)
return -1;
}
-void
-e_table_group_unfocus (ETableGroup *etg)
-{
- g_return_if_fail (etg != NULL);
- g_return_if_fail (E_IS_TABLE_GROUP (etg));
-
- if (ETG_CLASS (etg)->unfocus)
- ETG_CLASS (etg)->unfocus (etg);
-}
-
gboolean
e_table_group_get_focus (ETableGroup *etg)
{
@@ -378,7 +368,6 @@ etg_class_init (GtkObjectClass *object_class)
klass->set_focus = NULL;
klass->select_row = NULL;
klass->get_selected_view_row = NULL;
- klass->unfocus = NULL;
klass->get_focus = etg_get_focus;
klass->get_ecol = NULL;
klass->get_printable = NULL;
diff --git a/widgets/e-table/e-table-group.h b/widgets/e-table/e-table-group.h
index 6505759ce7..a7c04cad5e 100644
--- a/widgets/e-table/e-table-group.h
+++ b/widgets/e-table/e-table-group.h
@@ -60,7 +60,6 @@ typedef struct {
void (*set_focus) (ETableGroup *etg, EFocus direction, gint view_col);
void (*select_row) (ETableGroup *etg, gint row);
int (*get_selected_view_row) (ETableGroup *etg);
- void (*unfocus) (ETableGroup *etg);
gboolean (*get_focus) (ETableGroup *etg);
gint (*get_focus_column) (ETableGroup *etg);
ETableCol *(*get_ecol) (ETableGroup *etg);
@@ -85,7 +84,6 @@ void e_table_group_set_focus (ETableGroup *etg,
void e_table_group_select_row (ETableGroup *etg,
gint row);
int e_table_group_get_selected_view_row (ETableGroup *etg);
-void e_table_group_unfocus (ETableGroup *etg);
gboolean e_table_group_get_focus (ETableGroup *etg);
gint e_table_group_get_focus_column (ETableGroup *etg);
ETableHeader *e_table_group_get_header (ETableGroup *etg);
diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c
index b5b775d2f8..e385d97181 100644
--- a/widgets/e-table/e-table-item.c
+++ b/widgets/e-table/e-table-item.c
@@ -62,8 +62,42 @@ static int eti_row_height (ETableItem *eti, int row);
static void e_table_item_unselect_row (ETableItem *eti, int row);
static void e_table_item_select_row (ETableItem *eti, int row);
static void eti_selection (GnomeCanvasItem *item, int flags, gpointer user_data);
+static void e_table_item_focus (ETableItem *eti, int col, int row);
#define ETI_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row)))
+static gint
+model_to_view_row(ETableItem *eti, int row)
+{
+ int i;
+ if (eti->uses_source_model) {
+ ETableSubset *etss = E_TABLE_SUBSET(eti->table_model);
+ if (eti->row_guess >= 0 && eti->row_guess < etss->n_map) {
+ if (etss->map_table[eti->row_guess] == row) {
+ return eti->row_guess;
+ }
+ }
+ for (i = 0; i < etss->n_map; i++) {
+ if (etss->map_table[i] == row)
+ return i;
+ }
+ return -1;
+ } else
+ return row;
+}
+
+static gint
+view_to_model_row(ETableItem *eti, int row)
+{
+ if (eti->uses_source_model) {
+ ETableSubset *etss = E_TABLE_SUBSET(eti->table_model);
+ if (row >= 0 && row < etss->n_map)
+ return etss->map_table[row];
+ else
+ return -1;
+ } else
+ return row;
+}
+
static gboolean
eti_editing (ETableItem *eti)
{
@@ -490,11 +524,6 @@ eti_table_model_changed (ETableModel *table_model, ETableItem *eti)
{
eti->rows = e_table_model_row_count (eti->table_model);
- /* FIXME: cursor */
- if (eti->cursor_row > eti->rows - 1)
- eti->cursor_row = eti->rows - 1;
-
-
free_height_cache(eti);
eti->needs_compute_height = 1;
@@ -614,8 +643,8 @@ e_table_item_redraw_range (ETableItem *eti,
if ((start_col == eti->cursor_col) ||
(end_col == eti->cursor_col) ||
- (start_row == eti->cursor_row) ||
- (end_row == eti->cursor_row))
+ (view_to_model_row(eti, start_row) == eti->cursor_row) ||
+ (view_to_model_row(eti, end_row) == eti->cursor_row))
border = 2;
else
border = 0;
@@ -783,6 +812,9 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
if (eti->minimum_width < eti->width)
e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti));
break;
+ case ARG_CURSOR_ROW:
+ e_table_item_focus (eti, eti->cursor_col != -1 ? eti->cursor_col : 0, view_to_model_row(eti, GTK_VALUE_INT (*arg)));
+ break;
}
eti->needs_redraw = 1;
gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(eti));
@@ -811,7 +843,7 @@ eti_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
GTK_VALUE_BOOL (*arg) = (eti->cursor_row != -1);
break;
case ARG_CURSOR_ROW:
- GTK_VALUE_INT (*arg) = eti->cursor_row;
+ GTK_VALUE_INT (*arg) = model_to_view_row(eti, eti->cursor_row);
break;
default:
arg->type = GTK_TYPE_INVALID;
@@ -839,6 +871,7 @@ eti_init (GnomeCanvasItem *item)
eti->uses_source_model = 0;
eti->source_model = NULL;
+ eti->row_guess = -1;
eti->cursor_row = -1;
eti->cursor_col = 0;
eti->cursor_mode = E_TABLE_CURSOR_SIMPLE;
@@ -1031,11 +1064,8 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
xd = x_offset;
/* printf ("paint: %d %d\n", yd, yd + height); */
-
-#if 0
- selected = g_slist_find (eti->selection, GINT_TO_POINTER (row)) != NULL;
-#endif
- selected = (row == eti->cursor_row);
+
+ selected = g_slist_find (eti->selection, GINT_TO_POINTER (view_to_model_row(eti, row))) != NULL;
for (col = first_col; col < last_col; col++){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
@@ -1043,7 +1073,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
gboolean col_selected = selected;
switch (eti->cursor_mode) {
case E_TABLE_CURSOR_SIMPLE:
- if (eti->cursor_col == col && eti->cursor_row == row)
+ if (eti->cursor_col == col && eti->cursor_row == view_to_model_row(eti, row))
col_selected = !col_selected;
break;
case E_TABLE_CURSOR_LINE:
@@ -1054,7 +1084,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, col_selected,
xd, yd, xd + ecol->width, yd + height);
- if (col == eti->cursor_col && row == eti->cursor_row){
+ if (col == eti->cursor_col && view_to_model_row(eti, row) == eti->cursor_row){
f_x1 = xd;
f_x2 = xd + ecol->width;
f_y1 = yd;
@@ -1161,31 +1191,31 @@ static void
eti_cursor_move (ETableItem *eti, gint row, gint column)
{
e_table_item_leave_edit (eti);
- e_table_item_focus (eti, column, row);
+ e_table_item_focus (eti, column, view_to_model_row(eti, row));
}
static void
eti_cursor_move_left (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row, eti->cursor_col - 1);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row), eti->cursor_col - 1);
}
static void
eti_cursor_move_right (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row, eti->cursor_col + 1);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row), eti->cursor_col + 1);
}
static void
eti_cursor_move_up (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row - 1, eti->cursor_col);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) - 1, eti->cursor_col);
}
static void
eti_cursor_move_down (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row + 1, eti->cursor_col);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) + 1, eti->cursor_col);
}
/* FIXME: cursor */
@@ -1212,15 +1242,15 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1))
return TRUE;
- if (eti->cursor_row != row || eti->cursor_col != col){
+ if (eti->cursor_row != view_to_model_row(eti, row) || eti->cursor_col != col){
/*
* Focus the cell, and select the row
*/
e_table_item_leave_edit (eti);
- e_table_item_focus (eti, col, row);
+ e_table_item_focus (eti, col, view_to_model_row(eti, row));
}
- if (eti->cursor_row == row && eti->cursor_col == col){
+ if (eti->cursor_row == view_to_model_row(eti, row) && eti->cursor_col == col){
ecol = e_table_header_get_column (eti->header, col);
ecell_view = eti->cell_views [col];
@@ -1277,7 +1307,7 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1))
return TRUE;
- if (eti->cursor_row == row && eti->cursor_col == col){
+ if (eti->cursor_row == view_to_model_row(eti, row) && eti->cursor_col == col){
ecol = e_table_header_get_column (eti->header, col);
ecell_view = eti->cell_views [col];
@@ -1318,14 +1348,14 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
break;
case GDK_Up:
- if (eti->cursor_row > 0)
+ if (eti->cursor_row != view_to_model_row(eti, 0))
eti_cursor_move_up (eti);
else
return_val = FALSE;
break;
case GDK_Down:
- if ((eti->cursor_row + 1) < eti->rows)
+ if (eti->cursor_row != view_to_model_row(eti, eti->rows - 1))
eti_cursor_move_down (eti);
else
return_val = FALSE;
@@ -1338,15 +1368,15 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
/* shift tab */
if (eti->cursor_col > 0)
eti_cursor_move_left (eti);
- else if (eti->cursor_row > 0)
- eti_cursor_move (eti, eti->cursor_row - 1, eti->cols - 1);
+ else if (eti->cursor_row != view_to_model_row(eti, 0))
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) - 1, eti->cols - 1);
else
return_val = FALSE;
} else {
if (eti->cursor_col < eti->cols - 1)
eti_cursor_move_right (eti);
- else if (eti->cursor_row < eti->rows - 1)
- eti_cursor_move (eti, eti->cursor_row + 1, 0);
+ else if (eti->cursor_row != view_to_model_row(eti, eti->rows - 1))
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) + 1, 0);
else
return_val = FALSE;
}
@@ -1355,11 +1385,11 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
default:
if (!eti_editing (eti)){
gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS],
- eti->cursor_row, eti->cursor_col, e, &return_val);
+ model_to_view_row(eti, eti->cursor_row), eti->cursor_col, e, &return_val);
} else {
ecol = e_table_header_get_column (eti->header, eti->cursor_col);
ecell_view = eti->cell_views [eti->cursor_col];
- e_cell_event (ecell_view, e, ecol->col_idx, eti->cursor_col, eti->cursor_row);
+ e_cell_event (ecell_view, e, ecol->col_idx, eti->cursor_col, model_to_view_row(eti, eti->cursor_row));
}
}
break;
@@ -1387,15 +1417,13 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
static void
eti_row_selection (ETableItem *eti, int row, gboolean selected)
{
-#if 0
- eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, 0);
+ int view_row = model_to_view_row(eti, row);
+ eti_request_region_redraw (eti, 0, view_row, eti->cols - 1, view_row, 0);
if (selected)
eti->selection = g_slist_prepend (eti->selection, GINT_TO_POINTER (row));
else
eti->selection = g_slist_remove (eti->selection, GINT_TO_POINTER (row));
-#endif
-
}
static void
@@ -1445,7 +1473,7 @@ eti_class_init (GtkObjectClass *object_class)
gtk_object_add_arg_type ("ETableItem::has_cursor", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_HAS_CURSOR);
gtk_object_add_arg_type ("ETableItem::cursor_row", GTK_TYPE_INT,
- GTK_ARG_READABLE, ARG_CURSOR_ROW);
+ GTK_ARG_READWRITE, ARG_CURSOR_ROW);
eti_signals [ROW_SELECTION] =
gtk_signal_new ("row_selection",
@@ -1515,83 +1543,32 @@ e_table_item_get_type (void)
}
void
+e_table_item_set_cursor (ETableItem *eti, int col, int row)
+{
+ e_table_item_focus(eti, col, view_to_model_row(eti, row));
+}
+
+static void
e_table_item_focus (ETableItem *eti, int col, int row)
{
g_return_if_fail (eti != NULL);
g_return_if_fail (E_IS_TABLE_ITEM (eti));
- /*
- * make sure we have the Gtk Focus
- */
- gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti));
-
- e_table_item_unfocus (eti);
-
if (row == -1) {
- row = eti->rows - 1;
+ row = view_to_model_row(eti, eti->rows - 1);
}
if (col == -1) {
- col = eti->cursor_col;
- row = -1;
+ col = eti->cols - 1;
}
eti->cursor_col = col;
- eti->cursor_row = row;
- gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE],
- row);
if (row != -1) {
- /* FIXME: remove once selection stuff is done. */
-#if 0
- if (eti->cursor_mode == E_TABLE_CURSOR_SPREADSHEET)
- eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER);
- else
-#endif
- eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, FOCUSED_BORDER);
-
- eti_request_region_show (eti, 0, row, eti->cols - 1, row);
-
-#if 0
- e_table_item_select_row (eti, row);
-#endif
+ e_canvas_item_set_cursor(GNOME_CANVAS_ITEM(eti), (gpointer) row);
}
}
-void
-e_table_item_unfocus (ETableItem *eti)
-{
- g_return_if_fail (eti != NULL);
- g_return_if_fail (E_IS_TABLE_ITEM (eti));
-
- if (eti->cursor_row == -1)
- return;
-
- {
-#if 0
- const int col = eti->cursor_col;
-#endif
- const int row = eti->cursor_row;
-
-#if 0
- if (eti->cursor_mode == E_TABLE_CURSOR_SPREADSHEET)
- eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER);
- else
-#endif
- /* FIXME: remove once selection stuff is done. */
- gtk_signal_emit (GTK_OBJECT (eti), eti_signals [ROW_SELECTION],
- row, 0);
- eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, FOCUSED_BORDER);
-#if 0
- while (eti->selection){
- e_table_item_unselect_row (eti, GPOINTER_TO_INT(eti->selection->data));
- }
-#endif
- }
- eti->cursor_col = -1;
- eti->cursor_row = -1;
-}
-
gint
e_table_item_get_focused_column (ETableItem *eti)
{
@@ -1650,7 +1627,7 @@ eti_selection (GnomeCanvasItem *item, int flags, gpointer data)
int col = 0;
ETableItem *eti = E_TABLE_ITEM(item);
int selected = e_table_item_is_row_selected(eti, row);
- int cursored = row == eti->cursor_row;
+ int cursored = (row == eti->cursor_row);
if (selected && (flags & E_CANVAS_ITEM_SELECTION_SELECT) == 0) {
e_table_item_unselect_row (eti, row);
@@ -1659,8 +1636,17 @@ eti_selection (GnomeCanvasItem *item, int flags, gpointer data)
e_table_item_select_row (eti, row);
}
if ((!cursored) && (flags & E_CANVAS_ITEM_SELECTION_CURSOR) != 0) {
- eti->cursor_row = row;
+ int view_row = model_to_view_row(eti, row);
+
eti->cursor_col = col;
+ eti->cursor_row = row;
+ gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE],
+ view_row);
+ eti_request_region_show (eti, col, view_row, col, view_row);
+ }
+ if ((cursored) && (flags & E_CANVAS_ITEM_SELECTION_CURSOR) == 0) {
+ eti->cursor_row = -1;
+ eti->cursor_col = -1;
}
if (flags & E_CANVAS_ITEM_SELECTION_DELETE_DATA) {
diff --git a/widgets/e-table/e-table-item.h b/widgets/e-table/e-table-item.h
index 1d522413cd..235ab6d764 100644
--- a/widgets/e-table/e-table-item.h
+++ b/widgets/e-table/e-table-item.h
@@ -75,6 +75,7 @@ typedef struct {
*/
int length_threshold;
+ gint row_guess;
gint cursor_row;
gint cursor_col;
ETableCursorMode cursor_mode;
@@ -105,8 +106,7 @@ GtkType e_table_item_get_type (void);
/*
* Focus
*/
-void e_table_item_focus (ETableItem *eti, int col, int row);
-void e_table_item_unfocus (ETableItem *eti);
+void e_table_item_set_cursor (ETableItem *eti, int col, int row);
gint e_table_item_get_focused_column (ETableItem *eti);
diff --git a/widgets/table/e-table-group-container.c b/widgets/table/e-table-group-container.c
index 8e48f447a8..6e950f08ed 100644
--- a/widgets/table/e-table-group-container.c
+++ b/widgets/table/e-table-group-container.c
@@ -216,7 +216,6 @@ etgc_event (GnomeCanvasItem *item, GdkEvent *event)
if (start_col == -1)
start_col = e_table_header_count (e_table_group_get_header (child)) - 1;
- e_table_group_unfocus(child);
if (direction == E_FOCUS_END)
list = list->prev;
else
@@ -521,16 +520,6 @@ etgc_set_focus (ETableGroup *etg, EFocus direction, gint view_col)
}
}
-static void
-etgc_unfocus (ETableGroup *etg)
-{
- ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg);
- GList *list;
- for (list = etgc->children; list; list = g_list_next(list)) {
- e_table_group_unfocus (((ETableGroupContainerChildNode *)list->data)->child);
- }
-}
-
static gint
etgc_get_focus_column (ETableGroup *etg)
{
@@ -672,7 +661,6 @@ etgc_class_init (GtkObjectClass *object_class)
e_group_class->set_focus = etgc_set_focus;
e_group_class->select_row = etgc_select_row;
e_group_class->get_selected_view_row = etgc_get_selected_view_row;
- e_group_class->unfocus = etgc_unfocus;
e_group_class->get_focus_column = etgc_get_focus_column;
e_group_class->get_printable = etgc_get_printable;
diff --git a/widgets/table/e-table-group-leaf.c b/widgets/table/e-table-group-leaf.c
index 0845f93695..ea3400ceb9 100644
--- a/widgets/table/e-table-group-leaf.c
+++ b/widgets/table/e-table-group-leaf.c
@@ -207,9 +207,9 @@ etgl_set_focus (ETableGroup *etg, EFocus direction, gint view_col)
{
ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg);
if (direction == E_FOCUS_END) {
- e_table_item_focus (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1);
+ e_table_item_set_cursor (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1);
} else {
- e_table_item_focus (etgl->item, view_col, 0);
+ e_table_item_set_cursor (etgl->item, view_col, 0);
}
}
@@ -217,7 +217,9 @@ static void
etgl_select_row (ETableGroup *etg, gint row)
{
ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg);
- e_table_item_focus(etgl->item, 0, row);
+ gnome_canvas_item_set(GTK_OBJECT(etgl->item),
+ "cursor_row", row,
+ NULL);
}
static int
@@ -231,13 +233,6 @@ etgl_get_selected_view_row (ETableGroup *etg)
return row;
}
-static void
-etgl_unfocus (ETableGroup *etg)
-{
- ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg);
- e_table_item_unfocus (etgl->item);
-}
-
static gint
etgl_get_focus_column (ETableGroup *etg)
{
@@ -360,7 +355,6 @@ etgl_class_init (GtkObjectClass *object_class)
e_group_class->row_count = etgl_row_count;
e_group_class->set_focus = etgl_set_focus;
e_group_class->select_row = etgl_select_row;
- e_group_class->unfocus = etgl_unfocus;
e_group_class->get_selected_view_row = etgl_get_selected_view_row;
e_group_class->get_focus_column = etgl_get_focus_column;
e_group_class->get_printable = etgl_get_printable;
diff --git a/widgets/table/e-table-group.c b/widgets/table/e-table-group.c
index 571280e46f..98ac040037 100644
--- a/widgets/table/e-table-group.c
+++ b/widgets/table/e-table-group.c
@@ -194,16 +194,6 @@ e_table_group_get_selected_view_row (ETableGroup *etg)
return -1;
}
-void
-e_table_group_unfocus (ETableGroup *etg)
-{
- g_return_if_fail (etg != NULL);
- g_return_if_fail (E_IS_TABLE_GROUP (etg));
-
- if (ETG_CLASS (etg)->unfocus)
- ETG_CLASS (etg)->unfocus (etg);
-}
-
gboolean
e_table_group_get_focus (ETableGroup *etg)
{
@@ -378,7 +368,6 @@ etg_class_init (GtkObjectClass *object_class)
klass->set_focus = NULL;
klass->select_row = NULL;
klass->get_selected_view_row = NULL;
- klass->unfocus = NULL;
klass->get_focus = etg_get_focus;
klass->get_ecol = NULL;
klass->get_printable = NULL;
diff --git a/widgets/table/e-table-group.h b/widgets/table/e-table-group.h
index 6505759ce7..a7c04cad5e 100644
--- a/widgets/table/e-table-group.h
+++ b/widgets/table/e-table-group.h
@@ -60,7 +60,6 @@ typedef struct {
void (*set_focus) (ETableGroup *etg, EFocus direction, gint view_col);
void (*select_row) (ETableGroup *etg, gint row);
int (*get_selected_view_row) (ETableGroup *etg);
- void (*unfocus) (ETableGroup *etg);
gboolean (*get_focus) (ETableGroup *etg);
gint (*get_focus_column) (ETableGroup *etg);
ETableCol *(*get_ecol) (ETableGroup *etg);
@@ -85,7 +84,6 @@ void e_table_group_set_focus (ETableGroup *etg,
void e_table_group_select_row (ETableGroup *etg,
gint row);
int e_table_group_get_selected_view_row (ETableGroup *etg);
-void e_table_group_unfocus (ETableGroup *etg);
gboolean e_table_group_get_focus (ETableGroup *etg);
gint e_table_group_get_focus_column (ETableGroup *etg);
ETableHeader *e_table_group_get_header (ETableGroup *etg);
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c
index b5b775d2f8..e385d97181 100644
--- a/widgets/table/e-table-item.c
+++ b/widgets/table/e-table-item.c
@@ -62,8 +62,42 @@ static int eti_row_height (ETableItem *eti, int row);
static void e_table_item_unselect_row (ETableItem *eti, int row);
static void e_table_item_select_row (ETableItem *eti, int row);
static void eti_selection (GnomeCanvasItem *item, int flags, gpointer user_data);
+static void e_table_item_focus (ETableItem *eti, int col, int row);
#define ETI_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row)))
+static gint
+model_to_view_row(ETableItem *eti, int row)
+{
+ int i;
+ if (eti->uses_source_model) {
+ ETableSubset *etss = E_TABLE_SUBSET(eti->table_model);
+ if (eti->row_guess >= 0 && eti->row_guess < etss->n_map) {
+ if (etss->map_table[eti->row_guess] == row) {
+ return eti->row_guess;
+ }
+ }
+ for (i = 0; i < etss->n_map; i++) {
+ if (etss->map_table[i] == row)
+ return i;
+ }
+ return -1;
+ } else
+ return row;
+}
+
+static gint
+view_to_model_row(ETableItem *eti, int row)
+{
+ if (eti->uses_source_model) {
+ ETableSubset *etss = E_TABLE_SUBSET(eti->table_model);
+ if (row >= 0 && row < etss->n_map)
+ return etss->map_table[row];
+ else
+ return -1;
+ } else
+ return row;
+}
+
static gboolean
eti_editing (ETableItem *eti)
{
@@ -490,11 +524,6 @@ eti_table_model_changed (ETableModel *table_model, ETableItem *eti)
{
eti->rows = e_table_model_row_count (eti->table_model);
- /* FIXME: cursor */
- if (eti->cursor_row > eti->rows - 1)
- eti->cursor_row = eti->rows - 1;
-
-
free_height_cache(eti);
eti->needs_compute_height = 1;
@@ -614,8 +643,8 @@ e_table_item_redraw_range (ETableItem *eti,
if ((start_col == eti->cursor_col) ||
(end_col == eti->cursor_col) ||
- (start_row == eti->cursor_row) ||
- (end_row == eti->cursor_row))
+ (view_to_model_row(eti, start_row) == eti->cursor_row) ||
+ (view_to_model_row(eti, end_row) == eti->cursor_row))
border = 2;
else
border = 0;
@@ -783,6 +812,9 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
if (eti->minimum_width < eti->width)
e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti));
break;
+ case ARG_CURSOR_ROW:
+ e_table_item_focus (eti, eti->cursor_col != -1 ? eti->cursor_col : 0, view_to_model_row(eti, GTK_VALUE_INT (*arg)));
+ break;
}
eti->needs_redraw = 1;
gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(eti));
@@ -811,7 +843,7 @@ eti_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
GTK_VALUE_BOOL (*arg) = (eti->cursor_row != -1);
break;
case ARG_CURSOR_ROW:
- GTK_VALUE_INT (*arg) = eti->cursor_row;
+ GTK_VALUE_INT (*arg) = model_to_view_row(eti, eti->cursor_row);
break;
default:
arg->type = GTK_TYPE_INVALID;
@@ -839,6 +871,7 @@ eti_init (GnomeCanvasItem *item)
eti->uses_source_model = 0;
eti->source_model = NULL;
+ eti->row_guess = -1;
eti->cursor_row = -1;
eti->cursor_col = 0;
eti->cursor_mode = E_TABLE_CURSOR_SIMPLE;
@@ -1031,11 +1064,8 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
xd = x_offset;
/* printf ("paint: %d %d\n", yd, yd + height); */
-
-#if 0
- selected = g_slist_find (eti->selection, GINT_TO_POINTER (row)) != NULL;
-#endif
- selected = (row == eti->cursor_row);
+
+ selected = g_slist_find (eti->selection, GINT_TO_POINTER (view_to_model_row(eti, row))) != NULL;
for (col = first_col; col < last_col; col++){
ETableCol *ecol = e_table_header_get_column (eti->header, col);
@@ -1043,7 +1073,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
gboolean col_selected = selected;
switch (eti->cursor_mode) {
case E_TABLE_CURSOR_SIMPLE:
- if (eti->cursor_col == col && eti->cursor_row == row)
+ if (eti->cursor_col == col && eti->cursor_row == view_to_model_row(eti, row))
col_selected = !col_selected;
break;
case E_TABLE_CURSOR_LINE:
@@ -1054,7 +1084,7 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width,
e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, col_selected,
xd, yd, xd + ecol->width, yd + height);
- if (col == eti->cursor_col && row == eti->cursor_row){
+ if (col == eti->cursor_col && view_to_model_row(eti, row) == eti->cursor_row){
f_x1 = xd;
f_x2 = xd + ecol->width;
f_y1 = yd;
@@ -1161,31 +1191,31 @@ static void
eti_cursor_move (ETableItem *eti, gint row, gint column)
{
e_table_item_leave_edit (eti);
- e_table_item_focus (eti, column, row);
+ e_table_item_focus (eti, column, view_to_model_row(eti, row));
}
static void
eti_cursor_move_left (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row, eti->cursor_col - 1);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row), eti->cursor_col - 1);
}
static void
eti_cursor_move_right (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row, eti->cursor_col + 1);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row), eti->cursor_col + 1);
}
static void
eti_cursor_move_up (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row - 1, eti->cursor_col);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) - 1, eti->cursor_col);
}
static void
eti_cursor_move_down (ETableItem *eti)
{
- eti_cursor_move (eti, eti->cursor_row + 1, eti->cursor_col);
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) + 1, eti->cursor_col);
}
/* FIXME: cursor */
@@ -1212,15 +1242,15 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1))
return TRUE;
- if (eti->cursor_row != row || eti->cursor_col != col){
+ if (eti->cursor_row != view_to_model_row(eti, row) || eti->cursor_col != col){
/*
* Focus the cell, and select the row
*/
e_table_item_leave_edit (eti);
- e_table_item_focus (eti, col, row);
+ e_table_item_focus (eti, col, view_to_model_row(eti, row));
}
- if (eti->cursor_row == row && eti->cursor_col == col){
+ if (eti->cursor_row == view_to_model_row(eti, row) && eti->cursor_col == col){
ecol = e_table_header_get_column (eti->header, col);
ecell_view = eti->cell_views [col];
@@ -1277,7 +1307,7 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1))
return TRUE;
- if (eti->cursor_row == row && eti->cursor_col == col){
+ if (eti->cursor_row == view_to_model_row(eti, row) && eti->cursor_col == col){
ecol = e_table_header_get_column (eti->header, col);
ecell_view = eti->cell_views [col];
@@ -1318,14 +1348,14 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
break;
case GDK_Up:
- if (eti->cursor_row > 0)
+ if (eti->cursor_row != view_to_model_row(eti, 0))
eti_cursor_move_up (eti);
else
return_val = FALSE;
break;
case GDK_Down:
- if ((eti->cursor_row + 1) < eti->rows)
+ if (eti->cursor_row != view_to_model_row(eti, eti->rows - 1))
eti_cursor_move_down (eti);
else
return_val = FALSE;
@@ -1338,15 +1368,15 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
/* shift tab */
if (eti->cursor_col > 0)
eti_cursor_move_left (eti);
- else if (eti->cursor_row > 0)
- eti_cursor_move (eti, eti->cursor_row - 1, eti->cols - 1);
+ else if (eti->cursor_row != view_to_model_row(eti, 0))
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) - 1, eti->cols - 1);
else
return_val = FALSE;
} else {
if (eti->cursor_col < eti->cols - 1)
eti_cursor_move_right (eti);
- else if (eti->cursor_row < eti->rows - 1)
- eti_cursor_move (eti, eti->cursor_row + 1, 0);
+ else if (eti->cursor_row != view_to_model_row(eti, eti->rows - 1))
+ eti_cursor_move (eti, model_to_view_row(eti, eti->cursor_row) + 1, 0);
else
return_val = FALSE;
}
@@ -1355,11 +1385,11 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
default:
if (!eti_editing (eti)){
gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS],
- eti->cursor_row, eti->cursor_col, e, &return_val);
+ model_to_view_row(eti, eti->cursor_row), eti->cursor_col, e, &return_val);
} else {
ecol = e_table_header_get_column (eti->header, eti->cursor_col);
ecell_view = eti->cell_views [eti->cursor_col];
- e_cell_event (ecell_view, e, ecol->col_idx, eti->cursor_col, eti->cursor_row);
+ e_cell_event (ecell_view, e, ecol->col_idx, eti->cursor_col, model_to_view_row(eti, eti->cursor_row));
}
}
break;
@@ -1387,15 +1417,13 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
static void
eti_row_selection (ETableItem *eti, int row, gboolean selected)
{
-#if 0
- eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, 0);
+ int view_row = model_to_view_row(eti, row);
+ eti_request_region_redraw (eti, 0, view_row, eti->cols - 1, view_row, 0);
if (selected)
eti->selection = g_slist_prepend (eti->selection, GINT_TO_POINTER (row));
else
eti->selection = g_slist_remove (eti->selection, GINT_TO_POINTER (row));
-#endif
-
}
static void
@@ -1445,7 +1473,7 @@ eti_class_init (GtkObjectClass *object_class)
gtk_object_add_arg_type ("ETableItem::has_cursor", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_HAS_CURSOR);
gtk_object_add_arg_type ("ETableItem::cursor_row", GTK_TYPE_INT,
- GTK_ARG_READABLE, ARG_CURSOR_ROW);
+ GTK_ARG_READWRITE, ARG_CURSOR_ROW);
eti_signals [ROW_SELECTION] =
gtk_signal_new ("row_selection",
@@ -1515,83 +1543,32 @@ e_table_item_get_type (void)
}
void
+e_table_item_set_cursor (ETableItem *eti, int col, int row)
+{
+ e_table_item_focus(eti, col, view_to_model_row(eti, row));
+}
+
+static void
e_table_item_focus (ETableItem *eti, int col, int row)
{
g_return_if_fail (eti != NULL);
g_return_if_fail (E_IS_TABLE_ITEM (eti));
- /*
- * make sure we have the Gtk Focus
- */
- gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti));
-
- e_table_item_unfocus (eti);
-
if (row == -1) {
- row = eti->rows - 1;
+ row = view_to_model_row(eti, eti->rows - 1);
}
if (col == -1) {
- col = eti->cursor_col;
- row = -1;
+ col = eti->cols - 1;
}
eti->cursor_col = col;
- eti->cursor_row = row;
- gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE],
- row);
if (row != -1) {
- /* FIXME: remove once selection stuff is done. */
-#if 0
- if (eti->cursor_mode == E_TABLE_CURSOR_SPREADSHEET)
- eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER);
- else
-#endif
- eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, FOCUSED_BORDER);
-
- eti_request_region_show (eti, 0, row, eti->cols - 1, row);
-
-#if 0
- e_table_item_select_row (eti, row);
-#endif
+ e_canvas_item_set_cursor(GNOME_CANVAS_ITEM(eti), (gpointer) row);
}
}
-void
-e_table_item_unfocus (ETableItem *eti)
-{
- g_return_if_fail (eti != NULL);
- g_return_if_fail (E_IS_TABLE_ITEM (eti));
-
- if (eti->cursor_row == -1)
- return;
-
- {
-#if 0
- const int col = eti->cursor_col;
-#endif
- const int row = eti->cursor_row;
-
-#if 0
- if (eti->cursor_mode == E_TABLE_CURSOR_SPREADSHEET)
- eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER);
- else
-#endif
- /* FIXME: remove once selection stuff is done. */
- gtk_signal_emit (GTK_OBJECT (eti), eti_signals [ROW_SELECTION],
- row, 0);
- eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, FOCUSED_BORDER);
-#if 0
- while (eti->selection){
- e_table_item_unselect_row (eti, GPOINTER_TO_INT(eti->selection->data));
- }
-#endif
- }
- eti->cursor_col = -1;
- eti->cursor_row = -1;
-}
-
gint
e_table_item_get_focused_column (ETableItem *eti)
{
@@ -1650,7 +1627,7 @@ eti_selection (GnomeCanvasItem *item, int flags, gpointer data)
int col = 0;
ETableItem *eti = E_TABLE_ITEM(item);
int selected = e_table_item_is_row_selected(eti, row);
- int cursored = row == eti->cursor_row;
+ int cursored = (row == eti->cursor_row);
if (selected && (flags & E_CANVAS_ITEM_SELECTION_SELECT) == 0) {
e_table_item_unselect_row (eti, row);
@@ -1659,8 +1636,17 @@ eti_selection (GnomeCanvasItem *item, int flags, gpointer data)
e_table_item_select_row (eti, row);
}
if ((!cursored) && (flags & E_CANVAS_ITEM_SELECTION_CURSOR) != 0) {
- eti->cursor_row = row;
+ int view_row = model_to_view_row(eti, row);
+
eti->cursor_col = col;
+ eti->cursor_row = row;
+ gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE],
+ view_row);
+ eti_request_region_show (eti, col, view_row, col, view_row);
+ }
+ if ((cursored) && (flags & E_CANVAS_ITEM_SELECTION_CURSOR) == 0) {
+ eti->cursor_row = -1;
+ eti->cursor_col = -1;
}
if (flags & E_CANVAS_ITEM_SELECTION_DELETE_DATA) {
diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h
index 1d522413cd..235ab6d764 100644
--- a/widgets/table/e-table-item.h
+++ b/widgets/table/e-table-item.h
@@ -75,6 +75,7 @@ typedef struct {
*/
int length_threshold;
+ gint row_guess;
gint cursor_row;
gint cursor_col;
ETableCursorMode cursor_mode;
@@ -105,8 +106,7 @@ GtkType e_table_item_get_type (void);
/*
* Focus
*/
-void e_table_item_focus (ETableItem *eti, int col, int row);
-void e_table_item_unfocus (ETableItem *eti);
+void e_table_item_set_cursor (ETableItem *eti, int col, int row);
gint e_table_item_get_focused_column (ETableItem *eti);