]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailhtmlbox.c
Include <config.h>. Bug #504720.
[~andy/gtk] / modules / other / gail / gailhtmlbox.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 "gailhtmlbox.h"
24 #include "gailhtmlview.h"
25 #include <libgtkhtml/layout/htmlbox.h>
26
27 static void         gail_html_box_class_init               (GailHtmlBoxClass  *klass);
28 static void         gail_html_box_initialize               (AtkObject         *obj,
29                                                             gpointer          data);
30 static gint         gail_html_box_get_index_in_parent      (AtkObject         *obj);
31 static AtkStateSet* gail_html_box_ref_state_set            (AtkObject         *obj);
32
33 static void         gail_html_box_component_interface_init (AtkComponentIface *iface);
34 static guint        gail_html_box_add_focus_handler        (AtkComponent      *component,
35                                                             AtkFocusHandler   handler);
36 static void         gail_html_box_get_extents              (AtkComponent      *component,
37                                                             gint              *x,
38                                                             gint              *y,
39                                                             gint              *width,
40                                                             gint              *height,
41                                                             AtkCoordType      coord_type);
42 static gboolean     gail_html_box_grab_focus               (AtkComponent      *component);
43 static void         gail_html_box_remove_focus_handler     (AtkComponent      *component,
44                                                             guint             handler_id);
45
46 G_DEFINE_TYPE_WITH_CODE (GailHtmlBox, gail_html_box, ATK_TYPE_GOBJECT,
47                          G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, gail_html_box_component_interface_init))
48
49 static void
50 gail_html_box_class_init (GailHtmlBoxClass *klass)
51 {
52   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
53
54   class->get_index_in_parent = gail_html_box_get_index_in_parent;
55   class->ref_state_set = gail_html_box_ref_state_set;
56   class->initialize = gail_html_box_initialize;
57 }
58
59 AtkObject*
60 gail_html_box_new (GObject *obj)
61 {
62   GObject *object;
63   AtkObject *atk_object;
64
65   g_return_val_if_fail (HTML_IS_BOX (obj), NULL);
66   object = g_object_new (GAIL_TYPE_HTML_BOX, NULL);
67   atk_object = ATK_OBJECT (object);
68   atk_object_initialize (atk_object, obj);
69   atk_object->role = ATK_ROLE_UNKNOWN;
70   return atk_object;
71 }
72
73 static void
74 gail_html_box_initialize (AtkObject *obj,
75                           gpointer  data)
76 {
77   HtmlBox *box;
78   ATK_OBJECT_CLASS (gail_html_box_parent_class)->initialize (obj, data);
79
80   box = HTML_BOX (data);
81
82   /*
83    * We do not set the parent here for the root node of a HtmlView
84    */
85   if (box->parent)
86     { 
87       atk_object_set_parent (obj,
88                         atk_gobject_get_accessible (G_OBJECT (box->parent)));
89     }
90 }
91
92 static gint
93 gail_html_box_get_index_in_parent (AtkObject *obj)
94 {
95   AtkObject *parent;
96   AtkGObject *atk_gobj;
97   HtmlBox *box;
98   HtmlBox *parent_box;
99   gint n_children = 0;
100   GObject *g_obj;
101
102   g_return_val_if_fail (GAIL_IS_HTML_BOX (obj), -1);
103
104   atk_gobj = ATK_GOBJECT (obj);
105   g_obj = atk_gobject_get_object (atk_gobj);
106   if (g_obj == NULL)
107     return -1;
108
109   g_return_val_if_fail (HTML_IS_BOX (g_obj), -1);
110   box = HTML_BOX (g_obj);
111   parent = atk_object_get_parent (obj);
112   if (GAIL_IS_HTML_VIEW (parent))
113     {
114       return 0;
115     }
116   else if (ATK_IS_GOBJECT (parent))
117     {
118       parent_box = HTML_BOX (atk_gobject_get_object (ATK_GOBJECT (parent)));
119     }
120   else
121     {
122       g_assert_not_reached ();
123       return -1;
124     }
125
126   if (parent_box)
127     {
128       HtmlBox *child;
129
130       child = parent_box->children;
131
132       while (child)
133         {
134           if (child == box)
135             return n_children;
136
137           n_children++;
138           child = child->next;
139         }
140     }
141   return -1;
142 }
143
144 static AtkStateSet*
145 gail_html_box_ref_state_set (AtkObject    *obj)
146 {
147   AtkGObject *atk_gobj;
148   GObject *g_obj;
149   AtkStateSet *state_set;
150
151   g_return_val_if_fail (GAIL_IS_HTML_BOX (obj), NULL);
152   atk_gobj = ATK_GOBJECT (obj);
153   state_set = ATK_OBJECT_CLASS (gail_html_box_parent_class)->ref_state_set (obj);
154
155   g_obj = atk_gobject_get_object (atk_gobj);
156   if (g_obj == NULL)
157     {
158       /* Object is defunct */
159       atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
160     }
161   else
162     {
163       HtmlBox *box;
164   
165       box = HTML_BOX (g_obj);
166
167       if (HTML_BOX_GET_STYLE (box)->display != HTML_DISPLAY_NONE)
168         {
169           atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
170           atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
171         }
172     }
173   return state_set;
174
175
176 static void
177 gail_html_box_component_interface_init (AtkComponentIface *iface)
178 {
179   /*
180    * Use default implementation for contains and get_position
181    */
182   iface->contains = NULL;
183   iface->get_position = NULL;
184   iface->add_focus_handler = gail_html_box_add_focus_handler;
185   iface->get_extents = gail_html_box_get_extents;
186   iface->get_size = NULL;
187   iface->grab_focus = gail_html_box_grab_focus;
188   iface->remove_focus_handler = gail_html_box_remove_focus_handler;
189   iface->set_extents = NULL;
190   iface->set_position = NULL;
191   iface->set_size = NULL;
192 }
193
194 static guint
195 gail_html_box_add_focus_handler (AtkComponent    *component,
196                                  AtkFocusHandler handler)
197 {
198   return g_signal_connect_closure (component, 
199                                    "focus-event",
200                                    g_cclosure_new (
201                                                    G_CALLBACK (handler), NULL,
202                                                    (GClosureNotify) NULL),
203                                    FALSE);
204 }
205
206 static void
207 gail_html_box_get_extents (AtkComponent *component,
208                            gint         *x,
209                            gint         *y,
210                            gint         *width,
211                            gint         *height,
212                            AtkCoordType coord_type)
213 {
214   AtkGObject *atk_gobj;
215   HtmlBox *box;
216   GObject *g_obj;
217
218   g_return_if_fail (GAIL_IS_HTML_BOX (component));
219
220   atk_gobj = ATK_GOBJECT (component);
221   g_obj = atk_gobject_get_object (atk_gobj);
222   if (g_obj == NULL)
223     return;
224
225   g_return_if_fail (HTML_IS_BOX (g_obj));
226   box = HTML_BOX (g_obj);
227
228   *x = html_box_get_absolute_x (box);
229   *y = html_box_get_absolute_y (box);
230   *width = box->width;
231   *height = box->height;
232
233   g_print ("%d %d %d %d\n",
234            html_box_get_absolute_x (box),
235            html_box_get_absolute_y (box),
236            html_box_get_containing_block_width (box),
237            html_box_get_containing_block_height (box));
238 }
239
240 static gboolean
241 gail_html_box_grab_focus (AtkComponent    *component)
242 {
243   return TRUE;
244 }
245
246 static void
247 gail_html_box_remove_focus_handler (AtkComponent *component,
248                                     guint        handler_id)
249 {
250   g_signal_handler_disconnect (ATK_OBJECT (component), handler_id);
251 }