summaryrefslogtreecommitdiff
path: root/cspi/spi_text.c
blob: 13a9be40af8b8dbacc7c63efa23c1818bce34f66 (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2001, 2002 Sun Microsystems Inc.,
 * Copyright 2001, 2002 Ximian, 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 <cspi/spi-private.h>

static Accessibility_TEXT_BOUNDARY_TYPE
get_accessible_text_boundary_type (AccessibleTextBoundaryType type)
{
  switch (type)
    {
    case SPI_TEXT_BOUNDARY_CHAR:
      return Accessibility_TEXT_BOUNDARY_CHAR;
      break;
    case SPI_TEXT_BOUNDARY_CURSOR_POS:
      /* FixME */
      return Accessibility_TEXT_BOUNDARY_CHAR;
      break;
    case SPI_TEXT_BOUNDARY_WORD_START:
      return Accessibility_TEXT_BOUNDARY_WORD_START;
      break;
    case SPI_TEXT_BOUNDARY_WORD_END:
      return Accessibility_TEXT_BOUNDARY_WORD_END;
      break;
    case SPI_TEXT_BOUNDARY_SENTENCE_START:
      return Accessibility_TEXT_BOUNDARY_SENTENCE_START;
      break;
    case SPI_TEXT_BOUNDARY_SENTENCE_END:
      return Accessibility_TEXT_BOUNDARY_SENTENCE_END;
      break;
    case SPI_TEXT_BOUNDARY_LINE_START:
      return Accessibility_TEXT_BOUNDARY_LINE_START;
      break;
    case SPI_TEXT_BOUNDARY_LINE_END:
      return Accessibility_TEXT_BOUNDARY_LINE_END;
      break;
    case SPI_TEXT_BOUNDARY_ATTRIBUTE_RANGE:
      /* Fixme */
      return Accessibility_TEXT_BOUNDARY_CHAR;
      break;
    default:
      /* FIXME */
      return Accessibility_TEXT_BOUNDARY_CHAR;
    }
}

static Accessibility_TEXT_CLIP_TYPE
get_accessible_text_clip_type (AccessibleTextClipType type)
{
  switch (type)
    {
    case SPI_TEXT_CLIP_NONE:
      return Accessibility_TEXT_CLIP_NONE;
      break;
    case SPI_TEXT_CLIP_MIN:
      return Accessibility_TEXT_CLIP_MIN;
      break;
    case SPI_TEXT_CLIP_MAX:      
      return Accessibility_TEXT_CLIP_MAX;
      break;
    default:
      return Accessibility_TEXT_CLIP_BOTH;
    }
}

static AccessibleTextRange **
get_accessible_text_ranges_from_range_seq (Accessibility_Text_RangeList *range_seq)
{
  AccessibleTextRange **ranges = NULL;
  AccessibleTextRange *array = NULL;
  int i;
  if (range_seq && range_seq->_length > 0) 
    {
      ranges = g_new0 (AccessibleTextRange *, range_seq->_length + 1);
    }
  array = g_new0 (AccessibleTextRange, range_seq->_length);
  for (i = 0; i < range_seq->_length; i++) 
    {
      AccessibleTextRange *range;
      range = &array[i];
      range->start = range_seq->_buffer[i].startOffset;
      range->end = range_seq->_buffer[i].endOffset;
      range->contents = CORBA_string_dup (range_seq->_buffer[i].content);
      ranges[i] = range;
    }
  ranges[i] = NULL; /* null-terminated list! */
  CORBA_free (range_seq);

  return ranges;
}


/**
 * AccessibleText_ref:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 *
 * Increment the reference count for an #AccessibleText object.
 **/
void
AccessibleText_ref (AccessibleText *obj)
{
  cspi_object_ref (obj);
}

/**
 * AccessibleText_unref:
 * @obj: a pointer to the #Accessible object on which to operate.
 *
 * Decrement the reference count for an #AccessibleText object.
 **/
void
AccessibleText_unref (AccessibleText *obj)
{
  cspi_object_unref (obj);
}

/**
 * AccessibleText_getCharacterCount:
 * @obj: a pointer to the #AccessibleText object to query.
 *
 * Get the character count of an #AccessibleText object.
 *
 * Returns: a long integer indicating the total number of
 *              characters in the #AccessibleText object.
 **/
long
AccessibleText_getCharacterCount (AccessibleText *obj)
{
  long retval;

  cspi_return_val_if_fail (obj != NULL, -1);

  retval = Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ());

  cspi_return_val_if_ev ("getCharacterCount", -1);

  return retval;
}

