aboutsummaryrefslogtreecommitdiffstats
path: root/a11y/e-table/gal-a11y-e-table-column-header.c
blob: 5f060e9cde8f4e1fb1410f8c2975556745b6ab2e (plain) (blame)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* Evolution Accessibility: gal-a11y-e-table-column-header.h
 *
 * Author: Li Yuan <li.yuan@sun.com>
 *
 */

#include <config.h>
#include <glib/gi18n.h>
#include <atk/atkobject.h>
#include <atk/atkregistry.h>
#include "table/e-table-header-item.h"
#include "a11y/gal-a11y-util.h"
#include "gal-a11y-e-table-column-header.h"

static GObjectClass *parent_class;
static gint priv_offset;

#define GET_PRIVATE(object) ((GalA11yETableColumnHeaderPrivate *) (((char *) object) + priv_offset))
#define PARENT_TYPE (atk_gobject_accessible_get_type ())

struct _GalA11yETableColumnHeaderPrivate {
    ETableItem *item;
    AtkObject  *parent;
    AtkStateSet *state_set;
};

static void
etch_init (GalA11yETableColumnHeader *a11y)
{
    GET_PRIVATE (a11y)->item = NULL;
    GET_PRIVATE (a11y)->parent = NULL;
    GET_PRIVATE (a11y)->state_set = NULL;
}

static AtkStateSet *
gal_a11y_e_table_column_header_ref_state_set (AtkObject *accessible)
{
    GalA11yETableColumnHeaderPrivate *priv = GET_PRIVATE (accessible);

    g_return_val_if_fail (priv->state_set, NULL);

    g_object_ref(priv->state_set);

    return priv->state_set;
}

static void
gal_a11y_e_table_column_header_real_initialize (AtkObject *obj, gpointer data)
{
    ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);
}

static void
gal_a11y_e_table_column_header_dispose (GObject *object)
{
    GalA11yETableColumnHeader *a11y = GAL_A11Y_E_TABLE_COLUMN_HEADER (object);
    GalA11yETableColumnHeaderPrivate *priv = GET_PRIVATE (a11y);

    if (priv->state_set) {
        g_object_unref (priv->state_set);
        priv->state_set = NULL;
    }

    if (parent_class->dispose)
        parent_class->dispose (object);

}

static void
etch_class_init (GalA11yETableColumnHeaderClass *klass)
{
    AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    parent_class = g_type_class_ref (PARENT_TYPE);

    object_class->dispose = gal_a11y_e_table_column_header_dispose;

    class->ref_state_set = gal_a11y_e_table_column_header_ref_state_set;
    class->initialize = gal_a11y_e_table_column_header_real_initialize;
}

inline static GObject *
etch_a11y_get_gobject (AtkGObjectAccessible *accessible)
{
    return atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible));
}

static gboolean
gal_a11y_e_table_column_header_do_action (AtkAction *action,
                      gint      i)
{
    gboolean return_value = TRUE;
    GtkWidget *widget;
    GalA11yETableColumnHeader *a11y;
    ETableHeaderItem *ethi;
    ETableItem *item;
    ETableCol *col;

    switch (i) {
        case 0:
            a11y = GAL_A11Y_E_TABLE_COLUMN_HEADER (action);
            col = E_TABLE_COL (etch_a11y_get_gobject (ATK_GOBJECT_ACCESSIBLE (a11y)));
            item = GET_PRIVATE (a11y)->item;
            widget = gtk_widget_get_parent (GTK_WIDGET (item->parent.canvas));
            if (E_IS_TREE (widget)) {
                ethi = E_TABLE_HEADER_ITEM (e_tree_get_header_item (E_TREE (widget)));
            }
            else if (E_IS_TABLE (widget))
                ethi = E_TABLE_HEADER_ITEM (E_TABLE (widget)->header_item);
            else
                break;
            ethi_change_sort_state (ethi, col);
        default:
            return_value = FALSE;
            break;
    }
    return return_value;
}

static gint
gal_a11y_e_table_column_header_get_n_actions (AtkAction *action)
{
    return 1;
}

static G_CONST_RETURN gchar*
gal_a11y_e_table_column_header_action_get_name (AtkAction *action,
                        gint      i)
{
    G_CONST_RETURN gchar *return_value;

    switch (i) {
        case 0:
            return_value = _("sort");
            break;
        default:
            return_value = NULL;
            break;
    }
    return return_value;
}

static void
atk_action_interface_init (AtkActionIface *iface)
{
    g_return_if_fail (iface != NULL);

    iface->do_action = gal_a11y_e_table_column_header_do_action;
    iface->get_n_actions = gal_a11y_e_table_column_header_get_n_actions;
    iface->get_name = gal_a11y_e_table_column_header_action_get_name;
}

GType
gal_a11y_e_table_column_header_get_type (void)
{
    static GType type = 0;

    if (!type) {
        GTypeInfo info = {
            sizeof (GalA11yETableColumnHeaderClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) etch_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,
            sizeof (GalA11yETableColumnHeader),
            0,
            (GInstanceInitFunc) etch_init,
            NULL
        };
        static const GInterfaceInfo atk_action_info = {
            (GInterfaceInitFunc) atk_action_interface_init,
            (GInterfaceFinalizeFunc) NULL,
            NULL
        };

        type = gal_a11y_type_register_static_with_private (PARENT_TYPE, "GalA11yETableColumnHeader", &info, 0,
                                sizeof (GalA11yETableColumnHeaderPrivate), &priv_offset);

        g_type_add_interface_static (type, ATK_TYPE_ACTION, &atk_action_info);
    }

    return type;
}

AtkObject *
gal_a11y_e_table_column_header_new (ETableCol *ecol, ETableItem *item)
{
    GalA11yETableColumnHeader *a11y;
    AtkObject *accessible;

    g_return_val_if_fail (E_IS_TABLE_COL (ecol), NULL);

    a11y = g_object_new (gal_a11y_e_table_column_header_get_type(), NULL);
    accessible  = ATK_OBJECT (a11y);
    atk_object_initialize (accessible, ecol);

    GET_PRIVATE (a11y)->item = item;
    GET_PRIVATE (a11y)->state_set = atk_state_set_new ();

    atk_state_set_add_state (GET_PRIVATE(a11y)->state_set, ATK_STATE_VISIBLE);
    atk_state_set_add_state (GET_PRIVATE(a11y)->state_set, ATK_STATE_SHOWING);
    atk_state_set_add_state (GET_PRIVATE(a11y)->state_set, ATK_STATE_SENSITIVE);
    atk_state_set_add_state (GET_PRIVATE(a11y)->state_set, ATK_STATE_ENABLED);

    if (ecol->text)
        atk_object_set_name (accessible, ecol->text);
    atk_object_set_role (accessible, ATK_ROLE_TABLE_COLUMN_HEADER);

    return ATK_OBJECT (a11y);
}