Visual Studio builds: Adapt to the Python-fied glib-genmarshal
[platform/upstream/atk.git] / atk / atksocket.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright (C) 2009 Novell, 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 "atk.h"
23 #include "atksocket.h"
24
25 /**
26  * SECTION:atksocket
27  * @Short_description: Container for AtkPlug objects from other processes
28  * @Title: AtkSocket
29  * @See_also: #AtkPlug
30  *
31  * Together with #AtkPlug, #AtkSocket provides the ability to embed
32  * accessibles from one process into another in a fashion that is
33  * transparent to assistive technologies. #AtkSocket works as the
34  * container of #AtkPlug, embedding it using the method
35  * atk_socket_embed(). Any accessible contained in the #AtkPlug will
36  * appear to the assistive technologies as being inside the
37  * application that created the #AtkSocket.
38  *
39  * The communication between a #AtkSocket and a #AtkPlug is done by
40  * the IPC layer of the accessibility framework, normally implemented
41  * by the D-Bus based implementation of AT-SPI (at-spi2). If that is
42  * the case, at-spi-atk2 is the responsible to implement the abstract
43  * methods atk_plug_get_id() and atk_socket_embed(), so an ATK
44  * implementor shouldn't reimplement them. The process that contains
45  * the #AtkPlug is responsible to send the ID returned by
46  * atk_plug_id() to the process that contains the #AtkSocket, so it
47  * could call the method atk_socket_embed() in order to embed it.
48  *
49  * For the same reasons, an implementor doesn't need to implement
50  * atk_object_get_n_accessible_children() and
51  * atk_object_ref_accessible_child(). All the logic related to those
52  * functions will be implemented by the IPC layer.
53  */
54
55 static void atk_socket_class_init (AtkSocketClass *klass);
56 static void atk_socket_finalize   (GObject *obj);
57
58 static void atk_component_interface_init (AtkComponentIface *iface);
59
60 G_DEFINE_TYPE_WITH_CODE (AtkSocket, atk_socket, ATK_TYPE_OBJECT,
61                          G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
62
63 static void
64 atk_socket_init (AtkSocket* obj)
65 {
66   obj->embedded_plug_id = NULL;
67 }
68
69 static void
70 atk_socket_class_init (AtkSocketClass* klass)
71 {
72   GObjectClass *obj_class = G_OBJECT_CLASS (klass);
73
74   obj_class->finalize = atk_socket_finalize;
75
76   klass->embed = NULL;
77 }
78
79 static void
80 atk_socket_finalize (GObject *_obj)
81 {
82   AtkSocket *obj = ATK_SOCKET (_obj);
83
84   g_free (obj->embedded_plug_id);
85   obj->embedded_plug_id = NULL;
86
87   G_OBJECT_CLASS (atk_socket_parent_class)->finalize (_obj);
88 }
89
90 static void atk_component_interface_init (AtkComponentIface *iface)
91 {
92 }
93
94 AtkObject*
95 atk_socket_new (void)
96 {
97   AtkObject* accessible;
98   
99   accessible = g_object_new (ATK_TYPE_SOCKET, NULL);
100   g_return_val_if_fail (accessible != NULL, NULL);
101
102   accessible->role = ATK_ROLE_FILLER;
103   accessible->layer = ATK_LAYER_WIDGET;
104   
105   return accessible;
106 }
107
108 /**
109  * atk_socket_embed:
110  * @obj: an #AtkSocket
111  * @plug_id: the ID of an #AtkPlug
112  *
113  * Embeds the children of an #AtkPlug as the children of the
114  * #AtkSocket. The plug may be in the same process or in a different
115  * process.
116  *
117  * The class item used by this function should be filled in by the IPC
118  * layer (usually at-spi2-atk). The implementor of the AtkSocket
119  * should call this function and pass the id for the plug as returned
120  * by atk_plug_get_id().  It is the responsibility of the application
121  * to pass the plug id on to the process implementing the #AtkSocket
122  * as needed.
123  *
124  * Since: 1.30
125  **/
126 void
127 atk_socket_embed (AtkSocket* obj, gchar* plug_id)
128 {
129   AtkSocketClass *klass;
130
131   g_return_if_fail (plug_id != NULL);
132   g_return_if_fail (ATK_IS_SOCKET (obj));
133
134   klass = g_type_class_peek (ATK_TYPE_SOCKET);
135   if (klass && klass->embed)
136     {
137       if (obj->embedded_plug_id)
138         g_free (obj->embedded_plug_id);
139       obj->embedded_plug_id = g_strdup (plug_id);
140       (klass->embed) (obj, plug_id);
141     }
142 }
143
144 /**
145  * atk_socket_is_occupied:
146  * @obj: an #AtkSocket
147  *
148  * Determines whether or not the socket has an embedded plug.
149  *
150  * Returns: TRUE if a plug is embedded in the socket
151  *
152  * Since: 1.30
153  **/
154 gboolean
155 atk_socket_is_occupied (AtkSocket* obj)
156 {
157   g_return_val_if_fail (ATK_IS_SOCKET (obj), FALSE);
158
159   return (obj->embedded_plug_id != NULL);
160 }