From 5fa7ce6c09fe6ae8553e6c74281707144f1e7c8b Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 1 Mar 2001 08:32:16 +0000 Subject: Added e-selection-model-simple.lo. 2001-03-01 Christopher James Lahey * gal/Makefile.am (libgal_la_LIBADD): Added e-selection-model-simple.lo. * gal/widgets/Makefile.am (libwidgets_la_SOURCES): Added e-selection-model-simple.c. (libwidgetsinclude_HEADERS): Added e-selection-model-simple.h. * gal/widgets/e-reflow-sorted.c, gal/widgets/e-reflow-sorted.h: Added a gint *position argument to e_reflow_sorted_remove_item and e_reflow_sorted_get_item and two gint * arguments to e_reflow_sorted_replace_item and e_reflow_sorted_reorder_item to return the positions in the array of the items removed, gotten, or moved. * gal/widgets/e-reflow.c, gal/widgets/e-reflow.h: Added a gint *position argument to e_reflow_sorted_add_item to return the positions in the array of the item added. * gal/widgets/e-selection-model.c, gal/widgets/e-selection-model.h: Added e_selection_model_move_row. svn path=/trunk/; revision=8442 --- widgets/misc/e-reflow.c | 31 ++++++++++---------- widgets/misc/e-reflow.h | 11 ++++--- widgets/misc/e-selection-model.c | 62 ++++++++++++++++++++++++++++++++++------ widgets/misc/e-selection-model.h | 6 ++++ 4 files changed, 83 insertions(+), 27 deletions(-) (limited to 'widgets/misc') diff --git a/widgets/misc/e-reflow.c b/widgets/misc/e-reflow.c index 88e9dc590a..735d965120 100644 --- a/widgets/misc/e-reflow.c +++ b/widgets/misc/e-reflow.c @@ -42,7 +42,7 @@ static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, static void e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags); static double e_reflow_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item); static void e_reflow_reflow (GnomeCanvasItem *item, int flags); -static void e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +static void e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item, gint *position); static void set_empty(EReflow *e_reflow); static void e_reflow_resize_children (GnomeCanvasItem *item); @@ -109,17 +109,17 @@ e_reflow_class_init (EReflowClass *klass) klass->add_item = e_reflow_real_add_item; - object_class->set_arg = e_reflow_set_arg; - object_class->get_arg = e_reflow_get_arg; - object_class->destroy = e_reflow_destroy; + object_class->set_arg = e_reflow_set_arg; + object_class->get_arg = e_reflow_get_arg; + object_class->destroy = e_reflow_destroy; /* GnomeCanvasItem method overrides */ - item_class->event = e_reflow_event; - item_class->realize = e_reflow_realize; - item_class->unrealize = e_reflow_unrealize; - item_class->draw = e_reflow_draw; - item_class->update = e_reflow_update; - item_class->point = e_reflow_point; + item_class->event = e_reflow_event; + item_class->realize = e_reflow_realize; + item_class->unrealize = e_reflow_unrealize; + item_class->draw = e_reflow_draw; + item_class->update = e_reflow_update; + item_class->point = e_reflow_point; } static void @@ -481,18 +481,19 @@ e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) } static void -e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item, gint *position) { e_reflow->items = g_list_append(e_reflow->items, item); gtk_object_ref(GTK_OBJECT(item)); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + if (GTK_OBJECT_FLAGS (e_reflow) & GNOME_CANVAS_ITEM_REALIZED) { gnome_canvas_item_set(item, "width", (double) e_reflow->column_width, NULL); e_reflow_post_add_item(e_reflow, item); e_canvas_item_request_reflow(item); } - + if (position) + *position = g_list_index(e_reflow->items, item); } static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, @@ -847,10 +848,10 @@ e_reflow_reflow( GnomeCanvasItem *item, int flags ) } void -e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item, gint *position) { if (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) - (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) (e_reflow, item); + (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) (e_reflow, item, position); } void diff --git a/widgets/misc/e-reflow.h b/widgets/misc/e-reflow.h index eb66b094a5..b4c1dcb372 100644 --- a/widgets/misc/e-reflow.h +++ b/widgets/misc/e-reflow.h @@ -89,7 +89,7 @@ struct _EReflowClass GnomeCanvasGroupClass parent_class; /* Virtual methods. */ - void (* add_item) (EReflow *reflow, GnomeCanvasItem *item); + void (* add_item) (EReflow *reflow, GnomeCanvasItem *item, gint *position); }; /* @@ -98,11 +98,14 @@ struct _EReflowClass * should also do an ECanvas parent reflow request if its size * changes. */ -void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -GtkType e_reflow_get_type (void); +void e_reflow_add_item (EReflow *e_reflow, + GnomeCanvasItem *item, + gint *position); +GtkType e_reflow_get_type (void); /* Internal usage only: */ -void e_reflow_post_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +void e_reflow_post_add_item (EReflow *e_reflow, + GnomeCanvasItem *item); #ifdef __cplusplus } diff --git a/widgets/misc/e-selection-model.c b/widgets/misc/e-selection-model.c index e1f558f1e0..de48bc3952 100644 --- a/widgets/misc/e-selection-model.c +++ b/widgets/misc/e-selection-model.c @@ -27,6 +27,7 @@ static GtkObjectClass *e_selection_model_parent_class; +static void change_one_row(ESelectionModel *selection, int row, gboolean grow); static void esm_select_single_row (ESelectionModel *selection, int row); enum { @@ -47,8 +48,8 @@ enum { ARG_CURSOR_MODE, }; -void -e_selection_model_insert_row(ESelectionModel *esm, int row) +static void +e_selection_model_insert_row_real(ESelectionModel *esm, int row) { int box; int i; @@ -74,8 +75,8 @@ e_selection_model_insert_row(ESelectionModel *esm, int row) esm->cursor_row ++; } -void -e_selection_model_delete_row(ESelectionModel *esm, int row) +static void +e_selection_model_delete_row_real(ESelectionModel *esm, int row) { int box; int i; @@ -115,6 +116,51 @@ e_selection_model_delete_row(ESelectionModel *esm, int row) esm->cursor_row --; } +void +e_selection_model_delete_row(ESelectionModel *esm, int row) +{ + e_selection_model_delete_row_real(esm, row); + gtk_signal_emit(GTK_OBJECT(esm), + e_selection_model_signals [SELECTION_CHANGED]); + gtk_signal_emit(GTK_OBJECT(esm), + e_selection_model_signals [CURSOR_CHANGED], esm->cursor_row, esm->cursor_col); +} + +void +e_selection_model_insert_row(ESelectionModel *esm, int row) +{ + e_selection_model_insert_row_real(esm, row); + gtk_signal_emit(GTK_OBJECT(esm), + e_selection_model_signals [SELECTION_CHANGED]); + gtk_signal_emit(GTK_OBJECT(esm), + e_selection_model_signals [CURSOR_CHANGED], esm->cursor_row, esm->cursor_col); +} + +/* FIXME: Implement this more efficiently. */ +void +e_selection_model_move_row(ESelectionModel *esm, int old_row, int new_row) +{ + gint selected = e_selection_model_is_row_selected(esm, old_row); + gint cursor = esm->cursor_row == old_row; + + e_selection_model_delete_row_real(esm, old_row); + e_selection_model_insert_row_real(esm, new_row); + + if (selected) { + if (esm->mode == GTK_SELECTION_SINGLE) + esm_select_single_row (esm, new_row); + else + change_one_row(esm, new_row, TRUE); + } + if (cursor) { + esm->cursor_row = new_row; + } + gtk_signal_emit(GTK_OBJECT(esm), + e_selection_model_signals [SELECTION_CHANGED]); + gtk_signal_emit(GTK_OBJECT(esm), + e_selection_model_signals [CURSOR_CHANGED], esm->cursor_row, esm->cursor_col); +} + inline static void add_sorter(ESelectionModel *esm, ESorter *sorter) { @@ -288,7 +334,7 @@ gboolean e_selection_model_is_row_selected (ESelectionModel *selection, gint n) { - if (selection->row_count < n) + if (selection->row_count < n || selection->row_count == 0) return 0; else return (selection->selection[BOX(n)] >> OFFSET(n)) & 0x1; @@ -451,9 +497,9 @@ esm_set_selection_end (ESelectionModel *selection, int row) */ void e_selection_model_do_something (ESelectionModel *selection, - guint row, - guint col, - GdkModifierType state) + guint row, + guint col, + GdkModifierType state) { gint shift_p = state & GDK_SHIFT_MASK; gint ctrl_p = state & GDK_CONTROL_MASK; diff --git a/widgets/misc/e-selection-model.h b/widgets/misc/e-selection-model.h index 564a3e6e50..74cbcb50d2 100644 --- a/widgets/misc/e-selection-model.h +++ b/widgets/misc/e-selection-model.h @@ -65,6 +65,7 @@ typedef struct { } ESelectionModelClass; GtkType e_selection_model_get_type (void); + gboolean e_selection_model_is_row_selected (ESelectionModel *selection, gint n); void e_selection_model_foreach (ESelectionModel *selection, @@ -84,10 +85,15 @@ void e_selection_model_clear (ESelectionModel *selection); gint e_selection_model_selected_count (ESelectionModel *selection); void e_selection_model_select_all (ESelectionModel *selection); void e_selection_model_invert_selection (ESelectionModel *selection); + +/* Private Functions */ void e_selection_model_insert_row (ESelectionModel *esm, int row); void e_selection_model_delete_row (ESelectionModel *esm, int row); +void e_selection_model_move_row (ESelectionModel *esm, + int old_row, + int new_row); /* Virtual Function */ gint e_selection_model_get_row_count (ESelectionModel *esm); -- cgit