From d21447d096a320a08b3efb2b8768fad0dcdcfd64 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 5 May 2016 22:28:51 +0100 Subject: move frontends into sub directory --- riscos/gui/button_bar.c | 1229 ----------------------------------------- riscos/gui/button_bar.h | 309 ----------- riscos/gui/progress_bar.c | 535 ------------------ riscos/gui/progress_bar.h | 44 -- riscos/gui/status_bar.c | 625 --------------------- riscos/gui/status_bar.h | 45 -- riscos/gui/throbber.c | 418 -------------- riscos/gui/throbber.h | 147 ----- riscos/gui/url_bar.c | 1344 --------------------------------------------- riscos/gui/url_bar.h | 329 ----------- 10 files changed, 5025 deletions(-) delete mode 100644 riscos/gui/button_bar.c delete mode 100644 riscos/gui/button_bar.h delete mode 100644 riscos/gui/progress_bar.c delete mode 100644 riscos/gui/progress_bar.h delete mode 100644 riscos/gui/status_bar.c delete mode 100644 riscos/gui/status_bar.h delete mode 100644 riscos/gui/throbber.c delete mode 100644 riscos/gui/throbber.h delete mode 100644 riscos/gui/url_bar.c delete mode 100644 riscos/gui/url_bar.h (limited to 'riscos/gui') diff --git a/riscos/gui/button_bar.c b/riscos/gui/button_bar.c deleted file mode 100644 index 6ecd7cffa..000000000 --- a/riscos/gui/button_bar.c +++ /dev/null @@ -1,1229 +0,0 @@ -/* - * Copyright 2004, 2005 Richard Wilson - * Copyright 2011 Stephen Fryatt - * - * 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 . - */ - -/** \file - * Button bars (implementation). - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utils/log.h" - -#include "riscos/gui/button_bar.h" -#include "riscos/gui.h" -#include "riscos/mouse.h" -#include "riscos/theme.h" -#include "riscos/wimp.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_drag_end(wimp_dragged *drag, void *data); -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; - 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; - - for (def = 0; buttons[def].icon != NULL; def++) { - new_icon = malloc(sizeof(struct button_bar_button)); - if (new_icon == NULL) { - 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; - 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; - - 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; - - - if (button_bar == NULL || button_bar->window == NULL) - return (button_bar == NULL) ? false : true; - - button = button_bar->buttons; - - while (button != NULL) { - bool 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); - ro_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); - ro_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); - ro_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; - - 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)) { - char *sprite; - os_error *error; - - 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); - - ro_mouse_drag_start(ro_gui_button_bar_drag_end, - NULL, NULL, NULL); - - - 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; -} - - -/** - * Terminate a drag event that was initiated by a button bar. - * - * \param *drag The drag event data. - * \param *data NULL data to satisfy callback syntax. - */ - -void ro_gui_button_bar_drag_end(wimp_dragged *drag, void *data) -{ - 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(); - - 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); - ro_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); - ro_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()"); - ro_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; - - if (button_bar == NULL) - return NULL; - - button = button_bar->bar; - - while (button != NULL) { - /* Match button extents. */ - int x0, y0, x1, y1; - - 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 deleted file mode 100644 index a1f7e8b9f..000000000 --- a/riscos/gui/button_bar.h +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright 2005 Richard Wilson - * Copyright 2011 Stephen Fryatt - * - * 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 . - */ - -/** \file - * Button bars (interface). - */ - -#ifndef _NETSURF_RISCOS_BUTTONBAR_H_ -#define _NETSURF_RISCOS_BUTTONBAR_H_ - -#include -#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 - * - * Join two button bars 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. - * \param refresh The refresh callback. - * \param client_data context passed to the refresh callback - * \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); - - -/** - * 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/progress_bar.c b/riscos/gui/progress_bar.c deleted file mode 100644 index 3ec6b3aa8..000000000 --- a/riscos/gui/progress_bar.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright 2006 Richard Wilson - * - * 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 . - */ - -/** \file - * Progress bar (implementation). - */ - -#include -#include -#include -#include "swis.h" -#include "oslib/colourtrans.h" -#include "oslib/os.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" -#include "oslib/wimpspriteop.h" - -#include "desktop/plotters.h" -#include "utils/log.h" -#include "utils/utils.h" - -#include "riscos/gui.h" -#include "riscos/tinct.h" -#include "riscos/wimp_event.h" -#include "riscos/gui/progress_bar.h" - -#define MARGIN 6 - -struct progress_bar { - wimp_w w; /**< progress bar window handle */ - unsigned int range; /**< progress bar range */ - unsigned int value; /**< progress bar value */ - char icon[13]; /**< current icon */ - int offset; /**< progress bar rotation */ - os_box visible; /**< progress bar position */ - int icon_x0; /**< icon x0 */ - int icon_y0; /**< icon y0 */ - osspriteop_header *icon_img; /**< icon image */ - bool animating; /**< progress bar is animating */ - bool recalculate; /**< recalculation required */ - int cur_width; /**< current calculated width */ - int cur_height; /**< current calculated height */ - bool icon_obscured; /**< icon is partially obscured */ -}; - -static char progress_animation_sprite[] = "progress"; -static osspriteop_header *progress_icon; -static unsigned int progress_width; -static unsigned int progress_height; - -struct wimp_window_base progress_bar_definition = { - {0, 0, 1, 1}, - 0, - 0, - wimp_TOP, - wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE | wimp_WINDOW_NO_BOUNDS, - 0xff, - wimp_COLOUR_LIGHT_GREY, - wimp_COLOUR_LIGHT_GREY, - wimp_COLOUR_VERY_LIGHT_GREY, - wimp_COLOUR_DARK_GREY, - wimp_COLOUR_MID_LIGHT_GREY, - wimp_COLOUR_CREAM, - wimp_WINDOW_NEVER3D | 0x16u /* RISC OS 5.03+ */, - {0, 0, 65535, 65535}, - 0, - 0, - wimpspriteop_AREA, - 1, - 1, - {""}, - 0 -}; - - -static void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width, - int height); -static void ro_gui_progress_bar_redraw(wimp_draw *redraw); -static void ro_gui_progress_bar_redraw_window(wimp_draw *redraw, - struct progress_bar *pb); -static void ro_gui_progress_bar_animate(void *p); - - -/** - * Initialise the progress bar - * - * \param icons the sprite area to use for icons - */ -void ro_gui_progress_bar_init(osspriteop_area *icons) -{ - const char *name = progress_animation_sprite; - os_error *error; - - progress_bar_definition.sprite_area = icons; - - progress_icon = NULL; - error = xosspriteop_select_sprite(osspriteop_USER_AREA, - progress_bar_definition.sprite_area, - (osspriteop_id) name, &progress_icon); - if (!error) { - xosspriteop_read_sprite_info(osspriteop_USER_AREA, - progress_bar_definition.sprite_area, - (osspriteop_id) name, - (int *) &progress_width, (int *) &progress_height, - 0, 0); - } -} - - -/** - * Create a new progress bar - */ -struct progress_bar *ro_gui_progress_bar_create(void) -{ - struct progress_bar *pb; - os_error *error; - - pb = calloc(1, sizeof(*pb)); - if (!pb) - return NULL; - - error = xwimp_create_window((wimp_window *)&progress_bar_definition, - &pb->w); - if (error) { - LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess); - free(pb); - return NULL; - } - - ro_gui_wimp_event_register_redraw_window(pb->w, - ro_gui_progress_bar_redraw); - ro_gui_wimp_event_set_user_data(pb->w, pb); - return pb; -} - - -/** - * Destroy a progress bar and free all associated resources - * - * \param pb the progress bar to destroy - */ -void ro_gui_progress_bar_destroy(struct progress_bar *pb) -{ - os_error *error; - assert(pb); - - if (pb->animating) { - riscos_schedule(-1, ro_gui_progress_bar_animate, pb); - } - ro_gui_wimp_event_finalise(pb->w); - error = xwimp_delete_window(pb->w); - if (error) { - LOG("xwimp_delete_window: 0x%x:%s", error->errnum, error->errmess); - } - - free(pb); -} - - -/** - * Get the handle of the window that represents a progress bar - * - * \param pb the progress bar to get the window handle of - * \return the progress bar's window handle - */ -wimp_w ro_gui_progress_bar_get_window(struct progress_bar *pb) -{ - assert(pb); - - return pb->w; -} - - -/** - * Set the icon for a progress bar - * - * \param pb the progress bar to set the icon for - * \param icon the icon to use, or NULL for no icon - */ -void ro_gui_progress_bar_set_icon(struct progress_bar *pb, const char *icon) -{ - assert(pb); - - if (!strcmp(icon, pb->icon)) - return; - if (!icon) - pb->icon[0] = '\0'; - else { - strncpy(pb->icon, icon, 12); - pb->icon[12] = '\0'; - } - pb->recalculate = true; - xwimp_force_redraw(pb->w, 0, 0, 32, 32); - ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height); -} - - -/** - * Set the value of a progress bar - * - * \param pb the progress bar to set the value for - * \param value the value to use - */ -void ro_gui_progress_bar_set_value(struct progress_bar *pb, unsigned int value) -{ - assert(pb); - - pb->value = value; - if (pb->value > pb->range) - pb->range = pb->value; - ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height); -} - - -/** - * Get the value of a progress bar - * - * \param pb the progress bar to get the value of - * \return the current value - */ -unsigned int ro_gui_progress_bar_get_value(struct progress_bar *pb) -{ - assert(pb); - - return pb->value; -} - - -/** - * Set the range of a progress bar - * - * \param pb the progress bar to set the range for - * \param range the range to use - */ -void ro_gui_progress_bar_set_range(struct progress_bar *pb, unsigned int range) -{ - assert(pb); - - pb->range = range; - if (pb->value > pb->range) - pb->value = pb->range; - ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height); -} - - -/** - * Get the range of a progress bar - * - * \param pb the progress bar to get the range of - * \return the current range - */ -unsigned int ro_gui_progress_bar_get_range(struct progress_bar *pb) -{ - assert(pb); - - return pb->range; -} - - -/** - * Update the progress bar to a new dimension. - * - * \param pb the progress bar to update - * \param width the new progress bar width - * \param height the new progress bar height - */ -void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height) -{ - wimp_draw redraw; - os_error *error; - osbool more; - os_box cur; - - /* don't allow negative dimensions */ - width = max(width, 0); - height = max(height, 0); - - /* update the animation state */ - if ((pb->value == 0) || (pb->value == pb->range)) { - if (pb->animating) { - riscos_schedule(-1, ro_gui_progress_bar_animate, pb); - } - pb->animating = false; - } else { - if (!pb->animating) { - riscos_schedule(200, ro_gui_progress_bar_animate, pb); - } - pb->animating = true; - } - - /* get old and new positions */ - cur = pb->visible; - pb->recalculate = true; - ro_gui_progress_bar_calculate(pb, width, height); - - /* see if the progress bar hasn't moved. we don't need to consider - * the left edge moving as this is handled by the icon setting - * function */ - if (cur.x1 == pb->visible.x1) - return; - - /* if size has decreased then we must force a redraw */ - if (cur.x1 > pb->visible.x1) { - xwimp_force_redraw(pb->w, pb->visible.x1, pb->visible.y0, - cur.x1, pb->visible.y1); - return; - } - - /* perform a minimal redraw update */ - redraw.w = pb->w; - redraw.box = pb->visible; - redraw.box.x0 = cur.x1; - error = xwimp_update_window(&redraw, &more); - if (error) { - LOG("Error getting update window: 0x%x: %s", error->errnum, error->errmess); - return; - } - if (more) - ro_gui_progress_bar_redraw_window(&redraw, pb); -} - - -/** - * Process a WIMP redraw request - * - * \param redraw the redraw request to process - */ -void ro_gui_progress_bar_redraw(wimp_draw *redraw) -{ - struct progress_bar *pb; - os_error *error; - osbool more; - - pb = (struct progress_bar *)ro_gui_wimp_event_get_user_data(redraw->w); - assert(pb); - - error = xwimp_redraw_window(redraw, &more); - if (error) { - LOG("xwimp_redraw_window: 0x%x: %s", error->errnum, error->errmess); - return; - } - if (more) - ro_gui_progress_bar_redraw_window(redraw, pb); -} - - -/** - * Animate the progress bar - * - * \param p the progress bar to animate - */ -void ro_gui_progress_bar_animate(void *p) -{ - wimp_draw redraw; - os_error *error; - osbool more; - struct progress_bar *pb = p; - - if (!progress_icon) - return; - pb->offset -= 6; - if (pb->offset < 0) - pb->offset += progress_width * 2; - - if (pb->animating) { - riscos_schedule(200, ro_gui_progress_bar_animate, pb); - } - - redraw.w = pb->w; - redraw.box = pb->visible; - error = xwimp_update_window(&redraw, &more); - if (error != NULL) { - LOG("Error getting update window: '%s'", error->errmess); - return; - } - if (more) - ro_gui_progress_bar_redraw_window(&redraw, pb); -} - - -/** - * Calculate the position of the progress bar - * - * \param pb the progress bar to recalculate - * \param width the width of the progress bar - * \param height the height of the progress bar - * \return the address of the associated icon, or NULL - */ -void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width, - int height) -{ - int icon_width, icon_height; - int icon_x0 = 0, icon_y0 = 0, progress_x0, progress_x1; - osspriteop_header *icon = NULL; - bool icon_redraw = false; - - /* try to use cached values */ - if ((!pb->recalculate) && (pb->cur_width == width) && - (pb->cur_height == height)) - return; - - /* update cache status */ - pb->recalculate = false; - pb->cur_width = width; - pb->cur_height = height; - - /* get the window dimensions */ - width -= MARGIN * 2; - icon_width = icon_height = 0; - progress_x0 = MARGIN; - - /* get the icon information */ - if (progress_bar_definition.sprite_area != wimpspriteop_AREA) { - int progress_ymid = height / 2; - os_error *error; - error = xosspriteop_read_sprite_info(osspriteop_USER_AREA, - progress_bar_definition.sprite_area, - (osspriteop_id)pb->icon, - &icon_width, &icon_height, 0, 0); - if (!error) { - error = xosspriteop_select_sprite(osspriteop_USER_AREA, - progress_bar_definition.sprite_area, - (osspriteop_id)pb->icon, &icon); - } - if (!error) { - progress_x0 += 32 + MARGIN; - width -= 32 + MARGIN; - icon_x0 = MARGIN + 16 - icon_width; - icon_y0 = progress_ymid - icon_height; - if (width < -MARGIN) { - icon_x0 += width + MARGIN; - icon_redraw = true; - } - } - } - - /* update the icon */ - if ((pb->icon_obscured) || (icon_redraw)) { - if (icon_x0 != pb->icon_x0) - xwimp_force_redraw(pb->w, 0, 0, 32 + MARGIN, 65536); - } - pb->icon_obscured = icon_redraw; - - progress_x1 = progress_x0; - if ((pb->range > 0) && (width > 0)) - progress_x1 += (width * pb->value) / pb->range; - - pb->visible.x0 = progress_x0; - pb->visible.y0 = MARGIN; - pb->visible.x1 = progress_x1; - pb->visible.y1 = height - MARGIN; - pb->icon_x0 = icon_x0; - pb->icon_y0 = icon_y0; - pb->icon_img = icon; -} - - -/** - * Redraw a section of a progress bar window - * - * \param redraw the section of the window to redraw - * \param pb the progress bar to redraw - */ -void ro_gui_progress_bar_redraw_window(wimp_draw *redraw, - struct progress_bar *pb) -{ - osbool more = true; - struct rect clip; - int progress_ymid; - - /* initialise the plotters */ - ro_plot_origin_x = 0; - ro_plot_origin_y = 0; - - /* recalculate the progress bar */ - ro_gui_progress_bar_calculate(pb, redraw->box.x1 - redraw->box.x0, - redraw->box.y1 - redraw->box.y0); - progress_ymid = redraw->box.y0 + pb->visible.y0 + - ((pb->visible.y1 - pb->visible.y0) >> 1); - - /* redraw the window */ - while (more) { - os_error *error; - if (pb->icon) - _swix(Tinct_PlotAlpha, _IN(2) | _IN(3) | _IN(4) | _IN(7), - pb->icon_img, - redraw->box.x0 + pb->icon_x0, - redraw->box.y0 + pb->icon_y0, - tinct_ERROR_DIFFUSE); - if (!pb->icon_obscured) { - clip.x0 = max(redraw->clip.x0, - redraw->box.x0 + pb->visible.x0) >> 1; - clip.y0 = -min(redraw->clip.y1, - redraw->box.y0 + pb->visible.y1) >> 1; - clip.x1 = min(redraw->clip.x1, - redraw->box.x0 + pb->visible.x1) >> 1; - clip.y1 = -max(redraw->clip.y0, - redraw->box.y0 + pb->visible.y0) >> 1; - if ((clip.x0 < clip.x1) && (clip.y0 < clip.y1)) { - if (progress_icon) { - ro_plotters.clip(&clip); - _swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7), - progress_icon, - redraw->box.x0 - pb->offset, - progress_ymid - progress_height, - tinct_FILL_HORIZONTALLY); - } else { - ro_plotters.rectangle(clip.x0, clip.y0, - clip.x1, clip.y1, - plot_style_fill_red); - } - } - } - error = xwimp_get_rectangle(redraw, &more); - if (error) { - LOG("xwimp_get_rectangle: 0x%x: %s", error->errnum, error->errmess); - return; - } - } -} diff --git a/riscos/gui/progress_bar.h b/riscos/gui/progress_bar.h deleted file mode 100644 index e4cec1369..000000000 --- a/riscos/gui/progress_bar.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2006 Richard Wilson - * - * 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 . - */ - -/** \file - * Progress bar (interface). - */ - -#ifndef _NETSURF_RISCOS_PROGRESS_BAR_H_ -#define _NETSURF_RISCOS_PROGRESS_BAR_H_ - -#include -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" - -struct progress_bar; - -void ro_gui_progress_bar_init(osspriteop_area *icons); - -struct progress_bar *ro_gui_progress_bar_create(void); -void ro_gui_progress_bar_destroy(struct progress_bar *pb); -void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height); - -wimp_w ro_gui_progress_bar_get_window(struct progress_bar *pb); -void ro_gui_progress_bar_set_icon(struct progress_bar *pb, const char *icon); -void ro_gui_progress_bar_set_value(struct progress_bar *pb, unsigned int value); -unsigned int ro_gui_progress_bar_get_value(struct progress_bar *pb); -void ro_gui_progress_bar_set_range(struct progress_bar *pb, unsigned int range); -unsigned int ro_gui_progress_bar_get_range(struct progress_bar *pb); -#endif diff --git a/riscos/gui/status_bar.c b/riscos/gui/status_bar.c deleted file mode 100644 index cbc404658..000000000 --- a/riscos/gui/status_bar.c +++ /dev/null @@ -1,625 +0,0 @@ -/* - * Copyright 2006 Richard Wilson - * - * 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 . - */ - -/** \file - * UTF8 status bar (implementation). - */ - -#include -#include -#include -#include "swis.h" -#include "oslib/colourtrans.h" -#include "oslib/os.h" -#include "oslib/wimp.h" -#include "oslib/wimpspriteop.h" -#include "desktop/plotters.h" -#include "utils/log.h" -#include "utils/utils.h" - -#include "riscos/gui.h" -#include "riscos/wimp.h" -#include "riscos/wimp_event.h" -#include "riscos/wimputils.h" -#include "riscos/font.h" -#include "riscos/gui/progress_bar.h" -#include "riscos/gui/status_bar.h" - -#define ICON_WIDGET 0 -#define WIDGET_WIDTH 12 -#define PROGRESS_WIDTH 160 - -struct status_bar { - wimp_w w; /**< status bar window handle */ - wimp_w parent; /**< parent window handle */ - const char *text; /**< status bar text */ - struct progress_bar *pb; /**< progress bar */ - unsigned int scale; /**< current status bar scale */ - int width; /**< current status bar width */ - bool visible; /**< status bar is visible? */ -}; - -static char status_widget_text[] = ""; -static char status_widget_validation[] = "R5;Pptr_lr,8,6"; - -wimp_WINDOW(1) status_bar_definition = { - {0, 0, 1, 1}, - 0, - 0, - wimp_TOP, - wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE | - wimp_WINDOW_FURNITURE_WINDOW | - wimp_WINDOW_IGNORE_XEXTENT, - wimp_COLOUR_BLACK, - wimp_COLOUR_LIGHT_GREY, - wimp_COLOUR_LIGHT_GREY, - wimp_COLOUR_VERY_LIGHT_GREY, - wimp_COLOUR_DARK_GREY, - wimp_COLOUR_MID_LIGHT_GREY, - wimp_COLOUR_CREAM, - wimp_WINDOW_NEVER3D | 0x16u /* RISC OS 5.03+ */, - {0, 0, 65535, 65535}, - 0, - 0, - wimpspriteop_AREA, - 1, - 1, - {""}, - 1, - { - { - {0, 0, 1, 1}, - wimp_ICON_TEXT | wimp_ICON_INDIRECTED | - wimp_ICON_BORDER | wimp_ICON_FILLED | - (wimp_COLOUR_LIGHT_GREY << - wimp_ICON_BG_COLOUR_SHIFT) | - (wimp_BUTTON_CLICK_DRAG << - wimp_ICON_BUTTON_TYPE_SHIFT), - { - .indirected_text = { - status_widget_text, - status_widget_validation, - 1 - } - } - } - } -}; - -static void ro_gui_status_bar_open(wimp_open *open); -static bool ro_gui_status_bar_click(wimp_pointer *pointer); -static void ro_gui_status_bar_redraw(wimp_draw *redraw); -static void ro_gui_status_bar_redraw_callback(void *handle); -static void ro_gui_status_position_progress_bar(struct status_bar *sb); - - -/** - * Create a new status bar - * - * \param parent the window to contain the status bar - * \param width the proportional width to use (0...10,000) - */ -struct status_bar *ro_gui_status_bar_create(wimp_w parent, unsigned int width) -{ - struct status_bar *sb; - os_error *error; - - sb = calloc(1, sizeof(*sb)); - if (!sb) - return NULL; - - sb->pb = ro_gui_progress_bar_create(); - if (!sb->pb) - return NULL; - - error = xwimp_create_window((wimp_window *)&status_bar_definition, - &sb->w); - if (error) { - LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess); - free(sb); - return NULL; - } - sb->parent = parent; - sb->scale = width; - sb->visible = true; - - ro_gui_wimp_event_set_user_data(sb->w, sb); - ro_gui_wimp_event_register_open_window(sb->w, - ro_gui_status_bar_open); - ro_gui_wimp_event_register_mouse_click(sb->w, - ro_gui_status_bar_click); - ro_gui_wimp_event_register_redraw_window(sb->w, - ro_gui_status_bar_redraw); - ro_gui_wimp_event_set_help_prefix(sb->w, "HelpStatus"); - ro_gui_status_bar_resize(sb); - return sb; -} - - -/** - * Destroy a status bar and free all associated resources - * - * \param sb the status bar to destroy - */ -void ro_gui_status_bar_destroy(struct status_bar *sb) -{ - os_error *error; - assert(sb); - - ro_gui_wimp_event_finalise(sb->w); - error = xwimp_delete_window(sb->w); - if (error) { - LOG("xwimp_delete_window: 0x%x:%s", error->errnum, error->errmess); - } - - ro_gui_progress_bar_destroy(sb->pb); - - /* Remove any scheduled redraw callbacks */ - riscos_schedule(-1, ro_gui_status_bar_redraw_callback, (void *) sb); - - free(sb); -} - - -/** - * Get the handle of the window that represents a status bar - * - * \param sb the status bar to get the window handle of - * \return the status bar's window handle - */ -wimp_w ro_gui_status_bar_get_window(struct status_bar *sb) -{ - assert(sb); - - return sb->w; -} - - -/** - * Get the proportional width the status bar is currently using - * - * \param sb the status bar to get the width of - * \return the status bar's width (0...10,000) - */ -unsigned int ro_gui_status_bar_get_width(struct status_bar *sb) -{ - assert(sb); - - return sb->scale; -} - - -/** - * Set the visibility status of the status bar - * - * \param sb the status bar to check the visiblity of - * \param visible if the status bar should be shown or not. - * \return whether the status bar is visible - */ -void ro_gui_status_bar_set_visible(struct status_bar *sb, bool visible) -{ - assert(sb); - - sb->visible = visible; - if (visible) { - ro_gui_status_bar_resize(sb); - } else { - os_error *error = xwimp_close_window(sb->w); - if (error) { - LOG("xwimp_close_window: 0x%x:%s", error->errnum, error->errmess); - } - } -} - - -/** - * Get the visibility status of the status bar - * - * \param sb the status bar to check the visiblity of - * \return whether the status bar is visible - */ -bool ro_gui_status_bar_get_visible(struct status_bar *sb) -{ - assert(sb); - - return sb->visible; -} - - -/** - * Set the value of the progress bar - * - * \param sb the status bar to set the progress of - * \param value the value to use - */ -void ro_gui_status_bar_set_progress_value(struct status_bar *sb, - unsigned int value) -{ - assert(sb); - - ro_gui_status_bar_set_progress_range(sb, - max(value, ro_gui_progress_bar_get_range(sb->pb))); - ro_gui_progress_bar_set_value(sb->pb, value); -} - - -/** - * Set the range of the progress bar - * - * \param sb the status bar to set the range of - * \param range the range of the progress bar - */ -void ro_gui_status_bar_set_progress_range(struct status_bar *sb, - unsigned int range) -{ - unsigned int old_range; - - assert(sb); - - old_range = ro_gui_progress_bar_get_range(sb->pb); - ro_gui_progress_bar_set_range(sb->pb, range); - - LOG("Ranges are %i vs %i", old_range, range); - if ((old_range == 0) && (range != 0)) { - ro_gui_status_position_progress_bar(sb); - } else if ((old_range != 0) && (range == 0)) { - os_error *error = xwimp_close_window( - ro_gui_progress_bar_get_window(sb->pb)); - if (error) { - LOG("xwimp_close_window: 0x%x:%s", error->errnum, error->errmess); - } - } -} - - -/** - * Set the icon for the progress bar - * - * \param sb the status bar to set the icon for - * \param icon the icon to use, or NULL for no icon - */ -void ro_gui_status_bar_set_progress_icon(struct status_bar *sb, - const char *icon) -{ - assert(sb); - - ro_gui_progress_bar_set_icon(sb->pb, icon); -} - - -/** - * Set the text to display in the status bar - * - * \param sb the status bar to set the text for - * \param text the UTF8 text to display, or NULL for none - */ -void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text) -{ - assert(sb); - - sb->text = text; - - /* Schedule a window redraw for 1cs' time. - * - * We do this to ensure that redraws as a result of text changes - * do not prevent other applications obtaining CPU time. - * - * The scheduled callback will be run when we receive the first - * null poll after 1cs has elapsed. It may then issue a redraw - * request to the Wimp. - * - * The scheduler ensures that only one instance of the - * { callback, handle } pair is registered at once. - */ - if (sb->visible && text != NULL) { - riscos_schedule(10, ro_gui_status_bar_redraw_callback, sb); - } -} - - -/** - * Resize a status bar following a change in the dimensions of the - * parent window. - * - * \param sb the status bar to resize - */ -void ro_gui_status_bar_resize(struct status_bar *sb) -{ - int window_width; - int status_width, status_height; - wimp_window_state state; - os_error *error; - os_box extent; - - if ((!sb) || (!sb->visible)) - return; - - /* get the window work area dimensions */ - state.w = sb->parent; - error = xwimp_get_window_state(&state); - if (error) { - LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; - } - window_width = state.visible.x1 - state.visible.x0; - - - /* recalculate the scaled width */ - status_width = (window_width * sb->scale) / 10000; - if (status_width < WIDGET_WIDTH) - status_width = WIDGET_WIDTH; - status_height = ro_get_hscroll_height(sb->parent); - - /* resize the status/resize icons */ - if (status_width != sb->width) { - /* update the window extent */ - int redraw_left, redraw_right; - - extent.x0 = 0; - extent.y0 = 0; - extent.x1 = status_width; - extent.y1 = status_height - 4; - error = xwimp_set_extent(sb->w, &extent); - if (error) { - LOG("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess); - return; - } - - /* re-open the nested window */ - state.w = sb->w; - state.xscroll = 0; - state.yscroll = 0; - state.next = wimp_TOP; - state.visible.x0 = state.visible.x0; - state.visible.y1 = state.visible.y0 - 2; - state.visible.x1 = state.visible.x0 + status_width; - state.visible.y0 = state.visible.y1 - status_height + 4; - error = xwimp_open_window_nested(PTR_WIMP_OPEN(&state), - sb->parent, - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_XORIGIN_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_YORIGIN_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_LS_EDGE_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_BS_EDGE_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_RS_EDGE_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_TS_EDGE_SHIFT); - if (error) { - LOG("xwimp_open_window_nested: 0x%x: %s", error->errnum, error->errmess); - return; - } - ro_gui_status_position_progress_bar(sb); - error = xwimp_resize_icon(sb->w, ICON_WIDGET, - status_width - WIDGET_WIDTH, 0, - status_width, status_height - 4); - if (error) { - LOG("xwimp_resize_icon: 0x%x: %s", error->errnum, error->errmess); - return; - } - - redraw_left = min(status_width, sb->width) - WIDGET_WIDTH - 2; - redraw_right = max(status_width, sb->width); - xwimp_force_redraw(sb->w, redraw_left, 0, - redraw_right, status_height); - sb->width = status_width; - } -} - - -/** - * Process a WIMP redraw request - * - * \param redraw the redraw request to process - */ -void ro_gui_status_bar_redraw(wimp_draw *redraw) -{ - struct status_bar *sb; - os_error *error; - osbool more; - rufl_code code; - - sb = (struct status_bar *)ro_gui_wimp_event_get_user_data(redraw->w); - assert(sb); - - /* initialise the plotters */ - ro_plot_origin_x = 0; - ro_plot_origin_y = 0; - - /* redraw the window */ - error = xwimp_redraw_window(redraw, &more); - if (error) { - LOG("xwimp_redraw_window: 0x%x: %s", error->errnum, error->errmess); - return; - } - while (more) { - /* redraw the status text */ - if (sb->text) { - error = xcolourtrans_set_font_colours(font_CURRENT, - 0xeeeeee00, 0x00000000, 14, 0, 0, 0); - if (error) { - LOG("xcolourtrans_set_font_colours: 0x%x: %s", error->errnum, error->errmess); - return; - } - code = rufl_paint(ro_gui_desktop_font_family, - ro_gui_desktop_font_style, - ro_gui_desktop_font_size, - sb->text, strlen(sb->text), - redraw->box.x0 + 6, redraw->box.y0 + 8, - rufl_BLEND_FONT); - if (code != rufl_OK) { - if (code == rufl_FONT_MANAGER_ERROR) - LOG("rufl_FONT_MANAGER_ERROR: 0x%x: %s", rufl_fm_error->errnum, rufl_fm_error->errmess); - else - LOG("rufl_paint: 0x%x", code); - } - } - - /* separate the widget from the text with a line */ - ro_plotters.rectangle((redraw->box.x0 + sb->width - WIDGET_WIDTH - 2) >> 1, - -redraw->box.y0 >> 1, - (redraw->box.x0 + sb->width - WIDGET_WIDTH) >> 1, - -redraw->box.y1 >> 1, - plot_style_fill_black); - - error = xwimp_get_rectangle(redraw, &more); - if (error) { - LOG("xwimp_get_rectangle: 0x%x: %s", error->errnum, error->errmess); - return; - } - } -} - -/** - * Callback for scheduled redraw - * - * \param handle Callback handle - */ -void ro_gui_status_bar_redraw_callback(void *handle) -{ - struct status_bar *sb = handle; - - wimp_force_redraw(sb->w, 0, 0, sb->width - WIDGET_WIDTH, 65536); -} - - -/** - * Process an mouse_click event for a status window. - * - * \param pointer details of the mouse click - */ -bool ro_gui_status_bar_click(wimp_pointer *pointer) -{ - wimp_drag drag; - os_error *error; - - switch (pointer->i) { - case ICON_WIDGET: - drag.w = pointer->w; - drag.type = wimp_DRAG_SYSTEM_SIZE; - drag.initial.x0 = pointer->pos.x; - drag.initial.x1 = pointer->pos.x; - drag.initial.y0 = pointer->pos.y; - drag.initial.y1 = pointer->pos.y; - error = xwimp_drag_box(&drag); - if (error) { - LOG("xwimp_drag_box: 0x%x: %s", error->errnum, error->errmess); - } - break; - } - return true; -} - - -/** - * Process an open_window request for a status window. - * - * \param open the request to process - */ -void ro_gui_status_bar_open(wimp_open *open) -{ - struct status_bar *sb; - int window_width, status_width; - wimp_window_state state; - os_error *error; - - /* get the parent width for scaling */ - sb = (struct status_bar *)ro_gui_wimp_event_get_user_data(open->w); - state.w = sb->parent; - error = xwimp_get_window_state(&state); - if (error) { - LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; - } - window_width = state.visible.x1 - state.visible.x0; - if (window_width == 0) - window_width = 1; - status_width = open->visible.x1 - open->visible.x0; - if (status_width <= 12) - status_width = 0; - - /* store the new size */ - sb->scale = (10000 * status_width) / window_width; - if (sb->scale > 10000) - sb->scale = 10000; - ro_gui_status_bar_resize(sb); -} - - -/** - * Reposition the progress component following a change in the - * dimension of the status window. - * - * \param sb the status bar to update - */ -void ro_gui_status_position_progress_bar(struct status_bar *sb) -{ - wimp_window_state state; - os_error *error; - int left, right; - - if (!sb) - return; - if (ro_gui_progress_bar_get_range(sb->pb) == 0) - return; - - /* get the window work area dimensions */ - state.w = sb->w; - error = xwimp_get_window_state(&state); - if (error) { - LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; - } - - /* calculate the dimensions */ - right = state.visible.x1 - WIDGET_WIDTH - 2; - left = max(state.visible.x0, right - PROGRESS_WIDTH); - - /* re-open the nested window */ - state.w = ro_gui_progress_bar_get_window(sb->pb); - state.xscroll = 0; - state.yscroll = 0; - state.next = wimp_TOP; - state.visible.x0 = left; - state.visible.x1 = right; - error = xwimp_open_window_nested(PTR_WIMP_OPEN(&state), - sb->w, - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_XORIGIN_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_YORIGIN_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_LS_EDGE_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_BS_EDGE_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_RS_EDGE_SHIFT | - wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT - << wimp_CHILD_TS_EDGE_SHIFT); - if (error) { - LOG("xwimp_open_window: 0x%x: %s", error->errnum, error->errmess); - } - - /* update the progress bar display on non-standard width */ - if ((right - left) != PROGRESS_WIDTH) - ro_gui_progress_bar_update(sb->pb, right - left, - state.visible.y1 - state.visible.y0); -} diff --git a/riscos/gui/status_bar.h b/riscos/gui/status_bar.h deleted file mode 100644 index 8b5bb35aa..000000000 --- a/riscos/gui/status_bar.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2006 Richard Wilson - * - * 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 . - */ - -/** \file - * UTF8 status bar (interface). - */ - -#ifndef _NETSURF_RISCOS_STATUS_BAR_H_ -#define _NETSURF_RISCOS_STATUS_BAR_H_ - -#include - -struct status_bar; - -struct status_bar *ro_gui_status_bar_create(wimp_w parent, unsigned int width); -void ro_gui_status_bar_destroy(struct status_bar *sb); - -wimp_w ro_gui_status_bar_get_window(struct status_bar *sb); -unsigned int ro_gui_status_bar_get_width(struct status_bar *sb); -void ro_gui_status_bar_resize(struct status_bar *sb); -void ro_gui_status_bar_set_visible(struct status_bar *pb, bool visible); -bool ro_gui_status_bar_get_visible(struct status_bar *sb); -void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text); -void ro_gui_status_bar_set_progress_value(struct status_bar *sb, - unsigned int value); -void ro_gui_status_bar_set_progress_range(struct status_bar *sb, - unsigned int range); -void ro_gui_status_bar_set_progress_icon(struct status_bar *sb, - const char *icon); -#endif diff --git a/riscos/gui/throbber.c b/riscos/gui/throbber.c deleted file mode 100644 index a326f806c..000000000 --- a/riscos/gui/throbber.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright 2004, 2005 Richard Wilson - * Copyright 2011 Stephen Fryatt - * - * 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 . - */ - -/** \file - * Throbber (implementation). - */ - -#include -#include -#include -#include -#include -#include -#include "oslib/os.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" - -#include "utils/log.h" -#include "riscos/gui.h" - -#include "riscos/gui/throbber.h" -#include "riscos/theme.h" -#include "riscos/wimp.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); - ro_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); - ro_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) -{ - - if (throbber->window == NULL) - return false; - - if (throbber->icon != -1) { - os_error *error; - 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); - ro_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 deleted file mode 100644 index 6b2419b6e..000000000 --- a/riscos/gui/throbber.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2005 Richard Wilson - * Copyright 2011 Stephen Fryatt - * - * 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 . - */ - -/** \file - * Throbber (interface). - */ - -#ifndef _NETSURF_RISCOS_THROBBER_H_ -#define _NETSURF_RISCOS_THROBBER_H_ - -#include -#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 x0 top left of bounding box x coordinate - * \param y0 top left of bounding box y coordinate - * \param x1 bottom right of bounding box x coordinate - * \param y1 bottom right of bounding box y coordinate - * \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 screenpos The screen 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 deleted file mode 100644 index 053014784..000000000 --- a/riscos/gui/url_bar.c +++ /dev/null @@ -1,1344 +0,0 @@ -/* - * Copyright 2004, 2005 Richard Wilson - * Copyright 2011-2014 Stephen Fryatt - * - * 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 . - */ - -/** \file - * URL bars (implementation). - */ - -#include -#include -#include -#include -#include -#include -#include "oslib/os.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" - -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utf8.h" -#include "utils/utils.h" -#include "content/hlcache.h" -#include "content/content.h" -#include "desktop/browser.h" -#include "desktop/plotters.h" - -#include "riscos/gui.h" -#include "riscos/hotlist.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 "riscos/window.h" -#include "riscos/ucstables.h" -#include "riscos/filetype.h" - -#define URLBAR_HEIGHT 52 -#define URLBAR_FAVICON_SIZE 16 -#define URLBAR_HOTLIST_SIZE 17 -#define URLBAR_FAVICON_WIDTH ((5 + URLBAR_FAVICON_SIZE + 5) * 2) -#define URLBAR_HOTLIST_WIDTH ((5 + URLBAR_HOTLIST_SIZE + 5) * 2) -#define URLBAR_MIN_WIDTH 52 -#define URLBAR_GRIGHT_GUTTER 8 -#define URLBAR_FAVICON_NAME_LENGTH 12 - -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; - char *text_buffer_utf8; - - wimp_i suggest_icon; - int suggest_x, suggest_y; - - bool hidden; - bool display; - bool shaded; - - struct { - bool set; - os_box extent; - os_coord offset; - } hotlist; -}; - -static char text_validation[] = "Pptr_write;KN"; -static char suggest_icon[] = "gright"; -static char suggest_validation[] = "R5;Sgright,pgright"; -static char null_text_string[] = ""; - -struct url_bar_resource { - const char *url; - struct hlcache_handle *c; - int height; - bool ready; -}; /**< Treeview content resource data */ -enum url_bar_resource_id { - URLBAR_RES_HOTLIST_ADD = 0, - URLBAR_RES_HOTLIST_REMOVE, - URLBAR_RES_LAST -}; -static struct url_bar_resource url_bar_res[URLBAR_RES_LAST] = { - { "resource:icons/hotlist-add.png", NULL, 0, false }, - { "resource:icons/hotlist-rmv.png", NULL, 0, false } -}; /**< Treeview content resources */ - - -static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set); - - -/* 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 + - URLBAR_HOTLIST_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->hotlist.set = false; - url_bar->hotlist.extent.x0 = 0; - url_bar->hotlist.extent.y0 = 0; - url_bar->hotlist.extent.x1 = 0; - url_bar->hotlist.extent.y1 = 0; - - url_bar->text_size = RO_GUI_MAX_URL_SIZE; - url_bar->text_buffer = malloc(url_bar->text_size); - if (url_bar->text_buffer == NULL) { - free(url_bar); - return NULL; - } - url_bar->text_buffer[0] = 0; - url_bar->text_buffer_utf8 = NULL; - - url_bar->hidden = false; - - return url_bar; -} - - -/** - * 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. - */ - -static 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); - ro_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); - ro_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 - URLBAR_HOTLIST_WIDTH - - 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); - ro_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; - - /* Position the Hotlist icon. */ - - url_bar->hotlist.extent.x0 = url_bar->extent.x1 - eig.x - - URLBAR_HOTLIST_WIDTH - url_bar->suggest_x - - URLBAR_GRIGHT_GUTTER; - url_bar->hotlist.extent.x1 = url_bar->hotlist.extent.x0 + - URLBAR_HOTLIST_WIDTH; - url_bar->hotlist.extent.y0 = centre - (URLBAR_HEIGHT / 2) + eig.y; - url_bar->hotlist.extent.y1 = url_bar->hotlist.extent.y0 + URLBAR_HEIGHT - - 2 * eig.y; - - url_bar->hotlist.offset.x = ((url_bar->hotlist.extent.x1 - - url_bar->hotlist.extent.x0) - - (URLBAR_HOTLIST_SIZE * 2)) / 2; - url_bar->hotlist.offset.y = ((url_bar->hotlist.extent.y1 - - url_bar->hotlist.extent.y0) - - (URLBAR_HOTLIST_SIZE * 2)) / 2 - 1; - - return true; -} - - -/** - * 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. - */ - -static 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) | - (wimp_BUTTON_DOUBLE_CLICK_DRAG << - wimp_ICON_BUTTON_TYPE_SHIFT); - error = xwimp_create_icon(&icon, &url_bar->container_icon); - if (error != NULL) { - LOG("xwimp_create_icon: 0x%x: %s", error->errnum, error->errmess); - ro_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); - ro_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); - ro_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); - ro_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); - ro_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); - ro_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; -} - - -/* 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_HOTLIST_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; - - if (url_bar->text_buffer_utf8 != NULL) - free(url_bar->text_buffer_utf8); - - if (url_bar->text_buffer != NULL) - free(url_bar->text_buffer); - - 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->hidden) { - if (stretch) { - xwimp_force_redraw(url_bar->window, - x0 + URLBAR_FAVICON_WIDTH, y0, - (x1 > url_bar->extent.x1) ? - x1 : url_bar->extent.x1, y1); - } else { - xwimp_force_redraw(url_bar->window, - url_bar->extent.x0, url_bar->extent.y0, - url_bar->extent.x1, url_bar->extent.y1); - xwimp_force_redraw(url_bar->window, x0, 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); -} - - -/* 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; - bool draw_favicon = true; - bool draw_hotlist = true; - - /* Test for a valid URL bar */ - if (url_bar == NULL || url_bar->hidden) - return; - - if ((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)) { - /* Favicon not in redraw area */ - draw_favicon = false; - } - - if ((redraw->clip.x0 - (redraw->box.x0 - redraw->xscroll)) > - (url_bar->hotlist.extent.x1) || - (redraw->clip.y0 - (redraw->box.y1 - redraw->yscroll)) > - (url_bar->hotlist.extent.y1) || - (redraw->clip.x1 - (redraw->box.x0 - redraw->xscroll)) < - (url_bar->hotlist.extent.x0) || - (redraw->clip.y1 - (redraw->box.y1 - redraw->yscroll)) < - (url_bar->hotlist.extent.y0)) { - /* Hotlist icon not in redraw area */ - draw_hotlist = false; - } - - if (draw_favicon) { - 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 { - struct content_redraw_data data; - struct redraw_context ctx = { - .interactive = true, - .background_images = true, - .plot = &ro_plotters - }; - - 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; - - data.x = (url_bar->favicon_extent.x0 + - url_bar->favicon_offset.x) / 2; - data.y = (url_bar->favicon_offset.y - - url_bar->favicon_extent.y1) / 2; - data.width = url_bar->favicon_width; - data.height = url_bar->favicon_height; - data.background_colour = 0xFFFFFF; - data.scale = 1; - data.repeat_x = false; - data.repeat_y = false; - - content_redraw(url_bar->favicon_content, - &data, &clip, &ctx); - } - } - - if (draw_hotlist) { - struct content_redraw_data data; - struct redraw_context ctx = { - .interactive = true, - .background_images = true, - .plot = &ro_plotters - }; - struct url_bar_resource *hotlist_icon = url_bar->hotlist.set ? - &(url_bar_res[URLBAR_RES_HOTLIST_REMOVE]) : - &(url_bar_res[URLBAR_RES_HOTLIST_ADD]); - - xwimp_set_colour(wimp_COLOUR_WHITE); - xos_plot(os_MOVE_TO, - (redraw->box.x0 - redraw->xscroll) + - url_bar->hotlist.extent.x0, - (redraw->box.y1 - redraw->yscroll) + - url_bar->hotlist.extent.y0); - xos_plot(os_PLOT_TO | os_PLOT_RECTANGLE, - (redraw->box.x0 - redraw->xscroll) + - url_bar->hotlist.extent.x1, - (redraw->box.y1 - redraw->yscroll) + - url_bar->hotlist.extent.y1); - - if (hotlist_icon->ready == false) { - return; - } - - 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; - - data.x = (url_bar->hotlist.extent.x0 + - url_bar->hotlist.offset.x) / 2; - data.y = (url_bar->hotlist.offset.y - - url_bar->hotlist.extent.y1) / 2; - data.width = URLBAR_HOTLIST_SIZE; - data.height = URLBAR_HOTLIST_SIZE; - data.background_colour = 0xFFFFFF; - data.scale = 1; - data.repeat_x = false; - data.repeat_y = false; - - content_redraw(hotlist_icon->c, &data, &clip, &ctx); - } -} - - -/* 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 have a Select or Adjust click, check if it originated on the - * hotlist icon; if it did, return an event. - */ - - if (pointer->buttons == wimp_SINGLE_SELECT || - pointer->buttons == wimp_SINGLE_ADJUST) { - if (pos.x >= url_bar->hotlist.extent.x0 && - pos.x <= url_bar->hotlist.extent.x1 && - pos.y >= url_bar->hotlist.extent.y0 && - pos.y <= url_bar->hotlist.extent.y1) { - if (pointer->buttons == wimp_SINGLE_SELECT && - action != NULL) - *action = TOOLBAR_URL_SELECT_HOTLIST; - else if (pointer->buttons == wimp_SINGLE_ADJUST && - action != NULL) - *action = TOOLBAR_URL_ADJUST_HOTLIST; - return true; - } - } - - /* 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 *urltxt; - struct gui_window *g; - - if (url_bar == NULL || url_bar->suggest_icon != i || - menu != ro_gui_url_suggest_menu) - return false; - - urltxt = ro_gui_url_suggest_get_selection(selection); - g = ro_gui_toolbar_lookup(url_bar->window); - - if (urltxt != NULL && g != NULL && g->bw != NULL) { - nsurl *url; - nserror error; - - error = nsurl_create(urltxt, &url); - if (error != NSERROR_OK) { - ro_warn_user(messages_get_errorcode(error), 0); - } else { - ro_gui_window_set_url(g, url); - - browser_window_navigate(g->bw, - url, - NULL, - BW_NAVIGATE_HISTORY, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - } - - 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 if (pos.x >= url_bar->hotlist.extent.x0 && - pos.x <= url_bar->hotlist.extent.x1 && - pos.y >= url_bar->hotlist.extent.y0 && - pos.y <= url_bar->hotlist.extent.y1) - *suffix = "Hot"; - else 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) - *suffix = "Fav"; - 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); - ro_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; - char *local_text = NULL; - const char *local_url; - nsurl *n; - - if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL) - return; - - /* Before we do anything with the URL, get it into local encoding so - * that behaviour is consistant with the rest of the URL Bar module - * (which will act on the icon's text buffer, which is always in local - * encoding). - */ - - if (is_utf8) { - nserror err; - - err = utf8_to_local_encoding(url, 0, &local_text); - if (err != NSERROR_OK) { - /* A bad encoding should never happen, so assert this */ - assert(err != NSERROR_BAD_ENCODING); - LOG("utf8_to_enc failed"); - /* Paranoia */ - local_text = NULL; - } - local_url = (local_text != NULL) ? local_text : url; - } else { - local_url = url; - } - - /* Copy the text into the icon buffer. If the text is too long, blank - * the buffer and warn the user. - */ - - if (strlen(local_url) >= url_bar->text_size) { - url_bar->text_buffer[0] = '\0'; - ro_warn_user("LongURL", NULL); - LOG("Long URL (%zu chars): %s", strlen(url), url); - } else { - strncpy(url_bar->text_buffer, local_url, - url_bar->text_size - 1); - url_bar->text_buffer[url_bar->text_size - 1] = '\0'; - } - - if (local_text != NULL) - free(local_text); - - /* Set the hotlist flag. */ - - if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) { - ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); - nsurl_unref(n); - } - - /* If there's no icon, then there's nothing else to do... */ - - if (url_bar->text_icon == -1) - return; - - /* ...if there is, redraw the icon and fix the caret's position. */ - - ro_gui_redraw_icon(url_bar->window, url_bar->text_icon); - - error = xwimp_get_caret_position(&caret); - if (error) { - LOG("xwimp_get_caret_position: 0x%x: %s", error->errnum, error->errmess); - ro_warn_user("WimpError", error->errmess); - return; - } - - if (set_caret || (caret.w == url_bar->window && - caret.i == url_bar->text_icon)) { - const char *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); - ro_warn_user("WimpError", error->errmess); - } - } -} - - -/* This is an exported interface documented in url_bar.h */ - -void ro_gui_url_bar_update_hotlist(struct url_bar *url_bar) -{ - const char *url; - nsurl *n; - - if (url_bar == NULL) - return; - - url = (const char *) url_bar->text_buffer; - if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) { - ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); - nsurl_unref(n); - } -} - - -/** - * Set the state of a URL Bar's hotlist icon. - * - * \param *url_bar The URL Bar to update. - * \param set TRUE to set the hotlist icon; FALSE to clear it. - */ - -static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set) -{ - if (url_bar == NULL || set == url_bar->hotlist.set) - return; - - url_bar->hotlist.set = set; - - if (!url_bar->hidden) { - xwimp_force_redraw(url_bar->window, - url_bar->hotlist.extent.x0, - url_bar->hotlist.extent.y0, - url_bar->hotlist.extent.x1, - url_bar->hotlist.extent.y1); - } -} - - -/* 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) || (url_bar->text_buffer == NULL)) - return NULL; - - if (url_bar->text_buffer_utf8 != NULL) { - free(url_bar->text_buffer_utf8); - url_bar->text_buffer_utf8 = NULL; - } - - if (url_bar->text_buffer[0] == '\0') - return (const char *) url_bar->text_buffer; - - if (utf8_from_local_encoding(url_bar->text_buffer, 0, &url_bar->text_buffer_utf8) == NSERROR_OK) { - return (const char *) url_bar->text_buffer_utf8; - } - - 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); - ro_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) -{ - const char *url; - nsurl *n; - - if (url_bar == NULL || url_bar->hidden || key == NULL) - return false; - - if (key->w != url_bar->window || key->i != url_bar->text_icon) - return false; - - /* Update hotlist indicator */ - - url = (const char *) url_bar->text_buffer; - if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) { - ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); - nsurl_unref(n); - } else if (url_bar->hotlist.set) { - ro_gui_url_bar_set_hotlist(url_bar, false); - } - - return true; -} - - -/* 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_NONE; - - if (url_bar == NULL) - return false; - - if (h != NULL) - type = content_get_type(h); - - // \TODO -- Maybe test for CONTENT_ICO ??? - - if (type == CONTENT_IMAGE) { - 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 gui_window *g) -{ - int type = 0; - char sprite[URLBAR_FAVICON_NAME_LENGTH]; - struct hlcache_handle *h; - - if (url_bar == NULL || g == NULL) - return false; - - h = browser_window_get_content(g->bw); - if (h != NULL) - type = ro_content_filetype(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; -} - - -/** - * Callback for hlcache. - */ -static nserror ro_gui_url_bar_res_cb(hlcache_handle *handle, - const hlcache_event *event, void *pw) -{ - struct url_bar_resource *r = pw; - - switch (event->type) { - case CONTENT_MSG_READY: - case CONTENT_MSG_DONE: - r->ready = true; - r->height = content_get_height(handle); - break; - - default: - break; - } - - return NSERROR_OK; -} - - -/* Exported interface, documented in url_bar.h */ -bool ro_gui_url_bar_init(void) -{ - int i; - - for (i = 0; i < URLBAR_RES_LAST; i++) { - nsurl *url; - if (nsurl_create(url_bar_res[i].url, &url) == NSERROR_OK) { - hlcache_handle_retrieve(url, 0, NULL, NULL, - ro_gui_url_bar_res_cb, - &(url_bar_res[i]), NULL, - CONTENT_IMAGE, &(url_bar_res[i].c)); - nsurl_unref(url); - } - } - - return true; -} - - -/* Exported interface, documented in url_bar.h */ -void ro_gui_url_bar_fini(void) -{ - int i; - - for (i = 0; i < URLBAR_RES_LAST; i++) { - hlcache_handle_release(url_bar_res[i].c); - } -} diff --git a/riscos/gui/url_bar.h b/riscos/gui/url_bar.h deleted file mode 100644 index 981afb35f..000000000 --- a/riscos/gui/url_bar.h +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright 2005 Richard Wilson - * Copyright 2011 Stephen Fryatt - * - * 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 . - */ - -/** \file - * URL bars (interface). - */ - -#ifndef _NETSURF_RISCOS_URLBAR_H_ -#define _NETSURF_RISCOS_URLBAR_H_ - -#include -#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, - TOOLBAR_URL_SELECT_HOTLIST, - TOOLBAR_URL_ADJUST_HOTLIST -} url_bar_action; - -struct url_bar; -struct hlcache_handle; - -/** - * Initialise the url bar module. - * - * \return True iff success, else false. - */ - -bool ro_gui_url_bar_init(void); - -/** - * Finalise the url bar module - */ - -void ro_gui_url_bar_fini(void); - -/** - * 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 bar. - * - * \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); - - -/** - * Update the state of a URL Bar's hotlist icon to reflect any changes to the - * URL or the contents of the hotlist. - * - * \param *url_bar The URL Bar to update. - */ - -void ro_gui_url_bar_update_hotlist(struct url_bar *url_bar); - - -/** - * 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 key The key pressed - * \return true if the keypress 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 - * content within the supplied window. - * - * \param *url_bar The URL Bar to update the favicon on. - * \param *g The window with the content to use. - * \return true if successful; else false. - */ - -bool ro_gui_url_bar_set_content_favicon(struct url_bar *url_bar, - struct gui_window *g); - - -/** - * 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 - -- cgit v1.2.3