mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-17 23:50:16 +00:00
atspi: Implement Selection for notebook tabs
This is a bit different from the way things were done in GTK 3 - we follow what was done for GtkStackSwitcher, and make the tab bar carry the GTK_ACCESSIBLE_TAB_LIST role, and implement Selection there.
This commit is contained in:
parent
08b586bb57
commit
bf04beb711
@ -735,7 +735,11 @@ gtk_at_spi_context_register_object (GtkAtSpiContext *self)
|
|||||||
self->n_registered_objects++;
|
self->n_registered_objects++;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtable = gtk_atspi_get_selection_vtable (accessible);
|
/* Calling gtk_accessible_get_accessible_role() in here will recurse,
|
||||||
|
* so pass the role in explicitly.
|
||||||
|
*/
|
||||||
|
vtable = gtk_atspi_get_selection_vtable (accessible,
|
||||||
|
GTK_AT_CONTEXT (self)->accessible_role);
|
||||||
if (vtable)
|
if (vtable)
|
||||||
{
|
{
|
||||||
g_variant_builder_add (&interfaces, "s", atspi_selection_interface.name);
|
g_variant_builder_add (&interfaces, "s", atspi_selection_interface.name);
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "gtkflowbox.h"
|
#include "gtkflowbox.h"
|
||||||
#include "gtkcombobox.h"
|
#include "gtkcombobox.h"
|
||||||
#include "gtkstackswitcher.h"
|
#include "gtkstackswitcher.h"
|
||||||
|
#include "gtknotebook.h"
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
|
||||||
@ -575,14 +576,146 @@ stackswitcher_get_property (GDBusConnection *connection,
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GDBusInterfaceVTable stackswitcher_vtable = {
|
static const GDBusInterfaceVTable stackswitcher_vtable = {
|
||||||
stackswitcher_handle_method,
|
stackswitcher_handle_method,
|
||||||
stackswitcher_get_property,
|
stackswitcher_get_property,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
notebook_handle_method (GDBusConnection *connection,
|
||||||
|
const gchar *sender,
|
||||||
|
const gchar *object_path,
|
||||||
|
const gchar *interface_name,
|
||||||
|
const gchar *method_name,
|
||||||
|
GVariant *parameters,
|
||||||
|
GDBusMethodInvocation *invocation,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkATContext *self = user_data;
|
||||||
|
GtkAccessible *accessible = gtk_at_context_get_accessible (self);
|
||||||
|
GtkWidget *widget = GTK_WIDGET (accessible);
|
||||||
|
GtkWidget *notebook = gtk_widget_get_parent (gtk_widget_get_parent (widget));
|
||||||
|
|
||||||
|
if (g_strcmp0 (method_name, "GetSelectedChild") == 0)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
|
i = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
|
||||||
|
|
||||||
|
for (child = gtk_widget_get_first_child (widget);
|
||||||
|
child;
|
||||||
|
child = gtk_widget_get_next_sibling (widget))
|
||||||
|
{
|
||||||
|
/* skip actions */
|
||||||
|
if (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (child)) != GTK_ACCESSIBLE_ROLE_TAB)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child == NULL)
|
||||||
|
{
|
||||||
|
g_dbus_method_invocation_return_error_literal (invocation,
|
||||||
|
G_DBUS_ERROR,
|
||||||
|
G_DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"No selected child");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GtkATContext *ctx = gtk_accessible_get_at_context (GTK_ACCESSIBLE (child));
|
||||||
|
g_dbus_method_invocation_return_value (invocation,
|
||||||
|
g_variant_new ("(@(so))", gtk_at_spi_context_to_ref (GTK_AT_SPI_CONTEXT (ctx))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (g_strcmp0 (method_name, "SelectChild") == 0)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
|
g_variant_get (parameters, "(i)", &i);
|
||||||
|
|
||||||
|
/* skip an action widget */
|
||||||
|
child = gtk_widget_get_first_child (widget);
|
||||||
|
if (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (child)) != GTK_ACCESSIBLE_ROLE_TAB)
|
||||||
|
i--;
|
||||||
|
|
||||||
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), i);
|
||||||
|
|
||||||
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
|
||||||
|
}
|
||||||
|
else if (g_strcmp0 (method_name, "DeselectChild") == 0)
|
||||||
|
{
|
||||||
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
|
||||||
|
}
|
||||||
|
else if (g_strcmp0 (method_name, "DeselectSelectedChild") == 0)
|
||||||
|
{
|
||||||
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
|
||||||
|
}
|
||||||
|
else if (g_strcmp0 (method_name, "IsChildSelected") == 0)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
gboolean active;
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
|
g_variant_get (parameters, "(i)", &i);
|
||||||
|
|
||||||
|
/* skip an action widget */
|
||||||
|
child = gtk_widget_get_first_child (widget);
|
||||||
|
if (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (child)) != GTK_ACCESSIBLE_ROLE_TAB)
|
||||||
|
i--;
|
||||||
|
|
||||||
|
active = i == gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
|
||||||
|
|
||||||
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", active));
|
||||||
|
}
|
||||||
|
else if (g_strcmp0 (method_name, "SelectAll") == 0)
|
||||||
|
{
|
||||||
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
|
||||||
|
}
|
||||||
|
else if (g_strcmp0 (method_name, "ClearSelection") == 0)
|
||||||
|
{
|
||||||
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GVariant *
|
||||||
|
notebook_get_property (GDBusConnection *connection,
|
||||||
|
const gchar *sender,
|
||||||
|
const gchar *object_path,
|
||||||
|
const gchar *interface_name,
|
||||||
|
const gchar *property_name,
|
||||||
|
GError **error,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
if (g_strcmp0 (property_name, "NSelectedChildren") == 0)
|
||||||
|
{
|
||||||
|
return g_variant_new_int32 (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const GDBusInterfaceVTable notebook_vtable = {
|
||||||
|
notebook_handle_method,
|
||||||
|
notebook_get_property,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IS_NOTEBOOK_TAB_LIST(s,r) \
|
||||||
|
((r == GTK_ACCESSIBLE_ROLE_TAB_LIST) && \
|
||||||
|
(gtk_widget_get_parent (GTK_WIDGET (s)) != NULL) && \
|
||||||
|
GTK_IS_NOTEBOOK (gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (s)))))
|
||||||
|
|
||||||
const GDBusInterfaceVTable *
|
const GDBusInterfaceVTable *
|
||||||
gtk_atspi_get_selection_vtable (GtkAccessible *accessible)
|
gtk_atspi_get_selection_vtable (GtkAccessible *accessible,
|
||||||
|
GtkAccessibleRole role)
|
||||||
{
|
{
|
||||||
if (GTK_IS_LIST_BOX (accessible))
|
if (GTK_IS_LIST_BOX (accessible))
|
||||||
return &listbox_vtable;
|
return &listbox_vtable;
|
||||||
@ -592,6 +725,8 @@ gtk_atspi_get_selection_vtable (GtkAccessible *accessible)
|
|||||||
return &combobox_vtable;
|
return &combobox_vtable;
|
||||||
else if (GTK_IS_STACK_SWITCHER (accessible))
|
else if (GTK_IS_STACK_SWITCHER (accessible))
|
||||||
return &stackswitcher_vtable;
|
return &stackswitcher_vtable;
|
||||||
|
else if (IS_NOTEBOOK_TAB_LIST (accessible, role))
|
||||||
|
return ¬ebook_vtable;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -654,6 +789,19 @@ gtk_atspi_connect_selection_signals (GtkAccessible *accessible,
|
|||||||
|
|
||||||
g_signal_connect_swapped (accessible, "notify::visible-child", G_CALLBACK (selection_changed), data);
|
g_signal_connect_swapped (accessible, "notify::visible-child", G_CALLBACK (selection_changed), data);
|
||||||
}
|
}
|
||||||
|
else if (IS_NOTEBOOK_TAB_LIST (accessible, GTK_AT_CONTEXT (data)->accessible_role))
|
||||||
|
{
|
||||||
|
GtkWidget *notebook = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (accessible)));
|
||||||
|
SelectionChanged *changed;
|
||||||
|
|
||||||
|
changed = g_new (SelectionChanged, 1);
|
||||||
|
changed->changed = selection_changed;
|
||||||
|
changed->data = data;
|
||||||
|
|
||||||
|
g_object_set_data_full (G_OBJECT (accessible), "accessible-selection-data", changed, g_free);
|
||||||
|
|
||||||
|
g_signal_connect_swapped (notebook, "notify::page", G_CALLBACK (selection_changed), data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -670,6 +818,17 @@ gtk_atspi_disconnect_selection_signals (GtkAccessible *accessible)
|
|||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (accessible, changed->changed, changed->data);
|
g_signal_handlers_disconnect_by_func (accessible, changed->changed, changed->data);
|
||||||
|
|
||||||
|
g_object_set_data (G_OBJECT (accessible), "accessible-selection-data", NULL);
|
||||||
|
}
|
||||||
|
else if (IS_NOTEBOOK_TAB_LIST (accessible, gtk_accessible_get_accessible_role (accessible)))
|
||||||
|
{
|
||||||
|
GtkWidget *notebook = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (accessible)));
|
||||||
|
SelectionChanged *changed;
|
||||||
|
|
||||||
|
changed = g_object_get_data (G_OBJECT (accessible), "accessible-selection-data");
|
||||||
|
|
||||||
|
g_signal_handlers_disconnect_by_func (notebook, changed->changed, changed->data);
|
||||||
|
|
||||||
g_object_set_data (G_OBJECT (accessible), "accessible-selection-data", NULL);
|
g_object_set_data (G_OBJECT (accessible), "accessible-selection-data", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
const GDBusInterfaceVTable *gtk_atspi_get_selection_vtable (GtkAccessible *accessible);
|
const GDBusInterfaceVTable *gtk_atspi_get_selection_vtable (GtkAccessible *accessible,
|
||||||
|
GtkAccessibleRole role);
|
||||||
|
|
||||||
typedef void (GtkAtspiSelectionCallback) (gpointer data);
|
typedef void (GtkAtspiSelectionCallback) (gpointer data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user