Commit aaa5d908a3048a61e81a7a4ca02bd6d8519ee9e2
1 parent
5744fa08
Exists in
master
and in
5 other branches
Trabalhando em acessibilidade
Showing
3 changed files
with
156 additions
and
29 deletions
Show diff stats
src/gtk/v3270/accessible.c
| ... | ... | @@ -75,8 +75,6 @@ static void v3270_accessible_class_init(v3270AccessibleClass *klass) |
| 75 | 75 | { |
| 76 | 76 | AtkObjectClass *class = ATK_OBJECT_CLASS (klass); |
| 77 | 77 | |
| 78 | - trace("******************************* %s",__FUNCTION__); | |
| 79 | - | |
| 80 | 78 | /* |
| 81 | 79 | class->get_description = v3270_accessible_get_description; |
| 82 | 80 | |
| ... | ... | @@ -169,15 +167,80 @@ static gint v3270_accessible_get_character_count(AtkText *text) |
| 169 | 167 | |
| 170 | 168 | static gint v3270_accessible_get_offset_at_point(AtkText *atk_text, gint x, gint y, AtkCoordType coords) |
| 171 | 169 | { |
| 172 | - GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (atk_text)); | |
| 173 | - | |
| 174 | - g_warning("Call to incomplete function \"%s\"",__FUNCTION__); | |
| 170 | + gint x_window, | |
| 171 | + y_window, | |
| 172 | + x_widget, | |
| 173 | + y_widget; | |
| 174 | + GdkWindow * window; | |
| 175 | + GtkWidget * widget = gtk_accessible_get_widget(GTK_ACCESSIBLE(atk_text)); | |
| 175 | 176 | |
| 176 | 177 | if(!widget) |
| 177 | 178 | return -1; |
| 178 | 179 | |
| 180 | + window = gtk_widget_get_window(widget); | |
| 181 | + gdk_window_get_origin(window, &x_widget, &y_widget); | |
| 182 | + | |
| 183 | + switch(coords) | |
| 184 | + { | |
| 185 | + case ATK_XY_SCREEN: | |
| 186 | + x -= x_widget; | |
| 187 | + y -= y_widget; | |
| 188 | + break; | |
| 189 | + | |
| 190 | + case ATK_XY_WINDOW: | |
| 191 | + window = gdk_window_get_toplevel(window); | |
| 192 | + gdk_window_get_origin (window, &x_window, &y_window); | |
| 193 | + x = x - x_widget + x_window; | |
| 194 | + y = y - y_widget + y_window; | |
| 195 | + break; | |
| 196 | + | |
| 197 | + default: | |
| 198 | + return -1; | |
| 199 | + | |
| 200 | + } | |
| 201 | + | |
| 202 | + return v3270_get_offset_at_point(GTK_V3270(widget),x,y); | |
| 203 | +} | |
| 204 | + | |
| 205 | +static void v3270_accessible_get_character_extents( AtkText *text, | |
| 206 | + gint offset, | |
| 207 | + gint *x, | |
| 208 | + gint *y, | |
| 209 | + gint *width, | |
| 210 | + gint *height, | |
| 211 | + AtkCoordType coords ) | |
| 212 | +{ | |
| 213 | + v3270 * widget = (v3270 *) gtk_accessible_get_widget(GTK_ACCESSIBLE (text)); | |
| 214 | + int rows, cols; | |
| 215 | + GdkWindow * window; | |
| 216 | + gint x_window, y_window; | |
| 217 | + | |
| 218 | + trace("**************************** %s",__FUNCTION__); | |
| 219 | + | |
| 220 | + if (widget == NULL) | |
| 221 | + return; | |
| 222 | + | |
| 223 | + lib3270_get_screen_size(widget->host,&rows,&cols); | |
| 224 | + | |
| 225 | + // Get screen position | |
| 226 | + window = gtk_widget_get_window(GTK_WIDGET(widget)); | |
| 227 | + gdk_window_get_origin(window, &x_window, &y_window); | |
| 228 | + | |
| 229 | + // Get screen position | |
| 230 | + *x = x_window + widget->metrics.left + ((offset/cols) * widget->metrics.width); | |
| 231 | + *y = y_window + widget->metrics.top + ((offset%cols) * widget->metrics.spacing); | |
| 232 | + *width = widget->metrics.width; | |
| 233 | + *height = widget->metrics.height+widget->metrics.descent; | |
| 234 | + | |
| 235 | + if (coords == ATK_XY_WINDOW) | |
| 236 | + { | |
| 237 | + // Correct position based on toplevel | |
| 238 | + window = gdk_window_get_toplevel(window); | |
| 239 | + gdk_window_get_origin(window, &x_window, &y_window); | |
| 240 | + *x -= x_window; | |
| 241 | + *y -= y_window; | |
| 242 | + } | |
| 179 | 243 | |
| 180 | - return 1; | |
| 181 | 244 | } |
| 182 | 245 | |
| 183 | 246 | static gchar * v3270_accessible_get_text_at_offset(AtkText *atk_text, gint offset, AtkTextBoundary boundary_type, gint *start_offset, gint *end_offset) |
| ... | ... | @@ -261,34 +324,97 @@ static gchar * v3270_accessible_get_text_at_offset(AtkText *atk_text, gint offse |
| 261 | 324 | return NULL; |
| 262 | 325 | } |
| 263 | 326 | |
| 327 | +static gchar * v3270_accessible_get_text(AtkText *atk_text, gint start_pos, gint end_pos) | |
| 328 | +{ | |
| 329 | + GtkWidget * widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (atk_text)); | |
| 330 | + char * text; | |
| 331 | + H3270 * host; | |
| 332 | + gchar * utftext = NULL; | |
| 333 | + | |
| 334 | + if(widget == NULL) | |
| 335 | + return NULL; | |
| 336 | + | |
| 337 | + host = v3270_get_session(widget); | |
| 338 | + if(!host) | |
| 339 | + return NULL; | |
| 340 | + | |
| 341 | + if(!lib3270_connected(host)) | |
| 342 | + return g_strdup( "" ); | |
| 343 | + | |
| 344 | + text = lib3270_get_text(host,start_pos,end_pos < start_pos ? -1 : (end_pos - start_pos)); | |
| 345 | + | |
| 346 | + if(text) | |
| 347 | + { | |
| 348 | + gsize bytes_written; | |
| 349 | + GError * error = NULL; | |
| 350 | + | |
| 351 | + utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_charset(host)," ",NULL,&bytes_written, &error); | |
| 352 | + | |
| 353 | + if(error) | |
| 354 | + { | |
| 355 | + g_warning("%s failed: %s",__FUNCTION__,error->message); | |
| 356 | + g_error_free(error); | |
| 357 | + } | |
| 358 | + | |
| 359 | + free(text); | |
| 360 | + | |
| 361 | + trace("%s:\n%s\n",__FUNCTION__,utftext); | |
| 362 | + | |
| 363 | + } | |
| 364 | + | |
| 365 | + return utftext; | |
| 366 | +} | |
| 367 | + | |
| 368 | +static gboolean v3270_set_caret_offset(AtkText *text, gint offset) | |
| 369 | +{ | |
| 370 | + GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); | |
| 371 | + if (widget == NULL) | |
| 372 | + return FALSE; | |
| 373 | + | |
| 374 | + trace("%s - offset=%d",__FUNCTION__,offset); | |
| 375 | + | |
| 376 | + lib3270_set_cursor_address(GTK_V3270(widget)->host,offset); | |
| 377 | + | |
| 378 | + return TRUE; | |
| 379 | +} | |
| 380 | + | |
| 264 | 381 | static void atk_text_interface_init(AtkTextIface *iface) |
| 265 | 382 | { |
| 383 | + iface->get_text = v3270_accessible_get_text; | |
| 266 | 384 | iface->get_character_at_offset = v3270_accessible_get_character_at_offset; |
| 267 | - iface->get_caret_offset = v3270_accessible_get_caret_offset; | |
| 385 | + | |
| 386 | + iface->get_text_at_offset = v3270_accessible_get_text_at_offset; | |
| 387 | + | |
| 268 | 388 | iface->get_character_count = v3270_accessible_get_character_count; |
| 389 | + iface->get_caret_offset = v3270_accessible_get_caret_offset; | |
| 390 | + iface->set_caret_offset = v3270_set_caret_offset; | |
| 391 | + | |
| 392 | + iface->get_character_extents = v3270_accessible_get_character_extents; | |
| 269 | 393 | iface->get_offset_at_point = v3270_accessible_get_offset_at_point; |
| 270 | - iface->get_text_at_offset = v3270_accessible_get_text_at_offset; | |
| 394 | + | |
| 271 | 395 | /* |
| 272 | - iface->get_text = gtk_entry_accessible_get_text; | |
| 273 | - iface->get_text_before_offset = gtk_entry_accessible_get_text_before_offset; | |
| 274 | - iface->get_text_at_offset = gtk_entry_accessible_get_text_at_offset; | |
| 275 | - iface->get_text_after_offset = gtk_entry_accessible_get_text_after_offset; | |
| 276 | - iface->get_caret_offset = gtk_entry_accessible_get_caret_offset; | |
| 277 | - iface->set_caret_offset = gtk_entry_accessible_set_caret_offset; | |
| 278 | - iface->get_n_selections = gtk_entry_accessible_get_n_selections; | |
| 279 | - iface->get_selection = gtk_entry_accessible_get_selection; | |
| 280 | - iface->add_selection = gtk_entry_accessible_add_selection; | |
| 281 | - iface->remove_selection = gtk_entry_accessible_remove_selection; | |
| 282 | - iface->set_selection = gtk_entry_accessible_set_selection; | |
| 283 | - iface->get_run_attributes = gtk_entry_accessible_get_run_attributes; | |
| 284 | - iface->get_default_attributes = gtk_entry_accessible_get_default_attributes; | |
| 285 | - iface->get_character_extents = gtk_entry_accessible_get_character_extents; | |
| 396 | + iface->get_text_before_offset = gtk_label_accessible_get_text_before_offset; | |
| 397 | + | |
| 398 | + iface->get_text_after_offset = gtk_label_accessible_get_text_after_offset; | |
| 399 | + | |
| 400 | + iface->get_n_selections = gtk_label_accessible_get_n_selections; | |
| 401 | + iface->get_selection = gtk_label_accessible_get_selection; | |
| 402 | + iface->add_selection = gtk_label_accessible_add_selection; | |
| 403 | + iface->remove_selection = gtk_label_accessible_remove_selection; | |
| 404 | + iface->set_selection = gtk_label_accessible_set_selection; | |
| 405 | + | |
| 406 | + iface->get_run_attributes = gtk_label_accessible_get_run_attributes; | |
| 407 | + iface->get_default_attributes = gtk_label_accessible_get_default_attributes; | |
| 286 | 408 | */ |
| 287 | 409 | } |
| 288 | 410 | |
| 289 | 411 | |
| 290 | 412 | static void v3270_accessible_init(v3270Accessible *widget) |
| 291 | 413 | { |
| 414 | + AtkObject *obj = ATK_OBJECT(widget); | |
| 415 | + | |
| 416 | + | |
| 417 | + obj->role = ATK_ROLE_TEXT; | |
| 292 | 418 | } |
| 293 | 419 | |
| 294 | 420 | ... | ... |
src/gtk/v3270/widget.c
| ... | ... | @@ -619,11 +619,11 @@ static void changed(H3270 *session, int offset, int len) |
| 619 | 619 | |
| 620 | 620 | trace("%s: offset=%d len=%d",__FUNCTION__,offset,len) |
| 621 | 621 | |
| 622 | -// if(obj) | |
| 622 | + if(obj) | |
| 623 | 623 | { |
| 624 | 624 | // Get new text, notify atk |
| 625 | - gsize bytes_written; | |
| 626 | - char * text = lib3270_get_text(session,offset,len); | |
| 625 | + gsize bytes_written = 0; | |
| 626 | + char * text = lib3270_get_text(session,offset,len); | |
| 627 | 627 | |
| 628 | 628 | if(text) |
| 629 | 629 | { |
| ... | ... | @@ -644,9 +644,10 @@ static void changed(H3270 *session, int offset, int len) |
| 644 | 644 | g_warning("%s failed: %s",__FUNCTION__,error->message); |
| 645 | 645 | g_error_free(error); |
| 646 | 646 | } |
| 647 | - else | |
| 647 | + | |
| 648 | + if(utfchar) | |
| 648 | 649 | { |
| 649 | - // g_signal_emit_by_name(obj, "text-insert", offset,len,utfchar); | |
| 650 | + g_signal_emit_by_name(obj, "text-insert", offset, bytes_written, utfchar); | |
| 650 | 651 | g_free(utfchar); |
| 651 | 652 | } |
| 652 | 653 | ... | ... |
src/lib3270/selection.c
| ... | ... | @@ -425,7 +425,7 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) |
| 425 | 425 | else if(len > maxlen) |
| 426 | 426 | len = maxlen; |
| 427 | 427 | |
| 428 | - buffer = malloc(len+2); | |
| 428 | + buffer = malloc(len+1); | |
| 429 | 429 | ptr = buffer; |
| 430 | 430 | |
| 431 | 431 | while(len-- > 0) |
| ... | ... | @@ -446,7 +446,7 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) |
| 446 | 446 | len--; |
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | - buffer[len] = 0; | |
| 449 | + *ptr = 0; | |
| 450 | 450 | |
| 451 | 451 | return buffer; |
| 452 | 452 | } | ... | ... |