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 "atkplug.h"
24

            
25
/**
26
 * AtkPlug:
27
 *
28
 * Toplevel for embedding into other processes
29
 *
30
 * See [class@AtkSocket]
31
 */
32

            
33
static void atk_component_interface_init (AtkComponentIface *iface);
34

            
35
typedef struct
36
{
37
  AtkObject *child;
38
} AtkPlugPrivate;
39

            
40
static gint AtkPlug_private_offset;
41

            
42
161
G_DEFINE_TYPE_WITH_CODE (AtkPlug, atk_plug, ATK_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init) G_ADD_PRIVATE (AtkPlug))
43

            
44
static AtkObject *
45
atk_plug_ref_child (AtkObject *obj, int i)
46
{
47
  AtkPlugPrivate *private = atk_plug_get_instance_private (ATK_PLUG (obj));
48
  AtkObject *child;
49

            
50
  if (i != 0)
51
    return NULL;
52

            
53
  child = private->child;
54

            
55
  if (child == NULL)
56
    return NULL;
57

            
58
  return g_object_ref (child);
59
}
60

            
61
static int
62
atk_plug_get_n_children (AtkObject *obj)
63
{
64
  AtkPlugPrivate *private = atk_plug_get_instance_private (ATK_PLUG (obj));
65

            
66
  if (private->child == NULL)
67
    return 0;
68

            
69
  return 1;
70
}
71

            
72
static AtkStateSet *
73
atk_plug_ref_state_set (AtkObject *obj)
74
{
75
  AtkPlugPrivate *private = atk_plug_get_instance_private (ATK_PLUG (obj));
76
  AtkObject *child;
77

            
78
  child = private->child;
79

            
80
  if (child == NULL)
81
    return NULL;
82

            
83
  return atk_object_ref_state_set (child);
84
}
85

            
86
static void
87
atk_plug_init (AtkPlug *obj)
88
{
89
  AtkObject *accessible = ATK_OBJECT (obj);
90

            
91
  accessible->role = ATK_ROLE_FILLER;
92
  accessible->layer = ATK_LAYER_WIDGET;
93
}
94

            
95
static void
96
161
atk_plug_class_init (AtkPlugClass *klass)
97
{
98
161
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
99

            
100
161
  if (AtkPlug_private_offset != 0)
101
161
    g_type_class_adjust_private_offset (klass, &AtkPlug_private_offset);
102

            
103
161
  klass->get_object_id = NULL;
104

            
105
161
  class->get_n_children = atk_plug_get_n_children;
106
161
  class->ref_child = atk_plug_ref_child;
107
161
  class->ref_state_set = atk_plug_ref_state_set;
108
161
}
109

            
110
static void
111
161
atk_component_interface_init (AtkComponentIface *iface)
112
{
113
161
}
114

            
115
/**
116
 * atk_plug_new:
117
 *
118
 * Creates a new #AtkPlug instance.
119
 *
120
 * Returns: (transfer full): the newly created #AtkPlug
121
 *
122
 * Since: 1.30
123
 */
124
AtkObject *
125
atk_plug_new (void)
126
{
127
  return g_object_new (ATK_TYPE_PLUG, NULL);
128
}
129

            
130
/**
131
 * atk_plug_set_child:
132
 * @plug: an #AtkPlug to be set as accessible parent of @child.
133
 * @child: an #AtkObject to be set as accessible child of @plug.
134
 *
135
 * Sets @child as accessible child of @plug and @plug as accessible parent of
136
 * @child. @child can be NULL.
137
 *
138
 * In some cases, one can not use the AtkPlug type directly as accessible
139
 * object for the toplevel widget of the application. For instance in the gtk
140
 * case, GtkPlugAccessible can not inherit both from GtkWindowAccessible and
141
 * from AtkPlug. In such a case, one can create, in addition to the standard
142
 * accessible object for the toplevel widget, an AtkPlug object, and make the
143
 * former the child of the latter by calling atk_plug_set_child().
144
 *
145
 * Since: 2.35.0
146
 */
147
void
148
atk_plug_set_child (AtkPlug *plug, AtkObject *child)
149
{
150
  AtkPlugPrivate *private = atk_plug_get_instance_private (plug);
151

            
152
  if (private->child)
153
    atk_object_set_parent (private->child, NULL);
154

            
155
  private->child = child;
156

            
157
  if (child)
158
    atk_object_set_parent (child, ATK_OBJECT (plug));
159
}
160

            
161
/**
162
 * atk_plug_get_id:
163
 * @plug: an #AtkPlug
164
 *
165
 * Gets the unique ID of an #AtkPlug object, which can be used to
166
 * embed inside of an #AtkSocket using atk_socket_embed().
167
 *
168
 * Internally, this calls a class function that should be registered
169
 * by the IPC layer (usually at-spi2-atk). The implementor of an
170
 * #AtkPlug object should call this function (after atk-bridge is
171
 * loaded) and pass the value to the process implementing the
172
 * #AtkSocket, so it could embed the plug.
173
 *
174
 * Returns: the unique ID for the plug
175
 *
176
 * Since: 1.30
177
 **/
178
gchar *
179
atk_plug_get_id (AtkPlug *plug)
180
{
181
  AtkPlugClass *klass;
182

            
183
  g_return_val_if_fail (ATK_IS_PLUG (plug), NULL);
184

            
185
  klass = g_type_class_peek (ATK_TYPE_PLUG);
186

            
187
  if (klass && klass->get_object_id)
188
    return (klass->get_object_id) (plug);
189
  else
190
    return NULL;
191
}