From c115cff69df04b7580fd8a50e087c7bd53614cec Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Sat, 5 Aug 2000 23:00:41 +0000 Subject: Added functions to convert from view row to model row or from model row to 2000-08-05 Christopher James Lahey * e-table.c, e-table.h: Added functions to convert from view row to model row or from model row to view row. Also changed e_table_set_cursor_row and e_table_get_cursor_row to take a model row as this works better with the rest of the model. Changed the name of e_table_get_next_row_sorted and e_table_get_prev_row_sorted. (Dropped the _sorted.) svn path=/trunk/; revision=4556 --- widgets/e-table/ChangeLog | 9 +++++++++ widgets/e-table/e-table.c | 42 +++++++++++++++++++++++++++++++++--------- widgets/e-table/e-table.h | 9 +++++++-- widgets/table/e-table.c | 42 +++++++++++++++++++++++++++++++++--------- widgets/table/e-table.h | 9 +++++++-- 5 files changed, 89 insertions(+), 22 deletions(-) (limited to 'widgets') diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index eacf84cea9..0bf8bfb5c4 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,3 +1,12 @@ +2000-08-05 Christopher James Lahey + + * e-table.c, e-table.h: Added functions to convert from view row + to model row or from model row to view row. Also changed + e_table_set_cursor_row and e_table_get_cursor_row to take a model + row as this works better with the rest of the model. Changed the + name of e_table_get_next_row_sorted and + e_table_get_prev_row_sorted. (Dropped the _sorted.) + 2000-08-05 Dan Winship * e-table.c (e_table_get_{next,prev}_row_sorted): fix diff --git a/widgets/e-table/e-table.c b/widgets/e-table/e-table.c index d9cbbc4779..ca26678607 100644 --- a/widgets/e-table/e-table.c +++ b/widgets/e-table/e-table.c @@ -803,13 +803,17 @@ e_table_save_specification (ETable *e_table, gchar *filename) void e_table_set_cursor_row (ETable *e_table, int row) { - e_table_group_set_cursor_row(e_table->group, row); + row = e_table_sorter_model_to_sorted(e_table->sorter, row); + if (row != -1) + e_table_group_set_cursor_row(e_table->group, row); } int e_table_get_cursor_row (ETable *e_table) { - return e_table_group_get_cursor_row(e_table->group); + int row = e_table_group_get_cursor_row(e_table->group); + row = e_table_sorter_sorted_to_model(e_table->sorter, row); + return row; } void @@ -926,27 +930,27 @@ set_scroll_adjustments (ETable *table, } gint -e_table_get_next_row_sorted (ETable *e_table, - gint model_row) +e_table_get_next_row (ETable *e_table, + gint model_row) { if (e_table->sorter) { int i; i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - if (i < e_table_model_row_count(e_table->model) - 1) { - i++; + i++; + if (i < e_table_model_row_count(e_table->model)) { return e_table_sorter_sorted_to_model(e_table->sorter, i); } else return -1; } else - if (model_row < e_table_model_row_count(e_table->model)) + if (model_row < e_table_model_row_count(e_table->model) - 1) return model_row + 1; else return -1; } gint -e_table_get_prev_row_sorted (ETable *e_table, - gint model_row) +e_table_get_prev_row (ETable *e_table, + gint model_row) { if (e_table->sorter) { int i; @@ -960,6 +964,26 @@ e_table_get_prev_row_sorted (ETable *e_table, return model_row - 1; } +gint +e_table_model_to_view_row (ETable *e_table, + gint model_row) +{ + if (e_table->sorter) + return e_table_sorter_model_to_sorted(e_table->sorter, model_row); + else + return model_row; +} + +gint +e_table_view_to_model_row (ETable *e_table, + gint view_row) +{ + if (e_table->sorter) + return e_table_sorter_sorted_to_model(e_table->sorter, view_row); + else + return view_row; +} + struct _ETableDragSourceSite { GdkModifierType start_button_mask; diff --git a/widgets/e-table/e-table.h b/widgets/e-table/e-table.h index b0e3cd174a..19dcbfecc8 100644 --- a/widgets/e-table/e-table.h +++ b/widgets/e-table/e-table.h @@ -182,11 +182,16 @@ void e_table_selected_row_foreach (ETable *e_table, gpointer closure); EPrintable *e_table_get_printable (ETable *e_table); -gint e_table_get_next_row_sorted (ETable *e_table, +gint e_table_get_next_row (ETable *e_table, gint model_row); -gint e_table_get_prev_row_sorted (ETable *e_table, +gint e_table_get_prev_row (ETable *e_table, gint model_row); +gint e_table_model_to_view_row (ETable *e_table, + gint model_row); +gint e_table_view_to_model_row (ETable *e_table, + gint view_row); + /* Drag & drop stuff. */ /* Target */ diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index d9cbbc4779..ca26678607 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -803,13 +803,17 @@ e_table_save_specification (ETable *e_table, gchar *filename) void e_table_set_cursor_row (ETable *e_table, int row) { - e_table_group_set_cursor_row(e_table->group, row); + row = e_table_sorter_model_to_sorted(e_table->sorter, row); + if (row != -1) + e_table_group_set_cursor_row(e_table->group, row); } int e_table_get_cursor_row (ETable *e_table) { - return e_table_group_get_cursor_row(e_table->group); + int row = e_table_group_get_cursor_row(e_table->group); + row = e_table_sorter_sorted_to_model(e_table->sorter, row); + return row; } void @@ -926,27 +930,27 @@ set_scroll_adjustments (ETable *table, } gint -e_table_get_next_row_sorted (ETable *e_table, - gint model_row) +e_table_get_next_row (ETable *e_table, + gint model_row) { if (e_table->sorter) { int i; i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - if (i < e_table_model_row_count(e_table->model) - 1) { - i++; + i++; + if (i < e_table_model_row_count(e_table->model)) { return e_table_sorter_sorted_to_model(e_table->sorter, i); } else return -1; } else - if (model_row < e_table_model_row_count(e_table->model)) + if (model_row < e_table_model_row_count(e_table->model) - 1) return model_row + 1; else return -1; } gint -e_table_get_prev_row_sorted (ETable *e_table, - gint model_row) +e_table_get_prev_row (ETable *e_table, + gint model_row) { if (e_table->sorter) { int i; @@ -960,6 +964,26 @@ e_table_get_prev_row_sorted (ETable *e_table, return model_row - 1; } +gint +e_table_model_to_view_row (ETable *e_table, + gint model_row) +{ + if (e_table->sorter) + return e_table_sorter_model_to_sorted(e_table->sorter, model_row); + else + return model_row; +} + +gint +e_table_view_to_model_row (ETable *e_table, + gint view_row) +{ + if (e_table->sorter) + return e_table_sorter_sorted_to_model(e_table->sorter, view_row); + else + return view_row; +} + struct _ETableDragSourceSite { GdkModifierType start_button_mask; diff --git a/widgets/table/e-table.h b/widgets/table/e-table.h index b0e3cd174a..19dcbfecc8 100644 --- a/widgets/table/e-table.h +++ b/widgets/table/e-table.h @@ -182,11 +182,16 @@ void e_table_selected_row_foreach (ETable *e_table, gpointer closure); EPrintable *e_table_get_printable (ETable *e_table); -gint e_table_get_next_row_sorted (ETable *e_table, +gint e_table_get_next_row (ETable *e_table, gint model_row); -gint e_table_get_prev_row_sorted (ETable *e_table, +gint e_table_get_prev_row (ETable *e_table, gint model_row); +gint e_table_model_to_view_row (ETable *e_table, + gint model_row); +gint e_table_view_to_model_row (ETable *e_table, + gint view_row); + /* Drag & drop stuff. */ /* Target */ -- cgit