Frames 93.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : Frames.c                               */
17
/*                                                 */
18 19
/* Purpose: Frame handling functions for the       */
/*          browser.                               */
20
/*                                                 */
21
/* Author : A.D.Hodgkinson                         */
22 23
/*                                                 */
/* History: 19-Mar-97: Created.                    */
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/***************************************************/

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "swis.h"
#include "flex.h"

#include "HTMLLib.h" /* HTML library API, Which will include html2_ext.h, tags.h and struct.h */

#include "wimp.h"
#include "wimplib.h"
#include "event.h"

#include "toolbox.h"
#include "window.h"

#include "NestWimp.h"

#include "svcprint.h"
#include "Global.h"
#include "FromROSLib.h"
#include "Utils.h"

#include "Browser.h"
50
#include "Fetch.h" /* (Which itself includes URLstat.h) */
51 52 53
#include "FetchPage.h"
#include "Images.h"
#include "Memory.h"
54
#include "Mouse.h"
55
#include "Redraw.h"
56 57 58 59 60 61 62 63 64
#include "Reformat.h"
#include "Toolbars.h"
#include "URLutils.h"
#include "Windows.h"

#include "Frames.h"

/* Locals */

65 66 67 68 69 70
static int            highlight_timer  = 0;
static int            highlight_for    = 0;
static ObjectId       highlight_top    = 0;
static ObjectId       highlight_bottom = 0;
static ObjectId       highlight_left   = 0;
static ObjectId       highlight_right  = 0;
71 72 73

/* Static function prototypes */

74 75 76
static _kernel_oserror * frames_find_widths            (browser_data * b, int available);
static _kernel_oserror * frames_find_heights           (browser_data * b, int available);
static int               frames_check_recursion        (browser_data * parent, browser_data * child, HStream * token);
77
static _kernel_oserror * frames_reopen_frame           (browser_data * cb, browser_data * parent, BBox * frame_box);
78
static void              frames_collapse_child_tree    (browser_data * base, browser_data * real_parent, browser_data * close);
79

80 81
static browser_data    * frames_find_next_frame        (browser_data * check, browser_data * current, int * found);
static browser_data    * frames_find_previous_frame    (browser_data * check, browser_data * current, int * found);
82

83
static int               frames_remove_highlight_timer (int eventcode, WimpPollBlock * b, IdBlock * idb, browser_data * handle);
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

/*************************************************/
/* frames_find_widths()                          */
/*                                               */
/* Constructs an array pointed to by the         */
/* frame_widths field of a browser_data struct,  */
/* containing the widths of frames described by  */
/* the token pointed to in the frameset field of */
/* the browser_data structure.                   */
/*                                               */
/* These frame widths are set to occupy the      */
/* entire space given to the function; any       */
/* border and scroll bar size considerations     */
/* must therefore be done externally.            */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the frameset;         */
101
/*                                               */
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
/*             The available width the frameset  */
/*             must fit inside, in OS units.     */
/*************************************************/

static _kernel_oserror * frames_find_widths(browser_data * b, int available)
{
  _kernel_oserror * e;
  int               tw, units;
  int               col, cols, left, stars;

  cols = b->frameset->cols;
  if (!cols) cols = 1;

  /* Allocate memory for the array */

  e = memory_set_chunk_size(b, NULL, CK_FWID, cols * sizeof(int));
  if (e) return e;

  /* Ensure 'available' is a whole number of pixels */

  available &= ~(wimpt_dx() - 1);

  /* Fast simple case - only one column */

  if (cols == 1)
  {
    b->frame_widths[0] = available;
    return NULL;
  }

  /* Initial conditions */

  left  = available;
  stars = 0;

  /* First pass; subtract from the overall width, */
  /* the width of percentage specified frames     */
  /* and absolute pixel size specified frames.    */

  for (col = 0; col < cols; col ++)
  {
    tw     = ((int *) (b->frameset->value))[col];
    units  = tw & ~ROWCOL_VALUE;
    tw    &= ROWCOL_VALUE;

    if (units & ROWCOL_PERCENT)
    {
      tw    = ((available * tw) / 100) & ~(wimpt_dx() - 1);
      left -= tw;

      b->frame_widths[col] = tw;
    }
    else if (units & ROWCOL_STAR)
    {
156
      stars += tw;
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    }
    else
    {
      tw    = (tw * 2) & ~(wimpt_dx() - 1);
      left -= tw;

      b->frame_widths[col] = tw;
    }
  }

  /* Second pass; allocate a fraction of the   */
  /* remaining space to star specified frames. */

  if (stars)
  {
    int remaining;
173
    int rem_stars = stars;
174 175 176 177 178 179 180 181 182 183 184

    remaining = left;

    for (col = 0; col < cols; col ++)
    {
      tw     = ((int *) (b->frameset->value))[col];
      units  = tw & ~ROWCOL_VALUE;
      tw    &= ROWCOL_VALUE;

      if (units & ROWCOL_STAR)
      {
185 186 187 188 189
        rem_stars -= tw;

        if (rem_stars) tw = (remaining * tw / stars) & ~(wimpt_dx() - 1);
        else           tw = left;

190
        if (tw < controls.minimum_frame_width) tw = controls.minimum_frame_width;
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

        left -= tw;

        b->frame_widths[col] = tw;
      }
    }
  }

  /* Third pass; simple scale to fit all the frames in the */
  /* available space (scaling up or down). 'left' holds,   */
  /* in OS units, the amount left / overshot in the        */
  /* available width.                                      */

  if (left != 0)
  {
    int basic, remainder, left2 = available;

    if (available == left) left = available + 1;

    for (col = 0; col < cols; col ++)
    {
      left2                 -=
      b->frame_widths[col]  =

      (b->frame_widths[col] * available / (available - left)) & ~(wimpt_dx() - 1);
    }

    /* 'left2' is in OS units, but represents a whole number of */
219
    /* pixels due to careful use of wimpt_dx above. To cope     */
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    /* with rounding correctly during rescaling the widths      */
    /* (see below), want this now in pixel values.              */

    left = left2 / wimpt_dx();

    basic     = left / cols;
    remainder = left - (basic * cols);

    basic *= wimpt_dx();

    for (col = 0; col < cols; col ++)
    {
      if (remainder < 0)
      {
        b->frame_widths[col] += basic - wimpt_dx();
        remainder ++;
      }
      else if (remainder > 0)
      {
        b->frame_widths[col] += basic + wimpt_dx();
        remainder --;
      }
      else b->frame_widths[col] += basic;
    }
  }

  return NULL;
}

/*************************************************/
/* frames_find_heights()                         */
/*                                               */
/* Constructs an array pointed to by the         */
/* frame_heights field of a browser_data struct, */
/* containing the heights of frames described by */
/* the token pointed to in the frameset field of */
/* the browser_data structure.                   */
/*                                               */
/* These frame heights are set to occupy the     */
/* entire space given to the function; any       */
/* border and scroll bar size considerations     */
/* must therefore be done externally.            */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the frameset;         */
265
/*                                               */
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
/*             The available height the frameset */
/*             must fit inside, in OS units.     */
/*************************************************/

static _kernel_oserror * frames_find_heights(browser_data * b, int available)
{
  _kernel_oserror * e;
  int               th, units;
  int               row, rows, left, stars;

  rows = b->frameset->rows;
  if (!rows) rows = 1;

  /* Allocate memory for the array */

  e = memory_set_chunk_size(b, NULL, CK_FHEI, rows * sizeof(int));
  if (e) return e;

  /* Ensure 'available' is a whole number of pixels */

  available &= ~(wimpt_dy() - 1);

  /* Fast simple case - only one row */

  if (rows == 1)
  {
    b->frame_heights[0] = available;
    return NULL;
  }

  /* Initial conditions */

  left  = available;
  stars = 0;

  /* First pass; subtract from the overall height, */
  /* the height of percentage specified frames     */
  /* and absolute pixel size specified frames.     */

  for (row = 0; row < rows; row ++)
  {
    th     = ((int *) (b->frameset->name))[row];
    units  = th & ~ROWCOL_VALUE;
    th    &= ROWCOL_VALUE;

    if (units & ROWCOL_PERCENT)
    {
      th    = ((available * th) / 100) & ~(wimpt_dy() - 1);
      left -= th;

      b->frame_heights[row] = th;
    }
    else if (units & ROWCOL_STAR)
    {
320
      stars += th;
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
    }
    else
    {
      th    = (th * 2) & ~(wimpt_dy() - 1);
      left -= th;

      b->frame_heights[row] = th;
    }
  }

  /* Second pass; allocate a fraction of the   */
  /* remaining space to star specified frames. */

  if (stars)
  {
    int remaining;
337
    int rem_stars = stars;
338 339 340 341 342 343 344 345 346 347 348

    remaining = left;

    for (row = 0; row < rows; row ++)
    {
      th     = ((int *) (b->frameset->name))[row];
      units  = th & ~ROWCOL_VALUE;
      th    &= ROWCOL_VALUE;

      if (units & ROWCOL_STAR)
      {
349 350 351 352 353
        rem_stars -= th;

        if (rem_stars) th = (remaining * th / stars) & ~(wimpt_dy() - 1);
        else           th = left;

354
        if (th < controls.minimum_frame_height) th = controls.minimum_frame_height;
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

        left -= th;

        b->frame_heights[row] = th;
      }
    }
  }

  /* Third pass; simple scale to fit all the frames in the */
  /* available space (scaling up or down). 'left' holds,   */
  /* in OS units, the amount left / overshot in the        */
  /* available height.                                     */

  if (left != 0)
  {
    int basic, remainder, left2 = available;

    if (available == left) left = available + 1;

    for (row = 0; row < rows; row ++)
    {
      left2                 -=
      b->frame_heights[row]  =

      (b->frame_heights[row] * available / (available - left)) & ~(wimpt_dy() - 1);
    }

    /* 'left2' is in OS units, but represents a whole number of */
383
    /* pixels due to careful use of wimpt_dy above. To cope     */
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
    /* with rounding correctly during rescaling the heights     */
    /* (see below), want this now in pixel values.              */

    left = left2 / wimpt_dy();

    basic     = left / rows;
    remainder = left - (basic * rows);

    basic *= wimpt_dy();

    for (row = 0; row < rows; row ++)
    {
      if (remainder < 0)
      {
        b->frame_heights[row] += basic - wimpt_dy();
        remainder ++;
      }
      else if (remainder > 0)
      {
        b->frame_heights[row] += basic + wimpt_dy();
        remainder --;
      }
      else b->frame_heights[row] += basic;
    }
  }

  return NULL;
}

