Choices 44.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 50 51 52 53 54 55 56 57 58
/* 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   : Choices.c                              */
/*                                                 */
/* Purpose: Functions relating to the choices      */
/*          dialogue box and associated sub        */
/*          windows                                */
/*                                                 */
/* Author : D.T.A.Brown                            */
/*                                                 */
/* History: 23-Sep-97: Created.                    */
/***************************************************/

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

#include "swis.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 "menu.h"
#include "ColourDbox.h"

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

#include "Encoding.h"
#include "FetchPage.h"
#include "History.h"
#include "Menus.h"
#include "NestWimp.h"
#include "Save.h"
#include "URLutils.h"
#include "Windows.h"

#include "Choices.h"

59
/* Locals */
60

61 62 63
static int      * subwindows        = NULL;
static ObjectId   current_subwindow = CDSubNone;
static ObjectId   colourdbox_id     = 0;
64

65 66 67 68 69 70 71
static int        save_ticked = -1;
static int        disp_ticked = -1;

global_choices  * new_choices       = NULL;
ObjectId          choices_windowid  = 0;

/* Static function prototypes */
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

static _kernel_oserror * choices_show_subwindow          (ObjectId choices_window, int subwindow);
static _kernel_oserror * choices_set_contents            (void);
static _kernel_oserror * choices_get_contents            (void);

