Choices 67.8 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
/* 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"
50
#include "FontManage.h"
51 52 53
#include "History.h"
#include "Menus.h"
#include "NestWimp.h"
54
#include "Redraw.h"
55 56 57 58 59 60
#include "Save.h"
#include "URLutils.h"
#include "Windows.h"

#include "Choices.h"

61
/* Locals */
62

63 64
static char *consonant                = "bcdfghjklmnpqrstvwxyz";
static char *vowel                    = "aeiou";
65

66 67 68
static ObjectId * subwindows          = NULL;
static int        current_subwindow   = CDSubNone;
static ObjectId   colourdbox_id       = 0;
69

70 71
static int        save_ticked         = -1;
static int        disp_ticked         = -1;
72

73 74
static int        choices_modechanged = 0;

75 76
global_choices  * new_choices         = NULL;
ObjectId          choices_windowid    = 0;
77 78

/* Static function prototypes */
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

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);
96 97 98
static int               choices_option_state_handler    (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int               choices_redraw_fakepage_handler (int eventcode, WimpPollBlock * event, IdBlock * id_block, void * handle);
static int               choices_open_choice_window      (int eventcode, WimpPollBlock * event, IdBlock * id_block, void * handle);
99

100 101 102
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);
103
static ObjectId          choices_find_component          (ComponentId component);
104

105 106 107 108 109
static _kernel_oserror * choices_displayfield_set_value  (unsigned int flags, ObjectId window, ComponentId writable, char *text);
static _kernel_oserror * choices_writablefield_set_value (unsigned int flags, ObjectId window, ComponentId writable, char *text);
static _kernel_oserror * choices_button_set_validation   (unsigned int flags, ObjectId window, ComponentId writable, char *text);
static _kernel_oserror * choices_numberrange_set_value   (unsigned int flags, ObjectId window, ComponentId writable, int value);

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
/*************************************************/
/* 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        */
/*************************************************/

127
static _kernel_oserror * choices_show_subwindow(ObjectId choices_window, int subwindow)
128
{
129 130 131 132 133 134
  _kernel_oserror           * e;
  WindowShowObjectBlock       show_block;
  WimpGetWindowStateBlock     state;
  WimpGetWindowOutlineBlock   outline;
  int                         window_handle;
  int                         vwidth, hheight;
135

136
  if (current_subwindow != CDSubNone && current_subwindow != subwindow)
137 138
  {
    /* remove the current subwindow */
139

140
    RetError(toolbox_hide_object(0, subwindows[current_subwindow]));
141
    current_subwindow = CDSubNone;
142 143
  }

144
  if (subwindow == CDSubNone || !(subwindows[subwindow]))
145 146 147 148 149 150 151 152 153 154 155 156
  {
    /* Have not been asked to open a new subwindow */

    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);

157 158 159 160 161
  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);

162 163 164
  /* Adjustments for different types of window */

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

168
  RetError(window_get_wimp_handle(0, subwindows[subwindow], &state.window_handle));
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
  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,
188
                               subwindows[subwindow],
189 190 191 192 193 194 195 196 197
                               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)
198
  {
199
    show_block.visible_area.xmin += (show_block.visible_area.xmin - outline.outline.xmin);
200
  }
201
  if (outline.outline.ymin < (show_block.visible_area.ymin - hheight))
202
  {
203
    show_block.visible_area.ymin += (show_block.visible_area.ymin - outline.outline.ymin);
204
  }
205
  if (outline.outline.xmax > (show_block.visible_area.xmax + vwidth))
206
  {
207
    show_block.visible_area.xmax -= (outline.outline.xmax - show_block.visible_area.xmax);
208
  }
209
  if (outline.outline.ymax > show_block.visible_area.ymax)
210
  {
211
    show_block.visible_area.ymax -= (outline.outline.ymax - show_block.visible_area.ymax);
212
  }
213 214

  e = toolbox_show_object(Toolbox_ShowObject_AsSubWindow,
215
                          subwindows[subwindow],
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
                          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;
243
  ObjectId              window;
244 245

  #ifdef TRACE
246
    if (tl & (1u<<29)) Printf("choices_to_be_shown: Called\n");
247 248
  #endif

249 250
  if (choices_windowid) return 1;

251 252 253
  choices_windowid = idb->self_id;

  /* Allocate block for holding subwindows ObjectIds */
254

255 256 257 258
  if (!subwindows)
  {
    subwindows = malloc(sizeof(ObjectId)*CDNoSubwindows);

259
    /* If hide object doesn't work, things are really screwed */
260

261
    if (!subwindows) ChkError(toolbox_hide_object(0, idb->self_id));
262 263 264 265 266
  }

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

268 269
    if (!new_choices)
    {
270
      ChkError(toolbox_hide_object(0, idb->self_id));
271 272 273 274 275 276 277 278 279
    }
    else
    {
      memcpy(new_choices, &choices, sizeof(global_choices));
    }
  }

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

