Commit ae7521bd authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

Non-exported _gtk_menu_select_first() function that selects the first item

Sat Feb  2 20:16:04 2002  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
        Non-exported _gtk_menu_select_first() function that
        selects the first item of the menu in a standard
        way. (Skipping tearoffs.)

        * gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
        gtkmenuitem.c: Use _gtk_menu_shell_select_first().

        * gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
        if we are starting the timeout from a keypress so
        we can set menushell->ignore_enter properly.

        * gtk/gtknotebook.c (focus_child_in): Return something
        meaningful if there are no children.

        * gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
        problem.
parent 0ed21b67
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
Sat Feb 2 20:16:04 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenushell.c (_gtk_menu_shell_select_first):
Non-exported _gtk_menu_select_first() function that
selects the first item of the menu in a standard
way. (Skipping tearoffs.)
* gtk/gtkmenushell.c gtk/gtkentry.c gtk/gtktextview.c
gtkmenuitem.c: Use _gtk_menu_shell_select_first().
* gtk/gtkmenuitem.c (gtk_real_menu_item_select): Remember
if we are starting the timeout from a keypress so
we can set menushell->ignore_enter properly.
* gtk/gtknotebook.c (focus_child_in): Return something
meaningful if there are no children.
* gtk/gtkmenu.c (gtk_menu_key_press): Fix precendence
problem.
Sat Feb 2 19:15:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkmenu.c (gtk_menu_popup): Fix some bugs in
......
......@@ -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));
}
}
......
......@@ -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;
......
......@@ -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 ();
......
......@@ -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;
};
......
......@@ -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
{
......
......@@ -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
}
......
......@@ -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
......
......@@ -6273,28 +6273,6 @@ unichar_chosen_func (const char *text,
gtk_text_view_commit_text (text_view, 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,
......@@ -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));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment