atspi: Implement Selection for GtkStackSwitcher
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "gtklistbox.h"
|
||||
#include "gtkflowbox.h"
|
||||
#include "gtkcombobox.h"
|
||||
#include "gtkstackswitcher.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
@@ -459,6 +460,127 @@ static const GDBusInterfaceVTable combobox_vtable = {
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
stackswitcher_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);
|
||||
GtkStack *stack = gtk_stack_switcher_get_stack (GTK_STACK_SWITCHER (widget));
|
||||
|
||||
if (g_strcmp0 (method_name, "GetSelectedChild") == 0)
|
||||
{
|
||||
guint i, n;
|
||||
GtkSelectionModel *pages;
|
||||
GtkWidget *child;
|
||||
|
||||
pages = gtk_stack_get_pages (stack);
|
||||
n = g_list_model_get_n_items (G_LIST_MODEL (pages));
|
||||
for (i = 0, child = gtk_widget_get_first_child (widget);
|
||||
i < n && child;
|
||||
i++, child = gtk_widget_get_next_sibling (child))
|
||||
{
|
||||
if (gtk_selection_model_is_selected (pages, i))
|
||||
break;
|
||||
}
|
||||
g_object_unref (pages);
|
||||
|
||||
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 idx;
|
||||
GtkSelectionModel *pages;
|
||||
|
||||
g_variant_get (parameters, "(i)", &idx);
|
||||
|
||||
pages = gtk_stack_get_pages (stack);
|
||||
gtk_selection_model_select_item (pages, idx, TRUE);
|
||||
g_object_unref (pages);
|
||||
|
||||
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 idx;
|
||||
GtkSelectionModel *pages;
|
||||
gboolean active;
|
||||
|
||||
g_variant_get (parameters, "(i)", &idx);
|
||||
|
||||
pages = gtk_stack_get_pages (stack);
|
||||
active = gtk_selection_model_is_selected (pages, idx);
|
||||
g_object_unref (pages);
|
||||
|
||||
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 *
|
||||
stackswitcher_get_property (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *property_name,
|
||||
GError **error,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkATContext *self = GTK_AT_CONTEXT (user_data);
|
||||
GtkAccessible *accessible = gtk_at_context_get_accessible (self);
|
||||
GtkWidget *widget = GTK_WIDGET (accessible);
|
||||
|
||||
if (g_strcmp0 (property_name, "NSelectedChildren") == 0)
|
||||
{
|
||||
GtkStack *stack = gtk_stack_switcher_get_stack (GTK_STACK_SWITCHER (widget));
|
||||
|
||||
if (stack == NULL || gtk_stack_get_visible_child (stack) == NULL)
|
||||
return g_variant_new_int32 (0);
|
||||
else
|
||||
return g_variant_new_int32 (1);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static const GDBusInterfaceVTable stackswitcher_vtable = {
|
||||
stackswitcher_handle_method,
|
||||
stackswitcher_get_property,
|
||||
NULL
|
||||
};
|
||||
|
||||
const GDBusInterfaceVTable *
|
||||
gtk_atspi_get_selection_vtable (GtkAccessible *accessible)
|
||||
{
|
||||
@@ -468,6 +590,8 @@ gtk_atspi_get_selection_vtable (GtkAccessible *accessible)
|
||||
return &flowbox_vtable;
|
||||
else if (GTK_IS_COMBO_BOX (accessible))
|
||||
return &combobox_vtable;
|
||||
else if (GTK_IS_STACK_SWITCHER (accessible))
|
||||
return &stackswitcher_vtable;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -518,6 +642,18 @@ gtk_atspi_connect_selection_signals (GtkAccessible *accessible,
|
||||
|
||||
g_signal_connect_swapped (accessible, "changed", G_CALLBACK (selection_changed), data);
|
||||
}
|
||||
else if (GTK_IS_STACK_SWITCHER (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 (accessible, "notify::visible-child", G_CALLBACK (selection_changed), data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -525,7 +661,8 @@ gtk_atspi_disconnect_selection_signals (GtkAccessible *accessible)
|
||||
{
|
||||
if (GTK_IS_LIST_BOX (accessible) ||
|
||||
GTK_IS_FLOW_BOX (accessible) ||
|
||||
GTK_IS_COMBO_BOX (accessible))
|
||||
GTK_IS_COMBO_BOX (accessible) ||
|
||||
GTK_IS_STACK_SWITCHER (accessible))
|
||||
{
|
||||
SelectionChanged *changed;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user