280 281 282 283 284 285 286 287 288 289 290
  /* Might be worth changing this to a loop in the future */

  e = toolbox_create_object(0, "ChSub0", &subwindows[0]); if (e) subwindows[0] = NULL;
  e = toolbox_create_object(0, "ChSub1", &subwindows[1]); if (e) subwindows[1] = NULL;
  e = toolbox_create_object(0, "ChSub2", &subwindows[2]); if (e) subwindows[2] = NULL;
  e = toolbox_create_object(0, "ChSub3", &subwindows[3]); if (e) subwindows[3] = NULL;
  e = toolbox_create_object(0, "ChSub4", &subwindows[4]); if (e) subwindows[4] = NULL;
  e = toolbox_create_object(0, "ChSub5", &subwindows[5]); if (e) subwindows[5] = NULL;
  e = toolbox_create_object(0, "ChSub6", &subwindows[6]); if (e) subwindows[6] = NULL;
  e = toolbox_create_object(0, "ChSub7", &subwindows[7]); if (e) subwindows[7] = NULL;
  e = toolbox_create_object(0, "ChSub8", &subwindows[8]); if (e) subwindows[8] = NULL;
291

292
  ChkError(choices_show_subwindow(idb->self_id, 0));
293

294
  ChkError(radiobutton_set_state(0, idb->self_id, CDFirstSubRadio + 0, 1));
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

  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);
314 315 316 317 318 319
  if (!e) e = event_register_toolbox_handler(-1, OptionButton_StateChanged, choices_option_state_handler, NULL);

  if ((window = choices_find_component(CD_FakePage)) != 0)
  {
    if (!e) e = event_register_wimp_handler(window, Wimp_ERedrawWindow, choices_redraw_fakepage_handler, NULL);
  }
320

321
  if (!e) e = event_register_wimp_handler(idb->self_id, Wimp_EOpenWindow, choices_open_choice_window, NULL);
322
  /* Deal with errors */
323 324 325

  if (e)
  {
326 327 328 329 330 331 332 333 334 335 336 337
    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);
338 339 340 341 342 343
    event_deregister_toolbox_handler(-1, OptionButton_StateChanged, choices_option_state_handler, NULL);

    if ((window = choices_find_component(CD_FakePage)) != 0)
    {
      event_deregister_wimp_handler(window, Wimp_ERedrawWindow, choices_redraw_fakepage_handler, NULL);
    }
344 345

    event_deregister_wimp_handler(idb->self_id, Wimp_EOpenWindow, choices_open_choice_window, NULL);
346 347

    ChkError(e);
348 349 350 351 352 353 354 355 356 357 358 359
  }

  return 1;
}

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

361 362 363 364 365 366 367
static void choices_delete_subwindows(void)
{
  _kernel_oserror *e;
  int count;

  for(count = 0; count < CDNoSubwindows; count++)
  {
368
    if (subwindows[count])
369
    {
370
      e = toolbox_delete_object(0, subwindows[count]);
371
      if (e) show_error_ret(e);
372
      subwindows[count] = 0;
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
    }
  }
  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)
{
393
  _kernel_oserror * e;
394
  ObjectId          window;
395 396 397 398 399 400 401 402 403 404 405 406

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

407 408 409 410 411 412 413 414 415 416 417 418
  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);
419
  event_deregister_toolbox_handler(-1, OptionButton_StateChanged, choices_option_state_handler, NULL);
420

421 422 423 424
  if ((window = choices_find_component(CD_FakePage)) != 0)
  {
    event_deregister_wimp_handler(window, Wimp_ERedrawWindow, choices_redraw_fakepage_handler, NULL);
  }