/**
 * AccessibleText_getText:
 * @obj: a pointer to the #AccessibleText object to query.
 * @startOffset: a #long indicating the start of the desired text range.
 * @endOffset: a #long indicating the first character past the desired range.
 *
 * Get a range of text from an #AccessibleText object.  The number of bytes
 *          in the returned string may exceed endOffset-startOffset, since
 *          UTF-8 is a variable-width encoding.
 *
 * Returns: a text string containing characters from @startOffset
 *          to @endOffset-1, inclusive, encoded as UTF-8.
 **/
char *
AccessibleText_getText (AccessibleText *obj,
                        long int startOffset,
                        long int endOffset)
{
  char *retval;

  cspi_return_val_if_fail (obj != NULL, NULL);

  retval =
    Accessibility_Text_getText (CSPI_OBJREF (obj),
				startOffset,
				endOffset,
				cspi_ev ());

  cspi_return_val_if_ev ("getText", NULL);

  return retval;
}

/**
 * AccessibleText_getCaretOffset:
 * @obj: a pointer to the #AccessibleText object to query.
 *
 * Get the current offset of the text caret in an #AccessibleText object.
 *
 * Returns: a long integer indicating the current position of the text caret.
 **/
long
AccessibleText_getCaretOffset (AccessibleText *obj)
{
  long retval;

  cspi_return_val_if_fail (obj != NULL, -1);

  retval =
    Accessibility_Text__get_caretOffset (CSPI_OBJREF (obj), cspi_ev ());

  cspi_return_val_if_ev ("getCaretOffset", -1);

  return retval;
}

/**
 * AccessibleText_getAttributes:
 * @obj: a pointer to the #AccessibleText object to query.
 * @offset: a long integer indicating the offset from which the attribute
 *        search is based.
 * @startOffset: a #long indicating the start of the desired text range.
 * @endOffset: a #long indicating the first character past the desired range.
 *
 * Get the attributes applied to a range of text from an #AccessibleText
 *          object, and the bounds of the range.
 *          The text attributes correspond to CSS attributes where possible,
 *          keys and values are delimited from one another via ":", and
 *          the delimiter between key/value pairs is ";". Thus 
 *          "font-size:10;foreground-color:0,0,0" would be a valid
 *          return string.
 *
 * Returns: a text string describing the attributes occurring within the
 *          attribute run containing @offset, encoded as UTF-8.
 **/
char *
AccessibleText_getAttributes (AccessibleText *obj,
			      long int offset,
			      long int *startOffset,
			      long int *endOffset)
{
  CORBA_long retStartOffset, retEndOffset;
  char *retval;	

  if (obj == NULL)
    {
      *startOffset = *endOffset = -1;
      return NULL;
    }

  retval = Accessibility_Text_getAttributes (CSPI_OBJREF (obj),
				      offset,
				      &retStartOffset,
				      &retEndOffset,
				      cspi_ev ());

  if (!cspi_check_ev ("getAttributes"))
    {
      *startOffset = *endOffset = -1;
      retval = NULL;
    }
  else
    {
      *startOffset = retStartOffset;
      *endOffset   = retEndOffset;
    }

  return retval;
}

/**
 * AccessibleText_getDefaultAttributes:
 * @obj: a pointer to the #AccessibleText object to query.
 *
 * Get the default attributes applied to an #AccessibleText
 *          object.
 *          The text attributes correspond to CSS attributes where possible,
 *          keys and values are delimited from one another via ":", and
 *          the delimiter between key/value pairs is ";". Thus 
 *          "font-size:10;foreground-color:0,0,0" would be a valid
 *          return string.  The combination of this attribute set and
 *          the attributes reported by #AccessibleText_getAttributes
 *          describes the entire set of text attributes over a range.
 *
 * @Since: AT-SPI 1.4
 *
 * Returns: a text string describing the default attributes 
 *          applied to a text object, (exclusive of explicitly-set
 *          attributes), encoded as UTF-8.
 **/