/*************************************************/
/* frames_get_rc_info()                          */
/*                                               */
/* Returns the number of rows and columns in a   */
/* frameset, and the row and column that a       */
/* specific child lies in.                       */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of the set of */
/*             frames in question;               */
/*                                               */
/*             The child number, or -1 if not    */
/*             interested in this info;          */
/*                                               */
/*             Pointer to an int, into which the */
/*             number of rows is placed;         */
/*                                               */
/*             Pointer to an int, into which the */
/*             number of columns is placed;      */
/*                                               */
/*             Pointer to an int, into which the */
/*             row the child lies in is placed;  */
/*                                               */
/*             Pointer to an int, into which the */
/*             column the child lies in is       */
/*             placed.                           */
/*                                               */
/* Assumes:    Any of the four int pointers may  */
/*             be NULL.                          */
/*************************************************/

void frames_get_rc_info(browser_data * parent, int child,
                        int * retrows, int * retcols, int * retrow, int * retcol)
{
  int rows = 0, row = 0, cols = 0, col = 0;

  if (parent->nchildren)
  {
    rows = parent->frameset->rows;
    cols = parent->frameset->cols;

    if (!rows) rows = 1;
    if (!cols) cols = 1;

    if (child >= 0)
    {
      row = child / rows;
      col = child % cols;

      if (row <  0)    row = 0;
      if (row >= rows) row = rows - 1;
      if (col <  0)    col = 0;
      if (col >= cols) col = cols - 1;
    }
  }

  if (retrows) *retrows = rows;
  if (retcols) *retcols = cols;
  if (retrow)  *retrow  = row;
  if (retcol)  *retcol  = col;
}

475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
/*************************************************/
/* frames_find_pointer_in_frameset()             */
/*                                               */
/* Works out where in a frameset a given screen  */
/* coordinate is. The returned row and column    */
/* values are -1 if the coordinate lies within   */
/* a row or column, or are the row below, or     */
/* column to the right of the coordinate if it   */
/* lies in the border between two rows or        */
/* columns. So the value 0 would never be        */
/* returned for either.                          */
/*                                               */
/* In the event that the pointer lies between a  */
/* row or column but that row or column edge     */
/* cannot be resized due to specifiers in the    */
/* HTML source for the frameset, -2 will be      */
/* returned.                                     */
/*                                               */
/* Given that this is likely to be called by     */
/* routines handling border-driven resizing of   */
/* frames, the routine can constrain the pointer */
/* to a bounding box appropriate to the frames   */
/* surrounding it if required. This may be done  */
/* via. a mouse_rectangle or Wimp_DragBox.       */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the parent frame;    */
/*                                               */
/*             X screen coordinate to check;     */
/*                                               */
/*             Y screen coordinate to check;     */
/*                                               */
/*             Pointer to an int, into which the */
/*             row number (see above) will be    */
/*             written;                          */
/*                                               */
/*             Pointer to an int, into which the */
/*             column number (see above) will be */
/*             written;                          */
/*                                               */
/*             Pointer to an int, into which the */
/*             pointer's x offset from the left  */
/*             edge of the frame left of it, if  */
/*             applicable, is returned;          */
/*                                               */
/*             Pointer to an int, into which the */
/*             pointer's y offset from the top   */
/*             edge of the frame below it, if    */
/*             applicable, is returned;          */
/*                                               */
/*             1 to constrain the pointer (again */
/*             see above for more details) with  */
/*             Wimp_DragBox, 2 to constrain with */
/*             mouse_rectangle, 0 to not do any  */
/*             pointer constraint.               */
/*                                               */
/* Assumes:    Either of the four int pointers   */
/*             may be NULL.                      */
/*************************************************/

_kernel_oserror * frames_find_pointer_in_frameset(browser_data * handle, int x, int y, int * retrow, int * retcol,
                                                  int * offset_left, int * offset_top, int constrain)
{
  _kernel_oserror           * e;
  browser_data              * child;
  WimpGetWindowOutlineBlock   co;
  int                         oft,  ofl;
  int                         rows, cols;
  int                         row,  col;
  int                         i,    c;
  BBox                        span;

  if (offset_left) *offset_left = 0;
  if (offset_top)  *offset_top  = 0;

  oft = ofl = 0;

  /* Find the number of rows and columns */

  rows = handle->frameset->rows;
  cols = handle->frameset->cols;

  if (!rows) rows = 1;
  if (!cols) cols = 1;

  /* First find the row that the pointer lies between */

  row = -1, col = -1;

  for (i = 0; i < rows; i++)
  {
    /* What child number are we on? */

    c = i * cols;

    if (c < handle->nchildren)
    {
      /* Get this child frame's outline coordinates */

      child            = handle->children[c];
      co.window_handle = child->window_handle;

      e = wimp_get_window_outline(&co);
      if (e) return e;

      /* First case - pointer y coord lies within the bounding y */
      /* coords of the window, so it lies in this row. In this   */
      /* case, we've a column-only drag, so don't care about the */
      /* row. We can just exit, leaving row at -1.               */

      if (co.outline.ymax > y && co.outline.ymin < y) break;

      /* Second case - pointer y coord lies above the top of the */
      /* frame. So we've gone past it; in that case, the pointer */
      /* must lie between this row and the previous one.         */

      if (co.outline.ymax <= y)
      {
        row = i; /* So row points to the row below the pointer */
        oft = y - co.outline.ymax;

        if (offset_top) *offset_top = oft;

        break;
      }
    }
  }

  /* Right, next find the column the pointer lies between */

  for (i = 0; i < cols; i++)
  {
    if (i < handle->nchildren)
    {
      /* Get this child frame's outline coordinates */

      child            = handle->children[i];
      co.window_handle = child->window_handle;

      e = wimp_get_window_outline(&co);
      if (e) return e;

      /* As for rows, first case is the x coord lying within the */
      /* bounding x coords of the window.                        */

      if (co.outline.xmin < x && co.outline.xmax > x) break;

      /* Second case, the pointer x coord lies left of the left  */
      /* hand side of the frame, so we've gone past it.          */

      if (co.outline.xmin >= x)
      {
        col = i;
        ofl = co.outline.xmin - x;

        if (offset_left) *offset_left = ofl;

        break;
      }
    }
  }

  /* At this point, row holds -1 if the pointer lies within a  */
  /* particular row, or holds the row number below the pointer */
  /* if it lies between two rows. Similarly, col holds -1 if   */
  /* the pointer lies within a particular column, or holds the */
  /* column number to the right of the pointer if it lies      */
  /* between two columns.                                      */

  if (
       row == 0        ||
       col == 0        ||
       row >= rows ||
       col >= cols
     )
  {
    if (retrow) *retrow = -1;
    if (retcol) *retcol = -1;

    return NULL;
  }

  /* Are we allowed to resize this edge? */

  if (row > 0 && !frames_can_resize_top(handle, row * cols)) row = -2;
  if (col > 0 && !frames_can_resize_left(handle, col))       col = -2;

  /* Set the return values */

  if (retrow) *retrow = row;
  if (retcol) *retcol = col;

  /* If required, constrain the pointer */

  if (constrain)
  {
    int th, hh, vw;

    /* Find the tool sizes; we reduce the size of the bounding box */
    /* for the pointer by the relevant tool size times two to make */
    /* sure the frames don't get squashed too small, as well as    */
    /* considering the border width and original drag position.    */

    windows_return_tool_sizes(&th, &hh, &vw);

680 681
    span.xmin = span.xmax = x;
    span.ymin = span.ymax = y;
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704

    /* Finding the outlines again for four frames  */
    /* may duplicate some, or even all of the work */
    /* done above but this keeps the code clear    */
    /* and easy to understand. This is a very      */
    /* infrequent operation (only at the start of  */
    /* a drag, for example) so it doesn't need to  */
    /* be that fast.                               */

    if (row > 0)
    {
      /* Get the top frame outline coordinates */

      c = (row - 1) * cols;

      if (c < handle->nchildren)
      {
        child            = handle->children[c];
        co.window_handle = child->window_handle;

        e = wimp_get_window_outline(&co);
        if (e) return e;

705
        span.ymax = y + co.outline.ymax - co.outline.ymin - hh * 2;
706 707 708 709 710 711 712 713 714 715 716 717 718 719
      }

      /* Get the bottom frame outline coordinates */

      c = row * cols;

      if (c < handle->nchildren)
      {
        child            = handle->children[c];
        co.window_handle = child->window_handle;

        e = wimp_get_window_outline(&co);
        if (e) return e;

720
        span.ymin = y - (co.outline.ymax - co.outline.ymin - hh * 2);
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
      }

      if (span.ymax < span.ymin) span.ymax = span.ymin = y;
    }

    if (col > 0)
    {
      /* Get the left frame outline coordinates */

      c = col - 1;

      if (c < handle->nchildren)
      {
        child            = handle->children[c];
        co.window_handle = child->window_handle;

        e = wimp_get_window_outline(&co);
        if (e) return e;

740
        span.xmin = x - (co.outline.xmax - co.outline.xmin - vw * 2);
741 742 743 744 745 746 747 748 749 750 751 752 753 754
      }

      /* Get the right hand frame outline coordinates */

      c = col;

      if (c < handle->nchildren)
      {
        child            = handle->children[c];
        co.window_handle = child->window_handle;

        e = wimp_get_window_outline(&co);
        if (e) return e;

755
        span.xmax = x + co.outline.xmax - co.outline.xmin - vw * 2;
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
      }

      if (span.xmax < span.xmin) span.xmax = span.xmin = x;
    }

    /* Set the bounding box */

    if (constrain == 1)
    {
      WimpDragBox drag;

      drag.wimp_window       = handle->window_handle;
      drag.drag_type         = Wimp_DragBox_DragPoint;

      drag.dragging_box.xmin = 0;
      drag.dragging_box.ymin = 0;
      drag.dragging_box.xmax = 0;
      drag.dragging_box.ymax = 0;
      drag.parent_box        = span;

      drag.workspace         = NULL;
      drag.draw              = NULL;
      drag.remove            = NULL;
      drag.move              = NULL;

      wimp_drag_box(&drag);
    }
783
    else if (constrain == 2) mouse_rectangle(&span, 1);
784 785 786 787 788 789 790
  }

  /* Finished */

  return NULL;
}

791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
/*************************************************/
/* frames_can_resize_top()                       */
/*                                               */
/* Returns 1 if the top edge of a given frame    */
/* may be dragged to resize the frame.           */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of the set of */
/*             frames in question;               */
/*                                               */
/*             Number of the child to check.     */
/*                                               */
/* Returns:    1 if the frame's top edge can be  */
/*             dragged to resize it, else 0 (due */
/*             to NORESIZE specified on that     */
/*             frame or frames surrounding it).  */
/*************************************************/