425 426 427
  event_deregister_wimp_handler(idb->self_id, Wimp_EOpenWindow, choices_open_choice_window, NULL);

  choices_windowid = 0;
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443

  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)
{
444
  int window, state;
445

446 447 448 449 450
  radiobutton_get_state(0, idb->self_id, idb->self_component, &state, NULL);

  /* Is this a radiobutton selected event? */

  if (state)
451
  {
452 453 454
    window = idb->self_component - CDFirstSubRadio;
    if (window > CDNoSubwindows) window = CDSubNone;
    choices_show_subwindow(idb->self_id, window);
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  }

  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.       */
/*************************************************/

470
static _kernel_oserror * choices_set_contents(void)
471
{
472
  ObjectId window;
473
  /* No error handling here, as we want to allow items to be missing */
474

475
  if ((window = choices_find_component(CD_Homepage))       != 0) choices_writablefield_set_value(0, window, CD_Homepage,       new_choices->home_page);
476 477 478 479
  if ((window = choices_find_component(CD_UnderlineLinks)) != 0) optionbutton_set_state(0,  window, CD_UnderlineLinks, new_choices->underline_links);
  if ((window = choices_find_component(CD_UseDocColours))  != 0) optionbutton_set_state(0,  window, CD_UseDocColours,  new_choices->use_source_cols);
  if ((window = choices_find_component(CD_ShowForeground)) != 0) optionbutton_set_state(0,  window, CD_ShowForeground, new_choices->show_foreground);
  if ((window = choices_find_component(CD_ShowBackground)) != 0) optionbutton_set_state(0,  window, CD_ShowBackground, new_choices->show_background);
480 481

  /* Get encoding name */
482
  choices_set_encoding_field();
483 484 485 486 487 488 489 490 491 492 493 494 495

  if ((window = choices_find_component(CD_URLBar))         != 0) optionbutton_set_state(0, window, CD_URLBar,     new_choices->url_bar);
  if ((window = choices_find_component(CD_StatusBar))      != 0) optionbutton_set_state(0, window, CD_StatusBar,  new_choices->status_bar);
  if ((window = choices_find_component(CD_ButtonBar))      != 0) optionbutton_set_state(0, window, CD_ButtonBar , new_choices->button_bar);
  if ((window = choices_find_component(CD_FullScreen))     != 0) optionbutton_set_state(0, window, CD_FullScreen, new_choices->full_screen);

  if ((window = choices_find_component(CD_BackColour))     != 0) choices_colour_set_component(window, CD_BackColour, new_choices->background_colour);
  if ((window = choices_find_component(CD_TextColour))     != 0) choices_colour_set_component(window, CD_TextColour, new_choices->text_colour);
  if ((window = choices_find_component(CD_LinkColour))     != 0) choices_colour_set_component(window, CD_LinkColour, new_choices->link_colour);
  if ((window = choices_find_component(CD_UsedColour))     != 0) choices_colour_set_component(window, CD_UsedColour, new_choices->used_colour);
  if ((window = choices_find_component(CD_FolwColour))     != 0) choices_colour_set_component(window, CD_FolwColour, new_choices->followed_colour);
  if ((window = choices_find_component(CD_SlctColour))     != 0) choices_colour_set_component(window, CD_SlctColour, new_choices->selected_colour);

496 497
  if ((window = choices_find_component(CD_HlAutoOpen))     != 0) choices_numberrange_set_value(0,  window, CD_HlAutoOpen,   new_choices->auto_open_delay);
  if ((window = choices_find_component(CD_HlAutoScroll))   != 0) choices_numberrange_set_value(0,  window, CD_HlAutoScroll, new_choices->auto_scroll_delay);
498 499
  if ((window = choices_find_component(CD_HlDispDisp))     != 0) choices_set_display_field(window, CD_HlDispDisp,   new_choices->hotlist_show);
  if ((window = choices_find_component(CD_HlSaveDisp))     != 0) choices_set_save_field(   window, CD_HlSaveDisp,   new_choices->save_hotlist);
500

501 502
  if ((window = choices_find_component(CD_HiLines))        != 0) choices_numberrange_set_value(0,  window, CD_HiLines,    new_choices->v_hist_size);
  if ((window = choices_find_component(CD_HiMaxSize))      != 0) choices_numberrange_set_value(0,  window, CD_HiMaxSize,  new_choices->g_hist_size);
503
  if ((window = choices_find_component(CD_HiDispDisp))     != 0) choices_set_display_field(window, CD_HiDispDisp, new_choices->show_urls);
504 505 506 507 508
  if ((window = choices_find_component(CD_HiSaveDisp))     != 0) choices_set_save_field(   window, CD_HiSaveDisp, new_choices->save_history);

  if ((window = choices_find_component(CD_ClientPull))     != 0) optionbutton_set_state(0, window, CD_ClientPull,    new_choices->client_pull);
  if ((window = choices_find_component(CD_NetscapeEmu))    != 0) optionbutton_set_state(0, window, CD_NetscapeEmu,   new_choices->clone);
  if ((window = choices_find_component(CD_FramesSupport))  != 0) optionbutton_set_state(0, window, CD_FramesSupport, new_choices->support_frames);
509

510 511 512 513 514 515 516 517 518 519 520
  return NULL;
}

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

521
static _kernel_oserror * choices_get_contents(void)
522
{
523 524 525
  _kernel_oserror         * e;
  WimpGetWindowStateBlock   s;
  browser_data            * b;
526
  ObjectId                  window;
527 528
  char                    * tempstring;
  int                       reqsize;
529

530 531
  /* The lack of error chechking is to allow */
  /* items to be missing from the dialogue.  */
532

533
  if ((window = choices_find_component(CD_Homepage)) != 0)
534
  {
535
    e = writablefield_get_value(0, window, CD_Homepage, NULL, 0, &reqsize);
536

537
    if (!e)
538
    {
539 540 541
      tempstring = malloc(reqsize + 1);

      if (tempstring)
542
      {
543
        e = writablefield_get_value(0, window, CD_Homepage, tempstring, reqsize, NULL);
544 545 546 547 548 549 550 551 552 553 554 555 556

        if (!e)
        {
          if (!strcmp(tempstring, new_choices->home_page))
          {
            free(tempstring);
          }
          else
          {
            free(new_choices->home_page);
            new_choices->home_page = tempstring;
          }
        }
557 558 559
      }
      else
      {
560
        show_error_ret(make_no_memory_error(17));
561 562
      }
    }
563 564
  }

565 566
  if ((window = choices_find_component(CD_HlAutoOpen))     != 0) numberrange_get_value(0, window, CD_HlAutoOpen,   &new_choices->auto_open_delay);
  if ((window = choices_find_component(CD_HlAutoScroll))   != 0) numberrange_get_value(0, window, CD_HlAutoScroll, &new_choices->auto_scroll_delay);
567 568
  if ((window = choices_find_component(CD_HiLines))        != 0) numberrange_get_value(0, window, CD_HiLines,      &new_choices->v_hist_size);
  if ((window = choices_find_component(CD_HiMaxSize))      != 0) numberrange_get_value(0, window, CD_HiMaxSize,    &new_choices->g_hist_size);
569 570 571

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

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
  /* 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;
  }

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
  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)
{
639
  ObjectId        window;
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  int             update_fake;

  if ((choices.background_colour != new_choices->background_colour) ||
      (choices.text_colour       != new_choices->text_colour)       ||
      (choices.link_colour       != new_choices->link_colour)       ||
      (choices.used_colour       != new_choices->used_colour)       ||
      (choices.followed_colour   != new_choices->followed_colour)   ||
      (choices.selected_colour   != new_choices->selected_colour)   ||
      (choices.underline_links   != new_choices->underline_links))
  {
    update_fake = 1;
  }
  else
  {
    update_fake = 0;
  }
656 657 658 659

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

  choices_set_contents();
660 661 662

  /* Attempt to redraw fake page display */

663
  if (update_fake && (window = choices_find_component(CD_FakePage)) != 0) button_set_flags(0, window, CD_FakePage, 0, 0);
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684

  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;
685 686
  ObjectId        window;

687 688 689 690 691 692 693
  e = choices_get_contents();
  if (e)
  {
    show_error_ret(e);
    return 1;
  }

694 695 696 697
  /* Attempt to redraw fake page display */

  if ((window = choices_find_component(CD_FakePage)) != 0) button_set_flags(0, window, CD_FakePage, 0, 0);

698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
  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;
715
  ObjectId    objid, destwind;
716 717 718 719
  ComponentId compid;
  char *textptr;
  int sizereqd;

720 721 722 723 724
  /* Find which window the encoding display is in */

  destwind = choices_find_component(CD_EncodingDisply);
  if (!destwind) return NULL;

725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
  /* 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;
      }
745 746

      e = choices_displayfield_set_value(0, destwind, CD_EncodingDisply, textptr);
747 748

      free(textptr);
749
      return e;
750 751 752
    }
    else
    {
753
      RetError(make_no_memory_error(18));
754 755 756 757 758 759
    }
  }
  else
  {
    /* The encoding name could not be found in the menu structure */

760
    RetError(choices_displayfield_set_value(0, destwind, CD_EncodingDisply, "Unknown encoding")); //
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 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
  }

  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];

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
  /* 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;
  }

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 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
  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
950
    if (tl & (1u<<29)) Printf("choices_colour_closed_handler: Colour DBox deleted\n");
951 952 953 954 955 956
  #endif

  return 1;
}

/*************************************************/
957
/* choices_colour_selected_handler()             */
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
/*                                               */
/* 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;
  }

983 984 985 986 987 988 989
  /* Don't bother with errors as colour display field might not exist */

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

  /* Don't bother with errors as fake page display might not exist */

  button_set_flags(0, idb->parent_id, CD_FakePage, 0, 0);
