summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-07-06 00:21:43 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-07-06 00:21:43 +0000
commit367cacdf1b879c5bfa16f21502c80d8ed152ebef (patch)
treee373581e311d8e1f6d4772e87c393607f7cb3a7e /gtk
parente05a96609d5f3c2725ab2a7a35438cd2c6aed8c2 (diff)
downloadgtk+-367cacdf1b879c5bfa16f21502c80d8ed152ebef.tar.gz
Add an extra parameter to _gtk_menu_item_select_first() to allow us to
Fri Jul 5 20:18:23 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkmenushell.[ch] gtk/gtkmenubar.c gtk/gtkmenuitem.c gtk/gtkentry.c gtk/gtktextview.c: Add an extra parameter to _gtk_menu_item_select_first() to allow us to choose whether we want to select the first item predictably or to select the first sensitive item. Fixes problem with insensitive menu items and keynav. (#85796, reported by Bill Haneman and others.)
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkentry.c2
-rw-r--r--gtk/gtkmenubar.c2
-rw-r--r--gtk/gtkmenuitem.c2
-rw-r--r--gtk/gtkmenushell.c49
-rw-r--r--gtk/gtkmenushell.h3
-rw-r--r--gtk/gtktextview.c2
6 files changed, 48 insertions, 12 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 8231f940d5..70a2ddc5c6 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3922,7 +3922,7 @@ popup_targets_received (GtkClipboard *clipboard,
gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
popup_position_func, entry,
info->button, info->time);
- _gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu));
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
}
}
diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c
index 5b2a546198..7f891f2f15 100644
--- a/gtk/gtkmenubar.c
+++ b/gtk/gtkmenubar.c
@@ -450,7 +450,7 @@ window_key_press_handler (GtkWidget *widget,
GtkMenuShell *menu_shell = GTK_MENU_SHELL (menubars->data);
_gtk_menu_shell_activate (menu_shell);
- _gtk_menu_shell_select_first (menu_shell);
+ _gtk_menu_shell_select_first (menu_shell, FALSE);
g_list_free (menubars);
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 118e7009ba..0f3bc8e1a9 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -804,7 +804,7 @@ gtk_real_menu_item_activate_item (GtkMenuItem *menu_item)
gtk_menu_shell_select_item (GTK_MENU_SHELL (widget->parent), widget);
gtk_menu_item_popup_submenu (widget);
- _gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu));
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu), FALSE);
submenu = GTK_MENU_SHELL (menu_item->submenu);
}
}
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index 91fee1c574..0d8b0565ff 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -994,12 +994,19 @@ gtk_menu_shell_move_selected (GtkMenuShell *menu_shell,
/**
* _gtk_menu_shell_select_first:
* @menu_shell: a #GtkMenuShell
+ * @search_sensitive: if %TRUE, search for the first selectable
+ * menu item, otherwise select nothing if
+ * the first item isn't sensitive. This
+ * should be %FALSE if the menu is being
+ * popped up initially.
*
- * Select the first visible child of the menu shell, unless
- * it's a tearoff item.
+ * Select the first visible or selectable child of the menu shell;
+ * don't select tearoff items unless the only item is a tearoff
+ * item.
**/
void
-_gtk_menu_shell_select_first (GtkMenuShell *menu_shell)
+_gtk_menu_shell_select_first (GtkMenuShell *menu_shell,
+ gboolean search_sensitive)
{
GtkWidget *to_select = NULL;
GList *tmp_list;
@@ -1009,7 +1016,8 @@ _gtk_menu_shell_select_first (GtkMenuShell *menu_shell)
{
GtkWidget *child = tmp_list->data;
- if (GTK_WIDGET_VISIBLE (child))
+ if ((!search_sensitive && GTK_WIDGET_VISIBLE (child)) ||
+ _gtk_menu_item_is_selectable (child))
{
to_select = child;
if (!GTK_IS_TEAROFF_MENU_ITEM (child))
@@ -1024,6 +1032,33 @@ _gtk_menu_shell_select_first (GtkMenuShell *menu_shell)
}
static void
+gtk_menu_shell_select_last (GtkMenuShell *menu_shell,
+ gboolean search_sensitive)
+{
+ GtkWidget *to_select = NULL;
+ GList *tmp_list;
+
+ tmp_list = g_list_last (menu_shell->children);
+ while (tmp_list)
+ {
+ GtkWidget *child = tmp_list->data;
+
+ if ((!search_sensitive && GTK_WIDGET_VISIBLE (child)) ||
+ _gtk_menu_item_is_selectable (child))
+ {
+ to_select = child;
+ if (!GTK_IS_TEAROFF_MENU_ITEM (child))
+ break;
+ }
+
+ tmp_list = tmp_list->prev;
+ }
+
+ if (to_select)
+ gtk_menu_shell_select_item (menu_shell, to_select);
+}
+
+static void
gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell)
{
GtkMenuItem *menu_item;
@@ -1031,7 +1066,7 @@ gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell)
menu_item = GTK_MENU_ITEM (menu_shell->active_menu_item);
if (menu_item->submenu)
- _gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu));
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu), TRUE);
}
static void
@@ -1097,14 +1132,14 @@ gtk_real_menu_shell_move_current (GtkMenuShell *menu_shell,
if (!had_selection &&
!menu_shell->active_menu_item &&
menu_shell->children)
- gtk_menu_shell_select_item (menu_shell, g_list_last (menu_shell->children)->data);
+ gtk_menu_shell_select_last (menu_shell, TRUE);
break;
case GTK_MENU_DIR_NEXT:
gtk_menu_shell_move_selected (menu_shell, 1);
if (!had_selection &&
!menu_shell->active_menu_item &&
menu_shell->children)
- gtk_menu_shell_select_item (menu_shell, menu_shell->children->data);
+ _gtk_menu_shell_select_first (menu_shell, TRUE);
break;
}
diff --git a/gtk/gtkmenushell.h b/gtk/gtkmenushell.h
index 9edb887b32..d7529dc059 100644
--- a/gtk/gtkmenushell.h
+++ b/gtk/gtkmenushell.h
@@ -111,7 +111,8 @@ void gtk_menu_shell_activate_item (GtkMenuShell *menu_shell,
GtkWidget *menu_item,
gboolean force_deactivate);
-void _gtk_menu_shell_select_first (GtkMenuShell *menu_shell);
+void _gtk_menu_shell_select_first (GtkMenuShell *menu_shell,
+ gboolean search_sensitive);
void _gtk_menu_shell_activate (GtkMenuShell *menu_shell);
#ifdef __cplusplus
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 099809f522..7ef9788971 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -6447,7 +6447,7 @@ popup_targets_received (GtkClipboard *clipboard,
gtk_menu_popup (GTK_MENU (text_view->popup_menu), NULL, NULL,
popup_position_func, text_view,
0, gtk_get_current_event_time ());
- _gtk_menu_shell_select_first (GTK_MENU_SHELL (text_view->popup_menu));
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (text_view->popup_menu), FALSE);
}
}