int frames_can_resize_top(browser_data * parent, int child)
{
  int            row, rows, col, cols;
  int            checkcol, checkchild;
  browser_data * checkc;
  int            canresize = 1;
  HStream      * frametoken;

  if (!parent->nchildren) return 0;

  frametoken = parent->children[child]->frame;

  if (frametoken && (frametoken->type & TYPE_NORESIZE)) return 0;

  /* Find out the number of rows and columns, and the */
  /* row and column number the given child falls in.  */

  frames_get_rc_info(parent, child, &rows, &cols, &row, &col);

  for (checkcol = 0; checkcol < cols; checkcol ++)
  {
    /* Check all columns in the row the child is in for NORESIZE frames */

    checkchild = row * cols + checkcol;
    checkc     = parent->children[checkchild];
    frametoken = checkc->frame;

    if (frametoken && (frametoken->type & TYPE_NORESIZE))
    {
      canresize = 0;
      break;
    }

    /* If not already on row 0, check the row above for NORESIZE frames */

    if (row)
    {
      checkchild = (row - 1) * cols + checkcol;
      checkc     = parent->children[checkchild];
      frametoken = checkc->frame;

      if (frametoken && (frametoken->type & TYPE_NORESIZE))
      {
        canresize = 0;
        break;
      }
    }
  }

  return canresize;
}

/*************************************************/
/* frames_can_resize_bottom()                    */
/*                                               */
/* Returns 1 if the bottom edge of a given frame */
/* may be dragged to resize the frame.           */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of the set of */
/*             frames in question;               */
870
/*                                               */
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
/*             Number of the child to check.     */
/*                                               */
/* Returns:    1 if the frame's bottom edge can  */
/*             be dragged to resize it, else 0   */
/*             (due to NORESIZE specified on     */
/*             that frame or frames surrounding  */
/*             it).                              */
/*************************************************/

int frames_can_resize_bottom(browser_data * parent, int child)
{
  int            row, rows, col, cols;
  int            checkcol, checkchild;
  browser_data * checkc;
  int            canresize = 1;
  HStream      * frametoken;

  if (!parent->nchildren) return 0;

  frametoken = parent->children[child]->frame;

  if (frametoken && (frametoken->type & TYPE_NORESIZE)) return 0;

  /* Find out the number of rows and columns, and the */
  /* row and column number the given child falls in.  */

  frames_get_rc_info(parent, child, &rows, &cols, &row, &col);

  for (checkcol = 0; checkcol < cols; checkcol ++)
  {
    /* Check all columns in the row the child is in for NORESIZE frames */

    checkchild = row * cols + checkcol;
    checkc     = parent->children[checkchild];
    frametoken = checkc->frame;

    if (frametoken && (frametoken->type & TYPE_NORESIZE))
    {
      canresize = 0;
      break;
    }

    /* If not already on the last row, check the row below for NORESIZE frames */

    if (row < rows - 1)
    {
      checkchild = (row + 1) * cols + checkcol;
      checkc     = parent->children[checkchild];
      frametoken = checkc->frame;

      if (frametoken && (frametoken->type & TYPE_NORESIZE))
      {
        canresize = 0;
        break;
      }
    }
  }

  return canresize;
}

/*************************************************/
/* frames_can_resize_left()                      */
/*                                               */
/* Returns 1 if the left edge of a given frame   */
/* may be dragged to resize the frame.           */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of the set of */
/*             frames in question;               */
941
/*                                               */
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
/*             Number of the child to check.     */
/*                                               */
/* Returns:    1 if the frame's left edge can be */
/*             dragged to resize it, else 0 (due */
/*             to NORESIZE specified on that     */
/*             frame or frames surrounding it).  */
/*************************************************/

int frames_can_resize_left(browser_data * parent, int child)
{
  int            row, rows, col, cols;
  int            checkrow, checkchild;
  browser_data * checkc;
  int            canresize = 1;
  HStream      * frametoken;

  if (!parent->nchildren) return 0;

  frametoken = parent->children[child]->frame;

  if (frametoken && (frametoken->type & TYPE_NORESIZE)) return 0;

  /* Find out the number of rows and columns, and the */
  /* row and column number the given child falls in.  */

  frames_get_rc_info(parent, child, &rows, &cols, &row, &col);

  for (checkrow = 0; checkrow < rows; checkrow ++)
  {
    /* Check all rows in the column the child is in for NORESIZE frames */

    checkchild = col + checkrow * cols;
    checkc     = parent->children[checkchild];
    frametoken = checkc->frame;

    if (frametoken && (frametoken->type & TYPE_NORESIZE))
    {
      canresize = 0;
      break;
    }

    /* If not already on column 0, check the column to the left for NORESIZE frames */

    if (col)
    {
      checkchild = col - 1 + checkrow * cols;
      checkc     = parent->children[checkchild];
      frametoken = checkc->frame;

      if (frametoken && (frametoken->type & TYPE_NORESIZE))
      {
        canresize = 0;
        break;
      }
    }
  }

  return canresize;
}

/*************************************************/
/* frames_can_resize_right()                     */
/*                                               */
/* Returns 1 if the right edge of a given frame  */
/* may be dragged to resize the frame.           */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of the set of */
/*             frames in question;               */
/*                                               */
1012
/*             Number of the child to check.     */
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
/*                                               */
/* Returns:    1 if the frame's right edge can   */
/*             be dragged to resize it, else 0   */
/*             (due to NORESIZE specified on     */
/*             that frame or frames surrounding  */
/*             it).                              */
/*************************************************/

int frames_can_resize_right(browser_data * parent, int child)
{
  int            row, rows, col, cols;
  int            checkrow, checkchild;
  browser_data * checkc;
  int            canresize = 1;
  HStream      * frametoken;

  if (!parent->nchildren) return 0;

  frametoken = parent->children[child]->frame;

  if (frametoken && (frametoken->type & TYPE_NORESIZE)) return 0;

  /* Find out the number of rows and columns, and the */
  /* row and column number the given child falls in.  */

  frames_get_rc_info(parent, child, &rows, &cols, &row, &col);

  for (checkrow = 0; checkrow < rows; checkrow ++)
  {
    /* Check all rows in the column the child is in for NORESIZE frames */

    checkchild = col + checkrow * cols;
    checkc     = parent->children[checkchild];
    frametoken = checkc->frame;

    if (frametoken && (frametoken->type & TYPE_NORESIZE))
    {
      canresize = 0;
      break;
    }

    /* If not already on the last column, check the column to the right for NORESIZE frames */

    if (col < cols - 1)
    {
      checkchild = col + 1 + checkrow * cols;
      checkc     = parent->children[checkchild];
      frametoken = checkc->frame;

      if (frametoken && (frametoken->type & TYPE_NORESIZE))
      {
        canresize = 0;
        break;
      }
    }
  }

  return canresize;
}

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
/*************************************************/
/* frames_redraw_borders()                       */
/*                                               */
/* Redraws plinth borders and a resize sprite    */
/* indicator around frames in a given parent.    */
/*                                               */
/* Parameters: Pointer to a parent browser_data  */
/*             struct;                           */
/*                                               */
/*             A WimpRedrawWindow block          */
/*             describing the redraw region.     */
/*************************************************/

void frames_redraw_borders(browser_data * b, WimpRedrawWindowBlock * r)
{
  int                         child;
  unsigned int                colour;
  BBox                        sbox;
  browser_data              * c;
  WimpGetWindowOutlineBlock   co;

  sbox = r->redraw_area;

  /* The bottom bit of the colour field is set to indicate */
  /* that a colour is present, as opposed to having no     */
  /* colour set. In the latter case default to background  */
  /* grey, in the former strip off the set bit. Then set   */
1100 1101 1102
  /* that colour. Remember, we try to find a colour in the */
  /* FRAME tags, then failing that look in the FRAMESET    */
  /* (as in NN or MSIE 4).                                 */
1103

1104
  colour = 0;
1105

1106 1107 1108 1109 1110 1111 1112 1113 1114
  for (child = 0; child < b->nchildren && !(colour & 1); child ++)
  {
    c = b->children[child];
    if (c->frame) colour = c->frame->maxlen;
  }

  if (!(colour & 1)) colour = b->frameset->maxlen;

  if (!(colour & 1)) colour = Redraw_Colour_WNGrey;
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
  else               colour &= ~1;

  redraw_set_colour(colour);

  bbc_rectanglefill(sbox.xmin,
                    sbox.ymin,
                    sbox.xmax - sbox.xmin + 4,
                    sbox.ymax - sbox.ymin + 4);

  #ifdef TRACE

    if (tl & (1u<<23))
    {
      redraw_set_colour(0xff884400);
      bbc_rectangle(sbox.xmin,
                    sbox.ymin,
                    sbox.xmax - sbox.xmin - 1,
                    sbox.ymax - sbox.ymin - 1);

      redraw_set_colour(0xffaa6600);
      bbc_rectangle(sbox.xmin + 2,
                    sbox.ymin + 2,
                    sbox.xmax - sbox.xmin - 5,
                    sbox.ymax - sbox.ymin - 5);

      redraw_set_colour(0xffcc8800);
      bbc_rectangle(sbox.xmin + 4,
                    sbox.ymin + 4,
                    sbox.xmax - sbox.xmin - 9,
                    sbox.ymax - sbox.ymin - 9);
    }

  #endif

  /* Now loop round the children, drawing a 3D border around them */
  /* for border spacings >= 2, a black line for spacing 1, or     */
  /* nothing for spacing 0 (shouldn't then get redraw events for  */
  /* the parent, but you never know - e.g. user could have got a  */
  /* patch that allowed the frames to be moved by dragging on     */
  /* their work area).                                            */

  if (b->frameset->indent) /* Holds frame spacing (equiv. to border width) */
  {
    for (child = 0; child < b->nchildren; child ++)
    {
      c                = b->children[child];
      co.window_handle = c->window_handle;

      if (!wimp_get_window_outline(&co))
      {
        if (b->frameset->indent >= 2) redraw_set_colour(Redraw_Colour_AlmostWhite);
        else                          redraw_set_colour(0);

        /* Bottom edge */

        bbc_rectanglefill(co.outline.xmin,
                          co.outline.ymin - 2,
                          co.outline.xmax - co.outline.xmin + 1,
                          1);

        bbc_rectanglefill(co.outline.xmax,
                          co.outline.ymin,
                          1,
                          co.outline.ymax - co.outline.ymin - 1);

        /* Right hand edge */

        if (b->frameset->indent >= 2) redraw_set_colour(Redraw_Colour_PlinthGrey);

        /* Top edge */

        bbc_rectanglefill(co.outline.xmin - 2,
                          co.outline.ymax,
                          co.outline.xmax - co.outline.xmin + 3,
                          1);

        /* Left hand edge */

        bbc_rectanglefill(co.outline.xmin - 2,
                          co.outline.ymin - 2,
                          1,
                          co.outline.ymax - co.outline.ymin + 1);

        /* If the edges are draggable - for frame resizing - plot icons */
        /* indicate this.                                               */

        {
          int  width, height;
          BBox icon;

          /* Get the sprite size, work out a bounding box and plot */
          /* this as a virtual icon.                               */

          read_sprite_size("resizeframe", &width, &height);

          /* Can only plot sprites if there's room... The additions to width and */
          /* height account for the border plotted above.                        */

          if (
               width  + 4 <= b->frameset->indent * wimpt_dx() &&
               height + 4 <= b->frameset->indent * wimpt_dy()
             )
          {
            WimpPlotIconBlock block;

            block.flags = 0x1700311B;
            block.data.ist.buffer = "";
            block.data.ist.validation = "Sresizeframe";
            block.data.ist.buffer_size = 4;

1225
            if (frames_can_resize_right(b, child) && !printing)
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
            {
              /* Plot to right of frame */

              icon.xmin = co.outline.xmax + b->frameset->indent - width / 2;
              icon.ymin = co.outline.ymin + (co.outline.ymax - co.outline.ymin - height) / 2;
              icon.xmax = icon.xmin + width;
              icon.ymax = icon.ymin + height;

              coords_box_toworkarea(&icon, r);
              block.bbox  = icon;

              _swix(Wimp_PlotIcon,
                    _IN(1) | _INR(4,5),

                    &block,
                    0,
                    0);
            }

1245
            if (frames_can_resize_bottom(b, child) && !printing)
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
            {
              /* Plot below the frame */

              icon.xmin = co.outline.xmin + (co.outline.xmax - co.outline.xmin - width) / 2;
              icon.ymin = co.outline.ymin - height / 2 - b->frameset->indent;
              icon.xmax = icon.xmin + width;
              icon.ymax = icon.ymin + height;

              coords_box_toworkarea(&icon, r);
              block.bbox  = icon;

              _swix(Wimp_PlotIcon,
                    _IN(1) | _INR(4,5),

                    &block,
                    0,
                    0);
            }

          /* Closure of long 'if' checking that there is room to plot */
          /* a resize handle for this frame, given that the frame     */
          /* itself doesn't have noresize specified. The code above   */
          /* executes if noresize is not specified and there's room   */
          /* to do the plot.                                          */
          }

        /* Closure of code block dealing with resize handle plotting */
        }

      /* Closure of long 'if' ensuring a wimp_get_window_outline */
      /* call didn't return an error - the code above executes   */
      /* if there was no error.                                  */
      }

    /* Closure of 'for' looping round all children */
    }

  /* Closure of long 'if' checking that the frameset has spacing */
  /* between frames. The code above executes if so.              */
  }
}

