aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/ea-calendar.c
blob: dcdf8bd65057c2970ba21eb12a47806426a614f5 (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
/*
 * This program 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) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *      Bolian Yin <bolian.yin@sun.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include <text/e-text.h>
#include <libgnomecanvas/gnome-canvas-pixbuf.h>
#include "ea-calendar-helpers.h"
#include "a11y/ea-factory.h"
#include "ea-calendar.h"

#include "calendar/gui/ea-cal-view.h"
#include "calendar/gui/ea-cal-view-event.h"
#include "calendar/gui/ea-day-view.h"
#include "calendar/gui/ea-day-view-main-item.h"
#include "calendar/gui/ea-week-view.h"
#include "calendar/gui/ea-week-view-main-item.h"
#include "calendar/gui/ea-gnome-calendar.h"

EA_FACTORY (EA_TYPE_CAL_VIEW, ea_cal_view, ea_cal_view_new)
EA_FACTORY (EA_TYPE_DAY_VIEW, ea_day_view, ea_day_view_new)
EA_FACTORY_GOBJECT (EA_TYPE_DAY_VIEW_MAIN_ITEM, ea_day_view_main_item, ea_day_view_main_item_new)
EA_FACTORY (EA_TYPE_WEEK_VIEW, ea_week_view, ea_week_view_new)
EA_FACTORY_GOBJECT (EA_TYPE_WEEK_VIEW_MAIN_ITEM, ea_week_view_main_item, ea_week_view_main_item_new)
EA_FACTORY (EA_TYPE_GNOME_CALENDAR, ea_gnome_calendar, ea_gnome_calendar_new)

static gboolean ea_calendar_focus_watcher (GSignalInvocationHint *ihint,
                       guint n_param_values,
                       const GValue *param_values,
                       gpointer data);

static gpointer e_text_type, pixbuf_type, e_day_view_type, e_week_view_type;
static gpointer e_day_view_main_item_type, e_week_view_main_item_type;

void
gnome_calendar_a11y_init (void)
{
    /* we only add focus watcher when accessibility is enabled
     */
    if (atk_get_root ()) {
        EA_SET_FACTORY (gnome_calendar_get_type(), ea_gnome_calendar);

        /* force loading some types */
        e_text_type = g_type_class_ref (E_TYPE_TEXT);
        pixbuf_type = g_type_class_ref (GNOME_TYPE_CANVAS_PIXBUF);
        e_day_view_type = g_type_class_ref (e_day_view_get_type ());
        e_week_view_type = g_type_class_ref (E_TYPE_WEEK_VIEW);
        e_day_view_main_item_type = g_type_class_ref (e_day_view_main_item_get_type ());
        e_week_view_main_item_type = g_type_class_ref (e_week_view_main_item_get_type ());

        g_signal_add_emission_hook (g_signal_lookup ("event", E_TYPE_TEXT),
                        0, ea_calendar_focus_watcher,
                        NULL, (GDestroyNotify) NULL);
        g_signal_add_emission_hook (g_signal_lookup ("event", GNOME_TYPE_CANVAS_PIXBUF),
                                            0, ea_calendar_focus_watcher,
                                            NULL, (GDestroyNotify) NULL);
        g_signal_add_emission_hook (g_signal_lookup ("event-after",
                                 e_day_view_get_type()),
                        0, ea_calendar_focus_watcher,
                        NULL, (GDestroyNotify) NULL);
        g_signal_add_emission_hook (g_signal_lookup ("event",
                                 e_day_view_main_item_get_type()),
                        0, ea_calendar_focus_watcher,
                        NULL, (GDestroyNotify) NULL);
        g_signal_add_emission_hook (g_signal_lookup ("event-after",
                                 E_TYPE_WEEK_VIEW),
                        0, ea_calendar_focus_watcher,
                        NULL, (GDestroyNotify) NULL);
        g_signal_add_emission_hook (g_signal_lookup ("event",
                                 e_week_view_main_item_get_type()),
                        0, ea_calendar_focus_watcher,
                        NULL, (GDestroyNotify) NULL);

    }
}

void
e_cal_view_a11y_init (void)
{
    EA_SET_FACTORY (e_calendar_view_get_type(), ea_cal_view);
}

void
e_day_view_a11y_init (void)
{
    EA_SET_FACTORY (e_day_view_get_type(), ea_day_view);
}

void
e_day_view_main_item_a11y_init (void)
{
    EA_SET_FACTORY (e_day_view_main_item_get_type (), ea_day_view_main_item);
}

void
e_week_view_a11y_init (void)
{
    EA_SET_FACTORY (E_TYPE_WEEK_VIEW, ea_week_view);
}

void
e_week_view_main_item_a11y_init (void)
{
    EA_SET_FACTORY (e_week_view_main_item_get_type (), ea_week_view_main_item);
}

static gboolean
ea_calendar_focus_watcher (GSignalInvocationHint *ihint,
                           guint n_param_values,
                           const GValue *param_values,
                           gpointer data)
{
    GObject *object;
    GdkEvent *event;
        AtkObject *ea_event = NULL;

    object = g_value_get_object (param_values + 0);
    event = g_value_get_boxed (param_values + 1);

    if ((E_IS_TEXT (object)) || (GNOME_IS_CANVAS_PIXBUF (object))) {
        /* "event" signal on canvas item
         */
        GnomeCanvasItem *canvas_item;

        canvas_item = GNOME_CANVAS_ITEM (object);
        if (event->type == GDK_FOCUS_CHANGE) {
            if (event->focus_change.in) {
                ea_event =
                    ea_calendar_helpers_get_accessible_for (canvas_item);
                if (!ea_event)
                    /* not canvas item we want */
                    return TRUE;

            }
            atk_focus_tracker_notify (ea_event);
        }
    }
    else if (E_IS_DAY_VIEW (object)) {
        EDayView *day_view = E_DAY_VIEW (object);
        if (event->type == GDK_FOCUS_CHANGE) {
            if (event->focus_change.in) {
                /* give main item chance to emit focus */
                gnome_canvas_item_grab_focus (day_view->main_canvas_item);
            }
        }
    }
    else if (E_IS_DAY_VIEW_MAIN_ITEM (object)) {
        if (event->type == GDK_FOCUS_CHANGE) {
            if (event->focus_change.in) {
                /* we should emit focus on main item */
                ea_event = atk_gobject_accessible_for_object (object);
            }
            else
                /* focus out */
                ea_event = NULL;
#ifdef ACC_DEBUG
            printf ("EvoAcc: focus notify on day main item %p\n", (gpointer)object);
#endif
            atk_focus_tracker_notify (ea_event);
        }
    } else if (E_IS_WEEK_VIEW (object)) {
        EWeekView *week_view = E_WEEK_VIEW (object);
        if (event->type == GDK_FOCUS_CHANGE) {
            if (event->focus_change.in) {
                /* give main item chance to emit focus */
                gnome_canvas_item_grab_focus (week_view->main_canvas_item);
            }
        }
    }
    else if (E_IS_WEEK_VIEW_MAIN_ITEM (object)) {
        if (event->type == GDK_FOCUS_CHANGE) {
            if (event->focus_change.in) {
                /* we should emit focus on main item */
                ea_event = atk_gobject_accessible_for_object (object);
            }
            else
                /* focus out */
                ea_event = NULL;
#ifdef ACC_DEBUG
            printf ("EvoAcc: focus notify on week main item %p\n", (gpointer)object);
#endif
            atk_focus_tracker_notify (ea_event);
        }
    }
    return TRUE;
}