static int               choices_radio_click_handler     (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_set_button_handler      (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_cancel_button_handler   (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_save_button_handler     (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_encoding_button_handler (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_colour_button_handler   (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_colour_closed_handler   (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_colour_selected_handler (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_display_m_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_save_m_button_handler   (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_display_m_click_handler (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_save_m_click_handler    (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);

static _kernel_oserror * choices_colour_set_component    (ObjectId window, ComponentId component, int colour);
static _kernel_oserror * choices_set_save_field          (ObjectId obj, ComponentId comp, int state);
static _kernel_oserror * choices_set_display_field       (ObjectId obj, ComponentId comp, int state);

/*************************************************/
/* choices_show_subwindow()                      */
/*                                               */
/* Shows a choice subwindow in the main choices  */
/* window.                                      */
/*                                               */
/* Parameters: the ObjectId of the main choices  */
/*             window                            */
/*                                               */
/*             the number of the subwindow to    */
/*             show.  Defined in choices.h       */
/*             Use CDSubNone to remove           */
/*             the current subwindow.            */
/*                                               */
/* Returns:    pointer to _kernel_oserror        */
/*************************************************/

111
static _kernel_oserror * choices_show_subwindow(ObjectId choices_window, int subwindow)
112
{
113 114 115 116 117 118
  _kernel_oserror           * e;
  WindowShowObjectBlock       show_block;
  WimpGetWindowStateBlock     state;
  WimpGetWindowOutlineBlock   outline;
  int                         window_handle;
  int                         vwidth, hheight;
119 120 121 122

  if (current_subwindow != CDSubNone)
  {
    /* remove the current subwindow */
123

124
    RetError(toolbox_hide_object(0, subwindows[current_subwindow]));
125 126
  }

127
  if (subwindow == CDSubNone || !(subwindows[subwindow]) || subwindow == current_subwindow)
128 129 130 131 132 133 134 135 136 137 138 139 140
  {
    /* Have not been asked to open a new subwindow */

    current_subwindow = CDSubNone;
    return NULL;
  }

  RetError(window_get_wimp_handle(0, choices_window, &window_handle));
  state.window_handle = window_handle;
  RetError(wimp_get_window_state(&state));
  RetError(gadget_get_bbox(0, choices_window, CDPlaceHolder, &show_block.visible_area));
  windows_return_tool_sizes(NULL, &hheight, &vwidth);

141 142 143 144 145
  show_block.visible_area.xmin = coords_x_toscreen(show_block.visible_area.xmin, (WimpRedrawWindowBlock *) &state);
  show_block.visible_area.xmax = coords_x_toscreen(show_block.visible_area.xmax, (WimpRedrawWindowBlock *) &state);
  show_block.visible_area.ymin = coords_y_toscreen(show_block.visible_area.ymin, (WimpRedrawWindowBlock *) &state);
  show_block.visible_area.ymax = coords_y_toscreen(show_block.visible_area.ymax, (WimpRedrawWindowBlock *) &state);

146 147 148
  /* Adjustments for different types of window */

  #ifdef TRACE
149
    if (tl & (1u<<29)) Printf("choices_show_subwindow: Wimp flags = %x\n", state.flags);
150 151
  #endif

152
  RetError(window_get_wimp_handle(0, subwindows[subwindow], &state.window_handle));
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  RetError(wimp_get_window_state(&state));

  if (state.flags & WimpWindow_VScroll) show_block.visible_area.xmax -= vwidth;
  else vwidth  = 0;

  if (state.flags & WimpWindow_HScroll) show_block.visible_area.ymin += hheight;
  else hheight = 0;

  show_block.xscroll = 0;
  show_block.yscroll = 0;
  show_block.behind  = -1;

  show_block.window_flags    = 0;
  show_block.alignment_flags = 0;

  /* Requires wimp handle just to be awkward */
  show_block.parent_window_handle = window_handle;

  RetError(toolbox_show_object(Toolbox_ShowObject_AsSubWindow,
172
                               subwindows[subwindow],
173 174 175 176 177 178 179 180 181
                               Toolbox_ShowObject_FullSpec,
                               &show_block,
                               choices_window,
                               -1));

  outline.window_handle = state.window_handle;
  wimp_get_window_outline(&outline);

  if (outline.outline.xmin < show_block.visible_area.xmin)
182
  {
183
    show_block.visible_area.xmin += (show_block.visible_area.xmin - outline.outline.xmin);
184
  }
185
  if (outline.outline.ymin < (show_block.visible_area.ymin - hheight))
186
  {
187
    show_block.visible_area.ymin += (show_block.visible_area.ymin - outline.outline.ymin);
188
  }
189
  if (outline.outline.xmax > (show_block.visible_area.xmax + vwidth))
190
  {
191
    show_block.visible_area.xmax -= (outline.outline.xmax - show_block.visible_area.xmax);
192
  }
193
  if (outline.outline.ymax > show_block.visible_area.ymax)
194
  {
195
    show_block.visible_area.ymax -= (outline.outline.ymax - show_block.visible_area.ymax);
196
  }
197 198

  e = toolbox_show_object(Toolbox_ShowObject_AsSubWindow,
199
                          subwindows[subwindow],
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
                          Toolbox_ShowObject_FullSpec,
                          &show_block,
                          choices_window,
                          -1);

  if (!e) current_subwindow = subwindow;

  return e;
}

/*************************************************/
/* choices_to_be_shown()                         */
/*                                               */
/* Called when the ECDToBeShown event is         */
/* generated.                                    */
/* Creates all the subwindow dialogues and fills */
/* them in with appropriate values.              */
/* Registers all additional event handlers used  */
/* while the choices dialogue is visible.        */
/*                                               */
/* Parameters are as standard for a Toolbox      */
/* event handler.                                */
/*************************************************/

int choices_to_be_shown(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror       *e;

  #ifdef TRACE
229
    if (tl & (1u<<29)) Printf("choices_to_be_shown: Called\n");
230 231 232 233 234
  #endif

  choices_windowid = idb->self_id;

  /* Allocate block for holding subwindows ObjectIds */
235

236 237 238 239
  if (!subwindows)
  {
    subwindows = malloc(sizeof(ObjectId)*CDNoSubwindows);

240
    /* If hide object doesn't work, things are really screwed */
241

242
    if (!subwindows) ChkError(toolbox_hide_object(0, idb->self_id));
243 244 245 246 247
  }

  if (!new_choices)
  {
    new_choices = malloc(sizeof(global_choices));
248

249 250
    if (!new_choices)
    {
251
      ChkError(toolbox_hide_object(0, idb->self_id));
252 253 254 255 256 257 258 259 260
    }
    else
    {
      memcpy(new_choices, &choices, sizeof(global_choices));
    }
  }

  /* Create all choices subwindows.  Set their ObjectIds to NULL if they cannot be created */

261 262 263 264 265 266 267 268 269
  e = toolbox_create_object(0, "ChSub0", subwindows + CDSubBrowseDefaults); if (e) subwindows[CDSubBrowseDefaults] = NULL;
  e = toolbox_create_object(0, "ChSub1", subwindows + CDSubWindows);        if (e) subwindows[CDSubWindows]        = NULL;
  e = toolbox_create_object(0, "ChSub2", subwindows + CDSubColours);        if (e) subwindows[CDSubColours]        = NULL;
  e = toolbox_create_object(0, "ChSub3", subwindows + CDSubFonts);          if (e) subwindows[CDSubFonts]          = NULL;
  e = toolbox_create_object(0, "ChSub4", subwindows + CDSubHotlist);        if (e) subwindows[CDSubHotlist]        = NULL;
  e = toolbox_create_object(0, "ChSub5", subwindows + CDSubHistory);        if (e) subwindows[CDSubHistory]        = NULL;
  e = toolbox_create_object(0, "ChSub6", subwindows + CDSubSub6);           if (e) subwindows[CDSubSub6]           = NULL;
  e = toolbox_create_object(0, "ChSub7", subwindows + CDSubSub7);           if (e) subwindows[CDSubSub7]           = NULL;
  e = toolbox_create_object(0, "ChSub8", subwindows + CDSubSub8);           if (e) subwindows[CDSubSub8]           = NULL;
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

  ChkError(choices_show_subwindow(idb->self_id, CDSubBrowseDefaults));

  ChkError(radiobutton_set_state(0, idb->self_id, CDBrowseDefaults, 1));

  ChkError(choices_set_contents());

  /* Register choices event handlers. Make sure any additions here */
  /* are matched in the deregistration section below, and add to   */
  /* choices_hidden.                                               */

  e         = event_register_toolbox_handler(-1, ECDRG2,             choices_radio_click_handler,      NULL);
  if (!e) e = event_register_toolbox_handler(-1, CDSet,              choices_set_button_handler,       NULL);
  if (!e) e = event_register_toolbox_handler(-1, CDCancel,           choices_cancel_button_handler,    NULL);
  if (!e) e = event_register_toolbox_handler(-1, CDSaveButton,       choices_save_button_handler,      NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECD_EncodingMenuBt, choices_encoding_button_handler,  NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECD_ColourButton,   choices_colour_button_handler,    NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECD_HlDispBt,       choices_display_m_button_handler, NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECD_HiDispBt,       choices_display_m_button_handler, NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECD_HlSaveBt,       choices_save_m_button_handler,    NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECD_HiSaveBt,       choices_save_m_button_handler,    NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECDSaveMenuClick,   choices_save_m_click_handler,     NULL);
  if (!e) e = event_register_toolbox_handler(-1, ECDDispMenuClick,   choices_display_m_click_handler,  NULL);

  /* Deal with errors */
295 296 297

  if (e)
  {
298 299 300 301 302 303 304 305 306 307 308 309 310 311
    event_deregister_toolbox_handler(-1, ECDRG2,             choices_radio_click_handler,      NULL);
    event_deregister_toolbox_handler(-1, CDSet,              choices_set_button_handler,       NULL);
    event_deregister_toolbox_handler(-1, CDCancel,           choices_cancel_button_handler,    NULL);
    event_deregister_toolbox_handler(-1, CDSaveButton,       choices_save_button_handler,      NULL);
    event_deregister_toolbox_handler(-1, ECD_EncodingMenuBt, choices_encoding_button_handler,  NULL);
    event_deregister_toolbox_handler(-1, ECD_ColourButton,   choices_colour_button_handler,    NULL);
    event_deregister_toolbox_handler(-1, ECD_HlDispBt,       choices_display_m_button_handler, NULL);
    event_deregister_toolbox_handler(-1, ECD_HiDispBt,       choices_display_m_button_handler, NULL);
    event_deregister_toolbox_handler(-1, ECD_HlSaveBt,       choices_save_m_button_handler,    NULL);
    event_deregister_toolbox_handler(-1, ECD_HiSaveBt,       choices_save_m_button_handler,    NULL);
    event_deregister_toolbox_handler(-1, ECDSaveMenuClick,   choices_save_m_click_handler,     NULL);
    event_deregister_toolbox_handler(-1, ECDDispMenuClick,   choices_display_m_click_handler,  NULL);

    ChkError(e);
312 313 314 315 316 317 318 319 320 321 322 323
  }

  return 1;
}

/*************************************************/
/* choices_delete_subwindows()                   */
/*                                               */
/* Deletes all subwindows, reports any and all   */
/* errors occuring while deleting them.          */
/* Frees the structure holding the subwindows.   */
/*************************************************/
324

325 326 327 328 329 330 331
static void choices_delete_subwindows(void)
{
  _kernel_oserror *e;
  int count;

  for(count = 0; count < CDNoSubwindows; count++)
  {
332
    if (subwindows[count])
333
    {
334
      e = toolbox_delete_object(0, subwindows[count]);
335
      if (e) show_error_ret(e);
336
      subwindows[count] = 0;
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
    }
  }
  free(subwindows);
  subwindows = NULL;
}

/*************************************************/
/* choices_hidden()                              */
/*                                               */
/* Called when the ECDHidden event is generated. */
/* Deletes all the subwindow dialogues.          */
/* Deregisters all additional event handlers     */
/* used while the choices dialogue is visible.   */
/*                                               */
/* Parameters are as standard for a Toolbox      */
/* event handler.                                */
/*************************************************/

int choices_hidden(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
357
  _kernel_oserror * e;
358 359 360 361 362 363 364 365 366 367 368 369

  /* Close subwindow */

  e = choices_show_subwindow(idb->self_id, CDSubNone);
  if (e) show_error_ret(e);

  /* Delete all subwindow objects */

  choices_delete_subwindows();

  /* Deregister choices event handlers */

370 371 372 373 374 375 376 377 378 379 380 381
  event_deregister_toolbox_handler(-1, ECDRG2,             choices_radio_click_handler,      NULL);
  event_deregister_toolbox_handler(-1, CDSet,              choices_set_button_handler,       NULL);
  event_deregister_toolbox_handler(-1, CDCancel,           choices_cancel_button_handler,    NULL);
  event_deregister_toolbox_handler(-1, CDSaveButton,       choices_save_button_handler,      NULL);
  event_deregister_toolbox_handler(-1, ECD_EncodingMenuBt, choices_encoding_button_handler,  NULL);
  event_deregister_toolbox_handler(-1, ECD_ColourButton,   choices_colour_button_handler,    NULL);
  event_deregister_toolbox_handler(-1, ECD_HlDispBt,       choices_display_m_button_handler, NULL);
  event_deregister_toolbox_handler(-1, ECD_HiDispBt,       choices_display_m_button_handler, NULL);
  event_deregister_toolbox_handler(-1, ECD_HlSaveBt,       choices_save_m_button_handler,    NULL);
  event_deregister_toolbox_handler(-1, ECD_HiSaveBt,       choices_save_m_button_handler,    NULL);
  event_deregister_toolbox_handler(-1, ECDSaveMenuClick,   choices_save_m_click_handler,     NULL);
  event_deregister_toolbox_handler(-1, ECDDispMenuClick,   choices_display_m_click_handler,  NULL);
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401

  return 1;
}

/*************************************************/
/* choices_radio_click_handler()                 */
/*                                               */
/* Shows the appropriate subwindow when a radio  */
/* button in the choices dialogue is clicked on  */
/*                                               */
/* Parameters are as standard for a Toolbox      */
/* event handler.                                */
/*************************************************/

static int choices_radio_click_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  ObjectId window;

  switch(idb->self_component)
  {
402 403 404 405 406 407 408 409 410 411 412
    case CDBrowseDefaults: window = CDSubBrowseDefaults; break;
    case CDWindows:        window = CDSubWindows;        break;
    case CDColours:        window = CDSubColours;        break;
    case CDFonts:          window = CDSubFonts;          break;
    case CDHotlist:        window = CDSubHotlist;        break;
    case CDHistory:        window = CDSubHistory;        break;
    case CDSub6:           window = CDSubSub6;           break;
    case CDSub7:           window = CDSubSub7;           break;
    case CDSub8:           window = CDSubSub8;           break;

    default:               window = CDNoSubwindows;      break;
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
  }

  choices_show_subwindow(idb->self_id, window);

  return 1;
}

/*************************************************/
/* choices_set_contents()                        */
/*                                               */
/* Sets the contents of all choices subwindows   */
/* to reflect the current state of the global    */
/* choices.                                      */
/*                                               */
/* Returns:    pointer to _kernel_oserror.       */
/*************************************************/

430
static _kernel_oserror * choices_set_contents(void)
431
{
432
  /* No error handling here, as we want to allow items to be missing */
433

434
  if (subwindows[CDSubBrowseDefaults])
435
  {
436
    writablefield_set_value(0, subwindows[CDSubBrowseDefaults], CD_Homepage, new_choices->home_page);
437

438 439 440 441
    optionbutton_set_state(0, subwindows[CDSubBrowseDefaults], CD_UnderlineLinks, new_choices->underline_links);
    optionbutton_set_state(0, subwindows[CDSubBrowseDefaults], CD_UseDocColours,  new_choices->use_source_cols);
    optionbutton_set_state(0, subwindows[CDSubBrowseDefaults], CD_ShowForeground, new_choices->show_foreground);
    optionbutton_set_state(0, subwindows[CDSubBrowseDefaults], CD_ShowBackground, new_choices->show_background);
442 443 444

    /* Get encoding name */

445
    choices_set_encoding_field();
446 447
  }

448
  if (subwindows[CDSubWindows])
449
  {
450 451 452 453
    optionbutton_set_state(0, subwindows[CDSubWindows], CD_URLBar,     new_choices->url_bar);
    optionbutton_set_state(0, subwindows[CDSubWindows], CD_StatusBar,  new_choices->status_bar);
    optionbutton_set_state(0, subwindows[CDSubWindows], CD_ButtonBar,  new_choices->button_bar);
    optionbutton_set_state(0, subwindows[CDSubWindows], CD_FullScreen, new_choices->full_screen);
454 455
  }

456
  if (subwindows[CDSubColours])
457
  {
458 459 460 461 462 463
    choices_colour_set_component(subwindows[CDSubColours], CD_BackColour, new_choices->background_colour);
    choices_colour_set_component(subwindows[CDSubColours], CD_TextColour, new_choices->text_colour);
    choices_colour_set_component(subwindows[CDSubColours], CD_LinkColour, new_choices->link_colour);
    choices_colour_set_component(subwindows[CDSubColours], CD_UsedColour, new_choices->used_colour);
    choices_colour_set_component(subwindows[CDSubColours], CD_FolwColour, new_choices->followed_colour);
    choices_colour_set_component(subwindows[CDSubColours], CD_SlctColour, new_choices->selected_colour);
464 465
  }

466
  if (subwindows[CDSubHotlist])
467
  {
468 469
    numberrange_set_value(0, subwindows[CDSubHotlist], CD_HlAutoOpen,   new_choices->auto_open_delay);
    numberrange_set_value(0, subwindows[CDSubHotlist], CD_HlAutoScroll, new_choices->auto_scroll_delay);
470

471
    choices_set_display_field(subwindows[CDSubHotlist], CD_HlDispDisp, new_choices->hotlist_show);
472

473
    choices_set_save_field(subwindows[CDSubHotlist], CD_HlSaveDisp, new_choices->save_hotlist);
474 475
  }

476
  if (subwindows[CDSubHistory])
477
  {
478 479
    numberrange_set_value(0, subwindows[CDSubHistory], CD_HiLines,   new_choices->v_hist_size);
    numberrange_set_value(0, subwindows[CDSubHistory], CD_HiMaxSize, new_choices->g_hist_size);
480

481
    choices_set_display_field(subwindows[CDSubHistory], CD_HiDispDisp, new_choices->show_urls);
482

483
    choices_set_save_field(subwindows[CDSubHistory], CD_HiSaveDisp, new_choices->save_history);
484
  }
485

486 487 488 489 490 491 492 493 494 495 496
  return NULL;
}

/*************************************************/
/* choices_get_contents()                        */
/*                                               */
/* Sets the state of the global choices to       */
/* reflect the contents of all the choices       */
/* subwindows.                                   */
/*************************************************/

497
static _kernel_oserror * choices_get_contents(void)
498
{
499 500 501 502 503 504
  _kernel_oserror         * e;
  WimpGetWindowStateBlock   s;
  browser_data            * b;
  char                    * tempstring;
  int                       state;
  int                       reqsize;
505

506 507
  /* The lack of error chechking is to allow */
  /* items to be missing from the dialogue.  */
508

509
  if (subwindows[CDSubBrowseDefaults])
510
  {
511
    e = writablefield_get_value(0, subwindows[CDSubBrowseDefaults], CD_Homepage, NULL, 0, &reqsize);
512

513
    if (!e)
514
    {
515 516 517
      tempstring = malloc(reqsize + 1);

      if (tempstring)
518
      {
519 520 521 522 523 524 525 526 527 528 529 530 531 532
        e = writablefield_get_value(0, subwindows[CDSubBrowseDefaults], CD_Homepage, tempstring, reqsize, NULL);

        if (!e)
        {
          if (!strcmp(tempstring, new_choices->home_page))
          {
            free(tempstring);
          }
          else
          {
            free(new_choices->home_page);
            new_choices->home_page = tempstring;
          }
        }
533 534 535
      }
      else
      {
536
        show_error_ret(make_no_memory_error(17));
537 538 539
      }
    }

540 541
    e = optionbutton_get_state(0, subwindows[CDSubBrowseDefaults], CD_UnderlineLinks, &state);
    if (!e) new_choices->underline_links = !!state;
542

543 544
    e = optionbutton_get_state(0, subwindows[CDSubBrowseDefaults], CD_UseDocColours,  &state);
    if (!e) new_choices->use_source_cols = !!state;
545

546 547 548 549 550 551 552 553
    e = optionbutton_get_state(0, subwindows[CDSubBrowseDefaults], CD_ShowForeground, &state);
    if (!e) new_choices->show_foreground = !!state;

    e = optionbutton_get_state(0, subwindows[CDSubBrowseDefaults], CD_ShowBackground, &state);
    if (!e) new_choices->show_background = !!state;
  }

  if (subwindows[CDSubWindows])
554
  {
555 556 557 558 559 560 561 562 563 564 565
    e = optionbutton_get_state(0, subwindows[CDSubWindows], CD_URLBar,     &state);
    if (!e) new_choices->url_bar     = !!state;

    e = optionbutton_get_state(0, subwindows[CDSubWindows], CD_StatusBar,  &state);
    if (!e) new_choices->status_bar  = !!state;

    e = optionbutton_get_state(0, subwindows[CDSubWindows], CD_ButtonBar,  &state);
    if (!e) new_choices->button_bar  = !!state;

    e = optionbutton_get_state(0, subwindows[CDSubWindows], CD_FullScreen, &state);
    if (!e) new_choices->full_screen = !!state;
566 567
  }

568
  if (subwindows[CDSubHotlist])
569
  {
570 571
    numberrange_get_value(0, subwindows[CDSubHotlist], CD_HlAutoOpen,   &new_choices->auto_open_delay);
    numberrange_get_value(0, subwindows[CDSubHotlist], CD_HlAutoScroll, &new_choices->auto_scroll_delay);
572 573
  }

574
  if (subwindows[CDSubHistory])
575
  {
576 577
    numberrange_get_value(0, subwindows[CDSubHistory], CD_HiLines,   &new_choices->v_hist_size);
    numberrange_get_value(0, subwindows[CDSubHistory], CD_HiMaxSize, &new_choices->g_hist_size);
578 579 580 581
  }

  memcpy(&choices, new_choices, sizeof(global_choices));

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
  /* Update browsers */

  b = last_browser;

  while (b)
  {
    /* The Choices are only used directly for browsers which are */
    /* set to override document colours. Otherwise defaults will */
    /* have been read locally and possibly overridden by HTML,   */
    /* and a reload will be needed to reflect the changes.       */

    if (!b->use_source_cols)
    {
      s.window_handle = b->window_handle;
      RetError(wimp_get_window_state(&s));

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

      RetError(wimp_force_redraw(b->window_handle,
                                 s.visible_area.xmin,
                                 s.visible_area.ymin,
                                 s.visible_area.xmax,
                                 s.visible_area.ymax));
    }

    b = b->previous;
  }

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 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
  return NULL;
}

/*************************************************/
/* choices_set_button_handler()                  */
/*                                               */
/* Called when the set button in the main        */
/* choices dialogue is clicked.                  */
/* Uses choices_get_contents to set the global   */
/* choices to reflect the choices set in the     */
/* choices subwindows                            */
/*                                               */
/* Parameters are as standard for a Toolbox      */
/* event handler.                                */
/*************************************************/

static int choices_set_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e = NULL;
  e = choices_get_contents();
  if (e) show_error_ret(e);

  return 1;
}

/*************************************************/
/* choices_cancel_button_handler()               */
/*                                               */
/* Called when the cancel button in the main     */
/* choices dialogue is clicked.                  */
/* Uses choices_set_contents to restore the      */
/* subwindows to their previous state.           */
/*                                               */
/* Parameters are as standard for a Toolbox      */
/* event handler.                                */
/*************************************************/

static int choices_cancel_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e = NULL;

  memcpy(new_choices, &choices, sizeof(global_choices));

  choices_set_contents();
  if (e) show_error_ret(e);

  return 1;
}

/*************************************************/
/* choices_save_button_handler()                 */
/*                                               */
/* Called when the set button in the main        */
/* choices dialogue is clicked.                  */
/* Uses choices_get_contents to set the global   */
/* choices to reflect the choices set in the     */
/* choices subwindows and then saves the choices */
/* file.                                         */
/*                                               */
/* Parameters are as standard for a Toolbox      */
/* event handler.                                */
/*************************************************/

static int choices_save_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e = NULL;
  e = choices_get_contents();
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = save_save_choices(NULL);
  if (e) show_error_ret(e);

  return 1;
}

/*************************************************/
/* choices_set_encoding_field()                  */
/*                                               */
/* Sets the encoding display field appropriately */
/* to reflect the current state of               */
/* new_choices->encoding                         */
/*************************************************/

_kernel_oserror * choices_set_encoding_field(void)
{
  _kernel_oserror *e;
  ObjectId    objid;
  ComponentId compid;
  char *textptr;
  int sizereqd;

  /* Find menu item which contains encoding name */

  if (encoding_get_encoding_item(new_choices->encoding, &objid, &compid))
  {
    RetError(menu_get_entry_text(0, objid, compid, NULL, 0, &sizereqd));

    /* Add 1 to the buffer size just incase the sizereqd field is returned as string */
    /* length rather than the buffer size required.  Typical paranoid precautions    */
    /* when using the toolbox.                                                       */

    textptr = malloc(sizereqd+1);

    if (textptr)
    {
      e = menu_get_entry_text(0, objid, compid, textptr, sizereqd+1, NULL);
      if (e)
      {
        free(textptr);
        return e;
      }
725
      e = displayfield_set_value(0, subwindows[CDSubBrowseDefaults], CD_EncodingDisply, textptr);
726 727 728 729 730 731 732 733 734

      free(textptr);
      if (e)
      {
        return e;
      }
    }
    else
    {
735
      RetError(make_no_memory_error(18));
736 737 738 739 740 741
    }
  }
  else
  {
    /* The encoding name could not be found in the menu structure */

742
    RetError(displayfield_set_value(0, subwindows[CDSubBrowseDefaults], CD_EncodingDisply, "Unknown encoding")); //
743 744 745 746 747 748 749 750 751 752 753 754 755 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 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
  }

  return NULL;
}

/*************************************************/
/* choices_encoding_button_handler()             */
/*                                               */
/* Opens the encoding window with appropriate    */
/* values for the choices dialogue.              */
/*************************************************/

static int choices_encoding_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e;
  int  position[2];
  BBox box;
  WimpGetWindowStateBlock state;

  e = gadget_get_bbox(0, idb->self_id, idb->self_component, &box);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = window_get_wimp_handle(0, idb->self_id, &state.window_handle);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = wimp_get_window_state(&state);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  /* Set open coordinates of encoding menu to top left of encoding button */

  position[0] = coords_x_toscreen(box.xmax, (WimpRedrawWindowBlock*)&state);
  position[1] = coords_y_toscreen(box.ymax, (WimpRedrawWindowBlock*)&state);

  show_error_ret(toolbox_show_object(Toolbox_ShowObject_AsMenu,
                                     encoding_get_menuid(),
                                     Toolbox_ShowObject_TopLeft,
                                     position,
                                     choices_windowid,
                                     NULL));

  return 1;
}

/*************************************************/
/* choices_colour_button_handler()               */
/*                                               */
/* Opens a colour dialogue box with appropriate  */
/* settings for the current colour.              */
/*************************************************/

static int choices_colour_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e;
  int  position[2];
  BBox box;
  WimpGetWindowStateBlock state;
  int colour[2];

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
  /* Is the ColourDbox module in RMA? */

  e = _swix(OS_Module, _INR(0,1), 18, "ColourDbox");

  /* No, well try and load it from system */

  if (e)
  {
    e = _swix(OS_Module, _INR(0,1), 1, "System:Modules.Toolbox.ColourDbox");
  }

  /* That didn't work so try reinitialising it */

  if (e)
  {
    e = _swix(OS_Module, _INR(0,1), 3, "ColourDbox");
  }

  /* That didn't work either!  So it's tough you can't change the colours */

  if (e)
  {
    show_error_ret(e);
    return 1;
  }

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 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
  switch(idb->self_component)
  {
    case CD_BackColourBt: colour[0] = new_choices->background_colour; break;
    case CD_TextColourBt: colour[0] = new_choices->text_colour;       break;
    case CD_LinkColourBt: colour[0] = new_choices->link_colour;       break;
    case CD_UsedColourBt: colour[0] = new_choices->used_colour;       break;
    case CD_FolwColourBt: colour[0] = new_choices->followed_colour;   break;
    case CD_SlctColourBt: colour[0] = new_choices->selected_colour;   break;
    default:
    return 1;
    break;
  }

  colour[1] = 0;

  e = gadget_get_bbox(0, idb->self_id, idb->self_component, &box);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = window_get_wimp_handle(0, idb->self_id, &state.window_handle);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = wimp_get_window_state(&state);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  /* Set open coordinates of encoding menu to top left of encoding button */

  position[0] = coords_x_toscreen(box.xmax, (WimpRedrawWindowBlock*)&state);
  position[1] = coords_y_toscreen(box.ymax, (WimpRedrawWindowBlock*)&state);

  e = toolbox_create_object(0, "ColourDbox", &colourdbox_id);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = colourdbox_set_colour(0, colourdbox_id, colour);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  show_error_ret(toolbox_show_object(Toolbox_ShowObject_AsMenu,
                                     colourdbox_id,
                                     Toolbox_ShowObject_TopLeft,
                                     position,
                                     idb->self_id,
                                     idb->self_component));

  e = event_register_toolbox_handler(colourdbox_id, ColourDbox_DialogueCompleted, choices_colour_closed_handler, NULL);
  if (e) {show_error_ret(e); return 1;}

  e = event_register_toolbox_handler(colourdbox_id, ColourDbox_ColourSelected, choices_colour_selected_handler, NULL);
  if (e) {show_error_ret(e); return 1;}

  return 1;
}

/*************************************************/
/* choices_colour_closed_handler()               */
/*                                               */
/* Called when the colour dialogue box is closed */
/* deregisters all events attached to it and     */
/* deletes the dbox object.                      */
/*************************************************/

static int choices_colour_closed_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e;

  e = event_deregister_toolbox_handler(idb->self_id, ColourDbox_DialogueCompleted, choices_colour_closed_handler, NULL);
  if (e) {show_error_ret(e); return 1;}

  e = event_deregister_toolbox_handler(colourdbox_id, ColourDbox_ColourSelected, choices_colour_selected_handler, NULL);
  if (e) {show_error_ret(e); return 1;}

  e = toolbox_delete_object(0, idb->self_id);
  if (e) {show_error_ret(e); return 1;}

  #ifdef TRACE
932
    if (tl & (1u<<29)) Printf("choices_colour_closed_handler: Colour DBox deleted\n");
933 934 935 936 937 938 939 940 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
  #endif

  return 1;
}

/*************************************************/
/* choices_colour_closed_handler()               */
/*                                               */
/* Called when the a colour is selected in the   */
/* colour dialogue box.                          */
/* Sets appropriate fields in the new_choices    */
/* structure and updates the window to reflect   */
/* the new colour chosen.                        */
/*************************************************/

static int choices_colour_selected_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  ColourDboxColourSelectedEvent *cevent = (ColourDboxColourSelectedEvent*)event;

  switch(idb->parent_component)
  {
    case CD_BackColourBt: new_choices->background_colour = cevent->colour_block[0]; break;
    case CD_TextColourBt: new_choices->text_colour       = cevent->colour_block[0]; break;
    case CD_LinkColourBt: new_choices->link_colour       = cevent->colour_block[0]; break;
    case CD_UsedColourBt: new_choices->used_colour       = cevent->colour_block[0]; break;
    case CD_FolwColourBt: new_choices->followed_colour   = cevent->colour_block[0]; break;
    case CD_SlctColourBt: new_choices->selected_colour   = cevent->colour_block[0]; break;
    default:
    return 1;
    break;
  }

  show_error_ret(choices_colour_set_component(idb->parent_id, idb->parent_component-1, cevent->colour_block[0]));

  return 1;
}

/*************************************************/
/* choices_colour_closed_handler()               */
/*                                               */
/* Sets the validation string of a button to be  */
/* slabbed in and have the background colour     */
/* specified.                                    */
/*                                               */
/* Parameters: window ObjectId                   */
/*                                               */
/*             button ComponentId                */
/*                                               */
/*             colour                            */
/*************************************************/

static _kernel_oserror *choices_colour_set_component(ObjectId window, ComponentId component, int colour)
{
986 987 988
  char            newvalidation[32];
  unsigned char * newcol;

989 990
  newcol = (unsigned char*)&colour;

991
  sprintf(newvalidation, "R2;C/%02.2x%02.2x%02.2x", *(newcol + 3), *(newcol + 2), *(newcol + 1));
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 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

  return button_set_validation(0, window, component, newvalidation);
}

/*************************************************/
/* choices_display_button_handler()              */
/*                                               */
/* Opens the display menu with a value           */
/* appropriate to either the hotlist or history. */
/*************************************************/

static int choices_display_m_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e;
  int  position[2];
  BBox box;
  WimpGetWindowStateBlock state;
  ObjectId display;
  int new_tick;

  e = gadget_get_bbox(0, idb->self_id, idb->self_component, &box);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = window_get_wimp_handle(0, idb->self_id, &state.window_handle);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = wimp_get_window_state(&state);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  /* Set open coordinates of display menu to top left of display button */

  position[0] = coords_x_toscreen(box.xmax, (WimpRedrawWindowBlock*)&state);
  position[1] = coords_y_toscreen(box.ymax, (WimpRedrawWindowBlock*)&state);

  e = toolbox_create_object(0, "ChDisplay", &display);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  switch(idb->self_component)
  {
    case CD_HlDispBt: new_tick = new_choices->hotlist_show; break;
    case CD_HiDispBt: new_tick = new_choices->show_urls;    break;
    default: new_tick = 0; break;
  }

  if (disp_ticked != new_tick)
  {
    if (disp_ticked != -1) menu_set_tick(0, display, disp_ticked, 0);
    menu_set_tick(0, display, new_tick, 1);
    disp_ticked = new_tick;
  }

  show_error_ret(toolbox_show_object(Toolbox_ShowObject_AsMenu,
                                     display,
                                     Toolbox_ShowObject_TopLeft,
                                     position,
                                     idb->self_id,
                                     idb->self_component));

  return 1;
}

/*************************************************/
1070
/* choices_save_m_button_handler()               */
1071 1072 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 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 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
/*                                               */
/* Opens the save menu with a value appropriate  */
/* to either the hotlist or history.             */
/*************************************************/

static int choices_save_m_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  _kernel_oserror *e;
  int  position[2];
  BBox box;
  WimpGetWindowStateBlock state;
  ObjectId display;
  int new_tick;

  e = gadget_get_bbox(0, idb->self_id, idb->self_component, &box);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = window_get_wimp_handle(0, idb->self_id, &state.window_handle);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  e = wimp_get_window_state(&state);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  /* Set open coordinates of display menu to top left of display button */

  position[0] = coords_x_toscreen(box.xmax, (WimpRedrawWindowBlock*)&state);
  position[1] = coords_y_toscreen(box.ymax, (WimpRedrawWindowBlock*)&state);

  e = toolbox_create_object(0, "ChSave", &display);
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

  switch(idb->self_component)
  {
    case CD_HlSaveBt: new_tick = new_choices->save_hotlist; break;
    case CD_HiSaveBt: new_tick = new_choices->save_history; break;
    default: new_tick = 0; break;
  }

  if (save_ticked != new_tick)
  {
    if (save_ticked != -1) menu_set_tick(0, display, save_ticked, 0);
    menu_set_tick(0, display, new_tick, 1);
    save_ticked = new_tick;
  }

  show_error_ret(toolbox_show_object(Toolbox_ShowObject_AsMenu,
                                     display,
                                     Toolbox_ShowObject_TopLeft,
                                     position,
                                     idb->self_id,
                                     idb->self_component));

  return 1;
}