990 991 992 993 994

  return 1;
}

/*************************************************/
995
/* choices_colour_set_component()                */
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
/*                                               */
/* 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)
{
1010 1011 1012
  char            newvalidation[32];
  unsigned char * newcol;

1013 1014
  newcol = (unsigned char*)&colour;

1015
  sprintf(newvalidation, "R2;C/%02.2x%02.2x%02.2x", *(newcol + 3), *(newcol + 2), *(newcol + 1));
1016

1017
  return choices_button_set_validation(0, window, component, newvalidation);
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 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
}

/*************************************************/
/* 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;
}

/*************************************************/
1094
/* choices_save_m_button_handler()               */
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 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
/*                                               */
/* 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
1181
    if (tl & (1u<<29)) Printf("choices_set_display_field: Called\n");
1182 1183 1184 1185 1186 1187
  #endif

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

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

1188 1189
  tempstring = malloc(reqdsize + 1);
  if (!tempstring) return make_no_memory_error(19);
1190 1191 1192

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

1193
  e = choices_displayfield_set_value(0, obj, comp, tempstring);
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214

  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
1215
    if (tl & (1u<<29)) Printf("choices_set_display_field: Called\n");
1216 1217 1218 1219 1220 1221 1222
  #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);
1223
  if (!tempstring) return make_no_memory_error(20);
1224 1225 1226

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

1227
  e = choices_displayfield_set_value(0, obj, comp, tempstring);
1228 1229 1230 1231 1232 1233 1234 1235 1236

  free(tempstring);

  return e;
}

/*************************************************/
/* choices_display_m_click_handler()             */
/*                                               */
1237 1238 1239 1240 1241 1242 1243
/* Called when there is a selection in the       */
/* display menu.  Sets the selected menu item to */
/* be ticked, unticks the previously ticked      */
/* entry sets appropriate new_choices field and  */
/* updates the display field of the component    */
/* with component number 1 less than the menus   */
/* parent.                                       */
1244 1245 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
/*************************************************/

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()                */
/*                                               */
1273 1274 1275 1276 1277 1278 1279
/* Called when there is a selection in the save  */
/* menu.  Sets the selected menu item to be      */
/* ticked, unticks the previously ticked entry   */
/* sets appropriate new_choices field and        */
/* updates the display field of the component    */
/* with component number 1 less than the menus   */
/* parent.                                       */
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
/*************************************************/

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;
}
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 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 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 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

