]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailclistcell.c
Use G_DEFINE_TYPE[_WITH_CODE] instead of hand-coding the get_type functions. Bug...
[~andy/gtk] / modules / other / gail / gailclistcell.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gtk/gtk.h>
21 #include "gailclistcell.h"
22
23 static void      gail_clist_cell_class_init        (GailCListCellClass *klass);
24 static void      gail_clist_cell_init              (GailCListCell      *cell);
25
26 static G_CONST_RETURN gchar* gail_clist_cell_get_name (AtkObject *accessible);
27
28 G_DEFINE_TYPE (GailCListCell, gail_clist_cell, GAIL_TYPE_CELL)
29
30 static void      
31 gail_clist_cell_class_init (GailCListCellClass *klass)
32 {
33   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
34
35   class->get_name = gail_clist_cell_get_name;
36 }
37
38 static void
39 gail_clist_cell_init (GailCListCell *cell)
40 {
41 }
42
43 AtkObject* 
44 gail_clist_cell_new (void)
45 {
46   GObject *object;
47   AtkObject *atk_object;
48
49   object = g_object_new (GAIL_TYPE_CLIST_CELL, NULL);
50
51   g_return_val_if_fail (object != NULL, NULL);
52
53   atk_object = ATK_OBJECT (object);
54   atk_object->role = ATK_ROLE_TABLE_CELL;
55
56   g_return_val_if_fail (!ATK_IS_TEXT (atk_object), NULL);
57   
58   return atk_object;
59 }
60
61 static G_CONST_RETURN gchar*
62 gail_clist_cell_get_name (AtkObject *accessible)
63 {
64   if (accessible->name)
65     return accessible->name;
66   else
67     {
68       /*
69        * Get the cell's text if it exists
70        */
71       GailCell *cell = GAIL_CELL (accessible);
72       GtkWidget* widget = cell->widget;
73       GtkCellType cell_type;
74       GtkCList *clist;
75       gchar *text = NULL;
76       gint row, column;
77
78       if (widget == NULL)
79         /*
80          * State is defunct
81          */
82         return NULL;
83  
84       clist = GTK_CLIST (widget);
85       g_return_val_if_fail (clist->columns, NULL);
86       row = cell->index / clist->columns;
87       column = cell->index % clist->columns;
88       cell_type = gtk_clist_get_cell_type (clist, row, column);
89       switch (cell_type)
90         {
91         case GTK_CELL_TEXT:
92           gtk_clist_get_text (clist, row, column, &text);
93           break;
94         case GTK_CELL_PIXTEXT:
95           gtk_clist_get_pixtext (clist, row, column, &text, NULL, NULL, NULL);
96           break;
97         default:
98           break;
99         }
100       return text;
101     }
102 }