1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
/*************************************************/
/* frames_define_frameset()                      */
/*                                               */
/* For a given parent browser_data structure,    */
/* sets up a frameset within it. Frame details   */
/* for each of the children thus generated are   */
/* filled in later, when getting each frame      */
/* token from the HTML library.                  */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the parent;          */
1299
/*                                               */
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
/*             Pointer to a token defining the   */
/*             frameset.                         */
/*                                               */
/* Assumes:    If the window already has a       */
/*             frameset defined, this set and    */
/*             all nested sets above it will be  */
/*             destroyed before the new one is   */
/*             created.                          */
/*************************************************/

_kernel_oserror * frames_define_frameset(browser_data * b, HStream * token)
{
  _kernel_oserror         * e;
  WimpGetWindowStateBlock   s;
  BBox                      frame_box;
  int                       rows, cols;
  int                       num_rows, num_cols;
  int                       width, height;
1318
  int                       htop, hbot;
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
  int                       available_w, available_h;
  int                       start_x, start_y, accum_x, accum_y;
  int                       th, hh, vw;

  #ifdef TRACE
    if (tl & (1u<<17)) Printf("frames_define_frameset: Called with browser_data %p\n",b);
  #endif

  /* For ancestor windows, need to get the whole window */
  /* state and use the visible area, thus taking        */
  /* account of scrollbar presence etc.                 */

  if (!b->ancestor || !nested_wimp)
  {
    s.window_handle = b->window_handle;
    e = wimp_get_window_state(&s);
    if (e) return e;
  }

  /* However, for frames with frames about to be defined */
  /* inside them, we know that the scrollbars in this    */
  /* frame will disappear (if the nested wimp is in use) */
  /* and so need to use the window outline, not the      */
  /* visible area, as the latter may not be up to date.  */

  else
  {
    WimpGetWindowOutlineBlock o;

    o.window_handle = b->window_handle;
    e = wimp_get_window_outline(&o);
    if (e) return e;

    s.window_handle = o.window_handle;
    s.visible_area  = o.outline;
  }

  windows_return_tool_sizes(&th, &hh, &vw);

  /* Destroy any existing frameset */

  frames_collapse_set(b);

  /* Set up the basic starting parameters */

  b->nchildren     = 0;
  b->filling_frame = 0;
  b->frameset      = token;

  /* Work out the amount of visible area that toolbars are consuming */

1370
  if (!controls.swap_bars)
1371 1372 1373 1374 1375 1376 1377 1378 1379
  {
    htop = toolbars_url_height(b) + toolbars_button_height(b); /* Physically, the button bar and URL bar are just one real toolbar */
    hbot = toolbars_status_height(b);
  }
  else
  {
    htop = toolbars_status_height(b);
    hbot = toolbars_url_height(b) + toolbars_button_height(b);
  }
1380

1381 1382
  if (htop) htop += wimpt_dy(); /* Account for lower border of upper toolbar, if present */
  if (hbot) hbot += wimpt_dy(); /* Account for upper border of lower toolbar, if present */
1383 1384 1385 1386

  /* Work out the available frame space width and height */

  available_w = s.visible_area.xmax - s.visible_area.xmin;
1387
  available_h = s.visible_area.ymax - s.visible_area.ymin - htop - hbot;
1388 1389 1390 1391

  /* Start defining frames from the top left hand side of the visible area */

  start_x = s.visible_area.xmin;
1392
  start_y = s.visible_area.ymax - htop;
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403

  /* Work out the number of rows / columns */

  num_rows = token->rows;
  if (!num_rows) num_rows = 1;

  num_cols = token->cols;
  if (!num_cols) num_cols = 1;

  /* Account for frame spacing */

1404 1405
  available_w -= token->indent * 2 * (num_cols - 1); /* Scale to 2 OS units/pixel */
  available_h -= token->indent * 2 * (num_rows - 1);
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494

  #ifdef TRACE
    if (tl & (1u<<17))
    {
      Printf("frames_define_frameset: avail_w %d\n"
             "                        avail_h %d\n"
             "                        start_x %d\n"
             "                        start_y %d\n"
             "                        rows    %d\n"
             "                        cols    %d\n\n",
             available_w,
             available_h,
             start_x,
             start_y,
             num_rows,
             num_cols);
      {
        int i;

        Printf("frames_define_frameset: Size enumeration:\n\n");

        for (i = 0; i < num_rows; i++)
        {
          if (token->name) Printf("Row %d = %p\n",i,((int *) token->name)[i]);
          else             Printf("Row %d = undefined\n",i);
        }

        Printf("\n");

        for (i = 0; i < num_cols; i++)
        {
          if (token->value) Printf("Col %d = %p\n",i,((int *) token->value)[i]);
          else              Printf("Col %d = undefined\n",i);
        }

        Printf("\nframes_define_frameset: Proceeding\n");
      }
    }
  #endif

  /* Get all the sizes */

  frames_find_widths (b, available_w);
  frames_find_heights(b, available_h);

  /* Loop round defining each child */

  frame_box.ymax = start_y;
  accum_y        = 0;

  for (rows = 0; rows < num_rows; rows ++)
  {
    frame_box.xmin = start_x;
    accum_x        = 0;
    height         = b->frame_heights[rows];

    accum_y += height;

    if (rows == num_rows - 1)
    {
      /* For the last row, ensure it fills up the height - rounding errors in scaling */
      /* for the find_height calls often make this necessary.                         */

      if (accum_y != available_h) height -= accum_y - available_h, accum_y = available_h;
    }

    for (cols = 0; cols < num_cols; cols ++)
    {
      width = b->frame_widths[cols];

      accum_x += width;

      if (cols == num_cols - 1)
      {
        /* For the last column, ensure it fills up the width - rounding errors in scaling */
        /* for the find_width calls often make this necessary.                            */

        if (accum_x != available_w) width -= accum_x - available_w, accum_x = available_w;
      }

      /* Adjust the open coordinates to account for the scroll bars */
      /* present in the Res file. If these are not present, the     */
      /* reformatter will try to use the horizontal space a         */
      /* vertical bar normally occupies and things will get worse   */
      /* from there...                                              */

      frame_box.xmax = frame_box.xmin + width  - vw;
      frame_box.ymin = frame_box.ymax - height + hh;

1495
      windows_create_browser("", b, &frame_box, NULL, Windows_CreateBrowser_Normal);
1496 1497
      windows_set_tools(last_browser, &frame_box, 0, 0, 0, 0);

1498
      /* Make the child inherit some of the parent's characteristics */
1499

1500 1501 1502 1503 1504
      last_browser->underline_links = b->underline_links;
      last_browser->use_source_cols = b->use_source_cols;
      last_browser->show_foreground = b->show_foreground;
      last_browser->show_background = b->show_background;

1505 1506 1507 1508 1509 1510
      /* If this is the first frame for the ancestor, make it selected */

      if (last_browser->ancestor->nchildren == 1) last_browser->frame_selected = 1;

      /* Increment the position counters and loop round again */

1511
      frame_box.xmin += width + token->indent * 2; /* Scale to 2 OS units/pixel */
1512 1513
    }

1514
    frame_box.ymax -= height + token->indent * 2;
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
  }

  /* Finally, do a redraw of the parent to ensure borders are */
  /* up to date.                                              */

  coords_box_toworkarea(&s.visible_area, (WimpRedrawWindowBlock *) &s);

  e = wimp_force_redraw(b->window_handle,
                        s.visible_area.xmin,
                        s.visible_area.ymin,
                        s.visible_area.xmax,
                        s.visible_area.ymax);
  if (e) return e;

  #ifdef TRACE
    if (tl & (1u<<17)) Printf("frames_define_frameset: Successful\n");
  #endif

  return NULL;
}