/*************************************************/
/* choices_draw_string()                         */
/*                                               */
/* Writes a string on the screen using the       */
/* passed font handle, it underlines the text if */
/* required.  It also returns the position to    */
/* paint the next string following this one.     */
/*                                               */
/* Parameters: font handle                       */
/*                                               */
/*             string to print                   */
/*                                               */
/*             xposition on screen (os coords)   */
/*                                               */
/*             yposition on screen (os coords)   */
/*                                               */
/*             0     - don't underline           */
/*             non 0 - underline                 */
/*                                               */
/*             foreground colour                 */
/*                                               */
/*             background colour                 */
/*                                               */
/*             pointer to int to return x        */
/*             position in                       */
/*************************************************/

static _kernel_oserror * choices_draw_string(fm_face h,
                                             char *string,
                                             int xpos,
                                             int ypos,
                                             int underline,
                                             int forecolour,
                                             int backcolour,
                                             int *newxpos)
{
  int width, nochars;
  fm_set_font_colour(h, forecolour, backcolour);
  fm_get_string_width(h, string, 0x1000000, strlen(string), -1, &nochars, &width);
  convert_to_os(width, &width);

  /* The next string must be plotted straight after this string */

  *newxpos = xpos + width;

  fm_puts(h, xpos, ypos, string, 1, 0);

  if (underline)
  {
    redraw_set_colour(forecolour);
    bbc_move(xpos, ypos - 7);
    bbc_draw(*newxpos, ypos - 7);
  }
  return NULL;
}

/*************************************************/
/* choices_write_crap()                          */
/*                                               */
/* Writes a string of readable rubbish on the    */
/* screen using the passed font handle.  It also */
/* returns the position to paint the next string */
/* following this one.                           */
/*                                               */
/* Parameters: font handle                       */
/*                                               */
/*             xposition on screen (os coords)   */
/*                                               */
/*             yposition on screen (os coords)   */
/*                                               */
/*             Approximate x position to stop    */
/*             printing at (os coords)           */
/*                                               */
/*             foreground colour                 */
/*                                               */
/*             background colour                 */
/*                                               */
/*             pointer to int to return x        */
/*             position in                       */
/*                                               */
/*             Random seed for string to print   */
/*             (If you pass the same seed the    */
/*             string should be the same)        */
/*************************************************/

static _kernel_oserror * choices_write_crap(fm_face h,
                                            int xpos,
                                            int ypos,
                                            int maxxish,
                                            int forecolour,
                                            int backcolour,
                                            int *newxpos,
                                            int seed)
{
  char ministring[5];
  int chars = 0;
  int spcwidth, width, nochars;

  fm_set_font_colour(h, forecolour, backcolour);

  srand(seed);

  fm_get_string_width(h, " ", 0x1000000, 1, -1, &nochars, &width);
  convert_to_os(width, &spcwidth);
  xpos += spcwidth;

  while(xpos < maxxish)
  {
    ministring[0] = consonant[rand()%sizeof(consonant)];
    ministring[1] = vowel[rand()%sizeof(vowel)];

    if (rand()%2)
    {
      ministring[2] = consonant[rand()%sizeof(consonant)];
      ministring[3] = vowel[rand()%sizeof(vowel)];
      ministring[4] = 0;
    }
    else
    {
      ministring[2] = 0;
    }

    fm_puts(h, xpos, ypos, ministring, 1, 0);
    fm_get_string_width(h, ministring, 0x1000000, strlen(ministring), -1, &nochars, &width);
    convert_to_os(width, &width);
    xpos += width;

    chars++;
    if (chars > rand()%2 || xpos >= maxxish)
    {
      chars = 0;
      xpos += spcwidth;
    }
  }

  *newxpos = xpos;
  return NULL;
}