char *
AccessibleText_getDefaultAttributes (AccessibleText *obj)
{
  char *retval;	

  if (obj == NULL)
    {
      return NULL;
    }

  retval = Accessibility_Text_getDefaultAttributes (CSPI_OBJREF (obj),
						    cspi_ev ());

  if (!cspi_check_ev ("getAttributes"))
    {
      retval = NULL;
    }

  return retval;
}

/**
 * AccessibleText_setCaretOffset:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @newOffset: the offset to which the text caret is to be moved.
 *
 * Set the text caret position for an #AccessibleText object.
 *
 * Returns: #TRUE if successful, #FALSE otherwise.
 **/
SPIBoolean
AccessibleText_setCaretOffset (AccessibleText *obj,
                               long int newOffset)
{
  SPIBoolean retval;

  cspi_return_val_if_fail (obj != NULL, FALSE);

  retval =
    Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj),
				       newOffset, cspi_ev ());

  cspi_return_val_if_ev ("setCaretOffset", FALSE);

  return retval;
}

/**
 * AccessibleText_getTextBeforeOffset:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @offset: a long integer indicating the offset from which the delimiter
 *        search is based.
 * @type: an #AccessibleTextBoundaryType indicating whether the desired
 *       text string is a word, sentence, line, or attribute run.
 * @startOffset: a pointer to a long integer which is assigned the
 *       starting offset of the returned string, relative to the
 *       original #AccessibleText.
 * @endOffset: a pointer to a long integer which is assigned the
 *       ending offset of the returned string, relative to the original
 *       #AccessibleText.
 *
 * Get delimited text from an #AccessibleText object which precedes a given
 *          text offset.
 *
 * Returns: a UTF-8 string representing the delimited text, both of whose
 *          delimiting boundaries are before the current offset, or
 *          an empty string if no such text exists.
 **/
char *
AccessibleText_getTextBeforeOffset (AccessibleText *obj,
                                    long int offset,
                                    AccessibleTextBoundaryType type,
				    long int *startOffset,
				    long int *endOffset)
{
  char *retval;
  CORBA_long retStartOffset, retEndOffset;

  if (obj == NULL)
    {
      *startOffset = *endOffset = -1;
      return NULL;
    }

  retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj),
					   offset,
			get_accessible_text_boundary_type (type),
					   &retStartOffset, &retEndOffset,
					   cspi_ev ());
  if (!cspi_check_ev ("getTextBeforeOffset"))
    {
      *startOffset = *endOffset = -1;
      retval = NULL;
    }
  else
    {
      *startOffset = retStartOffset;
      *endOffset = retEndOffset;
    }
  return retval;
}

/**
 * AccessibleText_getTextAtOffset:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @offset: a long integer indicating the offset from which the delimiter
 *        search is based.
 * @type: an #AccessibleTextBoundaryType indicating whether the desired
 *       text string is a word, sentence, line, or attribute run.
 * @startOffset: a pointer to a long integer which is assigned the
 *       starting offset of the returned string, relative to the
 *       original #AccessibleText.
 * @endOffset: a pointer to a long integer which is assigned the
 *       ending offset of the returned string, relative to the original
 *       #AccessibleText.
 *
 * Get delimited text from an #AccessibleText object which includes a given
 *          text offset.
 *
 * Returns: a UTF-8 string representing the delimited text, whose
 *          delimiting boundaries bracket the current offset, or
 *          an empty string if no such text exists.
 **/
