Commit 1f1de3e18740a614dff72b26b9c675c22701474b
1 parent
3173e943
Exists in
master
and in
5 other branches
Implementando seleção
Showing
6 changed files
with
142 additions
and
51 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -197,7 +197,6 @@ |
| 197 | 197 | <Unit filename="src/lib3270/macros.c"> |
| 198 | 198 | <Option compilerVar="CC" /> |
| 199 | 199 | </Unit> |
| 200 | - <Unit filename="src/lib3270/menubarc.h" /> | |
| 201 | 200 | <Unit filename="src/lib3270/mkfb.c"> |
| 202 | 201 | <Option compilerVar="CC" /> |
| 203 | 202 | </Unit> |
| ... | ... | @@ -240,7 +239,6 @@ |
| 240 | 239 | <Option compilerVar="CC" /> |
| 241 | 240 | </Unit> |
| 242 | 241 | <Unit filename="src/lib3270/seec.h" /> |
| 243 | - <Unit filename="src/lib3270/selectc.h" /> | |
| 244 | 242 | <Unit filename="src/lib3270/selection.c"> |
| 245 | 243 | <Option compilerVar="CC" /> |
| 246 | 244 | </Unit> | ... | ... |
src/lib3270/appres.h
| ... | ... | @@ -220,12 +220,8 @@ typedef struct { |
| 220 | 220 | LIB3270_INTERNAL AppRes appres; |
| 221 | 221 | |
| 222 | 222 | // FIXME (perry#2#): Check for right implementation |
| 223 | -#if defined(LIB3270) | |
| 224 | - #define _( x ) x | |
| 225 | - #define N_( x ) x | |
| 226 | - #define MSG_( c, s ) s | |
| 227 | -#else | |
| 228 | - #define _( x ) x | |
| 229 | - #define N_( x ) x | |
| 230 | - #define MSG_( c, s ) get_message(c) | |
| 231 | -#endif | |
| 223 | +#define _( x ) x | |
| 224 | +#define N_( x ) x | |
| 225 | +#define MSG_( c, s ) s | |
| 226 | + | |
| 227 | +void toggle_rectselect(H3270 *session, struct toggle *t, LIB3270_TOGGLE_TYPE tt); | ... | ... |
src/lib3270/glue.c
| ... | ... | @@ -165,6 +165,11 @@ void lib3270_session_free(H3270 *h) |
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | +static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) | |
| 169 | +{ | |
| 170 | + | |
| 171 | +} | |
| 172 | + | |
| 168 | 173 | static void lib3270_session_init(H3270 *hSession, const char *model) |
| 169 | 174 | { |
| 170 | 175 | int ovc, ovr; |
| ... | ... | @@ -173,6 +178,11 @@ static void lib3270_session_init(H3270 *hSession, const char *model) |
| 173 | 178 | |
| 174 | 179 | memset(hSession,0,sizeof(H3270)); |
| 175 | 180 | hSession->sz = sizeof(H3270); |
| 181 | + | |
| 182 | + // A few dummy calls to avoid "ifs" | |
| 183 | + hSession->update = update_char; | |
| 184 | + | |
| 185 | + | |
| 176 | 186 | hSession->sock = -1; |
| 177 | 187 | hSession->model_num = -1; |
| 178 | 188 | hSession->cstate = NOT_CONNECTED; | ... | ... |
src/lib3270/selection.c
| ... | ... | @@ -29,12 +29,134 @@ |
| 29 | 29 | |
| 30 | 30 | #include "globals.h" |
| 31 | 31 | #include "ctlr.h" |
| 32 | + #include "appres.h" | |
| 32 | 33 | #include <lib3270.h> |
| 33 | 34 | #include <lib3270/session.h> |
| 34 | 35 | #include <lib3270/selection.h> |
| 35 | 36 | |
| 36 | 37 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 37 | 38 | |
| 39 | +static void update_selected_rectangle(H3270 *session) | |
| 40 | +{ | |
| 41 | + struct | |
| 42 | + { | |
| 43 | + int row; | |
| 44 | + int col; | |
| 45 | + } p[2]; | |
| 46 | + | |
| 47 | + int begin = session->selected.begin; | |
| 48 | + int end = session->selected.end; | |
| 49 | + int row, col, baddr; | |
| 50 | + | |
| 51 | + if(begin > end) | |
| 52 | + { | |
| 53 | + baddr = end; | |
| 54 | + end = begin; | |
| 55 | + begin = baddr; | |
| 56 | + } | |
| 57 | + | |
| 58 | + // Get start & end posision | |
| 59 | + p[0].row = (begin/session->cols); | |
| 60 | + p[0].col = (begin%session->cols); | |
| 61 | + p[1].row = (end/session->cols); | |
| 62 | + p[1].col = (end%session->cols); | |
| 63 | + | |
| 64 | + // First remove unselected areas | |
| 65 | + baddr = 0; | |
| 66 | + for(row=0;row < session->rows;row++) | |
| 67 | + { | |
| 68 | + for(col = 0; col < session->cols;col++) | |
| 69 | + { | |
| 70 | + if(!(row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && (ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 71 | + { | |
| 72 | + ea_buf[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 73 | + session->update(session,baddr,ea_buf[baddr].chr,ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 74 | + } | |
| 75 | + baddr++; | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + // Then, draw selected ones | |
| 80 | + baddr = 0; | |
| 81 | + for(row=0;row < session->rows;row++) | |
| 82 | + { | |
| 83 | + for(col = 0; col < session->cols;col++) | |
| 84 | + { | |
| 85 | + if((row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && !(ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 86 | + { | |
| 87 | + ea_buf[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 88 | + session->update(session,baddr,ea_buf[baddr].chr,ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 89 | + } | |
| 90 | + baddr++; | |
| 91 | + } | |
| 92 | + } | |
| 93 | + | |
| 94 | +} | |
| 95 | + | |
| 96 | +static void update_selected_region(H3270 *session) | |
| 97 | +{ | |
| 98 | + int baddr; | |
| 99 | + int begin = session->selected.begin; | |
| 100 | + int end = session->selected.end; | |
| 101 | + int len = session->rows*session->cols; | |
| 102 | + | |
| 103 | + if(begin > end) | |
| 104 | + { | |
| 105 | + baddr = end; | |
| 106 | + end = begin; | |
| 107 | + begin = baddr; | |
| 108 | + } | |
| 109 | + | |
| 110 | + // First remove unselected areas | |
| 111 | + for(baddr = 0; baddr < begin; baddr++) | |
| 112 | + { | |
| 113 | + if(ea_buf[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 114 | + { | |
| 115 | + ea_buf[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 116 | + session->update(session,baddr,ea_buf[baddr].chr,ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + for(baddr = end+1; baddr < len; baddr++) | |
| 121 | + { | |
| 122 | + if(ea_buf[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 123 | + { | |
| 124 | + ea_buf[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 125 | + session->update(session,baddr,ea_buf[baddr].chr,ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + | |
| 129 | + // Then draw the selected ones | |
| 130 | + for(baddr = begin; baddr <= end; baddr++) | |
| 131 | + { | |
| 132 | + if(!(ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 133 | + { | |
| 134 | + ea_buf[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 135 | + session->update(session,baddr,ea_buf[baddr].chr,ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + | |
| 139 | +} | |
| 140 | + | |
| 141 | +void update_selection(H3270 *session) | |
| 142 | +{ | |
| 143 | + if(lib3270_get_toggle(session,LIB3270_TOGGLE_RECTANGLE_SELECT)) | |
| 144 | + update_selected_rectangle(session); | |
| 145 | + else | |
| 146 | + update_selected_region(session); | |
| 147 | +} | |
| 148 | + | |
| 149 | +void toggle_rectselect(H3270 *session, struct toggle *t, LIB3270_TOGGLE_TYPE tt) | |
| 150 | +{ | |
| 151 | + if(session->selected.begin < 0) | |
| 152 | + return; | |
| 153 | + | |
| 154 | + if(t->value) | |
| 155 | + update_selected_rectangle(session); | |
| 156 | + else | |
| 157 | + update_selected_region(session); | |
| 158 | +} | |
| 159 | + | |
| 38 | 160 | LIB3270_EXPORT void lib3270_clear_selection(H3270 *session) |
| 39 | 161 | { |
| 40 | 162 | int a; |
| ... | ... | @@ -55,6 +177,7 @@ LIB3270_EXPORT void lib3270_clear_selection(H3270 *session) |
| 55 | 177 | } |
| 56 | 178 | } |
| 57 | 179 | |
| 180 | + | |
| 58 | 181 | LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) |
| 59 | 182 | { |
| 60 | 183 | CHECK_SESSION_HANDLE(session); |
| ... | ... | @@ -62,32 +185,9 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) |
| 62 | 185 | if(session->selected.begin < 0) |
| 63 | 186 | session->selected.begin = session->selected.end = session->cursor_addr; |
| 64 | 187 | |
| 65 | - if(baddr > session->cursor_addr) | |
| 66 | - { | |
| 67 | - session->selected.begin = session->cursor_addr; | |
| 68 | - session->selected.end = baddr; | |
| 69 | - } | |
| 70 | - else | |
| 71 | - { | |
| 72 | - session->selected.begin = baddr; | |
| 73 | - session->selected.end = session->cursor_addr; | |
| 74 | - } | |
| 75 | - | |
| 76 | - // Update screen contents | |
| 77 | - for(baddr = 0; baddr < session->rows*session->cols; baddr++) | |
| 78 | - { | |
| 79 | - unsigned short attr = ea_buf[baddr].attr; | |
| 188 | + lib3270_set_cursor_address(session,session->selected.end = baddr); | |
| 80 | 189 | |
| 81 | - if(baddr >= session->selected.begin && baddr <= session->selected.end) | |
| 82 | - attr |= LIB3270_ATTR_SELECTED; | |
| 83 | - else | |
| 84 | - attr &= ~LIB3270_ATTR_SELECTED; | |
| 190 | + update_selection(session); | |
| 85 | 191 | |
| 86 | - if(attr != ea_buf[baddr].attr && session->update) | |
| 87 | - { | |
| 88 | - ea_buf[baddr].attr = attr; | |
| 89 | - session->update(session,baddr,ea_buf[baddr].chr,attr,baddr == session->cursor_addr); | |
| 90 | - } | |
| 91 | - } | |
| 92 | 192 | } |
| 93 | 193 | ... | ... |
src/lib3270/toggle.h
| ... | ... | @@ -26,7 +26,6 @@ |
| 26 | 26 | * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) |
| 27 | 27 | * licinio@bb.com.br (Licínio Luis Branco) |
| 28 | 28 | * kraucer@bb.com.br (Kraucer Fernandes Mazuco) |
| 29 | - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) | |
| 30 | 29 | * |
| 31 | 30 | */ |
| 32 | 31 | |
| ... | ... | @@ -67,21 +66,9 @@ |
| 67 | 66 | |
| 68 | 67 | #define LIB3270_TOGGLE_ID LIB3270_TOGGLE |
| 69 | 68 | |
| 70 | - | |
| 71 | 69 | #define register_3270_toggle_monitor(ix,callback) lib3270_register_tchange(NULL,ix,callback) |
| 72 | - | |
| 73 | - // LIB3270_EXPORT void register_3270_toggle_monitor(LIB3270_TOGGLE_ID ix, void (*callback)(int value, LIB3270_TOGGLE_TYPE reason)); | |
| 74 | -// LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE_ID ix); | |
| 75 | - | |
| 76 | - LIB3270_EXPORT int set_3270_toggle(LIB3270_TOGGLE_ID ix, int value); | |
| 77 | - | |
| 78 | -// LIB3270_EXPORT const char * get_3270_toggle_name(LIB3270_TOGGLE_ID ix); | |
| 79 | -// LIB3270_EXPORT LIB3270_TOGGLE_ID get_3270_toggle_by_name(const char *name); | |
| 80 | 70 | #define get_3270_toggle_by_name(x) lib3270_get_toggle_id(x) |
| 81 | 71 | |
| 82 | - | |
| 83 | - LIB3270_EXPORT void update_toggle_actions(void); | |
| 84 | - | |
| 85 | 72 | // Compatibility macros |
| 86 | 73 | #define register_tchange(ix,callback) register_3270_toggle_monitor(ix,callback) |
| 87 | 74 | #define do_toggle(ix) lib3270_toggle(NULL,ix) | ... | ... |
src/lib3270/toggles.c
| ... | ... | @@ -107,8 +107,6 @@ static void do_toggle_reason(H3270 *session, LIB3270_TOGGLE ix, LIB3270_TOGGLE_T |
| 107 | 107 | if(session->update_toggle) |
| 108 | 108 | session->update_toggle(session,ix,t->value,reason,toggle_names[ix]); |
| 109 | 109 | |
| 110 | -// notify_toggle_changed(session, ix, t->value, reason); | |
| 111 | - | |
| 112 | 110 | } |
| 113 | 111 | |
| 114 | 112 | LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) |
| ... | ... | @@ -157,6 +155,8 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) |
| 157 | 155 | toggle[f].upcall = toggle_nop; |
| 158 | 156 | } |
| 159 | 157 | |
| 158 | + toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect; | |
| 159 | + | |
| 160 | 160 | #if defined(X3270_TRACE) |
| 161 | 161 | toggle[DS_TRACE].upcall = toggle_dsTrace; |
| 162 | 162 | toggle[SCREEN_TRACE].upcall = toggle_screenTrace; | ... | ... |