/*************************************************/
/* choices_redraw_fakepage_handler()             */
/*                                               */
/* Redraws the fake page in the colour selection */
/* dbox.                                         */
/*************************************************/

static int choices_redraw_fakepage_handler(int eventcode, WimpPollBlock * event, IdBlock * idb, void * handle)
{
  _kernel_oserror       * e = NULL;
  WimpRedrawWindowBlock   block;
  WimpGetWindowStateBlock state;
1457
  int                     more, ypos, xtarget, ptsize, gadsize, xstart, nolines;
1458 1459 1460 1461
  int                     fontheight = 0;
  int                     gotfont    = 0;
  BBox                    icon_coords, fbox;
  fm_face                 h = 0;
1462
  char                    display_this[4];
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

  block.window_handle = event->redraw_window_request.window_handle;
  state.window_handle = event->redraw_window_request.window_handle;

  e = wimp_get_window_state(&state);
  show_error_ret(e);
  if (!e) e = gadget_get_bbox(0, idb->self_id, CD_FakePage, &icon_coords);

  gadsize = icon_coords.ymax - icon_coords.ymin;

  xstart = gadsize / 8;

  if (e)
  {
    /* Gadget doesn't exist or something strange happened trying */
    /* to get window state so just do a simple redraw loop to    */
    /* keep the wimp happy.                                      */

    ChkError(wimp_redraw_window(&block, &more));
    while (more && !e) e = wimp_get_rectangle(&block, &more);
    return 1;
  }

  coords_box_toscreen(&icon_coords, (WimpRedrawWindowBlock *) &state);

1488 1489 1490 1491 1492 1493
  /* Find out which lines to draw */

  for(nolines = 0; nolines < sizeof(display_this); nolines++) display_this[nolines] = 0;

  nolines = 1; /* Start with one line (half at top, half at bottom) */

1494
  if (choices_find_component(CD_LinkColourBt))
1495 1496 1497 1498
  {
    nolines ++;
    display_this[0] = 1;
  }
1499
  if (choices_find_component(CD_UsedColourBt))
1500 1501 1502 1503
  {
    nolines ++;
    display_this[1] = 1;
  }
1504
  if (choices_find_component(CD_FolwColourBt))
1505 1506 1507 1508
  {
    nolines ++;
    display_this[2] = 1;
  }
1509
  if (choices_find_component(CD_SlctColourBt))
1510 1511 1512 1513 1514
  {
    nolines ++;
    display_this[3] = 1;
  }

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
  /* Start the redraw loop */

  ChkError(wimp_redraw_window(&block, &more));

  while (more && !e)
  {
    /* Clip the redraw area to only take in the gadget */

    if (set_graphics_intersection(&icon_coords, &block.redraw_area))
    {
      /* Only claim the font if it is required */

      if (!gotfont)
      {
        /* Find default browser font, the font manager will return system */
        /* font if it is configured.                                      */

        /* Find a 1000 subpoint (big) version of default browser font to scale against */

        h = fm_find_font(NULL, "serif", 1000, 1000, 0, 0);
        ChkError(fm_font_box(h, &fbox));
        fm_lose_font(NULL, h);
        fontheight = fbox.ymax - fbox.ymin;

        /* Find a version of the default browser font with a */
        /* point size which will allow an appropriate number */
        /* of lines in the fake page display.                */

1543
        ptsize = ((gadsize * 1000 / nolines) / fontheight);
1544 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

        h = fm_find_font(NULL, "serif", ptsize, ptsize, 0, 0);
        ChkError(fm_font_box(h, &fbox));
        fontheight = fbox.ymax - fbox.ymin;
        gotfont = 1;
      }

      /* Fake browser drawing code is here */

      /* Fill background with background colour */

      redraw_set_colour(new_choices->background_colour);
      ChkError(bbc_rectanglefill(icon_coords.xmin, icon_coords.ymin, icon_coords.xmax - icon_coords.xmin, icon_coords.ymax - icon_coords.ymin));

      xtarget = icon_coords.xmin - 32;
      ypos = icon_coords.ymax - fontheight / 3;

      /* Display the top line of the fake page display */

      ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmax, new_choices->text_colour, new_choices->background_colour, &xtarget, 1));

      ypos -= fontheight;
      xtarget = icon_coords.xmin - 32;

      /* Display the new link line of the fake page display */

1570 1571 1572 1573 1574
      if (display_this[0])
      {
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmin+xstart, new_choices->text_colour, new_choices->background_colour, &xtarget, 2));
        ChkError(choices_draw_string(h, "new", xtarget, ypos, new_choices->underline_links, new_choices->link_colour, new_choices->background_colour, &xtarget));
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmax, new_choices->text_colour, new_choices->background_colour, &xtarget, 3));
1575

