Commit 757cb72fd488760b57a38d17d104defeb8e43aab

Authored by perry.werneck@gmail.com
1 parent 1c28a0e5

Incluindo acerto dos cantos da area de selecao pelo mouse

src/gtk/v3270/mouse.c
@@ -180,7 +180,7 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) @@ -180,7 +180,7 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
180 else if(terminal->moving) 180 else if(terminal->moving)
181 { 181 {
182 // Move selected area 182 // Move selected area
183 - terminal->selection_addr = lib3270_move_selected_area(terminal->host,terminal->selection_addr,baddr); 183 + terminal->selection_addr = lib3270_drag_selection(terminal->host,terminal->pointer,terminal->selection_addr,baddr);
184 } 184 }
185 else if(terminal->pointer_id == LIB3270_CURSOR_NORMAL) 185 else if(terminal->pointer_id == LIB3270_CURSOR_NORMAL)
186 { 186 {
@@ -190,41 +190,41 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) @@ -190,41 +190,41 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
190 GdkWindow *window = gtk_widget_get_window(widget); 190 GdkWindow *window = gtk_widget_get_window(widget);
191 trace("Pointer changes to %04x",new_pointer); 191 trace("Pointer changes to %04x",new_pointer);
192 192
193 - switch(new_pointer & 0x1F) 193 + switch(new_pointer & 0x0F)
194 { 194 {
195 case 0x00: 195 case 0x00:
196 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_NORMAL]); 196 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_NORMAL]);
197 break; 197 break;
198 198
199 - case 0x05: 199 + case 0x02:
200 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP]); 200 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP]);
201 break; 201 break;
202 202
203 - case 0x0d: 203 + case 0x06:
204 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_RIGHT]); 204 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_RIGHT]);
205 break; 205 break;
206 206
207 - case 0x09: 207 + case 0x04:
208 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_RIGHT]); 208 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_RIGHT]);
209 break; 209 break;
210 210
211 - case 0x03: 211 + case 0x01:
212 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_LEFT]); 212 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_LEFT]);
213 break; 213 break;
214 214
215 - case 0x13: 215 + case 0x09:
216 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_LEFT]); 216 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_LEFT]);
217 break; 217 break;
218 218
219 - case 0x11: 219 + case 0x08:
220 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM]); 220 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM]);
221 break; 221 break;
222 222
223 - case 0x19: 223 + case 0x0c:
224 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_RIGHT]); 224 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_RIGHT]);
225 break; 225 break;
226 226
227 - case 0x07: 227 + case 0x03:
228 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_LEFT]); 228 gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_LEFT]);
229 break; 229 break;
230 230
src/include/lib3270/selection.h
@@ -86,6 +86,21 @@ @@ -86,6 +86,21 @@
86 LIB3270_EXPORT int lib3270_move_selected_area(H3270 *h, int from, int to); 86 LIB3270_EXPORT int lib3270_move_selected_area(H3270 *h, int from, int to);
87 87
88 /** 88 /**
  89 + * Drag selected region.
  90 + *
  91 + * Move or resize selected box according to the selection flags.
  92 + *
  93 + * @param h Session handle.
  94 + * @param flag Selection flag.
  95 + * @param origin Reference position (got from mouse button down or other move action).
  96 + * @param baddr New position.
  97 + *
  98 + * @return The new reference position.
  99 + *
  100 + */
  101 + LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr);
  102 +
  103 + /**
89 * Get addresses of selected area. 104 * Get addresses of selected area.
90 * 105 *
91 * @param h Session handle. 106 * @param h Session handle.
src/lib3270/selection.c
@@ -34,6 +34,12 @@ @@ -34,6 +34,12 @@
34 #include <lib3270/session.h> 34 #include <lib3270/session.h>
35 #include <lib3270/selection.h> 35 #include <lib3270/selection.h>
36 36
  37 + #define SELECTION_LEFT 0x01
  38 + #define SELECTION_TOP 0x02
  39 + #define SELECTION_RIGHT 0x04
  40 + #define SELECTION_BOTTOM 0x08
  41 + #define SELECTION_ACTIVE 0x10
  42 +
37 static void update_selection(H3270 *session); 43 static void update_selection(H3270 *session);
38 44
39 /*--[ Implement ]------------------------------------------------------------------------------------*/ 45 /*--[ Implement ]------------------------------------------------------------------------------------*/
@@ -240,19 +246,19 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba @@ -240,19 +246,19 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba
240 246
241 row = baddr / hSession->cols; 247 row = baddr / hSession->cols;
242 col = baddr % hSession->cols; 248 col = baddr % hSession->cols;
243 - rc |= 0x01; 249 + rc |= SELECTION_ACTIVE;
244 250
245 if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) ) 251 if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) )
246 - rc |= 0x02; 252 + rc |= SELECTION_LEFT;
247 253
248 if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) ) 254 if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) )
249 - rc |= 0x04; 255 + rc |= SELECTION_TOP;
250 256
251 if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) ) 257 if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) )
252 - rc |= 0x08; 258 + rc |= SELECTION_RIGHT;
253 259
254 if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) ) 260 if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) )
255 - rc |= 0x10; 261 + rc |= SELECTION_BOTTOM;
256 262
257 return rc; 263 return rc;
258 } 264 }
@@ -475,6 +481,53 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) @@ -475,6 +481,53 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to)
475 return from+step; 481 return from+step;
476 } 482 }
477 483
  484 +LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr)
  485 +{
  486 + int first, last, row, col;
  487 +
  488 + if(lib3270_get_selected_addr(h,&first,&last))
  489 + return origin;
  490 +
  491 + flag &= 0x1f;
  492 +
  493 + if(!flag)
  494 + return origin;
  495 + else if(flag == SELECTION_ACTIVE)
  496 + return lib3270_move_selected_area(h,origin,baddr);
  497 +
  498 + row = baddr/h->cols;
  499 + col = baddr%h->cols;
  500 +
  501 + if(flag & SELECTION_LEFT) // Update left margin
  502 + origin = first = ((first/h->cols)*h->cols) + col;
  503 +
  504 + if(flag & SELECTION_TOP) // Update top margin
  505 + origin = first = (row*h->cols) + (first%h->cols);
  506 +
  507 + if(flag & SELECTION_RIGHT) // Update right margin
  508 + origin = last = ((last/h->cols)*h->cols) + col;
  509 +
  510 + if(flag & SELECTION_BOTTOM) // Update bottom margin
  511 + origin = last = (row*h->cols) + (last%h->cols);
  512 +
  513 + if(h->select.begin < h->select.end)
  514 + {
  515 + h->select.begin = first;
  516 + h->select.end = last;
  517 + }
  518 + else
  519 + {
  520 + h->select.begin = last;
  521 + h->select.end = first;
  522 + }
  523 +
  524 + update_selection(h);
  525 + lib3270_set_cursor_address(h,h->select.end);
  526 +
  527 + return origin;
  528 +}
  529 +
  530 +
478 LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) 531 LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir)
479 { 532 {
480 if(!hSession->selected || hSession->select.begin == hSession->select.end) 533 if(!hSession->selected || hSession->select.begin == hSession->select.end)