/*************************************************/
/* choices_set_save_field()                      */
/*                                               */
/* Sets the passed save display field            */
/* appropriately to reflect the passed state.    */
/*************************************************/

static _kernel_oserror * choices_set_save_field(ObjectId obj, ComponentId comp, int state)
{
  _kernel_oserror *e;
  ObjectId menu_id;
  int reqdsize;
  char *tempstring;

  #ifdef TRACE
1157
    if (tl & (1u<<29)) Printf("choices_set_display_field: Called\n");
1158 1159 1160 1161 1162 1163
  #endif

  RetError(toolbox_create_object(0, "ChSave", &menu_id));

  RetError(menu_get_entry_text(0, menu_id, state, NULL, 0, &reqdsize));

1164 1165
  tempstring = malloc(reqdsize + 1);
  if (!tempstring) return make_no_memory_error(19);
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

  RetError(menu_get_entry_text(0, menu_id, state, tempstring, reqdsize+1, NULL));

  e = displayfield_set_value(0, obj, comp, tempstring);

  free(tempstring);

  return e;
}

/*************************************************/
/* choices_set_display_field()                   */
/*                                               */
/* Sets the passed display display field         */
/* appropriately to reflect the passed state.    */
/*************************************************/

static _kernel_oserror * choices_set_display_field(ObjectId obj, ComponentId comp, int state)
{
  _kernel_oserror *e;
  ObjectId menu_id;
  int reqdsize;
  char *tempstring;

  #ifdef TRACE
1191
    if (tl & (1u<<29)) Printf("choices_set_display_field: Called\n");
1192 1193 1194 1195 1196 1197 1198
  #endif

  RetError(toolbox_create_object(0, "ChDisplay", &menu_id));

  RetError(menu_get_entry_text(0, menu_id, state, NULL, 0, &reqdsize));

  tempstring = malloc(reqdsize+1);
1199
  if (!tempstring) return make_no_memory_error(20);
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 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266

  RetError(menu_get_entry_text(0, menu_id, state, tempstring, reqdsize+1, NULL));

  e = displayfield_set_value(0, obj, comp, tempstring);

  free(tempstring);

  return e;
}