char *
AccessibleText_getTextAtOffset (AccessibleText *obj,
				long int offset,
				AccessibleTextBoundaryType type,
				long int *startOffset, long int *endOffset)
{
  CORBA_long corbaStartOffset;
  CORBA_long corbaEndOffset;
  char      *retval;

  if (obj == NULL)
    {
      *startOffset = *endOffset = -1;
      return NULL;
    }

  retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj),
					       offset,
			  get_accessible_text_boundary_type (type),
					       &corbaStartOffset,
					       &corbaEndOffset,
					       cspi_ev ());

  if (!cspi_check_ev ("getTextAtOffset"))
    {
      *startOffset = *endOffset = -1;
      retval = NULL;
    }
  else
    {
      *startOffset = corbaStartOffset;
      *endOffset   = corbaEndOffset;
    }
  return retval;
}

/**
 * AccessibleText_getTextAfterOffset:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @offset: a long integer indicating the offset from which the delimiter
 *        search is based.
 * @type: an #AccessibleTextBoundaryType indicating whether the desired
 *       text string is a word, sentence, line, or attribute run.
 * @startOffset: a pointer to a long integer which is assigned the
 *       starting offset of the returned string, relative to the
 *       original #AccessibleText.
 * @endOffset: a pointer to a long integer which is assigned the
 *       ending offset of the returned string, relative to the original
 *       #AccessibleText.
 *
 * Get delimited text from an #AccessibleText object which follows a given
 *          text offset.
 *
 * Returns: a UTF-8 string representing the delimited text, both of whose
 *          delimiting boundaries are after or inclusive of the current
 *          offset, or an empty string if no such text exists.
 **/
char *
AccessibleText_getTextAfterOffset (AccessibleText *obj,
				   long int offset,
				   AccessibleTextBoundaryType type,
				   long int *startOffset, long int *endOffset)
{
  char *retval;
  CORBA_long retStartOffset, retEndOffset;

  if (obj == NULL)
    {
      *startOffset = *endOffset = -1;
      return NULL;
    }

  retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj),
					   offset,
			     get_accessible_text_boundary_type (type),
					   &retStartOffset, &retEndOffset,
					   cspi_ev ());

  if (!cspi_check_ev ("getTextAfterOffset"))
    {
      *startOffset = *endOffset = -1;
      retval = NULL;
    }
  else
    {
      *startOffset = retStartOffset;
      *endOffset   = retEndOffset;
    }
  return retval;
}

/**
 * AccessibleText_getCharacterAtOffset:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @offset: a long integer indicating the text offset where the desired
 *          character is located.
 *
 * Get the character at a given offset for an #AccessibleText object.
 *
 * Returns: an #unsigned long integer which represents the
 *        UCS-4 unicode code point of the given character, or
 *        0xFFFFFFFF if the character in question cannot be represented
 *        in the UCS-4 encoding.
 **/
unsigned long
AccessibleText_getCharacterAtOffset (AccessibleText *obj,
                                     long int offset)
{
  long retval;

  cspi_return_val_if_fail (obj != NULL, -1);

  retval =
    Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj),
					     offset,
					     cspi_ev ());

  cspi_return_val_if_ev ("getCharacterAtOffset", -1);

  return retval;
}

/**
 * AccessibleText_getCharacterExtents:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @offset: an integer indicating the offset of the text character for
 *        whom boundary information is requested.
 * @x: a pointer to a long integer into which the nominal x coordinate
 *     of the corresponding glyph will be returned.
 * @y:a pointer to a long integer into which the nominal y coordinate
 *     of the corresponding glyph will be returned.
 * @width:a pointer to a long integer into which the width
 *     of the corresponding glyph will be returned.
 * @height: a pointer to a long integer into which the height
 *     of the corresponding glyph will be returned.
 * @type: an #AccessibleCoordType indicating the coordinate system to use
 *        for the returned values.
 *
 * Get the bounding box containing the glyph representing
 *        the character at a particular text offset.
 **/
void
AccessibleText_getCharacterExtents (AccessibleText *obj,
                                    long int offset,
                                    long int *x,
                                    long int *y,
                                    long int *width,
                                    long int *height,
				    AccessibleCoordType type)
{
  CORBA_long retX, retY, retWidth, retHeight;

  if (obj == NULL)
    {
      *x = *y = -1;
      *width = *height = -1;
      return;
    }

  Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj),
					  offset,
					  &retX,
					  &retY,
					  &retWidth,
					  &retHeight,
					  type, cspi_ev ());

  if (!cspi_check_ev ("getCharacterExtents"))
    {
      *x = *y = -1;
      *width = *height = -1;
    }
  else
    {
      *x = retX;
      *y = retY;
      *width = retWidth;
      *height = retHeight;
    }
}

