new function to set/unset the selectable flag of a single row.

* gtk/gtkclist.c (gtk_clist_set_selectable): new function
  to set/unset the selectable flag of a single row.
  (gtk_clist_get_selectable): new function
  to get the state of the selectable flag

* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
  (gtk_ctree_node_get_selectable): clist analogons
This commit is contained in:
Lars Hamann 1998-09-11 13:52:42 +00:00
parent 6d13f0f9b3
commit cb7c4d6c7f
11 changed files with 288 additions and 63 deletions

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1,3 +1,13 @@
Fri Sep 11 15:25:10 1998 Lars Hamann <lars@gtk.org>
* gtk/gtkclist.c (gtk_clist_set_selectable): new function
to set/unset the selectable flag of a single row.
(gtk_clist_get_selectable): new function
to get the state of the selectable flag
* gtk/gtkctree.c (gtk_ctree_node_set_selectable)
(gtk_ctree_node_get_selectable): clist analogons
Thu Sep 10 17:04:03 1998 Raph Levien <raph@gimp.org>
* gtk/testrgb.c (testrgb_rgb_test): Small changes to the test

View File

@ -1624,6 +1624,66 @@ gtk_clist_set_shift (GtkCList * clist,
GTK_CLIST_CLASS_FW (clist)->draw_row (clist, NULL, row, clist_row);
}
void
gtk_clist_set_selectable (GtkCList *clist,
gint row,
gboolean selectable)
{
GtkCListRow *clist_row;
g_return_if_fail (clist != NULL);
g_return_if_fail (GTK_IS_CLIST (clist));
if (row < 0 || row >= clist->rows)
return;
clist_row = (g_list_nth (clist->row_list, row))->data;
if (selectable == clist_row->selectable)
return;
clist_row->selectable = selectable;
if (!selectable && clist_row->state == GTK_STATE_SELECTED)
{
if (clist->anchor >= 0 &&
clist->selection_mode == GTK_SELECTION_EXTENDED)
{
if ((gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_FOCUS (clist)))
{
GTK_CLIST_UNSET_FLAG (clist, CLIST_DRAG_SELECTION);
gtk_grab_remove (GTK_WIDGET (clist));
gdk_pointer_ungrab (GDK_CURRENT_TIME);
if (clist->htimer)
{
gtk_timeout_remove (clist->htimer);
clist->htimer = 0;
}
if (clist->vtimer)
{
gtk_timeout_remove (clist->vtimer);
clist->vtimer = 0;
}
}
GTK_CLIST_CLASS_FW (clist)->resync_selection (clist, NULL);
}
unselect_row (clist, row, -1, NULL);
}
}
gboolean
gtk_clist_get_selectable (GtkCList *clist,
gint row)
{
g_return_val_if_fail (clist != NULL, FALSE);
g_return_val_if_fail (GTK_IS_CLIST (clist), FALSE);
if (row < 0 || row >= clist->rows)
return FALSE;
return GTK_CLIST_ROW (g_list_nth (clist->row_list, row))->selectable;
}
gint
gtk_clist_append (GtkCList * clist,
gchar * text[])
@ -4010,7 +4070,7 @@ real_select_row (GtkCList * clist,
clist_row = (g_list_nth (clist->row_list, row))->data;
if (clist_row->state != GTK_STATE_NORMAL)
if (clist_row->state != GTK_STATE_NORMAL || !clist_row->selectable)
return;
clist_row->state = GTK_STATE_SELECTED;
@ -4716,6 +4776,7 @@ row_new (GtkCList * clist)
clist_row->fg_set = FALSE;
clist_row->bg_set = FALSE;
clist_row->selectable = TRUE;
clist_row->state = GTK_STATE_NORMAL;
clist_row->data = NULL;
clist_row->destroy = NULL;
@ -4901,7 +4962,15 @@ gtk_clist_focus_in (GtkWidget *widget,
if (clist->selection_mode == GTK_SELECTION_BROWSE &&
clist->selection == NULL && clist->focus_row > -1)
select_row (clist, clist->focus_row, -1, (GdkEvent *) event);
{
GList *list;
list = g_list_nth (clist->row_list, clist->focus_row);
if (list && GTK_CLIST_ROW (list)->selectable)
select_row (clist, clist->focus_row, -1, (GdkEvent *) event);
else
gtk_widget_draw_focus (widget);
}
else
gtk_widget_draw_focus (widget);
@ -4970,10 +5039,8 @@ toggle_focus_row (GtkCList *clist)
{
case GTK_SELECTION_SINGLE:
case GTK_SELECTION_MULTIPLE:
toggle_row (clist, clist->focus_row, 0, NULL);
break;
case GTK_SELECTION_EXTENDED:
g_list_free (clist->undo_selection);
g_list_free (clist->undo_unselection);
@ -4991,7 +5058,6 @@ toggle_focus_row (GtkCList *clist)
GTK_CLIST_CLASS_FW (clist)->resync_selection (clist, NULL);
break;
default:
break;
}
@ -5267,7 +5333,6 @@ resync_selection (GtkCList *clist,
if (clist->undo_selection)
{
list = clist->selection;
clist->selection = clist->undo_selection;
clist->selection_end = g_list_last (clist->selection);
@ -5280,30 +5345,36 @@ resync_selection (GtkCList *clist,
if (row < i || row > e)
{
clist_row = g_list_nth (clist->row_list, row)->data;
clist_row->state = GTK_STATE_SELECTED;
unselect_row (clist, row, -1, event);
clist->undo_selection = g_list_prepend
(clist->undo_selection, GINT_TO_POINTER (row));
if (clist_row->selectable)
{
clist_row->state = GTK_STATE_SELECTED;
unselect_row (clist, row, -1, event);
clist->undo_selection = g_list_prepend
(clist->undo_selection, GINT_TO_POINTER (row));
}
}
}
}
for (list = g_list_nth (clist->row_list, i); i <= e; i++, list = list->next)
if (g_list_find (clist->selection, GINT_TO_POINTER(i)))
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;
unselect_row (clist, 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;
unselect_row (clist, 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)
{
GTK_CLIST_ROW (list)->state = GTK_STATE_NORMAL;
clist->undo_unselection = g_list_prepend (clist->undo_unselection,
GINT_TO_POINTER (i));
}
for (list = clist->undo_unselection; list; list = list->next)
@ -5397,12 +5468,13 @@ update_extended_selection (GtkCList *clist,
{
for (i = s1, list = g_list_nth (clist->row_list, i); i <= e1;
i++, list = list->next)
{
if (GTK_CLIST_CLASS_FW (clist)->selection_find (clist, i, list))
GTK_CLIST_ROW (list)->state = GTK_STATE_SELECTED;
else
GTK_CLIST_ROW (list)->state = GTK_STATE_NORMAL;
}
if (GTK_CLIST_ROW (list)->selectable)
{
if (GTK_CLIST_CLASS_FW (clist)->selection_find (clist, i, list))
GTK_CLIST_ROW (list)->state = GTK_STATE_SELECTED;
else
GTK_CLIST_ROW (list)->state = GTK_STATE_NORMAL;
}
top = ROW_TOP_YPIXEL (clist, clist->focus_row);
@ -5434,7 +5506,8 @@ update_extended_selection (GtkCList *clist,
{
for (i = s2, list = g_list_nth (clist->row_list, i); i <= e2;
i++, list = list->next)
if (GTK_CLIST_ROW (list)->state != clist->anchor_state)
if (GTK_CLIST_ROW (list)->selectable &&
GTK_CLIST_ROW (list)->state != clist->anchor_state)
GTK_CLIST_ROW (list)->state = clist->anchor_state;
top = ROW_TOP_YPIXEL (clist, clist->focus_row);
@ -5459,7 +5532,7 @@ update_extended_selection (GtkCList *clist,
gtk_clist_moveto (clist, clist->focus_row, -1, 1, 0);
y2 = ROW_TOP_YPIXEL (clist, s2);
h2 = (e2-s2+1) * (clist->row_height + CELL_SPACING);
h2 = (e2 - s2 + 1) * (clist->row_height + CELL_SPACING);
}
area.y = MAX (0, MIN (y1, y2));
@ -5947,7 +6020,8 @@ fake_unselect_all (GtkCList * clist,
if (row >= 0 && (work = g_list_nth (clist->row_list, row)))
{
if (GTK_CLIST_ROW (work)->state == GTK_STATE_NORMAL)
if (GTK_CLIST_ROW (work)->state == GTK_STATE_NORMAL &&
GTK_CLIST_ROW (work)->selectable)
{
GTK_CLIST_ROW (work)->state = GTK_STATE_SELECTED;
@ -5982,7 +6056,8 @@ fake_toggle_row (GtkCList *clist,
{
GList *work;
if (!(work = g_list_nth (clist->row_list, row)))
if (!(work = g_list_nth (clist->row_list, row))||
!GTK_CLIST_ROW (work)->selectable)
return;
if (GTK_CLIST_ROW (work)->state == GTK_STATE_NORMAL)

View File

@ -275,8 +275,9 @@ struct _GtkCListRow
gpointer data;
GtkDestroyNotify destroy;
gint fg_set : 1;
gint bg_set : 1;
gint fg_set : 1;
gint bg_set : 1;
gint selectable : 1;
};
/* Cell Structures */
@ -518,6 +519,13 @@ void gtk_clist_set_shift (GtkCList *clist,
gint vertical,
gint horizontal);
/* set/get selectable flag of a single row */
void gtk_clist_set_selectable (GtkCList *clist,
gint row,
gboolean selectable);
gboolean gtk_clist_get_selectable (GtkCList *clist,
gint row);
/* append returns the index of the row you just added, making
* it easier to append and modify a row
*/

View File

@ -3239,7 +3239,8 @@ tree_select (GtkCTree *ctree,
GtkCTreeNode *node,
gpointer data)
{
if (node && GTK_CTREE_ROW (node)->row.state != GTK_STATE_SELECTED)
if (node && GTK_CTREE_ROW (node)->row.state != GTK_STATE_SELECTED &&
GTK_CTREE_ROW (node)->row.selectable)
gtk_signal_emit (GTK_OBJECT (ctree), ctree_signals[TREE_SELECT_ROW],
node, -1);
}
@ -3315,11 +3316,12 @@ row_new (GtkCTree *ctree)
GTK_CELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
ctree_row->row.fg_set = FALSE;
ctree_row->row.bg_set = FALSE;
ctree_row->row.state = GTK_STATE_NORMAL;
ctree_row->row.data = NULL;
ctree_row->row.destroy = NULL;
ctree_row->row.fg_set = FALSE;
ctree_row->row.bg_set = FALSE;
ctree_row->row.selectable = TRUE;
ctree_row->row.state = GTK_STATE_NORMAL;
ctree_row->row.data = NULL;
ctree_row->row.destroy = NULL;
ctree_row->level = 0;
ctree_row->expanded = FALSE;
@ -3379,7 +3381,8 @@ real_select_row (GtkCList *clist,
g_return_if_fail (clist != NULL);
g_return_if_fail (GTK_IS_CTREE (clist));
if ((node = g_list_nth (clist->row_list, row)))
if ((node = g_list_nth (clist->row_list, row)) &&
GTK_CTREE_ROW (node)->row.selectable)
gtk_signal_emit (GTK_OBJECT (clist), ctree_signals[TREE_SELECT_ROW],
node, column);
}
@ -3413,7 +3416,8 @@ real_tree_select (GtkCTree *ctree,
g_return_if_fail (ctree != NULL);
g_return_if_fail (GTK_IS_CTREE (ctree));
if (!node || GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED)
if (!node || GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED ||
!GTK_CTREE_ROW (node)->row.selectable)
return;
clist = GTK_CLIST (ctree);
@ -3502,13 +3506,14 @@ tree_toggle_selection (GtkCTree *ctree,
if (node && GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED)
gtk_signal_emit (GTK_OBJECT (ctree), ctree_signals[TREE_UNSELECT_ROW],
node, column);
else if (node)
else if (node && GTK_CTREE_ROW (node)->row.selectable)
gtk_signal_emit (GTK_OBJECT (ctree), ctree_signals[TREE_SELECT_ROW],
node, column);
break;
case GTK_SELECTION_BROWSE:
if (node && GTK_CTREE_ROW (node)->row.state == GTK_STATE_NORMAL)
if (node && GTK_CTREE_ROW (node)->row.state == GTK_STATE_NORMAL &&
GTK_CTREE_ROW (node)->row.selectable)
gtk_signal_emit (GTK_OBJECT (ctree), ctree_signals[TREE_SELECT_ROW],
node, column);
break;
@ -3523,7 +3528,8 @@ select_row_recursive (GtkCTree *ctree,
GtkCTreeNode *node,
gpointer data)
{
if (!node || GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED)
if (!node || GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED ||
!GTK_CTREE_ROW (node)->row.selectable)
return;
GTK_CLIST (ctree)->undo_unselection =
@ -4553,8 +4559,9 @@ gtk_ctree_select (GtkCTree *ctree,
g_return_if_fail (GTK_IS_CTREE (ctree));
g_return_if_fail (node != NULL);
gtk_signal_emit (GTK_OBJECT (ctree), ctree_signals[TREE_SELECT_ROW],
node, -1);
if (GTK_CTREE_ROW (node)->row.selectable)
gtk_signal_emit (GTK_OBJECT (ctree), ctree_signals[TREE_SELECT_ROW],
node, -1);
}
void
@ -4799,6 +4806,60 @@ gtk_ctree_node_set_shift (GtkCTree *ctree,
tree_draw_node (ctree, node);
}
void
gtk_ctree_node_set_selectable (GtkCTree *ctree,
GtkCTreeNode *node,
gboolean selectable)
{
g_return_if_fail (ctree != NULL);
g_return_if_fail (GTK_IS_CTREE (ctree));
g_return_if_fail (node != NULL);
if (selectable == GTK_CTREE_ROW (node)->row.selectable)
return;
GTK_CTREE_ROW (node)->row.selectable = selectable;
if (!selectable && GTK_CTREE_ROW (node)->row.state == GTK_STATE_SELECTED)
{
GtkCList *clist;
clist = GTK_CLIST (ctree);
if (clist->anchor >= 0 &&
clist->selection_mode == GTK_SELECTION_EXTENDED)
{
if ((gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_FOCUS (clist)))
{
GTK_CLIST_UNSET_FLAG (clist, CLIST_DRAG_SELECTION);
gtk_grab_remove (GTK_WIDGET (clist));
gdk_pointer_ungrab (GDK_CURRENT_TIME);
if (clist->htimer)
{
gtk_timeout_remove (clist->htimer);
clist->htimer = 0;
}
if (clist->vtimer)
{
gtk_timeout_remove (clist->vtimer);
clist->vtimer = 0;
}
}
GTK_CLIST_CLASS_FW (clist)->resync_selection (clist, NULL);
}
gtk_ctree_unselect (ctree, node);
}
}
gboolean
gtk_ctree_node_get_selectable (GtkCTree *ctree,
GtkCTreeNode *node)
{
g_return_val_if_fail (node != NULL, FALSE);
return GTK_CTREE_ROW (node)->row.selectable;
}
GtkCellType
gtk_ctree_node_get_cell_type (GtkCTree *ctree,
GtkCTreeNode *node,
@ -5327,7 +5388,8 @@ fake_unselect_all (GtkCList *clist,
if (row >= 0 && (focus_node = g_list_nth (clist->row_list, row)))
{
if (GTK_CTREE_ROW (focus_node)->row.state == GTK_STATE_NORMAL)
if (GTK_CTREE_ROW (focus_node)->row.state == GTK_STATE_NORMAL &&
GTK_CTREE_ROW (focus_node)->row.selectable)
{
GTK_CTREE_ROW (focus_node)->row.state = GTK_STATE_SELECTED;
@ -5410,7 +5472,7 @@ resync_selection (GtkCList *clist, GdkEvent *event)
if (row >= i && row <= e)
unselect = FALSE;
}
if (unselect)
if (unselect && GTK_CTREE_ROW (node)->row.selectable)
{
GTK_CTREE_ROW (node)->row.state = GTK_STATE_SELECTED;
gtk_ctree_unselect (ctree, node);
@ -5423,21 +5485,24 @@ 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 (g_list_find (clist->selection, 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)
{
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)
@ -5471,10 +5536,12 @@ real_undo_selection (GtkCList *clist)
ctree = GTK_CTREE (clist);
for (work = clist->undo_selection; work; work = work->next)
gtk_ctree_select (ctree, GTK_CTREE_NODE (work->data));
if (GTK_CTREE_ROW (work->data)->row.selectable)
gtk_ctree_select (ctree, GTK_CTREE_NODE (work->data));
for (work = clist->undo_unselection; work; work = work->next)
gtk_ctree_unselect (ctree, GTK_CTREE_NODE (work->data));
if (GTK_CTREE_ROW (work->data)->row.selectable)
gtk_ctree_unselect (ctree, GTK_CTREE_NODE (work->data));
if (GTK_WIDGET_HAS_FOCUS (clist) && clist->focus_row != clist->undo_anchor)
{

View File

@ -321,6 +321,11 @@ void gtk_ctree_node_set_shift (GtkCTree *ctree,
gint column,
gint vertical,
gint horizontal);
void gtk_ctree_node_set_selectable (GtkCTree *ctree,
GtkCTreeNode *node,
gboolean selectable);
gboolean gtk_ctree_node_get_selectable (GtkCTree *ctree,
GtkCTreeNode *node);
GtkCellType gtk_ctree_node_get_cell_type (GtkCTree *ctree,
GtkCTreeNode *node,
gint column);