/*************************************************/
/* choices_display_m_click_handler()             */
/*                                               */
/*************************************************/

static int choices_display_m_click_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  if (disp_ticked != idb->self_component)
  {
    if (disp_ticked != -1) menu_set_tick(0, idb->self_id, disp_ticked, 0);
    menu_set_tick(0, idb->self_id, idb->self_component, 1);
    disp_ticked = idb->self_component;
  }

  switch(idb->parent_component)
  {
    case CD_HlDispBt:
    new_choices->hotlist_show = idb->self_component;
    break;
    case CD_HiDispBt:
    new_choices->show_urls    = idb->self_component;
    break;
  }

  choices_set_display_field(idb->parent_id, idb->parent_component - 1, idb->self_component);

  return 1;
}

/*************************************************/
/* choices_save_m_click_handler()                */
/*                                               */
/*************************************************/

static int choices_save_m_click_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
  if (save_ticked != idb->self_component)
  {
    if (save_ticked != -1) menu_set_tick(0, idb->self_id, save_ticked, 0);
    menu_set_tick(0, idb->self_id, idb->self_component, 1);
    save_ticked = idb->self_component;
  }

  switch(idb->parent_component)
  {
    case CD_HlSaveBt:
    new_choices->save_hotlist = idb->self_component;
    break;
    case CD_HiSaveBt:
    new_choices->save_history = idb->self_component;
    break;
  }

  choices_set_save_field(idb->parent_id, idb->parent_component - 1, idb->self_component);

  return 1;
}