2011-02-21 02:16:33 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2004, 2005 Richard Wilson <info@tinct.net>
|
2014-01-03 02:25:23 +04:00
|
|
|
* Copyright 2011-2013 Stephen Fryatt <stevef@netsurf-browser.org>
|
2011-02-21 02:16:33 +03:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* URL bars (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <alloca.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/os.h"
|
|
|
|
#include "oslib/osspriteop.h"
|
|
|
|
#include "oslib/wimp.h"
|
2014-01-26 18:35:57 +04:00
|
|
|
#include "riscos/gui.h"
|
2013-12-30 19:41:38 +04:00
|
|
|
#include "riscos/hotlist.h"
|
2011-02-21 02:16:33 +03:00
|
|
|
#include "riscos/gui/url_bar.h"
|
|
|
|
#include "riscos/theme.h"
|
|
|
|
#include "riscos/url_suggest.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
2014-01-16 18:28:25 +04:00
|
|
|
#include "riscos/window.h"
|
2011-02-21 02:16:33 +03:00
|
|
|
#include "utils/log.h"
|
2013-02-18 16:58:04 +04:00
|
|
|
#include "utils/messages.h"
|
2014-01-26 17:30:08 +04:00
|
|
|
#include "utils/utf8.h"
|
2011-02-21 02:16:33 +03:00
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
|
|
#define URLBAR_HEIGHT 52
|
2013-11-22 15:21:52 +04:00
|
|
|
#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)
|
2011-02-21 02:16:33 +03:00
|
|
|
#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;
|
|
|
|
|
|
|
|
wimp_i suggest_icon;
|
|
|
|
int suggest_x, suggest_y;
|
|
|
|
|
|
|
|
bool hidden;
|
|
|
|
bool display;
|
|
|
|
bool shaded;
|
2013-11-22 15:21:52 +04:00
|
|
|
|
|
|
|
struct {
|
2013-12-30 19:41:38 +04:00
|
|
|
bool set;
|
2013-11-22 15:21:52 +04:00
|
|
|
os_box extent;
|
|
|
|
os_coord offset;
|
|
|
|
} hotlist;
|
2011-02-21 02:16:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static char text_validation[] = "Pptr_write;KN";
|
|
|
|
static char suggest_icon[] = "gright";
|
|
|
|
static char suggest_validation[] = "R5;Sgright,pgright";
|
|
|
|
static char null_text_string[] = "";
|
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
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 */
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
url_bar->x_min = URLBAR_FAVICON_WIDTH + URLBAR_MIN_WIDTH +
|
|
|
|
URLBAR_HOTLIST_WIDTH;
|
2011-02-21 02:16:33 +03:00
|
|
|
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);
|
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
url_bar->hotlist.set = false;
|
2013-11-22 15:21:52 +04:00
|
|
|
url_bar->hotlist.extent.x0 = 0;
|
|
|
|
url_bar->hotlist.extent.y0 = 0;
|
|
|
|
url_bar->hotlist.extent.x1 = 0;
|
|
|
|
url_bar->hotlist.extent.y1 = 0;
|
|
|
|
|
2014-01-26 18:35:57 +04:00
|
|
|
url_bar->text_size = RO_GUI_MAX_URL_SIZE;
|
2011-02-21 02:16:33 +03:00
|
|
|
url_bar->text_buffer = malloc(url_bar->text_size);
|
|
|
|
strncpy(url_bar->text_buffer, "", url_bar->text_size);
|
|
|
|
|
|
|
|
url_bar->hidden = false;
|
|
|
|
|
|
|
|
return url_bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
static bool ro_gui_url_bar_icon_resize(struct url_bar *url_bar, bool full)
|
2011-02-21 02:16:33 +03:00
|
|
|
{
|
2013-11-22 17:02:45 +04:00
|
|
|
int x0, y0, x1, y1;
|
|
|
|
int centre;
|
|
|
|
os_error *error;
|
|
|
|
os_coord eig = {1, 1};
|
|
|
|
wimp_caret caret;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
if (url_bar == NULL || url_bar->window == NULL)
|
|
|
|
return false;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* calculate 1px in OS units */
|
|
|
|
ro_convert_pixels_to_os_units(&eig, (os_mode) -1);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* The vertical centre line of the widget's extent. */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
centre = url_bar->extent.y0 +
|
|
|
|
(url_bar->extent.y1 - url_bar->extent.y0) / 2;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* Position the container icon. */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
if (url_bar->container_icon != -1) {
|
|
|
|
x0 = url_bar->extent.x0;
|
|
|
|
x1 = url_bar->extent.x1 -
|
|
|
|
url_bar->suggest_x - URLBAR_GRIGHT_GUTTER;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
y0 = centre - (URLBAR_HEIGHT / 2);
|
|
|
|
y1 = y0 + URLBAR_HEIGHT;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
error = xwimp_resize_icon(url_bar->window,
|
|
|
|
url_bar->container_icon,
|
|
|
|
x0, y0, x1, y1);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_resize_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
url_bar->container_icon = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* Position the URL Suggest icon. */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
if (url_bar->suggest_icon != -1) {
|
|
|
|
x0 = url_bar->extent.x1 - url_bar->suggest_x;
|
|
|
|
x1 = url_bar->extent.x1;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
y0 = centre - (url_bar->suggest_y / 2);
|
|
|
|
y1 = y0 + url_bar->suggest_y;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
error = xwimp_resize_icon(url_bar->window,
|
|
|
|
url_bar->suggest_icon,
|
|
|
|
x0, y0, x1, y1);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_resize_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
url_bar->suggest_icon = -1;
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* Position the Text icon. */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
y0 = centre - (URLBAR_HEIGHT / 2) + eig.y;
|
|
|
|
y1 = y0 + URLBAR_HEIGHT - 2 * eig.y;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
error = xwimp_resize_icon(url_bar->window,
|
|
|
|
url_bar->text_icon,
|
|
|
|
x0, y0, x1, y1);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_resize_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
url_bar->text_icon = -1;
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* Position the Favicon icon. */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* Position the Hotlist icon. */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
return true;
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
static bool ro_gui_url_bar_icon_update(struct url_bar *url_bar)
|
2011-02-21 02:16:33 +03:00
|
|
|
{
|
|
|
|
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 |
|
2013-12-30 01:39:23 +04:00
|
|
|
(wimp_COLOUR_BLACK <<
|
|
|
|
wimp_ICON_FG_COLOUR_SHIFT) |
|
|
|
|
(wimp_BUTTON_DOUBLE_CLICK_DRAG <<
|
|
|
|
wimp_ICON_BUTTON_TYPE_SHIFT);
|
2011-02-21 02:16:33 +03:00
|
|
|
error = xwimp_create_icon(&icon, &url_bar->container_icon);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_create_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
url_bar->container_icon = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
resize = true;
|
|
|
|
} else if (url_bar->hidden && url_bar->container_icon != -1){
|
|
|
|
error = xwimp_delete_icon(url_bar->window,
|
|
|
|
url_bar->container_icon);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_delete_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
url_bar->container_icon = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create or delete the text icon. */
|
|
|
|
|
|
|
|
if (!url_bar->hidden && url_bar->text_icon == -1) {
|
|
|
|
icon.icon.data.indirected_text.text = url_bar->text_buffer;
|
|
|
|
icon.icon.data.indirected_text.validation = text_validation;
|
|
|
|
icon.icon.data.indirected_text.size = url_bar->text_size;
|
|
|
|
icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED |
|
|
|
|
wimp_ICON_VCENTRED | wimp_ICON_FILLED |
|
|
|
|
(wimp_COLOUR_BLACK <<
|
|
|
|
wimp_ICON_FG_COLOUR_SHIFT);
|
|
|
|
if (url_bar->display)
|
|
|
|
icon.icon.flags |= (wimp_BUTTON_NEVER <<
|
|
|
|
wimp_ICON_BUTTON_TYPE_SHIFT);
|
|
|
|
else
|
|
|
|
icon.icon.flags |= (wimp_BUTTON_WRITE_CLICK_DRAG <<
|
|
|
|
wimp_ICON_BUTTON_TYPE_SHIFT);
|
|
|
|
error = xwimp_create_icon(&icon, &url_bar->text_icon);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
url_bar->text_icon = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
resize = true;
|
|
|
|
} else if (url_bar->hidden && url_bar->text_icon != -1) {
|
|
|
|
error = xwimp_delete_icon(url_bar->window,
|
|
|
|
url_bar->text_icon);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_delete_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
url_bar->text_icon = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create or delete the suggest icon. */
|
|
|
|
|
|
|
|
if (!url_bar->hidden && url_bar->suggest_icon == -1) {
|
|
|
|
icon.icon.data.indirected_text.text = null_text_string;
|
|
|
|
icon.icon.data.indirected_text.size = 1;
|
|
|
|
icon.icon.data.indirected_text.validation = suggest_validation;
|
|
|
|
icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE |
|
|
|
|
wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED |
|
|
|
|
wimp_ICON_VCENTRED | (wimp_BUTTON_CLICK <<
|
|
|
|
wimp_ICON_BUTTON_TYPE_SHIFT);
|
|
|
|
error = xwimp_create_icon(&icon, &url_bar->suggest_icon);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url_bar->display)
|
|
|
|
ro_gui_wimp_event_register_menu_gright(url_bar->window,
|
|
|
|
wimp_ICON_WINDOW, url_bar->suggest_icon,
|
|
|
|
ro_gui_url_suggest_menu);
|
|
|
|
|
|
|
|
if (!ro_gui_url_bar_update_urlsuggest(url_bar))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
resize = true;
|
|
|
|
} else if (url_bar->hidden && url_bar->suggest_icon != -1) {
|
|
|
|
ro_gui_wimp_event_deregister(url_bar->window,
|
|
|
|
url_bar->suggest_icon);
|
|
|
|
error = xwimp_delete_icon(url_bar->window,
|
|
|
|
url_bar->suggest_icon);
|
|
|
|
if (error != NULL) {
|
|
|
|
LOG(("xwimp_delete_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
url_bar->suggest_icon = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If any icons were created, resize the bar. */
|
|
|
|
|
|
|
|
if (resize && !ro_gui_url_bar_icon_resize(url_bar, true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If there are any icons, apply shading as necessary. */
|
|
|
|
|
|
|
|
if (url_bar->container_icon != -1)
|
|
|
|
ro_gui_set_icon_shaded_state(url_bar->window,
|
|
|
|
url_bar->container_icon, url_bar->shaded);
|
|
|
|
|
|
|
|
if (url_bar->text_icon != -1)
|
|
|
|
ro_gui_set_icon_shaded_state(url_bar->window,
|
|
|
|
url_bar->text_icon, url_bar->shaded);
|
|
|
|
|
|
|
|
if (url_bar->suggest_icon != -1)
|
|
|
|
ro_gui_set_icon_shaded_state(url_bar->window,
|
|
|
|
url_bar->suggest_icon, url_bar->shaded);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* This is an exported interface documented in url_bar.h */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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)
|
2011-02-21 02:16:33 +03:00
|
|
|
{
|
2013-11-22 17:02:45 +04:00
|
|
|
if (url_bar == NULL)
|
2011-02-21 02:16:33 +03:00
|
|
|
return false;
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
url_bar->theme = theme;
|
|
|
|
url_bar->window = window;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
url_bar->display = display;
|
|
|
|
url_bar->shaded = shaded;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
url_bar->container_icon = -1;
|
|
|
|
url_bar->text_icon = -1;
|
|
|
|
url_bar->suggest_icon = -1;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
ro_gui_wimp_get_sprite_dimensions((osspriteop_area *) -1,
|
|
|
|
suggest_icon, &url_bar->suggest_x, &url_bar->suggest_y);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
return ro_gui_url_bar_icon_update(url_bar);
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* This is an exported interface documented in url_bar.h */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
void ro_gui_url_bar_destroy(struct url_bar *url_bar)
|
|
|
|
{
|
|
|
|
if (url_bar == NULL)
|
|
|
|
return;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
free(url_bar);
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
|
|
|
|
/* 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;
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* This is an exported interface documented in url_bar.h */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
bool ro_gui_url_bar_set_extent(struct url_bar *url_bar,
|
|
|
|
int x0, int y0, int x1, int y1)
|
|
|
|
{
|
|
|
|
bool stretch;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
if (url_bar == NULL)
|
|
|
|
return false;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
if ((x1 - x0) < url_bar->x_min || (y1 - y0) < url_bar->y_min)
|
|
|
|
return false;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
if (url_bar->extent.x0 == x0 && url_bar->extent.y0 == y0 &&
|
|
|
|
url_bar->extent.x1 == x1 &&
|
|
|
|
url_bar->extent.y1 == y1)
|
|
|
|
return true;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* If it's only the length that changes, less needs to be updated. */
|
2013-11-22 15:21:52 +04:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
stretch = (url_bar->extent.x0 == x0 && url_bar->extent.y0 == y0 &&
|
|
|
|
url_bar->extent.y1 == y1) ? true : false;
|
2013-11-22 15:21:52 +04:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
/* Redraw the relevant bits of the toolbar. */
|
2013-11-22 15:21:52 +04:00
|
|
|
|
2013-11-22 17:02:45 +04:00
|
|
|
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);
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2013-11-22 15:21:52 +04:00
|
|
|
wimp_icon icon;
|
|
|
|
struct rect clip;
|
|
|
|
bool draw_favicon = true;
|
|
|
|
bool draw_hotlist = true;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
/* Test for a valid URL bar */
|
|
|
|
if (url_bar == NULL || url_bar->hidden)
|
2011-02-21 02:16:33 +03:00
|
|
|
return;
|
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
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) {
|
2011-06-29 00:17:39 +04:00
|
|
|
struct content_redraw_data data;
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
2011-12-24 02:39:25 +04:00
|
|
|
.background_images = true,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &ro_plotters
|
|
|
|
};
|
2013-12-30 19:41:38 +04:00
|
|
|
struct url_bar_resource *hotlist_icon = url_bar->hotlist.set ?
|
|
|
|
&(url_bar_res[URLBAR_RES_HOTLIST_REMOVE]) :
|
|
|
|
&(url_bar_res[URLBAR_RES_HOTLIST_ADD]);
|
2011-06-29 00:17:39 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
xwimp_set_colour(wimp_COLOUR_WHITE);
|
|
|
|
xos_plot(os_MOVE_TO,
|
|
|
|
(redraw->box.x0 - redraw->xscroll) +
|
2013-11-22 15:21:52 +04:00
|
|
|
url_bar->hotlist.extent.x0,
|
2011-02-21 02:16:33 +03:00
|
|
|
(redraw->box.y1 - redraw->yscroll) +
|
2013-11-22 15:21:52 +04:00
|
|
|
url_bar->hotlist.extent.y0);
|
2011-02-21 02:16:33 +03:00
|
|
|
xos_plot(os_PLOT_TO | os_PLOT_RECTANGLE,
|
|
|
|
(redraw->box.x0 - redraw->xscroll) +
|
2013-11-22 15:21:52 +04:00
|
|
|
url_bar->hotlist.extent.x1,
|
2011-02-21 02:16:33 +03:00
|
|
|
(redraw->box.y1 - redraw->yscroll) +
|
2013-11-22 15:21:52 +04:00
|
|
|
url_bar->hotlist.extent.y1);
|
|
|
|
|
2013-11-22 15:58:53 +04:00
|
|
|
if (hotlist_icon->ready == false) {
|
2013-11-22 15:21:52 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
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;
|
2011-06-29 00:17:39 +04:00
|
|
|
data.background_colour = 0xFFFFFF;
|
|
|
|
data.scale = 1;
|
|
|
|
data.repeat_x = false;
|
|
|
|
data.repeat_y = false;
|
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
content_redraw(hotlist_icon->c, &data, &clip, &ctx);
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2013-11-22 15:52:34 +04:00
|
|
|
os_coord pos;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-12-30 16:36:24 +04:00
|
|
|
/* If we have a Select or Adjust click, check if it originated on the
|
|
|
|
* hotlist icon; if it did, return an event.
|
|
|
|
*/
|
2013-12-30 01:39:23 +04:00
|
|
|
|
2013-12-30 16:36:24 +04:00
|
|
|
if (pointer->buttons == wimp_SINGLE_SELECT ||
|
|
|
|
pointer->buttons == wimp_SINGLE_ADJUST) {
|
2013-11-22 15:21:52 +04:00
|
|
|
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) {
|
2013-12-30 16:36:24 +04:00
|
|
|
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;
|
2013-11-22 15:21:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* 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 &&
|
2013-11-22 15:21:52 +04:00
|
|
|
pos.y <= url_bar->favicon_extent.y1) {
|
2011-02-21 02:16:33 +03:00
|
|
|
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)
|
|
|
|
{
|
2013-02-14 19:09:28 +04:00
|
|
|
const char *urltxt;
|
|
|
|
struct gui_window *g;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
if (url_bar == NULL || url_bar->suggest_icon != i ||
|
|
|
|
menu != ro_gui_url_suggest_menu)
|
|
|
|
return false;
|
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
urltxt = ro_gui_url_suggest_get_selection(selection);
|
2011-02-21 02:16:33 +03:00
|
|
|
g = ro_gui_toolbar_lookup(url_bar->window);
|
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
if (urltxt != NULL && g != NULL && g->bw != NULL) {
|
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
gui_window_set_url(g, urltxt);
|
|
|
|
|
|
|
|
error = nsurl_create(urltxt, &url);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
} else {
|
|
|
|
browser_window_navigate(g->bw,
|
|
|
|
url,
|
|
|
|
NULL,
|
2013-02-18 15:51:42 +04:00
|
|
|
BROWSER_WINDOW_HISTORY |
|
|
|
|
BROWSER_WINDOW_VERIFIABLE,
|
2013-02-14 19:09:28 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
2013-12-30 20:38:27 +04:00
|
|
|
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";
|
2011-02-21 02:16:33 +03:00
|
|
|
else
|
|
|
|
*suffix = "";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
bool ro_gui_url_bar_take_caret(struct url_bar *url_bar)
|
|
|
|
{
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
if (url_bar == NULL || url_bar->hidden)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
error = xwimp_set_caret_position(url_bar->window, url_bar->text_icon,
|
|
|
|
-1, -1, -1, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_set_caret_position: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
|
|
|
|
bool is_utf8, bool set_caret)
|
|
|
|
{
|
|
|
|
wimp_caret caret;
|
|
|
|
os_error *error;
|
2014-01-26 17:30:08 +04:00
|
|
|
char *local_text = NULL;
|
|
|
|
const char *set_url, *local_url;
|
2013-11-22 15:21:52 +04:00
|
|
|
nsurl *n;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2014-01-26 17:30:08 +04:00
|
|
|
if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL)
|
2011-02-21 02:16:33 +03:00
|
|
|
return;
|
|
|
|
|
2014-01-26 17:30:08 +04:00
|
|
|
/* 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) {
|
|
|
|
utf8_convert_ret err;
|
|
|
|
|
|
|
|
err = utf8_to_local_encoding(url, 0, &local_text);
|
|
|
|
if (err != UTF8_CONVERT_OK) {
|
|
|
|
/* A bad encoding should never happen, so assert this */
|
|
|
|
assert(err != UTF8_CONVERT_BADENC);
|
|
|
|
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) {
|
2014-01-26 19:15:49 +04:00
|
|
|
strncpy(url_bar->text_buffer, "", url_bar->text_size - 1);
|
|
|
|
url_bar->text_buffer[url_bar->text_size - 1] = '\0';
|
2014-01-26 17:30:08 +04:00
|
|
|
warn_user("LongURL", NULL);
|
|
|
|
LOG(("Long URL (%d chars): %s", strlen(url), url));
|
|
|
|
} else {
|
2014-01-26 19:15:49 +04:00
|
|
|
strncpy(url_bar->text_buffer, local_url,
|
|
|
|
url_bar->text_size - 1);
|
|
|
|
url_bar->text_buffer[url_bar->text_size - 1] = '\0';
|
2014-01-26 17:30:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (local_text != NULL)
|
|
|
|
free(local_text);
|
|
|
|
|
|
|
|
/* Set the hotlist flag. */
|
|
|
|
|
|
|
|
if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) {
|
2013-12-30 19:41:38 +04:00
|
|
|
ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
|
2013-11-22 15:21:52 +04:00
|
|
|
nsurl_unref(n);
|
|
|
|
}
|
|
|
|
|
2014-01-26 17:30:08 +04:00
|
|
|
/* If there's no icon, then there's nothing else to do... */
|
|
|
|
|
|
|
|
if (url_bar->text_icon == -1)
|
2011-02-21 02:16:33 +03:00
|
|
|
return;
|
|
|
|
|
2014-01-26 17:30:08 +04:00
|
|
|
/* ...if there is, redraw the icon and fix the caret's position. */
|
|
|
|
|
|
|
|
ro_gui_redraw_icon(url_bar->window, url_bar->text_icon);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
error = xwimp_get_caret_position(&caret);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_caret_position: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_caret || (caret.w == url_bar->window &&
|
|
|
|
caret.i == url_bar->text_icon)) {
|
|
|
|
set_url = ro_gui_get_icon_string(url_bar->window,
|
|
|
|
url_bar->text_icon);
|
|
|
|
|
|
|
|
error = xwimp_set_caret_position(url_bar->window,
|
|
|
|
url_bar->text_icon, 0, 0, -1, strlen(set_url));
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_set_caret_position: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-23 19:30:26 +04:00
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
void ro_gui_url_bar_update_hotlist(struct url_bar *url_bar)
|
2013-11-23 19:30:26 +04:00
|
|
|
{
|
2013-12-30 19:41:38 +04:00
|
|
|
const char *url;
|
2013-11-23 19:30:26 +04:00
|
|
|
nsurl *n;
|
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
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));
|
2013-11-23 19:30:26 +04:00
|
|
|
nsurl_unref(n);
|
2013-12-30 19:41:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-11-23 19:30:26 +04:00
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
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;
|
2014-01-03 02:25:23 +04:00
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
url_bar->hotlist.set = set;
|
2014-01-03 02:25:23 +04:00
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
if (!url_bar->hidden) {
|
2013-11-23 19:30:26 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
const char *ro_gui_url_bar_get_url(struct url_bar *url_bar)
|
|
|
|
{
|
|
|
|
if (url_bar == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (const char *) url_bar->text_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
bool ro_gui_url_bar_get_url_extent(struct url_bar *url_bar, os_box *extent)
|
|
|
|
{
|
|
|
|
wimp_icon_state state;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
if (url_bar == NULL || url_bar->hidden)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (extent == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
state.w = url_bar->window;
|
|
|
|
state.i = url_bar->container_icon;
|
|
|
|
error = xwimp_get_icon_state(&state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_icon_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
extent->x0 = state.icon.extent.x0;
|
|
|
|
extent->y0 = state.icon.extent.y0;
|
|
|
|
extent->x1 = state.icon.extent.x1;
|
|
|
|
extent->y1 = state.icon.extent.y1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
bool ro_gui_url_bar_test_for_text_field_click(struct url_bar *url_bar,
|
|
|
|
wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
if (url_bar == NULL || url_bar->hidden || pointer == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (pointer->w == url_bar->window &&
|
|
|
|
pointer->i == url_bar->text_icon) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar,
|
|
|
|
wimp_key *key)
|
|
|
|
{
|
2013-11-22 15:52:34 +04:00
|
|
|
const char *url;
|
|
|
|
nsurl *n;
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
if (url_bar == NULL || url_bar->hidden || key == NULL)
|
|
|
|
return false;
|
|
|
|
|
2013-11-22 15:52:34 +04:00
|
|
|
if (key->w != url_bar->window || key->i != url_bar->text_icon)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Update hotlist indicator */
|
2014-01-03 02:25:23 +04:00
|
|
|
|
2013-11-22 15:52:34 +04:00
|
|
|
url = (const char *) url_bar->text_buffer;
|
|
|
|
if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) {
|
2013-12-30 19:41:38 +04:00
|
|
|
ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
|
2013-11-22 15:52:34 +04:00
|
|
|
nsurl_unref(n);
|
2013-12-30 19:41:38 +04:00
|
|
|
} else if (url_bar->hotlist.set) {
|
|
|
|
ro_gui_url_bar_set_hotlist(url_bar, false);
|
2013-11-22 15:52:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
content_type type = CONTENT_NONE;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
if (url_bar == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (h != NULL)
|
|
|
|
type = content_get_type(h);
|
|
|
|
|
|
|
|
// \TODO -- Maybe test for CONTENT_ICO ???
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (type == CONTENT_IMAGE) {
|
2011-02-21 02:16:33 +03:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2013-12-30 16:44:07 +04:00
|
|
|
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);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is an exported interface documented in url_bar.h */
|
|
|
|
|
|
|
|
bool ro_gui_url_bar_set_content_favicon(struct url_bar *url_bar,
|
|
|
|
struct hlcache_handle *h)
|
|
|
|
{
|
|
|
|
int type = 0;
|
|
|
|
char sprite[URLBAR_FAVICON_NAME_LENGTH];
|
|
|
|
|
|
|
|
if (url_bar == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (h != NULL)
|
2011-05-07 00:40:09 +04:00
|
|
|
type = ro_content_filetype(h);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-22 15:21:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|