~robert-ancell/unity-control-center/color-panel-3.10

« back to all changes in this revision

Viewing changes to panels/color/egg-list-box-accessible.c

  • Committer: Robert Ancell
  • Date: 2014-02-21 01:36:38 UTC
  • Revision ID: robert.ancell@canonical.com-20140221013638-x2beiw9hhfa46tdg
Backport Color panel from GNOME Control Center 3.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 Red Hat, Inc.
3
 
 *
4
 
 * This library is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU Lesser General Public
6
 
 * License as published by the Free Software Foundation; either
7
 
 * version 2 of the License, or (at your option) any later version.
8
 
 *
9
 
 * This library is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * Lesser General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#include "egg-list-box.h"
19
 
#include "egg-list-box-accessible.h"
20
 
 
21
 
static void atk_selection_interface_init (AtkSelectionIface *iface);
22
 
 
23
 
G_DEFINE_TYPE_WITH_CODE (EggListBoxAccessible, egg_list_box_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
24
 
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
25
 
 
26
 
static void
27
 
egg_list_box_accessible_init (EggListBoxAccessible *accessible)
28
 
{
29
 
}
30
 
 
31
 
static void
32
 
egg_list_box_accessible_initialize (AtkObject *obj,
33
 
                                    gpointer   data)
34
 
{
35
 
  ATK_OBJECT_CLASS (egg_list_box_accessible_parent_class)->initialize (obj, data);
36
 
 
37
 
  obj->role = ATK_ROLE_LIST_BOX;
38
 
}
39
 
 
40
 
static AtkStateSet*
41
 
egg_list_box_accessible_ref_state_set (AtkObject *obj)
42
 
{
43
 
  AtkStateSet *state_set;
44
 
  GtkWidget *widget;
45
 
 
46
 
  state_set = ATK_OBJECT_CLASS (egg_list_box_accessible_parent_class)->ref_state_set (obj);
47
 
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
48
 
 
49
 
  if (widget != NULL)
50
 
    atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
51
 
 
52
 
  return state_set;
53
 
}
54
 
 
55
 
static void
56
 
egg_list_box_accessible_class_init (EggListBoxAccessibleClass *klass)
57
 
{
58
 
  AtkObjectClass *object_class = ATK_OBJECT_CLASS (klass);
59
 
 
60
 
  object_class->initialize = egg_list_box_accessible_initialize;
61
 
  object_class->ref_state_set = egg_list_box_accessible_ref_state_set;
62
 
}
63
 
 
64
 
static gboolean
65
 
egg_list_box_accessible_add_selection (AtkSelection *selection,
66
 
                                       gint          idx)
67
 
{
68
 
  GtkWidget *box;
69
 
  GList *children;
70
 
  GtkWidget *child;
71
 
 
72
 
  box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
73
 
  if (box == NULL)
74
 
    return FALSE;
75
 
 
76
 
  children = gtk_container_get_children (GTK_CONTAINER (box));
77
 
  child = g_list_nth_data (children, idx);
78
 
  g_list_free (children);
79
 
  if (child)
80
 
    {
81
 
      egg_list_box_select_child (EGG_LIST_BOX (box), child);
82
 
      return TRUE;
83
 
    }
84
 
  return FALSE;
85
 
}
86
 
 
87
 
static gboolean
88
 
egg_list_box_accessible_clear_selection (AtkSelection *selection)
89
 
{
90
 
  GtkWidget *box;
91
 
 
92
 
  box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
93
 
  if (box == NULL)
94
 
    return FALSE;
95
 
 
96
 
  egg_list_box_select_child (EGG_LIST_BOX (box), NULL);
97
 
  return TRUE;
98
 
}
99
 
 
100
 
static AtkObject *
101
 
egg_list_box_accessible_ref_selection (AtkSelection *selection,
102
 
                                       gint          idx)
103
 
{
104
 
  GtkWidget *box;
105
 
  GtkWidget *widget;
106
 
  AtkObject *accessible;
107
 
 
108
 
  if (idx != 0)
109
 
    return NULL;
110
 
 
111
 
  box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
112
 
  if (box == NULL)
113
 
    return NULL;
114
 
 
115
 
  widget = egg_list_box_get_selected_child (EGG_LIST_BOX (box));
116
 
  if (widget == NULL)
117
 
    return NULL;
118
 
 
119
 
  accessible = gtk_widget_get_accessible (widget);
120
 
  g_object_ref (accessible);
121
 
  return accessible;
122
 
}
123
 
 
124
 
static gint
125
 
egg_list_box_accessible_get_selection_count (AtkSelection *selection)
126
 
{
127
 
  GtkWidget *box;
128
 
  GtkWidget *widget;
129
 
 
130
 
  box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
131
 
  if (box == NULL)
132
 
    return 0;
133
 
 
134
 
  widget = egg_list_box_get_selected_child (EGG_LIST_BOX (box));
135
 
  if (widget == NULL)
136
 
    return 0;
137
 
 
138
 
  return 1;
139
 
}
140
 
 
141
 
static gboolean
142
 
egg_list_box_accessible_is_child_selected (AtkSelection *selection,
143
 
                                           gint          idx)
144
 
{
145
 
  GtkWidget *box;
146
 
  GtkWidget *widget;
147
 
  GList *children;
148
 
  GtkWidget *child;
149
 
 
150
 
  box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
151
 
  if (box == NULL)
152
 
    return FALSE;
153
 
 
154
 
  widget = egg_list_box_get_selected_child (EGG_LIST_BOX (box));
155
 
  if (widget == NULL)
156
 
    return FALSE;
157
 
 
158
 
  children = gtk_container_get_children (GTK_CONTAINER (box));
159
 
  child = g_list_nth_data (children, idx);
160
 
  g_list_free (children);
161
 
  return child == widget;
162
 
}
163
 
 
164
 
static void atk_selection_interface_init (AtkSelectionIface *iface)
165
 
{
166
 
  iface->add_selection = egg_list_box_accessible_add_selection;
167
 
  iface->clear_selection = egg_list_box_accessible_clear_selection;
168
 
  iface->ref_selection = egg_list_box_accessible_ref_selection;
169
 
  iface->get_selection_count = egg_list_box_accessible_get_selection_count;
170
 
  iface->is_child_selected = egg_list_box_accessible_is_child_selected;
171
 
}
172
 
 
173
 
void
174
 
_egg_list_box_accessible_update_selected (EggListBox *box,
175
 
                                          GtkWidget  *child)
176
 
{
177
 
  AtkObject *accessible;
178
 
  accessible = gtk_widget_get_accessible (GTK_WIDGET (box));
179
 
  g_signal_emit_by_name (accessible, "selection-changed");
180
 
}
181
 
 
182
 
void
183
 
_egg_list_box_accessible_update_cursor (EggListBox *box,
184
 
                                        GtkWidget  *child)
185
 
{
186
 
  AtkObject *accessible;
187
 
  AtkObject *descendant;
188
 
  accessible = gtk_widget_get_accessible (GTK_WIDGET (box));
189
 
  descendant = child ? gtk_widget_get_accessible (child) : NULL;
190
 
  g_signal_emit_by_name (accessible, "active-descendant-changed", descendant);
191
 
}