From dd87907c760c3b362a7f9c9acb52d2e7dd98e61e Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Wed, 4 Apr 2012 17:41:31 +0000 Subject: [PATCH] Trabalhando no suporte atk --- src/gtk/actions.c | 28 ++++++++++++++-------------- src/gtk/dialog.c | 2 +- src/gtk/mainwindow.c | 4 +++- src/gtk/v3270/accessible.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- src/gtk/v3270/clipboard.c | 4 ++-- src/gtk/v3270/mouse.c | 6 +++--- src/gtk/v3270/oia.c | 4 ++++ src/gtk/v3270/private.h | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/gtk/v3270/v3270.h | 79 +++++-------------------------------------------------------------------------- src/gtk/v3270/widget.c | 7 +++++++ src/include/lib3270.h | 10 +++++++--- src/lib3270/screen.c | 7 +++++++ src/lib3270/selection.c | 37 +++++++++++++++++++++++++++++++++++-- 13 files changed, 358 insertions(+), 128 deletions(-) diff --git a/src/gtk/actions.c b/src/gtk/actions.c index 705510c..5d51a27 100644 --- a/src/gtk/actions.c +++ b/src/gtk/actions.c @@ -45,7 +45,7 @@ static void lib3270_action(GtkAction *action, GtkWidget *widget) { int (*call)(H3270 *h) = (int (*)(H3270 *h)) g_object_get_data(G_OBJECT(action),"lib3270_call"); trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); - call(GTK_V3270(widget)->host); + call(v3270_get_session(widget)); } static void connect_action(GtkAction *action, GtkWidget *widget) @@ -116,7 +116,7 @@ static void paste_clipboard_action(GtkAction *action, GtkWidget *widget) static void paste_next_action(GtkAction *action, GtkWidget *widget) { trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); - lib3270_pastenext(GTK_V3270(widget)->host); + lib3270_pastenext(v3270_get_session(widget)); } static void connect_standard_action(GtkAction *action, GtkWidget *widget, const gchar *name) @@ -197,20 +197,20 @@ static void lib3270_toggle_action(GtkToggleAction *action,GtkWidget *widget) if(toggle == TOGGLE_GDKDEBUG) gdk_window_set_debug_updates(gtk_toggle_action_get_active(action)); else if(toggle < LIB3270_TOGGLE_COUNT) - lib3270_set_toggle(GTK_V3270(widget)->host,toggle,gtk_toggle_action_get_active(action)); + lib3270_set_toggle(v3270_get_session(widget),toggle,gtk_toggle_action_get_active(action)); } static void selection_move_action(GtkAction *action, GtkWidget *widget) { trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); - lib3270_move_selection(GTK_V3270(widget)->host,(LIB3270_DIRECTION) g_object_get_data(G_OBJECT(action),"direction")); + lib3270_move_selection(v3270_get_session(widget),(LIB3270_DIRECTION) g_object_get_data(G_OBJECT(action),"direction")); } static void cursor_move_action(GtkAction *action, GtkWidget *widget) { int flags = (int) g_object_get_data(G_OBJECT(action),"move_flags"); trace("Action %s activated on widget %p flags=%04x",gtk_action_get_name(action),widget,(unsigned short) g_object_get_data(G_OBJECT(action),"move_flags")); - lib3270_move_cursor(GTK_V3270(widget)->host,(LIB3270_DIRECTION) (flags & 0x03), (flags & 0x80) ); + lib3270_move_cursor(v3270_get_session(widget),(LIB3270_DIRECTION) (flags & 0x03), (flags & 0x80) ); } static void connect_move_action(GtkAction *action, GtkWidget *widget, const gchar *target, unsigned short flags, GError **error) @@ -244,47 +244,47 @@ static void connect_move_action(GtkAction *action, GtkWidget *widget, const gcha static void action_pfkey(GtkAction *action, GtkWidget *widget) { trace("Action %s activated on widget %p key=%p",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"pfkey")); - lib3270_pfkey(GTK_V3270(widget)->host,(int) g_object_get_data(G_OBJECT(action),"pfkey")); + lib3270_pfkey(v3270_get_session(widget),(int) g_object_get_data(G_OBJECT(action),"pfkey")); } static void action_pakey(GtkAction *action, GtkWidget *widget) { trace("Action %s activated on widget %p key=%p",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"pakey")); - lib3270_pakey(GTK_V3270(widget)->host,(int) g_object_get_data(G_OBJECT(action),"pakey")); + lib3270_pakey(v3270_get_session(widget),(int) g_object_get_data(G_OBJECT(action),"pakey")); } static void action_set_toggle(GtkAction *action, GtkWidget *widget) { LIB3270_TOGGLE id = (LIB3270_TOGGLE) g_object_get_data(G_OBJECT(action),"toggle_id"); trace("Action %s activated on widget %p toggle=%d",gtk_action_get_name(action),widget,id); - lib3270_set_toggle(GTK_V3270(widget)->host,id,1); + lib3270_set_toggle(v3270_get_session(widget),id,1); } static void action_reset_toggle(GtkAction *action, GtkWidget *widget) { LIB3270_TOGGLE id = (LIB3270_TOGGLE) g_object_get_data(G_OBJECT(action),"toggle_id"); trace("Action %s activated on widget %p toggle=%d",gtk_action_get_name(action),widget,id); - lib3270_set_toggle(GTK_V3270(widget)->host,id,0); + lib3270_set_toggle(v3270_get_session(widget),id,0); } static void action_select_all(GtkAction *action, GtkWidget *widget) { - lib3270_selectall(GTK_V3270(widget)->host); + lib3270_selectall(v3270_get_session(widget)); } static void action_select_field(GtkAction *action, GtkWidget *widget) { - lib3270_selectfield(GTK_V3270(widget)->host); + lib3270_selectfield(v3270_get_session(widget)); } static void action_select_none(GtkAction *action, GtkWidget *widget) { - lib3270_unselect(GTK_V3270(widget)->host); + lib3270_unselect(v3270_get_session(widget)); } static void action_select_last(GtkAction *action, GtkWidget *widget) { - lib3270_reselect(GTK_V3270(widget)->host); + lib3270_reselect(v3270_get_session(widget)); } static int id_from_array(const gchar *key, const gchar **array, GError **error) @@ -598,7 +598,7 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash if(id < LIB3270_TOGGLE_COUNT) toggle_action[id] = action; g_object_set_data(G_OBJECT(action),"toggle_id",(gpointer) id); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),(lib3270_get_toggle(GTK_V3270(widget)->host,id) != 0)); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),(lib3270_get_toggle(v3270_get_session(widget),id) != 0)); g_signal_connect(action,"toggled",G_CALLBACK(lib3270_toggle_action),widget); break; diff --git a/src/gtk/dialog.c b/src/gtk/dialog.c index a3236cb..2244fb2 100644 --- a/src/gtk/dialog.c +++ b/src/gtk/dialog.c @@ -388,7 +388,7 @@ void save_all_action(GtkAction *action, GtkWidget *widget) { - gchar *text = v3270_get_text(widget); + gchar *text = v3270_get_text(widget,0,-1); trace("Action %s activated on widget %p text=%p",gtk_action_get_name(action),widget,text); diff --git a/src/gtk/mainwindow.c b/src/gtk/mainwindow.c index c74ea83..b9ab439 100644 --- a/src/gtk/mainwindow.c +++ b/src/gtk/mainwindow.c @@ -201,7 +201,7 @@ static void setup_input_method(GtkWidget *widget, GtkWidget *obj) { GtkWidget *menu = gtk_menu_new(); - gtk_im_multicontext_append_menuitems((GtkIMMulticontext *) GTK_V3270(obj)->input_method,GTK_MENU_SHELL(menu)); + gtk_im_multicontext_append_menuitems((GtkIMMulticontext *) v3270_get_im_context(obj) ,GTK_MENU_SHELL(menu)); gtk_widget_show_all(menu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget),menu); } @@ -281,6 +281,8 @@ GtkWidget **popup; int f; + gtk_widget_set_tooltip_text(terminal,_( "3270 screen")); + if(uri) { lib3270_set_host(host,uri); diff --git a/src/gtk/v3270/accessible.c b/src/gtk/v3270/accessible.c index f8660f0..82e3acf 100644 --- a/src/gtk/v3270/accessible.c +++ b/src/gtk/v3270/accessible.c @@ -27,9 +27,18 @@ * */ + #include + + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + #include + #include + #include + #include #include "v3270.h" + #include "private.h" #include "accessible.h" // References: @@ -41,44 +50,55 @@ /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ static void atk_component_interface_init (AtkComponentIface *iface); -static void atk_editable_text_interface_init (AtkEditableTextIface *iface); static void v3270_accessible_class_init (v3270AccessibleClass *klass); static void v3270_accessible_init (v3270Accessible *widget); +static void atk_text_interface_init (AtkTextIface *iface); + /*--[ Widget definition ]----------------------------------------------------------------------------*/ G_DEFINE_TYPE_WITH_CODE (v3270Accessible, v3270_accessible, GTK_TYPE_ACCESSIBLE, G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init) - G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, atk_editable_text_interface_init) ) + G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init) ) +// G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, atk_editable_text_interface_init) ) // G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init) // G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, atk_editable_text_interface_init) // G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init) /*--[ Implement ]------------------------------------------------------------------------------------*/ +/* +static const gchar * v3270_accessible_get_description(AtkObject *accessible) +{ + return _( "3270 screen" ); +} +*/ + static void v3270_accessible_class_init(v3270AccessibleClass *klass) { + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + trace("******************************* %s",__FUNCTION__); + /* - AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - - klass->notify_gtk = gtk_widget_accessible_notify_gtk; - - class->get_description = gtk_widget_accessible_get_description; - class->get_parent = gtk_widget_accessible_get_parent; - class->ref_relation_set = gtk_widget_accessible_ref_relation_set; - class->ref_state_set = gtk_widget_accessible_ref_state_set; - class->get_index_in_parent = gtk_widget_accessible_get_index_in_parent; - class->initialize = gtk_widget_accessible_initialize; - class->get_attributes = gtk_widget_accessible_get_attributes; - class->focus_event = gtk_widget_accessible_focus_event; + class->get_description = v3270_accessible_get_description; + + + klass->notify_gtk = gtk_widget_accessible_notify_gtk; + + class->get_parent = gtk_widget_accessible_get_parent; + class->ref_relation_set = gtk_widget_accessible_ref_relation_set; + class->ref_state_set = gtk_widget_accessible_ref_state_set; + class->get_index_in_parent = gtk_widget_accessible_get_index_in_parent; + class->initialize = gtk_widget_accessible_initialize; + class->get_attributes = gtk_widget_accessible_get_attributes; + class->focus_event = gtk_widget_accessible_focus_event; */ } -static void -atk_component_interface_init(AtkComponentIface *iface) +static void atk_component_interface_init(AtkComponentIface *iface) { /* iface->get_extents = gtk_widget_accessible_get_extents; @@ -91,23 +111,164 @@ atk_component_interface_init(AtkComponentIface *iface) */ } -static void v3270_accessible_init(v3270Accessible *widget) +static gunichar v3270_accessible_get_character_at_offset(AtkText *atk_text, gint offset) +{ + GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (atk_text)); + + trace("*********** %s %p",__FUNCTION__,widget); + + if (widget == NULL) + return '\0'; + + return 'X'; +} + +static gint v3270_accessible_get_caret_offset(AtkText *text) +{ + GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE(text)); + + if (widget == NULL) + return 0; + + return lib3270_get_cursor_address(GTK_V3270(widget)->host); +} + +static gint v3270_accessible_get_character_count(AtkText *text) +{ + int rows,cols; + GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE(text)); + + trace("*********** %s %p len=%d",__FUNCTION__,widget,lib3270_get_length(GTK_V3270(widget)->host)); + + if(!widget) + return 0; + + return lib3270_get_length(GTK_V3270(widget)->host); +} + +static gint v3270_accessible_get_offset_at_point(AtkText *atk_text, gint x, gint y, AtkCoordType coords) { - trace("*********************************** %s",__FUNCTION__); + GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (atk_text)); + + trace("*********** %s %p",__FUNCTION__,widget); + + if(!widget) + return -1; + + return 1; } -static void atk_editable_text_interface_init(AtkEditableTextIface *iface) +static gchar * v3270_accessible_get_text_at_offset(AtkText *atk_text, gint offset, AtkTextBoundary boundary_type, gint *start_offset, gint *end_offset) { - trace("********************************** %s",__FUNCTION__); + GtkWidget * widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (atk_text)); + H3270 * host; + char * text; + int rows,cols,first; + + trace("*********** %s %p offset=%d",__FUNCTION__,widget,offset); + + if(!widget) + return NULL; + + host = GTK_V3270(widget)->host; + lib3270_get_screen_size(host,&rows,&cols); + + switch(boundary_type) + { + case ATK_TEXT_BOUNDARY_CHAR: // Boundary is the boundary between characters + // (including non-printing characters) + + text = lib3270_get_text(host,offset,1); + break; + + case ATK_TEXT_BOUNDARY_WORD_START: // Boundary is the start (i.e. first character) of a word. + return g_strdup("ATK_TEXT_BOUNDARY_WORD_START"); + break; + + case ATK_TEXT_BOUNDARY_WORD_END: // Boundary is the end (i.e. last character) of a word. + return g_strdup("ATK_TEXT_BOUNDARY_WORD_END"); + break; + + case ATK_TEXT_BOUNDARY_SENTENCE_START: // Boundary is the first character in a sentence. + return g_strdup("ATK_TEXT_BOUNDARY_SENTENCE_START"); + break; + + case ATK_TEXT_BOUNDARY_SENTENCE_END: // Boundary is the last (terminal) character in + // a sentence; in languages which use "sentence stop" punctuation such as English, the boundary is thus the '.', '?', or + // similar terminal punctuation character. + return g_strdup("ATK_TEXT_BOUNDARY_SENTENCE_END"); + break; + + + case ATK_TEXT_BOUNDARY_LINE_START: // Boundary is the initial character of the content or a character immediately following a newline, + // linefeed, or return character. + first = (offset/cols)*cols; + if(first == offset) + offset++; + text = lib3270_get_text(host,first,(offset-first)); + break; + + + case ATK_TEXT_BOUNDARY_LINE_END: // Boundary is the linefeed, or return character. + return g_strdup("ATK_TEXT_BOUNDARY_LINE_END"); + break; + + } + + if(text) + { + gsize bytes_written; + GError * error = NULL; + gchar * utfchar = g_convert_with_fallback( text, + -1, + "UTF-8", + lib3270_get_charset(host), + " ", + NULL, + &bytes_written, + &error ); + + if(error) + { + g_warning("%s failed: %s",__FUNCTION__,error->message); + g_error_free(error); + } + return utfchar; + } + + return NULL; +} + +static void atk_text_interface_init(AtkTextIface *iface) +{ + iface->get_character_at_offset = v3270_accessible_get_character_at_offset; + iface->get_caret_offset = v3270_accessible_get_caret_offset; + iface->get_character_count = v3270_accessible_get_character_count; + iface->get_offset_at_point = v3270_accessible_get_offset_at_point; + iface->get_text_at_offset = v3270_accessible_get_text_at_offset; /* - iface->set_text_contents = gtk_entry_accessible_set_text_contents; - iface->insert_text = gtk_entry_accessible_insert_text; - iface->copy_text = gtk_entry_accessible_copy_text; - iface->cut_text = gtk_entry_accessible_cut_text; - iface->delete_text = gtk_entry_accessible_delete_text; - iface->paste_text = gtk_entry_accessible_paste_text; - iface->set_run_attributes = NULL; + iface->get_text = gtk_entry_accessible_get_text; + iface->get_text_before_offset = gtk_entry_accessible_get_text_before_offset; + iface->get_text_at_offset = gtk_entry_accessible_get_text_at_offset; + iface->get_text_after_offset = gtk_entry_accessible_get_text_after_offset; + iface->get_caret_offset = gtk_entry_accessible_get_caret_offset; + iface->set_caret_offset = gtk_entry_accessible_set_caret_offset; + iface->get_n_selections = gtk_entry_accessible_get_n_selections; + iface->get_selection = gtk_entry_accessible_get_selection; + iface->add_selection = gtk_entry_accessible_add_selection; + iface->remove_selection = gtk_entry_accessible_remove_selection; + iface->set_selection = gtk_entry_accessible_set_selection; + iface->get_run_attributes = gtk_entry_accessible_get_run_attributes; + iface->get_default_attributes = gtk_entry_accessible_get_default_attributes; + iface->get_character_extents = gtk_entry_accessible_get_character_extents; */ } + +static void v3270_accessible_init(v3270Accessible *widget) +{ +} + + + diff --git a/src/gtk/v3270/clipboard.c b/src/gtk/v3270/clipboard.c index f8b7e25..216d3ec 100644 --- a/src/gtk/v3270/clipboard.c +++ b/src/gtk/v3270/clipboard.c @@ -75,7 +75,7 @@ static void clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection, } } -gchar * v3270_get_text(GtkWidget *widget) +gchar * v3270_get_text(GtkWidget *widget, int offset, int len) { v3270 * terminal; gchar * text; @@ -85,7 +85,7 @@ gchar * v3270_get_text(GtkWidget *widget) terminal = GTK_V3270(widget); - str = lib3270_get_text(terminal->host); + str = lib3270_get_text(terminal->host, offset, len); if(!str) return NULL; diff --git a/src/gtk/v3270/mouse.c b/src/gtk/v3270/mouse.c index 83b12a8..66bf4a3 100644 --- a/src/gtk/v3270/mouse.c +++ b/src/gtk/v3270/mouse.c @@ -37,7 +37,7 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ -static int decode_position(v3270 *widget, gdouble x, gdouble y) +gint v3270_get_offset_at_point(v3270 *widget, gint x, gint y) { GdkPoint point; int r,c; @@ -120,7 +120,7 @@ void v3270_emit_popup(v3270 *widget, int baddr, GdkEventButton *event) gboolean v3270_button_press_event(GtkWidget *widget, GdkEventButton *event) { - int baddr = decode_position(GTK_V3270(widget),event->x,event->y); + int baddr = v3270_get_offset_at_point(GTK_V3270(widget),event->x,event->y); if(baddr < 0) return FALSE; @@ -167,7 +167,7 @@ gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event) gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) { v3270 * terminal = GTK_V3270(widget); - int baddr = decode_position(terminal,event->x,event->y); + int baddr = v3270_get_offset_at_point(terminal,event->x,event->y); if(baddr < 0) return FALSE; diff --git a/src/gtk/v3270/oia.c b/src/gtk/v3270/oia.c index 8d253b1..2b9c6f2 100644 --- a/src/gtk/v3270/oia.c +++ b/src/gtk/v3270/oia.c @@ -726,6 +726,10 @@ void v3270_update_cursor(H3270 *session, unsigned short row, unsigned short col, gtk_widget_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height); } + + if(terminal->accessible) + g_signal_emit_by_name(ATK_TEXT(terminal->accessible),"text-caret-moved",lib3270_get_cursor_address(session)); + } struct timer_info diff --git a/src/gtk/v3270/private.h b/src/gtk/v3270/private.h index da335e6..aa7bce8 100644 --- a/src/gtk/v3270/private.h +++ b/src/gtk/v3270/private.h @@ -37,7 +37,9 @@ #include #include -#include +#ifndef V3270_H_INCLUDED + #include "v3270.h" +#endif G_BEGIN_DECLS @@ -98,6 +100,84 @@ G_BEGIN_DECLS #define V3270_CURSOR_COUNT LIB3270_CURSOR_USER+9 + + struct v3270_metrics + { + guint width; + guint height; + guint ascent; + guint descent; + + guint spacing; + + guint left; + guint top; + }; + +/*--[ Widget data ]----------------------------------------------------------------------------------*/ + + struct _v3270 + { + GtkWidget parent; + + // private + int selecting : 1; /**< Selecting region */ + int moving : 1; /**< Moving selected region */ + int resizing : 1; /**< Resizing selected region */ + +#if GTK_CHECK_VERSION(3,0,0) + +#else + gint width; + gint height; +#endif // GTK_CHECK_VERSION(3,0,0) + + GSource * timer; + GtkIMContext * input_method; + unsigned short keyflags; + gchar * clipboard; /**< Clipboard contents (text only) */ + + LIB3270_CURSOR pointer_id; + unsigned char pointer; /** Mouse pointer ID */ + int selection_addr; /** Selection addr */ + + // Font info + gchar * font_family; + cairo_font_weight_t font_weight; + cairo_scaled_font_t * font_scaled; + cairo_surface_t * surface; + + struct v3270_metrics metrics; + + gint minimum_width; + gint minimum_height; + + // Colors + GdkColor color[V3270_COLOR_COUNT]; /**< Terminal widget colors */ + + // Regions + GdkRectangle oia_rect[V3270_OIA_FIELD_COUNT]; + + struct + { + unsigned char show; /**< Cursor flag */ + unsigned char chr; /**< Char at cursor position */ + unsigned short attr; /**< Attribute at cursor position */ + GdkRectangle rect; /**< Cursor rectangle */ + GSource * timer; /**< Cursor blinking timer */ + cairo_surface_t * surface; /**< Cursor image */ + } cursor; + + // Acessibility + GtkAccessible * accessible; + + // lib3270 stuff + H3270 * host; /**< Related 3270 session */ + + }; + +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + G_GNUC_INTERNAL guint v3270_widget_signal[LAST_SIGNAL]; G_GNUC_INTERNAL GdkCursor * v3270_cursor[V3270_CURSOR_COUNT]; @@ -147,5 +227,6 @@ gboolean v3270_button_press_event(GtkWidget *widget, GdkEventButton *event); gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event); gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event); void v3270_emit_popup(v3270 *widget, int baddr, GdkEventButton *event); +gint v3270_get_offset_at_point(v3270 *widget, gint x, gint y); G_END_DECLS diff --git a/src/gtk/v3270/v3270.h b/src/gtk/v3270/v3270.h index 2b5accc..d1f8843 100644 --- a/src/gtk/v3270/v3270.h +++ b/src/gtk/v3270/v3270.h @@ -128,79 +128,6 @@ #define v3270char void #endif // v3270_char - struct v3270_metrics - { - guint width; - guint height; - guint ascent; - guint descent; - - guint spacing; - - guint left; - guint top; - }; - - struct _v3270 - { - GtkWidget parent; - - // private - int selecting : 1; /**< Selecting region */ - int moving : 1; /**< Moving selected region */ - int resizing : 1; /**< Resizing selected region */ - -#if GTK_CHECK_VERSION(3,0,0) - -#else - gint width; - gint height; -#endif // GTK_CHECK_VERSION(3,0,0) - - GSource * timer; - GtkIMContext * input_method; - unsigned short keyflags; - gchar * clipboard; /**< Clipboard contents (text only) */ - - LIB3270_CURSOR pointer_id; - unsigned char pointer; /** Mouse pointer ID */ - int selection_addr; /** Selection addr */ - - // Font info - gchar * font_family; - cairo_font_weight_t font_weight; - cairo_scaled_font_t * font_scaled; - cairo_surface_t * surface; - - struct v3270_metrics metrics; - - gint minimum_width; - gint minimum_height; - - // Colors - GdkColor color[V3270_COLOR_COUNT]; /**< Terminal widget colors */ - - // Regions - GdkRectangle oia_rect[V3270_OIA_FIELD_COUNT]; - - struct - { - unsigned char show; /**< Cursor flag */ - unsigned char chr; /**< Char at cursor position */ - unsigned short attr; /**< Attribute at cursor position */ - GdkRectangle rect; /**< Cursor rectangle */ - GSource * timer; /**< Cursor blinking timer */ - cairo_surface_t * surface; /**< Cursor image */ - } cursor; - - // Acessibility - GtkAccessible * accessible; - - // lib3270 stuff - H3270 * host; /**< Related 3270 session */ - - }; - GtkWidget * v3270_new(void); GType v3270_get_type(void); @@ -217,7 +144,7 @@ // Clipboard const gchar * v3270_get_selected_text(GtkWidget *widget); const gchar * v3270_get_copy(GtkWidget *widget); - gchar * v3270_get_text(GtkWidget *widget); + gchar * v3270_get_text(GtkWidget *widget,int offset, int len); const gchar * v3270_copy(GtkWidget *widget); const gchar * v3270_copy_append(GtkWidget *widget); @@ -233,6 +160,10 @@ void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color); GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); + // Misc + GtkIMContext * v3270_get_im_context(GtkWidget *widget); + + G_END_DECLS #endif // V3270_H_INCLUDED diff --git a/src/gtk/v3270/widget.c b/src/gtk/v3270/widget.c index 5514697..4c31173 100644 --- a/src/gtk/v3270/widget.c +++ b/src/gtk/v3270/widget.c @@ -1107,8 +1107,15 @@ static AtkObject * v3270_get_accessible(GtkWidget * widget) { terminal->accessible = g_object_new(GTK_TYPE_V3270_ACCESSIBLE,NULL); atk_object_initialize(ATK_OBJECT(terminal->accessible), widget); + gtk_accessible_set_widget(GTK_ACCESSIBLE(terminal->accessible),widget); + g_object_ref(terminal->accessible); } return ATK_OBJECT(terminal->accessible); } +GtkIMContext * v3270_get_im_context(GtkWidget *widget) +{ + return GTK_V3270(widget)->input_method; +} + diff --git a/src/include/lib3270.h b/src/include/lib3270.h index c450778..2c44bde 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -267,6 +267,8 @@ */ LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c); + LIB3270_EXPORT unsigned int lib3270_get_length(H3270 *h); + /** * Start a new session (INCOMPLETE). * @@ -660,12 +662,14 @@ /** * Get all text inside the terminal. * - * @param h Session Handle. + * @param h Session Handle. + * @param offset Start position. + * @param len Text length or -1 to all text. * - * @return All text if available, or NULL. Release it with free() + * @return Contents at position if available, or NULL. Release it with free() * */ - LIB3270_EXPORT char * lib3270_get_text(H3270 *h); + LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len); /** * Get a terminal character and attribute. diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 7ad09b6..2732bec 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -223,8 +223,15 @@ static unsigned short calc_attrs(H3270 *session, int baddr, int fa_addr, int fa) return a; } +LIB3270_EXPORT unsigned int lib3270_get_length(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->rows * h->cols; +} + LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c) { + CHECK_SESSION_HANDLE(h); *r = h->rows; *c = h->cols; } diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index a66d9a7..7ef4b61 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -407,9 +407,38 @@ static char * get_text(H3270 *hSession,unsigned char all) return ret; } -LIB3270_EXPORT char * lib3270_get_text(H3270 *hSession) +LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) { - return get_text(hSession,1); + char *buffer; + int col, maxlen; + char *ptr; + + CHECK_SESSION_HANDLE(h); + + maxlen = h->rows * (h->cols+1); + + if(len < 0) + len = (maxlen - offset); + else if(len > maxlen) + len = maxlen; + + buffer = malloc(len+1); + col = offset%h->cols; + ptr = buffer; + + while(len-- > 0) + { + *(ptr++) = h->text[offset++].chr; + if(col++ >= h->cols && len > 0) + { + col = 0; + *(ptr++) = '\n'; + len--; + } + } + *ptr = 0; + + return buffer; } LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) @@ -417,6 +446,10 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) if(!hSession->selected || hSession->select.begin == hSession->select.end) return NULL; + if(!lib3270_connected(hSession)) + return NULL; + + return get_text(hSession,0); } -- libgit2 0.21.2