aboutsummaryrefslogtreecommitdiffstats
path: root/a11y/calendar/ea-calendar-helpers.c
blob: e8b0d3aa9c75787d0dbb4ba57a3e60d513752a33 (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
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* vim:expandtab:shiftwidth=8:tabstop=8:
 */
/* Evolution Accessibility: ea-calendar-helpers.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-calendar-helpers.h"
#include "ea-cal-view-event.h"
#include "e-day-view.h"
#include "e-week-view.h"

#include <gal/e-text/e-text.h>

/**
 * ea_calendar_helpers_get_accessible_for
 * @canvas_item: the canvas item (e_text) for a event
 * @returns: the atk object for the canvas_item
 * 
 **/
AtkObject *
ea_calendar_helpers_get_accessible_for (GnomeCanvasItem *canvas_item)
{
    AtkObject *atk_obj = NULL;
    GObject *g_obj;

    g_return_val_if_fail (E_IS_TEXT (canvas_item), NULL);

    g_obj = G_OBJECT (canvas_item);
    /* we cannot use atk_gobject_accessible_for_object here,
     * EaDayViewEvent/EaWeekViewEvent cannot be created by the
     * registered facotry of E_TEXT
     */
    atk_obj = g_object_get_data (g_obj, "accessible-object");
    if (!atk_obj)
        atk_obj = ea_cal_view_event_new (g_obj);
    return atk_obj;
}

/**
 * ea_calendar_helpers_get_view_widget_from:
 * @canvas_item: the canvas item (e_text) for a event
 * @returns: the cal view widget if exists
 *
 * Get the cal view widget contains the canvas_item.
 * 
 **/
ECalView *
ea_calendar_helpers_get_cal_view_from (GnomeCanvasItem *canvas_item)
{
    GnomeCanvas *canvas;
    GtkWidget *view_widget = NULL;

    g_return_val_if_fail (canvas_item, NULL);
    g_return_val_if_fail (E_IS_TEXT (canvas_item), NULL);

    /* canvas_item is the e_text for the event */
    /* canvas_item->canvas is the ECanvas for day view */
    /* parent of canvas_item->canvas is the EDayView or EWeekView widget */
    canvas = canvas_item->canvas;
    view_widget = gtk_widget_get_parent (GTK_WIDGET(canvas));
    if (!view_widget || !E_IS_CAL_VIEW (view_widget))
        return NULL;
    return E_CAL_VIEW (view_widget);
}

/**
 * ea_calendar_helpers_get_cal_view_event_from
 * @canvas_item: the cavas_item (e_text) for the event
 * @returns: the ECalViewEvent
 *
 * Get the ECalViewEvent for the canvas_item.
 *
 **/
ECalViewEvent *
ea_calendar_helpers_get_cal_view_event_from (GnomeCanvasItem *canvas_item)
{
    ECalView *cal_view;
    gboolean event_found;
    ECalViewEvent *cal_view_event;

    g_return_val_if_fail (E_IS_TEXT (canvas_item), NULL);

    cal_view = ea_calendar_helpers_get_cal_view_from (canvas_item);

    if (!cal_view)
        return NULL;

    if (E_IS_DAY_VIEW (cal_view)) {
        gint event_day, event_num;
        EDayViewEvent *day_view_event;
        EDayView *day_view = E_DAY_VIEW (cal_view);
        event_found = e_day_view_find_event_from_item (day_view, canvas_item,
                                   &event_day, &event_num);
        if (!event_found)
            return NULL;
        if (event_day == E_DAY_VIEW_LONG_EVENT) {
            /* a long event */
            day_view_event = &g_array_index (day_view->long_events,
                             EDayViewEvent, event_num);
        }
        else {
            /* a main canvas event */
            day_view_event = &g_array_index (day_view->events[event_day],
                             EDayViewEvent, event_num);
        }
        cal_view_event = (ECalViewEvent *) day_view_event;
    }
    else if (E_IS_WEEK_VIEW (cal_view)) {
        gint event_num, span_num;
        EWeekViewEvent *week_view_event;
        EWeekView *week_view = E_WEEK_VIEW (cal_view);
        event_found = e_week_view_find_event_from_item (week_view,
                                canvas_item,
                                &event_num,
                                &span_num);
        if (!event_found)
            return NULL;

        week_view_event = &g_array_index (week_view->events, EWeekViewEvent,
                          event_num);

        cal_view_event = (ECalViewEvent *)week_view_event;
    }
    else {
        g_assert_not_reached ();
        return NULL;
    }
    return cal_view_event;
}