diff -urN cui124/cui.c cui125/cui.c --- cui124/cui.c Mon Apr 21 00:00:00 2014 +++ cui125/cui.c Mon Apr 21 01:00:00 2014 @@ -51,9 +51,8 @@ conn(cui obj) { char host[1024]; - int port = 12345, cfd; + int port, cfd; - strcpy(host, "localhost"); if(!cui_host_port_dialog(obj, 1, 1, host, &port)) return; if((cfd = cui_conn_host_port(host, port)) == -1){ cui_msg_dialog(obj, "connect failed"); diff -urN cui124/cui_srv.c cui125/cui_srv.c --- cui124/cui_srv.c Mon Apr 21 00:00:00 2014 +++ cui125/cui_srv.c Mon Apr 21 01:00:00 2014 @@ -108,12 +108,11 @@ { struct conn_prm *p = (struct conn_prm *)prm; char host[1024]; - int port = 12345, cfd; + int port, cfd; switch(evt){ case CUI_EVT_BUTTON: if(obj == p->conn){ - strcpy(host, "localhost"); if(!cui_host_port_dialog(p->view, p->conn->x+1, cui_y2(p->conn), host, &port)) break; if((cfd = cui_conn_host_port(host, port)) == -1){ cui_msg_dialog(p->view, "connect failed"); diff -urN cui124/dialog.c cui125/dialog.c --- cui124/dialog.c Mon Apr 21 00:00:00 2014 +++ cui125/dialog.c Mon Apr 21 01:00:00 2014 @@ -88,30 +88,53 @@ return TRUE; } +static cui host_port_panel = NULL; +static cui host_port_etxt = NULL; +static cui host_port_num = NULL; +static int host_port_result; + int cui_host_port_dialog(cui parent, int x, int y, char *host, int *port) { - int w = strlen("(OK)") + 1 + strlen("(Cancel)"); - cui panel = cui_panel_new(parent, x, y, w+2, 6); - cui view = cui_base_new(panel, 1, 1, w, 4); - cui etxt = cui_etext_new(view, 0, 0, view->w, host); - cui num = cui_num_new(view, 0, 1, view->w, *port, 0, 65535, 0); - cui ok = cui_button_new(view, 0, 3, "OK"); - cui cancel = cui_button_new(view, cui_x2(ok)+1, ok->y, "Cancle"); - int result; + cui panel = host_port_panel; + cui etxt = host_port_etxt; + cui num = host_port_num; + + if(host_port_panel == NULL){ + int w = strlen("(OK)") + 1 + strlen("(Cancel)"); + cui view, ok, cancel; + + panel = cui_panel_new(NULL, 0, 0, 0, 0); + cui_hide(panel); + cui_wh_set(panel, w+2, 6); - cui_bind(ok, CUI_EVT_BUTTON, ok_cancel_hdr, &result); - cui_bind(cancel, CUI_EVT_BUTTON, ok_cancel_hdr, &result); + view = cui_base_new(panel, 1, 1, w, 4); + etxt = cui_etext_new(view, 0, 0, view->w, "localhost"); + num = cui_num_new(view, 0, 1, view->w, 12345, 0, 65535, 0); + ok = cui_button_new(view, 0, 3, "OK"); + cancel = cui_button_new(view, cui_x2(ok)+1, ok->y, "Cancel"); + + cui_bind(ok, CUI_EVT_BUTTON, ok_cancel_hdr, &host_port_result); + cui_bind(cancel, CUI_EVT_BUTTON, ok_cancel_hdr, &host_port_result); + + host_port_panel = panel; + host_port_etxt = etxt; + host_port_num = num; + } + panel->parent = parent; + cui_base_child_add(parent, panel); + cui_xy_set(panel, x, y); + cui_show(panel); cui_main(panel, etxt); cui_hide(panel); cui_draw(parent); - if(result){ + if(host_port_result){ strcpy(host, cui_etext_str_get(etxt)); *port = cui_num_get(num); } - cui_del_free(panel); - return result; + cui_del(panel); + return host_port_result; } int