summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkentry.c24
-rw-r--r--gtk/gtkmenu.c2
-rw-r--r--gtk/gtkmenuitem.c34
-rw-r--r--gtk/gtkmenuitem.h1
-rw-r--r--gtk/gtkmenushell.c43
-rw-r--r--gtk/gtkmenushell.h1
-rw-r--r--gtk/gtknotebook.c2
-rw-r--r--gtk/gtktextview.c24
8 files changed, 63 insertions, 68 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 25cbcc7956..d58c93f96f 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3825,28 +3825,6 @@ unichar_chosen_func (const char *text,
gtk_entry_enter_text (entry, text);
}
-static void
-menu_select_first_child (GtkMenu *menu)
-{
- GList *children = gtk_container_get_children (GTK_CONTAINER (menu));
-
- GList *tmp_list = children;
- while (tmp_list)
- {
- GtkWidget *child = tmp_list->data;
-
- if (GTK_WIDGET_VISIBLE (child))
- {
- gtk_menu_shell_select_item (GTK_MENU_SHELL (menu), child);
- break;
- }
-
- tmp_list = tmp_list->next;
- }
-
- g_list_free (children);
-}
-
typedef struct
{
GtkEntry *entry;
@@ -3931,7 +3909,7 @@ popup_targets_received (GtkClipboard *clipboard,
gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
popup_position_func, entry,
info->button, info->time);
- menu_select_first_child (GTK_MENU (entry->popup_menu));
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu));
}
}
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 360a4202d4..3273c710c5 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -1808,7 +1808,7 @@ gtk_menu_key_press (GtkWidget *widget,
GtkAccelKey key;
if (gtk_accel_map_lookup_entry (path, &key) &&
- key.accel_key || key.accel_mods)
+ (key.accel_key || key.accel_mods))
{
accel_key = 0;
accel_mods = 0;
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 083358e989..06a47ed0ff 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -33,7 +33,6 @@
#include "gtkmenu.h"
#include "gtkmenubar.h"
#include "gtkmenuitem.h"
-#include "gtktearoffmenuitem.h"
#include "gtkseparatormenuitem.h"
#include "gtksignal.h"
@@ -668,11 +667,21 @@ gtk_real_menu_item_select (GtkItem *item)
GdkEvent *event = gtk_get_current_event ();
etime = event ? gdk_event_get_time (event) : GDK_CURRENT_TIME;
- if (etime >= last_submenu_deselect_time &&
+ if (event &&
+ etime >= last_submenu_deselect_time &&
last_submenu_deselect_time + SELECT_TIMEOUT > etime)
- menu_item->timer = gtk_timeout_add (SELECT_TIMEOUT - (etime - last_submenu_deselect_time),
- gtk_menu_item_select_timeout,
- menu_item);
+ {
+ if (!menu_item->timer)
+ menu_item->timer = gtk_timeout_add (SELECT_TIMEOUT - (etime - last_submenu_deselect_time),
+ gtk_menu_item_select_timeout,
+ menu_item);
+ if (event &&
+ event->type != GDK_BUTTON_PRESS &&
+ event->type != GDK_ENTER_NOTIFY)
+ menu_item->timer_from_keypress = TRUE;
+ else
+ menu_item->timer_from_keypress = FALSE;
+ }
else
gtk_menu_item_popup_submenu (menu_item);
if (event)
@@ -765,15 +774,8 @@ 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));
submenu = GTK_MENU_SHELL (menu_item->submenu);
- if (submenu->children)
- {
- if (submenu->children->next &&
- GTK_IS_TEAROFF_MENU_ITEM (submenu->children->data))
- gtk_menu_shell_select_item (submenu, submenu->children->next->data);
- else
- gtk_menu_shell_select_item (submenu, submenu->children->data);
- }
}
}
}
@@ -798,9 +800,15 @@ gtk_real_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,
static gint
gtk_menu_item_select_timeout (gpointer data)
{
+ GtkMenuItem *menu_item;
+
GDK_THREADS_ENTER ();
+ menu_item = GTK_MENU_ITEM (data);
+
gtk_menu_item_popup_submenu (data);
+ if (menu_item->timer_from_keypress && menu_item->submenu)
+ GTK_MENU_SHELL (menu_item->submenu)->ignore_enter = TRUE;
GDK_THREADS_LEAVE ();
diff --git a/gtk/gtkmenuitem.h b/gtk/gtkmenuitem.h
index 99c746573f..353a13b1fc 100644
--- a/gtk/gtkmenuitem.h
+++ b/gtk/gtkmenuitem.h
@@ -63,6 +63,7 @@ struct _GtkMenuItem
guint submenu_placement : 1;
guint submenu_direction : 1;
guint right_justify: 1;
+ guint timer_from_keypress : 1;
guint timer;
};
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index a09c222613..46355216ad 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -33,6 +33,7 @@
#include "gtkmenuitem.h"
#include "gtkmenushell.h"
#include "gtksignal.h"
+#include "gtktearoffmenuitem.h"
#include "gtkwindow.h"
#define MENU_SHELL_TIMEOUT 500
@@ -926,6 +927,38 @@ gtk_menu_shell_move_selected (GtkMenuShell *menu_shell,
}
}
+/**
+ * _gtk_menu_shell_select_first:
+ * @menu_shell: a #GtkMenuShell
+ *
+ * Select the first visible child of the menu shell, unless
+ * it's a tearoff item.
+ **/
+void
+_gtk_menu_shell_select_first (GtkMenuShell *menu_shell)
+{
+ GtkWidget *to_select = NULL;
+ GList *tmp_list;
+
+ tmp_list = menu_shell->children;
+ while (tmp_list)
+ {
+ GtkWidget *child = tmp_list->data;
+
+ if (GTK_WIDGET_VISIBLE (child))
+ {
+ to_select = child;
+ if (!GTK_IS_TEAROFF_MENU_ITEM (child))
+ break;
+ }
+
+ tmp_list = tmp_list->next;
+ }
+
+ if (to_select)
+ gtk_menu_shell_select_item (menu_shell, to_select);
+}
+
static void
gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell)
{
@@ -934,11 +967,7 @@ gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell)
menu_item = GTK_MENU_ITEM (menu_shell->active_menu_item);
if (menu_item->submenu)
- {
- GtkMenuShell *submenu = GTK_MENU_SHELL (menu_item->submenu);
- if (submenu->children)
- gtk_menu_shell_select_item (submenu, submenu->children->data);
- }
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu));
}
static void
@@ -974,9 +1003,7 @@ gtk_real_menu_shell_move_current (GtkMenuShell *menu_shell,
_gtk_menu_item_is_selectable (menu_shell->active_menu_item) &&
GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu)
{
- menu_shell = GTK_MENU_SHELL (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu);
- if (menu_shell->children)
- gtk_menu_shell_select_item (menu_shell, menu_shell->children->data);
+ gtk_menu_shell_select_submenu_first (menu_shell);
}
else
{
diff --git a/gtk/gtkmenushell.h b/gtk/gtkmenushell.h
index 3d09f7fbc9..2d2ca67636 100644
--- a/gtk/gtkmenushell.h
+++ b/gtk/gtkmenushell.h
@@ -105,6 +105,7 @@ void gtk_menu_shell_activate_item (GtkMenuShell *menu_shell,
GtkWidget *menu_item,
gboolean force_deactivate);
+void _gtk_menu_shell_select_first (GtkMenuShell *menu_shell);
#ifdef __cplusplus
}
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 50a6978f5f..be050d054b 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1868,6 +1868,8 @@ focus_child_in (GtkNotebook *notebook,
{
if (notebook->cur_page)
return gtk_widget_child_focus (notebook->cur_page->child, direction);
+ else
+ return FALSE;
}
/* Focus in the notebook can either be on the pages, or on
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index d834db973b..08f016f5de 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -6274,28 +6274,6 @@ unichar_chosen_func (const char *text,
}
static void
-menu_select_first_child (GtkMenu *menu)
-{
- GList *children = gtk_container_get_children (GTK_CONTAINER (menu));
-
- GList *tmp_list = children;
- while (tmp_list)
- {
- GtkWidget *child = tmp_list->data;
-
- if (GTK_WIDGET_VISIBLE (child))
- {
- gtk_menu_shell_select_item (GTK_MENU_SHELL (menu), child);
- break;
- }
-
- tmp_list = tmp_list->next;
- }
-
- g_list_free (children);
-}
-
-static void
popup_targets_received (GtkClipboard *clipboard,
GtkSelectionData *data,
gpointer user_data)
@@ -6381,7 +6359,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 ());
- menu_select_first_child (GTK_MENU (text_view->popup_menu));
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (text_view->popup_menu));
}
}