]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailpixmap.c
Include <config.h>. Bug #504720.
[~andy/gtk] / modules / other / gail / gailpixmap.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 <config.h>
21
22 #include <gtk/gtk.h>
23 #include "gailpixmap.h"
24
25 static void      gail_pixmap_class_init         (GailPixmapClass *klass);
26 static void      gail_pixmap_init               (GailPixmap      *pixmap);
27
28 /* AtkImage */
29 static void  atk_image_interface_init   (AtkImageIface  *iface);
30 static G_CONST_RETURN gchar* gail_pixmap_get_image_description 
31                                         (AtkImage       *obj);
32 static void  gail_pixmap_get_image_position    
33                                         (AtkImage       *obj,
34                                          gint           *x,
35                                          gint           *y,
36                                          AtkCoordType   coord_type);
37 static void  gail_pixmap_get_image_size (AtkImage       *obj,
38                                          gint           *width,
39                                          gint           *height);
40 static gboolean gail_pixmap_set_image_description 
41                                         (AtkImage       *obj,
42                                         const gchar    *description);
43 static void  gail_pixmap_finalize       (GObject         *object);
44
45 G_DEFINE_TYPE_WITH_CODE (GailPixmap, gail_pixmap, GAIL_TYPE_WIDGET,
46                          G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init))
47
48 static void      
49 gail_pixmap_class_init (GailPixmapClass *klass)
50 {
51   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
52  
53   gobject_class->finalize = gail_pixmap_finalize;
54 }
55
56 static void
57 gail_pixmap_init (GailPixmap *pixmap)
58 {
59   pixmap->image_description = NULL;
60 }
61
62 AtkObject* 
63 gail_pixmap_new (GtkWidget *widget)
64 {
65   GObject *object;
66   AtkObject *accessible;
67
68   g_assert (GTK_IS_PIXMAP (widget));
69   g_return_val_if_fail (GTK_IS_PIXMAP (widget), NULL);
70
71   object = g_object_new (GAIL_TYPE_PIXMAP, NULL);
72
73   accessible = ATK_OBJECT (object);
74   atk_object_initialize (accessible, widget);
75
76   accessible->role = ATK_ROLE_ICON;
77
78   return accessible;
79 }
80
81 static void
82 atk_image_interface_init (AtkImageIface *iface)
83 {
84   iface->get_image_description = gail_pixmap_get_image_description;
85   iface->get_image_position = gail_pixmap_get_image_position;
86   iface->get_image_size = gail_pixmap_get_image_size;
87   iface->set_image_description = gail_pixmap_set_image_description;
88 }
89
90 static G_CONST_RETURN gchar* 
91 gail_pixmap_get_image_description (AtkImage       *obj)
92 {
93   GailPixmap* pixmap;
94
95   g_return_val_if_fail (GAIL_IS_PIXMAP (obj), NULL);
96
97   pixmap = GAIL_PIXMAP (obj);
98
99   return pixmap->image_description;
100 }
101
102 static void
103 gail_pixmap_get_image_position (AtkImage       *obj,
104                                 gint           *x,
105                                 gint           *y,
106                                 AtkCoordType   coord_type)
107 {
108   atk_component_get_position (ATK_COMPONENT (obj), x, y, coord_type);
109 }
110
111 static void  
112 gail_pixmap_get_image_size (AtkImage       *obj,
113                             gint           *width,
114                             gint           *height)
115 {
116   GtkWidget *widget;
117   GtkPixmap *pixmap;
118  
119   *width = -1;
120   *height = -1;
121
122   g_return_if_fail (GAIL_IS_PIXMAP (obj));
123
124   widget = GTK_ACCESSIBLE (obj)->widget;
125   if (widget == 0)
126     /* State is defunct */
127     return;
128
129   g_return_if_fail (GTK_IS_PIXMAP (widget));
130
131   pixmap = GTK_PIXMAP (widget);
132
133   if (pixmap->pixmap)
134     gdk_window_get_size (pixmap->pixmap, width, height);
135 }
136
137 static gboolean 
138 gail_pixmap_set_image_description (AtkImage       *obj,
139                                    const gchar    *description)
140
141   GailPixmap* pixmap;
142
143   g_return_val_if_fail (GAIL_IS_PIXMAP (obj), FALSE);
144
145   pixmap = GAIL_PIXMAP (obj);
146   g_free (pixmap->image_description);
147
148   pixmap->image_description = g_strdup (description);
149
150   return TRUE;
151 }
152
153 static void
154 gail_pixmap_finalize (GObject      *object)
155 {
156   GailPixmap *pixmap = GAIL_PIXMAP (object);
157
158   g_free (pixmap->image_description);
159   G_OBJECT_CLASS (gail_pixmap_parent_class)->finalize (object);
160 }