diff --git a/c/Choices b/c/Choices index 805108b4e71febaf071612dea76a59ddfea12c8a..6efd8bda81254a6f24ea8a063ad3b645fc5573a2 100644 --- a/c/Choices +++ b/c/Choices @@ -102,6 +102,11 @@ static _kernel_oserror * choices_set_save_field (ObjectId obj, Componen static _kernel_oserror * choices_set_display_field (ObjectId obj, ComponentId comp, int state); static ObjectId choices_find_component (ComponentId component); +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); + /*************************************************/ /* choices_show_subwindow() */ /* */ @@ -467,14 +472,14 @@ static _kernel_oserror * choices_set_contents(void) ObjectId window; /* No error handling here, as we want to allow items to be missing */ - if ((window = choices_find_component(CD_Homepage)) != 0) writablefield_set_value(0, window, CD_Homepage, new_choices->home_page); + if ((window = choices_find_component(CD_Homepage)) != 0) choices_writablefield_set_value(0, window, CD_Homepage, new_choices->home_page); 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); /* Get encoding name */ - choices_set_encoding_field(); // + choices_set_encoding_field(); 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); @@ -488,13 +493,13 @@ static _kernel_oserror * choices_set_contents(void) 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); - if ((window = choices_find_component(CD_HlAutoOpen)) != 0) numberrange_set_value(0, window, CD_HlAutoOpen, new_choices->auto_open_delay); - if ((window = choices_find_component(CD_HlAutoScroll)) != 0) numberrange_set_value(0, window, CD_HlAutoScroll, new_choices->auto_scroll_delay); + 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); 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); - if ((window = choices_find_component(CD_HiLines)) != 0) numberrange_set_value(0, window, CD_HiLines, new_choices->v_hist_size); - if ((window = choices_find_component(CD_HiMaxSize)) != 0) numberrange_set_value(0, window, CD_HiMaxSize, new_choices->g_hist_size); + 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); if ((window = choices_find_component(CD_HiDispDisp)) != 0) choices_set_display_field(window, CD_HiDispDisp, new_choices->show_urls); if ((window = choices_find_component(CD_HiSaveDisp)) != 0) choices_set_save_field( window, CD_HiSaveDisp, new_choices->save_history); @@ -631,8 +636,23 @@ static int choices_set_button_handler(int eventcode, ToolboxEvent * event, IdBlo static int choices_cancel_button_handler(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle) { - _kernel_oserror *e = NULL; ObjectId window; + 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; + } memcpy(new_choices, &choices, sizeof(global_choices)); @@ -640,9 +660,7 @@ static int choices_cancel_button_handler(int eventcode, ToolboxEvent * event, Id /* Attempt to redraw fake page display */ - if ((window = choices_find_component(CD_FakePage)) != 0) button_set_flags(0, window, CD_FakePage, 0, 0); - - if (e) show_error_ret(e); + if (update_fake && (window = choices_find_component(CD_FakePage)) != 0) button_set_flags(0, window, CD_FakePage, 0, 0); return 1; } @@ -724,13 +742,11 @@ _kernel_oserror * choices_set_encoding_field(void) free(textptr); return e; } - e = displayfield_set_value(0, destwind, CD_EncodingDisply, textptr); + + e = choices_displayfield_set_value(0, destwind, CD_EncodingDisply, textptr); free(textptr); - if (e) - { - return e; - } + return e; } else { @@ -741,7 +757,7 @@ _kernel_oserror * choices_set_encoding_field(void) { /* The encoding name could not be found in the menu structure */ - RetError(displayfield_set_value(0, destwind, CD_EncodingDisply, "Unknown encoding")); // + RetError(choices_displayfield_set_value(0, destwind, CD_EncodingDisply, "Unknown encoding")); // } return NULL; @@ -998,7 +1014,7 @@ static _kernel_oserror *choices_colour_set_component(ObjectId window, ComponentI sprintf(newvalidation, "R2;C/%02.2x%02.2x%02.2x", *(newcol + 3), *(newcol + 2), *(newcol + 1)); - return button_set_validation(0, window, component, newvalidation); + return choices_button_set_validation(0, window, component, newvalidation); } /*************************************************/ @@ -1174,7 +1190,7 @@ static _kernel_oserror * choices_set_save_field(ObjectId obj, ComponentId comp, RetError(menu_get_entry_text(0, menu_id, state, tempstring, reqdsize+1, NULL)); - e = displayfield_set_value(0, obj, comp, tempstring); + e = choices_displayfield_set_value(0, obj, comp, tempstring); free(tempstring); @@ -1208,7 +1224,7 @@ static _kernel_oserror * choices_set_display_field(ObjectId obj, ComponentId com RetError(menu_get_entry_text(0, menu_id, state, tempstring, reqdsize+1, NULL)); - e = displayfield_set_value(0, obj, comp, tempstring); + e = choices_displayfield_set_value(0, obj, comp, tempstring); free(tempstring); @@ -1692,6 +1708,8 @@ static int choices_open_choice_window(int eventcode, WimpPollBlock * event, IdBl if (choices_modechanged) { + /* Reshow the subwindow at possibly new location */ + choices_show_subwindow(idb->self_id, current_subwindow); choices_modechanged = 0; } @@ -1717,13 +1735,127 @@ static ObjectId choices_find_component(ComponentId component) int findwindow; unsigned int flags; + /* Uses lazy evaluation to not call gadget_get_flags unless */ + /* subwindows[findwindow] contains an objectid. */ + for(findwindow = 0; findwindow < CDNoSubwindows; findwindow++) + 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)) { - if (subwindows[findwindow]) - { - if (!gadget_get_flags(0, subwindows[findwindow], component, &flags)) return subwindows[findwindow]; - } + e = writablefield_set_value(flags, window, writable, text); } - return 0; + 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; }