/**
 * AccessibleText_getOffsetAtPoint:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @x: the x coordinate of the point to be queried.
 * @y: the y coordinate of the point to be queried.
 * @type: an #AccessibleCoordType indicating the coordinate system in which
 *       the values should be returned.
 *
 * Get the bounding box for a glyph at a certain #AccessibleText offset.
 *
 * Returns: the offset (as a long integer) at the point (@x, @y)
 *       in the specified coordinate system.
 *
 **/
long
AccessibleText_getOffsetAtPoint (AccessibleText *obj,
                                 long int x,
                                 long int y,
				 AccessibleCoordType type)
{
  long retval;

  cspi_return_val_if_fail (obj != NULL, -1);

  retval =
    Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj),
					 x,
					 y,
					 type, cspi_ev ());

  cspi_return_val_if_ev ("getOffsetAtPoint", -1);

  return retval;
}

/**
 * AccessibleText_getRangeExtents:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @startOffset: an integer indicating the offset of the first text character for
 *        whom boundary information is requested.
 * @endOffset: an integer indicating the offset of the text character 
 *        after the last character for whom boundary information is requested.
 * @x: a pointer to a long integer into which the nominal x coordinate
 *     of the corresponding bounding box will be returned.
 * @y:a pointer to a long integer into which the nominal y coordinate
 *     of the corresponding bounding box will be returned.
 * @width:a pointer to a long integer into which the width
 *     of the corresponding bounding box will be returned.
 * @height: a pointer to a long integer into which the height
 *     of the corresponding bounding box will be returned.
 * @type: an #AccessibleCoordType indicating the coordinate system to use
 *        for the returned values.
 *
 * Get the bounding box for text within a range in an  #AccessibleText object.
 *
 * @Since: AT-SPI 1.2
 **/
void
AccessibleText_getRangeExtents (AccessibleText *obj,
				long int startOffset,
				long int endOffset,
				long int *x,
				long int *y,
				long int *width,
				long int *height,
				AccessibleCoordType type)
{
  CORBA_long retX, retY, retWidth, retHeight;

  if (obj == NULL)
    {
      *x = *y = -1;
      *width = *height = -1;
      return;
    }

  Accessibility_Text_getRangeExtents (CSPI_OBJREF (obj),
				      startOffset,
				      endOffset,
				      &retX,
				      &retY,
				      &retWidth,
				      &retHeight,
				      type, cspi_ev ());

  if (!cspi_check_ev ("getRangeExtents"))
    {
      *x = *y = -1;
      *width = *height = -1;
    }
  else
    {
      *x = retX;
      *y = retY;
      *width = retWidth;
      *height = retHeight;
    }
}

/**
 * AccessibleText_getBoundedRanges:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @x: the 'starting' x coordinate of the bounding box.
 * @y: the 'starting' y coordinate of the bounding box.
 * @width: the x extent of the bounding box.
 * @height: the y extent of the bounding box.
 * @type: an #AccessibleCoordType indicating the coordinate system to use
 *        for the returned values.
 * @clipTypeX: an #AccessibleTextClipType indicating how to treat characters that
 *        intersect the bounding box's x extents.
 * @clipTypeY: an #AccessibleTextClipType indicating how to treat characters that
 *        intersect the bounding box's y extents.
 *
 * Get the ranges of text from an #AccessibleText object which lie within the
 *          bounds defined by (@x, @y) and (@x+@width, @y+@height).  
 *
 * @Since: AT-SPI 1.2
 *
 * Returns: a null-terminated list of pointers to AccessibleTextRange structs 
 *          detailing the bounded text.
 **/
