aboutsummaryrefslogtreecommitdiffstats
path: root/a11y/calendar/ea-cal-view.c
blob: f31d24cc55e432ae10aa5541ef44a0714e1ed99d (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* vim:expandtab:shiftwidth=8:tabstop=8:
 */
/* Evolution Accessibility: ea-cal-view.c
 *
 * Copyright (C) 2003 Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Bolian Yin <bolian.yin@sun.com> Sun Microsystem Inc., 2003
 *
 */

#include "ea-cal-view.h"
#include "ea-calendar-helpers.h"
#include "e-day-view.h"
#include "e-week-view.h"
#include "calendar-commands.h"
#include <glib/gstrfuncs.h>

static void ea_cal_view_class_init (EaCalViewClass *klass);

static AtkObject* ea_cal_view_get_parent (AtkObject *accessible);
static gint ea_cal_view_get_index_in_parent (AtkObject *accessible);
static void ea_cal_view_real_initialize (AtkObject *accessible, gpointer data);

static void ea_cal_view_event_changed_cb (ECalView *cal_view,
                                          ECalViewEvent *event, gpointer data);
static void ea_cal_view_event_added_cb (ECalView *cal_view,
                                        ECalViewEvent *event, gpointer data);

static void ea_cal_view_dates_change_cb (GnomeCalendar *gcal, gpointer data);

static gpointer parent_class = NULL;

GType
ea_cal_view_get_type (void)
{
    static GType type = 0;
    AtkObjectFactory *factory;
    GTypeQuery query;
    GType derived_atk_type;

    if (!type) {
        static GTypeInfo tinfo = {
            sizeof (EaCalViewClass),
            (GBaseInitFunc) NULL, /* base init */
            (GBaseFinalizeFunc) NULL, /* base finalize */
            (GClassInitFunc) ea_cal_view_class_init, /* class init */
            (GClassFinalizeFunc) NULL, /* class finalize */
            NULL, /* class data */
            sizeof (EaCalView), /* instance size */
            0, /* nb preallocs */
            (GInstanceInitFunc) NULL, /* instance init */
            NULL /* value table */
        };

        /*
         * Figure out the size of the class and instance
         * we are run-time deriving from (GailWidget, in this case)
         */

        factory = atk_registry_get_factory (atk_get_default_registry (),
                            GTK_TYPE_WIDGET);
        derived_atk_type = atk_object_factory_get_accessible_type (factory);
        g_type_query (derived_atk_type, &query);

        tinfo.class_size = query.class_size;
        tinfo.instance_size = query.instance_size;

        type = g_type_register_static (derived_atk_type,
                           "EaCalView", &tinfo, 0);
    }

    return type;
}

static void
ea_cal_view_class_init (EaCalViewClass *klass)
{
    AtkObjectClass *class = ATK_OBJECT_CLASS (klass);

    parent_class = g_type_class_peek_parent (klass);

    class->get_parent = ea_cal_view_get_parent;
    class->get_index_in_parent = ea_cal_view_get_index_in_parent;
    class->initialize = ea_cal_view_real_initialize;
}

AtkObject* 
ea_cal_view_new (GtkWidget *widget)
{
    GObject *object;
    AtkObject *accessible;

    g_return_val_if_fail (E_IS_CAL_VIEW (widget), NULL);

    object = g_object_new (EA_TYPE_CAL_VIEW, NULL);

    accessible = ATK_OBJECT (object);
    atk_object_initialize (accessible, widget);

    return accessible;
}

static void
ea_cal_view_real_initialize (AtkObject *accessible, gpointer data)
{
    ECalView *cal_view;
    GnomeCalendar *gcal;

    g_return_if_fail (EA_IS_CAL_VIEW (accessible));
    g_return_if_fail (E_IS_CAL_VIEW (data));

        ATK_OBJECT_CLASS (parent_class)->initialize (accessible, data);
    accessible->role = ATK_ROLE_CANVAS;
    cal_view = E_CAL_VIEW (data);

    /* add listener for event_changed, event_added
     * we don't need to listen on event_removed. When the e_text
     * of the event is removed, the cal_view_event will go to the state
     * of "defunct" (changed by weak ref callback of atkgobjectaccessible
     */
    g_signal_connect (G_OBJECT(cal_view), "event_changed",
              G_CALLBACK (ea_cal_view_event_changed_cb), NULL);
    g_signal_connect (G_OBJECT(cal_view), "event_added",
              G_CALLBACK (ea_cal_view_event_added_cb), NULL);

    /* listen for date changes of calendar */
    gcal = e_cal_view_get_calendar (cal_view);

    if (gcal)
        g_signal_connect (gcal, "dates_shown_changed",
                  G_CALLBACK (ea_cal_view_dates_change_cb),
                  accessible);
}

static AtkObject* 
ea_cal_view_get_parent (AtkObject *accessible)
{
    ECalView *cal_view;
    GnomeCalendar *gnomeCalendar;

    g_return_val_if_fail (EA_IS_CAL_VIEW (accessible), NULL);

    if (!GTK_ACCESSIBLE (accessible)->widget)
        return NULL;
    cal_view = E_CAL_VIEW (GTK_ACCESSIBLE (accessible)->widget);

    gnomeCalendar = e_cal_view_get_calendar (cal_view);

    return gtk_widget_get_accessible (GTK_WIDGET(gnomeCalendar));
}

static gint
ea_cal_view_get_index_in_parent (AtkObject *accessible)
{
    return 1;
}

static void
ea_cal_view_event_changed_cb (ECalView *cal_view, ECalViewEvent *event,
                              gpointer data)
{
    AtkObject *atk_obj;
    EaCalView *ea_cal_view;
    AtkObject *event_atk_obj = NULL;

    g_return_if_fail (E_IS_CAL_VIEW (cal_view));

    atk_obj = gtk_widget_get_accessible (GTK_WIDGET(cal_view));
    if (!EA_IS_CAL_VIEW (atk_obj))
        return;
    ea_cal_view = EA_CAL_VIEW (atk_obj);

    if ((E_IS_DAY_VIEW (cal_view)) && event && event->canvas_item) {
        event_atk_obj =
            ea_calendar_helpers_get_accessible_for (event->canvas_item);
    }
    else if ((E_IS_WEEK_VIEW (cal_view)) && event) {
        EWeekViewEventSpan *span;
        EWeekViewEvent *week_view_event = (EWeekViewEvent *)event;
        EWeekView *week_view = E_WEEK_VIEW (cal_view);
        /* get the first span of the event */
        span = &g_array_index (week_view->spans, EWeekViewEventSpan,
                       week_view_event->spans_index);
        if (span && span->text_item)
            event_atk_obj = ea_calendar_helpers_get_accessible_for (span->text_item);
    }
    if (event_atk_obj) {
#ifdef ACC_DEBUG
        printf ("AccDebug: event=%p changed\n", event);
#endif
        g_object_notify (G_OBJECT(event_atk_obj), "accessible-name");
        g_signal_emit_by_name (event_atk_obj, "visible_data_changed");
    }

}

static void
ea_cal_view_event_added_cb (ECalView *cal_view, ECalViewEvent *event,
                            gpointer data)
{
    AtkObject *atk_obj;
    EaCalView *ea_cal_view;
    AtkObject *event_atk_obj = NULL;
    gint index;

    g_return_if_fail (E_IS_CAL_VIEW (cal_view));

    atk_obj = gtk_widget_get_accessible (GTK_WIDGET(cal_view));
    if (!EA_IS_CAL_VIEW (atk_obj))
        return;
    ea_cal_view = EA_CAL_VIEW (atk_obj);

    if ((E_IS_DAY_VIEW (cal_view)) && event && event->canvas_item) {
        event_atk_obj =
            ea_calendar_helpers_get_accessible_for (event->canvas_item);
    }
    else if ((E_IS_WEEK_VIEW (cal_view)) && event) {
        EWeekViewEventSpan *span;
        EWeekViewEvent *week_view_event = (EWeekViewEvent *)event;
        EWeekView *week_view = E_WEEK_VIEW (cal_view);
        /* get the first span of the event */
        span = &g_array_index (week_view->spans, EWeekViewEventSpan,
                       week_view_event->spans_index);
        if (span && span->text_item)
            event_atk_obj = ea_calendar_helpers_get_accessible_for (span->text_item);

    }
    if (event_atk_obj) {
        index = atk_object_get_index_in_parent (event_atk_obj);
        if (index < 0)
            return;
#ifdef ACC_DEBUG
        printf ("AccDebug: event=%p added\n", event);
#endif
        g_signal_emit_by_name (atk_obj, "children_changed::add",
                       index, event_atk_obj, NULL);
    }
}

static void
ea_cal_view_dates_change_cb (GnomeCalendar *gcal, gpointer data)
{
    AtkObject *atk_obj;

    g_return_if_fail (GNOME_IS_CALENDAR (gcal));
    g_return_if_fail (data);
    g_return_if_fail (EA_IS_CAL_VIEW (data));

    atk_obj = ATK_OBJECT(data);
    if (atk_obj->name) {
        g_free (atk_obj->name);
        atk_obj->name = NULL;
    }
    g_object_notify (G_OBJECT (data), "accessible-name");
    g_signal_emit_by_name (data, "visible_data_changed");
}