aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2002-01-16 06:33:13 +0800
committerChris Lahey <clahey@src.gnome.org>2002-01-16 06:33:13 +0800
commit1d68f8289f5686820da5ed0cecec586bc50e445c (patch)
tree661788cafb05bb83d9ac482979eba5cb57ce6875 /widgets
parent33748a64453cf5bcbde73ec7bf0a983ecfa49ff4 (diff)
downloadgsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.tar
gsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.tar.gz
gsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.tar.bz2
gsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.tar.lz
gsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.tar.xz
gsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.tar.zst
gsoc2013-evolution-1d68f8289f5686820da5ed0cecec586bc50e445c.zip
New functions for saving selection state and such.
2002-01-15 Christopher James Lahey <clahey@ximian.com> * e-cell.c, e-cell.h (e_cell_save_state, e_cell_load_state, e_cell_free_state): New functions for saving selection state and such. * e-cell-text.c (ect_save_state): Implemented the new state functions. * e-table-item.c, e-table-item.h: Use the new cell state functions when focusing in or out. Fixes Ximian bug #14968. svn path=/trunk/; revision=15335
Diffstat (limited to 'widgets')
-rw-r--r--widgets/table/e-cell-text.c47
-rw-r--r--widgets/table/e-cell.c115
-rw-r--r--widgets/table/e-cell.h23
-rw-r--r--widgets/table/e-table-item.c45
-rw-r--r--widgets/table/e-table-item.h3
5 files changed, 210 insertions, 23 deletions
diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c
index 9f57710d81..63a78a5a98 100644
--- a/widgets/table/e-cell-text.c
+++ b/widgets/table/e-cell-text.c
@@ -1093,6 +1093,50 @@ ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, voi
}
}
+/*
+ * ECellView::save_state method
+ */
+static void *
+ect_save_state (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context)
+{
+ ECellTextView *text_view = (ECellTextView *) ecell_view;
+ CellEdit *edit = text_view->edit;
+
+ int *save_state = g_new (int, 2);
+
+ save_state[0] = edit->selection_start;
+ save_state[1] = edit->selection_end;
+ return save_state;
+}
+
+/*
+ * ECellView::load_state method
+ */
+static void
+ect_load_state (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context, void *save_state)
+{
+ ECellTextView *text_view = (ECellTextView *) ecell_view;
+ CellEdit *edit = text_view->edit;
+ int length;
+ int *selection = save_state;
+
+ length = strlen (edit->cell.text);
+
+ edit->selection_start = MIN (selection[0], length);
+ edit->selection_end = MIN (selection[1], length);
+
+ ect_queue_redraw (text_view, view_col, row);
+}
+
+/*
+ * ECellView::free_state method
+ */
+static void
+ect_free_state (ECellView *ecell_view, int model_col, int view_col, int row, void *save_state)
+{
+ g_free (save_state);
+}
+
static void
ect_print (ECellView *ecell_view, GnomePrintContext *context,
int model_col, int view_col, int row,
@@ -1455,6 +1499,9 @@ e_cell_text_class_init (GtkObjectClass *object_class)
ecc->height = ect_height;
ecc->enter_edit = ect_enter_edit;
ecc->leave_edit = ect_leave_edit;
+ ecc->save_state = ect_save_state;
+ ecc->load_state = ect_load_state;
+ ecc->free_state = ect_free_state;
ecc->print = ect_print;
ecc->print_height = ect_print_height;
ecc->max_width = ect_max_width;
diff --git a/widgets/table/e-cell.c b/widgets/table/e-cell.c
index 9a11c2362e..3045081cc4 100644
--- a/widgets/table/e-cell.c
+++ b/widgets/table/e-cell.c
@@ -28,6 +28,8 @@
#define PARENT_TYPE gtk_object_get_type ()
+#define ECVIEW_EC_CLASS(v) (E_CELL_CLASS (GTK_OBJECT ((v)->ecell)->klass))
+
static ECellView *
ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view)
{
@@ -104,6 +106,22 @@ ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void
{
}
+static void *
+ec_save_state (ECellView *ecell_view, int model_col, int view_col, int row, void *context)
+{
+ return NULL;
+}
+
+static void
+ec_load_state (ECellView *ecell_view, int model_col, int view_col, int row, void *context, void *save_state)
+{
+}
+
+static void
+ec_free_state (ECellView *ecell_view, int model_col, int view_col, int row, void *save_state)
+{
+}
+
static void
ec_show_tooltip (ECellView *ecell_view, int model_col, int view_col, int row, int col_width, ETableTooltip *tooltip)
{
@@ -126,6 +144,9 @@ e_cell_class_init (GtkObjectClass *object_class)
ecc->height = ec_height;
ecc->enter_edit = ec_enter_edit;
ecc->leave_edit = ec_leave_edit;
+ ecc->save_state = ec_save_state;
+ ecc->load_state = ec_load_state;
+ ecc->free_state = ec_free_state;
ecc->print = NULL;
ecc->print_height = NULL;
ecc->max_width = NULL;
@@ -156,7 +177,7 @@ E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE)
gint
e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions)
{
- return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event (
+ return ECVIEW_EC_CLASS(ecell_view)->event (
ecell_view, event, model_col, view_col, row, flags, actions);
}
@@ -193,7 +214,7 @@ e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view
void
e_cell_realize (ECellView *ecell_view)
{
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view);
+ ECVIEW_EC_CLASS(ecell_view)->realize (ecell_view);
}
/**
@@ -205,7 +226,7 @@ e_cell_realize (ECellView *ecell_view)
void
e_cell_kill_view (ECellView *ecell_view)
{
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view);
+ ECVIEW_EC_CLASS(ecell_view)->kill_view (ecell_view);
}
/**
@@ -219,7 +240,7 @@ e_cell_kill_view (ECellView *ecell_view)
void
e_cell_unrealize (ECellView *ecell_view)
{
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view);
+ ECVIEW_EC_CLASS(ecell_view)->unrealize (ecell_view);
}
/**
@@ -250,8 +271,7 @@ e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable,
g_return_if_fail (row >= 0);
g_return_if_fail (row < e_table_model_row_count(ecell_view->e_table_model));
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw (
- ecell_view, drawable, model_col, view_col, row, flags, x1, y1, x2, y2);
+ ECVIEW_EC_CLASS(ecell_view)->draw (ecell_view, drawable, model_col, view_col, row, flags, x1, y1, x2, y2);
}
/**
@@ -271,8 +291,7 @@ e_cell_print (ECellView *ecell_view, GnomePrintContext *context,
int model_col, int view_col, int row,
double width, double height)
{
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print
- (ecell_view, context, model_col, view_col, row, width, height);
+ ECVIEW_EC_CLASS(ecell_view)->print (ecell_view, context, model_col, view_col, row, width, height);
}
/**
@@ -285,8 +304,8 @@ e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context,
int model_col, int view_col, int row,
double width)
{
- if (E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height)
- return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height
+ if (ECVIEW_EC_CLASS(ecell_view)->print_height)
+ return ECVIEW_EC_CLASS(ecell_view)->print_height
(ecell_view, context, model_col, view_col, row, width);
else
return 0.0;
@@ -305,8 +324,7 @@ e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context,
int
e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row)
{
- return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height (
- ecell_view, model_col, view_col, row);
+ return ECVIEW_EC_CLASS(ecell_view)->height (ecell_view, model_col, view_col, row);
}
/**
@@ -322,8 +340,7 @@ e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row)
void *
e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row)
{
- return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit (
- ecell_view, model_col, view_col, row);
+ return ECVIEW_EC_CLASS(ecell_view)->enter_edit (ecell_view, model_col, view_col, row);
}
/**
@@ -340,8 +357,66 @@ e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row)
void
e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context)
{
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit (
- ecell_view, model_col, view_col, row, edit_context);
+ ECVIEW_EC_CLASS(ecell_view)->leave_edit (ecell_view, model_col, view_col, row, edit_context);
+}
+
+/**
+ * e_cell_save_state:
+ * @ecell_view: the ECellView to save
+ * @model_col: the column in the model
+ * @view_col: the column in the view
+ * @row: the row
+ * @edit_context: the editing context
+ *
+ * Returns: The save state.
+ *
+ * Requests that the ECellView return a void * representing the state
+ * of the ECell. This is primarily intended for things like selection
+ * or scrolling.
+ */
+void *
+e_cell_save_state (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context)
+{
+ if (ECVIEW_EC_CLASS(ecell_view)->save_state)
+ return ECVIEW_EC_CLASS(ecell_view)->save_state (ecell_view, model_col, view_col, row, edit_context);
+ else
+ return NULL;
+}
+
+/**
+ * e_cell_load_state:
+ * @ecell_view: the ECellView to load
+ * @model_col: the column in the model
+ * @view_col: the column in the view
+ * @row: the row
+ * @edit_context: the editing context
+ * @save_state: the save state to load from
+ *
+ * Requests that the ECellView load from the given save state.
+ */
+void
+e_cell_load_state (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context, void *save_state)
+{
+ if (ECVIEW_EC_CLASS(ecell_view)->load_state)
+ ECVIEW_EC_CLASS(ecell_view)->load_state (ecell_view, model_col, view_col, row, edit_context, save_state);
+}
+
+/**
+ * e_cell_load_state:
+ * @ecell_view: the ECellView
+ * @model_col: the column in the model
+ * @view_col: the column in the view
+ * @row: the row
+ * @edit_context: the editing context
+ * @save_state: the save state to free
+ *
+ * Requests that the ECellView free the given save state.
+ */
+void
+e_cell_free_state (ECellView *ecell_view, int model_col, int view_col, int row, void *save_state)
+{
+ if (ECVIEW_EC_CLASS(ecell_view)->free_state)
+ ECVIEW_EC_CLASS(ecell_view)->free_state (ecell_view, model_col, view_col, row, save_state);
}
/**
@@ -356,7 +431,7 @@ e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row,
int
e_cell_max_width (ECellView *ecell_view, int model_col, int view_col)
{
- return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->max_width
+ return ECVIEW_EC_CLASS(ecell_view)->max_width
(ecell_view, model_col, view_col);
}
@@ -364,15 +439,15 @@ void
e_cell_show_tooltip (ECellView *ecell_view, int model_col, int view_col,
int row, int col_width, ETableTooltip *tooltip)
{
- E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->show_tooltip
+ ECVIEW_EC_CLASS(ecell_view)->show_tooltip
(ecell_view, model_col, view_col, row, col_width, tooltip);
}
gchar *
e_cell_get_bg_color(ECellView *ecell_view, int row)
{
- if (E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->get_bg_color)
- return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->get_bg_color (ecell_view, row);
+ if (ECVIEW_EC_CLASS(ecell_view)->get_bg_color)
+ return ECVIEW_EC_CLASS(ecell_view)->get_bg_color (ecell_view, row);
else
return NULL;
}
diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h
index b5277d657b..135ac1aa25 100644
--- a/widgets/table/e-cell.h
+++ b/widgets/table/e-cell.h
@@ -97,6 +97,9 @@ typedef struct {
void *(*enter_edit) (ECellView *ecell_view, int model_col, int view_col, int row);
void (*leave_edit) (ECellView *ecell_view, int model_col, int view_col, int row, void *context);
+ void *(*save_state) (ECellView *ecell_view, int model_col, int view_col, int row, void *context);
+ void (*load_state) (ECellView *ecell_view, int model_col, int view_col, int row, void *context, void *save_state);
+ void (*free_state) (ECellView *ecell_view, int model_col, int view_col, int row, void *save_state);
void (*print) (ECellView *ecell_view, GnomePrintContext *context,
int model_col, int view_col, int row,
gdouble width, gdouble height);
@@ -185,6 +188,26 @@ void e_cell_leave_edit (ECellView *ecell_view,
int row,
void *edit_context);
+void *e_cell_save_state (ECellView *ecell_view,
+ int model_col,
+ int view_col,
+ int row,
+ void *edit_context);
+
+void e_cell_load_state (ECellView *ecell_view,
+ int model_col,
+ int view_col,
+ int row,
+ void *edit_context,
+ void *state);
+
+void e_cell_free_state (ECellView *ecell_view,
+ int model_col,
+ int view_col,
+ int row,
+ void *state);
+
+
END_GNOME_DECLS
#endif /* _E_CELL_H_ */
diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c
index 0d947a942f..927e0f434b 100644
--- a/widgets/table/e-table-item.c
+++ b/widgets/table/e-table-item.c
@@ -280,6 +280,20 @@ eti_get_cell_foreground_color (ETableItem *eti, int row, int col, gboolean selec
return foreground;
}
+static void
+eti_free_save_state (ETableItem *eti)
+{
+ if (eti->save_row == -1 ||
+ !eti->cell_views_realized)
+ return;
+
+ e_cell_free_state (eti->cell_views [eti->save_col], view_to_model_col(eti, eti->save_col),
+ eti->save_col, eti->save_row, eti->save_state);
+ eti->save_row = -1;
+ eti->save_col = -1;
+ eti->save_state = NULL;
+}
+
/*
* During realization, we have to invoke the per-ecell realize routine
* (On our current setup, we have one e-cell per column.
@@ -342,6 +356,8 @@ eti_unrealize_cell_views (ETableItem *eti)
if (eti->cell_views_realized == 0)
return;
+ eti_free_save_state (eti);
+
for (i = 0; i < eti->n_cells; i++)
e_cell_unrealize (eti->cell_views [i]);
eti->cell_views_realized = 0;
@@ -352,6 +368,8 @@ eti_detach_cell_views (ETableItem *eti)
{
int i;
+ eti_free_save_state (eti);
+
for (i = 0; i < eti->n_cells; i++){
e_cell_kill_view (eti->cell_views [i]);
eti->cell_views [i] = NULL;
@@ -911,7 +929,7 @@ eti_check_cursor_bounds (ETableItem *eti)
eti->cursor_y1 = -1;
eti->cursor_x2 = -1;
eti->cursor_y2 = -1;
- eti->cursor_on_screen = FALSE;
+ eti->cursor_on_screen = TRUE;
return;
}
@@ -1499,6 +1517,10 @@ eti_init (GnomeCanvasItem *item)
eti->width = 0;
eti->minimum_width = 0;
+ eti->save_col = -1;
+ eti->save_row = -1;
+ eti->save_state = NULL;
+
eti->click_count = 0;
eti->height_cache = NULL;
@@ -2689,9 +2711,26 @@ eti_event (GnomeCanvasItem *item, GdkEvent *e)
case GDK_FOCUS_CHANGE:
d(g_print("%s: GDK_FOCUS_CHANGE received, %s\n", __FUNCTION__, e->focus_change.in ? "in": "out"));
- if (! e->focus_change.in) {
- if (eti_editing (eti))
+ if (e->focus_change.in) {
+ if (eti->save_row != -1 &&
+ eti->save_col != -1 &&
+ !eti_editing (eti) &&
+ e_table_model_is_cell_editable(eti->table_model, view_to_model_col (eti, eti->save_col), eti->save_row)) {
+ e_table_item_enter_edit (eti, eti->save_col, eti->save_row);
+ e_cell_load_state (eti->cell_views [eti->editing_col], view_to_model_col(eti, eti->save_col),
+ eti->save_col, eti->save_row, eti->edit_ctx, eti->save_state);
+ eti_free_save_state (eti);
+ }
+ } else {
+ if (eti_editing (eti)) {
+ eti_free_save_state (eti);
+
+ eti->save_row = eti->editing_row;
+ eti->save_col = eti->editing_col;
+ eti->save_state = e_cell_save_state (eti->cell_views [eti->editing_col], view_to_model_col(eti, eti->editing_col),
+ eti->editing_col, eti->editing_row, eti->edit_ctx);
e_table_item_leave_edit_(eti);
+ }
}
default:
diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h
index 4956c279dd..a9f992db1e 100644
--- a/widgets/table/e-table-item.h
+++ b/widgets/table/e-table-item.h
@@ -153,6 +153,9 @@ typedef struct {
int editing_col, editing_row;
void *edit_ctx;
+ int save_col, save_row;
+ void *save_state;
+
int grabbed_col, grabbed_row;
int grabbed_count;