1576 1577 1578
        ypos -= fontheight;
        xtarget = icon_coords.xmin - 32;
      }
1579 1580 1581

      /* Display the new followed line of the fake page display */

1582 1583 1584 1585 1586
      if (display_this[1])
      {
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmin+xstart, new_choices->text_colour, new_choices->background_colour, &xtarget, 4));
        ChkError(choices_draw_string(h, "followed", xtarget, ypos, new_choices->underline_links, new_choices->used_colour, new_choices->background_colour, &xtarget));
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmax, new_choices->text_colour, new_choices->background_colour, &xtarget, 5));
1587

1588 1589 1590
        ypos -= fontheight;
        xtarget = icon_coords.xmin - 32;
      }
1591 1592 1593

      /* Display the highlighted link line of the fake page display */

1594 1595 1596 1597 1598
      if (display_this[2])
      {
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmin+xstart, new_choices->text_colour, new_choices->background_colour, &xtarget, 6));
        ChkError(choices_draw_string(h, "highlighted", xtarget, ypos, new_choices->underline_links, new_choices->followed_colour, new_choices->background_colour, &xtarget));
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmax, new_choices->text_colour, new_choices->background_colour, &xtarget, 7));
1599

1600 1601 1602
        ypos -= fontheight;
        xtarget = icon_coords.xmin - 32;
      }
1603 1604

      /* Display the selected link line of the fake page display */
1605 1606
      if (display_this[3])
      {
1607 1608 1609 1610 1611 1612
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmin+xstart, new_choices->text_colour, new_choices->background_colour, &xtarget, 12));
        ChkError(choices_draw_string(h, "selected", xtarget, ypos, new_choices->underline_links, new_choices->selected_colour, new_choices->background_colour, &xtarget));
        ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmax, new_choices->text_colour, new_choices->background_colour, &xtarget, 9));

        ypos -= fontheight;
        xtarget = icon_coords.xmin - 32;
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

      /* Display the bottom line of the fake page display */

      ChkError(choices_write_crap(h, xtarget, ypos, icon_coords.xmax, new_choices->text_colour, new_choices->background_colour, &xtarget, 10));
    }

    restore_graphics_intersection(&block.redraw_area);

    /* Get the next redraw rectangle */

    if (!e) e = wimp_get_rectangle(&block, &more);
  }

  if (gotfont) fm_lose_font(NULL, h);

  return 1;
}

/*************************************************/
/* choices_option_state_handler()                */
/*                                               */
/* Called when an option button has its state    */
/* changed by being clicked on.  Sets or unsets  */
/* the relevant flag in new_choices and causes   */
/* redraws where necessary.                      */
/*************************************************/

static int choices_option_state_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
1643 1644
  int      state;
  ObjectId window;
1645 1646 1647 1648 1649 1650 1651 1652
  ChkError(optionbutton_get_state(0, idb->self_id, idb->self_component, &state));

  switch(idb->self_component)
  {
    case CD_UnderlineLinks:
    {
      new_choices->underline_links = !!state;

1653
      /* Attempt to redraw fake page display */
1654

1655
      if ((window = choices_find_component(CD_FakePage)) != 0) button_set_flags(0, window, CD_FakePage, 0, 0);
1656 1657 1658 1659 1660 1661
      break;
    }

    case CD_UseDocColours:  new_choices->use_source_cols = !!state; break;
    case CD_ShowForeground: new_choices->show_foreground = !!state; break;
    case CD_ShowBackground: new_choices->show_background = !!state; break;
1662 1663 1664 1665 1666 1667

    case CD_URLBar:         new_choices->url_bar         = !!state; break;
    case CD_StatusBar:      new_choices->status_bar      = !!state; break;
    case CD_ButtonBar:      new_choices->button_bar      = !!state; break;
    case CD_FullScreen:     new_choices->full_screen     = !!state; break;

1668 1669 1670 1671
    case CD_ClientPull:     new_choices->client_pull     = !!state; break;
    case CD_NetscapeEmu:    new_choices->clone           = !!state; break;
    case CD_FramesSupport:  new_choices->support_frames  = !!state; break;

1672 1673 1674
    /* Haven't recognised this option button event so pass it on */

    default: return 0;
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
  }

  return 1;
}

/*************************************************/
/* choices_mode_change()                         */
/*                                               */
/* Called on every mode change event.  Records   */
/* that a mode change has taken place for use    */
/* with the choices_open_choice_window function. */
/*************************************************/

_kernel_oserror * choices_mode_change(void)
{
  choices_modechanged = 1;

  return NULL;
}

