diff options
author | Steve Fryatt <steve@stevefryatt.org.uk> | 2011-02-20 23:16:33 +0000 |
---|---|---|
committer | Steve Fryatt <steve@stevefryatt.org.uk> | 2011-02-20 23:16:33 +0000 |
commit | cd9c0998e9849472473e577c4c04906e380896e1 (patch) | |
tree | 9bef19ebd3d56eccd03fa5613f1506c82762584b /riscos/gui | |
parent | f54fc080c2a96ffdb713a9c8b5d0ccb604197c07 (diff) | |
download | netsurf-cd9c0998e9849472473e577c4c04906e380896e1.tar.gz netsurf-cd9c0998e9849472473e577c4c04906e380896e1.tar.bz2 |
Merge branches/stevef/toolbars to trunk.
svn path=/trunk/netsurf/; revision=11741
Diffstat (limited to 'riscos/gui')
-rw-r--r-- | riscos/gui/button_bar.c | 1231 | ||||
-rw-r--r-- | riscos/gui/button_bar.h | 314 | ||||
-rw-r--r-- | riscos/gui/throbber.c | 419 | ||||
-rw-r--r-- | riscos/gui/throbber.h | 144 | ||||
-rw-r--r-- | riscos/gui/url_bar.c | 984 | ||||
-rw-r--r-- | riscos/gui/url_bar.h | 302 |
6 files changed, 3394 insertions, 0 deletions
diff --git a/riscos/gui/button_bar.c b/riscos/gui/button_bar.c new file mode 100644 index 000000000..00e357457 --- /dev/null +++ b/riscos/gui/button_bar.c @@ -0,0 +1,1231 @@ +/* + * Copyright 2004, 2005 Richard Wilson <info@tinct.net> + * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * Button bars (implementation). + */ + +#include <assert.h> +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include "oslib/dragasprite.h" +#include "oslib/os.h" +#include "oslib/osspriteop.h" +#include "oslib/wimp.h" +#include "oslib/wimpspriteop.h" +#include "riscos/gui/button_bar.h" +#include "riscos/gui.h" +#include "riscos/theme.h" +#include "riscos/wimp.h" +#include "utils/log.h" +#include "utils/utils.h" + +#define BUTTONBAR_SPRITE_NAME_LENGTH 12 +#define BUTTONBAR_VALIDATION_LENGTH 40 + +struct button_bar_button { + wimp_i icon; + bool shaded; + bool separator; + + button_bar_action select_action; + button_bar_action adjust_action; + + int x_pos, y_pos; + int x_size, y_size; + + char sprite[BUTTONBAR_SPRITE_NAME_LENGTH]; + char validation[BUTTONBAR_VALIDATION_LENGTH]; + char opt_key; + const char *help_suffix; + + struct button_bar_button *bar_next; + struct button_bar_button *next; +}; + + +struct button_bar { + /** The applied theme (or NULL to use the default) */ + struct theme_descriptor *theme; + + /** The widget dimensions. */ + int x_min, y_min; + int separator_width; + int vertical_offset; + + bool separators; + + /** The window details and bar position. */ + wimp_w window; + os_box extent; + osspriteop_area *sprites; + int background; + + bool hidden; + + bool edit; + struct button_bar *edit_target; + struct button_bar *edit_source; + void (*edit_refresh)(void *); + void *edit_client_data; + + /** The list of all the defined buttons. */ + + struct button_bar_button *buttons; + + /** The list of the buttons in the current bar. */ + + struct button_bar_button *bar; +}; + +static char null_text_string[] = ""; +static char separator_name[] = "separator"; + +static struct button_bar *drag_start = NULL; +static char drag_opt = '\0'; +static bool drag_separator = false; + +/* + * Private function prototypes. + */ + +static bool ro_gui_button_bar_place_buttons(struct button_bar *button_bar); +static bool ro_gui_button_bar_icon_update(struct button_bar *button_bar); +static bool ro_gui_button_bar_icon_resize(struct button_bar *button_bar); +static void ro_gui_button_bar_sync_editors(struct button_bar *target, + struct button_bar *source); +static struct button_bar_button *ro_gui_button_bar_find_icon( + struct button_bar *button_bar, wimp_i icon); +static struct button_bar_button *ro_gui_button_bar_find_opt_key( + struct button_bar *button_bar, char opt_key); +static struct button_bar_button *ro_gui_button_bar_find_action( + struct button_bar *button_bar, button_bar_action action); +static struct button_bar_button *ro_gui_button_bar_find_coords( + struct button_bar *button_bar, os_coord pos, + bool *separator, bool *right); + +/* This is an exported interface documented in button_bar.h */ + +struct button_bar *ro_gui_button_bar_create(struct theme_descriptor *theme, + const struct button_bar_buttons buttons[]) +{ + struct button_bar *button_bar; + struct button_bar_button *icon, *new_icon; + bool failed; + int def; + + /* Allocate memory. */ + + button_bar = malloc(sizeof(struct button_bar)); + if (button_bar == NULL) { + LOG(("No memory for malloc()")); + return NULL; + } + + /* Set up default parameters. */ + + button_bar->theme = theme; + button_bar->sprites = ro_gui_theme_get_sprites(theme); + button_bar->background = wimp_COLOUR_VERY_LIGHT_GREY; + + button_bar->x_min = -1; + button_bar->y_min = -1; + button_bar->separator_width = 0; + button_bar->vertical_offset = 0; + + button_bar->separators = false; + + button_bar->window = NULL; + + button_bar->hidden = false; + + button_bar->edit = false; + button_bar->edit_target = NULL; + button_bar->edit_source = NULL; + button_bar->edit_refresh = NULL; + button_bar->edit_client_data = NULL; + + button_bar->buttons = NULL; + + /* Process the button icon definitions */ + + icon = NULL; + failed = false; + + for (def = 0; buttons[def].icon != NULL; def++) { + new_icon = malloc(sizeof(struct button_bar_button)); + if (new_icon == NULL) { + failed = true; + break; + } + + if (icon == NULL) { + button_bar->buttons = new_icon; + button_bar->bar = new_icon; + } else { + icon->next = new_icon; + icon->bar_next = new_icon; + } + icon = new_icon; + icon->next = NULL; + icon->bar_next = NULL; + + strncpy(icon->sprite, buttons[def].icon, + BUTTONBAR_SPRITE_NAME_LENGTH); + snprintf(icon->validation, BUTTONBAR_VALIDATION_LENGTH, + "R5;S%s,p%s", icon->sprite, icon->sprite); + + icon->icon = -1; + icon->shaded = false; + icon->separator = false; + + icon->select_action = buttons[def].select; + icon->adjust_action = buttons[def].adjust; + icon->opt_key = buttons[def].opt_key; + icon->help_suffix = buttons[def].help; + } + + /* Add a separator after the last entry. This will be lost if the + * buttons are subsequently set, but is used for the edit source bar. + */ + + if (icon != NULL) + icon->separator = true; + + return button_bar; +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_link_editor(struct button_bar *target, + struct button_bar *source, void (* refresh)(void *), + void *client_data) +{ + if (target == NULL || source == NULL || + target->edit_target != NULL || + target->edit_source != NULL || + source->edit_target != NULL || + source->edit_source != NULL) + return false; + + target->edit_source = source; + source->edit_target = target; + + /* Store the callback data in the editor bar. */ + + source->edit_refresh = refresh; + source->edit_client_data = client_data; + + return true; +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_rebuild(struct button_bar *button_bar, + struct theme_descriptor *theme, theme_style style, + wimp_w window, bool edit) +{ + struct button_bar_button *button; + os_error *error; + int height; + + + if (button_bar == NULL) + return false; + + button_bar->theme = theme; + button_bar->window = window; + button_bar->sprites = ro_gui_theme_get_sprites(theme); + button_bar->background = ro_gui_theme_get_style_element(theme, style, + THEME_ELEMENT_BACKGROUND); + + button_bar->edit = edit; + + height = 0; + button_bar->separator_width = 16; + ro_gui_wimp_get_sprite_dimensions(button_bar->sprites, separator_name, + &button_bar->separator_width, &height); + + /* If the separator height is 0, then either the sprite really is + * zero pixels high or the default was used as no sprite was found. + * Either way, we don't have a separator. + */ + + button_bar->separators = (height == 0) ? false : true; + + button = button_bar->buttons; + error = NULL; + + while (button != NULL) { + button->x_size = 0; + button->y_size = 0; + button->icon = -1; + + ro_gui_wimp_get_sprite_dimensions(button_bar->sprites, + button->sprite, + &button->x_size, &button->y_size); + + button = button->next; + } + + if (!ro_gui_button_bar_place_buttons(button_bar)) + return false; + + if (button_bar->edit && button_bar->edit_target != NULL) + ro_gui_button_bar_sync_editors(button_bar->edit_target, + button_bar); + + return ro_gui_button_bar_icon_update(button_bar); +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_arrange_buttons(struct button_bar *button_bar, + char order[]) +{ + struct button_bar_button *button, *new; + int i; + + if (button_bar == NULL || order == NULL) + return false; + + /* Delete any existing button arrangement. */ + + button_bar->bar = NULL; + + for (button = button_bar->buttons; button != NULL; + button = button->next) { + button->bar_next = NULL; + button->separator = false; + } + + /* Parse the config string and link up the new buttons. */ + + button = NULL; + + for (i = 0; order[i] != '\0'; i++) { + if (order[i] != '|') { + new = ro_gui_button_bar_find_opt_key(button_bar, + order[i]); + + if (new != NULL) { + if (button == NULL) + button_bar->bar = new; + else + button->bar_next = new; + + button = new; + } + } else { + if (button != NULL) + button->separator = true; + } + } + + if (!ro_gui_button_bar_place_buttons(button_bar)) + return false; + + return ro_gui_button_bar_place_buttons(button_bar); +} + +/** + * Place the buttons on a button bar, taking into account the button arrangement + * and the current theme, and update the bar extent details. + * + * \param *button_bar The button bar to update. + * \return true if successful; else false. + */ + +bool ro_gui_button_bar_place_buttons(struct button_bar *button_bar) +{ + struct button_bar_button *button; + int x_pos, y_pos, height; + + if (button_bar == NULL) + return false; + + button = button_bar->bar; + x_pos = 0; + y_pos = 0; + height = 0; + + while (button != NULL) { + button->x_pos = x_pos; + button->y_pos = y_pos; + + x_pos += button->x_size; + if (button->separator) + x_pos += button_bar->separator_width; + + if (button->y_size > height) + height = button->y_size; + + button = button->bar_next; + } + + button_bar->x_min = x_pos; + button_bar->y_min = height; + + return true; +} + + +/* This is an exported interface documented in button_bar.h */ + +void ro_gui_button_bar_destroy(struct button_bar *button_bar) +{ + struct button_bar_button *button; + + if (button_bar == NULL) + return; + + /* Free the button definitions. */ + + while (button_bar->buttons != NULL) { + button = button_bar->buttons; + button_bar->buttons = button->next; + free(button); + } + + free(button_bar); +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_get_dims(struct button_bar *button_bar, + int *width, int *height) +{ + if (button_bar == NULL) + return false; + + if (button_bar->x_min != -1 && button_bar->y_min != -1) { + if (width != NULL) + *width = button_bar->x_min; + if (height != NULL) + *height = button_bar->y_min; + + return true; + } + + return false; +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_set_extent(struct button_bar *button_bar, + int x0, int y0, int x1, int y1) +{ + if (button_bar == NULL) + return false; + + if ((x1 - x0) < button_bar->x_min || (y1 - y0) < button_bar->y_min) + return false; + + if (button_bar->extent.x0 == x0 && button_bar->extent.y0 == y0 && + button_bar->extent.x1 == x1 && + button_bar->extent.y1 == y1) + return true; + + /* Redraw the relevant bits of the toolbar. We can't optimise for + * stretching the X-extent, as this probably means the button + * arrangement has changed which necessitates a full redraw anyway. + */ + + if (button_bar->window != NULL) { + xwimp_force_redraw(button_bar->window, + button_bar->extent.x0, button_bar->extent.y0, + button_bar->extent.x1, button_bar->extent.y1); + xwimp_force_redraw(button_bar->window, x0, y0, x1, y1); + } + + button_bar->extent.x0 = x0; + button_bar->extent.y0 = y0; + button_bar->extent.x1 = x1; + button_bar->extent.y1 = y1; + + if ((y1 - y0) > button_bar->y_min) + button_bar->vertical_offset = + ((y1 - y0) - button_bar->y_min) / 2; + else + button_bar->vertical_offset = 0; + + return ro_gui_button_bar_icon_resize(button_bar); +} + + +/** + * Update the icons on a button bar, creating or deleting them from the window + * as necessary. + */ + +bool ro_gui_button_bar_icon_update(struct button_bar *button_bar) +{ + wimp_icon_create icon; + struct button_bar_button *button, *b; + os_error *error; + bool on_bar; + + + if (button_bar == NULL || button_bar->window == NULL) + return (button_bar == NULL) ? false : true; + + button = button_bar->buttons; + + while (button != NULL) { + on_bar = false; + + /* Check if the icon is currently on the bar. */ + + for (b = button_bar->bar; b != NULL; b = b->bar_next) { + if (b == button) { + on_bar = true; + break; + } + } + + if (on_bar && !button_bar->hidden && button->icon == -1) { + icon.w = button_bar->window; + icon.icon.extent.x0 = 0; + icon.icon.extent.y0 = 0; + icon.icon.extent.x1 = 0; + icon.icon.extent.y1 = 0; + icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE | + wimp_ICON_INDIRECTED | + wimp_ICON_HCENTRED | + wimp_ICON_VCENTRED | + (button_bar->background + << wimp_ICON_BG_COLOUR_SHIFT); + icon.icon.data.indirected_text.size = 1; + + /* We don't actually shade buttons unless there's no + * editor active or this is the source bar. + */ + + if (button->shaded && (!button_bar->edit || + button_bar->edit_target != NULL)) + icon.icon.flags |= wimp_ICON_SHADED; + + if (button_bar->edit) + icon.icon.flags |= (wimp_BUTTON_CLICK_DRAG << + wimp_ICON_BUTTON_TYPE_SHIFT); + else + icon.icon.flags |= (wimp_BUTTON_CLICK << + wimp_ICON_BUTTON_TYPE_SHIFT); + + icon.icon.data.indirected_text.text = null_text_string; + icon.icon.data.indirected_text.validation = + button->validation; + + error = xwimp_create_icon(&icon, &button->icon); + if (error) { + LOG(("xwimp_create_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + button->icon = -1; + return false; + } + } else if ((!on_bar || button_bar->hidden) + && button->icon != -1) { + error = xwimp_delete_icon(button_bar->window, + button->icon); + if (error != NULL) { + LOG(("xwimp_delete_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + button->icon = -1; + } + + button = button->next; + } + + return ro_gui_button_bar_icon_resize(button_bar); +} + + +/** + * Position the icons in the button bar to take account of the currently + * configured extent. + * + * \param *button_bar The button bar to update. + * \return true if successful; else false. + */ + +bool ro_gui_button_bar_icon_resize(struct button_bar *button_bar) +{ + os_error *error; + struct button_bar_button *button; + + if (button_bar == NULL || button_bar->hidden) + return (button_bar == NULL) ? false : true; + + /* Reposition all the icons. */ + + button = button_bar->bar; + + while (button != NULL) { + if(button->icon != -1) { + error = xwimp_resize_icon(button_bar->window, + button->icon, + button_bar->extent.x0 + button->x_pos, + button_bar->extent.y0 + + button_bar->vertical_offset + + button->y_pos, + button_bar->extent.x0 + button->x_pos + + button->x_size, + button_bar->extent.y0 + + button_bar->vertical_offset + + button->y_pos + + button->y_size); + if (error != NULL) { + LOG(("xwimp_resize_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + button->icon = -1; + return false; + } + } + + button = button->bar_next; + } + + return true; +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_hide(struct button_bar *button_bar, bool hide) +{ + if (button_bar == NULL || button_bar->hidden == hide) + return (button_bar == NULL) ? false : true; + + button_bar->hidden = hide; + + return ro_gui_button_bar_icon_update(button_bar); +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_shade_button(struct button_bar *button_bar, + button_bar_action action, bool shaded) +{ + struct button_bar_button *button; + + if (button_bar == NULL) + return false; + + button = ro_gui_button_bar_find_action(button_bar, action); + if (button == NULL) + return false; + + if (button->shaded == shaded) + return true; + + button->shaded = shaded; + + /* We don't actually shade buttons unless there's no editor active + * or this is the source bar. + */ + + if (button->icon != -1 && + (!button_bar->edit || button_bar->edit_target != NULL)) + ro_gui_set_icon_shaded_state(button_bar->window, button->icon, + shaded); + + return true; +} + + +/* This is an exported interface documented in button_bar.h */ + +void ro_gui_button_bar_redraw(struct button_bar *button_bar, + wimp_draw *redraw) +{ + wimp_icon icon; + struct button_bar_button *button; + + /* Test for a valid button bar, and then check that the redraw box + * coincides with the bar's extent. + */ + + if (button_bar == NULL || button_bar->hidden || + (redraw->clip.x0 - (redraw->box.x0 - redraw->xscroll)) + > button_bar->extent.x1 || + (redraw->clip.y0 - (redraw->box.y1 - redraw->yscroll)) + > button_bar->extent.y1 || + (redraw->clip.x1 - (redraw->box.x0 - redraw->xscroll)) + < button_bar->extent.x0 || + (redraw->clip.y1 - (redraw->box.y1 - redraw->yscroll)) + < button_bar->extent.y0 || + (!button_bar->edit && !button_bar->separators)) + return; + + icon.flags = wimp_ICON_SPRITE | wimp_ICON_INDIRECTED | + wimp_ICON_HCENTRED | wimp_ICON_VCENTRED; + if (button_bar->edit) + icon.flags |= wimp_ICON_BORDER | wimp_COLOUR_DARK_GREY << + wimp_ICON_FG_COLOUR_SHIFT; + if (!button_bar->separators) + icon.flags |= wimp_ICON_FILLED | wimp_COLOUR_LIGHT_GREY << + wimp_ICON_BG_COLOUR_SHIFT; + icon.data.indirected_sprite.id = (osspriteop_id) separator_name; + icon.data.indirected_sprite.area = button_bar->sprites; + icon.data.indirected_sprite.size = 12; + icon.extent.y0 = button_bar->extent.y0 + button_bar->vertical_offset; + icon.extent.y1 = icon.extent.y0 + button_bar->y_min; + + for (button = button_bar->bar; button != NULL; + button = button->bar_next) { + if (button->separator) { + icon.extent.x0 = button_bar->extent.x0 + + button->x_pos + button->x_size; + icon.extent.x1 = icon.extent.x0 + + button_bar->separator_width; + xwimp_plot_icon(&icon); + } + } +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_click(struct button_bar *button_bar, + wimp_pointer *pointer, wimp_window_state *state, + button_bar_action *action) +{ + struct button_bar_button *button; + os_coord pos; + os_box box; + os_error *error; + char *sprite; + + if (button_bar == NULL || button_bar->hidden) + return false; + + /* Check that the click was within our part of the window. */ + + pos.x = pointer->pos.x - state->visible.x0 + state->xscroll; + pos.y = pointer->pos.y - state->visible.y1 + state->yscroll; + + if (pos.x < button_bar->extent.x0 || pos.x > button_bar->extent.x1 || + pos.y < button_bar->extent.y0 || + pos.y > button_bar->extent.y1) + return false; + + if (button_bar->edit && pointer->buttons == wimp_DRAG_SELECT) { + /* This is an editor click, so we need to check for drags on + * icons (buttons) and work area (separators). + */ + + button = ro_gui_button_bar_find_coords(button_bar, pos, + &drag_separator, NULL); + + if (button != NULL && (!button->shaded || drag_separator || + button_bar->edit_source != NULL)) { + gui_current_drag_type = GUI_DRAG_BUTTONBAR; + + drag_start = button_bar; + drag_opt = button->opt_key; + + if (drag_separator) { + box.x0 = pointer->pos.x - + button_bar->separator_width / 2; + box.x1 = box.x0 + button_bar->separator_width; + sprite = separator_name; + } else { + box.x0 = pointer->pos.x - button->x_size / 2; + box.x1 = box.x0 + button->x_size; + sprite = button->sprite; + } + + box.y0 = pointer->pos.y - button->y_size / 2; + box.y1 = box.y0 + button->y_size; + + error = xdragasprite_start(dragasprite_HPOS_CENTRE | + dragasprite_VPOS_CENTRE | + dragasprite_BOUND_SPRITE | + dragasprite_BOUND_TO_WINDOW | + dragasprite_DROP_SHADOW, + button_bar->sprites, + sprite, &box, NULL); + if (error) + LOG(("xdragasprite_start: 0x%x: %s", + error->errnum, error->errmess)); + + return true; + } + + } else if (!button_bar->edit && pointer->i != -1 && + (pointer->buttons == wimp_CLICK_SELECT || + pointer->buttons == wimp_CLICK_ADJUST)) { + /* This isn't an editor click, so we're only interested in + * Select or Adjust clicks that occur on physical icons. + */ + + button = ro_gui_button_bar_find_icon(button_bar, pointer->i); + + if (button != NULL) { + if (action != NULL) { + switch (pointer->buttons) { + case wimp_CLICK_SELECT: + *action = button->select_action; + break; + case wimp_CLICK_ADJUST: + *action = button->adjust_action; + break; + default: + break; + } + } + return true; + } + } + + return false; +} + + +/* This is an exported interface documented in button_bar.h */ + +bool ro_gui_button_bar_help_suffix(struct button_bar *button_bar, wimp_i i, + os_coord *mouse, wimp_window_state *state, + wimp_mouse_state buttons, const char **suffix) +{ + os_coord pos; + struct button_bar_button *button; + + if (button_bar == NULL || button_bar->hidden) + return false; + + /* Check that the click was within our part of the window. */ + + pos.x = mouse->x - state->visible.x0 + state->xscroll; + pos.y = mouse->y - state->visible.y1 + state->yscroll; + + if (pos.x < button_bar->extent.x0 || pos.x > button_bar->extent.x1 || + pos.y < button_bar->extent.y0 || + pos.y > button_bar->extent.y1) + return false; + + /* Look up and return the help suffix assocuated with the button. */ + + button = ro_gui_button_bar_find_icon(button_bar, i); + + if (button != NULL) + *suffix = button->help_suffix; + else + *suffix = ""; + + return true; +} + + +/* This is an exported interface documented in button_bar.h */ + +void ro_gui_button_bar_drag_end(wimp_dragged *drag) +{ + struct button_bar *drag_end = NULL; + struct button_bar *source = NULL, *target = NULL; + struct button_bar_button *button, *drop, *previous; + bool right, separator; + wimp_window_state state; + wimp_pointer pointer; + os_coord pos; + os_error *error; + + xdragasprite_stop(); + gui_current_drag_type = GUI_DRAG_NONE; + + if (drag_start == NULL) + return; + + /* Sort out the window coordinates of the drag end. */ + + error = xwimp_get_pointer_info(&pointer); + if (error) { + LOG(("xwimp_get_pointer_info: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + + assert(pointer.w = drag_start->window); + + state.w = drag_start->window; + error = xwimp_get_window_state(&state); + if (error) { + LOG(("xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + + pos.x = pointer.pos.x - state.visible.x0 + state.xscroll; + pos.y = pointer.pos.y - state.visible.y1 + state.yscroll; + + /* Work out the destination bar, and establish source and target. */ + + if (drag_start->edit_target != NULL) { + source = drag_start; + target = drag_start->edit_target; + if (pos.x >= target->extent.x0 && pos.x <= target->extent.x1 && + pos.y >= target->extent.y0 && + pos.y <= target->extent.y1) + drag_end = target; + } else if (drag_start->edit_source != NULL) { + source = drag_start->edit_source; + target = drag_start; + if (pos.x >= target->extent.x0 && pos.x <= target->extent.x1 && + pos.y >= target->extent.y0 && + pos.y <= target->extent.y1) + drag_end = target; + /* drag_end == source and drag_end == NULL are both equivalent + * as far as the following code are concerned, and we don't need + * to identify either case. */ + } + + button = ro_gui_button_bar_find_opt_key(target, drag_opt); + assert(button != NULL); + + /* The drag finished in the target bar, so find out where. */ + + if (drag_end == target) { + drop = ro_gui_button_bar_find_coords(target, pos, + &separator, &right); + } else { + drop = NULL; + } + + /* If the button is dropped on itself, there's no change and it's + * less messy to get out now. + */ + + if (drag_start == target && drag_end == target && button == drop) { + drag_start = NULL; + return; + } + + /* The drag started in the target bar, so remove the dragged button. */ + + if (drag_start == target) { + if (drag_separator) { + button->separator = false; + } else if (target->bar == button) { + target->bar = button->bar_next; + } else { + for (previous = target->bar; previous != NULL && + previous->bar_next != button; + previous = previous->bar_next); + assert(previous != NULL); + previous->bar_next = button->bar_next; + if (button->separator) // ?? + previous->separator = true; // ?? + } + } + + /* The drag ended in the target bar, so add the dragged button in. */ + + if (drop != NULL) { + if (right) { + if (drag_separator) { + drop->separator = true; + } else { + button->bar_next = drop->bar_next; + drop->bar_next = button; + if (drop->separator && !separator) { + drop->separator = false; + button->separator = true; + } else { + button->separator = false; + } + } + } else if (target->bar == drop && !drag_separator) { + button->separator = false; + button->bar_next = target->bar; + target->bar = button; + } else if (target->bar != drop) { + for (previous = target->bar; previous != NULL && + previous->bar_next != drop; + previous = previous->bar_next); + assert(previous != NULL); + + if (drag_separator) { + previous->separator = true; + } else { + if (separator) { + previous->separator = false; + button->separator = true; + } else { + button->separator = false; + } + button->bar_next = previous->bar_next; + previous->bar_next = button; + } + } + } + + /* Reposition the buttons and force our client to update. */ + + ro_gui_button_bar_place_buttons(target); + ro_gui_button_bar_icon_update(target); + ro_gui_button_bar_sync_editors(target, source); + + xwimp_force_redraw(target->window, + target->extent.x0, target->extent.y0, + target->extent.x1, target->extent.y1); + + if (source->edit_refresh != NULL) + source->edit_refresh(source->edit_client_data); + + drag_start = NULL; +} + + +/** + * Synchronise the shading of a button bar editor source bar with the currently + * defined buttons in its target bar. + * + * \param *target The editor target bar. + * \param *source The editor source bar. + */ + +void ro_gui_button_bar_sync_editors(struct button_bar *target, + struct button_bar *source) +{ + struct button_bar_button *sb, *tb; + + if (source == NULL || target == NULL) + return; + + /* Unshade all of the buttons in the source bar. */ + + for (sb = source->bar; sb != NULL; sb = sb->bar_next) + sb->shaded = false; + + /* Step through the target bar and shade each corresponding + * button in the source. + */ + + for (tb = target->bar; tb != NULL; tb = tb->bar_next) { + sb = ro_gui_button_bar_find_opt_key(source, tb->opt_key); + + if (sb != NULL) + sb->shaded = true; + } + + /* Phyically shade the necessary buttons in the toolbar. */ + + for (sb = source->bar; sb != NULL; sb = sb->bar_next) + if (sb->icon != -1) + ro_gui_set_icon_shaded_state(source->window, sb->icon, + sb->shaded); +} + + +/* This is an exported interface documented in button_bar.h */ + +char *ro_gui_button_bar_get_config(struct button_bar *button_bar) +{ + struct button_bar_button *button; + size_t size; + char *config; + int i; + + if (button_bar == NULL) + return NULL; + + for (size = 1, button = button_bar->bar; button != NULL; + button = button->bar_next) { + size++; + if (button->separator) + size++; + } + + config = malloc(size); + if (config == NULL) { + LOG(("No memory for malloc()")); + warn_user("NoMemory", 0); + return NULL; + } + + for (i = 0, button = button_bar->bar; button != NULL; + button = button->bar_next) { + config[i++] = button->opt_key; + if (button->separator) + config[i++] = '|'; + } + + config[i] = '\0'; + + return config; +} + + +/** + * Find a button bar icon definition from an icon handle. + * + * \param *button_bar The button bar to use. + * \param icon The icon handle. + * \return Pointer to the button bar icon, or NULL. + */ + +struct button_bar_button *ro_gui_button_bar_find_icon( + struct button_bar *button_bar, wimp_i icon) +{ + struct button_bar_button *button; + + if (button_bar == NULL || icon == -1) + return NULL; + + button = button_bar->buttons; + + while (button != NULL && button->icon != icon) + button = button->next; + + return button; +} + + +/** + * Find a button bar icon definition from an options key code. + * + * \param *button_bar The button bar to use. + * \param opt_key The option key character code. + * \return Pointer to the button bar icon, or NULL. + */ + +struct button_bar_button *ro_gui_button_bar_find_opt_key( + struct button_bar *button_bar, char opt_key) +{ + struct button_bar_button *button; + + if (button_bar == NULL) + return NULL; + + button = button_bar->buttons; + + while (button != NULL && button->opt_key != opt_key) + button = button->next; + + return button; +} + + +/** + * Find a button bar icon definition from an action code. + * + * \param *button_bar The button bar to use. + * \param action The button action to find. + * \return Pointer to the button bar icon, or NULL. + */ + +struct button_bar_button *ro_gui_button_bar_find_action( + struct button_bar *button_bar, button_bar_action action) +{ + struct button_bar_button *button; + + if (button_bar == NULL) + return NULL; + + button = button_bar->buttons; + + while (button != NULL && + button->select_action != action && + button->adjust_action != action) + button = button->next; + + return button; +} + + +/** + * Find a button bar icon definition from coordinates. + * + * \param *button_bar The button bar to use. + * \param pos The coordinates to find, work area relative. + * \param *separator Returns true if the associated separator was + * matched; else false. + * \param *right Returns true if the coordinates were in the + * right hand side of the target; else false. + * \return Pointer to the button bar icon, or NULL. + */ + +struct button_bar_button *ro_gui_button_bar_find_coords( + struct button_bar *button_bar, os_coord pos, + bool *separator, bool *right) +{ + struct button_bar_button *button; + int x0, y0, x1, y1; + + if (button_bar == NULL) + return NULL; + + button = button_bar->bar; + + while (button != NULL) { + /* Match button extents. */ + + x0 = button_bar->extent.x0 + button->x_pos; + y0 = button_bar->extent.y0 + button->y_pos; + x1 = x0 + button->x_size; + y1 = y0 + button->y_size; + + if (pos.x > x0 && pos.y > y0 && pos.x < x1 && pos.y < y1) { + if (separator != NULL) + *separator = false; + + if (right != NULL) + *right = (pos.x > x0 + button->x_size/2) ? + true : false; + return button; + } + + x0 = x1; + x1 = x0 + button_bar->separator_width; + + /* Match separator extents. */ + + if (pos.x > x0 && pos.y > y0 && pos.x < x1 && pos.y < y1 && + button->separator) { + if (separator != NULL) + *separator = true; + + if (right != NULL) + *right = (x0 + button_bar->separator_width/2) ? + true : false; + return button; + } + + button = button->bar_next; + } + + return NULL; +} + diff --git a/riscos/gui/button_bar.h b/riscos/gui/button_bar.h new file mode 100644 index 000000000..d92428859 --- /dev/null +++ b/riscos/gui/button_bar.h @@ -0,0 +1,314 @@ +/* + * Copyright 2005 Richard Wilson <info@tinct.net> + * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * Button bars (interface). + */ + +#ifndef _NETSURF_RISCOS_BUTTONBAR_H_ +#define _NETSURF_RISCOS_BUTTONBAR_H_ + +#include <stdbool.h> +#include "riscos/theme.h" + +/* A list of possible toolbar actions. */ + +typedef enum { + TOOLBAR_BUTTON_NONE = 0, /* Special case: no action */ + TOOLBAR_BUTTON_BACK, + TOOLBAR_BUTTON_BACK_NEW, + TOOLBAR_BUTTON_UP, + TOOLBAR_BUTTON_UP_NEW, + TOOLBAR_BUTTON_FORWARD, + TOOLBAR_BUTTON_FORWARD_NEW, + TOOLBAR_BUTTON_STOP, + TOOLBAR_BUTTON_RELOAD, + TOOLBAR_BUTTON_RELOAD_ALL, + TOOLBAR_BUTTON_HOME, + TOOLBAR_BUTTON_HISTORY_LOCAL, + TOOLBAR_BUTTON_HISTORY_GLOBAL, + TOOLBAR_BUTTON_SAVE_SOURCE, + TOOLBAR_BUTTON_SAVE_COMPLETE, + TOOLBAR_BUTTON_PRINT, + TOOLBAR_BUTTON_BOOKMARK_OPEN, + TOOLBAR_BUTTON_BOOKMARK_ADD, + TOOLBAR_BUTTON_SCALE, + TOOLBAR_BUTTON_SEARCH, + TOOLBAR_BUTTON_DELETE, + TOOLBAR_BUTTON_EXPAND, + TOOLBAR_BUTTON_COLLAPSE, + TOOLBAR_BUTTON_OPEN, + TOOLBAR_BUTTON_CLOSE, + TOOLBAR_BUTTON_LAUNCH, + TOOLBAR_BUTTON_CREATE +} button_bar_action; + +/* Button bar button source definitions. + * + * Help tokens are added to the help prefix for the given toolbar by the + * help system, and correspond to the hard-coded icon numbers that were + * assigned to the different buttons in the original toolbar implementation. + * If the Messages file can be updated, these can change to something more + * meaningful. + */ + +struct button_bar_buttons { + const char *icon; /**< The sprite used for the icon. */ + button_bar_action select; /**< The action for select clicks. */ + button_bar_action adjust; /**< The action for Adjust clicks. */ + const char opt_key; /**< The char used in option strings. */ + const char *help; /**< The interactive help token. */ +}; + +/* \TODO -- Move these to the correct modules. + */ + +static const struct button_bar_buttons brower_toolbar_buttons[] = { + {"back", TOOLBAR_BUTTON_BACK, TOOLBAR_BUTTON_BACK_NEW, '0', "0"}, + {"up", TOOLBAR_BUTTON_UP, TOOLBAR_BUTTON_UP_NEW, 'b', "11"}, + {"forward", TOOLBAR_BUTTON_FORWARD, TOOLBAR_BUTTON_FORWARD_NEW, '1', "1"}, + {"stop", TOOLBAR_BUTTON_STOP, TOOLBAR_BUTTON_NONE, '2', "2"}, + {"reload", TOOLBAR_BUTTON_RELOAD, TOOLBAR_BUTTON_RELOAD_ALL, '3', "3"}, + {"home", TOOLBAR_BUTTON_HOME, TOOLBAR_BUTTON_NONE, '4', "4"}, + {"history", TOOLBAR_BUTTON_HISTORY_LOCAL, TOOLBAR_BUTTON_HISTORY_GLOBAL, '5', "5"}, + {"save", TOOLBAR_BUTTON_SAVE_SOURCE, TOOLBAR_BUTTON_SAVE_COMPLETE, '6', "6"}, + {"print", TOOLBAR_BUTTON_PRINT, TOOLBAR_BUTTON_NONE, '7', "7"}, + {"hotlist", TOOLBAR_BUTTON_BOOKMARK_OPEN, TOOLBAR_BUTTON_BOOKMARK_ADD, '8', "8"}, + {"scale", TOOLBAR_BUTTON_SCALE, TOOLBAR_BUTTON_NONE, '9', "9"}, + {"search", TOOLBAR_BUTTON_SEARCH, TOOLBAR_BUTTON_NONE, 'a', "10"}, + {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""} +}; + +static const struct button_bar_buttons cookies_toolbar_buttons[] = { + {"delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"}, + {"expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"}, + {"open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"}, + {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""} +}; + +static const struct button_bar_buttons global_history_toolbar_buttons[] = { + {"delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"}, + {"expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"}, + {"open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"}, + {"launch", TOOLBAR_BUTTON_LAUNCH, TOOLBAR_BUTTON_NONE, '3', "3"}, + {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""} +}; + +static const struct button_bar_buttons hotlist_toolbar_buttons[] = { + {"delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"}, + {"expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"}, + {"open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"}, + {"launch", TOOLBAR_BUTTON_LAUNCH, TOOLBAR_BUTTON_NONE, '3', "3"}, + {"create", TOOLBAR_BUTTON_CREATE, TOOLBAR_BUTTON_NONE, '4', "4"}, + {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""} +}; + +struct button_bar; + + +/** + * Create a new button bar widget. + * + * \param *theme The theme to apply (or NULL for the default). + * \param buttons[] An array of button definitions for the bar. + * \return A button bar handle, or NULL on failure. + */ + +struct button_bar *ro_gui_button_bar_create(struct theme_descriptor *theme, + const struct button_bar_buttons buttons[]); + + +/** + * Link two button bars together: the target being the active bar, and the + * source being the editing bar used to supply valid buttons. The bars are + * checked to ensure that they are not already part of an edit pair, but are + * not checked for button-compatibility. + * + * \param *target The target button bar. + * \param *source The source button bar. + * \return true if successful; else false. + */ + +bool ro_gui_button_bar_link_editor(struct button_bar *target, + struct button_bar *source, void (* refresh)(void *), + void *client_data); + +/** + * Place a button bar into a toolbar window and initialise any theme-specific + * settings. Any previous incarnation of the bar will be forgotten: this + * is for use when a new toolbar is being created, or when a toolbar has been + * deleted and rebuilt following a theme change. + * + * \param *button_bar The button bar to rebuild. + * \param *theme The theme to apply (or NULL for current). + * \param style The theme style to apply. + * \param window The window that the bar is in. + * \param edit The edit mode of the button bar. + * \return true on success; else false. + */ + +bool ro_gui_button_bar_rebuild(struct button_bar *button_bar, + struct theme_descriptor *theme, theme_style style, + wimp_w window, bool edit); + + +/** + * Arrange buttons on a button bar, using an order string to specify the + * required button and separator layout. + * + * \param *button_bar The button bar to update. + * \param order[] The button order configuration string. + * \return true if successful; else false. + */ + +bool ro_gui_button_bar_arrange_buttons(struct button_bar *button_bar, + char order[]); + + +/** + * Destroy a button bar widget. + * + * \param *button_bar The button bar to destroy. + */ + +void ro_gui_button_bar_destroy(struct button_bar *button_bar); + + +/** + * Return the MINIMUM dimensions required by the button bar, in RO units, + * allowing for the current theme. + * + * \param *button_bar The button bar of interest. + * \param *width Return the required width. + * \param *height Return the required height. + * \return true if values are returned; else false. + */ + +bool ro_gui_button_bar_get_dims(struct button_bar *button_bar, + int *width, int *height); + + +/** + * Set or update the dimensions to be used by the button bar, in RO units. + * If these are greater than the minimum required, the button bar will fill + * the extended space; if less, the call will fail. + * + * \param *button_bar The button bar to update. + * \param x0 The minimum X window position. + * \param y0 The minimum Y window position. + * \param x1 The maximum X window position. + * \param y1 The maximum Y window position. + * \return true if size updated; else false. + */ + +bool ro_gui_button_bar_set_extent(struct button_bar *button_bar, + int x0, int y0, int x1, int y1); + + +/** + * Show or hide a button bar. + * + * \param *button_bar The button bar to hide. + * \param hide true to hide the bar; false to show it. + * \return true if successful; else false. + */ + +bool ro_gui_button_bar_hide(struct button_bar *button_bar, bool hide); + + +/** + * Shade or unshade a button in a bar corresponding to the given action. + * + * \param *button_bar The button bar to update. + * \param action The action to update. + * \param shaded true to shade the button; false to unshade. + * \return true if successful; else false. + */ + +bool ro_gui_button_bar_shade_button(struct button_bar *button_bar, + button_bar_action action, bool shaded); + + +/** + * Handle redraw event rectangles in a button bar. + * + * \param *button_bar The button bar to use. + * \param *redraw The Wimp redraw rectangle to process. + */ + +void ro_gui_button_bar_redraw(struct button_bar *button_bar, + wimp_draw *redraw); + + +/** + * Handle mouse clicks in a button bar. + * + * \param *button_bar The button bar to use. + * \param *pointer The Wimp mouse click event data. + * \param *state The toolbar window state. + * \param *action Returns the selected action, or + * TOOLBAR_BUTTON_NONE. + * \return true if the event was handled exclusively; + * else false. + */ + +bool ro_gui_button_bar_click(struct button_bar *button_bar, + wimp_pointer *pointer, wimp_window_state *state, + button_bar_action *action); + + +/** + * Translate mouse data into an interactive help message for a button bar. + * + * \param *button_bar The button bar to process. + * \param i The wimp icon under the pointer. + * \param *mouse The mouse position. + * \param *state The toolbar window state. + * \param buttons The mouse button state. + * \param **suffix Return a help token suffix, or "" for none. + * \return true if handled exclusively; else false. + */ + +bool ro_gui_button_bar_help_suffix(struct button_bar *button_bar, wimp_i i, + os_coord *mouse, wimp_window_state *state, + wimp_mouse_state buttons, const char **suffix); + + +/** + * Terminate a drag event that was initiated by a button bar. + * + * \param *drag The drag event data. + */ + +void ro_gui_button_bar_drag_end(wimp_dragged *drag); + + +/** + * Return a config string reflecting the configured order of buttons + * and spacers. The string is allocated with malloc(), and should be + * free()d after use. + * + * \param *button_bar The button bar of interest. + * \return Pointer to a config string, or NULL on failure. + */ + +char *ro_gui_button_bar_get_config(struct button_bar *button_bar); + +#endif + diff --git a/riscos/gui/throbber.c b/riscos/gui/throbber.c new file mode 100644 index 000000000..05860a923 --- /dev/null +++ b/riscos/gui/throbber.c @@ -0,0 +1,419 @@ +/* + * Copyright 2004, 2005 Richard Wilson <info@tinct.net> + * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * Throbber (implementation). + */ + +#include <alloca.h> +#include <assert.h> +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include "oslib/os.h" +#include "oslib/osspriteop.h" +#include "oslib/wimp.h" +#include "riscos/gui/throbber.h" +#include "riscos/theme.h" +#include "riscos/wimp.h" +#include "utils/log.h" +#include "utils/utils.h" + +#define THROBBER_SPRITE_NAME_LENGTH 12 +#define THROBBER_ANIMATE_INTERVAL 10 + +struct throbber { + /** The applied theme (or NULL to use the default) */ + struct theme_descriptor *theme; + + /** The widget dimensions. */ + int x_min, y_min; + + /** The window and icon details. */ + wimp_w window; + wimp_i icon; + os_box extent; + osspriteop_area *sprites; + bool hidden; + bool shaded; + + /** The animation details. */ + int max_frame; + int current_frame; + os_t last_update; + char sprite_name[THROBBER_SPRITE_NAME_LENGTH]; + bool force_redraw; +}; + +/* + * Private function prototypes. + */ + +static bool ro_gui_throbber_icon_update(struct throbber *throbber); +static bool ro_gui_throbber_icon_resize(struct throbber *throbber); + +/* This is an exported interface documented in throbber.h */ + +struct throbber *ro_gui_throbber_create(struct theme_descriptor *theme) +{ + struct throbber *throbber; + + /* Allocate memory. */ + + throbber = malloc(sizeof(struct throbber)); + if (throbber == NULL) { + LOG(("No memory for malloc()")); + return NULL; + } + + /* Set up default parameters. If reading the throbber theme data + * fails, we give up and return a failure. + */ + + if (!ro_gui_theme_get_throbber_data(theme, &throbber->max_frame, + &throbber->x_min, &throbber->y_min, NULL, + &throbber->force_redraw)) { + free(throbber); + return NULL; + } + + throbber->sprites = ro_gui_theme_get_sprites(theme); + + throbber->theme = theme; + + throbber->extent.x0 = 0; + throbber->extent.y0 = 0; + throbber->extent.x1 = 0; + throbber->extent.y1 = 0; + + throbber->current_frame = 0; + throbber->last_update = 0; + + throbber->window = NULL; + throbber->icon = -1; + + throbber->hidden = false; + throbber->shaded = false; + + return throbber; +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_rebuild(struct throbber *throbber, + struct theme_descriptor *theme, theme_style style, + wimp_w window, bool shaded) +{ + if (throbber == NULL) + return false; + + throbber->theme = theme; + throbber->window = window; + throbber->sprites = ro_gui_theme_get_sprites(theme); + + throbber->icon = -1; + + throbber->shaded = shaded; + + strcpy(throbber->sprite_name, "throbber0"); + + if (!ro_gui_theme_get_throbber_data(theme, &throbber->max_frame, + &throbber->x_min, &throbber->y_min, NULL, + &throbber->force_redraw)) { + free(throbber); + return false; + } + + return ro_gui_throbber_icon_update(throbber); +} + + +/* This is an exported interface documented in throbber.h */ + +void ro_gui_throbber_destroy(struct throbber *throbber) +{ + if (throbber == NULL) + return; + + free(throbber); +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_get_dims(struct throbber *throbber, + int *width, int *height) +{ + if (throbber == NULL) + return false; + + if (throbber->x_min != -1 && throbber->y_min != -1) { + if (width != NULL) + *width = throbber->x_min; + if (height != NULL) + *height = throbber->y_min; + + return true; + } + + return false; +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_set_extent(struct throbber *throbber, + int x0, int y0, int x1, int y1) +{ + if (throbber == NULL) + return false; + + if ((x1 - x0) < throbber->x_min || (y1 - y0) < throbber->y_min) + return false; + + if (throbber->extent.x0 == x0 && throbber->extent.y0 == y0 && + throbber->extent.x1 == x1 && + throbber->extent.y1 == y1) + return true; + + /* Redraw the relevant bits of the toolbar. */ + + if (throbber->window != NULL && throbber->icon != -1) { + xwimp_force_redraw(throbber->window, + throbber->extent.x0, throbber->extent.y0, + throbber->extent.x1, throbber->extent.y1); + xwimp_force_redraw(throbber->window, x0, y0, x1, y1); + } + + /* Update the throbber position */ + + throbber->extent.x0 = x0; + throbber->extent.y0 = y0; + throbber->extent.x1 = x1; + throbber->extent.y1 = y1; + + return ro_gui_throbber_icon_resize(throbber); +} + + +/** + * Create or delete a throbber's icon if required to bring it into sync with + * the current hidden setting. + * + * \param *throbber The throbber to update. + * \return true if successful; else false. + */ + +bool ro_gui_throbber_icon_update(struct throbber *throbber) +{ + wimp_icon_create icon; + os_error *error; + + if (throbber == NULL || throbber->window == NULL) + return false; + + if (!throbber->hidden && throbber->icon == -1) { + icon.w = throbber->window; + icon.icon.extent.x0 = throbber->extent.x0; + icon.icon.extent.y0 = throbber->extent.y0; + icon.icon.extent.x1 = throbber->extent.x1; + icon.icon.extent.y1 = throbber->extent.y1; + icon.icon.flags = wimp_ICON_SPRITE | wimp_ICON_INDIRECTED | + wimp_ICON_HCENTRED | wimp_ICON_VCENTRED; + icon.icon.data.indirected_sprite.id = + (osspriteop_id) throbber->sprite_name; + icon.icon.data.indirected_sprite.area = throbber->sprites; + icon.icon.data.indirected_sprite.size = + THROBBER_SPRITE_NAME_LENGTH; + + error = xwimp_create_icon(&icon, &throbber->icon); + if (error != NULL) { + LOG(("xwimp_create_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + throbber->icon = -1; + return false; + } + + if (!ro_gui_throbber_icon_resize(throbber)) + return false; + } else if (throbber->hidden && throbber->icon != -1) { + error = xwimp_delete_icon(throbber->window, throbber->icon); + if (error != NULL) { + LOG(("xwimp_delete_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + throbber->icon = -1; + } + + if (throbber->icon != -1) + ro_gui_set_icon_shaded_state(throbber->window, + throbber->icon, throbber->shaded); + + return true; +} + + +/** + * Position the icons in the throbber to take account of the currently + * configured extent. + * + * \param *throbber The throbber to update. + * \return true if successful; else false. + */ + +bool ro_gui_throbber_icon_resize(struct throbber *throbber) +{ + os_error *error; + + if (throbber->window == NULL) + return false; + + if (throbber->icon != -1) { + error = xwimp_resize_icon(throbber->window, throbber->icon, + throbber->extent.x0, throbber->extent.y0, + throbber->extent.x1, throbber->extent.y1); + if (error != NULL) { + LOG(("xwimp_resize_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + throbber->icon = -1; + return false; + } + } + + return true; +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_hide(struct throbber *throbber, bool hide) +{ + if (throbber == NULL || throbber->hidden == hide) + return (throbber == NULL) ? false : true; + + throbber->hidden = hide; + + return ro_gui_throbber_icon_update(throbber); +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_help_suffix(struct throbber *throbber, wimp_i i, + os_coord *mouse, wimp_window_state *state, + wimp_mouse_state buttons, const char **suffix) +{ + os_coord pos; + + if (throbber == NULL || throbber->hidden) + return false; + + /* Check that the click was within our part of the window. */ + + pos.x = mouse->x - state->visible.x0 + state->xscroll; + pos.y = mouse->y - state->visible.y1 + state->yscroll; + + if (pos.x < throbber->extent.x0 || pos.x > throbber->extent.x1 || + pos.y < throbber->extent.y0 || + pos.y > throbber->extent.y1) + return false; + + /* Return a hard-coded icon number that matches the one that was + * always allocated to the throbber in a previous implementation. + * If Messages can be updated, this could be changed. + */ + + if (i == throbber->icon) + *suffix = "16"; + else + *suffix = ""; + + return true; +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_animate(struct throbber *throbber) +{ + os_t t; + char sprite_name[THROBBER_SPRITE_NAME_LENGTH]; + + if (throbber == NULL || throbber->hidden) + return (throbber == NULL) ? false : true; + + xos_read_monotonic_time(&t); + + /* Drop out if we're not ready for the next frame, unless this + * call is to start animation from a stopped throbber (ie. if + * the current frame is 0). + */ + + if ((t < (throbber->last_update + THROBBER_ANIMATE_INTERVAL)) && + (throbber->current_frame > 0)) + return true; + + throbber->last_update = t; + throbber->current_frame++; + + if (throbber->current_frame > throbber->max_frame) + throbber->current_frame = 1; + + snprintf(sprite_name, THROBBER_SPRITE_NAME_LENGTH, + "throbber%i", throbber->current_frame); + ro_gui_set_icon_string(throbber->window, throbber->icon, + sprite_name, true); + + if (throbber->force_redraw) + ro_gui_force_redraw_icon(throbber->window, throbber->icon); + + return true; +} + + +/* This is an exported interface documented in throbber.h */ + +bool ro_gui_throbber_stop(struct throbber *throbber) +{ + char sprite_name[THROBBER_SPRITE_NAME_LENGTH]; + + if (throbber == NULL || throbber->hidden || + throbber->current_frame == 0) + return (throbber == FALSE) ? false : true; + + throbber->current_frame = 0; + throbber->last_update = 0; + + strcpy(sprite_name, "throbber0"); + ro_gui_set_icon_string(throbber->window, throbber->icon, + sprite_name, true); + + if (throbber->force_redraw) + ro_gui_force_redraw_icon(throbber->window, throbber->icon); + + return true; +} + diff --git a/riscos/gui/throbber.h b/riscos/gui/throbber.h new file mode 100644 index 000000000..10d39ebfd --- /dev/null +++ b/riscos/gui/throbber.h @@ -0,0 +1,144 @@ +/* + * Copyright 2005 Richard Wilson <info@tinct.net> + * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * Throbber (interface). + */ + +#ifndef _NETSURF_RISCOS_THROBBER_H_ +#define _NETSURF_RISCOS_THROBBER_H_ + +#include <stdbool.h> +#include "riscos/theme.h" + +struct throbber; + + +/** + * Create a new throbber widget. + * + * \param *theme The theme to apply (or NULL for the default). + * \return A throbber handle, or NULL on failure. + */ + +struct throbber *ro_gui_throbber_create(struct theme_descriptor *theme); + +/** + * Place a throbber into a toolbar window and initialise any theme-specific + * settings. Any previous incarnation of the throbber will be forgotten: this + * is for use when a new toolbar is being created, or when a toolbar has been + * deleted and rebuilt following a theme change. + * + * \param *throbber The throbber to rebuild. + * \param *theme The theme to apply (or NULL for current). + * \param style The theme style to apply. + * \param window The window that the throbber is in. + * \param shaded true if the bar should be throbber; else false. + * \return true on success; else false. + */ + +bool ro_gui_throbber_rebuild(struct throbber *throbber, + struct theme_descriptor *theme, theme_style style, + wimp_w window, bool shaded); + + +/** + * Destroy a throbber widget. + * + * \param *throbber The throbber to destroy. + */ + +void ro_gui_throbber_destroy(struct throbber *throbber); + + +/** + * Return the MINIMUM dimensions required by the throbber, in RO units, + * allowing for the current theme. + * + * \param *throbber The throbber of interest. + * \param *width Return the required width. + * \param *height Return the required height. + * \return true if values are returned; else false. + */ + +bool ro_gui_throbber_get_dims(struct throbber *throbber, + int *width, int *height); + + +/** + * Set or update the dimensions to be used by the throbber, in RO units. + * If these are greater than the minimum required, the throbber will fill + * the extended space; if less, the call will fail. + * + * \param *throbber The throbber to update. + * \param width The desired width. + * \param height The desired height. + * \return true if size updated; else false. + */ + +bool ro_gui_throbber_set_extent(struct throbber *throbber, + int x0, int y0, int x1, int y1); + + +/** + * Show or hide a throbber. + * + * \param *throbber The throbber to hide. + * \param hide true to hide the throbber; false to show it. + * \return true if successful; else false. + */ + +bool ro_gui_throbber_hide(struct throbber *throbber, bool hide); + + +/** + * Translate mouse data into an interactive help message for the throbber. + * + * \param *throbber The throbber to process. + * \param i The wimp icon under the pointer. + * \param *mouse The mouse position. + * \param *state The toolbar window state. + * \param buttons The mouse button state. + * \param **suffix Return a help token suffix, or "" for none. + * \return true if handled exclusively; else false. + */ + +bool ro_gui_throbber_help_suffix(struct throbber *throbber, wimp_i i, + os_coord *screenpos, wimp_window_state *state, + wimp_mouse_state buttons, const char **suffix); + +/** + * Start or update the amimation of a throbber. + * + * \param *throbber The throbber to amimate. + */ + +bool ro_gui_throbber_animate(struct throbber *throbber); + + +/** + * Stop the amimation of a throbber. + * + * \param *throbber The throbber to amimate. + */ + +bool ro_gui_throbber_stop(struct throbber *throbber); + +#endif + diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c new file mode 100644 index 000000000..df4e7c06c --- /dev/null +++ b/riscos/gui/url_bar.c @@ -0,0 +1,984 @@ +/* + * Copyright 2004, 2005 Richard Wilson <info@tinct.net> + * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * URL bars (implementation). + */ + +#include <alloca.h> +#include <assert.h> +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include "oslib/os.h" +#include "oslib/osspriteop.h" +#include "oslib/wimp.h" +#include "riscos/gui/url_bar.h" +#include "riscos/theme.h" +#include "riscos/url_suggest.h" +#include "riscos/wimp.h" +#include "riscos/wimp_event.h" +#include "utils/log.h" +#include "utils/utils.h" + +#define URLBAR_HEIGHT 52 +#define URLBAR_FAVICON_WIDTH 52 +#define URLBAR_MIN_WIDTH 52 +#define URLBAR_GRIGHT_GUTTER 8 +#define URLBAR_FAVICON_NAME_LENGTH 12 +#define URLBAR_INITIAL_LENGTH 256 +#define URLBAR_EXTEND_LENGTH 128 +#define URLBAR_FAVICON_SIZE 16 + +struct url_bar { + /** The applied theme (or NULL to use the default) */ + struct theme_descriptor *theme; + + /** The widget dimensions. */ + int x_min, y_min; + + /** The window and icon details. */ + wimp_w window; + os_box extent; + + wimp_i container_icon; + + char favicon_sprite[URLBAR_FAVICON_NAME_LENGTH]; + int favicon_type; + struct hlcache_handle *favicon_content; + os_box favicon_extent; + os_coord favicon_offset; + int favicon_width, favicon_height; + + wimp_i text_icon; + char *text_buffer; + size_t text_size; + + wimp_i suggest_icon; + int suggest_x, suggest_y; + + bool hidden; + bool display; + bool shaded; +}; + +static char text_validation[] = "Pptr_write;KN"; +static char suggest_icon[] = "gright"; +static char suggest_validation[] = "R5;Sgright,pgright"; +static char null_text_string[] = ""; + + +/* + * Private function prototypes. + */ + +static bool ro_gui_url_bar_icon_update(struct url_bar *url_bar); +static bool ro_gui_url_bar_icon_resize(struct url_bar *url_bar, bool full); + +/* This is an exported interface documented in url_bar.h */ + +struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme) +{ + struct url_bar *url_bar; + + /* Allocate memory. */ + + url_bar = malloc(sizeof(struct url_bar)); + if (url_bar == NULL) { + LOG(("No memory for malloc()")); + return NULL; + } + + /* Set up default parameters. */ + + url_bar->theme = theme; + + url_bar->display = false; + url_bar->shaded = false; + + url_bar->x_min = URLBAR_FAVICON_WIDTH + URLBAR_MIN_WIDTH; + url_bar->y_min = URLBAR_HEIGHT; + + url_bar->extent.x0 = 0; + url_bar->extent.y0 = 0; + url_bar->extent.x1 = 0; + url_bar->extent.y1 = 0; + + url_bar->window = NULL; + url_bar->container_icon = -1; + url_bar->text_icon = -1; + url_bar->suggest_icon = -1; + + url_bar->favicon_extent.x0 = 0; + url_bar->favicon_extent.y0 = 0; + url_bar->favicon_extent.x1 = 0; + url_bar->favicon_extent.y1 = 0; + url_bar->favicon_width = 0; + url_bar->favicon_height = 0; + url_bar->favicon_content = NULL; + url_bar->favicon_type = 0; + strncpy(url_bar->favicon_sprite, "Ssmall_xxx", + URLBAR_FAVICON_NAME_LENGTH); + + url_bar->text_size = URLBAR_INITIAL_LENGTH; + url_bar->text_buffer = malloc(url_bar->text_size); + strncpy(url_bar->text_buffer, "", url_bar->text_size); + + url_bar->hidden = false; + + return url_bar; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_rebuild(struct url_bar *url_bar, + struct theme_descriptor *theme, theme_style style, + wimp_w window, bool display, bool shaded) +{ + if (url_bar == NULL) + return false; + + url_bar->theme = theme; + url_bar->window = window; + + url_bar->display = display; + url_bar->shaded = shaded; + + url_bar->container_icon = -1; + url_bar->text_icon = -1; + url_bar->suggest_icon = -1; + + ro_gui_wimp_get_sprite_dimensions((osspriteop_area *) -1, + suggest_icon, &url_bar->suggest_x, &url_bar->suggest_y); + + url_bar->x_min = URLBAR_FAVICON_WIDTH + URLBAR_MIN_WIDTH + + URLBAR_GRIGHT_GUTTER + url_bar->suggest_x; + url_bar->y_min = (url_bar->suggest_y > URLBAR_HEIGHT) ? + url_bar->suggest_y : URLBAR_HEIGHT; + + return ro_gui_url_bar_icon_update(url_bar); +} + + +/* This is an exported interface documented in url_bar.h */ + +void ro_gui_url_bar_destroy(struct url_bar *url_bar) +{ + if (url_bar == NULL) + return; + + free(url_bar); +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_get_dims(struct url_bar *url_bar, + int *width, int *height) +{ + if (url_bar == NULL) + return false; + + if (url_bar->x_min != -1 && url_bar->y_min != -1) { + if (width != NULL) + *width = url_bar->x_min; + if (height != NULL) + *height = url_bar->y_min; + + return true; + } + + return false; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_set_extent(struct url_bar *url_bar, + int x0, int y0, int x1, int y1) +{ + bool stretch; + + if (url_bar == NULL) + return false; + + if ((x1 - x0) < url_bar->x_min || (y1 - y0) < url_bar->y_min) + return false; + + if (url_bar->extent.x0 == x0 && url_bar->extent.y0 == y0 && + url_bar->extent.x1 == x1 && + url_bar->extent.y1 == y1) + return true; + + /* If it's only the length that changes, less needs to be updated. */ + + stretch = (url_bar->extent.x0 == x0 && url_bar->extent.y0 == y0 && + url_bar->extent.y1 == y1) ? true : false; + + /* Redraw the relevant bits of the toolbar. */ + + if (url_bar->window != NULL && url_bar->container_icon != -1) { + xwimp_force_redraw(url_bar->window, + url_bar->extent.x0 + + (stretch) ? URLBAR_FAVICON_WIDTH : 0, + url_bar->extent.y0, + url_bar->extent.x1, url_bar->extent.y1); + xwimp_force_redraw(url_bar->window, + x0 + (stretch) ? URLBAR_FAVICON_WIDTH : 0, + y0, x1, y1); + } + + /* Reposition the URL bar icons. */ + + url_bar->extent.x0 = x0; + url_bar->extent.y0 = y0; + url_bar->extent.x1 = x1; + url_bar->extent.y1 = y1; + + return ro_gui_url_bar_icon_resize(url_bar, !stretch); +} + + +/** + * Create or delete a URL bar's icons if required to bring it into sync with + * the current hidden setting. + * + * \param *url_bar The URL bar to update. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_icon_update(struct url_bar *url_bar) +{ + wimp_icon_create icon; + os_error *error; + bool resize; + + if (url_bar == NULL || url_bar->window == NULL) + return false; + + icon.w = url_bar->window; + icon.icon.extent.x0 = 0; + icon.icon.extent.y0 = 0; + icon.icon.extent.x1 = 0; + icon.icon.extent.y1 = 0; + + resize = false; + + /* Create or delete the container icon. */ + + if (!url_bar->hidden && url_bar->container_icon == -1) { + icon.icon.flags = wimp_ICON_BORDER | + (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT); + error = xwimp_create_icon(&icon, &url_bar->container_icon); + if (error != NULL) { + LOG(("xwimp_create_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + url_bar->container_icon = -1; + return false; + } + + resize = true; + } else if (url_bar->hidden && url_bar->container_icon != -1){ + error = xwimp_delete_icon(url_bar->window, + url_bar->container_icon); + if (error != NULL) { + LOG(("xwimp_delete_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + url_bar->container_icon = -1; + } + + /* Create or delete the text icon. */ + + if (!url_bar->hidden && url_bar->text_icon == -1) { + icon.icon.data.indirected_text.text = url_bar->text_buffer; + icon.icon.data.indirected_text.validation = text_validation; + icon.icon.data.indirected_text.size = url_bar->text_size; + icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | + wimp_ICON_VCENTRED | wimp_ICON_FILLED | + (wimp_COLOUR_BLACK << + wimp_ICON_FG_COLOUR_SHIFT); + if (url_bar->display) + icon.icon.flags |= (wimp_BUTTON_NEVER << + wimp_ICON_BUTTON_TYPE_SHIFT); + else + icon.icon.flags |= (wimp_BUTTON_WRITE_CLICK_DRAG << + wimp_ICON_BUTTON_TYPE_SHIFT); + error = xwimp_create_icon(&icon, &url_bar->text_icon); + if (error) { + LOG(("xwimp_create_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + url_bar->text_icon = -1; + return false; + } + + resize = true; + } else if (url_bar->hidden && url_bar->text_icon != -1) { + error = xwimp_delete_icon(url_bar->window, + url_bar->text_icon); + if (error != NULL) { + LOG(("xwimp_delete_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + url_bar->text_icon = -1; + } + + /* Create or delete the suggest icon. */ + + if (!url_bar->hidden && url_bar->suggest_icon == -1) { + icon.icon.data.indirected_text.text = null_text_string; + icon.icon.data.indirected_text.size = 1; + icon.icon.data.indirected_text.validation = suggest_validation; + icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE | + wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | + wimp_ICON_VCENTRED | (wimp_BUTTON_CLICK << + wimp_ICON_BUTTON_TYPE_SHIFT); + error = xwimp_create_icon(&icon, &url_bar->suggest_icon); + if (error) { + LOG(("xwimp_create_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + if (!url_bar->display) + ro_gui_wimp_event_register_menu_gright(url_bar->window, + wimp_ICON_WINDOW, url_bar->suggest_icon, + ro_gui_url_suggest_menu); + + if (!ro_gui_url_bar_update_urlsuggest(url_bar)) + return false; + + resize = true; + } else if (url_bar->hidden && url_bar->suggest_icon != -1) { + ro_gui_wimp_event_deregister(url_bar->window, + url_bar->suggest_icon); + error = xwimp_delete_icon(url_bar->window, + url_bar->suggest_icon); + if (error != NULL) { + LOG(("xwimp_delete_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + url_bar->suggest_icon = -1; + } + + /* If any icons were created, resize the bar. */ + + if (resize && !ro_gui_url_bar_icon_resize(url_bar, true)) + return false; + + /* If there are any icons, apply shading as necessary. */ + + if (url_bar->container_icon != -1) + ro_gui_set_icon_shaded_state(url_bar->window, + url_bar->container_icon, url_bar->shaded); + + if (url_bar->text_icon != -1) + ro_gui_set_icon_shaded_state(url_bar->window, + url_bar->text_icon, url_bar->shaded); + + if (url_bar->suggest_icon != -1) + ro_gui_set_icon_shaded_state(url_bar->window, + url_bar->suggest_icon, url_bar->shaded); + + return true; +} + + +/** + * Position the icons in the URL bar to take account of the currently + * configured extent. + * + * \param *url_bar The URL bar to update. + * \param full true to resize everything; false to move only + * the right-hand end of the bar. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_icon_resize(struct url_bar *url_bar, bool full) +{ + int x0, y0, x1, y1; + int centre; + os_error *error; + os_coord eig = {1, 1}; + wimp_caret caret; + + if (url_bar == NULL || url_bar->window == NULL) + return false; + + /* calculate 1px in OS units */ + ro_convert_pixels_to_os_units(&eig, (os_mode) -1); + + /* The vertical centre line of the widget's extent. */ + + centre = url_bar->extent.y0 + + (url_bar->extent.y1 - url_bar->extent.y0) / 2; + + /* Position the container icon. */ + + if (url_bar->container_icon != -1) { + x0 = url_bar->extent.x0; + x1 = url_bar->extent.x1 - + url_bar->suggest_x - URLBAR_GRIGHT_GUTTER; + + y0 = centre - (URLBAR_HEIGHT / 2); + y1 = y0 + URLBAR_HEIGHT; + + error = xwimp_resize_icon(url_bar->window, + url_bar->container_icon, + x0, y0, x1, y1); + if (error != NULL) { + LOG(("xwimp_resize_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + url_bar->container_icon = -1; + return false; + } + } + + /* Position the URL Suggest icon. */ + + if (url_bar->suggest_icon != -1) { + x0 = url_bar->extent.x1 - url_bar->suggest_x; + x1 = url_bar->extent.x1; + + y0 = centre - (url_bar->suggest_y / 2); + y1 = y0 + url_bar->suggest_y; + + error = xwimp_resize_icon(url_bar->window, + url_bar->suggest_icon, + x0, y0, x1, y1); + if (error != NULL) { + LOG(("xwimp_resize_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + url_bar->suggest_icon = -1; + return false; + } + } + + /* Position the Text icon. */ + + if (url_bar->text_icon != -1) { + x0 = url_bar->extent.x0 + URLBAR_FAVICON_WIDTH; + x1 = url_bar->extent.x1 - eig.x - + url_bar->suggest_x - URLBAR_GRIGHT_GUTTER; + + y0 = centre - (URLBAR_HEIGHT / 2) + eig.y; + y1 = y0 + URLBAR_HEIGHT - 2 * eig.y; + + error = xwimp_resize_icon(url_bar->window, + url_bar->text_icon, + x0, y0, x1, y1); + if (error != NULL) { + LOG(("xwimp_resize_icon: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + url_bar->text_icon = -1; + return false; + } + + if (xwimp_get_caret_position(&caret) == NULL) { + if ((caret.w == url_bar->window) && + (caret.i == url_bar->text_icon)) { + xwimp_set_caret_position(url_bar->window, + url_bar->text_icon, caret.pos.x, + caret.pos.y, -1, caret.index); + } + } + } + + /* Position the Favicon icon. */ + + url_bar->favicon_extent.x0 = url_bar->extent.x0 + eig.x; + url_bar->favicon_extent.x1 = url_bar->extent.x0 + URLBAR_FAVICON_WIDTH; + url_bar->favicon_extent.y0 = centre - (URLBAR_HEIGHT / 2) + eig.y; + url_bar->favicon_extent.y1 = url_bar->favicon_extent.y0 + URLBAR_HEIGHT + - 2 * eig.y; + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_hide(struct url_bar *url_bar, bool hide) +{ + if (url_bar == NULL || url_bar->hidden == hide) + return (url_bar == NULL) ? false : true; + + url_bar->hidden = hide; + + return ro_gui_url_bar_icon_update(url_bar); +} + + +/* This is an exported interface documented in url_bar.h */ + +void ro_gui_url_bar_redraw(struct url_bar *url_bar, wimp_draw *redraw) +{ + wimp_icon icon; + struct rect clip; + + /* Test for a valid URL bar, and then check that the redraw box + * coincides with the bar's favicon extent. + */ + + if (url_bar == NULL || url_bar->hidden || + (redraw->clip.x0 - (redraw->box.x0 - redraw->xscroll)) + > (url_bar->favicon_extent.x1) || + (redraw->clip.y0 - (redraw->box.y1 - redraw->yscroll)) + > url_bar->favicon_extent.y1 || + (redraw->clip.x1 - (redraw->box.x0 - redraw->xscroll)) + < url_bar->favicon_extent.x0 || + (redraw->clip.y1 - (redraw->box.y1 - redraw->yscroll)) + < url_bar->favicon_extent.y0) + return; + + if (url_bar->favicon_content == NULL) { + icon.data.indirected_text.text = null_text_string; + icon.data.indirected_text.validation = url_bar->favicon_sprite; + icon.data.indirected_text.size = 1; + icon.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE | + wimp_ICON_INDIRECTED | wimp_ICON_FILLED | + wimp_ICON_HCENTRED | wimp_ICON_VCENTRED; + icon.extent.x0 = url_bar->favicon_extent.x0; + icon.extent.x1 = url_bar->favicon_extent.x1; + icon.extent.y0 = url_bar->favicon_extent.y0; + icon.extent.y1 = url_bar->favicon_extent.y1; + + xwimp_plot_icon(&icon); + } else { + xwimp_set_colour(wimp_COLOUR_WHITE); + xos_plot(os_MOVE_TO, + (redraw->box.x0 - redraw->xscroll) + + url_bar->favicon_extent.x0, + (redraw->box.y1 - redraw->yscroll) + + url_bar->favicon_extent.y0); + xos_plot(os_PLOT_TO | os_PLOT_RECTANGLE, + (redraw->box.x0 - redraw->xscroll) + + url_bar->favicon_extent.x1, + (redraw->box.y1 - redraw->yscroll) + + url_bar->favicon_extent.y1); + + clip.x0 = (redraw->clip.x0 - ro_plot_origin_x) / 2; + clip.y0 = (ro_plot_origin_y - redraw->clip.y0) / 2; + clip.x1 = (redraw->clip.x1 - ro_plot_origin_x) / 2; + clip.y1 = (ro_plot_origin_y - redraw->clip.y1) / 2; + + content_redraw(url_bar->favicon_content, + (url_bar->favicon_extent.x0 + + url_bar->favicon_offset.x) / 2, + (url_bar->favicon_offset.y - + url_bar->favicon_extent.y1) / 2, + url_bar->favicon_width, url_bar->favicon_height, + &clip, 1, 0); + } +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_click(struct url_bar *url_bar, + wimp_pointer *pointer, wimp_window_state *state, + url_bar_action *action) +{ + os_coord pos; + + if (url_bar == NULL || url_bar->hidden || + url_bar->display || url_bar->shaded) + return false; + + /* Check that the click was within our part of the window. */ + + pos.x = pointer->pos.x - state->visible.x0 + state->xscroll; + pos.y = pointer->pos.y - state->visible.y1 + state->yscroll; + + if (pos.x < url_bar->extent.x0 || pos.x > url_bar->extent.x1 || + pos.y < url_bar->extent.y0 || + pos.y > url_bar->extent.y1) + return false; + + /* If we find a Select or Adjust drag, check if it originated on the + * URL bar or over the favicon. If either, then return an event. + */ + + if (pointer->buttons == wimp_DRAG_SELECT || + pointer->buttons == wimp_DRAG_ADJUST) { + if (pointer->i == url_bar->text_icon) { + if (action != NULL) + *action = TOOLBAR_URL_DRAG_URL; + return true; + } + + if (pos.x >= url_bar->favicon_extent.x0 && + pos.x <= url_bar->favicon_extent.x1 && + pos.y >= url_bar->favicon_extent.y0 && + pos.y <=url_bar->favicon_extent.y1) { + if (action != NULL) + *action = TOOLBAR_URL_DRAG_FAVICON; + return true; + } + } + + return false; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_menu_prepare(struct url_bar *url_bar, wimp_i i, + wimp_menu *menu, wimp_pointer *pointer) +{ + if (url_bar == NULL || url_bar->suggest_icon != i || + menu != ro_gui_url_suggest_menu) + return false; + + if (pointer != NULL) + return ro_gui_url_suggest_prepare_menu(); + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_menu_select(struct url_bar *url_bar, wimp_i i, + wimp_menu *menu, wimp_selection *selection, menu_action action) +{ + const char *url; + struct gui_window *g; + + if (url_bar == NULL || url_bar->suggest_icon != i || + menu != ro_gui_url_suggest_menu) + return false; + + url = ro_gui_url_suggest_get_selection(selection); + g = ro_gui_toolbar_lookup(url_bar->window); + + if (url != NULL && g != NULL && g->bw != NULL) { + gui_window_set_url(g, url); + browser_window_go(g->bw, url, 0, true); + } + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_help_suffix(struct url_bar *url_bar, wimp_i i, + os_coord *mouse, wimp_window_state *state, + wimp_mouse_state buttons, const char **suffix) +{ + os_coord pos; + + if (url_bar == NULL || url_bar->hidden) + return false; + + /* Check that the click was within our part of the window. */ + + pos.x = mouse->x - state->visible.x0 + state->xscroll; + pos.y = mouse->y - state->visible.y1 + state->yscroll; + + if (pos.x < url_bar->extent.x0 || pos.x > url_bar->extent.x1 || + pos.y < url_bar->extent.y0 || + pos.y > url_bar->extent.y1) + return false; + + /* Return hard-coded icon numbers that match the ones that were + * always allocated to the URL bar in a previous implementation. + * If Messages can be updated, this could be changed. + */ + + if (i == url_bar->text_icon) + *suffix = "14"; + else if (i == url_bar->suggest_icon) + *suffix = "15"; + else + *suffix = ""; + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_take_caret(struct url_bar *url_bar) +{ + os_error *error; + + if (url_bar == NULL || url_bar->hidden) + return false; + + error = xwimp_set_caret_position(url_bar->window, url_bar->text_icon, + -1, -1, -1, 0); + if (error) { + LOG(("xwimp_set_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + + return false; + } + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url, + bool is_utf8, bool set_caret) +{ + wimp_caret caret; + os_error *error; + const char *set_url; + + if (url_bar == NULL || url_bar->text_buffer == NULL) + return; + + if (url_bar->text_icon == -1) { + strncpy(url_bar->text_buffer, url, url_bar->text_size); + return; + } + + ro_gui_set_icon_string(url_bar->window, url_bar->text_icon, + url, is_utf8); + + error = xwimp_get_caret_position(&caret); + if (error) { + LOG(("xwimp_get_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + + if (set_caret || (caret.w == url_bar->window && + caret.i == url_bar->text_icon)) { + set_url = ro_gui_get_icon_string(url_bar->window, + url_bar->text_icon); + + error = xwimp_set_caret_position(url_bar->window, + url_bar->text_icon, 0, 0, -1, strlen(set_url)); + if (error) { + LOG(("xwimp_set_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } +} + + +/* This is an exported interface documented in url_bar.h */ + +const char *ro_gui_url_bar_get_url(struct url_bar *url_bar) +{ + if (url_bar == NULL) + return NULL; + + return (const char *) url_bar->text_buffer; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_get_url_extent(struct url_bar *url_bar, os_box *extent) +{ + wimp_icon_state state; + os_error *error; + + if (url_bar == NULL || url_bar->hidden) + return false; + + if (extent == NULL) + return true; + + state.w = url_bar->window; + state.i = url_bar->container_icon; + error = xwimp_get_icon_state(&state); + if (error) { + LOG(("xwimp_get_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + + extent->x0 = state.icon.extent.x0; + extent->y0 = state.icon.extent.y0; + extent->x1 = state.icon.extent.x1; + extent->y1 = state.icon.extent.y1; + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_test_for_text_field_click(struct url_bar *url_bar, + wimp_pointer *pointer) +{ + if (url_bar == NULL || url_bar->hidden || pointer == NULL) + return false; + + return (pointer->w == url_bar->window && + pointer->i == url_bar->text_icon) ? true : false; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar, + wimp_key *key) +{ + if (url_bar == NULL || url_bar->hidden || key == NULL) + return false; + + return (key->w == url_bar->window && + key->i == url_bar->text_icon) ? true : false; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_set_site_favicon(struct url_bar *url_bar, + struct hlcache_handle *h) +{ + content_type type = CONTENT_OTHER; + + if (url_bar == NULL) + return false; + + if (h != NULL) + type = content_get_type(h); + + // \TODO -- Maybe test for CONTENT_ICO ??? + + if (type != CONTENT_OTHER && type != CONTENT_UNKNOWN) { + url_bar->favicon_content = h; + url_bar->favicon_width = content_get_width(h); + url_bar->favicon_height = content_get_height(h); + + if (url_bar->favicon_width > URLBAR_FAVICON_SIZE) + url_bar->favicon_width = URLBAR_FAVICON_SIZE; + + if (url_bar->favicon_height > URLBAR_FAVICON_SIZE) + url_bar->favicon_height = URLBAR_FAVICON_SIZE; + + url_bar->favicon_offset.x = ((url_bar->favicon_extent.x1 - + url_bar->favicon_extent.x0) - + (url_bar->favicon_width * 2)) / 2; + url_bar->favicon_offset.y = ((url_bar->favicon_extent.y1 - + url_bar->favicon_extent.y0) - + (url_bar->favicon_height * 2)) / 2; + } else { + url_bar->favicon_content = NULL; + + if (url_bar->favicon_type != 0) + snprintf(url_bar->favicon_sprite, + URLBAR_FAVICON_NAME_LENGTH, + "Ssmall_%.3x", url_bar->favicon_type); + else + snprintf(url_bar->favicon_sprite, + URLBAR_FAVICON_NAME_LENGTH, + "Ssmall_xxx"); + } + + if (!url_bar->hidden) + xwimp_force_redraw(url_bar->window, + url_bar->favicon_extent.x0, + url_bar->favicon_extent.y0, + url_bar->favicon_extent.x1, + url_bar->favicon_extent.y1); + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_set_content_favicon(struct url_bar *url_bar, + struct hlcache_handle *h) +{ + int type = 0; + char sprite[URLBAR_FAVICON_NAME_LENGTH]; + + if (url_bar == NULL) + return false; + + if (h != NULL) + type = ro_content_filetype_from_type(content_get_type(h)); + + if (type != 0) { + snprintf(sprite, URLBAR_FAVICON_NAME_LENGTH, + "small_%.3x", type); + + if (!ro_gui_wimp_sprite_exists(sprite)) + type = 0; + } + + url_bar->favicon_type = type; + + if (url_bar->favicon_content == NULL) { + if (type == 0) + snprintf(url_bar->favicon_sprite, + URLBAR_FAVICON_NAME_LENGTH, "Ssmall_xxx"); + else + snprintf(url_bar->favicon_sprite, + URLBAR_FAVICON_NAME_LENGTH, "S%s", sprite); + + if (!url_bar->hidden) + xwimp_force_redraw(url_bar->window, + url_bar->favicon_extent.x0, + url_bar->favicon_extent.y0, + url_bar->favicon_extent.x1, + url_bar->favicon_extent.y1); + } + + return true; +} + + +/* This is an exported interface documented in url_bar.h */ + +bool ro_gui_url_bar_update_urlsuggest(struct url_bar *url_bar) +{ + if (url_bar == NULL || url_bar->hidden) + return (url_bar == NULL) ? false : true; + + if (url_bar->window != NULL && url_bar->suggest_icon != -1) + ro_gui_set_icon_shaded_state(url_bar->window, + url_bar->suggest_icon, + !ro_gui_url_suggest_get_menu_available()); + + return true; +} + diff --git a/riscos/gui/url_bar.h b/riscos/gui/url_bar.h new file mode 100644 index 000000000..0f5c6bc14 --- /dev/null +++ b/riscos/gui/url_bar.h @@ -0,0 +1,302 @@ +/* + * Copyright 2005 Richard Wilson <info@tinct.net> + * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * URL bars (interface). + */ + +#ifndef _NETSURF_RISCOS_URLBAR_H_ +#define _NETSURF_RISCOS_URLBAR_H_ + +#include <stdbool.h> +#include "riscos/menus.h" +#include "riscos/theme.h" + +/* A list of possible URL bar actions. */ + +typedef enum { + TOOLBAR_URL_NONE = 0, /* Special case: no action */ + TOOLBAR_URL_DRAG_URL, + TOOLBAR_URL_DRAG_FAVICON, +} url_bar_action; + +struct url_bar; + +/** + * Create a new url bar widget. + * + * \param *theme The theme to apply (or NULL for the default). + * \return A url bar handle, or NULL on failure. + */ + +struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme); + + +/** + * Place a URL bar into a toolbar window and initialise any theme-specific + * settings. Any previous incarnation of the bar will be forgotten: this + * is for use when a new toolbar is being created, or when a toolbar has been + * deleted and rebuilt following a theme change. + * + * \param *url_bar The URL bar to rebuild. + * \param *theme The theme to apply (or NULL for current). + * \param style The theme style to apply. + * \param window The window that the bar is in. + * \param display true if the bar should be for display only. + * \param shaded true if the bar should be shaded; else false. + * \return true on success; else false. + */ + +bool ro_gui_url_bar_rebuild(struct url_bar *url_bar, + struct theme_descriptor *theme, theme_style style, + wimp_w window, bool display, bool shaded); + + +/** + * Destroy a url bar widget. + * + * \param *url_bar The url bar to destroy. + */ + +void ro_gui_url_bar_destroy(struct url_bar *url_bar); + + +/** + * Return the MINIMUM dimensions required by the URL bar, in RO units, + * allowing for the current theme. + * + * \param *url_bar The URL bar of interest. + * \param *width Return the required width. + * \param *height Return the required height. + * \return true if values are returned; else false. + */ + +bool ro_gui_url_bar_get_dims(struct url_bar *url_bar, + int *width, int *height); + + +/** + * Set or update the dimensions to be used by the URL bar, in RO units. + * If these are greater than the minimum required, the URL bar will fill + * the extended space; if less, the call will fail. + * + * \param *url_bar The URL bar to update. + * \param x0 The minimum X window position. + * \param y0 The minimum Y window position. + * \param x1 The maximum X window position. + * \param y1 The maximum Y window position. + * \return true if size updated; else false. + */ + +bool ro_gui_url_bar_set_extent(struct url_bar *url_bar, + int x0, int y0, int x1, int y1); + + +/** + * Show or hide a URL bar. + * + * \param *url_bar The URL bar to hide. + * \param hide true to hide the bar; false to show it. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_hide(struct url_bar *url_bar, bool hide); + + +/** + * Handle redraw event rectangles in a URL bat. + * + * \param *url_bar The URL bar to use. + * \param *redraw The Wimp redraw rectangle to process. + */ + +void ro_gui_url_bar_redraw(struct url_bar *url_bar, wimp_draw *redraw); + + +/** + * Handle mouse clicks in a URL bar. + * + * \param *url_bar The URL bar to use. + * \param *pointer The Wimp mouse click event data. + * \param *state The toolbar window state. + * \param *action Returns the selected action, or + * TOOLBAR_URL_NONE. + * \return true if the event was handled exclusively; + * else false. + */ + +bool ro_gui_url_bar_click(struct url_bar *url_bar, + wimp_pointer *pointer, wimp_window_state *state, + url_bar_action *action); + + +/** + * Process offered menu prepare events from the parent window. + * + * \param *url_bar The URL bar in question. + * \param i The icon owning the menu. + * \param *menu The menu to be prepared. + * \param *pointer The Wimp Pointer data from the event. + * \return true if the event is claimed; else false. + */ + +bool ro_gui_url_bar_menu_prepare(struct url_bar *url_bar, wimp_i i, + wimp_menu *menu, wimp_pointer *pointer); + + +/** + * Process offered menu select events from the parent window. + * + * \param *url_bar The URL bar in question. + * \param i The icon owning the menu. + * \param *menu The menu to be prepared. + * \param *selection The wimp menu selection data. + * \param action The selected menu action. + * \return true if the event is claimed; else false. + */ + +bool ro_gui_url_bar_menu_select(struct url_bar *url_bar, wimp_i i, + wimp_menu *menu, wimp_selection *selection, menu_action action); + + +/** + * Translate mouse data into an interactive help message for the URL bar. + * + * \param *url_bar The URL bar to process. + * \param i The wimp icon under the pointer. + * \param *mouse The mouse position. + * \param *state The toolbar window state. + * \param buttons The mouse button state. + * \param **suffix Return a help token suffix, or "" for none. + * \return true if handled exclusively; else false. + */ + +bool ro_gui_url_bar_help_suffix(struct url_bar *url_bar, wimp_i i, + os_coord *mouse, wimp_window_state *state, + wimp_mouse_state buttons, const char **suffix); + + +/** + * Give a URL bar input focus. + * + * \param *url_bar The URL bar to give focus to. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_take_caret(struct url_bar *url_bar); + + +/** + * Set the content of a URL Bar field. + * + * \param *url_bar The URL Bar to update. + * \param *url The new url to insert. + * \param is_utf8 true if the string is in utf8 encoding; false + * if it is in local encoding. + * \param set_caret true if the caret should be placed in the field; + * else false. + */ + +void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url, + bool is_utf8, bool set_caret); + + +/** + * Return a pointer to the URL contained in a URL bar. + * + * \param *url_bar The URL Bar to look up the URL from. + * \return Pointer to the URL, or NULL. + */ + +const char *ro_gui_url_bar_get_url(struct url_bar *url_bar); + + +/** + * Return the current work area coordinates of the URL and favicon field's + * bounding box. + * + * \param *url_bar The URL bar to check. + * \param *extent Returns the field extent. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_get_url_extent(struct url_bar *url_bar, os_box *extent); + + +/** + * Test a pointer click to see if it was in the URL bar's text field. + * + * \param *url_bar The URL Bar to test. + * \param *pointer The pointer event data to test. + * \return true if the click was in the field; else false. + */ + +bool ro_gui_url_bar_test_for_text_field_click(struct url_bar *url_bar, + wimp_pointer *pointer); + + +/** + * Test a keypress to see if it was in the URL bar's text field. + * + * \param *url_bar The URL Bar to test. + * \param *pointer The pointer event data to test. + * \return true if the click was in the field; else false. + */ + +bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar, + wimp_key *key); + + +/** + * Set the favicon to a site supplied favicon image, or remove the image + * and return to using filetype-based icons. + * + * \param *url_bar The URL Bar to update the favicon on. + * \param *h The content to use, or NULL to unset. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_set_site_favicon(struct url_bar *url_bar, + struct hlcache_handle *h); + + +/** + * Set the favicon to a RISC OS filetype sprite based on the type of the + * supplied content. + * + * \param *url_bar The URL Bar to update the favicon on. + * \param *h The content to use. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_set_content_favicon(struct url_bar *url_bar, + struct hlcache_handle *h); + + +/** + * Update the state of the URL suggestion pop-up menu icon on a URL bar. + * + * \param *url_bar The URL bar to update. + * \return true if successful; else false. + */ + +bool ro_gui_url_bar_update_urlsuggest(struct url_bar *url_bar); + +#endif + |