summaryrefslogtreecommitdiff
path: root/atk/atkplug.c
blob: ddd86ed0f0ec57f403f2c2624edbee7421916670 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* ATK -  Accessibility Toolkit
 * Copyright (C) 2009 Novell, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include "atk.h"
#include "atkplug.h"

/**
 * SECTION:atkplug
 * @Short_description: Toplevel for embedding into other processes
 * @Title: AtkPlug
 * @See_also: #AtkPlug
 *
 * See #AtkSocket
 *
 */

static void atk_component_interface_init (AtkComponentIface *iface);

typedef struct {
  AtkObject *child;
} AtkPlugPrivate;

static gint AtkPlug_private_offset;

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))

static AtkObject*
atk_plug_ref_child (AtkObject *obj, int i)
{
  AtkPlugPrivate *private = atk_plug_get_instance_private (ATK_PLUG (obj));
  AtkObject *child;

  if (i != 0)
    return NULL;

  child = private->child;

  if (child == NULL)
    return NULL;

  return g_object_ref (child);
}

static int
atk_plug_get_n_children (AtkObject *obj)
{
  AtkPlugPrivate *private = atk_plug_get_instance_private (ATK_PLUG (obj));

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

  return 1;
}

static AtkStateSet*
atk_plug_ref_state_set (AtkObject *obj)
{
  AtkPlugPrivate *private = atk_plug_get_instance_private (ATK_PLUG (obj));
  AtkObject *child;

  child = private->child;

  if (child == NULL)
    return NULL;

  return atk_object_ref_state_set (child);
}

static void
atk_plug_init (AtkPlug* obj)
{
  AtkObject *accessible = ATK_OBJECT (obj);

  accessible->role = ATK_ROLE_FILLER;
  accessible->layer = ATK_LAYER_WIDGET;
}

static void
atk_plug_class_init (AtkPlugClass* klass)
{
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);

  if (AtkPlug_private_offset != 0)
    g_type_class_adjust_private_offset (klass, &AtkPlug_private_offset);

  klass->get_object_id = NULL;

  class->get_n_children = atk_plug_get_n_children;
  class->ref_child      = atk_plug_ref_child;
  class->ref_state_set  = atk_plug_ref_state_set;
}

static void
atk_component_interface_init (AtkComponentIface *iface)
{
}

/**
 * atk_plug_new:
 *
 * Creates a new #AtkPlug instance.
 *
 * Returns: (transfer full): the newly created #AtkPlug
 *
 * Since: 1.30
 */
AtkObject *
atk_plug_new (void)
{
  return g_object_new (ATK_TYPE_PLUG, NULL);
}

/**
 * atk_plug_set_child:
 * @plug: an #AtkPlug to be set as accessible parent of @child.
 * @child: an #AtkObject to be set as accessible child of @plug.
 *
 * Sets @child as accessible child of @plug and @plug as accessible parent of
 * @child. @child can be NULL.
 *
 * In some cases, one can not use the AtkPlug type directly as accessible
 * object for the toplevel widget of the application. For instance in the gtk
 * case, GtkPlugAccessible can not inherit both from GtkWindowAccessible and
 * from AtkPlug. In such a case, one can create, in addition to the standard
 * accessible object for the toplevel widget, an AtkPlug object, and make the
 * former the child of the latter by calling atk_plug_set_child().
 *
 * Since: 2.35.0
 */
void
atk_plug_set_child (AtkPlug *plug, AtkObject *child)
{
  AtkPlugPrivate *private = atk_plug_get_instance_private (plug);

  if (private->child)
    atk_object_set_parent (private->child, NULL);

  private->child = child;

  if (child)
    atk_object_set_parent (child, ATK_OBJECT(plug));
}

/**
 * atk_plug_get_id:
 * @plug: an #AtkPlug
 *
 * Gets the unique ID of an #AtkPlug object, which can be used to
 * embed inside of an #AtkSocket using atk_socket_embed().
 *
 * Internally, this calls a class function that should be registered
 * by the IPC layer (usually at-spi2-atk). The implementor of an
 * #AtkPlug object should call this function (after atk-bridge is
 * loaded) and pass the value to the process implementing the
 * #AtkSocket, so it could embed the plug.
 *
 * Returns: the unique ID for the plug
 *
 * Since: 1.30
 **/
gchar*
atk_plug_get_id (AtkPlug* plug)
{
  AtkPlugClass *klass;

  g_return_val_if_fail (ATK_IS_PLUG (plug), NULL);

  klass = g_type_class_peek (ATK_TYPE_PLUG);

  if (klass && klass->get_object_id)
    return (klass->get_object_id) (plug);
  else
    return NULL;
}