From 30b68cb166ceb88d602eb2f943f811da32cf825c Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Sun, 18 Mar 2012 12:26:26 +0000 Subject: [PATCH] Implementando indicador de insert, otimizando toggles --- src/gtk/v3270/oia.c | 42 +++++++++++++++++++++++++++++++++++++----- src/gtk/v3270/private.h | 1 + src/gtk/v3270/widget.c | 1 + src/include/lib3270.h | 15 +-------------- src/lib3270/appres.h | 5 ++--- src/lib3270/kybd.c | 90 +++++++++++++++++++++--------------------------------------------------------------------- src/lib3270/paste.c | 12 ++++++------ src/lib3270/toggle.h | 6 +++--- src/lib3270/toggles.c | 44 +++++++++++++++++++------------------------- 9 files changed, 91 insertions(+), 125 deletions(-) diff --git a/src/gtk/v3270/oia.c b/src/gtk/v3270/oia.c index e5758e6..8c1c7aa 100644 --- a/src/gtk/v3270/oia.c +++ b/src/gtk/v3270/oia.c @@ -421,7 +421,22 @@ static void draw_status_message(cairo_t *cr, LIB3270_MESSAGE id, struct v3270_me cairo_show_text(cr,gettext(msg)); } -// trace("%s ends",__FUNCTION__); +} + +static void draw_insert(cairo_t *cr, H3270 *host, GdkColor *color, GdkRectangle *rect) +{ + if(lib3270_get_toggle(host,LIB3270_TOGGLE_INSERT)) + { + double y = rect->y+(rect->height-2); + + gdk_cairo_set_source_color(cr,color+V3270_COLOR_OIA_FOREGROUND); + + cairo_move_to(cr,rect->x,y); + cairo_rel_line_to(cr,rect->width/2,-(rect->height/1.7)); + cairo_line_to(cr,rect->x+rect->width,y); + cairo_stroke(cr); + } + } void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, struct v3270_metrics *metrics, GdkColor *color, GdkRectangle *rect) @@ -446,8 +461,6 @@ void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, struct v3270_me { V3270_OIA_SSL, setup_double_char_position }, }; -// static const V3270_OIA_FIELD left[] = { V3270_OIA_UNDERA, V3270_OIA_CONNECTION }; - int f; int rCol = metrics->left+(cols*metrics->width); int lCol = metrics->left+1; @@ -514,8 +527,6 @@ void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, struct v3270_me memset(rect+V3270_OIA_MESSAGE,0,sizeof(GdkRectangle)); -// trace("%s lcol=%d rcol=%d",__FUNCTION__,lCol,rCol); - if(lCol < rCol) { GdkRectangle *r = rect+V3270_OIA_MESSAGE; @@ -529,6 +540,10 @@ void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, struct v3270_me cairo_save(cr); v3270_draw_ssl_status(cr,host,metrics,color,rect+V3270_OIA_SSL); cairo_restore(cr); + + cairo_save(cr); + draw_insert(cr,host,color,rect+V3270_OIA_INSERT); + cairo_restore(cr); } /** @@ -810,6 +825,23 @@ void v3270_draw_alt_status(v3270 *terminal) update_text_field(terminal,terminal->keyflags & KEY_FLAG_ALT,V3270_OIA_ALT,"A"); } +void v3270_draw_ins_status(v3270 *terminal) +{ + GdkRectangle *r; + cairo_t *cr; + + if(!terminal->surface) + return; + + cr = set_update_region(terminal,&r,V3270_OIA_INSERT); + + draw_insert(cr,terminal->host,terminal->color,r); + + cairo_destroy(cr); + gtk_widget_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); + +} + static gboolean update_timer(struct timer_info *info) { cairo_t * cr; diff --git a/src/gtk/v3270/private.h b/src/gtk/v3270/private.h index f81dc1e..fa8197d 100644 --- a/src/gtk/v3270/private.h +++ b/src/gtk/v3270/private.h @@ -96,6 +96,7 @@ void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, struct v327 void v3270_draw_shift_status(v3270 *terminal); void v3270_draw_alt_status(v3270 *terminal); +void v3270_draw_ins_status(v3270 *terminal); void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short attr); diff --git a/src/gtk/v3270/widget.c b/src/gtk/v3270/widget.c index 0635caf..88e7a19 100644 --- a/src/gtk/v3270/widget.c +++ b/src/gtk/v3270/widget.c @@ -111,6 +111,7 @@ static void v3270_toggle_changed(v3270 *widget,LIB3270_TOGGLE toggle_id, gboolea break; case LIB3270_TOGGLE_INSERT: + v3270_draw_ins_status(widget); v3270_cursor_draw(widget); break; diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 890f233..6373167 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -294,17 +294,6 @@ LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *data); /** - * Register a toggle change callback. - * - * @param h Session handle. - * @param ix Toggle id - * @param func Function to call when toggle changes. - * - * @return 0 if ok, EINVAL if the toggle id is invalid. - */ - LIB3270_EXPORT int lib3270_register_tchange(H3270 *h, LIB3270_TOGGLE ix, void (*func)(H3270 *h, int, LIB3270_TOGGLE_TYPE reason)); - - /** * Network connect operation, keep main loop running * * Sets 'reconnect_host', 'current_host' and 'full_current_host' as @@ -431,10 +420,8 @@ * @param ix Toggle id. * @param value New toggle state (non zero for true). * - * @return 0 if the toggle wasn't changed, non zero if it was changed. - * */ - LIB3270_EXPORT int lib3270_set_toggle(H3270 *h, LIB3270_TOGGLE ix, int value); + LIB3270_EXPORT void lib3270_set_toggle(H3270 *h, LIB3270_TOGGLE ix, int value); /** * Translate a string toggle name to the corresponding value. diff --git a/src/lib3270/appres.h b/src/lib3270/appres.h index 96aeed7..cd36ff0 100644 --- a/src/lib3270/appres.h +++ b/src/lib3270/appres.h @@ -30,13 +30,12 @@ struct toggle { // Widget w[2]; /* the menu item widgets */ // const char *label[2]; /* labels */ void (*upcall)(H3270 *, struct toggle *, LIB3270_TOGGLE_TYPE); /* change value */ - void (*callback)(H3270 *, int, LIB3270_TOGGLE_TYPE); +// void (*callback)(H3270 *, int, LIB3270_TOGGLE_TYPE); }; #define toggled(ix) (appres.toggle[ix].value) -#define toggle_toggle(t) \ - { (t)->value = !(t)->value; } +// #define toggle_toggle(t) { (t)->value = !(t)->value; } /* Application resources */ diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 46ff348..07bb3ea 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -18,7 +18,7 @@ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA, 02111-1307, USA * - * Este programa está nomeado como kybd.c e possui 4414 linhas de código. + * Este programa está nomeado como kybd.c e possui - linhas de código. * * Contatos: * @@ -98,8 +98,7 @@ static unsigned char pa_xlate[] = { static unsigned long unlock_id; static time_t unlock_delay_time; #define UNLOCK_MS 350 /* 0.35s after last unlock */ -static Boolean key_Character(int code, Boolean with_ge, Boolean pasting, - Boolean *skipped); +static Boolean key_Character(int code, Boolean with_ge, Boolean pasting,Boolean *skipped); static Boolean flush_ta(void); static void key_AID(unsigned char aid_code); static void kybdlock_set(unsigned int bits, const char *cause); @@ -527,10 +526,11 @@ key_AID(unsigned char aid_code) /* Act as if the host had written our input. */ h3270.buffer_addr = h3270.cursor_addr; } - if (!IN_SSCP || aid_code != AID_CLEAR) { + if (!IN_SSCP || aid_code != AID_CLEAR) + { status_twait(&h3270); mcursor_waiting(&h3270); - set_toggle(INSERT,0); + lib3270_set_toggle(&h3270,LIB3270_TOGGLE_INSERT,0); kybdlock_set(KL_OIA_TWAIT | KL_OIA_LOCKED, "key_AID"); } aid = aid_code; @@ -745,15 +745,12 @@ key_Character_wrapper(Widget w unused, XEvent *event unused, String *params, * Handle an ordinary displayable character key. Lots of stuff to handle * insert-mode, protected fields and etc. */ -static Boolean -key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) +static Boolean key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) { register int baddr, faddr, xaddr; register unsigned char fa; enum dbcs_why why; -// reset_idle_timer(); - if (skipped != NULL) *skipped = False; @@ -798,7 +795,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) /* Add the character. */ if (h3270.ea_buf[baddr].cc == EBC_so) { - if (toggled(INSERT)) { + if (toggled(LIB3270_TOGGLE_INSERT)) { if (!ins_prep(faddr, baddr, 1)) return False; } else { @@ -835,7 +832,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) /* fall through... */ case DBCS_LEFT: if (why == DBCS_ATTRIBUTE) { - if (toggled(INSERT)) { + if (toggled(LIB3270_TOGGLE_INSERT)) { if (!ins_prep(faddr, baddr, 1)) return False; } else { @@ -852,7 +849,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) } else { Boolean was_si; - if (toggled(INSERT)) { + if (toggled(LIB3270_TOGGLE_INSERT)) { /* * Inserting SBCS into a DBCS subfield. * If this is the first position, we @@ -909,7 +906,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) break; default: case DBCS_NONE: - if (toggled(INSERT) && !ins_prep(faddr, baddr, 1)) + if (toggled(LIB3270_TOGGLE_INSERT) && !ins_prep(faddr, baddr, 1)) return False; break; } @@ -1292,73 +1289,28 @@ retry: */ void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped) { -// register int i; -// struct akeysym ak; - -// reset_idle_timer(); - if (skipped != NULL) *skipped = False; -// ak.keysym = c; -// ak.keytype = keytype; + trace_event(" %s -> Key(\"%s\")\n",ia_name[(int) cause], ctl_see((int) c)); -/* - switch (composing) { - case NONE: - break; - case COMPOSE: - for (i = 0; i < n_composites; i++) - if (ak_eq(composites[i].k1, ak) || - ak_eq(composites[i].k2, ak)) - break; - if (i < n_composites) { - cc_first.keysym = c; - cc_first.keytype = keytype; - composing = FIRST; - status_compose(True, c, keytype); - } else { - lib3270_ring_bell(); - composing = NONE; - status_compose(False, 0, KT_STD); - } - return; - case FIRST: - composing = NONE; - status_compose(False, 0, KT_STD); - for (i = 0; i < n_composites; i++) - if ((ak_eq(composites[i].k1, cc_first) && - ak_eq(composites[i].k2, ak)) || - (ak_eq(composites[i].k1, ak) && - ak_eq(composites[i].k2, cc_first))) - break; - if (i < n_composites) { - c = composites[i].translation.keysym; - keytype = composites[i].translation.keytype; - } else { - lib3270_ring_bell(); - return; - } - break; - } -*/ - - trace_event(" %s -> Key(\"%s\")\n", - ia_name[(int) cause], ctl_see((int) c)); - if (IN_3270) { - if (c < ' ') { + if (IN_3270) + { + if (c < ' ') + { trace_event(" dropped (control char)\n"); return; } - (void) key_Character((int) asc2ebc[c], keytype == KT_GE, False, - skipped); + (void) key_Character((int) asc2ebc[c], keytype == KT_GE, False, skipped); } #if defined(X3270_ANSI) /*[*/ - else if (IN_ANSI) { + else if (IN_ANSI) + { net_sendc((char) c); } #endif /*]*/ - else { + else + { trace_event(" dropped (not connected)\n"); } } @@ -1533,7 +1485,7 @@ do_reset(Boolean explicit) } /* Always clear insert mode. */ - set_toggle(INSERT,0); + lib3270_set_toggle(&h3270,LIB3270_TOGGLE_INSERT,0); /* Otherwise, if not connect, reset is a no-op. */ if (!CONNECTED) diff --git a/src/lib3270/paste.c b/src/lib3270/paste.c index bcd93cd..1c79de1 100644 --- a/src/lib3270/paste.c +++ b/src/lib3270/paste.c @@ -133,14 +133,14 @@ return -1; } - static int paste_char(PASTE_DATA *data, unsigned char c) + static int paste_char(H3270 *session, PASTE_DATA *data, unsigned char c) { if(toggled(SMART_PASTE)) { - int faddr = find_field_attribute(&h3270,h3270.cursor_addr); - if(FA_IS_PROTECTED(h3270.ea_buf[faddr].fa)) - h3270.cursor_addr++; + int faddr = find_field_attribute(session,session->cursor_addr); + if(FA_IS_PROTECTED(session->ea_buf[faddr].fa)) + session->cursor_addr++; else key_ACharacter(c, KT_STD, IA_PASTE, NULL); } @@ -197,7 +197,7 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) switch(*str) { case '\t': - last = paste_char(&data, ' '); + last = paste_char(h,&data, ' '); break; case '\n': @@ -218,7 +218,7 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) break; default: - last = paste_char(&data, *str); + last = paste_char(h,&data, *str); } str++; diff --git a/src/lib3270/toggle.h b/src/lib3270/toggle.h index 61d48cd..854517d 100644 --- a/src/lib3270/toggle.h +++ b/src/lib3270/toggle.h @@ -59,14 +59,14 @@ #define AID_WAIT LIB3270_TOGGLE_AID_WAIT #define FULL_SCREEN LIB3270_TOGGLE_FULL_SCREEN #define RECONNECT LIB3270_TOGGLE_RECONNECT - #define INSERT LIB3270_TOGGLE_INSERT +// #define INSERT LIB3270_TOGGLE_INSERT #define KEYPAD LIB3270_TOGGLE_KEYPAD #define SMART_PASTE LIB3270_TOGGLE_SMART_PASTE #define N_TOGGLES LIB3270_TOGGLE_COUNT #define LIB3270_TOGGLE_ID LIB3270_TOGGLE - #define register_3270_toggle_monitor(ix,callback) lib3270_register_tchange(NULL,ix,callback) +// #define register_3270_toggle_monitor(ix,callback) lib3270_register_tchange(NULL,ix,callback) #define get_3270_toggle_by_name(x) lib3270_get_toggle_id(x) // Compatibility macros @@ -75,7 +75,7 @@ #define get_3270_toggle_name(ix) lib3270_get_toggle_name(ix) #define get_toggle_name(ix) lib3270_get_toggle_name(ix) - #define set_toggle(ix,value) lib3270_set_toggle(NULL,ix,value) +// #define set_toggle(ix,value) lib3270_set_toggle(NULL,ix,value) #define get_toggle_by_name(name) lib3270_get_toggle_id(name) #endif /* TOGGLE3270_H_INCLUDED */ diff --git a/src/lib3270/toggles.c b/src/lib3270/toggles.c index 0b6f959..64c01b8 100644 --- a/src/lib3270/toggles.c +++ b/src/lib3270/toggles.c @@ -79,6 +79,7 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] = }; +/* static void no_callback(H3270 *h, int value, LIB3270_TOGGLE_TYPE reason) { } @@ -106,6 +107,7 @@ LIB3270_EXPORT int lib3270_register_tchange(H3270 *h, LIB3270_TOGGLE_ID ix, void return 0; } +*/ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) { @@ -117,54 +119,46 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE i } /* - * Generic toggle stuff + * Call the internal update routine */ -static void do_toggle_reason(H3270 *session, LIB3270_TOGGLE ix, LIB3270_TOGGLE_TYPE reason) +static void toggle_notify(H3270 *session, struct toggle *t, LIB3270_TOGGLE ix) { - struct toggle *t = &appres.toggle[ix]; - - /* - * Change the value, call the internal update routine, and reset the - * menu label(s). - */ - toggle_toggle(t); - t->upcall(session, t, reason); - t->callback(session,t->value, (int) reason); + t->upcall(session, t, TT_INTERACTIVE); +// t->callback(session,t->value, (int) TT_INTERACTIVE); if(session->update_toggle) - session->update_toggle(session,ix,t->value,reason,toggle_names[ix]); + session->update_toggle(session,ix,t->value,TT_INTERACTIVE,toggle_names[ix]); } -LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) +LIB3270_EXPORT void lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) { - Boolean v = ((Boolean) (value != 0)); // Convert int in Boolean - struct toggle *t; CHECK_SESSION_HANDLE(session); if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) - return 0; + return; t = &appres.toggle[ix]; + t->value = (value != 0); - if(t->value == v) - return 0; - - do_toggle_reason(session, ix, TT_INTERACTIVE); - - return -1; + toggle_notify(session,t,ix); } LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix) { + struct toggle *t; + CHECK_SESSION_HANDLE(session); if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) - return EINVAL; + return; + + t = &appres.toggle[ix]; - do_toggle_reason(session, ix, TT_INTERACTIVE); + t->value = !t->value; + toggle_notify(session,t,ix); return 0; } @@ -183,7 +177,7 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) for(f=0;f