/*************************************************/
/* choices_open_choice_window()                  */
/*                                               */
/* Called whenever the choices window needs to   */
/* be moved and specifically on mode changes so  */
/* the current sub window can be positioned      */
/* correctly dealing with rounding errors        */
/* between modes of different aspect ratio.      */
/*************************************************/

static int choices_open_choice_window(int eventcode, WimpPollBlock * event, IdBlock * idb, void * handle)
{
  toolbox_show_object(0, idb->self_id, Toolbox_ShowObject_FullSpec, &(event->open_window_request.visible_area), 0, -1);

  if (choices_modechanged)
  {
1711 1712
    /* Reshow the subwindow at possibly new location */

1713 1714 1715 1716 1717 1718
    choices_show_subwindow(idb->self_id, current_subwindow);
    choices_modechanged = 0;
  }

  return 1;
}
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737

/*************************************************/
/* choices_find_component()                      */
/*                                               */
/* Scans all the choices subwindows for the      */
/* requested component and returns the id of the */
/* first window in which it was seen.            */
/*                                               */
/* Parameters: The component to find.            */
/*                                               */
/* Returns:    Where to return the object id to. */
/*             0 if the component was not found  */
/*************************************************/

static ObjectId choices_find_component(ComponentId component)
{
  int          findwindow;
  unsigned int flags;

1738 1739 1740
  /* Uses lazy evaluation to not call gadget_get_flags unless */
  /* subwindows[findwindow] contains an objectid.             */

1741
  for(findwindow = 0; findwindow < CDNoSubwindows; findwindow++)
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
    if (subwindows[findwindow] && !gadget_get_flags(0, subwindows[findwindow], component, &flags)) return subwindows[findwindow];

  return 0;
}

/*************************************************/
/* choices_writablefield_set_value()             */
/*                                               */
/* Does as writablefield_set_value but will only */
/* update it if the text is different to that    */
/* currently in the display field.               */
/*************************************************/

static _kernel_oserror *choices_writablefield_set_value(unsigned int flags, ObjectId window, ComponentId writable, char *text)
{
  int               reqdsize;
  char            * oldtext;
  _kernel_oserror * e;

  RetError(writablefield_get_value(0, window, writable, NULL, 0, &reqdsize));

  oldtext = malloc(reqdsize+1);
  if (!oldtext) return make_no_memory_error(100);

  writablefield_get_value(0, window, writable, oldtext, reqdsize, NULL);

  if (strcmp(text, oldtext))
1769
  {
1770
    e = writablefield_set_value(flags, window, writable, text);
1771 1772
  }

1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
  free(oldtext);

  return e;
}

/*************************************************/
/* choices_displayfield_set_value()              */
/*                                               */
/* Does as displayfield_set_value but will only  */
/* update it if the text is different to that    */
/* currently in the display field.               */
/*************************************************/

static _kernel_oserror *choices_displayfield_set_value(unsigned int flags, ObjectId window, ComponentId writable, char *text)
{
  int               reqdsize;
  char            * oldtext;
  _kernel_oserror * e;

  RetError(displayfield_get_value(0, window, writable, NULL, 0, &reqdsize));

  oldtext = malloc(reqdsize+1);
  if (!oldtext) return make_no_memory_error(100);

  displayfield_get_value(0, window, writable, oldtext, reqdsize, NULL);

  if (strcmp(text, oldtext))
  {
    e = displayfield_set_value(flags, window, writable, text);
  }

  free(oldtext);

  return e;
}

/*************************************************/
/* choices_button_set_validation()               */
/*                                               */
/* Does as button_set_validation but will only   */
/* update it if the text is different to that    */
/* currently in the button.                      */
/*************************************************/

static _kernel_oserror *choices_button_set_validation(unsigned int flags, ObjectId window, ComponentId writable, char *text)
{
  int               reqdsize;
  char            * oldtext;
  _kernel_oserror * e;

  RetError(button_get_validation(0, window, writable, NULL, 0, &reqdsize));

  oldtext = malloc(reqdsize+1);
  if (!oldtext) return make_no_memory_error(100);

  button_get_validation(0, window, writable, oldtext, reqdsize, NULL);

  if (strcmp(text, oldtext))
  {
    e = button_set_validation(flags, window, writable, text);
  }

  free(oldtext);

  return e;
}

/*************************************************/
/* choices_numberrange_set_value()               */
/*                                               */
/* Does as numberrange_set_value but will only   */
/* update it if the number is different to that  */
/* currently in the display.                     */
/*************************************************/

static _kernel_oserror *choices_numberrange_set_value(unsigned int flags, ObjectId window, ComponentId writable, int value)
{
  int               oldvalue;
  _kernel_oserror * e;

  RetError(numberrange_get_value(0, window, writable, &oldvalue));

  if (oldvalue != value)
  {
    e = numberrange_set_value(flags, window, writable, value);
  }

  return e;
1861
}