Commit 7650482e authored by Matthias Clasen's avatar Matthias Clasen

Add sufficient API to make gail work

The accessible implementations should really be folded into
gtk proper. Until that happens, we need some more guts exposed...
parent 2ed81aa5
......@@ -2116,6 +2116,8 @@ gtk_menu_shell_activate_item
gtk_menu_shell_cancel
gtk_menu_shell_set_take_focus
gtk_menu_shell_get_take_focus
gtk_menu_shell_get_selected_item
gtk_menu_shell_get_parent_shell
GtkMenuDirectionType
<SUBSECTION Standard>
GTK_MENU_SHELL
......
......@@ -1501,6 +1501,8 @@ gtk_menu_shell_append
gtk_menu_shell_cancel
gtk_menu_shell_deactivate
gtk_menu_shell_deselect
gtk_menu_shell_get_selected_item
gtk_menu_shell_get_parent_shell
gtk_menu_shell_get_take_focus
gtk_menu_shell_get_type G_GNUC_CONST
gtk_menu_shell_insert
......
......@@ -1869,3 +1869,42 @@ gtk_menu_shell_set_take_focus (GtkMenuShell *menu_shell,
g_object_notify (G_OBJECT (menu_shell), "take-focus");
}
}
/**
* gtk_menu_shell_get_selected_item:
* @menu_shell: a #GtkMenuShell
*
* Gets the currently selected item.
*
* Returns: the currently selected item
*
* Since: 3.0
*/
GtkWidget *
gtk_menu_shell_get_selected_item (GtkMenuShell *menu_shell)
{
g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
return menu_shell->priv->active_menu_item;
}
/**
* gtk_menu_shell_get_parent_shell:
* @menu_shell: a #GtkMenuShell
*
* Gets the parent menu shell.
*
* The parent menu shell of a submenu is the #GtkMenu or #GtkMenuBar
* from which it was opened up.
*
* Returns: the parent #GtkMenuShell
*
* Since: 3.0
*/
GtkWidget *
gtk_menu_shell_get_parent_shell (GtkMenuShell *menu_shell)
{
g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
return menu_shell->priv->parent_menu_shell;
}
......@@ -111,6 +111,9 @@ gboolean gtk_menu_shell_get_take_focus (GtkMenuShell *menu_shell);
void gtk_menu_shell_set_take_focus (GtkMenuShell *menu_shell,
gboolean take_focus);
GtkWidget *gtk_menu_shell_get_selected_item (GtkMenuShell *menu_shell);
GtkWidget *gtk_menu_shell_get_parent_shell (GtkMenuShell *menu_shell);
G_END_DECLS
#endif /* __GTK_MENU_SHELL_H__ */
......@@ -250,7 +250,7 @@ gail_focus_watcher (GSignalInvocationHint *ihint,
{
if (GTK_IS_MENU_SHELL (child))
{
if (GTK_MENU_SHELL (child)->active_menu_item)
if (gtk_menu_shell_get_selected_item (GTK_MENU_SHELL (child)))
{
/*
* We have a menu which has a menu item selected
......@@ -349,10 +349,12 @@ gail_finish_select (GtkWidget *widget)
if (GTK_IS_MENU_ITEM (widget))
{
GtkMenuItem* menu_item;
GtkWidget *submenu;
menu_item = GTK_MENU_ITEM (widget);
if (menu_item->submenu &&
!gtk_widget_get_mapped (menu_item->submenu))
submenu = gtk_menu_item_get_submenu (menu_item);
if (submenu &&
!gtk_widget_get_mapped (submenu))
{
/*
* If the submenu is not visble, wait until it is before
......@@ -360,7 +362,7 @@ gail_finish_select (GtkWidget *widget)
*/
gulong handler_id;
handler_id = g_signal_handler_find (menu_item->submenu,
handler_id = g_signal_handler_find (submenu,
G_SIGNAL_MATCH_FUNC,
g_signal_lookup ("map",
GTK_TYPE_WINDOW),
......@@ -369,11 +371,10 @@ gail_finish_select (GtkWidget *widget)
(gpointer) gail_map_submenu_cb,
NULL);
if (!handler_id)
g_signal_connect (menu_item->submenu, "map",
g_signal_connect (submenu, "map",
G_CALLBACK (gail_map_submenu_cb),
NULL);
return;
}
/*
* If we are waiting to report focus on a menubar or a menu item
......@@ -422,8 +423,11 @@ gail_map_submenu_cb (GtkWidget *widget)
{
if (GTK_IS_MENU (widget))
{
if (GTK_MENU (widget)->parent_menu_item)
gail_finish_select (GTK_MENU (widget)->parent_menu_item);
GtkWidget *parent_menu_item;
parent_menu_item = gtk_menu_get_attach_widget (GTK_MENU (widget));
if (parent_menu_item)
gail_finish_select (parent_menu_item);
}
}
......@@ -454,12 +458,12 @@ gail_deselect_watcher (GSignalInvocationHint *ihint,
{
GtkWidget *parent_menu_shell;
parent_menu_shell = GTK_MENU_SHELL (menu_shell)->parent_menu_shell;
parent_menu_shell = gtk_menu_shell_get_parent_shell (GTK_MENU_SHELL (menu_shell));
if (parent_menu_shell)
{
GtkWidget *active_menu_item;
active_menu_item = GTK_MENU_SHELL (parent_menu_shell)->active_menu_item;
active_menu_item = gtk_menu_shell_get_selected_item (GTK_MENU_SHELL (parent_menu_shell));
if (active_menu_item)
{
gail_focus_notify_when_idle (active_menu_item);
......@@ -661,7 +665,7 @@ gail_deactivate_watcher (GSignalInvocationHint *ihint,
g_return_val_if_fail (GTK_IS_MENU_SHELL(widget), TRUE);
shell = GTK_MENU_SHELL(widget);
if (!shell->parent_menu_shell)
if (! gtk_menu_shell_get_parent_shell (shell))
focus = focus_before_menu;
/*
......
......@@ -88,8 +88,8 @@ static gboolean
gail_menu_shell_add_selection (AtkSelection *selection,
gint i)
{
GtkMenuShell *shell;
GList *item;
GList *kids;
GtkWidget *item;
guint length;
GtkWidget *widget;
......@@ -100,16 +100,18 @@ gail_menu_shell_add_selection (AtkSelection *selection,
return FALSE;
}
shell = GTK_MENU_SHELL (widget);
length = g_list_length (shell->children);
kids = gtk_container_get_children (GTK_CONTAINER (widget));
length = g_list_length (kids);
if (i < 0 || i > length)
return FALSE;
item = g_list_nth (shell->children, i);
g_return_val_if_fail (item != NULL, FALSE);
g_return_val_if_fail (GTK_IS_MENU_ITEM(item->data), FALSE);
gtk_menu_shell_select_item (shell, GTK_WIDGET (item->data));
{
g_list_free (kids);
return FALSE;
}
item = g_list_nth_data (kids, i);
g_list_free (kids);
g_return_val_if_fail (GTK_IS_MENU_ITEM(item), FALSE);
gtk_menu_shell_select_item (GTK_MENU_SHELL (widget), item);
return TRUE;
}
......@@ -139,6 +141,7 @@ gail_menu_shell_ref_selection (AtkSelection *selection,
GtkMenuShell *shell;
AtkObject *obj;
GtkWidget *widget;
GtkWidget *item;
if (i != 0)
return NULL;
......@@ -151,10 +154,11 @@ gail_menu_shell_ref_selection (AtkSelection *selection,
}
shell = GTK_MENU_SHELL (widget);
if (shell->active_menu_item != NULL)
item = gtk_menu_shell_get_selectec_item (shell);
if (item != NULL)
{
obj = gtk_widget_get_accessible (shell->active_menu_item);
obj = gtk_widget_get_accessible (item);
g_object_ref (obj);
return obj;
}
......@@ -182,7 +186,7 @@ gail_menu_shell_get_selection_count (AtkSelection *selection)
/*
* Identifies the currently selected menu item
*/
if (shell->active_menu_item == NULL)
if (gtk_menu_shell_get_selected_item (shell) == NULL)
{
return 0;
}
......@@ -197,8 +201,10 @@ gail_menu_shell_is_child_selected (AtkSelection *selection,
gint i)
{
GtkMenuShell *shell;
GList *kids;
gint j;
GtkWidget *widget;
GtkWidget *item;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
if (widget == NULL)
......@@ -208,12 +214,15 @@ gail_menu_shell_is_child_selected (AtkSelection *selection,
}
shell = GTK_MENU_SHELL (widget);
if (shell->active_menu_item == NULL)
item = gtk_menu_shell_get_selected_item (shell);
if (item == NULL)
return FALSE;
j = g_list_index (shell->children, shell->active_menu_item);
return (j==i);
kids = gtk_container_get_children (GTK_CONTAINER (shell));
j = g_list_index (kids, item);
g_list_free (kids);
return (j==i);
}
static gboolean
......@@ -222,6 +231,7 @@ gail_menu_shell_remove_selection (AtkSelection *selection,
{
GtkMenuShell *shell;
GtkWidget *widget;
GtkWidget *item;
if (i != 0)
return FALSE;
......@@ -235,8 +245,8 @@ gail_menu_shell_remove_selection (AtkSelection *selection,
shell = GTK_MENU_SHELL (widget);
if (shell->active_menu_item &&
GTK_MENU_ITEM (shell->active_menu_item)->submenu)
item = gtk_menu_shell_get_selected_item (shell);
if (item && gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
{
/*
* Menu item contains a menu and it is the selected menu item
......
......@@ -120,10 +120,11 @@ gail_sub_menu_item_add_selection (AtkSelection *selection,
gint i)
{
GtkMenuShell *shell;
GList *item;
GList *kids;
guint length;
GtkWidget *widget;
GtkWidget *submenu;
GtkWidget *child;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
if (widget == NULL)
......@@ -133,15 +134,18 @@ gail_sub_menu_item_add_selection (AtkSelection *selection,
submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
shell = GTK_MENU_SHELL (submenu);
length = g_list_length (shell->children);
kids = gtk_container_get_children (GTK_CONTAINER (shell));
length = g_list_length (kids);
if (i < 0 || i > length)
return FALSE;
{
g_list_free (kids);
return FALSE;
}
item = g_list_nth (shell->children, i);
g_return_val_if_fail (item != NULL, FALSE);
g_return_val_if_fail (GTK_IS_MENU_ITEM(item->data), FALSE);
gtk_menu_shell_select_item (shell, GTK_WIDGET (item->data));
child = g_list_nth_data (kids, i);
g_list_free (kids);
g_return_val_if_fail (GTK_IS_MENU_ITEM(child), FALSE);
gtk_menu_shell_select_item (shell, GTK_WIDGET (child));
return TRUE;
}
......@@ -173,6 +177,7 @@ gail_sub_menu_item_ref_selection (AtkSelection *selection,
AtkObject *obj;
GtkWidget *widget;
GtkWidget *submenu;
GtkWidget *item;
if (i != 0)
return NULL;
......@@ -185,10 +190,11 @@ gail_sub_menu_item_ref_selection (AtkSelection *selection,
submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), NULL);
shell = GTK_MENU_SHELL (submenu);
if (shell->active_menu_item != NULL)
item = gtk_menu_shell_get_selected_item (shell);
if (item != NULL)
{
obj = gtk_widget_get_accessible (shell->active_menu_item);
obj = gtk_widget_get_accessible (item);
g_object_ref (obj);
return obj;
}
......@@ -217,7 +223,7 @@ gail_sub_menu_item_get_selection_count (AtkSelection *selection)
/*
* Identifies the currently selected menu item
*/
if (shell->active_menu_item == NULL)
if (gtk_menu_shell_get_selected_item (shell) == NULL)
return 0;
else
return 1;
......@@ -231,6 +237,8 @@ gail_sub_menu_item_is_child_selected (AtkSelection *selection,
gint j;
GtkWidget *widget;
GtkWidget *submenu;
GtkWidget *item;
GList *kids;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
if (widget == NULL)
......@@ -241,12 +249,15 @@ gail_sub_menu_item_is_child_selected (AtkSelection *selection,
g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
shell = GTK_MENU_SHELL (submenu);
if (shell->active_menu_item == NULL)
item = gtk_menu_shell_get_selected_item (shell);
if (item == NULL)
return FALSE;
j = g_list_index (shell->children, shell->active_menu_item);
return (j==i);
kids = gtk_container_get_children (GTK_CONTAINER (shell));
j = g_list_index (kids, item);
g_list_free (kids);
return (j==i);
}
static gboolean
......@@ -256,6 +267,7 @@ gail_sub_menu_item_remove_selection (AtkSelection *selection,
GtkMenuShell *shell;
GtkWidget *widget;
GtkWidget *submenu;
GtkWidget *item;
if (i != 0)
return FALSE;
......@@ -269,8 +281,8 @@ gail_sub_menu_item_remove_selection (AtkSelection *selection,
g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
shell = GTK_MENU_SHELL (submenu);
if (shell->active_menu_item &&
GTK_MENU_ITEM (shell->active_menu_item)->submenu)
item = gtk_menu_shell_get_selected_item (shell);
if (item && gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
{
/*
* Menu item contains a menu and it is the selected menu item
......
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