aboutsummaryrefslogtreecommitdiffstats
path: root/a11y/calendar/ea-week-view-cell.c
blob: 5d97ed74b4dba48149f7ad1bbc35ed0cd5fa6912 (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* vim:expandtab:shiftwidth=8:tabstop=8:
 */
/* Evolution Accessibility: ea-week-view-cell.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
 * Author: Yang Wu <Yang.Wu@sun.com> Sun Microsystem Inc., 2003
 *
 */

#include "ea-week-view-cell.h"
#include "ea-week-view-main-item.h"
#include "ea-factory.h"

/* EWeekViewCell */

static void e_week_view_cell_class_init (EWeekViewCellClass *class);

EA_FACTORY_GOBJECT (EA_TYPE_WEEK_VIEW_CELL, ea_week_view_cell, ea_week_view_cell_new)

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

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

        type = g_type_register_static (G_TYPE_OBJECT,
                           "EWeekViewCell", &tinfo, 0);
    }

    return type;
}

static void
e_week_view_cell_class_init (EWeekViewCellClass *class)
{
    EA_SET_FACTORY (e_week_view_cell_get_type (), ea_week_view_cell);
}

EWeekViewCell *
e_week_view_cell_new (EWeekView *week_view, gint row, gint column)
{
    GObject *object;
    EWeekViewCell *cell;

    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL);

    object = g_object_new (E_TYPE_WEEK_VIEW_CELL, NULL);
    cell = E_WEEK_VIEW_CELL (object);
    cell->week_view = week_view;
    cell->row = row;
    cell->column = column;

#ifdef ACC_DEBUG
    printf ("EvoAcc: e_week_view_cell created %p\n", (void *)cell);
#endif

    return cell;
}

/* EaWeekViewCell */

static void ea_week_view_cell_class_init (EaWeekViewCellClass *klass);

static G_CONST_RETURN gchar* ea_week_view_cell_get_name (AtkObject *accessible);
static G_CONST_RETURN gchar* ea_week_view_cell_get_description (AtkObject *accessible);
static AtkStateSet* ea_week_view_cell_ref_state_set (AtkObject *obj);
static AtkObject * ea_week_view_cell_get_parent (AtkObject *accessible);
static gint ea_week_view_cell_get_index_in_parent (AtkObject *accessible);

/* component interface */
static void atk_component_interface_init (AtkComponentIface *iface);
static void component_interface_get_extents (AtkComponent *component,
                         gint *x, gint *y,
                         gint *width, gint *height,
                         AtkCoordType coord_type);
static gpointer parent_class = NULL;

#ifdef ACC_DEBUG
static gint n_ea_week_view_cell_created = 0, n_ea_week_view_cell_destroyed = 0;
static void ea_week_view_cell_finalize (GObject *object);
#endif

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

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

        static const GInterfaceInfo atk_component_info = {
            (GInterfaceInitFunc) atk_component_interface_init,
            (GInterfaceFinalizeFunc) NULL,
            NULL
        };
        type = g_type_register_static (ATK_TYPE_GOBJECT_ACCESSIBLE,
                           "EaWeekViewCell", &tinfo, 0);
        g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
                         &atk_component_info);

    }

    return type;
}

static void
ea_week_view_cell_class_init (EaWeekViewCellClass *klass)
{
    AtkObjectClass *class = ATK_OBJECT_CLASS (klass);

#ifdef ACC_DEBUG
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    gobject_class->finalize = ea_week_view_cell_finalize;
#endif

    parent_class = g_type_class_peek_parent (klass);

    class->get_name = ea_week_view_cell_get_name;
    class->get_description = ea_week_view_cell_get_description;
    class->ref_state_set = ea_week_view_cell_ref_state_set;

    class->get_parent = ea_week_view_cell_get_parent;
    class->get_index_in_parent = ea_week_view_cell_get_index_in_parent;

}

AtkObject* 
ea_week_view_cell_new (GObject *obj)
{
    gpointer object;
    AtkObject *atk_object;

    g_return_val_if_fail (E_IS_WEEK_VIEW_CELL (obj), NULL);
    object = g_object_new (EA_TYPE_WEEK_VIEW_CELL, NULL);
    atk_object = ATK_OBJECT (object);
    atk_object_initialize (atk_object, obj);
    atk_object->role = ATK_ROLE_UNKNOWN;

#ifdef ACC_DEBUG
    ++n_ea_week_view_cell_created;
    printf ("ACC_DEBUG: n_ea_week_view_cell_created = %d\n",
        n_ea_week_view_cell_created);
#endif
    return atk_object;
}

#ifdef ACC_DEBUG
static void ea_week_view_cell_finalize (GObject *object)
{
    ++n_ea_week_view_cell_destroyed;
    printf ("ACC_DEBUG: n_ea_week_view_cell_destroyed = %d\n",
        n_ea_week_view_cell_destroyed);
}
#endif