/*************************************************/
/* frames_check_recursion()                      */
/*                                               */
/* Checks to see if a frameset is defining       */
/* itself recursively.                           */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of the frame  */
1544
/*             being checked;                    */
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
/*                                               */
/*             Pointer to a browser_data struct  */
/*             which represents the frame being  */
/*             checked;                          */
/*                                               */
/*             Pointer to an HStream struct that */
/*             represents the <FRAME...> tag     */
/*             which is filling in the frame     */
/*             being checked.                    */
/*                                               */
/* Returns:    1 if the definition is recursive, */
/*             else 0.                           */
/*************************************************/

static int frames_check_recursion(browser_data * parent, browser_data * child, HStream * token)
{
  while (parent)
  {
    if (browser_fetch_url(parent)   && !strcmp(browser_fetch_url(parent),   token->src)) return 1;
    if (browser_current_url(parent) && !strcmp(browser_current_url(parent), token->src)) return 1;

    parent = parent->real_parent;
  }

  return 0;
}

/*************************************************/
/* frames_define_frame()                         */
/*                                               */
/* For a given parent browser_data structure,    */
/* fills in the next unfilled frame.             */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the parent;          */
1580
/*                                               */
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
/*             Pointer to the token that is to   */
/*             define the child characteristics. */
/*                                               */
/* Assumes:    If the parent has no children,    */
/*             the routine silently fails;       */
/*             If the parent's children are all  */
/*             defined (i.e. there appear to be  */
/*             more <frame> tags than defined by */
/*             the initial <frameset> the        */
/*             routine, again, silently fails.   */
/*************************************************/

_kernel_oserror * frames_define_frame(browser_data * b, HStream * token)
{
  browser_data    * child;
  _kernel_oserror * e;

  #ifdef TRACE
    if (tl & (1u<<17)) Printf("frames_define_frame: Called with browser_data %p\n",b);
  #endif

1602 1603 1604 1605 1606
  if (b->nchildren <= b->filling_frame)
  {
    #ifdef TRACE
      if (tl & (1u<<17)) Printf("frames_define_frame: nchildren %d, filling_frame %d - exitting!",b->nchildren,b->filling_frame);
    #endif
1607

1608 1609
    return NULL;
  }
1610 1611

  #ifdef TRACE
1612
    if (tl & (1u<<17)) Printf("frames_define_frame: Have not defined all children, so proceeding\n",b);
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
  #endif

  child = (browser_data *) b->children[b->filling_frame++];

  child->frame = token;

  if (token->name && *token->name)
  {
    e = memory_set_chunk_size(child, NULL, CK_NAME, strlen(token->name) + 1);
    if (e) return e;

    strcpy(child->window_name, token->name);
  }

  /* Set scrolling details */
  {
    int scroll;

    scroll = token->type & TYPE_SCROLLING_MASK;

    if      (scroll == TYPE_SCROLLING_NO)   child->frame_hscroll = 0;
    else if (scroll == TYPE_SCROLLING_AUTO) child->frame_hscroll = 1;
    else if (scroll == TYPE_SCROLLING_YES)  child->frame_hscroll = 2;

    child->frame_vscroll = child->frame_hscroll;
  }

  /* About to try and fetch the URL defined for the frame, */
  /* but need to first check it's not recursive.           */

  if (frames_check_recursion(b, child, token))
  {
    #ifdef TRACE
      if (tl & (1u<<17)) Printf("frames_define_frame: Exitting with no fetch (recursive frameset)\n");
    #endif

    #ifdef STRICT_PARSER

      erb.errnum = Utils_Error_Custom_Message;

      StrNCpy0(erb.errmess,
               lookup_token("FramRcrs:Frames definition references itself recursively; could not proceed with the frames layout.",
                            0,0));

      show_error_ret(&erb);

    #endif

    return NULL;
  }

  #ifdef TRACE
    if (tl & (1u<<17)) Printf("frames_define_frame: Exitting through fetchpage_new()\n",b);
  #endif

1668
  return fetchpage_new(child, token->src, 1, 0);
1669 1670
}

1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
/*************************************************/
/* frames_reopen_frame()                         */
/*                                               */
/* Reopens a given frame to a given outline      */
/* size.                                         */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the frame;           */
/*                                               */
/*             Pointer to a browser_data struct  */
/*             representing the parent, or NULL  */
/*             if not known;                     */
/*                                               */
/*             Pointer to a BBox describing the  */
/*             new outline (screen coordinates)  */
/*             for the frame.                    */
/*************************************************/

static _kernel_oserror * frames_reopen_frame(browser_data * cb, browser_data * parent, BBox * frame_box)
{
  _kernel_oserror         * e = NULL;
  WimpGetWindowStateBlock   frame_state;
  IdBlock                   idb;
  WimpPollBlock             block;
  int                       title_height, hscroll_height, vscroll_width;

  if (!cb) return NULL;
  if (!parent) parent = cb->parent;
  if (!parent) parent = cb->real_parent;
  if (!parent) parent = cb->ancestor;
  if (!parent) return NULL;

  /* Get the tool sizes */

  windows_return_tool_sizes(&title_height, &hscroll_height, &vscroll_width);

  /* Get the frame's window details */

  frame_state.window_handle = cb->window_handle;

  e = wimp_get_window_state(&frame_state);
  if (e) return e;

  /* Fill in the open window request block with the new size */
  /* details, etc.                                           */

  block.open_window_request.window_handle = frame_state.window_handle;

  if (frame_state.flags & WimpWindow_VScroll) frame_box->xmax -= vscroll_width;
  if (frame_state.flags & WimpWindow_HScroll) frame_box->ymin += hscroll_height;

  block.open_window_request.visible_area = *frame_box;
  block.open_window_request.xscroll      = frame_state.xscroll;
  block.open_window_request.yscroll      = frame_state.yscroll;

  /* Sort out the window to open behind. */

  block.open_window_request.behind = find_behind(block.open_window_request.window_handle);

  /* Fill in the ID block and call the open window function */

  idb.self_id   = cb->self_id;
  idb.parent_id = parent->self_id;

  windows_open_browser(0, &block, &idb, cb);

  /* If the frame was highlighted, move the highlight too */

  if (cb == highlight_frame)
  {
    e = frames_highlight_frame(cb);
    if (e) return e;
  }

  return NULL;
}

1748 1749 1750 1751
/*************************************************/
/* frames_resize_frameset()                      */
/*                                               */
/* For a given parent browser_data structure,    */
1752 1753 1754 1755 1756
/* resize a frameset within its window. Compare  */
/* with frames_resize_frame(), which also        */
/* resizes the parent (which is useful when the  */
/* natural progression of a calling function     */
/* would not include this itself).               */
1757 1758 1759 1760
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the parent;          */
/*                                               */
1761 1762 1763 1764
/*             Pointer to a BBox describing the  */
/*             required new window outline (in   */
/*             screen coordinates) of the parent */
/*             frame.                            */
1765 1766
/*************************************************/

1767
_kernel_oserror * frames_resize_frameset(browser_data * b, BBox * new_outline)
1768 1769 1770 1771 1772 1773 1774 1775
{
  _kernel_oserror         * e;
  WimpGetWindowStateBlock   s;
  BBox                      frame_box;
  HStream                 * token;
  int                       rows, cols;
  int                       num_rows, num_cols;
  int                       width, height;
1776
  int                       htop, hbot;
1777 1778 1779 1780 1781
  int                       available_w, available_h;
  int                       start_x, start_y, accum_x, accum_y;
  int                       th, hh, vw;
  int                       child;

1782 1783 1784 1785
  #ifdef TRACE
    if (tl & (1u<<17)) Printf("frames_resize_frameset: Called with browser_data %p\n",b);
  #endif

1786 1787 1788 1789
  /* Nothing to resize if there are no children */

  if (!b->nchildren) return NULL;

1790
  /* Get the frame window details and tool sizes */
1791

1792
  s.window_handle = b->window_handle;
1793 1794 1795
  e = wimp_get_window_state(&s);
  if (e) return e;

1796
  s.visible_area = *new_outline;
1797 1798 1799 1800 1801

  windows_return_tool_sizes(&th, &hh, &vw);

  /* Work out the amount of visible area that toolbars are consuming */

1802
  if (!controls.swap_bars)
1803 1804 1805 1806 1807 1808 1809 1810 1811
  {
    htop = toolbars_url_height(b) + toolbars_button_height(b); /* Physically, the button bar and URL bar are just one real toolbar */
    hbot = toolbars_status_height(b);
  }
  else
  {
    htop = toolbars_status_height(b);
    hbot = toolbars_url_height(b) + toolbars_button_height(b);
  }
1812

1813 1814
  if (htop) htop += wimpt_dy(); /* Account for lower border of upper toolbar, if present */
  if (hbot) hbot += wimpt_dy(); /* Account for upper border of lower toolbar, if present */
1815 1816 1817 1818 1819 1820

  /* Work out the available frame space width and height */

  available_w = s.visible_area.xmax - s.visible_area.xmin;

  available_h = s.visible_area.ymax - s.visible_area.ymin
1821 1822
                - htop
                - hbot;
1823 1824 1825 1826

  /* Start resizing frames from the top left hand side of the visible area */

  start_x = s.visible_area.xmin;
1827
  start_y = s.visible_area.ymax - htop;
1828 1829 1830 1831 1832 1833 1834

  /* Work out the number of rows / columns */

  token = b->frameset;

  num_rows = token->rows;
  num_cols = token->cols;
1835 1836

  if (!num_rows) num_rows = 1;
1837 1838 1839 1840
  if (!num_cols) num_cols = 1;

  /* Account for frame spacing */

1841 1842
  available_w -= token->indent * 2 * (num_cols - 1); /* Scale to 2 OS units/pixel */
  available_h -= token->indent * 2 * (num_rows - 1);
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928

  #ifdef TRACE
    if (tl & (1u<<17))
    {
      Printf("frames_resize_frameset: avail_w %d\n"
             "                        avail_h %d\n"
             "                        start_x %d\n"
             "                        start_y %d\n"
             "                        rows    %d\n"
             "                        cols    %d\n\n",
             available_w,
             available_h,
             start_x,
             start_y,
             num_rows,
             num_cols);
      {
        int i;

        Printf("frames_resize_frameset: Size enumeration:\n\n");

        for (i = 0; i < num_rows; i++)
        {
          if (token->name) Printf("Row %d = %p\n",i,((int *) token->name)[i]);
          else             Printf("Row %d = undefined\n",i);
        }

        Printf("\n");

        for (i = 0; i < num_cols; i++)
        {
          if (token->value) Printf("Col %d = %p\n",i,((int *) token->value)[i]);
          else              Printf("Col %d = undefined\n",i);
        }

        Printf("\nframes_resize_frameset: Proceeding\n");
      }
    }
  #endif

  /* Get all the sizes */

  frames_find_widths (b, available_w);
  frames_find_heights(b, available_h);

  /* Loop round resizing each child */

  frame_box.ymax = start_y;
  accum_y        = 0;
  child          = 0;

  for (rows = 0; rows < num_rows; rows ++)
  {
    frame_box.xmin = start_x;
    accum_x        = 0;
    height         = b->frame_heights[rows];

    accum_y += height;

    if (rows == num_rows - 1)
    {
      /* For the last row, ensure it fills up the height - rounding errors in scaling */
      /* for the find_height calls often make this necessary.                         */

      if (accum_y != available_h) height -= accum_y - available_h, accum_y = available_h;
    }

    for (cols = 0; cols < num_cols; cols ++)
    {
      width = b->frame_widths[cols];

      accum_x += width;

      if (cols == num_cols - 1)
      {
        /* For the last column, ensure it fills up the width - rounding errors in scaling */
        /* for the find_width calls often make this necessary.                            */

        if (accum_x != available_w) width -= accum_x - available_w, accum_x = available_w;
      }

      frame_box.xmax = frame_box.xmin + width;
      frame_box.ymin = frame_box.ymax - height;

      /* Handle reopening the frame */

1929 1930
      e = frames_reopen_frame(b->children[child], b, &frame_box);
      if (e) return e;
1931 1932 1933

      /* Prepare for the next frame */

1934
      frame_box.xmin += width + token->indent * 2; /* Scale to 2 OS units/pixel */
1935 1936 1937
      child++;
    }

1938
    frame_box.ymax -= height + token->indent * 2;
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
  }

  /* Now do a redraw of the parent, to ensure that borders are up to date */

  coords_box_toworkarea(&s.visible_area, (WimpRedrawWindowBlock *) &s);

  e = wimp_force_redraw(b->window_handle,
                        s.visible_area.xmin,
                        s.visible_area.ymin,
                        s.visible_area.xmax,
                        s.visible_area.ymax);
  if (e) return e;

  #ifdef TRACE
    if (tl & (1u<<17)) Printf("frames_resize_frameset: Successful\n");
  #endif

  return NULL;
}