AccessibleTextRange **
AccessibleText_getBoundedRanges (AccessibleText *obj,
				 long int x,
				 long int y,
				 long int width,
				 long int height,
				 AccessibleCoordType type,
				 AccessibleTextClipType clipTypeX,
				 AccessibleTextClipType clipTypeY)
{
  Accessibility_Text_RangeList *range_seq;

  cspi_return_val_if_fail (obj != NULL, NULL);

  range_seq =
    Accessibility_Text_getBoundedRanges (CSPI_OBJREF (obj), 
					 x, y, width, height,
					 type, 
					 get_accessible_text_clip_type (clipTypeX), 
					 get_accessible_text_clip_type (clipTypeY),
					 cspi_ev ());

  cspi_return_val_if_ev ("getBoundedRanges", NULL); 
 
  return get_accessible_text_ranges_from_range_seq (range_seq);
}

/**
 * AccessibleTextRange_freeRanges:
 * @ranges: a pointer to an array of AccessibleTextRange structs.
 *
 * Free the memory used by a list of AccessibleTextRange structs.
 * The argument passed in should be an array of pointers 
 * AccessibleTextRange structs.  
 *
 * @Since: AT-SPI 1.2
 **/
void
AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
{
  /* this was a contiguously allocated block, only free the first element */
  g_free (ranges[0]); 
  g_free (ranges);
}

/**
 * AccessibleText_getNSelections:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 *
 * Get the number of active non-contiguous selections for an
 *          #AccessibleText object.
 *
 * Returns: a long integer indicating the current
 *          number of non-contiguous text selections active
 *          within an #AccessibleText object.
 **/
long
AccessibleText_getNSelections (AccessibleText *obj)
{
  long retval;

  cspi_return_val_if_fail (obj != NULL, -1);

  retval =
    Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ());

  cspi_return_val_if_ev ("getNSelections", -1);

  return retval;
}

/**
 * AccessibleText_getSelection:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @selectionNum: an integer indicating which selection to query.
 * @startOffset: a pointer to a long integer into which the start offset
 *           of the selection will be returned.
 * @endOffset: a pointer to a long integer into which the start offset
 *           of the selection will be returned.
 *
 * Get the bounds of the @selectionNum-th active text selection for an
 *         #AccessibleText object.
 **/
void
AccessibleText_getSelection (AccessibleText *obj,
			     long int selectionNum,
			     long int *startOffset,
			     long int *endOffset)
{
  CORBA_long retStartOffset, retEndOffset;

  if (obj == NULL)
    {
      *endOffset = *startOffset = -1;
      return;
    }

  Accessibility_Text_getSelection (CSPI_OBJREF (obj),
				   selectionNum,
				   &retStartOffset, &retEndOffset,
				   cspi_ev ());

  if (!cspi_check_ev ("getSelection"))
    {
      *startOffset = *endOffset = -1;
    }
  else
    {
      *startOffset = retStartOffset;
      *endOffset   = retEndOffset;
    }
}

/**
 * AccessibleText_addSelection:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @startOffset: the starting offset of the desired new selection.
 * @endOffset: the offset of the first character after the new selection.
 *
 * Select some text (add a text selection) in an #AccessibleText object.
 *
 * Returns: #TRUE if successful, #FALSE otherwise.
 **/
SPIBoolean
AccessibleText_addSelection (AccessibleText *obj,
			     long int startOffset, long int endOffset)
{
  SPIBoolean retval;

  cspi_return_val_if_fail (obj != NULL, FALSE);

  retval =
    Accessibility_Text_addSelection (
      CSPI_OBJREF (obj), startOffset,
      endOffset, cspi_ev ());

  cspi_return_val_if_ev ("addSelection", FALSE);

  return retval;
}

/**
 * AccessibleText_removeSelection:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @selectionNum: an integer indicating which (possibly of several)
 *         text selection to remove.
 *
 * De-select a text selection.
 *
 * Returns: #TRUE if successful, #FALSE otherwise.
 **/
SPIBoolean
AccessibleText_removeSelection (AccessibleText *obj,
				long int selectionNum)
{
  SPIBoolean retval;

  cspi_return_val_if_fail (obj != NULL, FALSE);

  retval =
    Accessibility_Text_removeSelection (
      CSPI_OBJREF (obj), selectionNum, cspi_ev ());

  cspi_return_val_if_ev ("removeSelection", FALSE);

  return retval;
}

