--------------------------------------------------------------------------- | Facility : libnform | Function : static bool Field_Grown( FIELD *field, int amount) | | Description : This function is called for growable dynamic fields | only. It has to increase the buffers and to allocate | a new window for this field. |
| 447 | | |
| 448 | | Return Values : TRUE - field successfully increased |
| 449 | | FALSE - there was some error |
| 450 | +--------------------------------------------------------------------------*/ |
| 451 | static bool Field_Grown(FIELD * field, int amount) |
| 452 | { |
| 453 | bool result = FALSE; |
| 454 | |
| 455 | if (field && Growable(field)) |
| 456 | { |
| 457 | bool single_line_field = Single_Line_Field(field); |
| 458 | int old_buflen = Buffer_Length(field); |
| 459 | int new_buflen; |
| 460 | int old_dcols = field->dcols; |
| 461 | int old_drows = field->drows; |
| 462 | char *oldbuf = field->buf; |
| 463 | char *newbuf; |
| 464 | |
| 465 | int growth; |
| 466 | FORM *form = field->form; |
| 467 | bool need_visual_update = ((form != (FORM *)0) && |
| 468 | (form->status & _POSTED) && |
| 469 | (form->current==field)); |
| 470 | |
| 471 | if (need_visual_update) |
| 472 | Synchronize_Buffer(form); |
| 473 | |
| 474 | if (single_line_field) |
| 475 | { |
| 476 | growth = field->cols * amount; |
| 477 | if (field->maxgrow) |
| 478 | growth = Minimum(field->maxgrow - field->dcols,growth); |
| 479 | field->dcols += growth; |
| 480 | if (field->dcols == field->maxgrow) |
| 481 | field->status &= ~_MAY_GROW; |
| 482 | } |
| 483 | else |
| 484 | { |
| 485 | growth = (field->rows + field->nrow) * amount; |
| 486 | if (field->maxgrow) |
| 487 | growth = Minimum(field->maxgrow - field->drows,growth); |
| 488 | field->drows += growth; |
| 489 | if (field->drows == field->maxgrow) |
| 490 | field->status &= ~_MAY_GROW; |
| 491 | } |
| 492 | /* drows, dcols changed, so we get really the new buffer length */ |
| 493 | new_buflen = Buffer_Length(field); |
| 494 | newbuf=(char *)malloc((size_t)Total_Buffer_Size(field)); |
| 495 | if (!newbuf) |
| 496 | { /* restore to previous state */ |
| 497 | field->dcols = old_dcols; |
| 498 | field->drows = old_drows; |
| 499 | if (( single_line_field && (field->dcols!=field->maxgrow)) || |
| 500 | (!single_line_field && (field->drows!=field->maxgrow))) |
| 501 | field->status |= _MAY_GROW; |
| 502 | return FALSE; |
| 503 | } |
| 504 | else |
| 505 | { /* Copy all the buffers. This is the reason why we can't |
| 506 | just use realloc(). |
no test coverage detected
searching dependent graphs…