static G_CONST_RETURN gchar*
ea_week_view_cell_get_name (AtkObject *accessible)
{
    AtkGObjectAccessible *atk_gobj;
    GObject *g_obj;
    EWeekViewCell *cell;

    g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), NULL);

    if (!accessible->name) {
        AtkObject *ea_main_item;
        GnomeCanvasItem *main_item;
        gchar *new_name = g_strdup ("");
        const gchar *row_label, *column_label;

        atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
        g_obj = atk_gobject_accessible_get_object (atk_gobj);
        if (!g_obj)
            return NULL;

        cell = E_WEEK_VIEW_CELL (g_obj);
        main_item = cell->week_view->main_canvas_item;
        ea_main_item = atk_gobject_accessible_for_object (G_OBJECT (main_item));
        column_label = atk_table_get_column_description (ATK_TABLE (ea_main_item),
                                 cell->column);
        row_label = atk_table_get_row_description (ATK_TABLE (ea_main_item),
                               cell->row);
        new_name = g_strconcat (column_label, " ", row_label, NULL);
        ATK_OBJECT_CLASS (parent_class)->set_name (accessible, new_name);
        g_free (new_name);
    }
    return accessible->name;
}

static G_CONST_RETURN gchar*
ea_week_view_cell_get_description (AtkObject *accessible)
{
    return ea_week_view_cell_get_name (accessible);
}

static AtkStateSet*
ea_week_view_cell_ref_state_set (AtkObject *obj)
{
  AtkStateSet *state_set;
  GObject *g_obj;
  AtkObject *parent;
  gint x, y, width, height;
  gint parent_x, parent_y, parent_width, parent_height;

  state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj);
  g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(obj));
  if (!g_obj)
      return state_set;

  atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);

  parent = atk_object_get_parent (obj);
  atk_component_get_extents (ATK_COMPONENT (obj), &x, &y,
                 &width, &height, ATK_XY_WINDOW);
  atk_component_get_extents (ATK_COMPONENT (parent), &parent_x, &parent_y,
                 &parent_width, &parent_height, ATK_XY_WINDOW);


  if (x + width < parent_x || x > parent_x + parent_width ||
      y + height < parent_y || y > parent_y + parent_height)
      /* the cell is out of the main canvas */    
      ;
  else
      atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);

  return state_set;
}

static AtkObject *
ea_week_view_cell_get_parent (AtkObject *accessible)
{
    AtkGObjectAccessible *atk_gobj;
    GObject *g_obj;
    EWeekViewCell *cell;

    g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), NULL);

    atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
    g_obj = atk_gobject_accessible_get_object (atk_gobj);
    if (!g_obj)
        return NULL;

    cell = E_WEEK_VIEW_CELL (g_obj);
    return atk_gobject_accessible_for_object (G_OBJECT (cell->week_view->main_canvas_item));
}

static gint
ea_week_view_cell_get_index_in_parent (AtkObject *accessible)
{
    AtkGObjectAccessible *atk_gobj;
    GObject *g_obj;
    EWeekViewCell *cell;
    AtkObject *parent;

    g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), -1);

    atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
    g_obj = atk_gobject_accessible_get_object (atk_gobj);
    if (!g_obj)
        return -1;

    cell = E_WEEK_VIEW_CELL (g_obj);
    parent = atk_object_get_parent (accessible);
    return atk_table_get_index_at (ATK_TABLE (parent),
                       cell->row, cell->column);
}

/* Atk Component Interface */

static void 
atk_component_interface_init (AtkComponentIface *iface)
{
    g_return_if_fail (iface != NULL);

    iface->get_extents = component_interface_get_extents;
}

static void 
component_interface_get_extents (AtkComponent *component,
                 gint *x, gint *y, gint *width, gint *height,
                 AtkCoordType coord_type)
{
    GObject *g_obj;
    AtkObject *atk_obj;
    EWeekViewCell *cell;
    EWeekView *week_view;
    GtkWidget *main_canvas;
    gint week_view_width, week_view_height;
    gint scroll_x, scroll_y;

    *x = *y = *width = *height = 0;

    g_return_if_fail (EA_IS_WEEK_VIEW_CELL (component));

    g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component));
    if (!g_obj)
        /* defunct object*/
        return;

    cell = E_WEEK_VIEW_CELL (g_obj);
    week_view = cell->week_view;
    main_canvas = cell->week_view->main_canvas;

    atk_obj = atk_gobject_accessible_for_object (G_OBJECT (main_canvas));
    atk_component_get_extents (ATK_COMPONENT (atk_obj),
                   x, y,
                   &week_view_width, &week_view_height,
                   coord_type);
    gnome_canvas_get_scroll_offsets (GNOME_CANVAS (week_view->main_canvas),
                     &scroll_x, &scroll_y);
    *x += week_view->col_offsets[cell->column] - scroll_x;
    *y += week_view->row_offsets[cell->row*2]- scroll_y;
    *width = week_view->col_widths[cell->column];
    *height = week_view->row_heights[ cell->row*2]*2;
}