From a19e373baa6545c104fee06b572f795591fec81a Mon Sep 17 00:00:00 2001 From: Lars Hamann Date: Tue, 2 Feb 1999 01:57:11 +0000 Subject: [PATCH] in case of GTK_SELECTION_BROWSE select first inserted row. Tue Feb 2 00:28:44 1999 Lars Hamann * gtk/gtkctree.c (gtk_ctree_insert_node): in case of GTK_SELECTION_BROWSE select first inserted row. (resync_selection): select rows in correct order. * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE select first inserted row. (resync_selection): select rows in correct order. * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. --- ChangeLog | 12 ++++++++ ChangeLog.pre-2-0 | 12 ++++++++ ChangeLog.pre-2-10 | 12 ++++++++ ChangeLog.pre-2-2 | 12 ++++++++ ChangeLog.pre-2-4 | 12 ++++++++ ChangeLog.pre-2-6 | 12 ++++++++ ChangeLog.pre-2-8 | 12 ++++++++ gtk/gtkclist.c | 77 ++++++++++++++++++++++++++++++++++++---------- gtk/gtkctree.c | 69 +++++++++++++++++++++++++++++++---------- gtk/gtklist.c | 70 +++++++++++++++++++++++++++++------------ 10 files changed, 247 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index a849596cc5..4fc06a9709 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index a849596cc5..4fc06a9709 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a849596cc5..4fc06a9709 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index a849596cc5..4fc06a9709 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index a849596cc5..4fc06a9709 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index a849596cc5..4fc06a9709 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a849596cc5..4fc06a9709 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +Tue Feb 2 00:28:44 1999 Lars Hamann + + * gtk/gtkctree.c (gtk_ctree_insert_node): in case of + GTK_SELECTION_BROWSE select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtkclist.c (real_insert_row): in case of GTK_SELECTION_BROWSE + select first inserted row. + (resync_selection): select rows in correct order. + + * gtk/gtklist.c (gtk_list_end_selection): select rows in correct order. + Mon Feb 1 16:47:55 1999 Owen Taylor * gtk.m4: Pass gthread on to gtk-config. diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c index fe7515bffe..327f873e98 100644 --- a/gtk/gtkclist.c +++ b/gtk/gtkclist.c @@ -2782,8 +2782,8 @@ real_insert_row (GtkCList *clist, clist_row))->next; else clist->row_list = g_list_insert (clist->row_list, clist_row, row); + } - clist->rows++; if (row < ROW_FROM_YPIXEL (clist, 0)) @@ -2792,6 +2792,13 @@ real_insert_row (GtkCList *clist, /* syncronize the selection list */ sync_selection (clist, row, SYNC_INSERT); + if (clist->rows == 1) + { + clist->focus_row = 0; + if (clist->selection_mode == GTK_SELECTION_BROWSE) + gtk_clist_select_row (clist, 0, -1); + } + /* redraw the list if it isn't frozen */ if (CLIST_UNFROZEN (clist)) { @@ -3989,29 +3996,65 @@ resync_selection (GtkCList *clist, } } - for (list = g_list_nth (clist->row_list, i); i <= e; i++, list = list->next) - if (GTK_CLIST_ROW (list)->selectable) - { - if (g_list_find (clist->selection, GINT_TO_POINTER(i))) + if (clist->anchor < clist->drag_pos) + { + for (list = g_list_nth (clist->row_list, i); i <= e; + i++, list = list->next) + if (GTK_CLIST_ROW (list)->selectable) { - if (GTK_CLIST_ROW (list)->state == GTK_STATE_NORMAL) + if (g_list_find (clist->selection, GINT_TO_POINTER(i))) { - GTK_CLIST_ROW (list)->state = GTK_STATE_SELECTED; - gtk_signal_emit (GTK_OBJECT (clist), - clist_signals[UNSELECT_ROW], i, -1, event); - clist->undo_selection = g_list_prepend (clist->undo_selection, - GINT_TO_POINTER (i)); + if (GTK_CLIST_ROW (list)->state == GTK_STATE_NORMAL) + { + GTK_CLIST_ROW (list)->state = GTK_STATE_SELECTED; + gtk_signal_emit (GTK_OBJECT (clist), + clist_signals[UNSELECT_ROW], + i, -1, event); + clist->undo_selection = + g_list_prepend (clist->undo_selection, + GINT_TO_POINTER (i)); + } + } + else if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) + { + GTK_CLIST_ROW (list)->state = GTK_STATE_NORMAL; + clist->undo_unselection = + g_list_prepend (clist->undo_unselection, + GINT_TO_POINTER (i)); } } - else if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) + } + else + { + for (list = g_list_nth (clist->row_list, e); i <= e; + e--, list = list->prev) + if (GTK_CLIST_ROW (list)->selectable) { - GTK_CLIST_ROW (list)->state = GTK_STATE_NORMAL; - clist->undo_unselection = g_list_prepend (clist->undo_unselection, - GINT_TO_POINTER (i)); + if (g_list_find (clist->selection, GINT_TO_POINTER(e))) + { + if (GTK_CLIST_ROW (list)->state == GTK_STATE_NORMAL) + { + GTK_CLIST_ROW (list)->state = GTK_STATE_SELECTED; + gtk_signal_emit (GTK_OBJECT (clist), + clist_signals[UNSELECT_ROW], + e, -1, event); + clist->undo_selection = + g_list_prepend (clist->undo_selection, + GINT_TO_POINTER (e)); + } + } + else if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) + { + GTK_CLIST_ROW (list)->state = GTK_STATE_NORMAL; + clist->undo_unselection = + g_list_prepend (clist->undo_unselection, + GINT_TO_POINTER (e)); + } } - } + } - for (list = clist->undo_unselection; list; list = list->next) + for (list = g_list_reverse (clist->undo_unselection); list; + list = list->next) gtk_signal_emit (GTK_OBJECT (clist), clist_signals[SELECT_ROW], GPOINTER_TO_INT (list->data), -1, event); diff --git a/gtk/gtkctree.c b/gtk/gtkctree.c index 9b855a6079..da4b2c6610 100644 --- a/gtk/gtkctree.c +++ b/gtk/gtkctree.c @@ -3684,6 +3684,14 @@ gtk_ctree_insert_node (GtkCTree *ctree, column_auto_resize (clist, &(new_row->row), i, 0); } + if (clist->rows == 1) + { + clist->focus_row = 0; + if (clist->selection_mode == GTK_SELECTION_BROWSE) + gtk_ctree_select (ctree, node); + } + + CLIST_REFRESH (clist); return node; @@ -5664,30 +5672,57 @@ resync_selection (GtkCList *clist, GdkEvent *event) } } - - for (node = GTK_CTREE_NODE (g_list_nth (clist->row_list, i)); i <= e; - i++, node = GTK_CTREE_NODE_NEXT (node)) - if (GTK_CTREE_ROW (node)->row.selectable) - { - if (g_list_find (clist->selection, node)) + if (clist->anchor < clist->drag_pos) + { + for (node = GTK_CTREE_NODE (g_list_nth (clist->row_list, i)); i <= e; + i++, node = GTK_CTREE_NODE_NEXT (node)) + if (GTK_CTREE_ROW (node)->row.selectable) { - if (GTK_CTREE_ROW (node)->row.state == GTK_STATE_NORMAL) + if (g_list_find (clist->selection, node)) { - GTK_CTREE_ROW (node)->row.state = GTK_STATE_SELECTED; - gtk_ctree_unselect (ctree, node); - clist->undo_selection = g_list_prepend (clist->undo_selection, - node); + if (GTK_CTREE_ROW (node)->row.state == GTK_STATE_NORMAL) + { + GTK_CTREE_ROW (node)->row.state = GTK_STATE_SELECTED; + gtk_ctree_unselect (ctree, node); + clist->undo_selection = + g_list_prepend (clist->undo_selection, node); + } + } + else if (GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED) + { + GTK_CTREE_ROW (node)->row.state = GTK_STATE_NORMAL; + clist->undo_unselection = + g_list_prepend (clist->undo_unselection, node); } } - else if (GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED) + } + else + { + for (node = GTK_CTREE_NODE (g_list_nth (clist->row_list, e)); i <= e; + e--, node = GTK_CTREE_NODE_PREV (node)) + if (GTK_CTREE_ROW (node)->row.selectable) { - GTK_CTREE_ROW (node)->row.state = GTK_STATE_NORMAL; - clist->undo_unselection = g_list_prepend (clist->undo_unselection, - node); + if (g_list_find (clist->selection, node)) + { + if (GTK_CTREE_ROW (node)->row.state == GTK_STATE_NORMAL) + { + GTK_CTREE_ROW (node)->row.state = GTK_STATE_SELECTED; + gtk_ctree_unselect (ctree, node); + clist->undo_selection = + g_list_prepend (clist->undo_selection, node); + } + } + else if (GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED) + { + GTK_CTREE_ROW (node)->row.state = GTK_STATE_NORMAL; + clist->undo_unselection = + g_list_prepend (clist->undo_unselection, node); + } } - } + } - for (list = clist->undo_unselection; list; list = list->next) + for (list = g_list_reverse (clist->undo_unselection); list; + list = list->next) gtk_ctree_select (ctree, list->data); clist->anchor = -1; diff --git a/gtk/gtklist.c b/gtk/gtklist.c index 1f59758a92..c18431d4be 100644 --- a/gtk/gtklist.c +++ b/gtk/gtklist.c @@ -1690,6 +1690,7 @@ gtk_list_end_selection (GtkList *list) { gint i; gint e; + gboolean top_down; GList *work; GtkWidget *item; gint item_index; @@ -1703,10 +1704,12 @@ gtk_list_end_selection (GtkList *list) i = MIN (list->anchor, list->drag_pos); e = MAX (list->anchor, list->drag_pos); - + + top_down = (list->anchor < list->drag_pos); + list->anchor = -1; list->drag_pos = -1; - + if (list->undo_selection) { work = list->selection; @@ -1728,30 +1731,59 @@ gtk_list_end_selection (GtkList *list) } } - for (work = g_list_nth (list->children, i); i <= e; i++, work = work->next) + if (top_down) { - item = work->data; - if (g_list_find (list->selection, item)) - { - if (item->state == GTK_STATE_NORMAL) - { - gtk_widget_set_state (item, GTK_STATE_SELECTED); - gtk_list_unselect_child (list, item); - list->undo_selection = g_list_prepend (list->undo_selection, - item); - } - } - else if (item->state == GTK_STATE_SELECTED) + for (work = g_list_nth (list->children, i); i <= e; + i++, work = work->next) { - gtk_widget_set_state (item, GTK_STATE_NORMAL); - list->undo_unselection = g_list_prepend (list->undo_unselection, - item); + item = work->data; + if (g_list_find (list->selection, item)) + { + if (item->state == GTK_STATE_NORMAL) + { + gtk_widget_set_state (item, GTK_STATE_SELECTED); + gtk_list_unselect_child (list, item); + list->undo_selection = g_list_prepend (list->undo_selection, + item); + } + } + else if (item->state == GTK_STATE_SELECTED) + { + gtk_widget_set_state (item, GTK_STATE_NORMAL); + list->undo_unselection = g_list_prepend (list->undo_unselection, + item); + } + } + } + else + { + for (work = g_list_nth (list->children, e); i <= e; + e--, work = work->prev) + { + item = work->data; + if (g_list_find (list->selection, item)) + { + if (item->state == GTK_STATE_NORMAL) + { + gtk_widget_set_state (item, GTK_STATE_SELECTED); + gtk_list_unselect_child (list, item); + list->undo_selection = g_list_prepend (list->undo_selection, + item); + } + } + else if (item->state == GTK_STATE_SELECTED) + { + gtk_widget_set_state (item, GTK_STATE_NORMAL); + list->undo_unselection = g_list_prepend (list->undo_unselection, + item); + } } } - for (work = list->undo_unselection; work; work = work->next) + for (work = g_list_reverse (list->undo_unselection); work; work = work->next) gtk_list_select_child (list, GTK_WIDGET (work->data)); + } void