~ubuntu-branches/ubuntu/maverick/ldtp/maverick

« back to all changes in this revision

Viewing changes to src/text.c

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2010-02-04 10:36:08 UTC
  • mfrom: (1.4.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20100204103608-dhqdo7jk10ygwt40
Tags: 2.0.2-1
* New upstream release:
  + Packaging is based on Ubuntu packages, Thanks Ubuntu!
  + LDTPv2 is a complete rewrite of LDTPv1 in Python
  + LTFX is completely removed in LDTP v2 in favor of wnck
* debian/control:
  + Updated to Standards-Version 3.8.4 (no changes needed)
  + Fixed typo in description python->Python
  + ldtp is now arch: all package
* debian/rules:
  + Using dh to make it simple
* Removed unused manpages
* Updated package to use new source format 3.0 (quilt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
/*
3
 
 * Linux Desktop Testing Project http://ldtp.freedesktop.org
4
 
 *
5
 
 * Author:
6
 
 *    Nagappan Alagappan <nagappan@gmail.com>
7
 
 *
8
 
 * Copyright 2004 - 2006 Novell, Inc.
9
 
 * Copyright 2007 - 2008 Nagappan Alagappan
10
 
 *
11
 
 * This program is free software; you can redistribute it and/or
12
 
 * modify it under the terms of the GNU Lesser General Public
13
 
 * License as published by the Free Software Foundation; either
14
 
 * version 2 of the License, or (at your option) any later version.
15
 
 *
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
 
 * Lesser General Public License for more details.
20
 
 *
21
 
 * You should have received a copy of the GNU Lesser General Public
22
 
 * License along with this program; if not, write to the
23
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24
 
 * Boston, MA 02110, USA.
25
 
 */
26
 
 
27
 
#include "ldtp.h"
28
 
#include "ldtp-gui.h"
29
 
#include "ldtp-error.h"
30
 
#include "ldtp-logger.h"
31
 
#include "ldtp-command.h"
32
 
#include "ldtp-gui-comp.h"
33
 
 
34
 
extern gboolean ldtp_debug;
35
 
 
36
 
static LDTPErrorCode
37
 
is_text_state_enabled (Accessible *object, FILE *log_fp)
38
 
{
39
 
        LDTPErrorCode error;
40
 
        AccessibleStateSet *state;
41
 
        state = Accessible_getStateSet (object);
42
 
 
43
 
        if (AccessibleStateSet_contains (state, SPI_STATE_EDITABLE))
44
 
                error = LDTP_ERROR_SUCCESS;
45
 
        else
46
 
                error = LDTP_ERROR_TEXT_STATE_NOT_ENABLED;
47
 
        log_msg (LDTP_LOG_INFO, ldtp_error_get_message (error), log_fp);
48
 
        return error;
49
 
}
50
 
 
51
 
static LDTPErrorCode
52
 
set_text_value (Accessible *object, char *text, FILE *log_fp)
53
 
{
54
 
        LDTPErrorCode error;
55
 
 
56
 
        if (text && Accessible_isEditableText (object)) {
57
 
                SPIBoolean flag = FALSE;
58
 
                AccessibleEditableText *editable_text;
59
 
                if (Accessible_isComponent (object)) {
60
 
                        AccessibleComponent *accessible_component;
61
 
                        accessible_component = Accessible_getComponent (object);
62
 
                        flag = AccessibleComponent_grabFocus (accessible_component);
63
 
                        Accessible_unref (accessible_component);
64
 
                }
65
 
                editable_text = Accessible_getEditableText (object);
66
 
                if (editable_text) {
67
 
                        g_print ("Text: %s\n", text);
68
 
                        flag = AccessibleEditableText_setTextContents (editable_text, text);
69
 
                        Accessible_unref (editable_text);
70
 
                }
71
 
                if (flag == FALSE) {
72
 
                        g_print ("%s - %d\n", __FILE__, __LINE__);
73
 
                        error = LDTP_ERROR_UNABLE_TO_SET_TEXT;
74
 
                        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
75
 
                        return error;
76
 
                }
77
 
                return LDTP_ERROR_SUCCESS;
78
 
        } else {
79
 
                g_print ("%s - %d\n", __FILE__, __LINE__);
80
 
                error = LDTP_ERROR_UNABLE_TO_SET_TEXT;
81
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
82
 
                return error;
83
 
        }
84
 
}
85
 
 
86
 
static LDTPErrorCode
87
 
cut_text (Accessible *object, int startpos, int endpos, FILE *log_fp)
88
 
{
89
 
        LDTPErrorCode error;
90
 
        AccessibleEditableText *editableText;
91
 
 
92
 
        if (Accessible_isEditableText (object)) {
93
 
                AccessibleText *text = NULL;
94
 
                editableText = Accessible_getEditableText (object);
95
 
                if (editableText) {
96
 
                        SPIBoolean flag = FALSE;
97
 
                        if (!endpos) {
98
 
                                text = Accessible_getText (object);
99
 
                                if (text) {
100
 
                                        endpos = AccessibleText_getCharacterCount (text);
101
 
                                        Accessible_unref (text);
102
 
                                }
103
 
                                else {
104
 
                                        Accessible_unref (editableText);
105
 
                                        return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
106
 
                                }                                       
107
 
                        }
108
 
                        flag = AccessibleEditableText_cutText (editableText, startpos, endpos);
109
 
                        Accessible_unref (editableText);
110
 
                        if (flag)
111
 
                                return LDTP_ERROR_SUCCESS;
112
 
                        else {
113
 
                                error = LDTP_ERROR_UNABLE_TO_CUT_TEXT;
114
 
                                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
115
 
                                return error;
116
 
                        }
117
 
                }
118
 
        }
119
 
        error = LDTP_ERROR_UNABLE_TO_CUT_TEXT;
120
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
121
 
        return error;
122
 
123
 
 
124
 
static LDTPErrorCode
125
 
activate_text (Accessible *object, FILE *log_fp)
126
 
{
127
 
        long i;
128
 
        long action_count;
129
 
        char *name = NULL;
130
 
        LDTPErrorCode error;
131
 
        SPIBoolean result = FALSE;
132
 
        AccessibleAction *action;
133
 
 
134
 
        name = Accessible_getName (object);
135
 
        g_print ("Text name: %s\n", name);
136
 
        SPI_freeString (name);
137
 
 
138
 
        /*
139
 
          Get action handle of the given object
140
 
        */
141
 
        action = Accessible_getAction (object);
142
 
        action_count = AccessibleAction_getNActions (action);
143
 
        g_print ("action count: %ld\n", action_count);
144
 
        for (i = 0; i < action_count; i++) {
145
 
                char *name, *desc;
146
 
                name = AccessibleAction_getName (action, i);
147
 
                desc = AccessibleAction_getDescription (action, i);
148
 
                g_print ("Name: %s\tDesc: %s\n", name, desc);
149
 
                if (g_ascii_strcasecmp (name, "activate") == 0) {
150
 
                        SPI_freeString (name);
151
 
                        SPI_freeString (desc);
152
 
                        /*
153
 
                          To execute activate action
154
 
                        */
155
 
                        result = AccessibleAction_doAction (action, i);
156
 
                        Accessible_unref (action);
157
 
                        break;
158
 
                }
159
 
                SPI_freeString (name);
160
 
                SPI_freeString (desc);
161
 
        }
162
 
 
163
 
        if (result)
164
 
                g_print ("Activate: success\n");
165
 
        else {
166
 
                error = LDTP_ERROR_UNABLE_TO_ACTIVATE_TEXT;
167
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
168
 
                return error;
169
 
        }
170
 
        return LDTP_ERROR_SUCCESS;
171
 
}
172
 
 
173
 
static LDTPErrorCode
174
 
paste_text (Accessible *object, long pos, FILE *log_fp)
175
 
{
176
 
        LDTPErrorCode error;
177
 
        AccessibleEditableText *editableText;
178
 
 
179
 
        if (Accessible_isEditableText (object)) {
180
 
                SPIBoolean flag = FALSE;
181
 
                editableText = Accessible_getEditableText (object);
182
 
                flag = AccessibleEditableText_pasteText (editableText, pos);
183
 
                Accessible_unref (editableText);
184
 
                if (flag)
185
 
                        return LDTP_ERROR_SUCCESS;
186
 
                else {
187
 
                        error = LDTP_ERROR_UNABLE_TO_PASTE_TEXT;
188
 
                        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
189
 
                        return error;
190
 
                }
191
 
        }
192
 
        error = LDTP_ERROR_UNABLE_TO_PASTE_TEXT;
193
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
194
 
        return error;
195
 
}
196
 
 
197
 
static LDTPErrorCode
198
 
delete_text (Accessible *object, long startpos, long endpos, FILE *log_fp)
199
 
{
200
 
        LDTPErrorCode error;
201
 
        AccessibleEditableText *editableText;
202
 
 
203
 
        if (Accessible_isEditableText (object)) {
204
 
                AccessibleText *text = NULL;
205
 
                editableText = Accessible_getEditableText (object);
206
 
                if (editableText) {
207
 
                        SPIBoolean flag = FALSE;
208
 
                        if (!endpos) {
209
 
                                text = Accessible_getText (object);
210
 
                                if (text) {
211
 
                                        endpos = AccessibleText_getCharacterCount (text);
212
 
                                        Accessible_unref (text);
213
 
                                }
214
 
                                else {
215
 
                                        Accessible_unref (editableText);
216
 
                                        return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
217
 
                                }
218
 
                        }
219
 
                        flag = AccessibleEditableText_deleteText (editableText, startpos, endpos);
220
 
                        Accessible_unref (editableText);
221
 
                        if (flag)
222
 
                                return LDTP_ERROR_SUCCESS;
223
 
                        else {
224
 
                                error = LDTP_ERROR_UNABLE_TO_DELETE_TEXT;
225
 
                                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
226
 
                                return error;
227
 
                        }
228
 
                }
229
 
        }
230
 
        error = LDTP_ERROR_UNABLE_TO_DELETE_TEXT;
231
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
232
 
        return error;
233
 
}
234
 
 
235
 
static LDTPErrorCode
236
 
select_text_by_index_and_region (Accessible *object, long startpos,
237
 
                                 long endpos, long selection_num,
238
 
                                 FILE *log_fp)
239
 
{
240
 
        LDTPErrorCode error;
241
 
        AccessibleEditableText *editableText;
242
 
 
243
 
        if (Accessible_isEditableText (object)) {
244
 
                AccessibleText *text = NULL;
245
 
                editableText = Accessible_getEditableText (object);
246
 
                if (editableText) {
247
 
                        SPIBoolean flag = FALSE;
248
 
                        if (!endpos) {
249
 
                                text = Accessible_getText (object);
250
 
                                if (text) {
251
 
                                        endpos = AccessibleText_getCharacterCount (text);
252
 
                                        Accessible_unref (text);
253
 
                                }
254
 
                                else {
255
 
                                        Accessible_unref (editableText);
256
 
                                        return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
257
 
                                }
258
 
                        }
259
 
                        flag = AccessibleText_setSelection (editableText, selection_num, startpos, endpos);
260
 
                        Accessible_unref (editableText);
261
 
                        if (flag)
262
 
                                return LDTP_ERROR_SUCCESS;
263
 
                        else {
264
 
                                error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT;
265
 
                                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
266
 
                                return error;
267
 
                        }
268
 
                }
269
 
        }
270
 
        error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT;
271
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
272
 
        return error;
273
 
}
274
 
 
275
 
static LDTPErrorCode
276
 
select_text_by_name (Accessible *object, FILE *log_fp)
277
 
{
278
 
        LDTPErrorCode error;
279
 
        SPIBoolean flag = FALSE;
280
 
        AccessibleText *text;
281
 
 
282
 
        text = Accessible_getText (object);
283
 
        if (!text) {
284
 
                error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT;
285
 
                return error;
286
 
        }
287
 
        flag = AccessibleText_addSelection (text, 0,
288
 
                                            AccessibleText_getCharacterCount (text));
289
 
        if (flag)
290
 
                error = LDTP_ERROR_SUCCESS;
291
 
        else {
292
 
                error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT_ITEM;
293
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
294
 
        }
295
 
        Accessible_unref (text);
296
 
        return error;
297
 
}
298
 
 
299
 
static char*
300
 
get_text_value (Accessible *object)
301
 
{
302
 
        char *text = NULL;
303
 
 
304
 
        AccessibleText *accessibleText;
305
 
        g_print ("GETTEXTVALUE\n");
306
 
        accessibleText = Accessible_getText (object);
307
 
        if (accessibleText) {
308
 
                char *tmp = NULL;
309
 
                tmp = AccessibleText_getText (accessibleText, 0,
310
 
                                              AccessibleText_getCharacterCount (accessibleText));
311
 
                if (tmp) {
312
 
                        if (ldtp_debug)
313
 
                                g_print ("Text: %s\n", tmp);
314
 
                        text = g_strdup (tmp);
315
 
                        SPI_freeString (tmp);
316
 
                }
317
 
                Accessible_unref (accessibleText);
318
 
        }
319
 
        return text;
320
 
}
321
 
 
322
 
static LDTPErrorCode
323
 
append_text (Accessible *object, char *text, FILE *log_fp)
324
 
{
325
 
        char *tmp = NULL;
326
 
        LDTPErrorCode error;
327
 
        char *available_text = NULL;
328
 
        if (text == NULL) {
329
 
                error = LDTP_ERROR_ARGUMENT_NULL;
330
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
331
 
                return error;
332
 
        }
333
 
        available_text = get_text_value (object);
334
 
        if (!available_text) {
335
 
                error = LDTP_ERROR_UNABLE_TO_APPEND_TEXT;
336
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
337
 
                return error;
338
 
        }
339
 
        tmp = g_strdup_printf ("%s%s", available_text, text);
340
 
        free (available_text);
341
 
        error = set_text_value (object, tmp, log_fp);
342
 
        free (tmp);
343
 
        if (error == LDTP_ERROR_SUCCESS)
344
 
                return error;
345
 
        error = LDTP_ERROR_UNABLE_TO_APPEND_TEXT;
346
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
347
 
        return error;
348
 
}
349
 
 
350
 
static LDTPErrorCode
351
 
verify_set_text_value (Accessible *object, char *verify_text, FILE *log_fp)
352
 
{
353
 
        char *text = NULL;
354
 
        AccessibleText *text_object = NULL;
355
 
        LDTPErrorCode error;
356
 
        
357
 
        text_object = Accessible_getText (object);
358
 
        if (text_object) {
359
 
                text = AccessibleText_getText (text_object, 0, AccessibleText_getCharacterCount (text_object));
360
 
                Accessible_unref (text_object);
361
 
                g_print ("Text: %s\n", text);
362
 
        }
363
 
        else {
364
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
365
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
366
 
                return error;
367
 
        }
368
 
 
369
 
        if (verify_text == NULL || text == NULL ||
370
 
            g_utf8_collate (verify_text, text) != 0) {
371
 
                LDTPErrorCode error;
372
 
                SPI_freeString (text);
373
 
                error = LDTP_ERROR_VERIFY_SET_TEXT_FAILED;
374
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
375
 
                return error;
376
 
        }
377
 
        else
378
 
                SPI_freeString (text);
379
 
        return LDTP_ERROR_SUCCESS;
380
 
}
381
 
 
382
 
static LDTPErrorCode
383
 
verify_partial_match (Accessible *object, char *textvalue, FILE *log_fp)
384
 
{
385
 
        char *tmp = NULL,*sub = NULL;
386
 
        LDTPErrorCode error;
387
 
        AccessibleText *accessibleText;
388
 
        int i, j, k;
389
 
        
390
 
        sub = textvalue;
391
 
        accessibleText = Accessible_getText (object);
392
 
        if (accessibleText == NULL) {
393
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
394
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
395
 
                return error;
396
 
        }
397
 
        
398
 
        tmp = AccessibleText_getText (accessibleText, 0, -1);
399
 
        Accessible_unref (accessibleText);
400
 
        
401
 
        for (i = 0 ; tmp[i] != '\0' ; i++) {
402
 
                for(j = i, k=0; sub && sub[k] != '\0' && tmp[j] == sub[k] ; j++ , k++) 
403
 
                        ; /* Do nothing */
404
 
                if( k > 0 && sub[k] == '\0')
405
 
                        return LDTP_ERROR_SUCCESS;
406
 
        }
407
 
        error = LDTP_ERROR_VERIFY_PARTIAL_MATCH_FAILED;
408
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
409
 
        return error;
410
 
}
411
 
 
412
 
static LDTPErrorCode
413
 
get_text (Accessible *object, GSList **l)
414
 
{
415
 
        char *tmp = NULL;
416
 
        long startpos = 0;
417
 
        long endpos = 0;
418
 
        GSList *tmp_list = *l;
419
 
        AccessibleText *accessibleText;
420
 
        LDTPErrorCode error;
421
 
        
422
 
        accessibleText = Accessible_getText (object);
423
 
        if (accessibleText == NULL) {
424
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
425
 
                return error;
426
 
        }
427
 
 
428
 
        if (tmp_list && tmp_list->data) {
429
 
                startpos = atol (tmp_list->data);
430
 
                tmp_list = tmp_list->next;
431
 
        }
432
 
        if (tmp_list && tmp_list->data && atol (tmp_list->data) > 0)
433
 
                endpos = atol (tmp_list->data);
434
 
        else
435
 
                endpos = AccessibleText_getCharacterCount (accessibleText);
436
 
        g_print ("Start: %ld, End: %ld\n", startpos, endpos);
437
 
        tmp = AccessibleText_getText (accessibleText, startpos, endpos);
438
 
 
439
 
        Accessible_unref (accessibleText);
440
 
        if (tmp) {
441
 
                *l = g_slist_prepend (*l, g_strdup (tmp));
442
 
                g_print ("GetTextValue: %s\n", tmp);
443
 
                SPI_freeString (tmp);
444
 
                return LDTP_ERROR_SUCCESS;
445
 
        }
446
 
        else
447
 
                return LDTP_ERROR_GETTEXTVALUE_FAILED;
448
 
}
449
 
 
450
 
static long
451
 
get_character_count (Accessible *object)
452
 
{
453
 
        AccessibleText *accessibleText;
454
 
        long len;
455
 
        accessibleText = Accessible_getText (object);
456
 
        if (accessibleText == NULL)
457
 
                return (long) -1;
458
 
 
459
 
        len =  AccessibleText_getCharacterCount (accessibleText);
460
 
        Accessible_unref (accessibleText);
461
 
        return len;
462
 
}
463
 
 
464
 
static long
465
 
get_cursor_position (Accessible *object)
466
 
{
467
 
        AccessibleText *accessibleText;
468
 
        long pos;
469
 
        accessibleText = Accessible_getText (object);//cctxt->gui_handle->handle);
470
 
 
471
 
        if (accessibleText == NULL)
472
 
                return (long) -1;
473
 
        
474
 
        pos = AccessibleText_getCaretOffset (accessibleText);
475
 
        g_print ("Setting Caret position to %ld\n",pos);
476
 
        Accessible_unref (accessibleText);
477
 
        return pos;
478
 
}
479
 
 
480
 
static LDTPErrorCode
481
 
set_cursor_position (LDTPClientContext *cctxt)
482
 
{
483
 
        AccessibleText *accessibleText;
484
 
        LDTPErrorCode error;
485
 
        SPIBoolean flag;
486
 
        long offset;
487
 
        long count;
488
 
        FILE *log_fp = cctxt->log_fp;
489
 
 
490
 
        if (!cctxt->req->arg_list || !cctxt->req->arg_list->data) {
491
 
                error = LDTP_ERROR_ARGUMENT_NULL;
492
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
493
 
                return error;
494
 
        }
495
 
        offset = atol (cctxt->req->arg_list->data);
496
 
        count = get_character_count (cctxt->gui_handle->handle);
497
 
        if (count < offset) {
498
 
                error = LDTP_ERROR_OFFSET_OUT_OF_BOUND;
499
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
500
 
                return error;
501
 
        }
502
 
 
503
 
        accessibleText = Accessible_getText (cctxt->gui_handle->handle);
504
 
        if (accessibleText == NULL) {
505
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
506
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
507
 
                return error;
508
 
        }
509
 
        
510
 
        flag = AccessibleText_setCaretOffset (accessibleText, offset);
511
 
        if (flag == FALSE) {
512
 
                error = LDTP_ERROR_UNABLE_TO_SET_CARET;
513
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
514
 
                return error;
515
 
        }
516
 
        Accessible_unref (accessibleText);
517
 
 
518
 
        return LDTP_ERROR_SUCCESS;
519
 
}
520
 
 
521
 
static LDTPErrorCode
522
 
copy_text (Accessible *object, int startpos, int endpos, FILE *log_fp)
523
 
{
524
 
        LDTPErrorCode error;
525
 
        AccessibleText *editableText;
526
 
 
527
 
        if (Accessible_isEditableText (object)) {
528
 
                AccessibleText *text = NULL;
529
 
                editableText = Accessible_getEditableText (object);
530
 
                if (editableText) {
531
 
                        SPIBoolean flag = FALSE;
532
 
                        if (!endpos) {
533
 
                                text = Accessible_getText (object);
534
 
                                if (text) {
535
 
                                        endpos = AccessibleText_getCharacterCount (text);
536
 
                                        Accessible_unref (text);
537
 
                                }
538
 
                                else {
539
 
                                        Accessible_unref (editableText);
540
 
                                        return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
541
 
                                }                                       
542
 
                        }
543
 
                        flag = AccessibleEditableText_copyText (editableText, startpos, endpos);
544
 
                        Accessible_unref (editableText);
545
 
                        if (flag)
546
 
                                return LDTP_ERROR_SUCCESS;
547
 
                        else {
548
 
                                error = LDTP_ERROR_UNABLE_TO_COPY_TEXT;
549
 
                                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
550
 
                                return error;
551
 
                        }
552
 
                }
553
 
        }
554
 
        error = LDTP_ERROR_UNABLE_TO_COPY_TEXT;
555
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
556
 
        return error;
557
 
}
558
 
 
559
 
static LDTPErrorCode
560
 
insert_text (Accessible *object, char *text, int pos, FILE *log_fp)
561
 
{
562
 
        long len = 0;
563
 
        LDTPErrorCode error;
564
 
        AccessibleEditableText *editableText;
565
 
        long present_length = 0;
566
 
        
567
 
        if (text == NULL) {
568
 
                error = LDTP_ERROR_TEXT_TO_INSERT_IS_EMPTY;
569
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
570
 
                return error;
571
 
        }
572
 
        present_length = get_character_count (object);
573
 
        if (pos>present_length)
574
 
                log_msg (LDTP_LOG_WARNING, "Inserting text in earlier position due to inadequate text present", log_fp);
575
 
        len = strlen (text);
576
 
 
577
 
        g_print ("Length of text = %ld\n", len +1);
578
 
        if (Accessible_isEditableText (object)) {
579
 
                SPIBoolean flag = FALSE;
580
 
                editableText = Accessible_getEditableText (object);
581
 
                flag = AccessibleEditableText_insertText (editableText, pos, text, len);
582
 
                Accessible_unref (editableText);
583
 
                if (flag == TRUE)
584
 
                        return LDTP_ERROR_SUCCESS;
585
 
        }
586
 
        error = LDTP_ERROR_UNABLE_TO_INSERT_TEXT;
587
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
588
 
        return error;
589
 
}
590
 
 
591
 
static LDTPErrorCode
592
 
get_text_property (Accessible *object, GSList **l, FILE *log_fp)
593
 
{
594
 
        long start_pos = 0;
595
 
        long end_pos = 0;
596
 
        long int diff, zero = 0;
597
 
        GSList *tmp = *l;
598
 
        char *text_prop = NULL;
599
 
        AccessibleText *accessibleText;
600
 
        LDTPErrorCode error;
601
 
        
602
 
        accessibleText = Accessible_getText (object);
603
 
        if (accessibleText == NULL) {
604
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
605
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
606
 
                return error;
607
 
        }
608
 
 
609
 
        if (tmp && tmp->data) {
610
 
                start_pos = atol (tmp->data);
611
 
                tmp = tmp->next;
612
 
                if (tmp && tmp->data && (atol (tmp->data) > 0))
613
 
                        end_pos = atol (tmp->data);
614
 
                else
615
 
                        end_pos = AccessibleText_getCharacterCount (accessibleText);
616
 
        }
617
 
 
618
 
        diff = end_pos - start_pos;
619
 
        text_prop = AccessibleText_getAttributes (accessibleText, start_pos, &zero, &diff);
620
 
        /* AccessibleText_getAttributes doesn't seem to be taking the
621
 
        end position i.e. the diff value into account. It only checks
622
 
        from the start position */
623
 
 
624
 
        if (text_prop) {
625
 
                /* 
626
 
                   We don't have to free params[0] as they are just pointers
627
 
                   to actual parameters in LDTPRequest structure.
628
 
                */
629
 
                *l = g_slist_prepend (*l, g_strdup (text_prop));
630
 
                SPI_freeString (text_prop);
631
 
                Accessible_unref (accessibleText);
632
 
                return LDTP_ERROR_SUCCESS;
633
 
        }
634
 
        else {
635
 
                LDTPErrorCode error;
636
 
                /* 
637
 
                   We don't have to free params[0] as they are just pointers
638
 
                   to actual parameters in LDTPRequest structure.
639
 
                */
640
 
                Accessible_unref (accessibleText);
641
 
                error = LDTP_ERROR_UNABLE_TO_GET_TEXT_PROPERTY;
642
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
643
 
                return error;
644
 
        }
645
 
}
646
 
 
647
 
static LDTPErrorCode
648
 
compare_text_property (Accessible *object, GSList *l, FILE *log_fp)
649
 
{
650
 
        char *key;
651
 
        char *value;
652
 
        long start_pos = 0;
653
 
        long end_pos = 0;
654
 
        GSList *tmp = l;
655
 
        LDTPErrorCode error;
656
 
        char *text_prop = NULL;
657
 
        char *specimen_prop = NULL;
658
 
        int total = 0;
659
 
        gboolean flag = FALSE;
660
 
        GHashTable *property_table;
661
 
        AccessibleText *accessibleText;
662
 
 
663
 
        accessibleText = Accessible_getText (object);
664
 
        if (accessibleText == NULL) {
665
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
666
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
667
 
                return error;
668
 
        }
669
 
        
670
 
        if (tmp && tmp->data) {
671
 
                start_pos = atol (tmp->data);
672
 
                tmp = tmp->next;
673
 
                if (tmp && tmp->data && (atol (tmp->data) > 0))
674
 
                        end_pos = atol (tmp->data);
675
 
                else
676
 
                        end_pos = AccessibleText_getCharacterCount (accessibleText);
677
 
        }
678
 
        tmp = tmp->next;
679
 
        specimen_prop = g_strdup (tmp->data);
680
 
        text_prop = AccessibleText_getAttributes (accessibleText, 0, &start_pos, &end_pos);
681
 
 
682
 
        if (text_prop) {
683
 
                property_table = g_hash_table_new (&g_str_hash, &g_str_equal);
684
 
                key = strtok (g_strdup (specimen_prop), ":");
685
 
                while (key) {
686
 
                        key = g_strdup (g_strstrip (key));
687
 
                        value = strtok (NULL, ";");
688
 
                        if (value)
689
 
                                value = g_strdup (g_strstrip (value));
690
 
                        g_hash_table_insert (property_table, g_strdup (key), g_strdup (value));
691
 
                        total++;
692
 
                        g_free (value);
693
 
                        g_free (key);
694
 
                        key = strtok (NULL, ":");
695
 
                }
696
 
                g_print ("Obtained text property: %s\n", text_prop);
697
 
                key = strtok (strdup (text_prop), ":");
698
 
                while (key) {
699
 
                        char *hash_value;
700
 
                        key = g_strdup (g_strstrip (key));
701
 
                        value = strtok (NULL, ";");
702
 
                        if (value)
703
 
                                value = g_strdup (g_strstrip (value));
704
 
                        hash_value = g_hash_table_lookup (property_table, key);
705
 
                        if (hash_value) {
706
 
                                if (g_utf8_collate (value, hash_value) == 0)
707
 
                                        total--;
708
 
                                else {
709
 
                                        g_free (value);
710
 
                                        flag = TRUE;
711
 
                                        break;
712
 
                                }
713
 
                        } else {
714
 
                                g_free (value);
715
 
                                flag = TRUE;
716
 
                                break;
717
 
                        }
718
 
                        g_free (value);
719
 
                        key = strtok (NULL, ":");
720
 
                }
721
 
                g_hash_table_destroy (property_table);
722
 
                SPI_freeString (text_prop);
723
 
                g_free (specimen_prop);
724
 
                Accessible_unref (accessibleText);
725
 
 
726
 
                if (total == 0 && flag == FALSE)
727
 
                        return LDTP_ERROR_SUCCESS;
728
 
                error = LDTP_ERROR_ONE_OR_MORE_PROPERTIES_DOES_NOT_MATCH;
729
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
730
 
                return error;
731
 
        }
732
 
        g_free (specimen_prop);
733
 
        Accessible_unref (accessibleText);
734
 
        error = LDTP_ERROR_UNABLE_TO_GET_TEXT_PROPERTY;
735
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
736
 
        return error;
737
 
}
738
 
 
739
 
static LDTPErrorCode
740
 
contains_text_property (Accessible *object, GSList *l, FILE *log_fp)
741
 
{
742
 
        char *key = NULL;
743
 
        char *value = NULL;
744
 
        long start_pos = 0;
745
 
        long end_pos = 0;
746
 
        LDTPErrorCode error;
747
 
        char *text_prop = NULL;
748
 
        char *property = NULL;
749
 
        char *prop_key = NULL;
750
 
        char *prop_value = NULL;
751
 
        GHashTable *property_table;
752
 
        AccessibleText *accessibleText;
753
 
 
754
 
        accessibleText = Accessible_getText (object);
755
 
        if (accessibleText == NULL) {
756
 
                error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
757
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
758
 
                return error;
759
 
        }
760
 
        
761
 
        if (l && l->data) {
762
 
                start_pos = atol (l->data);
763
 
                l = l->next;
764
 
                if (l && l->data && (atol (l->data) > 0))
765
 
                        end_pos = atol (l->data);
766
 
                else
767
 
                        end_pos = AccessibleText_getCharacterCount (accessibleText);
768
 
        }
769
 
        l = l->next;
770
 
        if (l && l->data)
771
 
                property = strdup (l->data);
772
 
        text_prop = AccessibleText_getAttributes (accessibleText, 0, &start_pos, &end_pos);
773
 
 
774
 
        if (text_prop) {
775
 
                property_table = g_hash_table_new (&g_str_hash, &g_str_equal);
776
 
                g_print ("Obtained text property: %s\n", text_prop);
777
 
                key = strtok (strdup (text_prop), ":");
778
 
                while (key) {
779
 
                        key = g_strdup (g_strstrip (key));
780
 
                        value = strtok (NULL, ";");
781
 
                        if (value)
782
 
                                value = g_strdup (g_strstrip (value));
783
 
                        g_hash_table_insert (property_table, g_strdup (key), g_strdup (value));
784
 
                        g_free (value);
785
 
                        g_free (key);
786
 
                        key = strtok (NULL, ":");
787
 
                }
788
 
                prop_key = strtok (strdup (property), ":");
789
 
                prop_value = strtok (NULL, ";");
790
 
                if (prop_key && prop_value) {
791
 
                        value = g_hash_table_lookup (property_table, prop_key);
792
 
                        if (value) {
793
 
                                if (g_utf8_collate (value, prop_value) == 0) {
794
 
                                        g_free (property);
795
 
                                        g_free (prop_key);
796
 
                                        Accessible_unref (accessibleText);
797
 
                                        g_hash_table_destroy (property_table);
798
 
                                        SPI_freeString (text_prop);
799
 
                                        log_msg (LDTP_LOG_INFO, "Property matches", log_fp);
800
 
                                        return LDTP_ERROR_SUCCESS;
801
 
                                }
802
 
                                else {
803
 
                                        g_free (property);
804
 
                                        g_free (prop_key);
805
 
                                        Accessible_unref (accessibleText);
806
 
                                        g_hash_table_destroy (property_table);
807
 
                                        SPI_freeString (text_prop);
808
 
                                        error = LDTP_ERROR_TEXT_OBJECT_VALUE_CONTAINS_DIFF_PROEPRTY;
809
 
                                        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
810
 
                                        return error;
811
 
                                }
812
 
                        }
813
 
                        else {
814
 
                                g_free (property);
815
 
                                g_free (prop_key);
816
 
                                Accessible_unref (accessibleText);
817
 
                                SPI_freeString (text_prop);
818
 
                                error = LDTP_ERROR_TEXT_OBJECT_DOES_NOT_CONTAIN_PROEPRTY;
819
 
                                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
820
 
                                return error;
821
 
                        }
822
 
                }
823
 
                else {
824
 
                        g_free (property);
825
 
                        Accessible_unref (accessibleText);
826
 
                        SPI_freeString (text_prop);
827
 
                        error = LDTP_ERROR_TEXT_PROEPRTY_VALUE_PAIR_IS_INVALID;
828
 
                        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
829
 
                        return error;
830
 
                }
831
 
        }
832
 
        else {
833
 
                g_free (property);
834
 
                Accessible_unref (accessibleText);
835
 
                error = LDTP_ERROR_UNABLE_TO_GET_TEXT_PROPERTY;
836
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
837
 
                return error;
838
 
        }
839
 
}
840
 
 
841
 
static LDTPErrorCode
842
 
right_click (Accessible *object)
843
 
{
844
 
        gboolean flag = FALSE;
845
 
        long x, y, height, width;
846
 
        if (Accessible_isComponent (object)) {
847
 
                AccessibleComponent *accessible_component;
848
 
                accessible_component = Accessible_getComponent (object);
849
 
                AccessibleComponent_getExtents (accessible_component,
850
 
                                                &x, &y, &height, &width,
851
 
                                                SPI_COORD_TYPE_WINDOW);
852
 
                if (ldtp_debug) {
853
 
                        g_print ("X = %ld, Y = %ld, Width = %ld, Height = %ld\n",
854
 
                                 x, y, width, height);
855
 
                        g_print ("X = %ld, Y = %ld, Width / 2 = %ld, Height / 2 = %ld\n",
856
 
                                 x, y, (x + width) / 2, (y + height) / 2);
857
 
                }
858
 
                flag = AccessibleComponent_grabFocus (accessible_component);
859
 
                Accessible_unref (accessible_component);
860
 
        }
861
 
        if (flag && SPI_generateMouseEvent ((x + width) / 2, (y + height) / 2, "b3c"))
862
 
                return LDTP_ERROR_SUCCESS;
863
 
        else
864
 
                return LDTP_ERROR_RIGHT_CLICK_FAILED;
865
 
}
866
 
 
867
 
LDTPErrorCode
868
 
text_main (LDTPClientContext* cctxt, int command)
869
 
{
870
 
        LDTPErrorCode error;
871
 
        switch (command) {
872
 
        case LDTP_CMD_SETTEXTVALUE:
873
 
                if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
874
 
                        error = set_text_value (cctxt->gui_handle->handle,
875
 
                                                "", cctxt->log_fp);
876
 
                else
877
 
                        error = set_text_value (cctxt->gui_handle->handle,
878
 
                                                cctxt->req->arg_list->data,
879
 
                                                cctxt->log_fp);
880
 
                break;
881
 
        case LDTP_CMD_CUTTEXT: {
882
 
                long startpos = 0;
883
 
                long endpos = 0;
884
 
                GSList *l = cctxt->req->arg_list;
885
 
                if (l && l->data) {
886
 
                        startpos = atol (l->data);
887
 
                        l = l->next;
888
 
                        if (l && l->data)
889
 
                                endpos = atol (l->data);
890
 
                }
891
 
                /*TODO: Check if the given positions are within the character length*/
892
 
                error = cut_text (cctxt->gui_handle->handle, startpos, endpos, cctxt->log_fp);
893
 
                break;
894
 
        }
895
 
        case LDTP_CMD_PASTETEXT: {
896
 
                long pos = 0;
897
 
                if (cctxt->req->arg_list && cctxt->req->arg_list->data)
898
 
                        pos = atol (cctxt->req->arg_list->data);
899
 
                error = paste_text (cctxt->gui_handle->handle, pos, cctxt->log_fp);
900
 
                break;
901
 
        }
902
 
        case LDTP_CMD_ACTIVATETEXT:
903
 
                error = activate_text (cctxt->gui_handle->handle, cctxt->log_fp);
904
 
                break;
905
 
        case LDTP_CMD_DELETETEXT: {
906
 
                long startpos = 0;
907
 
                long endpos = 0;
908
 
                GSList *l = cctxt->req->arg_list;
909
 
                if (l && l->data) {
910
 
                        startpos = atol (l->data);
911
 
                        l = l->next;
912
 
                        if (l && l->data)
913
 
                                endpos = atol (l->data);
914
 
                }
915
 
                /*TODO: check if the given positions are within the available text length*/
916
 
                error = delete_text (cctxt->gui_handle->handle, startpos, endpos, cctxt->log_fp);
917
 
                break;
918
 
        }
919
 
        case LDTP_CMD_SELECTTEXTBYINDEXANDREGION: {
920
 
                /*
921
 
                  Select text based on index and optional region text
922
 
                */
923
 
                long startpos = 0;
924
 
                long endpos = 0;
925
 
                long selection_num = 0;
926
 
                GSList *l = cctxt->req->arg_list;
927
 
                if (l && l->data) {
928
 
                        startpos = atol (l->data);
929
 
                        l = l->next;
930
 
                        if (l && l->data) {
931
 
                                endpos = atol (l->data);
932
 
                                l = l->next;
933
 
                                if (l && l->data)
934
 
                                        selection_num = atol (l->data);
935
 
                        }
936
 
                }
937
 
                /*TODO: check if the given positions are within the available text length*/
938
 
                error = select_text_by_index_and_region (cctxt->gui_handle->handle,
939
 
                                                         selection_num, startpos,
940
 
                                                         endpos, cctxt->log_fp);
941
 
                break;
942
 
        }
943
 
        case LDTP_CMD_SELECTTEXTBYNAME:
944
 
                error = select_text_by_name (cctxt->gui_handle->handle, cctxt->log_fp);
945
 
                break;
946
 
        case LDTP_CMD_APPENDTEXT:
947
 
                if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
948
 
                        error = append_text (cctxt->gui_handle->handle,
949
 
                                             "", cctxt->log_fp);
950
 
                else
951
 
                        error = append_text (cctxt->gui_handle->handle,
952
 
                                             cctxt->req->arg_list->data, cctxt->log_fp);
953
 
                break;
954
 
        case LDTP_CMD_VERIFYPARTIALMATCH:
955
 
                if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
956
 
                        error = verify_partial_match (cctxt->gui_handle->handle,
957
 
                                                      "", cctxt->log_fp);
958
 
                else
959
 
                        error = verify_partial_match (cctxt->gui_handle->handle,
960
 
                                                      cctxt->req->arg_list->data,
961
 
                                                      cctxt->log_fp);
962
 
                break;  
963
 
        case LDTP_CMD_GETTEXTVALUE:
964
 
                error = get_text (cctxt->gui_handle->handle, &cctxt->req->arg_list);
965
 
                if (error == LDTP_ERROR_SUCCESS) {
966
 
                        if (cctxt->req->arg_list && cctxt->req->arg_list->data) {
967
 
                                cctxt->resp->data = cctxt->req->arg_list->data;
968
 
                                cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
969
 
                                cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list, cctxt->req->arg_list->data);
970
 
                        } else {
971
 
                                error = LDTP_ERROR_GETTEXTVALUE_FAILED;
972
 
                                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), cctxt->log_fp);
973
 
                                return error;
974
 
                        }
975
 
                }
976
 
                break;
977
 
        case LDTP_CMD_VERIFYSETTEXT:
978
 
                if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
979
 
                        error = verify_set_text_value (cctxt->gui_handle->handle,
980
 
                                                       "", cctxt->log_fp);
981
 
                else
982
 
                        error = verify_set_text_value (cctxt->gui_handle->handle,
983
 
                                                       cctxt->req->arg_list->data,
984
 
                                                       cctxt->log_fp);
985
 
                break;
986
 
        case LDTP_CMD_GRABFOCUS:
987
 
                error = grab_focus (cctxt->gui_handle->handle, cctxt->log_fp);
988
 
                break;
989
 
        case LDTP_CMD_GETCHARCOUNT:
990
 
                cctxt->resp->data = g_strdup_printf ("%ld", get_character_count (cctxt->gui_handle->handle));
991
 
                cctxt->resp->data_len = strlen (cctxt->resp->data);
992
 
                error =  (LDTP_ERROR_SUCCESS);
993
 
                break;
994
 
        case LDTP_CMD_COPYTEXT: {
995
 
                long startpos = 0;
996
 
                long endpos = 0;
997
 
                GSList *l = cctxt->req->arg_list;
998
 
                if (l && l->data) {
999
 
                        startpos = atol (l->data);
1000
 
                        l = l->next;
1001
 
                        if (l && l->data)
1002
 
                                endpos = atol (l->data);
1003
 
                }
1004
 
                /*TODO: check if the given positions are within the available text length*/
1005
 
                error = copy_text (cctxt->gui_handle->handle, startpos, endpos,
1006
 
                                   cctxt->log_fp);
1007
 
                break;
1008
 
        }
1009
 
        case LDTP_CMD_INSERTTEXT: {
1010
 
                long pos = 0;
1011
 
                char *text = NULL;
1012
 
                GSList *l = cctxt->req->arg_list;
1013
 
                if (l && l->data) {
1014
 
                        pos = atol(l->data);
1015
 
                        l = l->next;
1016
 
                        if (l && l->data) {
1017
 
                                text = l->data;
1018
 
                        }
1019
 
                }
1020
 
                
1021
 
                if (text == NULL)
1022
 
                        error = insert_text (cctxt->gui_handle->handle, "",
1023
 
                                             pos, cctxt->log_fp);
1024
 
                else
1025
 
                        error = insert_text (cctxt->gui_handle->handle, text,
1026
 
                                             pos, cctxt->log_fp);
1027
 
                break;
1028
 
        }
1029
 
        case LDTP_CMD_GETTEXTPROPERTY:
1030
 
                error = get_text_property (cctxt->gui_handle->handle,
1031
 
                                           &cctxt->req->arg_list, cctxt->log_fp);
1032
 
                if (error == LDTP_ERROR_SUCCESS) {
1033
 
                        cctxt->resp->data = cctxt->req->arg_list->data;
1034
 
                        cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
1035
 
                        cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list, cctxt->req->arg_list->data);
1036
 
                }
1037
 
                break;
1038
 
        case LDTP_CMD_COMPARETEXTPROPERTY:
1039
 
                error = compare_text_property (cctxt->gui_handle->handle,
1040
 
                                               cctxt->req->arg_list, cctxt->log_fp);
1041
 
                break;
1042
 
        case LDTP_CMD_CONTAINSTEXTPROPERTY:
1043
 
                error = contains_text_property (cctxt->gui_handle->handle,
1044
 
                                                cctxt->req->arg_list, cctxt->log_fp);
1045
 
                break;
1046
 
        case LDTP_CMD_ISTEXTSTATEENABLED:
1047
 
                error = is_text_state_enabled (cctxt->gui_handle->handle, cctxt->log_fp);
1048
 
                break;
1049
 
        case LDTP_CMD_RIGHTCLICK:
1050
 
                error = right_click (cctxt->gui_handle->handle);
1051
 
                break;
1052
 
        case LDTP_CMD_MOUSELEFTCLICK:
1053
 
        case LDTP_CMD_MOUSERIGHTCLICK:
1054
 
                error = is_text_state_enabled (cctxt->gui_handle->handle, cctxt->log_fp);
1055
 
                if (error != LDTP_ERROR_SUCCESS)
1056
 
                        error = device_main (cctxt, command);
1057
 
                break;
1058
 
        case LDTP_CMD_MOUSEMOVE:
1059
 
        case LDTP_CMD_KBDENTER:
1060
 
                error = device_main (cctxt, command);
1061
 
                break;
1062
 
        case LDTP_CMD_SETCURSORPOSITION:
1063
 
                error = set_cursor_position (cctxt);
1064
 
                break;
1065
 
        case LDTP_CMD_GETCURSORPOSITION: {
1066
 
                glong position;
1067
 
                position = get_cursor_position (cctxt->gui_handle->handle);
1068
 
                if (position == -1)
1069
 
                        error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
1070
 
                else {
1071
 
                        cctxt->resp->data = g_strdup_printf ("%ld", position);
1072
 
                        cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
1073
 
                        error = LDTP_ERROR_SUCCESS;
1074
 
                }
1075
 
                break;
1076
 
        }
1077
 
        default:
1078
 
                error = LDTP_ERROR_COMMAND_NOT_IMPLEMENTED;
1079
 
        }
1080
 
        return error;
1081
 
}