Commit 73de0f1c05ceb51390004eb1bd28f04fa8f8159a
1 parent
b0534ef4
Exists in
master
and in
3 other branches
Adding method to get a rectangle with the selected region.
Showing
4 changed files
with
69 additions
and
98 deletions
Show diff stats
src/include/lib3270/selection.h
| @@ -134,6 +134,20 @@ | @@ -134,6 +134,20 @@ | ||
| 134 | LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end); | 134 | LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end); |
| 135 | 135 | ||
| 136 | /** | 136 | /** |
| 137 | + * @brief Get the coordinates of a rectangle containing the selected region. | ||
| 138 | + * | ||
| 139 | + * @param hSession Session handle. | ||
| 140 | + * @param col Pointer to last row. | ||
| 141 | + * @param row Pointer to first row. | ||
| 142 | + * @param width Pointer to first col. | ||
| 143 | + * @param height Pointer to last col. | ||
| 144 | + * | ||
| 145 | + * @return 0 if suceeds, error code if not (sets errno). | ||
| 146 | + * | ||
| 147 | + */ | ||
| 148 | + LIB3270_EXPORT int lib3270_get_selection_rectangle(H3270 *hSession, unsigned int *col, unsigned int *row, unsigned int *width, unsigned int *height); | ||
| 149 | + | ||
| 150 | + /** | ||
| 137 | * @brief Get bitmasked flag for the current selection. | 151 | * @brief Get bitmasked flag for the current selection. |
| 138 | * | 152 | * |
| 139 | * Calculate flags to help drawing of the correct mouse pointer over a selection. | 153 | * Calculate flags to help drawing of the correct mouse pointer over a selection. |
src/lib3270/paste.c
| @@ -318,6 +318,7 @@ LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str) | @@ -318,6 +318,7 @@ LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str) | ||
| 318 | if(!lib3270_connected(h)) | 318 | if(!lib3270_connected(h)) |
| 319 | { | 319 | { |
| 320 | lib3270_ring_bell(h); | 320 | lib3270_ring_bell(h); |
| 321 | + errno = ENOTCONN; | ||
| 321 | return 0; | 322 | return 0; |
| 322 | } | 323 | } |
| 323 | 324 |
src/lib3270/selection/get.c
| @@ -141,4 +141,3 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -141,4 +141,3 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 141 | return lib3270_get_selection(hSession,0,LIB3270_SELECTION_CUT); | 141 | return lib3270_get_selection(hSession,0,LIB3270_SELECTION_CUT); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | - |
src/lib3270/selection/selection.c
| @@ -169,7 +169,7 @@ void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect | @@ -169,7 +169,7 @@ void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect | ||
| 169 | return; | 169 | return; |
| 170 | 170 | ||
| 171 | // Do we really need to change selection? | 171 | // Do we really need to change selection? |
| 172 | - if(start == h->select.start && end == h->select.end && h->selected) | 172 | + if( ((int) start) == h->select.start && ((int) end) == h->select.end && h->selected) |
| 173 | return; | 173 | return; |
| 174 | 174 | ||
| 175 | // Start address is inside the screen? | 175 | // Start address is inside the screen? |
| @@ -240,102 +240,6 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba | @@ -240,102 +240,6 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba | ||
| 240 | return rc; | 240 | return rc; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | -/* | ||
| 244 | -static void clear_chr(H3270 *hSession, int baddr) | ||
| 245 | -{ | ||
| 246 | - hSession->text[baddr].chr = ' '; | ||
| 247 | - | ||
| 248 | - hSession->ea_buf[baddr].cc = EBC_null; | ||
| 249 | - hSession->ea_buf[baddr].cs = 0; | ||
| 250 | - | ||
| 251 | - hSession->cbk.update( hSession, | ||
| 252 | - baddr, | ||
| 253 | - hSession->text[baddr].chr, | ||
| 254 | - hSession->text[baddr].attr, | ||
| 255 | - baddr == hSession->cursor_addr ); | ||
| 256 | -} | ||
| 257 | - | ||
| 258 | -static char * get_text(H3270 *hSession, unsigned char all, char tok, unsigned char cut) | ||
| 259 | -{ | ||
| 260 | - int row, col, baddr; | ||
| 261 | - char * ret; | ||
| 262 | - size_t buflen = (hSession->rows * (hSession->cols+1))+1; | ||
| 263 | - size_t sz = 0; | ||
| 264 | - unsigned short attr = 0xFFFF; | ||
| 265 | - | ||
| 266 | - if(check_online_session(hSession)) | ||
| 267 | - return NULL; | ||
| 268 | - | ||
| 269 | - if(!hSession->selected || hSession->select.start == hSession->select.end) | ||
| 270 | - return NULL; | ||
| 271 | - | ||
| 272 | - ret = lib3270_malloc(buflen); | ||
| 273 | - | ||
| 274 | - baddr = 0; | ||
| 275 | - unsigned char fa = 0; | ||
| 276 | - | ||
| 277 | - for(row=0;row < hSession->rows;row++) | ||
| 278 | - { | ||
| 279 | - int cr = 0; | ||
| 280 | - | ||
| 281 | - for(col = 0; col < hSession->cols;col++) | ||
| 282 | - { | ||
| 283 | - if(hSession->ea_buf[baddr].fa) { | ||
| 284 | - fa = hSession->ea_buf[baddr].fa; | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | - if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) | ||
| 288 | - { | ||
| 289 | - if(tok && attr != hSession->text[baddr].attr) | ||
| 290 | - { | ||
| 291 | - attr = hSession->text[baddr].attr; | ||
| 292 | - ret[sz++] = tok; | ||
| 293 | - ret[sz++] = (attr & 0x0F); | ||
| 294 | - ret[sz++] = ((attr & 0xF0) >> 4); | ||
| 295 | - | ||
| 296 | - } | ||
| 297 | - | ||
| 298 | - cr++; | ||
| 299 | - ret[sz++] = hSession->text[baddr].chr; | ||
| 300 | - | ||
| 301 | - if(cut && !FA_IS_PROTECTED(fa)) { | ||
| 302 | - clear_chr(hSession,baddr); | ||
| 303 | - } | ||
| 304 | - | ||
| 305 | - } | ||
| 306 | - baddr++; | ||
| 307 | - } | ||
| 308 | - | ||
| 309 | - if(cr) | ||
| 310 | - ret[sz++] = '\n'; | ||
| 311 | - | ||
| 312 | - if((sz+10) > buflen) | ||
| 313 | - { | ||
| 314 | - buflen += 100; | ||
| 315 | - ret = lib3270_realloc(ret,buflen); | ||
| 316 | - } | ||
| 317 | - } | ||
| 318 | - | ||
| 319 | - if(!sz) | ||
| 320 | - { | ||
| 321 | - lib3270_free(ret); | ||
| 322 | - errno = ENOENT; | ||
| 323 | - return NULL; | ||
| 324 | - } | ||
| 325 | - else if(sz > 1 && ret[sz-1] == '\n') // Remove ending \n | ||
| 326 | - { | ||
| 327 | - ret[sz-1] = 0; | ||
| 328 | - } | ||
| 329 | - | ||
| 330 | - ret[sz++] = 0; | ||
| 331 | - | ||
| 332 | - if(sz != buflen) | ||
| 333 | - ret = lib3270_realloc(ret,sz); | ||
| 334 | - | ||
| 335 | - return ret; | ||
| 336 | -} | ||
| 337 | -*/ | ||
| 338 | - | ||
| 339 | LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, unsigned char all) | 243 | LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, unsigned char all) |
| 340 | { | 244 | { |
| 341 | char * text; | 245 | char * text; |
| @@ -470,3 +374,56 @@ LIB3270_EXPORT int lib3270_has_selection(H3270 *hSession) | @@ -470,3 +374,56 @@ LIB3270_EXPORT int lib3270_has_selection(H3270 *hSession) | ||
| 470 | 374 | ||
| 471 | return hSession->selected != 0; | 375 | return hSession->selected != 0; |
| 472 | } | 376 | } |
| 377 | + | ||
| 378 | +LIB3270_EXPORT int lib3270_get_selection_rectangle(H3270 *hSession, unsigned int *col, unsigned int *row, unsigned int *width, unsigned int *height) | ||
| 379 | +{ | ||
| 380 | + unsigned int r, c, minRow, minCol, maxRow, maxCol, baddr, count; | ||
| 381 | + | ||
| 382 | + if(check_online_session(hSession)) | ||
| 383 | + return errno; | ||
| 384 | + | ||
| 385 | + if(!hSession->selected || hSession->select.start == hSession->select.end) | ||
| 386 | + return errno = ENOENT; | ||
| 387 | + | ||
| 388 | + minRow = hSession->rows; | ||
| 389 | + minCol = hSession->cols; | ||
| 390 | + maxRow = 0; | ||
| 391 | + maxCol = 0; | ||
| 392 | + baddr = 0; | ||
| 393 | + count = 0; | ||
| 394 | + | ||
| 395 | + for(r=0;r < hSession->rows;r++) | ||
| 396 | + { | ||
| 397 | + for(c = 0; c < hSession->cols;c++) | ||
| 398 | + { | ||
| 399 | + if(hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) | ||
| 400 | + { | ||
| 401 | + count++; | ||
| 402 | + | ||
| 403 | + if(c < minCol) | ||
| 404 | + minCol = c; | ||
| 405 | + | ||
| 406 | + if(r < minRow) | ||
| 407 | + minRow = r; | ||
| 408 | + | ||
| 409 | + if(c > maxCol) | ||
| 410 | + maxCol = c; | ||
| 411 | + | ||
| 412 | + if(r > maxRow) | ||
| 413 | + maxRow = r; | ||
| 414 | + } | ||
| 415 | + baddr++; | ||
| 416 | + } | ||
| 417 | + } | ||
| 418 | + | ||
| 419 | + if(!count) | ||
| 420 | + return errno = ENOENT; | ||
| 421 | + | ||
| 422 | + *col = minCol; | ||
| 423 | + *row = minRow; | ||
| 424 | + *width = (maxCol - minCol); | ||
| 425 | + *height = (maxRow - minRow); | ||
| 426 | + | ||
| 427 | + return 0; | ||
| 428 | +} | ||
| 429 | + |