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