static const char * get_name (AtkObject *accessible) { char *name; name = g_object_get_data (G_OBJECT (accessible), "gtk-accessibility-dump-name"); if (name) return name; if (GTK_IS_ACCESSIBLE (accessible)) { GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); name = g_strdup (gtk_buildable_get_name (GTK_BUILDABLE (widget))); } if (name == NULL && ATK_IS_TEXT (accessible)) { name = atk_text_get_text (ATK_TEXT (accessible), 0, -1); } if (name == NULL) { /* Generate a unique, repeatable name */ name = g_strdup_printf ("unnamed-%s-%d", G_OBJECT_TYPE_NAME (accessible), unnamed_object_count++); } g_object_set_data_full (G_OBJECT (accessible), "gtk-accessibility-dump-name", name, g_free); return name; }
static void _do_test(AtkObject *obj) { const char *type_name = g_type_name(G_TYPE_FROM_INSTANCE(obj)); AtkStateSet *state_set = atk_object_ref_state_set(obj); g_assert_cmpstr(type_name, ==, "EailLabel"); /** * AtkText tests */ g_assert(ATK_IS_TEXT(obj)); g_assert(atk_state_set_contains_state(state_set, ATK_STATE_MULTI_LINE)); g_object_unref(state_set); /* atk_text_get_text */ gchar *text = atk_text_get_text(ATK_TEXT(obj), 6, 11); g_assert_cmpstr(text, ==, "ipsum"); g_free(text); /* atk_text_get_character_at_offset */ g_assert(atk_text_get_character_at_offset(ATK_TEXT(obj), 12) == 'd'); /* atk_text_get_character_count */ g_assert(atk_text_get_character_count(ATK_TEXT(obj)) == 440); }
static void testWebkitAtkGetTextInParagraphAndBodyModerate(void) { WebKitWebView* webView; AtkObject* obj; AtkObject* obj1; AtkObject* obj2; GMainLoop* loop; AtkText* textObj1; AtkText* textObj2; webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); g_object_ref_sink(webView); GtkAllocation alloc = { 0, 0, 800, 600 }; gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); webkit_web_view_load_string(webView, contentsInParagraphAndBodyModerate, NULL, NULL, NULL); loop = g_main_loop_new(NULL, TRUE); g_timeout_add(100, (GSourceFunc)bail_out, loop); g_main_loop_run(loop); /* Get to the inner AtkText object */ obj = gtk_widget_get_accessible(GTK_WIDGET(webView)); g_assert(obj); obj1 = atk_object_ref_accessible_child(obj, 0); g_assert(obj1); obj2 = atk_object_ref_accessible_child(obj, 1); g_assert(obj2); textObj1 = ATK_TEXT(obj1); g_assert(ATK_IS_TEXT(textObj1)); textObj2 = ATK_TEXT(obj2); g_assert(ATK_IS_TEXT(textObj2)); char *text = atk_text_get_text(textObj1, 0, -1); g_assert_cmpstr(text, ==, "This is a test."); text = atk_text_get_text(textObj2, 0, 53); g_assert_cmpstr(text, ==, "Hello world.\nThis sentence is green.\nThis one is not."); g_object_unref(obj1); g_object_unref(obj2); g_object_unref(webView); }
//auxiliary function - create new range according to start_offset and end_offset AtkTextRange* text_range_new(AtkText* text, gint start_offset, gint end_offset, AtkCoordType coord_type) { AtkTextRange* range = g_malloc(sizeof(AtkTextRange)); if(range == NULL) return NULL; range->start_offset = start_offset; range->end_offset = end_offset; range->content = atk_text_get_text(text, start_offset, end_offset); atk_text_get_range_extents(text, start_offset, end_offset, coord_type, &range->bounds); return range; }
JSStringRef AccessibilityUIElement::stringValue() { if (!m_element || !ATK_IS_TEXT(m_element)) return JSStringCreateWithCharacters(0, 0); GOwnPtr<gchar> text(atk_text_get_text(ATK_TEXT(m_element), 0, -1)); GOwnPtr<gchar> textWithReplacedCharacters(replaceCharactersForResults(text.get())); GOwnPtr<gchar> axValue(g_strdup_printf("AXValue: %s", textWithReplacedCharacters.get())); return JSStringCreateWithUTF8CString(axValue.get()); }
// parameterized attributes int AccessibilityUIElement::lineForIndex(int index) { if (!ATK_IS_TEXT(m_element.get())) return -1; if (index < 0 || index > atk_text_get_character_count(ATK_TEXT(m_element.get()))) return -1; GOwnPtr<gchar> text(atk_text_get_text(ATK_TEXT(m_element.get()), 0, index)); int lineNo = 0; for (gchar* offset = text.get(); *offset; ++offset) { if (*offset == '\n') ++lineNo; } return lineNo; }
static void _set_values (AtkObject *obj) { GValue *value_back, val; static gint count = 0; gdouble double_value; value_back = &val; if(ATK_IS_VALUE(obj)) { /* Spin button also inherits the text interfaces from GailEntry. * Check when spin button recieves focus. */ if(ATK_IS_TEXT(obj) && ATK_IS_EDITABLE_TEXT(obj)) { if(count == 0) { gint x; gchar* text; count++; x = atk_text_get_character_count (ATK_TEXT (obj)); text = atk_text_get_text (ATK_TEXT (obj), 0, x); g_print("Text : %s\n", text); text = "5.7"; atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(obj),text); g_print("Set text to %s\n",text); atk_value_get_current_value(ATK_VALUE(obj), value_back); g_return_if_fail (G_VALUE_HOLDS_DOUBLE (value_back)); g_print("atk_value_get_current_value returns %f\n", g_value_get_double( value_back)); } } else { memset (value_back, 0, sizeof (GValue)); g_value_init (value_back, G_TYPE_DOUBLE); g_value_set_double (value_back, 10.0); if (atk_value_set_current_value (ATK_VALUE (obj), value_back)) { double_value = g_value_get_double (value_back); g_print("atk_value_set_current_value returns %f\n", double_value); } } } }
/* Handle inserted text by inserting the text into our gunichar array. */ static void text_changed_insert(AtkObject *obj, gint offset, gint length, gpointer data) { char *inserted, *p; gunichar c; int i; inserted = atk_text_get_text(ATK_TEXT(obj), offset, offset + length); if (!g_utf8_validate(inserted, -1, NULL)) { g_free(inserted); g_error("UTF-8 validation error"); return; } p = inserted; i = 0; while (i < length) { c = g_utf8_get_char(p); if ((guint)(offset + i) >= contents->len) { g_array_append_val(contents, c); } else { g_array_insert_val(contents, offset + i, c); } i++; p = g_utf8_next_char(p); } #ifdef VTE_DEBUG if ((getenv("REFLECT_VERBOSE") != NULL) && (atol(getenv("REFLECT_VERBOSE")) != 0)) { g_printerr("Inserted %d chars ('%.*s') at %d,", length, (int)(p - inserted), inserted, offset); g_printerr(" buffer contains %d characters.\n", contents->len); } #endif g_free(inserted); update_contents(obj, GTK_WIDGET(data)); }
static void run_get_text_tests(AtkText* text_obj) { char* text = atk_text_get_text(text_obj, 0, -1); g_assert_cmpstr(text, ==, "This is a test. This is the second sentence. And this the third."); g_free(text); /* ATK_TEXT_BOUNDARY_CHAR */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_CHAR, 0, "T", 0, 1); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_CHAR, 0, "h", 1, 2); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_CHAR, 0, "", 0, 0); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_CHAR, 1, "T", 0, 1); /* ATK_TEXT_BOUNDARY_WORD_START */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 0, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 4, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 10, "test. ", 10, 16); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 58, "third.", 58, 64); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_START, 5, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_START, 7, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, 0, "is ", 5, 8); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, 4, "is ", 5, 8); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, 3, "is ", 5, 8); /* ATK_TEXT_BOUNDARY_WORD_END */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 0, "This", 0, 4); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 4, " is", 4, 7); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 5, " is", 4, 7); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 9, " test", 9, 14); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, 5, "This", 0, 4); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, 4, "This", 0, 4); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, 7, " is", 4, 7); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_END, 5, " a", 7, 9); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_END, 4, " a", 7, 9); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 58, " third", 57, 63); /* ATK_TEXT_BOUNDARY_SENTENCE_START */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 0, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 15, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 0, "This is the second sentence. ", 16, 45); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 15, "This is the second sentence. ", 16, 45); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 16, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 44, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 15, "", 0, 0); /* ATK_TEXT_BOUNDARY_SENTENCE_END */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 0, "This is a test.", 0, 15); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 15, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 16, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 17, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 0, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 15, " And this the third.", 44, 64); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 16, "This is a test.", 0, 15); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 15, "This is a test.", 0, 15); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 14, "", 0, 0); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 44, " This is the second sentence.", 15, 44); /* It's trick to test these properly right now, since our a11y implementation splits different lines in different a11y items */ /* ATK_TEXT_BOUNDARY_LINE_START */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, "This is a test. This is the second sentence. And this the third.", 0, 64); /* ATK_TEXT_BOUNDARY_LINE_END */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, "This is a test. This is the second sentence. And this the third.", 0, 64); }
static void test_webkit_atk_get_text_at_offset(void) { WebKitWebView* webView; AtkObject *obj; GMainLoop* loop; AtkText* text_obj; char* text; webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); g_object_ref_sink(webView); webkit_web_view_load_string(webView, contents, NULL, NULL, NULL); loop = g_main_loop_new(NULL, TRUE); g_timeout_add(100, (GSourceFunc)bail_out, loop); g_main_loop_run(loop); /* Get to the inner AtkText object */ obj = gtk_widget_get_accessible(GTK_WIDGET(webView)); g_assert(obj); obj = atk_object_ref_accessible_child(obj, 0); g_assert(obj); obj = atk_object_ref_accessible_child(obj, 0); g_assert(obj); text_obj = ATK_TEXT(obj); g_assert(ATK_IS_TEXT(text_obj)); text = atk_text_get_text(text_obj, 0, -1); g_assert_cmpstr(text, ==, "This is a test. This is the second sentence. And this the third."); g_free(text); /* ATK_TEXT_BOUNDARY_CHAR */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_CHAR, 0, "T", 0, 1); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_CHAR, 0, "h", 1, 2); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_CHAR, 0, "", 0, 0); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_CHAR, 1, "T", 0, 1); /* ATK_TEXT_BOUNDARY_WORD_START */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 0, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 4, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 10, "test. ", 10, 16); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, 58, "third.", 58, 64); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_START, 5, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_START, 7, "This ", 0, 5); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, 0, "is ", 5, 8); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, 4, "is ", 5, 8); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, 3, "is ", 5, 8); /* ATK_TEXT_BOUNDARY_WORD_END */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 0, "This", 0, 4); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 4, " is", 4, 7); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 5, " is", 4, 7); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 9, " test", 9, 14); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, 5, "This", 0, 4); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, 4, "This", 0, 4); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, 7, " is", 4, 7); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_END, 5, " a", 7, 9); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_END, 4, " a", 7, 9); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, 58, " third", 57, 63); /* ATK_TEXT_BOUNDARY_SENTENCE_START */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 0, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 15, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 0, "This is the second sentence. ", 16, 45); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 15, "This is the second sentence. ", 16, 45); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 16, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 44, "This is a test. ", 0, 16); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, 15, "", 0, 0); /* ATK_TEXT_BOUNDARY_SENTENCE_END */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 0, "This is a test.", 0, 15); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 15, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 16, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 17, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 0, " This is the second sentence.", 15, 44); test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 15, " And this the third.", 44, 64); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 16, "This is a test.", 0, 15); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 15, "This is a test.", 0, 15); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 14, "", 0, 0); test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, 44, " This is the second sentence.", 15, 44); /* It's trick to test these properly right now, since our a11y implementation splits different lines in different a11y items */ /* ATK_TEXT_BOUNDARY_LINE_START */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, "This is a test. This is the second sentence. And this the third.", 0, 64); /* ATK_TEXT_BOUNDARY_LINE_END */ test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, "This is a test. This is the second sentence. And this the third.", 0, 64); g_object_unref(webView); }
static void _do_test(AtkObject *obj) { gchar *text; int start_offset, end_offset; g_assert(ATK_IS_EDITABLE_TEXT(obj)); text = atk_text_get_text(ATK_TEXT(obj), 0, -1); if (!g_strcmp0(text, ENTRY_FIRST)) { g_free(text); text = g_strdup(ENTRY_TEXT); atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(obj), text); g_free(text); start_offset = 0; end_offset = -1; text = atk_text_get_text(ATK_TEXT(obj), start_offset, end_offset); g_assert_cmpstr(text, ==, ENTRY_TEXT); g_free(text); start_offset = 0; end_offset = 7; atk_editable_text_delete_text(ATK_EDITABLE_TEXT(obj), start_offset, end_offset); text = atk_text_get_text(ATK_TEXT(obj), 0, -1); g_assert_cmpstr(text, ==, " lololololo olololo"); g_free(text); atk_editable_text_insert_text(ATK_EDITABLE_TEXT(obj), "Trololo", 7, &start_offset); text = atk_text_get_text(ATK_TEXT(obj), 0, -1); g_assert(start_offset == 7); g_assert_cmpstr(text, ==, ENTRY_TEXT); g_free(text); start_offset = 8; end_offset = 18; atk_editable_text_copy_text(ATK_EDITABLE_TEXT(obj), start_offset, end_offset); atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(obj), "123"); atk_editable_text_paste_text(ATK_EDITABLE_TEXT(obj), 3); start_offset = 0; end_offset = -1; text = atk_text_get_text(ATK_TEXT(obj), start_offset, end_offset); g_assert_cmpstr(text, ==, "123lololololo"); g_free(text); start_offset = 0; end_offset = 3; atk_editable_text_cut_text(ATK_EDITABLE_TEXT(obj), start_offset, end_offset); text = atk_text_get_text(ATK_TEXT(obj), start_offset, end_offset); g_assert_cmpstr(text, ==, "lol"); g_free(text); start_offset = 0; end_offset = -1; atk_editable_text_paste_text(ATK_EDITABLE_TEXT(obj), 3); text = atk_text_get_text(ATK_TEXT(obj), start_offset, end_offset); g_assert_cmpstr(text, ==, "lol123olololo"); g_free(text); atk_editable_text_cut_text(ATK_EDITABLE_TEXT(obj), 3, 6); text = atk_text_get_text(ATK_TEXT(obj), 0, -1); g_assert_cmpstr(text, ==, "lololololo"); g_free(text); }
int main(int argc, char **argv) { GtkWidget *label, *terminal, *tophalf, *pane, *window, *sw; AtkObject *obj; char *text, *p; gunichar c; guint count; gtk_init(&argc, &argv); contents = g_array_new(TRUE, FALSE, sizeof(gunichar)); terminal_init(&terminal); #ifdef USE_TEXT_VIEW tophalf = gtk_scrolled_window_new(NULL, terminal_adjustment(terminal)); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tophalf), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(tophalf), terminal); #else tophalf = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(tophalf), terminal, TRUE, TRUE, 0); gtk_widget_show(terminal); GtkWidget* scrollbar = gtk_vscrollbar_new(terminal_adjustment(terminal)); gtk_box_pack_start(GTK_BOX(tophalf), scrollbar, FALSE, TRUE, 0); gtk_widget_show(scrollbar); #endif gtk_widget_show(terminal); label = gtk_label_new(""); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), label); gtk_widget_show(label); pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL); gtk_paned_pack1(GTK_PANED(pane), tophalf, TRUE, FALSE); gtk_paned_pack2(GTK_PANED(pane), sw, TRUE, FALSE); gtk_widget_show(tophalf); gtk_widget_show(sw); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL); gtk_container_add(GTK_CONTAINER(window), pane); gtk_widget_show(pane); obj = gtk_widget_get_accessible(terminal); g_assert(obj != NULL); g_signal_connect(G_OBJECT(obj), "text-changed::insert", G_CALLBACK(text_changed_insert), label); g_signal_connect(G_OBJECT(obj), "text-changed::delete", G_CALLBACK(text_changed_delete), label); g_signal_connect(G_OBJECT(obj), "text-caret-moved", G_CALLBACK(text_caret_moved), label); g_signal_connect(G_OBJECT(obj), "text-selection-changed", G_CALLBACK(text_selection_changed), label); count = (guint)atk_text_get_character_count(ATK_TEXT(obj)); if (count > 0) { text = atk_text_get_text(ATK_TEXT(obj), 0, count); if (text != NULL) { for (p = text; contents->len < count; p = g_utf8_next_char(p)) { c = g_utf8_get_char(p); g_array_append_val(contents, c); } g_free(text); } } terminal_shell(terminal); gtk_window_set_default_size(GTK_WINDOW(window), 600, 450); gtk_widget_show(window); update_contents(obj, terminal); gtk_main(); g_array_free(contents, TRUE); contents = NULL; return 0; }