1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126
/*************************************************/
/* frames_resize_frame()                         */
/*                                               */
/* Resizes a given frame and its contents (e.g.  */
/* any nested frames). Compare with              */
/* frames_resize_frameset(), which doesn't       */
/* resize the parent - just the contents (which  */
/* is useful when the natural progression of a   */
/* calling function would resize the parent      */
/* anyway).                                      */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the frame;           */
/*                                               */
/*             Pointer to a BBox describing the  */
/*             required new frame outline (in    */
/*             screen coordinates).              */
/*************************************************/

_kernel_oserror * frames_resize_frame(browser_data * b, BBox * new_outline)
{
  _kernel_oserror * e;

  /* Update any child frames first, if needed */

  if (b->nchildren)
  {
    e = frames_resize_frameset(b, new_outline);
    if (e) return e;
  }

  /* Now resize the given frame */

  return frames_reopen_frame(b, NULL, new_outline);
}

/*************************************************/
/* frames_lock_frameset()                        */
/*                                               */
/* Examines the window sizes of a collection of  */
/* frames in a frameset, and rewrites the size   */
/* descriptions in the frameset representing     */
/* HStream structures. This, then, would mean    */
/* that for example, subsequent resizes of the   */
/* ancestor window would maintain that new       */
/* relative layout, rather than 'snapping back'  */
/* to values specified in the HStream structure. */
/*                                               */
/* Where possible, the nature of the value is    */
/* maintained - e.g. a pixel value will stay     */
/* as such, as will a percentage value (they     */
/* don't all become pixel sizes). At present,    */
/* all units are preserved though note that      */
/* significant rounding errors can occur with    */
/* percentage values.                            */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the parent for the   */
/*             frameset to lock.                 */
/*************************************************/

void frames_lock_frameset(browser_data * b)
{
  browser_data              * child;
  WimpGetWindowOutlineBlock   co;
  int                         units;
  int                         av_w, av_h;
  int                         wid,  hei;
  int                         col,  cols;
  int                         row,  rows;
  int                         tw,   th;

  if (!b->nchildren) return;

  rows = b->frameset->rows;
  cols = b->frameset->cols;

  /* Get the parent width/height to find available space. */

  co.window_handle = b->window_handle;
  if (wimp_get_window_outline(&co)) return;

  av_w = co.outline.xmax - co.outline.xmin;
  av_h = co.outline.ymax - co.outline.ymin;

  /* Now go through the columns. */

  for (col = 0; col < cols; col++)
  {
    tw    = ((int *) (b->frameset->value))[col];
    units = tw & ~ROWCOL_VALUE;

    /* Find the child and get information on it */

    child            = b->children[col];
    co.window_handle = child->window_handle;

    if (!wimp_get_window_outline(&co))
    {
      wid = co.outline.xmax - co.outline.xmin;

      /* Work out what the widths should be in the */
      /* given units.                              */

      if (units & ROWCOL_PERCENT)
      {
        tw = (100 * wid) / av_w;
      }
      else if (units & ROWCOL_STAR)
      {
        /* This works as 2*,* is the same as 422*,211*; */
        /* it's just fractions. So we can maintain the  */
        /* units but keep full accuracy here.           */

        tw = wid;
      }
      else
      {
        tw = wid / wimpt_dx();
      }

      /* Put the units field back in */

      tw |= units;

      /* Write the value to the token */

      ((int *) (b->frameset->value))[col] = tw;
    }
  }

  /* Now do rows - code is directly analogous to the  */
  /* columns stuff above, hence the lack of comments. */

  for (row = 0; row < rows; row++)
  {
    th    = ((int *) (b->frameset->name))[row];
    units = th & ~ROWCOL_VALUE;

    child            = b->children[row * (cols ? cols : 1)];
    co.window_handle = child->window_handle;

    if (!wimp_get_window_outline(&co))
    {
      hei = co.outline.ymax - co.outline.ymin;

      if (units & ROWCOL_PERCENT)
      {
        th = (100 * hei) / av_h;
      }
      else if (units & ROWCOL_STAR)
      {
        th = hei;
      }
      else
      {
        th = hei / wimpt_dy();
      }

      th |= units;

      ((int *) (b->frameset->name))[row] = th;
    }
  }

  /* ...and that's it. */
}

2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
/*************************************************/
/* frames_fetching()                             */
/*                                               */
/* Equivalent to fetch_fetching() in Fetch.c,    */
/* but returns 1 if any of the frames in a       */
/* frameset are fetching, else 0.                */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the parent of any frames */
/*             to check (so for an entire        */
/*             frameset, pass the ancestor in).  */
/*                                               */
/* Returns:    1 if any of the frames are        */
/*             fetching, else 0.                 */
/*************************************************/

int frames_fetching(browser_data * b)
{
  int i;

  /* Recurse for child frames */

  if (b->nchildren)
  {
    for (i = 0; i < b->nchildren; i++)
    {
      if (frames_fetching(b->children[i])) return 1;
    }
  }

  if (fetch_fetching(b)) return 1;

  return 0;
}

2162 2163 2164 2165 2166 2167 2168 2169
/*************************************************/
/* frames_abort_fetching()                       */
/*                                               */
/* Stops any page or image fetching, and stops   */
/* any current reformatting, in the given frame  */
/* and all of its children (if it has any). For  */
/* ancestor browser_data structures, if the      */
/* relevant Choices and Messages file options    */
2170
/* have been set, WebServe will be instructed to */
2171 2172 2173 2174
/* stop all fetching and ditch any objects that  */
/* are half fetched.                             */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
2175 2176 2177 2178
/*             relevant to the fetches to abort; */
/*                                               */
/*             1 to also stop image fetching,    */
/*             else 0 to let image fetches       */
2179 2180 2181 2182 2183
/*             continue;                         */
/*                                               */
/*             1 to also stop file spooling      */
/*             (i.e. the save_link flag is set), */
/*             else 0 to allow it to continue.   */
2184 2185
/*************************************************/

2186
void frames_abort_fetching(browser_data * b, int stop_images, int stop_spools)
2187 2188 2189 2190 2191 2192 2193 2194 2195
{
  int i;

  /* Recurse for child frames */

  if (b->nchildren)
  {
    for (i = 0; i < b->nchildren; i++)
    {
2196
      frames_abort_fetching(b->children[i], stop_images, stop_spools);
2197 2198 2199
    }
  }

2200 2201 2202 2203
  /* May not want to stop file saves */

  if (!stop_spools && b->save_link) return;

2204 2205 2206 2207 2208
  /* Stop the main fetch, stop any reformatting, and */
  /* stop image fetching.                            */

  fetch_cancel(b);
  reformat_stop(b);
2209 2210

  if (stop_images) image_abort_fetches(b);
2211

2212 2213 2214 2215 2216 2217
  /* If this is the ancestor, tell WebServe to stop all activity */
  /* as well (if we're running full screen). Can't do this if    */
  /* targetting a frame as we may still want the other frames    */
  /* to keep fetching (e.g. the images in a navigation panel     */
  /* may still be coming in whilst that panel is used to open a  */
  /* link in some other frame).                                  */
2218

2219
  if (controls.stop_proxy && choices.full_screen && !b->ancestor) utils_stop_proxy();
2220 2221 2222 2223 2224 2225
}

/*************************************************/
/* frames_collapse_child_tree()                  */
/*                                               */
/* Used during traversal of the child tree to    */
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237
/* close down unwanted frames. See the parameter */
/* list for the three browser_data structs       */
/* required.                                     */
/*                                               */
/* If the third browser has children the         */
/* function will call itself with the given base */
/* browser until the browser to close has no     */
/* children. It then closes it (unless it's the  */
/* same as the base browser, in which case the   */
/* final exit condition is reached) and          */
/* decrements the parent's child counter.        */
/* Recursion then collapses a level.             */
2238 2239 2240 2241
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             for the base browser - that is,   */
/*             the one that won't be closed;     */
2242
/*                                               */
2243 2244 2245
/*             Pointer to a browser_data struct  */
/*             that has the entry in its array   */
/*             of children for the browser given */
2246 2247 2248
/*             in the next parameter, i.e. the   */
/*             parent browser;                   */
/*                                               */
2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316
/*             Pointer to a browser_data struct  */
/*             that may have children, which     */
/*             is one of those that will be      */
/*             closed (unless it's the same as   */
/*             the base structure, which will    */
/*             tend to be the case on first      */
/*             call of the function).            */
/*************************************************/

