1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/* GTK - The GIMP Toolkit
* Copyright © 2014 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/>.
*
* Author: Carlos Garnacho <carlosg@gnome.org>
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include "gtkpopoveraccessible.h"
typedef struct _GtkPopoverAccessiblePrivate GtkPopoverAccessiblePrivate;
struct _GtkPopoverAccessiblePrivate
{
GtkWidget *widget;
};
G_DEFINE_TYPE_WITH_CODE (GtkPopoverAccessible, gtk_popover_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
G_ADD_PRIVATE (GtkPopoverAccessible))
static void
popover_update_relative_to (AtkObject *obj,
GtkPopover *popover)
{
GtkPopoverAccessiblePrivate *priv;
AtkObject *widget_accessible;
GtkWidget *widget;
priv = gtk_popover_accessible_get_instance_private (GTK_POPOVER_ACCESSIBLE (obj));
widget = gtk_popover_get_relative_to (popover);
if (priv->widget == widget)
return;
if (priv->widget)
{
g_object_remove_weak_pointer (G_OBJECT (priv->widget),
(gpointer*) &priv->widget);
widget_accessible = gtk_widget_get_accessible (priv->widget);
atk_object_remove_relationship (obj,
ATK_RELATION_POPUP_FOR,
widget_accessible);
}
priv->widget = widget;
if (widget)
{
AtkObject *parent;
parent = gtk_widget_get_accessible (widget);
if (parent)
atk_object_set_parent (obj, parent);
g_object_add_weak_pointer (G_OBJECT (priv->widget),
(gpointer*) &priv->widget);
widget_accessible = gtk_widget_get_accessible (widget);
atk_object_add_relationship (obj,
ATK_RELATION_POPUP_FOR,
widget_accessible);
}
}
static void
popover_update_modality (AtkObject *object,
GtkPopover *popover)
{
atk_object_notify_state_change (object, ATK_STATE_MODAL,
gtk_popover_get_modal (popover));
}
static void
popover_notify_cb (GtkPopover *popover,
GParamSpec *pspec,
AtkObject *object)
{
AtkObject *popover_accessible;
popover_accessible = gtk_widget_get_accessible (GTK_WIDGET (popover));
if (strcmp (g_param_spec_get_name (pspec), "relative-to") == 0)
popover_update_relative_to (popover_accessible, popover);
else if (strcmp (g_param_spec_get_name (pspec), "modal") == 0)
popover_update_modality (popover_accessible, popover);
}
static void
gtk_popover_accessible_initialize (AtkObject *obj,
gpointer data)
{
GtkPopover *popover = GTK_POPOVER (data);
ATK_OBJECT_CLASS (gtk_popover_accessible_parent_class)->initialize (obj, data);
g_signal_connect (popover, "notify",
G_CALLBACK (popover_notify_cb), obj);
popover_update_relative_to (obj, popover);
popover_update_modality (obj, popover);
obj->role = ATK_ROLE_PANEL;
}
static AtkStateSet *
gtk_popover_accessible_ref_state_set (AtkObject *obj)
{
AtkStateSet *state_set;
GtkWidget *widget;
state_set = ATK_OBJECT_CLASS (gtk_popover_accessible_parent_class)->ref_state_set (obj);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (gtk_popover_get_modal (GTK_POPOVER (widget)))
atk_state_set_add_state (state_set, ATK_STATE_MODAL);
return state_set;
}
static void
gtk_popover_accessible_finalize (GObject *object)
{
GtkPopoverAccessiblePrivate *priv;
priv = gtk_popover_accessible_get_instance_private (GTK_POPOVER_ACCESSIBLE (object));
if (priv->widget)
g_object_remove_weak_pointer (G_OBJECT (priv->widget),
(gpointer*) &priv->widget);
G_OBJECT_CLASS (gtk_popover_accessible_parent_class)->finalize (object);
}
static void
gtk_popover_accessible_class_init (GtkPopoverAccessibleClass *klass)
{
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gtk_popover_accessible_finalize;
class->initialize = gtk_popover_accessible_initialize;
class->ref_state_set = gtk_popover_accessible_ref_state_set;
}
static void
gtk_popover_accessible_init (GtkPopoverAccessible *popover)
{
}
|