/**
 * AccessibleText_setSelection:
 * @obj: a pointer to the #AccessibleText object on which to operate.
 * @selectionNum: a zero-offset index indicating which text selection to modify.
 * @startOffset: a long int, the new starting offset for the selection.
 * @endOffset: a long int, the desired new offset of the first character
 *             after the selection.
 *
 * Change the bounds of an existing #AccessibleText text selection.
 *
 * Returns: #TRUE if successful, #FALSE otherwise.
 **/
SPIBoolean
AccessibleText_setSelection (AccessibleText *obj,
			     long int selectionNum,
			     long int startOffset,
			     long int endOffset)
{
  SPIBoolean retval;

  cspi_return_val_if_fail (obj != NULL, FALSE);

  retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj),
				   selectionNum,
				   startOffset,
				   endOffset, cspi_ev ());

  cspi_return_val_if_ev ("setSelection", FALSE);

  return retval;
}


/**
 * AccessibleText_getAttributeRun:
 * @obj: a pointer to the #AccessibleText object to query.
 * @offset: a long integer indicating the offset from which the attribute
 *        search is based.
 * @startOffset: a #long indicating the start of the desired text range.
 * @endOffset: a #long indicating the first character past the desired range.
 * @includeDefaults: a #bool if False, the call should only return those 
 *                 attributes which are explicitly set on the current attribute 
 *                 run, omitting any attributes which are inherited from the 
 *                 default values.
 *
 *  @Since: AT-SPI 1.7
 *
 * Returns: the AttributeSet defined at offset, optionally including the 'default' attributes.
 **/

AccessibleAttributeSet *
AccessibleText_getAttributeRun (AccessibleText *obj,
				long int offset,
				long int *startOffset,
				long int *endOffset,
			        long int includeDefaults){

  CORBA_long retStartOffset, retEndOffset;
  AccessibleAttributeSet *retval;
  Accessibility_AttributeSet *attributes;

  if (obj == NULL)
  {
       *startOffset = *endOffset = -1;
       return NULL;
  }

  attributes = Accessibility_Text_getAttributeRun (CSPI_OBJREF (obj),
					       offset,
					       &retStartOffset,
					       &retEndOffset,
					       (includeDefaults)? TRUE : FALSE,
					       cspi_ev ());

  if (!cspi_check_ev ("getAttributeRun"))
    {
      *startOffset = *endOffset = -1;
      retval = NULL;
    }
  else 
  {
      *startOffset = retStartOffset;
      *endOffset   = retEndOffset;
  }

  retval =  _cspi_attribute_set_from_sequence (attributes);

  return retval;
				     
}

/**
 * AccessibleText_getDefaultAttributeSet:
 * @obj: a pointer to the #AccessibleText object to query.
 *
 *
 *  @Since: AT-SPI 1.7
 *
 * Returns: an AttributeSet containing the text attributes 
 * which apply to all text in the object by virtue of the
 * default settings of the document, view, or user agent; e.g.
 * those attributes which are implied rather than explicitly 
 * applied to the text object. For instance, an object whose 
 * entire text content has been explicitly marked as 'bold' 
 * will report the 'bold' attribute via getAttributeRun(), 
 * whereas an object whose text weight is inspecified may 
 * report the default or implied text weight in the default AttributeSet.
 *
 **/

AccessibleAttributeSet *
AccessibleText_getDefaultAttributeSet (AccessibleText *obj){
   AccessibleAttributeSet *retval;
   Accessibility_AttributeSet *attributes;

   cspi_return_val_if_fail (obj != NULL, NULL);

  attributes = Accessibility_Text_getDefaultAttributeSet (CSPI_OBJREF (obj), cspi_ev ());
  cspi_return_val_if_ev ("getDefaultAttributeSet", NULL);
  
  retval = _cspi_attribute_set_from_sequence (attributes);
  retval = NULL;
  return retval;
}