spinbutton: Implement GtkAccessible

This copies what was done for GtkEntry: get
the focused state from the GtkText within.

We also add a private getter for the text widget,
which was missing here.
This commit is contained in:
Matthias Clasen 2020-10-12 21:34:16 -04:00
parent 852c72fa28
commit 76b87272a6
2 changed files with 65 additions and 0 deletions

View File

@ -29,6 +29,9 @@
#include "gtkspinbutton.h"
#include "gtkspinbuttonprivate.h"
#include "gtkaccessibleprivate.h"
#include "gtkadjustment.h"
#include "gtkbox.h"
#include "gtkbutton.h"
@ -305,12 +308,15 @@ static void gtk_spin_button_default_output (GtkSpinButton *spin_button);
static void gtk_spin_button_update_width_chars (GtkSpinButton *spin_button);
static void gtk_spin_button_accessible_init (GtkAccessibleInterface *iface);
static guint spinbutton_signals[LAST_SIGNAL] = {0};
static GParamSpec *spinbutton_props[NUM_SPINBUTTON_PROPS] = {NULL, };
G_DEFINE_TYPE_WITH_CODE (GtkSpinButton, gtk_spin_button, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE,
gtk_spin_button_accessible_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
gtk_spin_button_editable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
@ -572,6 +578,31 @@ gtk_spin_button_editable_init (GtkEditableInterface *iface)
iface->insert_text = gtk_spin_button_insert_text;
}
static gboolean
gtk_spin_button_accessible_get_platform_state (GtkAccessible *self,
GtkAccessiblePlatformState state)
{
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (self);
switch (state)
{
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE:
return gtk_widget_get_focusable (spin_button->entry);
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return gtk_widget_has_focus (spin_button->entry);
default:
g_assert_not_reached ();
}
}
static void
gtk_spin_button_accessible_init (GtkAccessibleInterface *iface)
{
GtkAccessibleInterface *parent_iface = g_type_interface_peek_parent (iface);
iface->get_at_context = parent_iface->get_at_context;
iface->get_platform_state = gtk_spin_button_accessible_get_platform_state;
}
static void
gtk_cell_editable_spin_button_activated (GtkText *text, GtkSpinButton *spin)
{
@ -2310,3 +2341,10 @@ gtk_spin_button_update (GtkSpinButton *spin_button)
else
gtk_spin_button_set_value (spin_button, val);
}
GtkText *
gtk_spin_button_get_text_widget (GtkSpinButton *spin_button)
{
return GTK_TEXT (spin_button->entry);
}

View File

@ -0,0 +1,27 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <gtk/gtkspinbutton.h>
#include <gtk/gtktext.h>
G_BEGIN_DECLS
GtkText *gtk_spin_button_get_text_widget (GtkSpinButton *spin_button);
G_END_DECLS