Commit 0543c806 authored by Lars Hamann's avatar Lars Hamann Committed by Lars Hamann
Browse files

only call grab_add if pointer_grab succeeds. (gtk_list_unmap): remove

Tue Jan 19 22:15:10 1999  Lars Hamann  <lars@gtk.org>

	* gtk/gtklist.c
	(gtk_list_button_press):  only call grab_add if pointer_grab succeeds.
	(gtk_list_unmap): remove pointer/widget grabs if needed.
	(gtk_list_signal_focus_lost): removed.
	(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
	(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
 	undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
 	select a new item if selection is empty.
parent 17127d2c
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
Tue Jan 19 22:15:10 1999 Lars Hamann <lars@gtk.org>
* gtk/gtklist.c
(gtk_list_button_press): only call grab_add if pointer_grab succeeds.
(gtk_list_unmap): remove pointer/widget grabs if needed.
(gtk_list_signal_focus_lost): removed.
(gtk_list_focus) (gtk_list_set_focus_child): set last_focus_child.
(gtk_list_remove_items_internal) (gtk_list_clear_items): unset
undo_focus_child if necessary. In case of SELECTION_BROWSE/EXTENDED
select a new item if selection is empty.
Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org> Tue Jan 19 00:21:15 1999 Tim Janik <timj@gtk.org>
* gtk/gtkcompat.h: add compatibility define for * gtk/gtkcompat.h: add compatibility define for
......
...@@ -101,14 +101,12 @@ static void gtk_list_fake_toggle_row (GtkList *list, ...@@ -101,14 +101,12 @@ static void gtk_list_fake_toggle_row (GtkList *list,
GtkWidget *item); GtkWidget *item);
static void gtk_list_update_extended_selection (GtkList *list, static void gtk_list_update_extended_selection (GtkList *list,
gint row); gint row);
static void gtk_list_reset_extended_selection (GtkList *list);
/** GtkListItem Signal Functions **/ /** GtkListItem Signal Functions **/
static void gtk_list_signal_drag_begin (GtkWidget *widget, static void gtk_list_signal_drag_begin (GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
GtkList *list); GtkList *list);
static void gtk_list_signal_focus_lost (GtkWidget *item,
GdkEventKey *event,
GtkList *list);
static void gtk_list_signal_toggle_focus_row (GtkListItem *list_item, static void gtk_list_signal_toggle_focus_row (GtkListItem *list_item,
GtkList *list); GtkList *list);
static void gtk_list_signal_select_all (GtkListItem *list_item, static void gtk_list_signal_select_all (GtkListItem *list_item,
...@@ -452,10 +450,26 @@ gtk_list_map (GtkWidget *widget) ...@@ -452,10 +450,26 @@ gtk_list_map (GtkWidget *widget)
static void static void
gtk_list_unmap (GtkWidget *widget) gtk_list_unmap (GtkWidget *widget)
{ {
GtkList *list;
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_LIST (widget)); g_return_if_fail (GTK_IS_LIST (widget));
if (!GTK_WIDGET_MAPPED (widget))
return;
list = GTK_LIST (widget);
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (list))
{
gtk_list_end_drag_selection (list);
if (list->anchor != -1 && list->selection_mode == GTK_SELECTION_EXTENDED)
gtk_list_end_selection (list);
}
gdk_window_hide (widget->window); gdk_window_hide (widget->window);
} }
...@@ -593,13 +607,15 @@ gtk_list_button_press (GtkWidget *widget, ...@@ -593,13 +607,15 @@ gtk_list_button_press (GtkWidget *widget,
if (event->type == GDK_BUTTON_PRESS) if (event->type == GDK_BUTTON_PRESS)
{ {
list->drag_selection = TRUE; if (gdk_pointer_grab (widget->window, TRUE,
gdk_pointer_grab (widget->window, TRUE, GDK_POINTER_MOTION_HINT_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time))
NULL, NULL, event->time); return FALSE;
gtk_grab_add (widget); gtk_grab_add (widget);
list->drag_selection = TRUE;
} }
else if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (list)) else if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (list))
gtk_list_end_drag_selection (list); gtk_list_end_drag_selection (list);
...@@ -909,17 +925,19 @@ gtk_list_set_focus_child (GtkContainer *container, ...@@ -909,17 +925,19 @@ gtk_list_set_focus_child (GtkContainer *container,
g_return_if_fail (container != NULL); g_return_if_fail (container != NULL);
g_return_if_fail (GTK_IS_LIST (container)); g_return_if_fail (GTK_IS_LIST (container));
if (child) if (child)
g_return_if_fail (GTK_IS_WIDGET (child)); g_return_if_fail (GTK_IS_WIDGET (child));
list = GTK_LIST (container); list = GTK_LIST (container);
list->last_focus_child = container->focus_child;
if (child != container->focus_child) if (child != container->focus_child)
{ {
if (container->focus_child) if (container->focus_child)
gtk_widget_unref (container->focus_child); {
list->last_focus_child = container->focus_child;
gtk_widget_unref (container->focus_child);
}
container->focus_child = child; container->focus_child = child;
if (container->focus_child) if (container->focus_child)
gtk_widget_ref (container->focus_child); gtk_widget_ref (container->focus_child);
...@@ -937,16 +955,22 @@ gtk_list_set_focus_child (GtkContainer *container, ...@@ -937,16 +955,22 @@ gtk_list_set_focus_child (GtkContainer *container,
container->focus_child->allocation.y, container->focus_child->allocation.y,
(container->focus_child->allocation.y + (container->focus_child->allocation.y +
container->focus_child->allocation.height)); container->focus_child->allocation.height));
} switch (list->selection_mode)
{
switch (list->selection_mode) case GTK_SELECTION_BROWSE:
{ gtk_list_select_child (list, child);
case GTK_SELECTION_BROWSE: break;
if (child) case GTK_SELECTION_EXTENDED:
gtk_list_select_child (list, child); if (!list->last_focus_child && !list->add_mode)
break; {
default: list->undo_focus_child = list->last_focus_child;
break; gtk_list_unselect_all (list);
gtk_list_select_child (list, child);
}
break;
default:
break;
}
} }
} }
...@@ -959,16 +983,18 @@ gtk_list_focus (GtkContainer *container, ...@@ -959,16 +983,18 @@ gtk_list_focus (GtkContainer *container,
g_return_val_if_fail (container != NULL, FALSE); g_return_val_if_fail (container != NULL, FALSE);
g_return_val_if_fail (GTK_IS_LIST (container), FALSE); g_return_val_if_fail (GTK_IS_LIST (container), FALSE);
if (!GTK_WIDGET_IS_SENSITIVE (container)) if (container->focus_child == NULL ||
return_val = FALSE;
else if (container->focus_child == NULL ||
!GTK_WIDGET_HAS_FOCUS (container->focus_child)) !GTK_WIDGET_HAS_FOCUS (container->focus_child))
{ {
if (GTK_LIST (container)->last_focus_child)
gtk_container_set_focus_child
(container, GTK_LIST (container)->last_focus_child);
if (GTK_CONTAINER_CLASS (parent_class)->focus) if (GTK_CONTAINER_CLASS (parent_class)->focus)
return_val = GTK_CONTAINER_CLASS (parent_class)->focus return_val = GTK_CONTAINER_CLASS (parent_class)->focus (container,
(container, direction); direction);
} }
if (!return_val) if (!return_val)
{ {
GtkList *list; GtkList *list;
...@@ -976,6 +1002,9 @@ gtk_list_focus (GtkContainer *container, ...@@ -976,6 +1002,9 @@ gtk_list_focus (GtkContainer *container,
list = GTK_LIST (container); list = GTK_LIST (container);
if (list->selection_mode == GTK_SELECTION_EXTENDED && list->anchor >= 0) if (list->selection_mode == GTK_SELECTION_EXTENDED && list->anchor >= 0)
gtk_list_end_selection (list); gtk_list_end_selection (list);
if (container->focus_child)
list->last_focus_child = container->focus_child;
} }
return return_val; return return_val;
...@@ -1023,9 +1052,6 @@ gtk_list_insert_items (GtkList *list, ...@@ -1023,9 +1052,6 @@ gtk_list_insert_items (GtkList *list,
gtk_signal_connect (GTK_OBJECT (widget), "drag_begin", gtk_signal_connect (GTK_OBJECT (widget), "drag_begin",
GTK_SIGNAL_FUNC (gtk_list_signal_drag_begin), GTK_SIGNAL_FUNC (gtk_list_signal_drag_begin),
list); list);
gtk_signal_connect (GTK_OBJECT (widget), "focus_out_event",
GTK_SIGNAL_FUNC (gtk_list_signal_focus_lost),
list);
gtk_signal_connect (GTK_OBJECT (widget), "toggle_focus_row", gtk_signal_connect (GTK_OBJECT (widget), "toggle_focus_row",
GTK_SIGNAL_FUNC (gtk_list_signal_toggle_focus_row), GTK_SIGNAL_FUNC (gtk_list_signal_toggle_focus_row),
list); list);
...@@ -1160,74 +1186,103 @@ gtk_list_clear_items (GtkList *list, ...@@ -1160,74 +1186,103 @@ gtk_list_clear_items (GtkList *list,
gint start, gint start,
gint end) gint end)
{ {
GtkContainer *container;
GtkWidget *widget; GtkWidget *widget;
GtkWidget *new_focus_child = NULL;
GList *start_list; GList *start_list;
GList *end_list; GList *end_list;
GList *tmp_list; GList *tmp_list;
guint nchildren; guint nchildren;
gboolean grab_focus = FALSE;
g_return_if_fail (list != NULL); g_return_if_fail (list != NULL);
g_return_if_fail (GTK_IS_LIST (list)); g_return_if_fail (GTK_IS_LIST (list));
nchildren = g_list_length (list->children); nchildren = g_list_length (list->children);
if (nchildren > 0) if (nchildren == 0)
{ return;
gboolean selection_changed;
if ((end < 0) || (end > nchildren)) if ((end < 0) || (end > nchildren))
end = nchildren; end = nchildren;
if (start >= end) if (start >= end)
return; return;
start_list = g_list_nth (list->children, start); container = GTK_CONTAINER (list);
end_list = g_list_nth (list->children, end);
gtk_list_end_drag_selection (list); gtk_list_end_drag_selection (list);
if (list->selection_mode == GTK_SELECTION_EXTENDED && list->anchor >= 0) if (list->selection_mode == GTK_SELECTION_EXTENDED)
{
if (list->anchor >= 0)
gtk_list_end_selection (list); gtk_list_end_selection (list);
if (start_list->prev) gtk_list_reset_extended_selection (list);
start_list->prev->next = end_list; }
if (end_list && end_list->prev)
end_list->prev->next = NULL;
if (end_list)
end_list->prev = start_list->prev;
if (start_list == list->children)
list->children = end_list;
selection_changed = FALSE; start_list = g_list_nth (list->children, start);
widget = NULL; end_list = g_list_nth (list->children, end);
tmp_list = start_list;
while (tmp_list) if (start_list->prev)
{ start_list->prev->next = end_list;
widget = tmp_list->data; if (end_list && end_list->prev)
tmp_list = tmp_list->next; end_list->prev->next = NULL;
if (end_list)
end_list->prev = start_list->prev;
if (start_list == list->children)
list->children = end_list;
if (widget->state == GTK_STATE_SELECTED) if (container->focus_child)
{ {
gtk_list_unselect_child (list, widget); if (g_list_find (start_list, container->focus_child))
selection_changed = TRUE; {
} if (start_list->prev)
new_focus_child = start_list->prev->data;
else if (list->children)
new_focus_child = list->children->prev->data;
gtk_widget_unparent (widget); if (GTK_WIDGET_HAS_FOCUS (container->focus_child))
grab_focus = TRUE;
} }
}
tmp_list = start_list;
while (tmp_list)
{
widget = tmp_list->data;
tmp_list = tmp_list->next;
if (widget->state == GTK_STATE_SELECTED)
gtk_list_unselect_child (list, widget);
if (widget == list->undo_focus_child)
list->undo_focus_child = NULL;
if (widget == list->last_focus_child)
list->last_focus_child = NULL;
g_list_free (start_list); gtk_signal_disconnect_by_data (GTK_OBJECT (widget), (gpointer) list);
gtk_widget_unparent (widget);
}
g_list_free (start_list);
if (new_focus_child)
{
if (grab_focus)
gtk_widget_grab_focus (new_focus_child);
else if (container->focus_child)
gtk_container_set_focus_child (container, new_focus_child);
if (list->children && !list->selection && if ((list->selection_mode == GTK_SELECTION_BROWSE ||
(list->selection_mode == GTK_SELECTION_BROWSE)) list->selection_mode == GTK_SELECTION_EXTENDED) && !list->selection)
{ {
widget = list->children->data; list->last_focus_child = new_focus_child;
gtk_list_select_child (list, widget); gtk_list_select_child (list, new_focus_child);
} }
else if (selection_changed)
gtk_signal_emit (GTK_OBJECT (list), list_signals[SELECTION_CHANGED]);
gtk_widget_queue_resize (GTK_WIDGET (list));
} }
if (GTK_WIDGET_VISIBLE (list))
gtk_widget_queue_resize (GTK_WIDGET (list));
} }
gint gint
...@@ -1288,17 +1343,7 @@ gtk_list_remove_items_internal (GtkList *list, ...@@ -1288,17 +1343,7 @@ gtk_list_remove_items_internal (GtkList *list,
if (list->anchor >= 0) if (list->anchor >= 0)
gtk_list_end_selection (list); gtk_list_end_selection (list);
if (list->undo_selection || list->undo_unselection) gtk_list_reset_extended_selection (list);
{
g_list_free (list->undo_selection);
g_list_free (list->undo_unselection);
list->undo_selection = NULL;
list->undo_unselection = NULL;
list->anchor = -1;
list->drag_pos = -1;
list->undo_focus_child = container->focus_child;
}
} }
tmp_list = items; tmp_list = items;
...@@ -1309,20 +1354,25 @@ gtk_list_remove_items_internal (GtkList *list, ...@@ -1309,20 +1354,25 @@ gtk_list_remove_items_internal (GtkList *list,
if (widget->state == GTK_STATE_SELECTED) if (widget->state == GTK_STATE_SELECTED)
gtk_list_unselect_child (list, widget); gtk_list_unselect_child (list, widget);
}
if (container->focus_child)
{
old_focus_child = new_focus_child = container->focus_child;
if (GTK_WIDGET_HAS_FOCUS (container->focus_child))
grab_focus = TRUE;
} }
else
old_focus_child = new_focus_child = list->last_focus_child;
tmp_list = items; tmp_list = items;
old_focus_child = new_focus_child = container->focus_child;
while (tmp_list) while (tmp_list)
{ {
widget = tmp_list->data; widget = tmp_list->data;
tmp_list = tmp_list->next; tmp_list = tmp_list->next;
if (no_unref) if (no_unref)
gtk_widget_ref (widget); gtk_widget_ref (widget);
if (widget == new_focus_child) if (widget == new_focus_child)
{ {
...@@ -1336,12 +1386,14 @@ gtk_list_remove_items_internal (GtkList *list, ...@@ -1336,12 +1386,14 @@ gtk_list_remove_items_internal (GtkList *list,
new_focus_child = work->prev->data; new_focus_child = work->prev->data;
else else
new_focus_child = NULL; new_focus_child = NULL;
if (GTK_WIDGET_HAS_FOCUS (widget))
grab_focus = TRUE;
} }
} }
if (widget == list->undo_focus_child)
list->undo_focus_child = NULL;
if (widget == list->last_focus_child)
list->last_focus_child = NULL;
gtk_signal_disconnect_by_data (GTK_OBJECT (widget), (gpointer) list); gtk_signal_disconnect_by_data (GTK_OBJECT (widget), (gpointer) list);
list->children = g_list_remove (list->children, widget); list->children = g_list_remove (list->children, widget);
gtk_widget_unparent (widget); gtk_widget_unparent (widget);
...@@ -1351,10 +1403,17 @@ gtk_list_remove_items_internal (GtkList *list, ...@@ -1351,10 +1403,17 @@ gtk_list_remove_items_internal (GtkList *list,
{ {
if (grab_focus) if (grab_focus)
gtk_widget_grab_focus (new_focus_child); gtk_widget_grab_focus (new_focus_child);
else else if (container->focus_child)
gtk_container_set_focus_child (container, new_focus_child); gtk_container_set_focus_child (container, new_focus_child);
if ((list->selection_mode == GTK_SELECTION_BROWSE ||
list->selection_mode == GTK_SELECTION_EXTENDED) && !list->selection)
{
list->last_focus_child = new_focus_child;
gtk_list_select_child (list, new_focus_child);
}
} }
if (GTK_WIDGET_VISIBLE (list)) if (GTK_WIDGET_VISIBLE (list))
gtk_widget_queue_resize (GTK_WIDGET (list)); gtk_widget_queue_resize (GTK_WIDGET (list));
} }
...@@ -1396,7 +1455,6 @@ gtk_list_set_selection_mode (GtkList *list, ...@@ -1396,7 +1455,6 @@ gtk_list_set_selection_mode (GtkList *list,
case GTK_SELECTION_BROWSE: case GTK_SELECTION_BROWSE:
gtk_list_unselect_all (list); gtk_list_unselect_all (list);
break; break;
default: default:
break; break;
} }
...@@ -1473,7 +1531,6 @@ gtk_