[gtk/a11y/atspi] atspi: Implement Selection for GtkFlowBox
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/a11y/atspi] atspi: Implement Selection for GtkFlowBox
- Date: Tue, 13 Oct 2020 21:26:56 +0000 (UTC)
commit b15328e0d653a7c0bf5685598d0e1743abca44df
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 13 17:22:05 2020 -0400
atspi: Implement Selection for GtkFlowBox
This is a copy of the listbox implementation.
gtk/a11y/gtkatspiselection.c | 212 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 190 insertions(+), 22 deletions(-)
---
diff --git a/gtk/a11y/gtkatspiselection.c b/gtk/a11y/gtkatspiselection.c
index 351e573482..10de842b89 100644
--- a/gtk/a11y/gtkatspiselection.c
+++ b/gtk/a11y/gtkatspiselection.c
@@ -29,24 +29,25 @@
#include "gtkaccessibleprivate.h"
#include "gtkdebug.h"
#include "gtklistbox.h"
+#include "gtkflowbox.h"
#include "gtkcombobox.h"
#include <gio/gio.h>
typedef struct {
int n;
- GtkListBoxRow *row;
-} RowCounter;
+ GtkWidget *child;
+} Counter;
static void
-find_nth (GtkListBox *box,
- GtkListBoxRow *row,
- gpointer data)
+find_nth (GtkWidget *box,
+ GtkWidget *child,
+ gpointer data)
{
- RowCounter *counter = data;
+ Counter *counter = data;
if (counter->n == 0)
- counter->row = row;
+ counter->child = child;
counter->n--;
}
@@ -67,21 +68,21 @@ listbox_handle_method (GDBusConnection *connection,
if (g_strcmp0 (method_name, "GetSelectedChild") == 0)
{
- RowCounter counter;
+ Counter counter;
int idx;
g_variant_get (parameters, "(i)", &idx);
counter.n = idx;
- counter.row = NULL;
+ counter.child = NULL;
- gtk_list_box_selected_foreach (GTK_LIST_BOX (widget), find_nth, &counter);
+ gtk_list_box_selected_foreach (GTK_LIST_BOX (widget), (GtkListBoxForeachFunc)find_nth, &counter);
- if (counter.row == NULL)
+ if (counter.child == NULL)
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
selected child for %d", idx);
else
{
- GtkATContext *ctx = gtk_accessible_get_at_context (GTK_ACCESSIBLE (counter.row));
+ GtkATContext *ctx = gtk_accessible_get_at_context (GTK_ACCESSIBLE (counter.child));
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(@(so))",
gtk_at_spi_context_to_ref (GTK_AT_SPI_CONTEXT (ctx))));
}
}
@@ -125,24 +126,24 @@ listbox_handle_method (GDBusConnection *connection,
}
else if (g_strcmp0 (method_name, "DeselectSelectedChild") == 0)
{
- RowCounter counter;
+ Counter counter;
int idx;
g_variant_get (parameters, "(i)", &idx);
counter.n = idx;
- counter.row = NULL;
+ counter.child = NULL;
- gtk_list_box_selected_foreach (GTK_LIST_BOX (widget), find_nth, &counter);
+ gtk_list_box_selected_foreach (GTK_LIST_BOX (widget), (GtkListBoxForeachFunc)find_nth, &counter);
- if (counter.row == NULL)
+ if (counter.child == NULL)
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
selected child for %d", idx);
else
{
gboolean ret;
- gtk_list_box_unselect_row (GTK_LIST_BOX (widget), counter.row);
- ret = !gtk_list_box_row_is_selected (counter.row);
+ gtk_list_box_unselect_row (GTK_LIST_BOX (widget), GTK_LIST_BOX_ROW (counter.child));
+ ret = !gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (counter.child));
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", ret));
}
}
@@ -172,9 +173,9 @@ listbox_handle_method (GDBusConnection *connection,
}
static void
-count_selected (GtkListBox *box,
- GtkListBoxRow *row,
- gpointer data)
+count_selected (GtkWidget *box,
+ GtkWidget *child,
+ gpointer data)
{
*(int *)data += 1;
}
@@ -196,7 +197,7 @@ listbox_get_property (GDBusConnection *connection,
{
int count = 0;
- gtk_list_box_selected_foreach (GTK_LIST_BOX (widget), count_selected, &count);
+ gtk_list_box_selected_foreach (GTK_LIST_BOX (widget), (GtkListBoxForeachFunc)count_selected, &count);
return g_variant_new_int32 (count);
}
@@ -211,6 +212,158 @@ static const GDBusInterfaceVTable listbox_vtable = {
};
+static void
+flowbox_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);
+
+ if (g_strcmp0 (method_name, "GetSelectedChild") == 0)
+ {
+ Counter counter;
+ int idx;
+
+ g_variant_get (parameters, "(i)", &idx);
+
+ counter.n = idx;
+ counter.child = NULL;
+
+ gtk_flow_box_selected_foreach (GTK_FLOW_BOX (widget), (GtkFlowBoxForeachFunc)find_nth, &counter);
+
+ if (counter.child == NULL)
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
selected child for %d", idx);
+ else
+ {
+ GtkATContext *ctx = gtk_accessible_get_at_context (GTK_ACCESSIBLE (counter.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;
+ GtkFlowBoxChild *child;
+
+ g_variant_get (parameters, "(i)", &idx);
+
+ child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (widget), idx);
+ if (!child)
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
child at position %d", idx);
+ else
+ {
+ gboolean ret;
+
+ gtk_flow_box_select_child (GTK_FLOW_BOX (widget), child);
+ ret = gtk_flow_box_child_is_selected (child);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", ret));
+ }
+ }
+ else if (g_strcmp0 (method_name, "DeselectChild") == 0)
+ {
+ int idx;
+ GtkFlowBoxChild *child;
+
+ g_variant_get (parameters, "(i)", &idx);
+
+ child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (widget), idx);
+ if (!child)
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
child at position %d", idx);
+ else
+ {
+ gboolean ret;
+
+ gtk_flow_box_unselect_child (GTK_FLOW_BOX (widget), child);
+ ret = !gtk_flow_box_child_is_selected (child);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", ret));
+ }
+ }
+ else if (g_strcmp0 (method_name, "DeselectSelectedChild") == 0)
+ {
+ Counter counter;
+ int idx;
+
+ g_variant_get (parameters, "(i)", &idx);
+
+ counter.n = idx;
+ counter.child = NULL;
+
+ gtk_flow_box_selected_foreach (GTK_FLOW_BOX (widget), (GtkFlowBoxForeachFunc)find_nth, &counter);
+
+ if (counter.child == NULL)
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
selected child for %d", idx);
+ else
+ {
+ gboolean ret;
+
+ gtk_flow_box_unselect_child (GTK_FLOW_BOX (widget), GTK_FLOW_BOX_CHILD (counter.child));
+ ret = !gtk_flow_box_child_is_selected (GTK_FLOW_BOX_CHILD (counter.child));
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", ret));
+ }
+ }
+ else if (g_strcmp0 (method_name, "IsChildSelected") == 0)
+ {
+ int idx;
+ GtkFlowBoxChild *child;
+
+ g_variant_get (parameters, "(i)", &idx);
+
+ child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (widget), idx);
+ if (!child)
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No
child at position %d", idx);
+ else
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)",
gtk_flow_box_child_is_selected (child)));
+ }
+ else if (g_strcmp0 (method_name, "SelectAll") == 0)
+ {
+ gtk_flow_box_select_all (GTK_FLOW_BOX (widget));
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+ }
+ else if (g_strcmp0 (method_name, "ClearSelection") == 0)
+ {
+ gtk_flow_box_unselect_all (GTK_FLOW_BOX (widget));
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+ }
+}
+
+static GVariant *
+flowbox_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)
+ {
+ int count = 0;
+
+ gtk_flow_box_selected_foreach (GTK_FLOW_BOX (widget), (GtkFlowBoxForeachFunc)count_selected, &count);
+
+ return g_variant_new_int32 (count);
+ }
+
+ return NULL;
+}
+
+static const GDBusInterfaceVTable flowbox_vtable = {
+ flowbox_handle_method,
+ flowbox_get_property,
+ NULL
+};
+
+
static void
combobox_handle_method (GDBusConnection *connection,
const gchar *sender,
@@ -311,6 +464,8 @@ gtk_atspi_get_selection_vtable (GtkWidget *widget)
{
if (GTK_IS_LIST_BOX (widget))
return &listbox_vtable;
+ else if (GTK_IS_FLOW_BOX (widget))
+ return &flowbox_vtable;
else if (GTK_IS_COMBO_BOX (widget))
return &combobox_vtable;
@@ -339,6 +494,18 @@ gtk_atspi_connect_selection_signals (GtkWidget *widget,
g_signal_connect_swapped (widget, "selected-rows-changed", G_CALLBACK (selection_changed), data);
}
+ else if (GTK_IS_FLOW_BOX (widget))
+ {
+ SelectionChanged *changed;
+
+ changed = g_new (SelectionChanged, 1);
+ changed->changed = selection_changed;
+ changed->data = data;
+
+ g_object_set_data_full (G_OBJECT (widget), "accessible-selection-data", changed, g_free);
+
+ g_signal_connect_swapped (widget, "selected-children-changed", G_CALLBACK (selection_changed), data);
+ }
else if (GTK_IS_COMBO_BOX (widget))
{
SelectionChanged *changed;
@@ -357,6 +524,7 @@ void
gtk_atspi_disconnect_selection_signals (GtkWidget *widget)
{
if (GTK_IS_LIST_BOX (widget) ||
+ GTK_IS_FLOW_BOX (widget) ||
GTK_IS_COMBO_BOX (widget))
{
SelectionChanged *changed;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]