static void frames_collapse_child_tree(browser_data * base, browser_data * real_parent, browser_data * close)
{
  if (!base || !close) return;

  while (close->nchildren) frames_collapse_child_tree(base, close, (browser_data *) close->children[close->nchildren - 1]);

  /* At this stage, might have called ourselves many times or */
  /* not at all. In any event, we've reached a browser with   */
  /* no children - it's at the end of the tree. So if this    */
  /* isn't the base browser - at which point the tree must be */
  /* closed down - close this browser.                        */

  if (close != base)
  {
    windows_close_browser(close);

    if (real_parent)
    {
      real_parent->nchildren --;

      if (!real_parent->nchildren) memory_set_chunk_size(real_parent, NULL, CK_CHIL, 0);
    }
  }

  close->frameset = NULL;

  return;
}

/*************************************************/
/* frames_collapse_set()                         */
/*                                               */
/* Given a parent browser, close all children.   */
/*                                               */
/* Parameters: Pointer to parent browser_data    */
/*             struct.                           */
/*************************************************/

void frames_collapse_set(browser_data * b)
{
  _swix(Hourglass_Start, _IN(0), 10);

  frames_collapse_child_tree(b, NULL, b);

  _swix(Hourglass_Off, 0);
}

/*************************************************/
/* frames_find_named()                           */
/*                                               */
/* If a given name is found attached to the      */
/* given window or one of its children, return   */
/* the browser_data struct for that window (else */
/* NULL). The check is case insensitive.         */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             representing the parent (it and   */
/*             all its children are searched for */
/*             the name);                        */
2317
/*                                               */
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332
/*             Pointer to the name.              */
/*                                               */
/* Returns:    Pointer to the browser_data       */
/*             struct of that name, or NULL if   */
/*             not found.                        */
/*************************************************/

browser_data * frames_find_named(browser_data * parent, char * name)
{
  int child = 0;

  if (!parent || !name || (name && !*name)) return NULL;

  /* If the parent matches the given name, return it */

2333
  if (parent->window_name && *parent->window_name && !utils_strcasecmp(parent->window_name, name)) return parent;
2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354

  /* Otherwise, go through the list of children */

  if (parent->nchildren)
  {
    for (child = 0; child < parent->nchildren; child ++)
    {
      browser_data * found;

      found = frames_find_named((browser_data *) parent->children[child], name);

      if (found) return found;
    }
  }

  return NULL;
}

/*************************************************/
/* frames_find_target()                          */
/*                                               */
2355 2356
/* Given a base browser and a frame target name, */
/* returns the browser to which the target       */
2357 2358 2359 2360 2361
/* refers.                                       */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             that the tag lies in;             */
/*                                               */
2362
/*             Pointer to the target string.     */
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373
/*                                               */
/* Returns:    Pointer to the targetted browser, */
/*             or NULL to create a new window.   */
/*             Note that if a new window is not  */
/*             to be opened, NULL will *never*   */
/*             be passed, even if the target     */
/*             field of the given token is (say) */
/*             NULL itself. I.e., the caller     */
/*             doesn't need to worry about such  */
/*             cases.                            */
/*                                               */
2374 2375 2376 2377 2378 2379
/* Assumes:    In the case of named target       */
/*             windows where the name cannot be  */
/*             found, NULL is returned - the     */
/*             caller is expected to then open a */
/*             new window named after the target */
/*             given to this function.           */
2380 2381
/*************************************************/

2382
browser_data * frames_find_target(browser_data * b, const char * target)
2383 2384 2385 2386
{
  browser_data * ancestor;

  #ifdef TRACE
2387
    if (tl & (1u<<17)) Printf("frames_find_target: Called for %p, target %p\n",b,target);
2388 2389 2390 2391 2392
  #endif

  /* Only proceed if there's a browser, a token, and that */
  /* token has a target which isn't a null string.        */

2393
  if (b && target && *target)
2394 2395
  {
    #ifdef TRACE
2396
      if (tl & (1u<<17)) Printf("frames_find_target: Target = '%s'\n",target);
2397 2398
    #endif

2399
    if (!utils_strcasecmp(target, "_top")) /* Open in the top level window */
2400 2401 2402 2403 2404 2405 2406
    {
      ancestor = b->ancestor;
      if (!ancestor) ancestor = b->real_parent;
      if (!ancestor) ancestor = b;

      return ancestor;
    }
2407
    else if (!utils_strcasecmp(target, "_self")) /* Open within the frame */
2408 2409 2410
    {
      return b;
    }
2411
    else if (!utils_strcasecmp(target, "_blank")) /* Open in a new, blank window */
2412 2413 2414
    {
      return NULL;
    }
2415
    else if (!utils_strcasecmp(target, "_parent")) /* Open in the frame's parent */
2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440
    {
      browser_data * parent = b->real_parent;

      /* _parent is taken by most page authors to mean the complete parent document, */
      /* not the parent frame. That is, if one document defines within itself a      */
      /* nested frameset, then _parent does not refer to any of those nested frames; */
      /* it refers to the frame holding the orignal document.                        */
      /*                                                                             */
      /* Consequently, we need to follow real_parent pointers until we reach a child */
      /* frame which has a non-NULL display URL field, i.e. a frame which has frames */
      /* but has got them by fetching a document.                                    */

      while (parent->real_parent && !parent->urlddata) parent = parent->real_parent;

      if (!parent) parent = b->parent;
      if (!parent) parent = b->ancestor;
      if (!parent) parent = b;

      return parent;
    }
    else
    {
      /* According to the frame spec at the time of writing, */
      /* names must start with an alphanumeric character.    */

2441
      if (isalnum(*target)) /* Named window */
2442 2443 2444
      {
        browser_data * named;

2445
        ancestor = utils_ancestor(b);
2446

2447
        named = frames_find_named(ancestor, (char *) target);
2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460

        /* If the name isn't found, try all windows, rather */
        /* than just children of the specified one.         */

        if (!named)
        {
          browser_data * found = NULL;

          named = last_browser;

          while (named && !found)
          {
            if (
2461 2462
                 named->window_name                               &&
                 *named->window_name                              &&
2463
                 !utils_strcasecmp(named->window_name, target)
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484
               )
               found = named;

            else named = named->previous;
          }

          /* If the name still isn't there, supposed to open a */
          /* new window with this name. Flag this by returning */
          /* NULL.                                             */

          if (!found) return NULL;
          else        return found;
        }

        return named;
      }
    }
  }

  /* For null/unspecified targets, use the same frame */

2485
  if (!target || !*target) return b;
2486

2487 2488 2489
  /* If all else fails, we don't recognise the name or it is */
  /* illegal. Safest to open in a new window, leaving the    */
  /* original document intact.                               */
2490

2491
  return NULL;
2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519
}

/*************************************************/
/* frames_find_another_frame()                   */
/*                                               */
/* Given a browser_data structure which is a     */
/* child frame, finds the next structure in the  */
/* frame layout - intended for keyboard          */
/* navigation through frames.                    */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             which is the current child frame; */
/*                                               */
/*             Direction - 0 to find the logical */
/*             next frame in the set, 1 to find  */
/*             the logical previous.             */
/*                                               */
/* Returns:    Pointer to a browser_data struct  */
/*             which is the next child frame.    */
/*************************************************/

browser_data * frames_find_another_frame(browser_data * current, int dir)
{
  browser_data * ancestor;
  int            found = 0;

  if (!current) return NULL;

2520
  ancestor = utils_ancestor(current);
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674

  /* Finding the logical next frame */

  if (!dir)
  {
    browser_data * next;

    next = frames_find_next_frame(ancestor, current, &found);

    /* If 'next' is NULL, it could be because the current frame is  */
    /* the last one in the group. So try searching again from the   */
    /* ancestor (the routine will have updated 'found' so that it   */
    /* knows not to wait until it's got the current frame anymore). */

    if (!next) return frames_find_next_frame(ancestor, current, &found);

    return next;
  }
  else
  {
    browser_data * previous;

    previous = frames_find_previous_frame(ancestor, current, &found);

    if (!previous) return frames_find_previous_frame(ancestor, current, &found);

    return previous;
  }

  return NULL;
}

/*************************************************/
/* frames_find_next_frame()                      */
/*                                               */
/* Recursive back-end to                         */
/* frames_find_another_frame, for finding the    */
/* logical next frame.                           */
/*                                               */
/* Parameters: Pointer to the browser_data       */
/*             struct to compare with the        */
/*             current one;                      */
/*                                               */
/*             Pointer to the browser_data       */
/*             struct which is the current one;  */
/*                                               */
/*             Pointer to an int which should    */
/*             contain 0 on entry and will be    */
/*             written to by the function.       */
/*                                               */
/* Returns:    As frames_find_next_frame.        */
/*************************************************/

static browser_data * frames_find_next_frame(browser_data * check, browser_data * current, int * found)
{
  browser_data * b = NULL;
  int            c = 0;

  while (!b && c < check->nchildren)
  {
    if (check->children[c]->nchildren)
    {
      /* Recursive call, if the child has children */

      b = frames_find_next_frame(check->children[c], current, found);
    }
    else
    {
      /* 'found' is set to 1 if the 'current' browser_data struct */
      /* has been found. If so, we can use the next struct that   */
      /* has no children. If not, and the struct being examined   */
      /* is the same as 'current', set 'found'.                   */

      if (*found)
      {
        if (check->children[c] != current) return check->children[c];
      }
      else
      {
        if (check->children[c] == current) *found = 1;
      }
    }

    c++;
  }

  return b;
}

/*************************************************/
/* frames_find_previous_frame()                  */
/*                                               */
/* Recursive back-end to                         */
/* frames_find_another_frame, for finding the    */
/* logical previous frame.                       */
/*                                               */
/* Parameters: Pointer to the browser_data       */
/*             struct to compare with the        */
/*             current one;                      */
/*                                               */
/*             Pointer to the browser_data       */
/*             struct which is the current one;  */
/*                                               */
/*             Pointer to an int which should    */
/*             contain 0 on entry and will be    */
/*             written to by the function.       */
/*                                               */
/* Returns:    As frames_find_next_frame.        */
/*************************************************/

static browser_data * frames_find_previous_frame(browser_data * check, browser_data * current, int * found)
{
  browser_data * b = NULL;
  int            c = check->nchildren - 1;

  while (!b && c >= 0)
  {
    if (check->children[c]->nchildren)
    {
      /* Recursive call, if the child has children */

      b = frames_find_previous_frame(check->children[c], current, found);
    }
    else
    {
      /* 'found' is set to 1 if the 'current' browser_data struct */
      /* has been found. If so, we can use the next struct that   */
      /* has no children. If not, and the struct being examined   */
      /* is the same as 'current', set 'found'.                   */

      if (*found)
      {
        if (check->children[c] != current) return check->children[c];
      }
      else
      {
        if (check->children[c] == current) *found = 1;
      }
    }

    c--;
  }

  return b;
}

/*************************************************/
/* frames_highlight_frame()                      */
/*                                               */
/* Highlights a frame by showing a border around */
/* it, made of 'Highlight' borderless window     */
/* objects in the Res file. The highlight is     */
/* removed by a NULL poll timer.                 */
/*                                               */
2675 2676
/* Won't highlight ancestor windows, and only    */
/* highlights if keyboard control is enabled.    */
2677 2678 2679 2680 2681 2682 2683 2684
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the frame to be       */
/*             highlighted.                      */
/*************************************************/

_kernel_oserror * frames_highlight_frame(browser_data * b)
{
2685
  browser_data            * ancestor;
2686 2687 2688 2689 2690
  WimpGetWindowStateBlock   s;
  WindowShowObjectBlock     show;
  _kernel_oserror         * e;
  BBox                      top, bottom, left, right;

2691 2692
  /* Don't do anything if not using keyboard control */

2693
  if (!choices.keyboard_ctrl) return NULL;
2694

2695 2696 2697 2698
  /* Don't do anything if an ancestor */

  if (!b->ancestor) return NULL;

2699 2700
  /* Otherwise, proceed */

2701
  ancestor = utils_ancestor(b);
2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725

  s.window_handle = b->window_handle;

  e = wimp_get_window_state(&s);
  if (e) return e;

  /* If not already present, create the highlight window objects */

  if (!highlight_top)
  {
    e = toolbox_create_object(0, "Highlight", &highlight_top);
    if (e) return e;

    e = toolbox_create_object(0, "Highlight", &highlight_bottom);
    if (e) return e;

    e = toolbox_create_object(0, "Highlight", &highlight_left);
    if (e) return e;

    e = toolbox_create_object(0, "Highlight", &highlight_right);
    if (e) return e;

    /* Work out how long to leave the highlight visible */

2726
    highlight_for = atoi(lookup_control("ShowFHighFor:30",0,0));
2727 2728 2729 2730 2731 2732

    if (highlight_for < 5)    highlight_for = 5;
    if (highlight_for > 1000) highlight_for = 3000;

    /* Register a null claimant to get rid of the objects shortly */

2733
    register_null_claimant(Wimp_ENull, (WimpEventHandler *) frames_remove_highlight_timer, b);
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747
  }

  /* Reset the highlight removal timer */

  e = _swix(OS_ReadMonotonicTime,
            _OUT(0),

            &highlight_timer);

  if (e) return e;

  /* Adjust the visible area coordinates for toolbars */

  {
2748
    int htop, hbot;
2749

2750
    if (!controls.swap_bars)
2751 2752 2753 2754 2755 2756 2757 2758 2759
    {
      htop = toolbars_url_height(b) + toolbars_button_height(b); /* Physically, the button bar and URL bar are just one real toolbar */
      hbot = toolbars_status_height(b);
    }
    else
    {
      htop = toolbars_status_height(b);
      hbot = toolbars_url_height(b) + toolbars_button_height(b);
    }
2760

2761 2762
    if (htop) htop += wimpt_dy();
    if (hbot) hbot += wimpt_dy();
2763

2764 2765
    s.visible_area.ymax -= htop;
    s.visible_area.ymin += hbot;
2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789
  }

  /* Work out the visible areas that the highlight windows should take */

  top.xmin    = s.visible_area.xmin + 2;  /**************************************/
  top.ymin    = s.visible_area.ymax - 6;  /* If a lower case letter shows where */
  top.xmax    = s.visible_area.xmax - 2;  /* the appropriate box covers pixels, */
  top.ymax    = s.visible_area.ymax - 2;  /* and the upper case letters show    */
                                          /* the actual pixels referenced by    */
  bottom.xmin = s.visible_area.xmin + 6;  /* (xmin, ymin) and (xmax, ymax),     */
  bottom.ymin = s.visible_area.ymin + 2;  /* then we are calculating:           */
  bottom.xmax = s.visible_area.xmax - 2;  /*                         S          */
  bottom.ymax = s.visible_area.ymin + 6;  /*           ssssssssssssss           */
                                          /*           s         T Rs           */
  left.xmin   = s.visible_area.xmin + 2;  /*           s ttttttttrr s           */
  left.ymin   = s.visible_area.ymin + 2;  /*           s TtLtttttrr s           */
  left.xmax   = s.visible_area.xmin + 6;  /*           s ll      RrBs           */
  left.ymax   = s.visible_area.ymax - 6;  /*           s llbbbbbbbb s           */
                                          /*           s LlBbbbbbbb s           */
  right.xmin  = s.visible_area.xmax - 6;  /*           s            s           */
  right.ymin  = s.visible_area.ymin + 6;  /*           Ssssssssssssss           */
  right.xmax  = s.visible_area.xmax - 2;  /*                                    */
  right.ymax  = s.visible_area.ymax - 2;  /**************************************/

2790
  /* Show the objects */
2791 2792 2793 2794 2795 2796 2797 2798

  show.xscroll              = 0;
  show.yscroll              = 0;
  show.behind               = -1;
  show.visible_area         = top;
  show.parent_window_handle = ancestor->window_handle;
  show.alignment_flags      = 0;

2799

2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816
  e = toolbox_show_object(Toolbox_ShowObject_AsSubWindow, highlight_top,    Toolbox_ShowObject_FullSpec, &show, ancestor->self_id, -1);
  if (e) return e;

  /* The show call above can modify the contents of the 'show' */
  /* block passed to it, so need to fill in the values again   */
  /* for each call.                                            */

  show.xscroll              = 0;
  show.yscroll              = 0;
  show.behind               = -1;
  show.visible_area         = bottom;
  show.parent_window_handle = ancestor->window_handle;
  show.alignment_flags      = 0;

  e = toolbox_show_object(Toolbox_ShowObject_AsSubWindow, highlight_bottom, Toolbox_ShowObject_FullSpec, &show, ancestor->self_id, -1);
  if (e) return e;

2817 2818
  /* Show them */

2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838
  show.xscroll              = 0;
  show.yscroll              = 0;
  show.behind               = -1;
  show.visible_area         = left;
  show.parent_window_handle = ancestor->window_handle;
  show.alignment_flags      = 0;

  e = toolbox_show_object(Toolbox_ShowObject_AsSubWindow, highlight_left,   Toolbox_ShowObject_FullSpec, &show, ancestor->self_id, -1);
  if (e) return e;

  show.xscroll              = 0;
  show.yscroll              = 0;
  show.behind               = -1;
  show.visible_area         = right;
  show.parent_window_handle = ancestor->window_handle;
  show.alignment_flags      = 0;

  e = toolbox_show_object(Toolbox_ShowObject_AsSubWindow, highlight_right,  Toolbox_ShowObject_FullSpec, &show, ancestor->self_id, -1);
  if (e) return e;

2839 2840 2841 2842 2843 2844
  /* Remember the highlighted frame, for functions other than */
  /* the null handler that removes the highlight (which gets  */
  /* passed the value directly).                              */

  highlight_frame = b;

2845 2846 2847 2848 2849 2850
  /* Finished */

  return NULL;
}

/*************************************************/
2851
/* frames_remove_highlight_timer()               */
2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863
/*                                               */
/* A NULL event handler which times how long the */
/* frame highlight objects have been visible     */
/* and removes them after a time defined by the  */
/* Choices file 'ShowFHighFor' entry.            */
/*                                               */
/* Registered by frames_highlight_frame.         */
/*                                               */
/* Parameters as standard for a Wimp event       */
/* handler.                                      */
/*************************************************/

2864
static int frames_remove_highlight_timer(int eventcode, WimpPollBlock * b, IdBlock * idb, browser_data * handle)
2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886
{
  int time;

  if (_swix(OS_ReadMonotonicTime,
            _OUT(0),

            &time)) return 0;

  if (time - highlight_timer > highlight_for)
  {
    /* Delete the objects (so removing the highlight) */

    if (highlight_top)    toolbox_delete_object(0, highlight_top);
    if (highlight_bottom) toolbox_delete_object(0, highlight_bottom);
    if (highlight_left)   toolbox_delete_object(0, highlight_left);
    if (highlight_right)  toolbox_delete_object(0, highlight_right);

    /* Reset the Object IDs, so that the highlight routine knows it needs */
    /* to recreate the objects and reinstall this handler                 */

    highlight_top = highlight_bottom = highlight_left = highlight_right = 0;

2887 2888 2889 2890
    /* Clear the internal record of the highlighted frame */

    highlight_frame = NULL;

2891 2892
    /* Remove the handler */

2893
    deregister_null_claimant(Wimp_ENull, (WimpEventHandler *) frames_remove_highlight_timer, handle);
2894 2895 2896 2897 2898 2899
  }

  return 0;
}

/*************************************************/
2900 2901 2902
/* frames_remove_highlight()                     */
/*                                               */
/* Removes the highlight objects from around a   */
2903 2904
/* frame, regardless of which frame is           */
/* highlighted.                                  */
2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949
/*************************************************/

_kernel_oserror * frames_remove_highlight(void)
{
  _kernel_oserror * e;

  /* Delete the objects (so removing the highlight) */

  if (highlight_top)
  {
    e = toolbox_delete_object(0, highlight_top);
    if (e) return e;
  }

  if (highlight_bottom)
  {
    e = toolbox_delete_object(0, highlight_bottom);
    if (e) return e;
  }

  if (highlight_left)
  {
    e = toolbox_delete_object(0, highlight_left);
    if (e) return e;
  }

  if (highlight_right)
  {
    e = toolbox_delete_object(0, highlight_right);
    if (e) return e;
  }

  /* Reset the Object IDs, so that the highlight routine knows it needs */
  /* to recreate the objects and reinstall this handler                 */

  highlight_top = highlight_bottom = highlight_left = highlight_right = 0;

  /* Clear the internal record of the highlighted frame */

  highlight_frame = NULL;

  return NULL;
}

/*************************************************/
2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964
/* frames_remove_highlight_if_present()          */
/*                                               */
/* Removes the highlight objects from around a   */
/* given frame, if that frame is highlighted.    */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the highlight.        */
/*************************************************/

_kernel_oserror * frames_remove_highlight_if_present(browser_data * b)
{
  if (b && b == highlight_frame) return frames_remove_highlight();

  return NULL;
}