summaryrefslogtreecommitdiff
path: root/atk/atkeditabletext.c
blob: d44f8bff915f8fd2d56ae6d58a7b0421e52b79cb (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* ATK - The Accessibility Toolkit for GTK+
 * Copyright 2001 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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 "atkeditabletext.h"

/**
 * SECTION:atkeditabletext
 * @Short_description: The ATK interface implemented by components
 *  containing user-editable text content.
 * @Title:AtkEditableText
 *
 * #AtkEditableText should be implemented by UI components which
 * contain text which the user can edit, via the #AtkObject
 * corresponding to that component (see #AtkObject).
 *
 * #AtkEditableText is a subclass of #AtkText, and as such, an object
 * which implements #AtkEditableText is by definition an #AtkText
 * implementor as well.
 *
 * See also: #AtkText
 */

GType
atk_editable_text_get_type (void)
{
  static GType type = 0;

  if (!type) {
    static const GTypeInfo tinfo =
    {
      sizeof (AtkEditableTextIface),
      (GBaseInitFunc) NULL,
      (GBaseFinalizeFunc) NULL,

    };

    type = g_type_register_static (G_TYPE_INTERFACE, "AtkEditableText", &tinfo, 0);
  }

  return type;
}

/**
 *atk_editable_text_set_run_attributes:
 *@text: an #AtkEditableText
 *@attrib_set: an #AtkAttributeSet
 *@start_offset: start of range in which to set attributes
 *@end_offset: end of range in which to set attributes
 *
 *Sets the attributes for a specified range. See the ATK_ATTRIBUTE
 *macros (such as #ATK_ATTRIBUTE_LEFT_MARGIN) for examples of attributes 
 *that can be set. Note that other attributes that do not have corresponding
 *ATK_ATTRIBUTE macros may also be set for certain text widgets.
 *
 *Returns: %TRUE if attributes successfully set for the specified
 *range, otherwise %FALSE
 **/
gboolean
atk_editable_text_set_run_attributes (AtkEditableText *text,
                                      AtkAttributeSet *attrib_set,
			              gint start_offset,
                                      gint end_offset)
{
  AtkEditableTextIface *iface;

  g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (text), FALSE);

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->set_run_attributes)
    {
      return (*(iface->set_run_attributes)) (text, attrib_set, start_offset, end_offset);
    }
  else
    {
      return FALSE;
    }
}


/**
 * atk_editable_text_set_text_contents:
 * @text: an #AtkEditableText
 * @string: string to set for text contents of @text
 *
 * Set text contents of @text.
 **/
void 
atk_editable_text_set_text_contents (AtkEditableText  *text,
                                     const gchar      *string)
{
  AtkEditableTextIface *iface;

  g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->set_text_contents)
    (*(iface->set_text_contents)) (text, string);
}

/**
 * atk_editable_text_insert_text:
 * @text: an #AtkEditableText
 * @string: the text to insert
 * @length: the length of text to insert, in bytes
 * @position: The caller initializes this to 
 * the position at which to insert the text. After the call it
 * points at the position after the newly inserted text.
 *
 * Insert text at a given position.
 **/
void 
atk_editable_text_insert_text (AtkEditableText  *text,
                               const gchar      *string,
                               gint             length,
                               gint             *position)
{
  AtkEditableTextIface *iface;

  g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->insert_text)
    (*(iface->insert_text)) (text, string, length, position);
}

/**
 * atk_editable_text_copy_text:
 * @text: an #AtkEditableText
 * @start_pos: start position
 * @end_pos: end position
 *
 * Copy text from @start_pos up to, but not including @end_pos 
 * to the clipboard.
 **/
void 
atk_editable_text_copy_text (AtkEditableText  *text,
                             gint             start_pos,
                             gint             end_pos)
{
  AtkEditableTextIface *iface;

  g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->copy_text)
    (*(iface->copy_text)) (text, start_pos, end_pos);
}

/**
 * atk_editable_text_cut_text:
 * @text: an #AtkEditableText
 * @start_pos: start position
 * @end_pos: end position
 *
 * Copy text from @start_pos up to, but not including @end_pos
 * to the clipboard and then delete from the widget.
 **/
void 
atk_editable_text_cut_text  (AtkEditableText  *text,
                             gint             start_pos,
                             gint             end_pos)
{
  AtkEditableTextIface *iface;

  g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->cut_text)
    (*(iface->cut_text)) (text, start_pos, end_pos);
}

/**
 * atk_editable_text_delete_text:
 * @text: an #AtkEditableText
 * @start_pos: start position
 * @end_pos: end position
 *
 * Delete text @start_pos up to, but not including @end_pos.
 **/
void 
atk_editable_text_delete_text (AtkEditableText  *text,
                               gint             start_pos,
                               gint             end_pos)
{
  AtkEditableTextIface *iface;

  g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->delete_text)
    (*(iface->delete_text)) (text, start_pos, end_pos);
}

/**
 * atk_editable_text_paste_text:
 * @text: an #AtkEditableText
 * @position: position to paste
 *
 * Paste text from clipboard to specified @position.
 **/
void 
atk_editable_text_paste_text (AtkEditableText  *text,
                              gint             position)
{
  AtkEditableTextIface *iface;

  g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));

  iface = ATK_EDITABLE_TEXT_GET_IFACE (text);

  if (iface->paste_text)
    (*(iface->paste_text)) (text, position);
}